智慧保安后台管理-外网
src/main/java/org/springblade/modules/training/controller/TrainingRegistrationController.java
@@ -1,5 +1,6 @@
package org.springblade.modules.training.controller;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@@ -20,6 +21,8 @@
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.FTP.FtpUtil;
import org.springblade.modules.FTP.Monitor;
import org.springblade.modules.FTP.Result;
import org.springblade.modules.apply.entity.Apply;
import org.springblade.modules.exam.entity.ExamPaper;
import org.springblade.modules.exam.service.ExamPaperService;
@@ -35,6 +38,7 @@
import org.springblade.modules.vip.service.UserVipService;
import org.springblade.modules.vip.service.VipTopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -65,6 +69,8 @@
   private final VipTopicService vipTopicService;
   private final MyAsyncService myAsyncService;
   private final RedisTemplate redisTemplate;
   /**
@@ -310,16 +316,69 @@
   @PostMapping("/batchTrain")
   public R batchApply(@RequestBody TrainingRegistrationVo trainingRegistration){
      List<String> list = Arrays.asList(trainingRegistration.getUserIds().split(","));
      AtomicInteger count  = new AtomicInteger();
      //创建年龄部分对象集合
      //将集合推送内网,判断年龄是否符合要求,得到返回的结果,结果需包含userId,及年龄是否符合的状态
      //生成随机数
      String uuid = UUID.randomUUID().toString();
      //数据推送
      Map<String, Object> map = new HashMap<>(1);
      map.put(uuid, list);
      myAsyncService.FTPObjectListUserId(map);
      Result result = new Result();
      int count = 0;
      //调用ftp获取返回数据
      while (true){
         try {
            Thread.sleep(1000);
         } catch (InterruptedException e) {
            e.printStackTrace();
         }
         //调用ftp获取返回数据
         result = Monitor.getFtpDataByUuidListTrain(uuid);
         //如果返回true,就退处
         if (result.getCode() == 200) {
            break;
         }else {
            count++;
            if (count == 30) {
               break;
            }
         }
      }
      //创建集合,存年龄符合要求
      List<String> ageList = new ArrayList<>();
      //创建年龄不符合集合
      List<String> errorList = new ArrayList<>();
//      AtomicReference<StringBuilder> builder = new AtomicReference<>(new StringBuilder());
      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) {
      //遍历
      list.forEach(userId ->{
         ageList.forEach(userId -> {
         User user = userService.getUserById(userId);
         UserVO userVO = userService.getUserAgeById(Long.parseLong(userId));
         //判断年龄
         if (userVO.getAge()>=18 && userVO.getAge()<=60) {
            //未报名的新增,已报名的不做处理
            if (null == user.getIsTrain()) {
               TrainingRegistration trainingRegistration1 = new TrainingRegistration();
@@ -338,7 +397,6 @@
               //数据同步
               saveTrainingRegistration(trainingRegistration1,user);
//               builder.set(batchSaveTrainingRegistration(trainingRegistration1, user, builder.get()));
            } else {
               if (user.getIsTrain() != 1) {
                  TrainingRegistration trainingRegistration1 = new TrainingRegistration();
@@ -357,22 +415,13 @@
                  //数据同步
                  saveTrainingRegistration(trainingRegistration1,user);
//                  builder.set(batchSaveTrainingRegistration(trainingRegistration1, user, builder.get()));
               }
            }
         }else {
            //count ++
            count.getAndIncrement();
            //放入集合
            errorList.add(user.getCardid());
         }
      });
//      //同步
//      if (builder.get().length()>0) {
//         FtpSyncUtil.slqSync(builder.get());
//      }
      }
      //如果存在年龄不符的,则抛出异常
      if (count.get()>0){
      if (number.get()>0){
         String errorAccount = StringUtils.join(errorList, "\\\n");
         throw new ServiceException("保安员:[" + errorAccount + "]报名失败!年龄不符,报名年龄为[18-60]周岁!");
      }