cuixinpeng 2 лет назад
Родитель
Сommit
457b2cb42a

+ 14 - 3
src/main/java/com/ydtech/modules/report/controller/ReportController.java

@@ -222,19 +222,30 @@ public class ReportController extends BaseController {
     @PostMapping("/getPayApplyUserReport")
     @ApiOperation(value = "报表-应付分销费和手续费统计-查询")
     public HttpResult<BasePageResult<PayApplyUserReportResVo>> getPayApplyUserReport(@RequestBody PayApplyUserReportReqVo payApplyUserReportReqVo) {
-        BasePageResult<PayApplyUserReportResVo> quoteResult = reportService.getPayApplyUserReportData(payApplyUserReportReqVo);
+        BasePageResult<PayApplyUserReportResVo> quoteResult = new BasePageResult<PayApplyUserReportResVo>();
+        if("0".equals(payApplyUserReportReqVo.getIsDrilling())){
+            quoteResult = reportService.getPayApplyUserReportData(payApplyUserReportReqVo);
+        }else if("1".equals(payApplyUserReportReqVo.getIsDrilling())){//下钻查询
+            quoteResult=reportService.drilPayApplyUserReportData(payApplyUserReportReqVo);
+        }
         return HttpResult.ok("success", quoteResult);
     }
     @PostMapping("/exportPayApplyUserReport")
     @ApiOperation(value = "报表-应付统计分销费和手续费清单-导出清单")
     public HttpResult<String> exportPayApplyUserReport(@RequestBody PayApplyUserReportReqVo payApplyUserReportReqVo) {
-        return reportService.exportPayApplyUserReportData(payApplyUserReportReqVo);
+        String result="";
+        if("0".equals(payApplyUserReportReqVo.getIsDrilling())){
+            result = reportService.exportPayApplyUserReportData(payApplyUserReportReqVo);
+        }else if("1".equals(payApplyUserReportReqVo.getIsDrilling())){//下钻查询
+            result= reportService.exportDrilPayApplyUserReportData(payApplyUserReportReqVo);
+        }
+        return HttpResult.ok("", result);
     }
 
     @PostMapping("/exportPayApplyUserReporttListData")
     @ApiOperation(value = "报表-应付统计分销费和手续费清单-导出清单明细")
     public HttpResult<String> exportPayApplyUserReportListData(@RequestBody PayApplyUserReportReqVo payApplyUserReportReqVo) {
-        return reportService.exportPayApplyUserReportData(payApplyUserReportReqVo);
+        return reportService.exportPayApplyUserReportListData(payApplyUserReportReqVo);
     }
 
     /*--------------------------------------------------------------------------*/

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

@@ -29,6 +29,8 @@ public interface ReportInsurancePolicyMapper extends BaseMapper<ReportInsuranceP
 
     List<PayApplyUserReportResVo> queryPayApplyUserReportData(@Param("reportReqVo") PayApplyUserReportReqVo reqVo);
 
+    List<PayApplyUserReportListResVo>  queryPayApplyUserReportList(@Param("reportReqVo") PayApplyUserReportReqVo reqVo);
+
     Long queryPayApplyUserReportDataCount(@Param("reportReqVo") PayApplyUserReportReqVo reqVo);
 
     Page<PayApplyDeptReportResVo> queryPayApplyDeptReportData(@Param("page") Page page, @Param("reportReqVo") PayApplyDeptReportReqVo reqVo);

+ 4 - 1
src/main/java/com/ydtech/modules/report/model/vo/PayApplyUserReportReqVo.java

@@ -48,7 +48,10 @@ public class PayApplyUserReportReqVo {
 
     @ApiModelProperty(value = "是否下钻查询  1 下钻 0非下钻查询")
     private String isDrilling;
-
+    @ApiModelProperty(value = "下钻查询类型  1 团队下钻 0机构下钻  2返回上层")
+    private String drilType;
+    @ApiModelProperty(value = "机构下钻返回时 需要查询的机构层级    总部机构层级为空时,赋值为X")
+    private String drilFlag;
     @ApiModelProperty(value = "是否返回上层  1 返回上层 0非返回上层")
     private String isReturnBack;
 }

+ 1 - 0
src/main/java/com/ydtech/modules/report/model/vo/PayApplyUserReportResVo.java

@@ -59,6 +59,7 @@ public class PayApplyUserReportResVo {
      * 机构Id
      */
     @ExcelIgnore
+    @TableField(value = "institutionId")
     private String institutionId;
     /**
      * 团队Id

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

@@ -131,12 +131,32 @@ public interface ReportService {
      */
     public BasePageResult<PayApplyUserReportResVo> getPayApplyUserReportData(PayApplyUserReportReqVo reqDto);
 
+    /**
+     * 页获取应付分销费和手续费统计清单数据
+     * @param reqDto
+     * @return
+     */
+    public BasePageResult<PayApplyUserReportResVo> drilPayApplyUserReportData(PayApplyUserReportReqVo reqDto);
+
+    /**
+     * 导出应付统计分销费和手续费清单数据
+     * @param reqDto
+     * @return
+     */
+    public String exportPayApplyUserReportData(PayApplyUserReportReqVo reqDto);
     /**
      * 导出应付统计分销费和手续费清单数据
      * @param reqDto
      * @return
      */
-    public HttpResult<String> exportPayApplyUserReportData(PayApplyUserReportReqVo reqDto);
+    public String exportDrilPayApplyUserReportData(PayApplyUserReportReqVo reqDto);
+
+    /**
+     * 导出应付统计分销费和手续费清单明细数据
+     * @param reqDto
+     * @return
+     */
+    public HttpResult<String> exportPayApplyUserReportListData(PayApplyUserReportReqVo reqDto) ;
 
     /**
      * 分页获取应付管理费统计清单数据

+ 213 - 2
src/main/java/com/ydtech/modules/report/service/impl/ReportServiceImpl.java

@@ -1178,19 +1178,230 @@ public class ReportServiceImpl implements ReportService {
         page.setSearchCount(false).setOptimizeCountSql(false);//关闭count查询
         Page<PayApplyUserReportResVo> payApplyReportResVoPage = reportInsurancePolicyMapper.queryPayApplyUserReportData(page,
                 reqDto);
+        payApplyReportResVoPage.getRecords().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());
+                }
+            }
+        });
         Long total = reportInsurancePolicyMapper.queryPayApplyUserReportDataCount(reqDto);
         payApplyReportResVoPage.setTotal(total);
         return new BasePageResult<>(reqDto.getPageNum(), reqDto.getPageSize(),
                 payApplyReportResVoPage.getTotal(), payApplyReportResVoPage.getPages()
                 , payApplyReportResVoPage.getRecords());
     }
+    @Override
+    public BasePageResult<PayApplyUserReportResVo> drilPayApplyUserReportData(PayApplyUserReportReqVo reqDto) {
+        Page<InsOrders> page = new Page<>(reqDto.getPageNum(), reqDto.getPageSize());
+        page.setSearchCount(false).setOptimizeCountSql(false);//关闭count查询
+        //返回上层时 调整查询条件
+        if(StringUtils.isNotEmpty(reqDto.getIsReturnBack())&&"1".equals(reqDto.getIsReturnBack())){
+            if(StringUtils.isNotEmpty(reqDto.getTeamCode())) {
+                reqDto.setDeptId(reqDto.getTeamCode());
+            }
+            reqDto.setDrilType("2");
+            //如果是机构返回上层时,需要找上级的上级去查询
+            SysDept sysDept=sysDeptService.getById(reqDto.getDeptId());
+            SysDept sysDept1=sysDeptService.getById(sysDept.getParentId());
+            if(sysDept1==null){
+                throw new SystemException("已经到最上层,不能继续返回!");
+            }
+            String flag="";
+            SysDept sysDept2=sysDeptService.getById(sysDept1.getParentId());
+            if(sysDept2==null){
+                reqDto.setDeptId(sysDept1.getId());
+                flag="X";
+            }else{
+                reqDto.setDeptId(sysDept2.getId());
+                flag=sysDept1.getComlevel();
+            }
+            reqDto.setDrilFlag(flag);
+        }else if(StringUtils.isNotEmpty(reqDto.getIsDrilling())&&"1".equals(reqDto.getIsDrilling())){
+            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())){
+                    flag=sysDept.getComlevel();
+                }else{
+                    flag="X";
+                }
+                reqDto.setDrilFlag(flag);
+            }
+        }
+        Page<PayApplyUserReportResVo> payApplyReportResVoPage = reportInsurancePolicyMapper.queryPayApplyUserReportData(page,
+                reqDto);
+        payApplyReportResVoPage.getRecords().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{
+                    //不下钻到团队时,按返回机构赋值
+                    if(StringUtils.isNotEmpty(item.getInstitutionId())){
+                        item.setInstitutionId(item.getInstitutionId());
+                        SysDept sysDept=sysDeptService.getById(item.getInstitutionId());
+                        if(sysDept!=null){
+                            item.setInstitution(sysDept.getName());
+                        }
+                    }else {
+                        item.setInstitutionId(reqDto.getDeptId());
+                        SysDept sysDept=sysDeptService.getById(reqDto.getDeptId());
+                        if(sysDept!=null){
+                            item.setInstitution(sysDept.getName());
+                        }
+                    }
 
+                }
+            }
+        });
+        Long total = reportInsurancePolicyMapper.queryPayApplyUserReportDataCount(reqDto);
+        payApplyReportResVoPage.setTotal(total);
+        return new BasePageResult<>(reqDto.getPageNum(), reqDto.getPageSize(),
+                payApplyReportResVoPage.getTotal(), payApplyReportResVoPage.getPages()
+                , payApplyReportResVoPage.getRecords());
+    }
+
+    @Override
+    public String exportPayApplyUserReportData(PayApplyUserReportReqVo reqDto) {
+        List<PayApplyUserReportResVo> payApplyUserReportResVoList = reportInsurancePolicyMapper.queryPayApplyUserReportData(reqDto);
+        payApplyUserReportResVoList.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());
+                }
+            }
+        });
+        return EasyExcelUtils.downExcel(uploadFilePath, PayApplyUserReportResVo.class, payApplyUserReportResVoList);
+    }
     @Override
-    public HttpResult<String> exportPayApplyUserReportData(PayApplyUserReportReqVo reqDto) {
+    public String exportDrilPayApplyUserReportData(PayApplyUserReportReqVo reqDto) {
+        //返回上层时 调整查询条件
+        if(StringUtils.isNotEmpty(reqDto.getIsReturnBack())&&"1".equals(reqDto.getIsReturnBack())){
+            if(StringUtils.isNotEmpty(reqDto.getTeamCode())) {
+                reqDto.setDeptId(reqDto.getTeamCode());
+            }
+            reqDto.setDrilType("2");
+            //如果是机构返回上层时,需要找上级的上级去查询
+            SysDept sysDept=sysDeptService.getById(reqDto.getDeptId());
+            SysDept sysDept1=sysDeptService.getById(sysDept.getParentId());
+            if(sysDept1==null){
+                throw new SystemException("已经到最上层,不能继续返回!");
+            }
+            String flag="";
+            SysDept sysDept2=sysDeptService.getById(sysDept1.getParentId());
+            if(sysDept2==null){
+                reqDto.setDeptId(sysDept1.getId());
+                flag="X";
+            }else{
+                reqDto.setDeptId(sysDept2.getId());
+                flag=sysDept1.getComlevel();
+            }
+            reqDto.setDrilFlag(flag);
+        }else if(StringUtils.isNotEmpty(reqDto.getIsDrilling())&&"1".equals(reqDto.getIsDrilling())){
+            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())){
+                    flag=sysDept.getComlevel();
+                }else{
+                    flag="X";
+                }
+                reqDto.setDrilFlag(flag);
+            }
+        }
         List<PayApplyUserReportResVo> payApplyUserReportResVoList = reportInsurancePolicyMapper.queryPayApplyUserReportData(reqDto);
-        String s = EasyExcelUtils.downExcel(uploadFilePath, PayApplyUserReportResVo.class, payApplyUserReportResVoList);
+        payApplyUserReportResVoList.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{
+                    //不下钻到团队时,按返回机构赋值
+                    if(StringUtils.isNotEmpty(item.getInstitutionId())){
+                        item.setInstitutionId(item.getInstitutionId());
+                        SysDept sysDept=sysDeptService.getById(item.getInstitutionId());
+                        if(sysDept!=null){
+                            item.setInstitution(sysDept.getName());
+                        }
+                    }else {
+                        item.setInstitutionId(reqDto.getDeptId());
+                        SysDept sysDept=sysDeptService.getById(reqDto.getDeptId());
+                        if(sysDept!=null){
+                            item.setInstitution(sysDept.getName());
+                        }
+                    }
+
+                }
+            }
+        });
+        return EasyExcelUtils.downExcel(uploadFilePath, PayApplyUserReportResVo.class, payApplyUserReportResVoList);
+    }
+    @Override
+    public HttpResult<String> exportPayApplyUserReportListData(PayApplyUserReportReqVo reqDto) {
+        List<PayApplyUserReportListResVo> payApplyUserReportResVoList = reportInsurancePolicyMapper.queryPayApplyUserReportList(reqDto);
+        String s = EasyExcelUtils.downExcel(uploadFilePath, PayApplyUserReportListResVo.class, payApplyUserReportResVoList);
         return HttpResult.ok("", s);
     }
+
     @Override
     public BasePageResult<PayApplyDeptReportResVo> getPayApplyDeptReportData(PayApplyDeptReportReqVo reqDto) {
         Page<InsOrders> page = new Page<>(reqDto.getPageNum(), reqDto.getPageSize());

+ 405 - 40
src/main/resources/mapper/modules/report/ReportInsurancePolicyMapper.xml

@@ -755,6 +755,7 @@
 
     <resultMap id="PayApplyUserReportDataMap" type="com.ydtech.modules.report.model.vo.PayApplyUserReportResVo">
         <result property="institution" column="institution" jdbcType="VARCHAR"/>
+        <result property="institutionId" column="institutionId" jdbcType="VARCHAR"/>
         <result property="deptname" column="deptname" jdbcType="VARCHAR"/>
         <result property="username" column="username" jdbcType="VARCHAR"/>
         <result property="waitPayCostsPremiums" column="wait_pay_costs_premiums" jdbcType="DECIMAL"/>
@@ -767,10 +768,68 @@
 
 
     <select id="queryPayApplyUserReportData"  resultMap="PayApplyUserReportDataMap">
-        SELECT deptid,
-            <if test="reportReqVo.userId != null and reportReqVo.userId != ''">
-                userid,
+        SELECT
+        <!--下钻查询时拼接-->
+        <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()">
+                <!--下钻的是五级机构时,下钻到团队-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
+                    p.deptid,
+                </if>
+                <!--下钻的是四级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
+                    substr(p.deptid,1,11) institutionId,
+                </if>
+                <!--下钻的是三级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
+                    substr(p.deptid,1,8) institutionId,
+                </if>
+                <!--下钻的是二级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
+                    substr(p.deptid,1,6) institutionId,
+                </if>
+                <!--下钻的是一级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
+                    substr(p.deptid,1,4) institutionId,
+                </if>
+                <!--下钻的是总部时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
+                    substr(p.deptid,1,2) institutionId,
+                </if>
             </if>
+            <!--返回上层时-->
+            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '2'.toString()">
+                <!--返回的是五级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
+                    substr(p.deptid,1,11) institutionId,
+                </if>
+                <!--返回的是四级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
+                    substr(p.deptid,1,8) institutionId,
+                </if>
+                <!--返回的是三级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
+                    substr(p.deptid,1,6) institutionId,
+                </if>
+                <!--返回的是二级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
+                    substr(p.deptid,1,4) institutionId,
+                </if>
+                <!--返回的是一级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
+                    substr(p.deptid,1,2) institutionId,
+                </if>
+                <!--返回的是总部时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
+                    substr(p.deptid,1,1) institutionId,
+                </if>
+            </if>
+        </if>
           SUM( CASE feetype  WHEN '1'  THEN totalfee  ELSE 0  END )  AS sum_costs_premiums,
           SUM( CASE feetype  WHEN '1'  THEN paidfee  ELSE 0  END )  AS paid_costs_premiums,
           SUM( CASE feetype  WHEN '1'  THEN totalfee-paidfee  ELSE 0  END )  AS wait_pay_costs_premiums,
@@ -778,39 +837,221 @@
           SUM( CASE feetype  WHEN '2'  THEN paidfee  ELSE 0  END )  AS paid_retail_premiums,
           SUM( CASE feetype  WHEN '2'  THEN totalfee-paidfee  ELSE 0  END )  AS wait_pay_retail_premiums
         FROM report_payable_basedata  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 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>
-            </otherwise>
-        </choose>
-        <if test="reportReqVo.userId != null and reportReqVo.userId != ''">
-            and p.userId = #{reportReqVo.userId}
+            </if>
+            <!--按机构下钻时-->
+            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
+                <!--下钻的是五级机构时,下钻到团队-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
+                    and p.deptid in (SELECT id FROM `sys_dept`  WHERE parent_id= #{reportReqVo.deptId} )
+                </if>
+                <!--下钻的是四级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
+                    and substr(p.deptid,1,11) in (SELECT id FROM `sys_dept`  WHERE parent_id= #{reportReqVo.deptId} )
+                </if>
+                <!--下钻的是三级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
+                    and substr(p.deptid,1,8) in (SELECT id FROM `sys_dept`  WHERE parent_id= #{reportReqVo.deptId} )
+                </if>
+                <!--下钻的是二级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
+                    and substr(p.deptid,1,6) in (SELECT id FROM `sys_dept`  WHERE parent_id= #{reportReqVo.deptId} )
+                </if>
+                <!--下钻的是一级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
+                    and substr(p.deptid,1,4) in (SELECT id FROM `sys_dept`  WHERE parent_id= #{reportReqVo.deptId} )
+                </if>
+                <!--下钻的是总部时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
+                    and substr(p.deptid,1,2) in (SELECT id FROM `sys_dept`  WHERE parent_id= #{reportReqVo.deptId} )
+                </if>
+            </if>
+            <!--返回上层时-->
+            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '2'.toString()">
+                <!--返回的是五级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
+                    and substr(p.deptid,1,8)  = #{reportReqVo.deptId}
+                </if>
+                <!--返回的是四级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
+                    and substr(p.deptid,1,6)  = #{reportReqVo.deptId}
+                </if>
+                <!--返回的是三级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
+                    and substr(p.deptid,1,4)  = #{reportReqVo.deptId}
+                </if>
+                <!--返回的是二级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
+                    and substr(p.deptid,1,2)  = #{reportReqVo.deptId}
+                </if>
+                <!--返回的是一级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
+                    and substr(p.deptid,1,1)  = #{reportReqVo.deptId}
+                </if>
+                <!--返回的是总部时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
+                    and substr(p.deptid,1,1)  = #{reportReqVo.deptId}
+                </if>
+            </if>
+        </if>
+        <!--非下钻查询时拼接-->
+        <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.inscompany = #{reportReqVo.insCompany}
+            and p.company_id = #{reportReqVo.insCompany}
         </if>
         <if test="reportReqVo.quoteStartDate != null and reportReqVo.quoteEndDate != null">
             and p.signdate  between #{reportReqVo.quoteStartDate} AND #{reportReqVo.quoteEndDate}
         </if>
-        group by deptid
-        <if test="reportReqVo.userId != null and reportReqVo.userId != ''">
-            ,userid
+        <!--下钻查询时拼接-->
+        <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '1'.toString()">
+            <!--按团队下钻时-->
+            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '1'.toString()">
+                group by p.`username`,p.userid order by p.`username`
+            </if>
+            <!--按机构下钻时-->
+            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
+                <!--下钻的是五级机构时,下钻到团队-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
+                    group by  p.deptid  order by p.deptid
+                </if>
+                <!--下钻的是四级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
+                    group by  substr(p.deptid,1,11) order by    substr(p.deptid,1,11)
+                </if>
+                <!--下钻的是三级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
+                    group by  substr(p.deptid,1,8) order by    substr(p.deptid,1,8)
+                </if>
+                <!--下钻的是二级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
+                    group by  substr(p.deptid,1,6) order by    substr(p.deptid,1,6)
+                </if>
+                <!--下钻的是一级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
+                    group by  substr(p.deptid,1,4) order by    substr(p.deptid,1,4)
+                </if>
+                <!--下钻的是总部时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
+                    group by  substr(p.deptid,1,2) order by    substr(p.deptid,1,2)
+                </if>
+            </if>
+            <!--返回上层时-->
+            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '2'.toString()">
+                <!--返回的是五级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
+                    group by substr(p.deptid,1,11)   order by substr(p.deptid,1,11)
+                </if>
+                <!--返回的是四级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
+                    group by substr(p.deptid,1,8)   order by substr(p.deptid,1,8)
+                </if>
+                <!--返回的是三级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
+                    group by substr(p.deptid,1,6)   order by substr(p.deptid,1,6)
+                </if>
+                <!--返回的是二级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
+                    group by substr(p.deptid,1,4)   order by substr(p.deptid,1,4)
+                </if>
+                <!--返回的是一级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
+                    group by substr(p.deptid,1,2)   order by substr(p.deptid,1,2)
+                </if>
+                <!--返回的是总部时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
+                    group by substr(p.deptid,1,1)   order by substr(p.deptid,1,1)
+                </if>
+            </if>
         </if>
     </select>
     <select id="queryPayApplyUserReportDataCount" resultType="Long">
         select
         count(1)
         from (
-        SELECT deptid,
-        <if test="reportReqVo.userId != null and reportReqVo.userId != ''">
-            userid,
+        SELECT
+        <!--下钻查询时拼接-->
+        <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()">
+                <!--下钻的是五级机构时,下钻到团队-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
+                    p.deptid,
+                </if>
+                <!--下钻的是四级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
+                    substr(p.deptid,1,11) institutionId,
+                </if>
+                <!--下钻的是三级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
+                    substr(p.deptid,1,8) institutionId,
+                </if>
+                <!--下钻的是二级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
+                    substr(p.deptid,1,6) institutionId,
+                </if>
+                <!--下钻的是一级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
+                    substr(p.deptid,1,4) institutionId,
+                </if>
+                <!--下钻的是总部时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
+                    substr(p.deptid,1,2) institutionId,
+                </if>
+            </if>
+            <!--返回上层时-->
+            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '2'.toString()">
+                <!--返回的是五级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
+                    substr(p.deptid,1,11) institutionId,
+                </if>
+                <!--返回的是四级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
+                    substr(p.deptid,1,8) institutionId,
+                </if>
+                <!--返回的是三级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
+                    substr(p.deptid,1,6) institutionId,
+                </if>
+                <!--返回的是二级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
+                    substr(p.deptid,1,4) institutionId,
+                </if>
+                <!--返回的是一级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
+                    substr(p.deptid,1,2) institutionId,
+                </if>
+                <!--返回的是总部时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
+                    substr(p.deptid,1,1) institutionId,
+                </if>
+            </if>
         </if>
         SUM( CASE feetype  WHEN '1'  THEN totalfee  ELSE 0  END )  AS sum_costs_premiums,
         SUM( CASE feetype  WHEN '1'  THEN paidfee  ELSE 0  END )  AS paid_costs_premiums,
@@ -819,30 +1060,154 @@
         SUM( CASE feetype  WHEN '2'  THEN paidfee  ELSE 0  END )  AS paid_retail_premiums,
         SUM( CASE feetype  WHEN '2'  THEN totalfee-paidfee  ELSE 0  END )  AS wait_pay_retail_premiums
         FROM report_payable_basedata  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 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>
-            </otherwise>
-        </choose>
-        <if test="reportReqVo.userId != null and reportReqVo.userId != ''">
-            and p.userId = #{reportReqVo.userId}
+            </if>
+            <!--按机构下钻时-->
+            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
+                <!--下钻的是五级机构时,下钻到团队-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
+                    and p.deptid in (SELECT id FROM `sys_dept`  WHERE parent_id= #{reportReqVo.deptId} )
+                </if>
+                <!--下钻的是四级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
+                    and substr(p.deptid,1,11) in (SELECT id FROM `sys_dept`  WHERE parent_id= #{reportReqVo.deptId} )
+                </if>
+                <!--下钻的是三级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
+                    and substr(p.deptid,1,8) in (SELECT id FROM `sys_dept`  WHERE parent_id= #{reportReqVo.deptId} )
+                </if>
+                <!--下钻的是二级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
+                    and substr(p.deptid,1,6) in (SELECT id FROM `sys_dept`  WHERE parent_id= #{reportReqVo.deptId} )
+                </if>
+                <!--下钻的是一级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
+                    and substr(p.deptid,1,4) in (SELECT id FROM `sys_dept`  WHERE parent_id= #{reportReqVo.deptId} )
+                </if>
+                <!--下钻的是总部时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
+                    and substr(p.deptid,1,2) in (SELECT id FROM `sys_dept`  WHERE parent_id= #{reportReqVo.deptId} )
+                </if>
+            </if>
+            <!--返回上层时-->
+            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '2'.toString()">
+                <!--返回的是五级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
+                    and substr(p.deptid,1,8)  = #{reportReqVo.deptId}
+                </if>
+                <!--返回的是四级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
+                    and substr(p.deptid,1,6)  = #{reportReqVo.deptId}
+                </if>
+                <!--返回的是三级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
+                    and substr(p.deptid,1,4)  = #{reportReqVo.deptId}
+                </if>
+                <!--返回的是二级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
+                    and substr(p.deptid,1,2)  = #{reportReqVo.deptId}
+                </if>
+                <!--返回的是一级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
+                    and substr(p.deptid,1,1)  = #{reportReqVo.deptId}
+                </if>
+                <!--返回的是总部时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
+                    and substr(p.deptid,1,1)  = #{reportReqVo.deptId}
+                </if>
+            </if>
+        </if>
+        <!--非下钻查询时拼接-->
+        <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.inscompany = #{reportReqVo.insCompany}
+            and p.company_id = #{reportReqVo.insCompany}
         </if>
         <if test="reportReqVo.quoteStartDate != null and reportReqVo.quoteEndDate != null">
             and p.signdate  between #{reportReqVo.quoteStartDate} AND #{reportReqVo.quoteEndDate}
         </if>
-        group by deptid
-        <if test="reportReqVo.userId != null and reportReqVo.userId != ''">
-            ,userid
+        <!--下钻查询时拼接-->
+        <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '1'.toString()">
+            <!--按团队下钻时-->
+            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '1'.toString()">
+                group by p.`username`,p.userid order by p.`username`
+            </if>
+            <!--按机构下钻时-->
+            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
+                <!--下钻的是五级机构时,下钻到团队-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
+                    group by  p.deptid  order by p.deptid
+                </if>
+                <!--下钻的是四级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
+                    group by  substr(p.deptid,1,11) order by    substr(p.deptid,1,11)
+                </if>
+                <!--下钻的是三级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
+                    group by  substr(p.deptid,1,8) order by    substr(p.deptid,1,8)
+                </if>
+                <!--下钻的是二级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
+                    group by  substr(p.deptid,1,6) order by    substr(p.deptid,1,6)
+                </if>
+                <!--下钻的是一级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
+                    group by  substr(p.deptid,1,4) order by    substr(p.deptid,1,4)
+                </if>
+                <!--下钻的是总部时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
+                    group by  substr(p.deptid,1,2) order by    substr(p.deptid,1,2)
+                </if>
+            </if>
+            <!--返回上层时-->
+            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '2'.toString()">
+                <!--返回的是五级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
+                    group by substr(p.deptid,1,11)   order by substr(p.deptid,1,11)
+                </if>
+                <!--返回的是四级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
+                    group by substr(p.deptid,1,8)   order by substr(p.deptid,1,8)
+                </if>
+                <!--返回的是三级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
+                    group by substr(p.deptid,1,6)   order by substr(p.deptid,1,6)
+                </if>
+                <!--返回的是二级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
+                    group by substr(p.deptid,1,4)   order by substr(p.deptid,1,4)
+                </if>
+                <!--返回的是一级机构时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
+                    group by substr(p.deptid,1,2)   order by substr(p.deptid,1,2)
+                </if>
+                <!--返回的是总部时-->
+                <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
+                    group by substr(p.deptid,1,1)   order by substr(p.deptid,1,1)
+                </if>
+            </if>
         </if>
         ) as s
     </select>