From 84c488256d57b1c0b9e2556abebeea79f1b23bf1 Mon Sep 17 00:00:00 2001 From: yanps Date: Tue, 6 Aug 2024 16:51:03 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E6=B7=BB=E5=8A=A0=E4=BA=8C=E6=AC=A1?= =?UTF-8?q?=E5=88=86=E9=85=8D=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../agv/ndcone/AgvNdcOneDeviceDriver.java | 3 + .../src/main/resources/log/AutoCreateInst.xml | 2 +- .../log/NDCSocketConnectionAutoRun.xml | 2 +- .../log/OneNDCSocketConnectionAutoRun.xml | 2 +- .../java/org/nl/common/enums/GoodsEnum.java | 2 + .../acs/service/impl/AcsToWmsServiceImpl.java | 34 +++- .../impl/ConnectorToWmsServiceImpl.java | 4 +- .../point/service/ISchBasePointService.java | 9 +- .../sch/point/service/dao/SchBasePoint.java | 4 +- .../service/impl/SchBasePointServiceImpl.java | 65 ++++++- .../nl/wms/sch/task_manage/AbstractTask.java | 2 +- .../sch/task_manage/task/core/TaskType.java | 17 ++ .../task_manage/task/tasks/cnt/CNTTask.java | 21 +-- .../task_manage/task/tasks/cnt/FTGTask.java | 166 ++++++++++++++++++ 14 files changed, 305 insertions(+), 28 deletions(-) create mode 100644 lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/core/TaskType.java create mode 100644 lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/cnt/FTGTask.java diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java index 81b504e..afd27cc 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java @@ -461,6 +461,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic private byte[] feedBackStatus(byte[] data, int index, int agvStatus, Instruction inst, TaskDto task) { String hasWms = paramService.findByCode("hasWms").getValue(); if (StrUtil.isNotEmpty(hasWms) && "1".equals(hasWms)) { + log.info("存在LMS系统,需要反馈,指令号:{}",inst.getInstruction_code()); JSONArray ja = new JSONArray(); JSONObject jo = new JSONObject(); jo.put("vehicle_code", inst.getVehicle_code()); @@ -469,12 +470,14 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic jo.put("task_code", inst.getTask_code()); ja.add(jo); HttpResponse httpResponse = acsToWmsService.feedAgvTaskStatus(ja); + log.info("指令号:{},phase:{},acs反馈wms结果:{}", inst.getInstruction_code(), phase, httpResponse); if (ObjectUtil.isNotEmpty(httpResponse) && httpResponse.getStatus() == 200) { data = NDCAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0); } else { log.info("指令号:{},phase:{},acs反馈wms失败:{}", inst.getInstruction_code(), phase, httpResponse); } } else { + log.info("不存在LMS系统,不需要反馈直接进去取货,指令号:{}",inst.getInstruction_code()); data = NDCAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0); } return data; diff --git a/acs/nladmin-system/nlsso-server/src/main/resources/log/AutoCreateInst.xml b/acs/nladmin-system/nlsso-server/src/main/resources/log/AutoCreateInst.xml index 46daf98..4466239 100644 --- a/acs/nladmin-system/nlsso-server/src/main/resources/log/AutoCreateInst.xml +++ b/acs/nladmin-system/nlsso-server/src/main/resources/log/AutoCreateInst.xml @@ -26,7 +26,7 @@ 512 - + diff --git a/acs/nladmin-system/nlsso-server/src/main/resources/log/NDCSocketConnectionAutoRun.xml b/acs/nladmin-system/nlsso-server/src/main/resources/log/NDCSocketConnectionAutoRun.xml index 4b8a81a..9257d69 100644 --- a/acs/nladmin-system/nlsso-server/src/main/resources/log/NDCSocketConnectionAutoRun.xml +++ b/acs/nladmin-system/nlsso-server/src/main/resources/log/NDCSocketConnectionAutoRun.xml @@ -26,7 +26,7 @@ 512 - + diff --git a/acs/nladmin-system/nlsso-server/src/main/resources/log/OneNDCSocketConnectionAutoRun.xml b/acs/nladmin-system/nlsso-server/src/main/resources/log/OneNDCSocketConnectionAutoRun.xml index 6c2075c..fe51913 100644 --- a/acs/nladmin-system/nlsso-server/src/main/resources/log/OneNDCSocketConnectionAutoRun.xml +++ b/acs/nladmin-system/nlsso-server/src/main/resources/log/OneNDCSocketConnectionAutoRun.xml @@ -27,7 +27,7 @@ --> - + diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/common/enums/GoodsEnum.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/common/enums/GoodsEnum.java index a09c6c4..987c4a8 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/common/enums/GoodsEnum.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/common/enums/GoodsEnum.java @@ -15,6 +15,8 @@ public enum GoodsEnum { IN_STOCK("有货","1"), + EMPTY_PALLETS("空料容","1"), + PICK_UP("取货","1"), DELIVER_GOODS("送货","2"); 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 cd79fe9..eed508c 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 @@ -269,6 +269,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { if (ObjectUtil.isNotEmpty(param)) { String status = param.getString("status"); String task_code = param.getString("task_code"); + String is_connector = param.getString("is_connector"); if (StrUtil.isEmpty(status) || StrUtil.isEmpty(task_code)) { throw new BadRequestException("状态或任务号为空!"); } @@ -283,11 +284,11 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { break; case "2": //取货完成 - requestDeliver(schBaseTask, status); + pickupComplete(schBaseTask, status, is_connector); break; case "4": //放货完成 - requestDeliver(schBaseTask, status); + releaseComplete(schBaseTask, status); break; default: break; @@ -296,15 +297,38 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { return null; } + /** + * 放货完成 + * + * @param schBaseTask + * @param status + */ + private void releaseComplete(SchBaseTask schBaseTask, String status) { + //TODO:放货完成反馈给Connector + + } + /** * 取货完成 * * @param schBaseTask * @param status */ - private void requestDeliver(SchBaseTask schBaseTask, String status) { + private void pickupComplete(SchBaseTask schBaseTask, String status, String is_connector) { //TODO:取货完成创建第二条任务:补空托盘 - + if("1".equals(is_connector)){ + AbstractTask connectorTask = taskFactory.getTask("FTGTask"); + // 准备参数:设备编码 + JSONObject param = new JSONObject(); + param.put("device_code", schBaseTask.getPoint_code2()); + param.put("config_code", "FTGTask"); + param.put("create_mode", GeneralDefinition.AUTO_CREATION); + /*param.put("vehicle_code", vehicle_code); + param.put("task_type", task_type); + param.put("task_code", task_code); + param.put("remark",remark);*/ + connectorTask.apply(param); + } } /** @@ -331,7 +355,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { while (flag) { AcsResponse acsResponse = connectorService.feedAgvTaskStatus(json); if (acsResponse.getStatus() == 200 && StrUtil.isNotEmpty(acsResponse.getData())) { - vehiclematerialgroupService.updateByVehicleCode(schBaseTask.getVehicle_code(),acsResponse.getData()); + vehiclematerialgroupService.updateByVehicleCode(schBaseTask.getVehicle_code(), acsResponse.getData()); flag = false; } } diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/connector/service/impl/ConnectorToWmsServiceImpl.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/connector/service/impl/ConnectorToWmsServiceImpl.java index 6be5521..bc9c447 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/connector/service/impl/ConnectorToWmsServiceImpl.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/connector/service/impl/ConnectorToWmsServiceImpl.java @@ -90,8 +90,8 @@ public class ConnectorToWmsServiceImpl implements ConnectorToWmsService { param.put("task_code", task_code); param.put("remark",remark); connectorTask.apply(param); - schBasePoint.setIng_task_code(task_code); - schBasePointService.updateById(schBasePoint); + /*schBasePoint.setIng_task_code(task_code); + schBasePointService.updateById(schBasePoint);*/ map1.put("task_code", task_code); map1.put("status", HttpStatus.HTTP_OK); map1.put("message", "操作成功!"); diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/point/service/ISchBasePointService.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/point/service/ISchBasePointService.java index 046df01..a963a4d 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/point/service/ISchBasePointService.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/point/service/ISchBasePointService.java @@ -78,7 +78,7 @@ public interface ISchBasePointService extends IService { * 根据工序查询区域存放位置 * @param region_code */ - SchBasePoint selectByRegionCode(String region_code); + SchBasePoint selectByRegionCode(String region_code,String vehicleCode); /** * 根据点位编码查询 @@ -86,4 +86,11 @@ public interface ISchBasePointService extends IService { * @return */ SchBasePoint selectByPointCode(String start_device_code); + + /** + * 查询二次分配的虚拟站点 + * @param region_code + * @return + */ + SchBasePoint selectByReassign(String region_code ,String vehicleCode); } diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/point/service/dao/SchBasePoint.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/point/service/dao/SchBasePoint.java index ab3c64f..3e736df 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/point/service/dao/SchBasePoint.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/point/service/dao/SchBasePoint.java @@ -109,8 +109,8 @@ public class SchBasePoint implements Serializable { @ApiModelProperty(value = "是否启用") private Boolean is_used; - @ApiModelProperty(value = "是否货") - private String is_goods; + @ApiModelProperty(value = "是否锁") + private Boolean is_lock; @ApiModelProperty(value = "创建人") private String create_id; diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/point/service/impl/SchBasePointServiceImpl.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/point/service/impl/SchBasePointServiceImpl.java index 42dee9c..73c3f38 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/point/service/impl/SchBasePointServiceImpl.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/point/service/impl/SchBasePointServiceImpl.java @@ -19,6 +19,8 @@ import org.nl.common.domain.query.PageQuery; import org.nl.common.enums.GoodsEnum; import org.nl.common.exception.BadRequestException; import org.nl.common.utils.SecurityUtils; +import org.nl.wms.database.vehicle.service.IMdBaseVehicleService; +import org.nl.wms.database.vehicle.service.dao.MdBaseVehicle; import org.nl.wms.sch.point.service.ISchBasePointService; import org.nl.wms.sch.point.service.dao.SchBasePoint; import org.nl.wms.sch.point.service.dao.mapper.SchBasePointMapper; @@ -51,6 +53,9 @@ public class SchBasePointServiceImpl extends ServiceImpl queryAll(Map whereJson, PageQuery page){ String blurry = ObjectUtil.isNotEmpty(whereJson.get("blurry")) ? whereJson.get("blurry").toString() : null; @@ -223,14 +228,24 @@ public class SchBasePointServiceImpl extends ServiceImpl schBasePoints = pointMapper.selectList(Wrappers.lambdaQuery(SchBasePoint.class).eq(SchBasePoint::getRegion_code, region_code) .eq(SchBasePoint::getIs_used, true).isNull(SchBasePoint::getIng_task_code)); if(CollUtil.isEmpty(schBasePoints)) return null; //TODO:货位有无货的三种状态: 无货,空料容,有货 - List collect = schBasePoints.stream().filter(schBasePoint -> GoodsEnum.OUT_OF_STOCK.getValue().equals(schBasePoint.getIs_goods())).collect(Collectors.toList()); + List collect = schBasePoints.stream().filter(schBasePoint -> schBasePoint.getIs_lock().equals(false)).collect(Collectors.toList()); if(CollUtil.isNotEmpty(collect) && collect.size() > 0){ - return collect.get(0); + SchBasePoint schBasePoint = collect.get(0); + schBasePoint.setVehicle_code(vehicleCode); + schBasePoint.setIs_lock(true); + String currentUserId = SecurityUtils.getCurrentUserId(); + String nickName = SecurityUtils.getCurrentNickName(); + String now = DateUtil.now(); + schBasePoint.setUpdate_id(currentUserId); + schBasePoint.setUpdate_name(nickName); + schBasePoint.setUpdate_time(now); + updateById(schBasePoint); + return collect.get(0); } String can_vehicle_type = null; for (SchBasePoint schBasePoint : schBasePoints) { @@ -239,7 +254,7 @@ public class SchBasePointServiceImpl extends ServiceImpl schBasePoints1 = pointMapper.selectList(Wrappers.lambdaQuery(SchBasePoint.class).eq(SchBasePoint::getCan_vehicle_type, can_vehicle_type) - .eq(SchBasePoint::getIs_used, true).eq(SchBasePoint::getIs_goods, true).isNull(SchBasePoint::getIng_task_code)); + .eq(SchBasePoint::getIs_used, true).eq(SchBasePoint::getIs_lock, true).isNull(SchBasePoint::getIng_task_code)); if(ObjectUtil.isEmpty(schBasePoints1) || schBasePoints1.size() == 0) return null; return schBasePoints1.get(0); } @@ -249,4 +264,46 @@ public class SchBasePointServiceImpl extends ServiceImpl schBasePoints = pointMapper.selectList(Wrappers.lambdaQuery(SchBasePoint.class).eq(SchBasePoint::getIs_lock, false). + isNull(SchBasePoint::getVehicle_code).eq(SchBasePoint::getRegion_code, region_code) + .eq(SchBasePoint::getVehicle_type, mdBaseVehicle.getVehicle_type()).eq(SchBasePoint::getIs_used, true)); + if(CollUtil.isNotEmpty(schBasePoints) && schBasePoints.size() > 0){ + SchBasePoint schBasePoint = schBasePoints.get(0); + schBasePoint.setVehicle_code(vehicleCode); + schBasePoint.setIs_lock(true); + String currentUserId = SecurityUtils.getCurrentUserId(); + String nickName = SecurityUtils.getCurrentNickName(); + String now = DateUtil.now(); + schBasePoint.setUpdate_id(currentUserId); + schBasePoint.setUpdate_name(nickName); + schBasePoint.setUpdate_time(now); + updateById(schBasePoint); + return schBasePoint; + } + //分配载具类型相同的站点 + List schBasePoints1 = pointMapper.selectList(Wrappers.lambdaQuery(SchBasePoint.class).eq(SchBasePoint::getIs_lock, false). + isNull(SchBasePoint::getVehicle_code).eq(SchBasePoint::getVehicle_type, mdBaseVehicle.getVehicle_type()) + .eq(SchBasePoint::getIs_used, true)); + if(CollUtil.isNotEmpty(schBasePoints1) && schBasePoints1.size() > 0){ + SchBasePoint schBasePoint = schBasePoints.get(0); + schBasePoint.setVehicle_code(vehicleCode); + schBasePoint.setIs_lock(true); + String currentUserId = SecurityUtils.getCurrentUserId(); + String nickName = SecurityUtils.getCurrentNickName(); + String now = DateUtil.now(); + schBasePoint.setUpdate_id(currentUserId); + schBasePoint.setUpdate_name(nickName); + schBasePoint.setUpdate_time(now); + updateById(schBasePoint); + return schBasePoint; + } + return null; + } + } 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 3e84aaf..32f2cf8 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,7 +267,7 @@ public abstract class AbstractTask { task.setVehicle_code(param.getString("vehicle_code")); task.setVehicle_qty(param.getInteger("vehicle_qty")); task.setTask_status(TaskStatus.APPLY.getCode()); - task.setTask_type(param.getString("task_type")); + task.setTask_type(StrUtil.isNotEmpty(param.getString("task_type")) ? param.getString("task_type") : taskConfig.getTask_type()); task.setWorkshop_code(taskConfig.getWorkshop_code()); task.setRemark(param.getString("remark")); // 设置起/终点 diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/core/TaskType.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/core/TaskType.java new file mode 100644 index 0000000..f5eac34 --- /dev/null +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/core/TaskType.java @@ -0,0 +1,17 @@ +package org.nl.wms.sch.task_manage.task.core; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum TaskType { + + CARRY_TASK("搬运任务","1"), + REASSIGN_TASK("二次分配任务","2"); + + + private final String name; + private final String value; + +} diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/cnt/CNTTask.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/cnt/CNTTask.java index b975874..6b9ef31 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/cnt/CNTTask.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/cnt/CNTTask.java @@ -21,6 +21,7 @@ import org.nl.wms.sch.task_manage.GeneralDefinition; import org.nl.wms.sch.task_manage.enums.NoticeTypeEnum; import org.nl.wms.sch.task_manage.enums.TaskFinishedTypeEnum; import org.nl.wms.sch.task_manage.task.core.TaskStatus; +import org.nl.wms.sch.task_manage.task.core.TaskType; import org.nl.wms.util.PointUtils; import org.nl.wms.util.TaskUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -54,17 +55,17 @@ public class CNTTask extends AbstractTask { // 获取任务 List tasks = taskService.findTasksByTaskStatus(TASK_CONFIG_CODE, TaskStatus.APPLY); // 配置信息 - SchBaseTaskconfig taskConfig = taskConfigService.getOne(new LambdaQueryWrapper() - .eq(SchBaseTaskconfig::getConfig_code, TASK_CONFIG_CODE)); + /*SchBaseTaskconfig taskConfig = taskConfigService.getOne(new LambdaQueryWrapper() + .eq(SchBaseTaskconfig::getConfig_code, TASK_CONFIG_CODE));*/ for (SchBaseTask task : tasks) { TaskUtils.setUpdateByAcs(task); // 找起点 - String requestParam = task.getRequest_param(); - JSONObject jsonObject = JSONObject.parseObject(requestParam); - // 根据对接位查找对应的载具类型 - SchBasePoint schBasePoint = schBasePointService.selectByRegionCode(RegionEnum.TRUBEND_SHELVES_3_1_1.getRegion_code()); - if(ObjectUtil.isEmpty(schBasePoint)) continue; - jsonObject.put("vehicle_type", schBasePoint.getCan_vehicle_type()); + SchBasePoint schBasePoint = null; + if (TaskType.CARRY_TASK.getValue().equals(task.getTask_type())) { + schBasePoint = schBasePointService.selectByRegionCode(RegionEnum.TRUBEND_SHELVES_3_1_1.getRegion_code(), task.getVehicle_code()); + } else if (TaskType.REASSIGN_TASK.getValue().equals(task.getTask_type())){ + schBasePoint = schBasePointService.selectByReassign(RegionEnum.TRUBEND_SHELVES_3_1_1.getRegion_code(),task.getVehicle_code()); + } if (ObjectUtil.isEmpty(schBasePoint)) { task.setRemark("未找到所需点位!"); taskService.updateById(task); @@ -74,10 +75,10 @@ public class CNTTask extends AbstractTask { continue; } - SchBaseVehiclematerialgroup schBaseVehiclematerialgroup = new SchBaseVehiclematerialgroup(); + /*SchBaseVehiclematerialgroup schBaseVehiclematerialgroup = new SchBaseVehiclematerialgroup(); schBaseVehiclematerialgroup.setVehicle_code(task.getVehicle_code()); schBaseVehiclematerialgroup.setPoint_code(schBasePoint.getPoint_code()); - schBaseVehiclematerialgroupService.create(schBaseVehiclematerialgroup); + schBaseVehiclematerialgroupService.create(schBaseVehiclematerialgroup);*/ // 设置终点并修改创建成功状态 task.setPoint_code2(schBasePoint.getPoint_code()); diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/cnt/FTGTask.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/cnt/FTGTask.java new file mode 100644 index 0000000..c03ec2c --- /dev/null +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/cnt/FTGTask.java @@ -0,0 +1,166 @@ +package org.nl.wms.sch.task_manage.task.tasks.cnt; + +import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import lombok.extern.slf4j.Slf4j; +import org.nl.common.enums.region.RegionEnum; +import org.nl.common.exception.BadRequestException; +import org.nl.system.service.notice.ISysNoticeService; +import org.nl.wms.ext.acs.service.dto.to.BaseResponse; +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; +import org.nl.wms.sch.point.service.dao.SchBasePoint; +import org.nl.wms.sch.task.service.ISchBaseTaskService; +import org.nl.wms.sch.task.service.ISchBaseTaskconfigService; +import org.nl.wms.sch.task.service.dao.SchBaseTask; +import org.nl.wms.sch.task.service.dao.SchBaseTaskconfig; +import org.nl.wms.sch.task_manage.AbstractTask; +import org.nl.wms.sch.task_manage.GeneralDefinition; +import org.nl.wms.sch.task_manage.enums.NoticeTypeEnum; +import org.nl.wms.sch.task_manage.enums.TaskFinishedTypeEnum; +import org.nl.wms.sch.task_manage.task.core.TaskStatus; +import org.nl.wms.util.PointUtils; +import org.nl.wms.util.TaskUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Slf4j +@Component(value = "FTGTask") +public class FTGTask extends AbstractTask { + + + private static final String TASK_CONFIG_CODE = "FTGTask"; + @Autowired + private ISchBasePointService pointService; + @Autowired + private ISchBaseTaskService taskService; + @Autowired + private ISchBaseTaskconfigService taskConfigService; + @Autowired + private ISysNoticeService noticeService; + @Autowired + private ISchBasePointService schBasePointService; + @Autowired + private ISchBaseVehiclematerialgroupService schBaseVehiclematerialgroupService; + + @Override + protected void create() throws BadRequestException { + // 获取任务 + List tasks = taskService.findTasksByTaskStatus(TASK_CONFIG_CODE, TaskStatus.APPLY); + for (SchBaseTask task : tasks) { + TaskUtils.setUpdateByAcs(task); + // 找起点 + String requestParam = task.getRequest_param(); + JSONObject jsonObject = JSONObject.parseObject(requestParam); + // 根据对接位查找对应的载具类型 + SchBasePoint schBasePoint = schBasePointService.selectByRegionCode(RegionEnum.TRUBEND_SHELVES_3_1_1.getRegion_code(),task.getVehicle_code()); + if(ObjectUtil.isEmpty(schBasePoint)) continue; + jsonObject.put("vehicle_type", schBasePoint.getCan_vehicle_type()); + if (ObjectUtil.isEmpty(schBasePoint)) { + task.setRemark("未找到所需点位!"); + taskService.updateById(task); + // 消息通知 + noticeService.createNotice("未找到所需点位!", TASK_CONFIG_CODE + task.getTask_code(), + NoticeTypeEnum.WARN.getCode()); + continue; + } + + SchBaseVehiclematerialgroup schBaseVehiclematerialgroup = new SchBaseVehiclematerialgroup(); + schBaseVehiclematerialgroup.setVehicle_code(task.getVehicle_code()); + schBaseVehiclematerialgroup.setPoint_code(schBasePoint.getPoint_code()); + schBaseVehiclematerialgroupService.create(schBaseVehiclematerialgroup); + + // 设置终点并修改创建成功状态 + task.setPoint_code1(schBasePoint.getPoint_code()); + task.setVehicle_type(schBasePoint.getCan_vehicle_type()); + task.setRemark(""); + task.setTask_status(TaskStatus.CREATED.getCode()); + taskService.updateById(task); + + schBasePoint.setIng_task_code(task.getTask_code()); + PointUtils.setUpdateByAcs(schBasePoint); + pointService.updateById(schBasePoint); + } + } + + @Override + protected void updateStatus(String task_code, TaskStatus status) { + //TODO:完成任务的时候将int_task_code的清除 + + } + + @Override + public void forceFinish(String task_code) { + SchBaseTask taskObj = taskService.getByCode(task_code); + if (ObjectUtil.isEmpty(taskObj)) { + throw new BadRequestException("该任务不存在"); + } + this.finishTask(taskObj, TaskFinishedTypeEnum.MANUAL_CONNECTOR); + } + + @Override + public void cancel(String task_code) { + //TODO:取消任务的时候将int_task_code的清除 + SchBaseTask taskObj = taskService.getByCode(task_code); + if (ObjectUtil.isEmpty(taskObj)) { + throw new BadRequestException("该任务不存在"); + } + this.cancelTask(taskObj, TaskFinishedTypeEnum.MANUAL_CONNECTOR); + } + + @Override + protected void feedbackTaskState(JSONObject param, SchBaseTask schBaseTask, BaseResponse result) { + + } + + public void finishTask(SchBaseTask taskObj, TaskFinishedTypeEnum taskFinishedType) { + // 获取参数 + String startPoint = taskObj.getPoint_code1(); + SchBasePoint schBasePoint = pointService.selectByPointCode(startPoint); + // 起点清空 + if (ObjectUtil.isNotEmpty(schBasePoint)) { + PointUtils.updateByIngTaskCode(schBasePoint); + pointService.updateById(schBasePoint); + } + String point_code2 = taskObj.getPoint_code2(); + SchBasePoint schBasePoint2 = pointService.selectByPointCode(point_code2); + if (ObjectUtil.isNotEmpty(schBasePoint2)) { + PointUtils.updateByIngTaskCode(schBasePoint2); + pointService.updateById(schBasePoint2); + } + // 任务完成 + taskObj.setTask_status(TaskStatus.FINISHED.getCode()); + taskObj.setRemark(GeneralDefinition.TASK_FINISH); + taskObj.setFinished_type(taskFinishedType.getCode()); + TaskUtils.setUpdateByType(taskObj, taskFinishedType); + taskService.updateById(taskObj); + } + + public void cancelTask(SchBaseTask taskObj, TaskFinishedTypeEnum taskFinishedType) { + // 获取参数 + String startPoint = taskObj.getPoint_code1(); + SchBasePoint schBasePoint = pointService.selectByPointCode(startPoint); + // 起点清空 + if (ObjectUtil.isNotEmpty(schBasePoint)) { + PointUtils.updateByIngTaskCode(schBasePoint); + pointService.updateById(schBasePoint); + } + String point_code2 = taskObj.getPoint_code2(); + SchBasePoint schBasePoint2 = pointService.selectByPointCode(point_code2); + if (ObjectUtil.isNotEmpty(schBasePoint2)) { + PointUtils.updateByIngTaskCode(schBasePoint2); + pointService.updateById(schBasePoint2); + } + taskObj.setTask_status(TaskStatus.CANCELED.getCode()); + taskObj.setRemark(GeneralDefinition.TASK_CANCEL); + taskObj.setTask_status(TaskStatus.CANCELED.getCode()); + taskObj.setFinished_type(taskFinishedType.getCode()); + TaskUtils.setUpdateByType(taskObj, taskFinishedType); + taskService.updateById(taskObj); + } + +}