zhuguifei
2025-04-28 442928123f63ee497d766f9a7a14f0a6ee067e25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
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;
    }
 
}