invAccountExcelController.java 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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.dao.InvAccountExcelMapper;
  8. import com.ydtech.modules.inv.dao.InvAccountOperateMapper;
  9. import com.ydtech.modules.inv.model.InvAccountExcel;
  10. import com.ydtech.modules.inv.model.InvAccountOperate;
  11. import com.ydtech.modules.inv.model.excel.InvDisburseExcel;
  12. import com.ydtech.modules.inv.model.vo.InvAccountOperateVo;
  13. import com.ydtech.modules.inv.service.InvAccountExcelService;
  14. import com.ydtech.modules.inv.utils.EasyExcelUtils;
  15. import io.swagger.annotations.Api;
  16. import io.swagger.annotations.ApiOperation;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.beans.factory.annotation.Value;
  19. import org.springframework.web.bind.annotation.*;
  20. import javax.annotation.Resource;
  21. import java.io.IOException;
  22. import java.nio.file.Files;
  23. import java.nio.file.Path;
  24. import java.nio.file.Paths;
  25. import java.util.Date;
  26. import java.util.List;
  27. import static com.ydtech.modules.inv.utils.TransferUtils.isProfitFull;
  28. /**
  29. * @author jianlong
  30. * @date 2024-01-10 09:49
  31. */
  32. @Api(tags = "账户信息管理", value = "账户信息管理")
  33. @RequestMapping("accountExcel")
  34. @RestController
  35. public class invAccountExcelController {
  36. @Autowired
  37. private InvAccountExcelService invAccountExcelService;
  38. @Resource
  39. private InvAccountExcelMapper invAccountExcelMapper;
  40. @Resource
  41. private InvAccountOperateMapper invAccountOperateMapper;
  42. @Value("${upload.file.path}")
  43. private String uploadPath;
  44. @Value("${upload.file.url}")
  45. private String uploadUrl;
  46. @PostMapping("excel")
  47. @ApiOperation("导出资金申请模板")
  48. public HttpResult excelAccountOperate(@RequestBody List<String> idList) {
  49. return invAccountExcelService.excelAccount(idList);
  50. }
  51. @PostMapping("deriveReport")
  52. @ApiOperation("导出支出报表")
  53. public HttpResult deriveReport(@RequestBody List<String> idList) throws IOException {
  54. List<InvAccountOperate> insAccountExcels = invAccountOperateMapper.selectBatchIds(idList);
  55. String uploadPath = this.uploadPath + "/excel/";
  56. Path path = Paths.get(uploadPath);
  57. if (!Files.exists(path)) {
  58. Files.createDirectories(path);
  59. }
  60. String fileName = EasyExcelUtils.downExcel(uploadPath, "支出报表", InvDisburseExcel.class, insAccountExcels);
  61. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  62. }
  63. @PostMapping("insert")
  64. @ApiOperation("插入资金模板信息")
  65. public HttpResult invertAccount(@RequestBody InvAccountExcel invAccountExcel) {
  66. BaseController baseController = new BaseController();
  67. Date date = new Date();
  68. invAccountExcel.setCreateBy(baseController.getUserName());
  69. invAccountExcel.setCreateTime(date);
  70. JSONObject outProfit = invAccountExcel.getOutProfit();
  71. JSONObject entProfit = invAccountExcel.getEntProfit();
  72. isProfitFull(outProfit, entProfit);
  73. if (invAccountExcel.getOutCardNum() == null && invAccountExcel.getEnterCardNum() == null) {
  74. throw new SystemException("请先选择账户");
  75. }
  76. if (invAccountExcel.getEnterCardNum().equals(invAccountExcel.getOutCardNum())) {
  77. throw new SystemException("无法转账给本公司");
  78. }
  79. invAccountExcel.setTransferFlag("1"); //默认新增时未转帐状态
  80. invAccountExcel.setExcelAccountOperateId(String.valueOf(new Date().getTime()));
  81. if (invAccountExcelService.save(invAccountExcel)) {
  82. return HttpResult.ok("", "新增成功");
  83. }
  84. return HttpResult.error("新增失败");
  85. }
  86. @PostMapping("update")
  87. @ApiOperation("修改资金模板信息")
  88. public HttpResult updateAccount(@RequestBody InvAccountExcel invAccountExcel) {
  89. JSONObject outProfit = invAccountExcel.getOutProfit();
  90. JSONObject entProfit = invAccountExcel.getEntProfit();
  91. isProfitFull(outProfit, entProfit);
  92. if (invAccountExcel.getEnterCardNum().equals(invAccountExcel.getOutCardNum())) {
  93. throw new SystemException("无法转账给本公司");
  94. }
  95. if (invAccountExcel.getExcelAccountOperateId() != null) {
  96. if (invAccountExcel.getTransferFlag().equals("1")) {
  97. BaseController baseController = new BaseController();
  98. invAccountExcel.setUpdateBy(baseController.getUserName());
  99. invAccountExcel.setUpdateTime(new Date());
  100. invAccountExcel.setTransferFlag("1");
  101. return HttpResult.ok("", invAccountExcelService.updateById(invAccountExcel));
  102. } else {
  103. return HttpResult.error("已转账无法修改");
  104. }
  105. } else {
  106. return HttpResult.error("id不能为空");
  107. }
  108. }
  109. @ApiOperation("获取资金模板详细信息")
  110. @GetMapping("getAccountExcelById")
  111. public HttpResult<InvAccountExcel> getAccountExcelById(@RequestParam("excelAccountOperateId") String excelAccountOperateId) {
  112. if (excelAccountOperateId != null) {
  113. InvAccountExcel byId = invAccountExcelService.getById(excelAccountOperateId);
  114. StringBuilder a = new StringBuilder();
  115. String[] split = byId.getPayMethod().split(",");
  116. for (String i : split) {
  117. a.append(InvPayMethodEnum.getNameByCode(i)).append(",");
  118. }
  119. byId.setPayMethod(a.toString());
  120. return HttpResult.ok("", byId);
  121. } else {
  122. return HttpResult.error("id不能为空");
  123. }
  124. }
  125. @ApiOperation("获取资金模板列表")
  126. @PostMapping("getAccountExcel")
  127. public HttpResult getAccountExcel(@RequestBody InvAccountExcel invAccountExcel) {
  128. return invAccountExcelService.selectAccountExcel(invAccountExcel);
  129. }
  130. @ApiOperation("支出报表查看")
  131. @PostMapping("getDisburse")
  132. public HttpResult getDisburse(@RequestBody InvAccountOperateVo invAccountOperateVo) {
  133. return invAccountExcelService.selectDisburse(invAccountOperateVo);
  134. }
  135. @ApiOperation("删除资金模板")
  136. @DeleteMapping("{excelAccountOperateId}")
  137. public HttpResult deleteAccountExcel(@PathVariable("excelAccountOperateId") String excelAccountOperateId) {
  138. InvAccountExcel invAccountExcel = invAccountExcelService.getById(excelAccountOperateId);
  139. if (excelAccountOperateId != null) {
  140. if (invAccountExcel.getTransferFlag() == null) {
  141. return HttpResult.error("转账标志未传递");
  142. }
  143. if (invAccountExcel.getTransferFlag().equals("1")) {
  144. invAccountExcel.setDelFlag("1");
  145. return HttpResult.ok("", invAccountExcelService.updateById(invAccountExcel));
  146. } else {
  147. return HttpResult.error("已转账无法删除");
  148. }
  149. } else {
  150. return HttpResult.error("id不能为空");
  151. }
  152. }
  153. @ApiOperation("修改转账状态")
  154. @GetMapping("updateTransferFlag")
  155. public HttpResult updateTransferFlag(@RequestParam("excelAccountOperateId") String excelAccountOperateId) {
  156. if (excelAccountOperateId == null) {
  157. return HttpResult.error("id不能为空");
  158. }
  159. return invAccountExcelService.updateTransferFlag(excelAccountOperateId);
  160. }
  161. }