pang.jiabao
2025-05-25 be61c90200910a3e48c72596f3bbd459a2a73f25
src/main/java/com/zy/asrs/controller/CrnController.java
@@ -1,5 +1,6 @@
package com.zy.asrs.controller;
import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.annotations.ManagerAuth;
@@ -13,16 +14,15 @@
import com.zy.asrs.domain.vo.CrnListVo;
import com.zy.asrs.domain.vo.CrnMsgTableVo;
import com.zy.asrs.domain.vo.CrnStateTableVo;
import com.zy.asrs.entity.BasCrnError;
import com.zy.asrs.entity.BasCrnp;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.entity.*;
import com.zy.asrs.importexcle.ImportCrnErrDto;
import com.zy.asrs.importexcle.ImportCrnErrListener;
import com.zy.asrs.mapper.BasCrnErrorMapper;
import com.zy.asrs.mapper.TaskWrkMapper;
import com.zy.asrs.service.BasCrnErrorService;
import com.zy.asrs.service.BasCrnpService;
import com.zy.asrs.service.LocMastService;
import com.zy.asrs.service.WrkMastService;
import com.zy.asrs.service.impl.MainServiceImpl;
import com.zy.asrs.utils.CommandUtils;
import com.zy.asrs.utils.VersionUtils;
import com.zy.core.CrnThread;
import com.zy.core.cache.MessageQueue;
@@ -39,9 +39,12 @@
import com.zy.core.properties.SystemProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -55,11 +58,6 @@
@RestController
public class CrnController {
    @Value("${wms.url}")
    private String wmsUrl;
    @Value("${wms.movePath}")
    private String movePath;
    @Autowired
    private SlaveProperties slaveProperties;
@@ -70,9 +68,31 @@
    @Autowired
    private BasCrnpService basCrnpService;
    @Autowired
    private MainServiceImpl mainService;
    @Autowired
    private LocMastService locMastService;
    @Resource
    private TaskWrkMapper taskWrkMapper;
    @Resource
    private BasCrnErrorService basCrnErrorService;
    @PostMapping("/importCrnErr")
    @ManagerAuth(memo = "导入堆垛机异常表")
    public R importCrnErr(@RequestParam("file") MultipartFile multipartFile) {
        try {
            importCrnErrExec(multipartFile);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        }
        return R.ok("导入成功");
    }
    @Transactional(rollbackFor = Exception.class)
    public void importCrnErrExec(MultipartFile multipartFile) throws IOException {
        EasyExcel.read(multipartFile.getInputStream(), ImportCrnErrDto.class,
                new ImportCrnErrListener(basCrnErrorService)).sheet().doReadSync();
    }
    @ManagerAuth(memo = "进行中的命令")
@@ -196,13 +216,14 @@
            vo.setWorkNo(crnProtocol.getTaskNo());  //  任务号
            if (crnProtocol.getTaskNo() > 0) {
                WrkMast wrkMast = wrkMastService.selectById(crnProtocol.getTaskNo());
                if (wrkMast != null) {
                    vo.setStatus(CrnStatusType.process(wrkMast.getIoType()).getDesc());   //  模式状态
                    vo.setSourceStaNo(wrkMast.getSourceStaNo$());    //  源站
                    vo.setStaNo(wrkMast.getStaNo$());   //  目标站
                    vo.setSourceLocNo(wrkMast.getSourceLocNo());    //  源库位
                    vo.setLocNo(wrkMast.getLocNo());    //  目标库位
//                WrkMast wrkMast = wrkMastService.selectById(crnProtocol.getTaskNo());
                TaskWrk taskWrk = taskWrkMapper.selectByWrkNo(Integer.valueOf(crnProtocol.getTaskNo()));
                if (taskWrk != null) {
                    vo.setStatus(CrnStatusType.process(taskWrk.getIoType()).getDesc());   //  模式状态
                    vo.setSourceStaNo(taskWrk.getStartPoint());    //  源站
                    vo.setStaNo(taskWrk.getTargetPoint());   //  目标站
                    vo.setSourceLocNo(taskWrk.getStartPoint());    //  源库位
                    vo.setLocNo(taskWrk.getTargetPoint());    //  目标库位
                }
            } else {
                vo.setStatus(crnProtocol.modeType.equals(CrnModeType.AUTO) ? CrnStatusType.MACHINE_AUTO.getDesc() : CrnStatusType.MACHINE_UN_AUTO.getDesc());   //  模式状态
@@ -612,7 +633,7 @@
                crnCommand.setCommand((short) 0);  // 任务完成确认位
                // 延时发送
                Thread.sleep(1000L);
                if (CommandUtils.offer(SlaveType.Crn, crn.getId(), new Task(5, crnCommand), false)) {
                if (MessageQueue.offer(SlaveType.Crn, crn.getId(), new Task(5, crnCommand))) {
                    return R.ok();
                } else {
                    throw new CoolException("命令下发失败");
@@ -771,7 +792,7 @@
                }
                // 空闲判断
//                if (crnProtocol.getStatusType().equals(com.zy.core.enums.CrnStatusType.IDLE) && crnProtocol.getTaskNo() == 0) {
                if (CommandUtils.offer(SlaveType.Crn, crn.getId(), new Task(4, command), false)) {
                if (MessageQueue.offer(SlaveType.Crn, crn.getId(), new Task(4, command))) {
                    return true;
                } else {
                    throw new CoolException("命令下发失败");
@@ -802,7 +823,7 @@
                }
                // 空闲判断
//                if (crnProtocol.getStatusType().equals(com.zy.core.enums.CrnStatusType.IDLE) && crnProtocol.getTaskNo() == 0) {
                if (CommandUtils.offer(SlaveType.Crn, crn.getId(), new Task(2, command), false)) {
                if (MessageQueue.offer(SlaveType.Crn, crn.getId(), new Task(2, command))) {
                    return true;
                } else {
                    throw new CoolException("命令下发失败");