|
|
@@ -0,0 +1,241 @@
|
|
|
+package com.ydtech.modules.inv.utils;
|
|
|
+
|
|
|
+import com.ydtech.constants.enums.inv.InsAccountOperateEnum;
|
|
|
+import com.ydtech.exception.SystemException;
|
|
|
+import com.ydtech.modules.inv.model.InvAccount;
|
|
|
+import com.ydtech.modules.inv.model.InvAccountExcel;
|
|
|
+import com.ydtech.modules.inv.model.InvAccountOperate;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 转账工具类
|
|
|
+ *
|
|
|
+ * @author jianlong
|
|
|
+ * @date 2024-01-10 14:10
|
|
|
+ */
|
|
|
+public class TransferUtils {
|
|
|
+ /**
|
|
|
+ * 转账成功后添加支出账户操作信息
|
|
|
+ */
|
|
|
+ public static InvAccountOperate insertOutAccountOperate(InvAccountExcel insAccountExcel) {
|
|
|
+ //支出公司
|
|
|
+ InvAccountOperate insAccountOperate = new InvAccountOperate();
|
|
|
+ operate(insAccountExcel, insAccountOperate);
|
|
|
+ insAccountOperate.setRevenueOutlay("1");
|
|
|
+ return insAccountOperate;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 转账成功后添加收入账户操作信息
|
|
|
+ */
|
|
|
+ public static InvAccountOperate insertRevenueAccountOperate(InvAccountExcel insAccountExcel) {
|
|
|
+ //支出公司
|
|
|
+ InvAccountOperate insAccountOperate = new InvAccountOperate();
|
|
|
+ operate(insAccountExcel, insAccountOperate);
|
|
|
+ insAccountOperate.setRevenueOutlay("0");
|
|
|
+ return insAccountOperate;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void operate(InvAccountExcel invAccountExcel, InvAccountOperate invAccountOperate) {
|
|
|
+ invAccountOperate.setApplicant(invAccountExcel.getApplicant());
|
|
|
+ invAccountOperate.setApplySector(invAccountExcel.getApplySector());
|
|
|
+ invAccountOperate.setApplyTime(invAccountExcel.getApplyTime());
|
|
|
+ invAccountOperate.setCollectionMessage(invAccountExcel.getCollectionMessage());
|
|
|
+ invAccountOperate.setFundFlow(invAccountExcel.getFundFlow());
|
|
|
+ invAccountOperate.setFundUse(invAccountExcel.getFundUse());
|
|
|
+ invAccountOperate.setPayMethod(invAccountExcel.getPayMethod());
|
|
|
+ invAccountOperate.setRemark(InsAccountOperateEnum.getNameByCode(invAccountExcel.getRemark()));
|
|
|
+ invAccountOperate.setCompany(invAccountExcel.getCompany());
|
|
|
+ invAccountOperate.setApplyAmount(invAccountExcel.getApplyAmount());
|
|
|
+ invAccountOperate.setBigApplyAmount(invAccountExcel.getBigApplyAmount());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 内部转内部方法
|
|
|
+ */
|
|
|
+ public static List<InvAccount> insideTransfer(InvAccount outAccount, InvAccount enterAccount, InvAccountExcel invAccountExcel) {
|
|
|
+ List<InvAccount> list = new ArrayList<>();
|
|
|
+ if (outAccount != null && enterAccount != null && invAccountExcel != null) {
|
|
|
+ //公户单日转账剩余
|
|
|
+ BigDecimal pubDayLinesExcess = new BigDecimal(outAccount.getPubDayLinesExcess());
|
|
|
+ //私户单日转账剩余
|
|
|
+ BigDecimal priDayLinesExcess = new BigDecimal(outAccount.getPriDayLinesExcess());
|
|
|
+ //公户年额度剩余
|
|
|
+ BigDecimal pubYearExcess = new BigDecimal(outAccount.getPubYearExcess());
|
|
|
+ //私户年额度剩余
|
|
|
+ BigDecimal priYearExcess = new BigDecimal(outAccount.getPriYearExcess());
|
|
|
+ //对公单笔限额
|
|
|
+ BigDecimal pubSingleLines = new BigDecimal(outAccount.getPubSingleLines());
|
|
|
+ //对私单笔限额
|
|
|
+ BigDecimal priSingleLines = new BigDecimal(outAccount.getPriSingleLines());
|
|
|
+ //单日转账笔数剩余
|
|
|
+ long dayStrokeNumExcess = Long.parseLong(outAccount.getDayStrokeNumExcess());
|
|
|
+ //申请金额
|
|
|
+ BigDecimal insAccountExcelApplyAmount = new BigDecimal(invAccountExcel.getApplyAmount());
|
|
|
+ //转出账户现支出金额
|
|
|
+ BigDecimal outAccountSpend = new BigDecimal(outAccount.getSpend());
|
|
|
+
|
|
|
+ if (enterAccount.getAccountQuality().equals("0")) {
|
|
|
+ //公户操作
|
|
|
+ if (pubSingleLines.compareTo(insAccountExcelApplyAmount) > 0){
|
|
|
+ //收入方增加余额
|
|
|
+ String remark = invAccountExcel.getRemark();
|
|
|
+
|
|
|
+ list.add(pubAccountUtils(dayStrokeNumExcess,pubDayLinesExcess,pubYearExcess,insAccountExcelApplyAmount,outAccount,outAccountSpend));
|
|
|
+ list.add(enterAccountUtils(remark, enterAccount, insAccountExcelApplyAmount));
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ throw new SystemException("公户转账金额超出单笔限额");
|
|
|
+ } else {
|
|
|
+ if(priSingleLines.compareTo(insAccountExcelApplyAmount) > 0){
|
|
|
+ //私户操作
|
|
|
+ String remark = invAccountExcel.getRemark();
|
|
|
+ list.add(priAccountUtils(dayStrokeNumExcess,priDayLinesExcess,insAccountExcelApplyAmount, priYearExcess,outAccountSpend,outAccount));
|
|
|
+ list.add(enterAccountUtils(remark, enterAccount, insAccountExcelApplyAmount));
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ throw new SystemException("私户转账金额超出单笔限额");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 外部转内部方法
|
|
|
+ */
|
|
|
+ public static InvAccount outsideTransfer(InvAccount enterAccount, InvAccountOperate invAccountOperate) {
|
|
|
+ if (enterAccount == null && invAccountOperate == null) {
|
|
|
+ throw new SystemException("收入账户为空");
|
|
|
+ }
|
|
|
+ String remark = invAccountOperate.getRemark();
|
|
|
+ BigDecimal applyAmount = new BigDecimal(invAccountOperate.getApplyAmount());
|
|
|
+
|
|
|
+ return enterAccountUtils(remark, enterAccount, applyAmount);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 内部转外部方法
|
|
|
+ */
|
|
|
+ public static List<InvAccount> enterDeTransfer(InvAccount outAccount, InvAccount enterAccount, InvAccountExcel invAccountExcel) {
|
|
|
+ List<InvAccount> list = new ArrayList<>();
|
|
|
+ if (outAccount != null && enterAccount != null && invAccountExcel != null) {
|
|
|
+ //公户单日转账剩余
|
|
|
+ BigDecimal pubDayLinesExcess = new BigDecimal(outAccount.getPubDayLinesExcess());
|
|
|
+ //私户单日转账剩余
|
|
|
+ BigDecimal priDayLinesExcess = new BigDecimal(outAccount.getPriDayLinesExcess());
|
|
|
+ //公户年额度剩余
|
|
|
+ BigDecimal pubYearExcess = new BigDecimal(outAccount.getPubYearExcess());
|
|
|
+ //私户年额度剩余
|
|
|
+ BigDecimal priYearExcess = new BigDecimal(outAccount.getPriYearExcess());
|
|
|
+ //单日转账笔数剩余
|
|
|
+ long dayStrokeNumExcess = Long.parseLong(outAccount.getDayStrokeNumExcess());
|
|
|
+ //申请金额
|
|
|
+ BigDecimal insAccountExcelApplyAmount = new BigDecimal(invAccountExcel.getApplyAmount());
|
|
|
+ //转出账户现支出金额
|
|
|
+ BigDecimal outAccountSpend = new BigDecimal(outAccount.getSpend());
|
|
|
+
|
|
|
+ if (invAccountExcel.getOutAccountQuality().equals("0")) {
|
|
|
+ //公户操作
|
|
|
+ list.add(pubAccountUtils(dayStrokeNumExcess,pubDayLinesExcess,pubYearExcess,insAccountExcelApplyAmount,outAccount,outAccountSpend));
|
|
|
+ return list;
|
|
|
+
|
|
|
+ } else {
|
|
|
+ //私户操作
|
|
|
+ list.add(priAccountUtils(dayStrokeNumExcess,priDayLinesExcess,insAccountExcelApplyAmount, priYearExcess,outAccountSpend,outAccount));
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 收入方增加利润方法
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private static InvAccount enterAccountUtils(String remark, InvAccount enterAccount, BigDecimal invAccountExcelApplyAmount) {
|
|
|
+ switch (remark) {
|
|
|
+ case "0":
|
|
|
+ enterAccount.setInsuranceProfit(new BigDecimal(enterAccount.getInsuranceProfit()).add(invAccountExcelApplyAmount).toString());
|
|
|
+ break;
|
|
|
+ case "1":
|
|
|
+ enterAccount.setClearingProfit(new BigDecimal(enterAccount.getClearingProfit()).add(invAccountExcelApplyAmount).toString());
|
|
|
+ break;
|
|
|
+ case "2":
|
|
|
+ enterAccount.setTianqinProfit(new BigDecimal(enterAccount.getTianqinProfit()).add(invAccountExcelApplyAmount).toString());
|
|
|
+ break;
|
|
|
+ case "3":
|
|
|
+ enterAccount.setParkProfit(new BigDecimal(enterAccount.getParkProfit()).add(invAccountExcelApplyAmount).toString());
|
|
|
+ break;
|
|
|
+ case "4":
|
|
|
+ enterAccount.setOtherProfit(new BigDecimal(enterAccount.getOtherProfit()).add(invAccountExcelApplyAmount).toString());
|
|
|
+ break;
|
|
|
+ case "5":
|
|
|
+ enterAccount.setFiscalProfit(new BigDecimal(enterAccount.getFiscalProfit()).add(invAccountExcelApplyAmount).toString());
|
|
|
+ break;
|
|
|
+ case "6":
|
|
|
+ enterAccount.setExteriorProfit(new BigDecimal(enterAccount.getExteriorProfit()).add(invAccountExcelApplyAmount).toString());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ enterAccount.setBalance(new BigDecimal(enterAccount.getBalance()).add(invAccountExcelApplyAmount).toString());
|
|
|
+ return enterAccount;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 公户扣除余额方法
|
|
|
+ */
|
|
|
+ private static InvAccount pubAccountUtils(long dayStrokeNumExcess, BigDecimal pubDayLinesExcess, BigDecimal pubYearExcess, BigDecimal invAccountExcelApplyAmount, InvAccount outAccount,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("公户年额度不足");
|
|
|
+ }
|
|
|
+
|
|
|
+ //支出方减少余额
|
|
|
+ outAccount.setSpend(outAccountSpend.add(invAccountExcelApplyAmount).toString());
|
|
|
+ outAccount.setBalance(new BigDecimal(outAccount.getBalance()).subtract(invAccountExcelApplyAmount).toString());
|
|
|
+ //公户单日转账笔数减少
|
|
|
+ outAccount.setDayStrokeNumExcess(String.valueOf(dayStrokeNumExcess - 1));
|
|
|
+ //公户单日转账剩余减少
|
|
|
+ outAccount.setPubDayLinesExcess(pubDayLinesExcess.subtract(invAccountExcelApplyAmount).toString());
|
|
|
+ //公户年额度减少
|
|
|
+ outAccount.setPubYearExcess(pubYearExcess.subtract(invAccountExcelApplyAmount).toString());
|
|
|
+ return outAccount;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 私户扣除余额方法
|
|
|
+ */
|
|
|
+ private static InvAccount priAccountUtils(long dayStrokeNumExcess, BigDecimal priDayLinesExcess, BigDecimal invAccountExcelApplyAmount, BigDecimal priYearExcess, BigDecimal outAccountSpend,InvAccount outAccount) {
|
|
|
+ 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("私户年额度不足");
|
|
|
+ }
|
|
|
+
|
|
|
+ outAccount.setSpend(outAccountSpend.add(invAccountExcelApplyAmount).toString());
|
|
|
+ outAccount.setBalance(new BigDecimal(outAccount.getBalance()).subtract(invAccountExcelApplyAmount).toString());
|
|
|
+ outAccount.setDayStrokeNumExcess(String.valueOf(dayStrokeNumExcess - 1));
|
|
|
+ outAccount.setPriDayLinesExcess(priDayLinesExcess.subtract(invAccountExcelApplyAmount).toString());
|
|
|
+ outAccount.setPriYearExcess(priYearExcess.subtract(invAccountExcelApplyAmount).toString());
|
|
|
+ return outAccount;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|