From adbd4cad15588385f810d5397d26bfefda9e9bd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=B1=9F=E7=8E=AE?= Date: Mon, 7 Nov 2022 20:23:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86=E5=A4=A7=E9=83=A8?= =?UTF-8?q?=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/nl/wms/md/pb/VehicleStatus.java | 20 ++ .../org/nl/wms/pda/rest/PdaController.java | 91 +++++++ .../org/nl/wms/pda/service/PdaService.java | 25 ++ .../wms/pda/service/impl/PdaServiceImpl.java | 237 +++++++++++++++++ .../src/main/java/org/nl/wms/pda/wql/PDA.wql | 82 ++++++ .../org/nl/wms/sch/base/point/PointType.java | 20 ++ .../nl/wms/sch/task/CallEmptyVehicleTask.java | 112 +++++--- .../org/nl/wms/sch/task/CallMaterialTask.java | 208 +++++++++++++++ .../nl/wms/sch/task/SendFullVehicleTask.java | 248 ++++++++++++++++++ .../sch/task/SendResiduesMaterialTask.java | 248 ++++++++++++++++++ .../org/nl/wms/sch/task/util/TaskUtils.java | 61 +++-- .../sch/task/wql/SendEmptyVehicleTask.java | 229 ++++++++++++++++ .../java/org/nl/wms/sch/task/wql/TASK.wql | 20 +- .../java/org/nl/wms/util/CommonUtils.java | 12 + .../main/resources/config/application-dev.yml | 6 +- .../src/main/resources/logback-spring.xml | 2 +- .../src/views/wms/sch/point/index.vue | 2 +- 17 files changed, 1557 insertions(+), 66 deletions(-) create mode 100644 lms/nladmin-system/src/main/java/org/nl/wms/md/pb/VehicleStatus.java create mode 100644 lms/nladmin-system/src/main/java/org/nl/wms/pda/rest/PdaController.java create mode 100644 lms/nladmin-system/src/main/java/org/nl/wms/pda/service/PdaService.java create mode 100644 lms/nladmin-system/src/main/java/org/nl/wms/pda/service/impl/PdaServiceImpl.java create mode 100644 lms/nladmin-system/src/main/java/org/nl/wms/pda/wql/PDA.wql create mode 100644 lms/nladmin-system/src/main/java/org/nl/wms/sch/base/point/PointType.java create mode 100644 lms/nladmin-system/src/main/java/org/nl/wms/sch/task/CallMaterialTask.java create mode 100644 lms/nladmin-system/src/main/java/org/nl/wms/sch/task/SendFullVehicleTask.java create mode 100644 lms/nladmin-system/src/main/java/org/nl/wms/sch/task/SendResiduesMaterialTask.java create mode 100644 lms/nladmin-system/src/main/java/org/nl/wms/sch/task/wql/SendEmptyVehicleTask.java diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/md/pb/VehicleStatus.java b/lms/nladmin-system/src/main/java/org/nl/wms/md/pb/VehicleStatus.java new file mode 100644 index 0000000..ea50d14 --- /dev/null +++ b/lms/nladmin-system/src/main/java/org/nl/wms/md/pb/VehicleStatus.java @@ -0,0 +1,20 @@ +package org.nl.wms.md.pb; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * @author 张江玮 + * @date 2022/11/04 20:12 + */ +@AllArgsConstructor +@Getter +public enum VehicleStatus { + + EMPTY("1", "空载具"), + HAS_MATERIAL("2", "有物料"); + + private final String code; + + private final String name; +} diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/pda/rest/PdaController.java b/lms/nladmin-system/src/main/java/org/nl/wms/pda/rest/PdaController.java new file mode 100644 index 0000000..444b54b --- /dev/null +++ b/lms/nladmin-system/src/main/java/org/nl/wms/pda/rest/PdaController.java @@ -0,0 +1,91 @@ +package org.nl.wms.pda.rest; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.modules.logging.annotation.Log; +import org.nl.wms.pda.service.PdaService; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author 张江玮 + * @date 2022/11/04 18:16 + */ +@RestController +@RequiredArgsConstructor +@Api(tags = "手持接口") +@RequestMapping("/api/pda") +@Slf4j +public class PdaController { + + private final PdaService pdaService; + + @PostMapping("/region") + @Log("查询所有区域") + @ApiOperation("查询所有区域") + public ResponseEntity region() { + return new ResponseEntity<>(pdaService.region(), HttpStatus.OK); + } + + @PostMapping("/point") + @Log("根据区域查询点位") + @ApiOperation("根据区域查询点位") + public ResponseEntity point(@RequestBody JSONObject param) { + return new ResponseEntity<>(pdaService.point(param.getString("region_id")), HttpStatus.OK); + } + + @PostMapping("/vmByPoint") + @Log("查询点位上的载具及组盘信息") + @ApiOperation("查询点位上的载具及组盘信息") + public ResponseEntity vmByPoint(@RequestBody JSONObject param) { + return new ResponseEntity<>(pdaService.vmByPoint(param.getString("point_id")), HttpStatus.OK); + } + + @PostMapping("/bindPoint") + @Log("点位载具绑定") + @ApiOperation("点位载具绑定") + public ResponseEntity bindPoint(@RequestBody JSONObject param) { + pdaService.bindPoint(param.getString("point_id"), param.getString("vehicle_code")); + + return this.success(); + } + + @PostMapping("/vm") + @Log("组盘") + @ApiOperation("组盘") + public ResponseEntity vm(@RequestBody JSONObject param) { + pdaService.vm(param.getString("vehicle_code"), param.getJSONArray("material")); + + return this.success(); + } + + @PostMapping("/vmByVehicle") + @Log("查询载具及组盘信息") + @ApiOperation("查询载具及组盘信息") + public ResponseEntity vmByVehicle(@RequestBody JSONObject param) { + return new ResponseEntity<>(pdaService.vmByVehicle(param.getString("vehicle_code")), HttpStatus.OK); + } + + @PostMapping("/outbound") + @Log("确认出库") + @ApiOperation("确认出库") + public ResponseEntity outbound(@RequestBody JSONObject param) { + pdaService.outbound(param.getString("vehicle_code"), param.getJSONArray("vm")); + + return this.success(); + } + + private ResponseEntity success() { + JSONObject result = new JSONObject(); + result.put("message", "操作成功"); + return new ResponseEntity<>(result, HttpStatus.OK); + } +} diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/pda/service/PdaService.java b/lms/nladmin-system/src/main/java/org/nl/wms/pda/service/PdaService.java new file mode 100644 index 0000000..4701cec --- /dev/null +++ b/lms/nladmin-system/src/main/java/org/nl/wms/pda/service/PdaService.java @@ -0,0 +1,25 @@ +package org.nl.wms.pda.service; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; + +/** + * @author 张江玮 + * @date 2022/11/04 18:25 + */ +public interface PdaService { + + JSONArray region(); + + JSONArray point(String regionId); + + JSONObject vmByPoint(String pointId); + + void bindPoint(String pointId, String vehicleCode); + + void vm(String vehicleCode, JSONArray materials); + + JSONObject vmByVehicle(String vehicleCode); + + void outbound(String vehicleCode, JSONArray materials); +} diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/pda/service/impl/PdaServiceImpl.java b/lms/nladmin-system/src/main/java/org/nl/wms/pda/service/impl/PdaServiceImpl.java new file mode 100644 index 0000000..bb664e6 --- /dev/null +++ b/lms/nladmin-system/src/main/java/org/nl/wms/pda/service/impl/PdaServiceImpl.java @@ -0,0 +1,237 @@ +package org.nl.wms.pda.service.impl; + +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; +import org.nl.modules.common.exception.BadRequestException; +import org.nl.modules.wql.WQL; +import org.nl.modules.wql.core.bean.WQLObject; +import org.nl.wms.md.pb.VehicleStatus; +import org.nl.wms.pda.service.PdaService; +import org.nl.wms.sch.base.point.LockType; +import org.nl.wms.sch.base.point.PointStatus; +import org.nl.wms.sch.base.point.PointType; +import org.nl.wms.util.CommonUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + * @author 张江玮 + * @date 2022/11/04 18:25 + */ +@Service +@RequiredArgsConstructor +@Slf4j +public class PdaServiceImpl implements PdaService { + + + @Override + public JSONArray region() { + return WQL.getWO("PDA").addParam("flag", "1").process().getResultJSONArray(0); + } + + @Override + public JSONArray point(String regionId) { + JSONArray points = WQL + .getWO("PDA") + .addParam("flag", "2") + .addParam("region_id", regionId) + .process() + .getResultJSONArray(0); + for (Object o : points) { + JSONObject point = (JSONObject) o; + if (StrUtil.equals(point.getString("lock_type"), LockType.TASK_LOCKED.getCode())) { + point.put("status", "3"); + } + } + + return points; + } + + @Override + public JSONObject vmByPoint(String pointId) { + JSONObject result = new JSONObject(); + + JSONObject point = WQLObject + .getWQLObject("sch_base_point") + .query("point_id = " + pointId) + .uniqueResult(0); + + if (StrUtil.equals(point.getString("point_status"), PointStatus.HAS_VEHICLE.getCode())) { + String vehicleCode = point.getString("vehicle_code"); + result.put("vehicle_code", vehicleCode); + + JSONArray detail = WQL + .getWO("PDA") + .addParam("flag", "3") + .addParam("vehicle_code", vehicleCode) + .process() + .getResultJSONArray(0); + result.put("detail", detail); + } + + return result; + } + + @Transactional(rollbackFor = Exception.class) + @Override + public void bindPoint(String pointId, String vehicleCode) { + WQLObject pointTable = WQLObject.getWQLObject("sch_base_point"); + JSONObject point = pointTable + .query("point_id = " + pointId) + .uniqueResult(0); + if (StrUtil.equals(point.getString("lock_type"), LockType.TASK_LOCKED.getCode())) { + throw new BadRequestException("该点位存在任务"); + } + + WQLObject ivtTable = WQLObject.getWQLObject("st_ivt_structivt"); + if (StrUtil.isNotEmpty(vehicleCode)) { + JSONObject vehicle = WQLObject.getWQLObject("md_pb_vehicle").query("vehicle_code = " + vehicleCode).uniqueResult(0); + if (ObjectUtil.isEmpty(vehicle)) { + throw new BadRequestException("该载具号不存在,请从组盘功能添加"); + } + + JSONObject existPoint = pointTable.query("vehicle_code = " + vehicleCode).uniqueResult(0); + if (ObjectUtil.isNotEmpty(existPoint) && !StrUtil.equals(pointId, existPoint.getString("point_id"))) { + throw new BadRequestException("该载具号存放于" + existPoint.getString("point_name")); + } + + if (StrUtil.equals(vehicle.getString("vehicle_status"), VehicleStatus.HAS_MATERIAL.getCode()) + && StrUtil.equals(point.getString("point_type"), PointType.STORAGE_LOCATION.getCode())) { + JSONObject vm = WQLObject + .getWQLObject("st_ivt_vehicle_material") + .query("vehicle_id = " + vehicle.getString("vehicle_id"), "create_time ASC") + .uniqueResult(0); + + JSONObject ivt = new JSONObject(); + ivt.put("stockrecord_id", IdUtil.getSnowflake(1L, 1L).nextId()); + ivt.put("point_id", pointId); + ivt.put("instorage_time", vm.getString("create_time")); + + ivtTable.insert(ivt); + } + + point.put("point_status", PointStatus.HAS_VEHICLE.getCode()); + point.put("vehicle_code", vehicleCode); + } else { + ivtTable.delete("point_id = " + pointId); + + point.put("point_status", PointStatus.EMPTY.getCode()); + point.put("vehicle_code", ""); + } + + + CommonUtils.addUpdateColum(point); + pointTable.update(point); + } + + @Transactional(rollbackFor = Exception.class) + @Override + public void vm(String vehicleCode, JSONArray materials) { + WQLObject vehicleTable = WQLObject.getWQLObject("md_pb_vehicle"); + JSONObject vehicle = vehicleTable.query("vehicle_code = " + vehicleCode).uniqueResult(0); + if (ObjectUtil.isEmpty(vehicle)) { + vehicle = new JSONObject(); + vehicle.put("vehicle_id", IdUtil.getSnowflake(1L, 1L).nextId()); + vehicle.put("vehicle_code", vehicleCode); + vehicle.put("vehicle_status", VehicleStatus.EMPTY.getCode()); + CommonUtils.addCommonColum(vehicle); + vehicleTable.insert(vehicle); + } + String vehicleId = vehicle.getString("vehicle_id"); + + if (ObjectUtil.isNotEmpty(materials)) { + WQLObject materialTable = WQLObject.getWQLObject("md_me_materialbase"); + WQLObject vmTable = WQLObject.getWQLObject("st_ivt_vehicle_material"); + for (Object o : materials) { + String code = ((JSONObject) o).getString("code"); + Double qty = ((JSONObject) o).getDouble("qty"); + + String materialCode = code.substring(0, 8); + String materialBatch = code.substring(8, 18); + + JSONObject material = materialTable + .query("material_code = " + materialCode) + .uniqueResult(0); + if (ObjectUtil.isEmpty(material)) { + throw new BadRequestException("条码为" + code + "的物料信息不存在,请从后台管理界面添加"); + } + + JSONObject vm = new JSONObject(); + vm.put("vm_id", IdUtil.getSnowflake(1L, 1L).nextId()); + vm.put("vehicle_id", vehicleId); + vm.put("material_id", material.getString("material_id")); + vm.put("material_qty", qty); + vm.put("material_batch", materialBatch); + CommonUtils.addCreateColum(vm); + vmTable.insert(vm); + } + + vehicle.put("vehicle_status", VehicleStatus.HAS_MATERIAL.getCode()); + CommonUtils.addUpdateColum(vehicle); + vehicleTable.update(vehicle); + } + } + + @Override + public JSONObject vmByVehicle(String vehicleCode) { + JSONObject result = new JSONObject(); + JSONArray detail = WQL + .getWO("PDA") + .addParam("flag", "3") + .addParam("vehicle_code", vehicleCode) + .process() + .getResultJSONArray(0); + result.put("detail", detail); + + return result; + } + + @Transactional(rollbackFor = Exception.class) + @Override + public void outbound(String vehicleCode, JSONArray materials) { + WQLObject vehicleTable = WQLObject.getWQLObject("md_pb_vehicle"); + JSONObject vehicle = vehicleTable.query("vehicle_code = " + vehicleCode).uniqueResult(0); + String vehicleId = vehicle.getString("vehicle_id"); + + WQLObject vmTable = WQLObject.getWQLObject("st_ivt_vehicle_material"); + JSONObject oldVm = vmTable.query("vehicle_id = " + vehicleId, "create_time ASC").uniqueResult(0); + vmTable.delete("vehicle_id = " + vehicleId); + + if (ObjectUtil.isNotEmpty(materials)) { + WQLObject materialTable = WQLObject.getWQLObject("md_me_materialbase"); + for (Object o : materials) { + JSONObject material = (JSONObject) o; + String materialCode = material.getString("material_code"); + String materialQty = material.getString("material_qty"); + String materialBatch = material.getString("batch"); + + String materialId = materialTable + .query("material_code = " + materialCode) + .uniqueResult(0) + .getString("material_id"); + + JSONObject vm = new JSONObject(); + vm.put("vm_id", IdUtil.getSnowflake(1L, 1L).nextId()); + vm.put("vehicle_id", vehicleId); + vm.put("material_id", materialId); + vm.put("material_qty", materialQty); + vm.put("material_batch", materialBatch); + CommonUtils.addCreateColum(vm); + vm.put("create_time", oldVm.getString("create_time")); + vmTable.insert(vm); + } + + vehicle.put("vehicle_status", VehicleStatus.HAS_MATERIAL.getCode()); + } else { + vehicle.put("vehicle_status", VehicleStatus.EMPTY.getCode()); + } + + CommonUtils.addUpdateColum(vehicle); + vehicleTable.update(vehicle); + } +} diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/pda/wql/PDA.wql b/lms/nladmin-system/src/main/java/org/nl/wms/pda/wql/PDA.wql new file mode 100644 index 0000000..5a67c5e --- /dev/null +++ b/lms/nladmin-system/src/main/java/org/nl/wms/pda/wql/PDA.wql @@ -0,0 +1,82 @@ +[交易说明] + 交易名: 任务分页查询 + 所属模块: + 功能简述: + 版权所有: + 表引用: + 版本经历: + +[数据库] + --指定数据库,为空采用默认值,默认为db.properties中列出的第一个库 + +[IO定义] + ################################################# + ## 表字段对应输入参数 + ################################################# + 输入.flag TYPEAS s_string + 输入.region_id TYPEAS s_string + 输入.vehicle_code TYPEAS s_string + +[临时表] + --这边列出来的临时表就会在运行期动态创建 + +[临时变量] + --所有中间过程变量均可在此处定义 + +[业务过程] + + ########################################## + # 1、输入输出检查 # + ########################################## + + + ########################################## + # 2、主过程前处理 # + ########################################## + + + ########################################## + # 3、业务主过程 # + ########################################## + + IF 输入.flag = "1" + QUERY + SELECT + region_id, + region_name + FROM + sch_base_region + ENDSELECT + ENDQUERY + ENDIF + + IF 输入.flag = "2" + QUERY + SELECT + point_id, + point_name, + point_status AS `status`, + lock_type + FROM + sch_base_point + WHERE + region_id = 输入.region_id + ENDQUERY + ENDIF + + IF 输入.flag = "3" + QUERY + SELECT + material.material_code, + material.material_name, + vm.material_qty, + vm.material_batch AS batch + FROM + st_ivt_vehicle_material vm + LEFT JOIN md_pb_vehicle vehicle ON vm.vehicle_id = vehicle.vehicle_id + LEFT JOIN md_me_materialbase material ON vm.material_id = material.material_id + WHERE + vehicle.vehicle_code = 输入.vehicle_code + ENDSELECT + ENDQUERY + ENDIF diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/sch/base/point/PointType.java b/lms/nladmin-system/src/main/java/org/nl/wms/sch/base/point/PointType.java new file mode 100644 index 0000000..80dc496 --- /dev/null +++ b/lms/nladmin-system/src/main/java/org/nl/wms/sch/base/point/PointType.java @@ -0,0 +1,20 @@ +package org.nl.wms.sch.base.point; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * @author 张江玮 + * @date 2022/11/07 8:49 + */ +@AllArgsConstructor +@Getter +public enum PointType { + + POINT("1", "点位"), + STORAGE_LOCATION("2", "库位"); + + private final String code; + + private final String name; +} diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/sch/task/CallEmptyVehicleTask.java b/lms/nladmin-system/src/main/java/org/nl/wms/sch/task/CallEmptyVehicleTask.java index b35c271..d09b5a0 100644 --- a/lms/nladmin-system/src/main/java/org/nl/wms/sch/task/CallEmptyVehicleTask.java +++ b/lms/nladmin-system/src/main/java/org/nl/wms/sch/task/CallEmptyVehicleTask.java @@ -2,9 +2,9 @@ package org.nl.wms.sch.task; 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.NoArgsConstructor; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.nl.modules.common.exception.BadRequestException; @@ -12,6 +12,7 @@ import org.nl.modules.system.util.CodeUtil; import org.nl.modules.wql.WQL; import org.nl.modules.wql.core.bean.WQLObject; import org.nl.wms.sch.base.point.LockType; +import org.nl.wms.sch.base.point.PointStatus; import org.nl.wms.sch.manage.AbstractAcsTask; import org.nl.wms.sch.task.dto.AcsTaskDTO; import org.nl.wms.sch.task.util.TaskUtils; @@ -29,7 +30,7 @@ import java.util.List; * @date 2022/11/01 10:12 */ @Service -@NoArgsConstructor +@RequiredArgsConstructor @Slf4j public class CallEmptyVehicleTask extends AbstractAcsTask { @@ -42,32 +43,7 @@ public class CallEmptyVehicleTask extends AbstractAcsTask { */ @Override public List addTask() { - JSONArray tasks = WQLObject - .getWQLObject("sch_base_task") - .query("task_status = " + TaskStatus.START_AND_END.getCode() + " AND handle_class = " + THIS_CLASS_NAME) - .getResultJSONArray(0); - - ArrayList acsTasks = new ArrayList<>(); - for (Object o : tasks) { - JSONObject task = (JSONObject) o; - - AcsTaskDTO acsTask = AcsTaskDTO - .builder() - .task_id(task.getString("task_id")) - .task_code(task.getString("task_code")) - .task_type(task.getString("acs_task_type")) - .start_device_code(task.getString("point_code1")) - .next_device_code(task.getString("point_code2")) - .vehicle_code(task.getString("vehicle_code")) - .vehicle_type(task.getString("vehicle_type")) - .priority(task.getString("priority")) - .remark(task.getString("remark")) - .build(); - - acsTasks.add(acsTask); - } - - return acsTasks; + return TaskUtils.addTask(THIS_CLASS_NAME); } /** @@ -78,7 +54,28 @@ public class CallEmptyVehicleTask extends AbstractAcsTask { */ @Override public void updateTaskStatus(JSONObject taskJSON, String status) { + WQLObject taskTable = WQLObject.getWQLObject("sch_base_task"); + String taskCode = taskJSON.getString("task_code"); + JSONObject task = taskTable + .query("task_code = " + taskCode) + .uniqueResult(0); + if (ObjectUtil.isEmpty(task)) { + throw new BadRequestException("未找到任务号为" + taskCode + "的任务"); + } + + if (StrUtil.equals(status, "0")) { + this.cancel(task.getString("task_id")); + } + + if (StrUtil.equals(status, TaskStatus.EXECUTING.getCode())) { + task.put("task", TaskStatus.EXECUTING.getCode()); + CommonUtils.addAdminUpdateColum(task); + taskTable.update(task); + } + if (StrUtil.equals(status, TaskStatus.FINISHED.getCode())) { + this.finishTask(task, TaskFinishedType.AUTO); + } } /** @@ -110,7 +107,7 @@ public class CallEmptyVehicleTask extends AbstractAcsTask { CommonUtils.addCommonColum(task); WQLObject.getWQLObject("sch_base_task").insert(task); - point.put("lock_type", "2"); + point.put("lock_type", LockType.TASK_LOCKED.getCode()); CommonUtils.addUpdateColum(point); pointTable.update(point); @@ -125,7 +122,11 @@ public class CallEmptyVehicleTask extends AbstractAcsTask { @Transactional(rollbackFor = Exception.class) @Override public void forceFinish(String taskId) { - + JSONObject task = WQLObject + .getWQLObject("sch_base_task") + .query("task_id = " + taskId) + .uniqueResult(0); + this.finishTask(task, TaskFinishedType.MANUAL); } /** @@ -133,9 +134,29 @@ public class CallEmptyVehicleTask extends AbstractAcsTask { * * @param taskId 任务标识 */ + @Transactional(rollbackFor = Exception.class) @Override public void cancel(String taskId) { + WQLObject taskTable = WQLObject.getWQLObject("sch_base_task"); + JSONObject task = taskTable + .query("task_id = " + taskId) + .uniqueResult(0); + taskTable.delete(task); + + WQLObject pointTable = WQLObject.getWQLObject("sch_base_point"); + JSONObject startPoint = pointTable + .query("task_code = " + task.getString("point_code1")) + .uniqueResult(0); + JSONObject nextPoint = pointTable + .query("task_code = " + task.getString("point_code2")) + .uniqueResult(0); + startPoint.put("lock_type", LockType.UNLOCKED.getCode()); + CommonUtils.addAdminUpdateColum(startPoint); + pointTable.update(startPoint); + nextPoint.put("lock_type", LockType.UNLOCKED.getCode()); + CommonUtils.addAdminUpdateColum(nextPoint); + pointTable.update(nextPoint); } /** @@ -161,13 +182,42 @@ public class CallEmptyVehicleTask extends AbstractAcsTask { task.put("task_status", TaskStatus.START_AND_END.getCode()); task.put("point_code1", point.getString("point_code")); task.put("vehicle_code", point.getString("vehicle_code")); - CommonUtils.addUpdateColum(task); + CommonUtils.addAdminUpdateColum(task); taskTable.update(task); JSONObject lockPoint = new JSONObject(); lockPoint.put("lock_type", LockType.TASK_LOCKED.getCode()); + CommonUtils.addAdminUpdateColum(lockPoint); WQLObject.getWQLObject("sch_base_point").update(lockPoint, "point_id = " + point.getString("point_id")); } } } + + @Transactional(rollbackFor = Exception.class) + public void finishTask(JSONObject task, TaskFinishedType taskFinishedType) { + task.put("finished_type", taskFinishedType.getCode()); + task.put("task_status", TaskStatus.FINISHED.getCode()); + CommonUtils.addAdminUpdateColum(task); + WQLObject.getWQLObject("sch_base_task").update(task); + + WQLObject pointTable = WQLObject.getWQLObject("sch_base_point"); + JSONObject startPoint = pointTable + .query("task_code = " + task.getString("point_code1")) + .uniqueResult(0); + JSONObject nextPoint = pointTable + .query("task_code = " + task.getString("point_code2")) + .uniqueResult(0); + + nextPoint.put("point_status", PointStatus.HAS_VEHICLE.getCode()); + nextPoint.put("lock_type", LockType.UNLOCKED.getCode()); + nextPoint.put("vehicle_code", startPoint.getString("vehicle_code")); + CommonUtils.addAdminUpdateColum(nextPoint); + pointTable.update(nextPoint); + + startPoint.put("point_status", PointStatus.EMPTY.getCode()); + startPoint.put("lock_type", LockType.UNLOCKED.getCode()); + startPoint.put("vehicle_code", ""); + CommonUtils.addAdminUpdateColum(startPoint); + pointTable.update(startPoint); + } } diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/sch/task/CallMaterialTask.java b/lms/nladmin-system/src/main/java/org/nl/wms/sch/task/CallMaterialTask.java new file mode 100644 index 0000000..a8affe3 --- /dev/null +++ b/lms/nladmin-system/src/main/java/org/nl/wms/sch/task/CallMaterialTask.java @@ -0,0 +1,208 @@ +package org.nl.wms.sch.task; + +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.modules.common.exception.BadRequestException; +import org.nl.modules.system.util.CodeUtil; +import org.nl.modules.wql.core.bean.WQLObject; +import org.nl.wms.sch.base.point.LockType; +import org.nl.wms.sch.base.point.PointStatus; +import org.nl.wms.sch.base.point.PointType; +import org.nl.wms.sch.manage.AbstractAcsTask; +import org.nl.wms.sch.task.dto.AcsTaskDTO; +import org.nl.wms.sch.task.util.TaskUtils; +import org.nl.wms.util.CommonUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +/** + * 纽迪希亚3呼叫原料出库任务 + * + * @author 张江玮 + * @date 2022/11/07 20:03 + */ +@Service +@RequiredArgsConstructor +@Slf4j +public class CallMaterialTask extends AbstractAcsTask { + + private static final String THIS_CLASS_NAME = CallMaterialTask.class.getName(); + + /** + * 添加任务进行下发 + * + * @return + */ + @Override + public List addTask() { + return TaskUtils.addTask(THIS_CLASS_NAME); + } + + /** + * @param taskJSON 代表一条任务对象 + * @param status 代表wcs任务完成状态: //0:acs,取消,:执行中,2:完成 + * @return + * @discription wcs请求wms任务完成状态反馈接口, 比如agv从a点往b点走。生成任务的时候绑定b的物料信息,任务完成的时候,清除a的物料信息 + * @author ldjun + * @created 2019年4月17日 下午8:51:50 + */ + @Override + public void updateTaskStatus(JSONObject taskJSON, String status) { + WQLObject taskTable = WQLObject.getWQLObject("sch_base_task"); + String taskCode = taskJSON.getString("task_code"); + JSONObject task = taskTable + .query("task_code = " + taskCode) + .uniqueResult(0); + if (ObjectUtil.isEmpty(task)) { + throw new BadRequestException("未找到任务号为" + taskCode + "的任务"); + } + + if (StrUtil.equals(status, "0")) { + this.cancel(task.getString("task_id")); + } + + if (StrUtil.equals(status, TaskStatus.EXECUTING.getCode())) { + task.put("task", TaskStatus.EXECUTING.getCode()); + CommonUtils.addAdminUpdateColum(task); + taskTable.update(task); + } + + if (StrUtil.equals(status, TaskStatus.FINISHED.getCode())) { + this.finishTask(task, TaskFinishedType.AUTO); + } + } + + /** + * @param param 创建任务需要的参数 + * @return 返回任务标识 + */ + @Override + public String createTask(JSONObject param) { + WQLObject pointTable = WQLObject.getWQLObject("sch_base_point"); + JSONObject nextPoint = pointTable + .query("point_id = " + param.getString("point_id")) + .uniqueResult(0); + if (ObjectUtil.isEmpty(nextPoint)) { + throw new BadRequestException("终点不存在"); + } + + JSONObject startPoint = pointTable + .query("vehicle_code = " + param.getString("vehicle_code")) + .uniqueResult(0); + if (ObjectUtil.isEmpty(startPoint)) { + throw new BadRequestException("指定的料车点位不存在"); + } + + JSONObject task = new JSONObject(); + String taskId = IdUtil.getSnowflake(1L, 1L).nextIdStr(); + task.put("task_id", taskId); + task.put("task_code", CodeUtil.getNewCode("TASK_CODE")); + task.put("task_type", TaskType.CALL_MATERIAL.getCode()); + task.put("task_status", TaskStatus.START_AND_END.getCode()); + task.put("point_code1", startPoint.getString("point_code")); + task.put("point_code2", nextPoint.getString("point_code")); + task.put("vehicle_code", startPoint.getString("vehicle_code")); + task.put("handle_class", THIS_CLASS_NAME); + task.put("create_mode", CreateMode.SCCJ.getCode()); + CommonUtils.addCommonColum(task); + WQLObject.getWQLObject("sch_base_task").insert(task); + + startPoint.put("lock_type", LockType.TASK_LOCKED.getCode()); + CommonUtils.addUpdateColum(startPoint); + pointTable.update(startPoint); + + nextPoint.put("lock_type", LockType.TASK_LOCKED.getCode()); + CommonUtils.addUpdateColum(nextPoint); + pointTable.update(nextPoint); + + return taskId; + } + + /** + * @param taskId 任务标识 + * @return + * @discription 强制结束完成任务 + * @author ldjun + * @created 2020年6月19日 上午10:34:58 + */ + @Override + public void forceFinish(String taskId) { + JSONObject task = WQLObject + .getWQLObject("sch_base_task") + .query("task_id = " + taskId) + .uniqueResult(0); + this.finishTask(task, TaskFinishedType.MANUAL); + } + + /** + * 取消任务,货物搬回原点 + * + * @param taskId + */ + @Override + public void cancel(String taskId) { + WQLObject taskTable = WQLObject.getWQLObject("sch_base_task"); + JSONObject task = taskTable + .query("task_id = " + taskId) + .uniqueResult(0); + taskTable.delete(task); + + WQLObject pointTable = WQLObject.getWQLObject("sch_base_point"); + JSONObject startPoint = pointTable + .query("task_code = " + task.getString("point_code1")) + .uniqueResult(0); + JSONObject nextPoint = pointTable + .query("task_code = " + task.getString("point_code2")) + .uniqueResult(0); + + startPoint.put("lock_type", LockType.UNLOCKED.getCode()); + CommonUtils.addAdminUpdateColum(startPoint); + pointTable.update(startPoint); + nextPoint.put("lock_type", LockType.UNLOCKED.getCode()); + CommonUtils.addAdminUpdateColum(nextPoint); + pointTable.update(nextPoint); + } + + @Transactional(rollbackFor = Exception.class) + public void finishTask(JSONObject task, TaskFinishedType taskFinishedType) { + task.put("finished_type", taskFinishedType.getCode()); + task.put("task_status", TaskStatus.FINISHED.getCode()); + CommonUtils.addAdminUpdateColum(task); + WQLObject.getWQLObject("sch_base_task").update(task); + + WQLObject pointTable = WQLObject.getWQLObject("sch_base_point"); + JSONObject startPoint = pointTable + .query("task_code = " + task.getString("point_code1")) + .uniqueResult(0); + JSONObject nextPoint = pointTable + .query("task_code = " + task.getString("point_code2")) + .uniqueResult(0); + + if (StrUtil.equals(startPoint.getString("point_type"), PointType.STORAGE_LOCATION.getCode())) { + JSONObject vehicle = WQLObject + .getWQLObject("md_pb_vehicle") + .query("vehicle_code = " + startPoint.getString("vehicle_code")) + .uniqueResult(0); + + WQLObject.getWQLObject("st_ivt_structivt").delete("vehicle_id = " + vehicle.getString("vehicle_id")); + } + + nextPoint.put("point_status", PointStatus.HAS_VEHICLE.getCode()); + nextPoint.put("lock_type", LockType.UNLOCKED.getCode()); + nextPoint.put("vehicle_code", startPoint.getString("vehicle_code")); + CommonUtils.addAdminUpdateColum(nextPoint); + pointTable.update(nextPoint); + + startPoint.put("point_status", PointStatus.EMPTY.getCode()); + startPoint.put("lock_type", LockType.UNLOCKED.getCode()); + startPoint.put("vehicle_code", ""); + CommonUtils.addAdminUpdateColum(startPoint); + pointTable.update(startPoint); + } +} diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/sch/task/SendFullVehicleTask.java b/lms/nladmin-system/src/main/java/org/nl/wms/sch/task/SendFullVehicleTask.java new file mode 100644 index 0000000..44364dc --- /dev/null +++ b/lms/nladmin-system/src/main/java/org/nl/wms/sch/task/SendFullVehicleTask.java @@ -0,0 +1,248 @@ +package org.nl.wms.sch.task; + +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; +import org.nl.modules.common.exception.BadRequestException; +import org.nl.modules.system.util.CodeUtil; +import org.nl.modules.wql.WQL; +import org.nl.modules.wql.core.bean.WQLObject; +import org.nl.wms.sch.base.point.LockType; +import org.nl.wms.sch.base.point.PointStatus; +import org.nl.wms.sch.base.point.PointType; +import org.nl.wms.sch.manage.AbstractAcsTask; +import org.nl.wms.sch.task.dto.AcsTaskDTO; +import org.nl.wms.sch.task.util.TaskUtils; +import org.nl.wms.util.CommonUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +/** + * 纽迪希亚3送满料车任务 + * + * @author 张江玮 + * @date 2022/11/07 8:59 + */ +@Service +@RequiredArgsConstructor +@Slf4j +public class SendFullVehicleTask extends AbstractAcsTask { + + private static final String THIS_CLASS_NAME = SendFullVehicleTask.class.getName(); + + /** + * 添加任务进行下发 + * + * @return 所有这个类处理的已确认起点和终点任务 + */ + @Override + public List addTask() { + return TaskUtils.addTask(THIS_CLASS_NAME); + } + + /** + * @param taskJSON 代表一条任务对象 + * @param status 代表wcs任务完成状态: //0:acs,取消,:执行中,2:完成 + * @discription wcs请求wms任务完成状态反馈接口, 比如agv从a点往b点走。生成任务的时候绑定b的物料信息,任务完成的时候,清除a的物料信息 + * @author ldjun + * @created 2019年4月17日 下午8:51:50 + */ + @Transactional(rollbackFor = Exception.class) + @Override + public void updateTaskStatus(JSONObject taskJSON, String status) { + WQLObject taskTable = WQLObject.getWQLObject("sch_base_task"); + String taskCode = taskJSON.getString("task_code"); + JSONObject task = taskTable + .query("task_code = " + taskCode) + .uniqueResult(0); + if (ObjectUtil.isEmpty(task)) { + throw new BadRequestException("未找到任务号为" + taskCode + "的任务"); + } + + if (StrUtil.equals(status, "0")) { + this.cancel(task.getString("task_id")); + } + + if (StrUtil.equals(status, TaskStatus.EXECUTING.getCode())) { + task.put("task", TaskStatus.EXECUTING.getCode()); + CommonUtils.addAdminUpdateColum(task); + taskTable.update(task); + } + + if (StrUtil.equals(status, TaskStatus.FINISHED.getCode())) { + this.finishTask(task, TaskFinishedType.AUTO); + } + } + + /** + * @param param 创建任务需要的参数 + * + * @return 返回任务标识 + */ + @Transactional(rollbackFor = Exception.class) + @Override + public String createTask(JSONObject param) { + WQLObject pointTable = WQLObject.getWQLObject("sch_base_point"); + JSONObject point = pointTable + .query("point_id = " + param.getString("point_id")) + .uniqueResult(0); + if (ObjectUtil.isEmpty(point)) { + throw new BadRequestException("点位不存在"); + } + + JSONObject task = new JSONObject(); + String taskId = IdUtil.getSnowflake(1L, 1L).nextIdStr(); + task.put("task_id", taskId); + task.put("task_code", CodeUtil.getNewCode("TASK_CODE")); + task.put("task_type", TaskType.SEND_FULL_VEHICLE.getCode()); + task.put("task_status", TaskStatus.SURE_START.getCode()); + task.put("point_code1", point.getString("point_code")); + task.put("vehicle_code", point.getString("vehicle_code")); + task.put("handle_class", THIS_CLASS_NAME); + task.put("create_mode", CreateMode.SCCJ.getCode()); + CommonUtils.addCommonColum(task); + WQLObject.getWQLObject("sch_base_task").insert(task); + + point.put("lock_type", LockType.TASK_LOCKED.getCode()); + CommonUtils.addUpdateColum(point); + pointTable.update(point); + + return taskId; + } + + /** + * @param taskId 任务标识 + * @discription 强制结束完成任务 + * @author ldjun + * @created 2020年6月19日 上午10:34:58 + */ + @Transactional(rollbackFor = Exception.class) + @Override + public void forceFinish(String taskId) { + JSONObject task = WQLObject + .getWQLObject("sch_base_task") + .query("task_id = " + taskId) + .uniqueResult(0); + this.finishTask(task, TaskFinishedType.MANUAL); + } + + /** + * 取消任务,货物搬回原点 + * + * @param taskId 任务标识 + */ + @Transactional(rollbackFor = Exception.class) + @Override + public void cancel(String taskId) { + WQLObject taskTable = WQLObject.getWQLObject("sch_base_task"); + JSONObject task = taskTable + .query("task_id = " + taskId) + .uniqueResult(0); + taskTable.delete(task); + + WQLObject pointTable = WQLObject.getWQLObject("sch_base_point"); + JSONObject startPoint = pointTable + .query("task_code = " + task.getString("point_code1")) + .uniqueResult(0); + JSONObject nextPoint = pointTable + .query("task_code = " + task.getString("point_code2")) + .uniqueResult(0); + + startPoint.put("lock_type", LockType.UNLOCKED.getCode()); + CommonUtils.addAdminUpdateColum(startPoint); + pointTable.update(startPoint); + nextPoint.put("lock_type", LockType.UNLOCKED.getCode()); + CommonUtils.addAdminUpdateColum(nextPoint); + pointTable.update(nextPoint); + } + + /** + * @return + * @discription 确定下一点位 + * @author ldjun + * @created 2020年6月12日 下午6:01:06 + */ + @Transactional(rollbackFor = Exception.class) + @Override + public void findNextPoint() { + WQLObject taskTable = WQLObject.getWQLObject("sch_base_task"); + JSONArray tasks = taskTable + .query("task_status = " + TaskStatus.SURE_START.getCode() + " AND handle_class = " + THIS_CLASS_NAME) + .getResultJSONArray(0); + + for (Object o : tasks) { + JSONObject point = WQL.getWO("TASK") + .addParam("flag", "2") + .process() + .uniqueResult(0); + + if (ObjectUtil.isNotEmpty(point)) { + JSONObject task = (JSONObject) o; + + task.put("task_status", TaskStatus.START_AND_END.getCode()); + task.put("point_code2", point.getString("point_code")); + CommonUtils.addAdminUpdateColum(task); + taskTable.update(task); + + JSONObject lockPoint = new JSONObject(); + lockPoint.put("lock_type", LockType.TASK_LOCKED.getCode()); + CommonUtils.addAdminUpdateColum(lockPoint); + WQLObject.getWQLObject("sch_base_point").update(lockPoint, "point_id = " + point.getString("point_id")); + } + } + } + + @Transactional(rollbackFor = Exception.class) + public void finishTask(JSONObject task, TaskFinishedType taskFinishedType) { + task.put("finished_type", taskFinishedType.getCode()); + task.put("task_status", TaskStatus.FINISHED.getCode()); + CommonUtils.addAdminUpdateColum(task); + WQLObject.getWQLObject("sch_base_task").update(task); + + WQLObject pointTable = WQLObject.getWQLObject("sch_base_point"); + JSONObject startPoint = pointTable + .query("task_code = " + task.getString("point_code1")) + .uniqueResult(0); + JSONObject nextPoint = pointTable + .query("task_code = " + task.getString("point_code2")) + .uniqueResult(0); + + + if (StrUtil.equals(nextPoint.getString("point_type"), PointType.STORAGE_LOCATION.getCode())) { + JSONObject vehicle = WQLObject + .getWQLObject("md_pb_vehicle") + .query("vehicle_code = " + startPoint.getString("vehicle_code")) + .uniqueResult(0); + + JSONObject vm = WQLObject + .getWQLObject("st_ivt_vehicle_material") + .query("vehicle_id = " + vehicle.getString("vehicle_id"), "create_time ASC") + .uniqueResult(0); + + JSONObject ivt = new JSONObject(); + ivt.put("stockrecord_id", IdUtil.getSnowflake(1L, 1L).nextId()); + ivt.put("point_id", nextPoint.getString("point_id")); + ivt.put("instorage_time", vm.getString("create_time")); + + WQLObject.getWQLObject("st_ivt_structivt").insert(ivt); + } + + nextPoint.put("point_status", PointStatus.HAS_VEHICLE.getCode()); + nextPoint.put("lock_type", LockType.UNLOCKED.getCode()); + nextPoint.put("vehicle_code", startPoint.getString("vehicle_code")); + CommonUtils.addAdminUpdateColum(nextPoint); + pointTable.update(nextPoint); + + startPoint.put("point_status", PointStatus.EMPTY.getCode()); + startPoint.put("lock_type", LockType.UNLOCKED.getCode()); + startPoint.put("vehicle_code", ""); + CommonUtils.addAdminUpdateColum(startPoint); + pointTable.update(startPoint); + } +} diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/sch/task/SendResiduesMaterialTask.java b/lms/nladmin-system/src/main/java/org/nl/wms/sch/task/SendResiduesMaterialTask.java new file mode 100644 index 0000000..4ba66f1 --- /dev/null +++ b/lms/nladmin-system/src/main/java/org/nl/wms/sch/task/SendResiduesMaterialTask.java @@ -0,0 +1,248 @@ +package org.nl.wms.sch.task; + +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; +import org.nl.modules.common.exception.BadRequestException; +import org.nl.modules.system.util.CodeUtil; +import org.nl.modules.wql.WQL; +import org.nl.modules.wql.core.bean.WQLObject; +import org.nl.wms.sch.base.point.LockType; +import org.nl.wms.sch.base.point.PointStatus; +import org.nl.wms.sch.base.point.PointType; +import org.nl.wms.sch.manage.AbstractAcsTask; +import org.nl.wms.sch.task.dto.AcsTaskDTO; +import org.nl.wms.sch.task.util.TaskUtils; +import org.nl.wms.util.CommonUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +/** + * 纽迪西亚3呼叫余料入库任务 + * + * @author 张江玮 + * @date 2022/11/07 20:19 + */ +@Service +@RequiredArgsConstructor +@Slf4j +public class SendResiduesMaterialTask extends AbstractAcsTask { + + private static final String THIS_CLASS_NAME = SendResiduesMaterialTask.class.getName(); + + /** + * 添加任务进行下发 + * + * @return 所有这个类处理的已确认起点和终点任务 + */ + @Override + public List addTask() { + return TaskUtils.addTask(THIS_CLASS_NAME); + } + + /** + * @param taskJSON 代表一条任务对象 + * @param status 代表wcs任务完成状态: //0:acs,取消,:执行中,2:完成 + * @discription wcs请求wms任务完成状态反馈接口, 比如agv从a点往b点走。生成任务的时候绑定b的物料信息,任务完成的时候,清除a的物料信息 + * @author ldjun + * @created 2019年4月17日 下午8:51:50 + */ + @Transactional(rollbackFor = Exception.class) + @Override + public void updateTaskStatus(JSONObject taskJSON, String status) { + WQLObject taskTable = WQLObject.getWQLObject("sch_base_task"); + String taskCode = taskJSON.getString("task_code"); + JSONObject task = taskTable + .query("task_code = " + taskCode) + .uniqueResult(0); + if (ObjectUtil.isEmpty(task)) { + throw new BadRequestException("未找到任务号为" + taskCode + "的任务"); + } + + if (StrUtil.equals(status, "0")) { + this.cancel(task.getString("task_id")); + } + + if (StrUtil.equals(status, TaskStatus.EXECUTING.getCode())) { + task.put("task", TaskStatus.EXECUTING.getCode()); + CommonUtils.addAdminUpdateColum(task); + taskTable.update(task); + } + + if (StrUtil.equals(status, TaskStatus.FINISHED.getCode())) { + this.finishTask(task, TaskFinishedType.AUTO); + } + } + + /** + * @param param 创建任务需要的参数 + * + * @return 返回任务标识 + */ + @Transactional(rollbackFor = Exception.class) + @Override + public String createTask(JSONObject param) { + WQLObject pointTable = WQLObject.getWQLObject("sch_base_point"); + JSONObject point = pointTable + .query("point_id = " + param.getString("point_id")) + .uniqueResult(0); + if (ObjectUtil.isEmpty(point)) { + throw new BadRequestException("点位不存在"); + } + + JSONObject task = new JSONObject(); + String taskId = IdUtil.getSnowflake(1L, 1L).nextIdStr(); + task.put("task_id", taskId); + task.put("task_code", CodeUtil.getNewCode("TASK_CODE")); + task.put("task_type", TaskType.SEND_RESIDUES_MATERIAL.getCode()); + task.put("task_status", TaskStatus.SURE_START.getCode()); + task.put("point_code1", point.getString("point_code")); + task.put("vehicle_code", point.getString("vehicle_code")); + task.put("handle_class", THIS_CLASS_NAME); + task.put("create_mode", CreateMode.SCCJ.getCode()); + CommonUtils.addCommonColum(task); + WQLObject.getWQLObject("sch_base_task").insert(task); + + point.put("lock_type", LockType.TASK_LOCKED.getCode()); + CommonUtils.addUpdateColum(point); + pointTable.update(point); + + return taskId; + } + + /** + * @param taskId 任务标识 + * @discription 强制结束完成任务 + * @author ldjun + * @created 2020年6月19日 上午10:34:58 + */ + @Transactional(rollbackFor = Exception.class) + @Override + public void forceFinish(String taskId) { + JSONObject task = WQLObject + .getWQLObject("sch_base_task") + .query("task_id = " + taskId) + .uniqueResult(0); + this.finishTask(task, TaskFinishedType.MANUAL); + } + + /** + * 取消任务,货物搬回原点 + * + * @param taskId 任务标识 + */ + @Transactional(rollbackFor = Exception.class) + @Override + public void cancel(String taskId) { + WQLObject taskTable = WQLObject.getWQLObject("sch_base_task"); + JSONObject task = taskTable + .query("task_id = " + taskId) + .uniqueResult(0); + taskTable.delete(task); + + WQLObject pointTable = WQLObject.getWQLObject("sch_base_point"); + JSONObject startPoint = pointTable + .query("task_code = " + task.getString("point_code1")) + .uniqueResult(0); + JSONObject nextPoint = pointTable + .query("task_code = " + task.getString("point_code2")) + .uniqueResult(0); + + startPoint.put("lock_type", LockType.UNLOCKED.getCode()); + CommonUtils.addAdminUpdateColum(startPoint); + pointTable.update(startPoint); + nextPoint.put("lock_type", LockType.UNLOCKED.getCode()); + CommonUtils.addAdminUpdateColum(nextPoint); + pointTable.update(nextPoint); + } + + /** + * @return + * @discription 确定下一点位 + * @author ldjun + * @created 2020年6月12日 下午6:01:06 + */ + @Transactional(rollbackFor = Exception.class) + @Override + public void findNextPoint() { + WQLObject taskTable = WQLObject.getWQLObject("sch_base_task"); + JSONArray tasks = taskTable + .query("task_status = " + TaskStatus.SURE_START.getCode() + " AND handle_class = " + THIS_CLASS_NAME) + .getResultJSONArray(0); + + for (Object o : tasks) { + JSONObject point = WQL.getWO("TASK") + .addParam("flag", "2") + .process() + .uniqueResult(0); + + if (ObjectUtil.isNotEmpty(point)) { + JSONObject task = (JSONObject) o; + + task.put("task_status", TaskStatus.START_AND_END.getCode()); + task.put("point_code2", point.getString("point_code")); + CommonUtils.addAdminUpdateColum(task); + taskTable.update(task); + + JSONObject lockPoint = new JSONObject(); + lockPoint.put("lock_type", LockType.TASK_LOCKED.getCode()); + CommonUtils.addAdminUpdateColum(lockPoint); + WQLObject.getWQLObject("sch_base_point").update(lockPoint, "point_id = " + point.getString("point_id")); + } + } + } + + @Transactional(rollbackFor = Exception.class) + public void finishTask(JSONObject task, TaskFinishedType taskFinishedType) { + task.put("finished_type", taskFinishedType.getCode()); + task.put("task_status", TaskStatus.FINISHED.getCode()); + CommonUtils.addAdminUpdateColum(task); + WQLObject.getWQLObject("sch_base_task").update(task); + + WQLObject pointTable = WQLObject.getWQLObject("sch_base_point"); + JSONObject startPoint = pointTable + .query("task_code = " + task.getString("point_code1")) + .uniqueResult(0); + JSONObject nextPoint = pointTable + .query("task_code = " + task.getString("point_code2")) + .uniqueResult(0); + + + if (StrUtil.equals(nextPoint.getString("point_type"), PointType.STORAGE_LOCATION.getCode())) { + JSONObject vehicle = WQLObject + .getWQLObject("md_pb_vehicle") + .query("vehicle_code = " + startPoint.getString("vehicle_code")) + .uniqueResult(0); + + JSONObject vm = WQLObject + .getWQLObject("st_ivt_vehicle_material") + .query("vehicle_id = " + vehicle.getString("vehicle_id"), "create_time ASC") + .uniqueResult(0); + + JSONObject ivt = new JSONObject(); + ivt.put("stockrecord_id", IdUtil.getSnowflake(1L, 1L).nextId()); + ivt.put("point_id", nextPoint.getString("point_id")); + ivt.put("instorage_time", vm.getString("create_time")); + + WQLObject.getWQLObject("st_ivt_structivt").insert(ivt); + } + + nextPoint.put("point_status", PointStatus.HAS_VEHICLE.getCode()); + nextPoint.put("lock_type", LockType.UNLOCKED.getCode()); + nextPoint.put("vehicle_code", startPoint.getString("vehicle_code")); + CommonUtils.addAdminUpdateColum(nextPoint); + pointTable.update(nextPoint); + + startPoint.put("point_status", PointStatus.EMPTY.getCode()); + startPoint.put("lock_type", LockType.UNLOCKED.getCode()); + startPoint.put("vehicle_code", ""); + CommonUtils.addAdminUpdateColum(startPoint); + pointTable.update(startPoint); + } +} diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/sch/task/util/TaskUtils.java b/lms/nladmin-system/src/main/java/org/nl/wms/sch/task/util/TaskUtils.java index 18ffd7f..fa1db10 100644 --- a/lms/nladmin-system/src/main/java/org/nl/wms/sch/task/util/TaskUtils.java +++ b/lms/nladmin-system/src/main/java/org/nl/wms/sch/task/util/TaskUtils.java @@ -1,14 +1,19 @@ package org.nl.wms.sch.task.util; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import org.nl.modules.wql.core.bean.WQLObject; import org.nl.wms.sch.base.point.LockType; import org.nl.wms.sch.base.point.PointStatus; import org.nl.wms.sch.task.TaskFinishedType; import org.nl.wms.sch.task.TaskStatus; +import org.nl.wms.sch.task.dto.AcsTaskDTO; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.List; + /** * 纽迪希亚3任务工具类 * @@ -18,33 +23,33 @@ import org.springframework.transaction.annotation.Transactional; @Component public class TaskUtils { - @Transactional(rollbackFor = Exception.class) - public void finished(String taskId, TaskFinishedType taskFinishedType) { - WQLObject taskTable = WQLObject.getWQLObject("sch_base_task"); - JSONObject task = taskTable - .query("task_id = " + taskId) - .uniqueResult(0); - - WQLObject pointTable = WQLObject.getWQLObject("sch_base_point"); - JSONObject startPoint = pointTable - .query("task_code = " + task.getString("point_code1")) - .uniqueResult(0); - JSONObject nextPoint = pointTable - .query("task_code = " + task.getString("point_code2")) - .uniqueResult(0); - - task.put("finished_type", taskFinishedType.getCode()); - task.put("task_status", TaskStatus.FINISHED.getCode()); - taskTable.update(task); - - nextPoint.put("point_status", PointStatus.HAS_VEHICLE.getCode()); - nextPoint.put("lock_type", LockType.UNLOCKED.getCode()); - nextPoint.put("vehicle_code", startPoint.getString("vehicle_code")); - pointTable.update(nextPoint); - - startPoint.put("point_status", PointStatus.EMPTY.getCode()); - startPoint.put("lock_type", LockType.UNLOCKED.getCode()); - startPoint.put("vehicle_code", ""); - pointTable.update(startPoint); + + public static List addTask(String handleClassName) { + JSONArray tasks = WQLObject + .getWQLObject("sch_base_task") + .query("task_status = " + TaskStatus.START_AND_END.getCode() + " AND handle_class = " + handleClassName) + .getResultJSONArray(0); + + ArrayList acsTasks = new ArrayList<>(); + for (Object o : tasks) { + JSONObject task = (JSONObject) o; + + AcsTaskDTO acsTask = AcsTaskDTO + .builder() + .task_id(task.getString("task_id")) + .task_code(task.getString("task_code")) + .task_type(task.getString("acs_task_type")) + .start_device_code(task.getString("point_code1")) + .next_device_code(task.getString("point_code2")) + .vehicle_code(task.getString("vehicle_code")) + .vehicle_type(task.getString("vehicle_type")) + .priority(task.getString("priority")) + .remark(task.getString("remark")) + .build(); + + acsTasks.add(acsTask); + } + + return acsTasks; } } diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/sch/task/wql/SendEmptyVehicleTask.java b/lms/nladmin-system/src/main/java/org/nl/wms/sch/task/wql/SendEmptyVehicleTask.java new file mode 100644 index 0000000..af24851 --- /dev/null +++ b/lms/nladmin-system/src/main/java/org/nl/wms/sch/task/wql/SendEmptyVehicleTask.java @@ -0,0 +1,229 @@ +package org.nl.wms.sch.task.wql; + +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; +import org.nl.modules.common.exception.BadRequestException; +import org.nl.modules.system.util.CodeUtil; +import org.nl.modules.wql.WQL; +import org.nl.modules.wql.core.bean.WQLObject; +import org.nl.wms.sch.base.point.LockType; +import org.nl.wms.sch.base.point.PointStatus; +import org.nl.wms.sch.base.point.PointType; +import org.nl.wms.sch.manage.AbstractAcsTask; +import org.nl.wms.sch.task.*; +import org.nl.wms.sch.task.dto.AcsTaskDTO; +import org.nl.wms.sch.task.util.TaskUtils; +import org.nl.wms.util.CommonUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +/** + * 纽迪希亚3呼叫空车入库 + * + * @author 张江玮 + * @date 2022/11/07 20:14 + */ +@Service +@RequiredArgsConstructor +@Slf4j +public class SendEmptyVehicleTask extends AbstractAcsTask { + + private static final String THIS_CLASS_NAME = SendEmptyVehicleTask.class.getName(); + + /** + * 添加任务进行下发 + * + * @return 所有这个类处理的已确认起点和终点任务 + */ + @Override + public List addTask() { + return TaskUtils.addTask(THIS_CLASS_NAME); + } + + /** + * @param taskJSON 代表一条任务对象 + * @param status 代表wcs任务完成状态: //0:acs,取消,:执行中,2:完成 + * @discription wcs请求wms任务完成状态反馈接口, 比如agv从a点往b点走。生成任务的时候绑定b的物料信息,任务完成的时候,清除a的物料信息 + * @author ldjun + * @created 2019年4月17日 下午8:51:50 + */ + @Transactional(rollbackFor = Exception.class) + @Override + public void updateTaskStatus(JSONObject taskJSON, String status) { + WQLObject taskTable = WQLObject.getWQLObject("sch_base_task"); + String taskCode = taskJSON.getString("task_code"); + JSONObject task = taskTable + .query("task_code = " + taskCode) + .uniqueResult(0); + if (ObjectUtil.isEmpty(task)) { + throw new BadRequestException("未找到任务号为" + taskCode + "的任务"); + } + + if (StrUtil.equals(status, "0")) { + this.cancel(task.getString("task_id")); + } + + if (StrUtil.equals(status, TaskStatus.EXECUTING.getCode())) { + task.put("task", TaskStatus.EXECUTING.getCode()); + CommonUtils.addAdminUpdateColum(task); + taskTable.update(task); + } + + if (StrUtil.equals(status, TaskStatus.FINISHED.getCode())) { + this.finishTask(task, TaskFinishedType.AUTO); + } + } + + /** + * @param param 创建任务需要的参数 + * + * @return 返回任务标识 + */ + @Transactional(rollbackFor = Exception.class) + @Override + public String createTask(JSONObject param) { + WQLObject pointTable = WQLObject.getWQLObject("sch_base_point"); + JSONObject point = pointTable + .query("point_id = " + param.getString("point_id")) + .uniqueResult(0); + if (ObjectUtil.isEmpty(point)) { + throw new BadRequestException("点位不存在"); + } + + JSONObject task = new JSONObject(); + String taskId = IdUtil.getSnowflake(1L, 1L).nextIdStr(); + task.put("task_id", taskId); + task.put("task_code", CodeUtil.getNewCode("TASK_CODE")); + task.put("task_type", TaskType.SEND_EMPTY_VEHICLE.getCode()); + task.put("task_status", TaskStatus.SURE_START.getCode()); + task.put("point_code1", point.getString("point_code")); + task.put("vehicle_code", point.getString("vehicle_code")); + task.put("handle_class", THIS_CLASS_NAME); + task.put("create_mode", CreateMode.SCCJ.getCode()); + CommonUtils.addCommonColum(task); + WQLObject.getWQLObject("sch_base_task").insert(task); + + point.put("lock_type", LockType.TASK_LOCKED.getCode()); + CommonUtils.addUpdateColum(point); + pointTable.update(point); + + return taskId; + } + + /** + * @param taskId 任务标识 + * @discription 强制结束完成任务 + * @author ldjun + * @created 2020年6月19日 上午10:34:58 + */ + @Transactional(rollbackFor = Exception.class) + @Override + public void forceFinish(String taskId) { + JSONObject task = WQLObject + .getWQLObject("sch_base_task") + .query("task_id = " + taskId) + .uniqueResult(0); + this.finishTask(task, TaskFinishedType.MANUAL); + } + + /** + * 取消任务,货物搬回原点 + * + * @param taskId 任务标识 + */ + @Transactional(rollbackFor = Exception.class) + @Override + public void cancel(String taskId) { + WQLObject taskTable = WQLObject.getWQLObject("sch_base_task"); + JSONObject task = taskTable + .query("task_id = " + taskId) + .uniqueResult(0); + taskTable.delete(task); + + WQLObject pointTable = WQLObject.getWQLObject("sch_base_point"); + JSONObject startPoint = pointTable + .query("task_code = " + task.getString("point_code1")) + .uniqueResult(0); + JSONObject nextPoint = pointTable + .query("task_code = " + task.getString("point_code2")) + .uniqueResult(0); + + startPoint.put("lock_type", LockType.UNLOCKED.getCode()); + CommonUtils.addAdminUpdateColum(startPoint); + pointTable.update(startPoint); + nextPoint.put("lock_type", LockType.UNLOCKED.getCode()); + CommonUtils.addAdminUpdateColum(nextPoint); + pointTable.update(nextPoint); + } + + /** + * @return + * @discription 确定下一点位 + * @author ldjun + * @created 2020年6月12日 下午6:01:06 + */ + @Transactional(rollbackFor = Exception.class) + @Override + public void findNextPoint() { + WQLObject taskTable = WQLObject.getWQLObject("sch_base_task"); + JSONArray tasks = taskTable + .query("task_status = " + TaskStatus.SURE_START.getCode() + " AND handle_class = " + THIS_CLASS_NAME) + .getResultJSONArray(0); + + for (Object o : tasks) { + JSONObject point = WQL.getWO("TASK") + .addParam("flag", "2") + .process() + .uniqueResult(0); + + if (ObjectUtil.isNotEmpty(point)) { + JSONObject task = (JSONObject) o; + + task.put("task_status", TaskStatus.START_AND_END.getCode()); + task.put("point_code2", point.getString("point_code")); + CommonUtils.addAdminUpdateColum(task); + taskTable.update(task); + + JSONObject lockPoint = new JSONObject(); + lockPoint.put("lock_type", LockType.TASK_LOCKED.getCode()); + CommonUtils.addAdminUpdateColum(lockPoint); + WQLObject.getWQLObject("sch_base_point").update(lockPoint, "point_id = " + point.getString("point_id")); + } + } + } + + @Transactional(rollbackFor = Exception.class) + public void finishTask(JSONObject task, TaskFinishedType taskFinishedType) { + task.put("finished_type", taskFinishedType.getCode()); + task.put("task_status", TaskStatus.FINISHED.getCode()); + CommonUtils.addAdminUpdateColum(task); + WQLObject.getWQLObject("sch_base_task").update(task); + + WQLObject pointTable = WQLObject.getWQLObject("sch_base_point"); + JSONObject startPoint = pointTable + .query("task_code = " + task.getString("point_code1")) + .uniqueResult(0); + JSONObject nextPoint = pointTable + .query("task_code = " + task.getString("point_code2")) + .uniqueResult(0); + + nextPoint.put("point_status", PointStatus.HAS_VEHICLE.getCode()); + nextPoint.put("lock_type", LockType.UNLOCKED.getCode()); + nextPoint.put("vehicle_code", startPoint.getString("vehicle_code")); + CommonUtils.addAdminUpdateColum(nextPoint); + pointTable.update(nextPoint); + + startPoint.put("point_status", PointStatus.EMPTY.getCode()); + startPoint.put("lock_type", LockType.UNLOCKED.getCode()); + startPoint.put("vehicle_code", ""); + CommonUtils.addAdminUpdateColum(startPoint); + pointTable.update(startPoint); + } +} diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/sch/task/wql/TASK.wql b/lms/nladmin-system/src/main/java/org/nl/wms/sch/task/wql/TASK.wql index c8c818a..c1649ed 100644 --- a/lms/nladmin-system/src/main/java/org/nl/wms/sch/task/wql/TASK.wql +++ b/lms/nladmin-system/src/main/java/org/nl/wms/sch/task/wql/TASK.wql @@ -48,11 +48,27 @@ LEFT JOIN md_pb_vehicle vehicle ON point.vehicle_code = vehicle.vehicle_code WHERE point.is_used = '1' - AND point.is_delete = '0' AND point.lock_type = '1' AND point.region_id = 1585921595338264576 AND point.point_status = '2' AND vehicle.vehicle_status = '1' ENDSELECT ENDQUERY - ENDIF \ No newline at end of file + ENDIF + + IF 输入.flag = "1" + QUERY + SELECT + point_id, + point_code + FROM + sch_base_point + WHERE + is_used = '1' + AND lock_type = '1' + AND region_id = 1585921595338264576 + AND point_status = '1' + ENDSELECT + ENDQUERY + ENDIF + diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/util/CommonUtils.java b/lms/nladmin-system/src/main/java/org/nl/wms/util/CommonUtils.java index 6d522e5..180a72b 100644 --- a/lms/nladmin-system/src/main/java/org/nl/wms/util/CommonUtils.java +++ b/lms/nladmin-system/src/main/java/org/nl/wms/util/CommonUtils.java @@ -6,6 +6,7 @@ import org.nl.modules.common.utils.SecurityUtils; /** * 公共工具类 + * * @author 张江玮 * @date 2022/11/03 8:45 */ @@ -42,4 +43,15 @@ public class CommonUtils { row.put("update_optname", SecurityUtils.getCurrentNickName()); row.put("update_time", DateUtil.now()); } + + /** + * 系统循环更新,无当前用户,使用管理员 + * + * @param row 需要添加的行 + */ + public static void addAdminUpdateColum(JSONObject row) { + row.put("update_optid", "1"); + row.put("update_optname", "管理员"); + row.put("update_time", DateUtil.now()); + } } diff --git a/lms/nladmin-system/src/main/resources/config/application-dev.yml b/lms/nladmin-system/src/main/resources/config/application-dev.yml index d3cd31b..30662ae 100644 --- a/lms/nladmin-system/src/main/resources/config/application-dev.yml +++ b/lms/nladmin-system/src/main/resources/config/application-dev.yml @@ -7,10 +7,10 @@ spring: db-type: com.alibaba.druid.pool.DruidDataSource driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy # url: jdbc:log4jdbc:mysql://${DB_HOST:47.111.78.178}:${DB_PORT:3306}/${DB_NAME:yongyu_lms2}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true - url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:yongyu_lms2}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true + url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:ndxy3_lms}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true username: ${DB_USER:root} - password: ${DB_PWD:P@ssw0rd} - # password: ${DB_PWD:12356} +# password: ${DB_PWD:P@ssw0rd} + password: ${DB_PWD:zjw123} # 初始连接数 initial-size: 5 # 最小连接数 diff --git a/lms/nladmin-system/src/main/resources/logback-spring.xml b/lms/nladmin-system/src/main/resources/logback-spring.xml index dbc1ded..aa3681e 100644 --- a/lms/nladmin-system/src/main/resources/logback-spring.xml +++ b/lms/nladmin-system/src/main/resources/logback-spring.xml @@ -12,7 +12,7 @@ https://juejin.cn/post/6844903775631572999 nlAdmin + value="%black(%contextName-) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) - %cyan(%msg%n)"/> diff --git a/lms/nladmin-ui/src/views/wms/sch/point/index.vue b/lms/nladmin-ui/src/views/wms/sch/point/index.vue index d0bc51f..d5ba385 100644 --- a/lms/nladmin-ui/src/views/wms/sch/point/index.vue +++ b/lms/nladmin-ui/src/views/wms/sch/point/index.vue @@ -195,7 +195,7 @@ - +