invAccountExcelController.java 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. package com.ydtech.modules.inv.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.ydtech.constants.enums.inv.InvPayMethodEnum;
  4. import com.ydtech.core.page.HttpResult;
  5. import com.ydtech.exception.SystemException;
  6. import com.ydtech.modules.base.controller.BaseController;
  7. import com.ydtech.modules.inv.model.InvAccount;
  8. import com.ydtech.modules.inv.model.InvAccountCard;
  9. import com.ydtech.modules.inv.model.InvAccountExcel;
  10. import com.ydtech.modules.inv.service.InvAccountCardService;
  11. import com.ydtech.modules.inv.service.InvAccountExcelService;
  12. import com.ydtech.modules.inv.service.InvAccountService;
  13. import io.swagger.annotations.Api;
  14. import io.swagger.annotations.ApiOperation;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.web.bind.annotation.*;
  17. import java.math.BigDecimal;
  18. import java.util.Date;
  19. import java.util.List;
  20. import java.util.Map;
  21. /**
  22. * @author jianlong
  23. * @date 2024-01-10 09:49
  24. */
  25. @Api(tags = "账户信息管理", value = "账户信息管理")
  26. @RequestMapping("accountExcel")
  27. @RestController
  28. public class invAccountExcelController {
  29. @Autowired
  30. private InvAccountExcelService invAccountExcelService;
  31. @PostMapping("excel")
  32. @ApiOperation("导出资金申请模板")
  33. public HttpResult excelAccountOperate(@RequestBody List<String> idList) {
  34. return invAccountExcelService.excelAccount(idList);
  35. }
  36. @PostMapping("invert")
  37. @ApiOperation("插入资金模板信息")
  38. public HttpResult invertAccount(@RequestBody InvAccountExcel invAccountExcel) {
  39. BaseController baseController = new BaseController();
  40. Date date = new Date();
  41. invAccountExcel.setCreateBy(baseController.getUserName());
  42. invAccountExcel.setCreateTime(date);
  43. JSONObject outProfit = invAccountExcel.getOutProfit();
  44. JSONObject entProfit = invAccountExcel.getEntProfit();
  45. BigDecimal outAmount = new BigDecimal(0);
  46. BigDecimal entAmount = new BigDecimal(0);
  47. for (Map.Entry<String, Object> entry:outProfit.entrySet()){
  48. outAmount = outAmount.add(new BigDecimal(entry.getValue().toString()));
  49. }
  50. for (Map.Entry<String, Object> entry:entProfit.entrySet()){
  51. entAmount = entAmount.add(new BigDecimal(entry.getValue().toString()));
  52. }
  53. if (!String.valueOf(outAmount).equals("100")){
  54. throw new SystemException("支出金额未完全分配");
  55. }
  56. if (!String.valueOf(entAmount).equals("100")){
  57. throw new SystemException("收入金额未完全分配");
  58. }
  59. if (invAccountExcel.getOutCardNum() == null && invAccountExcel.getEnterCardNum() == null) {
  60. throw new SystemException("请先选择账户");
  61. }
  62. if (invAccountExcel.getEnterCardNum().equals(invAccountExcel.getOutCardNum())) {
  63. throw new SystemException("无法转账给本公司");
  64. }
  65. if (invAccountExcelService.save(invAccountExcel)) {
  66. return HttpResult.ok("", invAccountExcel.getExcelAccountOperateId());
  67. }
  68. return HttpResult.error("新增失败");
  69. }
  70. @PostMapping("update")
  71. @ApiOperation("修改资金模板信息")
  72. public HttpResult updateAccount(@RequestBody InvAccountExcel invAccountExcel) {
  73. JSONObject outProfit = invAccountExcel.getOutProfit();
  74. JSONObject entProfit = invAccountExcel.getEntProfit();
  75. BigDecimal outAmount = new BigDecimal(0);
  76. BigDecimal entAmount = new BigDecimal(0);
  77. for (Map.Entry<String, Object> entry:outProfit.entrySet()){
  78. outAmount = outAmount.add(new BigDecimal(entry.getValue().toString()));
  79. }
  80. for (Map.Entry<String, Object> entry:entProfit.entrySet()){
  81. entAmount = entAmount.add(new BigDecimal(entry.getValue().toString()));
  82. }
  83. if (!String.valueOf(outAmount).equals("100")){
  84. throw new SystemException("支出金额未完全分配");
  85. }
  86. if (!String.valueOf(entAmount).equals("100")){
  87. throw new SystemException("收入金额未完全分配");
  88. }
  89. if (invAccountExcel.getExcelAccountOperateId() != null) {
  90. if (invAccountExcel.getTransferFlag().equals("1")) {
  91. BaseController baseController = new BaseController();
  92. invAccountExcel.setUpdateBy(baseController.getUserName());
  93. invAccountExcel.setUpdateTime(new Date());
  94. return HttpResult.ok("", invAccountExcelService.updateById(invAccountExcel));
  95. } else {
  96. return HttpResult.error("已转账无法修改");
  97. }
  98. } else {
  99. return HttpResult.error("id不能为空");
  100. }
  101. }
  102. @ApiOperation("获取资金模板详细信息")
  103. @GetMapping("getAccountExcelById")
  104. public HttpResult<InvAccountExcel> getAccountExcelById(@RequestParam("excelAccountOperateId") String excelAccountOperateId) {
  105. if (excelAccountOperateId != null) {
  106. InvAccountExcel byId = invAccountExcelService.getById(excelAccountOperateId);
  107. StringBuilder a = new StringBuilder();
  108. String[] split = byId.getPayMethod().split(",");
  109. for (String i : split) {
  110. a.append(InvPayMethodEnum.getNameByCode(i)).append(",");
  111. }
  112. byId.setPayMethod(a.toString());
  113. return HttpResult.ok("", byId);
  114. } else {
  115. return HttpResult.error("id不能为空");
  116. }
  117. }
  118. @ApiOperation("获取资金模板列表")
  119. @PostMapping("getAccountExcel")
  120. public HttpResult getAccountExcel(@RequestBody InvAccountExcel invAccountExcel) {
  121. return invAccountExcelService.selectAccountExcel(invAccountExcel);
  122. }
  123. @ApiOperation("删除资金模板")
  124. @DeleteMapping("{excelAccountOperateId}")
  125. public HttpResult deleteAccountExcel(@PathVariable("excelAccountOperateId") String excelAccountOperateId) {
  126. InvAccountExcel invAccountExcel = invAccountExcelService.getById(excelAccountOperateId);
  127. if (excelAccountOperateId != null) {
  128. if (invAccountExcel.getTransferFlag() == null) {
  129. return HttpResult.error("转账标志未传递");
  130. }
  131. if (invAccountExcel.getTransferFlag().equals("1")) {
  132. invAccountExcel.setDelFlag("1");
  133. return HttpResult.ok("", invAccountExcelService.updateById(invAccountExcel));
  134. } else {
  135. return HttpResult.error("已转账无法删除");
  136. }
  137. } else {
  138. return HttpResult.error("id不能为空");
  139. }
  140. }
  141. @ApiOperation("修改转账状态")
  142. @GetMapping("updateTransferFlag")
  143. public HttpResult updateTransferFlag(@RequestParam("excelAccountOperateId") String excelAccountOperateId) {
  144. if (excelAccountOperateId == null) {
  145. return HttpResult.error("id不能为空");
  146. }
  147. return invAccountExcelService.updateTransferFlag(excelAccountOperateId);
  148. }
  149. }