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.entity.BonusPaymentItem;
|
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.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.math.BigDecimal;
|
import java.util.Arrays;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
|
@Slf4j
|
@Api(tags = "奖金发放item表")
|
@RestController
|
@RequestMapping("/bon/item")
|
public class BonusPaymentItemController extends JeecgController<BonusPaymentItem, IBonusPaymentItemService> {
|
@Autowired
|
private IBonusPaymentService bonusPaymentService;
|
|
@Autowired
|
private IProProjectService projectService;
|
|
@Autowired
|
private IBonusAllocationService allocationService;
|
|
@Autowired
|
private IBonusPaymentItemService paymentItemService;
|
|
/**************************市场型*******************************/
|
@RequestMapping(value = "/addsc", method = RequestMethod.POST)
|
@AutoLog(value = "添加市场型项目奖金发放item")
|
@Transactional
|
public Result<BonusPaymentItem> addsc(@RequestBody BonusPaymentItem item, HttpServletRequest request) {
|
Result<BonusPaymentItem> result = new Result<BonusPaymentItem>();
|
//查询项目是否已定额
|
BonusPayment payment = bonusPaymentService.getById(item.getPid());
|
if (payment == null) {
|
result.error500("未找到对应实体");
|
return result;
|
} else if (payment.getDe() == CommonConstant.BONUS_DE_STATU_0) {
|
result.error500("项目未定额,请先完成定额");
|
return result;
|
}
|
|
//计算添加里程碑应发金额
|
BigDecimal b = item.getYfje().multiply(new BigDecimal(item.getYfbl())).divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_DOWN);
|
item.setYfje(b);
|
item.setSfje(b);
|
//考评比例默认100%
|
item.setKpbl(100.0);
|
paymentItemService.save(item);
|
result.success("添加成功!");
|
result.setResult(item);
|
return result;
|
}
|
|
|
|
/**************************市场型*******************************/
|
|
/**************************客户型*******************************/
|
@RequestMapping(value = "/addkh", method = RequestMethod.POST)
|
@AutoLog(value = "添加客户型项目奖金发放item")
|
@Transactional
|
public Result<BonusPaymentItem> addkh(@RequestBody BonusPaymentItem item, HttpServletRequest request) {
|
Result<BonusPaymentItem> result = new Result<BonusPaymentItem>();
|
//查询项目是否已定额
|
BonusPayment payment = bonusPaymentService.getById(item.getPid());
|
if (payment == null) {
|
result.error500("未找到对应实体");
|
return result;
|
} else if (payment.getDe() == CommonConstant.BONUS_DE_STATU_0) {
|
result.error500("项目未定额,请先完成定额");
|
return result;
|
}
|
paymentItemService.save(item);
|
|
//发放后统计核算金额
|
String pid = item.getPid();
|
Map<String, Object> map = new HashMap<>();
|
map.put("pid", pid);
|
//考评后需重新计算项目核算奖金
|
List<BonusPaymentItem> bonusPaymentItems = paymentItemService.listByMap(map);
|
BigDecimal total = new BigDecimal(0);
|
double xse = 0.0;
|
for (int i = 0; i < bonusPaymentItems.size(); i++) {
|
BonusPaymentItem bonusPaymentItem = bonusPaymentItems.get(i);
|
BigDecimal sfje = bonusPaymentItem.getSfje();
|
Double x = bonusPaymentItem.getXse();
|
total = total.add(sfje);
|
xse += x;
|
}
|
payment.setSjjj(total.doubleValue());
|
payment.setXse(xse);
|
bonusPaymentService.updateById(payment);
|
|
result.success("添加成功!");
|
result.setResult(item);
|
return result;
|
}
|
|
/**************************客户型*******************************/
|
|
|
/**************************项目型*******************************/
|
@RequestMapping(value = "/addxm", method = RequestMethod.POST)
|
@AutoLog(value = "添加项目型项目奖金发放item")
|
@Transactional
|
public Result<BonusPaymentItem> addXm(@RequestBody BonusPaymentItem item, HttpServletRequest request) {
|
Result<BonusPaymentItem> result = new Result<BonusPaymentItem>();
|
//查询项目是否已定额
|
BonusPayment payment = bonusPaymentService.getById(item.getPid());
|
if (payment == null) {
|
result.error500("未找到对应实体");
|
return result;
|
} else if (payment.getDe() == CommonConstant.BONUS_DE_STATU_0) {
|
result.error500("项目未定额,请先完成定额");
|
return result;
|
}
|
|
//计算添加里程碑应发金额
|
item.setSfje(item.getYfje());
|
paymentItemService.save(item);
|
result.success("添加成功!");
|
result.setResult(item);
|
return result;
|
}
|
|
|
|
/**************************项目型*******************************/
|
|
|
/**************************贡献型*******************************/
|
@RequestMapping(value = "/addgx", method = RequestMethod.POST)
|
@AutoLog(value = "添加贡献型项目奖金发放item")
|
@Transactional
|
public Result<BonusPaymentItem> addgx(@RequestBody BonusPaymentItem item, HttpServletRequest request) {
|
Result<BonusPaymentItem> result = new Result<BonusPaymentItem>();
|
//查询项目是否已定额
|
BonusPayment payment = bonusPaymentService.getById(item.getPid());
|
if (payment == null) {
|
result.error500("未找到对应实体");
|
return result;
|
} else if (payment.getDe() == CommonConstant.BONUS_DE_STATU_0) {
|
result.error500("项目未定额,请先完成定额");
|
return result;
|
}
|
paymentItemService.save(item);
|
|
//发放后统计核算金额
|
String pid = item.getPid();
|
Map<String, Object> map = new HashMap<>();
|
map.put("pid", pid);
|
//考评后需重新计算项目核算奖金
|
List<BonusPaymentItem> bonusPaymentItems = paymentItemService.listByMap(map);
|
BigDecimal total = new BigDecimal(0);
|
double xse = 0.0;
|
for (int i = 0; i < bonusPaymentItems.size(); i++) {
|
BonusPaymentItem bonusPaymentItem = bonusPaymentItems.get(i);
|
BigDecimal sfje = bonusPaymentItem.getSfje();
|
Double x = bonusPaymentItem.getXse();
|
total = total.add(sfje);
|
xse += x;
|
}
|
payment.setSjjj(total.doubleValue());
|
payment.setXse(xse);
|
bonusPaymentService.updateById(payment);
|
|
result.success("添加成功!");
|
result.setResult(item);
|
return result;
|
}
|
|
/**************************贡献型*******************************/
|
|
|
|
@ApiOperation(value = "获取项目奖金发放item列表")
|
@AutoLog(value = "获取项目奖金发放item列表")
|
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
public Result<?> queryPageList(BonusPaymentItem item,
|
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
HttpServletRequest req) {
|
if (item.getPid().isEmpty()) {
|
return Result.error("参数不识别");
|
}
|
Result<IPage<BonusPaymentItem>> result = new Result<IPage<BonusPaymentItem>>();
|
QueryWrapper<BonusPaymentItem> queryWrapper = QueryGenerator.initQueryWrapper(item, req.getParameterMap());
|
Page<BonusPaymentItem> page = new Page<BonusPaymentItem>(pageNo, pageSize);
|
IPage<BonusPaymentItem> pageList = paymentItemService.page(page, queryWrapper);
|
result.setSuccess(true);
|
result.setResult(pageList);
|
return result;
|
}
|
|
|
@RequestMapping(value = "/edit", method = RequestMethod.PUT)
|
public Result<BonusPaymentItem> edit(@RequestBody BonusPaymentItem paymentItem) {
|
Result<BonusPaymentItem> result = new Result<BonusPaymentItem>();
|
paymentItemService.updateById(paymentItem);
|
result.success("修改成功!");
|
result.setResult(paymentItem);
|
String pid = paymentItem.getPid();
|
Map<String, Object> map = new HashMap<>();
|
map.put("pid", pid);
|
//考评后需重新计算项目核算奖金
|
List<BonusPaymentItem> bonusPaymentItems = paymentItemService.listByMap(map);
|
BigDecimal zjj = new BigDecimal(0);
|
BigDecimal yfjj = new BigDecimal(0);
|
for (int i = 0; i < bonusPaymentItems.size(); i++) {
|
BonusPaymentItem bonusPaymentItem = bonusPaymentItems.get(i);
|
BigDecimal sfje = bonusPaymentItem.getSfje();
|
BigDecimal fpze = bonusPaymentItem.getFpze();
|
zjj = zjj.add(sfje);
|
if(fpze!=null)
|
yfjj = yfjj.add(fpze);
|
}
|
BonusPayment payment = bonusPaymentService.getById(pid);
|
payment.setSjjj(zjj.doubleValue());
|
//如果是已分配状态计算更新已分配总金额 更新发放进度
|
if(paymentItem.getPaymentStatu() == 1){
|
payment.setYfjj(yfjj.doubleValue());
|
payment.setFfjd(paymentItem.getFfjd());
|
}
|
bonusPaymentService.updateById(payment);
|
|
return result;
|
}
|
|
|
@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
|
@Transactional
|
public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
|
paymentItemService.removeById(id);
|
Map<String, Object> map = new HashMap<>();
|
map.put("pid", id);
|
//删除里程碑时同时删除发放明细
|
allocationService.removeByMap(map);
|
return Result.ok("删除成功");
|
}
|
|
|
}
|