package org.jeecg.modules.bonus.controller;
|
|
import io.swagger.annotations.Api;
|
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.modules.bonus.entity.BonusPayment;
|
import org.jeecg.modules.bonus.entity.BonusPaymentItem;
|
import org.jeecg.modules.bonus.entity.BonusQuotaParam;
|
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.service.IProProjectService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.servlet.http.HttpServletRequest;
|
import java.math.BigDecimal;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
|
@Slf4j
|
@Api(tags = "项目定额")
|
@RestController
|
@RequestMapping("/bon/quota")
|
public class BonusQuotaParamController extends JeecgController<BonusQuotaParam, IBonusQuotaParamService> {
|
@Autowired
|
private IBonusPaymentService bonusPaymentService;
|
@Autowired
|
private IBonusPaymentItemService bonusPaymentItemService;
|
@Autowired
|
private IBonusQuotaParamService quotaParamService;
|
|
@Autowired
|
private IProProjectService projectService;
|
|
//----------------------市场型-------------------------------
|
@AutoLog(value = "项目产品(市场)-定额")
|
@RequestMapping(value = "/sc", method = RequestMethod.PUT)
|
@Transactional
|
public Result<BonusQuotaParam> quotaSc(@RequestBody BonusQuotaParam param, HttpServletRequest request) {
|
Result<BonusQuotaParam> result = new Result<BonusQuotaParam>();
|
|
BonusPayment payment = bonusPaymentService.getById(param.getId());
|
if (payment == null ) {
|
result.error500("未找到对应实体");
|
return result;
|
}
|
//先查询是否已定额并且核算状态
|
Map<String,Object> map = new HashMap<>();
|
map.put("pid",param.getId());
|
List<BonusPaymentItem> bonusPaymentItems = bonusPaymentItemService.listByMap(map);
|
if (bonusPaymentItems != null && bonusPaymentItems.size() > 0) {
|
result.error500("该项目已定额并核算奖金,请先删除核算记录再重新定额");
|
return result;
|
}
|
|
|
//计算定额奖金
|
BonusQuotaParam proQuotaParam = quotaParamService.calcScParam(param);
|
//保存定额参数及奖金
|
quotaParamService.saveOrUpdate(proQuotaParam);
|
//更新奖金发放表
|
payment.setDe(CommonConstant.BONUS_DE_STATU_1);
|
payment.setDejj(proQuotaParam.getQuotaBonus().doubleValue());
|
payment.setSjjj(proQuotaParam.getQuotaBonus().doubleValue());
|
bonusPaymentService.updateById(payment);
|
|
result.setSuccess(true);
|
result.setMessage("操作成功!");
|
|
return result;
|
|
}
|
|
//----------------------市场型-------------------------------
|
|
|
//----------------------客户型-------------------------------
|
@AutoLog(value = "项目产品(客户)-定额")
|
@RequestMapping(value = "/kh", method = RequestMethod.PUT)
|
@Transactional
|
public Result<BonusQuotaParam> quotaKh(@RequestBody BonusQuotaParam param, HttpServletRequest request) {
|
Result<BonusQuotaParam> result = new Result<BonusQuotaParam>();
|
BonusPayment payment = bonusPaymentService.getById(param.getId());
|
if (payment == null ) {
|
result.error500("未找到对应实体");
|
return result;
|
}
|
//先查询是否已定额并且核算状态
|
Map<String,Object> map = new HashMap<>();
|
map.put("pid",param.getId());
|
List<BonusPaymentItem> bonusPaymentItems = bonusPaymentItemService.listByMap(map);
|
if (bonusPaymentItems != null && bonusPaymentItems.size() > 0) {
|
result.error500("该项目已定额并核算奖金,请先删除核算记录再重新定额");
|
return result;
|
}
|
|
//保存定额参数
|
quotaParamService.saveOrUpdate(param);
|
//更新奖金发放表
|
payment.setDe(CommonConstant.BONUS_DE_STATU_1);
|
payment.setTcxs(param.getKhTcxs());
|
bonusPaymentService.updateById(payment);
|
|
result.setSuccess(true);
|
result.setMessage("操作成功!");
|
|
return result;
|
|
}
|
//----------------------客户型-------------------------------
|
|
//----------------------项目型-------------------------------
|
@AutoLog(value = "项目产品(项目)-定额")
|
@RequestMapping(value = "/xm", method = RequestMethod.PUT)
|
@Transactional
|
public Result<BonusQuotaParam> quotaXm(@RequestBody BonusQuotaParam param, HttpServletRequest request) {
|
Result<BonusQuotaParam> result = new Result<BonusQuotaParam>();
|
|
BonusPayment payment = bonusPaymentService.getById(param.getId());
|
if (payment == null ) {
|
result.error500("未找到对应实体");
|
return result;
|
}
|
//先查询是否已定额并且核算状态
|
Map<String,Object> map = new HashMap<>();
|
map.put("pid",param.getId());
|
List<BonusPaymentItem> bonusPaymentItems = bonusPaymentItemService.listByMap(map);
|
if (bonusPaymentItems != null && bonusPaymentItems.size() > 0) {
|
result.error500("该项目已定额并核算奖金,请先删除核算记录再重新定额");
|
return result;
|
}
|
|
|
//计算定额奖金
|
double quota = param.getBase() * param.getXmJsfl() * param.getXmNdfl();
|
BigDecimal q = new BigDecimal(quota);
|
BigDecimal quotaBonus = q.setScale(0, BigDecimal.ROUND_HALF_DOWN);
|
param.setQuotaBonus(quotaBonus);
|
//保存定额参数及奖金
|
quotaParamService.saveOrUpdate(param);
|
//更新奖金发放表
|
payment.setDe(CommonConstant.BONUS_DE_STATU_1);
|
payment.setDejj(quotaBonus.doubleValue());
|
payment.setSjjj(quotaBonus.doubleValue());
|
bonusPaymentService.updateById(payment);
|
|
//TODO 修改贡献型技术分类
|
Double xmJsfl = param.getXmJsfl();
|
//通过项目号以及类型 找到与项目型对应的贡献型奖励
|
Map<String,Object> m = new HashMap<>();
|
m.put("pro",payment.getPro());
|
m.put("type",4);
|
List<BonusPayment> bonusPayments = bonusPaymentService.listByMap(m);
|
if(bonusPayments!=null && bonusPayments.size() > 0){
|
BonusPayment p = bonusPayments.get(0);
|
//设置技术分类索引 注释看CommonConstant.BONUS_JSFL_MAP
|
p.setJsfl(CommonConstant.BONUS_JSFL_MAP().get(xmJsfl));
|
bonusPaymentService.updateById(p);
|
}
|
|
result.setSuccess(true);
|
result.setMessage("操作成功!");
|
|
return result;
|
|
}
|
|
//----------------------项目型-------------------------------
|
|
|
//----------------------贡献型-------------------------------
|
@AutoLog(value = "项目产品(贡献)-定额")
|
@RequestMapping(value = "/gx", method = RequestMethod.PUT)
|
@Transactional
|
public Result<BonusQuotaParam> quotaGx(@RequestBody BonusQuotaParam param, HttpServletRequest request) {
|
Result<BonusQuotaParam> result = new Result<BonusQuotaParam>();
|
|
BonusPayment payment = bonusPaymentService.getById(param.getId());
|
if (payment == null ) {
|
result.error500("未找到对应实体");
|
return result;
|
}
|
//先查询是否已定额并且核算状态
|
Map<String,Object> map = new HashMap<>();
|
map.put("pid",param.getId());
|
List<BonusPaymentItem> bonusPaymentItems = bonusPaymentItemService.listByMap(map);
|
if (bonusPaymentItems != null && bonusPaymentItems.size() > 0) {
|
result.error500("该项目已定额并核算奖金,请先删除核算记录再重新定额");
|
return result;
|
}
|
|
|
//保存定额参数及奖金
|
quotaParamService.saveOrUpdate(param);
|
//更新奖金发放表
|
payment.setDe(CommonConstant.BONUS_DE_STATU_1);
|
//设置成本系数
|
payment.setTcxs(param.getGxCbxs());
|
|
bonusPaymentService.updateById(payment);
|
|
result.setSuccess(true);
|
result.setMessage("操作成功!");
|
|
return result;
|
|
}
|
|
//----------------------贡献型-------------------------------
|
|
|
|
@RequestMapping(value = "/query", method = RequestMethod.GET)
|
public Result<BonusQuotaParam> queryQuotaParam(BonusQuotaParam param, HttpServletRequest req) {
|
Result<BonusQuotaParam> result = new Result<BonusQuotaParam>();
|
BonusQuotaParam byId = quotaParamService.getById(param.getId());
|
if (byId != null) {
|
result.setResult(byId);
|
result.setSuccess(true);
|
} else {
|
result.error500("未找到对应实体");
|
}
|
|
return result;
|
}
|
}
|