add:添加深坑清洗功能

This commit is contained in:
zhangzhiqiang
2023-04-10 10:24:17 +08:00
parent 3dcbb17f75
commit 9c9f25465e
23 changed files with 708 additions and 242 deletions

View File

@@ -19,7 +19,12 @@
<sa-token.version>1.31.0</sa-token.version>
</properties>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>3.0.13</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.json</groupId>

View File

@@ -44,6 +44,9 @@ public enum AcsTaskEnum {
REQUEST_PLOTTER_CALL_EMP("4","刻字缺空框请求"),
REQUEST_WARP_CALL_FULL("5","包装缺料请求"),
REQUEST_WARP_SEND_EMP("6","包装送空框请求"),
REQUEST_WASH_EMP("7","清洗机器缺料请求"),
REQUEST_WASH_FULL("8","清洗机器满料请求"),
//
AGV_SYSTEM_NB("1","诺宝机器人任务"),

View File

@@ -20,7 +20,12 @@ public enum StatusEnum {
//锁状态
LOCK_OFF("0","",""),
LOCK_ON("1","",""),
//缓存线点位异常情况
CACHE_POINT_NORMAL("0","正常",""),
CACHE_POINT_ERROR("1","异常盘点",""),
CACHE_POINT_SCAN_ERROR("2","异常扫码",""),
//缓存线载具状态 1-空位、2-绿色空箱、3-黄色满箱、4-红色异常、5不显示
CACHE_VEL_NORMAL("0","正常",""),
CACHE_VEL_NULL("1","空位",""),
CACHE_VEL_EMT("2","绿色空箱",""),
CACHE_VEL_FULL("3","黄色满箱",""),
@@ -65,6 +70,7 @@ public enum StatusEnum {
IOS_RUNNING("02","执行中",""),
IOS_FINISH("99","完成",""),
;
private String code;
private String desc;
private String ext;

View File

@@ -1,4 +1,4 @@
package org.nl.wms.sch.tasks;
package org.nl.common.enums;
/**
* 任务状态枚举

View File

@@ -48,38 +48,42 @@ public class AcsUtil {
log.info("ACS相应参数----------------------------------------+"+api+",---"+result.toString());
} catch (Exception e) {
log.info("ACS反馈异常----------------------------------------+"+api+",---"+e.getMessage());
String msg = e.getMessage();
//ConnectException: Connection refused: connect
//网络不通
System.out.println(msg);
result.put("status", HttpStatus.BAD_REQUEST);
result.put("message", "网络不通,操作失败!");
result.put("data", new JSONObject());
result.put("error", msg);
}
//acs抛异常这里
List<String> errorList = new ArrayList();
if (!StrUtil.equals(result.getString("status"), "200")) {
result.put("status", HttpStatus.BAD_REQUEST);
JSONArray errorArr = result.getJSONArray("result");
if (errorArr !=null && errorArr.size()>0){
errorList = errorArr.stream().map(a -> ((JSONObject) a).getString("task_id")).collect(Collectors.toList());
}
result.put("message", result.getString("message"));
result.put("data", new JSONObject());
}else {
//如果向ACS下发任务变更任务状态为下发
if (api.equals("api/wms/task")){
for (int i = 0; i < list.size(); i++) {
JSONObject task_jo = list.getJSONObject(i);
String task_id = task_jo.getString("task_id");
if (errorList.contains(task_id)){
continue;
}
HashMap<String,String> map = new HashMap<>();
map.put("task_status", TaskStatusEnum.ISSUE.getCode());
WQLObject.getWQLObject("SCH_BASE_Task").update(map,"task_id = '"+task_id+"'");
if (api.equals("api/wms/task")){
List<String> errorList = new ArrayList();
if (!StrUtil.equals(result.getString("status"), "200")) {
result.put("status", HttpStatus.BAD_REQUEST);
JSONArray errorArr = result.getJSONArray("result");
if (errorArr !=null && errorArr.size()>0){
errorList = errorArr.stream().map(a -> ((JSONObject) a).getString("task_id")).collect(Collectors.toList());
}
result.put("message", result.getString("message"));
result.put("data", new JSONObject());
}
for (int i = 0; i < list.size(); i++) {
JSONObject task_jo = list.getJSONObject(i);
String task_id = task_jo.getString("task_id");
if (errorList.contains(task_id)){
continue;
}
HashMap<String,String> map = new HashMap<>();
map.put("task_status", TaskStatusEnum.ISSUE.getCode());
WQLObject.getWQLObject("SCH_BASE_Task").update(map,"task_id = '"+task_id+"'");
}
}
else {
//如果向ACS下发任务变更任务状态为下发
}
return result;
}

View File

@@ -10,17 +10,17 @@ import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.nl.common.anno.Log;
import lombok.extern.slf4j.Slf4j;
import org.nl.common.utils.MapOf;
import org.nl.common.utils.api.ResultCode;
import org.nl.modules.common.exception.BizCoreException;
import org.nl.wms.ext.acs.service.AcsToWmsService;
import org.nl.wms.pda.service.CacheLineHandService;
import org.nl.wms.sch.tasks.SpeMachineryTask;
import org.nl.wms.sch.tasks.TaskScheduleService;
import org.nl.wms.sch.tasks.WashMachineryTask;
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;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
@@ -39,6 +39,8 @@ public class AcsToWmsController {
private final AcsToWmsService acsToWmsService;
private final SpeMachineryTask speMachineryTask;
private final CacheLineHandService cacheLineHandService;
private final TaskScheduleService taskScheduleService;
private final WashMachineryTask washMachineryTask;
@PostMapping("/apply")
@Log("ACS给WMS发送任务")
@@ -76,6 +78,15 @@ public class AcsToWmsController {
return new ResponseEntity<>(acsToWmsService.orderStatus(param), HttpStatus.OK);
}
@PostMapping("/washOrder")
@Log("ACS给WMS反馈清洗工单完成")
@ApiOperation("ACS给WMS反馈清洗工单完成")
@SaIgnore
public ResponseEntity<Object> washOrderFinish(@RequestBody JSONObject param) {
washMachineryTask.updateTaskStatus( param, param.getString("status"));
return new ResponseEntity<>(HttpStatus.OK);
}
@PostMapping("/feedDeviceStatusType")
@Log("向wms反馈设备状态")
@ApiOperation("向wms反馈设备状态")
@@ -121,10 +132,8 @@ public class AcsToWmsController {
@ApiOperation("向wms反订单实施数量")
@SaIgnore
public ResponseEntity<Object> test(@RequestBody JSONObject param) {
cacheLineHandService.cacheLineMaterSync(param.getString("cacheline_code"));
// taskScheduleService.taskPublish();
washMachineryTask.createTask(new JSONObject(MapOf.of("device_code","QX03")));
return null;
}
}

View File

@@ -52,6 +52,7 @@ public interface AcsToWmsService {
* @return
*/
Map<String, Object> orderStatus(JSONObject param);
Map<String, Object> washOrderFinish(JSONObject param);
/**
* 设备实时数量

View File

@@ -10,9 +10,11 @@ import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.nl.common.enums.AcsTaskEnum;
import org.nl.common.enums.StatusEnum;
import org.nl.common.enums.WorkerOrderEnum;
import org.nl.common.utils.IdUtil;
import org.nl.common.utils.MapOf;
import org.nl.common.utils.RedissonUtils;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.wms.ext.acs.service.AcsToWmsService;
@@ -24,6 +26,8 @@ import org.nl.wms.sch.tasks.callEmpty.PlotterCallEmptyTask;
import org.nl.wms.sch.tasks.callMaterial.WrapCallMaterialTask;
import org.nl.wms.sch.tasks.sendEmpty.WrapSendEmptyTask;
import org.nl.wms.sch.tasks.sendMaterial.PlotterSendMaterialTask;
import org.nl.wms.sch.tasks.WashMachineryTask;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
@@ -40,45 +44,49 @@ import java.util.Map;
@RequiredArgsConstructor
@Slf4j
public class AcsToWmsServiceImpl implements AcsToWmsService{
@Autowired
private TaskService taskService;
@Autowired
private CacheLineHandService cacheLineHandService;
private final CacheLineHandService cacheLineHandService;
private final SpeMachineryTask speMachineryTask;
private final WashMachineryTask washMachineryTask;
private final PlotterSendMaterialTask plotterSendMaterialTask;
private final PlotterCallEmptyTask plotterCallEmptyTask;
private final WrapCallMaterialTask wrapCallMaterialTask;
private final WrapSendEmptyTask wrapSendEmptyTask;
@Override
public Map<String, Object> apply(JSONObject param) {
Map result = MapOf.of("status", HttpStatus.OK.value(), "message", "ACS向WMS申请任务成功!");
String type = param.getString("type");
AcsTaskEnum taskEnum = AcsTaskEnum.getType(type, "REQUEST_");
try {
switch (taskEnum){
//1.专机设备满料请求 2.专机设备缺料请求:专机
case REQUEST_CALLTYPE_FULL: case REQUEST_CALLTYPE_EMP:
speMachineryTask.createTask(param);
break;
case REQUEST_PLOTTER_SEND_FULL:
plotterSendMaterialTask.createTask(param);
break;
case REQUEST_PLOTTER_CALL_EMP:
plotterCallEmptyTask.createTask(param);
break;
case REQUEST_WARP_CALL_FULL:
wrapCallMaterialTask.createTask(param);
break;
case REQUEST_WARP_SEND_EMP:
wrapSendEmptyTask.createTask(param);
break;
default:
throw new BadRequestException("任务请求类型错误!");
}
RedissonUtils.lock(()->{
switch (taskEnum){
//1.专机设备满料请求 2.专机设备缺料请求:专机
case REQUEST_CALLTYPE_FULL: case REQUEST_CALLTYPE_EMP:
speMachineryTask.createTask(param);
break;
//清洗机缺料请求:
case REQUEST_WASH_EMP:
washMachineryTask.createTask(param);
break;
case REQUEST_PLOTTER_SEND_FULL:
plotterSendMaterialTask.createTask(param);
break;
case REQUEST_PLOTTER_CALL_EMP:
plotterCallEmptyTask.createTask(param);
break;
case REQUEST_WARP_CALL_FULL:
wrapCallMaterialTask.createTask(param);
break;
case REQUEST_WARP_SEND_EMP:
wrapSendEmptyTask.createTask(param);
break;
default:
throw new BadRequestException("任务请求类型错误!");
}
},type,5);
}catch (Exception ex){
result.put("status", HttpStatus.BAD_REQUEST.value());
result.put("message",ex.getMessage());
@@ -193,6 +201,21 @@ public class AcsToWmsServiceImpl implements AcsToWmsService{
return null;
}
@Override
public Map<String, Object> washOrderFinish(JSONObject param) {
JSONObject result = new JSONObject();
try {
washMachineryTask.updateTaskStatus(param,StatusEnum.TASK_FINISH.getCode());
} catch (Exception e){
result.put("status", 400);
result.put("message", e.getMessage());
return result;
}
result.put("status", HttpStatus.OK.value());
result.put("message", "订单完成状态反馈成功!");
return result;
}
@Override
public Map<String, Object> orderStatus(JSONObject orderJson) {
JSONObject result = new JSONObject();
@@ -275,7 +298,11 @@ public class AcsToWmsServiceImpl implements AcsToWmsService{
}
for (int i = 0; i < cachePositions.size(); i++) {
JSONObject cachePosition = (JSONObject) cachePositions.get(i);
cachePosition.put("vehicle_code",collect[i].equals("0")?"":collect[i]);
String vehicleCode = collect[i];
cachePosition.put("vehicle_code",vehicleCode.equals("0")?"": vehicleCode);
if (vehicleCode.equals("99999")){
cachePosition.put("err_type", StatusEnum.CACHE_POINT_SCAN_ERROR.getCode());
}
positionTab.update(cachePosition,"position_code = '"+cachePosition.getString("position_code")+"'");
}
//更新缓存线及缓存线载具表对应关系

View File

@@ -47,8 +47,6 @@ import java.util.stream.Collectors;
@Service
public class AgvInstService {
private static final String OPT_NAME = "acs回调#";
@Autowired
private PointLockUtils pointLockUtils;
@Autowired
@@ -56,109 +54,88 @@ public class AgvInstService {
@Autowired
private RedissonClient redissonClient;
//满料请求
//满料请求点位确认
//1.判断当前设备路由表是否配置下一道路由设备,如果不是则说明直接到清洗
//2.是否设置人工搬运(人工搬运之后维护设备状态)
//3.判断下一道路由设备是否含有没满的设备料斗
//4.有则创建agv指令
// 没有则创建缓存架任务
public JSONObject fullMaster(JSONObject param){
JSONObject taskForm = null;
log.info(OPT_NAME+"fullMaster param:{}",JSONObject.toJSONString(param));
WQLObject workOrder = WQLObject.getWQLObject("PDM_produce_workOrder");
public void fullMaster(JSONObject task){
final String OPT_NAME = "满料请求:";
WQLObject basePoint = WQLObject.getWQLObject("sch_base_point");
WQLObject taskTab = WQLObject.getWQLObject("sch_base_task");
WQLObject cacheLineSearch = WQLObject.getWQLObject("SCH_cacheLine_region_relation");
try {
String workorder = param.getString("workorder_code");//
String point_code = param.getString("device_code");
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);
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;
//判断缓存线是不是去深坑清洗深坑区域15个点判断空的物料坑位
String cacheVehile = "";
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();
}
}
String point_code = task.getString("start_point_code");
String quantity = task.getString("quantity");
JSONObject devicePoint = basePoint.query("point_code = '" + point_code + "' and is_delete = 0 and is_used = 1").uniqueResult(0);
String nextPoint;
//判断缓存线是不是去深坑清洗深坑区域15个点判断空的物料坑位
String cacheVehile = "";
if (devicePoint.getString("next_region_code").equals(ConstantParam.SK_REGION)){
JSONArray nextPointList = WQL.getWO("sch_point").addParamMap(MapOf.of("flag","7","region_code", devicePoint.getString("next_region_code"),"qty",quantity)).process().getResultJSONArray(0);
if (nextPointList.size() == 0){
throw new BadRequestException(OPT_NAME+"深坑区域:"+devicePoint.getString("next_region_code")+"无可用点位");
}
nextPoint = nextPointList.getJSONObject(0).getString("point_code");
}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){
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(OPT_NAME+"缓存线:"+nextPoint+"没有可用空载具");
}
//生成任务nextPoint
SpeMachineryTask pointTask = new SpeMachineryTask();
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));
return taskForm;
}else {
nextPoint = nextPointList.getJSONObject(0).getString("point_code");
}
}
}catch (Exception ex){
log.error(OPT_NAME+"fullMaster error:{}",ex);
throw ex;
if (StringUtils.isEmpty(nextPoint)){
throw new BadRequestException(OPT_NAME+"设备:"+point_code+"没有可用点位");
}
return taskForm;
task.put("vehicle_code",cacheVehile);
task.put("next_point_code",nextPoint);
task.put("task_status",StatusEnum.TASK_START_END_P.getCode());
task.put("update_time", DateUtil.now());
taskTab.update(task);
};
//缺料请求:上料位
//1.判断当前设备表对应的缓存线是否开放
//2.根据当前设备绑定的物料id从缓存线中获取相同物料对应载具列表
//3.agv根据对应载具列表行进扫码匹配匹配到对应物料则创建点对点任务
public JSONObject callMatter(JSONObject param){
JSONObject taskForm = null;
log.info(OPT_NAME+"callMatter param:{}",JSONObject.toJSONString(param));
public void callMatter(JSONObject task){
final String OPT_NAME = "专机缺料请求:";
WQLObject basePointTable = WQLObject.getWQLObject("SCH_BASE_Point");
WQLObject workOrderTable = WQLObject.getWQLObject("PDM_produce_workOrder");
WQLObject cacheLineTable = WQLObject.getWQLObject("SCH_cacheLine_region_relation");
WQLObject taskTable = WQLObject.getWQLObject("SCH_base_task");
//参数
String point_code = param.getString("device_code");
String workorder = param.getString("workorder_code");
String point_code = task.getString("next_point_code");
String material_id = task.getString("material_id");
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));
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);
Assert.notNull(cacheLine, String.format("区域%s对应缓存线信息不存在", devicePoint.getString("region_code")));
//缓存线位置编码 :缺料请求获取缓存线满载具列表
String startPoint = cacheLine.getString("cacheline_code");
String cacheVehile = getCacheVehile(startPoint, material_id);
if (StringUtils.isEmpty(cacheVehile)) {
throw new BadRequestException("缓存线:"+startPoint+"没有可用载具");
}
//判断当前物料载具已经任务分配数量:如果>物料已经分配任务。说明满了,不允许再分配
JSONArray allocateTask = taskTable.query("point_code1 = '" + startPoint + "' and material_id = '" + material_id + "' and task_status <" + StatusEnum.TASK_FINISH.getCode()).getResultJSONArray(0);
if (allocateTask.size()>=cacheVehile.split(",").length){
log.error(OPT_NAME+"callMatter 缓存线:{}上含有物料:{}的载具分配完任务id:{}",startPoint,material_id,allocateTask.stream().map(o-> ((JSONObject)o).getString("task_id")).collect(Collectors.joining(",")));
throw new BadRequestException(String.format("缓存线%s上含物料%s的载具已分配完",startPoint,material_id));
}
SpeMachineryTask pointTask = new SpeMachineryTask();
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));
}catch (Exception ex){
log.error(OPT_NAME+"callMatter error:{}",ex);
throw ex;
JSONObject cacheLine = cacheLineTable.query("region_code = '"+devicePoint.getString("region_code")+"' and is_active = '"+StatusEnum.STATUS_TRUE.getCode()+"'").uniqueResult(0);
Assert.notNull(cacheLine, String.format(OPT_NAME+"区域%s对应缓存线信息不存在", devicePoint.getString("region_code")));
//缓存线位置编码 :缺料请求获取缓存线满载具列表
String startPoint = cacheLine.getString("cacheline_code");
String cacheVehile = getCacheVehile(startPoint, material_id);
if (StringUtils.isEmpty(cacheVehile)) {
throw new BadRequestException(OPT_NAME+"缓存线:"+startPoint+"没有可用载具");
}
return taskForm;
//判断当前物料载具已经任务分配数量:如果>物料已经分配任务。说明满了,不允许再分配
JSONArray allocateTask = taskTable.query("point_code1 = '" + startPoint + "' and material_id = '" + material_id + "' and task_status <" + StatusEnum.TASK_FINISH.getCode()).getResultJSONArray(0);
if (allocateTask.size()>=cacheVehile.split(",").length){
log.error(OPT_NAME+"callMatter 缓存线:{}上含有物料:{}的载具分配完任务id:{}",startPoint,material_id,allocateTask.stream().map(o-> ((JSONObject)o).getString("task_id")).collect(Collectors.joining(",")));
throw new BadRequestException(String.format(OPT_NAME+"缓存线%s上含物料%s的载具已分配完",startPoint,material_id));
}
task.put("vehicle_code",cacheVehile);
task.put("start_point_code",startPoint);
task.put("return_point_code",startPoint);
task.put("task_status",StatusEnum.TASK_START_END_P.getCode());
task.put("update_time", DateUtil.now());
taskTable.update(task);
}
public String getCacheVehile(String cacheLine,String materialId){

View File

@@ -0,0 +1,17 @@
package org.nl.wms.pdm;
import com.baomidou.mybatisplus.extension.service.IService;
import org.nl.wms.pdm.dao.PdmProduceWashorder;
/**
* <p>
* 清洗工单表 服务类
* </p>
*
* @author generator
* @since 2023-04-07
*/
public interface IPdmProduceWashorderService extends IService<PdmProduceWashorder> {
}

View File

@@ -0,0 +1,116 @@
package org.nl.wms.pdm.dao;
import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* <p>
* 清洗工单表
* </p>
*
* @author generator
* @since 2023-04-07
*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("pdm_produce_washorder")
public class PdmProduceWashorder implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 工单编号
*/
private String workorderId;
/**
* 工单编号
*/
private String workorderCode;
private String status;
/**
* 生产区域
*/
private String productArea;
/**
* 实际数量
*/
private String qty;
/**
* 物料编号
*/
private String materialCode;
/**
* 物料标识
*/
private String isNeedmove;
/**
* 实际单重
*/
private BigDecimal materialWeight;
/**
* 当前生产设备编码
*/
private String deviceCode;
/**
* 工单是否异常
*/
private String isError;
/**
* 设备集合
*/
private String inDevices;
/**
* 异常信息
*/
private String errorInfo;
/**
* 备注
*/
private String remark;
/**
* 创建人
*/
private String createId;
/**
* 创建人
*/
private String createName;
/**
* 创建时间
*/
private String createTime;
/**
* 修改人
*/
private String updateId;
/**
* 修改人
*/
private String updateName;
/**
* 修改时间
*/
private String updateTime;
}

View File

@@ -0,0 +1,17 @@
package org.nl.wms.pdm.dao.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.nl.wms.pdm.dao.PdmProduceWashorder;
/**
* <p>
* 清洗工单表 Mapper 接口
* </p>
*
* @author generator
* @since 2023-04-07
*/
public interface PdmProduceWashorderMapper extends BaseMapper<PdmProduceWashorder> {
}

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.nl.wms.pdm.dao.mapper.PdmProduceWashorderMapper">
</mapper>

View File

@@ -0,0 +1,21 @@
package org.nl.wms.pdm.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.nl.wms.pdm.IPdmProduceWashorderService;
import org.nl.wms.pdm.dao.PdmProduceWashorder;
import org.nl.wms.pdm.dao.mapper.PdmProduceWashorderMapper;
import org.springframework.stereotype.Service;
/**
* <p>
* 清洗工单表 服务实现类
* </p>
*
* @author generator
* @since 2023-04-07
*/
@Service
public class PdmProduceWashorderServiceImpl extends ServiceImpl<PdmProduceWashorderMapper, PdmProduceWashorder> implements IPdmProduceWashorderService {
}

View File

@@ -22,7 +22,6 @@ public abstract class AbstractAcsTask {
public abstract void updateTaskStatus(JSONObject taskObj,String status);
public abstract String createTask(JSONObject param);

View File

@@ -5,8 +5,8 @@ package org.nl.wms.sch.manage;
*/
public enum TaskStatusEnum {
CREATED("1", "生成"),
SURE_START("2", "确定起"),
SURE_END("3", "确定终点"),
SURE_START_ERROR("2", "位确认异常"),
//SURE_END("3", "确定终点"),
START_AND_POINT("4", "起点终点确认"),
ISSUE("5", "下发"),
EXECUTING("6", "执行中"),

View File

@@ -13,10 +13,9 @@ import lombok.extern.slf4j.Slf4j;
import org.nl.system.service.dict.ISysDictService;
import org.nl.system.service.dict.dao.Dict;
import org.nl.wms.sch.manage.FinishTypeEnum;
import org.nl.wms.sch.manage.TaskStatusEnum;
import org.nl.wms.sch.service.TaskService;
import org.nl.wms.sch.service.dto.TaskDto;
import org.nl.wms.sch.tasks.TaskTypeEnum;
import org.nl.common.enums.TaskTypeEnum;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

View File

@@ -121,7 +121,7 @@ public class CallMaterialTask extends AbstractAcsTask {
}
public void findStartPoint() {
String task_status = TaskStatusEnum.SURE_START.getCode();
String task_status = TaskStatusEnum.START_AND_POINT.getCode();
WQLObject taskTab = WQLObject.getWQLObject("SCH_BASE_Task");
JSONArray taskArry = taskTab.query("task_status='" + task_status + "' AND handle_class='" + THIS_CLASS + "' AND is_delete='0' ").getResultJSONArray(0);
for (int i = 0; i < taskArry.size(); i++) {
@@ -170,7 +170,7 @@ public class CallMaterialTask extends AbstractAcsTask {
String start_point_code = form.getString("start_point_code");
String next_point_code = form.getString("next_point_code");
String vehicle_code = form.getString("vehicle_code");
String task_status = TaskStatusEnum.SURE_START.getCode();
String task_status = TaskStatusEnum.CREATED.getCode();
String material_id = form.getString("material_id");
String create_mode = form.getString("create_mode");

View File

@@ -1,10 +1,14 @@
package org.nl.wms.sch.tasks;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.nl.common.ConstantParam;
import org.nl.common.enums.AcsTaskEnum;
import org.nl.common.enums.InterfaceLogType;
import org.nl.common.enums.StatusEnum;
@@ -12,12 +16,14 @@ import org.nl.common.utils.MapOf;
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.WQL;
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;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
@@ -59,56 +65,71 @@ public class SpeMachineryTask extends AbstractAcsTask {
@Override
public String createTask(JSONObject param) {
WQLObject taskTab = WQLObject.getWQLObject("sch_base_task");
WQLObject workOrder = WQLObject.getWQLObject("PDM_produce_workOrder");
String workorder = param.getString("workorder_code");//
String point_code = param.getString("device_code");
String quantity = param.getString("quantity");
String type = param.getString("type");
JSONObject order = workOrder.query("workorder_code = '" + workorder + "' and is_delete = 0 and workorder_status != "+StatusEnum.TASK_FINISH.getCode()).uniqueResult(0);
Assert.notNull(order, String.format("下发工单%s不存在未完成工单", workorder));
JSONObject form = null;
if (AcsTaskEnum.REQUEST_CALLTYPE_FULL.getCode().equals(type)){
form = agvInstService.fullMaster(param);
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);
form = new JSONObject(MapOf.of("start_point_code",point_code,
"next_point_code","","return_point_code", empPoint,"vehicle_code",
"","product_area","quantity", quantity,order.getString("product_area"),"type",type,"material_id", order.getString("material_id")));
}
if (AcsTaskEnum.REQUEST_CALLTYPE_EMP.getCode().equals(type)){
form = agvInstService.callMatter(param);
form = new JSONObject(MapOf.of("start_point_code","",
"next_point_code",point_code,"return_point_code", "","vehicle_code",
"","product_area","quantity", quantity,order.getString("product_area"),"type",type,"material_id", order.getString("material_id")));
}
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");
if(StrUtil.isEmpty(start_point_code)) {
throw new BadRequestException("起点不能为空!");
}
if(StrUtil.isEmpty(next_point_code)) {
throw new BadRequestException("终点不能为空!");
}
if(StrUtil.isEmpty(vehicle_code)) {
throw new BadRequestException("载具不能为空!");
}
String taskdtl_id = IdUtil.getSnowflake(1, 1).nextId() + "";
JSONObject task = new JSONObject();
task.put("task_id", taskdtl_id);
task.put("task_name", task_name);
task.put("task_code", CodeUtil.getNewCode("TASK_CODE"));
task.put("task_type", type);
task.put("task_status", TaskStatusEnum.CREATED.getCode());
task.put("point_code1", start_point_code);
task.put("point_code2", next_point_code);
task.put("vehicle_code2", vehicle_code2);
task.put("vehicle_code", vehicle_code);
task.put("material_id", material_id);
task.put("handle_class", this.getClass().getName());
task.put("finished_type", "01");
task.put("is_delete", "0");
String currentUserId = SecurityUtils.getCurrentUserId();
task.put("create_id", currentUserId);
task.put("create_name", SecurityUtils.getCurrentNickName());
task.put("update_optid", currentUserId);
task.put("update_optname", SecurityUtils.getCurrentNickName());
task.put("create_time", DateUtil.now());
task.put("update_time", DateUtil.now());
task.put("priority", "1");
WQLObject.getWQLObject("SCH_BASE_Task").insert(task);
JSONObject task = new JSONObject();
String taskdtl_id = IdUtil.getSnowflake(1, 1).nextId() + "";
packageParam(type, form, task, taskdtl_id);
WQLObject.getWQLObject("SCH_BASE_Task").insert(task);
try {
pointConfirm(task);
//下发
}catch (Exception ex){
task.put("task_status",TaskStatusEnum.SURE_START_ERROR.getCode());
task.put("remark",ex.getMessage());
taskTab.update(task);
}
return taskdtl_id;
}
private void packageParam(String type, JSONObject form, JSONObject task, String taskdtl_id) {
参数封装:{
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");
task.put("task_id", taskdtl_id);
task.put("task_name", task_name);
task.put("task_code", CodeUtil.getNewCode("TASK_CODE"));
task.put("task_type", type);
task.put("task_status", TaskStatusEnum.CREATED.getCode());
task.put("point_code1", start_point_code);
task.put("point_code2", next_point_code);
task.put("vehicle_code2", vehicle_code2);
task.put("vehicle_code", vehicle_code);
task.put("material_id", material_id);
task.put("handle_class", this.getClass().getName());
task.put("finished_type", "1");
task.put("is_delete", "0");
String currentUserId = SecurityUtils.getCurrentUserId();
task.put("create_id", currentUserId);
task.put("create_name", SecurityUtils.getCurrentNickName());
task.put("update_optid", currentUserId);
task.put("update_optname", SecurityUtils.getCurrentNickName());
task.put("create_time", DateUtil.now());
task.put("update_time", DateUtil.now());
task.put("priority", "1");}
}
@Override
public void cancel(String taskId) {
@@ -223,6 +244,12 @@ public class SpeMachineryTask extends AbstractAcsTask {
@Override
public void pointConfirm(JSONObject param) {
String type = param.getString("type");
if (AcsTaskEnum.REQUEST_CALLTYPE_FULL.getCode().equals(type)){
agvInstService.fullMaster(param);
}
if (AcsTaskEnum.REQUEST_CALLTYPE_EMP.getCode().equals(type)){
agvInstService.callMatter(param);
}
}
}

View File

@@ -1,12 +1,18 @@
package org.nl.wms.sch.tasks;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.unit.DataUnit;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.jetbrains.annotations.NotNull;
import org.nl.common.enums.AcsTaskEnum;
import org.nl.common.enums.StatusEnum;
import org.nl.common.utils.IdUtil;
import org.nl.common.utils.MapOf;
@@ -26,6 +32,8 @@ import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collector;
import java.util.stream.Collectors;
/*
@@ -47,15 +55,18 @@ 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.getCode() + "'").getResultJSONArray(0);
JSONArray all = taskTable.query("is_auto_issue = '1' and task_status < '" + 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();
Iterator<Object> iterator = all.iterator();
while (iterator.hasNext()){
JSONObject task = (JSONObject)iterator.next();
if (!task.getString("task_type").equals(StatusEnum.TASK_START_ERROR.getCode())){
continue;
}
try {
Class<?> clz = Class.forName(task.getString("handle_class"));
Object obj = clz.newInstance();
@@ -66,6 +77,8 @@ public class TaskScheduleService {
}catch (Exception ex){
task.put("task_type", StatusEnum.TASK_START_ERROR.getCode());
task.put("remark",ex.getMessage());
task.put("update_time",DateUtil.now());
taskTable.update(task);
iterator.remove();
}
}
@@ -74,8 +87,8 @@ public class TaskScheduleService {
for (String area : areaCollent.keySet()) {
List<Object> array = areaCollent.get(area);
if (array.size()>0){
String pointCollect = array.stream().map(o -> ((JSONObject) o).getString("point_code1") + "','" + ((JSONObject) o).getString("point_code2")).collect(Collectors.joining(","));
JSONArray needMergeCollect = WQL.getWO("sch_point").addParamMap(MapOf.of("flag", "5", "point_code", "'" + pointCollect + "'")).process().getResultJSONArray(0);
String pointCollect = array.stream().map(o -> ((JSONObject) o).getString("point_code1") + "','" + ((JSONObject) o).getString("point_code2")).collect(Collectors.joining("','"));
JSONArray needMergeCollect = WQL.getWO("sch_point").addParamMap(MapOf.of("flag", "5", "point_codes", "'" + pointCollect + "'")).process().getResultJSONArray(0);
//区域编号对应point_code
Map<String, List<Object>> pointRegionCollent = needMergeCollect.stream().collect(Collectors.groupingBy(o -> ((JSONObject) o).getString("point_code")));
Set<String> mergePointCollent = needMergeCollect.stream().map(item -> ((JSONObject) item).getString("point_code")).collect(Collectors.toSet());
@@ -92,18 +105,22 @@ public class TaskScheduleService {
if (taskGroupMap.get(taskId) != null){
task.put("task_group_id",taskGroupMap.get(taskId));
task.put("is_send","0");
Merge.add(task);
continue;
}
String start = task.getString("point_code1");
String end = task.getString("point_code2");
taskGroupMap.put(taskId,taskGroupId);
task.put("task_group_id",taskGroupId);
//如果点位不属于查询出来可以合并点位集合:则单独下发集合
if (mergePointCollent.contains(start)&&mergePointCollent.contains(end)){
if (!mergePointCollent.contains(start) && !mergePointCollent.contains(end)){
notMerge.add(task);
continue;
}
//起点点位是否有多个合并任务点,如果没有则判断终点是否有多个合并任务点;都没有则说明当前起点终点对应区域只有一个任务:放入等待下发集合中
String mergeTargetId = getMergePoint(pointRegionCollent, start,end,array);
List<String> collect = taskGroupMap.keySet().stream().collect(Collectors.toList());
collect.add(taskId);
String mergeTargetId = getMergePoint(pointRegionCollent, start,end,array,collect);
if (mergeTargetId == null){
waitingTask.add(task);
continue;
@@ -113,8 +130,8 @@ public class TaskScheduleService {
Merge.add(task);
}
//开始下发处理waitingTask如果创建时间>2分钟则改单独下发
if (waitingTask.size()>1){
List<Object> needPublish = waitingTask.stream().filter(a -> ((JSONObject)a).getString("create_time") == DateUtil.now()).collect(Collectors.toList());
if (waitingTask.size()>0){
List<Object> needPublish = waitingTask.stream().filter(a -> DateUtil.between(new Date(),DateUtil.parseDateTime(((JSONObject)a).getString("create_time") ), DateUnit.MINUTE) >2 ).collect(Collectors.toList());
notMerge.addAll(needPublish);
}
String notMergeID = notMerge.stream().map(a -> ((JSONObject) a).getString("task_id")).collect(Collectors.joining(","));
@@ -126,7 +143,8 @@ public class TaskScheduleService {
//批量更新任务状态is_send,task_group_id
for (Object task : Merge) {
JSONObject task1 = (JSONObject) task;
task1.put("task_type",StatusEnum.TASK_PUBLISH.getCode());
task1.put("update_name","schedule");
task1.put("update_time",DateUtil.now());
taskTable.update(task1,"task_id = '"+task1.getString("task_id")+"'");
}
//缓存线任务待确认是否生成多个
@@ -141,39 +159,28 @@ public class TaskScheduleService {
}
}
@NotNull
private String getMergePoint(Map<String, List<Object>> pointRegionCollent, String start,String end,List<Object> tasks) {
JSONObject startPointInfo = (JSONObject) pointRegionCollent.get(start).get(0);
String startPointCollent = startPointInfo.getString("pointCollent");
private String getMergePoint(Map<String, List<Object>> pointRegionCollent, String start,String end,List<Object> tasks,List<String> taskIds) {
String findpoint = findpoint(pointRegionCollent, start, tasks, taskIds);
if (findpoint == null){
findpoint = findpoint(pointRegionCollent, end, tasks, taskIds);
}
return findpoint;
}
private String findpoint(Map<String, List<Object>> pointRegionCollent, String start, List<Object> tasks, List<String> taskIds) {
List<Object> objects = pointRegionCollent.get(start);
JSONObject startPointInfo = (JSONObject) objects.get(0);
String startPointCollent = startPointInfo.getString("pointcollent");
String[] split = startPointCollent.split(",");
if (split.length>1){
for (String s : split) {
if (!s.equals(start)){
Object task = tasks.stream().filter(a -> ((JSONObject) a).getString("point_code1").equals(s)).findAny().get();
return ((JSONObject)task).getString("task_id");
}
}
}else {
JSONObject endPointInfo = (JSONObject) pointRegionCollent.get(start).get(0);
String endPointCollent = endPointInfo.getString("pointCollent");
split = endPointCollent.split(",");
for (String s : split) {
if (!s.equals(start)){
Object task = tasks.stream().filter(a -> ((JSONObject) a).getString("point_code2").equals(s)).findAny().get();
return ((JSONObject)task).getString("task_id");
}
for (String s : split) {
Optional<Object> any = tasks.stream().filter(a -> ((JSONObject) a).getString("point_code1").equals(s) && !taskIds.contains(((JSONObject) a).getString("task_id"))).findAny();
if (any.isPresent()){
return ((JSONObject)any.get()).getString("task_id");
}
}
return null;
}
public static void main(String[] args) {
JSONArray array = new JSONArray();
for (int i =0;i<10;i++){
JSONObject jsonObject = new JSONObject(MapOf.of("product_area", new Random().nextInt(2) + 1, "name", UUID.randomUUID().toString()));
array.add(jsonObject);
}
}
}

View File

@@ -0,0 +1,168 @@
package org.nl.wms.sch.tasks;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Assert;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import groovy.lang.GroovyShell;
import groovy.lang.Script;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.nl.common.ConstantParam;
import org.nl.common.enums.AcsTaskEnum;
import org.nl.common.enums.InterfaceLogType;
import org.nl.common.enums.StatusEnum;
import org.nl.common.enums.WorkerOrderEnum;
import org.nl.common.utils.IdUtil;
import org.nl.common.utils.MapOf;
import org.nl.common.utils.SecurityUtils;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.common.utils.FileUtil;
import org.nl.modules.system.util.CodeUtil;
import org.nl.modules.wql.WQL;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.wms.ext.acs.service.WmsToAcsService;
import org.nl.wms.ext.acs.service.impl.AgvInstService;
import org.nl.wms.pdm.IPdmProduceWashorderService;
import org.nl.wms.pdm.dao.PdmProduceWashorder;
import org.nl.wms.sch.manage.AbstractAcsTask;
import org.nl.wms.sch.manage.TaskStatusEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.Function;
import java.util.function.ToDoubleFunction;
import java.util.stream.Collectors;
/**
* 专机任务
*/
@Slf4j
@Service
public class WashMachineryTask extends AbstractAcsTask {
@Autowired
private IPdmProduceWashorderService iPdmProduceWashorderService;
@Autowired
private WmsToAcsService wmsToAcsService;
FileSystemResourceLoader loader = new FileSystemResourceLoader();
GroovyShell groovyShell = new GroovyShell();
@Override
@Transactional
public void updateTaskStatus(JSONObject param,String status) {
WQLObject pointTab = WQLObject.getWQLObject("SCH_BASE_Point");
Assert.notEmpty(new Object[]{param,param.getString("workorder_id")},"参数不能为空");
String inDevices = param.getString("in_devices");
String workorderId = param.getString("workorder_id");
if (!StringUtils.isEmpty(inDevices)){
String sql = Arrays.stream(inDevices.split(",")).collect(Collectors.joining("','"));
//跟新工单:状态为完成;跟新点位 material_id is not null and point_status = '2'
pointTab.update(MapOf.of("material_id","","point_status","1"),"point_code in ('"+sql+"')");
QueryWrapper<PdmProduceWashorder> query = new QueryWrapper<>();
PdmProduceWashorder update = new PdmProduceWashorder();
update.setIsError("0");
update.setErrorInfo("");
update.setUpdateId("1");
update.setUpdateTime(DateUtil.now());
update.setCreateName("acs");
update.setStatus(StatusEnum.TASK_FINISH.getCode());
iPdmProduceWashorderService.update(update,new QueryWrapper<PdmProduceWashorder>().eq("workorder_id",workorderId));
}
}
@Override
@SneakyThrows
public String createTask(JSONObject param) {
WQLObject pointTab = WQLObject.getWQLObject("SCH_BASE_Point");
WQLObject materialTab = WQLObject.getWQLObject("md_me_materialbase");
String pointCode = param.getString("device_code");
JSONObject device = WQL.getWO("sch_point").addParamMap(MapOf.of("flag", "8", "point_code", pointCode)).process().uniqueResult(0);
//is_used = '0'人工下料:入料仓上线inupperlimit_qty;is_artificial人工
Double inupperlimitQty = device.getDouble("inupperlimit_qty");
String deviceCode = device.getString("device_code");
String artificial = device.getString("is_artificial").equals("1")?"0":"1";
JSONArray points = pointTab.query("region_code = 'SKQX' and material_id is not null and point_status = '2' and is_used = '"+artificial+"' order by vehicle_qty desc").getResultJSONArray(0);
//查询深坑相同物料类型的点位:深坑单位:重量
if (points.size()>0){
Map<String, List<Object>> materialCollent = points.stream().collect(Collectors.groupingBy(o -> ((JSONObject) o).getString("material_id")));
//查询清洗设备最大重量
Resource resource = loader.getResource("classpath:/groovyFile.groovy");
Script script = groovyShell.parse(resource.getFile());
ArrayList<JSONObject> result = (ArrayList)script.invokeMethod("getPoints", new Object[]{points, materialCollent, inupperlimitQty});
//确认acs参数 创建工单下发acs
if (!CollectionUtils.isEmpty(result)){
String material_id = result.get(0).getString("material_id");
JSONObject material = materialTab.query("material_id = '" + material_id + "' and is_delete = 0").uniqueResult(0);
Double qty = result.stream().mapToDouble(value -> value.getDouble("qty")).sum();
PdmProduceWashorder washorder = new PdmProduceWashorder();
washorder.setWorkorderId(IdUtil.getStringId());
washorder.setWorkorderCode(IdUtil.getStringId());
washorder.setIsNeedmove("0");
washorder.setDeviceCode(deviceCode);
washorder.setMaterialWeight(new BigDecimal(qty));
washorder.setMaterialCode(material.getString("material_code"));
washorder.setCreateTime(DateUtil.now());
washorder.setInDevices(result.stream().map(a->a.getString("point_code")).collect(Collectors.joining(",")));
washorder.setProductArea(device.getString("product_area"));
washorder.setCreateId("1");
washorder.setCreateName("acs");
washorder.setStatus(StatusEnum.TASK_CREATE.getCode());
//下发"
JSONArray request = new JSONArray();
JSONObject jsonObject = new JSONObject(MapOf.of("workorder_id", washorder.getWorkorderId()
, "workorder_code", washorder.getWorkorderCode()
, "qty", washorder.getMaterialWeight()
, "material_code", washorder.getMaterialCode()
, "device_code", pointCode
, "is_needmove", "0"
, "in_devices", washorder.getInDevices()
));
request.add(jsonObject);
Map<String, Object> response = wmsToAcsService.order(request);
if (response.get("status").equals(HttpStatus.BAD_REQUEST)){
washorder.setErrorInfo((String) response.get("message"));
washorder.setStatus(StatusEnum.TASK_START_ERROR.getCode());
washorder.setIsError("1");
}
iPdmProduceWashorderService.save(washorder);
}
}
return null;
}
@Override
public void cancel(String taskId) {
}
@Override
public void pointConfirm(JSONObject param) {
//查询深坑相同物料类型的点位
WQLObject pointTab = WQLObject.getWQLObject("SCH_BASE_Point");
JSONArray points = pointTab.query("material_id is not null and point_status = 1 and is_used = 1 and lock_type = 0 and region_code = '" + ConstantParam.SK_REGION + "'").getResultJSONArray(0);
}
}

View File

@@ -26,6 +26,7 @@
输入.vehicle_status TYPEAS s_string
输入.device_code TYPEAS s_string
输入.point_code TYPEAS s_string
输入.point_codes TYPEAS f_string
输入.region_code TYPEAS s_string
[临时表]
@@ -51,7 +52,7 @@
##########################################
IF 输入.flag = "1"
PAGEQUERY
QUERY
SELECT
next_de.inupperlimit_qty - next_de.deviceinstor_qty - IFNULL( sum( material_qty ), 0 ) AS currentQty,
next_de.cacheline_code,
@@ -66,12 +67,12 @@
AND next_de.material_id = 输入.material_id
AND sch_base_task.task_status < 7
ENDSELECT
ENDPAGEQUERY
ENDQUERY
ENDIF
IF 输入.flag = "2"
PAGEQUERY
QUERY
SELECT
b.*
FROM
@@ -81,11 +82,11 @@
a.point_code = 输入.point_code
AND b.point_type = 输入.point_type
ENDSELECT
ENDPAGEQUERY
ENDQUERY
ENDIF
IF 输入.flag = "3"
PAGEQUERY
QUERY
SELECT
pdm_bi_device.inupperlimit_qty - ifnull( sum( sch_base_task.material_qty ), 0 ) - pdm_bi_device.deviceinstor_qty AS currentQty,
pdm_bi_device.device_code,
@@ -106,11 +107,11 @@
device_code
HAVING currentQty> 输入.qty
ENDSELECT
ENDPAGEQUERY
ENDQUERY
ENDIF
IF 输入.flag = "4"
PAGEQUERY
QUERY
SELECT
*
FROM
@@ -121,29 +122,29 @@
device_code
HAVING status_type = '02'
ENDSELECT
ENDPAGEQUERY
ENDQUERY
ENDIF
IF 输入.flag = "5"
PAGEQUERY
QUERY
SELECT
sch_base_region.region_code,
sch_base_point.point_code,
GROUP_CONCAT(b.point_code) as pointCollent
GROUP_CONCAT(b.point_code) as pointcollent
FROM
sch_base_region
LEFT JOIN sch_base_point ON sch_base_region.region_code = sch_base_point.region_code
LEFT JOIN sch_base_point b ON sch_base_region.region_code = b.region_code AND b.point_code IN ( 输入.point_code )
LEFT JOIN sch_base_point b ON sch_base_region.region_code = b.region_code AND b.point_code IN ( 输入.point_codes )
WHERE
sch_base_region.MERGE = '1'
AND sch_base_point.point_code IN ( 输入.point_code )
AND sch_base_point.point_code IN ( 输入.point_codes )
GROUP BY sch_base_point.point_code
ENDSELECT
ENDPAGEQUERY
ENDQUERY
ENDIF
IF 输入.flag = "6"
PAGEQUERY
QUERY
SELECT
v.vehicle_code,v.vehicle_status,v.material_id
FROM
@@ -155,6 +156,39 @@
v.material_id = 输入.material_id
ENDOPTION
ENDSELECT
ENDPAGEQUERY
ENDQUERY
ENDIF
IF 输入.flag = "7"
QUERY
SELECT
GROUP_CONCAT(sch_base_task.task_id),
sch_base_point.vehicle_max_qty - ifnull( sum( sch_base_task.material_qty ), 0 ) - sch_base_point.vehicle_qty AS currentQty,
sch_base_point.*,
from sch_base_point
left JOIN sch_base_task ON sch_base_point.point_code = point_code2 and task_status < 7
OPTION 输入.region_code <> ""
sch_base_point.region_code = 输入.region_code
ENDOPTION
GROUP BY sch_base_point.point_code
HAVING currentQty > 输入.qty
ENDSELECT
ENDQUERY
ENDIF
IF 输入.flag = "8"
QUERY
SELECT
pdm_bi_device.*
FROM
sch_base_point
LEFT JOIN pdm_bi_device ON sch_base_point.device_code = pdm_bi_device.device_code
WHERE
sch_base_point.point_code = 输入.point_code
ENDSELECT
ENDQUERY
ENDIF

View File

@@ -0,0 +1,24 @@
import com.alibaba.fastjson.JSONArray
import com.alibaba.fastjson.JSONObject
def getPoints(JSONArray points,Map<String, List<Object>> materialCollent,Double inupperlimitQty){
def list = new ArrayList<>();
JSONObject point = points.getJSONObject(0)
String materialId = point.getString("material_id");
List<Object> collect = materialCollent.get(materialId);
collect.sort(Comparator.comparingDouble({ item -> ((JSONObject) item).getDouble("vehicle_qty") }).reversed());
Double qty = 0.0;
for (Object o1 : collect) {
if (qty>inupperlimitQty){
return list;
}
def item = new JSONObject()
item.put("point_code",((JSONObject) o1).getString("point_code"))
item.put("qty",((JSONObject) o1).getDouble("vehicle_qty"));
item.put("material_id",materialId);
list.add(item);
qty = qty+((JSONObject) o1).getDouble("vehicle_qty");
}
return list;
}