TransferUtils.java 14 KB

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