Procházet zdrojové kódy

修改发票管理 重构代码

y před 2 roky
rodič
revize
46f97a0010

+ 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);
     }
 }

+ 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) {

+ 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;
     }
 
 

+ 58 - 69
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,39 @@ 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);
-            }
+            outProfit.put(entry.getKey(), new BigDecimal(String.valueOf(entry.getValue())).negate().toString());
         }
-        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,13 +189,14 @@ 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.setEnterCardId(invAccountIncoice1.getRevBankCardNum());
@@ -221,7 +211,6 @@ public class InvAccountIncoiceServiceImpl extends ServiceImpl<InvAccountIncoiceM
             invAccountOperateService.insert(invAccountOperate1);
         }
 
-
         return HttpResult.ok(invAccountIncoiceMapper.updateById(invAccountIncoice1));
     }
 

+ 50 - 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,48 @@ 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());
         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 +137,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 +161,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("文件导出失败");
             }
 

+ 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;
-    }
-
-
 }