Browse Source

1.保险手续费结算新调整1.0

wuhp 2 years ago
parent
commit
cf1c0c3d48

+ 2 - 1
src/main/java/com/ydtech/modules/admin/controller/InsuranceHandlingSettlementMonthController.java

@@ -4,6 +4,7 @@ package com.ydtech.modules.admin.controller;
 import com.ydtech.core.page.HttpResult;
 import com.ydtech.modules.fnc.dto.InsuranceHandlingSettlementMonthDto;
 import com.ydtech.modules.fnc.entity.InsPlyIncome;
+import com.ydtech.modules.fnc.entity.InsuranceHandlingSettlementMonthEntity;
 import com.ydtech.modules.fnc.service.InsuranceHandlingSettlementMonthService;
 import com.ydtech.modules.fnc.vo.InsPlyIncomeVo;
 import com.ydtech.modules.fnc.vo.InsuranceHandlingSettlementMonthVo;
@@ -53,7 +54,7 @@ public class InsuranceHandlingSettlementMonthController {
      */
     @PostMapping("/insert")
     @ApiModelProperty(value = "新增")
-    public HttpResult<InsuranceHandlingSettlementMonthDto> insertByEntity(@RequestBody InsuranceHandlingSettlementMonthVo insuranceHandlingSettlementMonthVo) {
+    public HttpResult<InsuranceHandlingSettlementMonthDto> insertByEntity(@RequestBody InsuranceHandlingSettlementMonthEntity insuranceHandlingSettlementMonthVo) {
         return insuranceHandlingSettlementMonthService.insertByEntity(insuranceHandlingSettlementMonthVo);
     }
 

+ 6 - 0
src/main/java/com/ydtech/modules/fnc/dao/InsPlyIncomeMapper.java

@@ -4,10 +4,12 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.ydtech.modules.admin.model.report.financialReceivables.*;
 import com.ydtech.modules.admin.model.report.profitAnalysis.ProfitAnalysisDto;
 import com.ydtech.modules.admin.model.report.profitAnalysis.ProfitAnalysisQueryDto;
+import com.ydtech.modules.fnc.dto.InsuranceHandlingSettlementMonthDto;
 import com.ydtech.modules.fnc.dto.PlatformSettlementRecordDto;
 import com.ydtech.modules.fnc.entity.InsPlyIncome;
 import com.ydtech.modules.fnc.vo.InsPlyIncomeVo;
 import com.ydtech.modules.fnc.vo.InsPlySettleVo;
+import com.ydtech.modules.fnc.vo.InsuranceHandlingSettlementMonthVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
@@ -193,4 +195,8 @@ public interface InsPlyIncomeMapper extends BaseMapper<InsPlyIncome> {
 
     List<FinancialReceivablesVo> queryPrivateCar(@Param("vo") FinancialReceivablesQueryVo financialReceivablesQueryVo);
 
+    List<ProfitAnalysisDto> getProfitAnalysisQueryList(@Param("vo")  ProfitAnalysisQueryDto profitAnalysisQueryDto);
+
+    List<InsuranceHandlingSettlementMonthDto> getInvociAmount(@Param("vo") InsuranceHandlingSettlementMonthVo insuranceHandlingSettlementMonthVo);
+
 }

+ 1 - 0
src/main/java/com/ydtech/modules/fnc/dao/InsuranceHandlingSettlementMonthMapper.java

@@ -20,6 +20,7 @@ import java.util.List;
 @Mapper
 public interface InsuranceHandlingSettlementMonthMapper extends BaseMapper<InsuranceHandlingSettlementMonthEntity> {
     List<InsuranceHandlingSettlementMonthDto> queryList( @Param("vo") InsuranceHandlingSettlementMonthVo insuranceHandlingSettlementMonthVo);
+    List<InsuranceHandlingSettlementMonthDto> queryListNew( @Param("vo") InsuranceHandlingSettlementMonthVo insuranceHandlingSettlementMonthVo);
 
 
 }

+ 6 - 0
src/main/java/com/ydtech/modules/fnc/dto/InsuranceHandlingSettlementMonthDto.java

@@ -35,6 +35,9 @@ public class InsuranceHandlingSettlementMonthDto implements Serializable {
     @ApiModelProperty("签单时间")
     private LocalDateTime signingTime;
 
+    @ApiModelProperty("签单时间")
+    private String incomeSigningTime;
+
     @ApiModelProperty("创建人")
     private String createrId;
 
@@ -43,4 +46,7 @@ public class InsuranceHandlingSettlementMonthDto implements Serializable {
 
     @ApiModelProperty("开票手续费")
     private String invoiccommissionFeevalue;
+
+    @ApiModelProperty("是否手续费")
+    private String isNotDocumentary;
 }

+ 5 - 0
src/main/java/com/ydtech/modules/fnc/entity/InsuranceHandlingSettlementMonthEntity.java

@@ -62,4 +62,9 @@ public class InsuranceHandlingSettlementMonthEntity implements Serializable {
     @ApiModelProperty("合作公司id")
     @TableField("partner_companies_id")
     private String partnerCompaniesId;
+
+
+    @ApiModelProperty("签单日期")
+    @TableField(exist = false)
+    private String incomeSigningTime;
 }

+ 4 - 0
src/main/java/com/ydtech/modules/fnc/service/InsPlyIncomeService.java

@@ -6,12 +6,14 @@ import com.ydtech.modules.admin.model.report.financialReceivables.FinancialRecei
 import com.ydtech.modules.admin.model.report.financialReceivables.FinancialReceivablesAllVo;
 import com.ydtech.modules.admin.model.report.financialReceivables.FinancialReceivablesQueryMonthVo;
 import com.ydtech.modules.admin.model.report.financialReceivables.FinancialReceivablesQueryVo;
+import com.ydtech.modules.fnc.dto.InsuranceHandlingSettlementMonthDto;
 import com.ydtech.modules.fnc.dto.PlatformSettlementRecordDto;
 import com.ydtech.modules.fnc.entity.InsAreaCompany;
 import com.ydtech.modules.fnc.entity.InsPlyIncome;
 import com.ydtech.modules.fnc.entity.SettlementDocumentaryFeesEntity;
 import com.ydtech.modules.fnc.vo.InsPlyIncomeIdsVo;
 import com.ydtech.modules.fnc.vo.InsPlyIncomeVo;
+import com.ydtech.modules.fnc.vo.InsuranceHandlingSettlementMonthVo;
 import com.ydtech.modules.order.entity.BasePageResult;
 import com.ydtech.modules.order.entity.InsOrders;
 import com.ydtech.modules.protocols.entity.po.InsFeeOrderNew;
@@ -212,4 +214,6 @@ public interface InsPlyIncomeService extends IService<InsPlyIncome> {
      */
     HttpResult<List<InsPlyIncome>> createData(InsPlyIncomeIdsVo insPlyIncomeIdsVo);
 
+    List<InsuranceHandlingSettlementMonthDto> getInvociAmount(InsuranceHandlingSettlementMonthVo insuranceHandlingSettlementMonthVo);
+
 }

+ 1 - 1
src/main/java/com/ydtech/modules/fnc/service/InsuranceHandlingSettlementMonthService.java

@@ -26,6 +26,6 @@ public interface InsuranceHandlingSettlementMonthService  extends IService<Insur
      * @param insuranceHandlingSettlementMonthVo
      * @return
      */
-    HttpResult<InsuranceHandlingSettlementMonthDto> insertByEntity(InsuranceHandlingSettlementMonthVo insuranceHandlingSettlementMonthVo);
+    HttpResult<InsuranceHandlingSettlementMonthDto> insertByEntity(InsuranceHandlingSettlementMonthEntity insuranceHandlingSettlementMonthVo);
 
 }

+ 43 - 1
src/main/java/com/ydtech/modules/fnc/service/impl/InsPlyIncomeServiceImpl.java

@@ -21,11 +21,13 @@ import com.ydtech.modules.esm.model.EsmInsCompany;
 import com.ydtech.modules.esm.service.EsmInsCompanyService;
 import com.ydtech.modules.fnc.dao.FncInsAreaCompanyMapper;
 import com.ydtech.modules.fnc.dao.InsPlyIncomeMapper;
+import com.ydtech.modules.fnc.dto.InsuranceHandlingSettlementMonthDto;
 import com.ydtech.modules.fnc.dto.PlatformSettlementRecordDto;
 import com.ydtech.modules.fnc.entity.*;
 import com.ydtech.modules.fnc.service.*;
 import com.ydtech.modules.fnc.vo.InsPlyIncomeIdsVo;
 import com.ydtech.modules.fnc.vo.InsPlyIncomeVo;
+import com.ydtech.modules.fnc.vo.InsuranceHandlingSettlementMonthVo;
 import com.ydtech.modules.fnc.vo.SettlementDocumentaryFeesVo;
 import com.ydtech.modules.ins.model.vo.res.*;
 import com.ydtech.modules.inv.model.dto.*;
@@ -126,6 +128,9 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
     @Autowired
     private FncInsAreaCompanyMapper fncInsAreaCompanyMapper;
 
+    @Autowired
+    private InsuranceHandlingSettlementMonthService   insuranceHandlingSettlementMonthService;
+
 
     public HttpResult<BasePageResult<InsPlyIncome>> queryplyIncome(InsPlyIncomeVo insPlyIncomeVo) {
 
@@ -2068,7 +2073,38 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
                 }
             }
         }
-//            分批结算
+//      分批结算
+        List<InsuranceHandlingSettlementMonthEntity> insuranceHandlingList = insPlyIncomeVo.getInsuranceHandlingList();
+        BigDecimal allsettlementAmount = BigDecimal.ZERO;
+        for(InsuranceHandlingSettlementMonthEntity item :  insuranceHandlingList){
+            String incomeSigningTime = item.getIncomeSigningTime();
+
+            DateTimeFormatter yearMonthFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
+
+            // 尝试解析为LocalDate(这里实际上解析为YearMonth,但使用LocalDate的parse方法,因为它会接受只有年和月的TemporalQuery)
+            // 注意:这里直接解析为LocalDate可能会引发异常,因为DateTimeFormatter应该与要解析的Temporal类型精确匹配。
+            // 但由于Java的灵活性,以及默认行为(假设日为1),这通常可以工作。
+            LocalDate date = YearMonth.parse(incomeSigningTime, yearMonthFormatter).atDay(1);
+
+            // 将LocalDate转换为LocalDateTime,时间为00:00:00
+            LocalDateTime localDateTime = date.atStartOfDay();
+
+
+            BigDecimal totalAmount = item.getTotalAmount();  //开票金额
+            BigDecimal settlementAmount = item.getSettlementAmount();  //结算金额
+
+            if(settlementAmount.compareTo(BigDecimal.ZERO) > 0){
+                allsettlementAmount =    this.calculateTotal(settlementAmount,allsettlementAmount,null);
+                BigDecimal subtract = totalAmount.subtract(settlementAmount);
+                item.setRemainingAmount(subtract);
+                item.setCreateTime(LocalDateTime.now());
+            }
+            item.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId());
+            item.setSigningTime(localDateTime);
+            item.setTotalAmount(item.getRemainingAmount());
+        }
+        insuranceHandlingSettlementMonthService.saveBatch(insuranceHandlingList);
+
         SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo();
         settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getInvoicId());   //开票号
         settlementDocumentaryFeesVo.setSettlementTime(insPlyIncomeVo.getSettlementTime());   //结算时间
@@ -3515,4 +3551,10 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
         }
         return HttpResult.ok(newList);
     }
+
+    @Override
+    public List<InsuranceHandlingSettlementMonthDto> getInvociAmount(InsuranceHandlingSettlementMonthVo insuranceHandlingSettlementMonthVo) {
+
+        return baseMapper.getInvociAmount(insuranceHandlingSettlementMonthVo);
+    }
 }

+ 41 - 20
src/main/java/com/ydtech/modules/fnc/service/impl/InsuranceHandlingSettlementMonthServiceImpl.java

@@ -4,16 +4,23 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ydtech.core.page.HttpResult;
 import com.ydtech.modules.fnc.dao.InsuranceHandlingSettlementMonthMapper;
 import com.ydtech.modules.fnc.dto.InsuranceHandlingSettlementMonthDto;
+import com.ydtech.modules.fnc.entity.InsPlyIncome;
 import com.ydtech.modules.fnc.entity.InsuranceHandlingSettlementMonthEntity;
+import com.ydtech.modules.fnc.service.InsPlyIncomeService;
 import com.ydtech.modules.fnc.service.InsuranceHandlingSettlementMonthService;
 import com.ydtech.modules.fnc.vo.InsuranceHandlingSettlementMonthVo;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
+import java.math.BigDecimal;
 import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
+import java.util.function.BinaryOperator;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
@@ -27,27 +34,43 @@ import java.util.stream.Collectors;
 @Slf4j
 @Service
 public class InsuranceHandlingSettlementMonthServiceImpl extends ServiceImpl<InsuranceHandlingSettlementMonthMapper, InsuranceHandlingSettlementMonthEntity> implements InsuranceHandlingSettlementMonthService {
-
+    @Autowired
+    private InsPlyIncomeService  insPlyIncomeService;
     @Override
     public List<InsuranceHandlingSettlementMonthDto> queryList(InsuranceHandlingSettlementMonthVo insuranceHandlingSettlementMonthVo) {
+        List<InsuranceHandlingSettlementMonthDto>  incomeList=  insPlyIncomeService.getInvociAmount(insuranceHandlingSettlementMonthVo);
         List<InsuranceHandlingSettlementMonthDto> resultList = baseMapper.queryList(insuranceHandlingSettlementMonthVo);
+        if(resultList.size()>0){
+            Map<String, InsuranceHandlingSettlementMonthDto> latestByTaskId = resultList.stream()
+                    .collect(Collectors.toMap(
+                            InsuranceHandlingSettlementMonthDto::getIncomeSigningTime, // 用于生成Map的键
+                            Function.identity(),// 值是Stream中的元素本身
+                            // 如果两个元素有相同的key(即相同的taskId),则选择createTime更晚的那个
+                            BinaryOperator.maxBy(Comparator.comparing(InsuranceHandlingSettlementMonthDto::getCreateTime))
+                    ));
+
+            for (InsuranceHandlingSettlementMonthDto   incomeItem   : incomeList){
+                String incomeSigningTime = incomeItem.getIncomeSigningTime();
+                InsuranceHandlingSettlementMonthDto insuranceHandlingSettlementMonthDto = latestByTaskId.get(incomeSigningTime);
+                incomeItem.setRemainingAmount(insuranceHandlingSettlementMonthDto.getRemainingAmount());
+                incomeItem.setTotalAmount(insuranceHandlingSettlementMonthDto.getTotalAmount());
+                incomeItem.setCreateTime(null);
+                if( incomeItem.getSettlementAmount() ==null || incomeItem.getSettlementAmount().compareTo(BigDecimal.ZERO)==0){
+                    incomeItem.setSettlementAmount(new BigDecimal("0.00"));
+
+                }
+            }
+        }else {
+            for (InsuranceHandlingSettlementMonthDto   incomeItem   : incomeList){
+                    incomeItem.setRemainingAmount(incomeItem.getTotalAmount());
 
-        List<InsuranceHandlingSettlementMonthDto> latestRecords = resultList.stream()
-                // 根据taskId分组,并收集每个taskId对应的所有记录
-                .collect(Collectors.groupingBy(
-                        InsuranceHandlingSettlementMonthDto::getTaskId,
-                        Collectors.toList()
-                ))
-                // 遍历每个分组,找出每组中createTime最新的记录
-                .entrySet().stream()
-                .map(entry -> entry.getValue().stream()
-                        .max(Comparator.comparing(InsuranceHandlingSettlementMonthDto::getCreateTime))
-                        .orElse(null) // 如果没有记录,则返回null(这里根据需求决定是否处理null)
-                )
-                // 收集结果到新的List中
-                .collect(Collectors.toList());
+                if( incomeItem.getSettlementAmount() ==null || incomeItem.getSettlementAmount().compareTo(BigDecimal.ZERO)==0){
+                    incomeItem.setSettlementAmount(new BigDecimal("0.00"));
 
-        return resultList;
+                }
+            }
+        }
+        return incomeList;
     }
 
     /**
@@ -57,10 +80,8 @@ public class InsuranceHandlingSettlementMonthServiceImpl extends ServiceImpl<Ins
      * @return
      */
     @Override
-    public HttpResult<InsuranceHandlingSettlementMonthDto> insertByEntity(InsuranceHandlingSettlementMonthVo insuranceHandlingSettlementMonthVo) {
-        InsuranceHandlingSettlementMonthEntity insuranceHandlingSettlementMonthEntity = new InsuranceHandlingSettlementMonthEntity();
-        BeanUtils.copyProperties(insuranceHandlingSettlementMonthVo, insuranceHandlingSettlementMonthEntity);
-        baseMapper.insert(insuranceHandlingSettlementMonthEntity);
+    public HttpResult<InsuranceHandlingSettlementMonthDto> insertByEntity(InsuranceHandlingSettlementMonthEntity insuranceHandlingSettlementMonthVo) {
+        baseMapper.insert(insuranceHandlingSettlementMonthVo);
         return HttpResult.ok("结算成功");
     }
 }

+ 7 - 0
src/main/java/com/ydtech/modules/fnc/vo/InsPlyIncomeVo.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.ydtech.modules.fnc.entity.InsPlyIncome;
+import com.ydtech.modules.fnc.entity.InsuranceHandlingSettlementMonthEntity;
 import com.ydtech.modules.order.entity.po.InsUploadFiles;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
@@ -415,4 +416,10 @@ public class InsPlyIncomeVo implements Serializable {
 
     @ApiModelProperty("批量修改结果")
     private List<InsPlyIncome> resultList;
+
+
+    @ApiModelProperty("保险手续费结算")
+    private List<InsuranceHandlingSettlementMonthEntity> insuranceHandlingList;
+
+
 }

+ 7 - 0
src/main/java/com/ydtech/modules/fnc/vo/InsuranceHandlingSettlementMonthVo.java

@@ -44,4 +44,11 @@ public class InsuranceHandlingSettlementMonthVo implements Serializable {
 
     @ApiModelProperty("合作公司id")
     private String partnerCompaniesId;
+
+
+    @ApiModelProperty("是否手续费")
+    private String isNotDocumentary;
+
+    @ApiModelProperty("是否非车")
+    private String isNotCar;
 }

+ 208 - 0
src/main/resources/mapper/modules/fnc/InsPlyIncomeMapper.xml

@@ -2838,4 +2838,212 @@
         </where>
         GROUP BY DATE_FORMAT( a.signdate, '%Y-%m' )
     </select>
+    <select id="getProfitAnalysisQueryList" resultType="com.ydtech.modules.admin.model.report.profitAnalysis.ProfitAnalysisDto">
+        SELECT
+            a.signingTime as "signingTime",
+            a.sumpremium as "sumpremium",
+            b.allAmount as "sumcount",
+            d.settlement as "meet",
+            c.ActualPayment as "paid",
+            ifnull(d.settlement,0) - IFNULL(c.ActualPayment,0)  as "unpaid",
+            IFNULL( b.allAmount,0)- IFNULL (d.settlement,0)  as "grossProfit",
+            e.applyAmount  as "laborCost",
+            f.applyAmount  as "fixedCost",
+            j.applyAmount  as "variableCost",
+            (IFNULL (b.allAmount,0) - IFNULL(d.settlement,0) ) -( IFNULL(e.applyAmount,0) + IFNULL(f.applyAmount,0) + IFNULL(j.applyAmount,0) ) as "operatingProfit",
+            g.applyAmount  as "税费",
+            (IFNULL(b.allAmount,0)- IFNULL(d.settlement,0) ) -( IFNULL(e.applyAmount,0) + IFNULL(f.applyAmount,0) + IFNULL(j.applyAmount,0) ) - IFNULL(g.applyAmount,0) as "netProfit"
+        FROM
+            (
+                SELECT
+                    sum( iac.sumpremium ) as "sumpremium",
+                    DATE_FORMAT( iac.signing_time, '%Y-%m' ) AS "signingTime"
+                FROM
+                    `ins_fee_audit` ifa
+                        LEFT JOIN ins_area_company iac ON iac.id = ifa.ins_order_no
+                WHERE
+                    ifa.auditstatus = '1'
+                  AND iac.signing_time IS NOT NULL
+                GROUP BY
+                    DATE_FORMAT( iac.signing_time, '%Y-%m' )
+            ) a
+                LEFT JOIN (
+                SELECT
+                    sum( ipi.commission_feevalue +ipi.other_feevalue ) as "allAmount",
+                    DATE_FORMAT( ipi.signdate, '%Y-%m' ) AS "signingTime"
+                FROM
+                    ins_ply_income ipi
+                GROUP BY
+                    DATE_FORMAT( ipi.signdate, '%Y-%m' )
+            ) b ON a.signingTime = b.signingTime
+                left  join (
+                select
+                    sum(a.amount) as "ActualPayment",DATE_FORMAT( a.auditing_time, '%Y-%m' )  as "auditingTime"
+                from sys_amount_auditing a
+                         left join sys_user_account_history b on a.id = b.auditiing_id
+                         left join sys_user su on su.id =a.user_id
+                where a.auditing_status= '3'
+                GROUP BY DATE_FORMAT( a.auditing_time, '%Y-%m' )
+            ) c  on  c.auditingTime  =a.signingTime
+        left  join  (
+                SELECT
+                    sum(
+                            ifo.jq_export_supervise_costs_premiums + ifo.sy_export_supervise_costs_premiums + ifo.no_export_supervise_costs_premiums + ifo.jq_export_other_costs_premiums + ifo.sy_export_other_costs_premiums + ifo.no_export_other_costs_premiums + ifo.first_detail_premiums + ifo.second_detail_premiums + ifo.third_detail_premiums
+                    ) AS "settlement",
+                    DATE_FORMAT( iac.signing_time, '%Y-%m' )  as "signingTime"
+                FROM
+                    ins_fee_order_new ifo
+                        LEFT JOIN ins_fee_audit ifa ON ifo.ins_order_no = ifa.ins_order_no
+                        LEFT JOIN ins_area_company iac ON ifa.ins_order_no = iac.id
+                WHERE
+                    ifa.auditstatus = '1'
+                  AND iac.orderstatus = '3'
+                GROUP BY
+                    DATE_FORMAT( iac.signing_time, '%Y-%m' )
+            ) d  on  d.signingTime =a.signingTime
+        left join  (
+                SELECT
+                    sum(apply_amount) as "applyAmount",
+                    DATE_FORMAT( a.create_time, '%Y-%m' ) as "createTime",
+                    b.expenditureDetails
+                FROM
+                    inv_account_operate a
+                        left  join  (
+                        select a.category as "aCategory",b. category as "bCategory",a.expenditure_details as "expenditureDetails" from  inv_account_expenses a
+                                                                                                                                            left  join  inv_account_expenses  b  on a.parent_id =b.expenses_id
+                        where   b.category  is  not  null
+                    )  b on a.fund_use  = b.bCategory  and  a.fund_fen  = b.aCategory
+                WHERE
+                    a.out_card_num IN (
+                        SELECT
+                            bank_card_num
+                        FROM
+                            inv_account_card iac
+                                LEFT JOIN inv_account ia ON iac.account_id = ia.account_id
+                        WHERE
+                            ia.del_flag = '0'
+                          AND ia.outer_flag LIKE concat( '%', '0', '%' )
+                    )
+                  AND a.revenue_outlay = '1'
+                  AND a.del_flag = '0'
+                  AND b.expenditureDetails = '1'
+                GROUP BY  DATE_FORMAT( a.create_time, '%Y-%m' )  , b.expenditureDetails
+            ) e on  e.createTime =a.signingTime
+        left  join (
+                SELECT
+                    sum(apply_amount) as "applyAmount",
+                    DATE_FORMAT( a.create_time, '%Y-%m' ) as "createTime",
+                    b.expenditureDetails
+                FROM
+                    inv_account_operate a
+                        left  join  (
+                        select a.category as "aCategory",b. category as "bCategory",a.expenditure_details as "expenditureDetails" from  inv_account_expenses a
+                                                                                                                                            left  join  inv_account_expenses  b  on a.parent_id =b.expenses_id
+                        where   b.category  is  not  null
+                    )  b on a.fund_use  = b.bCategory  and  a.fund_fen  = b.aCategory
+                WHERE
+                    a.out_card_num IN (
+                        SELECT
+                            bank_card_num
+                        FROM
+                            inv_account_card iac
+                                LEFT JOIN inv_account ia ON iac.account_id = ia.account_id
+                        WHERE
+                            ia.del_flag = '0'
+                          AND ia.outer_flag LIKE concat( '%', '0', '%' )
+                    )
+                  AND a.revenue_outlay = '1'
+                  AND a.del_flag = '0'
+                  AND b.expenditureDetails = '2'
+                GROUP BY  DATE_FORMAT( a.create_time, '%Y-%m' )  , b.expenditureDetails
+            ) f on  f.createTime =a.signingTime
+            left join  (
+                SELECT
+                    sum(apply_amount) as "applyAmount",
+                    DATE_FORMAT( a.create_time, '%Y-%m' ) as "createTime",
+                    b.expenditureDetails
+                FROM
+                    inv_account_operate a
+                        left  join  (
+                        select a.category as "aCategory",b. category as "bCategory",a.expenditure_details as "expenditureDetails" from  inv_account_expenses a
+                                                                                                                                            left  join  inv_account_expenses  b  on a.parent_id =b.expenses_id
+                        where   b.category  is  not  null
+                    )  b on a.fund_use  = b.bCategory  and  a.fund_fen  = b.aCategory
+                WHERE
+                    a.out_card_num IN (
+                        SELECT
+                            bank_card_num
+                        FROM
+                            inv_account_card iac
+                                LEFT JOIN inv_account ia ON iac.account_id = ia.account_id
+                        WHERE
+                            ia.del_flag = '0'
+                          AND ia.outer_flag LIKE concat( '%', '0', '%' )
+                    )
+                  AND a.revenue_outlay = '1'
+                  AND a.del_flag = '0'
+                  AND b.expenditureDetails = '3'
+                GROUP BY  DATE_FORMAT( a.create_time, '%Y-%m' )  , b.expenditureDetails
+            ) j on  j.createTime =a.signingTime
+         left  join (
+                SELECT
+                    sum(apply_amount) as "applyAmount",
+                    DATE_FORMAT( a.create_time, '%Y-%m' ) as "createTime",
+                    b.expenditureDetails
+                FROM
+                    inv_account_operate a
+                        left  join  (
+                        select a.category as "aCategory",b. category as "bCategory",a.expenditure_details as "expenditureDetails" from  inv_account_expenses a
+                                                                                                                                            left  join  inv_account_expenses  b  on a.parent_id =b.expenses_id
+                        where   b.category  is  not  null
+                    )  b on a.fund_use  = b.bCategory  and  a.fund_fen  = b.aCategory
+                WHERE
+                    a.out_card_num IN (
+                        SELECT
+                            bank_card_num
+                        FROM
+                            inv_account_card iac
+                                LEFT JOIN inv_account ia ON iac.account_id = ia.account_id
+                        WHERE
+                            ia.del_flag = '0'
+                          AND ia.outer_flag LIKE concat( '%', '0', '%' )
+                    )
+                  AND a.revenue_outlay = '1'
+                  AND a.del_flag = '0'
+                  AND b.expenditureDetails = '4'
+                GROUP BY  DATE_FORMAT( a.create_time, '%Y-%m' )  , b.expenditureDetails
+            )  g  on  g.createTime  =a.signingTime
+
+    </select>
+
+
+    <select id="getInvociAmount" resultType="com.ydtech.modules.fnc.dto.InsuranceHandlingSettlementMonthDto" >
+        select
+        DATE_FORMAT( a.signdate, '%Y-%m' ) as "incomeSigningTime",
+        a.task_id as "taskId",
+        sum(a.commission_feevalue) as "totalAmount"
+        from  ins_ply_income a
+        LEFT  JOIN  ptl_agreement  pa  on  a.agreement_id  = pa.id
+        LEFT  JOIN  sys_user   su  on su.id=a.user_id
+        LEFT  JOIN  sys_user   su1  on su1.id=a.settlement_user_id
+        LEFT  JOIN  sys_user   su2  on su2.id=a.update_user_id
+        LEFT  JOIN   ins_upload_files  upf   on  a.settlement_image_id=upf.id
+        LEFT  JOIN   esm_ins_company  eic   on  eic.id=a.partner_companies_id
+        LEFT  JOIN   sys_dept b on pa.dept_id=b.id
+        <where>
+            1=1
+            <if test="vo.isNotCar !=null  and  vo.isNotCar  !=''">
+                and a.is_not_car =#{vo.isNotCar}
+            </if>
+
+            <if test="vo.isNotDocumentary !=null  and  vo.isNotDocumentary  !=''">
+                and a.is_not_documentary   =#{vo.isNotDocumentary}
+            </if>
+
+            <if test="vo.taskId != null and vo.taskId != ''">
+                and a.task_id = #{vo.taskId}
+            </if>
+        </where>
+        group by   a.task_id  , DATE_FORMAT( a.signdate, '%Y-%m' )
+    </select>
 </mapper>

+ 24 - 18
src/main/resources/mapper/modules/insuranceHandlingSettlementMonth/InsuranceHandlingSettlementMonthMapper.xml

@@ -7,21 +7,16 @@
                 a.task_id  as  "taskId",
                 a.settlement_documentary_fees_id  as  "settlementDocumentaryFeesId",
                 a.partner_companies_id  as  "partnerCompaniesId",
-                a.settlement_amount  as  "settlementAmount",
+                IFNULL(a.settlement_amount,0)  as  "settlementAmount",
                 a.total_amount  as  "totalAmount",
                 a.remaining_amount  as  "remainingAmount",
                 a.create_time  as  "createTime",
                 a.signing_time  as  "signingTime",
+                DATE_FORMAT( a.signing_time, '%Y-%m' )  as  "incomeSigningTime",
                 a.creater_id  as  "createrId"
     </sql>
 
     <select id="queryList" resultType="com.ydtech.modules.fnc.dto.InsuranceHandlingSettlementMonthDto">
-        select ipi.task_id as "taskId" ,
-        sum(IFNULL(ipi.commission_feevalue),0) as"invoiccommissionFeevalue"
-        from
-        ins_ply_income ipi
-        left join ptl_agreement pa on pa.id=ipi.agreement_id
-        left join (
         select
         <include refid="insuranceHandling_com"/>
         from
@@ -35,23 +30,34 @@
                 AND  a.task_id=#{vo.taskId}
             </if>
         </where>
-        )  b on b. taskId =ipi.task_id
+    </select>
+
+  <select id="queryListNew" resultType="com.ydtech.modules.fnc.dto.InsuranceHandlingSettlementMonthDto">
+        select
+          max( a.id ) AS "id",
+          max( a.task_id ) AS "taskId",
+          max( a.settlement_documentary_fees_id ) AS "settlementDocumentaryFeesId",
+          max( a.partner_companies_id ) AS "partnerCompaniesId",
+          max( IFNULL( a.settlement_amount, 0 ) ) AS "settlementAmount",
+          max( a.total_amount ) AS "totalAmount",
+          min( a.remaining_amount ) AS "remainingAmount",
+          max( a.create_time ) AS "createTime",
+          max( a.signing_time ) AS "signingTime",
+          max( DATE_FORMAT( a.signing_time, '%Y-%m' ) ) AS "incomeSigningTime",
+          max( a.creater_id ) AS "createrId"
+      from
+        sys_insurance_handling_settlement_month a
         <where>
-            pa.agreement_type ='2'
-            AND ipi.task_id is  not  null
-            <if test="vo.isNotCar  !=null and vo.isNotCar !=''">
-                AND ipi.is_not_car =#{vo.isNotCar}
-            </if>
-            <if test="vo.isnotDocumentary !=null and vo.isnotDocumentary !=''">
-                AND ipi.is_not_documentary =#{vo.isnotDocumentary}
+            1=1
+            <if test="vo.partnerCompaniesId  !=null  and  vo.partnerCompaniesId!=''">
+                AND  a.partner_companies_id=#{vo.partnerCompaniesId}
             </if>
             <if test="vo.taskId  !=null  and  vo.taskId!=''">
                 AND  a.task_id=#{vo.taskId}
             </if>
         </where>
-        group by ipi.task_id
-
-
+      GROUP BY
+      a.task_id, DATE_FORMAT(a.signing_time,  '%Y-%m' )
     </select>