Ver código fonte

1. 结算非车明细 校验

wuhp 2 anos atrás
pai
commit
079815b9c5

+ 1 - 1
src/main/java/com/ydtech/modules/fnc/controller/SettlementDocumentaryFeesController.java

@@ -44,7 +44,7 @@ public class SettlementDocumentaryFeesController extends BaseController {
     @PutMapping("/voidInvoicing")
     @ApiModelProperty(value = "作废开票")
     public HttpResult<Object> voidInvoicing(@RequestBody SettlementDocumentaryFeesVo settlementDocumentaryFeesVo) {
-        settlementDocumentaryFeesService.voidInvoicing(settlementDocumentaryFeesVo);
+        HttpResult<Object>  result= settlementDocumentaryFeesService.voidInvoicing(settlementDocumentaryFeesVo);
         return HttpResult.ok("作废成功");
     }
 

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

@@ -28,7 +28,7 @@ public interface SettlementDocumentaryFeesMapper  extends BaseMapper<SettlementD
 
     List<HashMap<String, Object>> getInvoicIds(HashMap<String, Object> params);
 
-    SettlementDocumentaryFeesEntity getByParentSettlementAmount(String id);
+    SettlementDocumentaryFeesEntity getByParentSettlementAmount(HashMap<String, Object> params);
 
     List<SettlementDocumentaryFeesEntity> queryNew(HashMap<String, Object> params);
 

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

@@ -27,9 +27,9 @@ public interface SettlementDocumentaryFeesService extends IService<SettlementDoc
 
     List<HashMap<String, Object>> getInvoicIds(HashMap<String, Object> params);
 
-    SettlementDocumentaryFeesEntity getByParentSettlementAmount(String id);
+    SettlementDocumentaryFeesEntity getByParentSettlementAmount(HashMap<String, Object> params);
 
-    void voidInvoicing(SettlementDocumentaryFeesVo settlementDocumentaryFeesVo);
+    HttpResult<Object> voidInvoicing(SettlementDocumentaryFeesVo settlementDocumentaryFeesVo);
 
     List<SettlementDocumentaryFeesEntity> queryNew(HashMap<String, Object> params);
 }

+ 5 - 0
src/main/java/com/ydtech/modules/fnc/service/impl/ImportAsyncServiceImpl.java

@@ -347,6 +347,7 @@ public class ImportAsyncServiceImpl extends ServiceImpl<ImportAsyncMapper, Impor
 
     @Override
     public void bxNoOtherImportData(List<InsNoBxOtherExcelDto> dtoList, String isNotCar, String taskId) {
+        List<String> idList= new ArrayList<>();
 
         BigDecimal totalAmount = BigDecimal.ZERO;
         HashMap<String, Object> params = new HashMap<>();
@@ -400,6 +401,7 @@ public class ImportAsyncServiceImpl extends ServiceImpl<ImportAsyncMapper, Impor
                             reason = "该数据非车跟单比例有问题";
                         }
                     }
+                    idList.add(insPlyIncome.getId());
                     if (insPlyIncome.getOtherFeevalue() != null && insPlyIncome.getOtherFeevalue().compareTo(BigDecimal.ZERO) != 0) {
                         totalAmount = totalAmount.add(insPlyIncome.getOtherFeevalue());  //添加总手续费
                     }
@@ -437,6 +439,9 @@ public class ImportAsyncServiceImpl extends ServiceImpl<ImportAsyncMapper, Impor
         endTask.setStatus("complete");
         if(!CollectionUtils.isEmpty(insImportResultsExcel)){
             endTask.setUploadUrl("/upload/excel/" + taskId + "/" + fileName);
+        }else {
+            //则生成 结算任务关系表
+            incomeTaskRelationshipService.saveByIncomeIdList(taskId,idList);
         }
         endTask.setCompanyId(companyId);
         endTask.setAgreementId(agreementId);

+ 65 - 40
src/main/java/com/ydtech/modules/fnc/service/impl/InsPlyIncomeServiceImpl.java

@@ -169,8 +169,8 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
         insPlyIncome.setCreateTime(LocalDate.now());
         insPlyIncome.setDocumentaryFeesStatus("0");
         insPlyIncome.setHandlingFeesStatus("0");
-        insPlyIncome.setNoNoTaxPremium(insPlyIncome.getNoNoTaxPremium());
-        insPlyIncome.setNoPremium(insPlyIncome.getNoPremium());
+        insPlyIncome.setNoNoTaxPremium(insFeeOrderNew.getNoNoTaxPremium());
+        insPlyIncome.setNoPremium(insFeeOrderNew.getNoPremium());
         insPlyIncome.setIsNotCar("1");
         insPlyIncome.setIsNotDocumentary("1");
         insPlyIncome.setJqStartDate(insAreaCompany.getJqStartDate());
@@ -1416,11 +1416,32 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
     @Override
     @Transactional
     public HttpResult batchBalance(InsPlyIncomeVo insPlyIncomeVo) {
-//  通过ids 查出跟单非结算单
-        BigDecimal allAmount = BigDecimal.ZERO;
 //            分批结算
         SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo();
 
+
+        String id = insPlyIncomeVo.getId();   //  开票id
+        SettlementDocumentaryFeesEntity settlementDocumentaryFeesServiceById = settlementDocumentaryFeesService.getById(id);  //
+        BigDecimal allAmount = settlementDocumentaryFeesServiceById.getTotalAmount();
+
+
+        HashMap<String, Object> params = new HashMap<>();
+        params.put("id",insPlyIncomeVo.getId());
+        params.put("handlingFeesStatus", "1");
+        SettlementDocumentaryFeesEntity parentSettlementDocumentaryFeesEntity = settlementDocumentaryFeesService.getByParentSettlementAmount(params);
+
+        if(ObjectUtils.isNotEmpty(parentSettlementDocumentaryFeesEntity)){ // 多次结算
+            BigDecimal totalAmount = parentSettlementDocumentaryFeesEntity.getTotalAmount();
+            totalAmount=totalAmount.add(insPlyIncomeVo.getSettlementAmount());
+            if(allAmount.compareTo(totalAmount) <0){
+                return HttpResult.error("结算金额超出开票金额");
+            }
+        }else {
+            if(allAmount.compareTo(insPlyIncomeVo.getSettlementAmount()) <0){
+                return HttpResult.error("结算金额超出开票金额");
+            }
+        }
+
         settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getInvoicId());   //开票号
         settlementDocumentaryFeesVo.setSettlementTime(insPlyIncomeVo.getSettlementTime());   //结算时间
         settlementDocumentaryFeesVo.setSettlementStatus("2");   //2为结算状态
@@ -1599,26 +1620,42 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
     }
 
     @Override
+    @Transactional
     public HttpResult<Object> batchBxBalance(InsPlyIncomeVo insPlyIncomeVo) {
+
 //         表内总金额
-        BigDecimal invoicCommissionFeevalue = insPlyIncomeVo.getInvoicCommissionFeevalue();
-        BigDecimal settlementAmount = insPlyIncomeVo.getSettlementAmount();
+        BigDecimal settlementAmount = insPlyIncomeVo.getSettlementAmount();  //结算金额
 
+        SettlementDocumentaryFeesEntity byIdSettlementDocumentaryFeesEntity = settlementDocumentaryFeesService.getById(insPlyIncomeVo.getId());
+        BigDecimal  invoicAmount = byIdSettlementDocumentaryFeesEntity.getTotalAmount();
 
         HashMap<String, Object> params = new HashMap<>();
-        params = this.saveParams(insPlyIncomeVo,params);
-        params.put("handlingFeesStatus",insPlyIncomeVo.getHandlingFeesStatus());
-        List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
-        for (InsPlyIncome  item : insPlyIncomes){
-            if(settlementAmount.compareTo(invoicCommissionFeevalue) ==0){
-                item.setHandlingFeesStatus("1");
-                baseMapper.updateById(item);
+        params.put("id",insPlyIncomeVo.getId());
+        params.put("handlingFeesStatus", "0");
+        SettlementDocumentaryFeesEntity parentSettlementDocumentaryFeesEntity = settlementDocumentaryFeesService.getByParentSettlementAmount(params);
+
+        if(ObjectUtils.isNotEmpty(parentSettlementDocumentaryFeesEntity)){ // 多次结算
+            BigDecimal totalAmount = parentSettlementDocumentaryFeesEntity.getTotalAmount();
+            totalAmount = totalAmount.add(insPlyIncomeVo.getSettlementAmount());
+            if(invoicAmount .compareTo(totalAmount)<0){
+                return HttpResult.error("结算金额大于开票金额");
+            }
+        }else {
+            if(invoicAmount.compareTo(insPlyIncomeVo.getSettlementAmount()) <0){
+                return HttpResult.error("结算金额大于开票金额");
+            } else if (invoicAmount.compareTo(insPlyIncomeVo.getSettlementAmount()) ==0) {
+                HashMap<String, Object> incomeParams = new HashMap<>();
+                incomeParams = this.saveParams(insPlyIncomeVo,incomeParams);
+                incomeParams.put("handlingFeesStatus",insPlyIncomeVo.getHandlingFeesStatus());
+                List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(incomeParams);
+                for (InsPlyIncome  item : insPlyIncomes){
+                        item.setHandlingFeesStatus("1");
+                        baseMapper.updateById(item);
+                }
             }
         }
 //            分批结算
         SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo();
-        String id = String.valueOf(new SnowFlakeUtil().nextId());
-        settlementDocumentaryFeesVo.setId(id);
         settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getInvoicId());   //开票号
         settlementDocumentaryFeesVo.setSettlementTime(insPlyIncomeVo.getSettlementTime());   //结算时间
         settlementDocumentaryFeesVo.setSettlementStatus("2");   //2为结算状态
@@ -1631,7 +1668,8 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
         settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount());   //进账金额
         settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getInvoicCommissionFeevalue());
         settlementDocumentaryFeesVo.setHandlingFeesStatus("0");
-        settlementDocumentaryFeesVo.setParentId(id);
+        settlementDocumentaryFeesVo.setParentId(insPlyIncomeVo.getId());
+        settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId());
         settlementDocumentaryFeesVo.setSettlementImageId(insPlyIncomeVo.getSettlementImageId());
         settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
         settlementDocumentaryFeesVo.setAgreementType("2");  //1平台 2  保险
@@ -1639,21 +1677,6 @@ 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) {
@@ -1687,7 +1710,7 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
 
 
             params.put("partnerCompaniesId", item.getPartnerCompaniesId());
-
+            params.remove("handlingFeesStatus");
             List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);  // 总跟单费
             for (InsPlyIncome all : insPlyIncomes) {
                 otherFeevalue = otherFeevalue.add(all.getOtherFeevalue());
@@ -1770,7 +1793,7 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
         settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId());// 保险公司id
         settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId());  //合作公司id
         settlementDocumentaryFeesVo.setAgreementId(insPlyIncomeVo.getAgreementId());
-        settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getOtherFeevalue());  //其他费用金额
+        settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getSettlementAmount());  //其他费用金额
         settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getNoInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算
         settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount());//已经开票
         settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
@@ -2240,6 +2263,8 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
                 params.put("isOther","1");
                 InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
                 if(byBxLicenseno.getNoOtherCostsProportion().compareTo(item.getNoOtherCostsProportion()) !=0 ){
+                    HashMap<String, Object> newMap = new HashMap<>();
+
                     // 如果比例不相等
                     BigDecimal noOtherCostsProportion = item.getNoOtherCostsProportion();
 
@@ -2251,18 +2276,18 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
                     byBxLicenseno.setOtherFeerate(this.calculateTotal(noOtherCostsProportion,null ,null));
                     baseMapper.updateById(byBxLicenseno);
 
-                    resultMap.put("licenseno",item.getLicenseno());
-                    resultMap.put("noPolicyno",item.getNoPolicyno());
-                    resultMap.put("noOtherCostsPremium",noOtherAmount);
+                    newMap.put("licenseno",item.getLicenseno());
+                    newMap.put("noPolicyno",item.getNoPolicyno());
+                    newMap.put("noOtherCostsPremium",noOtherAmount);
 
-                    resultMap.put("otherFeevalue",byBxLicenseno.getOtherFeevalue());
-                    resultMap.put("otherFeerate",byBxLicenseno.getOtherFeerate());
-                    resultList.add(resultMap);
+                    newMap.put("otherFeevalue",byBxLicenseno.getOtherFeevalue());
+                    newMap.put("otherFeerate",byBxLicenseno.getOtherFeerate());
+                    resultList.add(newMap);
                     allAmount = allAmount.add(noOtherAmount);
                 }
-
             }
             resultMap.put("allAmount",allAmount);
+            resultMap.put("resultList",resultList);
         } catch (IOException e) {
             throw new RuntimeException(e);
         }

+ 9 - 4
src/main/java/com/ydtech/modules/fnc/service/impl/SettlementDocumentaryFeesServiceImpl.java

@@ -168,9 +168,9 @@ public class SettlementDocumentaryFeesServiceImpl extends ServiceImpl<Settlement
     }
 
     @Override
-    public SettlementDocumentaryFeesEntity getByParentSettlementAmount(String id) {
+    public SettlementDocumentaryFeesEntity getByParentSettlementAmount(HashMap<String, Object> params) {
 
-        return baseMapper.getByParentSettlementAmount(id);
+        return baseMapper.getByParentSettlementAmount(params);
     }
 
     /**
@@ -179,14 +179,19 @@ public class SettlementDocumentaryFeesServiceImpl extends ServiceImpl<Settlement
      * @param settlementDocumentaryFeesVo
      */
     @Override
-    public void voidInvoicing(SettlementDocumentaryFeesVo settlementDocumentaryFeesVo) {
+    public HttpResult<Object> voidInvoicing(SettlementDocumentaryFeesVo settlementDocumentaryFeesVo) {
         SettlementDocumentaryFeesEntity oldSettlementDocumentaryFeesEntity = baseMapper.selectById(settlementDocumentaryFeesVo.getId());
 
+        if(settlementDocumentaryFeesVo.getReadyCommissionFeevalue()  !=null  && settlementDocumentaryFeesVo.getReadyCommissionFeevalue().compareTo(BigDecimal.ZERO) !=0){
+            return HttpResult.error("已经结算该数据不能作废");
+        }
+
         String taskId = oldSettlementDocumentaryFeesEntity.getTaskId();
         HashMap<String, Object> params = new HashMap<>();
         params.put("taskId", taskId);
         List<InsPlyIncome> insPlyIncomes = insPlyIncomeMapper.queryNew(params);
 
+
         for (InsPlyIncome item : insPlyIncomes) {
             LambdaUpdateWrapper<InsPlyIncome> wrapper = new LambdaUpdateWrapper<>();
             wrapper.eq(InsPlyIncome::getId, item.getId());
@@ -200,7 +205,7 @@ public class SettlementDocumentaryFeesServiceImpl extends ServiceImpl<Settlement
         BeanUtils.copyProperties(settlementDocumentaryFeesVo, settlementDocumentaryFeesEntity);
         settlementDocumentaryFeesEntity.setSettlementStatus("3");  // 3  为作废
         baseMapper.updateById(settlementDocumentaryFeesEntity);
-
+        return  HttpResult.ok();
     }
 
     @Override

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

@@ -343,6 +343,9 @@ public class InsPlyIncomeVo implements Serializable {
     @ApiModelProperty(value = "parentId")
     private String parentId;
 
+    @ApiModelProperty(value = "开票总额")
+    private BigDecimal allInvoicCommissionFeevalue;
+
 
 
 

+ 3 - 0
src/main/java/com/ydtech/modules/fnc/vo/SettlementDocumentaryFeesVo.java

@@ -116,4 +116,7 @@ public class SettlementDocumentaryFeesVo implements Serializable {
     private String settlementImageId;
     @ApiModelProperty("任务id")
     private String taskId;
+
+    @ApiModelProperty("已开票已结算")
+    private BigDecimal readyCommissionFeevalue;
 }

+ 2 - 1
src/main/resources/mapper/modules/fnc/InsPlyIncomeMapper.xml

@@ -897,6 +897,7 @@
 
     <select id="totalPinAmount" resultType="com.ydtech.modules.fnc.entity.InsPlyIncome">
                 select
+                MAX(a.partner_companies_id) as "partnerCompaniesId",
                 MAX( ec.name ) AS "companyName",
                 sum( a.commission_feevalue ) AS "commissionFeevalue",
                 sum( a.other_feevalue ) AS "otherFeevalue",
@@ -917,7 +918,7 @@
                     AND   a.documentary_fees_status = #{documentaryFeesStatus}
                 </if>
                 <if test="handlingFeesStatus != null  and  handlingFeesStatus != ''">
-                    AND   handling_fees_status = #{handlingFeesStatus}
+                    AND   a.handling_fees_status = #{handlingFeesStatus}
                 </if>
                 <if test="year !=null  and  year  !=''">
                     AND YEAR(a.signdate) =#{year}

+ 6 - 1
src/main/resources/mapper/modules/fnc/SettlementDocumentaryFeesMapper.xml

@@ -88,6 +88,7 @@
             a.create_time AS "invoicTime",
             a.invoice_id AS  "invoicId",
             a.tax_points AS  "taxPoints",
+            a.partner_companies_id AS  "partnerCompaniesId",
             a.agreement_type as "agreementType",
             IFNULL(settlement_amount ,0) "invoicCommissionFeevalue",
             a.invoicing_method as "invoicingMethod",
@@ -174,8 +175,12 @@
              sum(a.settlement_amount) as "totalAmount"
         FROM settlement_documentary_fees a
         <where>
+                a.settlement_status = '2'
                 <if test="id !=null and  id  !=''">
-                    a.parent_id =#{id}
+                 and   a.parent_id =#{id}
+                </if>
+              <if test="handlingFeesStatus !=null and  handlingFeesStatus  !=''">
+                 and   a.handling_fees_status =#{handlingFeesStatus}
                 </if>
         </where>
     </select>