#
zjj
3 天以前 c904f735e0b8a488ef56744c08f8e10258639bce
src/main/java/com/zy/asrs/task/TaskLogScheduler.java
@@ -3,13 +3,12 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.SpringUtils;
import com.zy.asrs.domain.enums.TaskStatusType;
import com.zy.asrs.entity.CommandInfo;
import com.zy.asrs.entity.TaskWrk;
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.param.TaskOverToWms;
import com.zy.asrs.entity.param.TaskStatusFeedbackParam;
import com.zy.asrs.service.CommandInfoService;
import com.zy.asrs.service.TaskWrkService;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.PostMesDataUtils;
import com.zy.common.utils.HttpHandler;
import lombok.extern.slf4j.Slf4j;
@@ -19,9 +18,11 @@
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;
import java.util.concurrent.TimeUnit;
/**
 * 定时将任务(完成、取消)转成日志
@@ -34,6 +35,15 @@
    private TaskWrkService taskWrkService;
    @Autowired
    private CommandInfoService commandInfoService;
    @Autowired
    private ApiLogService apiLogService;
    @Autowired
    private BasDevpService basDevpService;
    @Autowired
    private StaDescService staDescService;
    @Autowired
    private LocMastService locMastService;
    @Value("${wms.url}")
    private String wmsUrl;
@@ -44,7 +54,7 @@
    public void execute() throws IOException {
        for (TaskWrk taskWrk : taskWrkService.selectToBeHistoryData()) {
            TaskStatusFeedbackParam taskStatusFeedbackParam = new TaskStatusFeedbackParam(taskWrk);
            if (taskWrk.getStatus().equals(TaskStatusType.COMPLETE.id)) {//完成
            if (taskWrk.getStatus().equals(TaskStatusType.OVER.id)) {//完成
                taskStatusFeedbackParam.setTaskStatus("done");
                Map<String, Object> map = new HashMap<>();
                map.put("x-api-key","7a15b5db-29b6-552c-8cff-0cfec3756da2");
@@ -54,19 +64,38 @@
                taskOverToWms.setTaskNo(taskWrk.getTaskNo()); //任务号
                taskOverToWms.setTaskType(taskStatusFeedbackParam.getTaskType()); // 任务类型
                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())); //设备编码
                    StaDesc staDesc = staDescService.queryCrn(2, Integer.valueOf(taskWrk.getTargetPoint()), taskWrk.getCrnNo());
                    taskOverToWms.setEquipmentCode(staDesc.getStnDesc()); //设备编码
                    taskOverToWms.setSourceLocationCode(taskWrk.getOriginStartPoint()); //源库位
                    //判断托盘是否走到出库站
                    BasDevp basDevp = basDevpService.selectOne(new EntityWrapper<BasDevp>().eq("dev_no", taskWrk.getTargetPoint()));
                    if (!basDevp.getWrkNo().equals(taskWrk.getWrkNo()) || !basDevp.getOutEnable().equals("Y")){
                        continue;
                    }
                } else if (taskWrk.getIoType() ==3) {
                    taskOverToWms.setEquipmentCode(String.valueOf(taskWrk.getCrnNo())); //设备编码
                    taskOverToWms.setTargetLocationCode(taskWrk.getOriginTargetPoint()); //目标库位
                    Date now = new Date();
//                    //更新库位状态
//                    LocMast locMast = locMastService.selectByLocNo(taskWrk.getStartPoint());
//                    locMast.setLocSts("K");//O.空库位
//                    locMast.setBarcode("");//托盘码
//                    locMast.setModiTime(now);
//                    locMast.setModiUser(9999L);
//                    locMastService.updateById(locMast);
//
//                    //更新库位状态
//                    LocMast locMast2 = locMastService.selectByLocNo(taskWrk.getTargetPoint());
//                    locMast2.setLocSts("Z");//F.在库
//                    locMast2.setBarcode(taskWrk.getBarcode());//托盘码
//                    locMast2.setModiTime(now);
//                    locMast2.setModiUser(9999L);
//                    locMastService.updateById(locMast2);
                }
                taskOverToWms.setTaskStatus("done"); //任务状态
@@ -77,6 +106,7 @@
                            .setUri(wmsUrl)
                            .setPath("wcsManager/wcsInterface/taskStatusFeedback")
                            .setJson(JSON.toJSONString(taskOverToWms))
                            .setTimeout(60, TimeUnit.SECONDS)
                            .build()
                            .doPost();
                }catch (Exception e){
@@ -86,7 +116,14 @@
                JSONObject jsonObject = JSON.parseObject(response);
                if (jsonObject.getInteger("code").equals(200)){
                    apiLogService.save("Wms任务完成接口"
                            ,wmsUrl+"/wcsManager/wcsInterface/taskStatusFeedback"
                            ,null
                            ,"127.0.0.1"
                            ,JSON.toJSONString(taskOverToWms)
                            ,response
                            ,true
                    );
                }else {
                    continue;
                }
@@ -108,5 +145,103 @@
            }
        }
    }
    @Scheduled(cron = "0/3 * * * * ? ")
    public void task4to5(){
        List<TaskWrk> taskWrks = taskWrkService.selectbyWrksts4();
        for (TaskWrk taskWrk: taskWrks){
            String tasktype = null;
            switch (taskWrk.getIoType()){
                case 1:
                    tasktype= "RK";
                    break;
                case 2:
                    tasktype= "CK";
                    break;
                case 3:
                    tasktype= "YK";
                    break;
                default:
                    tasktype= "未知";
            }
            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(tasktype); // 任务类型
            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");
                map1.put(305,"H-1101");
                map1.put(405,"G-1101");
                taskOverToWms.setEquipmentCode(map1.get(taskWrk.getTargetPoint())); //设备编码
                taskOverToWms.setSourceLocationCode(taskWrk.getOriginStartPoint()); //源库位
            } else if (taskWrk.getIoType() == 3) {
                taskOverToWms.setEquipmentCode(String.valueOf(taskWrk.getCrnNo())); //设备编码
                taskOverToWms.setSourceLocationCode(taskWrk.getOriginStartPoint());
                taskOverToWms.setTargetLocationCode(taskWrk.getOriginTargetPoint()); //目标库位
            }
            taskOverToWms.setTaskStatus("location_done"); //任务状态
            String response = null;
            try {
                response = new HttpHandler.Builder()
                        .setHeaders(map)
                        .setUri("10.32.53.195:8080")
                        .setPath("wcsManager/wcsInterface/taskStatusFeedback")
                        .setJson(JSON.toJSONString(taskOverToWms))
                        .build()
                        .doPost();
            }catch (Exception e){
                log.error("堆垛机任务完成,请求wms任务完成接口失败");
            }
//            ApiLogService apiLogService = SpringUtils.getBean(ApiLogService.class);
            apiLogService.save("Wms任务完成接口"
                    ,"10.32.53.195:8080"+"/wcsManager/wcsInterface/taskStatusFeedback"
                    ,null
                    ,"127.0.0.1"
                    ,JSON.toJSONString(taskOverToWms)
                    ,response
                    ,true
            );
            JSONObject jsonObject = JSON.parseObject(response);
            if (jsonObject.getInteger("code").equals(200)){
                if (taskWrk.getIoType() == 3 || taskWrk.getIoType() == 1){
                    taskWrk.setWrkSts(5);
                }else {
                    taskWrk.setWrkSts(15);
                }
                if (!taskWrkService.updateById(taskWrk)){
                    log.error("堆垛机任务完成,改变任务状态失败");
                }
                log.info("堆垛机任务完成,请求wms任务完成接口成功");
            }else {
                log.error("堆垛机任务完成,请求wms任务完成接口完成,但返回失败");
            }
        }
    }
    @Scheduled(cron = "0 0 1 * * ? ")
    public void clearApiLog(){
        try {
            apiLogService.clearWeekBefore();
        } catch (Exception e) {
            log.error("第三方接口日志自动清除失败(范围:一周之前", e);
        }
    }
}