ZengTao
2023-12-12 be64830b020d7cacc429776b0fe5bfab4d893e05
springboot-vue3/src/main/java/com/example/springboot/controller/HomeController.java
@@ -1,222 +1,387 @@
package com.example.springboot.controller;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import com.example.springboot.mapper.HomeMapper;
import com.example.springboot.mapper.SpianMapper;
import com.example.springboot.security.constant.SystemConstant;
import com.example.springboot.security.util.JwtUtil;
import com.example.springboot.security.util.SecurityUtil;
import com.example.springboot.service.HomeService;
import com.example.springboot.service.JdbcConnections;
import com.example.springboot.service.North_Glass_Buffer1Service;
import com.example.springboot.service.OutSliceServive;
import com.example.springboot.service.PermissionService;
import com.example.springboot.service.SpianService;
import cn.hutool.core.util.StrUtil;
import com.example.springboot.common.Result;
import com.example.springboot.component.Plchome;
import com.example.springboot.component.S7control;
import com.example.springboot.entity.CarPosition;
import com.example.springboot.entity.Glass;
import com.example.springboot.entity.StorageCage;
import com.example.springboot.entity.User;
import com.example.springboot.entity.alarmmg;
import com.example.springboot.entity.north_glass_buffer1;
import com.example.springboot.entity.Out_slice;
import com.example.springboot.entity.Permission;
import com.example.springboot.entity.Queue;
import com.example.springboot.entity.RolePermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
@RestController
@RequestMapping("/home")
public class HomeController {
    @Autowired
    HomeMapper homeMapper;
  @Autowired
  HomeMapper homeMapper;
    @Autowired
    HomeService storageRackService;
  @Autowired
  HomeService storageRackService;
    @Autowired
    SpianService spianService;
  @Autowired
  SpianService spianService;
    @Autowired
    SpianMapper spianMapper;
    //查询理片笼使用情况
    @GetMapping("/load")
    public Result selectAll() {
        List<StorageCage> storageCagelist = homeMapper.selectAll();
        Map<String, Object> map = new HashMap<>();
        map.put("list", storageCagelist);
        return Result.success(map);
  @Autowired
  SpianMapper spianMapper;
  @Autowired
  OutSliceServive outSliceServive;
  @Autowired
  North_Glass_Buffer1Service north_Glass_Buffer1Service;
  @Autowired
  private JdbcConnections jdbcConnections;
  // 获取当前登录用户权限
  @GetMapping("/SelectPermissionByUserName")
  public Result SelectPermissionByUserName(String username) {
    Map<String, Object> map = new HashMap<>();
    List<RolePermission> permission = homeMapper.SelectPermissionByUserName(username);
    map.put("permission", permission);
    return Result.success(map);
  }
  // 查询理片笼使用情况
  @GetMapping("/load")
  public Result selectAll() {
    List<StorageCage> storageCagelist = homeMapper.selectAll();
    Map<String, Object> map = new HashMap<>();
    map.put("list", storageCagelist);
    return Result.success(map);
  }
  // 查询理片笼玻璃情况
  @GetMapping("/loads")
  public Result selectRack() {
    List<StorageCage> storageCagelist1 = homeMapper.selectRack1();
    List<StorageCage> storageCagelist2 = homeMapper.selectRack2();
    List<StorageCage> storageCagelist3 = homeMapper.selectRack3();
    List<StorageCage> storageCagelist4 = homeMapper.selectRack4();
    Map<String, Object> map = new HashMap<>();
    map.put("list1", storageCagelist1);
    map.put("list2", storageCagelist2);
    map.put("list3", storageCagelist3);
    map.put("list4", storageCagelist4);
    return Result.success(map);
  }
  // 按订单出片
  @GetMapping("/InsertOrder")
  public Result InsertOrder(String orderid) {
    short result = homeMapper.SelectOrder(orderid);
    Map<String, Object> map = new HashMap<>();
    if (result > 0) {
      homeMapper.updateOrder();
      homeMapper.InsertOrder(orderid);
      map.put("message", "200");
    } else {
      map.put("message", "500");
    }
    //查询理片笼玻璃情况
    @GetMapping("/loads")
    public Result selectRack() {
        List<StorageCage> storageCagelist1 = homeMapper.selectRack1();
        List<StorageCage> storageCagelist2 = homeMapper.selectRack2();
        List<StorageCage> storageCagelist3 = homeMapper.selectRack3();
        List<StorageCage> storageCagelist4 = homeMapper.selectRack4();
        Map<String, Object> map = new HashMap<>();
        map.put("list1", storageCagelist1);
        map.put("list2", storageCagelist2);
        map.put("list3", storageCagelist3);
        map.put("list4", storageCagelist4);
        return Result.success(map);
    return Result.success(map);
  }
  // 根据玻璃id手动上片
  @GetMapping("/Addglassid")
  public Result Addglassid(String glassid) {
    Map<String, Object> map = new HashMap<>();
    short taskno = homeMapper.SelectInTask();
    if (taskno > 0) {
      map.put("message2", "500");
    } else {
      // 调用伍上片函数
      short results = spianService.selectAll(glassid);
      if (results == 200) {
        map.put("message2", "200");
      } else if (results == 300) {
        map.put("message2", "300");
      } else if (results == 400) {
        map.put("message2", "400");
      }
    }
    //查询进/出片任务
    @GetMapping("/loadinout")
    public Result selectinout(Integer types) {
        List<StorageCage> storageCageinout = homeMapper.selectinout(types);
        Map<String, Object> map = new HashMap<>();
        map.put("list", storageCageinout);
        return Result.success(map);
    return Result.success(map);
  }
  // 手动完成进/出片任务
  @GetMapping("/UpdateTask")
  public Result UpdateTask(Integer types, Integer shelfrack, String glassid) {
    Map<String, Object> map = new HashMap<>();
    homeMapper.UpdateTask(types, glassid);
    StorageCage glass = homeMapper.SelectGlassInfo(glassid);
    if (types == 0) {
      homeMapper.UpdateCageTask1(glassid);
      S7control.getinstance().WriteWord("DB105.14", (short) 0);
    } else {
      spianMapper.UpdataOutCage1(glass.getGlassWidth(), glass.getCage(), glass.getCell());
      homeMapper.UpdateCageTask2(glassid);
      S7control.getinstance().WriteWord("DB105.12", (short) 0);
    }
    //按订单出片
    @GetMapping("/InsertOrder")
    public Result InsertOrder(String orderid) {
        short result = homeMapper.SelectOrder(orderid);
        Map<String, Object> map = new HashMap<>();
        if (result > 0) {
            homeMapper.updateOrder();
            homeMapper.InsertOrder(orderid);
            map.put("message", "200");
    map.put("message3", "200");
    return Result.success(map);
  }
  // 查询报警信息
  @GetMapping("/SelectAlarmmgInfo")
  public Result SelectAlarmmgInfo() {
    List<alarmmg> alarmmg = homeMapper.SelectAlarmmgInfo();
    Map<String, Object> map = new HashMap<>();
    map.put("alarmmg", alarmmg);
    return Result.success(map);
  }
  // 查询理片笼详情
  @GetMapping("/SelectCageInfo")
  public Result SelectCageInfo(String cage) throws SQLException {
    List<StorageCage> cageinfo = homeMapper.SelectCageInfo(cage);
    Map<String, Object> map = new HashMap<>();
    map.put("cageinfo", cageinfo);
    return Result.success(map);
  }
  // 手动删除理片笼玻璃
  @GetMapping("/DeleteByGlassID")
  public Result DeleteByGlassID(String glassid) {
    StorageCage glassinfor = homeMapper.SelectGlassInfo(glassid);
    spianMapper.UpdataOutCage1(glassinfor.getGlassWidth(), glassinfor.getCage(), glassinfor.getCell());
    homeMapper.DeleteByGlassID(glassid);
    Map<String, Object> map = new HashMap<>();
    map.put("message3", "200");
    return Result.success(map);
  }
  // 根据玻璃id手动出片
  @GetMapping("/OutByGlassID")
  public Result OutByGlassID(String glassid) throws SQLException {
    Map<String, Object> map = new HashMap<>();
    Out_slice result = homeMapper.SelectQueueByglassid(glassid);
    if (result == null) {
      north_glass_buffer1 north_glass_buffer1 = jdbcConnections.SelectGlassByGlassIdOrderIdFrameId(glassid, "", "");
      String flip = jdbcConnections.SelectFlipByFrameBarcode(north_glass_buffer1.getFrameBarcode());
      if (flip != null) {
        String position = jdbcConnections.SelectPositionByFrameBarcode(north_glass_buffer1.getFrameBarcode());
        if (position != null) {
          int sequence = homeMapper.SelectMaxSquence();
          homeMapper.AddOutSliceS(glassid, flip, north_glass_buffer1.getFrameBarcode(),
              north_glass_buffer1.getglasslengthmm().toString(), north_glass_buffer1.getglassheightmm().toString(),
              sequence, position);
          map.put("message2", "200");
        } else {
            map.put("message", "500");
        }
        return Result.success(map);
    }
    //根据玻璃id手动上片
    @GetMapping("/Addglassid")
    public Result Addglassid(String glassid) {
        Map<String, Object> map = new HashMap<>();
        short taskno = homeMapper.SelectInTask();
        if (taskno > 0) {
            map.put("message2", "500");
        } else {
            // 调用伍上片函数
            short results = spianService.selectAll(glassid);
            if (results == 200) {
                map.put("message2", "200");
            } else if (results == 300) {
                map.put("message2", "300");
            } else if (results == 400) {
                map.put("message2", "400");
            }
        }
        return Result.success(map);
    }
    //手动完成进/出片任务
    @GetMapping("/UpdateTask")
    public Result UpdateTask(Integer types, Integer shelfrack, String glassid) {
        Map<String, Object> map = new HashMap<>();
        homeMapper.UpdateTask(types);
        StorageCage glass = homeMapper.SelectGlassInfo(glassid);
        if (types == 0) {
            // spianMapper.UpdataAddCage1(glass.getGlassWidth(),glass.getCage(),glass.getCell());
            homeMapper.UpdateCageTask1(glassid);
            S7control.getinstance().WriteWord("DB105.14", (short) 0);
        } else {
            spianMapper.UpdataOutCage1(glass.getGlassWidth(), glass.getCage(), glass.getCell());
            homeMapper.UpdateCageTask2(glassid);
            S7control.getinstance().WriteWord("DB105.12", (short) 0);
        }
        map.put("message3", "200");
        return Result.success(map);
    }
    //查询报警信息
    @GetMapping("/SelectAlarmmgInfo")
    public Result SelectAlarmmgInfo() {
        List<alarmmg> alarmmg = homeMapper.SelectAlarmmgInfo();
        Map<String, Object> map = new HashMap<>();
        map.put("alarmmg", alarmmg);
        return Result.success(map);
    }
    //查询理片笼详情
    @GetMapping("/SelectCageInfo")
    public Result SelectCageInfo(short cage) {
        List<StorageCage> cageinfo = homeMapper.SelectCageInfo(cage);
        Map<String, Object> map = new HashMap<>();
        map.put("cageinfo", cageinfo);
        return Result.success(map);
    }
    //手动删除理片笼玻璃
    @GetMapping("/DeleteByGlassID")
    public Result DeleteByGlassID(String glassid) {
        StorageCage glassinfor = homeMapper.SelectGlassInfo(glassid);
        spianMapper.UpdataOutCage1(glassinfor.getGlassWidth(), glassinfor.getCage(), glassinfor.getCell());
        homeMapper.DeleteByGlassID(glassid);
        Map<String, Object> map = new HashMap<>();
        map.put("message3", "200");
        return Result.success(map);
    }
    //根据玻璃id手动出片
    @GetMapping("/OutByGlassID")
    public Result OutByGlassID(String glassid) {
        Map<String, Object> map = new HashMap<>();
        // 调用伍上片函数
        short result = homeMapper.SelectStorageByGlassId(glassid);
        if (result > 0) {
            Short results = spianService.selectout2(glassid);
            if (results == 200) {
                map.put("message2", "200");
            } else if (results == 300) {
                map.put("message2", "300");
            }
        }else{
            map.put("message2", "500");
          map.put("message2", "300");
        }
        return Result.success(map);
      } else {
        map.put("message2", "400");
      }
    } else {
      map.put("message2", "500");
    }
    //加载小车位置
    @GetMapping("/Loadcarlist")
    public Result Loadcarlist() {
        List<CarPosition> carlist = homeMapper.Loadcarlist();
        Map<String, Object> map = new HashMap<>();
        map.put("carlist", carlist);
        return Result.success(map);
    return Result.success(map);
  }
  // 加载小车位置
  @GetMapping("/Loadcarlist")
  public Result Loadcarlist() {
    List<CarPosition> carlist = homeMapper.Loadcarlist();
    Map<String, Object> map = new HashMap<>();
    map.put("carlist", carlist);
    return Result.success(map);
  }
  // 查询确认密码
  @GetMapping("/SelectPassword")
  public Result SelectPassword() {
    String pwdct = homeMapper.SelectPassword();
    Map<String, Object> map = new HashMap<>();
    map.put("password", pwdct);
    return Result.success(map);
  }
  // 根据玻璃id查询玻璃信息
  @GetMapping("/SelectGlassByGlassID")
  public Result SelectGlassByGlassID(String glassid) throws SQLException {
    Queue queue = jdbcConnections.SelectGlassByGlassIdOrderIdFrameIdQueue(glassid, "", "");
    Map<String, Object> map = new HashMap<>();
    if (glassid != "") {
      map.put("form", queue);
    }
    //查询确认密码
    @GetMapping("/SelectPassword")
    public Result SelectPassword() {
        String pwdct = homeMapper.SelectPassword();
        Map<String, Object> map = new HashMap<>();
        map.put("password", pwdct);
        return Result.success(map);
    }
    //根据玻璃id查询玻璃信息
    @GetMapping("/SelectGlassByGlassID")
    public Result SelectGlassByGlassID(String glassid) {
        Glass Glass = homeMapper.SelectGlassByGlassID(glassid);
        Map<String, Object> map = new HashMap<>();
        map.put("form", Glass);
        return Result.success(map);
    }
    //启用/禁用理片笼格子
    @GetMapping("/Disabled")
    public Result Disabled(short cage, short cell, short disabled) {
        homeMapper.Disabled(cage, cell, disabled);
        Map<String, Object> map = new HashMap<>();
    return Result.success(map);
  }
  // 启用/禁用理片笼格子
  @GetMapping("/Disabled")
  public Result Disabled(short cage, short cell, short disabled) {
    homeMapper.Disabled(cage, cell, disabled);
    Map<String, Object> map = new HashMap<>();
    map.put("message", "200");
    return Result.success(map);
  }
  // 手动往理片笼添加玻璃
  @PostMapping("/Inglassid")
  public Result Inglassid(short cage, short cell, short tier, @RequestBody Queue queue) {
    Map<String, Object> map = new HashMap<>();
    short result = homeMapper.SelectStorageByGlassId(queue.getglassId());
    Double cagewidth = homeMapper.SelectCageWidth(cage, cell);
    if (cagewidth - queue.getglasswidth() - 400 < 0 || (cagewidth == 2750 && queue.getglasswidth() > cagewidth)) {
      map.put("message", "400");
    } else {
      if (result > 0) {
        map.put("message", "300");
      } else {
        homeMapper.Inglassid(queue, cage, cell, tier);
        spianMapper.UpdataAddCage1(queue.getglasswidth(), cage, cell);
        map.put("message", "200");
        return Result.success(map);
      }
    }
    //手动往理片笼添加玻璃
    @PostMapping("/Inglassid")
    public Result Inglassid(short cage, short cell, short tier, @RequestBody Glass glass) {
        Map<String, Object> map = new HashMap<>();
        short result = homeMapper.SelectStorageByGlassId(glass.getGlassId());
        if (result > 0) {
            map.put("message", "300");
        } else {
            homeMapper.Inglassid(glass, cage, cell, tier);
            spianMapper.UpdataAddCage1(glass.getWidth(), cage, cell);
        }
        return Result.success(map);
    }
    return Result.success(map);
  }
    //查询玻璃信息
    @PostMapping("/SelectGlass")
    public Result SelectGlass(String orderid) {
        Map<String, Object> map = new HashMap<>();
        List<Glass> glass=homeMapper.SelectGlass(orderid);
        map.put("glass", glass);
        return Result.success(map);
    }
  // 查询玻璃信息
  @PostMapping("/SelectGlass")
  public Result SelectGlass(String orderid) throws SQLException {
    Map<String, Object> map = new HashMap<>();
    List<north_glass_buffer1> glass = jdbcConnections.SelectGlassByGlassIdOrderIdFrameIds("", orderid, "");
    map.put("glass", glass);
    return Result.success(map);
  }
  // 手动添加扫码位玻璃
  @PostMapping("/InsertQueueGlassId")
  public Result InsertQueueGlassId(Short id, @RequestBody Queue queue) {
    Map<String, Object> map = new HashMap<>();
    short result = homeMapper.SelectStorageByGlassId(queue.getglassId());
    if (result > 0) {
      map.put("message", "300");
    } else {
      homeMapper.InsertQueueGlassId(queue, id);
      if (id == 1) {
        // 调用伍存储过程
        spianService.selectAll(queue.getglassId());
      }
      map.put("message", "200");
    }
    return Result.success(map);
  }
  // 确认扫码位玻璃信息
  @PostMapping("/UpdateQueueState")
  public Result UpdateQueueState() {
    homeMapper.UpdateQueueState();
    Map<String, Object> map = new HashMap<>();
    map.put("message", "200");
    return Result.success(map);
  }
  // 清除上片队列玻璃
  @PostMapping("/DeleteQueueGlass")
  public Result DeleteQueueGlass(String id) {
    homeMapper.DeleteQueueGlass(id);
    Map<String, Object> map = new HashMap<>();
    map.put("message", "200");
    return Result.success(map);
  }
  // 查询此订单在理片笼里的玻璃数
  @PostMapping("/SelectGlassNo")
  public Result SelectGlassNo(String orderid) {
    Short count = homeMapper.SelectGlassNo(orderid);
    Map<String, Object> map = new HashMap<>();
    map.put("count", count);
    return Result.success(map);
  }
  // 根据铝框id获取对应玻璃信息
  @PostMapping("/SelectAluminumFrameInfoById")
  public Result SelectAluminumFrameInfoById(String FrameBarcode) throws SQLException {
    String flip = jdbcConnections.SelectFlipByFrameBarcode(FrameBarcode);
    List<north_glass_buffer1> listAluminumFrame = north_Glass_Buffer1Service.SelectAluminumFrameInfoById(FrameBarcode);
    Map<String, Object> map = new HashMap<>();
    map.put("listAluminumFrame", listAluminumFrame);
    map.put("flip", flip);
    return Result.success(map);
  }
  // 根据铝框id删除出片队列玻璃
  @PostMapping("/DeleteProductionQueueGlass")
  public Result DeleteProductionQueueGlass(String FrameNo) {
    homeMapper.CompleteQueueByFrameNo(FrameNo);
    Map<String, Object> map = new HashMap<>();
    map.put("message", "200");
    return Result.success(map);
  }
  // 添加铝框id对应玻璃到出片队列
  @PostMapping("/AddOutSliceS")
  public Result AddOutSliceS(@RequestBody String[][] AluminumFrames) throws SQLException {
    outSliceServive.AddOutSliceS(AluminumFrames);
    Map<String, Object> map = new HashMap<>();
    map.put("message", "200");
    return Result.success(map);
  }
  // 修改出片队列状态与出片队列调序
  @PostMapping("/isAllowQueues")
  public Result isAllowQueues(Boolean isAllowQueue, @RequestBody List<Out_slice> out_slice) {
    Plchome.isAllowQueue = isAllowQueue;
    if (isAllowQueue == true) {
      for (Out_slice out_slice2 : out_slice) {
        homeMapper.UpdateOutSliceSequence(out_slice2.getGlassId(), out_slice2.getSequence());
      }
    }
    Map<String, Object> map = new HashMap<>();
    map.put("message", "200");
    return Result.success(map);
  }
  // 修改出片队列状态与出片队列调序
  @PostMapping("/isConfirmStates")
  public Result isConfirmStates(Boolean isConfirmStates) {
    Plchome.isConfirm = isConfirmStates;
    Map<String, Object> map = new HashMap<>();
    map.put("message", "200");
    return Result.success(map);
  }
  // 手动完成任务
  @PostMapping("/CompleteQueue")
  public Result CompleteQueue(String id, String frameid, String glassid) {
    return outSliceServive.CompleteQueue(id, frameid, glassid);
  }
}