自动化立体仓库 - WCS系统
#
Junjie
6 天以前 d65679fefe52fc2bf2435825c65aec3a329e3b9e
#
8个文件已添加
14个文件已修改
1017 ■■■■ 已修改文件
src/main/java/com/zy/asrs/controller/OpenController.java 85 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/controller/TaskWrkController.java 75 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/controller/WorkController.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/domain/dto/NotifyCustomDataDto.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/domain/dto/NotifyDto.java 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/domain/enums/NotifyMsgType.java 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/domain/enums/RedisKeyType.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/entity/param/TaskCreateInParam.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/entity/param/TaskCreateParam.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/OpenService.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/WorkService.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java 207 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/task/NotifyScheduler.java 149 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/task/TaskLogScheduler.java 76 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/utils/NotifyUtils.java 100 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/utils/Utils.java 89 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/common/config/RedisConfig.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/common/utils/RedisUtil.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/MainProcess.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application.yml 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
version/立库 WMS接口文档 2024 0807.docx 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/controller/OpenController.java
@@ -57,6 +57,17 @@
        add("ea1f0459efc02a79f046f982767939ae");
    }};
    private void auth(String appkey, Object obj, HttpServletRequest request) {
        log.info("{}接口被访问;appkey:{};请求数据:{}", request.getServletPath(), appkey, JSON.toJSONString(obj));
        request.setAttribute("cache", obj);
        if (Cools.isEmpty(appkey)) {
            throw new CoolException("认证失败,请确认appkey无误!");
        }
        if (!APP_KEY_LIST.contains(appkey)) {
            throw new CoolException("认证失败,请确认appkey无误!");
        }
    }
    //创建任务
    @PostMapping("/taskCreate")
    @Transactional
@@ -81,26 +92,26 @@
                    return R.error("条码[barcode]不能为空");
                }
                String locNo=null;
                if(param.getIoType()==1){
                    locNo=param.getTargetPoint();
                }else{
                    locNo=param.getStartPoint();
                if (param.getIoType() == 1) {
                    locNo = param.getTargetPoint();
                } else {
                    locNo = param.getStartPoint();
                }
                try{
                try {
                    LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                            .eq("loc_no", locNo).ne("loc_sts","X"));
                    if (Cools.isEmpty(locMast)){
                        log.error("库位号不存在"+locNo);
                        return R.error("库位号不存在"+locNo).add("库位号不存在"+locNo);
                            .eq("loc_no", locNo).ne("loc_sts", "X"));
                    if (Cools.isEmpty(locMast)) {
                        log.error("库位号不存在" + locNo);
                        return R.error("库位号不存在" + locNo).add("库位号不存在" + locNo);
                    }
                }catch (Exception e){
                    log.error("库位号检测程序异常==》异常信息"+e);
                    return R.error("库位号检测程序异常").add("库位号检测程序异常==》异常信息"+e);
                } catch (Exception e) {
                    log.error("库位号检测程序异常==》异常信息" + e);
                    return R.error("库位号检测程序异常").add("库位号检测程序异常==》异常信息" + e);
                }
                LocMast locMast=locMastService.selectOne(new EntityWrapper<LocMast>()
                        .eq("loc_sts","F")
                        .eq("loc_no",locNo)
                        .eq("barcode",param.getBarcode()));
                LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                        .eq("loc_sts", "F")
                        .eq("loc_no", locNo)
                        .eq("barcode", param.getBarcode()));
                if(Cools.isEmpty(locMast)){
                    return R.error("该库位不满足出库条件"+param.getTargetPoint());
                }
@@ -108,12 +119,41 @@
                    locNoList.add(locMast.getLocNo());
                    paramList.add(param);
                }else {
                    return R.error("该库位不能同时下发两笔任务"+locMast.getLocNo());
                    return R.error("该库位不能同时下发两笔任务" + locMast.getLocNo());
                }
            }
            for (TaskCreateParam param : paramList){
                openService.taskCreate(param);
            }
        }catch (Exception e){
            log.error("任务下发异常"+e);
            return R.error();
        }
        return R.ok();
    }
    //创建入库任务
    @PostMapping("/taskCreateIn")
    @Transactional
    public R taskCreateIn(@RequestHeader String appkey,
                        @RequestBody TaskCreateInParam param,
                        HttpServletRequest request) {
        auth(appkey, param, request);
        try{
            if (Cools.isEmpty(param)) {
                return R.parse(BaseRes.PARAM);
            }
            if (Cools.isEmpty(param.getTaskNo())) {
                return R.error("任务号[taskNo]不能为空");
            }
            if (Cools.isEmpty(param.getIoType())) {
                return R.error("任务类型[ioType]不能为空");
            }
            if (Cools.isEmpty(param.getBarcode())) {
                return R.error("条码[barcode]不能为空");
            }
            openService.taskCreateIn(param);
        }catch (Exception e){
            log.error("任务下发异常"+e);
            return R.error();
@@ -147,17 +187,6 @@
        List<CommandInfo> commandInfos = commandInfoService.selectByTaskNo(taskNo);
        return R.ok().add(commandInfos);
    }
    private void auth(String appkey, Object obj, HttpServletRequest request) {
        log.info("{}接口被访问;appkey:{};请求数据:{}", request.getServletPath(), appkey, JSON.toJSONString(obj));
        request.setAttribute("cache", obj);
        if (Cools.isEmpty(appkey)) {
            throw new CoolException("认证失败,请确认appkey无误!");
        }
        if (!APP_KEY_LIST.contains(appkey)) {
            throw new CoolException("认证失败,请确认appkey无误!");
        }
    }
    //任务下发接口
src/main/java/com/zy/asrs/controller/TaskWrkController.java
@@ -6,12 +6,11 @@
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.core.common.DateUtils;
import com.core.exception.CoolException;
import com.zy.asrs.domain.dto.NotifyCustomDataDto;
import com.zy.asrs.domain.enums.NotifyMsgType;
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.ApiLogService;
import com.zy.asrs.service.CommandInfoService;
import com.zy.asrs.service.LocMastService;
@@ -20,6 +19,7 @@
import com.core.common.BaseRes;
import com.core.common.Cools;
import com.core.common.R;
import com.zy.asrs.utils.NotifyUtils;
import com.zy.common.utils.HttpHandler;
import com.zy.common.web.BaseController;
import lombok.extern.slf4j.Slf4j;
@@ -35,21 +35,18 @@
    @Value("${wms.url}")
    private String wmsUrl;
    @Autowired
    private TaskWrkService taskWrkService;
    @Autowired
    private CommandInfoService commandInfoService;
    @Autowired
    private LocMastService locMastService;
    @Value("${wms.TaskExecCallback}")
    private String TaskExecCallback;
    @Autowired
    private ApiLogService apiLogService;
    @Autowired
    private NotifyUtils notifyUtils;
    @RequestMapping(value = "/taskWrk/{wrkNo}/auth")
    @ManagerAuth
@@ -179,9 +176,9 @@
        if (Cools.isEmpty(taskWrk) || taskWrk.getStatus()>=3){
            return R.error("已完结或已取消") ;
        }
        LocMast locMast=new LocMast();
        LocMast locMast = new LocMast();
        if(taskWrk.getIoType()==1){//入库任务完成库位为F
            locMast=locMastService.selectByLocNo(taskWrk.getTargetPoint());
            locMast = locMastService.selectByLocNo(taskWrk.getTargetPoint());
            if(Cools.isEmpty(locMast)){
              R.error("没有找到该库位") ;
            }
@@ -189,14 +186,14 @@
            locMast.setModiTime(new Date());
            locMast.setBarcode(taskWrk.getBarcode());
        }else if(taskWrk.getIoType()==2){//出库任务完成库位为O
            locMast=locMastService.selectByLocNo(taskWrk.getStartPoint());
            locMast = locMastService.selectByLocNo(taskWrk.getStartPoint());
            if(Cools.isEmpty(locMast)){
                R.error("没有找到该库位") ;
            }
            locMast.setLocSts("O");
            locMast.setModiTime(new Date());
        }else if(taskWrk.getIoType()==3){
            locMast=locMastService.selectByLocNo(taskWrk.getStartPoint());
            locMast = locMastService.selectByLocNo(taskWrk.getStartPoint());
            if(Cools.isEmpty(locMast)){
                R.error("没有找到该库位") ;
            }
@@ -212,34 +209,7 @@
            locMast.setBarcode(taskWrk.getBarcode());
        }
        String response="";
        try{
            HashMap<String, Object> headParam = new HashMap<>();
            headParam.put("TaskNo",taskWrk.getTaskNo());
            headParam.put("Result",1);
//            headParam.put("reportTime",new Date());
            log.info("wcs手动完成任务上报wms={}", taskWrk);
            response = new HttpHandler.Builder()
                    // .setHeaders(headParam)
                    .setUri(wmsUrl)
                    .setPath(TaskExecCallback)
                    .setJson(JSON.toJSONString(headParam))
                    .build()
                    .doPost();
            JSONObject jsonObject = JSON.parseObject(response);
            apiLogService.save("wcs手动完成任务上报wms"
                    ,wmsUrl+TaskExecCallback
                    ,null
                    ,"127.0.0.1"
                    ,JSON.toJSONString(headParam)
                    ,response
                    ,true
            );
        }catch (Exception e){
            log.error("wcs手动完成任务上报wms失{},返回值={}", taskWrk,response);
//            throw new CoolException(e);
        }
        locMastService.updateById(locMast);
        taskWrk.setStatus(7);//手动完成任务
        taskWrk.setModiTime(new Date());
@@ -288,34 +258,7 @@
        }catch (Exception e){
            taskWrk.setModiUser(9999L);//操作员
        }
        String response="";
        try{
            HashMap<String, Object> headParam = new HashMap<>();
            headParam.put("TaskNo",taskWrk.getTaskNo());
            headParam.put("Result",0);
//            headParam.put("reportTime",new Date());
            log.info("wcs手动取消任务上报wm={}", taskWrk);
            response = new HttpHandler.Builder()
                    // .setHeaders(headParam)
                    .setUri(wmsUrl)
                    .setPath(TaskExecCallback)
                    .setJson(JSON.toJSONString(headParam))
                    .build()
                    .doPost();
            JSONObject jsonObject = JSON.parseObject(response);
            apiLogService.save("wcs手动取消任务上报wms"
                    ,wmsUrl+TaskExecCallback
                    ,null
                    ,"127.0.0.1"
                    ,JSON.toJSONString(headParam)
                    ,response
                    ,true
            );
        }catch (Exception e){
            log.error("wcs手动取消任务上报wms失败={},返回值={}", taskWrk,response);
//            throw new CoolException(e);
        }
        taskWrk.setCompleteTime(now);//完结时间
        taskWrkService.updateById(taskWrk);
        return R.ok();
src/main/java/com/zy/asrs/controller/WorkController.java
@@ -1,12 +1,8 @@
package com.zy.asrs.controller;
import com.core.annotations.ManagerAuth;
import com.core.common.R;
import com.zy.asrs.service.WorkService;
import com.zy.common.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@@ -19,19 +15,5 @@
    @Autowired
    private WorkService workService;
    @RequestMapping("/hand/control/wrkMast")
    @ManagerAuth(memo = "手动处理工作档")
    public R handControlWrkMast(@RequestParam String workNo,
                                @RequestParam Integer type){
        if (type == 1) {
            workService.completeWrkMast(workNo, getUserId());
            return R.ok("任务已完成");
        } else if (type == 2) {
            workService.cancelWrkMast(workNo, getUserId());
            return R.ok("任务已取消");
        }
        return R.ok();
    }
}
src/main/java/com/zy/asrs/domain/dto/NotifyCustomDataDto.java
New file
@@ -0,0 +1,14 @@
package com.zy.asrs.domain.dto;
import lombok.Data;
@Data
public class NotifyCustomDataDto {
    private String uri;
    private String path;
    private String data;
}
src/main/java/com/zy/asrs/domain/dto/NotifyDto.java
New file
@@ -0,0 +1,49 @@
package com.zy.asrs.domain.dto;
import lombok.Data;
@Data
public class NotifyDto {
    private Long id;
    //通知类型
    private String notifyType;
    //设备号
    private Integer device;
    //工作号
    private String taskNo;
    //上级系统工作号
    private String superTaskNo;
    //消息类型
    private String msgType;
    //消息描述
    private String msgDesc;
    //消息数据
    private String data;
    //发送自定义消息数据,默认标准格式
    private Boolean sendCustomData = false;
    //自定义消息数据格式
    private NotifyCustomDataDto customData;
    //失败重试次数
    private Integer failTimes = 3;
    //重试次数
    private Integer retryTimes = 0;
    //重试间隔默认30s
    private Integer retryTime = 30;
    //上次重试时间
    private Long lastRetryTime = 0L;
}
src/main/java/com/zy/asrs/domain/enums/NotifyMsgType.java
New file
@@ -0,0 +1,40 @@
package com.zy.asrs.domain.enums;
public enum NotifyMsgType {
    //任务
    TASK_COMPLETE("task_complete", "任务完成"),
    TASK_CANCEL("task_cancel", "任务取消"),
    ;
    public String flag;
    public String desc;
    NotifyMsgType(String flag, String desc) {
        this.flag = flag;
        this.desc = desc;
    }
    public static NotifyMsgType get(String flag) {
        if (null == flag) {
            return null;
        }
        for (NotifyMsgType type : NotifyMsgType.values()) {
            if (type.flag.equals(flag)) {
                return type;
            }
        }
        return null;
    }
    public static NotifyMsgType get(NotifyMsgType type) {
        if (null == type) {
            return null;
        }
        for (NotifyMsgType type2 : NotifyMsgType.values()) {
            if (type2 == type) {
                return type2;
            }
        }
        return null;
    }
}
src/main/java/com/zy/asrs/domain/enums/RedisKeyType.java
New file
@@ -0,0 +1,13 @@
package com.zy.asrs.domain.enums;
public enum RedisKeyType {
    QUEUE_TASK("queue_task_"),
    ;
    public String key;
    RedisKeyType(String key) {
        this.key = key;
    }
}
src/main/java/com/zy/asrs/entity/param/TaskCreateInParam.java
New file
@@ -0,0 +1,32 @@
package com.zy.asrs.entity.param;
import lombok.Data;
@Data
public class TaskCreateInParam {
    //任务号
    private String taskNo;
    //任务类型
    private Integer ioType;
    //优先级
    private Integer taskPriority;
    //终点
    private String targetPoint;
    //是否空托盘 Y:是 N:否
    private String emptyContainer;
    //条码
    private String barcode;
    //备注
    private String memo;
    //堆垛机
    private Integer crn;
}
src/main/java/com/zy/asrs/entity/param/TaskCreateParam.java
@@ -1,6 +1,5 @@
package com.zy.asrs.entity.param;
import io.swagger.models.auth.In;
import lombok.Data;
@Data
src/main/java/com/zy/asrs/service/OpenService.java
@@ -1,5 +1,6 @@
package com.zy.asrs.service;
import com.zy.asrs.entity.param.TaskCreateInParam;
import com.zy.asrs.entity.param.TaskCreateParam;
import java.util.HashMap;
@@ -8,4 +9,6 @@
    //创建任务
    HashMap<String,Object> taskCreate(TaskCreateParam param);
    HashMap<String,Object> taskCreateIn(TaskCreateInParam param);
}
src/main/java/com/zy/asrs/service/WorkService.java
@@ -2,14 +2,4 @@
public interface WorkService {
    /**
     * æ‰‹åŠ¨å®Œæˆå·¥ä½œæ¡£
     */
    void completeWrkMast(String workNo, Long userId);
    /**
     * æ‰‹åŠ¨å–æ¶ˆå·¥ä½œæ¡£
     */
    void cancelWrkMast(String workNo, Long userId);
}
src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java
@@ -5,6 +5,7 @@
import com.zy.asrs.domain.enums.TaskStatusType;
import com.zy.asrs.domain.enums.WorkNoType;
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.param.TaskCreateInParam;
import com.zy.asrs.entity.param.TaskCreateParam;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.Utils;
@@ -56,7 +57,7 @@
        if (param.getIoType() == 1) {
            taskWrk.setWrkSts(1);
            if (!Cools.isEmpty(param.getTargetPoint())) {
                taskWrk.setTargetPoint(Utils.getWcsLocNo(param.getTargetPoint()));//终点
                taskWrk.setTargetPoint(param.getTargetPoint());//终点
                taskWrk.setOriginTargetPoint(param.getTargetPoint());
            }
@@ -90,4 +91,42 @@
        return map;
    }
    @Override
    public HashMap<String, Object> taskCreateIn(TaskCreateInParam param) {
        HashMap<String, Object> map = new HashMap<>();
        TaskWrk taskWrk = taskWrkService.selectByTaskNo(param.getTaskNo());
        if (taskWrk != null) {
            map.put("Code","0");
            map.put("Msg", param.getTaskNo() + "任务已经生成!");
            return map;
        }
        Date now = new Date();
        taskWrk = new TaskWrk();
        LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", param.getTargetPoint()));
        int workNo1 = commonService.getWorkNo(WorkNoType.PAKIN.type);//获取入库工作号
        taskWrk.setTaskNo(param.getTaskNo());//任务号
        taskWrk.setWrkNo(workNo1);
        taskWrk.setStatus(TaskStatusType.RECEIVE.id);//任务状态:接收
        taskWrk.setCreateTime(now);
        taskWrk.setIoType(param.getIoType());//任务类型
        taskWrk.setIoPri(param.getTaskPriority());//优先级
        taskWrk.setBarcode(param.getBarcode());//条码
        taskWrk.setCrnNo(locMast.getCrnNo());
        taskWrk.setWrkSts(1);
        taskWrk.setTargetPoint(param.getTargetPoint());//终点
        taskWrk.setOriginTargetPoint(param.getTargetPoint());
        if (!Cools.isEmpty(param.getMemo())) {
            taskWrk.setMemo(param.getMemo());//备注
        }
        if (!taskWrkService.insert(taskWrk)) {
            map.put("Code", "0");
            map.put("Msg", param.getTaskNo() + "创建任务失败!");
            return map;
        }
        map.put("Code","1");
        map.put("Msg","ok");
        return map;
    }
}
src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java
@@ -1,211 +1,12 @@
package com.zy.asrs.service.impl;
import com.alibaba.fastjson.JSON;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.exception.CoolException;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.service.*;
import com.zy.common.utils.HttpHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
import com.zy.asrs.service.WorkService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class WorkServiceImpl implements WorkService {
    @Autowired
    private WrkMastService wrkMastService;
    @Autowired
    private LocMastService locMastService;
    @Autowired
    private WaitPakinService waitPakinService;
    @Autowired
    private WrkMastLogService wrkMastLogService;
    @Autowired
    private WrkDetlLogService wrkDetlLogService;
    @Autowired
    private WrkDetlService wrkDetlService;
    @Autowired
    private ApiLogService apiLogService;
    @Value("${wms.url}")
    private String wmsUrl;
    @Value("${wms.inboundTaskApplyPath}")
    private String inboundTaskApplyPath;
    @Value("${wms.movePath}")
    private String movePath;
    @Value("${wms.taskStatusFeedbackPath}")
    private String taskStatusFeedbackPath;
    @Override
    @Transactional
    public void completeWrkMast(String workNo, Long userId) {
        WrkMast wrkMast = wrkMastService.selectById(workNo);
        if (Cools.isEmpty(wrkMast)) {
            throw new CoolException(workNo + "工作档不存在");
        }
        if (wrkMast.getWrkSts() == 4 || wrkMast.getWrkSts() == 14) {
            throw new CoolException("当前工作档已完成");
        }
        // å…¥åº“ + åº“位转移
        if (wrkMast.getWrkSts() < 4 || (wrkMast.getWrkSts() > 10 && wrkMast.getIoType() == 11)) {
            wrkMast.setWrkSts(4L);
            // å‡ºåº“
        } else if (wrkMast.getWrkSts() > 10) {
            wrkMast.setWrkSts(14L);
        }
        Date now = new Date();
        wrkMast.setCrnStrTime(DateUtils.calculate(now, 1L, TimeUnit.SECONDS, true));
        wrkMast.setCrnEndTime(now);
        wrkMast.setModiTime(now);
        wrkMast.setModiUser(userId);
        // å®Œæˆæ“ä½œäººå‘˜è®°å½•
        wrkMast.setManuType("手动完成");
        if (!wrkMastService.updateById(wrkMast)) {
            throw new CoolException("修改工作档失败");
        }
        HashMap<String,Object> headParam = new HashMap<>();
        headParam.put("TaskNo",wrkMast.getTaskNo());
        headParam.put("Result",0);//完成
        try {
            String response;
            log.error("wcs手动完结任务上报wms={}", wrkMast);
            response = new HttpHandler.Builder()
                    // .setHeaders(headParam)
                    .setUri(wmsUrl)
                    .setPath(taskStatusFeedbackPath)
                    .setJson(JSON.toJSONString(headParam))
                    .build()
                    .doPost();
            apiLogService.save("wcs手动完成任务上报wms"
                    , wmsUrl + taskStatusFeedbackPath
                    , null
                    , "127.0.0.1"
                    , JSON.toJSONString(headParam)
                    , response
                    , true
            );
        } catch (Exception e) {
            log.error("wcs手动完结任务上报wms失败={}", wrkMast);
            log.error("wcs手动完结任务上报wms失败,报错信息:", e);
//                        throw new CoolException("wcs派发入库任务上报wms失败");
        }
    }
    @Override
    @Transactional
    public void cancelWrkMast(String workNo, Long userId) {
        Date now = new Date();
        WrkMast wrkMast = wrkMastService.selectById(workNo);
        String locNo = ""; // å¾…修改目标库位
        String locSts = ""; // å¾…修改目标库位状态
        // å…¥åº“取消(修改目标库位)
        if (wrkMast.getWrkSts() < 4) {
            locNo = wrkMast.getLocNo();
            locSts = "O";
            // åº“位转移
            if (wrkMast.getIoType() == 11) {
                // åº“位转移:源库位
                LocMast locMast = locMastService.selectById(wrkMast.getSourceLocNo());
                if (Cools.isEmpty(locMast)) {
                    throw new CoolException("取消库位转移失败,源库位不存在:" + wrkMast.getSourceLocNo());
                }
                locMast.setLocSts(wrkMast.getFullPlt().equalsIgnoreCase("N") ? "D" : "F");
                locMast.setModiTime(now);
                locMast.setModiUser(userId);
                locMastService.updateById(locMast);
            }
            // å‡ºåº“取消(修改源库位)
        } else if (wrkMast.getWrkSts() > 10 && wrkMast.getWrkSts() != 14) {
            locNo = wrkMast.getSourceLocNo();
            // å‡ºåº“ ===>> F.在库
            if (wrkMast.getIoType() > 100 && wrkMast.getIoType() != 110) {
                locSts = "F";
                // ç©ºæ¿å‡ºåº“ ===>> D.空桶/空栈板
            } else if (wrkMast.getIoType() == 110) {
                locSts = "D";
                // åº“位转移 ===>> D.空桶/空栈板
            } else if (wrkMast.getIoType() == 11) {
                locSts = wrkMast.getFullPlt().equalsIgnoreCase("N") ? "D" : "F";
                // åº“位转移:目标库位
                LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
                if (Cools.isEmpty(locMast)) {
                    throw new CoolException("取消库位转移失败,目标库位不存在:" + wrkMast.getSourceLocNo());
                }
                locMast.setLocSts("O");
                locMast.setModiTime(now);
                locMast.setModiUser(userId);
                locMastService.updateById(locMast);
            }
        } else {
            throw new CoolException("当前工作状态无法取消");
        }
        // å–消操作人员记录
        wrkMast.setManuType("手动取消");
        wrkMast.setModiUser(userId);
        wrkMast.setModiTime(now);
        if (!wrkMastService.updateById(wrkMast)) {
            throw new CoolException("取消任务失败");
        }
        // ä¿å­˜å·¥ä½œä¸»æ¡£åŽ†å²æ¡£
        if (!wrkMastLogService.save(wrkMast.getWrkNo())) {
            throw new CoolException("保存任务历史档失败, workNo = " + wrkMast.getWrkNo());
        }
        // åˆ é™¤å·¥ä½œä¸»æ¡£
        boolean wrkMastRes = wrkMastService.deleteById(wrkMast);
        // ä¿®æ”¹åº“位状态
        LocMast locMast = locMastService.selectById(locNo);
        if (Cools.isEmpty(locMast)) {
            throw new CoolException("取消任务失败,库位不存在:" + locNo);
        }
        locMast.setLocSts(locSts);
        locMast.setModiTime(now);
        locMast.setModiUser(userId);
        boolean locMastRes = locMastService.updateById(locMast);
        if (!wrkMastRes || !locMastRes) {
            throw new CoolException("保存数据失败");
        }
        HashMap<String,Object> headParam = new HashMap<>();
        headParam.put("TaskNo",wrkMast.getTaskNo());
        headParam.put("Result",1);//取消
        try {
            String response;
            log.error("wcs手动取消任务上报wms={}", wrkMast);
            response = new HttpHandler.Builder()
                    // .setHeaders(headParam)
                    .setUri(wmsUrl)
                    .setPath(taskStatusFeedbackPath)
                    .setJson(JSON.toJSONString(headParam))
                    .build()
                    .doPost();
            apiLogService.save("wcs手动取消任务上报wms"
                    , wmsUrl + taskStatusFeedbackPath
                    , null
                    , "127.0.0.1"
                    , JSON.toJSONString(headParam)
                    , response
                    , true
            );
        } catch (Exception e) {
            log.error("wcs手动取消任务上报wms失败={}", wrkMast);
            log.error("wcs手动取消任务上报wms失败,报错信息:", e);
//                        throw new CoolException("wcs派发入库任务上报wms失败");
        }
    }
}
src/main/java/com/zy/asrs/task/NotifyScheduler.java
New file
@@ -0,0 +1,149 @@
package com.zy.asrs.task;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zy.asrs.domain.dto.NotifyCustomDataDto;
import com.zy.asrs.domain.dto.NotifyDto;
import com.zy.asrs.entity.ApiLog;
import com.zy.asrs.service.ApiLogService;
import com.zy.asrs.utils.NotifyUtils;
import com.zy.common.utils.HttpHandler;
import com.zy.common.utils.RedisUtil;
import com.zy.core.properties.SlaveProperties;
import com.zy.system.entity.Config;
import com.zy.system.service.ConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
@Component
@Slf4j
public class NotifyScheduler {
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private NotifyUtils notifyUtils;
    @Autowired
    private SlaveProperties slaveProperties;
    @Autowired
    private ConfigService configService;
    @Autowired
    private ApiLogService apiLogService;
    @Scheduled(cron = "0/3 * * * * ? ")
    public synchronized void notifyTask(){
        notifyMsg("task", 1);
    }
    private synchronized void notifyMsg(String notifyType, Integer device) {
        Config notifyEnableConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "notifyEnable"));
        if(notifyEnableConfig == null){
            return;
        }
        String notifyEnable = notifyEnableConfig.getValue();
        if (!notifyEnable.equals("Y")) {
            return;
        }
        Config notifyUriConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "notifyUri"));
        if(notifyUriConfig == null){
            return;
        }
        String notifyUri = notifyUriConfig.getValue();
        Config notifyUriPathConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "notifyUriPath"));
        if(notifyUriPathConfig == null){
            return;
        }
        String notifyUriPath = notifyUriPathConfig.getValue();
        List<String> keys = notifyUtils.takeKeys(notifyType, device);
        if(keys == null){
            return;
        }
        if (keys.isEmpty()) {
            return;
        }
        for (String key : keys) {
            Object object = redisUtil.get(key);
            if (object == null) {
                continue;
            }
            NotifyDto notifyDto = (NotifyDto) object;
            if (System.currentTimeMillis() - notifyDto.getLastRetryTime() < 1000 * notifyDto.getRetryTime()) {
                continue;
            }
            ApiLog apiLog = new ApiLog();
            try {
                //触发通知
                String response = null;
                if (notifyDto.getSendCustomData()) {
                    //自定义消息格式
                    NotifyCustomDataDto customData = notifyDto.getCustomData();
                    response = new HttpHandler.Builder()
                            .setUri(customData.getUri())
                            .setPath(customData.getPath())
                            .setJson(customData.getData())
                            .build()
                            .doPost();
                    apiLog.setUrl(customData.getUri() + customData.getPath());
                    apiLog.setRequest(customData.getData());
                    apiLog.setCreateTime(new Date());
                }else {
                    response = new HttpHandler.Builder()
                            .setUri(notifyUri)
                            .setPath(notifyUriPath)
                            .setJson(JSON.toJSONString(notifyDto))
                            .build()
                            .doPost();
                    apiLog.setUrl(notifyUri + notifyUriPath);
                    apiLog.setRequest(JSON.toJSONString(notifyDto));
                    apiLog.setCreateTime(new Date());
                }
                apiLog.setResponse(response);
                JSONObject jsonObject = JSON.parseObject(response);
                Integer code = jsonObject.getInteger("code");
                if(code == 200){
                    //通知成功
                    redisUtil.del(key);
                    continue;
                }
            }catch (Exception e){
                e.printStackTrace();
            }finally {
                //保存记录
                apiLogService.insert(apiLog);
            }
            //通知失败
            int times = notifyDto.getRetryTimes() + 1;
            if (times >= notifyDto.getFailTimes()) {
                //超过次数
                redisUtil.del(key);
                continue;
            }
            notifyDto.setLastRetryTime(System.currentTimeMillis());
            notifyDto.setRetryTimes(times);
            redisUtil.set(key, notifyDto);
            continue;
        }
    }
}
src/main/java/com/zy/asrs/task/TaskLogScheduler.java
@@ -1,17 +1,14 @@
package com.zy.asrs.task;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.exception.CoolException;
import com.zy.asrs.domain.dto.NotifyCustomDataDto;
import com.zy.asrs.domain.enums.NotifyMsgType;
import com.zy.asrs.domain.enums.TaskStatusType;
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.param.TaskOverToWms;
import com.zy.asrs.entity.param.TaskStatusFeedbackParam;
import com.zy.asrs.service.*;
import com.zy.asrs.service.impl.TaskWrkLogServiceImpl;
import com.zy.asrs.utils.PostMesDataUtils;
import com.zy.common.utils.HttpHandler;
import com.zy.asrs.utils.NotifyUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -19,10 +16,7 @@
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * å®šæ—¶å°†ä»»åŠ¡(完成、取消)转成日志
@@ -33,17 +27,6 @@
    @Autowired
    private TaskWrkService taskWrkService;
    @Autowired
    private CommandInfoService commandInfoService;
    @Autowired
    private ApiLogService apiLogService;
    @Autowired
    private BasDevpService basDevpService;
    @Autowired
    private StaDescService staDescService;
    @Autowired
    private LocMastService locMastService;
    @Autowired
    private TaskWrkLogServiceImpl wrkLogService;
@@ -57,49 +40,32 @@
    private String TaskExecCallback;
    @Value("${wms.taskStatusFeedbackPath}")
    private String taskStatusFeedbackPath;
    @Autowired
    private NotifyUtils notifyUtils;
    @Scheduled(cron = "0/3 * * * * ? ")
    public void execute() throws IOException {
        for (TaskWrk taskWrk : taskWrkService.selectToBeHistoryData()) {
            HashMap<String, Object> headParam = new HashMap<>();
            headParam.put("TaskNo", taskWrk.getTaskNo());
            if (taskWrk.getStatus().equals(TaskStatusType.OVER.id) || taskWrk.getStatus() == 7) {//完成
                headParam.put("Result", 1);
                headParam.put("Result", 1);//完成
            } else if (taskWrk.getStatus().equals(TaskStatusType.CANCEL.id)) {
                headParam.put("Result", 2);
                headParam.put("Result", 2);//取消
            }
            String response = "";
            Boolean bool = false;
            try {
                headParam.put("TaskNo", taskWrk.getTaskNo());
                log.info("wcs手动完成任务上报wms={}", taskWrk);
                response = new HttpHandler.Builder()
                        // .setHeaders(headParam)
                        .setUri(wmsUrl)
                        .setPath(TaskExecCallback)
                        .setJson(JSON.toJSONString(headParam))
                        .build()
                        .doPost();
                JSONObject jsonObject = JSON.parseObject(response);
                TaskWrkLog taskWrkLog = new TaskWrkLog(taskWrk);
                if (!wrkLogService.insert(taskWrkLog)) {
                    throw new CoolException("转历史档失败" + taskWrkLog);
                }
                if (!taskWrkService.deleteById(taskWrk)) {
                    throw new CoolException("任务档删除失败" + taskWrkLog);
                }
                bool = true;
            } catch (Exception e) {
                log.error("wcs手动完成任务上报wms失败{},返回值={}", taskWrk, response);
            } finally {
                apiLogService.save("wcs完成或者取消任务上报wms"
                        , wmsUrl + TaskExecCallback
                        , null
                        , "127.0.0.1"
                        , JSON.toJSONString(headParam)
                        , response
                        , bool
                );
            NotifyCustomDataDto customDataDto = new NotifyCustomDataDto();
            customDataDto.setUri(wmsUrl);
            customDataDto.setPath(TaskExecCallback);
            customDataDto.setData(JSON.toJSONString(headParam));
            notifyUtils.notify("task", 1, String.valueOf(taskWrk.getWrkNo()), taskWrk.getTaskNo(), NotifyMsgType.TASK_COMPLETE, JSON.toJSONString(taskWrk), true, customDataDto);
            TaskWrkLog taskWrkLog = new TaskWrkLog(taskWrk);
            if (!wrkLogService.insert(taskWrkLog)) {
                throw new CoolException("转历史档失败" + taskWrkLog);
            }
            if (!taskWrkService.deleteById(taskWrk)) {
                throw new CoolException("任务档删除失败" + taskWrkLog);
            }
        }
    }
src/main/java/com/zy/asrs/utils/NotifyUtils.java
New file
@@ -0,0 +1,100 @@
package com.zy.asrs.utils;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.SnowflakeIdWorker;
import com.zy.asrs.domain.dto.NotifyCustomDataDto;
import com.zy.asrs.domain.dto.NotifyDto;
import com.zy.asrs.domain.enums.NotifyMsgType;
import com.zy.asrs.domain.enums.RedisKeyType;
import com.zy.common.utils.RedisUtil;
import com.zy.system.entity.Config;
import com.zy.system.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@Component
public class NotifyUtils {
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private SnowflakeIdWorker snowflakeIdWorker;
    @Autowired
    private ConfigService configService;
    public synchronized boolean notify(String notifyType, Integer device, String taskNo, String superTaskNo, NotifyMsgType msgType) {
        return append(notifyType, device, taskNo, superTaskNo, msgType, null, false, null);
    }
    public synchronized boolean notify(String notifyType, Integer device, String taskNo, String superTaskNo, NotifyMsgType msgType, String data, Boolean sendCustomData, NotifyCustomDataDto customData) {
        return append(notifyType, device, taskNo, superTaskNo, msgType, data, sendCustomData, customData);
    }
    public synchronized List<String> takeKeys(String notifyType, Integer device) {
        String key = getKey(notifyType, device);
        if(key == null){
            return null;
        }
        Set keys = redisUtil.keys(key + "*");
        if (keys == null) {
            return null;
        }
        List<String> list = new ArrayList<>();
        for (Object object : keys) {
            list.add(object.toString());
        }
        return list;
    }
    public String getKey(String notifyType, Integer device) {
        String key = null;
        if (notifyType.equals("task")) {
            key = RedisKeyType.QUEUE_TASK.key + device;
        } else {
            return null;
        }
        return key;
    }
    private boolean append(String notifyType, Integer device, String taskNo, String superTaskNo, NotifyMsgType msgType, String data, Boolean sendCustomData, NotifyCustomDataDto customData) {
        String key = getKey(notifyType, device);
        if (key == null) {
            return false;
        }
        NotifyDto dto = new NotifyDto();
        dto.setId(snowflakeIdWorker.nextId());
        dto.setNotifyType(notifyType);
        dto.setDevice(device);
        dto.setMsgType(msgType.flag);
        dto.setMsgDesc(msgType.desc);
        dto.setData(data);
        dto.setTaskNo(taskNo);
        dto.setSuperTaskNo(superTaskNo);
        dto.setSendCustomData(sendCustomData);
        dto.setCustomData(customData);
        //重试次数
        Config notifyFailTimesConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "notifyFailTimes"));
        if (notifyFailTimesConfig != null) {
            dto.setFailTimes(Integer.parseInt(notifyFailTimesConfig.getValue()));
        }
        //重试间隔
        Config notifyRetryTimeConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "notifyRetryTime"));
        if (notifyRetryTimeConfig != null) {
            dto.setRetryTime(Integer.parseInt(notifyRetryTimeConfig.getValue()));
        }
        redisUtil.set(key + "_" + dto.getId(), dto);
        return true;
    }
}
src/main/java/com/zy/asrs/utils/Utils.java
@@ -59,93 +59,6 @@
        return crnNo == 1 ? s : 3 - s;
    }
    //转换wms传输的库位号
    public static String getWcsLocNo(String locNo){
        String[] split = locNo.split("-");
        int[] wcsRow = getWcsRow(split[0]);
        int[] ints = null;
        if (split[3].equals("01")){
            ints = Arrays.copyOfRange(wcsRow, 0, (wcsRow.length+2-1) / 2);
            if (split[4].equals("01")){
                if (ints.length<2){
                }else {
                    ints = Arrays.copyOfRange(ints, ints.length / 2, ints.length);
                }
            }else {
                if (ints.length<2){
                }else {
                    ints = Arrays.copyOfRange(ints, ints.length / 2-1,ints.length-1);
                }
            }
        }else {
            ints = Arrays.copyOfRange(wcsRow, (wcsRow.length+2-1) / 2,wcsRow.length );
            if (split[4].equals("01")){
                if (ints.length<2){
                }else {
                    ints = Arrays.copyOfRange(ints, ints.length / 2-1,ints.length-1);
                }
            }else {
                if (ints.length<2){
                }else {
                    ints = Arrays.copyOfRange(ints, ints.length / 2, ints.length);
                }
            }
        }
        int i = ints[0];
        String wcsLocNo = "";
        Integer bay = Integer.parseInt(split[1])+1;
        String bay2 = "";
        if (bay>9){
            bay2 = bay.toString();
        }else {
            bay2 = "0"+bay;
        }
        if (i>9){
            wcsLocNo = i+"0"+bay2+split[2];
        }else {
            wcsLocNo = "0"+i+"0"+bay2+split[2];
        }
        return wcsLocNo;
    }
    public static int[] getWcsRow(String row){
        int[] array = null;
        switch (row){
            case "01":
                 array= new int[]{1, 2, 3, 4};
                break;
            case "02":
                 array= new int[]{5,6};
                break;
            case "03":
                 array= new int[]{7,8,9,10};
                break;
            case "04":
                 array= new int[]{11,12,13,14};
                break;
            case "05":
                 array= new int[]{15,16,17,18};
                break;
            case "06":
                 array= new int[]{19,20,21};
                break;
            default:
        }
        return array;
    }
    public static float scale(Float f){
        if (f == null || f == 0f || Float.isNaN(f)) {
            return 0f;
@@ -382,8 +295,6 @@
//        slaveProperties.setGroupCount(4);
//        Integer deepRow = getDeepRow(slaveProperties, 6);
//        System.out.println(deepRow);
        String wcsLocNo = getWcsLocNo("01-01-01-01-01");
        System.out.println(wcsLocNo);
    }
    public static Integer StaNoCrnNo(Integer staNo) {
src/main/java/com/zy/common/config/RedisConfig.java
@@ -5,6 +5,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.*;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
@@ -14,7 +15,7 @@
 * Redis配置类
 * Created by vincent on 2019-12-23
 */
//@Configuration
@Configuration
//@EnableCaching // å¼€å¯æ•°æ®ç¼“存机制
public class RedisConfig extends CachingConfigurerSupport {
src/main/java/com/zy/common/utils/RedisUtil.java
@@ -2,7 +2,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
src/main/java/com/zy/core/MainProcess.java
@@ -26,9 +26,6 @@
    // é¢‘率
    private int i = 0;
    @Value("${wms.maxCirle}")
    private Integer maxCount;
    /**
     * =====>>  å¼€å§‹å·¥ä½œ
     */
src/main/resources/application.yml
@@ -8,7 +8,7 @@
    name: @pom.build.finalName@
  datasource:
    driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
    url: jdbc:sqlserver://192.168.4.42:1433;databasename=czbrasrs
    url: jdbc:sqlserver://192.168.4.42:1433;databasename=ynhfasrs
    username: sa
    password: sa@123
  mvc:
@@ -46,18 +46,12 @@
wms:
  #输送线暂存数
  count: 8
  maxCirle: 3
  # æ˜¯å¦å¼€å¯ä¸ŠæŠ¥
  start: true
  # WMS系统ip
  #url: 10.32.53.195:8080
  # WMS系统ip
  #  url: 10.210.157.109:8090
  url: 10.10.10.222:2410
  # å…¥åº“任务申请接口
  #inboundTaskApplyPath: api/InterFace/inboundTaskApply
  inboundTaskApplyPath: api/StereoscopicCallBack/AcceptTaskStatus
  #  inboundTaskApplyPath: open/asrs/inboundTaskApply
  # ä»»åŠ¡å¼€å§‹æ—¶ï¼ŒWCS回调WMS
  taskStatusFeedbackPath: api/StereoscopicCallBack/TaskExecCallback
  # ä»»åŠ¡å®Œæˆç»“æŸæ—¶ï¼ŒWCS回调WMS
version/Á¢¿â WMS½Ó¿ÚÎĵµ 2024 0807.docx
Binary files differ