package org.jeecg.modules.bonus.controller;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.extern.slf4j.Slf4j;
|
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.aspect.annotation.AutoLog;
|
import org.jeecg.common.constant.CommonConstant;
|
import org.jeecg.common.system.base.controller.JeecgController;
|
import org.jeecg.common.system.query.QueryGenerator;
|
import org.jeecg.modules.bonus.entity.BonusPayment;
|
import org.jeecg.modules.bonus.service.IBonusAllocationService;
|
import org.jeecg.modules.bonus.service.IBonusPaymentItemService;
|
import org.jeecg.modules.bonus.service.IBonusPaymentService;
|
import org.jeecg.modules.bonus.service.IBonusQuotaParamService;
|
import org.jeecg.modules.project.entity.ProProject;
|
import org.jeecg.modules.project.service.IProProjectService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.HttpServletRequest;
|
import java.util.Arrays;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* (BonusPayment)表控制层
|
*
|
* @author makejava
|
* @since 2022-03-18 16:43:57
|
*/
|
@Slf4j
|
@Api(tags = "奖金发放表")
|
@RestController
|
@RequestMapping("/bon/payment")
|
public class BonusPaymentController extends JeecgController<BonusPayment, IBonusPaymentService> {
|
@Autowired
|
private IBonusPaymentService bonusPaymentService;
|
@Autowired
|
private IBonusPaymentItemService bonusPaymentItemService;
|
|
@Autowired
|
private IProProjectService projectService;
|
@Autowired
|
private IBonusQuotaParamService quotaParamService;
|
@Autowired
|
private IBonusAllocationService allocationService;
|
|
@ApiOperation(value = "获取奖金发放列表", notes = "获取所有奖金发放列表")
|
@AutoLog(value = "获取奖金发放列表")
|
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
public Result<?> queryPageList(BonusPayment payment,
|
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
HttpServletRequest req) {
|
/*Page<BonusPayment> page = new Page<BonusPayment>(pageNo, pageSize);
|
List<BonusPayment> list = bonusPaymentService.queryPageList(payment);
|
page.setRecords(list);*/
|
Result<IPage<BonusPayment>> result = new Result<IPage<BonusPayment>>();
|
QueryWrapper<BonusPayment> queryWrapper = QueryGenerator.initQueryWrapper(payment, req.getParameterMap());
|
Page<BonusPayment> page = new Page<BonusPayment>(pageNo, pageSize);
|
IPage<BonusPayment> pageList = bonusPaymentService.page(page, queryWrapper);
|
result.setSuccess(true);
|
result.setResult(pageList);
|
return result;
|
}
|
|
@RequestMapping(value = "/add", method = RequestMethod.POST)
|
@AutoLog(value = "添加项目奖金发放")
|
@Transactional
|
public Result<BonusPayment> add(@RequestBody BonusPayment payment, HttpServletRequest request) {
|
Result<BonusPayment> result = new Result<BonusPayment>();
|
bonusPaymentService.save(payment);
|
ProProject pro = new ProProject();
|
pro.setId(payment.getPro());
|
pro.setBonus(CommonConstant.BONUS_PAYMENT_STATU_1);//设置项目为已发放奖金
|
projectService.saveOrUpdate(pro);
|
|
//TODO 贡献型奖励是项目型奖励的第二阶段,所以新增项目型时同时新增贡献型
|
if (payment.getType() == 3) {
|
payment.setId(null);
|
payment.setType(4);
|
bonusPaymentService.save(payment);
|
}
|
|
|
result.success("添加成功!");
|
result.setResult(payment);
|
return result;
|
}
|
|
/**
|
*
|
*/
|
@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
|
@Transactional
|
public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
|
BonusPayment payment = bonusPaymentService.getById(id);
|
ProProject pro = new ProProject();
|
pro.setId(payment.getPro());
|
pro.setBonus(CommonConstant.BONUS_PAYMENT_STATU_0);//删除时设置奖金未发放
|
projectService.saveOrUpdate(pro);
|
//同时删除定额表 核算表 分配明细表
|
Map<String, Object> map = new HashMap<>();
|
map.put("pid", id);
|
bonusPaymentItemService.removeByMap(map);
|
quotaParamService.removeById(id);
|
|
//TODO 贡献型奖励是项目型奖励的第二阶段,所以删除项目型时同时删除贡献型
|
if(payment.getType()==3){
|
Map<String,Object> del = new HashMap<>();
|
del.put("pro",payment.getPro());
|
bonusPaymentService.removeByMap(del);
|
}
|
bonusPaymentService.removeById(id);
|
|
|
Map<String, Object> map2 = new HashMap<>();
|
map2.put("ppid", id);
|
allocationService.removeByMap(map2);
|
return Result.ok("删除成功");
|
}
|
|
@RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
|
@Transactional
|
public Result<BonusPayment> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
|
|
Result<BonusPayment> result = new Result<BonusPayment>();
|
if (ids == null || "".equals(ids.trim())) {
|
result.error500("参数不识别!");
|
} else {
|
List<String> asList = Arrays.asList(ids.split(","));
|
for (int i = 0; i < asList.size(); i++) {
|
String id = asList.get(i);
|
BonusPayment payment = bonusPaymentService.getById(id);
|
ProProject pro = new ProProject();
|
pro.setId(payment.getPro());
|
pro.setBonus(CommonConstant.BONUS_PAYMENT_STATU_0);//设置项目为已发放奖金
|
projectService.saveOrUpdate(pro);
|
|
//删除 核算表
|
Map<String, Object> map = new HashMap<>();
|
map.put("pid", id);
|
bonusPaymentItemService.removeByMap(map);
|
//删除 分配明细表
|
Map<String, Object> map2 = new HashMap<>();
|
map2.put("ppid", id);
|
allocationService.removeByMap(map2);
|
|
//TODO 贡献型奖励是项目型奖励的第二阶段,所以删除项目型时同时删除贡献型
|
if(payment.getType()==3){
|
Map<String,Object> del = new HashMap<>();
|
del.put("pro",payment.getPro());
|
bonusPaymentService.removeByMap(del);
|
}
|
}
|
bonusPaymentService.removeByIds(asList);
|
//同时删除定额表
|
quotaParamService.removeByIds(asList);
|
result.success("删除成功!");
|
}
|
return result;
|
}
|
|
}
|