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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
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;
    }
}