郑永安
2023-06-19 f65443d8abeaedc9d102324565e8368e7c9d90c8
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
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.AccessAssessApply;
import com.gk.firework.Domain.AssessApply;
import com.gk.firework.Domain.Enum.AssessAppealStatus;
import com.gk.firework.Domain.Enum.AssessApplyStatus;
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.AccessAssessApplyMapper;
import com.gk.firework.Service.AccessAssessApplyService;
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("accessAssessApplyService")
public class AccessAssessApplyServiceImpl extends ServiceImpl<AccessAssessApplyMapper, AccessAssessApply> implements AccessAssessApplyService {
 
    @Autowired
    private AccessAssessApplyMapper accessAssessApplyMapper;
    @Autowired
    private UserService userService;
 
 
    /**
     * @Description: 准入评定分页查询
     * @date 2021/7/5 14:30
     */
    @Override
    public IPage selectAccessPages(Page<AccessAssessApply> page, Map filter, UserInfo user) {
        Map<String, Object> params = new HashMap<>();
        params.put("type", AssessType.ACCESS);
        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<AccessAssessApply> data = accessAssessApplyMapper.selectPages(params, page);
        return page.setRecords(data);
    }
 
 
    @Override
    public void AccessAppeal(AccessAssessApply accessAccessApply, UserInfo user) {
 
        Long id = accessAccessApply.getId();
        if (id == null) throw new
                BusinessException("参数传递错误,请联系管理员");
        String appealcontent = accessAccessApply.getAppealcontent();
        AccessAssessApply aa = this.getById(id);
        assert aa.getDeadline() != null;
        Date now = new Date();
        //时间检查
        if (now.after(aa.getDeadline()))
            throw new BusinessException("已超过截止日期,不可申诉");
        //处罚状态
        if (aa.getPunishstatus() != PunishStatus.UNPUNISH)
            throw new BusinessException("处罚已经执行,不能申诉");
        //状态变更为申诉中
        if (aa.getAppealstatus() != AssessAppealStatus.UNAPPEALED)
            throw new BusinessException("单子已经在申诉中或者已经完成,无法再次申诉");
 
        if (accessAccessApply.getFile() == null)
            throw new BusinessException("请上传申诉文件");
 
        try {
            String filename = UploadUtil.uploadFile(accessAccessApply.getFile(), com.gk.firework.Domain.Utils.Properties.assessApplyPath);
            aa.setPath2(Properties.assessApply + filename);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException("上传文件出现问题,请联系管理员");
        }
        aa.setAppealstatus(AssessAppealStatus.APPEALING);
        aa.setAppealtime(now);
        aa.setAppealcontent(StringUtils.isBlank(appealcontent) ? null : appealcontent);
        this.updateById(aa);
    }
 
 
    @Override
    public void approveAccessAssessApply(JSONObject entity, UserInfo user) {
        Long id = entity.getLong("id");
        if (id == null ) throw new BusinessException("传参有误,请联系管理员");
 
        AccessAssessApply accessAssessApply = this.getById(id);
        if (accessAssessApply == null) throw new BusinessException("传参有误或者单子不存在");
 
        accessAssessApply.setApprover(user.getUsername());
        Date approveDate = new Date();
        accessAssessApply.setApprovetime(approveDate);
        //往后推两周 后的晚上零点为截止日期
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(approveDate);
        calendar.add(Calendar.WEEK_OF_YEAR, 2);
        calendar.add(Calendar.DATE,1);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        accessAssessApply.setDeadline(calendar.getTime());
        accessAssessApply.setStatus(AssessApplyStatus.APPROVED);
        accessAssessApply.setAppealstatus(AssessAppealStatus.UNAPPEALED);
        this.updateById(accessAssessApply);
    }
 
    @Override
    public void rejectAccessAssessApply(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("请填写拒绝理由");
 
        AccessAssessApply accessAssessApply = this.getById(id);
        if (accessAssessApply == null) throw new BusinessException("传参有误或者单子不存在");
 
        Date now = new Date();
        accessAssessApply.setApprover(user.getUsername());
        accessAssessApply.setApprovetime(now);
        accessAssessApply.setLastrejecttime(now);
        accessAssessApply.setStatus(AssessApplyStatus.REJECT);
        accessAssessApply.setLastrejectreason(lastrejectreason);
        this.updateById(accessAssessApply);
    }
 
 
    /**
     * @Description: 申诉通过
     * @date 2021/7/9 9:11
     */
    @Override
    @Transactional
    public void appealAccessPass(Long id, UserInfo user) {
 
        if (id == null)
            throw new BusinessException("参数传递错误,请联系管理员");
 
        AccessAssessApply accessAssessApply = this.getById(id);
        if (accessAssessApply == null)
            throw new BusinessException("参数传递错误或者申请单不存在");
 
        if (accessAssessApply.getAppealstatus() == AssessAppealStatus.UNPASSED)
            throw new BusinessException("申请单已被拒绝,不能再次审批");
 
        if (accessAssessApply.getAppealstatus() == AssessAppealStatus.PASSED)
            throw new BusinessException("申诉已通过,请勿再次审批");
 
        //通过
        accessAssessApply.setAppealstatus(AssessAppealStatus.PASSED);
        accessAssessApply.setAppealapprovetime(new Date());
        accessAssessApply.setAppealapprover(user.getUsername());
        this.updateById(accessAssessApply);
 
    }
 
    @Override
    public void appealAccessReject(JSONObject entity, UserInfo user) {
        Long id = entity.getLong("id");
        if (id == null)
            throw new BusinessException("参数传递错误,请联系管理员");
 
        AccessAssessApply accessAssessApply = this.getById(id);
        if (accessAssessApply == null)
            throw new BusinessException("参数传递错误或者申请单不存在");
 
        AssessAppealStatus appealstatus = accessAssessApply.getAppealstatus();
        if (appealstatus != AssessAppealStatus.APPEALING)
            throw new BusinessException("当前申请单状态为"+appealstatus.getMsg()+",不可以拒绝");
 
        String appealrejectreason = entity.getString("appealrejectreason");
        accessAssessApply.setAppealstatus(AssessAppealStatus.UNPASSED);
        accessAssessApply.setAppealrejectreason(StringUtils.isBlank(appealrejectreason) ? null : appealrejectreason);
        this.updateById(accessAssessApply);
 
    }
 
    /**
     * @Description: 获取所有超过14日公示日的未申诉的准入评定信息
     * @date 2021/7/12 13:56
     */
    @Override
    public List<AccessAssessApply> selectAllOverTimeAccessAssessApply() {
        //条件一:type准入
        //条件二:不是申诉通过的
        //条件三:未惩罚的
        return accessAssessApplyMapper.selectAllOverTimeAccessAssessApply(AssessType.ACCESS,AssessAppealStatus.PASSED,PunishStatus.UNPUNISH);
    }
 
    @Override
    public List<AccessAssessApply> selectAllPunishingAccessAssessApply() {
        //条件一:type准入
        //条件二:惩罚中的
        return accessAssessApplyMapper.selectAllPunishingAccessAssessApply(AssessType.ACCESS,PunishStatus.PUNISHING);
    }
 
 
    @Override
    public IPage selectAccessAppealPages(Page<AssessApplyAppealVo> page, Map filter, UserInfo user) {
        UserInfo userInfo = userService.getById(user.getId());
 
        Map<String, Object> params = new HashMap<>();
        //判断参数  参数-未申诉
        params.put("unappealed", AssessAppealStatus.UNAPPEALED);
        params.put("passed", AssessAppealStatus.PASSED);
        params.put("unpunish", PunishStatus.UNPUNISH);
        //固定页面变量
        params.put("type", AssessType.ACCESS);
        params.put("status", AssessApplyStatus.APPROVED);
 
        //页面过滤条件
        params.put("code", filter.get("code"));
        params.put("enterprisename", filter.get("enterprisename"));
        params.put("appealstatus", filter.get("appealstatus"));
 
        //只看到自己的
        if (user.getType() != 1 && user.getType()!= 2) {
            params.put("enterprisenumber", userInfo.getCompanynumber());
        }
 
        List<AssessApplyAppealVo> data  = accessAssessApplyMapper.selectAppealPages(params,page);
        return page.setRecords(data);
    }
 
}