TransferUtils.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. package com.ydtech.modules.inv.utils;
  2. import com.ydtech.constants.enums.inv.InsAccountOperateEnum;
  3. import com.ydtech.exception.SystemException;
  4. import com.ydtech.modules.inv.model.*;
  5. import java.math.BigDecimal;
  6. import java.util.ArrayList;
  7. import java.util.List;
  8. /**
  9. * 转账工具类
  10. *
  11. * @author jianlong
  12. * @date 2024-01-10 14:10
  13. */
  14. public class TransferUtils {
  15. /**
  16. * 转账成功后添加支出账户操作信息
  17. */
  18. public static InvAccountOperate insertOutAccountOperate(InvAccountExcel insAccountExcel) {
  19. //支出公司
  20. InvAccountOperate insAccountOperate = new InvAccountOperate();
  21. operate(insAccountExcel, insAccountOperate);
  22. insAccountOperate.setRevenueOutlay("1");
  23. return insAccountOperate;
  24. }
  25. /**
  26. * 转账成功后添加收入账户操作信息
  27. */
  28. public static InvAccountOperate insertRevenueAccountOperate(InvAccountExcel insAccountExcel) {
  29. //支出公司
  30. InvAccountOperate insAccountOperate = new InvAccountOperate();
  31. operate(insAccountExcel, insAccountOperate);
  32. insAccountOperate.setRevenueOutlay("0");
  33. return insAccountOperate;
  34. }
  35. private static void operate(InvAccountExcel invAccountExcel, InvAccountOperate invAccountOperate) {
  36. invAccountOperate.setApplicant(invAccountExcel.getApplicant());
  37. invAccountOperate.setApplySector(invAccountExcel.getApplySector());
  38. invAccountOperate.setApplyTime(invAccountExcel.getApplyTime());
  39. invAccountOperate.setCollectionMessage(invAccountExcel.getCollectionMessage());
  40. invAccountOperate.setFundFlow(invAccountExcel.getFundFlow());
  41. invAccountOperate.setFundUse(invAccountExcel.getFundUse());
  42. invAccountOperate.setPayMethod(invAccountExcel.getPayMethod());
  43. invAccountOperate.setRemark(InsAccountOperateEnum.getNameByCode(invAccountExcel.getRemark()));
  44. invAccountOperate.setCompany(invAccountExcel.getCompany());
  45. invAccountOperate.setApplyAmount(invAccountExcel.getApplyAmount());
  46. invAccountOperate.setBigApplyAmount(invAccountExcel.getBigApplyAmount());
  47. }
  48. /**
  49. * 内部转内部方法
  50. */
  51. public static List<InvAccountCard> insideTransfer(InvAccountCard outAccountCard, InvAccountCard enterAccountCard, InvAccountExcel invAccountExcel) {
  52. List<InvAccountCard> list = new ArrayList<>();
  53. if (outAccountCard != null && enterAccountCard != null && invAccountExcel != null) {
  54. //公户单日转账剩余
  55. BigDecimal pubDayLinesExcess = new BigDecimal(outAccountCard.getPubDayLinesExcess());
  56. //私户单日转账剩余
  57. BigDecimal priDayLinesExcess = new BigDecimal(outAccountCard.getPriDayLinesExcess());
  58. //公户年额度剩余
  59. BigDecimal pubYearExcess = new BigDecimal(outAccountCard.getPubYearExcess());
  60. //私户年额度剩余
  61. BigDecimal priYearExcess = new BigDecimal(outAccountCard.getPriYearExcess());
  62. //对公单笔限额
  63. BigDecimal pubSingleLines = new BigDecimal(outAccountCard.getPubSingleLines());
  64. //对私单笔限额
  65. BigDecimal priSingleLines = new BigDecimal(outAccountCard.getPriSingleLines());
  66. //单日转账笔数剩余
  67. long dayStrokeNumExcess = Long.parseLong(outAccountCard.getDayStrokeNumExcess());
  68. //申请金额
  69. BigDecimal insAccountExcelApplyAmount = new BigDecimal(invAccountExcel.getApplyAmount());
  70. //转出账户现支出金额
  71. BigDecimal outAccountSpend = new BigDecimal(outAccountCard.getSpend());
  72. if (enterAccountCard.getAccountQuality().equals("0")) {
  73. //公户操作
  74. if (pubSingleLines.compareTo(insAccountExcelApplyAmount) > 0){
  75. //收入方增加余额
  76. String remark = invAccountExcel.getRemark();
  77. list.add(pubAccountUtils(dayStrokeNumExcess,pubDayLinesExcess,pubYearExcess,insAccountExcelApplyAmount,outAccountCard,outAccountSpend));
  78. list.add(enterAccountUtils(remark, enterAccountCard, insAccountExcelApplyAmount));
  79. return list;
  80. }
  81. throw new SystemException("公户转账金额超出单笔限额");
  82. } else {
  83. if(priSingleLines.compareTo(insAccountExcelApplyAmount) > 0){
  84. //私户操作
  85. String remark = invAccountExcel.getRemark();
  86. list.add(priAccountUtils(dayStrokeNumExcess,priDayLinesExcess,insAccountExcelApplyAmount, priYearExcess,outAccountSpend,outAccountCard));
  87. list.add(enterAccountUtils(remark, enterAccountCard, insAccountExcelApplyAmount));
  88. return list;
  89. }
  90. throw new SystemException("私户转账金额超出单笔限额");
  91. }
  92. }
  93. return list;
  94. }
  95. /**
  96. * 外部转内部方法
  97. */
  98. public static InvAccountCard outsideTransfer(InvAccountCard enterAccountCard, InvAccountOperate invAccountOperate) {
  99. if (enterAccountCard == null && invAccountOperate == null) {
  100. throw new SystemException("收入账户为空");
  101. }
  102. String remark = invAccountOperate.getRemark();
  103. BigDecimal applyAmount = new BigDecimal(invAccountOperate.getApplyAmount());
  104. return enterAccountUtils(remark, enterAccountCard, applyAmount);
  105. }
  106. /**
  107. * 撤销发票方法
  108. */
  109. public static InvAccountCard quashOutsideTransfer(InvAccountCard enterAccountCard, InvAccountIncoice invAccountIncoice) {
  110. if (enterAccountCard == null && invAccountIncoice == null) {
  111. throw new SystemException("账户为空");
  112. }
  113. String remark = invAccountIncoice.getRemark();
  114. BigDecimal applyAmount = new BigDecimal(invAccountIncoice.getInvoiceMoney());
  115. return enterAccountBreakUtils(remark, enterAccountCard, applyAmount);
  116. }
  117. /**
  118. * 内部转外部方法
  119. */
  120. public static List<InvAccountCard> enterDeTransfer(InvAccountCard outAccountCard, InvAccountCard enterAccountCard, InvAccountExcel invAccountExcel) {
  121. List<InvAccountCard> list = new ArrayList<>();
  122. if (outAccountCard != null && enterAccountCard != null && invAccountExcel != null) {
  123. //公户单日转账剩余
  124. BigDecimal pubDayLinesExcess = new BigDecimal(outAccountCard.getPubDayLinesExcess());
  125. //私户单日转账剩余
  126. BigDecimal priDayLinesExcess = new BigDecimal(outAccountCard.getPriDayLinesExcess());
  127. //公户年额度剩余
  128. BigDecimal pubYearExcess = new BigDecimal(outAccountCard.getPubYearExcess());
  129. //私户年额度剩余
  130. BigDecimal priYearExcess = new BigDecimal(outAccountCard.getPriYearExcess());
  131. //单日转账笔数剩余
  132. long dayStrokeNumExcess = Long.parseLong(outAccountCard.getDayStrokeNumExcess());
  133. //申请金额
  134. BigDecimal insAccountExcelApplyAmount = new BigDecimal(invAccountExcel.getApplyAmount());
  135. //转出账户现支出金额
  136. BigDecimal outAccountSpend = new BigDecimal(outAccountCard.getSpend());
  137. if (invAccountExcel.getOutAccountQuality().equals("0")) {
  138. //公户操作
  139. list.add(pubAccountUtils(dayStrokeNumExcess,pubDayLinesExcess,pubYearExcess,insAccountExcelApplyAmount,outAccountCard,outAccountSpend));
  140. return list;
  141. } else {
  142. //私户操作
  143. list.add(priAccountUtils(dayStrokeNumExcess,priDayLinesExcess,insAccountExcelApplyAmount, priYearExcess,outAccountSpend,outAccountCard));
  144. return list;
  145. }
  146. }
  147. return list;
  148. }
  149. /**
  150. * 收入方增加利润方法
  151. *
  152. * @return
  153. */
  154. private static InvAccountCard enterAccountUtils(String remark, InvAccountCard enterAccountCard, BigDecimal invAccountExcelApplyAmount) {
  155. if (remark.isEmpty()){
  156. throw new SystemException("备注不能为空");
  157. }
  158. if (enterAccountCard == null){
  159. throw new SystemException("收入账户为空");
  160. }
  161. switch (remark) {
  162. case "0":
  163. enterAccountCard.setInsuranceProfit(new BigDecimal(enterAccountCard.getInsuranceProfit()).add(invAccountExcelApplyAmount).toString());
  164. break;
  165. case "1":
  166. enterAccountCard.setClearingProfit(new BigDecimal(enterAccountCard.getClearingProfit()).add(invAccountExcelApplyAmount).toString());
  167. break;
  168. case "2":
  169. enterAccountCard.setTianqinProfit(new BigDecimal(enterAccountCard.getTianqinProfit()).add(invAccountExcelApplyAmount).toString());
  170. break;
  171. case "3":
  172. enterAccountCard.setParkProfit(new BigDecimal(enterAccountCard.getParkProfit()).add(invAccountExcelApplyAmount).toString());
  173. break;
  174. case "4":
  175. enterAccountCard.setOtherProfit(new BigDecimal(enterAccountCard.getOtherProfit()).add(invAccountExcelApplyAmount).toString());
  176. break;
  177. case "5":
  178. enterAccountCard.setFiscalProfit(new BigDecimal(enterAccountCard.getFiscalProfit()).add(invAccountExcelApplyAmount).toString());
  179. break;
  180. case "6":
  181. enterAccountCard.setExteriorProfit(new BigDecimal(enterAccountCard.getExteriorProfit()).add(invAccountExcelApplyAmount).toString());
  182. break;
  183. }
  184. enterAccountCard.setBalance(new BigDecimal(enterAccountCard.getBalance()).add(invAccountExcelApplyAmount).toString());
  185. return enterAccountCard;
  186. }
  187. /**
  188. * 收入方回滚利润方法
  189. *
  190. * @return
  191. */
  192. private static InvAccountCard enterAccountBreakUtils(String remark, InvAccountCard enterAccountCard, BigDecimal invAccountExcelApplyAmount) {
  193. switch (remark) {
  194. case "0":
  195. enterAccountCard.setInsuranceProfit(new BigDecimal(enterAccountCard.getInsuranceProfit()).subtract(invAccountExcelApplyAmount).toString());
  196. break;
  197. case "1":
  198. enterAccountCard.setClearingProfit(new BigDecimal(enterAccountCard.getClearingProfit()).subtract(invAccountExcelApplyAmount).toString());
  199. break;
  200. case "2":
  201. enterAccountCard.setTianqinProfit(new BigDecimal(enterAccountCard.getTianqinProfit()).subtract(invAccountExcelApplyAmount).toString());
  202. break;
  203. case "3":
  204. enterAccountCard.setParkProfit(new BigDecimal(enterAccountCard.getParkProfit()).subtract(invAccountExcelApplyAmount).toString());
  205. break;
  206. case "4":
  207. enterAccountCard.setOtherProfit(new BigDecimal(enterAccountCard.getOtherProfit()).subtract(invAccountExcelApplyAmount).toString());
  208. break;
  209. case "5":
  210. enterAccountCard.setFiscalProfit(new BigDecimal(enterAccountCard.getFiscalProfit()).subtract(invAccountExcelApplyAmount).toString());
  211. break;
  212. case "6":
  213. enterAccountCard.setExteriorProfit(new BigDecimal(enterAccountCard.getExteriorProfit()).subtract(invAccountExcelApplyAmount).toString());
  214. break;
  215. }
  216. enterAccountCard.setBalance(new BigDecimal(enterAccountCard.getBalance()).subtract(invAccountExcelApplyAmount).toString());
  217. return enterAccountCard;
  218. }
  219. /**
  220. * 公户扣除余额方法
  221. */
  222. private static InvAccountCard pubAccountUtils(long dayStrokeNumExcess, BigDecimal pubDayLinesExcess, BigDecimal pubYearExcess, BigDecimal invAccountExcelApplyAmount, InvAccountCard outAccountCard,BigDecimal outAccountSpend) {
  223. //判断单日转账笔数是否超过
  224. if (dayStrokeNumExcess <= 0) {
  225. throw new SystemException("公户单日转账笔数不足");
  226. }
  227. //判断单日转账金额是否超过
  228. if (pubDayLinesExcess.compareTo(BigDecimal.valueOf(0)) != 0 && pubDayLinesExcess.compareTo(invAccountExcelApplyAmount) < 0) {
  229. throw new SystemException("公户单日转账金额不足");
  230. }
  231. //判断年额度是否超过
  232. if (pubYearExcess.compareTo(BigDecimal.valueOf(0)) != 0 && pubYearExcess.compareTo(invAccountExcelApplyAmount) < 0) {
  233. throw new SystemException("公户年额度不足");
  234. }
  235. //支出方减少余额
  236. outAccountCard.setSpend(outAccountSpend.add(invAccountExcelApplyAmount).toString());
  237. outAccountCard.setBalance(new BigDecimal(outAccountCard.getBalance()).subtract(invAccountExcelApplyAmount).toString());
  238. //公户单日转账笔数减少
  239. outAccountCard.setDayStrokeNumExcess(String.valueOf(dayStrokeNumExcess - 1));
  240. //公户单日转账剩余减少
  241. outAccountCard.setPubDayLinesExcess(pubDayLinesExcess.subtract(invAccountExcelApplyAmount).toString());
  242. //公户年额度减少
  243. outAccountCard.setPubYearExcess(pubYearExcess.subtract(invAccountExcelApplyAmount).toString());
  244. return outAccountCard;
  245. }
  246. /**
  247. * 私户扣除余额方法
  248. */
  249. private static InvAccountCard priAccountUtils(long dayStrokeNumExcess, BigDecimal priDayLinesExcess, BigDecimal invAccountExcelApplyAmount, BigDecimal priYearExcess, BigDecimal outAccountSpend,InvAccountCard outAccountCard) {
  250. if (dayStrokeNumExcess <= 0) {
  251. throw new SystemException("私户单日转账笔数不足");
  252. }
  253. if (priDayLinesExcess.compareTo(BigDecimal.valueOf(0)) != 0 && priDayLinesExcess.compareTo(invAccountExcelApplyAmount) < 0) {
  254. throw new SystemException("私户单日转账金额不足");
  255. }
  256. if (priYearExcess.compareTo(BigDecimal.valueOf(0)) != 0 && priYearExcess.compareTo(invAccountExcelApplyAmount) < 0) {
  257. throw new SystemException("私户年额度不足");
  258. }
  259. outAccountCard.setSpend(outAccountSpend.add(invAccountExcelApplyAmount).toString());
  260. outAccountCard.setBalance(new BigDecimal(outAccountCard.getBalance()).subtract(invAccountExcelApplyAmount).toString());
  261. outAccountCard.setDayStrokeNumExcess(String.valueOf(dayStrokeNumExcess - 1));
  262. outAccountCard.setPriDayLinesExcess(priDayLinesExcess.subtract(invAccountExcelApplyAmount).toString());
  263. outAccountCard.setPriYearExcess(priYearExcess.subtract(invAccountExcelApplyAmount).toString());
  264. return outAccountCard;
  265. }
  266. }