智慧保安后台管理-外网项目备份
Administrator
2021-11-08 d4cb6034a5e05b7aa2fb4593f4c2b630be138ca1
src/main/java/org/springblade/modules/dispatcher/controller/DispatcherController.java
@@ -23,7 +23,6 @@
import lombok.AllArgsConstructor;
import javax.validation.Valid;
import org.springblade.common.utils.arg;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
@@ -43,6 +42,7 @@
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
/**
 *  控制器
@@ -167,14 +167,11 @@
   @ApiOperationSupport(order = 6)
   @ApiOperation(value = "新增或修改", notes = "传入dispatcher")
   public R submit(@Valid @RequestBody Dispatcher dispatcher) {
      //List<String> list = Arrays.asList(dispatcher.getUserIds().split(","));
      //计算派遣人数
      //dispatcher.setNum(list.size());
      boolean status = false;
      if (dispatcher.getId()==null){
         dispatcher.setCreateTime(new Date());
         dispatcher.setStatus(0);
         dispatcher.setUserIds(dispatcher.getUserIds());
         User user = new User();
         user.setId(Long.parseLong(dispatcher.getUserIds()));
@@ -202,8 +199,6 @@
         FtpUtil.sqlFileUpload(s1);
      }else {
            dispatcher.setUpdateTime(new Date());
            //查询当前派遣记录
            Dispatcher dispatcher1 = dispatcherService.getById(dispatcher.getId());
            if (!dispatcher1.getUserIds().equals(dispatcher.getUserIds())){
@@ -215,7 +210,7 @@
               List<Dispatcher> dispatcherList = dispatcherService.list(Condition.getQueryWrapper(dispatcher2));
               User user = new User();
               user.setId(Long.parseLong(dispatcher1.getUserIds()));
               if (dispatcherList.size()<1){
            if (dispatcherList.size() == 1) {
                  //用户状态改变
                  user.setDispatch("1");
               }else {
@@ -233,6 +228,127 @@
               //修改
               status = dispatcherService.updateById(dispatcher);
            //内网同步
            String s1 =
               "update blade_user set dispatch = " + "'" + user.getDispatch() + "'" +
                  " " + "where id = " + "'" + user.getId() + "';" +
               "update sys_dispatcher set dispatcherTime = " + "'" + new SimpleDateFormat("yyyy-MM-dd").format(dispatcher.getDispatchertime()) + "'" +
                  ",dispatcherAddress = " + "'" + dispatcher.getDispatcheraddress() + "'" +
                  ",dispatcher_unit_id = " + "'" + dispatcher.getDispatcherUnitId() + "'" +
                  ",user_ids = " + "'" + dispatcher.getUserIds() + "'" +
                  ",end_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd").format(dispatcher.getEndTime()) + "'" +
                  ",update_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dispatcher.getUpdateTime()) + "'" +
                  ",dept_id = " + "'" + dispatcher.getDeptId() + "'" +
                  ",jurisdiction = " + "'" + dispatcher.getJurisdiction() + "'" +
                  " " + "where id = " + "'" + dispatcher.getId() + "';" +
               "update blade_user set dispatch = " + "'" + user1.getDispatch() + "'" +
                  " " + "where id = " + "'" + user1.getId() + "'";
            FtpUtil.sqlFileUpload(s1);
         }else {
            //没有修改保安员,只修改了派遣时间等信息
            //修改
            status = dispatcherService.updateById(dispatcher);
            //内网同步
            String s1 =
               "update sys_dispatcher set dispatcherTime = " + "'" + new SimpleDateFormat("yyyy-MM-dd").format(dispatcher.getDispatchertime()) + "'" +
                  ",dispatcherAddress = " + "'" + dispatcher.getDispatcheraddress() + "'" +
                  ",dispatcher_unit_id = " + "'" + dispatcher.getDispatcherUnitId() + "'" +
                  ",user_ids = " + "'" + dispatcher.getUserIds() + "'" +
                  ",end_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd").format(dispatcher.getEndTime()) + "'" +
                  ",update_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dispatcher.getUpdateTime()) + "'" +
                  ",dept_id = " + "'" + dispatcher.getDeptId() + "'" +
                  ",jurisdiction = " + "'" + dispatcher.getJurisdiction() + "'" +
                  " " + "where id = " + "'" + dispatcher.getId() + "'";
            FtpUtil.sqlFileUpload(s1);
         }
      }
      return R.status(status);
   }
   /**
    * 新增派遣(批量)
    */
   @PostMapping("/saveDispatcher")
   public R saveDispatcher(@RequestBody DispatcherVO dispatcher) {
      List<String> list = Arrays.asList(dispatcher.getIds().split(","));
      //修改状态
      AtomicBoolean status = new AtomicBoolean(false);
      if (list.size()>0) {
         //遍历
         list.forEach(id -> {
            dispatcher.setCreateTime(new Date());
            dispatcher.setStatus(0);
            dispatcher.setUserIds(id);
            User user = new User();
            user.setId(Long.parseLong(id));
            user.setDispatch("0");
            userService.updateById(user);
            //新增派遣记录
            status.set(dispatcherService.save(dispatcher));
            //数据同步
            String s1 =
               "insert into sys_dispatcher(id,dispatcherTime,dispatcherAddress,dispatcher_unit_id,user_ids,end_time,dept_id,jurisdiction,create_time,status) " +
                  "values(" + "'" + dispatcher.getId() + "'" + "," +
                  "'" + new SimpleDateFormat("yyyy-MM-dd").format(dispatcher.getDispatchertime()) + "'" + "," +
                  "'" + dispatcher.getDispatcheraddress() + "'" + "," +
                  "'" + dispatcher.getDispatcherUnitId() + "'" + "," +
                  "'" + dispatcher.getUserIds() + "'" + "," +
                  "'" + new SimpleDateFormat("yyyy-MM-dd").format(dispatcher.getEndTime()) + "'" + "," +
                  "'" + dispatcher.getDeptId() + "'" + "," +
                  "'" + dispatcher.getJurisdiction() + "'" + "," +
                  "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dispatcher.getCreateTime()) + "'" + "," +
                  "'" + dispatcher.getStatus() + "'" + ");" +
               "update blade_user set dispatch = " + "'" + user.getDispatch() + "'" +
                  " " + "where id = " + "'" + user.getId() + "'";
            FtpUtil.sqlFileUpload(s1);
         });
      }
      return R.status(status.get());
   }
   /**
    * 派遣记录修改
    */
   @PostMapping("/updateDispatcher")
   public R updateDispatcher(@RequestBody DispatcherVO dispatcher) {
      boolean status = false;
      dispatcher.setUpdateTime(new Date());
      //查询当前派遣记录
      Dispatcher dispatcher1 = dispatcherService.getById(dispatcher.getId());
      if (!dispatcher1.getUserIds().equals(dispatcher.getUserIds())) {
         //修改原保安人员的派遣状态
         //查询原保安人员的派遣记录,是否存在多条未结束派遣的
         Dispatcher dispatcher2 = new Dispatcher();
         dispatcher2.setUserIds(dispatcher1.getUserIds());
         dispatcher2.setStatus(0);
         List<Dispatcher> dispatcherList = dispatcherService.list(Condition.getQueryWrapper(dispatcher2));
         User user = new User();
         user.setId(Long.parseLong(dispatcher1.getUserIds()));
         if (dispatcherList.size() == 1) {
            //用户状态改变
            user.setDispatch("1");
         } else {
            user.setDispatch("0");
         }
         //修改原保安人员用户信息
         userService.updateById(user);
         //修改当前保安人员的派遣状态
         User user1 = new User();
         user1.setId(Long.parseLong(dispatcher.getUserIds()));
         user1.setDispatch("0");
         userService.updateById(user1);
         //修改派遣记录信息
         status = dispatcherService.updateById(dispatcher);
               //内网同步
               String s1 =
@@ -250,8 +366,23 @@
                  "update blade_user set dispatch = " + "'" + user1.getDispatch() + "'" +
                     " " +"where id = " + "'" + user1.getId() + "'";
               FtpUtil.sqlFileUpload(s1);
            }
      }else {
         //没有修改保安员,只修改了派遣时间等信息
         //修改
         status = dispatcherService.updateById(dispatcher);
         //内网同步
         String s1 =
            "update sys_dispatcher set dispatcherTime = " + "'" + new SimpleDateFormat("yyyy-MM-dd").format(dispatcher.getDispatchertime()) + "'" +
               ",dispatcherAddress = " + "'" + dispatcher.getDispatcheraddress() + "'" +
               ",dispatcher_unit_id = " + "'" + dispatcher.getDispatcherUnitId() + "'" +
               ",user_ids = " + "'" + dispatcher.getUserIds() + "'" +
               ",end_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd").format(dispatcher.getEndTime()) + "'" +
               ",update_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dispatcher.getUpdateTime()) + "'" +
               ",dept_id = " + "'" + dispatcher.getDeptId() + "'" +
               ",jurisdiction = " + "'" + dispatcher.getJurisdiction() + "'" +
               " " + "where id = " + "'" + dispatcher.getId() + "'";
         FtpUtil.sqlFileUpload(s1);
      }
      return R.status(status);
   }