#
taisheng
2025-05-24 53ae8e478f6034579303c51bdf881ffa526c942c
src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java
@@ -1,23 +1,19 @@
package com.zy.asrs.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.core.common.R;
import com.core.exception.CoolException;
import com.zy.asrs.domain.enums.TaskStatusType;
import com.zy.asrs.entity.TaskWrk;
import com.zy.asrs.entity.ToWmsDTO;
import com.zy.asrs.entity.param.WMSAndAGVInterfaceParam;
import com.zy.asrs.entity.param.taskCreateParam;
import com.zy.asrs.service.OpenService;
import com.zy.asrs.service.TaskWrkService;
import com.zy.common.utils.HttpHandler;
import com.zy.asrs.domain.enums.WorkNoType;
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.param.GenerateAgvTaskParam;
import com.zy.asrs.entity.param.TaskCreateParam;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.Utils;
import com.zy.common.service.CommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.*;
@Service
@@ -25,84 +21,126 @@
    @Autowired
    private TaskWrkService taskWrkService;
    @Value("${wms.url}")
    private String wmsUrl;
    @Autowired
    private CommonService commonService;
    @Autowired
    private LocMastService locMastService;
    @Override
    public void taskCreate(taskCreateParam param) {
    public HashMap<String, Object> taskCreate(TaskCreateParam param) {
        HashMap<String,Object> map=new HashMap<>();
        TaskWrk taskWrk = taskWrkService.selectByTaskNo(param.getTaskNo());
        if (taskWrk != null) {
            throw new CoolException(param.getTaskNo() + "任务已存在,请勿重复提交");
        }
        if (param.getIoType().equals(0)){
            throw new CoolException("生成任务失败,任务类型不存在!");
            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.getStartPoint()));
        int workNo1 = commonService.getWorkNo(WorkNoType.PAKOUT.type);//获取入库工作号
        taskWrk.setTaskNo(param.getTaskNo());//任务号
        taskWrk.setWrkNo(workNo1);
        taskWrk.setStatus(TaskStatusType.RECEIVE.id);//任务状态:接收
        taskWrk.setCreateTime(now);
        try {
            if (param.getIoType() > 1) {
                if (Utils.locNoRowBoolean(locMast.getRow1())) {
                    param.setTaskPriority(11);
                }
            }
        } catch (Exception e) {
        }
        taskWrk.setIoType(param.getIoType());//任务类型
        taskWrk.setIoPri(param.getTaskPriority());//优先级
        taskWrk.setBarcode(param.getBarcode());//条码
        taskWrk.setCrnNo(param.getCrn());
        if(param.getIoType() == 1){
        taskWrk.setCrnNo(locMast.getCrnNo());
        if (param.getIoType() == 1) {
            taskWrk.setWrkSts(1);
            if (!Cools.isEmpty(param.getTargetPoint())) {
                taskWrk.setTargetPoint(Utils.getWcsLocNo(param.getTargetPoint()));//终点
                taskWrk.setOriginTargetPoint(param.getTargetPoint());
            }
        } else if (param.getIoType() == 2) {
            taskWrk.setWrkSts(11);
            if (!Cools.isEmpty(param.getStartPoint())) {
                taskWrk.setStartPoint(param.getStartPoint());//起点
                taskWrk.setTargetPoint(param.getTargetPoint());
            }
            taskWrk.setTargetPoint(param.getTargetPoint());
        } else if (param.getIoType() == 3) {
            taskWrk.setWrkSts(11);
            if (!Cools.isEmpty(param.getStartPoint())) {
                taskWrk.setStartPoint(param.getStartPoint());//起点
                taskWrk.setTargetPoint(param.getTargetPoint());
            }
        }
        if (!Cools.isEmpty(param.getStartPoint())) {
            taskWrk.setStartPoint(param.getStartPoint());//起点
        }
        if (!Cools.isEmpty(param.getTargetPoint())) {
            taskWrk.setTargetPoint(param.getTargetPoint());//终点
        }
        if (!Cools.isEmpty(param.getMemo())) {
            taskWrk.setMemo(param.getMemo());//备注
        }
        if (!taskWrkService.insert(taskWrk)) {
            throw new CoolException("生成任务失败,请联系管理员");
            map.put("Code","0");
            map.put("Msg",param.getTaskNo()+"创建任务失败!");
            return map;
        }
        map.put("Code","1");
        map.put("Msg","ok");
        return map;
    }
    @Override
    public R AgvToWCSToWms(WMSAndAGVInterfaceParam param) throws IOException {
        ToWmsDTO toWmsDTO = new ToWmsDTO();
        Map<String, Object> map = new HashMap<>();
        map.put("x-api-key","7a15b5db-29b6-552c-8cff-0cfec3756da2");
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(4);
        //TaskWrk taskWrk = taskWrkService.selectByTaskNo(param.getTaskNo());
        toWmsDTO.setWarehouseId("1688469798893297665");
        toWmsDTO.setContainerCode(param.getContainerCode());
        toWmsDTO.setApplyType("TUNNEL");
        toWmsDTO.setWharfSource(null);
        toWmsDTO.setCanInboundTunnels(list);
        String response = new HttpHandler.Builder()
                .setHeaders(map)
                .setUri(wmsUrl)
                .setPath("wcsManager/wcsInterface/inboundTaskApply")
                .setJson(JSON.toJSONString(toWmsDTO))
                .build()
                .doPost();
        JSONObject jsonObject = JSON.parseObject(response);
        if (jsonObject.getInteger("code").equals(200)) {
            //解析
            List<WMSAndAGVInterfaceParam> params = new ArrayList<>();
            params.add(param);
            WMSAndAGVInterfaceParam data = JSONObject.parseObject(jsonObject.get("data").toString(), WMSAndAGVInterfaceParam.class);
            taskCreate(new taskCreateParam(data));
            return R.ok(jsonObject.get("data"));
        }else {
            return R.error((String) jsonObject.get("msg"));
    public boolean generateAgvTask(GenerateAgvTaskParam param) {
        Date now = new Date();
        String originPoint = param.getOriginPoint();
        String targetPoint = param.getTargetPoint();
        LocMast startLocMast = locMastService.selectByLocNo(originPoint);
        if(startLocMast == null){
            throw new CoolException("取货点库位不存在");
        }
        if (!startLocMast.getLocSts().equals("F")) {
            throw new CoolException("取货点不处于在库");
        }
        LocMast targetLocMast = locMastService.selectByLocNo(targetPoint);
        if(targetLocMast == null){
            throw new CoolException("放货点库位不存在");
        }
        if (!targetLocMast.getLocSts().equals("O")) {
            throw new CoolException("放货点不处于空库");
        }
        TaskWrk taskWrk = new TaskWrk();
        int workNo1 = commonService.getWorkNo(WorkNoType.AGV.type);//获取AGV工作号
        taskWrk.setTaskNo(String.valueOf(workNo1));//任务号
        taskWrk.setWrkNo(workNo1);
        taskWrk.setStatus(TaskStatusType.RECEIVE.id);//任务状态:接收
        taskWrk.setCreateTime(now);
        taskWrk.setWrkSts(11);
        taskWrk.setIoType(4);//AGV搬运
        taskWrk.setStartPoint(param.getOriginPoint());//取货点
        taskWrk.setTargetPoint(param.getTargetPoint());//放货点
        boolean insert = taskWrkService.insert(taskWrk);
        if (!insert) {
            throw new CoolException("任务生成失败");
        }
        startLocMast.setLocSts("R");
        startLocMast.setModiTime(now);
        locMastService.updateById(startLocMast);
        targetLocMast.setLocSts("S");
        targetLocMast.setModiTime(now);
        locMastService.updateById(targetLocMast);
        return true;
    }
}