This commit is contained in:
2023-04-03 14:18:04 +08:00
11 changed files with 109 additions and 65 deletions

View File

@@ -6,5 +6,5 @@ package org.nl.common;
*/
public class ConstantParam {
//深坑清洗区域编码
public static String SK_REGION = "SK_REGION";
public static String SK_REGION = "QSQX";
}

View File

@@ -25,6 +25,8 @@ public enum AcsTaskEnum {
TASK_PRODUCT_CACHE("2","专机-缓存线满料任务"),
//3个点任务编号缓存线满料载具列表
TASK_CACHELINE_OUT("3","缓存线-专机出库任务"),
//专机到深坑任务:深坑业务单独处理
TASK_PRODUCT_WASH("4","专机-深坑任务"),
//回调状态
STATUS_START("1","执行中"),

View File

@@ -28,8 +28,8 @@ public enum StatusEnum {
CACHE_VEL_DIS("5","不显示",""),
//任务状态
TASK_CREATE("1","生成",""),
TASK_START_P("2","起点确认",""),
TASK_END_P("3","确定终点",""),
TASK_START_ERROR("2","点位确认异常",""),
//TASK_END_P("3","确定终点",""),
TASK_START_END_P("4","起点和终点确认",""),
TASK_PUBLISH("5","下发",""),
TASK_RUNNING("6","运行",""),

View File

@@ -19,6 +19,7 @@ import org.nl.wms.ext.acs.service.AcsToWmsService;
import org.nl.wms.pda.service.CacheLineHandService;
import org.nl.wms.sch.service.TaskService;
import org.nl.wms.sch.service.dto.TaskDto;
import org.nl.wms.sch.tasks.SpeMachineryTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
@@ -41,20 +42,22 @@ public class AcsToWmsServiceImpl implements AcsToWmsService{
private TaskService taskService;
@Autowired
private CacheLineHandService cacheLineHandService;
private final AgvInstService agvInstService;
private final SpeMachineryTask speMachineryTask;
@Override
public Map<String, Object> apply(JSONObject jsonObject) {
public Map<String, Object> apply(JSONObject param) {
Map result = MapOf.of("status", HttpStatus.OK.value(), "message", "ACS向WMS申请任务成功!");
//1.专机设备满料请求
//2.专机设备缺料请求:专机,深坑
String type = jsonObject.getString("type");
String type = param.getString("type");
AcsTaskEnum taskEnum = AcsTaskEnum.getType(type, "REQUEST_");
try {
if (type.equals(AcsTaskEnum.REQUEST_CALLTYPE_FULL.getCode())){
agvInstService.fullMaster(jsonObject);
}
if (type.equals(AcsTaskEnum.REQUEST_CALLTYPE_EMP.getCode())){
agvInstService.callMatter(jsonObject);
switch (taskEnum){
//1.专机设备满料请求 2.专机设备缺料请求:专机
case REQUEST_CALLTYPE_FULL: case REQUEST_CALLTYPE_EMP:
speMachineryTask.createTask(param);
break;
default:
}
}catch (Exception ex){
result.put("status", HttpStatus.BAD_REQUEST.value());
result.put("message",ex.getMessage());

View File

@@ -62,9 +62,9 @@ public class AgvInstService {
//3.判断下一道路由设备是否含有没满的设备料斗
//4.有则创建agv指令
// 没有则创建缓存架任务
public void fullMaster(JSONObject param){
public JSONObject fullMaster(JSONObject param){
JSONObject taskForm = null;
log.info(OPT_NAME+"fullMaster param:{}",JSONObject.toJSONString(param));
WQLObject workOrder = WQLObject.getWQLObject("PDM_produce_workOrder");
WQLObject basePoint = WQLObject.getWQLObject("sch_base_point");
WQLObject cacheLineSearch = WQLObject.getWQLObject("SCH_cacheLine_region_relation");
@@ -74,65 +74,53 @@ public class AgvInstService {
String quantity = param.getString("quantity");
//1.PDM_produce_workOrder
JSONObject order = workOrder.query("workorder_code = '" + workorder + "' and is_delete = 0 and workorder_status != "+StatusEnum.TASK_FINISH.getCode()).uniqueResult(0);
if (order==null){
throw new BadRequestException("下发工单不存在未完成工单:"+workorder);
}
String needMove = order.getString("is_needmove");
String materialprocessSeries = order.getString("materialprocess_series");
Assert.notNull(order, String.format("下发工单%s不存在未完成工单", workorder));
String needMove = order.getString("is_needmove");
String taskType = AcsTaskEnum.TASK_PRODUCT_MAC.getCode();
if (StatusEnum.STATUS_TRUE.getCode().equals(needMove)){
JSONObject devicePoint = basePoint.query("point_code = '" + point_code + "' and is_delete = 0 and is_used = 1").uniqueResult(0);
JSONObject empPoint = WQL.getWO("sch_point").addParamMap(MapOf.of("flag", "2", "point_code", point_code, "point_type", StatusEnum.POINT_LOCATION_EMP.getCode())).process().uniqueResult(0);
String nextPoint = null;
//2.进行终点判断
JSONArray nextPointList = WQL.getWO("sch_point").addParamMap(MapOf.of("flag","3","region_code", devicePoint.getString("next_region_code"),"qty",quantity)).process().getResultJSONArray(0);
if (nextPointList.size()>0){
//判断缓存线是不是去深坑清洗
if (devicePoint.getString("next_region_code").equals(ConstantParam.SK_REGION)){
String deviceSql = nextPointList.stream().map(a -> ((JSONObject) a).getString("device_code")).collect(Collectors.joining("','"));
JSONArray runDevs = WQL.getWO("sch_point").addParamMap(MapOf.of("flag","4", "device_code","'"+deviceSql+"'")).process().getResultJSONArray(0);
if (runDevs.size()>0){
String device_code = runDevs.getJSONObject(0).getString("device_code");
JSONObject SKPoint = (JSONObject)nextPointList.stream().filter(o -> ((JSONObject) o).getString("device_code").equals(device_code)).findFirst().get();
nextPoint = SKPoint.getString("point_code");
}
}else {
nextPoint = nextPointList.getJSONObject(0).getString("point_code");
}
}
//判断缓存线是不是去深坑清洗深坑区域15个点判断空的物料坑位
String cacheVehile = "";
//根据区域物料对应关系查询缓存线
if (StringUtils.isEmpty(nextPoint)){
JSONObject cacheLine = cacheLineSearch.query("region_code = '"+devicePoint.getString("region_code")+"'").uniqueResult(0);
nextPoint = cacheLine.getString("cacheline_code");
//满料请求:查询缓存线空载具列表
cacheVehile = getCacheVehile(nextPoint, null);
if (StringUtils.isEmpty(cacheVehile)) {
throw new BadRequestException("缓存线:"+nextPoint+"没有可用空载具");
if (devicePoint.getString("next_region_code").equals(ConstantParam.SK_REGION)){
nextPoint = "";
}else {
JSONArray nextPointList = WQL.getWO("sch_point").addParamMap(MapOf.of("flag","3","region_code", devicePoint.getString("next_region_code"),"qty",quantity)).process().getResultJSONArray(0);
if (nextPointList.size()>0){
nextPoint = nextPointList.getJSONObject(0).getString("point_code");
if (StringUtils.isEmpty(nextPoint)){
JSONObject cacheLine = cacheLineSearch.query("region_code = '"+devicePoint.getString("region_code")+"'").uniqueResult(0);
nextPoint = cacheLine.getString("cacheline_code");
//满料请求:查询缓存线空载具列表
cacheVehile = getCacheVehile(nextPoint, null);
if (StringUtils.isEmpty(cacheVehile)) {
throw new BadRequestException("缓存线:"+nextPoint+"没有可用空载具");
}
taskType = AcsTaskEnum.TASK_CACHELINE_OUT.getCode();
}
}
taskType = AcsTaskEnum.TASK_CACHELINE_OUT.getCode();
}
//生成任务nextPoint
SpeMachineryTask pointTask = new SpeMachineryTask();
JSONObject taskForm = new JSONObject(MapOf.of("start_point_code",point_code,
taskForm = new JSONObject(MapOf.of("start_point_code",point_code,
"next_point_code",nextPoint,"return_point_code", empPoint.getString("point_code"),"vehicle_code",
cacheVehile,"quantity", quantity,"product_area",devicePoint.getString("product_area"),"type",taskType));
String taskId = pointTask.createTask(taskForm);
log.info(OPT_NAME+"fullMaster taskID:{}",taskId);
return taskForm;
}
}catch (Exception ex){
log.error(OPT_NAME+"fullMaster error:{}",ex);
throw ex;
}
return taskForm;
};
//缺料请求:上料位
//1.判断当前设备表对应的缓存线是否开放
//2.根据当前设备绑定的物料id从缓存线中获取相同物料对应载具列表
//3.agv根据对应载具列表行进扫码匹配匹配到对应物料则创建点对点任务
public void callMatter(JSONObject param){
public JSONObject callMatter(JSONObject param){
JSONObject taskForm = null;
log.info(OPT_NAME+"callMatter param:{}",JSONObject.toJSONString(param));
WQLObject basePointTable = WQLObject.getWQLObject("SCH_BASE_Point");
WQLObject workOrderTable = WQLObject.getWQLObject("PDM_produce_workOrder");
@@ -145,9 +133,6 @@ public class AgvInstService {
JSONObject devicePoint = basePointTable.query("point_code = '" + point_code + "' and is_delete = 0 and is_used = 1").uniqueResult(0);
JSONObject order = workOrderTable.query("workorder_code = '" + workorder + "' and is_delete = 0 and workorder_status != "+StatusEnum.TASK_FINISH.getCode()).uniqueResult(0);
Assert.notNull(devicePoint, String.format("点位%s对应点位信息不存在", point_code));
if (order == null){
return;
}
String material_id = order.getString("material_id");
try {
JSONObject cacheLine = cacheLineTable.query("region_code = '"+devicePoint.getString("region_code")+"' and is_active = '"+StatusEnum.STATUS_TRUE.getCode()+"'").uniqueResult(0);
@@ -166,16 +151,14 @@ public class AgvInstService {
throw new BadRequestException(String.format("缓存线%s上含物料%s的载具已分配完",startPoint,material_id));
}
SpeMachineryTask pointTask = new SpeMachineryTask();
JSONObject taskForm = new JSONObject(MapOf.of("start_point_code",startPoint,
taskForm = new JSONObject(MapOf.of("start_point_code",startPoint,
"next_point_code",point_code,"return_point_code", startPoint,"vehicle_code",
cacheVehile,"product_area",devicePoint.getString("product_area"),"type",AcsTaskEnum.TASK_CACHELINE_OUT.getCode(),"material_id", material_id));
String taskId = pointTask.createTask(taskForm);
log.info(OPT_NAME+"callMatter taskID:{}",taskId);
}catch (Exception ex){
log.error(OPT_NAME+"callMatter error:{}",ex);
throw ex;
}
return taskForm;
}
public String getCacheVehile(String cacheLine,String materialId){

View File

@@ -29,4 +29,7 @@ public abstract class AbstractAcsTask {
public abstract void cancel(String task_id);
public abstract void pointConfirm(JSONObject param);
}

View File

@@ -391,4 +391,9 @@ public class CallMaterialTask extends AbstractAcsTask {
public void cancel(String task_id) {
}
@Override
public void pointConfirm(JSONObject param) {
}
}

View File

@@ -193,4 +193,10 @@ public class ProductInTask extends AbstractAcsTask {
JSONObject taskObj = WQLObject.getWQLObject("SCH_BASE_Task").query("task_id = '" + task_id + "'").uniqueResult(0);
this.updateTaskStatus(taskObj, "0");
}
@Override
public void pointConfirm(JSONObject param) {
}
}

View File

@@ -135,7 +135,7 @@ public class SendMaterialTask extends AbstractAcsTask {
}
}
@Override
@Transactional
@@ -316,7 +316,7 @@ public class SendMaterialTask extends AbstractAcsTask {
return task_id;
}
@Override
public void cancel(String task_id) {
@@ -324,4 +324,8 @@ public class SendMaterialTask extends AbstractAcsTask {
}
@Override
public void pointConfirm(JSONObject param) {
}
}

View File

@@ -13,8 +13,10 @@ import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.system.util.CodeUtil;
import org.nl.common.utils.SecurityUtils;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.wms.ext.acs.service.impl.AgvInstService;
import org.nl.wms.sch.manage.AbstractAcsTask;
import org.nl.wms.sch.manage.TaskStatusEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -27,6 +29,9 @@ import java.util.Map;
@Slf4j
@Service
public class SpeMachineryTask extends AbstractAcsTask {
@Autowired
AgvInstService agvInstService;
private final Map<String,SpeStatusHandler > SpeHandles= new HashMap<>();
private static String OPT_NAME = "ACS回调# ";
@@ -53,14 +58,21 @@ public class SpeMachineryTask extends AbstractAcsTask {
}
@Override
public String createTask(JSONObject form) {
String task_name = form.getString("task_name");
public String createTask(JSONObject param) {
String type = param.getString("type");
JSONObject form = null;
if (AcsTaskEnum.REQUEST_CALLTYPE_FULL.getCode().equals(type)){
form = agvInstService.fullMaster(param);
}
if (AcsTaskEnum.REQUEST_CALLTYPE_EMP.getCode().equals(type)){
form = agvInstService.callMatter(param);
}
String task_name = form.getString("task_name");
String start_point_code = form.getString("point_code1");
String next_point_code = form.getString("point_code2");
String vehicle_code = form.getString("vehicle_code");
String vehicle_code2 = form.getString("vehicle_code2");
String material_id = form.getString("material_id");
String type = form.getString("type");
if(StrUtil.isEmpty(start_point_code)) {
throw new BadRequestException("起点不能为空!");
}
@@ -208,4 +220,9 @@ public class SpeMachineryTask extends AbstractAcsTask {
}
}
}
@Override
public void pointConfirm(JSONObject param) {
}
}

View File

@@ -19,6 +19,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.lang.reflect.Method;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
@@ -46,9 +47,29 @@ public class TaskScheduleService {
if (islock){
WQLObject taskTable = WQLObject.getWQLObject("sch_base_task");
//查询所有自动下发的任务
JSONArray all = taskTable.query("is_auto_issue = '1' and task_type < '" + StatusEnum.TASK_PUBLISH + "'").getResultJSONArray(0);
//分区域不同区域调用不同acs接口
JSONArray all = taskTable.query("is_auto_issue = '1' and task_type < '" + StatusEnum.TASK_PUBLISH.getCode() + "'").getResultJSONArray(0);
//进行起点终点确认:
if (all.size() == 0){
return;
}
log.info("TaskScheduleService#taskPublish all_task:{}",all.size());
Iterator<Object> iterator = all.stream().iterator();
while (iterator.hasNext()){
JSONObject task = (JSONObject)iterator.next();
try {
Class<?> clz = Class.forName(task.getString("handle_class"));
Object obj = clz.newInstance();
// 调用每个任务类的forceFinishInst()强制结束方法
Method m = obj.getClass().getDeclaredMethod("pointConfirm", JSONObject.class, String.class);
m.invoke(obj,task);
task.put("task_type", StatusEnum.TASK_START_END_P.getCode());
}catch (Exception ex){
task.put("task_type", StatusEnum.TASK_START_ERROR.getCode());
task.put("remark",ex.getMessage());
iterator.remove();
}
}
//分区域不同区域调用不同acs接口
Map<String, List<Object>> areaCollent = all.stream().collect(Collectors.groupingBy(o -> ((JSONObject) o).getString("product_area")));
for (String area : areaCollent.keySet()) {
List<Object> array = areaCollent.get(area);