Browse Source

add:mes接口

master2
刘先源 2 months ago
parent
commit
4190e6eb87
  1. 32
      lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/mes/controller/MesToWmsController.java
  2. 64
      lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/mes/service/MesToWmsService.java
  3. 52
      lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/mes/service/dto/ResultTaskMesDto.java
  4. 286
      lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/mes/service/impl/MesToWmsServiceImpl.java
  5. 42
      lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/region/enums/RegionEnum.java
  6. 4
      lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task/service/dao/SchBaseTask.java
  7. 1
      lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task/service/impl/SchBaseTaskServiceImpl.java
  8. 97
      lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/AbstractTask.java
  9. 41
      lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/enums/GroupStatusEnum.java
  10. 36
      lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/enums/WorkOrderStatusEnum.java
  11. 1
      lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/TaskListType.java
  12. 34
      lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/TaskServiceImpl.java
  13. 1
      lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/core/TaskApplyDto.java
  14. 11
      lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/core/TaskDto.java
  15. 4
      lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/core/TaskStatus.java
  16. 233
      lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/fj/FJSLTask.java
  17. 132
      lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/fj/MABCTask.java

32
lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/mes/controller/MesToWmsController.java

@ -1,7 +1,15 @@
package org.nl.wms.ext.mes.controller;
import cn.dev33.satoken.annotation.SaIgnore;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.nl.common.logging.annotation.Log;
import org.nl.wms.ext.mes.service.MesToWmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -17,4 +25,28 @@ import org.springframework.web.bind.annotation.RestController;
@SaIgnore
public class MesToWmsController {
@Autowired
private MesToWmsService mesToWmsService;
@PostMapping("/TaskSend")
@Log("mes下发任务")
@SaIgnore
public ResponseEntity<Object> taskSend(@RequestBody JSONObject jo) {
return new ResponseEntity<>(mesToWmsService.taskSend(jo), HttpStatus.OK);
}
@PostMapping("/SearchTasks")
@Log("mes查看任务")
@SaIgnore
public ResponseEntity<Object> searchTasks(@RequestBody JSONObject jo) {
return new ResponseEntity<>(mesToWmsService.SearchTasks(jo), HttpStatus.OK);
}
@PostMapping("/DeleteTask")
@Log("mes删除任务")
@SaIgnore
public ResponseEntity<Object> deleteTask(@RequestBody JSONObject jo) {
return new ResponseEntity<>(mesToWmsService.deleteTask(jo), HttpStatus.OK);
}
}

64
lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/mes/service/MesToWmsService.java

@ -1,9 +1,73 @@
package org.nl.wms.ext.mes.service;
import com.alibaba.fastjson.JSONObject;
/**
* @Author: lyd
* @Description: mes请求wms
* @Date: 2023/8/3
*/
public interface MesToWmsService {
/**
* mes下发任务任务是数组形式下发返回结果也要数组形式返回
* @param jo {
* item : [
* {
* TaskCode: 任务编码
* PickingLocation: 取料货位
* PlacedLocation: 放料库位
* Priority: 优先级
* MsgTime: 下发时间
* }
* ]
* }
* @return {
* item : [
* {
* TaskCode: 任务编码
* ReturnStatus: 下发结果0-成功1-失败
* ReturnInfo: 请求结果描述1-AVG可立即执行任务2-立库入库口占用无法执行3-不能立即派送
* ReturnCount: 返回空车库位剩余数量
* MsgTime: 返回时间
* }
* ]
* }
*/
JSONObject taskSend(JSONObject jo);
/**
* mes查看任务
* @param jo {}
* @return JSONObject {
* ReturnStatus 任务下发结果
* MsgTime 返回时间
* TaskLists任务列表 [
* {
* TaskCode任务编码
* PickingLocation取料货位
* PlacedLocation放料货位
* TaskStatus任务状态
* ExecutingAGV执行AVG名称
* CreateTime创建时间
* ExecuteTime执行时间
* }
* ]
* }
*/
JSONObject SearchTasks(JSONObject jo);
/**
* mes删除任务
* @param jo{
* TaskCode 任务编码
* }
* @return JSONObject{
* ReturnStatus删除结果0-成功1-失败
* ReturnInfo结果描述
* MsgTime返回时间
* }
*/
JSONObject deleteTask(JSONObject jo);
}

52
lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/mes/service/dto/ResultTaskMesDto.java

@ -0,0 +1,52 @@
package org.nl.wms.ext.mes.service.dto;
import lombok.Builder;
import lombok.Data;
import java.util.Map;
/**
* @Author: lxy
* @Description: 返回mes任务
* @Date: 2024/9/24
*/
@Data
@Builder
public class ResultTaskMesDto {
/**
* 任务编码
*/
String TaskCode;
/**
* 取料货位
*/
String PickingLocation;
/**
* 放料货位
*/
String PlacedLocation;
/**
* 任务状态
*/
String TaskStatus;
/**
* 执行AVG名称
*/
String ExecutingAGV;
/**
* 创建时间
*/
String CreateTime;
/**
* 执行时间
*/
String ExecuteTime;
}

286
lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/ext/mes/service/impl/MesToWmsServiceImpl.java

@ -1,8 +1,37 @@
package org.nl.wms.ext.mes.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpStatus;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.nl.common.exception.BadRequestException;
import org.nl.config.SpringContextHolder;
import org.nl.wms.ext.acs.service.WmsToAcsService;
import org.nl.wms.ext.acs.service.dto.to.wms.AcsResponse;
import org.nl.wms.ext.mes.service.MesToWmsService;
import org.nl.wms.ext.mes.service.dto.ResultTaskMesDto;
import org.nl.wms.sch.point.service.ISchBasePointService;
import org.nl.wms.sch.point.service.dao.SchBasePoint;
import org.nl.wms.sch.region.enums.RegionEnum;
import org.nl.wms.sch.task.service.ISchBaseTaskService;
import org.nl.wms.sch.task.service.ISchBaseTaskconfigService;
import org.nl.wms.sch.task.service.dao.SchBaseTask;
import org.nl.wms.sch.task.service.dao.SchBaseTaskconfig;
import org.nl.wms.sch.task_manage.AbstractTask;
import org.nl.wms.sch.task_manage.AcsTaskDto;
import org.nl.wms.sch.task_manage.task.TaskFactory;
import org.nl.wms.sch.task_manage.task.core.TaskStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @Author: lyd
@ -13,4 +42,261 @@ import org.springframework.stereotype.Service;
@Service
public class MesToWmsServiceImpl implements MesToWmsService {
/**
* 点位服务
*/
@Autowired
private ISchBasePointService iSchBasePointService;
/**
* 任务配置服务
*/
@Autowired
private ISchBaseTaskconfigService iSchBaseTaskconfigService;
/**
* 任务工厂服务
*/
@Autowired
private TaskFactory taskFactory;
/**
* 调用acs服务
*/
@Autowired
private WmsToAcsService wmsToAcsService;
/**
* 任务服务
*/
@Autowired
private ISchBaseTaskService taskService;
@Override
@Transactional(rollbackFor = Exception.class)
public JSONObject taskSend(JSONObject jo) {
// 返回给mes的结果
JSONObject result = new JSONObject();
// 需要返回的所有任务及状态
List<JSONObject> resultAllList = new ArrayList<>();
// 错误数组集合
List<JSONObject> erroList = new ArrayList<>();
// 可创建任务数组集合
List<JSONObject> taskCreateList = new ArrayList<>();
// mes下发任务的集合
List<JSONObject> itemList = jo.getJSONArray("item").toJavaList(JSONObject.class);
// 查询所有点位
List<SchBasePoint> pointList = iSchBasePointService.list(
new QueryWrapper<SchBasePoint>().lambda()
.eq(SchBasePoint::getIs_used, RegionEnum.IS_NOTANDYES.code("是"))
);
// 循环判断任务类型
for (JSONObject jsonItem : itemList) {
// 判断任务类型
JSONObject json = ifTaskType(jsonItem, pointList);
// 判断是否是错误的
if (json.getString("is_erro").equals(RegionEnum.IS_NOTANDYES.code("是"))) {
JSONObject jsonErro = new JSONObject();
jsonErro.put("TaskCode", jsonItem.getString("TaskCode"));
jsonErro.put("ReturnStatus", 1);
jsonErro.put("ReturnInfo", json.getString("message"));
jsonErro.put("ReturnCount", "");
jsonErro.put("MsgTime", DateUtil.now());
erroList.add(jsonErro);
} else {
jsonItem.put("task_type",json.getString("task_type"));
taskCreateList.add(jsonItem);
}
}
// 需下发给acs的任务
List<AcsTaskDto> sendAcsList = new ArrayList<>();
// 创建任务
for (JSONObject json : taskCreateList) {
// 根据任务类型反射得到任务类创建任务
AbstractTask task = taskFactory.getTask(json.getString("task_type"));
String taskId = task.create(json);
// 下发前任务整理
AcsTaskDto acsTaskDto = task.sendAcsParam(taskId);
sendAcsList.add(acsTaskDto);
}
// 调用下发acs
AcsResponse acsResponse = wmsToAcsService.renotifyAcs(sendAcsList);
if (acsResponse.getCode() == HttpStatus.HTTP_BAD_REQUEST) {
// 说明有报错,处理报错内容
List<JSONObject> resultErroList = acsResponse.getErrArr().toJavaList(JSONObject.class);
for (JSONObject json : resultErroList) {
JSONObject jsonErro = new JSONObject();
jsonErro.put("TaskCode",json.getString("task_code"));
jsonErro.put("ReturnStatus",1);
jsonErro.put("ReturnInfo",json.getString("message"));
jsonErro.put("ReturnCount", "");
jsonErro.put("MsgTime", DateUtil.now());
erroList.add(jsonErro);
}
}
// 找出未报错的任务集合
String taskCodeIn = erroList.stream()
.map(row -> row.getString("TaskCode"))
.collect(Collectors.joining("','"));
// 下发成功的任务集合
List<JSONObject> taskList = itemList.stream()
.filter(row -> !taskCodeIn.contains(row.getString("TaskCode")))
.collect(Collectors.toList());
for (JSONObject json : taskList) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("TaskCode",json.getString("TaskCode"));
jsonObject.put("ReturnStatus",0);
jsonObject.put("ReturnInfo","");
jsonObject.put("ReturnCount","");
jsonObject.put("MsgTime",DateUtil.now());
resultAllList.add(jsonObject);
}
resultAllList.addAll(erroList);
result.put("item", resultAllList);
return result;
}
@Override
public JSONObject SearchTasks(JSONObject jo) {
JSONObject result = new JSONObject();
// 查询所有任务
List<SchBaseTask> taskList = taskService.list(
new QueryWrapper<SchBaseTask>().lambda()
.eq(SchBaseTask::getIs_delete, RegionEnum.IS_NOTANDYES.code("否"))
);
// 处理需返回数据
List<ResultTaskMesDto> mesDtoList = new ArrayList<>();
for (SchBaseTask dao : taskList) {
ResultTaskMesDto mesDto = ResultTaskMesDto.builder()
.TaskCode(dao.getTask_code())
.PickingLocation(dao.getPoint_code1())
.PlacedLocation(dao.getPoint_code2())
.TaskStatus(dao.getTask_status())
.ExecutingAGV("")
.CreateTime(dao.getCreate_time())
.ExecuteTime(dao.getUpdate_time())
.build();
mesDtoList.add(mesDto);
}
// 返回结果
result.put("ReturnStatus", 0);
result.put("MsgTime", DateUtil.now());
result.put("TaskLists", mesDtoList);
return result;
}
@Override
@Transactional(rollbackFor = Exception.class)
public JSONObject deleteTask(JSONObject jo) {
JSONObject result = new JSONObject();
// 根据任务号查询出对应任务
SchBaseTask taskDao = taskService.getByCode(jo.getString("TaskCode"));
if (ObjectUtil.isEmpty(taskDao)) {
result.put("ReturnStatus", 1);
result.put("ReturnInfo", "没有查到任务号为【"+jo.getString("TaskCode")+"】的任务!");
result.put("MsgTime", DateUtil.now());
return result;
}
// 判断此任务的状态是否能删除
if (Integer.parseInt(taskDao.getTask_status()) > Integer.parseInt(TaskStatus.ISSUED.getCode())) {
result.put("ReturnStatus", 1);
result.put("ReturnInfo", "任务号为【"+jo.getString("TaskCode")+"】的任务正在执行中或者已完成,不能取消任务!");
result.put("MsgTime", DateUtil.now());
return result;
}
// 组织需要删除的任务参数
Map<String, Object> param = new HashMap<>();
param.put("task_code",taskDao.getTask_code());
param.put("method_name", "cancel");
param.put("config_code", taskDao.getConfig_code());
taskService.operation(param);
result.put("ReturnStatus",0);
result.put("ReturnInfo", "任务【"+jo.getString("TaskCode")+"】删除成功!");
result.put("MsgTime", DateUtil.now());
return result;
}
/**
* 判断任务类型
* @param jsonItem mes下发的任务
* @param pointList 所有点位集合
* @return JSONObject {
* task_type: 任务类型
* is_erro: 是否错误1-0-
* message: 错误信息
* }
*/
private JSONObject ifTaskType(JSONObject jsonItem, List<SchBasePoint> pointList) {
JSONObject result = new JSONObject();
// 查询起点点位所属的区域
SchBasePoint startPoint = pointList.stream()
.filter(row -> row.getPoint_code().equals(jsonItem.getString("PickingLocation")))
.findFirst().orElse(null);
if (ObjectUtil.isEmpty(startPoint)) {
result.put("is_erro",RegionEnum.IS_NOTANDYES.code("是"));
result.put("message","取货点位【"+jsonItem.getString("PickingLocation")+"】在LMS系统不存在或未启用!");
return result;
}
// 查询终点点位所属的区域
SchBasePoint nextPoint = pointList.stream()
.filter(row -> row.getPoint_code().equals(jsonItem.getString("PlacedLocation")))
.findFirst().orElse(null);
if (ObjectUtil.isEmpty(nextPoint)) {
result.put("is_erro",RegionEnum.IS_NOTANDYES.code("是"));
result.put("message","放货点位【"+jsonItem.getString("PlacedLocation")+"】在LMS系统不存在或未启用!");
return result;
}
// 判断任务类型
String task_code = ifTaskRegion(startPoint.getRegion_code(), nextPoint.getRegion_code());
if (ObjectUtil.isEmpty(task_code)) {
result.put("is_erro",RegionEnum.IS_NOTANDYES.code("是"));
result.put("message","请检查LMS任务配置是否存在!");
return result;
}
// 返回结果
result.put("is_erro",RegionEnum.IS_NOTANDYES.code("否"));
result.put("task_type",task_code);
return result;
}
/**
* 根据点位区域判断出任务类型
* @param start_region 起点区域
* @param next_region 终点区域
* @return 任务类型编码
*/
private String ifTaskRegion(String start_region, String next_region) {
String task_code = "";
// 获取全部任务配置类
List<SchBaseTaskconfig> taskConfigList = iSchBaseTaskconfigService.list(
new QueryWrapper<SchBaseTaskconfig>().lambda()
.eq(SchBaseTaskconfig::getIs_used, RegionEnum.IS_NOTANDYES.code("是"))
.eq(SchBaseTaskconfig::getIs_delete, RegionEnum.IS_NOTANDYES.code("否"))
);
// 匹配任务类
SchBaseTaskconfig taskConfigDao = taskConfigList.stream()
.filter(row -> row.getStart_region_str().equals(start_region) &&
row.getNext_region_str().equals(next_region)
)
.findFirst().orElse(null);
if (ObjectUtil.isNotEmpty(taskConfigDao)) {
task_code = taskConfigDao.getConfig_code();
}
return task_code;
}
}

42
lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/region/enums/RegionEnum.java

@ -0,0 +1,42 @@
package org.nl.wms.sch.region.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.nl.common.exception.BadRequestException;
import org.nl.config.MapOf;
import java.util.Map;
/**
* 区域任务类型枚举类
*
* @author lxy
* @Date 2023/11/14 20:11
*/
@AllArgsConstructor
@Getter
public enum RegionEnum {
//是否
IS_NOTANDYES(MapOf.of("否", "0", "是", "1")),
;
private Map<String, String> code;
public String code(String desc) {
String code = this.getCode().get(desc);
if (StringUtils.isNotEmpty(code)) {
return code;
}
throw new BadRequestException(this.name() + "对应类型" + desc + "未定义");
}
public String check(String code) {
for (Map.Entry<String, String> entry : this.getCode().entrySet()) {
if (entry.getValue().equals("code")) {
return entry.getValue();
}
}
throw new BadRequestException(this.name() + "对应类型" + code + "未定义");
}
}

4
lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task/service/dao/SchBaseTask.java

@ -23,7 +23,6 @@ public class SchBaseTask implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "task_id", type = IdType.NONE)
private String task_id;
@ -105,6 +104,9 @@ public class SchBaseTask implements Serializable {
private String create_id;
private String priority;
private String create_name;

1
lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task/service/impl/SchBaseTaskServiceImpl.java

@ -238,6 +238,7 @@ public class SchBaseTaskServiceImpl extends ServiceImpl<SchBaseTaskMapper, SchBa
public SchBaseTask getByCode(String taskCode) {
LambdaQueryWrapper<SchBaseTask> lam = new QueryWrapper<SchBaseTask>().lambda();
lam.eq(SchBaseTask::getTask_code, taskCode);
lam.eq(SchBaseTask::getIs_delete, "0");
return this.getOne(lam);
}

97
lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/AbstractTask.java

@ -49,21 +49,15 @@ public abstract class AbstractTask {
/**
* 任务创建
* 根据配置生成任务如并发控制等
*
* @throws BadRequestException
* 根据配置生成任务
*/
public abstract void create() throws BadRequestException;
public abstract String create(JSONObject json);
/**
* 任务创建
* 只会创建完整的任务创建失败则抛出异常
*
* @param task
* 下发acs前参数整理
* @param taskId
*/
public void createCompletion(SchBaseTask task) {
}
public abstract AcsTaskDto sendAcsParam(String taskId);
/**
* @return WCS的任务集合
@ -158,7 +152,6 @@ public abstract class AbstractTask {
*/
public void schedule() {
this.autoCreate();
this.create();
// 下发
this.getAllFinishTask();
}
@ -194,23 +187,6 @@ public abstract class AbstractTask {
protected abstract void updateStatus(String task_code, TaskStatus status);
/**
* 设置起点或者终点
*
* @param taskConfig
* @param task
* @param apply_point_code
*/
protected void setTaskPoint(SchBaseTaskconfig taskConfig, SchBaseTask task, String apply_point_code) {
String taskDirection = taskConfig.getTask_direction();
if (TaskDirectionEnum.SEND.getValue().equals(taskDirection)) {
task.setPoint_code1(apply_point_code);
} else {
task.setPoint_code2(apply_point_code);
}
}
/**
* 首先组盘在下发任务
*
@ -241,69 +217,6 @@ public abstract class AbstractTask {
* @throws BadRequestException
*/
public void apply(JSONObject param) throws BadRequestException {
// 申请任务
SchBaseTask task = new SchBaseTask();
// 请求点
String apply_point_code = param.getString("device_code");
String config_code = param.getString("config_code");
String requestNo = param.getString("requestNo");
String vehicleType = param.getString("vehicle_type");
String vehicleCode = TaskUtils.defaultVehicleCode(param.getString("vehicle_code"));
AbstractTask bean = SpringContextHolder.getBean(this.getClass());
// 1、校验数据
SchBaseTaskconfig taskConfig = taskConfigService.getOne(new LambdaQueryWrapper<SchBaseTaskconfig>()
.eq(SchBaseTaskconfig::getConfig_code, config_code));
Assert.notNull(taskConfig, "找不到配置文件,请确认[" + config_code + "]配置是否存在!");
// 最大任务数
Integer tcmn = taskConfig.getTask_create_max_num();
// 获取执行中的任务
List<SchBaseTask> unFinishTasksByTaskConfig = taskService.findUnFinishTasksByTaskConfig(
taskConfig.getConfig_code(), apply_point_code, taskConfig.getTask_direction());
Assert.isFalse(unFinishTasksByTaskConfig.size() >= tcmn,
apply_point_code + "该点位申请的任务未完成数已超过上限,无法申请任务");
// 获取对接位点位对象
SchBasePoint pointObj = pointService.getOne(new LambdaQueryWrapper<SchBasePoint>()
.eq(SchBasePoint::getPoint_code, apply_point_code));
// 判断是否校验工单
if (taskConfig.getIs_check_workorder()) {
// 校验工单
// 根据对接位的父点位编码(设备)找到工单设备
SchBasePoint parentPoint = pointService.getOne(new LambdaQueryWrapper<SchBasePoint>()
.eq(SchBasePoint::getPoint_code, pointObj.getParent_point_code()));
}
// 校验是否需要自动agv
if (!pointObj.getIs_auto()) {
// 如果不需要自动,则不创建任务
return;
}
// 2、创建申请任务
task.setAcs_trace_id(requestNo);
task.setTask_id(IdUtil.getSnowflake(1, 1).nextIdStr());
task.setTask_code(IdUtil.getSnowflake(1, 1).nextIdStr());
task.setConfig_code(config_code);
task.setCreate_mode(GeneralDefinition.ACS_CREATION);
task.setVehicle_code(vehicleCode);
task.setVehicle_qty(param.getInteger("vehicle_qty"));
task.setVehicle_type(vehicleType);
task.setTask_status(TaskStatus.APPLY.getCode());
task.setWorkshop_code(taskConfig.getWorkshop_code());
// 设置起/终点
bean.setTaskPoint(taskConfig, task, apply_point_code);
task.setRequest_param(JSONObject.toJSONString(param));
// 设置创建人信息
TaskUtils.setCreateByAcsOrPda(task, param);
// 3、判断是否直接找点下发
// 立即创建吧组盘放到具体位置,免得重复创建
if (taskConfig.getIs_immediate_create()) {
bean.createCompletion(task);
} else { // 不需要立即创建,需要立马组盘
// 设置组盘 - 需要的话由子类自行实现
task.setGroup_id(bean.setGroupPlate(param));
// 创建一条单点任务。
taskService.save(task);
bean.create();
}
}
}

41
lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/enums/GroupStatusEnum.java

@ -1,41 +0,0 @@
package org.nl.wms.sch.task_manage.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @Author: lyd
* @Description: 组盘状态枚举
* @Date: 2023/5/24
*/
@Getter
@AllArgsConstructor
public enum GroupStatusEnum {
/**
* 系统外
*/
OUT_SYSTEM("1", "系统外"),
/**
* 存储中
*/
IN_STORAGE("2", "存储中"),
/**
* 处理中
*/
IN_PROCESS("3", "处理中"),
/**
* 搬运中
*/
IN_CARRY("4", "搬运中"),
/**
* 可放料
*/
DISCHARGE_MATERIAL("5", "可放料"),
/**
* 可取料
*/
CABLE_RETRIEVABLE_MATERIAL("6", "可取料");
private final String type;
private final String name;
}

36
lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/enums/WorkOrderStatusEnum.java

@ -1,36 +0,0 @@
package org.nl.wms.sch.task_manage.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @Author: lyd
* @Description: 工单状态枚举
* @Date: 2023/6/16
*/
@Getter
@AllArgsConstructor
public enum WorkOrderStatusEnum {
/**
* 未生产
*/
UNPRODUCED("1", "未生产"),
/**
* 已下发
*/
ISSUED("2", "已下发"),
/**
* 生产中
*/
PRODUCING("3", "生产中"),
/**
* 暂停
*/
STOP("4", "暂停"),
/**
* 完成
*/
COMPLETE("5", "完成");
private final String code;
private final String name;
}

1
lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/TaskListType.java

@ -1 +0,0 @@
package org.nl.wms.sch.task_manage.task;

34
lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/TaskServiceImpl.java

@ -1,34 +0,0 @@
package org.nl.wms.sch.task_manage.task;
import cn.hutool.core.lang.Assert;
import com.alibaba.fastjson.JSONObject;
import org.nl.common.exception.BadRequestException;
/**
* @author ldjun
* @version 1.0
* @date 2023年05月08日 13:59
* @desc desc
*/
public class TaskServiceImpl {
String create(JSONObject param) throws BadRequestException {
return null;
}
public void beforeToCreate(JSONObject param) throws BadRequestException {
String point_code = param.getString("point_code");
Assert.notEmpty(point_code, "点位编码为空!");
//1、查找点位
//2、校验点位是否启用
//3、校验点位是否自动
//4、任务类型
}
public void createAfter(JSONObject param) throws BadRequestException {
}
}

1
lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/core/TaskApplyDto.java

@ -1 +0,0 @@
package org.nl.wms.sch.task_manage.task.core;

11
lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/core/TaskDto.java

@ -1,11 +0,0 @@
package org.nl.wms.sch.task_manage.task.core;
/**
* @author ldjun
* @version 1.0
* @date 2023年05月08日 13:41
* @desc desc
*/
public class TaskDto {
private String task_code;
}

4
lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/core/TaskStatus.java

@ -6,6 +6,10 @@ package org.nl.wms.sch.task_manage.task.core;
* @Date: 2023/8/14
*/
public enum TaskStatus {
/**
* 申请
*/
CREATE("0", "生成", "生成"),
/**
* 申请
*/

233
lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/fj/FJSLTask.java

@ -1,233 +0,0 @@
package org.nl.wms.sch.task_manage.task.tasks.fj;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.nl.common.exception.BadRequestException;
import org.nl.system.service.notice.ISysNoticeService;
import org.nl.wms.sch.point.service.ISchBasePointService;
import org.nl.wms.sch.point.service.dao.SchBasePoint;
import org.nl.wms.sch.task.service.ISchBaseTaskService;
import org.nl.wms.sch.task.service.ISchBaseTaskconfigService;
import org.nl.wms.sch.task.service.dao.SchBaseTask;
import org.nl.wms.sch.task.service.dao.SchBaseTaskconfig;
import org.nl.wms.sch.task_manage.AbstractTask;
import org.nl.wms.sch.task_manage.GeneralDefinition;
import org.nl.wms.sch.task_manage.enums.GroupBindMaterialStatusEnum;
import org.nl.wms.sch.task_manage.enums.NoticeTypeEnum;
import org.nl.wms.sch.task_manage.enums.PointStatusEnum;
import org.nl.wms.sch.task_manage.enums.TaskFinishedTypeEnum;
import org.nl.wms.sch.task_manage.task.TaskType;
import org.nl.wms.sch.task_manage.task.core.TaskStatus;
import org.nl.wms.util.PointUtils;
import org.nl.wms.util.TaskUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Author: lyd
* @Description: 分拣回收剩料
* @Date: 2023/7/20
*/
@Component(value = "FJSLHSTask")
@TaskType("FJSLHSTask")
public class FJSLTask extends AbstractTask {
private static final String TASK_CONFIG_CODE = "FJSLHSTask";
@Autowired
private ISchBasePointService pointService;
@Autowired
private ISchBaseTaskService taskService;
@Autowired
private ISchBaseTaskconfigService taskConfigService;
@Autowired
private ISysNoticeService noticeService;
@Override
public void create() throws BadRequestException {
// 获取任务
List<SchBaseTask> tasks = taskService.findTasksByTaskStatus(TASK_CONFIG_CODE, TaskStatus.APPLY);
// 配置信息
SchBaseTaskconfig taskConfig = taskConfigService.getOne(new LambdaQueryWrapper<SchBaseTaskconfig>()
.eq(SchBaseTaskconfig::getConfig_code, TASK_CONFIG_CODE));
for (SchBaseTask task : tasks) {
TaskUtils.setUpdateByAcs(task);
List<String> nextRegionStr = Arrays.stream(taskConfig.getNext_region_str().split(","))
.collect(Collectors.toList());
// 找终点
String requestParam = task.getRequest_param();
JSONObject jsonObject = JSONObject.parseObject(requestParam);
SchBasePoint point = findNextPoint(nextRegionStr, jsonObject);
if (ObjectUtil.isEmpty(point)) {
task.setRemark("分拣机械手[" + task.getPoint_code1() + "]未找到所需点位!");
taskService.updateById(task);
// 消息通知
noticeService.createNotice(task.getRemark(), TASK_CONFIG_CODE + task.getTask_code(),
NoticeTypeEnum.WARN.getCode());
continue;
}
// 设置终点并修改创建成功状态
task.setPoint_code2(point.getPoint_code());
task.setTask_status(TaskStatus.CREATED.getCode());
task.setRemark("");
TaskUtils.setUpdateByAcs(task);
taskService.updateById(task);
point.setIng_task_code(task.getTask_code());
PointUtils.setUpdateByAcs(point);
pointService.updateById(point);
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void createCompletion(SchBaseTask task) {
// 配置信息
SchBaseTaskconfig taskConfig = taskConfigService.getOne(new LambdaQueryWrapper<SchBaseTaskconfig>()
.eq(SchBaseTaskconfig::getConfig_code, TASK_CONFIG_CODE));
TaskUtils.setUpdateByAcs(task);
List<String> nextRegionStr = Arrays.stream(taskConfig.getNext_region_str().split(","))
.collect(Collectors.toList());
// 找终点
String requestParam = task.getRequest_param();
JSONObject jsonObject = JSONObject.parseObject(requestParam);
SchBasePoint point = findNextPoint(nextRegionStr, jsonObject);
if (ObjectUtil.isEmpty(point)) {
// 消息通知
noticeService.createNotice("分拣机械手[" + task.getPoint_code1() + "]未找到所需点位!", TASK_CONFIG_CODE + task.getPoint_code1(),
NoticeTypeEnum.WARN.getCode());
throw new BadRequestException("分拣机械手[" + task.getPoint_code1() + "]未找到所需点位!");
}
// 设置组盘 - 需要的话由子类自行实现
task.setGroup_id(setGroupPlate(jsonObject));
// 设置终点并修改创建成功状态
task.setPoint_code2(point.getPoint_code());
task.setTask_status(TaskStatus.CREATED.getCode());
task.setRemark("");
task.setVehicle_type(GeneralDefinition.STEEL_TRAY);
TaskUtils.setUpdateByAcs(task);
taskService.save(task);
point.setIng_task_code(task.getTask_code());
PointUtils.setUpdateByAcs(point);
pointService.updateById(point);
}
private SchBasePoint findNextPoint(List<String> nextRegionStr, JSONObject jsonObject) {
LambdaQueryWrapper<SchBasePoint> lam = new QueryWrapper<SchBasePoint>().lambda();
lam.in(SchBasePoint::getRegion_code, nextRegionStr)
.eq(SchBasePoint::getPoint_status, PointStatusEnum.EMPTY_POINT.getCode())
// 当前执行的任务为空或者NULL,有数据表示锁住
.and(la -> la.isNull(SchBasePoint::getIng_task_code)
.or()
.eq(SchBasePoint::getIng_task_code, ""))
.eq(SchBasePoint::getIs_used, true)
.ne(SchBasePoint::getLayer_num, "3")
.orderByAsc(SchBasePoint::getIn_order_seq)
.orderByAsc(SchBasePoint::getPoint_code);
List<SchBasePoint> schBasePoints = pointService.list(lam);
return ObjectUtil.isNotEmpty(schBasePoints) ? schBasePoints.get(0) : null;
}
@Override
public String setGroupPlate(JSONObject param) {
return null;
}
@Override
protected void updateStatus(String task_code, TaskStatus status) {
// 校验任务
SchBaseTask taskObj = taskService.getByCode(task_code);
if (taskObj.getTask_status().equals(TaskStatus.FINISHED.getCode())) {
throw new BadRequestException("该任务已完成!");
}
if (taskObj.getTask_status().equals(TaskStatus.CANCELED.getCode())) {
throw new BadRequestException("该任务已取消!");
}
// 根据传来的类型去对任务进行操作
if (status.equals(TaskStatus.EXECUTING)) {
taskObj.setTask_status(TaskStatus.EXECUTING.getCode());
taskObj.setRemark("执行中");
TaskUtils.setUpdateByAcs(taskObj);
taskService.updateById(taskObj);
}
if (status.equals(TaskStatus.FINISHED)) {
this.finishTask(taskObj, TaskFinishedTypeEnum.AUTO_ACS);
}
if (status.equals(TaskStatus.CANCELED)) {
this.cancelTask(taskObj, TaskFinishedTypeEnum.AUTO_ACS);
}
}
@Override
public void forceFinish(String task_code) {
SchBaseTask taskObj = taskService.getByCode(task_code);
if (ObjectUtil.isEmpty(taskObj)) {
throw new BadRequestException("该任务不存在");
}
this.finishTask(taskObj, TaskFinishedTypeEnum.MANUAL_PC);
}
@Override
public void cancel(String task_code) {
SchBaseTask taskObj = taskService.getByCode(task_code);
if (ObjectUtil.isEmpty(taskObj)) {
throw new BadRequestException("该任务不存在");
}
this.cancelTask(taskObj, TaskFinishedTypeEnum.MANUAL_PC);
}
@Transactional(rollbackFor = Exception.class)
public void finishTask(SchBaseTask taskObj, TaskFinishedTypeEnum taskFinishedType) {
String vehicleCode = taskObj.getVehicle_code();
String vehicleType = taskObj.getVehicle_type();
String startPoint = taskObj.getPoint_code1();
String endPoint = taskObj.getPoint_code2();
SchBasePoint startPointObj = pointService.getById(startPoint);
SchBasePoint endPointObj = pointService.getById(endPoint);
if (ObjectUtil.isNotEmpty(endPointObj)) {
// 记录库存并解锁
endPointObj.setIng_task_code("");
endPointObj.setVehicle_code(vehicleCode);
endPointObj.setVehicle_qty(1);
endPointObj.setVehicle_type(vehicleType);
endPointObj.setPoint_status(PointStatusEnum.FULL_POINT.getCode());
PointUtils.setUpdateByType(endPointObj, taskFinishedType);
pointService.updateById(endPointObj);
}
// 起点清空
PointUtils.setUpdateByType(startPointObj, taskFinishedType);
PointUtils.clearPoint(startPointObj);
// 任务完成
taskObj.setTask_status(TaskStatus.FINISHED.getCode());
taskObj.setRemark(GeneralDefinition.TASK_FINISH);
taskObj.setFinished_type(taskFinishedType.getCode());
TaskUtils.setUpdateByType(taskObj, taskFinishedType);
taskService.updateById(taskObj);
}
@Transactional(rollbackFor = Exception.class)
public void cancelTask(SchBaseTask taskObj, TaskFinishedTypeEnum taskFinishedType) {
// 获取参数
String endPoint = taskObj.getPoint_code2();
SchBasePoint endPointObj = pointService.getById(endPoint);
// 终点解锁
if (ObjectUtil.isNotEmpty(endPointObj)) {
endPointObj.setIng_task_code("");
PointUtils.setUpdateByType(endPointObj, taskFinishedType);
pointService.updateById(endPointObj);
}
taskObj.setRemark(GeneralDefinition.TASK_CANCEL);
taskObj.setTask_status(TaskStatus.CANCELED.getCode());
taskObj.setFinished_type(taskFinishedType.getCode());
TaskUtils.setUpdateByType(taskObj, taskFinishedType);
taskService.updateById(taskObj);
}
}

132
lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/fj/MABCTask.java

@ -0,0 +1,132 @@
package org.nl.wms.sch.task_manage.task.tasks.fj;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import org.nl.common.exception.BadRequestException;
import org.nl.common.utils.SecurityUtils;
import org.nl.config.IdUtil;
import org.nl.wms.sch.task.service.ISchBaseTaskService;
import org.nl.wms.sch.task.service.ISchBaseTaskconfigService;
import org.nl.wms.sch.task.service.dao.SchBaseTask;
import org.nl.wms.sch.task_manage.AbstractTask;
import org.nl.wms.sch.task_manage.AcsTaskDto;
import org.nl.wms.sch.task_manage.GeneralDefinition;
import org.nl.wms.sch.task_manage.enums.TaskFinishedTypeEnum;
import org.nl.wms.sch.task_manage.task.TaskType;
import org.nl.wms.sch.task_manage.task.core.TaskStatus;
import org.nl.wms.util.TaskUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
/**
* @Author: lxy
* @Description: AB区送满托盘到C区
* @Date: 2024/9/24
*/
@Component(value = "MABCTask")
@TaskType("MABCTask")
public class MABCTask extends AbstractTask {
@Autowired
private ISchBaseTaskService taskService;
@Autowired
private ISchBaseTaskconfigService taskConfigService;
@Override
public String create(JSONObject json) {
SchBaseTask task = new SchBaseTask();
task.setTask_id(IdUtil.getStringId());
task.setTask_code(json.getString("TaskCode"));
task.setTask_status(TaskStatus.CREATE.getCode());
task.setConfig_code(json.getString("task_type"));
task.setPoint_code1(json.getString("PickingLocation"));
task.setPoint_code2(json.getString("PlacedLocation"));
task.setRequest_param(json.toString());
task.setPriority(json.getString("Priority"));
task.setCreate_id(SecurityUtils.getCurrentUserId());
task.setCreate_name(SecurityUtils.getCurrentNickName());
task.setCreate_time(DateUtil.now());
taskService.save(task);
return task.getTask_id();
}
@Override
public AcsTaskDto sendAcsParam(String taskId) {
SchBaseTask taskDao = taskService.getById(taskId);
// 组织下发给acs的数据
AcsTaskDto acsTaskDto = new AcsTaskDto();
acsTaskDto.setExt_task_uuid(taskDao.getTask_id());
acsTaskDto.setTask_code(taskDao.getTask_code());
acsTaskDto.setStart_device_code(taskDao.getPoint_code1());
acsTaskDto.setNext_device_code(taskDao.getPoint_code2());
acsTaskDto.setPriority(taskDao.getPriority());
acsTaskDto.setTask_type(taskDao.getConfig_code());
return acsTaskDto;
}
@Override
protected void updateStatus(String task_code, TaskStatus status) {
// 校验任务
SchBaseTask taskObj = taskService.getByCode(task_code);
if (taskObj.getTask_status().equals(TaskStatus.FINISHED.getCode())) {
throw new BadRequestException("该任务已完成!");
}
if (taskObj.getTask_status().equals(TaskStatus.CANCELED.getCode())) {
throw new BadRequestException("该任务已取消!");
}
// 根据传来的类型去对任务进行操作
if (status.equals(TaskStatus.EXECUTING)) {
taskObj.setTask_status(TaskStatus.EXECUTING.getCode());
taskObj.setRemark("执行中");
TaskUtils.setUpdateByAcs(taskObj);
taskService.updateById(taskObj);
}
if (status.equals(TaskStatus.FINISHED)) {
this.finishTask(taskObj, TaskFinishedTypeEnum.AUTO_ACS);
}
if (status.equals(TaskStatus.CANCELED)) {
this.cancelTask(taskObj, TaskFinishedTypeEnum.AUTO_ACS);
}
}
@Override
public void forceFinish(String task_code) {
SchBaseTask taskObj = taskService.getByCode(task_code);
if (ObjectUtil.isEmpty(taskObj)) {
throw new BadRequestException("该任务不存在");
}
this.finishTask(taskObj, TaskFinishedTypeEnum.MANUAL_PC);
}
@Override
public void cancel(String task_code) {
SchBaseTask taskObj = taskService.getByCode(task_code);
if (ObjectUtil.isEmpty(taskObj)) {
throw new BadRequestException("该任务不存在");
}
this.cancelTask(taskObj, TaskFinishedTypeEnum.MANUAL_PC);
}
@Transactional(rollbackFor = Exception.class)
public void finishTask(SchBaseTask taskObj, TaskFinishedTypeEnum taskFinishedType) {
// 任务完成
taskObj.setTask_status(TaskStatus.FINISHED.getCode());
taskObj.setRemark(GeneralDefinition.TASK_FINISH);
taskObj.setFinished_type(taskFinishedType.getCode());
TaskUtils.setUpdateByType(taskObj, taskFinishedType);
taskService.updateById(taskObj);
}
@Transactional(rollbackFor = Exception.class)
public void cancelTask(SchBaseTask taskObj, TaskFinishedTypeEnum taskFinishedType) {
taskObj.setRemark(GeneralDefinition.TASK_CANCEL);
taskObj.setTask_status(TaskStatus.CANCELED.getCode());
taskObj.setFinished_type(taskFinishedType.getCode());
TaskUtils.setUpdateByType(taskObj, taskFinishedType);
taskService.updateById(taskObj);
}
}
Loading…
Cancel
Save