| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- package com.ydtech.modules.inv.controller;
- import com.alibaba.fastjson.JSONObject;
- import com.ydtech.constants.enums.inv.InvPayMethodEnum;
- import com.ydtech.core.page.HttpResult;
- import com.ydtech.exception.SystemException;
- import com.ydtech.modules.base.controller.BaseController;
- import com.ydtech.modules.inv.dao.InvAccountExcelMapper;
- import com.ydtech.modules.inv.dao.InvAccountOperateMapper;
- import com.ydtech.modules.inv.model.InvAccountExcel;
- import com.ydtech.modules.inv.model.InvAccountOperate;
- import com.ydtech.modules.inv.model.excel.InvDisburseExcel;
- import com.ydtech.modules.inv.model.vo.InvAccountOperateVo;
- import com.ydtech.modules.inv.service.InvAccountExcelService;
- import com.ydtech.modules.inv.utils.EasyExcelUtils;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.web.bind.annotation.*;
- import javax.annotation.Resource;
- import java.io.IOException;
- import java.nio.file.Files;
- import java.nio.file.Path;
- import java.nio.file.Paths;
- import java.util.Date;
- import java.util.List;
- import static com.ydtech.modules.inv.utils.TransferUtils.isProfitFull;
- /**
- * @author jianlong
- * @date 2024-01-10 09:49
- */
- @Api(tags = "账户信息管理", value = "账户信息管理")
- @RequestMapping("accountExcel")
- @RestController
- public class invAccountExcelController {
- @Autowired
- private InvAccountExcelService invAccountExcelService;
- @Resource
- private InvAccountExcelMapper invAccountExcelMapper;
- @Resource
- private InvAccountOperateMapper invAccountOperateMapper;
- @Value("${upload.file.path}")
- private String uploadPath;
- @Value("${upload.file.url}")
- private String uploadUrl;
- @PostMapping("excel")
- @ApiOperation("导出资金申请模板")
- public HttpResult excelAccountOperate(@RequestBody List<String> idList) {
- return invAccountExcelService.excelAccount(idList);
- }
- @PostMapping("deriveReport")
- @ApiOperation("导出支出报表")
- public HttpResult deriveReport(@RequestBody List<String> idList) throws IOException {
- List<InvAccountOperate> insAccountExcels = invAccountOperateMapper.selectBatchIds(idList);
- String uploadPath = this.uploadPath + "/excel/";
- Path path = Paths.get(uploadPath);
- if (!Files.exists(path)) {
- Files.createDirectories(path);
- }
- String fileName = EasyExcelUtils.downExcel(uploadPath, "支出报表", InvDisburseExcel.class, insAccountExcels);
- return HttpResult.ok("",uploadUrl + "excel/" + fileName);
- }
- @PostMapping("insert")
- @ApiOperation("插入资金模板信息")
- public HttpResult invertAccount(@RequestBody InvAccountExcel invAccountExcel) {
- BaseController baseController = new BaseController();
- Date date = new Date();
- invAccountExcel.setCreateBy(baseController.getUserName());
- invAccountExcel.setCreateTime(date);
- JSONObject outProfit = invAccountExcel.getOutProfit();
- JSONObject entProfit = invAccountExcel.getEntProfit();
- isProfitFull(outProfit, entProfit);
- if (invAccountExcel.getOutCardNum() == null && invAccountExcel.getEnterCardNum() == null) {
- throw new SystemException("请先选择账户");
- }
- if (invAccountExcel.getEnterCardNum().equals(invAccountExcel.getOutCardNum())) {
- throw new SystemException("无法转账给本公司");
- }
- invAccountExcel.setTransferFlag("1"); //默认新增时未转帐状态
- invAccountExcel.setExcelAccountOperateId(String.valueOf(new Date().getTime()));
- if (invAccountExcelService.save(invAccountExcel)) {
- return HttpResult.ok("", "新增成功");
- }
- return HttpResult.error("新增失败");
- }
- @PostMapping("update")
- @ApiOperation("修改资金模板信息")
- public HttpResult updateAccount(@RequestBody InvAccountExcel invAccountExcel) {
- JSONObject outProfit = invAccountExcel.getOutProfit();
- JSONObject entProfit = invAccountExcel.getEntProfit();
- isProfitFull(outProfit, entProfit);
- if (invAccountExcel.getEnterCardNum().equals(invAccountExcel.getOutCardNum())) {
- throw new SystemException("无法转账给本公司");
- }
- if (invAccountExcel.getExcelAccountOperateId() != null) {
- if (invAccountExcel.getTransferFlag().equals("1")) {
- BaseController baseController = new BaseController();
- invAccountExcel.setUpdateBy(baseController.getUserName());
- invAccountExcel.setUpdateTime(new Date());
- invAccountExcel.setTransferFlag("1");
- return HttpResult.ok("", invAccountExcelService.updateById(invAccountExcel));
- } else {
- return HttpResult.error("已转账无法修改");
- }
- } else {
- return HttpResult.error("id不能为空");
- }
- }
- @ApiOperation("获取资金模板详细信息")
- @GetMapping("getAccountExcelById")
- public HttpResult<InvAccountExcel> getAccountExcelById(@RequestParam("excelAccountOperateId") String excelAccountOperateId) {
- if (excelAccountOperateId != null) {
- InvAccountExcel byId = invAccountExcelService.getById(excelAccountOperateId);
- StringBuilder a = new StringBuilder();
- String[] split = byId.getPayMethod().split(",");
- for (String i : split) {
- a.append(InvPayMethodEnum.getNameByCode(i)).append(",");
- }
- byId.setPayMethod(a.toString());
- return HttpResult.ok("", byId);
- } else {
- return HttpResult.error("id不能为空");
- }
- }
- @ApiOperation("获取资金模板列表")
- @PostMapping("getAccountExcel")
- public HttpResult getAccountExcel(@RequestBody InvAccountExcel invAccountExcel) {
- return invAccountExcelService.selectAccountExcel(invAccountExcel);
- }
- @ApiOperation("支出报表查看")
- @PostMapping("getDisburse")
- public HttpResult getDisburse(@RequestBody InvAccountOperateVo invAccountOperateVo) {
- return invAccountExcelService.selectDisburse(invAccountOperateVo);
- }
- @ApiOperation("删除资金模板")
- @DeleteMapping("{excelAccountOperateId}")
- public HttpResult deleteAccountExcel(@PathVariable("excelAccountOperateId") String excelAccountOperateId) {
- InvAccountExcel invAccountExcel = invAccountExcelService.getById(excelAccountOperateId);
- if (excelAccountOperateId != null) {
- if (invAccountExcel.getTransferFlag() == null) {
- return HttpResult.error("转账标志未传递");
- }
- if (invAccountExcel.getTransferFlag().equals("1")) {
- invAccountExcel.setDelFlag("1");
- return HttpResult.ok("", invAccountExcelService.updateById(invAccountExcel));
- } else {
- return HttpResult.error("已转账无法删除");
- }
- } else {
- return HttpResult.error("id不能为空");
- }
- }
- @ApiOperation("修改转账状态")
- @GetMapping("updateTransferFlag")
- public HttpResult updateTransferFlag(@RequestParam("excelAccountOperateId") String excelAccountOperateId) {
- if (excelAccountOperateId == null) {
- return HttpResult.error("id不能为空");
- }
- return invAccountExcelService.updateTransferFlag(excelAccountOperateId);
- }
- }
|