CompanyDeductController.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package com.fs.company.controller;
  2. import java.math.BigDecimal;
  3. import java.util.Date;
  4. import java.util.List;
  5. import com.fs.common.core.domain.R;
  6. import com.fs.common.utils.ServletUtils;
  7. import com.fs.company.domain.Company;
  8. import com.fs.company.domain.CompanyMoneyLogs;
  9. import com.fs.company.domain.CompanyRecharge;
  10. import com.fs.company.service.ICompanyMoneyLogsService;
  11. import com.fs.company.service.ICompanyService;
  12. import com.fs.company.vo.CompanyDeductExportVO;
  13. import com.fs.company.vo.CompanyDeductVO;
  14. import com.fs.company.vo.CompanyRechargeVO;
  15. import com.fs.core.security.LoginUser;
  16. import com.fs.core.web.service.TokenService;
  17. import lombok.Synchronized;
  18. import org.springframework.security.access.prepost.PreAuthorize;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.transaction.annotation.Transactional;
  21. import org.springframework.web.bind.annotation.GetMapping;
  22. import org.springframework.web.bind.annotation.PostMapping;
  23. import org.springframework.web.bind.annotation.PutMapping;
  24. import org.springframework.web.bind.annotation.DeleteMapping;
  25. import org.springframework.web.bind.annotation.PathVariable;
  26. import org.springframework.web.bind.annotation.RequestBody;
  27. import org.springframework.web.bind.annotation.RequestMapping;
  28. import org.springframework.web.bind.annotation.RestController;
  29. import com.fs.common.annotation.Log;
  30. import com.fs.common.core.controller.BaseController;
  31. import com.fs.common.core.domain.AjaxResult;
  32. import com.fs.common.enums.BusinessType;
  33. import com.fs.company.domain.CompanyDeduct;
  34. import com.fs.company.service.ICompanyDeductService;
  35. import com.fs.common.utils.poi.ExcelUtil;
  36. import com.fs.common.core.page.TableDataInfo;
  37. /**
  38. * 扣款Controller
  39. *
  40. * @author fs
  41. * @date 2023-02-27
  42. */
  43. @RestController
  44. @RequestMapping("/company/companyDeduct")
  45. public class CompanyDeductController extends BaseController
  46. {
  47. @Autowired
  48. private ICompanyDeductService companyDeductService;
  49. @Autowired
  50. private TokenService tokenService;
  51. @Autowired
  52. private ICompanyService companyService;
  53. @Autowired
  54. private ICompanyMoneyLogsService moneyLogsService;
  55. /**
  56. * 查询扣款列表
  57. */
  58. @PreAuthorize("@ss.hasPermi('company:companyDeduct:list')")
  59. @GetMapping("/list")
  60. public TableDataInfo list(CompanyDeduct companyDeduct)
  61. {
  62. startPage();
  63. List<CompanyDeductVO> list = companyDeductService.selectCompanyDeductVOList(companyDeduct);
  64. return getDataTable(list);
  65. }
  66. /**
  67. * 导出扣款列表
  68. */
  69. @PreAuthorize("@ss.hasPermi('company:companyDeduct:export')")
  70. @Log(title = "扣款", businessType = BusinessType.EXPORT)
  71. @GetMapping("/export")
  72. public AjaxResult export(CompanyDeduct companyDeduct)
  73. {
  74. List<CompanyDeductExportVO> list = companyDeductService.selectCompanyExportDeductList(companyDeduct);
  75. ExcelUtil<CompanyDeductExportVO> util = new ExcelUtil<CompanyDeductExportVO>(CompanyDeductExportVO.class);
  76. return util.exportExcel(list, "companyDeduct");
  77. }
  78. /**
  79. * 获取扣款详细信息
  80. */
  81. @PreAuthorize("@ss.hasPermi('company:companyDeduct:query')")
  82. @GetMapping(value = "/{deductId}")
  83. public AjaxResult getInfo(@PathVariable("deductId") Long deductId)
  84. {
  85. return AjaxResult.success(companyDeductService.selectCompanyDeductById(deductId));
  86. }
  87. /**
  88. * 新增扣款
  89. */
  90. @PreAuthorize("@ss.hasPermi('company:companyDeduct:add')")
  91. @Log(title = "扣款", businessType = BusinessType.INSERT)
  92. @PostMapping
  93. public AjaxResult add(@RequestBody CompanyDeduct companyDeduct)
  94. {
  95. return toAjax(companyDeductService.insertCompanyDeduct(companyDeduct));
  96. }
  97. /**
  98. * 修改扣款
  99. */
  100. @PreAuthorize("@ss.hasPermi('company:companyDeduct:edit')")
  101. @Log(title = "扣款", businessType = BusinessType.UPDATE)
  102. @PutMapping
  103. public AjaxResult edit(@RequestBody CompanyDeduct companyDeduct)
  104. {
  105. return toAjax(companyDeductService.updateCompanyDeduct(companyDeduct));
  106. }
  107. /**
  108. * 删除扣款
  109. */
  110. @PreAuthorize("@ss.hasPermi('company:companyDeduct:remove')")
  111. @Log(title = "扣款", businessType = BusinessType.DELETE)
  112. @DeleteMapping("/{deductIds}")
  113. public AjaxResult remove(@PathVariable Long[] deductIds)
  114. {
  115. return toAjax(companyDeductService.deleteCompanyDeductByIds(deductIds));
  116. }
  117. @PreAuthorize("@ss.hasPermi('company:companyDeduct:audit')")
  118. @PostMapping("/audit")
  119. @Transactional
  120. public R audit(@RequestBody CompanyDeduct param)
  121. {
  122. CompanyDeduct deduct=companyDeductService.selectCompanyDeductById(param.getDeductId());
  123. if(deduct.getIsAudit()!=0){
  124. return R.error("非法操作");
  125. }
  126. deduct.setIsAudit(param.getIsAudit());
  127. deduct.setRemark(param.getRemark());
  128. LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
  129. if(deduct.getIsAudit()==1){
  130. Company company=companyService.selectCompanyByIdForUpdate(deduct.getCompanyId());
  131. company.setMoney(company.getMoney().subtract(deduct.getMoney()));
  132. companyService.updateCompany(company);
  133. CompanyMoneyLogs log=new CompanyMoneyLogs();
  134. log.setCompanyId(deduct.getCompanyId());
  135. log.setMoney(deduct.getMoney().multiply(new BigDecimal(-1)));
  136. log.setRemark(deduct.getRemark());
  137. log.setLogsType(2);
  138. log.setBalance(company.getMoney());
  139. log.setCreateTime(new Date());
  140. moneyLogsService.insertCompanyMoneyLogs(log);
  141. }
  142. deduct.setAuditTime(new Date());
  143. deduct.setAuditUserId(loginUser.getUser().getUserId());
  144. companyDeductService.updateCompanyDeduct(deduct);
  145. return R.ok("操作成功");
  146. }
  147. }