#
zjj
2024-03-15 dbae31a7a7cd59048ada9b51fe8faff545324c59
src/main/java/com/zy/asrs/controller/TaskWrkController.java
@@ -8,14 +8,18 @@
import com.core.common.DateUtils;
import com.zy.asrs.domain.enums.TaskStatusType;
import com.zy.asrs.entity.CommandInfo;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.entity.TaskWrk;
import com.zy.asrs.entity.param.TaskOverToWms;
import com.zy.asrs.service.CommandInfoService;
import com.zy.asrs.service.LocMastService;
import com.zy.asrs.service.TaskWrkService;
import com.core.annotations.ManagerAuth;
import com.core.common.BaseRes;
import com.core.common.Cools;
import com.core.common.R;
import com.zy.asrs.utils.SaasUtils;
import com.zy.asrs.utils.Utils;
import com.zy.common.utils.HttpHandler;
import com.zy.common.web.BaseController;
import lombok.extern.slf4j.Slf4j;
@@ -23,7 +27,11 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
import static com.zy.asrs.entity.param.TaskStatusFeedbackParam.getTaskType;
@RestController
@Slf4j
@@ -37,6 +45,8 @@
    @Autowired
    private CommandInfoService commandInfoService;
    @Autowired
    private LocMastService locMastService;
    @RequestMapping(value = "/taskWrk/{wrkNo}/auth")
    @ManagerAuth
@@ -90,7 +100,7 @@
    @RequestMapping(value = "/taskWrk/updatePoint/auth")
    @ManagerAuth
    public R updatePoint(TaskWrk taskWrk){
    public R updatePoint(TaskWrk taskWrk) throws UnknownHostException {
        if (Cools.isEmpty(taskWrk) || null == taskWrk.getTaskNo()) {
            return R.error();
        }
@@ -98,10 +108,25 @@
        if (taskWrk1 == null) {
            return R.error();
        }
        InetAddress localHost = InetAddress.getLocalHost();
        String ipAddress = localHost.getHostAddress();
        SaasUtils.insertLog(1,taskWrk1.getStartPoint()+"-"+taskWrk1.getTargetPoint(),taskWrk.getStartPoint()+"-"+taskWrk.getTargetPoint(), ipAddress,getUser().getUsername());
        taskWrk1.setStartPoint(taskWrk.getStartPoint());
        taskWrk1.setTargetPoint(taskWrk.getTargetPoint());
        if (taskWrk1.getIoType() == 1){
            taskWrk1.setOriginTargetPoint(Utils.getWmsLocNo(taskWrk.getTargetPoint()));
        } else if (taskWrk1.getIoType() == 2) {
            taskWrk1.setOriginStartPoint(Utils.getWmsLocNo(taskWrk.getStartPoint()));
        } else if (taskWrk1.getIoType() == 3) {
            taskWrk1.setOriginTargetPoint(Utils.getWmsLocNo(taskWrk.getTargetPoint()));
            taskWrk1.setOriginStartPoint(Utils.getWmsLocNo(taskWrk.getStartPoint()));
        }
        taskWrk1.setModiTime(new Date());
        taskWrk1.setModiUser(getUserId());
        taskWrkService.updateById(taskWrk1);
        return R.ok();
    }
@@ -222,6 +247,25 @@
            taskWrkService.updateById(taskWrk);
            if (taskWrk.getIoType() == 1) {
                //更新库位状态
                LocMast locMast = locMastService.selectByLocNo(taskWrk.getTargetPoint());
                locMast.setLocSts("Z");//F.在库
                locMast.setBarcode(taskWrk.getBarcode());//托盘码
                locMast.setModiTime(now);
                locMast.setModiUser(9999L);
                locMastService.updateById(locMast);
            } else if (taskWrk.getIoType() == 2) {
                //更新库位状态
                LocMast locMast = locMastService.selectByLocNo(taskWrk.getStartPoint());
                locMast.setLocSts("K");//O.空库位
                locMast.setBarcode("");//托盘码
                locMast.setModiTime(now);
                locMast.setModiUser(9999L);
                locMastService.updateById(locMast);
            }
            if (taskWrkService.saveToHistory(taskWrk.getTaskNo()) > 0) {
                //任务已经转日志,将该任务下面的指令转日志
                commandInfoService.saveToHistory(taskWrk.getTaskNo());
@@ -246,21 +290,64 @@
        if (taskWrk == null) {
            return R.error();
        }
        if (taskWrk.getStatus().equals(TaskStatusType.CANCEL.id)) {
            return R.error(taskWrk.getTaskNo() + "已被取消");
        String wmsCancelledtask = toWmsCancelledtask(taskWrk);
        JSONObject jsonObject = JSON.parseObject(wmsCancelledtask);
        if (Cools.isEmpty(jsonObject)){
            return R.error("超时或未知错误");
        }
        Date now = new Date();
        taskWrk.setStatus(TaskStatusType.CANCEL.id);
        taskWrk.setModiTime(now);//操作时间
        try{
            taskWrk.setModiUser(getUserId());//操作员
        }catch (Exception e){
            taskWrk.setModiUser(9999L);//操作员
        if (jsonObject.getInteger("code").equals(200)){
            if (!taskWrkService.delete(new EntityWrapper<TaskWrk>().eq("task_no",taskNo))){
                return R.error("删除任务失败");
            }
        }else if (jsonObject.getInteger("code").equals(500)){
            return R.error(jsonObject.get("msg").toString());
        }else {
            return R.error("超时或未知错误");
        }
        taskWrk.setCompleteTime(now);//完结时间
        taskWrkService.updateById(taskWrk);
        return R.ok();
    }
    public String toWmsCancelledtask(TaskWrk taskWrk){
        Map<String, Object> map = new HashMap<>();
        map.put("x-api-key","7a15b5db-29b6-552c-8cff-0cfec3756da2");
        TaskOverToWms taskOverToWms = new TaskOverToWms();
        taskOverToWms.setFeedbackFrom("WCS"); //来源
        taskOverToWms.setWarehouseId("1688469798893297665"); //仓库标识
        taskOverToWms.setTaskNo(taskWrk.getTaskNo()); //任务号
        taskOverToWms.setTaskType(getTaskType(taskWrk.getIoType())); // 任务类型
        taskOverToWms.setContainerCode(taskWrk.getBarcode()); // 容器编码
        if (taskWrk.getIoType() ==1 ){
            taskOverToWms.setEquipmentCode(String.valueOf(taskWrk.getCrnNo())); //设备编码
            taskOverToWms.setTargetLocationCode(taskWrk.getOriginTargetPoint()); //目标库位
        }else if (taskWrk.getIoType() ==2){
            Map<Integer,String> map1 = new HashMap<>();
            map1.put(102,"J-1101");
            map1.put(106,"J-1103");
            map1.put(110,"J-1105");
            map1.put(114,"J-1107");
            map1.put(118,"J-1109");
            map1.put(122,"J-1111");
            taskOverToWms.setEquipmentCode(map1.get(taskWrk.getTargetPoint())); //设备编码
            taskOverToWms.setSourceLocationCode(taskWrk.getOriginStartPoint()); //源库位
        }
        taskOverToWms.setTaskStatus("cancelled"); //任务状态
        String response = null;
        try {
            response = new HttpHandler.Builder()
                    .setHeaders(map)
                    .setUri(wmsUrl)
                    .setPath("wcsManager/wcsInterface/taskStatusFeedback")
                    .setJson(JSON.toJSONString(taskOverToWms))
                    .build()
                    .doPost();
        }catch (Exception e){
            log.error("wms连接失败");
        }
        return response;
    }
    @PostMapping(value = "/taskWrk/updateCommandStep")
    @ManagerAuth(memo = "更新步序")
@@ -276,6 +363,36 @@
        taskWrkService.updateById(taskWrk);
        return R.ok();
    }
    @PostMapping(value = "/taskWrk/upIoPri")
    public R upIoPri(@RequestParam String taskNo){
        TaskWrk taskWrk = taskWrkService.selectByTaskNo(taskNo);
        if (taskWrk.getIoPri() > 300){
            return R.error("优先级已最高");
        }
        Map<Integer,Integer> map = new HashMap<>();
        map.put(100,200);map.put(200,300);map.put(300,400);
        Integer pri = map.get(taskWrk.getIoPri());
        taskWrk.setIoPri(pri);
        if (!taskWrkService.updateById(taskWrk)){
            return R.error("增加优先级失败");
        }
        return R.ok();
    }
    @PostMapping(value = "/taskWrk/downIoPri")
    public R downIoPri(@RequestParam String taskNo){
        TaskWrk taskWrk = taskWrkService.selectByTaskNo(taskNo);
        if (taskWrk.getIoPri() <200){
            return R.error("优先级已最低");
        }
        Map<Integer,Integer> map = new HashMap<>();
        map.put(200,100);map.put(300,200);map.put(400,300);
        Integer pri = map.get(taskWrk.getIoPri());
        taskWrk.setIoPri(pri);
        if (!taskWrkService.updateById(taskWrk)){
            return R.error("降低优先级失败");
        }
        return R.ok();
    }
    public static String getTaskType(Integer paramIoType){
        switch (paramIoType){