diff --git a/lms/hd/nladmin-system/src/main/java/org/nl/wms/ext/acs/service/impl/AcsToWmsServiceImpl.java b/lms/hd/nladmin-system/src/main/java/org/nl/wms/ext/acs/service/impl/AcsToWmsServiceImpl.java index bcf8d56..b7132de 100644 --- a/lms/hd/nladmin-system/src/main/java/org/nl/wms/ext/acs/service/impl/AcsToWmsServiceImpl.java +++ b/lms/hd/nladmin-system/src/main/java/org/nl/wms/ext/acs/service/impl/AcsToWmsServiceImpl.java @@ -372,7 +372,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { JSONObject param = new JSONObject(); param.put("start_point_code", point_code); // 1.生成起点确定的任务 - SpringContextHolder.getBean(PointToPointTask.class).createTask(param); + SpringContextHolder.getBean(P2PTask.class).createTask(param); resuft.put("status", "200"); resuft.put("message", ""); diff --git a/lms/hd/nladmin-system/src/main/java/org/nl/wms/ext/auto/AutoQueryTask.java b/lms/hd/nladmin-system/src/main/java/org/nl/wms/ext/auto/AutoQueryTask.java index 641963c..1d5d4ad 100644 --- a/lms/hd/nladmin-system/src/main/java/org/nl/wms/ext/auto/AutoQueryTask.java +++ b/lms/hd/nladmin-system/src/main/java/org/nl/wms/ext/auto/AutoQueryTask.java @@ -8,7 +8,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.nl.utils.SpringContextHolder; import org.nl.wms.ext.acs.service.WmsToAcsService; -import org.nl.wms.sch.tasks.PointToPointTask; +import org.nl.wms.sch.tasks.P2PTask; import org.nl.wql.WQL; import org.nl.wql.core.bean.WQLObject; import org.springframework.stereotype.Service; @@ -25,7 +25,7 @@ public class AutoQueryTask { public void run() { WQLObject taskTab = WQLObject.getWQLObject("SCH_BASE_Task"); - PointToPointTask pointTaskBean = SpringContextHolder.getBean(PointToPointTask.class); + P2PTask pointTaskBean = SpringContextHolder.getBean(P2PTask.class); // 1.查找起点为油漆线 物料下料位的任务 JSONArray taskArr = WQL.getWO("AUTO_QUERYTASK").addParam("flag", "1").process().getResultJSONArray(0); diff --git a/lms/hd/nladmin-system/src/main/java/org/nl/wms/pad/rest/PadController.java b/lms/hd/nladmin-system/src/main/java/org/nl/wms/pad/rest/PadController.java index 46fdb4e..3662fed 100644 --- a/lms/hd/nladmin-system/src/main/java/org/nl/wms/pad/rest/PadController.java +++ b/lms/hd/nladmin-system/src/main/java/org/nl/wms/pad/rest/PadController.java @@ -281,4 +281,39 @@ public class PadController { return new ResponseEntity<>(padService.lockRow(regionId, col, type), HttpStatus.OK); } + + /** + * 点对点任务 + * + * @param param String start_devicecode 起点编码 + * String next_devicecode 终点编码 + * @return 提示 + */ + @PostMapping("/p2p") + @Log("点对点任务") + @ApiOperation("点对点任务") + public ResponseEntity p2p(@RequestBody JSONObject param) { + String startPointCode = param.getString("start_devicecode"); + if (StrUtil.isBlank(startPointCode)) { + JSONObject resultJSON = new JSONObject(); + resultJSON.put("code", "0"); + resultJSON.put("desc", "起点不能为空"); + return new ResponseEntity<>(resultJSON, HttpStatus.OK); + } + String nextPointCode = param.getString("next_devicecode"); + if (StrUtil.isBlank(nextPointCode)) { + JSONObject resultJSON = new JSONObject(); + resultJSON.put("code", "0"); + resultJSON.put("desc", "终点不能为空"); + return new ResponseEntity<>(resultJSON, HttpStatus.OK); + } + if (startPointCode.equals(nextPointCode)) { + JSONObject resultJSON = new JSONObject(); + resultJSON.put("code", "0"); + resultJSON.put("desc", "起点和终点不能相同"); + return new ResponseEntity<>(resultJSON, HttpStatus.OK); + } + + return new ResponseEntity<>(padService.p2p(startPointCode, nextPointCode), HttpStatus.OK); + } } diff --git a/lms/hd/nladmin-system/src/main/java/org/nl/wms/pad/service/PadService.java b/lms/hd/nladmin-system/src/main/java/org/nl/wms/pad/service/PadService.java index 03187e8..a7c9274 100644 --- a/lms/hd/nladmin-system/src/main/java/org/nl/wms/pad/service/PadService.java +++ b/lms/hd/nladmin-system/src/main/java/org/nl/wms/pad/service/PadService.java @@ -91,4 +91,13 @@ public interface PadService { * @return 提示 */ JSONObject lockRow(String regionId, String col, String type); + + /** + * 点对点任务 + * + * @param startPointCode 起点编码 + * @param nextPointCode 终点编码 + * @return 提示 + */ + JSONObject p2p(String startPointCode, String nextPointCode); } diff --git a/lms/hd/nladmin-system/src/main/java/org/nl/wms/pad/service/impl/PadServiceImpl.java b/lms/hd/nladmin-system/src/main/java/org/nl/wms/pad/service/impl/PadServiceImpl.java index ef0c43c..fcc66db 100644 --- a/lms/hd/nladmin-system/src/main/java/org/nl/wms/pad/service/impl/PadServiceImpl.java +++ b/lms/hd/nladmin-system/src/main/java/org/nl/wms/pad/service/impl/PadServiceImpl.java @@ -19,6 +19,7 @@ import org.nl.utils.RsaUtils; import org.nl.utils.SecurityUtils; import org.nl.wms.pad.service.PadService; import org.nl.wms.sch.tasks.CallTask; +import org.nl.wms.sch.tasks.P2PTask; import org.nl.wms.sch.tasks.SendTask; import org.nl.wql.WQL; import org.nl.wql.core.bean.WQLObject; @@ -62,6 +63,8 @@ public class PadServiceImpl implements PadService { private final SendTask sendTask; + private final P2PTask p2pTask; + /** * 手持登陆 * @@ -424,4 +427,34 @@ public class PadServiceImpl implements PadService { resultJSON.put("desc", "操作成功"); return resultJSON; } + + /** + * 点对点任务 + * + * @param startPointCode 起点编码 + * @param nextPointCode 终点编码 + * @return 提示 + */ + @Override + public JSONObject p2p(String startPointCode, String nextPointCode) { + // 返回值 + JSONObject resultJSON = new JSONObject(); + + // 调用送料任务类创建任务 + try { + JSONObject param = new JSONObject(); + param.put("start_point_code", startPointCode); + param.put("next_point_code", nextPointCode); + p2pTask.createTask(param); + } catch (Exception e) { + resultJSON.put("code", "0"); + resultJSON.put("desc", e.getMessage()); + return resultJSON; + } + + // 返回 + resultJSON.put("code", "1"); + resultJSON.put("desc", "已创建任务"); + return resultJSON; + } } diff --git a/lms/hd/nladmin-system/src/main/java/org/nl/wms/sch/tasks/CallTask.java b/lms/hd/nladmin-system/src/main/java/org/nl/wms/sch/tasks/CallTask.java index 9a86434..bde749a 100644 --- a/lms/hd/nladmin-system/src/main/java/org/nl/wms/sch/tasks/CallTask.java +++ b/lms/hd/nladmin-system/src/main/java/org/nl/wms/sch/tasks/CallTask.java @@ -69,7 +69,7 @@ public class CallTask extends AbstractAcsTask { .getWQLObject("sch_base_point") .query("point_code = '" + nextPointCode + "'") .uniqueResult(0); - if (ObjectUtil.isEmpty(nextPointCode)) { + if (ObjectUtil.isEmpty(nextPoint)) { throw new BadRequestException("未找到该点位"); } diff --git a/lms/hd/nladmin-system/src/main/java/org/nl/wms/sch/tasks/P2PTask.java b/lms/hd/nladmin-system/src/main/java/org/nl/wms/sch/tasks/P2PTask.java new file mode 100644 index 0000000..2280198 --- /dev/null +++ b/lms/hd/nladmin-system/src/main/java/org/nl/wms/sch/tasks/P2PTask.java @@ -0,0 +1,119 @@ +package org.nl.wms.sch.tasks; + +import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.exception.BadRequestException; +import org.nl.modules.system.util.CodeUtil; +import org.nl.utils.SpringContextHolder; +import org.nl.wms.sch.manage.AbstractAcsTask; +import org.nl.wql.core.bean.WQLObject; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author zhangjiangwei + * @date 2023/03/22 08:59 + */ +@Service +@RequiredArgsConstructor +@Slf4j +public class P2PTask extends AbstractAcsTask { + + @Override + public void updateTaskStatus(JSONObject taskJSON, String status) { + SpringContextHolder.getBean(SendTask.class).updateTaskStatus(taskJSON, status); + } + + @Override + public void findStartPoint() { + + } + + @Override + public void findNextPoint() { + + } + + @Override + public String createTask(JSONObject param) { + // 起点 + String startPointCode = param.getString("start_point_code"); + + // 判断起点是否存在 + JSONObject startPoint = WQLObject + .getWQLObject("sch_base_point") + .query("point_code = '" + startPointCode + "'") + .uniqueResult(0); + if (ObjectUtil.isEmpty(startPoint)) { + throw new BadRequestException("未找到起点"); + } + + // 判断起点是否可用 + if (!"00".equals(startPoint.getString("lock_type"))) { + throw new BadRequestException(startPoint.getString("point_name") + "已被锁定"); + } + if ("00".equals(startPoint.getString("point_status"))) { + throw new BadRequestException("起点无货"); + } + + // 终点 + String nextPointCode = param.getString("next_point_code"); + + // 判断终点是否存在 + JSONObject nextPoint = WQLObject + .getWQLObject("sch_base_point") + .query("point_code = '" + nextPointCode + "'") + .uniqueResult(0); + if (ObjectUtil.isEmpty(nextPoint)) { + throw new BadRequestException("未找到终点"); + } + + // 判断终点是否可用 + if (!"00".equals(nextPoint.getString("lock_type"))) { + throw new BadRequestException(startPoint.getString("point_name") + "已被锁定"); + } + if (!"00".equals(nextPoint.getString("point_status"))) { + throw new BadRequestException("终点有货"); + } + + // 判断终点是否可以存放起点的物料 + List nextPointMaterial = WQLObject + .getWQLObject("sch_base_point_material") + .query("point_id = " + nextPoint.getString("point_id")) + .getResultJSONArray(0) + .stream() + .map(o -> ((JSONObject) o).getString("material")) + .collect(Collectors.toList()); + if (!nextPointMaterial.contains(startPoint.getString("current_material_type"))) { + throw new BadRequestException("终点不能存放起点的物料"); + } + + return SpringContextHolder.getBean(SendTask.class).createTaskRelated( + startPoint, + nextPoint, + param, + P2PTask.class, + "03", + CodeUtil.getNewCode("P2P_BILL_CODE"), + "0"); + } + + @Override + public void forceFinish(String task_id) { + SpringContextHolder.getBean(SendTask.class).forceFinish(task_id); + } + + @Override + public void pullBack(String task_id) { + + } + + @Override + public void cancel(String task_id) { + + } +} diff --git a/lms/hd/nladmin-system/src/main/java/org/nl/wms/sch/tasks/SendTask.java b/lms/hd/nladmin-system/src/main/java/org/nl/wms/sch/tasks/SendTask.java index 9aa8e48..fe3f2c2 100644 --- a/lms/hd/nladmin-system/src/main/java/org/nl/wms/sch/tasks/SendTask.java +++ b/lms/hd/nladmin-system/src/main/java/org/nl/wms/sch/tasks/SendTask.java @@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -174,7 +175,7 @@ public class SendTask extends AbstractAcsTask { .getWQLObject("sch_base_point") .query("point_code = '" + startPointCode + "'") .uniqueResult(0); - if (ObjectUtil.isEmpty(startPointCode)) { + if (ObjectUtil.isEmpty(startPoint)) { throw new BadRequestException("未找到该点位"); } @@ -195,20 +196,64 @@ public class SendTask extends AbstractAcsTask { } - // 查送料点位(出入库顺序升序) - JSONObject nextPoint; - String currentMaterialType = startPoint.getString("current_material_type"); - nextPoint = WQL + // 查询送料区域存放此物料的排 + JSONArray colArray = WQL .getWO("SEND_TASK") - .addParam("flag", "1") + .addParam("flag", "2") .addParam("region_id", nextRegionId) - .addParam("material_type", currentMaterialType) + .addParam("material_type", startPoint.getString("current_material_type")) .process() - .uniqueResult(0); + .getResultJSONArray(0); + + // 遍历该区域存放此物料的排寻找合适的点位 + JSONObject nextPoint = null; + for (Object o : colArray) { + String col = ((JSONObject) o).getString("col"); + + // 查找该排有货 或 已锁定的点位(出入库顺序降序) + JSONObject tempPoint = WQL + .getWO("SEND_TASK") + .addParam("flag", "3") + .addParam("region_id", nextRegionId) + .addParam("col", col) + .process() + .uniqueResult(0); + + // 如果该排没有有货 或 已锁定的点位,则取第一个点位 + if (ObjectUtil.isEmpty(tempPoint)) { + nextPoint = WQL + .getWO("SEND_TASK") + .addParam("flag", "1") + .addParam("region_id", nextRegionId) + .addParam("col", col) + .process() + .uniqueResult(0); + break; + } else { + // 如果该排有有货 或 已锁定的点位 + if (StrUtil.equals(tempPoint.getString("lock_type"), "00")) { + // 如果点位未锁定,则取他的下一个点位(出入库顺序升序) + nextPoint = WQL + .getWO("SEND_TASK") + .addParam("flag", "1") + .addParam("region_id", nextRegionId) + .addParam("col", col) + .addParam("seq", tempPoint.getString("seq")) + .process() + .uniqueResult(0); + + if (ObjectUtil.isNotEmpty(nextPoint)) { + // 如果下一个点位不为空,跳出循环,取这个点位 + break; + } + } + } + } if (ObjectUtil.isEmpty(nextPoint)) { throw new BadRequestException("未找到合适的送料点位"); } + assert nextPoint != null; return createTaskRelated( startPoint, nextPoint, diff --git a/lms/hd/nladmin-system/src/main/java/org/nl/wms/sch/wql/SEND_TASK.wql b/lms/hd/nladmin-system/src/main/java/org/nl/wms/sch/wql/SEND_TASK.wql index 6c39341..b81a599 100644 --- a/lms/hd/nladmin-system/src/main/java/org/nl/wms/sch/wql/SEND_TASK.wql +++ b/lms/hd/nladmin-system/src/main/java/org/nl/wms/sch/wql/SEND_TASK.wql @@ -16,7 +16,8 @@ 输入.flag TYPEAS s_string 输入.region_id TYPEAS s_string 输入.material_type TYPEAS s_string - 输入.col TYPEAS s_string + 输入.col TYPEAS s_string + 输入.seq TYPEAS s_string [临时表] --这边列出来的临时表就会在运行期动态创建 @@ -46,17 +47,17 @@ * FROM sch_base_point point - LEFT JOIN sch_base_point_material pm ON point.point_id = pm.point_id WHERE - point.point_status = '00' - AND point.lock_type = '00' - AND point.is_delete = '0' - AND point.is_used = '1' - OPTION 输入.region_id <> "" - point.region_id = 输入.region_id + is_delete = '0' + AND is_used = '1' + OPTION 输入.region_id <> "" + region_id = 输入.region_id ENDOPTION - OPTION 输入.material_type <> "" - pm.material = 输入.material_type + OPTION 输入.col <> "" + col = 输入.col + ENDOPTION + OPTION 输入.seq <> "" + seq > 输入.seq ENDOPTION ORDER BY seq ASC