| | |
| | | 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.training.entity.TrainingRegistration; |
| | | import org.springblade.modules.training.service.TrainingRegistrationService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | |
| | | import java.io.InputStream; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | import static org.springblade.common.config.FtpConfig.*; |
| | | import static org.springblade.common.config.FtpConfig.ftpPath; |
| | |
| | | ftp.setConnectTimeout(10000); |
| | | //连接 |
| | | ftp.connect(ftpHost, ftpPort); |
| | | System.out.println("ftp 连接成功!"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); |
| | | System.out.println("定时读取内网返回的 sql 文件!"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); |
| | | // 登陆 |
| | | ftp.login(ftpUserNameIn, ftpPasswordIn); |
| | | // 检验登陆操作的返回码是否正确 |
| | |
| | | return false; |
| | | } |
| | | else { |
| | | for (int i = files.length-1; i >0 ; i--) { |
| | | for (int i = files.length-1; i >=0 ; i--) { |
| | | String fileName = files[i].getName(); |
| | | System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+":读取到文件 = " + fileName); |
| | | if (fileName.contains("nq")) { |
| | | // InputStream is = ftp.retrieveFileStream(new String(fileName.getBytes("GBK"), FTP.DEFAULT_CONTROL_ENCODING)); |
| | | //把文件下载到本地 |
| | | long l = System.currentTimeMillis(); |
| | | FtpUtil.downloadFtpFile(ftpHost, ftpUserNameIn, ftpPasswordIn, ftpPort, ftpPath, localPath, fileName); |
| | |
| | | ftp.setConnectTimeout(10000); |
| | | //连接 |
| | | ftp.connect(ftpHost, ftpPort); |
| | | System.out.println("ftp 连接成功!"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); |
| | | System.out.println("定时任务:处理单个用户新增文件,ftp 连接成功!"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); |
| | | // 登陆 |
| | | ftp.login(ftpUserNameIn, ftpPasswordIn); |
| | | // 检验登陆操作的返回码是否正确 |
| | |
| | | |
| | | FTPFile[] files = ftp.listFiles(); |
| | | //文件个数大于10个时开始处理 |
| | | if (files.length==0 || files.length<6){ |
| | | // if (files.length==0 || files.length<10){ |
| | | if (files.length==0){ |
| | | ftp.logout(); |
| | | return false; |
| | | } |
| | | else { |
| | | for (int i = files.length-1; i >0 ; i--) { |
| | | for (int i = files.length-1; i >=0 ; i--) { |
| | | String fileName = files[i].getName(); |
| | | System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+":读取到文件 = " + fileName); |
| | | if (fileName.contains("ni")) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 读取内外推送的保安员单个新增文件 |
| | | * 读取内外推送的保安员批量导入文件 |
| | | * @return |
| | | */ |
| | | public boolean readSecurityListFile() { |
| | |
| | | ftp.setConnectTimeout(10000); |
| | | //连接 |
| | | ftp.connect(ftpHost, ftpPort); |
| | | System.out.println("ftp 连接成功!"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); |
| | | System.out.println("定时任务:读取内外推送的保安员批量导入文件!"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); |
| | | // 登陆 |
| | | ftp.login(ftpUserNameIn, ftpPasswordIn); |
| | | // 检验登陆操作的返回码是否正确 |
| | |
| | | |
| | | FTPFile[] files = ftp.listFiles(); |
| | | //文件个数大于10个时开始处理 |
| | | if (files.length==0 || files.length<10){ |
| | | if (files.length==0){ |
| | | ftp.logout(); |
| | | return false; |
| | | } |
| | | else { |
| | | for (int i = files.length-1; i >0 ; i--) { |
| | | for (int i = files.length-1; i >=0 ; i--) { |
| | | String fileName = files[i].getName(); |
| | | System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+":读取到文件 = " + fileName); |
| | | if (fileName.contains("nl")) { |
| | | // InputStream is = ftp.retrieveFileStream(new String(fileName.getBytes("GBK"), FTP.DEFAULT_CONTROL_ENCODING)); |
| | | //把文件下载到本地 |
| | | long l = System.currentTimeMillis(); |
| | | FtpUtil.downloadFtpFile(ftpHost, ftpUserNameIn, ftpPasswordIn, ftpPort, ftpPath, localPath, fileName); |
| | | long x = System.currentTimeMillis(); |
| | | System.out.println("下载文件耗时 = " + (x-l)+" 毫秒"); |
| | | // |
| | | String s = OutJson.TestJson(fileName); |
| | | //sql语句 |
| | | String sql = OutJson.stringReplace(s); |
| | | //删除本地服务器文件 |
| | | //数据转换 |
| | | 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) { |
| | | try { |
| | | userListInfoHandler(result); |
| | | }catch (Exception e) { |
| | | //异步用户处理逻辑 |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | //删除本地文件 |
| | | MysqlCenlint.deletess(fileName); |
| | | //删除 ftp 服务器文件 |
| | | // ftp.dele(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); |
| | | } |
| | |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 用户集合信息处理 |
| | | * @param result |
| | | */ |
| | | private void userListInfoHandler(Result result) { |
| | | //获取 result |
| | | List<Result> data1 = result.getData(); |
| | | if (data1.size()>0){ |
| | | for (Result result1 : data1) { |
| | | // 取出 Msg ,此 msg 存的对应的 uuid |
| | | String uuid = result1.getMsg(); |
| | | // 从redis 中获取对应的用户信息,脱敏处理过 |
| | | User user = handlerUserInfo(uuid); |
| | | if (result1.getCode()==200){ |
| | | user.setId(result1.getUserId()); |
| | | boolean save = userService.save(user); |
| | | if (save){ |
| | | //数据异步同步到群防群控 |
| | | myAsyncService.qfqkUserSave(user); |
| | | } |
| | | } |
| | | //更新 |
| | | if (result1.getCode()==201){ |
| | | //先查询当前库是否有改用户? |
| | | User user1 = userService.getById(result1.getUserId()); |
| | | if (null!=user1) { |
| | | //存在,更新 |
| | | user.setId(result1.getUserId()); |
| | | user.setCreateTime(null); |
| | | boolean update = userService.updateById(user); |
| | | if (update) { |
| | | //数据异步同步到群防群控 |
| | | myAsyncService.updateUserByQfqk(user); |
| | | } |
| | | }else { |
| | | //不存在,则新增 |
| | | user.setId(result1.getUserId()); |
| | | boolean save = userService.save(user); |
| | | if (save){ |
| | | //数据异步同步到群防群控 |
| | | myAsyncService.qfqkUserSave(user); |
| | | } |
| | | } |
| | | } |
| | | if (result1.getCode()==202){ |
| | | //已在其他单位存在 |
| | | } |
| | | if (result1.getCode()==203){ |
| | | //保安证编号不匹配 |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | ftp.setConnectTimeout(10000); |
| | | //连接 |
| | | ftp.connect(ftpHost, ftpPort); |
| | | System.out.println("ftp 连接成功!"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); |
| | | System.out.println("读取内外推送的保安员报名信息!"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); |
| | | // 登陆 |
| | | ftp.login(ftpUserNameIn, ftpPasswordIn); |
| | | // 检验登陆操作的返回码是否正确 |
| | |
| | | |
| | | FTPFile[] files = ftp.listFiles(); |
| | | //文件个数大于10个时开始处理 |
| | | if (files.length==0 || files.length<10){ |
| | | if (files.length==0){ |
| | | ftp.logout(); |
| | | return false; |
| | | } |
| | | else { |
| | | for (int i = files.length-1; i >0 ; i--) { |
| | | for (int i = files.length-1; i >=0 ; i--) { |
| | | String fileName = files[i].getName(); |
| | | System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+":读取到文件 = " + fileName); |
| | | if (fileName.contains("nt")) { |
| | |
| | | FtpUtil.downloadFtpFile(ftpHost, ftpUserNameIn, ftpPasswordIn, ftpPort, ftpPath, localPath, fileName); |
| | | long x = System.currentTimeMillis(); |
| | | System.out.println("下载文件耗时 = " + (x-l)+" 毫秒"); |
| | | // |
| | | String s = OutJson.TestJson(fileName); |
| | | //sql语句 |
| | | String sql = OutJson.stringReplace(s); |
| | | //删除本地服务器文件 |
| | | //数据转换 |
| | | 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()) { |
| | | uuid = entry.getKey().toString(); |
| | | Object value = entry.getValue(); |
| | | //转换 |
| | | result = JSON.parseObject(value.toString(), Result.class); |
| | | } |
| | | if (null!=result) { |
| | | applyHandler(uuid,result); |
| | | } |
| | | //删除本地文件 |
| | | MysqlCenlint.deletess(fileName); |
| | | //删除 ftp 服务器文件 |
| | | // ftp.dele(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); |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 报名信息处理 |
| | | * @param result |
| | | */ |
| | | private void applyHandler(String uuid,Result result) { |
| | | //取出培训学校id |
| | | //从redis 中获取用户数据 |
| | | String s = redisTemplate.opsForValue().get(uuid).toString(); |
| | | if (null!=s && !s.equals("")) { |
| | | //创建集合,存年龄符合要求 |
| | | List<String> ageList = new ArrayList<>(); |
| | | //创建年龄不符合集合 |
| | | List<String> errorList = new ArrayList<>(); |
| | | AtomicInteger number = new AtomicInteger(); |
| | | if (null != result) { |
| | | //获取 result |
| | | List<Result> data1 = result.getData(); |
| | | if (data1.size() > 0) { |
| | | for (Result result1 : data1) { |
| | | // 取出 Msg ,此 msg 存的对应的 uuid |
| | | Long userId = result1.getUserId(); |
| | | if (result1.getCode() == 200) { |
| | | //加入新增集合 |
| | | ageList.add(userId.toString()); |
| | | } |
| | | //年龄不符合要求 |
| | | if (result1.getCode() == 201) { |
| | | //number ++ |
| | | number.getAndIncrement(); |
| | | //查询用户信息 |
| | | User user = userService.getById(userId); |
| | | //加入更新集合 |
| | | errorList.add(user.getRealName()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (ageList.size() > 0) { |
| | | //遍历 |
| | | ageList.forEach(userId -> { |
| | | User user = userService.getUserById(userId); |
| | | //未报名的新增,已报名的不做处理 |
| | | if (null == user.getIsTrain()) { |
| | | TrainingRegistration trainingRegistration1 = new TrainingRegistration(); |
| | | trainingRegistration1.setCancel(1); |
| | | //默认为未考试状态 |
| | | trainingRegistration1.setIsExam(1); |
| | | //未提交考试审核 |
| | | trainingRegistration1.setAuditStatus(4); |
| | | trainingRegistration1.setTrainingTime(new Date()); |
| | | trainingRegistration1.setUserId(userId); |
| | | trainingRegistration1.setTrainingUnitId(s); |
| | | trainingRegistrationService.save(trainingRegistration1); |
| | | //修改保安报名状态 |
| | | user.setIsTrain(1); |
| | | userService.updateById(user); |
| | | |
| | | //数据同步 |
| | | saveTrainingRegistration(trainingRegistration1, user); |
| | | } else { |
| | | if (user.getIsTrain() != 1) { |
| | | TrainingRegistration trainingRegistration1 = new TrainingRegistration(); |
| | | trainingRegistration1.setCancel(1); |
| | | //默认为未考试状态 |
| | | trainingRegistration1.setIsExam(1); |
| | | //未提交考试审核 |
| | | trainingRegistration1.setAuditStatus(4); |
| | | trainingRegistration1.setTrainingTime(new Date()); |
| | | trainingRegistration1.setUserId(userId); |
| | | trainingRegistration1.setTrainingUnitId(s); |
| | | trainingRegistrationService.save(trainingRegistration1); |
| | | //修改保安报名状态 |
| | | user.setIsTrain(1); |
| | | userService.updateById(user); |
| | | |
| | | //数据同步 |
| | | saveTrainingRegistration(trainingRegistration1, user); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 报名 |
| | | */ |
| | | private void saveTrainingRegistration(TrainingRegistration trainingRegistration,User user1){ |
| | | String formatStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); |
| | | Long id = trainingRegistration.getId(); |
| | | String sql = "insert into sys_training_registration(id,training_unit_id,training_time,cancel,user_id,is_exam,audit_status) " + |
| | | "values(" + "'" + id + "'" |
| | | + "," + "'" + trainingRegistration.getTrainingUnitId() +"'" |
| | | + "," + "'" + formatStr +"'" |
| | | + "," + "'" + trainingRegistration.getCancel() + "'" |
| | | + "," + "'" + trainingRegistration.getUserId() + "'" |
| | | + "," + "'" + trainingRegistration.getIsExam() + "'" |
| | | + "," +"'" + trainingRegistration.getAuditStatus() + "'" + ");" + |
| | | "update blade_user set is_train = " + user1.getIsTrain() + " " +"where id = " + "'" + user1.getId() + "'"; |
| | | myAsyncService.FTP(sql); |
| | | } |
| | | |
| | | /** |
| | | * 用户审查 |
| | | * @return |
| | | */ |
| | | public void userExamine() { |
| | | System.out.println("用户审查任务发起"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); |
| | | //查询审查状态为未审查的保安员 |
| | | User user = new User(); |
| | | user.setStatus(1); |