diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/acs/service/impl/AcsToWmsServiceImpl.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/acs/service/impl/AcsToWmsServiceImpl.java index 3477692..132ace6 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/acs/service/impl/AcsToWmsServiceImpl.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/acs/service/impl/AcsToWmsServiceImpl.java @@ -9,8 +9,11 @@ import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpStatus; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import lombok.extern.slf4j.Slf4j; +import lombok.var; +import org.apache.commons.lang3.StringUtils; import org.nl.common.enums.GoodsEnum; import org.nl.common.exception.BadRequestException; import org.nl.system.service.notice.ISysNoticeService; @@ -26,6 +29,7 @@ import org.nl.wms.ext.acs.service.dto.to.wms.FeedBackTaskStatusRequest; import org.nl.wms.ext.connector.service.WmsToConnectorService; import org.nl.wms.ext.connector.service.dto.ConnectorDto; import org.nl.wms.ext.record.service.ISysInteractRecordService; +import org.nl.wms.ext.sorting.service.impl.WmsToSortingService; import org.nl.wms.sch.group.service.ISchBaseVehiclematerialgroupService; import org.nl.wms.sch.group.service.dao.SchBaseVehiclematerialgroup; import org.nl.wms.sch.point.service.ISchBasePointService; @@ -43,6 +47,7 @@ import org.nl.wms.sch.task_manage.task.core.TaskType; import org.nl.wms.sch.task_manage.task.tasks.mapper.PointMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import javax.annotation.PostConstruct; import java.lang.reflect.InvocationTargetException; @@ -87,7 +92,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { @Autowired private WmsToConnectorService connectorService; @Autowired - private ISchBaseTaskconfigService taskConfigService; + private WmsToSortingService sortingService; @Autowired private IMdBaseVehicleService iMdBaseVehicleService; @@ -339,17 +344,27 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { */ private void releaseComplete(SchBaseTask schBaseTask, String status, String is_connector, String taskType, boolean is_empty) { //TODO:空料容放货完成反馈给Connector - if ("1".equals(is_connector)) { - if (!is_empty) { - finishTask(schBaseTask.getTask_code(), schBaseTask.getPoint_code2()); - } else { + if (!is_empty) { + finishTask(schBaseTask.getTask_code(), schBaseTask.getPoint_code2()); + }else { + finishTask(schBaseTask.getTask_code(), schBaseTask.getPoint_code1()); + + if ("1".equals(is_connector)) { JSONObject json = new JSONObject(); json.put("vehicle_code", schBaseTask.getVehicle_code()); json.put("status", status); json.put("device_code", schBaseTask.getPoint_code2()); json.put("task_code", schBaseTask.getTask_code()); AcsResponse acsResponse = connectorService.feedAgvTaskStatus(json); - finishTask(schBaseTask.getTask_code(), schBaseTask.getPoint_code1()); + + } + if ("2".equals(is_connector)) { + JSONObject json = new JSONObject(); + json.put("vehicle_code", schBaseTask.getVehicle_code()); + json.put("status", status); + json.put("device_code", schBaseTask.getPoint_code2()); + json.put("task_code", schBaseTask.getTask_code()); + AcsResponse acsResponse = sortingService.feedAgvTaskStatus(json); } } } @@ -369,30 +384,38 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { */ private void pickupComplete(SchBaseTask schBaseTask, String status, String is_connector, String taskType) { //TODO:取货完成创建第二条任务:补空托盘 + String vehicle_code = schBaseTask.getVehicle_code(); if ("1".equals(is_connector)) { List list = taskService.list(Wrappers.lambdaQuery(SchBaseTask.class).eq(SchBaseTask::getPoint_code2, schBaseTask.getPoint_code1()) .in(SchBaseTask::getTask_status, TaskStatus.APPLY.getCode(), TaskStatus.CREATED.getCode(), TaskStatus.ISSUED.getCode(), TaskStatus.EXECUTING.getCode())); - if (CollUtil.isNotEmpty(list) || list.size() > 0) { - throw new BadRequestException("该点位已有任务,请等待任务完成"); + if (CollectionUtils.isEmpty(list)) { + MdBaseVehicle mdBaseVehicle = iMdBaseVehicleService.getOne(new QueryWrapper().eq("vehicle_code", vehicle_code)); + AbstractTask connectorTask = taskFactory.getTask("FTGTask"); + // 准备参数:设备编码 + JSONObject param = new JSONObject(); + param.put("device_code", schBaseTask.getPoint_code1()); + param.put("config_code", "FTGTask"); + param.put("create_mode", GeneralDefinition.AUTO_CREATION); + param.put("vehicle_type", mdBaseVehicle.getVehicle_type()); + connectorTask.apply(param); + pointService.update(Wrappers.lambdaUpdate(SchBasePoint.class) + .eq(SchBasePoint::getPoint_code, schBaseTask.getPoint_code1()).set(SchBasePoint::getIs_lock, true)); } - MdBaseVehicle mdBaseVehicle = iMdBaseVehicleService.getById(schBaseTask.getVehicle_code()); - AbstractTask connectorTask = taskFactory.getTask("FTGTask"); - // 准备参数:设备编码 - JSONObject param = new JSONObject(); - param.put("device_code", schBaseTask.getPoint_code1()); - param.put("config_code", "FTGTask"); - param.put("create_mode", GeneralDefinition.AUTO_CREATION); - param.put("vehicle_type", StrUtil.isNotEmpty(mdBaseVehicle.getVehicle_type()) ? mdBaseVehicle.getVehicle_type() : ""); - connectorTask.apply(param); - pointService.update(Wrappers.lambdaUpdate(SchBasePoint.class) - .eq(SchBasePoint::getPoint_code, schBaseTask.getPoint_code1()).set(SchBasePoint::getIs_lock, true)); JSONObject json = new JSONObject(); - json.put("vehicle_code", schBaseTask.getVehicle_code()); + json.put("vehicle_code", vehicle_code); json.put("status", status); json.put("device_code", schBaseTask.getPoint_code1()); json.put("task_code", schBaseTask.getTask_code()); AcsResponse acsResponse = connectorService.feedAgvTaskStatus(json); } + if ("2".equals(is_connector)) { + JSONObject json = new JSONObject(); + json.put("vehicle_code", vehicle_code); + json.put("status", status); + json.put("device_code", schBaseTask.getPoint_code1()); + json.put("task_code", schBaseTask.getTask_code()); + AcsResponse acsResponse = sortingService.feedAgvTaskStatus(json); + } } /** diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/sorting/service/impl/SortingServiceImpl.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/sorting/service/impl/SortingServiceImpl.java index ee55b7e..1fee937 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/sorting/service/impl/SortingServiceImpl.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/sorting/service/impl/SortingServiceImpl.java @@ -58,7 +58,7 @@ public class SortingServiceImpl implements SortingService { //托盘上的堆垛信息 JSONArray jsonArray = JSONUtil.parseArray(jsonObject.get("pallet_detail")); // TODO:呼叫空托 - JSONObject taskParam = new JSONObject(MapOf.of("device_code",pointCode,"requestNo", "sorting_"+IdUtil.getStringId(),"ext_data",jsonObject)); + JSONObject taskParam = new JSONObject(MapOf.of("task_code",task_code,"job_name",jobname,"device_code",pointCode,"requestNo", "sorting_"+IdUtil.getStringId(),"ext_data",jsonObject)); if(SortingEnum.TASK_TYPE_ONE.getValue().equals(task_type) && SortingEnum.IS_EMPTY.getValue().equals(is_empty)){ taskParam.put("config_code","sortingCNTTask"); sortingCNTTask.apply(taskParam); diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/sorting/service/impl/WmsToSortingService.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/sorting/service/impl/WmsToSortingService.java new file mode 100644 index 0000000..a5880f3 --- /dev/null +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/sorting/service/impl/WmsToSortingService.java @@ -0,0 +1,41 @@ +package org.nl.wms.ext.sorting.service.impl; + +import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.nl.common.exception.BadRequestException; +import org.nl.config.MapOf; +import org.nl.wms.ext.acs.service.dto.to.wms.AcsResponse; +import org.nl.wms.ext.connector.service.WmsToConnectorService; +import org.nl.wms.sch.task.service.ISchBaseTaskService; +import org.nl.wms.sch.task.service.dao.SchBaseTask; +import org.nl.wms.sch.task_manage.GeneralDefinition; +import org.nl.wms.sch.task_manage.task.ConnectorUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * @author LENOVO + */ +@Slf4j +@Service +public class WmsToSortingService { + + @Autowired + private ISchBaseTaskService iSchBaseTaskService; + + public AcsResponse feedAgvTaskStatus(JSONObject json) { + String task_code = json.getString("task_code"); + SchBaseTask task = iSchBaseTaskService.getByCode(task_code); + String request_param = task.getRequest_param(); + JSONObject toJSON = (JSONObject)JSONObject.toJSON(request_param); + String ext_data = toJSON.getString("ext_data"); + if (StringUtils.isEmpty(ext_data)){ + throw new BadRequestException("WmsToSortingService反馈异常,sorting对接数据ext_data为空"); + } + AcsResponse acsResponse = ConnectorUtil.notifyEextSystem("api/external/wms/agv", ext_data, GeneralDefinition.SORTING_URL); + return acsResponse; + } + + +} diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/AbstractTask.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/AbstractTask.java index 46f3d71..9c70bb7 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/AbstractTask.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/AbstractTask.java @@ -267,6 +267,7 @@ public abstract class AbstractTask { task.setVehicle_code(param.getString("vehicle_code")); task.setVehicle_qty(param.getInteger("vehicle_qty")); task.setVehicle_type(param.getString("vehicle_type")); + task.setJob_name(param.getString("job_name")); task.setTask_status(TaskStatus.APPLY.getCode()); task.setTask_type(StrUtil.isNotEmpty(param.getString("task_type")) ? param.getString("task_type") : taskConfig.getTask_type()); task.setWorkshop_code(taskConfig.getWorkshop_code()); diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/GeneralDefinition.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/GeneralDefinition.java index 1922ddb..28da35c 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/GeneralDefinition.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/GeneralDefinition.java @@ -65,6 +65,7 @@ public class GeneralDefinition { * CONNECTOR路径 */ public static final String CONNECTOR_URL = "connector_url"; + public static final String SORTING_URL = "sorting_url"; /** 是否连接 */ public static final String IS_CONNECT_MES = "is_connect_mes"; /** MES路径 */ diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/ConnectorUtil.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/ConnectorUtil.java index 5c6ff6d..ac61c6e 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/ConnectorUtil.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/ConnectorUtil.java @@ -86,7 +86,42 @@ public class ConnectorUtil { return AcsResponse.requestRefuse("未连接ACS!"); } String url = connectorUrl + api; - log.info("下发acs任务的参数为:{}", object.toString()); + log.info("下发acs任务的参数为:{}", JSON.toJSONString(object)); + AcsResponse resultForAcs; + try { + String resultMsg = HttpRequest.post(url) + .body(JSON.toJSONString(object)) + .execute().body(); + result = JSONObject.parseObject(resultMsg); + resultForAcs = JSONObject.toJavaObject(result, AcsResponse.class); + } catch (Exception e) { + String msg = e.getMessage(); + //网络不通 + log.error("连接失败:{}", msg); + return AcsResponse.requestRefuse("网络不通,操作失败!"); + } + return resultForAcs; + } + public static AcsResponse notifyEextSystem(String api, T object,String urlConfig) { + SysParamServiceImpl sysParamService = SpringContextHolder.getBean(SysParamServiceImpl.class); + //判断是否连接ACS系统 + Param isConnectConnector = sysParamService.findByCode(GeneralDefinition.IS_CONNECT_CONNECTOR); + if (ObjectUtil.isEmpty(isConnectConnector)) { + return AcsResponse.requestRefuse("参数表中:" + GeneralDefinition.IS_CONNECT_CONNECTOR + "不存在"); + } + String isConnect = isConnectConnector.getValue(); + //ACS地址:127.0.0.1:8010 + Param connectorUrlObj = sysParamService.findByCode(urlConfig); + if (ObjectUtil.isEmpty(connectorUrlObj)) { + return AcsResponse.requestRefuse("参数表中:" + urlConfig + "不存在"); + } + String connectorUrl = connectorUrlObj.getValue(); + JSONObject result; + if (StrUtil.equals(GeneralDefinition.NO, isConnect)) { + return AcsResponse.requestRefuse("未连接ACS!"); + } + String url = connectorUrl + api; + log.info("下发acs任务的参数为:{}", JSON.toJSONString(object)); AcsResponse resultForAcs; try { String resultMsg = HttpRequest.post(url)