diff --git a/lms/nladmin-system/src/main/java/org/nl/b_lms/sch/tasks/first_floor_area/auto/AutoIssueOutEmptyTask.java b/lms/nladmin-system/src/main/java/org/nl/b_lms/sch/tasks/first_floor_area/auto/AutoIssueOutEmptyTask.java new file mode 100644 index 000000000..89d910cb2 --- /dev/null +++ b/lms/nladmin-system/src/main/java/org/nl/b_lms/sch/tasks/first_floor_area/auto/AutoIssueOutEmptyTask.java @@ -0,0 +1,166 @@ +package org.nl.b_lms.sch.tasks.first_floor_area.auto; + +import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.nl.b_lms.sch.point.dao.BstIvtPackageinfoivt; +import org.nl.b_lms.sch.point.service.IbstIvtPackageinfoivtService; +import org.nl.b_lms.sch.task.dao.SchBaseTask; +import org.nl.b_lms.sch.task.service.IschBaseTaskService; +import org.nl.b_lms.sch.tasks.TwoOutBoxTask; +import org.nl.b_lms.sch.tasks.first_floor_area.ShiftingTask; +import org.nl.b_lms.storage_manage.ios.enums.IOSEnum; +import org.nl.b_lms.storage_manage.ios.service.iostorInv.util.service.OutBoxManageService; +import org.nl.common.enums.PackageInfoIvtEnum; +import org.nl.modules.wql.core.bean.WQLObject; +import org.nl.wms.sch.AcsTaskDto; +import org.nl.wms.sch.AcsUtil; +import org.nl.wms.sch.manage.TaskStatusEnum; +import org.redisson.api.RLock; +import org.redisson.api.RedissonClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import static org.nl.wms.util.TaskUtil.getRoutePlanCode; + + +@Slf4j +@Component +@RequiredArgsConstructor +public class AutoIssueOutEmptyTask { + + private final String TASK_CLASS = TwoOutBoxTask.class.getName(); + + @Autowired + private OutBoxManageService outBoxManageService; + + @Autowired + private IschBaseTaskService ischBaseTaskService; + + //自动执行等待的桁架任务 + public void run() { + try { + this.execute(); + } catch (Exception ex) { + log.error(ex.getMessage()); + } + } + + /** + * Executes a task that processes ACS (Automation Control System) tasks. + * + * This method checks the number of active tasks and ensures the limit is not exceeded. + * If tasks are eligible for further processing, it retrieves task data from the + * database, evaluates conditions based on their attributes, and issues new tasks + * to the ACS system. The method also handles specific locking and task dependency + * scenarios, ensuring that all conditions for task issuance are met. + * + * Key logic includes: + * - Querying database tables to fetch and analyze task details. + * - Ensuring task limits are respected to prevent excessive task submissions. + * - Checking and managing task statuses and related storage attributes, such as + * lock states and box specifications. + * - Notifying the ACS system with the correctly formatted task data. + * - Handling errors and updating task remarks in case of exceptions or conflicting conditions. + * + * This method operates with various modules such as task management, box handling services, + * and ACS system notification utilities. + */ + @SneakyThrows + public void execute() { + /* + * 下发给ACS时需要特殊处理 + */ + // 判断当前有多少个正在执行中的任务 + int num = WQLObject.getWQLObject("SCH_BASE_Task").query("handle_class = '" + TASK_CLASS + "' and task_status IN ('05','06') and is_delete ='0'") + .getResultJSONArray(0).size(); + // 如果缓存了4个箱子则不下发任务 + if (num >= 2) { + return; + } + + JSONArray arr = WQLObject.getWQLObject("SCH_BASE_Task").query("handle_class = '" + TASK_CLASS + "' and task_status = '" + TaskStatusEnum.START_AND_POINT.getCode() + "' and is_delete ='0' order by create_time").getResultJSONArray(0); + for (int i = 0; i < arr.size(); i++) { + if (num >= 2) { + break; + } + ArrayList resultList = new ArrayList<>(); + JSONObject json = arr.getJSONObject(i); + WQLObject attrTab = WQLObject.getWQLObject("st_ivt_structattr"); + JSONObject attr = attrTab.query("struct_code = '" + json.getString("point_code1") + "'").uniqueResult(0); + + if (attr.getString("zdepth").equals(IOSEnum.ZDEPTH_STRUCT.code("深"))) { + JSONObject 浅Attr = attrTab + .query("zdepth = '1' and row_num = '" + attr.getString("row_num") + "' and col_num = '" + attr.getString("col_num") + "' and layer_num = '" + attr.getString("layer_num") + "'") + .uniqueResult(0); + if (ObjectUtil.isEmpty(浅Attr.getString("storagevehicle_code"))) { + if (!浅Attr.getString("lock_type").equals(IOSEnum.LOCK_TYPE.code("未锁定"))) { + json.put("remark", "当前仓位对应的浅货位【" + 浅Attr.getString("struct_code") + "被锁定无法下发任务!】"); + WQLObject.getWQLObject("SCH_BASE_Task").update(json); + continue; + } + } else { + try { + if (浅Attr.getString("lock_type").equals(IOSEnum.LOCK_TYPE.code("未锁定"))) { + // 判断浅货位木箱和深货位木箱是否相同规格 + outBoxManageService.createBoxMove(浅Attr); + } else if (浅Attr.getString("lock_type").equals(IOSEnum.LOCK_TYPE.code("验箱出库锁"))) { + List list = ischBaseTaskService.list(new QueryWrapper() + .eq("is_delete", "0") + .eq("point_code1", 浅Attr.getString("struct_code")) + .lt("task_status", TaskStatusEnum.FINISHED.getCode())); + if (!CollectionUtils.isEmpty(list)) { + json.put("remark", "当前仓位对应的浅货位【" + 浅Attr.getString("struct_code") + "有正在执行中的任务,任务完成后才能下发!】"); + WQLObject.getWQLObject("SCH_BASE_Task").update(json); + continue; + } else { + outBoxManageService.createBoxMove(浅Attr); + } + } else { + continue; + } + }catch (Exception e){ + json.put("remark", e.getMessage()); + WQLObject.getWQLObject("SCH_BASE_Task").update(json); + continue; + } + } + } + char dtl_type = json.getString("task_type").charAt(json.getString("task_type").length() - 1); + AcsTaskDto dto = AcsTaskDto.builder() + .ext_task_id(json.getString("task_id")) + .task_code(json.getString("task_code")) + .route_plan_code(getRoutePlanCode(json.getString("point_code1"))) + .task_type(json.getString("acs_task_type")) + .start_device_code(json.getString("point_code1")) + .next_device_code(json.getString("point_code2")) + .vehicle_code(json.getString("vehicle_code2")) + .vehicle_code2(json.getString("vehicle_code")) + .interaction_json(json.getJSONObject("request_param")) + .priority(json.getString("priority")) + .class_type(json.getString("task_type")) + .dtl_type(String.valueOf(dtl_type)) + .product_area(IOSEnum.PRODUCT_AREA.code("BLK")) + .remark(json.getString("remark")) + .build(); + resultList.add(dto); + JSONArray list = JSONArray.parseArray(JSON.toJSONString(resultList)); + AcsUtil.notifyAcs("api/wms/task", list); + num += 1; + } + + } +}