| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486 |
- package com.ydtech.modules.inv.utils;
- import com.alibaba.fastjson.JSONObject;
- import com.ydtech.exception.SystemException;
- import com.ydtech.modules.base.controller.BaseController;
- import com.ydtech.modules.inv.model.*;
- import com.ydtech.modules.inv.service.InvAccountService;
- import com.ydtech.modules.inv.service.impl.InvAccountServiceImpl;
- import org.apache.bcel.generic.IF_ACMPEQ;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.time.LocalDateTime;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- /**
- * 转账工具类
- *
- * @author jianlong
- * @date 2024-01-10 14:10
- */
- public class TransferUtils {
- /**
- * 插入收入归属
- *
- * @param entProfit
- * @param entAccount
- * @param entAccountCard
- * @return
- */
- public static List<InvAccountOp> invAccountEntOpList(JSONObject entProfit, InvAccount entAccount, InvAccountCard entAccountCard, String operateId) {
- List<InvAccountOp> list = new ArrayList<>();
- if (entProfit != null) {
- for (Map.Entry<String, Object> entry : entProfit.entrySet()) {
- if (new BigDecimal(entry.getValue().toString()).compareTo(BigDecimal.ZERO) != 0) {
- InvAccountOp invAccountOp = new InvAccountOp();
- invAccountOp.setAccountId(entAccount.getAccountId());
- invAccountOp.setAccountName(entAccount.getAccountName());
- invAccountOp.setCardNum(entAccountCard.getBankCardNum());
- invAccountOp.setCardName(entAccountCard.getBankName());
- invAccountOp.setAccountOperateId(operateId);
- invAccountOp.setProfit(entry.getKey());
- invAccountOp.setMoney(entry.getValue().toString());
- list.add(invAccountOp);
- }
- }
- }
- return list;
- }
- public static List<InvAccountOp> invAccountEntOpList1(JSONObject entProfit, InvAccount entAccount, InvAccountCard entAccountCard, String operateId,String payoutAmount) {
- List<InvAccountOp> list = new ArrayList<>();
- if (entProfit != null) {
- for (Map.Entry<String, Object> entry : entProfit.entrySet()) {
- if (new BigDecimal(entry.getValue().toString()).compareTo(BigDecimal.ZERO) != 0) {
- InvAccountOp invAccountOp = new InvAccountOp();
- invAccountOp.setAccountId(entAccount.getAccountId());
- invAccountOp.setAccountName(entAccount.getAccountName());
- invAccountOp.setCardNum(entAccountCard.getBankCardNum());
- invAccountOp.setCardName(entAccountCard.getBankName());
- invAccountOp.setAccountOperateId(operateId);
- invAccountOp.setProfit(entry.getKey());
- invAccountOp.setMoney(payoutAmount);
- list.add(invAccountOp);
- }
- }
- }
- return list;
- }
- /**
- * 插入支出归属
- *
- * @param outProfit
- * @param outAccount
- * @param outAccountCard
- * @return
- */
- public static List<InvAccountOp> invAccountOutOpList(JSONObject outProfit, InvAccount outAccount, InvAccountCard outAccountCard, String operateId) {
- List<InvAccountOp> list = new ArrayList<>();
- for (Map.Entry<String, Object> entry : outProfit.entrySet()) {
- if (new BigDecimal(entry.getValue().toString()).compareTo(BigDecimal.ZERO) != 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.setAccountOperateId(operateId);
- invAccountOp.setMoney(String.valueOf(entry.getValue()));
- list.add(invAccountOp);
- }
- }
- return list;
- }
- //处理部分支出时逻辑
- public static List<InvAccountOp> invAccountOutOpList1(JSONObject outProfit, InvAccount outAccount, InvAccountCard outAccountCard, String operateId,String payoutAmount) {
- List<InvAccountOp> list = new ArrayList<>();
- for (Map.Entry<String, Object> entry : outProfit.entrySet()) {
- if (new BigDecimal(entry.getValue().toString()).compareTo(BigDecimal.ZERO) != 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.setAccountOperateId(operateId);
- payoutAmount = "-" + payoutAmount;
- invAccountOp.setMoney(payoutAmount);
- list.add(invAccountOp);
- }
- }
- return list;
- }
- /**
- * 转账成功后添加支出账户操作信息
- */
- public static InvAccountOperate insertOutAccountOperate(InvAccountExcel insAccountExcel) {
- //支出公司
- InvAccountOperate insAccountOperate = new InvAccountOperate();
- BaseController baseController = new BaseController();
- InvAccountOperate operate = operate(insAccountExcel, insAccountOperate);
- operate.setRevenueOutlay("1");
- operate.setApplyAmount(insAccountExcel.getPayoutAmount());
- operate.setOutProfit(insAccountExcel.getOutProfit());
- operate.setCreateTime(LocalDateTime.now().toString());
- operate.setCreateBy(baseController.getUserName());
- operate.setCreateId(baseController.getUserId());
- operate.setRemark(insAccountExcel.getRemark());
- operate.setOutCardNum(insAccountExcel.getOutCardNum());
- return operate;
- }
- /**
- * 转账成功后添加收入账户操作信息
- */
- public static InvAccountOperate insertRevenueAccountOperate(InvAccountExcel insAccountExcel) {
- //支出公司
- InvAccountOperate insAccountOperate = new InvAccountOperate();
- BaseController baseController = new BaseController();
- InvAccountOperate operate = operate(insAccountExcel, insAccountOperate);
- operate.setRevenueOutlay("0");
- operate.setEntProfit(insAccountExcel.getEntProfit());
- operate.setCreateTime(LocalDateTime.now().toString());
- operate.setRemark(insAccountExcel.getRemark());
- operate.setCreateBy(baseController.getUserName());
- operate.setCreateId(baseController.getUserId());
- operate.setEnterCardNum(insAccountExcel.getEnterCardNum());
- return operate;
- }
- private static InvAccountOperate 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.setCompany(invAccountExcel.getCompany());
- invAccountOperate.setApplyAmount(invAccountExcel.getApplyAmount());
- invAccountOperate.setBigApplyAmount(invAccountExcel.getBigApplyAmount());
- invAccountOperate.setFundFen(invAccountExcel.getFundFen());
- return invAccountOperate;
- }
- /**
- * 判断各余额是否足够
- *
- * @param outAccountCard
- * @param entAccountCard
- * @param ApplyAmount
- * @return
- */
- 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());
- //私户单日转账剩余
- BigDecimal priDayLinesExcess = new BigDecimal(outAccountCard.getPriDayLinesExcess());
- //公户年额度剩余
- BigDecimal pubYearExcess = new BigDecimal(outAccountCard.getPubYearExcess());
- //私户年额度剩余
- BigDecimal priYearExcess = new BigDecimal(outAccountCard.getPriYearExcess());
- //对公单笔限额
- BigDecimal pubSingleLines = new BigDecimal(outAccountCard.getPubSingleLines());
- //对私单笔限额
- BigDecimal priSingleLines = new BigDecimal(outAccountCard.getPriSingleLines());
- //单日转账笔数剩余
- long dayStrokeNumExcess = Long.parseLong(outAccountCard.getDayStrokeNumExcess());
- //申请金额
- BigDecimal invApplyAmount = new BigDecimal(ApplyAmount);
- //转出账户余额
- BigDecimal outAccountBalance = new BigDecimal(outAccountCard.getBalance());
- 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 (pubSingleLines.compareTo(invApplyAmount) < 0) {
- throw new SystemException("公户转账金额超出单笔限额");
- }
- } else {
- //收入账户为私户
- 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) < 0) {
- throw new SystemException("私户转账金额超出单笔限额");
- }
- }
- }
- return true;
- }
- /**
- * 判断归属是否分配完毕
- *
- * @param outProfit
- * @param entProfit
- * @return
- */
- 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()));
- }
- String string = (new BigDecimal(String.valueOf(entAmount)).add(new BigDecimal(String.valueOf(outAmount)))).toString();
- if (new BigDecimal(string).compareTo(BigDecimal.ZERO) != 0) {
- throw new SystemException("金额未完全分配");
- }
- return true;
- }
- /**
- * 判断归属是否分配完毕
- *
- * @param outProfit
- * @param entProfit
- * @return
- */
- public static Boolean isProfitFull(JSONObject outProfit, JSONObject entProfit, String payoutMoney) {
- 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()));
- }
- String string = (new BigDecimal(String.valueOf(entAmount)).add(new BigDecimal(String.valueOf(outAmount)))).toString();
- if (new BigDecimal(string).compareTo(BigDecimal.ZERO) != 0) {
- throw new SystemException("金额未完全分配");
- }
- if ((entAmount.compareTo(new BigDecimal(payoutMoney)) != 0)
- || (outAmount.abs().compareTo(new BigDecimal(payoutMoney)) != 0)) {
- throw new SystemException("进账金额与板块总金额不匹配");
- }
- return true;
- }
- /**
- * 转给私户扣除余额方法
- */
- 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;
- }
- /**
- * 转给公户扣除余额方法
- */
- 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> insideTransfer(InvAccountCard outAccountCard, InvAccount outAccount, InvAccountCard enterAccountCard, InvAccount enterAccount, String applyAmount) {
- List<InvAccountCard> list = new ArrayList<>();
- 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, InvAccount outAccount, InvAccountCard enterAccountCard, InvAccount enterAccount, String applyAmount) {
- List<InvAccountCard> list = new ArrayList<>();
- 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, 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, BigDecimal applyAmount, InvAccount entInvAccount) {
- List<InvAccountCard> list = new ArrayList<>();
- list.add(enterAccountBreakUtils(enterAccountCard, outAccountCard, applyAmount, entInvAccount));
- InvAccountCard invAccountCard = outAccountBreakUtils(outAccountCard, enterAccountCard, applyAmount);
- if (invAccountCard != null) {
- list.add(invAccountCard);
- }
- return list;
- }
- /**
- * 收入方回滚利润方法
- *
- * @return
- */
- private static InvAccountCard enterAccountBreakUtils(InvAccountCard enterAccountCard, InvAccountCard outAccountCard, BigDecimal invAccountExcelApplyAmount, InvAccount entInvAccount) {
- if (entInvAccount.getOuterFlag().equals("0")) {
- if (enterAccountCard != null) {
- if (outAccountCard != null) {
- if (new BigDecimal(enterAccountCard.getBalance()).compareTo(BigDecimal.ZERO) == 0) {
- throw new SystemException("账户余额不足");
- }
- if (new BigDecimal(enterAccountCard.getBalance()).compareTo(invAccountExcelApplyAmount) < 0) {
- throw new SystemException("账户余额不足");
- }
- }
- if (!enterAccountCard.getBalance().isEmpty()) {
- enterAccountCard.setBalance(new BigDecimal(enterAccountCard.getBalance()).subtract(invAccountExcelApplyAmount).toString());
- }
- }
- }
- return enterAccountCard;
- }
- /**
- * 支出方回滚利润方法
- *
- * @return
- */
- private static InvAccountCard outAccountBreakUtils(InvAccountCard outAccountCard, InvAccountCard enterAccountCard, BigDecimal invAccountExcelApplyAmount) {
- if (outAccountCard != null) {
- if (outAccountCard.getBalance() != null && !outAccountCard.getBalance().isEmpty()) {
- outAccountCard.setBalance(new BigDecimal(outAccountCard.getBalance()).add(invAccountExcelApplyAmount).toString());
- outAccountCard.setSpend(new BigDecimal(outAccountCard.getSpend()).subtract(invAccountExcelApplyAmount).toString());
- if (outAccountCard.getDayStrokeNumExcess() != null && !outAccountCard.getDayStrokeNumExcess().isEmpty()) {
- outAccountCard.setDayStrokeNumExcess(new BigDecimal(outAccountCard.getDayStrokeNumExcess()).add(new BigDecimal("1")).toString());
- }
- if (enterAccountCard.getAccountQuality().equals("0")) {
- if (outAccountCard.getPubDayLinesExcess() != null && !outAccountCard.getPubDayLinesExcess().isEmpty()) {
- outAccountCard.setPubDayLinesExcess(new BigDecimal(outAccountCard.getPubDayLinesExcess()).add(invAccountExcelApplyAmount).toString());
- }
- if (outAccountCard.getPubYearExcess() != null && !outAccountCard.getPubYearExcess().isEmpty()) {
- outAccountCard.setPubYearExcess(new BigDecimal(outAccountCard.getPubYearExcess()).add(invAccountExcelApplyAmount).toString());
- }
- } else {
- if (outAccountCard.getPriDayLinesExcess() != null && !outAccountCard.getPriDayLinesExcess().isEmpty()) {
- outAccountCard.setPriDayLinesExcess(new BigDecimal(outAccountCard.getPriDayLinesExcess()).add(invAccountExcelApplyAmount).toString());
- }
- if (outAccountCard.getPriYearExcess() != null && !outAccountCard.getPriYearExcess().isEmpty()) {
- outAccountCard.setPriYearExcess(new BigDecimal(outAccountCard.getPriYearExcess()).add(invAccountExcelApplyAmount).toString());
- }
- }
- }
- }
- return outAccountCard;
- }
- }
|