李永德
6 months ago
12 changed files with 1112 additions and 7 deletions
@ -0,0 +1,18 @@ |
|||||
|
package org.nl.wms.ext.erp.rest; |
||||
|
|
||||
|
import io.swagger.annotations.Api; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
/** |
||||
|
* @Author: lyd |
||||
|
* @Description: Erp请求Wms |
||||
|
* @Date: 2024/5/13 |
||||
|
*/ |
||||
|
@RestController |
||||
|
@Api(tags = "erp请求wms") |
||||
|
@RequestMapping("/api/erp/task") |
||||
|
@Slf4j |
||||
|
public class ErpToWmsController { |
||||
|
} |
@ -0,0 +1,9 @@ |
|||||
|
package org.nl.wms.ext.erp.service; |
||||
|
|
||||
|
/** |
||||
|
* @Author: lyd |
||||
|
* @Description: |
||||
|
* @Date: 2024/5/13 |
||||
|
*/ |
||||
|
public interface ErpToWmsService { |
||||
|
} |
@ -0,0 +1,15 @@ |
|||||
|
package org.nl.wms.ext.erp.service.impl; |
||||
|
|
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.nl.wms.ext.erp.service.ErpToWmsService; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
/** |
||||
|
* @Author: lyd |
||||
|
* @Description: |
||||
|
* @Date: 2024/5/13 |
||||
|
*/ |
||||
|
@Service |
||||
|
@Slf4j |
||||
|
public class ErpToWmsServiceImpl implements ErpToWmsService { |
||||
|
} |
@ -0,0 +1,194 @@ |
|||||
|
package org.nl.wms.sch.task.p2p; |
||||
|
|
||||
|
import cn.hutool.core.util.ObjectUtil; |
||||
|
import cn.hutool.core.util.StrUtil; |
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import org.nl.modules.common.exception.BadRequestException; |
||||
|
import org.nl.modules.common.utils.SecurityUtils; |
||||
|
import org.nl.modules.wql.core.bean.WQLObject; |
||||
|
import org.nl.wms.sch.manage.*; |
||||
|
import org.nl.wms.sch.task.util.TaskUtils; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
/** |
||||
|
* @Author: lyd |
||||
|
* @Description: 手持点对点任务类 |
||||
|
* @Date: 2024/5/14 |
||||
|
*/ |
||||
|
@RequiredArgsConstructor |
||||
|
@Component |
||||
|
public class PDATask extends AbstractAcsTask { |
||||
|
@Override |
||||
|
public void updateTaskStatus(JSONObject task, String status) { |
||||
|
if (TaskStatus.EXECUTING.value().equals(status)) { |
||||
|
task.put("task_status", TaskStatus.EXECUTING.value()); |
||||
|
TaskUtils.addACSUpdateColum(task); |
||||
|
WQLObject.getWQLObject("sch_base_task").update(task); |
||||
|
} else if (TaskStatus.FINISHED.value().equals(status)) { |
||||
|
this.finishTask(task, OperationType.AUTO); |
||||
|
} else if (TaskStatus.CANCELLED.value().equals(status)) { |
||||
|
this.cancelTask(task, OperationType.AUTO); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String createTask(JSONObject form) { |
||||
|
JSONObject point1 = form.getJSONObject("point1"); |
||||
|
JSONObject point2 = form.getJSONObject("point2"); |
||||
|
|
||||
|
JSONObject task = TaskUtils.buildTask( |
||||
|
"手持点对点任务", |
||||
|
TaskType.PDA_TASK.value(), |
||||
|
TaskStatus.START_AND_END.value(), |
||||
|
point1.getString("point_code"), |
||||
|
point2.getString("point_code"), |
||||
|
form.getLong("group_id"), |
||||
|
null, |
||||
|
form.getString("vehicle_type"), |
||||
|
form.getString("vehicle_code"), |
||||
|
8, |
||||
|
PDATask.class.getName(), |
||||
|
form.getString("create_mode"), |
||||
|
JSONObject.toJSONString(form), |
||||
|
String.valueOf(SecurityUtils.getCurrentUserId()), |
||||
|
SecurityUtils.getCurrentUsername() |
||||
|
); |
||||
|
|
||||
|
point1.put("lock_type", LockType.TASK_LOCKED.value()); |
||||
|
point1.put("task_code", task.getString("task_code")); |
||||
|
TaskUtils.addFormUpdateColum(point1, form); |
||||
|
WQLObject pointTable = WQLObject.getWQLObject("sch_base_point"); |
||||
|
pointTable.update(point1); |
||||
|
|
||||
|
point2.put("lock_type", LockType.TASK_LOCKED.value()); |
||||
|
point2.put("task_code", task.getString("task_code")); |
||||
|
TaskUtils.addFormUpdateColum(point2, form); |
||||
|
pointTable.update(point2); |
||||
|
|
||||
|
WQLObject.getWQLObject("sch_base_task").insert(task); |
||||
|
|
||||
|
return task.getString("task_code"); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void forceFinish(String task_id) { |
||||
|
JSONObject task = WQLObject.getWQLObject("sch_base_task").query("task_id = " + task_id).uniqueResult(0); |
||||
|
if (ObjectUtil.isEmpty(task)) { |
||||
|
throw new BadRequestException("未找到任务!"); |
||||
|
} |
||||
|
this.finishTask(task, OperationType.MANUAL); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
public void cancel(String task_id) { |
||||
|
JSONObject task = WQLObject.getWQLObject("sch_base_task").query("task_id = " + task_id).uniqueResult(0); |
||||
|
if (ObjectUtil.isEmpty(task)) { |
||||
|
throw new BadRequestException("未找到任务!"); |
||||
|
} |
||||
|
this.cancelTask(task, OperationType.MANUAL); |
||||
|
} |
||||
|
|
||||
|
public void cancelTask(JSONObject task, OperationType operation_type) { |
||||
|
if (task.getIntValue("task_status") < Integer.parseInt(TaskStatus.FINISHED.value())) { |
||||
|
task.put("task_status", TaskStatus.CANCELLED.value()); |
||||
|
if (operation_type == OperationType.AUTO) { |
||||
|
TaskUtils.addACSUpdateColum(task); |
||||
|
} else if (operation_type == OperationType.MANUAL) { |
||||
|
TaskUtils.addCurrentUpdateColum(task); |
||||
|
} |
||||
|
WQLObject.getWQLObject("sch_base_task").update(task); |
||||
|
|
||||
|
WQLObject point_table = WQLObject.getWQLObject("sch_base_point"); |
||||
|
|
||||
|
String point_code1 = task.getString("point_code1"); |
||||
|
if (StrUtil.isNotBlank(point_code1)) { |
||||
|
JSONObject point1 = point_table.query("point_code = '" + point_code1 + "'").uniqueResult(0); |
||||
|
if (ObjectUtil.isNotEmpty(point1) |
||||
|
&& LockType.TASK_LOCKED.value().equals(point1.getString("lock_type")) |
||||
|
&& task.getString("task_code").equals(point1.getString("task_code"))) { |
||||
|
point1.put("lock_type", LockType.UNLOCKED.value()); |
||||
|
point1.put("task_code", ""); |
||||
|
if (operation_type == OperationType.AUTO) { |
||||
|
TaskUtils.addACSUpdateColum(point1); |
||||
|
} else if (operation_type == OperationType.MANUAL) { |
||||
|
TaskUtils.addCurrentUpdateColum(point1); |
||||
|
} |
||||
|
point_table.update(point1); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
String point_code2 = task.getString("point_code2"); |
||||
|
if (StrUtil.isNotBlank(point_code2)) { |
||||
|
JSONObject point2 = new JSONObject(); |
||||
|
point2.put("lock_type", LockType.UNLOCKED.value()); |
||||
|
point2.put("task_code", ""); |
||||
|
if (operation_type == OperationType.AUTO) { |
||||
|
TaskUtils.addACSUpdateColum(point2); |
||||
|
} else if (operation_type == OperationType.MANUAL) { |
||||
|
TaskUtils.addCurrentUpdateColum(point2); |
||||
|
} |
||||
|
point_table.update(point2, "point_code = '" + point_code2 + "'"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public void finishTask(JSONObject task, OperationType operation_type) { |
||||
|
int current_task_status = task.getIntValue("task_status"); |
||||
|
if (current_task_status < Integer.parseInt(TaskStatus.FINISHED.value())) { |
||||
|
if (operation_type == OperationType.MANUAL |
||||
|
&& current_task_status < Integer.parseInt(TaskStatus.START_AND_END.value())) { |
||||
|
throw new BadRequestException("只能手动完成 [确认起点和终点] 之后的任务!"); |
||||
|
} |
||||
|
|
||||
|
task.put("task_status", TaskStatus.FINISHED.value()); |
||||
|
if (operation_type == OperationType.AUTO) { |
||||
|
TaskUtils.addACSUpdateColum(task); |
||||
|
} else if (operation_type == OperationType.MANUAL) { |
||||
|
TaskUtils.addCurrentUpdateColum(task); |
||||
|
} |
||||
|
WQLObject.getWQLObject("sch_base_task").update(task); |
||||
|
|
||||
|
WQLObject point_table = WQLObject.getWQLObject("sch_base_point"); |
||||
|
|
||||
|
String point_code1 = task.getString("point_code1"); |
||||
|
if (StrUtil.isNotBlank(point_code1)) { |
||||
|
JSONObject point1 = point_table.query("point_code = '" + point_code1 + "'").uniqueResult(0); |
||||
|
if (LockType.TASK_LOCKED.value().equals(point1.getString("lock_type")) |
||||
|
&& task.getString("task_code").equals(point1.getString("task_code"))) { |
||||
|
point1.put("lock_type", LockType.UNLOCKED.value()); |
||||
|
point1.put("task_code", ""); |
||||
|
point1.put("vehicle_type", ""); |
||||
|
point1.put("vehicle_code", ""); |
||||
|
point1.put("vd_id", null); |
||||
|
point1.put("point_status", PointStatus.EMPTY.value()); |
||||
|
if (operation_type == OperationType.AUTO) { |
||||
|
TaskUtils.addACSUpdateColum(point1); |
||||
|
} else if (operation_type == OperationType.MANUAL) { |
||||
|
TaskUtils.addCurrentUpdateColum(point1); |
||||
|
} |
||||
|
point_table.update(point1); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
String point_code2 = task.getString("point_code2"); |
||||
|
if (StrUtil.isNotBlank(point_code2)) { |
||||
|
JSONObject point2 = new JSONObject(); |
||||
|
point2.put("lock_type", LockType.UNLOCKED.value()); |
||||
|
point2.put("task_code", ""); |
||||
|
point2.put("vehicle_type", task.getString("vehicle_type")); |
||||
|
point2.put("vehicle_code", task.getString("vehicle_code")); |
||||
|
point2.put("vd_id", task.getString("group_id")); |
||||
|
point2.put("point_status", PointStatus.NOT_EMPTY.value()); |
||||
|
if (operation_type == OperationType.AUTO) { |
||||
|
TaskUtils.addACSUpdateColum(point2); |
||||
|
} else if (operation_type == OperationType.MANUAL) { |
||||
|
TaskUtils.addCurrentUpdateColum(point2); |
||||
|
} |
||||
|
point_table.update(point2, "point_code = '" + point_code2 + "'"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue