智慧保安后台管理-外网项目备份
Administrator
2021-12-25 1199c43057ef8f35133249c015a97882055e2914
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
 
package org.springblade.modules.exam.service.impl;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springblade.common.utils.QRCodeUtil;
import org.springblade.modules.FTP.FtpUtil;
import org.springblade.modules.accreditation.excel.ExportSecurityPaperExcel;
import org.springblade.modules.exam.entity.ExamScore;
import org.springblade.modules.exam.entity.ScoreAuditRecords;
import org.springblade.modules.exam.mapper.ScoreAuditRecordsMapper;
import org.springblade.modules.exam.service.ExamScoreService;
import org.springblade.modules.exam.service.ScoreAuditRecordsService;
import org.springblade.modules.exam.util.SecurityPaperUtil;
import org.springblade.modules.exam.vo.ScoreAuditRecordsVO;
import org.springblade.modules.securitypaper.entity.SecurityPaper;
import org.springblade.modules.securitypaper.service.SecurityPaperService;
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.service.IUserService;
import org.springblade.modules.system.vo.UserVO;
import org.springblade.modules.training.entity.TrainingRegistration;
import org.springblade.modules.training.service.TrainingRegistrationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
 
/**
 * 考试成绩修改申请记录服务实现类
 * @author zhongrj
 */
@Service
public class ScoreAuditRecordsServiceImpl extends ServiceImpl<ScoreAuditRecordsMapper, ScoreAuditRecords> implements ScoreAuditRecordsService {
 
    @Autowired
    private ExamScoreService examScoreService;
 
    @Autowired
    private IUserService userService;
 
    @Autowired
    private TrainingRegistrationService trainingRegistrationService;
 
    @Autowired
    private SecurityPaperService securityPaperService;
 
    /**
     * 自定义分页
     * @param page
     * @param scoreAuditRecords
     * @return
     */
    @Override
    public IPage<ScoreAuditRecordsVO> selectScoreAuditRecordsPage(IPage<ScoreAuditRecordsVO> page, ScoreAuditRecordsVO scoreAuditRecords) {
        List<ScoreAuditRecordsVO> scoreAuditRecordsVOs = baseMapper.selectScoreAuditRecordsPage(page, scoreAuditRecords);
        return page.setRecords(scoreAuditRecordsVOs);
    }
 
    /**
     * 自定义详情信息
     * @param scoreAuditRecords
     * @return
     */
    @Override
    public ScoreAuditRecordsVO getScoreAuditRecordsDetails(ScoreAuditRecords scoreAuditRecords) {
        return baseMapper.getScoreAuditRecordsDetails(scoreAuditRecords);
    }
 
    /**
     * 申请审核
     * @param scoreAuditRecords
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean applyAudit(ScoreAuditRecords scoreAuditRecords) {
        //审核
        //如果是审核通过,则修改考试成绩,并改变培训考试状态,用户培训状态
        if (scoreAuditRecords.getStatus()==2) {
            ScoreAuditRecords auditRecords = this.getById(scoreAuditRecords.getId());
            //查询考试成绩
            ExamScore examScore = examScoreService.getById(auditRecords.getExamScoreId());
            //1.修改培训报名考试状态
            TrainingRegistration trainingRegistration = trainingRegistrationService.getById(examScore.getApplyId());
            //已考试
            trainingRegistration.setIsExam(2);
            //修改
            trainingRegistrationService.updateById(trainingRegistration);
 
            //2.修改用户培训考试状态
            User user = userService.getById(examScore.getUserId());
            //修改为考试结束状态
            user.setIsTrain(3);
 
            //3.修改考试理论成绩
            examScore.setTheoryGrade(auditRecords.getNewScore());
            //查询用户年龄
            UserVO userVO = userService.getUserAgeById(Long.parseLong(examScore.getUserId()));
            //判断实操成绩是否为空
            if (null == examScore.getLearnGrade()) {
                //如果为空,之间修改理论成绩和总成绩
                //总成绩
                if (userVO.getAge() <= 50) {
                    examScore.setAllGrade(Math.round(examScore.getTheoryGrade()/2));
                }
                if (userVO.getAge() > 50) {
                    examScore.setAllGrade(Math.round(examScore.getTheoryGrade()/2));
                }
                if (examScore.getTheoryGrade() >= 60) {
                    //实操成绩暂未录入
                    examScore.setQualified(2);
                }else {
                    //不合格
                    examScore.setQualified(1);
                }
                //更新保安数据
                userService.updateById(user);
                //更新成绩数据
                examScoreService.updateById(examScore);
 
                //内网培训报名,人员,成绩数据同步
                String s1 =
                    "update exam_score set theory_grade = " + "'" + examScore.getTheoryGrade() + "'" +
                        ",all_grade = " + "'" + examScore.getAllGrade() + "'" +
                        ",qualified = " + "'" + examScore.getQualified() + "'" +
                        " " + "where id = " + "'" + examScore.getId() + "';"+
                    "update sys_training_registration set is_exam = " + "'" + trainingRegistration.getIsExam() + "'" +
                        " " + "where id = " + "'" + trainingRegistration.getId() + "';"+
                    "update blade_user set is_train = " + "'" +  user.getIsTrain() + "'" +
                        " " + "where id = " + "'" + user.getId() + "'";
                FtpUtil.sqlFileUpload(s1);
            } else {
                //实操成绩不为空
                if (examScore.getTheoryGrade() >= 60 && examScore.getLearnGrade() >= 60) {
                    //合格
                    examScore.setQualified(0);
                    //设置为未制证的状态
                    user.setUserType(7);
                    //如果已有保安证编号,不更保安证编号信息
                    if (null == user.getSecuritynumber() || user.getSecuritynumber().equals("")) {
                        //去生成保安证编号
                        String pre = SecurityPaperUtil.getSecurityPaper();
                        //查询当前年份已有的保安证编号
                        int count = userService.getSecurityPaperCount(pre);
                        String result = null;
                        if (count == 0) {
                            result = pre + "00001";
                        } else {
                            //格式化
                            DecimalFormat decimalFormat = new DecimalFormat("00000");
                            count++;
                            result = pre + (decimalFormat.format(count));
                        }
                        user.setSecuritynumber(result);
                        //修改为持证保安
                        user.setHold("1");
                        //更新保安数据
                        userService.updateById(user);
 
                        //生成保安证的同时向保安证管理表中插入一条数据
                        SecurityPaper securityPaper = new SecurityPaper();
                        securityPaper.setUserId(user.getId());
                        securityPaper.setNumber(result);
                        securityPaper.setCreateTime(new Date());
                        securityPaper.setIdCardNo(user.getCardid());
                        securityPaper.setPeopleName(user.getRealName());
                        securityPaper.setExamId(Long.parseLong(examScore.getExamId()));
                        securityPaper.setApplyId(examScore.getApplyId());
                        //新增保安员证信息
                        securityPaperService.save(securityPaper);
 
                        //数据同步
                        String s1 =
                            "insert into sys_security_paper(id,number,create_time,people_name,id_card_no,user_id,apply_id,exam_id) " +
                                "values(" + "'" + securityPaper.getId() + "'"
                                + "," + "'" + securityPaper.getNumber() +"'"
                                + "," + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(securityPaper.getCreateTime()) +"'"
                                + "," + "'" + securityPaper.getPeopleName() + "'"
                                + "," + "'" + securityPaper.getIdCardNo() + "'"
                                + "," + "'" + securityPaper.getUserId() + "'"
                                + "," + "'" + securityPaper.getApplyId() + "'"
                                + "," +"'" + securityPaper.getExamId() + "'" + ")";
                        FtpUtil.sqlFileUpload(s1);
                    }
                } else {
                    //不合格
                    examScore.setQualified(1);
                }
                //总成绩
                if (userVO.getAge() <= 50) {
                    if (null != examScore.getTheoryGrade()) {
                        examScore.setAllGrade(Math.round((examScore.getTheoryGrade() + examScore.getLearnGrade()) / 2));
                    } else {
                        examScore.setAllGrade(Math.round(examScore.getLearnGrade() / 2));
                    }
                }
                if (userVO.getAge() > 50) {
                    if (null != examScore.getTheoryGrade()) {
                        examScore.setAllGrade(Integer.parseInt(String.valueOf(Math.round(examScore.getTheoryGrade() * 0.5)))
                            + Integer.parseInt(String.valueOf(Math.round(examScore.getLearnGrade() * 0.5))));
                    } else {
                        examScore.setAllGrade(Math.round(examScore.getLearnGrade() / 2));
                    }
                }
 
                //更新成绩数据
                examScoreService.updateById(examScore);
 
                //内网培训报名,人员,成绩数据同步
                String s1 =
                    "update exam_score set theory_grade = " + "'" + examScore.getTheoryGrade() + "'" +
                        ",all_grade = " + "'" + examScore.getAllGrade() + "'" +
                        ",qualified = " + "'" + examScore.getQualified() + "'" +
                        " " + "where id = " + "'" + examScore.getId() + "';"+
                    "update sys_training_registration set is_exam = " + "'" + trainingRegistration.getIsExam() + "'" +
                        " " + "where id = " + "'" + trainingRegistration.getId() + "';"+
                    "update blade_user set hold = " + "'" + user.getHold() + "'" +
                        ",securitynumber = " + "'" + user.getSecuritynumber() + "'" +
                        ",user_type = " + "'" + user.getUserType() + "'" +
                        ",is_train = " + "'" + user.getIsTrain() + "'" +
                        " " + "where id = " + "'" + user.getId() + "'";
                FtpUtil.sqlFileUpload(s1);
            }
        }
        //审核时间
        scoreAuditRecords.setAuditTime(new Date());
        //修改申请记录信息
        baseMapper.updateById(scoreAuditRecords);
        //返回
        return true;
    }
 
 
    /**
     * 批量申请审核
     * @param scoreAuditRecords 考试成绩修改申请记录审核
     */
    @Override
    public boolean batchAudit(ScoreAuditRecordsVO scoreAuditRecords) {
        List<String> list = Arrays.asList(scoreAuditRecords.getIds().split(","));
        for (String id : list) {
            //审核
            ScoreAuditRecords records = this.getById(id);
            //如果是审核通过,则修改考试成绩,并改变培训考试状态,用户培训状态
            if (scoreAuditRecords.getStatus()==2) {
                //查询考试成绩
                ExamScore examScore = examScoreService.getById(records.getExamScoreId());
                //1.修改培训报名考试状态
                TrainingRegistration trainingRegistration = trainingRegistrationService.getById(examScore.getApplyId());
                //已考试
                trainingRegistration.setIsExam(2);
                //修改
                trainingRegistrationService.updateById(trainingRegistration);
 
                //2.修改用户培训考试状态
                User user = userService.getById(examScore.getUserId());
                //修改为考试结束状态
                user.setIsTrain(3);
 
                //3.修改考试理论成绩
                examScore.setTheoryGrade(records.getNewScore());
                //查询用户年龄
                UserVO userVO = userService.getUserAgeById(Long.parseLong(examScore.getUserId()));
                //判断实操成绩是否为空
                if (null == examScore.getLearnGrade()) {
                    //如果为空,之间修改理论成绩和总成绩
                    //总成绩
                    if (userVO.getAge() <= 50) {
                        examScore.setAllGrade(Math.round(examScore.getTheoryGrade()/2));
                    }
                    if (userVO.getAge() > 50) {
                        examScore.setAllGrade(Math.round(examScore.getTheoryGrade()/2));
                    }
                    if (examScore.getTheoryGrade() >= 60) {
                        //实操成绩暂未录入
                        examScore.setQualified(2);
                    }else {
                        //不合格
                        examScore.setQualified(1);
                    }
                    //更新保安数据
                    userService.updateById(user);
                    //更新成绩数据
                    examScoreService.updateById(examScore);
 
                    //内网培训报名,人员,成绩数据同步
                    String s1 =
                        "update exam_score set theory_grade = " + "'" + examScore.getTheoryGrade() + "'" +
                            ",all_grade = " + "'" + examScore.getAllGrade() + "'" +
                            ",qualified = " + "'" + examScore.getQualified() + "'" +
                            " " + "where id = " + "'" + examScore.getId() + "';"+
                        "update sys_training_registration set is_exam = " + "'" + trainingRegistration.getIsExam() + "'" +
                            " " + "where id = " + "'" + trainingRegistration.getId() + "';"+
                        "update blade_user set is_train = " + "'" +  user.getIsTrain() + "'" +
                            " " + "where id = " + "'" + user.getId() + "'";
                    FtpUtil.sqlFileUpload(s1);
                } else {
                    //实操成绩不为空
                    if (examScore.getTheoryGrade() >= 60 && examScore.getLearnGrade() >= 60) {
                        //合格
                        examScore.setQualified(0);
                        //设置为未制证的状态
                        user.setUserType(7);
                        //如果已有保安证编号,不更保安证编号信息
                        if (null == user.getSecuritynumber() || user.getSecuritynumber().equals("")) {
                            //去生成保安证编号
                            String pre = SecurityPaperUtil.getSecurityPaper();
                            //查询当前年份已有的保安证编号
                            int count = userService.getSecurityPaperCount(pre);
                            String result = null;
                            if (count == 0) {
                                result = pre + "00001";
                            } else {
                                //格式化
                                DecimalFormat decimalFormat = new DecimalFormat("00000");
                                count++;
                                result = pre + (decimalFormat.format(count));
                            }
                            user.setSecuritynumber(result);
                            //发证日期
//                    user.setPaperTime(new Date());
                            //修改为持证保安
                            user.setHold("1");
                            //更新保安数据
                            userService.updateById(user);
 
//                        String s1 =
//                            "update blade_user set hold = " + "'" + user.getHold() + "'" +
//                                ",securitynumber = " + "'" + user.getSecuritynumber() + "'" +
//                                ",is_train = " + "'" + user.getIsTrain() + "'" +
//                                " " + "where id = " + "'" + user.getId() + "'";
//                        FtpUtil.sqlFileUpload(s1);
                        }
                    } else {
                        //不合格
                        examScore.setQualified(1);
                    }
                    //总成绩
                    if (userVO.getAge() <= 50) {
                        if (null != examScore.getTheoryGrade()) {
                            examScore.setAllGrade(Math.round((examScore.getTheoryGrade() + examScore.getLearnGrade()) / 2));
                        } else {
                            examScore.setAllGrade(Math.round(examScore.getLearnGrade() / 2));
                        }
                    }
                    if (userVO.getAge() > 50) {
                        if (null != examScore.getTheoryGrade()) {
                            examScore.setAllGrade(Integer.parseInt(String.valueOf(Math.round(examScore.getTheoryGrade() * 0.5)))
                                + Integer.parseInt(String.valueOf(Math.round(examScore.getLearnGrade() * 0.5))));
                        } else {
                            examScore.setAllGrade(Math.round(examScore.getLearnGrade() / 2));
                        }
                    }
 
                    //更新成绩数据
                    examScoreService.updateById(examScore);
 
                    //内网培训报名,人员,成绩数据同步
                    String s1 =
                        "update exam_score set theory_grade = " + "'" + examScore.getTheoryGrade() + "'" +
                            ",all_grade = " + "'" + examScore.getAllGrade() + "'" +
                            ",qualified = " + "'" + examScore.getQualified() + "'" +
                            " " + "where id = " + "'" + examScore.getId() + "';"+
                        "update sys_training_registration set is_exam = " + "'" + trainingRegistration.getIsExam() + "'" +
                            " " + "where id = " + "'" + trainingRegistration.getId() + "';"+
                        "update blade_user set hold = " + "'" + user.getHold() + "'" +
                            ",securitynumber = " + "'" + user.getSecuritynumber() + "'" +
                            ",user_type = " + "'" + user.getUserType() + "'" +
                            ",is_train = " + "'" + user.getIsTrain() + "'" +
                            " " + "where id = " + "'" + user.getId() + "'";
                    FtpUtil.sqlFileUpload(s1);
                }
            }
            //审核时间
            records.setAuditTime(new Date());
            if (null!=scoreAuditRecords.getAuditDetail() && !scoreAuditRecords.getAuditDetail().equals("")){
                records.setAuditDetail(scoreAuditRecords.getAuditDetail());
            }
            records.setAuditUser(scoreAuditRecords.getAuditUser());
            records.setStatus(scoreAuditRecords.getStatus());
            //修改申请记录信息
            baseMapper.updateById(records);
        }
        //返回
        return true;
    }
}