Kaynağa Gözat

Merge branch 'test'

wks 2 yıl önce
ebeveyn
işleme
f051b52396

+ 5 - 15
src/main/java/com/ydtech/modules/inv/controller/InvAccountIncoiceController.java

@@ -27,6 +27,7 @@ import java.util.Map;
 import java.util.stream.DoubleStream;
 
 import static com.ydtech.modules.inv.service.impl.InvAccountIncoiceServiceImpl.getBigDecimal;
+import static com.ydtech.modules.inv.utils.TransferUtils.isProfitFull;
 
 /**
  * 发票管理表(InvAccountIncoice)表控制层
@@ -98,7 +99,7 @@ public class InvAccountIncoiceController {
         invAccountIncoiceResult.setTaxSum("0");
 
         records.forEach(inv -> {
-            invAccountIncoiceResult.setNotPayoutMoneySum(String.valueOf(new BigDecimal(inv.getInvoiceMoney()).add(new BigDecimal(invAccountIncoiceResult.getNotPayoutMoneySum()))));
+            invAccountIncoiceResult.setNotPayoutMoneySum(String.valueOf(new BigDecimal(inv.getNotPayoutMoney()).add(new BigDecimal(invAccountIncoiceResult.getNotPayoutMoneySum()))));
             invAccountIncoiceResult.setInvoiceMoneySum(String.valueOf(new BigDecimal(inv.getInvoiceMoney()).add(new BigDecimal(invAccountIncoiceResult.getInvoiceMoneySum()))));
             invAccountIncoiceResult.setNoHasTaxSum(String.valueOf(new BigDecimal(inv.getNoHasTax()).add(new BigDecimal(invAccountIncoiceResult.getNoHasTaxSum()))));
             invAccountIncoiceResult.setInvoiceNumSum(String.valueOf(new BigDecimal(inv.getInvoiceNum()).add(new BigDecimal(invAccountIncoiceResult.getInvoiceNumSum()))));
@@ -141,20 +142,9 @@ public class InvAccountIncoiceController {
     public HttpResult updateIncome(@RequestBody InvAccountIncoice invAccountIncoice) {
         JSONObject outProfit = invAccountIncoice.getOutProfit();
         JSONObject entProfit = invAccountIncoice.getEntProfit();
-        BigDecimal outAmount = new BigDecimal(0);
-        BigDecimal entAmount = new BigDecimal(0);
-        for (Map.Entry<String, Object> entry:outProfit.entrySet()){
-            outAmount = outAmount.add(new BigDecimal(entry.getValue().toString()));
-        }
-        for (Map.Entry<String, Object> entry:entProfit.entrySet()){
-            entAmount = entAmount.add(new BigDecimal(entry.getValue().toString()));
-        }
-        if (!String.valueOf(outAmount).equals("100")){
-            throw new SystemException("支出金额未完全分配");
-        }
-        if (!String.valueOf(entAmount).equals("100")){
-            throw new SystemException("收入金额未完全分配");
-        }
+
+        isProfitFull(outProfit, entProfit);
+
         return this.invAccountIncoiceService.updateInvAccountIncoice(invAccountIncoice);
     }
 

+ 3 - 14
src/main/java/com/ydtech/modules/inv/controller/InvAccountOperateController.java

@@ -14,6 +14,8 @@ import org.springframework.web.bind.annotation.*;
 import java.math.BigDecimal;
 import java.util.Map;
 
+import static com.ydtech.modules.inv.utils.TransferUtils.isProfitFull;
+
 
 /**
  * @author jianlong
@@ -53,20 +55,7 @@ public class InvAccountOperateController {
     public HttpResult insertAccountOperate(@RequestBody InvAccountOperate accountOperate) {
         JSONObject outProfit = accountOperate.getOutProfit();
         JSONObject entProfit = accountOperate.getEntProfit();
-        BigDecimal outAmount = new BigDecimal(0);
-        BigDecimal entAmount = new BigDecimal(0);
-        for (Map.Entry<String, Object> entry:outProfit.entrySet()){
-            outAmount = outAmount.add(new BigDecimal(String.valueOf(entry.getValue())));
-        }
-        for (Map.Entry<String, Object> entry:entProfit.entrySet()){
-            entAmount = entAmount.add(new BigDecimal(String.valueOf(entry.getValue())));
-        }
-        if (!String.valueOf(outAmount).equals("100")){
-            throw new SystemException("支出金额未完全分配");
-        }
-        if (!String.valueOf(entAmount).equals("100")){
-            throw new SystemException("收入金额未完全分配");
-        }
+        isProfitFull(outProfit, entProfit);
         return invAccountOperateService.insert(accountOperate);
     }
 }

+ 44 - 43
src/main/java/com/ydtech/modules/inv/controller/InvReceivableController.java

@@ -1,25 +1,19 @@
 package com.ydtech.modules.inv.controller;
 
-import com.alibaba.excel.EasyExcel;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ydtech.core.page.HttpResult;
 import com.ydtech.core.page.PageResult;
 import com.ydtech.modules.base.controller.BaseController;
 import com.ydtech.modules.esm.model.EsmInsCompany;
-import com.ydtech.modules.inv.model.po.InvChannelAccount;
 import com.ydtech.modules.inv.model.po.InvSettlementSource;
 import com.ydtech.modules.inv.model.po.InvSource;
-import com.ydtech.modules.inv.model.po.QueryInvChannelAccount;
 import com.ydtech.modules.inv.model.vo.*;
-import com.ydtech.modules.inv.service.InvChannelAccountService;
 import com.ydtech.modules.inv.service.InvReceivableService;
 import com.ydtech.modules.inv.utils.EasyExcelUtils;
 import com.ydtech.modules.order.entity.BasePageResult;
-import com.ydtech.utils.excel.ExcelUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
-import org.apache.poi.ss.formula.functions.T;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
@@ -28,15 +22,12 @@ import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
 import java.time.YearMonth;
 import java.time.format.DateTimeFormatter;
 import java.util.List;
 
 
 /**
- *
  * @author jianlong
  * @date 2024-01-05 09:31
  */
@@ -57,7 +48,7 @@ public class InvReceivableController extends BaseController {
 
     @ApiOperation("应收导入数据分页查询")
     @PostMapping("receivablePage")
-    public HttpResult<PageResult> receivablePage(@RequestBody InvSourceQueryVo invSourceQueryVo){
+    public HttpResult<PageResult> receivablePage(@RequestBody InvSourceQueryVo invSourceQueryVo) {
 
         IPage<InvSource> recivablePage = invReceivableService.getRecivablePage(invSourceQueryVo);
         PageResult pageResult = buildPageResponse(recivablePage);
@@ -66,14 +57,14 @@ public class InvReceivableController extends BaseController {
 
     @ApiOperation("应收导入数据修改")
     @PostMapping("receivableUpdates")
-    public HttpResult updateRecivable(@RequestBody InvSource invSource){
+    public HttpResult updateRecivable(@RequestBody InvSource invSource) {
         Boolean b = invReceivableService.updateRecivable(invSource);
         return b ? HttpResult.ok("修改成功") : HttpResult.error("修改失败");
     }
 
     @ApiOperation("应收导入批量数据修改")
     @PostMapping("receivableUpdateBatch")
-    public HttpResult updateRecivableBatch(@RequestBody InvSource invSource){
+    public HttpResult updateRecivableBatch(@RequestBody InvSource invSource) {
         Boolean b = invReceivableService.updateRecivableBatch(invSource);
         return b ? HttpResult.ok("修改成功") : HttpResult.error("修改失败");
     }
@@ -84,23 +75,23 @@ public class InvReceivableController extends BaseController {
         List<InvSource> recivablePage = invReceivableService.getRecivableList(invSourceQueryVo);
         String uploadPath = this.uploadPath + "/excel/";
         Path path = Paths.get(uploadPath);
-        if(!Files.exists(path)){
+        if (!Files.exists(path)) {
             Files.createDirectories(path);
         }
         String fileName = EasyExcelUtils.downExcel(uploadPath, "应收表", InvSource.class, recivablePage);
-        return HttpResult.ok(uploadUrl + "excel/" +fileName);
+        return HttpResult.ok(uploadUrl + "excel/" + fileName);
     }
 
     @ApiOperation("应收导入新增")
     @PostMapping("addReceivable")
-    public HttpResult addReceivable(@RequestBody InvSource invSource){
+    public HttpResult addReceivable(@RequestBody InvSource invSource) {
         Boolean b = invReceivableService.addReceivable(invSource);
         return b ? HttpResult.ok("新增成功") : HttpResult.error("新增失败");
     }
 
     @ApiOperation("应收导入删除")
     @PostMapping("deleteReceivable")
-    public HttpResult deleteReceivable(@RequestBody String[] ids){
+    public HttpResult deleteReceivable(@RequestBody String[] ids) {
         Boolean b = invReceivableService.deleteReceivable(ids);
         return b ? HttpResult.ok("删除成功") : HttpResult.error("删除失败");
     }
@@ -108,7 +99,7 @@ public class InvReceivableController extends BaseController {
 
     @ApiOperation("结算导入数据分页查询")
     @PostMapping("settlementPage")
-    public HttpResult<PageResult> settlementPage(@RequestBody InvSettlementSourceQueryVo invSettlementSourceQueryVo){
+    public HttpResult<PageResult> settlementPage(@RequestBody InvSettlementSourceQueryVo invSettlementSourceQueryVo) {
 
         IPage<InvSettlementSource> recivablePage = invReceivableService.getSettlementPage(invSettlementSourceQueryVo);
         PageResult pageResult = buildPageResponse(recivablePage);
@@ -117,14 +108,14 @@ public class InvReceivableController extends BaseController {
 
     @ApiOperation("结算导入数据修改")
     @PostMapping("updateSettlement")
-    public HttpResult updateSettlement(@RequestBody InvSettlementSource invSettlementSource){
+    public HttpResult updateSettlement(@RequestBody InvSettlementSource invSettlementSource) {
         Boolean b = invReceivableService.updateSettlement(invSettlementSource);
         return b ? HttpResult.ok("修改成功") : HttpResult.error("修改失败");
     }
 
     @ApiOperation("结算导入数据批量修改")
     @PostMapping("updateSettlementBatch")
-    public HttpResult updateSettlementBatch(@RequestBody InvSettlementSource invSettlementSource){
+    public HttpResult updateSettlementBatch(@RequestBody InvSettlementSource invSettlementSource) {
         Boolean b = invReceivableService.updateSettlementBatch(invSettlementSource);
         return b ? HttpResult.ok("修改成功") : HttpResult.error("修改失败");
     }
@@ -135,65 +126,75 @@ public class InvReceivableController extends BaseController {
         List<InvSettlementSource> recivableList = invReceivableService.getSettlementList(invSettlementSourceQueryVo);
         String uploadPath = this.uploadPath + "/excel/";
         Path path = Paths.get(uploadPath);
-        if(!Files.exists(path)){
+        if (!Files.exists(path)) {
             Files.createDirectories(path);
         }
         String fileName = EasyExcelUtils.downExcel(uploadPath, "结算表", InvSettlementSource.class, recivableList);
-        return HttpResult.ok(uploadUrl + "excel/" +fileName);
+        return HttpResult.ok(uploadUrl + "excel/" + fileName);
+    }
+
+    @ApiOperation("结算导入删除")
+    @PostMapping("deleteSettlement")
+    public HttpResult deleteSettlement(@RequestBody String[] ids) {
+        Boolean b = invReceivableService.deleteSettlement(ids);
+        return b ? HttpResult.ok("删除成功") : HttpResult.error("删除失败");
     }
 
 
     @ApiOperation("应收结果")
     @GetMapping("receivableResult")
-    public HttpResult<BasePageResult<ReceivableResultVo>> receivableResult(String yearMonthStr,String insuranceId){
+    public HttpResult<BasePageResult<ReceivableResultVo>> receivableResult(String yearMonthStr, String insuranceId) {
         // 获取当前年月
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
         YearMonth yearMonth = YearMonth.parse(yearMonthStr, formatter);
         // 获取当前月份的最大天数
         int maxDaysInMonth = yearMonth.lengthOfMonth();
-        List<ReceivableResultVo> invChannelAccountList = invReceivableService.getReceivableList(yearMonth.toString() + "-01",yearMonth.toString() + "-" + String.valueOf(maxDaysInMonth),insuranceId);
+        List<ReceivableResultVo> invChannelAccountList = invReceivableService.getReceivableList(yearMonth + "-01",
+                yearMonth + "-" + maxDaysInMonth, insuranceId);
         BasePageResult<ReceivableResultVo> invChannelAccountBasePageResult = new BasePageResult<>(0, 0, 0, 0, invChannelAccountList);
         return HttpResult.ok(invChannelAccountBasePageResult);
     }
 
     @ApiOperation("签单日期结算来源表")
     @GetMapping("signingSourceResult")
-    public HttpResult<BasePageResult<SigningSourceResultVo>> signingSourceResult(String yearMonthStr){
+    public HttpResult<BasePageResult<SigningSourceResultVo>> signingSourceResult(String yearMonthStr, String insuranceId) {
         // 获取当前年月
         String startMonth = yearMonthStr + "-01-01";
         String endMonth = yearMonthStr + "-12-31";
-        List<SigningSourceResultVo> invChannelAccountList = invReceivableService.getSigningSourceResult(yearMonthStr,startMonth,endMonth);
+        List<SigningSourceResultVo> invChannelAccountList = invReceivableService.getSigningSourceResult(yearMonthStr, insuranceId,
+                startMonth, endMonth);
         BasePageResult<SigningSourceResultVo> invChannelAccountBasePageResult = new BasePageResult<>(0, 0, 0, 0, invChannelAccountList);
         return HttpResult.ok(invChannelAccountBasePageResult);
     }
 
     @ApiOperation("结算日期结算来源表")
     @GetMapping("settlementSourceResult")
-    public HttpResult<BasePageResult<SettlementSourceResultVo>> settlementSourceResult(String yearMonthStr,String insuranceId){
+    public HttpResult<BasePageResult<SettlementSourceResultVo>> settlementSourceResult(String yearMonthStr, String insuranceId) {
         // 获取当前年月
-        List<SettlementSourceResultVo> invChannelAccountList = invReceivableService.getSettlementSourceResult(yearMonthStr,insuranceId);
+        List<SettlementSourceResultVo> invChannelAccountList = invReceivableService.getSettlementSourceResult(yearMonthStr, insuranceId);
         BasePageResult<SettlementSourceResultVo> invChannelAccountBasePageResult = new BasePageResult<>(0, 0, 0, 0, invChannelAccountList);
         return HttpResult.ok(invChannelAccountBasePageResult);
     }
 
     @ApiOperation("同步应收表与结算表的状态")
     @GetMapping("syncStatus")
-    public HttpResult syncStatus(){
+    public HttpResult syncStatus() {
         Integer i = invReceivableService.syncStatus();
         return HttpResult.ok("同步成功,共同步" + i + "条数据");
     }
 
     @ApiOperation("获取保险公司")
     @GetMapping("getInsureCompany")
-    public HttpResult getInsureCompany(){
+    public HttpResult getInsureCompany() {
         List<EsmInsCompany> insureCompany = invReceivableService.getInsureCompany();
         return HttpResult.ok(insureCompany);
     }
 
     @ApiOperation("应收应付表")
     @PostMapping("receivableAndSettlement")
-    public HttpResult<PageResult> receivableAndSettlement(@RequestBody ReceivableAndSettlementQueryVo receivableAndSettlementQueryVo){
-        Page<ReceivableAndSettlementVo> invChannelAccountList = invReceivableService.getReceivableAndSettlementPage(receivableAndSettlementQueryVo);
+    public HttpResult<PageResult> receivableAndSettlement(@RequestBody ReceivableAndSettlementQueryVo receivableAndSettlementQueryVo) {
+        Page<ReceivableAndSettlementVo> invChannelAccountList =
+                invReceivableService.getReceivableAndSettlementPage(receivableAndSettlementQueryVo);
         PageResult pageResult = buildPageResponse(invChannelAccountList);
         return HttpResult.ok(pageResult);
     }
@@ -203,28 +204,28 @@ public class InvReceivableController extends BaseController {
     public HttpResult excelReceivableAndSettlement(@RequestBody ReceivableAndSettlementQueryVo receivableAndSettlementQueryVo) throws IOException {
         String uploadPath = this.uploadPath + "/excel/";
         Path path = Paths.get(uploadPath);
-        if(!Files.exists(path)){
+        if (!Files.exists(path)) {
             Files.createDirectories(path);
         }
-        List<ReceivableAndSettlementVo> invChannelAccountList = invReceivableService.getReceivableAndSettlementList(receivableAndSettlementQueryVo);
+        List<ReceivableAndSettlementVo> invChannelAccountList =
+                invReceivableService.getReceivableAndSettlementList(receivableAndSettlementQueryVo);
         String fileName = EasyExcelUtils.downExcel(uploadPath, "应收应付表", ReceivableAndSettlementVo.class, invChannelAccountList);
-        return HttpResult.ok(uploadUrl + "excel/" +fileName);
+        return HttpResult.ok(uploadUrl + "excel/" + fileName);
     }
 
     @ApiOperation("数据匹配")
     @GetMapping("dataMatching")
-    public HttpResult dataMatching(){
+    public HttpResult dataMatching() {
         List<String> licensenos = invReceivableService.dataMatching();
-        if(licensenos.size() > 0)
-        {
-            String msg = "";
-            for(int i=0;i<licensenos.size();i++){
-                msg += licensenos.get(i) + ",";
+        if (!licensenos.isEmpty()) {
+            StringBuilder msg = new StringBuilder();
+            for (String licenseno : licensenos) {
+                msg.append(licenseno).append(",");
             }
-            msg = msg.substring(0,msg.length()-1);
-            return HttpResult.ok("有"+licensenos.size()+"条数据与应收表数据无法匹配,其中包括:" + msg,true);
+            msg = new StringBuilder(msg.substring(0, msg.length() - 1));
+            return HttpResult.ok("有" + licensenos.size() + "条数据与应收表数据无法匹配,其中包括:" + msg, true);
         }
-        return HttpResult.ok("",false);
+        return HttpResult.ok("", false);
     }
 
 }

+ 9 - 27
src/main/java/com/ydtech/modules/inv/controller/invAccountExcelController.java

@@ -21,6 +21,8 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
+import static com.ydtech.modules.inv.utils.TransferUtils.isProfitFull;
+
 /**
  * @author jianlong
  * @date 2024-01-10 09:49
@@ -48,20 +50,8 @@ public class invAccountExcelController {
 
         JSONObject outProfit = invAccountExcel.getOutProfit();
         JSONObject entProfit = invAccountExcel.getEntProfit();
-        BigDecimal outAmount = new BigDecimal(0);
-        BigDecimal entAmount = new BigDecimal(0);
-        for (Map.Entry<String, Object> entry:outProfit.entrySet()){
-            outAmount = outAmount.add(new BigDecimal(entry.getValue().toString()));
-        }
-        for (Map.Entry<String, Object> entry:entProfit.entrySet()){
-            entAmount = entAmount.add(new BigDecimal(entry.getValue().toString()));
-        }
-        if (!String.valueOf(outAmount).equals("100")){
-            throw new SystemException("支出金额未完全分配");
-        }
-        if (!String.valueOf(entAmount).equals("100")){
-            throw new SystemException("收入金额未完全分配");
-        }
+
+        isProfitFull(outProfit, entProfit);
 
 
         if (invAccountExcel.getOutCardNum() == null && invAccountExcel.getEnterCardNum() == null) {
@@ -83,19 +73,11 @@ public class invAccountExcelController {
     public HttpResult updateAccount(@RequestBody InvAccountExcel invAccountExcel) {
         JSONObject outProfit = invAccountExcel.getOutProfit();
         JSONObject entProfit = invAccountExcel.getEntProfit();
-        BigDecimal outAmount = new BigDecimal(0);
-        BigDecimal entAmount = new BigDecimal(0);
-        for (Map.Entry<String, Object> entry:outProfit.entrySet()){
-            outAmount = outAmount.add(new BigDecimal(entry.getValue().toString()));
-        }
-        for (Map.Entry<String, Object> entry:entProfit.entrySet()){
-            entAmount = entAmount.add(new BigDecimal(entry.getValue().toString()));
-        }
-        if (!String.valueOf(outAmount).equals("100")){
-            throw new SystemException("支出金额未完全分配");
-        }
-        if (!String.valueOf(entAmount).equals("100")){
-            throw new SystemException("收入金额未完全分配");
+
+        isProfitFull(outProfit, entProfit);
+
+        if (invAccountExcel.getEnterCardNum().equals(invAccountExcel.getOutCardNum())) {
+            throw new SystemException("无法转账给本公司");
         }
 
         if (invAccountExcel.getExcelAccountOperateId() != null) {

+ 1 - 1
src/main/java/com/ydtech/modules/inv/dao/InvReceivableMapper.java

@@ -20,7 +20,7 @@ import java.util.List;
 public interface InvReceivableMapper extends BaseMapper<InvChannelAccount> {
     List<ReceivableResultVo> getReceivableList(String startTime, String endTime,String insuranceId);
 
-    List<SigningSourceResultVo> getSigningSourceResult(String startTime, String endTime);
+    List<SigningSourceResultVo> getSigningSourceResult(String startTime, String endTime, String insuranceId);
 
     List<SigningSourceResultVo> getSigningSourceDayResult(String startTime, String endTime,String insuranceId);
 

+ 2 - 0
src/main/java/com/ydtech/modules/inv/model/excel/AccountExcel.java

@@ -22,6 +22,8 @@ public class AccountExcel implements Serializable {
 
     @ExcelProperty("编号")
     private String accountId;
+    @ExcelProperty("户名")
+    private String accountName;
 
     /**
      * 开户行名称

+ 10 - 13
src/main/java/com/ydtech/modules/inv/service/InvReceivableService.java

@@ -2,32 +2,27 @@ package com.ydtech.modules.inv.service;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.baomidou.mybatisplus.extension.service.IService;
-import com.ydtech.core.page.HttpResult;
 import com.ydtech.modules.esm.model.EsmInsCompany;
-import com.ydtech.modules.inv.model.InvAccount;
 import com.ydtech.modules.inv.model.po.InvSettlementSource;
 import com.ydtech.modules.inv.model.po.InvSource;
-import com.ydtech.modules.inv.model.po.QueryInvChannelAccount;
 import com.ydtech.modules.inv.model.vo.*;
 
-import java.util.HashMap;
 import java.util.List;
 
 /**
-* @author Administrator
-* @description 针对表【ins_account(账户信息表)】的数据库操作Service
-* @createDate 2024-01-04 18:29:20
-*/
+ * @author Administrator
+ * @description 针对表【ins_account(账户信息表)】的数据库操作Service
+ * @createDate 2024-01-04 18:29:20
+ */
 public interface InvReceivableService {
 
-    List<ReceivableResultVo> getReceivableList(String startTime,String endTime,String insuranceId);
+    List<ReceivableResultVo> getReceivableList(String startTime, String endTime, String insuranceId);
 
-    List<SigningSourceResultVo> getSigningSourceResult(String yearMonthStr,String startTime, String endTime);
+    List<SigningSourceResultVo> getSigningSourceResult(String yearMonthStr, String insuranceId, String startTime, String endTime);
 
-    List<SigningSourceResultVo> getSigningSourceDayResult(String yearMonthStr,String startTime, String endTime,String insuranceId);
+    List<SigningSourceResultVo> getSigningSourceDayResult(String yearMonthStr, String startTime, String endTime, String insuranceId);
 
-    List<SettlementSourceResultVo> getSettlementSourceResult(String yearMonthStr,String insuranceId);
+    List<SettlementSourceResultVo> getSettlementSourceResult(String yearMonthStr, String insuranceId);
 
 
     IPage<InvSource> getRecivablePage(InvSourceQueryVo invSourceQueryVo);
@@ -59,4 +54,6 @@ public interface InvReceivableService {
     Boolean addReceivable(InvSource invSource);
 
     List<String> dataMatching();
+
+    Boolean deleteSettlement(String[] ids);
 }

+ 18 - 61
src/main/java/com/ydtech/modules/inv/service/impl/InvAccountExcelServiceImpl.java

@@ -17,6 +17,7 @@ import com.ydtech.modules.inv.dao.InvAccountExcelMapper;
 import com.ydtech.modules.inv.model.*;
 import com.ydtech.modules.inv.service.*;
 import com.ydtech.modules.inv.utils.EasyExcelUtils;
+import com.ydtech.modules.inv.utils.TransferUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
@@ -66,10 +67,10 @@ public class InvAccountExcelServiceImpl extends ServiceImpl<InvAccountExcelMappe
         if (!insAccountExcels.isEmpty()) {
             File folder = new File(uploadFilePath);
             if (folder.exists()) {
-                return HttpResult.ok("", easyExcelUtils.downAccountExcel(uploadFilePath, insAccountExcels,list));
+                return HttpResult.ok("", easyExcelUtils.downAccountExcel(uploadFilePath, insAccountExcels, list));
             } else {
                 if (folder.mkdirs()) {
-                    return HttpResult.ok("", easyExcelUtils.downAccountExcel(uploadFilePath, insAccountExcels,list));
+                    return HttpResult.ok("", easyExcelUtils.downAccountExcel(uploadFilePath, insAccountExcels, list));
                 } else {
                     throw new SystemException("文件导出失败");
                 }
@@ -117,16 +118,16 @@ public class InvAccountExcelServiceImpl extends ServiceImpl<InvAccountExcelMappe
         InvAccountCard enterAccountCard = invAccountCardService.getById(invAccountExcel.getEnterCardNum());
         InvAccount outAccount = insAccountService.getById(outAccountCard.getAccountId());
         InvAccount enterAccount = insAccountService.getById(enterAccountCard.getAccountId());
-
+        //操作金额
+        String applyAmount = invAccountExcel.getApplyAmount();
 
         //修改转账状态
         invAccountExcel.setTransferFlag("0");
+
         //判断是转账给内部还是外部
         if (invAccountExcel.getOutFlag().equals("0")) {
-            //转账操作
-
             //如果转账失败就返回错误
-            List<InvAccountCard> insAccountCards = insideTransfer(outAccountCard, enterAccountCard, invAccountExcel);
+            List<InvAccountCard> insAccountCards = insideTransfer(outAccountCard, outAccount, enterAccountCard, enterAccount, applyAmount);
             if (insAccountCards.isEmpty()) {
                 throw new RuntimeException("转账失败");
             }
@@ -138,82 +139,38 @@ public class InvAccountExcelServiceImpl extends ServiceImpl<InvAccountExcelMappe
             List<InvAccountOperate> list = new ArrayList<>();
             JSONObject outProfit = invAccountExcel.getOutProfit();
             JSONObject entProfit = invAccountExcel.getEntProfit();
-            InvAccountExcel out = outJsonUtil(invAccountExcel, outProfit, outAccount, outAccountCard);
-            InvAccountExcel ent = entJsonUtil(invAccountExcel, entProfit, enterAccount, enterAccountCard);
-
+            outJsonUtil(invAccountExcel, outProfit, outAccount, outAccountCard);
+            entJsonUtil(invAccountExcel, entProfit, enterAccount, enterAccountCard);
 
             //支出信息
-            list.add(insertOutAccountOperate(out));
+            list.add(insertOutAccountOperate(invAccountExcel));
             //收入信息
-            list.add(insertRevenueAccountOperate(ent));
+            list.add(insertRevenueAccountOperate(invAccountExcel));
 
             if (!insAccountOperateService.saveBatch(list)) {
                 throw new RuntimeException("添加转账信息失败");
             }
-            //重新将值赋值回去方便编辑
-            invAccountExcel.setOutProfit(outProfit);
-            invAccountExcel.setEntProfit(entProfit);
         } else {
             //内转外部转账
-            List<InvAccountCard> invAccounts = enterDeTransfer(outAccountCard, enterAccountCard, invAccountExcel);
+            List<InvAccountCard> invAccounts = enterDeTransfer(outAccountCard, outAccount, enterAccountCard, enterAccount, applyAmount);
             if (!invAccountCardService.saveBatch(invAccounts)) {
                 throw new RuntimeException("添加转账信息失败");
             }
             JSONObject outProfit = invAccountExcel.getOutProfit();
-            InvAccountExcel out = outJsonUtil(invAccountExcel, outProfit, outAccount, outAccountCard);
-            insAccountOperateService.save(insertOutAccountOperate(out));
-
-            //重新将值赋值回去方便编辑
-            invAccountExcel.setOutProfit(outProfit);
+            outJsonUtil(invAccountExcel, outProfit, outAccount, outAccountCard);
+            insAccountOperateService.save(insertOutAccountOperate(invAccountExcel));
         }
-
-
         return HttpResult.ok("", insAccountExcelMapper.updateById(invAccountExcel));
     }
 
-    private InvAccountExcel outJsonUtil(InvAccountExcel invAccountExcel, JSONObject outProfit, InvAccount outAccount, InvAccountCard outCard) {
-        JSONObject jsonObject = new JSONObject();
-        List<InvAccountOp> list = new ArrayList<>();
-
-        for (Map.Entry<String, Object> entry : outProfit.entrySet()) {
-            if (Integer.parseInt(entry.getValue().toString()) != 0) {
-                InvAccountOp invAccountOp = new InvAccountOp();
-                invAccountOp.setAccountId(outAccount.getAccountId());
-                invAccountOp.setAccountName(outAccount.getAccountName());
-                invAccountOp.setCardNum(outCard.getBankCardNum());
-                invAccountOp.setCardName(outCard.getBankName());
-                invAccountOp.setProfit(entry.getKey());
-                invAccountOp.setMoney(new BigDecimal(String.valueOf(entry.getValue())).multiply(new BigDecimal(invAccountExcel.getApplyAmount())).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP).negate().toString());
-                BigDecimal multiply = new BigDecimal(String.valueOf(entry.getValue())).multiply(new BigDecimal(invAccountExcel.getApplyAmount())).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP).negate();
-                jsonObject.put(entry.getKey(), multiply);
-                list.add(invAccountOp);
-            }
-        }
+    private void outJsonUtil(InvAccountExcel invAccountExcel, JSONObject outProfit, InvAccount outAccount, InvAccountCard outCard) {
+        List<InvAccountOp> list = invAccountOutOpList(outProfit, outAccount, outCard, invAccountExcel.getApplyAmount());
         insAccountOpService.saveBatch(list);
-        invAccountExcel.setOutProfit(jsonObject);
-        return invAccountExcel;
     }
 
-    private InvAccountExcel entJsonUtil(InvAccountExcel invAccountExcel, JSONObject outProfit, InvAccount entAccount, InvAccountCard entCard) {
-        JSONObject jsonObject = new JSONObject();
-        List<InvAccountOp> list = new ArrayList<>();
-        for (Map.Entry<String, Object> entry : outProfit.entrySet()) {
-            if (Integer.parseInt(entry.getValue().toString()) != 0) {
-                InvAccountOp invAccountOp = new InvAccountOp();
-                invAccountOp.setAccountId(entAccount.getAccountId());
-                invAccountOp.setAccountName(entAccount.getAccountName());
-                invAccountOp.setCardNum(entCard.getBankCardNum());
-                invAccountOp.setCardName(entCard.getBankName());
-                invAccountOp.setProfit(entry.getKey());
-                invAccountOp.setMoney(new BigDecimal(String.valueOf(entry.getValue())).multiply(new BigDecimal(invAccountExcel.getApplyAmount())).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP).toString());
-                BigDecimal multiply = new BigDecimal(String.valueOf(entry.getValue())).multiply(new BigDecimal(invAccountExcel.getApplyAmount())).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
-                jsonObject.put(entry.getKey(), multiply);
-                list.add(invAccountOp);
-            }
-        }
+    private void entJsonUtil(InvAccountExcel invAccountExcel, JSONObject outProfit, InvAccount entAccount, InvAccountCard entCard) {
+        List<InvAccountOp> list = invAccountEntOpList(outProfit, entAccount, entCard, invAccountExcel.getApplyAmount());
         insAccountOpService.saveBatch(list);
-        invAccountExcel.setEntProfit(jsonObject);
-        return invAccountExcel;
     }
 
 

+ 59 - 72
src/main/java/com/ydtech/modules/inv/service/impl/InvAccountIncoiceServiceImpl.java

@@ -14,6 +14,7 @@ import com.ydtech.modules.inv.model.*;
 import com.ydtech.modules.inv.model.vo.InvAccountIncoiceQueryVo;
 import com.ydtech.modules.inv.service.*;
 import com.ydtech.modules.inv.utils.EasyExcelUtils;
+import com.ydtech.modules.inv.utils.TransferUtils;
 import com.ydtech.utils.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -56,6 +57,11 @@ public class InvAccountIncoiceServiceImpl extends ServiceImpl<InvAccountIncoiceM
 
     @Override
     public HttpResult insertInvAccountIncoice(InvAccountIncoice invAccountIncoice) {
+
+        if (invAccountIncoice.getRevBankCardNum().equals(invAccountIncoice.getOutBankCardNum())) {
+            throw new SystemException("无法给本公司开票");
+        }
+
         BigDecimal tax = getBigDecimal(invAccountIncoice);
         //不含税金额
         BigDecimal noHasTax = new BigDecimal(invAccountIncoice.getInvoiceMoney()).subtract(tax);
@@ -78,19 +84,33 @@ public class InvAccountIncoiceServiceImpl extends ServiceImpl<InvAccountIncoiceM
     @Override
     public HttpResult updateInvAccountIncoice(InvAccountIncoice invAccountIncoice) {
         InvAccountIncoice invAccountIncoice1 = invAccountIncoiceMapper.selectById(invAccountIncoice.getInvoiceId());
-        InvAccount account = invAccountService.getById(invAccountIncoice1.getAccountId());
+        //支出卡号
+        String outBankCardNum = invAccountIncoice1.getOutBankCardNum();
+        //进账卡号
+        String entBankCardNum = invAccountIncoice1.getRevBankCardNum();
+        //收入卡
         InvAccountCard entCard = invAccountCardService.getById(invAccountIncoice1.getRevBankCardNum());
+        //支出卡
         InvAccountCard outCard = invAccountCardService.getById(invAccountIncoice1.getOutBankCardNum());
-        List<InvAccountOp> list = new ArrayList<>();
+        //收入账户
+        InvAccount revInvAccount = invAccountService.getById(entCard.getAccountId());
+        //支出账户
+        InvAccount outInvAccount = invAccountService.getById(outCard.getAccountId());
+        //收入金额
+        String payoutMoney = invAccountIncoice.getPayoutMoney();
 
-        if (new BigDecimal(invAccountIncoice1.getInvoiceMoney()).subtract(new BigDecimal(invAccountIncoice1.getPayoutMoney()).add(new BigDecimal(invAccountIncoice.getPayoutMoney()))).compareTo(new BigDecimal("0")) < 0) {
+        //支出归属
+        JSONObject outProfit = invAccountIncoice.getOutProfit();
+        //收入归属
+        JSONObject entProfit = invAccountIncoice.getEntProfit();
+
+
+        if (new BigDecimal(invAccountIncoice1.getInvoiceMoney()).subtract(new BigDecimal(invAccountIncoice1.getPayoutMoney()).add(new BigDecimal(payoutMoney))).compareTo(new BigDecimal("0")) < 0) {
             throw new SystemException("进账金额大于开票金额");
         }
 
-        //进账卡号
-        String bankCardNum = invAccountIncoice1.getRevBankCardNum();
+
         //进账金额
-        String payoutMoney = new BigDecimal(invAccountIncoice.getPayoutMoney()).toString();
         invAccountIncoice1.setPayoutMoney(new BigDecimal(invAccountIncoice1.getPayoutMoney()).add(new BigDecimal(payoutMoney)).toString());
         invAccountIncoice1.setNotPayoutMoney(new BigDecimal(invAccountIncoice1.getInvoiceMoney()).subtract(new BigDecimal(invAccountIncoice1.getPayoutMoney())).toString());
         invAccountIncoice1.setPayoutTime(invAccountIncoice.getPayoutTime());
@@ -99,10 +119,13 @@ public class InvAccountIncoiceServiceImpl extends ServiceImpl<InvAccountIncoiceM
             invAccountIncoice1.setClearFlag("1");
         }
 
+        //资金流出
         String fundFlow = invAccountIncoice1.getOtherUnit() + "→" + invAccountIncoice1.getInvoiceBy();
-        //修改发票增加卡的收入
+
+
+        //收入操作记录
         InvAccountOperate invAccountOperate = new InvAccountOperate();
-        invAccountOperate.setEnterCardId(bankCardNum);
+        invAccountOperate.setEnterCardId(entBankCardNum);
         invAccountOperate.setApplyAmount(payoutMoney);
         invAccountOperate.setRevenueOutlay("0");
         invAccountOperate.setFundFlow(fundFlow);
@@ -112,32 +135,11 @@ public class InvAccountIncoiceServiceImpl extends ServiceImpl<InvAccountIncoiceM
         invAccountOperate.setFundFen(invAccountIncoice.getFundFen());
         invAccountOperate.setInvoiceId(invAccountIncoice1.getInvoiceId());
         invAccountOperate.setCreateTime(LocalDateTime.now());
-        //计算收入百分比
-        JSONObject entProfit = invAccountIncoice.getEntProfit();
-        JSONObject jsonObject = new JSONObject();
-        for (Map.Entry<String, Object> entry : entProfit.entrySet()) {
-            if (Integer.parseInt(entry.getValue().toString()) != 0) {
-                BigDecimal multiply = new BigDecimal(String.valueOf(entry.getValue())).multiply(new BigDecimal(invAccountIncoice.getPayoutMoney())).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
-                jsonObject.put(entry.getKey(), multiply);
-                InvAccountOp invAccountOp = new InvAccountOp();
-                invAccountOp.setAccountId(invAccountIncoice1.getAccountId());
-                invAccountOp.setAccountName(account.getAccountName());
-                invAccountOp.setCardNum(entCard.getBankCardNum());
-                invAccountOp.setCardName(entCard.getBankName());
-                invAccountOp.setProfit(entry.getKey());
-                invAccountOp.setMoney(new BigDecimal(String.valueOf(entry.getValue())).multiply(new BigDecimal(invAccountIncoice.getPayoutMoney())).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP).toString());
-                invAccountOp.setInvoiceId(invAccountIncoice1.getInvoiceId());
-                list.add(invAccountOp);
-            }
-        }
-        invAccountOperate.setOutProfit(jsonObject);
-        invAccountOperate.setEnterCardId(invAccountIncoice.getRevBankCardNum());
-
-
+        invAccountOperate.setEntProfit(entProfit);
 
-        //支出操作
+        //支出操作记录
         InvAccountOperate outInvAccountOperate = new InvAccountOperate();
-        outInvAccountOperate.setEnterCardId(bankCardNum);
+        outInvAccountOperate.setOutCardNum(outBankCardNum);
         outInvAccountOperate.setApplyAmount(payoutMoney);
         outInvAccountOperate.setRevenueOutlay("1");
         outInvAccountOperate.setFundFlow(fundFlow);
@@ -147,52 +149,35 @@ public class InvAccountIncoiceServiceImpl extends ServiceImpl<InvAccountIncoiceM
         outInvAccountOperate.setFundFen(invAccountIncoice.getFundFen());
         outInvAccountOperate.setInvoiceId(invAccountIncoice1.getInvoiceId());
         outInvAccountOperate.setCreateTime(LocalDateTime.now());
-        //计算支出百分比
-        JSONObject outProfit = invAccountIncoice.getOutProfit();
-        JSONObject outJsonObject = new JSONObject();
-        for (Map.Entry<String, Object> entry : outProfit.entrySet()) {
-            if (Integer.parseInt(entry.getValue().toString()) != 0) {
-                BigDecimal multiply = new BigDecimal(String.valueOf(entry.getValue())).multiply(new BigDecimal(invAccountIncoice.getPayoutMoney())).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP).negate();
-                outJsonObject.put(entry.getKey(), multiply.negate());
-                InvAccountOp invAccountOp = new InvAccountOp();
-                invAccountOp.setAccountId(invAccountIncoice1.getAccountId());
-                invAccountOp.setAccountName(account.getAccountName());
-                invAccountOp.setCardNum(outCard.getBankCardNum());
-                invAccountOp.setCardName(outCard.getBankName());
-                invAccountOp.setProfit(entry.getKey());
-                invAccountOp.setMoney(new BigDecimal(String.valueOf(entry.getValue())).multiply(new BigDecimal(invAccountIncoice.getPayoutMoney())).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP).negate().toString());
-                invAccountOp.setInvoiceId(invAccountIncoice1.getInvoiceId());
-                list.add(invAccountOp);
-            }
-        }
-        outInvAccountOperate.setOutProfit(outJsonObject);
-        invAccountOperate.setEnterCardId(invAccountIncoice.getOutBankCardNum());
+        outInvAccountOperate.setOutProfit(outProfit);
+
 
+        //归属列表
+        List<InvAccountOp> list = new ArrayList<>();
+        List<InvAccountOp> list1 = invAccountEntOpList(entProfit, revInvAccount, entCard, payoutMoney);
+        List<InvAccountOp> list2 = invAccountOutOpList(outProfit, outInvAccount, outCard, payoutMoney);
+        //将发票id放入  防止撤销发票时对应归属没删掉
+        list1.forEach(invAccountOp -> {
+            invAccountOp.setInvoiceId(invAccountIncoice1.getInvoiceId());
+        });
+        list2.forEach(invAccountOp -> {
+            invAccountOp.setInvoiceId(invAccountIncoice1.getInvoiceId());
+        });
+        list.addAll(list1);
+        list.addAll(list2);
+
+        //放入操作记录list中
         List<InvAccountOperate> invAccountOperateList = new ArrayList<>();
         invAccountOperateList.add(outInvAccountOperate);
         invAccountOperateList.add(invAccountOperate);
 
 
-
-        //支出卡号
-        String outBankCardNum = invAccountIncoice1.getOutBankCardNum();
-        //支出账户
-        InvAccountCard outInvAccountCard = invAccountCardService.getById(outBankCardNum);
-        //收入账户
-        InvAccountCard revInvAccountCard = invAccountCardService.getById(bankCardNum);
-        if (outInvAccountCard == null || revInvAccountCard == null) {
-            throw new SystemException("支出账户或收入账户为空");
-        }
         //判断收款方是内部还是外部
-        InvAccount revInvAccount = invAccountService.getById(revInvAccountCard.getAccountId());
-        InvAccount outInvAccount = invAccountService.getById(outInvAccountCard.getAccountId());
-
-        //转账
         if (outInvAccount.getOuterFlag().equals("0")) {
             if (revInvAccount.getOuterFlag().equals("0")) {
                 InvAccountExcel invAccountExcel = new InvAccountExcel();
-                invAccountExcel.setApplyAmount(invAccountIncoice.getPayoutMoney());
-                List<InvAccountCard> invAccountCards = insideTransfer(outInvAccountCard, revInvAccountCard, invAccountExcel);
+                invAccountExcel.setApplyAmount(payoutMoney);
+                List<InvAccountCard> invAccountCards = insideTransfer(outCard, outInvAccount, entCard, revInvAccount, payoutMoney);
                 invAccountCardService.updateBatchById(invAccountCards);
                 invAccountOperateService.saveBatch(invAccountOperateList);
                 invAccountOpService.saveBatch(list);
@@ -200,15 +185,16 @@ public class InvAccountIncoiceServiceImpl extends ServiceImpl<InvAccountIncoiceM
             } else {
                 InvAccountExcel invAccountExcel = new InvAccountExcel();
                 invAccountExcel.setOutAccountQuality(revInvAccount.getOuterFlag());
-                invAccountExcel.setApplyAmount(invAccountIncoice.getPayoutMoney());
-                List<InvAccountCard> invAccountCards = enterDeTransfer(outInvAccountCard, revInvAccountCard, invAccountExcel);
+                invAccountExcel.setApplyAmount(payoutMoney);
+                List<InvAccountCard> invAccountCards = enterDeTransfer(outCard, outInvAccount, entCard, revInvAccount, payoutMoney);
                 invAccountCardService.updateBatchById(invAccountCards);
                 invAccountOperateService.saveBatch(invAccountOperateList);
                 invAccountOpService.saveBatch(list);
             }
         } else {
+            //转账给外部重新设置操作
             InvAccountOperate invAccountOperate1 = new InvAccountOperate();
-            invAccountOperate1.setOutCardNum(invAccountIncoice1.getOutBankCardNum());
+            invAccountOperate1.setOutCardId(invAccountIncoice1.getOutBankCardNum());
             invAccountOperate1.setEnterCardId(invAccountIncoice1.getRevBankCardNum());
             invAccountOperate1.setApplyAmount(payoutMoney);
             invAccountOperate1.setRevenueOutlay("0");
@@ -218,10 +204,11 @@ public class InvAccountIncoiceServiceImpl extends ServiceImpl<InvAccountIncoiceM
             invAccountOperate1.setFundUse(invAccountIncoice.getFundUse());
             invAccountOperate1.setFundFen(invAccountIncoice.getFundFen());
             invAccountOperate1.setInvoiceId(invAccountIncoice1.getInvoiceId());
+            invAccountOperate1.setOutProfit(outProfit);
+            invAccountOperate1.setEntProfit(entProfit);
             invAccountOperateService.insert(invAccountOperate1);
         }
 
-
         return HttpResult.ok(invAccountIncoiceMapper.updateById(invAccountIncoice1));
     }
 

+ 51 - 41
src/main/java/com/ydtech/modules/inv/service/impl/InvAccountOperateServiceImpl.java

@@ -1,6 +1,7 @@
 package com.ydtech.modules.inv.service.impl;
 
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -25,6 +26,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
+import static com.ydtech.modules.inv.utils.TransferUtils.invAccountEntOpList;
 import static com.ydtech.modules.inv.utils.TransferUtils.outsideTransfer;
 
 /**
@@ -69,15 +71,15 @@ public class InvAccountOperateServiceImpl extends ServiceImpl<InvAccountOperateM
         Page page = PageRequest.buildPageRequest(pageRequest);
         IPage<InvAccountOperate> invAccountOperateIPage = insAccountOperateMapper.selectInsAccountOperate(page, accountOperate);
         List<InvAccountOperate> records = invAccountOperateIPage.getRecords();
-        for (InvAccountOperate record:records){
+        for (InvAccountOperate record : records) {
             StringBuilder a = new StringBuilder();
-           if (record.getPayMethod() != null){
-               String[] split = record.getPayMethod().split(",");
-               for (String i : split) {
-                   a.append(InvPayMethodEnum.getNameByCode(i)).append(",");
-               }
-               record.setPayMethod(a.toString());
-           }
+            if (record.getPayMethod() != null) {
+                String[] split = record.getPayMethod().split(",");
+                for (String i : split) {
+                    a.append(InvPayMethodEnum.getNameByCode(i)).append(",");
+                }
+                record.setPayMethod(a.toString());
+            }
         }
         invAccountOperateIPage.setRecords(records);
         return invAccountOperateIPage;
@@ -85,41 +87,49 @@ public class InvAccountOperateServiceImpl extends ServiceImpl<InvAccountOperateM
 
     /**
      * 外部转内部
+     *
      * @param invAccountOperate
      * @return
      */
     @Override
     public HttpResult insert(InvAccountOperate invAccountOperate) {
-        InvAccountCard enterAccount = invAccountCardService.getById(invAccountOperate.getEnterCardId());
-        InvAccountCard outAccount = invAccountCardService.getById(invAccountOperate.getOutCardId());
+        InvAccountCard entAccountCard = invAccountCardService.getById(invAccountOperate.getEnterCardId());
+        InvAccountCard outAccountCard = invAccountCardService.getById(invAccountOperate.getOutCardId());
+        InvAccount entAccount = invAccountService.getById(entAccountCard.getAccountId());
+        InvAccount outAccoun = invAccountService.getById(outAccountCard.getAccountId());
+        String applyAmount = invAccountOperate.getApplyAmount();
+
+        JSONObject outProfit = invAccountOperate.getOutProfit();
+        JSONObject entProfit = invAccountOperate.getEntProfit();
+        if (entAccount.getOuterFlag().equals("1")) {
+            return HttpResult.error("此操作收入账户不可为外部账户");
+        }
 
-        InvAccount account = invAccountService.getById(enterAccount.getAccountId());
-        InvAccountCard invAccount = new InvAccountCard();
-        if (account.getOuterFlag().equals("0") || !enterAccount.getAccountId().equals(outAccount.getAccountId())){
-            invAccount = outsideTransfer(enterAccount, invAccountOperate);
+        if (entAccountCard.equals(outAccountCard)) {
+            for (Map.Entry<String, Object> entry : outProfit.entrySet()) {
+                for (Map.Entry<String, Object> entry2 : entProfit.entrySet()) {
+                    if (Integer.parseInt(entry.getValue().toString()) != 0 && Integer.parseInt(entry2.getValue().toString()) != 0){
+                        if (entry.getKey().equals(entry2.getKey())) {
+                            throw new SystemException("无法向同公司同板块互相转账");
+                        }
+                    }
+                }
+            }
         }
 
-        if (!invAccountCardService.updateById(invAccount)){
-            return HttpResult.error("新增收入失败");
+
+        if (entAccount.getOuterFlag().equals("0") && !entAccountCard.getAccountId().equals(outAccountCard.getAccountId())) {
+            InvAccountCard invAccount = outsideTransfer(outAccountCard, outAccoun, entAccountCard, entAccount, applyAmount);
+            invAccountCardService.updateById(invAccount);
         }
+
         invAccountOperate.setCreateTime(LocalDateTime.now());
+        invAccountOperate.setOutProfit(null);
         insAccountOperateMapper.insert(invAccountOperate);
-        List<InvAccountOp> list = new ArrayList<>();
-        if (invAccountOperate.getOutProfit()!=null){
-            for (Map.Entry<String, Object> entry:invAccountOperate.getOutProfit().entrySet()){
-                if (Integer.parseInt(entry.getValue().toString()) != 0){
-                    InvAccountOp invAccountOp = new InvAccountOp();
-                    invAccountOp.setAccountId(enterAccount.getAccountId());
-                    invAccountOp.setAccountName(account.getAccountName());
-                    invAccountOp.setCardNum(invAccount.getBankCardNum());
-                    invAccountOp.setCardName(invAccount.getBankName());
-                    invAccountOp.setProfit(entry.getKey());
-                    invAccountOp.setMoney(new BigDecimal(entry.getValue().toString()).multiply(new BigDecimal(invAccountOperate.getApplyAmount())).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP).toString());
-                    list.add(invAccountOp);
-                }
-            }
-        }
+
+        List<InvAccountOp> list = invAccountEntOpList(entProfit, entAccount, entAccountCard, applyAmount);
         invAccountOpService.saveBatch(list);
+
         return HttpResult.ok("新增收入成功");
     }
 
@@ -128,18 +138,18 @@ public class InvAccountOperateServiceImpl extends ServiceImpl<InvAccountOperateM
         List<InvAccountOperate> invAccountOperates = insAccountOperateMapper.selectInsAccountOperateList(accountOperate);
         List<InvAccountProfit> list = invAccountProfitService.list();
 
-        for (InvAccountOperate record:invAccountOperates){
+        for (InvAccountOperate record : invAccountOperates) {
             StringBuilder a = new StringBuilder();
-            if (record.getPayMethod() != null){
+            if (record.getPayMethod() != null) {
                 String[] split = record.getPayMethod().split(",");
                 for (String i : split) {
                     a.append(InvPayMethodEnum.getNameByCode(i)).append(",");
                 }
                 record.setPayMethod(a.toString());
             }
-            if (record.getOutProfit()!=null) {
+            if (record.getOutProfit() != null) {
                 StringBuffer buffer = new StringBuffer();
-                for (Map.Entry<String, Object> entry : record.getOutProfit().entrySet()){
+                for (Map.Entry<String, Object> entry : record.getOutProfit().entrySet()) {
 
                     list.forEach(invAccountProfit -> {
                         if (invAccountProfit.getProfitEng().equals(entry.getKey())) {
@@ -152,12 +162,12 @@ public class InvAccountOperateServiceImpl extends ServiceImpl<InvAccountOperateM
             }
         }
         File folder = new File(uploadFilePath);
-        if (folder.exists()){
-            return HttpResult.ok("", EasyExcelUtils.noModelOperateWrite(uploadFilePath, list,invAccountOperates));
-        }else {
-            if (folder.mkdirs()){
-                return HttpResult.ok("", EasyExcelUtils.noModelOperateWrite(uploadFilePath, list,invAccountOperates));
-            }else {
+        if (folder.exists()) {
+            return HttpResult.ok("", EasyExcelUtils.noModelOperateWrite(uploadFilePath, list, invAccountOperates));
+        } else {
+            if (folder.mkdirs()) {
+                return HttpResult.ok("", EasyExcelUtils.noModelOperateWrite(uploadFilePath, list, invAccountOperates));
+            } else {
                 throw new SystemException("文件导出失败");
             }
 

+ 1 - 0
src/main/java/com/ydtech/modules/inv/service/impl/InvAccountServiceImpl.java

@@ -247,6 +247,7 @@ public class InvAccountServiceImpl extends ServiceImpl<InvAccountMapper, InvAcco
                 invAccount.getInvAccountCardList().forEach(invAccountCard -> {
                     AccountExcel accountExcel = new AccountExcel();
                     accountExcel.setAccountId(invAccount.getAccountId());
+                    accountExcel.setAccountName(invAccount.getAccountName());
                     accountExcel.setBankName(invAccountCard.getBankName());
                    if (invAccount.getBusinessQuality() != null){
                        if (invAccount.getBusinessQuality().equals("3")){

+ 128 - 130
src/main/java/com/ydtech/modules/inv/service/impl/InvReceivableServiceImpl.java

@@ -3,21 +3,14 @@ package com.ydtech.modules.inv.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.ydtech.core.page.HttpResult;
 import com.ydtech.core.page.PageRequest;
 import com.ydtech.modules.esm.model.EsmInsCompany;
-import com.ydtech.modules.inv.dao.InvChannelAccountMapper;
 import com.ydtech.modules.inv.dao.InvReceivableMapper;
 import com.ydtech.modules.inv.dao.InvSettlementSourceMapper;
 import com.ydtech.modules.inv.dao.InvSourceMapper;
-import com.ydtech.modules.inv.model.InvAccount;
-import com.ydtech.modules.inv.model.po.InvChannelAccount;
 import com.ydtech.modules.inv.model.po.InvSettlementSource;
 import com.ydtech.modules.inv.model.po.InvSource;
-import com.ydtech.modules.inv.model.po.QueryInvChannelAccount;
 import com.ydtech.modules.inv.model.vo.*;
-import com.ydtech.modules.inv.service.InvChannelAccountService;
 import com.ydtech.modules.inv.service.InvReceivableService;
 import com.ydtech.modules.inv.service.InvSourceService;
 import com.ydtech.utils.idgen.IdGenerate;
@@ -26,7 +19,6 @@ import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.time.MonthDay;
 import java.time.YearMonth;
 import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
@@ -36,10 +28,10 @@ import java.util.List;
 import java.util.stream.Collectors;
 
 /**
-* @author Administrator
-* @description 针对表【inv_channel_account(渠道账户表)】的数据库操作Service实现
-* @createDate 2024-01-20 10:29:30
-*/
+ * @author Administrator
+ * @description 针对表【inv_channel_account(渠道账户表)】的数据库操作Service实现
+ * @createDate 2024-01-20 10:29:30
+ */
 @Service
 public class InvReceivableServiceImpl implements InvReceivableService {
     @Autowired
@@ -55,13 +47,13 @@ public class InvReceivableServiceImpl implements InvReceivableService {
     InvSettlementSourceMapper invSettlementSourceMapper;
 
     @Override
-    public List<ReceivableResultVo> getReceivableList(String startTime, String endTime,String insuranceId) {
-        return invReceivableMapper.getReceivableList(startTime,endTime,insuranceId);
+    public List<ReceivableResultVo> getReceivableList(String startTime, String endTime, String insuranceId) {
+        return invReceivableMapper.getReceivableList(startTime, endTime, insuranceId);
     }
 
     @Override
-    public List<SigningSourceResultVo> getSigningSourceResult(String yearMonthStr,String startTime, String endTime) {
-        List<SigningSourceResultVo> signingSources = invReceivableMapper.getSigningSourceResult(startTime, endTime);
+    public List<SigningSourceResultVo> getSigningSourceResult(String yearMonthStr, String insuranceId, String startTime, String endTime) {
+        List<SigningSourceResultVo> signingSources = invReceivableMapper.getSigningSourceResult(startTime, endTime, insuranceId);
         List<SigningSourceResultVo> signingSourceResult = new ArrayList<>();
 
         Float jqPremiumTax = 0f;
@@ -70,14 +62,13 @@ public class InvReceivableServiceImpl implements InvReceivableService {
         Float writtenPremium = 0f;
         Float settlementAmount = 0f;
 
-        for(int i=1;i<=12;i++){
+        for (int i = 1; i <= 12; i++) {
             //查找day是否有数据
             String finalI = i < 10 ? "0" + String.valueOf(i) : String.valueOf(i);
             boolean countBol = signingSources.stream().filter(x -> finalI.equals(x.getDay())).count() > 0 ? true : false;
-            if(countBol)
-            {
+            if (countBol) {
                 signingSourceResult.add(signingSources.stream().filter(x -> String.valueOf(finalI).equals(x.getDay())).findFirst().get());
-            }else{
+            } else {
                 SigningSourceResultVo signingSourceResultVo = new SigningSourceResultVo();
                 signingSourceResultVo.setDay(finalI);
                 signingSourceResultVo.setYearmonth(yearMonthStr + "-" + finalI);
@@ -87,7 +78,7 @@ public class InvReceivableServiceImpl implements InvReceivableService {
 
 
         //处理合计
-        for(SigningSourceResultVo vo : signingSourceResult){
+        for (SigningSourceResultVo vo : signingSourceResult) {
             jqPremiumTax = Float.parseFloat(vo.getJqPremiumTax()) + jqPremiumTax;
             syPremiumTax = Float.parseFloat(vo.getSyPremiumTax()) + syPremiumTax;
             nonCarPremiumTax = Float.parseFloat(vo.getNonCarPremiumTax()) + nonCarPremiumTax;
@@ -106,8 +97,9 @@ public class InvReceivableServiceImpl implements InvReceivableService {
     }
 
     @Override
-    public List<SigningSourceResultVo> getSigningSourceDayResult(String yearMonthStr, String startTime, String endTime,String insuranceId) {
-        List<SigningSourceResultVo> signingSources = invReceivableMapper.getSigningSourceDayResult(startTime, endTime,insuranceId);
+    public List<SigningSourceResultVo> getSigningSourceDayResult(String yearMonthStr, String startTime, String endTime,
+                                                                 String insuranceId) {
+        List<SigningSourceResultVo> signingSources = invReceivableMapper.getSigningSourceDayResult(startTime, endTime, insuranceId);
         List<SigningSourceResultVo> signingSourceResult = new ArrayList<>();
         // 定义日期时间格式
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
@@ -120,14 +112,13 @@ public class InvReceivableServiceImpl implements InvReceivableService {
         Float writtenPremium = 0f;
         Float settlementAmount = 0f;
 
-        for(int i=1;i<=maxDays;i++){
+        for (int i = 1; i <= maxDays; i++) {
             //查找day是否有数据
             String finalI = i < 10 ? "0" + String.valueOf(i) : String.valueOf(i);
             boolean countBol = signingSources.stream().filter(x -> finalI.equals(x.getDay())).count() > 0 ? true : false;
-            if(countBol)
-            {
+            if (countBol) {
                 signingSourceResult.add(signingSources.stream().filter(x -> String.valueOf(finalI).equals(x.getDay())).findFirst().get());
-            }else{
+            } else {
                 SigningSourceResultVo signingSourceResultVo = new SigningSourceResultVo();
                 signingSourceResultVo.setDay(finalI);
                 signingSourceResultVo.setYearmonth(yearMonthStr + "-" + finalI);
@@ -137,7 +128,7 @@ public class InvReceivableServiceImpl implements InvReceivableService {
 
 
         //处理合计
-        for(SigningSourceResultVo vo : signingSourceResult){
+        for (SigningSourceResultVo vo : signingSourceResult) {
             jqPremiumTax = Float.parseFloat(vo.getJqPremiumTax()) + jqPremiumTax;
             syPremiumTax = Float.parseFloat(vo.getSyPremiumTax()) + syPremiumTax;
             nonCarPremiumTax = Float.parseFloat(vo.getNonCarPremiumTax()) + nonCarPremiumTax;
@@ -174,11 +165,12 @@ public class InvReceivableServiceImpl implements InvReceivableService {
         String[] next12MonthsDates = getNext12MonthsDates(yearMonth);
         int maxDays = yearMonth.lengthOfMonth();
         //获取签单数据
-        List<SigningSourceResultVo> signingSources = invReceivableMapper.getSigningSourceDayResult(yearMonthStr + "-01", yearMonthStr + "-" + maxDays,insuranceId);
+        List<SigningSourceResultVo> signingSources = invReceivableMapper.getSigningSourceDayResult(yearMonthStr + "-01", yearMonthStr +
+                "-" + maxDays, insuranceId);
         //转换类型
         List<SettlementSourceResultVo> settlementSourcesTmp = new ArrayList<>();
         List<SettlementSourceResultVo> settlementSources = new ArrayList<>();
-        signingSources.forEach(signing->{
+        signingSources.forEach(signing -> {
             SettlementSourceResultVo settlementSourceResultVo = new SettlementSourceResultVo();
             settlementSourceResultVo.setDay(signing.getDay());
             settlementSourceResultVo.setSignDate(signing.getYearmonth());
@@ -188,47 +180,44 @@ public class InvReceivableServiceImpl implements InvReceivableService {
             settlementSourcesTmp.add(settlementSourceResultVo);
         });
 
-        for(int i=1;i<=maxDays;i++)
-        {
+        for (int i = 1; i <= maxDays; i++) {
             //查找day是否有数据
             String finalI = i < 10 ? "0" + String.valueOf(i) : String.valueOf(i);
             boolean countBol = settlementSourcesTmp.stream().filter(x -> finalI.equals(x.getDay())).count() > 0 ? true : false;
-            if(!countBol)
-            {
+            if (!countBol) {
                 SettlementSourceResultVo settlementSourceResultVo = new SettlementSourceResultVo();
                 settlementSourceResultVo.setDay(finalI);
                 settlementSourceResultVo.setSignDate(yearMonthStr + "-" + finalI);
                 settlementSources.add(settlementSourceResultVo);
-            }else{
+            } else {
                 settlementSources.add(settlementSourcesTmp.stream().filter(x -> finalI.equals(x.getDay())).findFirst().get());
             }
         }
 
         int year = yearMonth.getYear();
         //遍历结算数据
-        settlementSources.forEach(signing->{
+        settlementSources.forEach(signing -> {
 //            String startTime = String.valueOf(year) + "-01-01";
 //            String endTime = String.valueOf(year) + "-12-31";
             String startTime = next12MonthsDates[0] + "-01";
             int day = YearMonth.parse(next12MonthsDates[11], formatter).lengthOfMonth();
             String endTime = next12MonthsDates[11] + "-" + day;
             List<SettlementSourceDataVo> settlementSourceResultTmp =
-                    invReceivableMapper.getSettlementSourceResult(signing.getSignDate(),startTime, endTime, insuranceId);
+                    invReceivableMapper.getSettlementSourceResult(signing.getSignDate(), startTime, endTime, insuranceId);
             List<SettlementSourceDataVo> settlementSourceResult = new ArrayList<>();
             System.out.printf("1");
             //补齐数据
-            for(int i=0;i<12;i++)
-            {
+            for (int i = 0; i < 12; i++) {
                 //查找day是否有数据
                 String month = next12MonthsDates[i];
-                boolean countBol = settlementSourceResultTmp.stream().filter(x -> month.equals(x.getSettlementDate())).count() > 0 ? true : false;
-                if(!countBol)
-                {
+                boolean countBol = settlementSourceResultTmp.stream().filter(x -> month.equals(x.getSettlementDate())).count() > 0 ?
+                        true : false;
+                if (!countBol) {
                     SettlementSourceDataVo settlementSourceData = new SettlementSourceDataVo();
                     settlementSourceData.setDay(month);
                     settlementSourceData.setSettlementDate(next12MonthsDates[i]);
                     settlementSourceResult.add(settlementSourceData);
-                }else{
+                } else {
                     settlementSourceResult.add(settlementSourceResultTmp.stream().filter(x -> month.equals(x.getSettlementDate())).findFirst().get());
                 }
             }
@@ -237,12 +226,12 @@ public class InvReceivableServiceImpl implements InvReceivableService {
 
 
         //计算每个日期的签单保费 和代理人佣金
-        settlementSources.forEach(settlementSource->{
+        settlementSources.forEach(settlementSource -> {
             int length = settlementSource.getSettlementData().size();
             BigDecimal settlementPremium = new BigDecimal(0);
             BigDecimal agentCommission = new BigDecimal(0);
             //横向计算
-            for(int i=0;i<length;i++){
+            for (int i = 0; i < length; i++) {
                 SettlementSourceDataVo settlementSourceData = settlementSource.getSettlementData().get(i);
                 settlementPremium = settlementPremium.add(settlementSourceData.getSettlementPremium());
                 agentCommission = agentCommission.add(settlementSourceData.getAgentCommission());
@@ -260,7 +249,7 @@ public class InvReceivableServiceImpl implements InvReceivableService {
         // 计算每个日期的签单保费 和代理人佣金 竖向计算
         List<SettlementSourceDataVo> settlementSourceDataSum = new ArrayList<>();
 
-        for(int i=0;i<12;i++){
+        for (int i = 0; i < 12; i++) {
             //提取每个月的数据
 //            String finalI = i < 10 ? "0" + String.valueOf(i) : String.valueOf(i);
             String month = next12MonthsDates[i];
@@ -269,11 +258,11 @@ public class InvReceivableServiceImpl implements InvReceivableService {
             BigDecimal settlementPremium = new BigDecimal(0);
             BigDecimal agentCommission = new BigDecimal(0);
 
-            for(int j=0;j<settlementSources.size();j++){
+            for (int j = 0; j < settlementSources.size(); j++) {
 
-                List<SettlementSourceDataVo> collect = settlementSources.get(j).getSettlementData().stream().filter(x -> x.getSettlementDate() != null && x.getSettlementDate().equals(month)).collect(Collectors.toList());
-                for(int k=0;k<collect.size();k++)
-                {
+                List<SettlementSourceDataVo> collect =
+                        settlementSources.get(j).getSettlementData().stream().filter(x -> x.getSettlementDate() != null && x.getSettlementDate().equals(month)).collect(Collectors.toList());
+                for (int k = 0; k < collect.size(); k++) {
                     settlementPremium = settlementPremium.add(collect.get(k).getAgentCommission());
                     agentCommission = agentCommission.add(collect.get(k).getAgentCommission());
                 }
@@ -287,7 +276,8 @@ public class InvReceivableServiceImpl implements InvReceivableService {
 
         //未结算签单保费 与 已结算利润计算
         settlementSources.forEach(settlementSource -> {
-            SettlementSourceDataVo settlementSourceDataVo = settlementSource.getSettlementData().stream().filter(x -> !"合计".equals(x.getSettlementDate())).findFirst().get();
+            SettlementSourceDataVo settlementSourceDataVo =
+                    settlementSource.getSettlementData().stream().filter(x -> !"合计".equals(x.getSettlementDate())).findFirst().get();
             settlementSource.setUnCalculatedAmount(settlementSource.getSignPremium().subtract(settlementSourceDataVo.getSettlementPremium()));
             settlementSource.setSettledProfit(settlementSource.getSignReceivableAmount().subtract(settlementSourceDataVo.getAgentCommission()));
         });
@@ -295,25 +285,29 @@ public class InvReceivableServiceImpl implements InvReceivableService {
         //计算代理人佣金
         List<HashMap> maxReceivable = invReceivableMapper.getMaxReceivable(yearMonthStr + "-01", yearMonthStr + "-" + maxDays);
         settlementSources.forEach(settlementSource -> {
-            Boolean b = maxReceivable.stream().filter(x -> settlementSource.getSignDate().equals(x.get("yeatmonth"))).findFirst().isPresent();
-            if(!b)
-            {
+            Boolean b =
+                    maxReceivable.stream().filter(x -> settlementSource.getSignDate().equals(x.get("yeatmonth"))).findFirst().isPresent();
+            if (!b) {
                 settlementSource.setAgentAmount(new BigDecimal(0));
-            }else{
-                HashMap max = maxReceivable.stream().filter(x -> settlementSource.getSignDate().equals(x.get("yeatmonth"))).findFirst().get();
-                SettlementSourceDataVo settlementSourceDataVo = settlementSource.getSettlementData().get(settlementSource.getSettlementData().size() - 1);
+            } else {
+                HashMap max =
+                        maxReceivable.stream().filter(x -> settlementSource.getSignDate().equals(x.get("yeatmonth"))).findFirst().get();
+                SettlementSourceDataVo settlementSourceDataVo =
+                        settlementSource.getSettlementData().get(settlementSource.getSettlementData().size() - 1);
                 settlementSource.setAgentAmount(new BigDecimal(max.get("receivable").toString()).subtract(settlementSourceDataVo.getAgentCommission()));
             }
         });
         //计算未结算利润测算
-        List<HashMap> unsettledProfitCalculation = invReceivableMapper.getUnsettledProfitCalculation(yearMonthStr + "-01", yearMonthStr + "-" + maxDays);
+        List<HashMap> unsettledProfitCalculation = invReceivableMapper.getUnsettledProfitCalculation(yearMonthStr + "-01",
+                yearMonthStr + "-" + maxDays);
         settlementSources.forEach(settlementSource -> {
-            Boolean b = unsettledProfitCalculation.stream().filter(x -> settlementSource.getSignDate().equals(x.get("yeatmonth"))).findFirst().isPresent();
-            if(!b)
-            {
+            Boolean b =
+                    unsettledProfitCalculation.stream().filter(x -> settlementSource.getSignDate().equals(x.get("yeatmonth"))).findFirst().isPresent();
+            if (!b) {
                 settlementSource.setUnsettledProfitCalculation(new BigDecimal(0));
-            }else{
-                HashMap max = unsettledProfitCalculation.stream().filter(x -> settlementSource.getSignDate().equals(x.get("yeatmonth"))).findFirst().get();
+            } else {
+                HashMap max =
+                        unsettledProfitCalculation.stream().filter(x -> settlementSource.getSignDate().equals(x.get("yeatmonth"))).findFirst().get();
                 settlementSource.setUnsettledProfitCalculation(new BigDecimal(max.get("unsettled_profit_calculation").toString()));
             }
         });
@@ -338,7 +332,6 @@ public class InvReceivableServiceImpl implements InvReceivableService {
         }
 
 
-
         //合计
         SettlementSourceResultVo settlementSourceResultVo = new SettlementSourceResultVo();
         settlementSourceResultVo.setSignDate("合计");
@@ -359,14 +352,12 @@ public class InvReceivableServiceImpl implements InvReceivableService {
         pageRequest.setPageNum(invSourceQueryVo.getPageNum());
         pageRequest.setPageSize(invSourceQueryVo.getPageSize());
         Page page = PageRequest.buildPageRequest(pageRequest);
-        if(invSourceQueryVo.getSigningTime() != null && !"".equals(invSourceQueryVo.getSigningTime()))
-        {
+        if (invSourceQueryVo.getSigningTime() != null && !"".equals(invSourceQueryVo.getSigningTime())) {
             String[] split = invSourceQueryVo.getSigningTime().split(",");
             invSourceQueryVo.setSigningTimeStartTime(split[0]);
             invSourceQueryVo.setSigningTimeEndTime(split[1]);
         }
-        if(invSourceQueryVo.getClearingTime() != null && !"".equals(invSourceQueryVo.getClearingTime()))
-        {
+        if (invSourceQueryVo.getClearingTime() != null && !"".equals(invSourceQueryVo.getClearingTime())) {
             String[] split1 = invSourceQueryVo.getClearingTime().split(",");
             invSourceQueryVo.setClearingTimeStartTime(split1[0]);
             invSourceQueryVo.setClearingTimeEndTime(split1[1]);
@@ -375,7 +366,7 @@ public class InvReceivableServiceImpl implements InvReceivableService {
 
         Page<InvSource> pageData = invSourceMapper.getRecivablePage(page, invSourceQueryVo);
         List<InvSource> records = pageData.getRecords();
-        records.forEach(x->{
+        records.forEach(x -> {
             x.setClearingState("0".equals(x.getClearingState()) ? "未结算" : "1".equals(x.getClearingState()) ? "已结算" :
                     "2".equals(x.getClearingState()) ? "孤儿单" : x.getClearingState());
             x.setInsuranceClearingState("0".equals(x.getInsuranceClearingState()) ? "未结算" :
@@ -387,16 +378,19 @@ public class InvReceivableServiceImpl implements InvReceivableService {
 
     @Override
     public List<InvSource> getRecivableList(InvSourceQueryVo invSourceQueryVo) {
-        String[] split = invSourceQueryVo.getSigningTime().split(",");
-        invSourceQueryVo.setSigningTimeStartTime(split[0]);
-        invSourceQueryVo.setSigningTimeEndTime(split[1]);
-
-        String[] split1 = invSourceQueryVo.getClearingTime().split(",");
-        invSourceQueryVo.setClearingTimeStartTime(split1[0]);
-        invSourceQueryVo.setClearingTimeEndTime(split1[1]);
+        if (invSourceQueryVo.getSigningTime() != null && !"".equals(invSourceQueryVo.getSigningTime())) {
+            String[] split = invSourceQueryVo.getSigningTime().split(",");
+            invSourceQueryVo.setSigningTimeStartTime(split[0]);
+            invSourceQueryVo.setSigningTimeEndTime(split[1]);
+        }
+        if (invSourceQueryVo.getClearingTime() != null && !"".equals(invSourceQueryVo.getClearingTime())) {
+            String[] split1 = invSourceQueryVo.getClearingTime().split(",");
+            invSourceQueryVo.setClearingTimeStartTime(split1[0]);
+            invSourceQueryVo.setClearingTimeEndTime(split1[1]);
+        }
 
         List<InvSource> pageData = invSourceMapper.getRecivableList(invSourceQueryVo);
-        pageData.forEach(x->{
+        pageData.forEach(x -> {
             x.setClearingState("0".equals(x.getClearingState()) ? "未结算" : "1".equals(x.getClearingState()) ? "已结算" :
                     "2".equals(x.getClearingState()) ? "孤儿单" : x.getClearingState());
             x.setInsuranceClearingState("0".equals(x.getInsuranceClearingState()) ? "未结算" :
@@ -407,13 +401,13 @@ public class InvReceivableServiceImpl implements InvReceivableService {
 
     @Override
     public Boolean updateRecivable(InvSource invSource) {
-        BigDecimal tax = new BigDecimal(1.06);
+        BigDecimal tax = BigDecimal.valueOf(1.06);
         //处理交强不含税
-        invSource.setJqPremium(invSource.getJqPremiumTax().divide(tax,2, RoundingMode.HALF_UP));
+        invSource.setJqPremium(invSource.getJqPremiumTax().divide(tax, 2, RoundingMode.HALF_UP));
         //处理商业不含税
-        invSource.setSyPremium(invSource.getSyPremiumTax().divide(tax,2, RoundingMode.HALF_UP));
+        invSource.setSyPremium(invSource.getSyPremiumTax().divide(tax, 2, RoundingMode.HALF_UP));
         //处理非车不含税
-        invSource.setNonCarPremium(invSource.getNonCarPremiumTax().divide(tax,2, RoundingMode.HALF_UP));
+        invSource.setNonCarPremium(invSource.getNonCarPremiumTax().divide(tax, 2, RoundingMode.HALF_UP));
 
         //处理非跟单比例
         invSource.setJqNonCopyingRatio(invSource.getJqReceivableRatio().subtract(invSource.getJqPremiumRatio()));
@@ -452,7 +446,7 @@ public class InvReceivableServiceImpl implements InvReceivableService {
                 "已结算".equals(invSource.getClearingState()) ? "1" : invSource.getClearingState());
         invSource.setInsuranceClearingState("未结算".equals(invSource.getInsuranceClearingState()) ? "0" :
                 "已结算".equals(invSource.getInsuranceClearingState()) ? "1" : invSource.getInsuranceClearingState());
-        return invSourceMapper.updateById(invSource) > 0 ? true : false;
+        return invSourceMapper.updateById(invSource) > 0;
     }
 
     @Override
@@ -462,44 +456,40 @@ public class InvReceivableServiceImpl implements InvReceivableService {
         pageRequest.setPageSize(invSettlementSourceQueryVo.getPageSize());
         Page page = PageRequest.buildPageRequest(pageRequest);
         LambdaQueryWrapper<InvSettlementSource> queryWrapper = new LambdaQueryWrapper<>();
-        if(invSettlementSourceQueryVo.getLicenseno() != null && !"".equals(invSettlementSourceQueryVo.getLicenseno())){
-            queryWrapper.eq(InvSettlementSource::getLicenseno,invSettlementSourceQueryVo.getLicenseno());
+        if (invSettlementSourceQueryVo.getLicenseno() != null && !"".equals(invSettlementSourceQueryVo.getLicenseno())) {
+            queryWrapper.eq(InvSettlementSource::getLicenseno, invSettlementSourceQueryVo.getLicenseno());
         }
-        if(invSettlementSourceQueryVo.getJqPolicyId() != null && !"".equals(invSettlementSourceQueryVo.getJqPolicyId())){
-            queryWrapper.eq(InvSettlementSource::getJqPolicyId,invSettlementSourceQueryVo.getJqPolicyId());
+        if (invSettlementSourceQueryVo.getJqPolicyId() != null && !"".equals(invSettlementSourceQueryVo.getJqPolicyId())) {
+            queryWrapper.eq(InvSettlementSource::getJqPolicyId, invSettlementSourceQueryVo.getJqPolicyId());
         }
-        if(invSettlementSourceQueryVo.getSyPolicyId() != null && !"".equals(invSettlementSourceQueryVo.getSyPolicyId())){
-            queryWrapper.eq(InvSettlementSource::getSyPolicyId,invSettlementSourceQueryVo.getSyPolicyId());
+        if (invSettlementSourceQueryVo.getSyPolicyId() != null && !"".equals(invSettlementSourceQueryVo.getSyPolicyId())) {
+            queryWrapper.eq(InvSettlementSource::getSyPolicyId, invSettlementSourceQueryVo.getSyPolicyId());
         }
-        if(invSettlementSourceQueryVo.getNonCarPolicyId() != null && !"".equals(invSettlementSourceQueryVo.getNonCarPolicyId())){
-            queryWrapper.eq(InvSettlementSource::getNonCarPolicyId,invSettlementSourceQueryVo.getNonCarPolicyId());
+        if (invSettlementSourceQueryVo.getNonCarPolicyId() != null && !"".equals(invSettlementSourceQueryVo.getNonCarPolicyId())) {
+            queryWrapper.eq(InvSettlementSource::getNonCarPolicyId, invSettlementSourceQueryVo.getNonCarPolicyId());
         }
-        if(invSettlementSourceQueryVo.getInsuranceId() != null && !"".equals(invSettlementSourceQueryVo.getInsuranceId())){
-            queryWrapper.in(InvSettlementSource::getInsuranceId,invSettlementSourceQueryVo.getInsuranceId());
+        if (invSettlementSourceQueryVo.getInsuranceId() != null && !"".equals(invSettlementSourceQueryVo.getInsuranceId())) {
+            queryWrapper.in(InvSettlementSource::getInsuranceId, invSettlementSourceQueryVo.getInsuranceId());
         }
-        if(invSettlementSourceQueryVo.getInsuranceType() != null && !"".equals(invSettlementSourceQueryVo.getInsuranceType())){
-            queryWrapper.eq(InvSettlementSource::getInsuranceType,invSettlementSourceQueryVo.getInsuranceType());
+        if (invSettlementSourceQueryVo.getInsuranceType() != null && !"".equals(invSettlementSourceQueryVo.getInsuranceType())) {
+            queryWrapper.eq(InvSettlementSource::getInsuranceType, invSettlementSourceQueryVo.getInsuranceType());
         }
-        if(invSettlementSourceQueryVo.getSignDate() != null && !"".equals(invSettlementSourceQueryVo.getSignDate()))
-        {
+        if (invSettlementSourceQueryVo.getSignDate() != null && !"".equals(invSettlementSourceQueryVo.getSignDate())) {
             String[] split = invSettlementSourceQueryVo.getSignDate().split(",");
-            queryWrapper.between(InvSettlementSource::getSignDate,split[0],split[1]);
+            queryWrapper.between(InvSettlementSource::getSignDate, split[0], split[1]);
         }
-        if(invSettlementSourceQueryVo.getAgencySettlementTime() != null && !"".equals(invSettlementSourceQueryVo.getAgencySettlementTime()))
-        {
+        if (invSettlementSourceQueryVo.getAgencySettlementTime() != null && !"".equals(invSettlementSourceQueryVo.getAgencySettlementTime())) {
             String[] split = invSettlementSourceQueryVo.getAgencySettlementTime().split(",");
-            queryWrapper.between(InvSettlementSource::getAgencySettlementTime,split[0],split[1]);
+            queryWrapper.between(InvSettlementSource::getAgencySettlementTime, split[0], split[1]);
         }
-        if(invSettlementSourceQueryVo.getChannel() != null && !"".equals(invSettlementSourceQueryVo.getChannel()))
-        {
-            queryWrapper.eq(InvSettlementSource::getChannel,invSettlementSourceQueryVo.getChannel());
+        if (invSettlementSourceQueryVo.getChannel() != null && !"".equals(invSettlementSourceQueryVo.getChannel())) {
+            queryWrapper.eq(InvSettlementSource::getChannel, invSettlementSourceQueryVo.getChannel());
         }
-        if(invSettlementSourceQueryVo.getChannelClassification() != null && !"".equals(invSettlementSourceQueryVo.getChannelClassification()))
-        {
-            queryWrapper.eq(InvSettlementSource::getChannelClassification,invSettlementSourceQueryVo.getChannelClassification());
+        if (invSettlementSourceQueryVo.getChannelClassification() != null && !"".equals(invSettlementSourceQueryVo.getChannelClassification())) {
+            queryWrapper.eq(InvSettlementSource::getChannelClassification, invSettlementSourceQueryVo.getChannelClassification());
         }
-        if(invSettlementSourceQueryVo.getInsuredName() != null && !"".equals(invSettlementSourceQueryVo.getInsuredName())){
-            queryWrapper.like(InvSettlementSource::getInsuredName,invSettlementSourceQueryVo.getInsuredName());
+        if (invSettlementSourceQueryVo.getInsuredName() != null && !"".equals(invSettlementSourceQueryVo.getInsuredName())) {
+            queryWrapper.like(InvSettlementSource::getInsuredName, invSettlementSourceQueryVo.getInsuredName());
         }
         Page pageData = invSettlementSourceMapper.selectPage(page, queryWrapper);
 
@@ -509,28 +499,27 @@ public class InvReceivableServiceImpl implements InvReceivableService {
     @Override
     public List<InvSettlementSource> getSettlementList(InvSettlementSourceQueryVo invSettlementSourceQueryVo) {
         LambdaQueryWrapper<InvSettlementSource> queryWrapper = new LambdaQueryWrapper<>();
-        if(invSettlementSourceQueryVo.getLicenseno() != null && !"".equals(invSettlementSourceQueryVo.getLicenseno())){
-            queryWrapper.eq(InvSettlementSource::getLicenseno,invSettlementSourceQueryVo.getLicenseno());
+        if (invSettlementSourceQueryVo.getLicenseno() != null && !"".equals(invSettlementSourceQueryVo.getLicenseno())) {
+            queryWrapper.eq(InvSettlementSource::getLicenseno, invSettlementSourceQueryVo.getLicenseno());
         }
-        if(invSettlementSourceQueryVo.getJqPolicyId() != null && !"".equals(invSettlementSourceQueryVo.getJqPolicyId())){
-            queryWrapper.eq(InvSettlementSource::getJqPolicyId,invSettlementSourceQueryVo.getJqPolicyId());
+        if (invSettlementSourceQueryVo.getJqPolicyId() != null && !"".equals(invSettlementSourceQueryVo.getJqPolicyId())) {
+            queryWrapper.eq(InvSettlementSource::getJqPolicyId, invSettlementSourceQueryVo.getJqPolicyId());
         }
-        if(invSettlementSourceQueryVo.getSyPolicyId() != null && !"".equals(invSettlementSourceQueryVo.getSyPolicyId())){
-            queryWrapper.eq(InvSettlementSource::getSyPolicyId,invSettlementSourceQueryVo.getSyPolicyId());
+        if (invSettlementSourceQueryVo.getSyPolicyId() != null && !"".equals(invSettlementSourceQueryVo.getSyPolicyId())) {
+            queryWrapper.eq(InvSettlementSource::getSyPolicyId, invSettlementSourceQueryVo.getSyPolicyId());
         }
-        if(invSettlementSourceQueryVo.getNonCarPolicyId() != null && !"".equals(invSettlementSourceQueryVo.getNonCarPolicyId())){
-            queryWrapper.eq(InvSettlementSource::getNonCarPolicyId,invSettlementSourceQueryVo.getNonCarPolicyId());
+        if (invSettlementSourceQueryVo.getNonCarPolicyId() != null && !"".equals(invSettlementSourceQueryVo.getNonCarPolicyId())) {
+            queryWrapper.eq(InvSettlementSource::getNonCarPolicyId, invSettlementSourceQueryVo.getNonCarPolicyId());
         }
-        if(invSettlementSourceQueryVo.getInsuranceId() != null && !"".equals(invSettlementSourceQueryVo.getInsuranceId())){
-            queryWrapper.in(InvSettlementSource::getInsuranceId,invSettlementSourceQueryVo.getInsuranceId());
+        if (invSettlementSourceQueryVo.getInsuranceId() != null && !"".equals(invSettlementSourceQueryVo.getInsuranceId())) {
+            queryWrapper.in(InvSettlementSource::getInsuranceId, invSettlementSourceQueryVo.getInsuranceId());
         }
-        if(invSettlementSourceQueryVo.getInsuranceType() != null && !"".equals(invSettlementSourceQueryVo.getInsuranceType())){
-            queryWrapper.eq(InvSettlementSource::getInsuranceType,invSettlementSourceQueryVo.getInsuranceType());
+        if (invSettlementSourceQueryVo.getInsuranceType() != null && !"".equals(invSettlementSourceQueryVo.getInsuranceType())) {
+            queryWrapper.eq(InvSettlementSource::getInsuranceType, invSettlementSourceQueryVo.getInsuranceType());
         }
-        if(invSettlementSourceQueryVo.getSignDate() != null && !"".equals(invSettlementSourceQueryVo.getSignDate()))
-        {
+        if (invSettlementSourceQueryVo.getSignDate() != null && !"".equals(invSettlementSourceQueryVo.getSignDate())) {
             String[] split = invSettlementSourceQueryVo.getSignDate().split(",");
-            queryWrapper.between(InvSettlementSource::getSignDate,split[0],split[1]);
+            queryWrapper.between(InvSettlementSource::getSignDate, split[0], split[1]);
         }
         List<InvSettlementSource> pageData = invSettlementSourceMapper.selectList(queryWrapper);
 
@@ -564,19 +553,21 @@ public class InvReceivableServiceImpl implements InvReceivableService {
         Page page = new Page();
         page.setCurrent(receivableAndSettlementQueryVo.getPageNum());
         page.setSize(receivableAndSettlementQueryVo.getPageSize());
-        Page<ReceivableAndSettlementVo> receivableAndSettlementPage = invReceivableMapper.getReceivableAndSettlementPage(page, receivableAndSettlementQueryVo);
+        Page<ReceivableAndSettlementVo> receivableAndSettlementPage = invReceivableMapper.getReceivableAndSettlementPage(page,
+                receivableAndSettlementQueryVo);
         return receivableAndSettlementPage;
     }
 
     @Override
     public List<ReceivableAndSettlementVo> getReceivableAndSettlementList(ReceivableAndSettlementQueryVo receivableAndSettlementQueryVo) {
-        List<ReceivableAndSettlementVo> receivableAndSettlementVoList = invReceivableMapper.getReceivableAndSettlementPage(receivableAndSettlementQueryVo);
+        List<ReceivableAndSettlementVo> receivableAndSettlementVoList =
+                invReceivableMapper.getReceivableAndSettlementPage(receivableAndSettlementQueryVo);
         return receivableAndSettlementVoList;
     }
 
     @Override
     public Boolean deleteReceivable(String[] ids) {
-        return invReceivableMapper.deleteReceivable(String.join(",",ids));
+        return invReceivableMapper.deleteReceivable(String.join(",", ids));
     }
 
     @Override
@@ -611,11 +602,11 @@ public class InvReceivableServiceImpl implements InvReceivableService {
         invSource.builder();
         BigDecimal tax = new BigDecimal(1.06);
         //处理交强不含税
-        invSource.setJqPremium(invSource.getJqPremiumTax().divide(tax,2, RoundingMode.HALF_UP));
+        invSource.setJqPremium(invSource.getJqPremiumTax().divide(tax, 2, RoundingMode.HALF_UP));
         //处理商业不含税
-        invSource.setSyPremium(invSource.getSyPremiumTax().divide(tax,2, RoundingMode.HALF_UP));
+        invSource.setSyPremium(invSource.getSyPremiumTax().divide(tax, 2, RoundingMode.HALF_UP));
         //处理非车不含税
-        invSource.setNonCarPremium(invSource.getNonCarPremiumTax().divide(tax,2, RoundingMode.HALF_UP));
+        invSource.setNonCarPremium(invSource.getNonCarPremiumTax().divide(tax, 2, RoundingMode.HALF_UP));
 
         //处理非跟单比例
         invSource.setJqNonCopyingRatio(invSource.getJqReceivableRatio().subtract(invSource.getJqPremiumRatio()));
@@ -650,7 +641,7 @@ public class InvReceivableServiceImpl implements InvReceivableService {
                 invSource.getJqPremiumTax().multiply(invSource.getMaxJqReceivableRatio())
                         .add(invSource.getSyPremiumTax().multiply(invSource.getMaxSyReceivableRatio()))
                         .add(invSource.getNonCarPremiumTax().multiply(invSource.getMaxNonCarReceivableRatio())));
-        boolean save = invSourceMapper.insert (invSource) > 0 ? true : false;
+        boolean save = invSourceMapper.insert(invSource) > 0 ? true : false;
         return save;
     }
 
@@ -660,6 +651,13 @@ public class InvReceivableServiceImpl implements InvReceivableService {
         return data;
     }
 
+    @Override
+    public Boolean deleteSettlement(String[] ids) {
+        List<String> list = Arrays.asList(ids);
+        int i = invSettlementSourceMapper.deleteBatchIds(list);
+        return i > 0 ? true : false;
+    }
+
 }
 
 

+ 9 - 2
src/main/java/com/ydtech/modules/inv/utils/EasyExcelUtils.java

@@ -167,7 +167,7 @@ public class EasyExcelUtils {
             data.add(invAccountOperate.getFundUse());
             data.add(invAccountOperate.getFundFen());
             data.add(invAccountOperate.getApplyAmount());
-            data.add(invAccountOperate.getRevenueOutlay().equals("0")?"收入":"支出");
+            data.add(invAccountOperate.getRevenueOutlay().equals("0") ? "收入" : "支出");
             invAccountProfitList.forEach(invAccountProfit -> {
                 if (invAccountOperate.getOutProfit() != null) {
                     for (Map.Entry<String, Object> entry : invAccountOperate.getOutProfit().entrySet()) {
@@ -176,6 +176,13 @@ public class EasyExcelUtils {
                         }
                     }
                 }
+                if (invAccountOperate.getEntProfit() != null){
+                    for (Map.Entry<String, Object> entry : invAccountOperate.getEntProfit().entrySet()) {
+                        if (entry.getKey().equals(invAccountProfit.getProfitEng())) {
+                            data.add(entry.getValue());
+                        }
+                    }
+                }
             });
             list.add(data);
         });
@@ -216,7 +223,7 @@ public class EasyExcelUtils {
     /**
      * 导出资金申请模板
      */
-    public String downAccountExcel(String uploadFilePath, List<InvAccountExcel> invAccountExcel,List<InvAccountProfit> invAccountProfit) {
+    public String downAccountExcel(String uploadFilePath, List<InvAccountExcel> invAccountExcel, List<InvAccountProfit> invAccountProfit) {
         // 加载模板
         String templateFile = "资金申请单模板.xlsx";
         List<InvAccountExcel> list = new ArrayList<>();

+ 222 - 128
src/main/java/com/ydtech/modules/inv/utils/TransferUtils.java

@@ -18,6 +18,60 @@ import java.util.Map;
  * @date 2024-01-10 14:10
  */
 public class TransferUtils {
+    /**
+     * 插入收入归属
+     * @param entProfit
+     * @param entAccount
+     * @param entAccountCard
+     * @param applyAmount
+     * @return
+     */
+    public static List<InvAccountOp> invAccountEntOpList(JSONObject entProfit,InvAccount entAccount, InvAccountCard entAccountCard, String applyAmount){
+        List<InvAccountOp> list = new ArrayList<>();
+        if (entProfit != null) {
+            for (Map.Entry<String, Object> entry : entProfit.entrySet()) {
+                if (Integer.parseInt(entry.getValue().toString()) != 0) {
+                    InvAccountOp invAccountOp = new InvAccountOp();
+                    invAccountOp.setAccountId(entAccount.getAccountId());
+                    invAccountOp.setAccountName(entAccount.getAccountName());
+                    invAccountOp.setCardNum(entAccountCard.getBankCardNum());
+                    invAccountOp.setCardName(entAccountCard.getBankName());
+                    invAccountOp.setProfit(entry.getKey());
+                    invAccountOp.setMoney(new BigDecimal(entry.getValue().toString()).multiply(new BigDecimal(applyAmount)).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP).toString());
+                    list.add(invAccountOp);
+                }
+            }
+        }
+        return list;
+    }
+
+
+    /**
+     * 插入支出归属
+     * @param outProfit
+     * @param outAccount
+     * @param outAccountCard
+     * @param applyAmount
+     * @return
+     */
+    public static List<InvAccountOp> invAccountOutOpList(JSONObject outProfit,InvAccount outAccount, InvAccountCard outAccountCard, String applyAmount){
+        List<InvAccountOp> list = new ArrayList<>();
+        for (Map.Entry<String, Object> entry : outProfit.entrySet()) {
+            if (Integer.parseInt(entry.getValue().toString()) != 0) {
+                InvAccountOp invAccountOp = new InvAccountOp();
+                invAccountOp.setAccountId(outAccount.getAccountId());
+                invAccountOp.setAccountName(outAccount.getAccountName());
+                invAccountOp.setCardNum(outAccountCard.getBankCardNum());
+                invAccountOp.setCardName(outAccountCard.getBankName());
+                invAccountOp.setProfit(entry.getKey());
+                invAccountOp.setMoney(new BigDecimal(String.valueOf(entry.getValue())).multiply(new BigDecimal(applyAmount)).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP).negate().toString());
+                list.add(invAccountOp);
+            }
+        }
+        return list;
+    }
+
+
     /**
      * 转账成功后添加支出账户操作信息
      */
@@ -27,7 +81,7 @@ public class TransferUtils {
         InvAccountOperate operate = operate(insAccountExcel, insAccountOperate);
         operate.setRevenueOutlay("1");
         JSONObject outProfit = insAccountExcel.getOutProfit();
-        for (Map.Entry<String, Object> entry : outProfit.entrySet()){
+        for (Map.Entry<String, Object> entry : outProfit.entrySet()) {
             outProfit.put(entry.getKey(), new BigDecimal(String.valueOf(entry.getValue())).negate().toString());
         }
         operate.setOutProfit(outProfit);
@@ -51,7 +105,6 @@ public class TransferUtils {
         operate.setEnterCardNum(insAccountExcel.getEnterCardNum());
         return operate;
     }
-
     private static InvAccountOperate operate(InvAccountExcel invAccountExcel, InvAccountOperate invAccountOperate) {
         invAccountOperate.setApplicant(invAccountExcel.getApplicant());
         invAccountOperate.setApplySector(invAccountExcel.getApplySector());
@@ -67,12 +120,29 @@ public class TransferUtils {
         return invAccountOperate;
     }
 
+
+
     /**
-     * 内部转内部方法
+     * 判断各余额是否足够
+     *
+     * @param outAccountCard
+     * @param entAccountCard
+     * @param ApplyAmount
+     * @return
      */
-    public static List<InvAccountCard> insideTransfer(InvAccountCard outAccountCard, InvAccountCard enterAccountCard, InvAccountExcel invAccountExcel) {
-        List<InvAccountCard> list = new ArrayList<>();
-        if (outAccountCard != null && enterAccountCard != null && invAccountExcel != null) {
+    public static Boolean lenss(InvAccountCard outAccountCard, InvAccountCard entAccountCard, InvAccount outAccount, InvAccount entAccount, String ApplyAmount) {
+
+        if (entAccountCard == null || entAccount == null) {
+            throw new SystemException("收入卡或收入账户为空");
+        }
+        if (outAccountCard == null || outAccount == null) {
+            throw new SystemException("转出卡或转出账户为空");
+        }
+        if (ApplyAmount == null) {
+            throw new SystemException("金额为空");
+        }
+
+        if (outAccount.getOuterFlag().equals("0")) {
             //公户单日转账剩余
             BigDecimal pubDayLinesExcess = new BigDecimal(outAccountCard.getPubDayLinesExcess());
             //私户单日转账剩余
@@ -88,124 +158,199 @@ public class TransferUtils {
             //单日转账笔数剩余
             long dayStrokeNumExcess = Long.parseLong(outAccountCard.getDayStrokeNumExcess());
             //申请金额
-            BigDecimal insAccountExcelApplyAmount = new BigDecimal(invAccountExcel.getApplyAmount());
-
-            //转出账户现支出金额
-            BigDecimal outAccountSpend = new BigDecimal(outAccountCard.getSpend());
+            BigDecimal invApplyAmount = new BigDecimal(ApplyAmount);
 
+            //转出账户余额
             BigDecimal outAccountBalance = new BigDecimal(outAccountCard.getBalance());
 
-            if (outAccountBalance.compareTo(insAccountExcelApplyAmount) < 0) {
-                //转出账户余额不足
+
+            if (outAccountBalance.compareTo(invApplyAmount) < 0) {
                 throw new SystemException("转出账户余额不足");
             }
 
+            if (entAccountCard.getAccountQuality().equals("0")) {
+                //收入账户为公户
+                if (dayStrokeNumExcess <= 0) {
+                    throw new SystemException("公户单日转账笔数不足");
+                }
+                //判断单日转账金额是否超过
+                if (pubDayLinesExcess.compareTo(BigDecimal.valueOf(0)) != 0 && pubDayLinesExcess.compareTo(invApplyAmount) < 0) {
+                    throw new SystemException("公户单日转账金额不足");
+                }
+                //判断年额度是否超过
+                if (pubYearExcess.compareTo(BigDecimal.valueOf(0)) != 0 && pubYearExcess.compareTo(invApplyAmount) < 0) {
+                    throw new SystemException("公户年额度不足");
+                }
 
-            if (enterAccountCard.getAccountQuality().equals("0")) {
-                //公户操作
-                if (pubSingleLines.compareTo(insAccountExcelApplyAmount) > 0){
-                    //收入方增加余额
-
-                    list.add(pubAccountUtils(dayStrokeNumExcess,pubDayLinesExcess,pubYearExcess,insAccountExcelApplyAmount,outAccountCard,outAccountSpend));
-                    list.add(enterAccountUtils( enterAccountCard, insAccountExcelApplyAmount));
-                    return list;
+                if (pubSingleLines.compareTo(invApplyAmount) < 0) {
+                    throw new SystemException("公户转账金额超出单笔限额");
                 }
-                throw new SystemException("公户转账金额超出单笔限额");
             } else {
-                if(priSingleLines.compareTo(insAccountExcelApplyAmount) > 0){
-                    //私户操作
-
-                    list.add(priAccountUtils(dayStrokeNumExcess,priDayLinesExcess,insAccountExcelApplyAmount, priYearExcess,outAccountSpend,outAccountCard));
-                    list.add(enterAccountUtils( enterAccountCard, insAccountExcelApplyAmount));
-
-                    return list;
+                //收入账户为私户
+                if (dayStrokeNumExcess <= 0) {
+                    throw new SystemException("私户单日转账笔数不足");
+                }
+                if (priDayLinesExcess.compareTo(BigDecimal.valueOf(0)) != 0 && priDayLinesExcess.compareTo(invApplyAmount) < 0) {
+                    throw new SystemException("私户单日转账金额不足");
+                }
+                if (priYearExcess.compareTo(BigDecimal.valueOf(0)) != 0 && priYearExcess.compareTo(invApplyAmount) < 0) {
+                    throw new SystemException("私户年额度不足");
+                }
+                if (priSingleLines.compareTo(invApplyAmount) > -1) {
+                    throw new SystemException("私户转账金额超出单笔限额");
                 }
-                throw new SystemException("私户转账金额超出单笔限额");
             }
         }
-        return list;
-    }
 
+        return true;
+    }
 
     /**
-     * 外部转内部方法
+     * 判断归属是否分配完毕
+     * @param outProfit
+     * @param entProfit
+     * @return
      */
-    public static InvAccountCard outsideTransfer(InvAccountCard enterAccountCard, InvAccountOperate invAccountOperate) {
-        if (enterAccountCard == null || invAccountOperate == null) {
-            throw new SystemException("收入账户为空");
+    public static Boolean isProfitFull (JSONObject outProfit,JSONObject entProfit) {
+        BigDecimal outAmount = new BigDecimal(0);
+        BigDecimal entAmount = new BigDecimal(0);
+        for (Map.Entry<String, Object> entry : outProfit.entrySet()) {
+            outAmount = outAmount.add(new BigDecimal(entry.getValue().toString()));
+        }
+        for (Map.Entry<String, Object> entry : entProfit.entrySet()) {
+            entAmount = entAmount.add(new BigDecimal(entry.getValue().toString()));
+        }
+        if (!String.valueOf(outAmount).equals("100")) {
+            throw new SystemException("支出金额未完全分配");
         }
+        if (!String.valueOf(entAmount).equals("100")) {
+            throw new SystemException("收入金额未完全分配");
+        }
+        return true;
+    }
 
-        BigDecimal applyAmount = new BigDecimal(invAccountOperate.getApplyAmount());
+    /**
+     * 转给私户扣除余额方法
+     */
+    private static InvAccountCard priAccountUtils(InvAccountCard outAccountCard, String invAccountExcelApplyAmount) {
+        String spend = outAccountCard.getSpend();
+        String dayStrokeNumExcess = outAccountCard.getDayStrokeNumExcess();
+        String priDayLinesExcess = outAccountCard.getPriDayLinesExcess();
+        String priYearExcess = outAccountCard.getPriYearExcess();
+
+        outAccountCard.setSpend(new BigDecimal(spend).add(new BigDecimal(invAccountExcelApplyAmount)).toString());
+        outAccountCard.setBalance(new BigDecimal(outAccountCard.getBalance()).subtract(new BigDecimal(invAccountExcelApplyAmount)).toString());
+        outAccountCard.setDayStrokeNumExcess(String.valueOf(Integer.parseInt(dayStrokeNumExcess) - 1));
+        outAccountCard.setPriDayLinesExcess(new BigDecimal(priDayLinesExcess).subtract(new BigDecimal(invAccountExcelApplyAmount)).toString());
+        outAccountCard.setPriYearExcess(new BigDecimal(priYearExcess).subtract(new BigDecimal(invAccountExcelApplyAmount)).toString());
+        return outAccountCard;
+    }
 
-        return enterAccountUtils(enterAccountCard, applyAmount);
+    /**
+     * 转给公户扣除余额方法
+     */
+    private static InvAccountCard pubAccountUtils(InvAccountCard outAccountCard, String invAccountExcelApplyAmount) {
+        String spend = outAccountCard.getSpend();
+        String dayStrokeNumExcess = outAccountCard.getDayStrokeNumExcess();
+        String pubDayLinesExcess = outAccountCard.getPubDayLinesExcess();
+        String pubYearExcess = outAccountCard.getPubYearExcess();
+        BigDecimal bigDecimal = new BigDecimal(invAccountExcelApplyAmount);
+
+        //支出方减少余额
+        outAccountCard.setSpend(new BigDecimal(spend).add(bigDecimal).toString());
+        outAccountCard.setBalance(new BigDecimal(outAccountCard.getBalance()).subtract(bigDecimal).toString());
+        //公户单日转账笔数减少
+        outAccountCard.setDayStrokeNumExcess(String.valueOf(Integer.parseInt(dayStrokeNumExcess) - 1));
+        //公户单日转账剩余减少
+        outAccountCard.setPubDayLinesExcess(new BigDecimal(pubDayLinesExcess).subtract(bigDecimal).toString());
+        //公户年额度减少
+        outAccountCard.setPubYearExcess(new BigDecimal(pubYearExcess).subtract(bigDecimal).toString());
+        return outAccountCard;
     }
 
 
     /**
-     * 撤销发票方法
+     * 内部转内部方法
      */
-    public static List<InvAccountCard> quashOutsideTransfer(InvAccountCard outAccountCard,InvAccountCard enterAccountCard, InvAccountIncoice invAccountIncoice) {
-        if (enterAccountCard == null || invAccountIncoice == null) {
-            throw new SystemException("账户为空");
-        }
+    public static List<InvAccountCard> insideTransfer(InvAccountCard outAccountCard, InvAccount outAccount, InvAccountCard enterAccountCard, InvAccount enterAccount, String applyAmount) {
 
 
-        BigDecimal applyAmount = new BigDecimal(invAccountIncoice.getInvoiceMoney());
         List<InvAccountCard> list = new ArrayList<>();
-        list.add(enterAccountBreakUtils(enterAccountCard, applyAmount));
-        list.add(outAccountBreakUtils(outAccountCard, applyAmount));
-        return list;
+
+        TransferUtils.lenss(outAccountCard, enterAccountCard, outAccount, enterAccount, applyAmount);
+
+        if (enterAccountCard.getAccountQuality().equals("0")) {
+            list.add(pubAccountUtils(outAccountCard, applyAmount));
+            list.add(enterAccountUtils(enterAccountCard, applyAmount));
+            return list;
+
+        } else {
+            //私户操作
+            list.add(priAccountUtils(outAccountCard, applyAmount));
+            list.add(enterAccountUtils(enterAccountCard, applyAmount));
+            return list;
+        }
     }
 
+
     /**
      * 内部转外部方法
      */
-    public static List<InvAccountCard> enterDeTransfer(InvAccountCard outAccountCard, InvAccountCard enterAccountCard, InvAccountExcel invAccountExcel) {
+    public static List<InvAccountCard> enterDeTransfer(InvAccountCard outAccountCard, InvAccount outAccount, InvAccountCard enterAccountCard, InvAccount enterAccount, String applyAmount) {
         List<InvAccountCard> list = new ArrayList<>();
-        if (outAccountCard != null && enterAccountCard != null && invAccountExcel != null) {
-            //公户单日转账剩余
-            BigDecimal pubDayLinesExcess = new BigDecimal(outAccountCard.getPubDayLinesExcess());
-            //私户单日转账剩余
-            BigDecimal priDayLinesExcess = new BigDecimal(outAccountCard.getPriDayLinesExcess());
-            //公户年额度剩余
-            BigDecimal pubYearExcess = new BigDecimal(outAccountCard.getPubYearExcess());
-            //私户年额度剩余
-            BigDecimal priYearExcess = new BigDecimal(outAccountCard.getPriYearExcess());
-            //单日转账笔数剩余
-            long dayStrokeNumExcess = Long.parseLong(outAccountCard.getDayStrokeNumExcess());
-            //申请金额
-            BigDecimal insAccountExcelApplyAmount = new BigDecimal(invAccountExcel.getApplyAmount());
-            //转出账户现支出金额
-            BigDecimal outAccountSpend = new BigDecimal(outAccountCard.getSpend());
-
-            if (invAccountExcel.getOutAccountQuality().equals("0")) {
-                //公户操作
-                list.add(pubAccountUtils(dayStrokeNumExcess,pubDayLinesExcess,pubYearExcess,insAccountExcelApplyAmount,outAccountCard,outAccountSpend));
-                return list;
-
-            } else {
-                //私户操作
-                list.add(priAccountUtils(dayStrokeNumExcess,priDayLinesExcess,insAccountExcelApplyAmount, priYearExcess,outAccountSpend,outAccountCard));
-                return list;
-            }
+        TransferUtils.lenss(outAccountCard, enterAccountCard, outAccount, enterAccount, applyAmount);
+
+        if (enterAccountCard.getAccountQuality().equals("0")) {
+            //公户操作
+            list.add(pubAccountUtils(outAccountCard, applyAmount));
+        } else {
+            //私户操作
+            list.add(priAccountUtils(outAccountCard, applyAmount));
         }
         return list;
     }
 
 
+    /**
+     * 外部转内部方法
+     */
+    public static InvAccountCard outsideTransfer(InvAccountCard outAccountCard, InvAccount outAccount, InvAccountCard enterAccountCard, InvAccount enterAccount, String applyAmount) {
+        TransferUtils.lenss(outAccountCard, enterAccountCard, outAccount, enterAccount, applyAmount);
+
+        return enterAccountUtils(enterAccountCard, applyAmount);
+    }
+
     /**
      * 收入方增加利润方法
      *
      * @return
      */
-    private static InvAccountCard enterAccountUtils(InvAccountCard enterAccountCard, BigDecimal invAccountExcelApplyAmount) {
-        if(enterAccountCard.getBalance()!=null && !enterAccountCard.getBalance().isEmpty()){
-            enterAccountCard.setBalance(new BigDecimal(enterAccountCard.getBalance()).add(invAccountExcelApplyAmount).toString());
+    private static InvAccountCard enterAccountUtils(InvAccountCard enterAccountCard, String  invAccountExcelApplyAmount) {
+        if (enterAccountCard.getBalance() != null && !enterAccountCard.getBalance().isEmpty()) {
+            enterAccountCard.setBalance(new BigDecimal(enterAccountCard.getBalance()).add(new BigDecimal(invAccountExcelApplyAmount)).toString());
         }
         return enterAccountCard;
     }
 
 
+    /**
+     * 撤销发票方法
+     */
+    public static List<InvAccountCard> quashOutsideTransfer(InvAccountCard outAccountCard, InvAccountCard enterAccountCard, InvAccountIncoice invAccountIncoice) {
+        if (enterAccountCard == null || invAccountIncoice == null) {
+            throw new SystemException("账户为空");
+        }
+
+        BigDecimal applyAmount = new BigDecimal(invAccountIncoice.getInvoiceMoney());
+        List<InvAccountCard> list = new ArrayList<>();
+        list.add(enterAccountBreakUtils(enterAccountCard, applyAmount));
+        list.add(outAccountBreakUtils(outAccountCard, applyAmount));
+        return list;
+    }
+
+
+
+
 
     /**
      * 收入方回滚利润方法
@@ -223,61 +368,10 @@ public class TransferUtils {
      * @return
      */
     private static InvAccountCard outAccountBreakUtils(InvAccountCard enterAccountCard, BigDecimal invAccountExcelApplyAmount) {
-        if (enterAccountCard.getBalance()!=null && !enterAccountCard.getBalance().isEmpty()){
+        if (enterAccountCard.getBalance() != null && !enterAccountCard.getBalance().isEmpty()) {
             enterAccountCard.setBalance(new BigDecimal(enterAccountCard.getBalance()).add(invAccountExcelApplyAmount).toString());
         }
         return enterAccountCard;
     }
 
-    /**
-     * 公户扣除余额方法
-     */
-    private static InvAccountCard pubAccountUtils(long dayStrokeNumExcess, BigDecimal pubDayLinesExcess, BigDecimal pubYearExcess, BigDecimal invAccountExcelApplyAmount, InvAccountCard outAccountCard,BigDecimal outAccountSpend) {
-        //判断单日转账笔数是否超过
-        if (dayStrokeNumExcess <= 0) {
-            throw new SystemException("公户单日转账笔数不足");
-        }
-        //判断单日转账金额是否超过
-        if (pubDayLinesExcess.compareTo(BigDecimal.valueOf(0)) != 0 && pubDayLinesExcess.compareTo(invAccountExcelApplyAmount) < 0) {
-            throw new SystemException("公户单日转账金额不足");
-        }
-        //判断年额度是否超过
-        if (pubYearExcess.compareTo(BigDecimal.valueOf(0)) != 0 && pubYearExcess.compareTo(invAccountExcelApplyAmount) < 0) {
-            throw new SystemException("公户年额度不足");
-        }
-
-        //支出方减少余额
-        outAccountCard.setSpend(outAccountSpend.add(invAccountExcelApplyAmount).toString());
-        outAccountCard.setBalance(new BigDecimal(outAccountCard.getBalance()).subtract(invAccountExcelApplyAmount).toString());
-        //公户单日转账笔数减少
-        outAccountCard.setDayStrokeNumExcess(String.valueOf(dayStrokeNumExcess - 1));
-        //公户单日转账剩余减少
-        outAccountCard.setPubDayLinesExcess(pubDayLinesExcess.subtract(invAccountExcelApplyAmount).toString());
-        //公户年额度减少
-        outAccountCard.setPubYearExcess(pubYearExcess.subtract(invAccountExcelApplyAmount).toString());
-        return outAccountCard;
-    }
-    /**
-     * 私户扣除余额方法
-     */
-    private static InvAccountCard priAccountUtils(long dayStrokeNumExcess, BigDecimal priDayLinesExcess, BigDecimal invAccountExcelApplyAmount, BigDecimal priYearExcess, BigDecimal outAccountSpend,InvAccountCard outAccountCard) {
-        if (dayStrokeNumExcess <= 0) {
-            throw new SystemException("私户单日转账笔数不足");
-        }
-        if (priDayLinesExcess.compareTo(BigDecimal.valueOf(0)) != 0 && priDayLinesExcess.compareTo(invAccountExcelApplyAmount) < 0) {
-            throw new SystemException("私户单日转账金额不足");
-        }
-        if (priYearExcess.compareTo(BigDecimal.valueOf(0)) != 0 && priYearExcess.compareTo(invAccountExcelApplyAmount) < 0) {
-            throw new SystemException("私户年额度不足");
-        }
-
-        outAccountCard.setSpend(outAccountSpend.add(invAccountExcelApplyAmount).toString());
-        outAccountCard.setBalance(new BigDecimal(outAccountCard.getBalance()).subtract(invAccountExcelApplyAmount).toString());
-        outAccountCard.setDayStrokeNumExcess(String.valueOf(dayStrokeNumExcess - 1));
-        outAccountCard.setPriDayLinesExcess(priDayLinesExcess.subtract(invAccountExcelApplyAmount).toString());
-        outAccountCard.setPriYearExcess(priYearExcess.subtract(invAccountExcelApplyAmount).toString());
-        return outAccountCard;
-    }
-
-
 }

+ 12 - 3
src/main/resources/mapper/modules/inv/InvReceivableMapper.xml

@@ -47,7 +47,9 @@
         SELECT
         DATE_FORMAT( signing_time, '%m') as day,
         DATE_FORMAT( signing_time, '%Y-%m' ) as yearmonth,
-        insurance_name,
+        <if test="insuranceId != null and insuranceId != ''">
+            insurance_name,
+        </if>
         sum( jq_premium_tax ) as jq_premium_tax,
         sum(jq_premium) as jq_premium,
         sum(sy_premium_tax) as sy_premium_tax,
@@ -66,9 +68,16 @@
         signing_time BETWEEN #{startTime}
         AND #{endTime}
         <!--and insurance_id = '123'-->
+
+        <if test="insuranceId != null and insuranceId != ''">
+            and insurance_id = #{insuranceId}
+        </if>
+
         GROUP BY
-        insurance_id,
-        insurance_name,
+        <if test="insuranceId != null and insuranceId != ''">
+            insurance_id,
+            insurance_name,
+        </if>
         DATE_FORMAT(
         signing_time,
         '%Y-%m'),

+ 6 - 6
src/main/resources/mapper/modules/inv/InvSourceMapper.xml

@@ -136,22 +136,22 @@
             and a.licenseno = #{param.licenseno}
         </if>
         <if test="param.jqPolicyId != null and param.jqPolicyId != ''">
-            and a.jq_policy_id = #{jqPolicyId}
+            and a.jq_policy_id = #{param.jqPolicyId}
         </if>
         <if test="param.syPolicyId != null and param.syPolicyId != ''">
-            and a.sy_policy_id = #{syPolicyId}
+            and a.sy_policy_id = #{param.syPolicyId}
         </if>
         <if test="param.nonCarPolicyId != null and param.nonCarPolicyId != ''">
-            and a.non_car_policy_id = #{nonCarPolicyId}
+            and a.non_car_policy_id = #{param.nonCarPolicyId}
         </if>
         <if test="param.insuranceId != null and param.insuranceId != ''">
-            and a.insurance_id = #{insuranceId}
+            and a.insurance_id = #{param.insuranceId}
         </if>
         <if test="param.risk != null and param.risk != ''">
-            and a.risk = #{risk}
+            and a.risk = #{param.risk}
         </if>
         <if test="param.insuranceName != null and param.insuranceName != ''">
-            and a.insurance_name = #{insuranceName}
+            and a.insurance_name = #{param.insuranceName}
         </if>
         <if test="param.clearingTimeStartTime != null and param.clearingTimeStartTime != ''">
             and a.clearing_time between #{param.clearingTimeStartTime} and #{param.clearingTimeEndTime]}