package org.springblade.modules.exam.service.impl; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 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.vo.ScoreAuditRecordsVO; 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.service.MyAsyncService; 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.util.*; /** * 考试成绩修改申请记录服务实现类 * @author zhongrj */ @Service public class ScoreAuditRecordsServiceImpl extends ServiceImpl implements ScoreAuditRecordsService { @Autowired private ExamScoreService examScoreService; @Autowired private IUserService userService; @Autowired private TrainingRegistrationService trainingRegistrationService; @Autowired private SecurityPaperService securityPaperService; @Autowired private MyAsyncService myAsyncService; /** * 自定义分页 * @param page * @param scoreAuditRecords * @return */ @Override public IPage selectScoreAuditRecordsPage(IPage page, ScoreAuditRecordsVO scoreAuditRecords) { List 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()); //考试状态修改 if(trainingRegistration.getIsExam()==4) { //考试状态修改为纸质考试 trainingRegistration.setIsExam(5); trainingRegistration.setCancel(1); }else { //考试结束 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() + "'" + ",cancel = " + "'" + trainingRegistration.getCancel() + "'" + " " + "where id = " + "'" + trainingRegistration.getId() + "';"+ "update blade_user set is_train = " + "'" + user.getIsTrain() + "'" + " " + "where id = " + "'" + user.getId() + "'"; //FtpUtil.sqlFileUpload(s1); myAsyncService.FTP(s1); } else { //实操成绩不为空 if (examScore.getTheoryGrade() >= 60 && examScore.getLearnGrade() >= 60) { //合格 examScore.setQualified(0); //设置为未制证的状态 user.setUserType(7); //如果已有保安证编号,不更保安证编号信息 if (null == user.getSecuritynumber() || user.getSecuritynumber().equals("")) { //去内网生成保安证编号,由内网生成,无需返回 //数据推送 Map map = new HashMap<>(1); map.put("key",examScore); myAsyncService.FTPSecurityNumberBit(map); } } 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() + "'" + ",cancel = " + "'" + trainingRegistration.getCancel() + "'" + " " + "where id = " + "'" + trainingRegistration.getId() + "'"; myAsyncService.FTP(s1); } } //审核时间 scoreAuditRecords.setAuditTime(new Date()); //修改申请记录信息 baseMapper.updateById(scoreAuditRecords); //返回 return true; } /** * 批量申请审核 * @param scoreAuditRecords 考试成绩修改申请记录审核 */ @Override public boolean batchAudit(ScoreAuditRecordsVO scoreAuditRecords) { List 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); myAsyncService.FTP(s1); } else { //实操成绩不为空 if (examScore.getTheoryGrade() >= 60 && examScore.getLearnGrade() >= 60) { //合格 examScore.setQualified(0); //设置为未制证的状态 user.setUserType(7); //如果已有保安证编号,不更保安证编号信息 // if (null == user.getSecuritynumber() || user.getSecuritynumber().equals("")) { //去内网生成保安证编号,由内网生成,无需返回 //数据推送 Map map = new HashMap<>(1); map.put("key",examScore); myAsyncService.FTPSecurityNumberBit(map); // } } 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 = " + "'" + 2 + "'" + // ",securitynumber = " + "'" + "" + "'" + // ",user_type = " + "'" + user.getUserType() + "'" + // ",is_train = " + "'" + user.getIsTrain() + "'" + // " " + "where id = " + "'" + user.getId() + "'"; myAsyncService.FTP(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; } }