Explorar o código

出单量及费用统计 报表调整

li.pengfei %!s(int64=2) %!d(string=hai) anos
pai
achega
a42a8fcc80

+ 18 - 2
src/main/java/com/ydtech/modules/report/controller/ReportController.java

@@ -174,16 +174,32 @@ public class ReportController extends BaseController {
     @PostMapping(value = "/queryOrderAndCostData")
     @ApiOperation(value = "报表-出单量及费用统计-查询")
     public HttpResult<BasePageResult<OrderVolumeAndCostStatisticsResVo>> queryOrderAndCostData(@RequestBody StatisticsReportReqVo reqDto) {
-        BasePageResult<OrderVolumeAndCostStatisticsResVo> quoteResult = reportService.queryOrderAndCostData(reqDto);
+        BasePageResult<OrderVolumeAndCostStatisticsResVo> quoteResult = new BasePageResult<OrderVolumeAndCostStatisticsResVo>();
+        if("0".equals(reqDto.getIsDrilling())){
+            quoteResult=reportService.queryOrderAndCostData(reqDto);
+        }else if("1".equals(reqDto.getIsDrilling())){//下钻查询
+            quoteResult=reportService.drilQueryOrderAndCostData(reqDto);
+        }
         return HttpResult.ok("success", quoteResult);
     }
 
     @PostMapping("/exportOrderAndCostData")
     @ApiOperation(value = "报表-出单量及费用统计-导出")
     public HttpResult<String> exportOrderAndCostData(@RequestBody StatisticsReportReqVo reqDto) {
-        return reportService.exportOrderAndCostData(reqDto);
+        String result="";
+        if("0".equals(reqDto.getIsDrilling())){
+            result=reportService.exportOrderAndCostData(reqDto);
+        }else if("1".equals(reqDto.getIsDrilling())){//下钻查询
+            result=reportService.exportDrilOrderAndCostData(reqDto);
+        }
+        return HttpResult.ok("", result);
     }
 
+    @PostMapping("/exportOrderAndCostListData")
+    @ApiOperation(value = "报表-出单量及费用统计-导出清单")
+    public HttpResult<String> exportOrderAndCostListData(@RequestBody StatisticsReportReqVo reqDto) {
+        return reportService.exportOrderAndCostListData(reqDto);
+    }
 
     @PostMapping("/getInsPlySettleReport")
     @ApiOperation(value = "分页获取月度结算清单数据")

+ 3 - 0
src/main/java/com/ydtech/modules/report/dao/ReportInsurancePolicyMapper.java

@@ -3,6 +3,7 @@ package com.ydtech.modules.report.dao;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ydtech.modules.report.model.ReportInsurancePolicy;
+import com.ydtech.modules.report.model.vo.OrderVolumeAndCostStatisticsListResVo;
 import com.ydtech.modules.report.model.vo.OrderVolumeAndCostStatisticsResVo;
 import com.ydtech.modules.report.model.vo.StatisticsReportReqVo;
 import org.apache.ibatis.annotations.Param;
@@ -22,5 +23,7 @@ public interface ReportInsurancePolicyMapper extends BaseMapper<ReportInsuranceP
 
     Long queryOrderAndCostDataCount(@Param("reportReqVo") StatisticsReportReqVo reqVo);
 
+    List<OrderVolumeAndCostStatisticsListResVo> queryOrderAndCostList(@Param("reportReqVo")StatisticsReportReqVo reqVo);
+
 
 }

+ 167 - 0
src/main/java/com/ydtech/modules/report/model/vo/OrderVolumeAndCostStatisticsListResVo.java

@@ -0,0 +1,167 @@
+package com.ydtech.modules.report.model.vo;
+
+import com.alibaba.excel.annotation.ExcelIgnore;
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
+@Data
+@TableName(autoResultMap = true)
+public class OrderVolumeAndCostStatisticsListResVo {
+
+    /**
+     * 保险名称
+     */
+    @TableField(value = "ins_company")
+    @ExcelProperty(value = "保险公司")
+    private String insCompany;
+    /**
+     * 协议名称
+     */
+    @TableField(value = "agreement_name")
+    @ExcelProperty(value = "协议名称")
+    private String agreementName;
+    /**
+     * 保单号
+     */
+    @TableField(value = "policyno")
+    @ExcelProperty(value = "保单号")
+    private String policyno;
+    /**
+     * 签单时间
+     */
+    @TableField(value = "inside_pay_time")
+    @ExcelProperty(value = "签单时间")
+    private String insidePayTime;
+    /**
+     * 保险起期
+     */
+    @TableField(value = "start_date")
+    @ExcelProperty(value = "保险起期")
+    private String startDate;
+    /**
+     * 保险止期
+     */
+    @TableField(value = "end_date")
+    @ExcelProperty(value = "保险止期")
+    private String endDate;
+    /**
+     * 险种名称
+     */
+    @TableField(value = "risk_name")
+    @ExcelProperty(value = "险种名称")
+    private String riskName;
+    /**
+     * 总保费
+     */
+    @TableField(value = "sumpremium")
+    @ExcelProperty(value = "总保费")
+    private BigDecimal sumpremium;
+    /**
+     * 车船税
+     */
+    @TableField(value = "taxpremium")
+    @ExcelProperty(value = "车船税")
+    private BigDecimal taxpremium;
+    /**
+     * 车船税滞纳金
+     */
+    @TableField(value = "tax_later_premium")
+    @ExcelProperty(value = "车船税滞纳金")
+    private BigDecimal taxLaterPremium;
+    /**
+     * 险种分保额
+     */
+    @TableField(value = "insurance_sub_amount")
+    @ExcelProperty(value = "险种分保额")
+    private String insuranceSubAmount;
+    /**
+     * 车架号
+     */
+    @TableField(value = "frameno")
+    @ExcelProperty(value = "车架号")
+    private String frameno;
+    /**
+     * 车牌号
+     */
+    @TableField(value = "licenseno")
+    @ExcelProperty(value = "车牌号")
+    private String licenseno;
+    /**
+     * 车辆使用性质
+     */
+    @TableField(value = "vehicle_use")
+    @ExcelProperty(value = "车辆使用性质")
+    private String vehicleUse;
+    /**
+     * 能源种类
+     */
+    @TableField(value = "power_type")
+    @ExcelProperty(value = "能源种类")
+    private String powerType;
+    /**
+     * 车辆种类
+     */
+    @TableField(value = "cimodelclass")
+    @ExcelProperty(value = "车辆种类")
+    private String cimodelclass;
+    /**
+     * 核定载质量
+     */
+    @TableField(value = "limit_load")
+    @ExcelProperty(value = "核定载质量")
+    private String limitLoad;
+    /**
+     * 投保人名称
+     */
+    @TableField(value = "appli_name")
+    @ExcelProperty(value = "投保人名称")
+    private String appliName;
+    /**
+     * 被保人名称
+     */
+    @TableField(value = "insure_name")
+    @ExcelProperty(value = "被保人名称")
+    private String insureName;
+    /**
+     * 代理团队名称
+     */
+    @TableField(value = "deptname")
+    @ExcelProperty(value = "团队名称")
+    private String deptname;
+    /**
+     * 用户名称
+     */
+    @TableField(value = "username")
+    @ExcelProperty(value = "业务员")
+    private String username;
+    /**
+     * 产品名称
+     */
+    @TableField(value = "product")
+    @ExcelProperty(value = "产品名称")
+    private String product;
+    /**
+     * 总费用
+     */
+    @TableField(value = "sum_costs_premiums")
+    @ExcelProperty(value = "总费用")
+    private BigDecimal sumCostsPremiums;
+    /**
+     * 监管费
+     */
+    @TableField(value = "supervise_costs_premiums")
+    @ExcelProperty(value = "手续费")
+    private BigDecimal superviseCostsPremiums;
+    /**
+     * 其他费
+     */
+    @TableField(value = "other_costs_premiums")
+    @ExcelProperty(value = "跟单费")
+    private BigDecimal otherCostsPremiums;
+
+}

+ 23 - 5
src/main/java/com/ydtech/modules/report/model/vo/OrderVolumeAndCostStatisticsResVo.java

@@ -1,5 +1,7 @@
 package com.ydtech.modules.report.model.vo;
 
+import com.alibaba.excel.annotation.ExcelIgnore;
+import com.alibaba.excel.annotation.ExcelProperty;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
@@ -13,57 +15,73 @@ public class OrderVolumeAndCostStatisticsResVo {
     /**
      * 机构名称
      */
+    @ExcelProperty(value = "机构名称")
     @TableField(value = "institution")
     private String institution;
     /**
      * 团队名称
      */
+    @ExcelProperty(value = "团队名称")
     @TableField(value = "deptname")
     private String deptname;
 
     /**
      * 用户名称
      */
+    @ExcelProperty(value = "业务员名称")
     @TableField(value = "username")
     private String username;
     /**
      * 险种名称
      */
+    @ExcelProperty(value = "产品")
     @TableField(value = "risk_name")
     private String riskName;
     /**
      * 保单数量
      */
+    @ExcelProperty(value = "保单数量")
     @TableField(value = "policy_count")
     private BigDecimal policyCount;
     /**
      * 总保费
      */
+    @ExcelProperty(value = "总保费")
     @TableField(value = "sumremium")
     private BigDecimal sumpremium;
-    /**
-     * 总费用
-     */
-    @TableField(value = "sum_costs_premiums")
-    private BigDecimal sumCostsPremiums;
     /**
      * 监管费
      */
+    @ExcelProperty(value = "总手续费")
     @TableField(value = "supervise_costs_premiums")
     private BigDecimal superviseCostsPremiums;
     /**
      * 其他费
      */
+    @ExcelProperty(value = "总跟单费")
     @TableField(value = "other_costs_premiums")
     private BigDecimal otherCostsPremiums;
 
+    /**
+     * 总费用
+     */
+    @ExcelProperty(value = "费用合计")
+    @TableField(value = "sum_costs_premiums")
+    private BigDecimal sumCostsPremiums;
     /**
      * 机构Id
      */
+    @ExcelIgnore
     private String institutionId;
     /**
      * 团队Id
      */
+    @ExcelIgnore
     private String deptId;
+    /**
+     * 人员Id
+     */
+    @ExcelIgnore
+    private String userId;
 
 }

+ 7 - 0
src/main/java/com/ydtech/modules/report/model/vo/StatisticsReportReqVo.java

@@ -38,4 +38,11 @@ public class StatisticsReportReqVo {
 
     @ApiModelProperty(value = "页数")
     private int pageNum;
+    @ApiModelProperty(value = "是否下钻查询  1 下钻 0非下钻查询")
+    private String isDrilling;
+    @ApiModelProperty(value = "下钻查询类型  1 团队下钻 0机构下钻")
+    private String drilType;
+    @ApiModelProperty(value = "机构下钻需要截取机构位数  2总部下钻  4一级机构下钻 6二级机构下钻  8三级机构下钻  11四级机构下钻  0五级机构下钻")
+    private String drilFlag;
+
 }

+ 20 - 1
src/main/java/com/ydtech/modules/report/service/ReportService.java

@@ -102,6 +102,25 @@ public interface ReportService {
      * @param reqDto
      * @return
      */
-    public HttpResult<String> exportOrderAndCostData(StatisticsReportReqVo reqDto);
+    public String exportOrderAndCostData(StatisticsReportReqVo reqDto);
+    /**
+     * 报表-出单量及费用统计-下钻查询
+     * @param reqVo
+     * @return
+     */
+    public BasePageResult<OrderVolumeAndCostStatisticsResVo> drilQueryOrderAndCostData(StatisticsReportReqVo reqVo);
+    /**
+     * 报表-出单量及费用统计-下钻导出
+     * @param reqDto
+     * @return
+     */
+    public String exportDrilOrderAndCostData(StatisticsReportReqVo reqDto);
+
+    /**
+     * 报表-出单量及费用统计-导出清单
+     * @param reqDto
+     * @return
+     */
+    public HttpResult<String> exportOrderAndCostListData(StatisticsReportReqVo reqDto);
 
 }

+ 154 - 1
src/main/java/com/ydtech/modules/report/service/impl/ReportServiceImpl.java

@@ -967,11 +967,164 @@ public class ReportServiceImpl implements ReportService {
                 orderVolumeAndCostStatisticsResVoPage.getTotal(), orderVolumeAndCostStatisticsResVoPage.getPages()
                 , orderVolumeAndCostStatisticsResVoPage.getRecords());
     }
+    /**
+     * 报表-出单量及费用统计-下钻查询
+     * @param reqVo
+     * @return
+     */
+    public BasePageResult<OrderVolumeAndCostStatisticsResVo> drilQueryOrderAndCostData(StatisticsReportReqVo reqVo){
+        com.baomidou.mybatisplus.extension.plugins.pagination.Page<InsOrders> page = new Page<>(reqVo.getPageNum(), reqVo.getPageSize());
+        page.setSearchCount(false).setOptimizeCountSql(false);//关闭count查询
+        if(StringUtils.isNotEmpty(reqVo.getTeamCode())){
+            //如果团队不为空,则为团队下钻  查询到业务员
+            reqVo.setDrilType("1");
+        }else{
+            //如果团队为空,则为机构下钻,查询下一级机构
+            reqVo.setDrilType("0");
+            SysDept sysDept=sysDeptService.getById(reqVo.getDeptId());
+            String flag="";
+            if(StringUtils.isNotEmpty(sysDept.getComlevel())){
+                switch (sysDept.getComlevel()){
+                    case "1":
+                        flag="4"; break;
+                    case "2":
+                        flag="6"; break;
+                    case "3":
+                        flag="8"; break;
+                    case "4":
+                        flag="11"; break;
+                    case "5":
+                        flag="0"; break;
+                }
+            }else{
+                flag="2";
+            }
+            reqVo.setDrilFlag(flag);
+        }
+        Page<OrderVolumeAndCostStatisticsResVo> orderVolumeAndCostStatisticsResVoPage = reportInsurancePolicyMapper.queryOrderAndCostData(page,
+                reqVo);
+        orderVolumeAndCostStatisticsResVoPage.getRecords().stream().forEach(item->{
+            //如果返回业务员时
+            if(StringUtils.isNotEmpty(item.getUsername())){
+                SysDept sysDept1=sysDeptService.getById(reqVo.getDeptId());
+                item.setInstitutionId(reqVo.getDeptId());
+                item.setInstitution(sysDept1.getName());
+                SysDept sysDept2=sysDeptService.getById(reqVo.getTeamCode());
+                item.setDeptId(reqVo.getTeamCode());
+                item.setDeptname(sysDept2.getName());
+            }else{
+                //如果返回团队时
+                if(StringUtils.isNotEmpty(item.getDeptId())){
+                    SysDept sysDept1=sysDeptService.getById(item.getDeptId());
+                    item.setDeptname(sysDept1.getName());
+                    item.setDeptId(item.getDeptId());
+                    SysDept sysDept2=sysDeptService.getById(reqVo.getDeptId());
+                    item.setInstitutionId(reqVo.getDeptId());
+                    item.setInstitution(sysDept2.getName());
+                }else{
+                    //不下钻到团队时,按返回机构赋值
+                    item.setInstitutionId(item.getInstitutionId());
+                    SysDept sysDept=sysDeptService.getById(item.getInstitutionId());
+                    item.setInstitution(sysDept.getName());
+                }
+            }
+        });
+        Long total = reportInsurancePolicyMapper.queryOrderAndCostDataCount(reqVo);
+        orderVolumeAndCostStatisticsResVoPage.setTotal(total);
+        return new BasePageResult<>(reqVo.getPageNum(), reqVo.getPageSize(),
+                orderVolumeAndCostStatisticsResVoPage.getTotal(), orderVolumeAndCostStatisticsResVoPage.getPages()
+                , orderVolumeAndCostStatisticsResVoPage.getRecords());
+    }
+
+    @Override
+    public String exportOrderAndCostData(StatisticsReportReqVo reqDto) {
+        List<OrderVolumeAndCostStatisticsResVo> orderVolumeAndCostStatisticsResVoPage = reportInsurancePolicyMapper.queryOrderAndCostData(reqDto);
+        orderVolumeAndCostStatisticsResVoPage.stream().forEach(item->{
+            item.setInstitutionId(reqDto.getDeptId());
+            SysDept sysDept1=sysDeptService.getById(reqDto.getDeptId());
+            item.setInstitution(sysDept1.getName());
+            if(StringUtils.isNotEmpty(reqDto.getTeamCode())){
+                item.setDeptId(reqDto.getTeamCode());
+                SysDept sysDept2=sysDeptService.getById(reqDto.getTeamCode());
+                if(sysDept2!=null){
+                    item.setDeptname(sysDept2.getName());
+                }
+            }
+            if(StringUtils.isNotEmpty(reqDto.getUserId())){
+                SysUser sysUser=sysUserService.getById(reqDto.getUserId());
+                if(sysUser!=null){
+                    item.setUsername(sysUser.getName());
+                }
+            }
+        });
+        String s = EasyExcelUtils.downExcel(uploadFilePath, OrderVolumeAndCostStatisticsResVo.class, orderVolumeAndCostStatisticsResVoPage);
+        return s;
+    }
 
     @Override
-    public HttpResult<String> exportOrderAndCostData(StatisticsReportReqVo reqDto) {
+    public String exportDrilOrderAndCostData(StatisticsReportReqVo reqDto) {
+        if(StringUtils.isNotEmpty(reqDto.getTeamCode())){
+            //如果团队不为空,则为团队下钻  查询到业务员
+            reqDto.setDrilType("1");
+        }else{
+            //如果团队为空,则为机构下钻,查询下一级机构
+            reqDto.setDrilType("0");
+            SysDept sysDept=sysDeptService.getById(reqDto.getDeptId());
+            String flag="";
+            if(StringUtils.isNotEmpty(sysDept.getComlevel())){
+                switch (sysDept.getComlevel()){
+                    case "1":
+                        flag="4"; break;
+                    case "2":
+                        flag="6"; break;
+                    case "3":
+                        flag="8"; break;
+                    case "4":
+                        flag="11"; break;
+                    case "5":
+                        flag="0"; break;
+                }
+            }else{
+                flag="2";
+            }
+            reqDto.setDrilFlag(flag);
+        }
         List<OrderVolumeAndCostStatisticsResVo> orderVolumeAndCostStatisticsResVoPage = reportInsurancePolicyMapper.queryOrderAndCostData(reqDto);
+        orderVolumeAndCostStatisticsResVoPage.stream().forEach(item->{
+            //如果返回业务员时
+            if(StringUtils.isNotEmpty(item.getUsername())){
+                SysDept sysDept1=sysDeptService.getById(reqDto.getDeptId());
+                item.setInstitutionId(reqDto.getDeptId());
+                item.setInstitution(sysDept1.getName());
+                SysDept sysDept2=sysDeptService.getById(reqDto.getTeamCode());
+                item.setDeptId(reqDto.getTeamCode());
+                item.setDeptname(sysDept2.getName());
+            }else{
+                //如果返回团队时
+                if(StringUtils.isNotEmpty(item.getDeptId())){
+                    SysDept sysDept1=sysDeptService.getById(item.getDeptId());
+                    item.setDeptname(sysDept1.getName());
+                    item.setDeptId(item.getDeptId());
+                    SysDept sysDept2=sysDeptService.getById(reqDto.getDeptId());
+                    item.setInstitutionId(reqDto.getDeptId());
+                    item.setInstitution(sysDept2.getName());
+                }else{
+                    //不下钻到团队时,按返回机构赋值
+                    item.setInstitutionId(item.getInstitutionId());
+                    SysDept sysDept=sysDeptService.getById(item.getInstitutionId());
+                    item.setInstitution(sysDept.getName());
+                }
+            }
+        });
         String s = EasyExcelUtils.downExcel(uploadFilePath, OrderVolumeAndCostStatisticsResVo.class, orderVolumeAndCostStatisticsResVoPage);
+        return s;
+    }
+
+
+    @Override
+    public HttpResult<String> exportOrderAndCostListData(StatisticsReportReqVo reqDto) {
+        List<OrderVolumeAndCostStatisticsListResVo> orderVolumeAndCostStatisticsListResVos = reportInsurancePolicyMapper.queryOrderAndCostList(reqDto);
+        String s = EasyExcelUtils.downExcel(uploadFilePath, OrderVolumeAndCostStatisticsListResVo.class, orderVolumeAndCostStatisticsListResVos);
         return HttpResult.ok("", s);
     }
 }

+ 244 - 49
src/main/resources/mapper/modules/report/ReportInsurancePolicyMapper.xml

@@ -43,36 +43,75 @@
     <select id="queryOrderAndCostData"  resultMap="OrderAndCostDataMap">
 
         SELECT
-        ''institution,
-        <if test="reportReqVo.teamCode != null and reportReqVo.teamCode != ''">
-            p.deptname,
-        </if>
-        <if test="reportReqVo.teamCode == null || reportReqVo.teamCode == ''">
-            ''deptname,
-        </if>
-        <if test="reportReqVo.userId != null and reportReqVo.userId != ''">
-            p.username,
-        </if>
-        <if test="reportReqVo.userId == null || reportReqVo.userId == ''">
-            ''username,
+        <!--下钻查询时拼接-->
+        <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '1'.toString()">
+            <!--按团队下钻时-->
+            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '1'.toString()">
+                p.`username`,p.userid userId,
+            </if>
+            <!--按机构下钻时-->
+            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
+                <choose>
+                    <!--下钻的是五级机构时,下钻到团队-->
+                    <when test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '0'.toString()">
+                        p.deptid,
+                    </when>
+                    <!--下钻的非五级机构时,下钻到下级机构-->
+                    <otherwise>
+                        substr(p.deptid,1,#{reportReqVo.drilFlag}) institutionId,
+                    </otherwise>
+                </choose>
+            </if>
         </if>
         p.`risk_name` risk_name,
-        count(1) policy_count,
+        count(distinct policyno) policy_count,
         SUM(p.`sumpremium`) sumpremium,
         SUM(p.`supervise_costs_premiums`) supervise_costs_premiums,
         SUM(p.`other_costs_premiums`) other_costs_premiums,
         SUM(p.`sum_costs_premiums`) sum_costs_premiums
         FROM
         report_insurance_policy p WHERE 1=1
-        <if test="reportReqVo.deptId != null and reportReqVo.deptId != ''">
-            and p.deptid like #{reportReqVo.deptId}"%"
-        </if>
-        <if test="reportReqVo.teamCode != null and reportReqVo.teamCode != ''">
-            and p.deptid = #{reportReqVo.teamCode}
+        <!--下钻查询时拼接-->
+        <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '1'.toString()">
+            <!--按团队下钻时-->
+            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '1'.toString()">
+                <if test="reportReqVo.teamCode != null and reportReqVo.teamCode != ''">
+                    and p.deptid = #{reportReqVo.teamCode}
+                </if>
+            </if>
+            <!--按机构下钻时-->
+            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
+                <choose>
+                    <!--下钻的是五级机构时,下钻到团队-->
+                    <when test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '0'.toString()">
+                        and p.deptid in (SELECT id FROM `sys_dept`  WHERE parent_id= #{reportReqVo.deptId} )
+                    </when>
+                    <!--下钻的非五级机构时,下钻到下级机构-->
+                    <otherwise>
+                        and substr(p.deptid,1,#{reportReqVo.drilFlag}) in (SELECT id FROM `sys_dept`  WHERE parent_id= #{reportReqVo.deptId} )
+                    </otherwise>
+                </choose>
+            </if>
         </if>
-        <if test="reportReqVo.userId != null and reportReqVo.userId != ''">
-            and p.userid = #{reportReqVo.userId}
+        <!--非下钻查询时拼接-->
+        <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '0'.toString()">
+            <choose>
+                <!--条件中团队不为空时,直接拼接团队-->
+                <when test="reportReqVo.teamCode != null and reportReqVo.teamCode != ''">
+                    and p.deptid = #{reportReqVo.teamCode}
+                </when>
+                <!--条件中团队为空时,使用机构模糊查询-->
+                <otherwise>
+                    <if test="reportReqVo.deptId != null and reportReqVo.deptId != ''">
+                        and p.deptid like #{reportReqVo.deptId}"%"
+                    </if>
+                </otherwise>
+            </choose>
+            <if test="reportReqVo.userId != null and reportReqVo.userId != ''">
+                and p.userid = #{reportReqVo.userId}
+            </if>
         </if>
+        <!--通用查询条件拼接-->
         <if test="reportReqVo.insCompany != null and reportReqVo.insCompany != ''">
             and p.company_id = #{reportReqVo.insCompany}
         </if>
@@ -85,11 +124,25 @@
             and p.inside_pay_time  between #{reportReqVo.quoteStartDate} AND #{reportReqVo.quoteEndDate}
         </if>
         GROUP BY p.`risk_name`
-        <if test="reportReqVo.userId != null and reportReqVo.userId != ''">
-            ,p.username
-        </if>
-        <if test="reportReqVo.teamCode != null and reportReqVo.teamCode != ''">
-            ,p.deptname
+        <!--下钻查询时拼接-->
+        <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '1'.toString()">
+            <!--按团队下钻时-->
+            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '1'.toString()">
+                ,p.`username`,p.userid order by p.`username`,p.`risk_name`
+            </if>
+            <!--按机构下钻时-->
+            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
+                <choose>
+                    <!--下钻的是五级机构时,下钻到团队-->
+                    <when test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '0'.toString()">
+                        ,p.deptid  order by p.deptid,p.`risk_name`
+                    </when>
+                    <!--下钻的非五级机构时,下钻到下级机构-->
+                    <otherwise>
+                        ,substr(p.deptid,1,#{reportReqVo.drilFlag}) order by    substr(p.deptid,1,#{reportReqVo.drilFlag}),p.`risk_name`
+                    </otherwise>
+                </choose>
+            </if>
         </if>
     </select>
 
@@ -109,36 +162,75 @@
         count(1)
         from (
         SELECT
-        ''institution,
-        <if test="reportReqVo.teamCode != null and reportReqVo.teamCode != ''">
-            p.deptname,
-        </if>
-        <if test="reportReqVo.teamCode == null || reportReqVo.teamCode == ''">
-            ''deptname,
-        </if>
-        <if test="reportReqVo.userId != null and reportReqVo.userId != ''">
-            p.username,
-        </if>
-        <if test="reportReqVo.userId == null || reportReqVo.userId == ''">
-            ''username,
+        <!--下钻查询时拼接-->
+        <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '1'.toString()">
+            <!--按团队下钻时-->
+            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '1'.toString()">
+                p.`username`,p.userid userId,
+            </if>
+            <!--按机构下钻时-->
+            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
+                <choose>
+                    <!--下钻的是五级机构时,下钻到团队-->
+                    <when test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '0'.toString()">
+                        p.deptid,
+                    </when>
+                    <!--下钻的非五级机构时,下钻到下级机构-->
+                    <otherwise>
+                        substr(p.deptid,1,#{reportReqVo.drilFlag}) institutionId,
+                    </otherwise>
+                </choose>
+            </if>
         </if>
         p.`risk_name` risk_name,
-        count(1) policy_count,
+        count(distinct policyno) policy_count,
         SUM(p.`sumpremium`) sumpremium,
         SUM(p.`supervise_costs_premiums`) supervise_costs_premiums,
         SUM(p.`other_costs_premiums`) other_costs_premiums,
         SUM(p.`sum_costs_premiums`) sum_costs_premiums
         FROM
         report_insurance_policy p WHERE 1=1
-        <if test="reportReqVo.deptId != null and reportReqVo.deptId != ''">
-            and p.deptid like #{reportReqVo.deptId}"%"
-        </if>
-        <if test="reportReqVo.teamCode != null and reportReqVo.teamCode != ''">
-            and p.deptid = #{reportReqVo.teamCode}
+        <!--下钻查询时拼接-->
+        <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '1'.toString()">
+            <!--按团队下钻时-->
+            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '1'.toString()">
+                <if test="reportReqVo.teamCode != null and reportReqVo.teamCode != ''">
+                    and p.deptid = #{reportReqVo.teamCode}
+                </if>
+            </if>
+            <!--按机构下钻时-->
+            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
+                <choose>
+                    <!--下钻的是五级机构时,下钻到团队-->
+                    <when test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '0'.toString()">
+                        and p.deptid in (SELECT id FROM `sys_dept`  WHERE parent_id= #{reportReqVo.deptId} )
+                    </when>
+                    <!--下钻的非五级机构时,下钻到下级机构-->
+                    <otherwise>
+                        and substr(p.deptid,1,#{reportReqVo.drilFlag}) in (SELECT id FROM `sys_dept`  WHERE parent_id= #{reportReqVo.deptId} )
+                    </otherwise>
+                </choose>
+            </if>
         </if>
-        <if test="reportReqVo.userId != null and reportReqVo.userId != ''">
-            and p.userid = #{reportReqVo.userId}
+        <!--非下钻查询时拼接-->
+        <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '0'.toString()">
+            <choose>
+                <!--条件中团队不为空时,直接拼接团队-->
+                <when test="reportReqVo.teamCode != null and reportReqVo.teamCode != ''">
+                    and p.deptid = #{reportReqVo.teamCode}
+                </when>
+                <!--条件中团队为空时,使用机构模糊查询-->
+                <otherwise>
+                    <if test="reportReqVo.deptId != null and reportReqVo.deptId != ''">
+                        and p.deptid like #{reportReqVo.deptId}"%"
+                    </if>
+                </otherwise>
+            </choose>
+            <if test="reportReqVo.userId != null and reportReqVo.userId != ''">
+                and p.userid = #{reportReqVo.userId}
+            </if>
         </if>
+        <!--通用查询条件拼接-->
         <if test="reportReqVo.insCompany != null and reportReqVo.insCompany != ''">
             and p.company_id = #{reportReqVo.insCompany}
         </if>
@@ -151,12 +243,115 @@
             and p.inside_pay_time  between #{reportReqVo.quoteStartDate} AND #{reportReqVo.quoteEndDate}
         </if>
         GROUP BY p.`risk_name`
+        <!--下钻查询时拼接-->
+        <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '1'.toString()">
+            <!--按团队下钻时-->
+            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '1'.toString()">
+                ,p.`username`,p.userid order by p.`username`,p.`risk_name`
+            </if>
+            <!--按机构下钻时-->
+            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
+                <choose>
+                    <!--下钻的是五级机构时,下钻到团队-->
+                    <when test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '0'.toString()">
+                        ,p.deptid  order by p.deptid,p.`risk_name`
+                    </when>
+                    <!--下钻的非五级机构时,下钻到下级机构-->
+                    <otherwise>
+                        ,substr(p.deptid,1,#{reportReqVo.drilFlag}) order by    substr(p.deptid,1,#{reportReqVo.drilFlag}),p.`risk_name`
+                    </otherwise>
+                </choose>
+            </if>
+        </if>
+        ) as s
+    </select>
+
+
+    <resultMap id="OrderVolumeAndCostStatisticsListResMap" type="com.ydtech.modules.report.model.vo.OrderVolumeAndCostStatisticsListResVo">
+        <result property="insCompany" column="ins_company" jdbcType="VARCHAR"/>
+        <result property="agreementName" column="agreement_name" jdbcType="VARCHAR"/>
+        <result property="policyno" column="policyno" jdbcType="VARCHAR"/>
+        <result property="insidePayTime" column="inside_pay_time" jdbcType="VARCHAR"/>
+        <result property="startDate" column="start_date" jdbcType="VARCHAR"/>
+        <result property="endDate" column="end_date" jdbcType="VARCHAR"/>
+        <result property="riskName" column="risk_name" jdbcType="VARCHAR"/>
+        <result property="sumpremium" column="sumpremium" jdbcType="DECIMAL"/>
+        <result property="taxpremium" column="taxpremium" jdbcType="DECIMAL"/>
+        <result property="taxLaterPremium" column="tax_later_premium" jdbcType="DECIMAL"/>
+        <result property="insuranceSubAmount" column="insurance_sub_amount" jdbcType="VARCHAR"/>
+        <result property="frameno" column="frameno" jdbcType="VARCHAR"/>
+        <result property="licenseno" column="licenseno" jdbcType="VARCHAR"/>
+        <result property="vehicleUse" column="vehicle_use" jdbcType="VARCHAR"/>
+        <result property="powerType" column="power_type" jdbcType="VARCHAR"/>
+        <result property="cimodelclass" column="cimodelclass" jdbcType="VARCHAR"/>
+        <result property="limitLoad" column="limit_load" jdbcType="VARCHAR"/>
+        <result property="appliName" column="appli_name" jdbcType="VARCHAR"/>
+        <result property="insureName" column="insure_name" jdbcType="VARCHAR"/>
+        <result property="deptname" column="deptname" jdbcType="VARCHAR"/>
+        <result property="username" column="username" jdbcType="VARCHAR"/>
+        <result property="product" column="product" jdbcType="VARCHAR"/>
+        <result property="sumCostsPremiums" column="sum_costs_premiums" jdbcType="DECIMAL"/>
+        <result property="superviseCostsPremiums" column="supervise_costs_premiums" jdbcType="DECIMAL"/>
+        <result property="otherCostsPremiums" column="other_costs_premiums" jdbcType="DECIMAL"/>
+    </resultMap>
+
+    <select id="queryOrderAndCostList"  resultMap="OrderVolumeAndCostStatisticsListResMap">
+
+        SELECT
+        ins_company,
+        agreement_name,
+        policyno,
+        DATE_FORMAT(inside_pay_time, '%Y-%m-%d') inside_pay_time,
+        DATE_FORMAT(start_date, '%Y-%m-%d') start_date,
+        DATE_FORMAT(end_date, '%Y-%m-%d') end_date,
+        risk_name,
+        sumpremium,
+        taxpremium,
+        tax_later_premium,
+        insurance_sub_amount,
+        frameno,
+        licenseno,
+        vehicle_use,
+        power_type,
+        cimodelclass,
+        limit_load,
+        appli_name,
+        insure_name,
+        deptname,
+        username,
+        product,
+        sum_costs_premiums,
+        supervise_costs_premiums,
+        other_costs_premiums
+        FROM
+        report_insurance_policy p WHERE 1=1
+        <choose>
+            <!--条件中团队不为空时,直接拼接团队-->
+            <when test="reportReqVo.teamCode != null and reportReqVo.teamCode != ''">
+                and p.deptid = #{reportReqVo.teamCode}
+            </when>
+            <!--条件中团队为空时,使用机构模糊查询-->
+            <otherwise>
+                <if test="reportReqVo.deptId != null and reportReqVo.deptId != ''">
+                    and p.deptid like #{reportReqVo.deptId}"%"
+                </if>
+            </otherwise>
+        </choose>
         <if test="reportReqVo.userId != null and reportReqVo.userId != ''">
-            ,p.username
+            and p.userid = #{reportReqVo.userId}
         </if>
-        <if test="reportReqVo.teamCode != null and reportReqVo.teamCode != ''">
-            ,p.deptname
+        <!--通用查询条件拼接-->
+        <if test="reportReqVo.insCompany != null and reportReqVo.insCompany != ''">
+            and p.company_id = #{reportReqVo.insCompany}
         </if>
-        ) as s
+        <if test="reportReqVo.riskCode != null and reportReqVo.riskCode != ''">
+            <if test="reportReqVo.riskCode!='ALL'.toString()">
+                and p.risk_code = #{reportReqVo.riskCode}
+            </if>
+        </if>
+        <if test="reportReqVo.quoteStartDate != null and reportReqVo.quoteEndDate != null">
+            and p.inside_pay_time  between #{reportReqVo.quoteStartDate} AND #{reportReqVo.quoteEndDate}
+        </if>
+
     </select>
 </mapper>