30 changed files with 507 additions and 1193 deletions
@ -1,449 +0,0 @@ |
|||
package org.nl.wms.sch.tasks.sendEmpty; |
|||
|
|||
import cn.hutool.core.date.DateUtil; |
|||
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; |
|||
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.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.manage.RegionTypeEnum; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 一楼往二楼送空托盘业务 |
|||
*/ |
|||
@Service |
|||
@RequiredArgsConstructor |
|||
@Slf4j |
|||
public class HtSendEmpVehicleTask extends AbstractAcsTask { |
|||
private final String THIS_CLASS = HtSendEmpVehicleTask.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")) { |
|||
// 取消删除任务
|
|||
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 + "'"); |
|||
} |
|||
|
|||
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_time", DateUtil.now()); |
|||
taskTab.update(jsonTask); |
|||
|
|||
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(endPoint.getString("region_id"), RegionTypeEnum.DPJQA.getId())) { |
|||
Integer vehicle_qty = endPoint.getInteger("vehicle_qty"); |
|||
vehicle_qty += jsonTask.getInteger("vehicle_qty"); |
|||
endPoint.put("lock_type", "1"); |
|||
endPoint.put("vehicle_qty", vehicle_qty); |
|||
endPoint.put("point_status", "2"); |
|||
endPoint.put("vehicle_type", jsonTask.getString("vehicle_type")); |
|||
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", "2"); |
|||
pointTab.update(endPoint); |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public String createTask(JSONObject form) { |
|||
/* |
|||
* 1.先生成确定起点的任务 |
|||
* 2.通过findNextPoint()找终点 |
|||
* 3.下发给ACS |
|||
*/ |
|||
WQLObject taskTab = WQLObject.getWQLObject("SCH_BASE_Task"); // 任务表
|
|||
|
|||
String point_code1 = form.getString("point_code1"); |
|||
|
|||
SchTaskDto dto = SchTaskDto.builder().task_id(org.nl.wms.util.IdUtil.getLongId()) |
|||
.task_code(CodeUtil.getNewCode("TASK_CODE")) |
|||
.task_type("") |
|||
.task_name("电梯送空载具") |
|||
.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()); |
|||
} |
|||
|
|||
@Override |
|||
public void findNextPoint() { |
|||
/* |
|||
* 根据业务找对应的终点 |
|||
*/ |
|||
WQLObject taskTab = WQLObject.getWQLObject("SCH_BASE_Task"); |
|||
WQLObject pointTab = WQLObject.getWQLObject("sch_base_point"); |
|||
|
|||
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 point_code_ht = ""; |
|||
|
|||
//判断SSX01A1是否有任务没有则判断其他的三个点位
|
|||
boolean ssx_1 = this.isTask("SSX01A1"); |
|||
if (ssx_1) { |
|||
String like = "SSX01%"; |
|||
|
|||
JSONArray taskArrNum = new JSONArray(); |
|||
JSONArray pointArr = pointTab.query("region_id = '" + RegionTypeEnum.SSX.getId() + "' and is_used = '1' and is_delete = '0' and point_code like '" + like + "'").getResultJSONArray(0); |
|||
|
|||
for (int j = 0; j < pointArr.size(); j++) { |
|||
JSONObject json = pointArr.getJSONObject(j); |
|||
boolean is_empTask = this.isTask(json.getString("point_code")); |
|||
|
|||
if (!is_empTask) taskArrNum.add(json); |
|||
} |
|||
|
|||
if (taskArrNum.size() > 0) { |
|||
|
|||
} else { |
|||
point_code_ht = "SSX01A1"; |
|||
} |
|||
} |
|||
|
|||
// 判断SSX02A1是否有任务没有则判断其他的三个点位
|
|||
if (ObjectUtil.isEmpty(point_code_ht)) { |
|||
boolean ssx_2 = this.isTask("SSX02A1"); |
|||
if (ssx_2) { |
|||
String like = "SSX02%"; |
|||
|
|||
JSONArray taskArrNum = new JSONArray(); |
|||
JSONArray pointArr = pointTab.query("region_id = '" + RegionTypeEnum.SSX.getId() + "' and is_used = '1' and is_delete = '0' and point_code like '" + like + "'").getResultJSONArray(0); |
|||
|
|||
for (int k = 0; k < pointArr.size(); k++) { |
|||
JSONObject json = pointArr.getJSONObject(k); |
|||
boolean is_empTask = this.isTask(json.getString("point_code")); |
|||
|
|||
if (!is_empTask) taskArrNum.add(json); |
|||
} |
|||
|
|||
if (taskArrNum.size() > 0) { |
|||
|
|||
} else { |
|||
point_code_ht = "SSX02A1"; |
|||
} |
|||
} |
|||
} |
|||
|
|||
// 如果此时point_code_ht为空则循环下一个任务
|
|||
if (ObjectUtil.isEmpty(point_code_ht)) { |
|||
continue; |
|||
} |
|||
|
|||
// 说明货梯无任务:找终点
|
|||
JSONObject param = new JSONObject(); |
|||
param.put("vehicle_type", jsonTask.getString("vehicle_type")); |
|||
param.put("qty", jsonTask.getString("vehicle_qty")); |
|||
String endPoint = this.endPoint(param); |
|||
|
|||
// 如果此时endPoint为空则循环下一个任务
|
|||
if (ObjectUtil.isEmpty(endPoint)) { |
|||
continue; |
|||
} |
|||
|
|||
// 更新任务表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) { |
|||
/* |
|||
* 强制完成 |
|||
*/ |
|||
WQLObject taskTab = WQLObject.getWQLObject("SCH_BASE_Task"); |
|||
JSONObject taskObj = taskTab.query("task_id = '" + task_id + "' and is_delete = '0' and task_status <> " + TaskStatusEnum.FINISHED.getCode()).uniqueResult(0); |
|||
if (ObjectUtil.isNotEmpty(taskObj)) |
|||
this.updateTaskStatus(taskObj,"2"); |
|||
else { |
|||
throw new BadRequestException("未找到该任务或者任务已完成!"); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void cancel(String task_id) { |
|||
WQLObject taskTab = WQLObject.getWQLObject("SCH_BASE_Task"); |
|||
JSONObject taskObj = taskTab.query("task_id = '" + task_id + "' and is_delete = '0' and task_status <> " + TaskStatusEnum.FINISHED.getCode()).uniqueResult(0); |
|||
if (ObjectUtil.isNotEmpty(taskObj)) |
|||
this.updateTaskStatus(taskObj,"0"); |
|||
else { |
|||
throw new BadRequestException("未找到该任务或者任务已完成!"); |
|||
} |
|||
} |
|||
|
|||
@Transactional(rollbackFor = Exception.class) |
|||
public String endPoint(JSONObject param) { |
|||
/* |
|||
* 1.叠盘架有A对应货位 规则:如果暂存位能放下则放暂存位如果放不下则走2或3 |
|||
* 2.叠盘架A没有货位 则去叠盘架暂存位 |
|||
* 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.DPJQA.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.KTPHCQA.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 col_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 row_num = '" + jsonEmpWait.getString("row_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.KTPHCQA.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 col_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 row_num = '" + jsonEmpWait.getString("row_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 row_num = '" + jsonPoint2.getString("row_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 row_num = '" + jsonPoint2.getString("row_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 row_num = '" + jsonPoint2.getString("row_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); |
|||
} |
|||
//判断点位是否属于养生A区
|
|||
if (point_code.startsWith("2")) { |
|||
//养生A区发给ACS需要新的点位(2101-03-1----->21011-03-1)
|
|||
point_code = point_code.substring(0, 4) + "1" + point_code.substring(4, 9); |
|||
} |
|||
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); |
|||
|
|||
String point_code3=json.getString("point_code3"); |
|||
//判断终点是否属于养生A区
|
|||
if (point_code3.startsWith("2")) { |
|||
//养生A区发给ACS需要新的点位(2101-03-1----->21011-03-1)
|
|||
point_code3 = point_code3.substring(0, 4) + "1" + point_code3.substring(4, 9); |
|||
} |
|||
|
|||
|
|||
AcsTaskDto dto = AcsTaskDto.builder() |
|||
.task_id(json.getString("task_id")) |
|||
.task_code(json.getString("task_code")) |
|||
.task_type(json.getString("acs_task_type")) |
|||
.start_device_code(json.getString("point_code1")) |
|||
.next_device_code(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; |
|||
} |
|||
} |
@ -1,403 +0,0 @@ |
|||
package org.nl.wms.sch.tasks.sendEmpty; |
|||
|
|||
import cn.hutool.core.date.DateUtil; |
|||
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; |
|||
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.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.manage.RegionTypeEnum; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
@Service |
|||
@RequiredArgsConstructor |
|||
@Slf4j |
|||
public class YqxSendEmpVehicleTask extends AbstractAcsTask { |
|||
private final String THIS_CLASS = YqxSendEmpVehicleTask.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")) { |
|||
// 取消删除任务
|
|||
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 + "'"); |
|||
} |
|||
|
|||
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_time", DateUtil.now()); |
|||
taskTab.update(jsonTask); |
|||
|
|||
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(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"); |
|||
endPoint.put("vehicle_qty", vehicle_qty); |
|||
endPoint.put("point_status", "2"); |
|||
endPoint.put("vehicle_type", jsonTask.getString("vehicle_type")); |
|||
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", "2"); |
|||
pointTab.update(endPoint); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public String createTask(JSONObject form) { |
|||
/* |
|||
* 1.先生成确定起点的任务 |
|||
* 2.通过findNextPoint()找终点 |
|||
* 3.下发给ACS |
|||
*/ |
|||
WQLObject taskTab = WQLObject.getWQLObject("SCH_BASE_Task"); // 任务表
|
|||
|
|||
String point_code1 = form.getString("point_code1"); |
|||
|
|||
SchTaskDto dto = SchTaskDto.builder().task_id(org.nl.wms.util.IdUtil.getLongId()) |
|||
.task_code(CodeUtil.getNewCode("TASK_CODE")) |
|||
.task_type("") |
|||
.task_name("油漆线空盘入库") |
|||
.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()); |
|||
} |
|||
|
|||
/** |
|||
* @return |
|||
* @discription 确定下一点位 |
|||
* @author ldjun |
|||
* @created 2020年6月12日 下午6:01:06 |
|||
*/ |
|||
@Override |
|||
public void findNextPoint() { |
|||
/* |
|||
* 根据业务找对应的终点 |
|||
*/ |
|||
WQLObject taskTab = WQLObject.getWQLObject("SCH_BASE_Task"); |
|||
WQLObject pointTab = WQLObject.getWQLObject("sch_base_point"); |
|||
|
|||
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); |
|||
|
|||
// 找终点
|
|||
JSONObject param = new JSONObject(); |
|||
param.put("vehicle_type", jsonTask.getString("vehicle_type")); |
|||
param.put("qty", jsonTask.getString("vehicle_qty")); |
|||
String endPoint = this.endPoint(param); |
|||
|
|||
// 如果此时endPoint为空则循环下一个任务
|
|||
if (ObjectUtil.isEmpty(endPoint)) { |
|||
continue; |
|||
} |
|||
|
|||
// 更新任务表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) { |
|||
/* |
|||
* 强制完成 |
|||
*/ |
|||
WQLObject taskTab = WQLObject.getWQLObject("SCH_BASE_Task"); |
|||
JSONObject taskObj = taskTab.query("task_id = '" + task_id + "' and is_delete = '0' and task_status <> " + TaskStatusEnum.FINISHED.getCode()).uniqueResult(0); |
|||
if (ObjectUtil.isNotEmpty(taskObj)) |
|||
this.updateTaskStatus(taskObj,"2"); |
|||
else { |
|||
throw new BadRequestException("未找到该任务或者任务已完成!"); |
|||
} |
|||
} |
|||
|
|||
|
|||
@Override |
|||
public void cancel(String task_id) { |
|||
WQLObject taskTab = WQLObject.getWQLObject("SCH_BASE_Task"); |
|||
JSONObject taskObj = taskTab.query("task_id = '" + task_id + "' and is_delete = '0' and task_status <> " + TaskStatusEnum.FINISHED.getCode()).uniqueResult(0); |
|||
if (ObjectUtil.isNotEmpty(taskObj)) |
|||
this.updateTaskStatus(taskObj,"0"); |
|||
else { |
|||
throw new BadRequestException("未找到该任务或者任务已完成!"); |
|||
} |
|||
} |
|||
|
|||
@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 col_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 row_num = '" + jsonEmpWait.getString("row_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 col_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 row_num = '" + jsonEmpWait.getString("row_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 row_num = '" + jsonPoint2.getString("row_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 row_num = '" + jsonPoint2.getString("row_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 row_num = '" + jsonPoint2.getString("row_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); |
|||
} |
|||
//判断点位是否属于养生A区
|
|||
if (point_code.startsWith("2")) { |
|||
//养生A区发给ACS需要新的点位(2101-03-1----->21011-03-1)
|
|||
point_code = point_code.substring(0, 4) + "1" + point_code.substring(4, 9); |
|||
} |
|||
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); |
|||
String point_code3 = json.getString("point_code3"); |
|||
//判断终点是否属于养生A区
|
|||
if (point_code3.startsWith("2")) { |
|||
//养生A区发给ACS需要新的点位(2101-03-1----->21011-03-1)
|
|||
point_code3 = point_code3.substring(0, 4) + "1" + point_code3.substring(4, 9); |
|||
} |
|||
|
|||
|
|||
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(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; |
|||
} |
|||
|
|||
|
|||
} |
Binary file not shown.
Loading…
Reference in new issue