123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- package com.fs.company.controller;
- import java.math.BigDecimal;
- import java.util.Date;
- import java.util.List;
- import com.fs.common.core.domain.R;
- import com.fs.common.utils.ServletUtils;
- import com.fs.company.domain.Company;
- import com.fs.company.domain.CompanyMoneyLogs;
- import com.fs.company.domain.CompanyRecharge;
- import com.fs.company.service.ICompanyMoneyLogsService;
- import com.fs.company.service.ICompanyService;
- import com.fs.company.vo.CompanyDeductExportVO;
- import com.fs.company.vo.CompanyDeductVO;
- import com.fs.company.vo.CompanyRechargeVO;
- import com.fs.core.security.LoginUser;
- import com.fs.core.web.service.TokenService;
- import lombok.Synchronized;
- import org.springframework.security.access.prepost.PreAuthorize;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.PutMapping;
- import org.springframework.web.bind.annotation.DeleteMapping;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import com.fs.common.annotation.Log;
- import com.fs.common.core.controller.BaseController;
- import com.fs.common.core.domain.AjaxResult;
- import com.fs.common.enums.BusinessType;
- import com.fs.company.domain.CompanyDeduct;
- import com.fs.company.service.ICompanyDeductService;
- import com.fs.common.utils.poi.ExcelUtil;
- import com.fs.common.core.page.TableDataInfo;
- /**
- * 扣款Controller
- *
- * @author fs
- * @date 2023-02-27
- */
- @RestController
- @RequestMapping("/company/companyDeduct")
- public class CompanyDeductController extends BaseController
- {
- @Autowired
- private ICompanyDeductService companyDeductService;
- @Autowired
- private TokenService tokenService;
- @Autowired
- private ICompanyService companyService;
- @Autowired
- private ICompanyMoneyLogsService moneyLogsService;
- /**
- * 查询扣款列表
- */
- @PreAuthorize("@ss.hasPermi('company:companyDeduct:list')")
- @GetMapping("/list")
- public TableDataInfo list(CompanyDeduct companyDeduct)
- {
- startPage();
- List<CompanyDeductVO> list = companyDeductService.selectCompanyDeductVOList(companyDeduct);
- return getDataTable(list);
- }
- /**
- * 导出扣款列表
- */
- @PreAuthorize("@ss.hasPermi('company:companyDeduct:export')")
- @Log(title = "扣款", businessType = BusinessType.EXPORT)
- @GetMapping("/export")
- public AjaxResult export(CompanyDeduct companyDeduct)
- {
- List<CompanyDeductExportVO> list = companyDeductService.selectCompanyExportDeductList(companyDeduct);
- ExcelUtil<CompanyDeductExportVO> util = new ExcelUtil<CompanyDeductExportVO>(CompanyDeductExportVO.class);
- return util.exportExcel(list, "companyDeduct");
- }
- /**
- * 获取扣款详细信息
- */
- @PreAuthorize("@ss.hasPermi('company:companyDeduct:query')")
- @GetMapping(value = "/{deductId}")
- public AjaxResult getInfo(@PathVariable("deductId") Long deductId)
- {
- return AjaxResult.success(companyDeductService.selectCompanyDeductById(deductId));
- }
- /**
- * 新增扣款
- */
- @PreAuthorize("@ss.hasPermi('company:companyDeduct:add')")
- @Log(title = "扣款", businessType = BusinessType.INSERT)
- @PostMapping
- public AjaxResult add(@RequestBody CompanyDeduct companyDeduct)
- {
- return toAjax(companyDeductService.insertCompanyDeduct(companyDeduct));
- }
- /**
- * 修改扣款
- */
- @PreAuthorize("@ss.hasPermi('company:companyDeduct:edit')")
- @Log(title = "扣款", businessType = BusinessType.UPDATE)
- @PutMapping
- public AjaxResult edit(@RequestBody CompanyDeduct companyDeduct)
- {
- return toAjax(companyDeductService.updateCompanyDeduct(companyDeduct));
- }
- /**
- * 删除扣款
- */
- @PreAuthorize("@ss.hasPermi('company:companyDeduct:remove')")
- @Log(title = "扣款", businessType = BusinessType.DELETE)
- @DeleteMapping("/{deductIds}")
- public AjaxResult remove(@PathVariable Long[] deductIds)
- {
- return toAjax(companyDeductService.deleteCompanyDeductByIds(deductIds));
- }
- @PreAuthorize("@ss.hasPermi('company:companyDeduct:audit')")
- @PostMapping("/audit")
- @Transactional
- public R audit(@RequestBody CompanyDeduct param)
- {
- CompanyDeduct deduct=companyDeductService.selectCompanyDeductById(param.getDeductId());
- if(deduct.getIsAudit()!=0){
- return R.error("非法操作");
- }
- deduct.setIsAudit(param.getIsAudit());
- deduct.setRemark(param.getRemark());
- LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
- if(deduct.getIsAudit()==1){
- Company company=companyService.selectCompanyByIdForUpdate(deduct.getCompanyId());
- company.setMoney(company.getMoney().subtract(deduct.getMoney()));
- companyService.updateCompany(company);
- CompanyMoneyLogs log=new CompanyMoneyLogs();
- log.setCompanyId(deduct.getCompanyId());
- log.setMoney(deduct.getMoney().multiply(new BigDecimal(-1)));
- log.setRemark(deduct.getRemark());
- log.setLogsType(2);
- log.setBalance(company.getMoney());
- log.setCreateTime(new Date());
- moneyLogsService.insertCompanyMoneyLogs(log);
- }
- deduct.setAuditTime(new Date());
- deduct.setAuditUserId(loginUser.getUser().getUserId());
- companyDeductService.updateCompanyDeduct(deduct);
- return R.ok("操作成功");
- }
- }
|