智慧保安后台管理-外网项目备份
Administrator
2022-01-04 2649be9534e68592660ecd4d03f14edcdc9b5c45
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;
   /**
    * 自定义分页数据
@@ -166,7 +173,6 @@
            apply1.setIsExam(2);
            applyService.updateById(apply1);
            //数据同步
            String s =
               "update sys_apply set is_exam = " + apply1.getIsExam() + " " +"where id = " + "'" + apply1.getId() + "';" +
@@ -193,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);
         }
@@ -250,99 +256,135 @@
         examScoreExcelList.forEach(examScoreExcel -> {
            if (null!=examScoreExcel.getLearnGrade() && null!=examScoreExcel.getIdCardNo() && examScoreExcel.getIdCardNo()!=""){
               //使用考试名称匹配考试信息
//               ExamPaper examPaper = examPaperService.getExamInfoByExamName(examScoreExcel.getExamName());
               List<ExamPaper> examPaperList = examPaperService.getExamInfoByExamName(examScoreExcel.getExamName());
               ExamPaper examPaper = examPaperList.get(0);
               //查询出成绩数据
//               ExamScore examScore = baseMapper.getExamScoreInfoByIdCardNo(examScoreExcel.getIdCardNo(),examPaper.getId());
               //根据身份证号查询用户
               User user0 = userService.getUserInfoByIdCardNo(examScoreExcel.getIdCardNo());
               if (null==user0){
                  throw new ServiceException("用户:["+examScoreExcel.getIdCardNo()+"]不存在");
               }
               ExamScore examScore1 = new ExamScore();
               examScore1.setCandidateNo(examScoreExcel.getCandidateNo());
               examScore1.setUserId(user0.getId().toString());
               //根据准考证号和用户id查询考试成绩
               ExamScore examScore = this.getOne(Condition.getQueryWrapper(examScore1));
               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";
               if (examPaperList.size()>0){
                  //取第一个
                  List<ExamScore> examScoreList = baseMapper.getExamScoreInfoByIdCardNo(examScoreExcel.getIdCardNo(),new SimpleDateFormat("yyyy-MM-dd").format(examPaper.getStartTime()));
                  if (examScoreList.size()==0){
                     //根据身份证号查询用户
                     User user0 = userService.getUserInfoByIdCardNo(examScoreExcel.getIdCardNo());
                     if (null==user0){
                        throw new ServiceException("没有找到用户:["+examScoreExcel.getIdCardNo()+"]相关考试成绩信息,请检查身份证是否有误!");
//                        throw new ServiceException("用户:["+examScoreExcel.getIdCardNo()+"]不存在");
                     }
                  }
                  //遍历集合
                  examScoreList.forEach(examScore -> {
//                     ExamScore examScore1 = new ExamScore();
//                     examScore1.setCandidateNo(examScoreExcel.getCandidateNo());
//                     examScore1.setUserId(user0.getId().toString());
//                     //根据准考证号和用户id查询考试成绩
//                     ExamScore examScore = this.getOne(Condition.getQueryWrapper(examScore1));
                     if (null!=examScore) {
                        //查询当前保安信息
                        UserVO user = userService.getUserAgeById(Long.parseLong(examScore.getUserId()));
                        //设置实操成绩
                        examScore.setLearnGrade(examScoreExcel.getLearnGrade());
                        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);
                                 //生成保安证的同时向保安证管理表中插入一条数据
                                 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 {
                           //格式化
                           DecimalFormat decimalFormat = new DecimalFormat("00000");
                           count++;
                           result = pre + (decimalFormat.format(count));
                           //不合格
                           examScore.setQualified(1);
                        }
                        user.setSecuritynumber(result);
                        //发证日期
//                        user.setPaperTime(new Date());
                        //修改为持证保安
                        user.setHold("1");
                        //更新保安数据
                        userService.updateById(user);
                        //总成绩
                        if (user.getAge() <= 50) {
                           if (null!=examScore.getTheoryGrade()) {
                              examScore.setAllGrade(Math.round((examScore.getTheoryGrade() + examScoreExcel.getLearnGrade()) / 2));
                           }else {
                              examScore.setAllGrade(Math.round(examScoreExcel.getLearnGrade() / 2));
                           }
                        }
                        if (user.getAge() > 50) {
                           if (null!=examScore.getTheoryGrade()) {
                              examScore.setAllGrade(Integer.parseInt(String.valueOf(Math.round(examScore.getTheoryGrade() * 0.5)))
                                 + Integer.parseInt(String.valueOf(Math.round(examScoreExcel.getLearnGrade() * 0.5))));
                           }else {
                              examScore.setAllGrade(Math.round(examScoreExcel.getLearnGrade() / 2));
                           }
                        }
                        //内网同步
                        String s1 =
                           "update blade_user set hold = " + "'" + user.getHold() + "'" +
                              ",securitynumber = " + "'" + user.getSecuritynumber() + "'" +
                              ",user_type = " + "'" + user.getUserType() + "'" +
                              " " + "where id = " + "'" + user.getId() + "'";
                           "update exam_score set learn_grade = " + "'" + examScore.getLearnGrade() + "'" +
                              ",all_grade = " + "'" + examScore.getAllGrade() + "'" +
                              ",qualified = " + "'" + examScore.getQualified() + "'" +
                              " " + "where id = " + "'" + examScore.getId() + "'";
                        FtpUtil.sqlFileUpload(s1);
                     }
                     //分配保安角色
//                        Role role = new Role();
//                        role.setRoleAlias("保安");
//                        Role oneRole = roleService.getOne(Condition.getQueryWrapper(role));
//                        user.setRoleId(oneRole.getId().toString());
//                     }
                  } else {
                     //不合格
                     examScore.setQualified(1);
                  }
                  //总成绩
                  if (user.getAge() <= 50) {
                     if (null!=examScore.getTheoryGrade()) {
                        examScore.setAllGrade(Math.round((examScore.getTheoryGrade() + examScoreExcel.getLearnGrade()) / 2));
                        //更新成绩数据
                        baseMapper.updateById(examScore);
                     }else {
                        examScore.setAllGrade(Math.round(examScoreExcel.getLearnGrade() / 2));
                        errorList.add(examScoreExcel.getIdCardNo());
                        status.set(false);
                     }
                  }
                  if (user.getAge() > 50) {
                     if (null!=examScore.getTheoryGrade()) {
                        examScore.setAllGrade(Integer.parseInt(String.valueOf(Math.round(examScore.getTheoryGrade() * 0.5)))
                           + Integer.parseInt(String.valueOf(Math.round(examScoreExcel.getLearnGrade() * 0.5))));
                     }else {
                        examScore.setAllGrade(Math.round(examScoreExcel.getLearnGrade() / 2));
                     }
                  }
                  });
                  //内网同步
                  String s1 =
                     "update exam_score set learn_grade = " + "'" + examScore.getLearnGrade() + "'" +
                        ",all_grade = " + "'" + examScore.getAllGrade() + "'" +
                        ",qualified = " + "'" + examScore.getQualified() + "'" +
                        " " + "where id = " + "'" + examScore.getId() + "'";
                  FtpUtil.sqlFileUpload(s1);
                  //更新成绩数据
                  baseMapper.updateById(examScore);
               }else {
                  errorList.add(examScoreExcel.getIdCardNo());
                  status.set(false);
                  throw new ServiceException("导入失败!考试名称:["+examScoreExcel.getExamName()+"]不存在!请核对!");
               }
            }
         });
@@ -447,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));
   }
   /**
@@ -708,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;
   }
}