郑永安
2023-06-19 59e91a4e9ddaf23cebb12993c774aa899ab22d16
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
package com.gk.firework.Service.ServiceImpl;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gk.firework.Domain.AssessApply;
import com.gk.firework.Domain.Enterprise;
import com.gk.firework.Domain.Enum.AssessApplyStatus;
import com.gk.firework.Domain.Enum.AssessPunishment;
import com.gk.firework.Domain.Enum.AssessType;
import com.gk.firework.Domain.Enum.PunishStatus;
import com.gk.firework.Domain.Exception.BusinessException;
import com.gk.firework.Domain.UserInfo;
import com.gk.firework.Domain.Utils.Properties;
import com.gk.firework.Domain.Utils.StringUtils;
import com.gk.firework.Domain.Utils.UploadUtil;
import com.gk.firework.Domain.Vo.AssessApplyAppealVo;
import com.gk.firework.Mapper.AssessApplyMapper;
import com.gk.firework.Service.AssessApplyService;
import com.gk.firework.Service.EnterpriseService;
import com.gk.firework.Service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.*;
 
@Service("assessApplyService")
public class AssessApplyServiceImpl extends ServiceImpl<AssessApplyMapper, AssessApply> implements AssessApplyService {
 
    @Autowired
    private AssessApplyMapper assessApplyMapper;
    @Autowired
    private UserService userService;
    @Autowired
    private EnterpriseService enterpriseService;
 
    @Override
    public void addSaleAssessApply(AssessApply assessApply, UserInfo user)  {
 
        if (StringUtils.isBlank(assessApply.getEnterprisename())
                || StringUtils.isBlank(assessApply.getEnterprisenumber()))
            throw new BusinessException("请选择企业信息");
 
        if (assessApply.getPunishmentmeasure() == null)
            throw new BusinessException("请选择处罚措施");
 
        if (StringUtils.isBlank(assessApply.getPunishmentreason()))
            throw new BusinessException("请填写处罚原因");
 
        assessApply.setValidflag(true);
        assessApply.setCode("SA-" + System.currentTimeMillis());
        assessApply.setCreatetime(new Date());
        assessApply.setRequestor(user.getUsername());
        assessApply.setRequestorid(user.getId());
        assessApply.setPunishstatus(PunishStatus.UNPUNISH);
        assessApply.setStatus(AssessApplyStatus.TOSUBMIT);
        assessApply.setType(AssessType.SALE);
        if (assessApply.getFile() != null) {
            try {
                String filename = UploadUtil.uploadFile(assessApply.getFile(), Properties.assessApplyPath);
                assessApply.setPath1(Properties.assessApply + filename);
            } catch (Exception e) {
                e.printStackTrace();
                throw new BusinessException("上传文件出现问题,请联系管理员");
            }
        }
 
        this.save(assessApply);
    }
 
    @Override
    public void modSaleAssessApply(AssessApply assessApply, UserInfo user) {
 
        AssessApply aa = this.getById(assessApply.getId());
        if (aa == null)
            throw new BusinessException("单子不存在,请联系管理员");
 
        if (aa.getStatus() != AssessApplyStatus.TOSUBMIT
                && aa.getStatus() != AssessApplyStatus.REJECT)
            throw new BusinessException("提交后的单子不能修改");
 
        if (StringUtils.isBlank(assessApply.getEnterprisename())
                || StringUtils.isBlank(assessApply.getEnterprisenumber()))
            throw new BusinessException("请选择企业信息");
 
        if (assessApply.getPunishmentmeasure() == null)
            throw new BusinessException("请选择处罚措施");
 
        if (StringUtils.isBlank(assessApply.getPunishmentreason()))
            throw new BusinessException("请填写处罚原因");
 
        if (assessApply.getFile() != null) {
            try {
                String filename = UploadUtil.uploadFile(assessApply.getFile(), Properties.assessApplyPath);
                aa.setPath1(Properties.assessApply + filename);
            } catch (Exception e) {
                e.printStackTrace();
                throw new BusinessException("上传文件出现问题,请联系管理员");
            }
        }
 
        aa.setPunishmentmeasure(assessApply.getPunishmentmeasure());
        aa.setPunishmentreason(assessApply.getPunishmentreason());
        aa.setModifytime(new Date());
        aa.setEnterprisename(assessApply.getEnterprisename());
        aa.setEnterprisenumber(assessApply.getEnterprisenumber());
        this.updateById(aa);
    }
 
    @Override
    public void submitSaleAssessApply(Long id, UserInfo user) {
        AssessApply assessApply = this.getById(id);
        if (assessApply.getStatus() != AssessApplyStatus.REJECT
                && assessApply.getStatus() != AssessApplyStatus.TOSUBMIT) {
            throw new BusinessException("当前状态不能提交");
        }
 
        assessApply.setStatus(AssessApplyStatus.PENDING);
        assessApply.setSubmittime(new Date());
        this.updateById(assessApply);
    }
 
    /**
     * @Description: 审批通过,直接停用
     * @date 2021/7/12 8:47
     */
    @Override
    @Transactional
    public void approveSaleAssessApply(JSONObject entity, UserInfo user) {
        Long id = entity.getLong("id");
//        String approvenote = entity.getString("approvenote");
 
        if (id == null ) throw new BusinessException("传参有误,请联系管理员");
 
        AssessApply assessApply = this.getById(id);
        if (assessApply == null) throw new BusinessException("传参有误或者单子不存在");
 
        assessApply.setApprover(user.getUsername());
        assessApply.setApprovetime(new Date());
        assessApply.setStatus(AssessApplyStatus.APPROVED);
//        assessApply.setApprovenote(StringUtils.isBlank(approvenote) ? null : approvenote);
        assessApply.setPunishstatus(PunishStatus.PUNISHING);
        this.updateById(assessApply);
        //直接执行处罚 先停用
        enterpriseService.deactivateEnterprise(null,assessApply.getEnterprisenumber(), user);
    }
 
    @Override
    public void rejectSaleAssessApply(JSONObject entity, UserInfo user) {
        Long id = entity.getLong("id");
        String lastrejectreason = entity.getString("lastrejectreason");
 
        if (id == null ) throw new BusinessException("传参有误,请联系管理员");
 
        if (StringUtils.isBlank(lastrejectreason)) throw new BusinessException("请填写拒绝理由");
 
        AssessApply assessApply = this.getById(id);
        if (assessApply == null) throw new BusinessException("传参有误或者单子不存在");
 
        Date now = new Date();
        assessApply.setApprover(user.getUsername());
        assessApply.setApprovetime(now);
        assessApply.setLastrejecttime(now);
        assessApply.setStatus(AssessApplyStatus.REJECT);
        assessApply.setLastrejectreason(lastrejectreason);
        this.updateById(assessApply);
    }
 
    /**
     * @Description: 销售评定分页查询
     * @date 2021/7/5 14:30
     */
    @Override
    public IPage selectSalePages(Page<AssessApply> page, Map filter, UserInfo user) {
        Map<String, Object> params = new HashMap<>();
        params.put("type", AssessType.SALE);
        params.put("code", filter.get("code"));
        params.put("enterprisename", filter.get("enterprisename"));
        params.put("status", filter.get("status"));
        //不是超级管理员只能看到自己的
        if (user.getType() != 1 && user.getType()!= 2) {
            params.put("requestorid", user.getId());
        }
        List<AssessApply> data = assessApplyMapper.selectPages(params, page);
        return page.setRecords(data);
    }
 
 
    @Override
    public void addAccessAssessApply(AssessApply assessApply, UserInfo user) {
        if (StringUtils.isBlank(assessApply.getEnterprisename())
                || StringUtils.isBlank(assessApply.getEnterprisenumber()))
            throw new BusinessException("请选择企业信息");
 
        if (assessApply.getPunishmentmeasure() == null)
            throw new BusinessException("请选择处罚措施");
 
        if (StringUtils.isBlank(assessApply.getPunishmentreason()))
            throw new BusinessException("请填写处罚意见");
 
        if (assessApply.getFile() == null)
            throw new BusinessException("请上传处罚凭证");
 
        assessApply.setValidflag(true);
        assessApply.setPunishstatus(PunishStatus.UNPUNISH);
        assessApply.setCode("AA-" + System.currentTimeMillis());
        assessApply.setCreatetime(new Date());
        assessApply.setRequestor(user.getUsername());
        assessApply.setRequestorid(user.getId());
        assessApply.setStatus(AssessApplyStatus.TOSUBMIT);
        assessApply.setType(AssessType.ACCESS);
 
        try {
            String filename = UploadUtil.uploadFile(assessApply.getFile(), Properties.assessApplyPath);
            assessApply.setPath1(Properties.assessApply + filename);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException("上传文件出现问题,请联系管理员");
        }
        this.save(assessApply);
 
    }
 
    @Override
    public void modAccessAssessApply(AssessApply assessApply, UserInfo user) {
        AssessApply aa = this.getById(assessApply.getId());
        if (aa == null)
            throw new BusinessException("单子不存在,请联系管理员");
 
        if (aa.getStatus() != AssessApplyStatus.TOSUBMIT
                && aa.getStatus() != AssessApplyStatus.REJECT)
            throw new BusinessException("提交后的单子不能修改");
 
        if (StringUtils.isBlank(assessApply.getEnterprisename())
                || StringUtils.isBlank(assessApply.getEnterprisenumber()))
            throw new BusinessException("请选择企业信息");
 
        if (StringUtils.isBlank(assessApply.getPunishmentreason()))
            throw new BusinessException("请填写处罚意见");
 
        if (assessApply.getFile() == null)
            throw new BusinessException("请上传处罚凭证");
 
 
        try {
            String filename = UploadUtil.uploadFile(assessApply.getFile(), Properties.assessApplyPath);
            aa.setPath1(Properties.assessApply + filename);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException("上传文件出现问题,请联系管理员");
        }
        aa.setPunishmentmeasure(assessApply.getPunishmentmeasure());
        aa.setPunishmentreason(assessApply.getPunishmentreason());
        aa.setModifytime(new Date());
        aa.setEnterprisename(assessApply.getEnterprisename());
        aa.setEnterprisenumber(assessApply.getEnterprisenumber());
        //处罚的信息
        this.updateById(aa);
 
    }
 
    @Override
    public void submitAccessAssessApply(Long id, UserInfo user) {
        AssessApply assessApply = this.getById(id);
        if (assessApply.getStatus() != AssessApplyStatus.REJECT
                && assessApply.getStatus() != AssessApplyStatus.TOSUBMIT) {
            throw new BusinessException("当前状态不能提交");
        }
 
        assessApply.setStatus(AssessApplyStatus.PENDING);
        assessApply.setSubmittime(new Date());
        this.updateById(assessApply);
    }
 
 
    @Override
    public List<AssessApply> selectAllPunishingSaleAssessApply() {
        //条件一:type为sale 销售评定
        //条件二:处罚中的单子 punishing
        return assessApplyMapper.selectAllPunishingSaleAssessApply(AssessType.SALE, PunishStatus.PUNISHING);
    }
 
 
}