Forráskód Böngészése

1.优化结算逻辑保险手续费

wuhp 2 éve
szülő
commit
6fff5a81e0

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

@@ -119,4 +119,5 @@ public interface InsPlyIncomeMapper extends BaseMapper<InsPlyIncome> {
 
     InsPlyIncome getEntityById(@Param("id") String id);
 
+    void updateByIds(String[] split);
 }

+ 2 - 0
src/main/java/com/ydtech/modules/fnc/dao/SettlementDocumentaryFeesMapper.java

@@ -26,4 +26,6 @@ public interface SettlementDocumentaryFeesMapper  extends BaseMapper<SettlementD
     void batchByInvoice( HashMap<String,Object> ids);
 
     List<HashMap<String, Object>> getInvoicIds(HashMap<String, Object> params);
+
+    SettlementDocumentaryFeesEntity getByParentSettlementAmount(String id);
 }

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

@@ -26,4 +26,5 @@ public interface SettlementDocumentaryFeesService extends IService<SettlementDoc
 
     List<HashMap<String, Object>> getInvoicIds(HashMap<String, Object> params);
 
+    SettlementDocumentaryFeesEntity getByParentSettlementAmount(String id);
 }

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

@@ -688,6 +688,8 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
         HashMap<String, Object> params = new HashMap<>();
         ArrayList<HashMap<String, Object>> resultList = new ArrayList<>();
         HashMap<String, Object> resultMap = new HashMap<>();
+        StringBuffer strBuilder = new StringBuffer();
+        String ids="";
         try {
             List<InsBxPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsBxPlyIncomeExcelDto.class, 0, 1, 1);
             Integer i=0;
@@ -718,6 +720,7 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
                         resultMap.put("agreementId",insPlyIncome.getAgreementId());  //协议id
                     }
                     if(ObjectUtils.isNotEmpty(insPlyIncome)){  // 比配上汇总金额 未匹配则返回到数据当中
+                        strBuilder.append(insPlyIncome.getId()).append(",");
                         if(  insPlyIncome.getCommissionFeevalue()!=null && insPlyIncome.getCommissionFeevalue().compareTo(BigDecimal.ZERO)!=0){
                             totalAmount = totalAmount.add(insPlyIncome.getCommissionFeevalue());  //添加总手续费
                         }
@@ -736,6 +739,10 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
                     }
                 }
             }
+            if(strBuilder.length() >0){
+                ids = strBuilder.deleteCharAt(strBuilder.length() - 1).toString();
+            }
+            resultMap.put("ids",ids);
             resultMap.put("totalAmount",totalAmount);
             resultMap.put("resultList",resultList);
             return resultMap;
@@ -751,6 +758,7 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
         HashMap<String, Object> params = new HashMap<>();
         HashMap<String, Object> resultMap = new HashMap<>();
         ArrayList<HashMap<String, Object>> resultList = new ArrayList<>();
+        StringBuffer strBuilder = new StringBuffer();
         String ids="";
         try {
             Integer i=0;
@@ -777,6 +785,7 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
                         resultMap.put("agreementId",insPlyIncome.getAgreementId());  //协议id
                     }
                     if(ObjectUtils.isNotEmpty(insPlyIncome)){  // 比配上汇总金额 未匹配则返回到数据当中
+                        strBuilder.append(insPlyIncome.getId()).append(",");
                         if(  insPlyIncome.getCommissionFeevalue()!=null && insPlyIncome.getCommissionFeevalue().compareTo(BigDecimal.ZERO)!=0){
                             totalAmount = totalAmount.add(insPlyIncome.getCommissionFeevalue());  //添加总手续费
                         }
@@ -791,7 +800,10 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
                         resultList.add(noMatching);
                     }
                 }
-
+                if(strBuilder.length() >0){
+                    ids = strBuilder.deleteCharAt(strBuilder.length() - 1).toString();
+                }
+                resultMap.put("ids",ids);
                 resultMap.put("totalAmount",totalAmount);
                 resultMap.put("resultList",resultList);
             }
@@ -839,6 +851,12 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
     public HttpResult<List<HashMap<String,Object>>> invicdetail(InsPlyIncomeVo insPlyIncomeVo) {
         HashMap<String, Object> params = new HashMap<>();
         params =this.saveParams(insPlyIncomeVo,params);
+        if (StringUtils.isEmpty(insPlyIncomeVo.getIsSettlement())){
+            params.put("isSettlement","1");
+        }
+        if(StringUtils.isNotEmpty(insPlyIncomeVo.getSettlementStatus())){
+            params.put("settlementStatus",insPlyIncomeVo.getSettlementStatus());
+        }
         List<HashMap<String, Object>> resultList = settlementDocumentaryFeesService.getOtherSettldetail(params);
         if (resultList.size() > 0) {
             return HttpResult.ok(resultList);
@@ -1273,10 +1291,23 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
     @Override
     @Transactional
     public HttpResult<Object> batchInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
+        //      开票时生成  记录 用来合计已经开票数据
+        String ids = insPlyIncomeVo.getIds();
+        if(StringUtils.isNotEmpty(ids)){
+            String[] split = ids.split(",");
+            for (String id :  split){
+                InsPlyIncome insPlyIncome = baseMapper.selectById(id);
+                insPlyIncome.setInvoicTime(LocalDate.now());  //开票时间
+                insPlyIncome.setInvoicId(insPlyIncomeVo.getInvoicId()); //开票号
+                insPlyIncome.setHandlingFeesStatus("2");   //2为开票
+                baseMapper.updateById(insPlyIncome);
+            }
+        }
         insPlyIncomeVo.setNoInvoicCommissionFeevalue(insPlyIncomeVo.getTotalAmount());
         insPlyIncomeVo.setOtherFeevalue(insPlyIncomeVo.getTotalAmount());
         insPlyIncomeVo.setHandlingFeesStatus("0");  // 0手续费 1  跟单费
         insPlyIncomeVo.setIsNotCar(insPlyIncomeVo.getIsNotCar());
+        insPlyIncomeVo.setAgreementId(insPlyIncomeVo.getAgreementId());
         insPlyIncomeVo.setSettlementAmount(insPlyIncomeVo.getTotalAmount());
         insPlyIncomeVo.setContractId(insPlyIncomeVo.getInvoicId());
         this.batchInvoic(insPlyIncomeVo);
@@ -1296,6 +1327,9 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
 
     @Override
     public HttpResult<Object> batchBxBalance(InsPlyIncomeVo insPlyIncomeVo) {
+        if(StringUtils.isNotEmpty(insPlyIncomeVo.getIds())){// 判断 ins_ply_income  是否完全结算完 如果结算完则改为已结算状态
+            this.changeHandStatus(insPlyIncomeVo.getIds(),insPlyIncomeVo);
+        }
 //            分批结算
         SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo();
 
@@ -1323,6 +1357,22 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
         return HttpResult.ok();
     }
 
+    private void changeHandStatus(String ids, InsPlyIncomeVo insPlyIncomeVo) {
+        String[] split = ids.split(",");
+
+        SettlementDocumentaryFeesEntity byId = settlementDocumentaryFeesService.getById(insPlyIncomeVo.getId());
+        BigDecimal totalAmount = byId.getTotalAmount();  //开票总金额
+        BigDecimal settlementAmount = insPlyIncomeVo.getSettlementAmount();   //本次结算金额
+        //多次结算 表中已经结算的金额
+        SettlementDocumentaryFeesEntity    settlementAmountEntity = settlementDocumentaryFeesService.getByParentSettlementAmount(insPlyIncomeVo.getId());
+        if(ObjectUtils.isNotEmpty(settlementAmountEntity)){
+            BigDecimal all = settlementAmount.add(settlementAmountEntity.getTotalAmount());
+            if(all.equals(totalAmount)){
+                baseMapper.updateByIds(split);
+            }
+        }
+    }
+
     @Override
     public HttpResult<InsPlyIncome> querySettInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
         HashMap<String, Object> params = new HashMap<>();
@@ -1436,6 +1486,7 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
         settlementDocumentaryFeesVo.setHandlingFeesStatus(insPlyIncomeVo.getHandlingFeesStatus());
         settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
         settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
+        settlementDocumentaryFeesVo.setIds(insPlyIncomeVo.getIds());
         //  税点支出
         if(BigDecimalUtils.nullToZero(insPlyIncomeVo.getTaxPoints()) !=null   && BigDecimalUtils.nullToZero(insPlyIncomeVo.getSettlementAmount()) !=null){
             BigDecimal settlementAmount = insPlyIncomeVo.getSettlementAmount();

+ 6 - 0
src/main/java/com/ydtech/modules/fnc/service/impl/SettlementDocumentaryFeesServiceImpl.java

@@ -163,6 +163,12 @@ public class SettlementDocumentaryFeesServiceImpl extends ServiceImpl<Settlement
         return  baseMapper.getInvoicIds(params);
     }
 
+    @Override
+    public SettlementDocumentaryFeesEntity getByParentSettlementAmount(String id) {
+
+        return baseMapper.getByParentSettlementAmount(id);
+    }
+
     private int compareAmount(BigDecimal settlementAmount, BigDecimal settlementAmount1) {
 
         return settlementAmount.compareTo(settlementAmount1);

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

@@ -276,4 +276,10 @@ public class InsPlyIncomeVo implements Serializable {
     @ApiModelProperty("税点金额")
     private BigDecimal expendAmount;
 
+    @ApiModelProperty("是否已结算")
+    private String isSettlement;
+
+    @ApiModelProperty("结算状态")
+    private String settlementStatus;
+
 }

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

@@ -239,6 +239,8 @@
                   AND  a.insured_name =#{insuredName}
                 </if>
             </where>
+            ORDER  BY  a.create_time  desc
+
     </select>
     <select id="getEntityById"  resultType="com.ydtech.modules.fnc.entity.InsPlyIncome">
             select
@@ -1060,4 +1062,19 @@
         group  by  a.invoic_id
     </select>
 
+    <update id="updateByIds"  parameterType="com.ydtech.modules.fnc.entity.InsPlyIncome">
+        update ins_ply_income
+            set  handling_fees_status ='1',
+                 settlement_time =NOW()
+        <where>
+                 1=1
+            <if test="split != null and split != '' and split.length > 0">
+                and  id in
+                <foreach collection="split" item="item" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+            </if>
+        </where>
+    </update>
+
 </mapper>

+ 24 - 2
src/main/resources/mapper/modules/fnc/SettlementDocumentaryFeesMapper.xml

@@ -77,6 +77,7 @@
         a.tax_points AS  "taxPoints",
         a.settlement_amount - COALESCE(b.settlementAmount, 0) AS "invoicCommissionFeevalue",
         a.agreement_type as "agreementType",
+        a.ids  as "ids",
         a.invoicing_method AS  "invoicingMethod"
         FROM
         settlement_documentary_fees a
@@ -88,8 +89,17 @@
         ) b  on a.id=b.parentId
         <where>
             1=1
-            and  a.settlement_status  ='1'
-            and a.settlement_amount - COALESCE(b.settlementAmount, 0) &lt;&gt; 0
+            <choose>
+                <when test="settlementStatus != null  and  settlementStatus!=''">
+                    and  a.settlement_status  =#{settlementStatus}
+                </when>
+                <otherwise>
+                    and  a.settlement_status  ='1'
+                </otherwise>
+            </choose>
+            <if test="isSettlement !=null and  isSettlement  !=''">
+                and a.settlement_amount - COALESCE(b.settlementAmount, 0) &lt;&gt; 0
+            </if>
             <if test="partnerCompaniesId !=null  and  partnerCompaniesId  !=''">
                 and a.partner_companies_id =#{partnerCompaniesId}
             </if>
@@ -146,6 +156,18 @@
     </select>
 
 
+    <select id="getByParentSettlementAmount" resultType="com.ydtech.modules.fnc.entity.SettlementDocumentaryFeesEntity">
+        SELECT
+             sum(a.settlement_amount) as "totalAmount"
+        FROM settlement_documentary_fees a
+        <where>
+                <if test="id !=null and  id  !=''">
+                    a.parent_id =#{id}
+                </if>
+        </where>
+    </select>
+
+
 
 
 

+ 4 - 4
src/main/resources/mapper/modules/ins/InsFeeOrderNewMapper.xml

@@ -207,7 +207,7 @@
 
     <select id="getSumWillAmount"  resultType="com.ydtech.modules.protocols.entity.po.InsFeeOrderNew">
         select
-        a.id as "id",
+        a.ins_order_no as "id",
         a.user_id as "userId",
         ins.signing_time as "signingTime",
         o.licenseno as "licenseno",
@@ -252,7 +252,7 @@
         FROM
         (
         SELECT
-        a.id as "id",
+        a.ins_order_no as "id",
         a.user_id as "userId",
         iac.signing_time as "signingTime",
         o.licenseno as "licenseno",
@@ -276,7 +276,7 @@
         </where>
         UNION
         SELECT
-        a.id as "id",
+        a.ins_order_no as "id",
         a.user_id as "userId",
         iac.signing_time as "signingTime",
         o.licenseno as "licenseno",
@@ -300,7 +300,7 @@
         </where>
         UNION
         SELECT
-        a.id as "id",
+        a.ins_order_no as "id",
         a.user_id as "userId",
         iac.signing_time as "signingTime",
         o.licenseno as "licenseno",