Ver Fonte

Merge remote-tracking branch 'origin/test'

y há 2 anos atrás
pai
commit
61eeea1ed2

+ 3 - 1
src/main/java/com/ydtech/modules/fnc/service/impl/InsPlySettleServiceImpl.java

@@ -301,7 +301,9 @@ public class InsPlySettleServiceImpl extends ServiceImpl<InsPlySettleMapper, Ins
 
         List<InsPlySettleReportResVo> insPlySettleReportResVoList = baseMapper.getInsPlySettleReport(insPlySettleReportReqVo);
         if(insPlySettleReportResVoList.size()==0){
-            throw new SystemException("未查询到有效数据!");
+            if(StringUtils.isNotEmpty(insPlySettleReportReqVo.getIsDrilling())&&"1".equals(insPlySettleReportReqVo.getIsDrilling())){
+                throw new SystemException("已经是最底层机构,无法继续下钻!");
+            }
         }
         insPlySettleReportResVoList.stream().forEach(item->{
             EsmInsCompany esmInsCompany =esmInsCompanyService.getById(item.getCompanyId());

+ 15 - 4
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);
     }
 
     /*--------------------------------------------------------------------------*/
@@ -253,7 +264,7 @@ public class ReportController extends BaseController {
     @PostMapping("/exportPayApplyDeptReportListData")
     @ApiOperation(value = "报表-应付统计管理费-导出清单明细")
     public HttpResult<String> exportPayApplyDeptReportListData(@RequestBody PayApplyDeptReportReqVo payApplyDeptReportReqVo) {
-        return reportService.exportPayApplyDeptReportData(payApplyDeptReportReqVo);
+        return reportService.exportPayApplyDeptReportListData(payApplyDeptReportReqVo);
 
     }
 }

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

@@ -29,11 +29,15 @@ 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);
 
     List<PayApplyDeptReportResVo> queryPayApplyDeptReportData(@Param("reportReqVo") PayApplyDeptReportReqVo reqVo);
 
+    List<PayApplyDeptReportListResVo> exportPayApplyDeptReportListData(@Param("reportReqVo") PayApplyDeptReportReqVo reqVo);
+
     Long queryPayApplyDeptReportDataCount(@Param("reportReqVo") PayApplyDeptReportReqVo reqVo);
 }

+ 57 - 0
src/main/java/com/ydtech/modules/report/model/vo/PayApplyDeptReportListResVo.java

@@ -0,0 +1,57 @@
+package com.ydtech.modules.report.model.vo;
+
+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;
+
+@Data
+@TableName(autoResultMap = true)
+public class PayApplyDeptReportListResVo {
+    @ExcelProperty(value = "订单号")
+    @TableField("orderno")
+    private String orderno;
+    @ExcelProperty(value = "保单号")
+    @TableField("policyno")
+    private String policyno;
+    @ExcelProperty(value = "险种")
+    @TableField("riskcode")
+    private String riskcode;
+    @ExcelProperty(value = "车牌")
+    @TableField("licenseno")
+    private String licenseno;
+    @ExcelProperty(value = "机构等级")
+    @TableField("comlevel")
+    private String comlevel;
+
+    @ExcelProperty(value = "机构代码")
+    @TableField("comcode")
+    private String comcode;
+    @ExcelProperty(value = "管理费比例")
+    @TableField("keeprate")
+    private double keeprate;
+    @ExcelProperty(value = "追加费比例")
+    @TableField("addrate")
+    private double addrate;
+    @ExcelProperty(value = "管理费金额")
+    @TableField("keepamount")
+    private double keepamount;
+    @ExcelProperty(value = "追加费金额")
+    @TableField("addamount")
+    private double addamount;
+    @ExcelProperty(value = "审核状态")
+    @TableField("auditstatus")
+    private String auditstatus;
+    @ExcelProperty(value = "结算状态")
+    @TableField("settlestatus")
+    private String settlestatus;
+    @ExcelProperty(value = "保险公司")
+    @TableField("inscompany")
+    private String inscompany;
+    @ExcelProperty(value = "签单日期")
+    @TableField("signDate")
+    private String signDate;
+
+}

+ 4 - 3
src/main/java/com/ydtech/modules/report/model/vo/PayApplyDeptReportReqVo.java

@@ -7,6 +7,7 @@ import lombok.Data;
 import javax.validation.constraints.Max;
 import javax.validation.constraints.Min;
 import java.time.LocalDate;
+import java.util.List;
 
 /**
  * @Author: CXP
@@ -39,9 +40,9 @@ public class PayApplyDeptReportReqVo {
     @Min(value = 1, message = "页数最小为1")
     private int pageNum;
 
-    @ApiModelProperty(value = "是否下钻查询  1 下钻 0非下钻查询")
+    @ApiModelProperty(value = "是否下钻查询  1 下钻  0 正常查询  2 返回上层")
     private String isDrilling;
 
-    @ApiModelProperty(value = "是否返回上层  1 返回上层 0非返回上层")
-    private String isReturnBack;
+    @ApiModelProperty(value = "需要分组的保险公司列表")
+    private List<String> groupInsCompanyArr;
 }

+ 4 - 35
src/main/java/com/ydtech/modules/report/model/vo/PayApplyDeptReportResVo.java

@@ -18,56 +18,25 @@ public class PayApplyDeptReportResVo {
     @TableField(value = "institution")
     private String institution;
 
-    @ExcelProperty(value = "团队名称")
-    @TableField(value = "deptname")
-    private String deptname;
-
-    @ExcelProperty(value = "业务员名称")
-    @TableField(value = "username")
-    private String username;
-
-    @ExcelProperty(value = "待付手续费")
+    @ExcelProperty(value = "待付管理费")
     @TableField(value = "wait_pay_costs_premiums")
     private BigDecimal waitPayCostsPremiums;
 
 
-    @ExcelProperty(value = "已付手续费")
+    @ExcelProperty(value = "已付管理费")
     @TableField(value = "paid_costs_premiums")
     private BigDecimal paidCostsPremiums;
 
 
-    @ExcelProperty(value = "手续费合计")
+    @ExcelProperty(value = "管理费合计")
     @TableField(value = "sum_costs_premiums")
     private BigDecimal sumCostsPremiums;
 
-
-    @ExcelProperty(value = "待付分销费")
-    @TableField(value = "wait_pay_retail_premiums")
-    private BigDecimal waitPayRetailPremiums;
-
-    @ExcelProperty(value = "已付分销费")
-    @TableField(value = "paid_retail_premiums")
-    private BigDecimal paidRetailPremiums;
-
-
-    @ExcelProperty(value = "总分销费")
-    @TableField(value = "sum_retail_premiums")
-    private BigDecimal sumRetailPremiums;
-
     /**
      * 机构Id
      */
     @ExcelIgnore
     private String institutionId;
-    /**
-     * 团队Id
-     */
-    @ExcelIgnore
-    private String deptId;
-    /**
-     * 人员Id
-     */
-    @ExcelIgnore
-    private String userId;
+
 
 }

+ 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

+ 28 - 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) ;
 
     /**
      * 分页获取应付管理费统计清单数据
@@ -151,4 +171,11 @@ public interface ReportService {
      * @return
      */
     public HttpResult<String> exportPayApplyDeptReportData(PayApplyDeptReportReqVo reqDto);
+
+    /**
+     * 报表-应付统计管理费-导出清单
+     * @param payApplyDeptReportReqVo
+     * @return
+     */
+    public HttpResult<String> exportPayApplyDeptReportListData(PayApplyDeptReportReqVo payApplyDeptReportReqVo);
 }

+ 329 - 3
src/main/java/com/ydtech/modules/report/service/impl/ReportServiceImpl.java

@@ -2,6 +2,7 @@ package com.ydtech.modules.report.service.impl;
 
 import cn.afterturn.easypoi.excel.entity.ExportParams;
 import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.github.pagehelper.PageHelper;
 import com.ydtech.aop.exception.DescribeException;
@@ -12,6 +13,7 @@ import com.ydtech.modules.admin.model.SysDept;
 import com.ydtech.modules.admin.model.SysUser;
 import com.ydtech.modules.admin.service.SysDeptService;
 import com.ydtech.modules.admin.service.SysUserService;
+import com.ydtech.modules.esm.model.EsmInsCompany;
 import com.ydtech.modules.ins.utils.ExcelStyleLeftUtil;
 import com.ydtech.modules.ins.utils.ExcelStyleUtil;
 import com.ydtech.modules.ins.utils.ExcelUtils2;
@@ -1176,25 +1178,283 @@ 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());
         page.setSearchCount(false).setOptimizeCountSql(false);//关闭count查询
+        List<String> comStr=new ArrayList<>();
+        if(StringUtils.isNotEmpty(reqDto.getIsDrilling())&&"1".equals(reqDto.getIsDrilling())){//下钻时查询下级所有机构
+            LambdaQueryWrapper<SysDept> lqw1 = new LambdaQueryWrapper<>();
+            lqw1.eq(SysDept::getParentId, reqDto.getDeptId());
+            List<SysDept> sysDeptList=sysDeptService.list(lqw1);
+            if(sysDeptList!=null&&sysDeptList.size()>0){
+                sysDeptList.stream().forEach(item->{
+                    comStr.add(item.getId());
+                });
+            }else{
+                throw new SystemException("已经到最底层,不能继续下钻!");
+            }
+        }else if(StringUtils.isNotEmpty(reqDto.getIsDrilling())&&"2".equals(reqDto.getIsDrilling())){//返回时 查询上级的上级的所有下级
+            SysDept sysDept1=sysDeptService.getById(reqDto.getDeptId());
+            if("1".equals(sysDept1.getComlevel())||"0".equals(sysDept1.getComlevel())){
+                throw new SystemException("已经到最顶层,不能继续返回!");
+            }else if("2".equals(sysDept1.getComlevel())){//如果是二级 往上找一级
+                SysDept sysDept2=sysDeptService.getById(sysDept1.getParentId());
+                comStr.add(sysDept2.getId());
+            }else{//找上级的上级的所有下级
+                SysDept sysDept2=sysDeptService.getById(sysDept1.getParentId());
+                SysDept sysDept3=sysDeptService.getById(sysDept2.getParentId());
+                LambdaQueryWrapper<SysDept> lqw1 = new LambdaQueryWrapper<>();
+                lqw1.eq(SysDept::getParentId, sysDept3.getId());
+                List<SysDept> sysDeptList=sysDeptService.list(lqw1);
+                if(sysDeptList!=null&&sysDeptList.size()>0){
+                    sysDeptList.stream().forEach(item->{
+                        comStr.add(item.getId());
+                    });
+                }else{
+                    throw new SystemException("机构数据有误,请联系管理员!");
+                }
+            }
+        }else{//正常查询时
+            comStr.add(reqDto.getDeptId());
+        }
+        reqDto.setGroupInsCompanyArr(comStr);
         Page<PayApplyDeptReportResVo> payApplyDeptReportResVoPage = reportInsurancePolicyMapper.queryPayApplyDeptReportData(page,
                 reqDto);
+
+        if(payApplyDeptReportResVoPage.getRecords().size()==0){
+            if(StringUtils.isNotEmpty(reqDto.getIsDrilling())&&"1".equals(reqDto.getIsDrilling())){
+                throw new SystemException("已经是最底层机构,无法继续下钻!");
+            }
+        }
+        payApplyDeptReportResVoPage.getRecords().stream().forEach(item->{
+            SysDept sysDept1=sysDeptService.getById(item.getInstitutionId());
+            item.setInstitution(sysDept1.getName());
+        });
         Long total = reportInsurancePolicyMapper.queryPayApplyDeptReportDataCount(reqDto);
         payApplyDeptReportResVoPage.setTotal(total);
         return new BasePageResult<>(reqDto.getPageNum(), reqDto.getPageSize(),
@@ -1204,8 +1464,74 @@ public class ReportServiceImpl implements ReportService {
 
     @Override
     public HttpResult<String> exportPayApplyDeptReportData(PayApplyDeptReportReqVo reqDto) {
+        List<String> comStr=new ArrayList<>();
+        if(StringUtils.isNotEmpty(reqDto.getIsDrilling())&&"1".equals(reqDto.getIsDrilling())){//下钻时查询下级所有机构
+            LambdaQueryWrapper<SysDept> lqw1 = new LambdaQueryWrapper<>();
+            lqw1.eq(SysDept::getParentId, reqDto.getDeptId());
+            List<SysDept> sysDeptList=sysDeptService.list(lqw1);
+            if(sysDeptList!=null&&sysDeptList.size()>0){
+                sysDeptList.stream().forEach(item->{
+                    comStr.add(item.getId());
+                });
+            }else{
+                throw new SystemException("已经到最底层,不能继续下钻!");
+            }
+        }else if(StringUtils.isNotEmpty(reqDto.getIsDrilling())&&"2".equals(reqDto.getIsDrilling())){//返回时 查询上级的上级的所有下级
+            SysDept sysDept1=sysDeptService.getById(reqDto.getDeptId());
+            if("1".equals(sysDept1.getComlevel())||"0".equals(sysDept1.getComlevel())){
+                throw new SystemException("已经到最顶层,不能继续返回!");
+            }else if("2".equals(sysDept1.getComlevel())){//如果是二级 往上找一级
+                SysDept sysDept2=sysDeptService.getById(sysDept1.getParentId());
+                comStr.add(sysDept2.getId());
+            }else{//找上级的上级的所有下级
+                SysDept sysDept2=sysDeptService.getById(sysDept1.getParentId());
+                SysDept sysDept3=sysDeptService.getById(sysDept2.getParentId());
+                LambdaQueryWrapper<SysDept> lqw1 = new LambdaQueryWrapper<>();
+                lqw1.eq(SysDept::getParentId, sysDept3.getId());
+                List<SysDept> sysDeptList=sysDeptService.list(lqw1);
+                if(sysDeptList!=null&&sysDeptList.size()>0){
+                    sysDeptList.stream().forEach(item->{
+                        comStr.add(item.getId());
+                    });
+                }else{
+                    throw new SystemException("机构数据有误,请联系管理员!");
+                }
+            }
+        }else{//正常查询时
+            comStr.add(reqDto.getDeptId());
+        }
+        reqDto.setGroupInsCompanyArr(comStr);
         List<PayApplyDeptReportResVo> payApplyUserReportResVoList = reportInsurancePolicyMapper.queryPayApplyDeptReportData(reqDto);
-        String s = EasyExcelUtils.downExcel(uploadFilePath, PayApplyUserReportResVo.class, payApplyUserReportResVoList);
+        if(payApplyUserReportResVoList.size()==0){
+            if(StringUtils.isNotEmpty(reqDto.getIsDrilling())&&"1".equals(reqDto.getIsDrilling())){
+                throw new SystemException("已经是最底层机构,无法继续下钻!");
+            }
+        }
+        payApplyUserReportResVoList.stream().forEach(item->{
+            SysDept sysDept1=sysDeptService.getById(item.getInstitutionId());
+            item.setInstitution(sysDept1.getName());
+        });
+        String s = EasyExcelUtils.downExcel(uploadFilePath, PayApplyDeptReportResVo.class, payApplyUserReportResVoList);
+        return HttpResult.ok("", s);
+    }
+
+
+    @Override
+    public HttpResult<String> exportPayApplyDeptReportListData(PayApplyDeptReportReqVo payApplyDeptReportReqVo) {
+        List<PayApplyDeptReportListResVo> payApplyDeptReportListData = reportInsurancePolicyMapper.exportPayApplyDeptReportListData(payApplyDeptReportReqVo);
+        payApplyDeptReportListData.stream().forEach(item->{
+            if("0".equals(item.getAuditstatus())){
+                item.setAuditstatus("未审核");
+            }else if("1".equals(item.getAuditstatus())){
+                item.setAuditstatus("已审核");
+            }
+            if ("0".equals(item.getSettlestatus())){
+                item.setSettlestatus("未结算");
+            }else if("1".equals(item.getSettlestatus())){
+                item.setSettlestatus("已结算");
+            }
+        });
+        String s = EasyExcelUtils.downExcel(uploadFilePath, PayApplyDeptReportListResVo.class, payApplyDeptReportListData);
         return HttpResult.ok("", s);
     }
 }

+ 487 - 64
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>
@@ -893,38 +1258,96 @@
     </select>
     <!--===========================================分割线=======报表管理费=================================================-->
     <resultMap id="PayApplyDeptReportDataMap" type="com.ydtech.modules.report.model.vo.PayApplyDeptReportResVo">
-        <result property="institution" column="institution" jdbcType="VARCHAR"/>
-        <result property="deptname" column="deptname" jdbcType="VARCHAR"/>
-        <result property="username" column="username" jdbcType="VARCHAR"/>
+        <result property="institutionId" column="institutionId" jdbcType="VARCHAR"/>
         <result property="waitPayCostsPremiums" column="wait_pay_costs_premiums" jdbcType="DECIMAL"/>
         <result property="paidCostsPremiums" column="paid_costs_premiums" jdbcType="DECIMAL"/>
         <result property="sumCostsPremiums" column="sum_costs_premiums" jdbcType="DECIMAL"/>
-        <result property="waitPayRetailPremiums" column="wait_pay_retail_premiums" jdbcType="DECIMAL"/>
-        <result property="paidRetailPremiums" column="paid_retail_premiums" jdbcType="DECIMAL"/>
-        <result property="sumRetailPremiums" column="sum_retail_premiums" jdbcType="DECIMAL"/>
     </resultMap>
     <select id="queryPayApplyDeptReportData"  resultMap="PayApplyDeptReportDataMap">
-        SELECT
-        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_payable_basedata p WHERE 1=1
+        SELECT comcode as institutionId,
+        sum( t.keepamount + t.addamount ) AS sum_costs_premiums,
+        sum( CASE WHEN settlestatus = '1' THEN t.keepamount + t.addamount ELSE 0 END ) AS paid_costs_premiums ,
+        sum( t.keepamount + t.addamount ) - sum( CASE WHEN settlestatus = '1' THEN t.keepamount + t.addamount ELSE 0 END ) as wait_pay_costs_premiums
+        FROM ins_deptfee  t WHERE 1=1
+        <if test="reportReqVo.groupInsCompanyArr != null and reportReqVo.groupInsCompanyArr != ''">
+            and t.comcode in
+            <foreach collection="reportReqVo.groupInsCompanyArr" item="comcode" open="("
+                     separator=","  close=")">
+                      #{comcode}
+            </foreach>
+        </if>
+        <if test="reportReqVo.insCompany != null and reportReqVo.insCompany != ''">
+            and t.inscompany = #{reportReqVo.insCompany}
+        </if>
+        <if test="reportReqVo.quoteStartDate != null and reportReqVo.quoteEndDate != null">
+            and t.signdate  between #{reportReqVo.quoteStartDate} AND #{reportReqVo.quoteEndDate}
+        </if>
+        group by comcode
     </select>
     <select id="queryPayApplyDeptReportDataCount" resultType="Long">
-        select
-        count(1)
-        from (
+        select count(1) from (
+        SELECT comcode as institutionId,
+        sum( t.keepamount + t.addamount ) AS sum_costs_premiums,
+        sum( CASE WHEN settlestatus = '1' THEN t.keepamount + t.addamount ELSE 0 END ) AS paid_costs_premiums ,
+        sum( t.keepamount + t.addamount ) - sum( CASE WHEN settlestatus = '1' THEN t.keepamount + t.addamount ELSE 0 END ) as wait_pay_costs_premiums
+        FROM ins_deptfee  t WHERE 1=1
+        <if test="reportReqVo.groupInsCompanyArr != null and reportReqVo.groupInsCompanyArr != ''">
+            and t.comcode in
+            <foreach collection="reportReqVo.groupInsCompanyArr" item="comcode" open="("
+                     separator=","  close=")">
+                #{comcode}
+            </foreach>
+        </if>
+        <if test="reportReqVo.insCompany != null and reportReqVo.insCompany != ''">
+            and t.inscompany = #{reportReqVo.insCompany}
+        </if>
+        <if test="reportReqVo.quoteStartDate != null and reportReqVo.quoteEndDate != null">
+            and t.signdate  between #{reportReqVo.quoteStartDate} AND #{reportReqVo.quoteEndDate}
+        </if>
+        group by comcode
+        ) as s
+    </select>
+
+    <resultMap id="PayApplyDeptReportListResMap" type="com.ydtech.modules.report.model.vo.PayApplyDeptReportListResVo">
+        <result column="orderno" property="orderno" />
+        <result column="policyno" property="policyno" />
+        <result column="riskcode" property="riskcode" />
+        <result column="licenseno" property="licenseno" />
+        <result column="comlevel" property="comlevel" />
+        <result column="comcode" property="comcode" />
+        <result column="keeprate" property="keeprate" />
+        <result column="addrate" property="addrate" />
+        <result column="keepamount" property="keepamount" />
+        <result column="addamount" property="addamount" />
+        <result column="auditstatus" property="auditstatus" />
+        <result column="settlestatus" property="settlestatus" />
+        <result column="inscompany" property="inscompany" />
+        <result column="signDate" property="signDate" />
+    </resultMap>
+
+    <select id="exportPayApplyDeptReportListData" resultMap="PayApplyDeptReportListResMap">
         SELECT
-        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
+        p.orderno,
+        p.policyno,
+        p.riskcode,
+        p.licenseno,
+        p.comlevel,
+        p.comcode,
+        p.keeprate,
+        p.addrate,
+        p.keepamount,
+        p.addamount,
+        p.auditstatus,
+        p.settlestatus,
+        p.inscompany,
+        p.signDate
         FROM
-        report_payable_basedata p WHERE 1=1
-        ) as s
+        ins_deptfee p WHERE 1=1
+        <if test="reportReqVo.deptId != null and reportReqVo.deptId != ''">
+            and p.comcode = #{reportReqVo.deptId}
+        </if>
+        <if test="reportReqVo.insCompany != null and reportReqVo.insCompany != ''">
+            and p.inscompany = #{reportReqVo.insCompany}
+        </if>
     </select>
 </mapper>