This commit is contained in:
lyd
2022-10-24 18:29:21 +08:00
9 changed files with 290 additions and 671 deletions

View File

@@ -23,7 +23,6 @@ import org.nl.wms.sch.service.PointService;
import org.nl.wms.sch.service.TaskService;
import org.nl.wms.sch.service.dto.TaskDto;
import org.nl.wms.sch.tasks.PointToPointTask;
import org.nl.wms.sch.tasks.callEmpty.CallEmpVehicleTask;
import org.nl.wms.sch.tasks.callEmpty.GjxCallEmpVehicleTask;
import org.nl.wms.sch.tasks.callMaterial.CallMaterialTask;
import org.nl.wms.sch.tasks.sendEmpty.HtSendEmpVehicleTask;
@@ -174,10 +173,9 @@ public class AcsToWmsServiceImpl implements AcsToWmsService {
public JSONObject apply(JSONObject whereJson) {
String type = whereJson.getString("type");
String point_code = whereJson.getString("point_code");
String vehicle_num = whereJson.getString("vehicle_num");
String vehicle_type = whereJson.getString("vehicle_type");
String vehicle_code = whereJson.getString("vehicle_code");
String qty = whereJson.getString("qty");
String qty = whereJson.getString("vehicle_num");
if (ObjectUtil.isEmpty(type)) throw new BadRequestException("类型不能为空");
if (ObjectUtil.isEmpty(point_code)) throw new BadRequestException("点位不能为空");
@@ -201,12 +199,12 @@ public class AcsToWmsServiceImpl implements AcsToWmsService {
*/
if (StrUtil.equals(type, "1")) {
// 1.共挤线申请空盘: 调用空托盘出库处理类创建任务
if (ObjectUtil.isEmpty(vehicle_num)) throw new BadRequestException("数量不能为空");
if (ObjectUtil.isEmpty(qty)) throw new BadRequestException("数量不能为空");
JSONObject param = new JSONObject();
param.put("point_code2", point_code);
param.put("vehicle_type", vehicle_type);
param.put("qty", vehicle_num);
param.put("qty", qty);
// 创建任务
GjxCallEmpVehicleTask taskBean = SpringContextHolder.getBean(GjxCallEmpVehicleTask.class);
taskBean.createTask(param);
@@ -226,13 +224,13 @@ public class AcsToWmsServiceImpl implements AcsToWmsService {
String task_id = taskBean.createTask(param); // 创建任务
} else if (StrUtil.equals(type, "3")) {
// 3.油漆线申请空盘: 调用空托盘出库处理类创建任务
if (ObjectUtil.isEmpty(vehicle_num)) throw new BadRequestException("数量不能为空");
if (ObjectUtil.isEmpty(qty)) throw new BadRequestException("数量不能为空");
JSONObject param = new JSONObject();
param.put("point_code2", point_code);
param.put("qty", vehicle_num);
param.put("qty", qty);
// 创建任务
CallEmpVehicleTask taskBean = SpringContextHolder.getBean(CallEmpVehicleTask.class);
GjxCallEmpVehicleTask taskBean = SpringContextHolder.getBean(GjxCallEmpVehicleTask.class);
String task_id = taskBean.createTask(param);
} else if (StrUtil.equals(type, "4")) {
// 4.油漆线申请物料: 调用物料出库库处理类创建任务
@@ -261,12 +259,13 @@ public class AcsToWmsServiceImpl implements AcsToWmsService {
} else if (StrUtil.equals(type, "5")) {
// 5.油漆线空盘入库: 调用空托盘入库处理类创建任务
if (ObjectUtil.isEmpty(vehicle_num)) throw new BadRequestException("数量不能为空");
if (ObjectUtil.isEmpty(point_code)) throw new BadRequestException("点位不能为空");
if (ObjectUtil.isEmpty(qty)) throw new BadRequestException("数量不能为空");
if (ObjectUtil.isEmpty(vehicle_type)) throw new BadRequestException("载具类型不能为空");
JSONObject param = new JSONObject();
param.put("point_code1", point_code);
param.put("vehicle_num", vehicle_num);
param.put("qty", qty);
param.put("vehicle_type", vehicle_type);
// 创建任务
YqxSendEmpVehicleTask taskBean = SpringContextHolder.getBean(YqxSendEmpVehicleTask.class);

View File

@@ -102,6 +102,8 @@ public class SchTaskDto implements Serializable {
* 任务顺序号
*/
private Integer sort_seq;
//物料数量
private Integer material_qty;
/**
* 任务完成类型

View File

@@ -1,301 +0,0 @@
package org.nl.wms.sch.tasks.callEmpty;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.common.utils.SecurityUtils;
import org.nl.modules.system.util.CodeUtil;
import org.nl.modules.wql.WQL;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.modules.wql.util.SpringContextHolder;
import org.nl.wms.pdm.service.DeviceService;
import org.nl.wms.pdm.service.dto.DeviceDto;
import org.nl.wms.sch.manage.AbstractAcsTask;
import org.nl.wms.sch.manage.TaskStatusEnum;
import org.nl.wms.sch.service.PointService;
import org.nl.wms.sch.service.dto.PointDto;
import org.nl.wms.sch.tasks.AcsTaskDto;
import org.nl.wms.sch.tasks.RegionTypeEnum;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.List;
@Service
@RequiredArgsConstructor
@Slf4j
public class CallEmpVehicleTask extends AbstractAcsTask {
private final String THIS_CLASS = CallEmpVehicleTask.class.getName();
@Override
@Transactional(rollbackFor = Exception.class)
public void updateTaskStatus(JSONObject taskObj, String status) {
WQLObject taskTab = WQLObject.getWQLObject("SCH_BASE_Task");
WQLObject pointTab = WQLObject.getWQLObject("sch_base_point");
String task_id = taskObj.getString("task_id");
JSONObject jsonTask = taskTab.query("task_id = '" + task_id + "'").uniqueResult(0);
if (StrUtil.equals(status, "0")) {
// 取消删除任务
taskTab.delete("task_id = '" + task_id + "'");
}
if (TaskStatusEnum.EXECUTING.getCode().equals(status)) {
// 更新任务状态为执行中
jsonTask.put("task_status", TaskStatusEnum.EXECUTING.getCode());
jsonTask.put("update_time", DateUtil.now());
jsonTask.put("car_no", taskObj.getString("car_no"));
taskTab.update(jsonTask);
}
if (StrUtil.equals(status, TaskStatusEnum.FINISHED.getCode())) {
// 更改任务状态为完成
jsonTask.put("task_status", TaskStatusEnum.FINISHED.getCode());
jsonTask.put("update_optid", SecurityUtils.getCurrentUserId());
jsonTask.put("update_optname", SecurityUtils.getCurrentUsername());
jsonTask.put("update_time", DateUtil.now());
taskTab.update(jsonTask);
PointService point = SpringContextHolder.getBean(PointService.class);
// 校验起点是否存在
PointDto point_code1 = point.findByCode(jsonTask.getString("point_code1"));
if (ObjectUtil.isEmpty(point_code1)) throw new BadRequestException("未找到可用点位:" + point_code1);
// 校验终点是否存在
PointDto point_code2 = point.findByCode(jsonTask.getString("point_code2"));
if (ObjectUtil.isEmpty(point_code1)) throw new BadRequestException("未找到可用点位:" + point_code2);
// 1.更新点位数量 2.解锁点位
int vehicle_qty = JSONObject.parseObject(JSON.toJSONString(point_code1)).getIntValue("vehicle_qty");
BigDecimal vehicle_qty_point = NumberUtil.sub(String.valueOf(vehicle_qty), String.valueOf(1));
point_code1.setVehicle_qty(vehicle_qty_point);
if (StrUtil.equals(vehicle_qty_point.toString(), "0")) {
point_code1.setPoint_status("00");
point_code1.setVehicle_type("");
}
point_code1.setLock_type("00");
pointTab.update(JSONObject.parseObject(JSON.toJSONString(point_code1)));
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public String createTask(JSONObject form) {
WQLObject taskTab = WQLObject.getWQLObject("SCH_BASE_Task");
WQLObject pointTab = WQLObject.getWQLObject("sch_base_point");
String point_code1 = form.getString("point_code1");
String point_code2 = form.getString("point_code2");
String qty = form.getString("qty");
String vehicle_type = form.getString("vehicle_type");
// 出库终点不能为空
if (ObjectUtil.isEmpty(point_code2)) {
throw new BadRequestException("终点不能为空");
} else {
// 判断终点是否有正在执行的任务
JSONObject beforTaskObj = taskTab.query("is_delete='0' and point_code2='" + point_code2 + "' and task_status <>'" + TaskStatusEnum.FINISHED.getCode() + "'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(beforTaskObj))
throw new BadRequestException("存在任务号为'" + beforTaskObj.getString("task_code") + "' 未完成!");
}
// 载具数量不能为空
if (ObjectUtil.isEmpty(qty)) throw new BadRequestException("载具数量不能为空");
/*
* 1. 点对点: 起点和终点都确定,直接创建任务
* 2. 终点确定: 需要找到对应起点,在创建任务 具体找起点货位的规则在findBeginPoint()中
*/
//起点不确定
if (ObjectUtil.isEmpty(point_code1)) {
JSONObject param = new JSONObject();
param.put("point_code2",point_code2);
param.put("vehicle_qty",qty);
JSONObject json = this.findBeginPoint(param);
point_code1 = json.getString("start_point_code");
vehicle_type = json.getString("vehicle_type");
} else {
// 判断终点是否是空位
JSONObject jsonPoint = pointTab.query("point_code = '" + point_code1 + "' and lock_type = '00' and point_status <> '02' and is_delete = '0' and is_used = '1'").uniqueResult(0);
if (ObjectUtil.isEmpty(jsonPoint)) throw new BadRequestException("起点点位不可用或不存在");
}
// 创建任务
JSONObject jsonTask = new JSONObject();
String task_id = IdUtil.getSnowflake(1, 1).nextId() + "";
jsonTask.put("task_id", task_id);
jsonTask.put("task_code", CodeUtil.getNewCode("TASK_CODE"));
jsonTask.put("task_type", "04");
jsonTask.put("task_status", "01");
jsonTask.put("point_code1", point_code1);
jsonTask.put("point_code2", point_code2);
jsonTask.put("handle_class", THIS_CLASS);
jsonTask.put("vehicle_type", vehicle_type);
jsonTask.put("create_name", SecurityUtils.getCurrentUsername());
jsonTask.put("create_id", SecurityUtils.getCurrentUserId());
jsonTask.put("create_time", DateUtil.now());
jsonTask.put("acs_task_type", "1");
taskTab.insert(jsonTask);
// 锁定起点点位
JSONObject jsonPoint = pointTab.query("point_code = '" + point_code1 + "'").uniqueResult(0);
jsonPoint.put("lock_type", "02");
pointTab.update(jsonPoint);
return task_id;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void forceFinish(String task_id) {
JSONObject taskObj = WQLObject.getWQLObject("SCH_BASE_Task").query("task_id = '" + task_id + "'").uniqueResult(0);
this.updateTaskStatus(taskObj, TaskStatusEnum.FINISHED.getCode());
}
@Override
public void cancel(String task_id) {
}
@Transactional(rollbackFor = Exception.class)
public JSONObject findBeginPoint(JSONObject json) {
String point_code2 = json.getString("point_code2");
String vehicle_qty = json.getString("vehicle_qty");
if (ObjectUtil.isEmpty(point_code2)) throw new BadRequestException("终点不能为空");
if (ObjectUtil.isEmpty(vehicle_qty)) throw new BadRequestException("载具数量不能为空");
WQLObject pointTab = WQLObject.getWQLObject("sch_base_point");
WQLObject regionTab = WQLObject.getWQLObject("SCH_BASE_Region");
WQLObject orderTab = WQLObject.getWQLObject("PDM_BD_WorkOrder");
WQLObject taskTab = WQLObject.getWQLObject("SCH_BASE_Task");
// 根据终点区域判断优先的起点区域
JSONObject jsonPointEnd = pointTab.query("point_code = '" + point_code2 + "'").uniqueResult(0);
if (ObjectUtil.isEmpty(jsonPointEnd)) throw new BadRequestException("终点点位不存在");
JSONObject jsonRegionEnd = regionTab.query("region_id ='" + jsonPointEnd.getString("region_id") + "'").uniqueResult(0);
// 根据起点找到对应设备,根据设备查询工单表中 - 正在运行的工单中的载具类型
String device_code = point_code2.substring(0, point_code2.indexOf("_"));
DeviceService deviceBean = SpringContextHolder.getBean(DeviceService.class);
DeviceDto deviceDto = deviceBean.findByCode(device_code);
if (ObjectUtil.isEmpty(deviceDto)) throw new BadRequestException("此设备不存在");
JSONObject jsonOrder = orderTab.query("device_id = '" + deviceDto.getDevice_id() + "' and order_status = '02' and is_delete = '0'").uniqueResult(0);
if (ObjectUtil.isEmpty(jsonOrder)) throw new BadRequestException("此设备未在生产中或不存在");
//当前设备所需要的载具类型
String vehicle_type = jsonOrder.getString("vehicle_type");
/*
* 空托盘出库任务:
* 1.叠盘架B区、养生A区 --> 共挤线 优先级1叠盘架B区 2养生A区
* 2.叠盘架A区、养生A区 --> 油漆线 优先级1叠盘架A区 2养生A区
*/
String point_code1 = "";
JSONObject map = new JSONObject();
if (StrUtil.equals(jsonRegionEnd.getString("region_code"), RegionTypeEnum.GJQY.getCode())) {
//1、判断是否有拆托盘任务。
taskTab.query("task_type= 'gjxsqkp' ");
//2、判断是否有到该叠盘位的堆叠任务。
//1、判断叠盘架B是否有对应类型的空载具
JSONObject jsonDpjB = pointTab.query("point_status ='2' and lock_type='00' and can_vehicle_type = '" + vehicle_type + "'").uniqueResult(0);
if (ObjectUtil.isEmpty(jsonDpjB)) {//没有则去空托盘缓存区B和养生A区找
}
// 共挤线呼叫空托盘业务查找叠盘架B区是否有满足条件的点位
map.put("flag", "1");
map.put("vehicle_qty", vehicle_qty);
map.put("vehicle_type", jsonOrder.getString("vehicle_type"));
map.put("region_code", RegionTypeEnum.DPJQB.getCode());
JSONObject jsonStartPointDPB = WQL.getWO("ST_VEHICLE_OUT_02").addParamMap(map).process().uniqueResult(0);
if (ObjectUtil.isNotEmpty(jsonStartPointDPB)) {
point_code1 = jsonStartPointDPB.getString("point_code");
} else {
// 为空说明叠盘架B区没有则去养生A区找 : 只能找数量为1的空托盘
map.put("flag", "3");
map.put("region_code", RegionTypeEnum.YSQA.getCode());
JSONObject jsonStartPointYSA = WQL.getWO("ST_VEHICLE_OUT_02").addParamMap(map).process().uniqueResult(0);
if (ObjectUtil.isNotEmpty(jsonStartPointYSA)) {
point_code1 = jsonStartPointYSA.getString("point_code");
} else {
throw new BadRequestException("没有满足需求数量的点位");
/* // 如果没有则需要从养生区A区里找到 > 1的货位 出库到叠盘架B中
map.put("flag", "1");
map.put("region_code", RegionTypeEnum.YSQA.getCode());
// 起点
JSONObject jsonStart = WQL.getWO("ST_VEHICLE_OUT_02").addParamMap(map).process().uniqueResult(0);
if (ObjectUtil.isEmpty(jsonStart)) throw new BadRequestException("没有满足需求数量的点位");
// 终点
JSONObject jsonEnd = pointTab.query("region_id = '" + RegionTypeEnum.DPJQB.getId() + "' and point_status = '00' and lock_type = '00' and is_used = '1' and is_delete = '0'").uniqueResult(0);
if (ObjectUtil.isEmpty(jsonEnd)) throw new BadRequestException("叠盘架B货位不足");
JSONObject parem = new JSONObject();
parem.put("point_code1",jsonStart.getString("point_code"));
parem.put("point_code2",jsonEnd.getString("point_code"));
parem.put("qty",jsonStart.getString("vehicle_qty"));
parem.put("vehicle_type",jsonStart.getString("vehicle_qty"));
String task_id = this.createTask(parem);
// 生成 叠盘架 -> 共挤线的任务 返回叠盘架B的点位code
point_code1 = jsonEnd.getString("point_code");*/
}
}
} else if (StrUtil.equals(jsonRegionEnd.getString("region_code"), RegionTypeEnum.YQQY.getCode())) {
// 油漆线呼叫空托盘业务查找叠盘架A区是否有满足条件的点位
map.put("flag", "1");
map.put("vehicle_qty", vehicle_qty);
map.put("vehicle_type", jsonOrder.getString("vehicle_type"));
map.put("region_code", RegionTypeEnum.DPJQA.getCode());
JSONObject jsonStartPointDPA = WQL.getWO("ST_VEHICLE_OUT_02").addParamMap(map).process().uniqueResult(0);
if (ObjectUtil.isNotEmpty(jsonStartPointDPA)) {
point_code1 = jsonStartPointDPA.getString("point_code");
} else {
// 为空说明叠盘架A区没有则去养生A区找
map.put("flag", "3");
map.put("region_code", RegionTypeEnum.YSQA.getCode());
JSONObject jsonStartPointYSA = WQL.getWO("ST_VEHICLE_OUT_02").addParamMap(map).process().uniqueResult(0);
if (ObjectUtil.isEmpty(jsonStartPointYSA)) throw new BadRequestException("没有满足需求数量的点位");
point_code1 = jsonStartPointYSA.getString("point_code");
}
}
JSONObject resuft = new JSONObject();
resuft.put("point_code1", point_code1);
resuft.put("vehicle_type", jsonOrder.getString("vehicle_type"));
return resuft;
}
@Override
public List<AcsTaskDto> addTask() {
return null;
}
}

View File

@@ -138,7 +138,7 @@ public class GjxCallEmpVehicleTask extends AbstractAcsTask {
JSONObject whereParam = new JSONObject();
whereParam.put("flag", "1");
whereParam.put("vehicle_type", '%' + jsonTask.getString("vehicle_type") + "%");
JSONObject outJsonObj = WQL.getWO("ST_VEHICLE_OUT_01").addParamMap(whereParam).process().uniqueResult(0);
JSONObject outJsonObj = WQL.getWO("QSCH_GjxCallEmpVehicleTask").addParamMap(whereParam).process().uniqueResult(0);
// 空托盘缓存货架或者养生A区------>叠盘架B区
JSONObject param = new JSONObject();

View File

@@ -1,5 +1,5 @@
[交易说明]
交易名: 空载具出库业务
交易名: 共挤线申请空盘
所属模块:
功能简述:
版权所有:

View File

@@ -83,6 +83,9 @@ public class HtSendEmpVehicleTask extends AbstractAcsTask {
// 更新point_code2:解锁
JSONObject point2 = pointTab.query("point_code = '" + jsonTask.getString("point_code2") + "'").uniqueResult(0);
point2.put("lock_type", "1");
point2.put("vehicle_type", "");
point2.put("vehicle_code", "");
point2.put("vehicle_qty", 0);
pointTab.update(point2);
} else {
point_code = jsonTask.getString("point_code2");
@@ -351,7 +354,7 @@ public class HtSendEmpVehicleTask extends AbstractAcsTask {
"' and block_num = '" + jsonPoint2.getString("block_num") +
"' and col_num = '" + jsonPoint2.getString("col_num") +
"' and point_code <> '" + jsonPoint2.getString("point_code") +
"' and point_status = '2' order by in_empty_seq ASC").uniqueResult(0);
"' and point_status = '2' and lock_type = '1' order by in_empty_seq ASC").uniqueResult(0);
// 如果为空说明这一列其他货位为空 则入到最后一个货位
if (ObjectUtil.isEmpty(jsonOnePoint)) {
@@ -359,7 +362,7 @@ public class HtSendEmpVehicleTask extends AbstractAcsTask {
"' and block_num = '" + jsonPoint2.getString("block_num") +
"' and col_num = '" + jsonPoint2.getString("col_num") +
"' and point_code <> '" + jsonPoint2.getString("point_code") +
"' and point_status = '1' order by in_empty_seq DESC").uniqueResult(0);
"' and point_status = '1' and lock_type = '1' order by in_empty_seq DESC").uniqueResult(0);
if (ObjectUtil.isNotEmpty(jsonEmpPoint)) {
point_code = jsonEmpPoint.getString("point_code");
@@ -375,7 +378,7 @@ public class HtSendEmpVehicleTask extends AbstractAcsTask {
"' and col_num = '" + jsonPoint2.getString("col_num") +
"' and point_code <> '" + jsonPoint2.getString("point_code") +
"' and in_empty_seq = '" + in_empty_seq +
"' and point_status = '1'").uniqueResult(0);
"' and point_status = '1' and lock_type = '1'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(jsonEmpPoint)) {
point_code = jsonEmpPoint.getString("point_code");
@@ -383,9 +386,12 @@ public class HtSendEmpVehicleTask extends AbstractAcsTask {
taskTab.update(jsonTask);
}
}
JSONObject jsonEndPoint = pointTab.query("point_code = '" + point_code + "'").uniqueResult(0);
jsonEndPoint.put("lock_type", "2");
pointTab.update(jsonEndPoint);
if (ObjectUtil.isNotEmpty(point_code)) {
JSONObject jsonEndPoint = pointTab.query("point_code = '" + point_code + "'").uniqueResult(0);
jsonEndPoint.put("lock_type", "2");
pointTab.update(jsonEndPoint);
}
return point_code;
}

View File

@@ -1,279 +0,0 @@
package org.nl.wms.sch.tasks.sendEmpty;
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.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.common.utils.SecurityUtils;
import org.nl.modules.system.util.CodeUtil;
import org.nl.modules.wql.WQL;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.modules.wql.util.SpringContextHolder;
import org.nl.wms.basedata.service.VehicleService;
import org.nl.wms.basedata.service.dto.VehicleDto;
import org.nl.wms.pdm.service.DeviceService;
import org.nl.wms.pdm.service.dto.DeviceDto;
import org.nl.wms.sch.manage.AbstractAcsTask;
import org.nl.wms.sch.manage.TaskStatusEnum;
import org.nl.wms.sch.service.PointService;
import org.nl.wms.sch.service.dto.PointDto;
import org.nl.wms.sch.tasks.AcsTaskDto;
import org.nl.wms.sch.tasks.RegionTypeEnum;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;
@Service
@RequiredArgsConstructor
@Slf4j
public class SendEmpVehicleTask extends AbstractAcsTask {
private final String THIS_CLASS = SendEmpVehicleTask.class.getName();
@Override
@Transactional(rollbackFor = Exception.class)
public void updateTaskStatus(JSONObject taskObj, String status) {
WQLObject taskTab = WQLObject.getWQLObject("SCH_BASE_Task");
WQLObject pointTab = WQLObject.getWQLObject("sch_base_point");
String task_id = taskObj.getString("task_id");
JSONObject jsonTask = taskTab.query("task_id = '" + task_id + "'").uniqueResult(0);
if (StrUtil.equals(status,"0")) {
// 取消删除任务
taskTab.delete("task_id = '"+task_id+"'");
}
if (TaskStatusEnum.EXECUTING.getCode().equals(status)) {
// 更新任务状态为执行中
jsonTask.put("task_status", TaskStatusEnum.EXECUTING.getCode());
jsonTask.put("update_time", DateUtil.now());
jsonTask.put("car_no", taskObj.getString("car_no"));
taskTab.update(jsonTask);
}
if(StrUtil.equals(status, TaskStatusEnum.FINISHED.getCode())) {
// 更改任务状态为完成
jsonTask.put("task_status",TaskStatusEnum.FINISHED.getCode());
jsonTask.put("update_optid", SecurityUtils.getCurrentUserId());
jsonTask.put("update_optname", SecurityUtils.getCurrentUsername());
jsonTask.put("update_time", DateUtil.now());
taskTab.update(jsonTask);
String point_code1 = jsonTask.getString("point_code1");
PointService point = SpringContextHolder.getBean(PointService.class);
// 校验起点是否存在
PointDto startDto = point.findByCode(point_code1);
if (ObjectUtil.isEmpty(startDto)) throw new BadRequestException("未找到可用点位:" + startDto);
// 校验终点是否存在
PointDto nextDto = point.findByCode(jsonTask.getString("point_code2"));
if (ObjectUtil.isEmpty(nextDto)) throw new BadRequestException("未找到可用点位:" + nextDto);
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public String createTask(JSONObject form) {
WQLObject taskTab = WQLObject.getWQLObject("SCH_BASE_Task");
WQLObject pointTab = WQLObject.getWQLObject("sch_base_point");
String point_code1 = form.getString("point_code1");
String point_code2 = form.getString("point_code2");
String vehicle_code = form.getString("vehicle_code");
String qty = form.getString("qty");
String record_uuid = form.getString("record_uuid");
String vehicle_type = "";
// 入库起点不能为空
if (ObjectUtil.isEmpty(point_code1)) {
throw new BadRequestException("起点不能为空");
} else {
// 判断起点是否有正在执行的任务
JSONObject beforTaskObj = taskTab.query("is_delete='0' and point_code1='" + point_code1 + "' and task_status <>'" + TaskStatusEnum.FINISHED.getCode() + "'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(beforTaskObj)) throw new BadRequestException("存在指令号为'" + beforTaskObj.getString("task_code") + "' 未完成!");
}
// 载具数量不能为空
if (ObjectUtil.isEmpty(qty)) throw new BadRequestException("载具数量不能为空");
/*
* 1. 点对点: 起点和终点都确定,直接创建任务
* 2. 起点确定: 需要找到对应终点,在创建任务 具体找终点货位的规则在findEndPoint()中
*/
// 起点确定:找终点
if (ObjectUtil.isEmpty(point_code2)) {
JSONObject param = new JSONObject();
param.put("point_code1",point_code1);
param.put("vehicle_qty",qty);
param.put("vehicle_code",vehicle_code);
JSONObject json = this.findEndPoint(param);
point_code2 = json.getString("EndPoint_code");
vehicle_type = json.getString("vehicle_type");
} else {
// 判断终点是否是空位
JSONObject jsonPoint = pointTab.query("point_code = '" + point_code2 + "' and lock_type = '00' and point_status <> '02' and is_delete = '0' and is_used = '1'").uniqueResult(0);
if (ObjectUtil.isEmpty(jsonPoint)) throw new BadRequestException("终点点位不不可用或不存在");
}
// 创建任务
JSONObject jsonTask = new JSONObject();
String task_id = IdUtil.getSnowflake(1, 1).nextId() + "";
jsonTask.put("task_id", task_id);
jsonTask.put("task_code", CodeUtil.getNewCode("TASK_CODE"));
jsonTask.put("task_type", "03");
jsonTask.put("task_status", "01");
jsonTask.put("point_code1", point_code1);
jsonTask.put("point_code2", point_code2);
jsonTask.put("vehicle_type", vehicle_type);
jsonTask.put("vehicle_code", vehicle_code);
jsonTask.put("handle_class", THIS_CLASS);
jsonTask.put("create_name", SecurityUtils.getCurrentUsername());
jsonTask.put("create_id", SecurityUtils.getCurrentUserId());
jsonTask.put("create_time", DateUtil.now());
jsonTask.put("acs_task_type", "1");
taskTab.insert(jsonTask);
// 锁定终点点位
JSONObject jsonPoint = pointTab.query("point_code = '" + point_code2 + "'").uniqueResult(0);
jsonPoint.put("lock_type", "02");
pointTab.update(jsonPoint);
return task_id;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void forceFinish(String task_id) {
JSONObject taskObj = WQLObject.getWQLObject("SCH_BASE_Task").query("task_id = '" + task_id + "'").uniqueResult(0);
this.updateTaskStatus(taskObj, TaskStatusEnum.FINISHED.getCode());
}
@Override
public void cancel(String task_id) {
}
@Transactional(rollbackFor = Exception.class)
public JSONObject findEndPoint(JSONObject json) {
String point_code1 = json.getString("point_code1");
String vehicle_qty = json.getString("vehicle_qty");
String vehicle_code = json.getString("vehicle_code");
if (ObjectUtil.isEmpty(point_code1)) throw new BadRequestException("起点不能为空");
if (ObjectUtil.isEmpty(vehicle_qty)) throw new BadRequestException("载具数量不能为空");
WQLObject pointTab = WQLObject.getWQLObject("sch_base_point"); // 点位表
WQLObject regionTab = WQLObject.getWQLObject("SCH_BASE_Region"); // 区域表
WQLObject orderTab = WQLObject.getWQLObject("PDM_BD_WorkOrder"); //空载具记录表
WQLObject velicleTab = WQLObject.getWQLObject("md_pb_storagevehicleinfo"); // 载具表
// 根据起点区域判断优先的终点区域
JSONObject jsonPointStart = pointTab.query("point_code = '" + point_code1 + "'").uniqueResult(0);
if (ObjectUtil.isEmpty(jsonPointStart)) throw new BadRequestException("起点点位不存在");
JSONObject jsonRegionStart = regionTab.query("region_id ='" + jsonPointStart.getString("region_id") + "'").uniqueResult(0);
// 根据起点找到对应设备,根据设备查询工单表中 - 正在运行的工单中的载具类型
String device_code = "";
if (ObjectUtil.isEmpty(vehicle_code)) {
device_code = point_code1.substring(0, point_code1.indexOf("_"));
}
String vehicle_type = "";
DeviceService deviceBean = SpringContextHolder.getBean(DeviceService.class);
DeviceDto deviceDto = deviceBean.findByCode(device_code);
if (ObjectUtil.isEmpty(deviceDto)) {
// 如果说明是货梯业务:则判断载具号是否为空
if (ObjectUtil.isEmpty(vehicle_code)) throw new BadRequestException("起点点位错误");
// 根据载具号找对应的载具类型
VehicleDto vehicleDto = SpringContextHolder.getBean(VehicleService.class).findByCode(vehicle_code);
if (ObjectUtil.isEmpty(vehicleDto)) throw new BadRequestException("载具不存在");
vehicle_type = vehicleDto.getVehicle_type();
} else {
// 不为空说明不是货梯业务:则根据工单找到对应类型
JSONObject jsonOrder = orderTab.query("device_id = '" + deviceDto.getDevice_id() + "' and order_status = '02' and is_delete = '0'").uniqueResult(0);
if (ObjectUtil.isEmpty(jsonOrder)) throw new BadRequestException("此设备未在生产中或不存在");
vehicle_type = jsonOrder.getString("vehicle_type");
}
/*
* 空托盘入库业务:
* 1.油漆线 --> 叠盘架A区、养生区A区 优先级1叠盘架A区 2.养生A区
* 2.货梯 --> 叠盘架B区、养生区A区 优先级1叠盘架B区 2.养生A区
*/
String EndPoint_code = "";
HashMap<String, String> map = new HashMap<>();
if (StrUtil.equals(jsonRegionStart.getString("region_code"), RegionTypeEnum.YQQY.getCode())) {
// 油漆线入库查找叠盘架A区是否有满足的空位
map.put("flag", "1");
map.put("vehicle_qty",vehicle_qty);
map.put("vehicle_type",vehicle_type);
map.put("region_code",RegionTypeEnum.DPJQA.getCode());
JSONObject jsonEndPointDPA = WQL.getWO("ST_VEHICLE_IN_02").addParamMap(map).process().uniqueResult(0);
if (ObjectUtil.isNotEmpty(jsonEndPointDPA)) {
EndPoint_code = jsonEndPointDPA.getString("point_code");
} else {
// 为空说明没有相同的载具类型
map.put("flag", "2");
map.put("vehicle_type","");
JSONObject jsonEndPointDPA2 = WQL.getWO("ST_VEHICLE_IN_02").addParamMap(map).process().uniqueResult(0);
if (ObjectUtil.isNotEmpty(jsonEndPointDPA2)) {
EndPoint_code = jsonEndPointDPA2.getString("point_code");
} else {
// 为空说明叠盘架A区上货位不足则需要入库到养生A区
map.put("flag", "3");
map.put("region_code",RegionTypeEnum.YSQA.getCode() );
JSONObject jsonEndPointYSA = WQL.getWO("ST_VEHICLE_IN_02").addParamMap(map).process().uniqueResult(0);
if (ObjectUtil.isEmpty(jsonEndPointYSA)) throw new BadRequestException("没有满足需求的空位");
EndPoint_code = jsonEndPointYSA.getString("point_code");
}
}
} else {
// 货梯入库查找叠盘架B区是否有满足的空位
map.put("flag", "1");
map.put("vehicle_qty",vehicle_qty);
map.put("vehicle_type",vehicle_type);
map.put("region_code",RegionTypeEnum.DPJQB.getCode());
JSONObject jsonEndPointDPB = WQL.getWO("ST_VEHICLE_IN_02").addParamMap(map).process().uniqueResult(0);
if (ObjectUtil.isNotEmpty(jsonEndPointDPB)) {
EndPoint_code = jsonEndPointDPB.getString("point_code");
} else {
// 为空说明没有相同的载具类型
map.put("flag", "2");
map.put("vehicle_type","");
JSONObject jsonEndPointDPB2 = WQL.getWO("ST_VEHICLE_IN_02").addParamMap(map).process().uniqueResult(0);
if (ObjectUtil.isNotEmpty(jsonEndPointDPB2)) {
EndPoint_code = jsonEndPointDPB2.getString("point_code");
} else {
// 为空说明叠盘架B区上货位不足则需要入库到养生A区
map.put("flag", "3");
map.put("region_code", RegionTypeEnum.YSQA.getCode());
JSONObject jsonEndPointYSA = WQL.getWO("ST_VEHICLE_IN_02").addParamMap(map).process().uniqueResult(0);
if (ObjectUtil.isEmpty(jsonEndPointYSA)) throw new BadRequestException("没有满足需求的空位");
EndPoint_code = jsonEndPointYSA.getString("point_code");
}
}
}
JSONObject resuft = new JSONObject();
resuft.put("EndPoint_code",EndPoint_code);
resuft.put("vehicle_type",vehicle_type);
return resuft;
}
@Override
public List<AcsTaskDto> addTask() {
return null;
}
}

View File

@@ -2,8 +2,10 @@ package org.nl.wms.sch.tasks.sendEmpty;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
@@ -13,12 +15,15 @@ import org.nl.modules.common.utils.SecurityUtils;
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.SchTaskDto;
import org.nl.wms.sch.manage.AbstractAcsTask;
import org.nl.wms.sch.manage.TaskStatusEnum;
import org.nl.wms.sch.tasks.AcsTaskDto;
import org.nl.wms.sch.tasks.RegionTypeEnum;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
@Service
@@ -39,6 +44,21 @@ public class YqxSendEmpVehicleTask extends AbstractAcsTask {
if (StrUtil.equals(status, "0")) {
// 取消删除任务
if (StrUtil.equals(jsonTask.getString("task_status"), TaskStatusEnum.FINISHED.getCode())) {
throw new BadRequestException("已完成不能取消!");
}
String point_code3 = jsonTask.getString("point_code3");
String point_code2 = jsonTask.getString("point_code2");
if (ObjectUtil.isNotEmpty(point_code3)) {
JSONObject jsonPoint3 = pointTab.query("point_code ='" + point_code3 + "'").uniqueResult(0);
jsonPoint3.put("point_status", "1");
pointTab.update(jsonPoint3);
}
if (ObjectUtil.isNotEmpty(point_code2)) {
JSONObject jsonPoint2 = pointTab.query("point_code ='" + point_code2 + "'").uniqueResult(0);
jsonPoint2.put("point_status", "1");
pointTab.update(jsonPoint2);
}
taskTab.delete("task_id = '" + task_id + "'");
}
@@ -53,15 +73,29 @@ public class YqxSendEmpVehicleTask extends AbstractAcsTask {
if (StrUtil.equals(status, TaskStatusEnum.FINISHED.getCode())) {
// 更改任务状态为完成
jsonTask.put("task_status", TaskStatusEnum.FINISHED.getCode());
jsonTask.put("update_optid", SecurityUtils.getCurrentUserId());
jsonTask.put("update_optname", SecurityUtils.getCurrentUsername());
jsonTask.put("update_time", DateUtil.now());
taskTab.update(jsonTask);
String point_code2 = jsonTask.getString("point_code2");
JSONObject endPoint = pointTab.query("point_code = '" + point_code2 + "'").uniqueResult(0);
String point_code3 = jsonTask.getString("point_code3");
String point_code = "";
// 更新终点判断point_code3是否为空为空就更新point_code2
if (ObjectUtil.isNotEmpty(point_code3)) {
point_code = point_code3;
// 更新point_code2:解锁
JSONObject point2 = pointTab.query("point_code = '" + jsonTask.getString("point_code2") + "'").uniqueResult(0);
point2.put("lock_type", "1");
point2.put("vehicle_type", "");
point2.put("vehicle_code", "");
point2.put("vehicle_qty", 0);
pointTab.update(point2);
} else {
point_code = jsonTask.getString("point_code2");
}
JSONObject endPoint = pointTab.query("point_code = '" + point_code + "'").uniqueResult(0);
//终点是叠盘架
if (StrUtil.equals("DPJQB01", endPoint.getString("region_code"))) {
if (StrUtil.equals(endPoint.getString("region_id"), RegionTypeEnum.DPJQB.getId())) {
Integer vehicle_qty = endPoint.getInteger("vehicle_qty");
vehicle_qty += jsonTask.getInteger("vehicle_qty");
endPoint.put("lock_type", "1");
@@ -71,55 +105,43 @@ public class YqxSendEmpVehicleTask extends AbstractAcsTask {
pointTab.update(endPoint);
} else {//非叠盘架
endPoint.put("lock_type", "1");
endPoint.put("vehicle_code", jsonTask.getString("vehicle_code"));
endPoint.put("vehicle_qty", jsonTask.getString("vehicle_qty"));
endPoint.put("vehicle_type", jsonTask.getString("vehicle_type"));
endPoint.put("point_status", "1");
endPoint.put("point_status", "2");
pointTab.update(endPoint);
}
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public String createTask(JSONObject form) {
WQLObject taskTab = WQLObject.getWQLObject("SCH_BASE_Task");
/*
* 1.先生成确定起点的任务
* 2.通过findNextPoint()找终点
* 3.下发给ACS
*/
WQLObject taskTab = WQLObject.getWQLObject("SCH_BASE_Task"); // 任务表
String point_code1 = form.getString("point_code1");
String point_code2 = form.getString("point_code2");
String vehicle_code = form.getString("vehicle_code");
String vehicle_type = form.getString("vehicle_type");
String vehicle_num = form.getString("vehicle_num");
// 入库起点不能为空
if (ObjectUtil.isEmpty(point_code1)) {
throw new BadRequestException("起点不能为空");
}
// 判断起点是否有正在执行的任务
JSONObject beforTaskObj = taskTab.query("is_delete='0' and point_code1='" + point_code1 + "' and task_status <>'" + TaskStatusEnum.FINISHED.getCode() + "'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(beforTaskObj)) throw new BadRequestException("存在指令号为'" + beforTaskObj.getString("task_code") + "' 未完成!");
// 创建任务
JSONObject jsonTask = new JSONObject();
String task_id = IdUtil.getSnowflake(1, 1).nextId() + "";
jsonTask.put("task_id", task_id);
jsonTask.put("task_code", CodeUtil.getNewCode("TASK_CODE"));
jsonTask.put("task_type", "kzj");
jsonTask.put("task_status", TaskStatusEnum.SURE_START.getCode());
jsonTask.put("point_code1", point_code1);
jsonTask.put("point_code2", point_code2);
jsonTask.put("vehicle_type", vehicle_type);
jsonTask.put("vehicle_code", vehicle_code);
jsonTask.put("vehicle_num", vehicle_num);
jsonTask.put("handle_class", THIS_CLASS);
jsonTask.put("create_name", SecurityUtils.getCurrentUsername());
jsonTask.put("create_id", SecurityUtils.getCurrentUserId());
jsonTask.put("create_time", DateUtil.now());
taskTab.insert(jsonTask);
this.findNextPoint();
return task_id;
SchTaskDto dto = SchTaskDto.builder().task_id(org.nl.wms.util.IdUtil.getLongId())
.task_code(CodeUtil.getNewCode("TASK_CODE"))
.task_type("")
.task_status(TaskStatusEnum.SURE_START.getCode())
.point_code1(point_code1)
.vehicle_code(form.getString("vehicle_code"))
.vehicle_type(form.getString("vehicle_type"))
.vehicle_qty(form.getIntValue("qty"))
.handle_class(THIS_CLASS)
.create_time(DateUtil.now())
.build();
JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto));
taskTab.insert(json);
// this.findNextPoint();
this.immediateNotifyAcs();
return String.valueOf(dto.getTask_id());
}
/**
@@ -130,49 +152,46 @@ public class YqxSendEmpVehicleTask extends AbstractAcsTask {
*/
@Override
public void findNextPoint() {
/*
* 根据业务找对应的终点
*/
WQLObject taskTab = WQLObject.getWQLObject("SCH_BASE_Task");
WQLObject pointTab = WQLObject.getWQLObject("sch_base_point");
JSONArray taskArr = taskTab.query("is_delete = '0' and handle_class = '" + this.THIS_CLASS + "' and task_status = '" + TaskStatusEnum.SURE_START.getCode() + "'").getResultJSONArray(0);
JSONArray taskArr = taskTab.query("handle_class = '" + THIS_CLASS + "'and is_delete = '0' and task_status = '2'").getResultJSONArray(0);
for (int i = 0; i < taskArr.size(); i++) {
JSONObject jsonTask = taskArr.getJSONObject(i);
String vehicle_type = jsonTask.getString("vehicle_type");
Integer vehicle_qty = jsonTask.getInteger("vehicle_qty");
//TODO 判断叠盘位是否有另外任务,则不生成任务后续可以考虑托盘数量大于某个数直接去缓存区或者养生A区
JSONObject taskObj = taskTab.query("is_delete='0' and handle_class='" + this.THIS_CLASS + "' and task_status <>'" + TaskStatusEnum.FINISHED.getCode() + "' and task_id <> " + jsonTask.getLong("task_id")).uniqueResult(0);
if (ObjectUtil.isNotEmpty(taskObj)) continue;
JSONObject dpjPoint = pointTab.query("is_used ='1' and lock_type='00' and is_delete='0' and region_code='DPJQB01' and can_vehicle_type like '%" + vehicle_type + "%'").uniqueResult(0);
// 找终点
JSONObject param = new JSONObject();
param.put("vehicle_type", jsonTask.getString("vehicle_type"));
param.put("qty", jsonTask.getString("vehicle_qty"));
String endPoint = this.endPoint(param);
int sum_qty=(dpjPoint.getInteger("vehicle_qty")==null?0:dpjPoint.getInteger("vehicle_qty"))+vehicle_qty;
//超过叠盘架允许的最大托盘数去托盘缓存区或者去养生A区,后续可以考虑任务的载具数量和叠盘架的载具数量谁比较大大的先去缓存位或者去养生A区
if ( sum_qty > dpjPoint.getInteger("vehicle_max_qty")) {
JSONObject endPoint = WQL.getWO("ST_VEHICLE_IN_01").addParam("flag", "1").addParam("vehicle_type", "'%" + vehicle_type + "'").process().uniqueResult(0);
jsonTask.put("point_code2", endPoint.getString("point_code"));
jsonTask.put("task_status", TaskStatusEnum.START_AND_POINT);
jsonTask.put("update_time", DateUtil.now());
taskTab.update(jsonTask);
} else {//去叠盘架
jsonTask.put("point_code2", dpjPoint.getString("point_code"));
jsonTask.put("task_status", TaskStatusEnum.START_AND_POINT.getCode());
jsonTask.put("update_time", DateUtil.now());
taskTab.update(jsonTask);
// 如果此时endPoint为空则循环下一个任务
if (ObjectUtil.isEmpty(endPoint)) {
continue;
}
//锁住终点
JSONObject pointObj = new JSONObject();
pointObj.put("lock_type", "2");
pointObj.put("update_time", DateUtil.now());
pointTab.update(pointObj, "point_code ='" + jsonTask.getString("point_code2") + "'");
// 更新任务表point_code2
jsonTask.put("point_code2", endPoint);
jsonTask.put("task_status", "4");
taskTab.update(jsonTask);
// 锁定终点
JSONObject jsonEnd = pointTab.query("point_code = '" + endPoint + "'").uniqueResult(0);
jsonEnd.put("lock_type", "2");
pointTab.update(jsonEnd);
}
}
;
@Override
@Transactional(rollbackFor = Exception.class)
public void forceFinish(String task_id) {
/*
* 强制完成
*/
JSONObject taskObj = WQLObject.getWQLObject("SCH_BASE_Task").query("task_id = '" + task_id + "'").uniqueResult(0);
this.updateTaskStatus(taskObj, TaskStatusEnum.FINISHED.getCode());
}
@@ -183,9 +202,182 @@ public class YqxSendEmpVehicleTask extends AbstractAcsTask {
public void cancel(String task_id) {
}
@Override
public List<AcsTaskDto> addTask() {
return null;
@Transactional(rollbackFor = Exception.class)
public String endPoint(JSONObject param) {
/*
* 1.叠盘架有B对应货位 规则如果暂存位能放下则放暂存位如果放不下则走2或3
* 2.叠盘架B没有货位 则去叠盘架暂存位
* 3.叠盘架暂存位没有货位则去养生A区
*/
WQLObject pointTab = WQLObject.getWQLObject("SCH_BASE_Point"); // 点位表
String end_code = "";
String vehicle_type = param.getString("vehicle_type");
// 1.找到对应类型的叠盘架
JSONObject jsonDpjEnd = pointTab.query("region_id = '" + RegionTypeEnum.DPJQB.getId() + "' and can_vehicle_type = '" + vehicle_type + "' and lock_type = '1' and is_used = '1' and is_delete = '0'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(jsonDpjEnd)) {
// 判断数量 + 叠盘架的数量是否超过此叠盘架的最大数量
double add_num = NumberUtil.add(param.getIntValue("qty"), jsonDpjEnd.getIntValue("vehicle_qty"));
if (jsonDpjEnd.getDoubleValue("vehicle_max_qty") >= add_num) {
end_code = jsonDpjEnd.getString("point_code");
} else {
// 如果数量大于此叠盘架最大数量则查找叠盘架缓存位是否有对应空位
JSONObject jsonZcwEnd = pointTab.query("region_id = '" + RegionTypeEnum.KTPHCQB.getId() + "' and can_vehicle_type = '" + vehicle_type + "' and lock_type = '1' and is_used = '1' and is_delete = '0' and point_status = '1'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(jsonZcwEnd)) {
end_code = jsonZcwEnd.getString("point_code");
} else {
// 为空就去养生A区的等待位
JSONObject jsonEmpWait = pointTab.query("region_id = '" + RegionTypeEnum.YSAQKTPQ01.getId() + "' and row_num = '1' and can_vehicle_type = '" + vehicle_type + "' and lock_type = '1' and is_used = '1' and is_delete = '0' and point_status = '1'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(jsonEmpWait)) {
// 判断是否有任务
boolean is_point = this.isTask(jsonEmpWait.getString("point_code"));
if (is_point) {
JSONArray jsonEmpArr = pointTab.query("region_id = '" + RegionTypeEnum.YSAQKTPQ01.getId() + "' and col_num = '" + jsonEmpWait.getString("col_num") + "' and can_vehicle_type = '" + vehicle_type + "' and lock_type = '1' and is_used = '1' and is_delete = '0' and point_status = '1'").getResultJSONArray(0);
if (ObjectUtil.isNotEmpty(jsonEmpArr)) end_code = jsonEmpWait.getString("point_code");
}
}
}
}
} else {
// 2.叠盘架没有空位去找叠盘暂存位
JSONObject jsonZcwEnd = pointTab.query("region_id = '" + RegionTypeEnum.KTPHCQB.getId() + "' and can_vehicle_type = '" + vehicle_type + "' and lock_type = '1' and is_used = '1' and is_delete = '0' and point_status = '1'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(jsonZcwEnd)) {
end_code = jsonZcwEnd.getString("point_code");
} else {
// 为空就去养生A区的等待位
JSONObject jsonEmpWait = pointTab.query("region_id = '" + RegionTypeEnum.YSAQKTPQ01.getId() + "' and row_num = '1' and can_vehicle_type = '" + vehicle_type + "' and lock_type = '1' and is_used = '1' and is_delete = '0' and point_status = '1'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(jsonEmpWait)) {
// 判断是否有任务
boolean is_point = this.isTask(jsonEmpWait.getString("point_code"));
if (is_point) {
JSONArray jsonEmpArr = pointTab.query("region_id = '" + RegionTypeEnum.YSAQKTPQ01.getId() + "' and col_num = '" + jsonEmpWait.getString("col_num") + "' and can_vehicle_type = '" + vehicle_type + "' and lock_type = '1' and is_used = '1' and is_delete = '0' and point_status = '1'").getResultJSONArray(0);
if (ObjectUtil.isNotEmpty(jsonEmpArr)) end_code = jsonEmpWait.getString("point_code");
}
}
}
}
return end_code;
}
@Transactional(rollbackFor = Exception.class)
public boolean isTask(String point_code) {
/*
* 判断点位是否有任务存在
*/
WQLObject tab = WQLObject.getWQLObject("SCH_BASE_Task");
boolean result;
JSONObject jsonPointCode1 = tab.query("point_code1 = '" + point_code + "' and task_status <> '7' and is_delete = '0'").uniqueResult(0);
JSONObject jsonPointCode2 = tab.query("point_code2 = '" + point_code + "' and task_status <> '7' and is_delete = '0'").uniqueResult(0);
JSONObject jsonPointCode3 = tab.query("point_code3 = '" + point_code + "' and task_status <> '7' and is_delete = '0'").uniqueResult(0);
JSONObject jsonPointCode4 = tab.query("point_code4 = '" + point_code + "' and task_status <> '7' and is_delete = '0'").uniqueResult(0);
if (ObjectUtil.isEmpty(jsonPointCode1) && ObjectUtil.isEmpty(jsonPointCode2) && ObjectUtil.isEmpty(jsonPointCode3) && ObjectUtil.isEmpty(jsonPointCode4)) {
result = true;
} else {
result = false;
}
return result;
}
@Transactional(rollbackFor = Exception.class)
@Override
public String againApply(String task_id) {
/*
* 再次下发任务处理方法
* 涉及业务:入空载具、出空载具、入物料、出物料
*/
WQLObject taskTab = WQLObject.getWQLObject("SCH_BASE_Task"); // 任务表
WQLObject pointTab = WQLObject.getWQLObject("SCH_BASE_Point"); // 点位表
String point_code = "";
JSONObject jsonTask = taskTab.query("task_id ='" + task_id + "'").uniqueResult(0);
JSONObject jsonPoint2 = pointTab.query("point_code = '" + jsonTask.getString("point_code2") + "'").uniqueResult(0);
// 根据 区域、块、列找到第一个有物料的货位
JSONObject jsonOnePoint = pointTab.query("region_id = '" + jsonPoint2.getString("region_id") +
"' and block_num = '" + jsonPoint2.getString("block_num") +
"' and col_num = '" + jsonPoint2.getString("col_num") +
"' and point_code <> '" + jsonPoint2.getString("point_code") +
"' and point_status = '2' and lock_type = '1' order by in_empty_seq ASC").uniqueResult(0);
// 如果为空说明这一列其他货位为空 则入到最后一个货位
if (ObjectUtil.isEmpty(jsonOnePoint)) {
JSONObject jsonEmpPoint = pointTab.query("region_id = '" + jsonPoint2.getString("region_id") +
"' and block_num = '" + jsonPoint2.getString("block_num") +
"' and col_num = '" + jsonPoint2.getString("col_num") +
"' and point_code <> '" + jsonPoint2.getString("point_code") +
"' and point_status = '1' and lock_type = '1' order by in_empty_seq DESC").uniqueResult(0);
if (ObjectUtil.isNotEmpty(jsonEmpPoint)) {
point_code = jsonEmpPoint.getString("point_code");
jsonTask.put("point_code3", point_code);
taskTab.update(jsonTask);
}
} else {
// 找前一位的空位
double in_empty_seq = NumberUtil.sub(jsonOnePoint.getIntValue("in_empty_seq"), 1);
JSONObject jsonEmpPoint = pointTab.query("region_id = '" + jsonPoint2.getString("region_id") +
"' and block_num = '" + jsonPoint2.getString("block_num") +
"' and col_num = '" + jsonPoint2.getString("col_num") +
"' and point_code <> '" + jsonPoint2.getString("point_code") +
"' and in_empty_seq = '" + in_empty_seq +
"' and point_status = '1' and lock_type = '1'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(jsonEmpPoint)) {
point_code = jsonEmpPoint.getString("point_code");
jsonTask.put("point_code3", point_code);
taskTab.update(jsonTask);
}
}
if (ObjectUtil.isNotEmpty(point_code)) {
JSONObject jsonEndPoint = pointTab.query("point_code = '" + point_code + "'").uniqueResult(0);
jsonEndPoint.put("lock_type", "2");
pointTab.update(jsonEndPoint);
}
return point_code;
}
@Override
public List<AcsTaskDto> addTask() {
/*
* 下发给ACS时需要特殊处理
*/
JSONArray arr = WQLObject.getWQLObject("SCH_BASE_Task").query("handle_class = '"+THIS_CLASS+"' and task_status = '"+TaskStatusEnum.START_AND_POINT.getCode()+"' and is_delete ='0'").getResultJSONArray(0);
ArrayList<AcsTaskDto> resultList = new ArrayList<>();
for (int i = 0; i < arr.size(); i++) {
JSONObject json = arr.getJSONObject(i);
AcsTaskDto dto = AcsTaskDto.builder()
.task_id(json.getString("task_id"))
.task_code(json.getString("task_code"))
.task_type(json.getString("task_type"))
.start_device_code(json.getString("point_code1"))
.next_device_code(json.getString("point_code3"))
.vehicle_code(json.getString("vehicle_code"))
.vehicle_type(json.getString("vehicle_type"))
.priority(json.getString("priority"))
.remark(json.getString("remark"))
.build();
resultList.add(dto);
}
return resultList;
}
}