Browse Source

出单量及费用统计 报表调整(调整返回上级)

li.pengfei 2 years ago
parent
commit
5185fdf285

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

@@ -40,9 +40,9 @@ public class StatisticsReportReqVo {
     private int pageNum;
     @ApiModelProperty(value = "是否下钻查询  1 下钻 0非下钻查询")
     private String isDrilling;
-    @ApiModelProperty(value = "下钻查询类型  1 团队下钻 0机构下钻")
+    @ApiModelProperty(value = "下钻查询类型  1 团队下钻 0机构下钻  2返回上层")
     private String drilType;
-    @ApiModelProperty(value = "机构下钻需要截取机构位数  2总部下钻  4一级机构下钻 6二级机构下钻  8三级机构下钻  11四级机构下钻  0五级机构下钻")
+    @ApiModelProperty(value = "机构下钻返回时 需要查询的机构层级    总部机构层级为空时,赋值为X")
     private String drilFlag;
     @ApiModelProperty(value = "是否返回上层  1 返回上层 0非返回上层")
     private String isReturnBack;

+ 40 - 132
src/main/java/com/ydtech/modules/report/service/impl/ReportServiceImpl.java

@@ -987,61 +987,26 @@ public class ReportServiceImpl implements ReportService {
         page.setSearchCount(false).setOptimizeCountSql(false);//关闭count查询
         //返回上层时 调整查询条件
         if(StringUtils.isNotEmpty(reqVo.getIsReturnBack())&&"1".equals(reqVo.getIsReturnBack())){
-            if(StringUtils.isNotEmpty(reqVo.getTeamCode())){
-                //团队不为空时,直接置为上一级  清空团队
-                reqVo.setTeamCode("");
-                reqVo.setDrilType("3");
-                //如果是机构找上层时
-                SysDept sysDept=sysDeptService.getById(reqVo.getDeptId());
-                reqVo.setDeptId(sysDept.getId());
-                //如果团队为空,则为机构下钻,查询下一级机构
-                String flag="";
-                if(StringUtils.isNotEmpty(sysDept.getComlevel())){
-                    switch (sysDept.getComlevel()){
-                        case "1":
-                            flag="2"; break;
-                        case "2":
-                            flag="4"; break;
-                        case "3":
-                            flag="6"; break;
-                        case "4":
-                            flag="8"; break;
-                        case "5":
-                            flag="11"; break;
-                    }
-                }else{
-                    flag="1";
-                }
-                reqVo.setDrilFlag(flag);
-            }else{
-                reqVo.setDrilType("3");
-                //如果是机构找上层时
-                SysDept sysDept=sysDeptService.getById(reqVo.getDeptId());
-                SysDept sysDept1=sysDeptService.getById(sysDept.getParentId());
-                if(sysDept1==null){
-                    throw new SystemException("已经到最上层,不能继续返回!");
-                }
+            if(StringUtils.isNotEmpty(reqVo.getTeamCode())) {
+                reqVo.setDeptId(reqVo.getTeamCode());
+            }
+            reqVo.setDrilType("2");
+            //如果是机构返回上层时,需要找上级的上级去查询
+            SysDept sysDept=sysDeptService.getById(reqVo.getDeptId());
+            SysDept sysDept1=sysDeptService.getById(sysDept.getParentId());
+            if(sysDept1==null){
+                throw new SystemException("已经到最上层,不能继续返回!");
+            }
+            String flag="";
+            SysDept sysDept2=sysDeptService.getById(sysDept1.getParentId());
+            if(sysDept2==null){
                 reqVo.setDeptId(sysDept1.getId());
-                //如果团队为空,则为机构下钻,查询下一级机构
-                String flag="";
-                if(StringUtils.isNotEmpty(sysDept1.getComlevel())){
-                    switch (sysDept1.getComlevel()){
-                        case "1":
-                            flag="2"; break;
-                        case "2":
-                            flag="4"; break;
-                        case "3":
-                            flag="6"; break;
-                        case "4":
-                            flag="8"; break;
-                        case "5":
-                            flag="11"; break;
-                    }
-                }else{
-                    flag="1";
-                }
-                reqVo.setDrilFlag(flag);
+                flag="X";
+            }else{
+                reqVo.setDeptId(sysDept2.getId());
+                flag=sysDept1.getComlevel();
             }
+            reqVo.setDrilFlag(flag);
         }else{
             if(StringUtils.isNotEmpty(reqVo.getTeamCode())){
                 //如果团队不为空,则为团队下钻  查询到业务员
@@ -1052,20 +1017,9 @@ public class ReportServiceImpl implements ReportService {
                 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;
-                    }
+                    flag=sysDept.getComlevel();
                 }else{
-                    flag="2";
+                    flag="X";
                 }
                 reqVo.setDrilFlag(flag);
             }
@@ -1143,61 +1097,26 @@ public class ReportServiceImpl implements ReportService {
     public String exportDrilOrderAndCostData(StatisticsReportReqVo reqDto) {
         //返回上层时 调整查询条件
         if(StringUtils.isNotEmpty(reqDto.getIsReturnBack())&&"1".equals(reqDto.getIsReturnBack())){
-            if(StringUtils.isNotEmpty(reqDto.getTeamCode())){
-                //团队不为空时,直接置为上一级  清空团队
-                reqDto.setTeamCode("");
-                reqDto.setDrilType("3");
-                //如果是机构找上层时
-                SysDept sysDept=sysDeptService.getById(reqDto.getDeptId());
-                reqDto.setDeptId(sysDept.getId());
-                //如果团队为空,则为机构下钻,查询下一级机构
-                String flag="";
-                if(StringUtils.isNotEmpty(sysDept.getComlevel())){
-                    switch (sysDept.getComlevel()){
-                        case "1":
-                            flag="2"; break;
-                        case "2":
-                            flag="4"; break;
-                        case "3":
-                            flag="6"; break;
-                        case "4":
-                            flag="8"; break;
-                        case "5":
-                            flag="11"; break;
-                    }
-                }else{
-                    flag="1";
-                }
-                reqDto.setDrilFlag(flag);
-            }else{
-                reqDto.setDrilType("3");
-                //如果是机构找上层时
-                SysDept sysDept=sysDeptService.getById(reqDto.getDeptId());
-                SysDept sysDept1=sysDeptService.getById(sysDept.getParentId());
-                if(sysDept1==null){
-                    throw new SystemException("已经到最上层,不能继续返回!");
-                }
+            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());
-                //如果团队为空,则为机构下钻,查询下一级机构
-                String flag="";
-                if(StringUtils.isNotEmpty(sysDept1.getComlevel())){
-                    switch (sysDept1.getComlevel()){
-                        case "1":
-                            flag="2"; break;
-                        case "2":
-                            flag="4"; break;
-                        case "3":
-                            flag="6"; break;
-                        case "4":
-                            flag="8"; break;
-                        case "5":
-                            flag="11"; break;
-                    }
-                }else{
-                    flag="1";
-                }
-                reqDto.setDrilFlag(flag);
+                flag="X";
+            }else{
+                reqDto.setDeptId(sysDept2.getId());
+                flag=sysDept1.getComlevel();
             }
+            reqDto.setDrilFlag(flag);
         }else{
             if(StringUtils.isNotEmpty(reqDto.getTeamCode())){
                 //如果团队不为空,则为团队下钻  查询到业务员
@@ -1208,20 +1127,9 @@ public class ReportServiceImpl implements ReportService {
                 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;
-                    }
+                    flag=sysDept.getComlevel();
                 }else{
-                    flag="2";
+                    flag="X";
                 }
                 reqDto.setDrilFlag(flag);
             }

+ 394 - 131
src/main/resources/mapper/modules/report/ReportInsurancePolicyMapper.xml

@@ -51,25 +51,59 @@
             </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 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()">
-                p.deptid,
-            </if>
-            <!--机构返回上层时-->
-            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '3'.toString()">
-                substr(p.deptid,1,#{reportReqVo.drilFlag}) institutionId,
+                <!--返回的是五级机构时-->
+                <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>
         <if test="reportReqVo.riskCode != null and reportReqVo.riskCode != ''">
             <if test="reportReqVo.riskCode!='ALL'.toString()">
@@ -93,25 +127,57 @@
             </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 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()">
-                and p.deptid = #{reportReqVo.deptId}
-            </if>
-            <!--机构返回上层时-->
-            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '3'.toString()">
-                and substr(p.deptid,1,#{reportReqVo.drilFlag})  = #{reportReqVo.deptId}
+                <!--返回的是五级机构时-->
+                <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>
         <!--非下钻查询时拼接-->
@@ -156,24 +222,57 @@
                     </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 test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
+                            ,p.deptid  order by p.deptid,p.`risk_name`
+                        </if>
+                        <!--下钻的是四级机构时-->
+                        <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
+                            ,substr(p.deptid,1,11) order by    substr(p.deptid,1,11),p.`risk_name`
+                        </if>
+                        <!--下钻的是三级机构时-->
+                        <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
+                            ,substr(p.deptid,1,8) order by    substr(p.deptid,1,8),p.`risk_name`
+                        </if>
+                        <!--下钻的是二级机构时-->
+                        <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
+                            ,substr(p.deptid,1,6) order by    substr(p.deptid,1,6),p.`risk_name`
+                        </if>
+                        <!--下钻的是一级机构时-->
+                        <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
+                            ,substr(p.deptid,1,4) order by    substr(p.deptid,1,4),p.`risk_name`
+                        </if>
+                        <!--下钻的是总部时-->
+                        <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
+                            ,substr(p.deptid,1,2) order by    substr(p.deptid,1,2),p.`risk_name`
+                        </if>
                     </if>
-                    <!--团队返回上层时-->
+                    <!--返回上层时-->
                     <if test="reportReqVo.drilType != null and reportReqVo.drilType == '2'.toString()">
-                        ,p.deptid order by p.deptid
-                    </if>
-                    <!--机构返回上层时-->
-                    <if test="reportReqVo.drilType != null and reportReqVo.drilType == '3'.toString()">
-                        ,substr(p.deptid,1,#{reportReqVo.drilFlag})   order by substr(p.deptid,1,#{reportReqVo.drilFlag})
+                        <!--返回的是五级机构时-->
+                        <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
+                            ,substr(p.deptid,1,11)   order by substr(p.deptid,1,11)
+                        </if>
+                        <!--返回的是四级机构时-->
+                        <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
+                            ,substr(p.deptid,1,8)   order by substr(p.deptid,1,8)
+                        </if>
+                        <!--返回的是三级机构时-->
+                        <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
+                            ,substr(p.deptid,1,6)   order by substr(p.deptid,1,6)
+                        </if>
+                        <!--返回的是二级机构时-->
+                        <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
+                            ,substr(p.deptid,1,4)   order by substr(p.deptid,1,4)
+                        </if>
+                        <!--返回的是一级机构时-->
+                        <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
+                            ,substr(p.deptid,1,2)   order by substr(p.deptid,1,2)
+                        </if>
+                        <!--返回的是总部时-->
+                        <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
+                            ,substr(p.deptid,1,1)   order by substr(p.deptid,1,1)
+                        </if>
                     </if>
                 </if>
             </when>
@@ -186,24 +285,57 @@
                     </if>
                     <!--按机构下钻时-->
                     <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
-                        <choose>
-                            <!--下钻的是五级机构时,下钻到团队-->
-                            <when test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '0'.toString()">
-                                group by  p.deptid  order by p.deptid
-                            </when>
-                            <!--下钻的非五级机构时,下钻到下级机构-->
-                            <otherwise>
-                                group by  substr(p.deptid,1,#{reportReqVo.drilFlag}) order by    substr(p.deptid,1,#{reportReqVo.drilFlag})
-                            </otherwise>
-                        </choose>
+                        <!--下钻的是五级机构时,下钻到团队-->
+                        <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()">
-                        group by p.deptid order by p.deptid
-                    </if>
-                    <!--机构返回上层时-->
-                    <if test="reportReqVo.drilType != null and reportReqVo.drilType == '3'.toString()">
-                        group by substr(p.deptid,1,#{reportReqVo.drilFlag})   order by substr(p.deptid,1,#{reportReqVo.drilFlag})
+                        <!--返回的是五级机构时-->
+                        <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>
             </otherwise>
@@ -226,7 +358,6 @@
         select
         count(1)
         from (
-
         SELECT
         <!--下钻查询时拼接-->
         <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '1'.toString()">
@@ -236,25 +367,59 @@
             </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 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()">
-                p.deptid,
-            </if>
-            <!--机构返回上层时-->
-            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '3'.toString()">
-                substr(p.deptid,1,#{reportReqVo.drilFlag}) institutionId,
+                <!--返回的是五级机构时-->
+                <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>
         <if test="reportReqVo.riskCode != null and reportReqVo.riskCode != ''">
             <if test="reportReqVo.riskCode!='ALL'.toString()">
@@ -278,25 +443,57 @@
             </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 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()">
-                and p.deptid = #{reportReqVo.deptId}
-            </if>
-            <!--机构返回上层时-->
-            <if test="reportReqVo.drilType != null and reportReqVo.drilType == '3'.toString()">
-                and substr(p.deptid,1,#{reportReqVo.drilFlag})  = #{reportReqVo.deptId}
+                <!--返回的是五级机构时-->
+                <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>
         <!--非下钻查询时拼接-->
@@ -341,24 +538,57 @@
                     </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 test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
+                            ,p.deptid  order by p.deptid,p.`risk_name`
+                        </if>
+                        <!--下钻的是四级机构时-->
+                        <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
+                            ,substr(p.deptid,1,11) order by    substr(p.deptid,1,11),p.`risk_name`
+                        </if>
+                        <!--下钻的是三级机构时-->
+                        <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
+                            ,substr(p.deptid,1,8) order by    substr(p.deptid,1,8),p.`risk_name`
+                        </if>
+                        <!--下钻的是二级机构时-->
+                        <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
+                            ,substr(p.deptid,1,6) order by    substr(p.deptid,1,6),p.`risk_name`
+                        </if>
+                        <!--下钻的是一级机构时-->
+                        <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
+                            ,substr(p.deptid,1,4) order by    substr(p.deptid,1,4),p.`risk_name`
+                        </if>
+                        <!--下钻的是总部时-->
+                        <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
+                            ,substr(p.deptid,1,2) order by    substr(p.deptid,1,2),p.`risk_name`
+                        </if>
                     </if>
-                    <!--团队返回上层时-->
+                    <!--返回上层时-->
                     <if test="reportReqVo.drilType != null and reportReqVo.drilType == '2'.toString()">
-                        ,p.deptid order by p.deptid
-                    </if>
-                    <!--机构返回上层时-->
-                    <if test="reportReqVo.drilType != null and reportReqVo.drilType == '3'.toString()">
-                        ,substr(p.deptid,1,#{reportReqVo.drilFlag})   order by substr(p.deptid,1,#{reportReqVo.drilFlag})
+                        <!--返回的是五级机构时-->
+                        <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
+                            ,substr(p.deptid,1,11)   order by substr(p.deptid,1,11)
+                        </if>
+                        <!--返回的是四级机构时-->
+                        <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
+                            ,substr(p.deptid,1,8)   order by substr(p.deptid,1,8)
+                        </if>
+                        <!--返回的是三级机构时-->
+                        <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
+                            ,substr(p.deptid,1,6)   order by substr(p.deptid,1,6)
+                        </if>
+                        <!--返回的是二级机构时-->
+                        <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
+                            ,substr(p.deptid,1,4)   order by substr(p.deptid,1,4)
+                        </if>
+                        <!--返回的是一级机构时-->
+                        <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
+                            ,substr(p.deptid,1,2)   order by substr(p.deptid,1,2)
+                        </if>
+                        <!--返回的是总部时-->
+                        <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
+                            ,substr(p.deptid,1,1)   order by substr(p.deptid,1,1)
+                        </if>
                     </if>
                 </if>
             </when>
@@ -371,24 +601,57 @@
                     </if>
                     <!--按机构下钻时-->
                     <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
-                        <choose>
-                            <!--下钻的是五级机构时,下钻到团队-->
-                            <when test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '0'.toString()">
-                                group by  p.deptid  order by p.deptid
-                            </when>
-                            <!--下钻的非五级机构时,下钻到下级机构-->
-                            <otherwise>
-                                group by  substr(p.deptid,1,#{reportReqVo.drilFlag}) order by    substr(p.deptid,1,#{reportReqVo.drilFlag})
-                            </otherwise>
-                        </choose>
+                        <!--下钻的是五级机构时,下钻到团队-->
+                        <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()">
-                        group by p.deptid order by p.deptid
-                    </if>
-                    <!--机构返回上层时-->
-                    <if test="reportReqVo.drilType != null and reportReqVo.drilType == '3'.toString()">
-                        group by substr(p.deptid,1,#{reportReqVo.drilFlag})   order by substr(p.deptid,1,#{reportReqVo.drilFlag})
+                        <!--返回的是五级机构时-->
+                        <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>
             </otherwise>