src/main/java/org/springblade/modules/FTP/FtpUtil.java
@@ -419,4 +419,22 @@ FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/", "u"+response1+".json", in1); MysqlCenlint.deletess("u"+response1+".json"); } /** * 考试实操成绩推送内网导入 * @param map */ public static void objectFileUploadExamScore(Map<String, Object> map) { String json1 = JSON.toJSONString(map); String response1 = String.valueOf((new Date()).getTime()); OutJson.createJsonFile(json1, localPath, "e"+response1); FileInputStream in1 = null; try { in1 = new FileInputStream(new File(localPath + "e"+response1+".json")); } catch (FileNotFoundException e) { e.printStackTrace(); } FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/", "e"+response1+".json", in1); MysqlCenlint.deletess("e"+response1+".json"); } } src/main/java/org/springblade/modules/exam/controller/ExamScoreController.java
@@ -422,16 +422,16 @@ ExamScoreExcel examScoreExcel = new ExamScoreExcel(); examScoreExcel.setExamName("2021年10月**日保安员证培训考试"); examScoreExcel.setName("张三"); examScoreExcel.setIdCardNo("360XXX19XXXXXX****"); // examScoreExcel.setCandidateNo("2110**m0001"); // examScoreExcel.setIdCardNo("360XXX19XXXXXX****"); examScoreExcel.setCandidateNo("2110**m0001"); examScoreExcel.setLearnGrade(80); list.add(examScoreExcel); ExamScoreExcel examScoreExcel1 = new ExamScoreExcel(); examScoreExcel1.setExamName("2021年10月**日保安员证培训考试"); examScoreExcel1.setName("李四"); examScoreExcel1.setIdCardNo("360XXX19XXXXXX****"); // examScoreExcel1.setCandidateNo("2110**m0002"); // examScoreExcel1.setIdCardNo("360XXX19XXXXXX****"); examScoreExcel1.setCandidateNo("2110**m0002"); examScoreExcel1.setLearnGrade(88); list.add(examScoreExcel1); // ExcelUtil.export(response, "实操成绩数据模板", "实操成绩数据表", list, ExamScoreExcel.class); src/main/java/org/springblade/modules/exam/excel/ExamScoreExcel.java
@@ -47,14 +47,14 @@ private String name; @ColumnWidth(25) @ExcelProperty("身份证号码*") private String idCardNo; // @ColumnWidth(25) // @ExcelProperty("身份证号码*") // private String idCardNo; // @ColumnWidth(20) // @ExcelProperty("准考证号*") // private String candidateNo; @ColumnWidth(20) @ExcelProperty("准考证号*") private String candidateNo; // @ColumnWidth(15) // @ExcelProperty("理论得分*") src/main/java/org/springblade/modules/exam/service/impl/ExamScoreServiceImpl.java
@@ -1,6 +1,7 @@ package org.springblade.modules.exam.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.commons.lang3.StringUtils; @@ -257,8 +258,43 @@ return false; } // /** // * 导入实操成绩 // * // * @param examScoreExcelList // * @param isCovered 是否覆盖 // */ // @Override // public void importExamScore(List<ExamScoreExcel> examScoreExcelList, Boolean isCovered) { // if (examScoreExcelList.size() > 0) { // //遍历 // examScoreExcelList.forEach(examScoreExcel -> { // if (null != examScoreExcel.getLearnGrade() && null != examScoreExcel.getIdCardNo() && examScoreExcel.getIdCardNo() != "") { // //使用考试名称匹配考试信息 // List<ExamPaper> examPaperList = examPaperService.getExamInfoByExamName(examScoreExcel.getExamName()); // ExamPaper examPaper = examPaperList.get(0); // //查询出成绩数据 // if (examPaperList.size() > 0) { // ExamScore score = new ExamScore(); // score.setCandidateNo(examScoreExcel.getIdCardNo()); // score.setLearnGrade(examScoreExcel.getLearnGrade()); // score.setExamTime(examPaper.getStartTime()); // //生成随机数 // String uuid = UUID.randomUUID().toString(); // //数据推送 // Map<String, Object> map = new HashMap<>(1); // map.put(uuid, score); // myAsyncService.FTPObjectExamScore(map); // } else { // throw new ServiceException("导入失败!考试名称:[" + examScoreExcel.getExamName() + "]不存在!请核对!"); // } // } // }); // } // } /** * 导入实操成绩 * 导入实操成绩(按准考证编号导入版) * * @param examScoreExcelList * @param isCovered 是否覆盖 @@ -270,30 +306,22 @@ //导入状态,默认为true ,如果有一个出现问题则为 false AtomicBoolean status = new AtomicBoolean(true); //遍历 examScoreExcelList.forEach(examScoreExcel -> { if (null != examScoreExcel.getLearnGrade() && null != examScoreExcel.getIdCardNo() && examScoreExcel.getIdCardNo() != "") { for (ExamScoreExcel examScoreExcel : examScoreExcelList) { if (null != examScoreExcel.getLearnGrade() && null != examScoreExcel.getCandidateNo() && examScoreExcel.getCandidateNo() != "") { //使用考试名称匹配考试信息 List<ExamPaper> examPaperList = examPaperService.getExamInfoByExamName(examScoreExcel.getExamName()); ExamPaper examPaper = examPaperList.get(0); //查询出成绩数据 if (examPaperList.size() > 0) { //取第一个 List<ExamScore> examScoreList = baseMapper.getExamScoreInfoByIdCardNo(examScoreExcel.getIdCardNo(), new SimpleDateFormat("yyyy-MM-dd").format(examPaper.getStartTime())); ExamScore score = new ExamScore(); score.setCandidateNo(examScoreExcel.getCandidateNo()); List<ExamScore> examScoreList = this.list(new QueryWrapper<>(score)); if (examScoreList.size() == 0) { //根据身份证号查询用户 User user0 = userService.getUserInfoByIdCardNo(examScoreExcel.getIdCardNo()); if (null == user0) { throw new ServiceException("没有找到用户:[" + examScoreExcel.getIdCardNo() + "]相关考试成绩信息,请检查身份证是否有误!"); // throw new ServiceException("用户:["+examScoreExcel.getIdCardNo()+"]不存在"); } errorList.add(examScoreExcel.getName()); status.set(false); break; } //遍历集合 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())); @@ -307,97 +335,11 @@ user.setUserType(7); //如果已有保安证编号,不更新用户信息 if (null == user.getSecuritynumber() || user.getSecuritynumber().equals("")) { //去生成保安证编号 String pre = SecurityPaperUtil.getSecurityPaper(); //查询当前年份已有的保安证编号 // int count = userService.getSecurityPaperCount(pre); //需调用内网查询 //生成随机数 String uuid = UUID.randomUUID().toString(); //去内网生成保安证编号,由内网生成,无需返回 //数据推送 Map<String, Object> map = new HashMap<>(1); map.put(uuid, pre); map.put("key",examScore); myAsyncService.FTPSecurityNumberBit(map); int count = 0; Result result0 = new Result(); //调用ftp获取返回数据 while (true) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } //调用ftp获取返回数据 result0 = Monitor.getSecurityNumberBit(uuid); //如果返回true,就退处 if (result0.getCode() == 200) { break; } else { //计数 count++; //如果超过100s 没有读取到,则退出 if (count == 100) { break; } } } int max = Integer.parseInt(result0.getMsg()); String result = null; if (max == 0) { result = pre + "00001"; } else { //格式化 DecimalFormat decimalFormat = new DecimalFormat("00000"); max++; result = pre + (decimalFormat.format(max)); } //脱敏处理 user.setSecuritynumber(DesensitizedUtil.desensitizedSecurityNumber(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()); securityPaper.setSource(1); //内网对象 SecurityPaper paper = Objects.requireNonNull(BeanUtil.copy(securityPaper, SecurityPaper.class)); //新增保安员证信息 securityPaper.setNumber(DesensitizedUtil.desensitizedSecurityNumber(result)); securityPaper.setIdCardNo(""); securityPaperService.save(securityPaper); //设置id paper.setId(securityPaper.getId()); //内网同步 String s1 = "insert into sys_security_paper(id,number,create_time,people_name,id_card_no,user_id,apply_id,exam_id,source) " + "values(" + "'" + paper.getId() + "'" + "," + "'" + paper.getNumber() + "'" + "," + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(paper.getCreateTime()) + "'" + "," + "'" + paper.getPeopleName() + "'" + "," + "'" + paper.getIdCardNo() + "'" + "," + "'" + paper.getUserId() + "'" + "," + "'" + paper.getApplyId() + "'" + "," + "'" + paper.getExamId() + "'" + "," + "'" + paper.getSource() + "'" + ");" + "update blade_user set hold = " + "'" + user.getHold() + "'" + ",securitynumber = " + "'" + result + "'" + ",update_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getUpdateTime()) + "'" + ",user_type = " + "'" + user.getUserType() + "'" + " " + "where id = " + "'" + user.getId() + "'"; myAsyncService.FTP(s1); } } } else { @@ -427,7 +369,6 @@ ",all_grade = " + "'" + examScore.getAllGrade() + "'" + ",qualified = " + "'" + examScore.getQualified() + "'" + " " + "where id = " + "'" + examScore.getId() + "'"; //FtpUtil.sqlFileUpload(s1); myAsyncService.FTP(s1); //更新成绩数据 baseMapper.updateById(examScore); @@ -436,12 +377,11 @@ status.set(false); } }); } else { throw new ServiceException("导入失败!考试名称:[" + examScoreExcel.getExamName() + "]不存在!请核对!"); } } }); } //如果所有数据导入有一个异常 if (!status.get()) { String errorAccount = StringUtils.join(errorList, "\\\n"); src/main/java/org/springblade/modules/exam/service/impl/ScoreAuditRecordsServiceImpl.java
@@ -3,22 +3,12 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.AllArgsConstructor; import org.springblade.common.utils.DesensitizedUtil; import org.springblade.common.utils.QRCodeUtil; import org.springblade.core.tool.utils.BeanUtil; import org.springblade.modules.FTP.FtpUtil; import org.springblade.modules.FTP.Monitor; import org.springblade.modules.FTP.Result; 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; @@ -29,12 +19,6 @@ 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.*; /** @@ -161,95 +145,11 @@ user.setUserType(7); //如果已有保安证编号,不更保安证编号信息 if (null == user.getSecuritynumber() || user.getSecuritynumber().equals("")) { //去生成保安证编号 String pre = SecurityPaperUtil.getSecurityPaper(); //查询当前年份已有的保安证编号 // int count = userService.getSecurityPaperCount(pre); //需调用内网查询 //生成随机数 String uuid = UUID.randomUUID().toString(); //去内网生成保安证编号,由内网生成,无需返回 //数据推送 Map<String, Object> map = new HashMap<>(1); map.put(uuid,pre); map.put("key",examScore); myAsyncService.FTPSecurityNumberBit(map); int count = 0; Result result0 = new Result(); //调用ftp获取返回数据 while (true){ try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } //调用ftp获取返回数据 result0 = Monitor.getSecurityNumberBit(uuid); //如果返回true,就退处 if (result0.getCode()==200){ break; }else{ //计数 count++; //如果超过100s 没有读取到,则退出 if (count == 100) { break; } } } int max = Integer.parseInt(result0.getMsg()); String result = null; if (max == 0) { result = pre + "00001"; } else { //格式化 DecimalFormat decimalFormat = new DecimalFormat("00000"); max++; result = pre + (decimalFormat.format(max)); } user.setSecuritynumber(result); //修改为持证保安 user.setHold("1"); //创建保安证脱敏对象 User user1 = user; //更新保安数据 user1.setSecuritynumber(DesensitizedUtil.desensitizedSecurityNumber(result)); userService.updateById(user1); //生成保安证的同时向保安证管理表中插入一条数据 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()); securityPaper.setSource(1); //创建内网对象 SecurityPaper paper = Objects.requireNonNull(BeanUtil.copy(securityPaper,SecurityPaper.class)); //脱敏 securityPaper.setNumber(DesensitizedUtil.desensitizedSecurityNumber(result)); securityPaper.setIdCardNo(""); //新增保安员证信息 securityPaperService.save(securityPaper); //设置id paper.setId(securityPaper.getId()); //数据同步 String s1 = "insert into sys_security_paper(id,number,create_time,people_name,id_card_no,user_id,apply_id,exam_id,source) " + "values(" + "'" + paper.getId() + "'" + "," + "'" + paper.getNumber() + "'" + "," + "," + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(paper.getCreateTime()) + "'" + "," + "'" + paper.getPeopleName() + "'" + "," + "'" + paper.getIdCardNo() + "'" + "," + "'" + paper.getUserId() + "'" + "," + "'" + paper.getApplyId() + "'" + "," + "'" + paper.getExamId() + "'" + "," + "'" + paper.getSource() + "'" + ")"; myAsyncService.FTP(s1); } } else { //不合格 @@ -374,46 +274,11 @@ 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); //生成保安证的同时向保安证管理表中插入一条数据 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()); securityPaper.setSource(1); //新增保安员证信息 securityPaperService.save(securityPaper); // String s1 = // "update blade_user set hold = " + "'" + user.getHold() + "'" + // ",securitynumber = " + "'" + user.getSecuritynumber() + "'" + // ",is_train = " + "'" + user.getIsTrain() + "'" + // " " + "where id = " + "'" + user.getId() + "'"; // FtpUtil.sqlFileUpload(s1); //去内网生成保安证编号,由内网生成,无需返回 //数据推送 Map<String, Object> map = new HashMap<>(1); map.put("key",examScore); myAsyncService.FTPSecurityNumberBit(map); } } else { //不合格 @@ -452,7 +317,6 @@ ",user_type = " + "'" + user.getUserType() + "'" + ",is_train = " + "'" + user.getIsTrain() + "'" + " " + "where id = " + "'" + user.getId() + "'"; //FtpUtil.sqlFileUpload(s1); myAsyncService.FTP(s1); } } src/main/java/org/springblade/modules/quartz/task/Task.java
@@ -610,6 +610,121 @@ return false; } // /** // * 读取内外推送的实操成绩导入情况信息 // * @return // */ // public boolean readExamScoreFile() { // FTPClient ftp = new FTPClient(); // try { // //设置传输超时时间为60秒 // ftp.setDataTimeout(10000); // //连接超时为60秒 // ftp.setConnectTimeout(10000); // //连接 // ftp.connect(ftpHost, ftpPort); // System.out.println("读取内外推送的实操成绩导入情况信息!"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); // // 登陆 // ftp.login(ftpUserNameIn, ftpPasswordIn); // // 检验登陆操作的返回码是否正确 // if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) { // ftp.disconnect(); // return false; // } // //// ftp.enterLocalActiveMode(); // // // 设置文件类型为二进制,与ASCII有区别 // ftp.setFileType(FTP.BINARY_FILE_TYPE); // // // 设置编码格式 // ftp.setControlEncoding("GBK"); // // // 检验文件是否存在 //// ftp.changeWorkingDirectory(ftpPath); // // // Use passive mode as default // ftp.enterLocalPassiveMode(); // // FTPFile[] files = ftp.listFiles(); // //文件个数大于10个时开始处理 // if (files.length==0){ //// ftp.logout(); // return false; // } // else { // for (int i = files.length-1; i >=0 ; i--) { // String fileName = files[i].getName(); // String substring = fileName.substring(0, 2); // System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+":读取到文件 = " + fileName); // if (substring.contains("ne")) { // //把文件下载到本地 // long l = System.currentTimeMillis(); // FtpUtil.downloadFtpFile(ftpHost, ftpUserNameIn, ftpPasswordIn, ftpPort, ftpPath, localPath, fileName); // long x = System.currentTimeMillis(); // System.out.println("下载文件耗时 = " + (x-l)+" 毫秒"); // //数据转换 // String json = OutJson.TestJson(fileName); // //取出map // Map<String,Object> map = JSON.parseObject(json, Map.class); // //取出 key/uuid,取出结果 // String uuid = null; // Result result = new Result(); // for (Map.Entry entry : map.entrySet()) { // Object value = entry.getValue(); // //转换 // result = JSON.parseObject(value.toString(), Result.class); // } // if (null!=result) { // examScoreHandler(result); // } // //删除本地文件 // MysqlCenlint.deletess(fileName); // //删除 ftp 文件 // FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserNameIn, ftpPasswordIn, ftpPath, fileName); // System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+":成功删除ftp文件 = " + fileName); // } // } // //关闭流 //// ftp.completePendingCommand(); //// ftp.logout(); // } // } catch (Exception e) { // System.out.println("ftp连接失败"); // e.printStackTrace(); // } finally { // try { // ftp.logout(); // } catch (IOException e) { // e.printStackTrace(); // } // if (ftp.isConnected()) { // try { // ftp.disconnect(); // } catch (IOException e) { // e.printStackTrace(); // } // } // } // return false; // } // /** // * 实操成绩导入修改 // * @param result // */ // private void examScoreHandler(Result result) { // //导入的人员不存在 // HandlerLog handlerLog = new HandlerLog(); // handlerLog.setCreateTime(new Date()); // handlerLog.setDeptId(deptId); // handlerLog.setOperatorTime(new Date()); // handlerLog.setType(4); // handlerLog.setRemark(result.getMsg()); // //插入记录 // handlerLogService.save(handlerLog); // } /** * 报名信息处理 * @param result src/main/java/org/springblade/modules/system/service/MyAsyncService.java
@@ -210,4 +210,12 @@ public void FTPSecurityNumberBit(Map<String, Object> map) { FtpUtil.getSecurityNumberBit(map); } /** * 考试实操成绩推送内网导入 * @param map */ public void FTPObjectExamScore(Map<String, Object> map) { FtpUtil.objectFileUploadExamScore(map); } }