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.BonusAllocation; 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.HashMap; import java.util.List; import java.util.Map; @Slf4j @Api(tags = "奖金分配表") @RestController @RequestMapping("/bon/alloca") public class BonusAllocationController extends JeecgController { @Autowired private IBonusPaymentService bonusPaymentService; @Autowired private IProProjectService projectService; @Autowired private IBonusPaymentItemService paymentItemService; @Autowired private IBonusAllocationService allocationService; @RequestMapping(value = "/list", method = RequestMethod.GET) public Result> queryPageList(BonusAllocation allocation, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "100") Integer pageSize, HttpServletRequest req) { Result> result = new Result>(); //没有分配明细id(bonus_payment_item)不查询 if (allocation.getPid() == null) return result; QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(allocation, req.getParameterMap()); Page page = new Page(pageNo, pageSize); IPage pageList = allocationService.page(page, queryWrapper); result.setSuccess(true); result.setResult(pageList); return result; } @RequestMapping(value = "/add", method = RequestMethod.POST) @AutoLog(value = "添加里程碑分配明细") @Transactional public Result add(@RequestBody BonusPaymentItem paymentItem, HttpServletRequest request) { Result result = new Result(); //主要更新项目成员,以及分配总额以及总配总比例 paymentItemService.updateById(paymentItem); //新增明细前删除历史明细 String id = paymentItem.getId(); Map map = new HashMap<>(); map.put("pid",id); allocationService.removeByMap(map); List allocationList = paymentItem.getAllocationList(); String userNames = ""; //保存分配明细 for (int i = 0; i < allocationList.size(); i++) { BonusAllocation bonusAllocation = allocationList.get(i); bonusAllocation.setPid(paymentItem.getId()); bonusAllocation.setPpid(paymentItem.getPid()); bonusAllocation.setPro(paymentItem.getPro()); allocationService.save(bonusAllocation); } result.success("添加成功!"); result.setResult(paymentItem); return result; } /* @RequestMapping(value = "/edit", method = RequestMethod.PUT) public Result edit(@RequestBody ProProject project) { Result result = new Result(); proProjectService.updateProject(project); result.success("修改成功!"); result.setResult(project); return result; } */ }