소스 검색

报表应收统计

li.pengfei 2 년 전
부모
커밋
9e66a3ea2e

+ 7 - 0
src/main/java/com/ydtech/modules/esm/service/EsmInsCompanyService.java

@@ -59,6 +59,13 @@ public interface EsmInsCompanyService extends IService<EsmInsCompany> {
      * @return
      */
     List<String> getAllRelationCompanyId(String companyId);
+
+    /**
+     * 获取指定保险公司的下一级保司列表,入参为空时,直接返回顶层保司
+     * @param companyId
+     * @return
+     */
+    List<String> getInsCompanyNextLevel(String companyId);
 }
 
 

+ 19 - 0
src/main/java/com/ydtech/modules/esm/service/impl/EsmInsCompanyServiceImpl.java

@@ -146,6 +146,25 @@ public class EsmInsCompanyServiceImpl extends ServiceImpl<EsmInsCompanyMapper, E
         }
         return result;
     }
+
+    @Override
+    public List<String> getInsCompanyNextLevel(String companyId){
+        List<String> result=new ArrayList<>();
+        LambdaQueryWrapper<EsmInsCompany> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(EsmInsCompany::getType,"1");
+        if(StringUtils.isNotEmpty(companyId)){
+            //不为空时,需要找选定机构的下一层
+            wrapper.eq(EsmInsCompany::getParentId,companyId);
+        }else{
+            //为空时,直接查询顶层保险公司机构  parentid=0
+            wrapper.eq(EsmInsCompany::getParentId,"0");
+        }
+        List<EsmInsCompany> allList = list(wrapper);
+        allList.forEach(item -> {
+             result.add(item.getId());
+        });
+        return result;
+    }
 }
 
 

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

@@ -7,7 +7,10 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.ydtech.core.page.HttpResult;
+import com.ydtech.exception.SystemException;
 import com.ydtech.modules.admin.model.SysUser;
+import com.ydtech.modules.esm.model.EsmInsCompany;
+import com.ydtech.modules.esm.service.EsmInsCompanyService;
 import com.ydtech.modules.fnc.dao.InsPlyIncomeMapper;
 import com.ydtech.modules.fnc.dao.InsPlySettleDetailMapper;
 import com.ydtech.modules.fnc.dao.InsPlySettleHxMapper;
@@ -40,6 +43,7 @@ import java.sql.Wrapper;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.YearMonth;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
@@ -62,7 +66,8 @@ public class InsPlySettleServiceImpl extends ServiceImpl<InsPlySettleMapper, Ins
     private InsPlyIncomeMapper insPlyIncomeMapper;
     @Autowired
     private InsPlySettleHxMapper insPlySettleHxMapper;
-
+    @Autowired
+    private EsmInsCompanyService esmInsCompanyService;
 
     @Override
     @Transactional
@@ -211,8 +216,52 @@ public class InsPlySettleServiceImpl extends ServiceImpl<InsPlySettleMapper, Ins
     public BasePageResult<InsPlySettleReportResVo> getInsPlySettleReport( InsPlySettleReportReqVo insPlySettleReportReqVo) {
         Page<InsOrders> page = new Page<>(insPlySettleReportReqVo.getPageNum(), insPlySettleReportReqVo.getPageSize());
         page.setSearchCount(false).setOptimizeCountSql(false);//关闭count查询
+        if(StringUtils.isNotEmpty(insPlySettleReportReqVo.getIsReturnBack())&&"1".equals(insPlySettleReportReqVo.getIsReturnBack())){
+            //如果是返回上级时,找上级的上级往下找
+            LambdaQueryWrapper<EsmInsCompany> lqw1 = new LambdaQueryWrapper<>();
+            lqw1.eq(EsmInsCompany::getId, insPlySettleReportReqVo.getCompanyId());
+            EsmInsCompany esmInsCompany1=esmInsCompanyService.getOne(lqw1);
+            if(esmInsCompany1==null){
+                throw new SystemException("已经是最顶层机构,无法继续返回!");
+            }
+            LambdaQueryWrapper<EsmInsCompany> lqw2 = new LambdaQueryWrapper<>();
+            lqw2.eq(EsmInsCompany::getId, esmInsCompany1.getParentId());
+            EsmInsCompany esmInsCompany2=esmInsCompanyService.getOne(lqw2);
+            if(esmInsCompany2==null){
+                insPlySettleReportReqVo.setCompanyId(esmInsCompany1.getParentId());
+            }else{
+                insPlySettleReportReqVo.setCompanyId(esmInsCompany2.getParentId());
+            }
+        }
+
+        //正常查询,下钻查询时调整
+        List<String> companyArr=esmInsCompanyService.getInsCompanyNextLevel(insPlySettleReportReqVo.getCompanyId());
+        if(!(companyArr!=null&&companyArr.size()>0)){
+            throw new SystemException("已经是最底层机构,无法继续下钻!");
+        }
+        insPlySettleReportReqVo.setGroupInsCompanyArr(companyArr);
+
         Page<InsPlySettleReportResVo> policyInsuranceReportResVoPage = baseMapper.getInsPlySettleReport(page,
                 insPlySettleReportReqVo);
+        if(policyInsuranceReportResVoPage.getRecords().size()==0){
+            throw new SystemException("未查询到有效数据!");
+        }
+        policyInsuranceReportResVoPage.getRecords().stream().forEach(item->{
+            EsmInsCompany esmInsCompany =esmInsCompanyService.getById(item.getCompanyId());
+            item.setCompanyName(esmInsCompany.getName());
+            if(StringUtils.isEmpty(item.getStatus())){
+                item.setStatus("全部");
+            }else{
+                if("0".equals(item.getStatus())){
+                    item.setStatus("未核销");
+                }else if("1".equals(item.getStatus())){
+                    item.setStatus("部分核销");
+                }else if ("2".equals(item.getStatus())){
+                    item.setStatus("已核销");
+                }
+            }
+        });
+
         Long total = baseMapper.getInsPlySettleReportCount(insPlySettleReportReqVo);
         policyInsuranceReportResVoPage.setTotal(total);
         return new BasePageResult<>(insPlySettleReportReqVo.getPageNum(), insPlySettleReportReqVo.getPageSize(),
@@ -222,7 +271,50 @@ public class InsPlySettleServiceImpl extends ServiceImpl<InsPlySettleMapper, Ins
 
     @Override
     public HttpResult<String> exportInsPlySettleReport(InsPlySettleReportReqVo insPlySettleReportReqVo) {
+        if(StringUtils.isNotEmpty(insPlySettleReportReqVo.getIsReturnBack())&&"1".equals(insPlySettleReportReqVo.getIsReturnBack())){
+            //如果是返回上级时,找上级的上级往下找
+            LambdaQueryWrapper<EsmInsCompany> lqw1 = new LambdaQueryWrapper<>();
+            lqw1.eq(EsmInsCompany::getId, insPlySettleReportReqVo.getCompanyId());
+            EsmInsCompany esmInsCompany1=esmInsCompanyService.getOne(lqw1);
+            if(esmInsCompany1==null){
+                throw new SystemException("已经是最顶层机构,无法继续返回!");
+            }
+            LambdaQueryWrapper<EsmInsCompany> lqw2 = new LambdaQueryWrapper<>();
+            lqw2.eq(EsmInsCompany::getId, esmInsCompany1.getParentId());
+            EsmInsCompany esmInsCompany2=esmInsCompanyService.getOne(lqw2);
+            if(esmInsCompany2==null){
+                insPlySettleReportReqVo.setCompanyId(esmInsCompany1.getParentId());
+            }else{
+                insPlySettleReportReqVo.setCompanyId(esmInsCompany2.getParentId());
+            }
+        }
+
+        //正常查询,下钻查询时调整
+        List<String> companyArr=esmInsCompanyService.getInsCompanyNextLevel(insPlySettleReportReqVo.getCompanyId());
+        if(!(companyArr!=null&&companyArr.size()>0)){
+            throw new SystemException("已经是最底层机构,无法继续下钻!");
+        }
+        insPlySettleReportReqVo.setGroupInsCompanyArr(companyArr);
+
         List<InsPlySettleReportResVo> insPlySettleReportResVoList = baseMapper.getInsPlySettleReport(insPlySettleReportReqVo);
+        if(insPlySettleReportResVoList.size()==0){
+            throw new SystemException("未查询到有效数据!");
+        }
+        insPlySettleReportResVoList.stream().forEach(item->{
+            EsmInsCompany esmInsCompany =esmInsCompanyService.getById(item.getCompanyId());
+            item.setCompanyName(esmInsCompany.getName());
+            if(StringUtils.isEmpty(item.getStatus())){
+                item.setStatus("全部");
+            }else{
+                if("0".equals(item.getStatus())){
+                    item.setStatus("未核销");
+                }else if("1".equals(item.getStatus())){
+                    item.setStatus("部分核销");
+                }else if ("2".equals(item.getStatus())){
+                    item.setStatus("已核销");
+                }
+            }
+        });
         String s = EasyExcelUtils.downExcel(uploadFilePath, InsPlySettleReportResVo.class, insPlySettleReportResVoList);
         return HttpResult.ok("", s);
     }

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

@@ -8,6 +8,7 @@ import javax.validation.constraints.Max;
 import javax.validation.constraints.Min;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.util.List;
 
 /**
  * @Author: CXP
@@ -38,4 +39,10 @@ public class InsPlySettleReportReqVo {
     @ApiModelProperty(value = "页数")
     @Min(value = 1, message = "页数最小为1")
     private int pageNum;
+
+    @ApiModelProperty(value = "需要分组的保险公司列表")
+    private List<String> groupInsCompanyArr;
+
+    @ApiModelProperty(value = "是否返回上层  1 返回上层 0非返回上层")
+    private String isReturnBack;
 }

+ 5 - 1
src/main/java/com/ydtech/modules/report/model/vo/InsPlySettleReportResVo.java

@@ -1,5 +1,6 @@
 package com.ydtech.modules.report.model.vo;
 
+import com.alibaba.excel.annotation.ExcelIgnore;
 import com.alibaba.excel.annotation.ExcelProperty;
 import com.baomidou.mybatisplus.annotation.TableField;
 import io.swagger.annotations.ApiModelProperty;
@@ -15,7 +16,6 @@ import java.time.LocalDateTime;
 @Data
 public class InsPlySettleReportResVo {
 
-    @TableField(value = "company_name")
     @ExcelProperty(value = "保险公司")
     private String companyName;
 
@@ -38,4 +38,8 @@ public class InsPlySettleReportResVo {
     @TableField(value = "status")
     @ExcelProperty(value = "账单状态")
     private String status;
+
+    @ExcelIgnore
+    @TableField(value = "company_id")
+    private String companyId;
 }

+ 47 - 51
src/main/resources/mapper/modules/fnc/InsPlySettleMapper.xml

@@ -20,7 +20,7 @@
     </resultMap>
 
     <resultMap id="SettleReportDataMap" type="com.ydtech.modules.report.model.vo.InsPlySettleReportResVo">
-        <result property="companyName" column="company_name" jdbcType="VARCHAR"/>
+        <result property="companyId" column="company_id" jdbcType="VARCHAR"/>
         <result property="settleMonth" column="settle_month" jdbcType="VARCHAR"/>
         <result property="commissionFeevalue" column="commission_feevalue" jdbcType="DECIMAL"/>
         <result property="otherFeevalue" column="other_feevalue" jdbcType="DECIMAL"/>
@@ -29,61 +29,57 @@
     </resultMap>
 
     <select id="getInsPlySettleReport"  resultMap="SettleReportDataMap">
-        SELECT
-        ''company_name,
-        ''settle_month,
-        ''status,
-        SUM(p.`commission_feevalue`) commission_feevalue,
-        SUM(p.`other_feevalue`) other_feevalue,
-        SUM(p.`all_fee_value`) all_fee_value
-        FROM
-        ins_ply_settle p WHERE 1=1
-        <if test="reportReqVo.companyId != null and reportReqVo.companyId != ''">
-            and p.company_id = #{reportReqVo.companyId}
-        </if>
-        <if test="reportReqVo.status != null and reportReqVo.status != ''">
-            and p.status = #{reportReqVo.status}
-        </if>
-        <if test="reportReqVo.quoteStartDate != null and reportReqVo.quoteEndDate != null">
-            and p.create_time  between #{reportReqVo.quoteStartDate} AND #{reportReqVo.quoteEndDate}
-        </if>
-        GROUP BY p.`settle_month`
-        <if test="reportReqVo.companyId != null and reportReqVo.companyId != ''">
-            ,p.company_id
-        </if>
-        <if test="reportReqVo.status != null and reportReqVo.status != ''">
-            ,p.status
-        </if>
+        <foreach collection="reportReqVo.groupInsCompanyArr" item="id"
+                 separator=" union all " >
+
+            SELECT
+            #{id} company_id,
+            settle_month,
+            #{reportReqVo.status} status,
+            SUM(p.`commission_feevalue`) commission_feevalue,
+            SUM(p.`other_feevalue`) other_feevalue,
+            SUM(p.`all_fee_value`) all_fee_value
+            FROM
+            ins_ply_settle p WHERE
+            p.company_id in (select id from esm_ins_company  where FIND_IN_SET(id,get_child_list(#{id})))
+            <if test="reportReqVo.status != null and reportReqVo.status != ''">
+                and p.status = #{reportReqVo.status}
+            </if>
+            <if test="reportReqVo.quoteStartDate != null and reportReqVo.quoteEndDate != null">
+                and p.create_time  between #{reportReqVo.quoteStartDate} AND #{reportReqVo.quoteEndDate}
+            </if>
+            GROUP BY p.`settle_month`
+
+        </foreach>
+
+
     </select>
     <select id="getInsPlySettleReportCount" resultType="Long">
         select
         count(1)
         from (
-        SELECT
-        ''company_name,
-        ''settle_month,
-        ''status,
-        SUM(p.`commission_feevalue`) commission_feevalue,
-        SUM(p.`other_feevalue`) other_feevalue,
-        SUM(p.`all_fee_value`) all_fee_value
-        FROM
-        ins_ply_settle p WHERE 1=1
-        <if test="reportReqVo.companyId != null and reportReqVo.companyId != ''">
-            and p.company_id = #{reportReqVo.companyId}
-        </if>
-        <if test="reportReqVo.status != null and reportReqVo.status != ''">
-            and p.status = #{reportReqVo.status}
-        </if>
-        <if test="reportReqVo.quoteStartDate != null and reportReqVo.quoteEndDate != null">
-            and p.create_time  between #{reportReqVo.quoteStartDate} AND #{reportReqVo.quoteEndDate}
-        </if>
-        GROUP BY p.`settle_month`
-        <if test="reportReqVo.companyId != null and reportReqVo.companyId != ''">
-            ,p.company_id
-        </if>
-        <if test="reportReqVo.status != null and reportReqVo.status != ''">
-            ,p.status
-        </if>
+        <foreach collection="reportReqVo.groupInsCompanyArr" item="id"
+                 separator=" union all " >
+
+            SELECT
+            #{id} company_id,
+            settle_month,
+            #{reportReqVo.status} status,
+            SUM(p.`commission_feevalue`) commission_feevalue,
+            SUM(p.`other_feevalue`) other_feevalue,
+            SUM(p.`all_fee_value`) all_fee_value
+            FROM
+            ins_ply_settle p WHERE
+            p.company_id in (select id from esm_ins_company  where FIND_IN_SET(id,get_child_list(#{id})))
+            <if test="reportReqVo.status != null and reportReqVo.status != ''">
+                and p.status = #{reportReqVo.status}
+            </if>
+            <if test="reportReqVo.quoteStartDate != null and reportReqVo.quoteEndDate != null">
+                and p.create_time  between #{reportReqVo.quoteStartDate} AND #{reportReqVo.quoteEndDate}
+            </if>
+            GROUP BY p.`settle_month`
+
+        </foreach>
         ) as s
     </select>
     <select id="getInsPlySettleReportList" resultMap="BaseResultMap">