| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- package com.ydtech.modules.inv.utils;
- import com.ydtech.exception.SystemException;
- import com.ydtech.modules.inv.model.*;
- 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(invAccountExcel.getRemark());
- invAccountOperate.setCompany(invAccountExcel.getCompany());
- invAccountOperate.setApplyAmount(invAccountExcel.getApplyAmount());
- invAccountOperate.setBigApplyAmount(invAccountExcel.getBigApplyAmount());
- }
- /**
- * 内部转内部方法
- */
- public static List<InvAccountCard> insideTransfer(InvAccountCard outAccountCard, InvAccountCard enterAccountCard, InvAccountExcel invAccountExcel) {
- 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());
- //对公单笔限额
- BigDecimal pubSingleLines = new BigDecimal(outAccountCard.getPubSingleLines());
- //对私单笔限额
- BigDecimal priSingleLines = new BigDecimal(outAccountCard.getPriSingleLines());
- //单日转账笔数剩余
- long dayStrokeNumExcess = Long.parseLong(outAccountCard.getDayStrokeNumExcess());
- //申请金额
- BigDecimal insAccountExcelApplyAmount = new BigDecimal(invAccountExcel.getApplyAmount());
- //转出账户现支出金额
- BigDecimal outAccountSpend = new BigDecimal(outAccountCard.getSpend());
- if (enterAccountCard.getAccountQuality().equals("0")) {
- //公户操作
- if (pubSingleLines.compareTo(insAccountExcelApplyAmount) > 0){
- //收入方增加余额
- String remark = invAccountExcel.getRemark();
- list.add(pubAccountUtils(dayStrokeNumExcess,pubDayLinesExcess,pubYearExcess,insAccountExcelApplyAmount,outAccountCard,outAccountSpend));
- list.add(enterAccountUtils(remark, enterAccountCard, insAccountExcelApplyAmount));
- return list;
- }
- throw new SystemException("公户转账金额超出单笔限额");
- } else {
- if(priSingleLines.compareTo(insAccountExcelApplyAmount) > 0){
- //私户操作
- String remark = invAccountExcel.getRemark();
- list.add(priAccountUtils(dayStrokeNumExcess,priDayLinesExcess,insAccountExcelApplyAmount, priYearExcess,outAccountSpend,outAccountCard));
- list.add(enterAccountUtils(remark, enterAccountCard, insAccountExcelApplyAmount));
- return list;
- }
- throw new SystemException("私户转账金额超出单笔限额");
- }
- }
- return list;
- }
- /**
- * 外部转内部方法
- */
- public static InvAccountCard outsideTransfer(InvAccountCard enterAccountCard, InvAccountOperate invAccountOperate) {
- if (enterAccountCard == null && invAccountOperate == null) {
- throw new SystemException("收入账户为空");
- }
- String remark = invAccountOperate.getRemark();
- BigDecimal applyAmount = new BigDecimal(invAccountOperate.getApplyAmount());
- return enterAccountUtils(remark, enterAccountCard, applyAmount);
- }
- /**
- * 撤销发票方法
- */
- public static InvAccountCard quashOutsideTransfer(InvAccountCard enterAccountCard, InvAccountIncoice invAccountIncoice) {
- if (enterAccountCard == null && invAccountIncoice == null) {
- throw new SystemException("账户为空");
- }
- String remark = invAccountIncoice.getRemark();
- BigDecimal applyAmount = new BigDecimal(invAccountIncoice.getInvoiceMoney());
- return enterAccountBreakUtils(remark, enterAccountCard, applyAmount);
- }
- /**
- * 内部转外部方法
- */
- public static List<InvAccountCard> enterDeTransfer(InvAccountCard outAccountCard, InvAccountCard enterAccountCard, InvAccountExcel invAccountExcel) {
- 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;
- }
- }
- return list;
- }
- /**
- * 收入方增加利润方法
- *
- * @return
- */
- private static InvAccountCard enterAccountUtils(String remark, InvAccountCard enterAccountCard, BigDecimal invAccountExcelApplyAmount) {
- if (remark.isEmpty()){
- throw new SystemException("备注不能为空");
- }
- if (enterAccountCard == null){
- throw new SystemException("收入账户为空");
- }
- switch (remark) {
- case "0":
- enterAccountCard.setInsuranceProfit(new BigDecimal(enterAccountCard.getInsuranceProfit()).add(invAccountExcelApplyAmount).toString());
- break;
- case "1":
- enterAccountCard.setClearingProfit(new BigDecimal(enterAccountCard.getClearingProfit()).add(invAccountExcelApplyAmount).toString());
- break;
- case "2":
- enterAccountCard.setTianqinProfit(new BigDecimal(enterAccountCard.getTianqinProfit()).add(invAccountExcelApplyAmount).toString());
- break;
- case "3":
- enterAccountCard.setParkProfit(new BigDecimal(enterAccountCard.getParkProfit()).add(invAccountExcelApplyAmount).toString());
- break;
- case "4":
- enterAccountCard.setOtherProfit(new BigDecimal(enterAccountCard.getOtherProfit()).add(invAccountExcelApplyAmount).toString());
- break;
- case "5":
- enterAccountCard.setFiscalProfit(new BigDecimal(enterAccountCard.getFiscalProfit()).add(invAccountExcelApplyAmount).toString());
- break;
- case "6":
- enterAccountCard.setExteriorProfit(new BigDecimal(enterAccountCard.getExteriorProfit()).add(invAccountExcelApplyAmount).toString());
- break;
- }
- enterAccountCard.setBalance(new BigDecimal(enterAccountCard.getBalance()).add(invAccountExcelApplyAmount).toString());
- return enterAccountCard;
- }
- /**
- * 收入方回滚利润方法
- *
- * @return
- */
- private static InvAccountCard enterAccountBreakUtils(String remark, InvAccountCard enterAccountCard, BigDecimal invAccountExcelApplyAmount) {
- switch (remark) {
- case "0":
- enterAccountCard.setInsuranceProfit(new BigDecimal(enterAccountCard.getInsuranceProfit()).subtract(invAccountExcelApplyAmount).toString());
- break;
- case "1":
- enterAccountCard.setClearingProfit(new BigDecimal(enterAccountCard.getClearingProfit()).subtract(invAccountExcelApplyAmount).toString());
- break;
- case "2":
- enterAccountCard.setTianqinProfit(new BigDecimal(enterAccountCard.getTianqinProfit()).subtract(invAccountExcelApplyAmount).toString());
- break;
- case "3":
- enterAccountCard.setParkProfit(new BigDecimal(enterAccountCard.getParkProfit()).subtract(invAccountExcelApplyAmount).toString());
- break;
- case "4":
- enterAccountCard.setOtherProfit(new BigDecimal(enterAccountCard.getOtherProfit()).subtract(invAccountExcelApplyAmount).toString());
- break;
- case "5":
- enterAccountCard.setFiscalProfit(new BigDecimal(enterAccountCard.getFiscalProfit()).subtract(invAccountExcelApplyAmount).toString());
- break;
- case "6":
- enterAccountCard.setExteriorProfit(new BigDecimal(enterAccountCard.getExteriorProfit()).subtract(invAccountExcelApplyAmount).toString());
- break;
- }
- enterAccountCard.setBalance(new BigDecimal(enterAccountCard.getBalance()).subtract(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;
- }
- }
|