From cb04ed62736efe70cf5babe534220b4ae4c1ca67 Mon Sep 17 00:00:00 2001
From: Administrator <admin>
Date: Thu, 20 Jan 2022 21:08:42 +0800
Subject: [PATCH] 1. 定时任务调整 2. 成绩修改审核通过修改状态调整 3. 考试统计查询修改

---
 src/main/java/org/springblade/modules/exam/service/impl/ExamScoreServiceImpl.java |  253 +++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 208 insertions(+), 45 deletions(-)

diff --git a/src/main/java/org/springblade/modules/exam/service/impl/ExamScoreServiceImpl.java b/src/main/java/org/springblade/modules/exam/service/impl/ExamScoreServiceImpl.java
index c918736..8a3a54f 100644
--- a/src/main/java/org/springblade/modules/exam/service/impl/ExamScoreServiceImpl.java
+++ b/src/main/java/org/springblade/modules/exam/service/impl/ExamScoreServiceImpl.java
@@ -18,9 +18,12 @@
 import org.springblade.modules.exam.service.ExamScoreService;
 import org.springblade.modules.exam.service.ExamSubjectChoicesService;
 import org.springblade.modules.exam.util.SecurityPaperUtil;
-import org.springblade.modules.exam.vo.ExamResultVO;
-import org.springblade.modules.exam.vo.ExamScoreVO;
-import org.springblade.modules.exam.vo.UpdateParamVo;
+import org.springblade.modules.exam.vo.*;
+import org.springblade.modules.information.entity.Information;
+import org.springblade.modules.information.service.IInformationService;
+import org.springblade.modules.information.vo.InformationVO;
+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.IRoleService;
 import org.springblade.modules.system.service.IUserService;
@@ -61,11 +64,15 @@
 	private TrainingRegistrationService trainingRegistrationService;
 
 	@Autowired
-	private IRoleService roleService;
-
+	private SecurityPaperService securityPaperService;
 
 	@Autowired
 	private ExamAnswerRecordService examAnswerRecordService;
+
+	@Autowired
+	private IInformationService informationService;
+
+
 
 	/**
 	 * 自定义分页数据
@@ -192,7 +199,7 @@
 				//数据同步
 				String s =
 					"update sys_training_registration set is_exam = " + trainingRegistration1.getIsExam() + " " +"where id = " + "'" + trainingRegistration1.getId() + "';" +
-						"update blade_user set is_apply = " + user.getIsApply() + " " +"where id = " + "'" + user.getId() + "'";
+						"update blade_user set is_train = " + user.getIsTrain() + " " +"where id = " + "'" + user.getId() + "'";
 				FtpUtil.sqlFileUpload(s);
 			}
 
@@ -273,45 +280,72 @@
 							if (null!=examScore) {
 								//查询当前保安信息
 								UserVO user = userService.getUserAgeById(Long.parseLong(examScore.getUserId()));
+								//设置实操成绩
 								examScore.setLearnGrade(examScoreExcel.getLearnGrade());
-								if (examScore.getTheoryGrade() >= 60 && examScore.getLearnGrade() >= 60) {
-									//合格
-									examScore.setQualified(0);
-									//修改制证状态为未制证
-									user.setUserType(7);
-									//正式考试通过生成保安证编号
-//							if (examPaper.getExamType()==1) {
-									//如果已有保安证编号,不更新用户信息
-									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");
-										user.setUpdateTime(new Date());
-										//更新保安数据
-										userService.updateById(user);
+								if (null!=examScore.getTheoryGrade()){
+									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");
+											user.setUpdateTime(new Date());
+											//更新保安数据
+											userService.updateById(user);
 
-										String s1 =
-											"update blade_user set hold = " + "'" + user.getHold() + "'" +
-												",securitynumber = " + "'" + user.getSecuritynumber() + "'" +
-												",update_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getUpdateTime()) + "'" +
-												",user_type = " + "'" + user.getUserType() + "'" +
-												" " + "where id = " + "'" + user.getId() + "'";
-										FtpUtil.sqlFileUpload(s1);
+											//生成保安证的同时向保安证管理表中插入一条数据
+											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 =
+												"update blade_user set hold = " + "'" + user.getHold() + "'" +
+													",securitynumber = " + "'" + user.getSecuritynumber() + "'" +
+													",update_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getUpdateTime()) + "'" +
+													",user_type = " + "'" + user.getUserType() + "'" +
+													" " + "where id = " + "'" + user.getId() + "'";
+
+//											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() + "'" + ");" +
+//												"update blade_user set hold = " + "'" + user.getHold() + "'" +
+//													",securitynumber = " + "'" + user.getSecuritynumber() + "'" +
+//													",update_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getUpdateTime()) + "'" +
+//													",user_type = " + "'" + user.getUserType() + "'" +
+//													" " + "where id = " + "'" + user.getId() + "'";
+											FtpUtil.sqlFileUpload(s1);
+										}
 									}
 								} else {
 									//不合格
@@ -455,8 +489,8 @@
 	}
 
 	@Override
-	public IPage<ExamScoreVO> scorePage(IPage page, String deptid, String jurisdiction) {
-		return page.setRecords(baseMapper.scorePage(page,deptid,jurisdiction));
+	public IPage<ExamScoreVO> scorePage(IPage page, ExamScoreVO examScore) {
+		return page.setRecords(baseMapper.scorePage(page,examScore));
 	}
 
 	/**
@@ -716,4 +750,133 @@
 		});
 		return false;
 	}
+
+	/**
+	 * 点击了开始考试后超过60分钟后再考试的,计算之前的考试成绩
+	 * @param examScore
+	 * @return
+	 */
+	@Override
+	public boolean getExamScore(ExamScoreVO examScore) {
+		//查询考试成绩
+		ExamScore score = this.getById(examScore.getId());
+		//查询考试记录
+		ExamAnswerRecord examAnswerRecord = new ExamAnswerRecord();
+		examAnswerRecord.setScoreId(examScore.getId());
+		List<ExamAnswerRecord> list = examAnswerRecordService.list(Condition.getQueryWrapper(examAnswerRecord));
+		//设置默认理论成绩为0
+		int count = 0;
+		//计算成绩
+		if (list.size()>0){
+			//成绩相加
+			count = list.stream().mapToInt(ExamAnswerRecord::getAnswerScore).sum();
+
+		}else {
+			//没有考试记录,本次考试理论成绩为 0
+			count = 0;
+		}
+		int age = 0;
+		UserVO user = new UserVO();
+		//查询培训报名数据
+		TrainingRegistration trainingRegistration = new TrainingRegistration();
+		trainingRegistration.setCandidateNo(score.getCandidateNo());
+		trainingRegistration.setCancel(1);
+		TrainingRegistration trainingRegistration1 = trainingRegistrationService.getOne(Condition.getQueryWrapper(trainingRegistration));
+		//查询用户年龄,根据年龄计算总分
+		user = userService.getUserAgeById(Long.parseLong(trainingRegistration1.getUserId()));
+		//修改用户的培训状态,理论考试结束
+		user.setIsTrain(3);
+		age = user.getAge();
+		userService.updateById(user);
+		//修改为已考试
+		trainingRegistration1.setIsExam(2);
+		trainingRegistrationService.updateById(trainingRegistration1);
+
+		//数据同步
+		String s =
+			"update sys_training_registration set is_exam = " + trainingRegistration1.getIsExam() + " " +"where id = " + "'" + trainingRegistration1.getId() + "';" +
+				"update blade_user set is_train = " + user.getIsTrain() + " " +"where id = " + "'" + user.getId() + "'";
+		FtpUtil.sqlFileUpload(s);
+
+		//设置理论得分
+		score.setTheoryGrade(count);
+		//计算总成绩,此时没有实操成绩,总成绩为实操成绩和理论成绩和的一半
+		if (age<=50) {
+			score.setAllGrade(Math.round(count / 2));
+		}
+		if (age>50) {
+			score.setAllGrade(Integer.parseInt(String.valueOf(Math.round(count*0.5))));
+		}
+		//设置状态
+		if (count>=60){
+			score.setQualified(2);
+		}else {
+			score.setQualified(1);
+		}
+		//修改成绩数据
+		int i = baseMapper.updateById(score);
+
+		String s1 =
+			"update exam_score set exam_id = " + score.getExamId() +
+				",theory_grade = " + "'" + score.getTheoryGrade() + "'" +
+				",all_grade = " + "'" + score.getAllGrade() + "'" +
+				",exam_end_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:dd").format(new Date()) + "'" +
+				",qualified = " + "'" + score.getQualified() + "'" +
+				" " +"where id = " + "'" + score.getId() + "'";
+		FtpUtil.sqlFileUpload(s1);
+
+		if (i>0){
+			//返回结果
+			return true;
+		}
+		return false;
+	}
+
+	/**
+	 * 考试情况统计,按月统计各个培训学校考试合格人数和不合格人数
+	 * @param
+	 */
+	@Override
+	public Object getExamStatisInfo(InformationVO information) {
+		//获取培训学校信息
+		Information information2 = new Information();
+		information2.setStats("1");
+		List<Information> informationList = informationService.list(Condition.getQueryWrapper(information2));
+		//创建 objectList 集合
+		List<Object> objectList = new ArrayList<>();
+		for (Information information1 : informationList) {
+			//查询各个培训学校本年每月考试情况统计,不是测试学校
+			if(!information1.getId().equals(469)) {
+				//合格和不合格
+				ExamSocreStatisVo statisVo = new ExamSocreStatisVo();
+				ExamSocreStatisVo statisVo1 = new ExamSocreStatisVo();
+
+				information.setDepartmentid(information1.getDepartmentid());
+				//统计数据查询
+				List<ExamSocreStatis> examStatisInfo = baseMapper.getExamStatisInfo(information);
+				//数据转换
+				List<Integer> list = new ArrayList<>();
+				List<Integer> list1 = new ArrayList<>();
+				for (ExamSocreStatis examSocreStatis : examStatisInfo) {
+					//合格人数集合
+					list.add(examSocreStatis.getHgnum());
+					//不合格人数集合
+					list1.add(examSocreStatis.getBhgnum());
+				}
+				//合格
+				statisVo.setName(information1.getEnterprisename());
+				statisVo.setType(1);
+				statisVo.setExamSocreStatis(list);
+				//不合格
+				statisVo1.setName(information1.getEnterprisename());
+				statisVo1.setType(2);
+				statisVo1.setExamSocreStatis(list1);
+				//数据封装
+				objectList.add(statisVo);
+				objectList.add(statisVo1);
+			}
+		}
+		//返回数据
+		return objectList;
+	}
 }

--
Gitblit v1.9.3