feat: 外包间任务

This commit is contained in:
2026-01-12 19:46:34 +08:00
parent 95c4bc3997
commit 999d4bebea
23 changed files with 1861 additions and 20 deletions

View File

@@ -0,0 +1,10 @@
package org.nl.config;
/**
*
* @author: lyd
* @date: 2026/1/12
*/
public class BusinessUtils {
}

View File

@@ -123,4 +123,23 @@ public class PdaProductionController {
public ResponseEntity<Object> confirmCallBucketMaterial(@RequestBody JSONObject whereJson) {
return new ResponseEntity<>(pdaProductionService.confirmCallBucketMaterial(whereJson), HttpStatus.OK);
}
@PostMapping("/getTaskBucketGroupInfo")
@Log("料桶称重-获取物料库存信息")
@SaIgnore
public ResponseEntity<Object> getTaskBucketGroupInfo(@RequestBody JSONObject whereJson) {
return new ResponseEntity<>(pdaProductionService.getTaskBucketGroupInfo(whereJson), HttpStatus.OK);
}
@PostMapping("/manualInbound")
@Log("料桶称重-入站")
@SaIgnore
public ResponseEntity<Object> manualInbound(@RequestBody JSONObject whereJson) {
return new ResponseEntity<>(pdaProductionService.manualInbound(whereJson), HttpStatus.OK);
}
@PostMapping("/manualOutbound")
@Log("料桶称重-出站")
@SaIgnore
public ResponseEntity<Object> manualOutbound(@RequestBody JSONObject whereJson) {
return new ResponseEntity<>(pdaProductionService.manualOutbound(whereJson), HttpStatus.OK);
}
}

View File

@@ -92,4 +92,20 @@ public interface PdaProductionService {
* @return
*/
PdaResponse confirmCallBucketMaterial(JSONObject param);
PdaResponse getTaskBucketGroupInfo(JSONObject param);
/**
* 手动入站
* @param param
* @return
*/
PdaResponse manualInbound(JSONObject param);
/**
* 手动出战
* @param param
* @return
*/
PdaResponse manualOutbound(JSONObject param);
}

View File

@@ -15,6 +15,8 @@ import org.nl.common.utils.CodeUtil;
import org.nl.common.utils.IdUtil;
import org.nl.common.utils.MapOf;
import org.nl.common.utils.SecurityUtils;
import org.nl.system.service.param.ISysParamService;
import org.nl.system.service.param.dao.Param;
import org.nl.wms.basedata_manage.enums.BaseDataEnum;
import org.nl.wms.basedata_manage.service.*;
import org.nl.wms.basedata_manage.service.dao.MdPbStoragevehicleext;
@@ -24,6 +26,8 @@ import org.nl.wms.pda.general_management.service.PdaBuildParamService;
import org.nl.wms.pda.general_management.service.PdaWarehouseService;
import org.nl.wms.pda.general_management.service.PdaProductionService;
import org.nl.wms.pda.util.PdaResponse;
import org.nl.wms.pda.util.ThresholdChecker;
import org.nl.wms.sch_manage.enums.TaskStatus;
import org.nl.wms.sch_manage.service.ISchBasePointService;
import org.nl.wms.sch_manage.service.ISchBaseTaskService;
import org.nl.wms.sch_manage.service.dao.SchBasePoint;
@@ -103,6 +107,8 @@ public class PdaProductionServiceImpl implements PdaProductionService {
private IOStorInvDisMapper ioStorInvDisMapper;
@Resource
private IOStorInvDtlMapper ioStorInvDtlMapper;
@Resource
private ISysParamService paramService;
@Override
public PdaResponse getGroupInfo(JSONObject param) {
// search;
@@ -125,6 +131,12 @@ public class PdaProductionServiceImpl implements PdaProductionService {
return PdaResponse.requestParamOk(res);
}
/**
* 称量、粉碎、制粒、配液、缠膜叫料:
* 选择物料、输入批号,选择库区,查询物料库存,选择一个托盘物料,扫/选点位,点确认,进行叫料;
* @param param
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public PdaResponse confirmCallMaterial(JSONObject param) {
@@ -473,7 +485,7 @@ public class PdaProductionServiceImpl implements PdaProductionService {
* 1、称量、粉碎下料组盘后扫点位/载具点确认,系统分配物料存放室或批料室空货位入库;
* 2、压片下料组盘后扫点位、载具点确认系统分配中间站空货位入库
* 3、包衣下料组盘后扫点位点呼叫AGV系统呼叫AGV来取货扫点位、载具点确认系统分配中间站空货位入库
* 4、码垛完成后扫点位、载具点确认系统分配缓存点位搬运暂存
* 4、× 码垛完成后,扫点位、载具点确认,系统分配缓存点位搬运暂存;
* 5、缠膜完成后扫点位、载具点确认系统分配缓存点位搬运暂存
* @param param
* @return
@@ -494,7 +506,7 @@ public class PdaProductionServiceImpl implements PdaProductionService {
productionInStorage(param, point);
return PdaResponse.requestOk();
}
// 压片下料
// 压片/包衣下料
AbstractTask task = taskFactory.getTask(IOSEnum.DOWN_CONFIG_CODE.code(point.getRegion_code()));
task.create(param);
return PdaResponse.requestOk();
@@ -664,6 +676,125 @@ public class PdaProductionServiceImpl implements PdaProductionService {
lock.unlock();
}
}
return null;
return PdaResponse.requestOk();
}
@Override
public PdaResponse getTaskBucketGroupInfo(JSONObject param) {
JSONObject res = new JSONObject();
// vehicle_code
List<JSONObject> infoByBucket = groupbucketService.getBucketInfoByBucket(param.getString("vehicle_code"));
if (infoByBucket.size() == 0) {
throw new BadRequestException("料桶信息不存在!");
}
JSONObject bucketInfo = infoByBucket.get(0);
// 判断是否存在任务
SchBaseTask task = taskService.getOne(new LambdaQueryWrapper<SchBaseTask>()
.eq(SchBaseTask::getVehicle_code, param.getString("vehicle_code"))
.eq(SchBaseTask::getTask_status, TaskStatus.EXECUTING.getCode())
.eq(SchBaseTask::getIs_delete, false));
if (ObjectUtil.isNotEmpty(task)) {
res.put("current_point", task.getPoint_code2());
// ext 有出站站点
bucketInfo.put("task_id", task.getTask_id());
JSONObject parseObject = JSONObject.parseObject(task.getRequest_param());
if (ObjectUtil.isNotEmpty(parseObject.get("ext"))) {
JSONObject ext = parseObject.getJSONObject("ext");
bucketInfo.put("station", ext.getString("target"));
}
}
// todo:获取ACS的重量
res.put("total", bucketInfo.getBigDecimal("qty"));
res.put("row", bucketInfo);
return PdaResponse.requestParamOk(res);
}
@Override
@Transactional(rollbackFor = Exception.class)
public PdaResponse manualInbound(JSONObject param) {
assertNotBlankJson(param, "当前点位不能为空!", "row", "current_point", "vehicle_code");
JSONObject row = param.getJSONObject("row");
String currentPoint = param.getString("current_point");
String vehicleCode = param.getString("vehicle_code");
// ACS 获取的重量
String total = param.getString("total");
String taskId = row.getString("task_id");
if (ObjectUtil.isNotEmpty(taskId)) {
// 有任务直接任务完成
SchBaseTask baseTask = taskService.getById(taskId);
AbstractTask task = taskFactory.getTask(baseTask.getConfig_code());
task.updateTaskStatus(baseTask.getTask_code(), TaskStatus.FINISHED);
return PdaResponse.requestOk();
}
SchBasePoint startPoint = pointService.getById(currentPoint);
// 没任务,证明是人工放上去录进去的
groupbucketService.upDateWeight(total, vehicleCode);
JSONObject param2 = new JSONObject();
// 创建入库任务
List<JSONObject> infos = groupbucketService.getBucketInfoByBucket(vehicleCode);
Sectattr sectattr = sectattrService.findByCode(startPoint.getIn_sect(), false);
param2.put("bill_type", IOSEnum.IN_BILL_TYPE.code("中间站入库"));
param2.put("rows", infos);
// 1 创建入库单、明细、分配明细
Map<String, Object> invObj = defaultPdaBuildParam.doBuildInvObj(param2, startPoint, sectattr);
String invId = rawAssistIStorService.insertDtl(invObj);
// 2 调用分配
Map<String, Object> divObj = defaultPdaBuildParam.buildDivStructData(param2, sectattr, invId, true);
rawAssistIStorService.divStruct(divObj);
// 3 创建任务
Map<String, Object> jsonMst = defaultPdaBuildParam.buildTaskData(startPoint, invId);
rawAssistIStorService.divPoint(jsonMst);
return PdaResponse.requestOk();
}
@Override
public PdaResponse manualOutbound(JSONObject param) {
assertNotBlankJson(param, "当前点位不能为空!", "row", "current_point", "vehicle_code");
JSONObject row = param.getJSONObject("row");
String currentPoint = param.getString("current_point");
String vehicleCode = param.getString("vehicle_code");
// ACS 获取的重量
BigDecimal currentTotal = param.getBigDecimal("total");
BigDecimal originalQty = row.getBigDecimal("qty");
Param threshold = paramService.findByCode("weighing_threshold");
// 对比与组盘的重量是否大于阈值
ThresholdChecker.ThresholdCheckResult result = ThresholdChecker.checkThresholdWithDetails(
currentTotal,
originalQty,
threshold.getValue()
);
if (result.isExceeded()) {
throw new BadRequestException(result.toString());
}
// 判断是否有任务
String taskId = row.getString("task_id");
if (ObjectUtil.isNotEmpty(taskId)) {
// 有任务直接任务完成
SchBaseTask baseTask = taskService.getById(taskId);
AbstractTask task = taskFactory.getTask(baseTask.getConfig_code());
task.updateTaskStatus(baseTask.getTask_code(), TaskStatus.FINISHED);
return PdaResponse.requestOk();
}
if (ObjectUtil.isEmpty(row.getString("station"))) {
throw new BadRequestException("产线目标站为空");
}
List<JSONObject> infoByBucket = groupbucketService.getBucketInfoByBucket(vehicleCode);
if (infoByBucket.size() == 0) {
throw new BadRequestException("桶物料信息不存在!请检查组桶!");
}
JSONObject bucket = infoByBucket.get(0);
JSONObject ext = new JSONObject();
// todo: 先固定包衣,后续改
ext.put("config_code", "CoatingUpTask");
ext.put("vehicle_code", vehicleCode);
ext.put("material_qty", currentTotal);
ext.put("material_name", bucket.getString("material_name"));
ext.put("material_id", bucket.getString("material_id"));
ext.put("group_id", bucket.getString("group_id"));
ext.put("point_code", currentPoint);
ext.put("target", row.getString("station"));
AbstractTask coatingUpTask = taskFactory.getTask("CoatingUpTask");
coatingUpTask.create(ext);
return PdaResponse.requestOk();
}
}

View File

@@ -0,0 +1,165 @@
package org.nl.wms.pda.util;
import java.math.BigDecimal;
import java.math.RoundingMode;
/**
*
* @author: lyd
* @date: 2026/1/12
*/
public class ThresholdChecker {
/**
* 判断当前值相比原始值是否超过设置阈值的±大小
* @param currentTotal 当前重量/值
* @param originalQty 原始重量/值
* @param threshold 阈值,支持百分比(如"10%")或绝对值(如"10"
* @return true-超过阈值范围false-在阈值范围内
*/
public static boolean isExceedThreshold(BigDecimal currentTotal,
BigDecimal originalQty,
String threshold) {
if (currentTotal == null || originalQty == null || threshold == null) {
throw new IllegalArgumentException("参数不能为空");
}
// 计算实际偏差(绝对值)
BigDecimal deviation = currentTotal.subtract(originalQty).abs();
// 解析阈值
BigDecimal thresholdValue = parseThreshold(threshold, originalQty);
// 判断是否超过阈值
return deviation.compareTo(thresholdValue) > 0;
}
/**
* 解析阈值字符串
* @param threshold 阈值字符串,支持百分比或绝对值
* @param baseValue 用于计算百分比的基础值
* @return 解析后的阈值数值
*/
private static BigDecimal parseThreshold(String threshold, BigDecimal baseValue) {
if (threshold == null || threshold.trim().isEmpty()) {
throw new IllegalArgumentException("阈值不能为空");
}
String trimmedThreshold = threshold.trim();
// 判断是否为百分比形式
if (trimmedThreshold.endsWith("%")) {
try {
// 去掉百分号,转换为小数
String percentStr = trimmedThreshold.substring(0, trimmedThreshold.length() - 1);
BigDecimal percent = new BigDecimal(percentStr);
// 计算百分比对应的实际值
return baseValue.multiply(percent)
.divide(BigDecimal.valueOf(100), 10, RoundingMode.HALF_UP);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("无效的百分比阈值格式: " + threshold, e);
}
} else {
try {
// 直接解析为绝对值
return new BigDecimal(trimmedThreshold);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("无效的阈值格式: " + threshold, e);
}
}
}
/**
* 获取当前值相对于原始值的偏差比例(带正负号)
* @param currentTotal 当前值
* @param originalQty 原始值
* @return 偏差比例(百分比,正数表示增加,负数表示减少)
*/
public static BigDecimal getDeviationPercentage(BigDecimal currentTotal,
BigDecimal originalQty) {
if (currentTotal == null || originalQty == null) {
throw new IllegalArgumentException("参数不能为空");
}
if (originalQty.compareTo(BigDecimal.ZERO) == 0) {
throw new ArithmeticException("原始值不能为0");
}
// 计算偏差比例:(当前值 - 原始值) / 原始值 * 100%
return currentTotal.subtract(originalQty)
.multiply(BigDecimal.valueOf(100))
.divide(originalQty, 2, RoundingMode.HALF_UP);
}
/**
* 判断当前值是否超过阈值,并返回详细信息
* @param currentTotal 当前值
* @param originalQty 原始值
* @param threshold 阈值
* @return 检查结果对象
*/
public static ThresholdCheckResult checkThresholdWithDetails(BigDecimal currentTotal,
BigDecimal originalQty,
String threshold) {
boolean exceeded = isExceedThreshold(currentTotal, originalQty, threshold);
BigDecimal deviation = currentTotal.subtract(originalQty);
BigDecimal deviationPercentage = getDeviationPercentage(currentTotal, originalQty);
BigDecimal thresholdValue = parseThreshold(threshold, originalQty);
return new ThresholdCheckResult(
exceeded,
currentTotal,
originalQty,
deviation,
deviationPercentage,
threshold,
thresholdValue
);
}
/**
* 阈值检查结果类
*/
public static class ThresholdCheckResult {
private final boolean exceeded;
private final BigDecimal currentValue;
private final BigDecimal originalValue;
private final BigDecimal deviation;
private final BigDecimal deviationPercentage;
private final String thresholdExpression;
private final BigDecimal thresholdValue;
public ThresholdCheckResult(boolean exceeded,
BigDecimal currentValue,
BigDecimal originalValue,
BigDecimal deviation,
BigDecimal deviationPercentage,
String thresholdExpression,
BigDecimal thresholdValue) {
this.exceeded = exceeded;
this.currentValue = currentValue;
this.originalValue = originalValue;
this.deviation = deviation;
this.deviationPercentage = deviationPercentage;
this.thresholdExpression = thresholdExpression;
this.thresholdValue = thresholdValue;
}
// Getter方法
public boolean isExceeded() { return exceeded; }
public BigDecimal getCurrentValue() { return currentValue; }
public BigDecimal getOriginalValue() { return originalValue; }
public BigDecimal getDeviation() { return deviation; }
public BigDecimal getDeviationPercentage() { return deviationPercentage; }
public String getThresholdExpression() { return thresholdExpression; }
public BigDecimal getThresholdValue() { return thresholdValue; }
@Override
public String toString() {
return String.format("阈值检查结果: %s (当前值: %s, 原始值: %s, 偏差: %s [%s%%, 阈值: %s])",
exceeded ? "超过阈值" : "未超过阈值",
currentValue, originalValue, deviation, deviationPercentage, thresholdExpression);
}
}
}

View File

@@ -0,0 +1,54 @@
package org.nl.wms.sch_manage.controller;
import cn.dev33.satoken.annotation.SaIgnore;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.nl.wms.sch_manage.service.SecondaryPackagingService;
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 javax.annotation.Resource;
/**
*
* @author: lyd
* @date: 2026/1/10
*/
@Slf4j
@RestController
@RequestMapping("/api/test")
public class TestApiController {
@Resource
private SecondaryPackagingService secondaryPackagingService;
@PostMapping("/down")
@SaIgnore
public ResponseEntity<Object> query(@RequestBody JSONObject whereJson) {
secondaryPackagingService.palletizingDown(whereJson);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@PostMapping("/call")
@SaIgnore
public ResponseEntity<Object> query2(@RequestBody JSONObject whereJson) {
secondaryPackagingService.wrappingCall(whereJson);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@PostMapping("/down2")
@SaIgnore
public ResponseEntity<Object> query3(@RequestBody JSONObject whereJson) {
secondaryPackagingService.wrappingDown(whereJson);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@PostMapping("/call2")
@SaIgnore
public ResponseEntity<Object> query4(@RequestBody JSONObject whereJson) {
secondaryPackagingService.palletizingCallEmpty(whereJson);
return new ResponseEntity<>(HttpStatus.CREATED);
}
}

View File

@@ -141,4 +141,19 @@ public interface ISchBasePointService extends IService<SchBasePoint> {
List<SchBasePoint> getCanUsePointByRegion(String regionCode);
List<SchBasePoint> getByVehicleCode(String search);
/**
* 获取可用点位
* @param region
* @param type
* @return
*/
List<SchBasePoint> getNoTaskPointByRegionAndType(String region, String type, String pointStatus);
/**
* 获取可以直接上料的缠绕机
* @return
*/
List<SchBasePoint> getCRUsedDevice();
}

View File

@@ -79,4 +79,6 @@ public interface ISchBaseTaskService extends IService<SchBaseTask> {
List<SchBaseTask> getTaskConfigList(String config_code);
List<SchBaseTask> getTaskByQuery(LambdaQueryWrapper<SchBaseTask> lam);
Integer haveTaskAll(String deviceCode);
}

View File

@@ -0,0 +1,35 @@
package org.nl.wms.sch_manage.service;
import com.alibaba.fastjson.JSONObject;
/**
* 外包间服务类
* @author: lyd
* @date: 2026/1/9
*/
public interface SecondaryPackagingService {
/**
* 外包间码垛下料
* @param param
*/
void palletizingDown(JSONObject param);
/**
* 缠绕机叫料
* @param param
*/
void wrappingCall(JSONObject param);
/**
* 缠绕下料
* @param param
*/
void wrappingDown(JSONObject param);
/**
* 码垛缺空
* @param param
*/
void palletizingCallEmpty(JSONObject param);
}

View File

@@ -78,4 +78,8 @@ public interface SchBasePointMapper extends BaseMapper<SchBasePoint> {
* @return PdaResponse
*/
List<JSONObject> pdaQueryPointDtl(@Param("param") JSONObject whereJson);
List<SchBasePoint> getNoTaskPointByRegionAndType(String region, String type, String pointStatus);
List<SchBasePoint> getCRUsedDevice();
}

View File

@@ -171,4 +171,42 @@
</where>
</select>
<select id="getNoTaskPointByRegionAndType" resultType="org.nl.wms.sch_manage.service.dao.SchBasePoint">
SELECT *
FROM sch_base_point p
WHERE p.region_code = #{region}
AND p.point_type = #{type}
AND p.point_status = #{pointStatus}
AND p.is_used = TRUE
AND 0 = (SELECT COUNT(*)
FROM sch_base_task t
WHERE t.is_delete = '0'
AND (t.point_code1 = p.point_code OR
t.point_code2 = p.point_code OR t.point_code3 = p.point_code OR t.point_code4 = p.point_code)
AND '5' > t.task_status)
</select>
<select id="getCRUsedDevice" resultType="org.nl.wms.sch_manage.service.dao.SchBasePoint">
SELECT p.*
FROM sch_base_point p
WHERE p.point_type = '2'
AND p.point_status = '1'
AND p.is_used = TRUE
AND p.region_code = 'CRHCQ'
AND 0 = (SELECT COUNT(*)
FROM sch_base_task t
WHERE t.is_delete = FALSE
AND '5' > t.task_status
AND (
t.point_code1 = p.point_code
OR t.point_code2 = p.point_code
OR t.point_code3 = p.point_code
OR t.point_code4 = p.point_code
))
AND 0 = (SELECT COUNT(*)
FROM sch_base_point p
WHERE p.point_type = '1'
AND p.point_status = '2'
AND p.is_used = TRUE
AND p.region_code = 'CRHCQ')
</select>
</mapper>

View File

@@ -37,6 +37,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@@ -329,4 +330,14 @@ public class SchBasePointServiceImpl extends ServiceImpl<SchBasePointMapper, Sch
lam.eq(SchBasePoint::getVehicle_code, search);
return list(lam);
}
@Override
public List<SchBasePoint> getNoTaskPointByRegionAndType(String region, String type, String pointStatus) {
return this.baseMapper.getNoTaskPointByRegionAndType(region, type, pointStatus);
}
@Override
public List<SchBasePoint> getCRUsedDevice() {
return this.baseMapper.getCRUsedDevice();
}
}

View File

@@ -31,6 +31,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;
/**
@@ -177,4 +178,16 @@ public class SchBaseTaskServiceImpl extends ServiceImpl<SchBaseTaskMapper, SchBa
return list(lam);
}
@Override
public Integer haveTaskAll(String deviceCode) {
LambdaQueryWrapper<SchBaseTask> lam = new LambdaQueryWrapper<>();
lam.eq(SchBaseTask::getIs_delete, false)
.and(ll -> ll.eq(SchBaseTask::getPoint_code1, deviceCode).or()
.eq(SchBaseTask::getPoint_code2, deviceCode).or()
.eq(SchBaseTask::getPoint_code3, deviceCode).or()
.eq(SchBaseTask::getPoint_code4, deviceCode))
.lt(SchBaseTask::getTask_status, TaskStatus.FINISHED.getCode());
return this.count(lam);
}
}

View File

@@ -0,0 +1,130 @@
package org.nl.wms.sch_manage.service.impl;
import cn.hutool.core.date.DateUtil;
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.basedata_manage.service.IMdMeMaterialbaseService;
import org.nl.wms.basedata_manage.service.dao.MdMeMaterialbase;
import org.nl.wms.sch_manage.service.ISchBasePointService;
import org.nl.wms.sch_manage.service.ISchBaseTaskService;
import org.nl.wms.sch_manage.service.SecondaryPackagingService;
import org.nl.wms.sch_manage.service.dao.SchBasePoint;
import org.nl.wms.sch_manage.service.util.AbstractTask;
import org.nl.wms.sch_manage.service.util.TaskFactory;
import org.nl.wms.sch_manage.service.util.tasks.EmptyDiskConveyTask;
import org.nl.wms.sch_manage.service.util.tasks.EmptyDiskEnterTask;
import org.nl.wms.sch_manage.service.util.tasks.WrappingDownTask;
import org.nl.wms.sch_manage.service.util.tasks.WrappingUpTask;
import org.nl.wms.warehouse_management.service.IMdPbGroupplateService;
import org.nl.wms.warehouse_management.service.dao.GroupPlate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
/**
*
* @author: lyd
* @date: 2026/1/9
*/
@Service
public class SecondaryPackagingServiceImpl implements SecondaryPackagingService {
@Resource
private IMdPbGroupplateService groupplateService;
@Resource
private IMdMeMaterialbaseService materialbaseService;
@Resource
private TaskFactory taskFactory;
@Resource
private ISchBasePointService pointService;
@Resource
private ISchBaseTaskService taskService;
@Resource(name = "WrappingUpTask")
private WrappingUpTask wrappingUpTask;
@Resource(name = "WrappingDownTask")
private WrappingDownTask wrappingDownTask;
@Resource(name = "EmptyDiskConveyTask")
private EmptyDiskConveyTask emptyDiskConveyTask;
@Resource(name = "EmptyDiskEnterTask")
private EmptyDiskEnterTask emptyDiskEnterTask;
@Override
@Transactional(rollbackFor = Exception.class)
public void palletizingDown(JSONObject param) {
// device_code、material_code、qty、vehicle_seq、pcsn、cases
MdMeMaterialbase materialCode = materialbaseService.getByCode(param.getString("material_code"));
// 组盘
GroupPlate groupPlate = new GroupPlate();
groupPlate.setGroup_id(IdUtil.getStringId());
groupPlate.setVehicle_code( DateUtil.format(new Date(), "yyyyMMddss") + "-" + param.getString("vehicle_seq"));
groupPlate.setRemark(param.toJSONString());
groupPlate.setStatus("1");
groupPlate.setQty(param.getBigDecimal("qty"));
groupPlate.setPcsn(param.getString("pcsn"));
groupPlate.setMaterial_id(materialCode.getMaterial_id());
groupPlate.setCreate_id(SecurityUtils.getCurrentUserId());
groupPlate.setCreate_name(SecurityUtils.getCurrentNickName());
groupPlate.setCreate_time(DateUtil.now());
// ....待定
groupplateService.save(groupPlate);
// todo: 校验任务
param.put("config_code", "PalletizingDownTask");
param.put("group_id", groupPlate.getGroup_id());
param.put("material_id", materialCode.getMaterial_id());
param.put("material_qty", groupPlate.getQty());
param.put("vehicle_code", groupPlate.getVehicle_code());
AbstractTask palletizingDownTask = taskFactory.getTask("PalletizingDownTask");
palletizingDownTask.create(param);
}
@Override
public void wrappingCall(JSONObject param) {
// 校验任务
Integer num = taskService.haveTaskAll(param.getString("device_code"));
if (num > 0) {
throw new BadRequestException("该点位已存在任务!");
}
param.put("config_code", "WrappingUpTask");
wrappingUpTask.create(param);
}
@Override
public void wrappingDown(JSONObject param) {
// 校验任务
Integer num = taskService.haveTaskAll(param.getString("device_code"));
if (num > 0) {
throw new BadRequestException("该点位已存在任务!");
}
param.put("config_code", "WrappingDownTask");
wrappingDownTask.create(param);
}
@Override
public void palletizingCallEmpty(JSONObject param) {
// 空盘进入任务、空盘运输任务、
// 校验任务
Integer num = taskService.haveTaskAll(param.getString("device_code"));
if (num > 0) {
throw new BadRequestException("该点位已存在任务!");
}
// 获取缓存点有空托盘的位置
List<SchBasePoint> palletPoints = pointService.getNoTaskPointByRegionAndType("WBZQ", "2", "3");
if (palletPoints.size() == 0) {
// 创建空盘进入任务
param.put("config_code", "EmptyDiskEnterTask");
emptyDiskEnterTask.create(param);
return;
}
SchBasePoint point = palletPoints.get(0);
// 创建运输任务
param.put("point_code1", point.getPoint_code());
param.put("point_code2", param.getString("device_code"));
param.put("config_code", "EmptyDiskEnterTask");
emptyDiskConveyTask.create(param);
}
}

View File

@@ -1,25 +1,30 @@
package org.nl.wms.sch_manage.service.util.tasks;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.nl.common.exception.BadRequestException;
import org.nl.common.utils.CodeUtil;
import org.nl.common.utils.SecurityUtils;
import org.nl.config.IdUtil;
import org.nl.wms.basedata_manage.service.IMdPdGroupbucketService;
import org.nl.wms.basedata_manage.service.dao.MdPdGroupbucket;
import org.nl.wms.sch_manage.enums.TaskEnum;
import org.nl.wms.sch_manage.enums.TaskStatus;
import org.nl.wms.sch_manage.service.ISchBaseTaskService;
import org.nl.wms.sch_manage.service.dao.SchBasePoint;
import org.nl.wms.sch_manage.service.dao.SchBaseTask;
import org.nl.wms.sch_manage.service.util.ACSTaskTypeEnum;
import org.nl.wms.sch_manage.service.util.AbstractTask;
import org.nl.wms.sch_manage.service.util.AcsTaskDto;
import org.nl.wms.warehouse_management.enums.IOSConstant;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
/**
* 包衣上料任务
* 包衣/内包装上料任务
* @author: lyd
* @date: 2026/1/9
*/
@@ -29,6 +34,9 @@ public class CoatingUpTask extends AbstractTask {
@Resource
private ISchBaseTaskService taskService;
@Resource
private IMdPdGroupbucketService groupbucketService;
@Override
public String create(JSONObject json) {
SchBaseTask task = new SchBaseTask();
@@ -56,24 +64,91 @@ public class CoatingUpTask extends AbstractTask {
return task.getTask_id();
}
@Override
public AcsTaskDto sendAcsParam(String taskId) {
return null;
SchBaseTask taskDao = taskService.getById(taskId);
// 组织下发给acs的数据
AcsTaskDto acsTaskDto = new AcsTaskDto();
acsTaskDto.setExt_task_id(taskDao.getTask_id());
acsTaskDto.setTask_code(taskDao.getTask_code());
acsTaskDto.setStart_device_code(taskDao.getPoint_code1());
acsTaskDto.setNext_device_code(taskDao.getPoint_code2());
acsTaskDto.setVehicle_code(taskDao.getVehicle_code());
acsTaskDto.setVehicle_type(IOSConstant.ONE);
acsTaskDto.setIs_wait(IOSConstant.ZERO);
acsTaskDto.setTask_type(ACSTaskTypeEnum.AGV_TASK.getCode());
acsTaskDto.setPriority(IOSConstant.ONE);
acsTaskDto.setAgv_system_type(IOSConstant.THREE);
acsTaskDto.setIs_get_pause(IOSConstant.ZERO);
acsTaskDto.setIs_put_pause(IOSConstant.ZERO);
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("执行中");
taskService.updateById(taskObj);
}
if (status.equals(TaskStatus.FINISHED)) {
this.finishTask(taskObj);
}
if (status.equals(TaskStatus.CANCELED)) {
this.cancelTask(taskObj);
}
}
public void cancelTask(SchBaseTask taskObj) {
// 更新任务状态
taskObj.setTask_status(TaskStatus.CANCELED.getCode());
taskObj.setRemark("已取消");
taskService.updateById(taskObj);
}
@Transactional(rollbackFor = Exception.class)
public void finishTask(SchBaseTask taskObj) {
// 任务完成
taskObj.setTask_status(TaskStatus.FINISHED.getCode());
taskObj.setRemark("已完成");
taskService.updateById(taskObj);
// 删除组盘信息
groupbucketService.remove(
new QueryWrapper<MdPdGroupbucket>().lambda()
.eq(MdPdGroupbucket::getBucket_code, taskObj.getVehicle_code())
);
}
@Override
public void forceFinish(String task_code) {
SchBaseTask taskObj = taskService.getByCode(task_code);
if (ObjectUtil.isEmpty(taskObj)) {
throw new BadRequestException("该任务不存在");
}
this.finishTask(taskObj);
}
@Override
public void cancel(String task_code) {
SchBaseTask taskObj = taskService.getByCode(task_code);
if (ObjectUtil.isEmpty(taskObj)) {
throw new BadRequestException("该任务不存在");
}
this.cancelTask(taskObj);
}
@Override

View File

@@ -0,0 +1,188 @@
package org.nl.wms.sch_manage.service.util.tasks;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import lombok.extern.slf4j.Slf4j;
import org.nl.common.exception.BadRequestException;
import org.nl.common.utils.CodeUtil;
import org.nl.common.utils.SecurityUtils;
import org.nl.config.IdUtil;
import org.nl.wms.sch_manage.enums.TaskEnum;
import org.nl.wms.sch_manage.enums.TaskStatus;
import org.nl.wms.sch_manage.service.ISchBasePointService;
import org.nl.wms.sch_manage.service.ISchBaseTaskService;
import org.nl.wms.sch_manage.service.dao.SchBasePoint;
import org.nl.wms.sch_manage.service.dao.SchBaseTask;
import org.nl.wms.sch_manage.service.util.ACSTaskTypeEnum;
import org.nl.wms.sch_manage.service.util.AbstractTask;
import org.nl.wms.sch_manage.service.util.AcsTaskDto;
import org.nl.wms.warehouse_management.enums.IOSConstant;
import org.nl.wms.warehouse_management.enums.IOSEnum;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
/**
* 空盘运输任务
* @author: lyd
* @date: 2026/1/12
*/
@Slf4j
@Component("EmptyDiskConveyTask")
public class EmptyDiskConveyTask extends AbstractTask {
@Resource
private ISchBaseTaskService taskService;
@Resource
private ISchBasePointService pointService;
@Resource(name = "EmptyDiskEnterTask")
private EmptyDiskEnterTask emptyDiskEnterTask;
@Override
public String create(JSONObject json) {
SchBaseTask task = new SchBaseTask();
task.setTask_id(IdUtil.getStringId());
task.setTask_code(CodeUtil.getNewCode("TASK_CODE"));
task.setTask_status(TaskStatus.CREATED.getCode());
task.setConfig_code(EmptyDiskConveyTask.class.getSimpleName());
task.setPoint_code1(json.getString("point_code1"));
task.setPoint_code2(json.getString("point_code2"));
task.setVehicle_code(json.getString("vehicle_code"));
task.setMaterial_id(json.getString("material_id"));
task.setMaterial_qty(json.getBigDecimal("material_qty"));
task.setGroup_id(json.getString("group_id"));
task.setRequest_param(json.toString());
task.setPriority(json.getString("Priority"));
task.setTask_type(TaskEnum.TASK_TYPE.code("料箱"));
task.setIs_wait(json.getString("is_wait"));
task.setCreate_id(SecurityUtils.getCurrentUserId());
task.setCreate_name(SecurityUtils.getCurrentNickName());
task.setCreate_time(DateUtil.now());
taskService.save(task);
// 下发任务
// this.sendTaskOne(task.getTask_id());
return task.getTask_id();
}
@Override
public AcsTaskDto sendAcsParam(String taskId) {
SchBaseTask taskDao = taskService.getById(taskId);
// 组织下发给acs的数据
AcsTaskDto acsTaskDto = new AcsTaskDto();
acsTaskDto.setExt_task_id(taskDao.getTask_id());
acsTaskDto.setTask_code(taskDao.getTask_code());
acsTaskDto.setStart_device_code(taskDao.getPoint_code1());
acsTaskDto.setNext_device_code(taskDao.getPoint_code2());
acsTaskDto.setVehicle_code(taskDao.getVehicle_code());
acsTaskDto.setVehicle_type(IOSConstant.ONE);
acsTaskDto.setIs_wait(IOSConstant.ZERO);
acsTaskDto.setTask_type(ACSTaskTypeEnum.AGV_TASK.getCode());
acsTaskDto.setPriority(IOSConstant.ONE);
acsTaskDto.setAgv_system_type(IOSConstant.THREE);
acsTaskDto.setIs_get_pause(IOSConstant.ZERO);
acsTaskDto.setIs_put_pause(IOSConstant.ZERO);
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("执行中");
taskService.updateById(taskObj);
}
if (status.equals(TaskStatus.FINISHED)) {
this.finishTask(taskObj);
}
if (status.equals(TaskStatus.CANCELED)) {
this.cancelTask(taskObj);
}
}
public void cancelTask(SchBaseTask taskObj) {
// 更新任务状态
taskObj.setTask_status(TaskStatus.CANCELED.getCode());
taskObj.setRemark("已取消");
taskService.updateById(taskObj);
}
@Transactional(rollbackFor = Exception.class)
public void finishTask(SchBaseTask taskObj) {
// 任务完成
taskObj.setTask_status(TaskStatus.FINISHED.getCode());
taskObj.setRemark("已完成");
taskService.updateById(taskObj);
// 更新
pointService.update(
new UpdateWrapper<SchBasePoint>().lambda()
.set(SchBasePoint::getVehicle_code, "")
.set(SchBasePoint::getPoint_status, IOSEnum.POINT_STATUS.code("空位"))
.eq(SchBasePoint::getPoint_code, taskObj.getPoint_code1())
.set(SchBasePoint::getIng_task_code, "")
);
pointService.update(
new UpdateWrapper<SchBasePoint>().lambda()
.set(SchBasePoint::getVehicle_code, "")
.set(SchBasePoint::getPoint_status, IOSEnum.POINT_STATUS.code("空载具"))
.eq(SchBasePoint::getPoint_code, taskObj.getPoint_code2())
.set(SchBasePoint::getIng_task_code, "")
);
// 判断是否需要呼叫空盘
List<SchBasePoint> palletPoints = pointService.getNoTaskPointByRegionAndType("WBZQ", "2", "1");
for (SchBasePoint palletPoint : palletPoints) {
// 创建进入任务。
try {
JSONObject param = new JSONObject();
param.put("device_code", palletPoint.getPoint_code());
param.put("config_code", "EmptyDiskEnterTask");
emptyDiskEnterTask.create(param);
} catch (Exception e) {
log.warn(e.getMessage());
}
}
}
@Override
public void forceFinish(String task_code) {
SchBaseTask taskObj = taskService.getByCode(task_code);
if (ObjectUtil.isEmpty(taskObj)) {
throw new BadRequestException("该任务不存在");
}
this.finishTask(taskObj);
}
@Override
public void cancel(String task_code) {
SchBaseTask taskObj = taskService.getByCode(task_code);
if (ObjectUtil.isEmpty(taskObj)) {
throw new BadRequestException("该任务不存在");
}
if (!TaskStatus.CREATE.getCode().equals(taskObj.getTask_status())) {
throw new BadRequestException("任务状态必须为生成才能取消任务");
}
this.cancelTask(taskObj);
}
@Override
public void taskConfirm(String task_code) {
}
}

View File

@@ -0,0 +1,189 @@
package org.nl.wms.sch_manage.service.util.tasks;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.nl.common.exception.BadRequestException;
import org.nl.common.utils.CodeUtil;
import org.nl.common.utils.SecurityUtils;
import org.nl.config.IdUtil;
import org.nl.wms.sch_manage.enums.TaskEnum;
import org.nl.wms.sch_manage.enums.TaskStatus;
import org.nl.wms.sch_manage.service.ISchBasePointService;
import org.nl.wms.sch_manage.service.ISchBaseTaskService;
import org.nl.wms.sch_manage.service.dao.SchBasePoint;
import org.nl.wms.sch_manage.service.dao.SchBaseTask;
import org.nl.wms.sch_manage.service.util.ACSTaskTypeEnum;
import org.nl.wms.sch_manage.service.util.AbstractTask;
import org.nl.wms.sch_manage.service.util.AcsTaskDto;
import org.nl.wms.sch_manage.service.util.TaskFactory;
import org.nl.wms.warehouse_management.enums.IOSConstant;
import org.nl.wms.warehouse_management.enums.IOSEnum;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
/**
* 空盘进入任务
* @author: lyd
* @date: 2026/1/12
*/
@Component("EmptyDiskEnterTask")
public class EmptyDiskEnterTask extends AbstractTask {
@Resource
private ISchBaseTaskService taskService;
@Resource
private ISchBasePointService pointService;
@Resource
private TaskFactory taskFactory;
@Override
public String create(JSONObject json) {
// 获取中转位
List<SchBasePoint> transferStation = pointService.getNoTaskPointByRegionAndType("AGVZJZ01", "1", "1");
if (transferStation.size() == 0) {
throw new BadRequestException("找不到可用的中转位!");
}
SchBasePoint point = transferStation.get(0);
SchBaseTask task = new SchBaseTask();
task.setTask_id(IdUtil.getStringId());
task.setTask_code(CodeUtil.getNewCode("TASK_CODE"));
task.setTask_status(TaskStatus.CREATED.getCode());
task.setConfig_code(EmptyDiskEnterTask.class.getSimpleName());
task.setPoint_code1("ZBJ01");
task.setPoint_code2(point.getPoint_code());
task.setPoint_code3(json.getString("device_code"));
task.setVehicle_code(json.getString("vehicle_code"));
task.setMaterial_id(json.getString("material_id"));
task.setMaterial_qty(json.getBigDecimal("material_qty"));
task.setGroup_id(json.getString("group_id"));
task.setRequest_param(json.toString());
task.setPriority(json.getString("Priority"));
task.setTask_type(TaskEnum.TASK_TYPE.code("料箱"));
task.setIs_wait(json.getString("is_wait"));
task.setCreate_id(SecurityUtils.getCurrentUserId());
task.setCreate_name(SecurityUtils.getCurrentNickName());
task.setCreate_time(DateUtil.now());
taskService.save(task);
// 下发任务
// this.sendTaskOne(task.getTask_id());
return task.getTask_id();
}
@Override
public AcsTaskDto sendAcsParam(String taskId) {
SchBaseTask taskDao = taskService.getById(taskId);
// 组织下发给acs的数据
AcsTaskDto acsTaskDto = new AcsTaskDto();
acsTaskDto.setExt_task_id(taskDao.getTask_id());
acsTaskDto.setTask_code(taskDao.getTask_code());
acsTaskDto.setStart_device_code(taskDao.getPoint_code1());
acsTaskDto.setNext_device_code(taskDao.getPoint_code2());
acsTaskDto.setVehicle_code(taskDao.getVehicle_code());
acsTaskDto.setVehicle_type(IOSConstant.ONE);
acsTaskDto.setIs_wait(IOSConstant.ZERO);
acsTaskDto.setTask_type(ACSTaskTypeEnum.AGV_TASK.getCode());
acsTaskDto.setPriority(IOSConstant.ONE);
acsTaskDto.setAgv_system_type(IOSConstant.THREE);
acsTaskDto.setIs_get_pause(IOSConstant.ZERO);
acsTaskDto.setIs_put_pause(IOSConstant.ZERO);
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("执行中");
taskService.updateById(taskObj);
}
if (status.equals(TaskStatus.FINISHED)) {
this.finishTask(taskObj);
}
if (status.equals(TaskStatus.CANCELED)) {
this.cancelTask(taskObj);
}
}
public void cancelTask(SchBaseTask taskObj) {
// 更新任务状态
taskObj.setTask_status(TaskStatus.CANCELED.getCode());
taskObj.setRemark("已取消");
taskService.updateById(taskObj);
}
@Transactional(rollbackFor = Exception.class)
public void finishTask(SchBaseTask taskObj) {
// 任务完成
taskObj.setTask_status(TaskStatus.FINISHED.getCode());
taskObj.setRemark("已完成");
taskService.updateById(taskObj);
// 更新
pointService.update(
new UpdateWrapper<SchBasePoint>().lambda()
.set(SchBasePoint::getVehicle_code, "")
.set(SchBasePoint::getPoint_status, IOSEnum.POINT_STATUS.code("空位"))
.eq(SchBasePoint::getPoint_code, taskObj.getPoint_code1())
.set(SchBasePoint::getIng_task_code, "")
);
// 更新
pointService.update(
new UpdateWrapper<SchBasePoint>().lambda()
.set(SchBasePoint::getVehicle_code, taskObj.getVehicle_code())
.set(SchBasePoint::getPoint_status, IOSEnum.POINT_STATUS.code("空载具"))
.eq(SchBasePoint::getPoint_code, taskObj.getPoint_code2())
.set(SchBasePoint::getIng_task_code, "")
);
// 创建输送任务
AbstractTask task = taskFactory.getTask("EmptyDiskConveyTask");
JSONObject parm = new JSONObject();
parm.put("config_code", "EmptyDiskConveyTask");
parm.put("point_code1", taskObj.getPoint_code2());
parm.put("point_code2", taskObj.getPoint_code3());
task.create(parm);
}
@Override
public void forceFinish(String task_code) {
SchBaseTask taskObj = taskService.getByCode(task_code);
if (ObjectUtil.isEmpty(taskObj)) {
throw new BadRequestException("该任务不存在");
}
this.finishTask(taskObj);
}
@Override
public void cancel(String task_code) {
SchBaseTask taskObj = taskService.getByCode(task_code);
if (ObjectUtil.isEmpty(taskObj)) {
throw new BadRequestException("该任务不存在");
}
if (!TaskStatus.CREATE.getCode().equals(taskObj.getTask_status())) {
throw new BadRequestException("任务状态必须为生成才能取消任务");
}
this.cancelTask(taskObj);
}
@Override
public void taskConfirm(String task_code) {
}
}

View File

@@ -0,0 +1,175 @@
package org.nl.wms.sch_manage.service.util.tasks;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.nl.common.exception.BadRequestException;
import org.nl.common.utils.CodeUtil;
import org.nl.common.utils.SecurityUtils;
import org.nl.config.IdUtil;
import org.nl.wms.basedata_manage.service.dao.Structattr;
import org.nl.wms.sch_manage.enums.TaskEnum;
import org.nl.wms.sch_manage.enums.TaskStatus;
import org.nl.wms.sch_manage.service.ISchBasePointService;
import org.nl.wms.sch_manage.service.ISchBaseTaskService;
import org.nl.wms.sch_manage.service.dao.SchBasePoint;
import org.nl.wms.sch_manage.service.dao.SchBaseTask;
import org.nl.wms.sch_manage.service.util.ACSTaskTypeEnum;
import org.nl.wms.sch_manage.service.util.AbstractTask;
import org.nl.wms.sch_manage.service.util.AcsTaskDto;
import org.nl.wms.sch_manage.service.util.PointUtils;
import org.nl.wms.warehouse_management.enums.IOSConstant;
import org.nl.wms.warehouse_management.enums.IOSEnum;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
/**
* 码垛追加任务
* @author: lyd
* @date: 2026/1/12
*/
@Component("PalletizingAddTask")
public class PalletizingAddTask extends AbstractTask {
@Resource
private ISchBaseTaskService taskService;
@Resource
private ISchBasePointService pointService;
@Override
public String create(JSONObject json) {
SchBaseTask task = new SchBaseTask();
task.setTask_id(IdUtil.getStringId());
task.setTask_code(CodeUtil.getNewCode("TASK_CODE"));
task.setTask_status(TaskStatus.CREATED.getCode());
task.setConfig_code(PalletizingAddTask.class.getSimpleName());
task.setPoint_code1(json.getString("point_code1"));
task.setPoint_code2(json.getString("point_code2"));
task.setVehicle_code(json.getString("vehicle_code"));
task.setMaterial_id(json.getString("material_id"));
task.setMaterial_qty(json.getBigDecimal("material_qty"));
task.setGroup_id(json.getString("group_id"));
task.setRequest_param(json.toString());
task.setPriority(json.getString("Priority"));
task.setTask_type(TaskEnum.TASK_TYPE.code("料箱"));
task.setIs_wait(json.getString("is_wait"));
task.setCreate_id(SecurityUtils.getCurrentUserId());
task.setCreate_name(SecurityUtils.getCurrentNickName());
task.setCreate_time(DateUtil.now());
taskService.save(task);
// 下发任务
// this.sendTaskOne(task.getTask_id());
return task.getTask_id();
}
@Override
public AcsTaskDto sendAcsParam(String taskId) {
SchBaseTask taskDao = taskService.getById(taskId);
// 组织下发给acs的数据
AcsTaskDto acsTaskDto = new AcsTaskDto();
acsTaskDto.setExt_task_id(taskDao.getTask_id());
acsTaskDto.setTask_code(taskDao.getTask_code());
acsTaskDto.setStart_device_code(taskDao.getPoint_code1());
acsTaskDto.setNext_device_code(taskDao.getPoint_code2());
acsTaskDto.setVehicle_code(taskDao.getVehicle_code());
acsTaskDto.setVehicle_type(IOSConstant.ONE);
acsTaskDto.setIs_wait(IOSConstant.ZERO);
acsTaskDto.setTask_type(ACSTaskTypeEnum.AGV_TASK.getCode());
acsTaskDto.setPriority(IOSConstant.ONE);
acsTaskDto.setAgv_system_type(IOSConstant.THREE);
acsTaskDto.setIs_get_pause(IOSConstant.ZERO);
acsTaskDto.setIs_put_pause(IOSConstant.ZERO);
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("执行中");
taskService.updateById(taskObj);
}
if (status.equals(TaskStatus.FINISHED)) {
this.finishTask(taskObj);
}
if (status.equals(TaskStatus.CANCELED)) {
this.cancelTask(taskObj);
}
}
public void cancelTask(SchBaseTask taskObj) {
// 更新任务状态
taskObj.setTask_status(TaskStatus.CANCELED.getCode());
taskObj.setRemark("已取消");
taskService.updateById(taskObj);
}
@Transactional(rollbackFor = Exception.class)
public void finishTask(SchBaseTask taskObj) {
// 任务完成
taskObj.setTask_status(TaskStatus.FINISHED.getCode());
taskObj.setRemark("已完成");
taskService.updateById(taskObj);
// 更新
pointService.update(
new UpdateWrapper<SchBasePoint>().lambda()
.set(SchBasePoint::getVehicle_code, "")
.set(SchBasePoint::getPoint_status, IOSEnum.POINT_STATUS.code("空位"))
.eq(SchBasePoint::getPoint_code, taskObj.getPoint_code1())
.set(SchBasePoint::getIng_task_code, "")
);
// 更新
pointService.update(
new UpdateWrapper<SchBasePoint>().lambda()
.set(SchBasePoint::getVehicle_code, taskObj.getVehicle_code())
.set(SchBasePoint::getPoint_status, IOSEnum.POINT_STATUS.code("有箱有料"))
.eq(SchBasePoint::getPoint_code, taskObj.getPoint_code2())
.set(SchBasePoint::getIng_task_code, "")
);
}
@Override
public void forceFinish(String task_code) {
SchBaseTask taskObj = taskService.getByCode(task_code);
if (ObjectUtil.isEmpty(taskObj)) {
throw new BadRequestException("该任务不存在");
}
this.finishTask(taskObj);
}
@Override
public void cancel(String task_code) {
SchBaseTask taskObj = taskService.getByCode(task_code);
if (ObjectUtil.isEmpty(taskObj)) {
throw new BadRequestException("该任务不存在");
}
if (!TaskStatus.CREATE.getCode().equals(taskObj.getTask_status())) {
throw new BadRequestException("任务状态必须为生成才能取消任务");
}
this.cancelTask(taskObj);
}
@Override
public void taskConfirm(String task_code) {
}
}

View File

@@ -0,0 +1,190 @@
package org.nl.wms.sch_manage.service.util.tasks;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.nl.common.exception.BadRequestException;
import org.nl.common.utils.CodeUtil;
import org.nl.common.utils.SecurityUtils;
import org.nl.config.IdUtil;
import org.nl.wms.basedata_manage.service.dao.Sectattr;
import org.nl.wms.sch_manage.enums.TaskEnum;
import org.nl.wms.sch_manage.enums.TaskStatus;
import org.nl.wms.sch_manage.service.ISchBasePointService;
import org.nl.wms.sch_manage.service.ISchBaseTaskService;
import org.nl.wms.sch_manage.service.dao.SchBasePoint;
import org.nl.wms.sch_manage.service.dao.SchBaseTask;
import org.nl.wms.sch_manage.service.util.ACSTaskTypeEnum;
import org.nl.wms.sch_manage.service.util.AbstractTask;
import org.nl.wms.sch_manage.service.util.AcsTaskDto;
import org.nl.wms.warehouse_management.enums.IOSConstant;
import org.nl.wms.warehouse_management.enums.IOSEnum;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
* 码垛下料
* @author: lyd
* @date: 2026/1/9
*/
@Component("PalletizingDownTask")
public class PalletizingDownTask extends AbstractTask {
@Resource
private ISchBasePointService pointService;
@Resource
private ISchBaseTaskService taskService;
@Resource(name = "PalletizingAddTask")
private PalletizingAddTask palletizingAddTask;
@Override
public String create(JSONObject json) {
// 查找空闲的内外中转点
List<SchBasePoint> list = pointService.getNoTaskPointByRegionAndType("AGVZJZ01", "1", "1");
if (list.size() == 0) {
throw new BadRequestException("没有可用的内外中转点!");
}
SchBasePoint point = list.get(0);
SchBaseTask task = new SchBaseTask();
task.setTask_id(IdUtil.getStringId());
task.setTask_code(CodeUtil.getNewCode("TASK_CODE"));
task.setTask_status(TaskStatus.CREATED.getCode());
task.setConfig_code(PalletizingDownTask.class.getSimpleName());
task.setPoint_code1(json.getString("device_code"));
task.setPoint_code2(point.getPoint_code());
task.setVehicle_code(json.getString("vehicle_code"));
task.setMaterial_id(json.getString("material_id"));
task.setMaterial_qty(json.getBigDecimal("material_qty"));
task.setGroup_id(json.getString("group_id"));
task.setRequest_param(json.toString());
task.setPriority(json.getString("Priority"));
task.setTask_type(TaskEnum.TASK_TYPE.code("料箱"));
task.setIs_wait(json.getString("is_wait"));
task.setCreate_id(SecurityUtils.getCurrentUserId());
task.setCreate_name(SecurityUtils.getCurrentNickName());
task.setCreate_time(DateUtil.now());
taskService.save(task);
// 下发任务
// this.sendTaskOne(task.getTask_id());
return task.getTask_id();
}
@Override
public AcsTaskDto sendAcsParam(String taskId) {
SchBaseTask taskDao = taskService.getById(taskId);
// 组织下发给acs的数据
AcsTaskDto acsTaskDto = new AcsTaskDto();
acsTaskDto.setExt_task_id(taskDao.getTask_id());
acsTaskDto.setTask_code(taskDao.getTask_code());
acsTaskDto.setStart_device_code(taskDao.getPoint_code1());
acsTaskDto.setNext_device_code(taskDao.getPoint_code2());
acsTaskDto.setVehicle_code(taskDao.getVehicle_code());
acsTaskDto.setVehicle_type(IOSConstant.ONE);
acsTaskDto.setIs_wait(IOSConstant.ZERO);
acsTaskDto.setTask_type(ACSTaskTypeEnum.AGV_TASK.getCode());
acsTaskDto.setPriority(IOSConstant.ONE);
acsTaskDto.setAgv_system_type(IOSConstant.THREE);
acsTaskDto.setIs_get_pause(IOSConstant.ZERO);
acsTaskDto.setIs_put_pause(IOSConstant.ZERO);
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("执行中");
taskService.updateById(taskObj);
}
if (status.equals(TaskStatus.FINISHED)) {
this.finishTask(taskObj);
}
if (status.equals(TaskStatus.CANCELED)) {
this.cancelTask(taskObj);
}
}
public void cancelTask(SchBaseTask taskObj) {
// 更新任务状态
taskObj.setTask_status(TaskStatus.CANCELED.getCode());
taskObj.setRemark("已取消");
taskService.updateById(taskObj);
}
@Transactional(rollbackFor = Exception.class)
public void finishTask(SchBaseTask taskObj) {
// 任务完成
taskObj.setTask_status(TaskStatus.FINISHED.getCode());
taskObj.setRemark("已完成");
taskService.updateById(taskObj);
// 更新
pointService.update(
new UpdateWrapper<SchBasePoint>().lambda()
.set(SchBasePoint::getVehicle_code, taskObj.getVehicle_code())
.set(SchBasePoint::getPoint_status, IOSEnum.POINT_STATUS.code("有箱有料"))
.eq(SchBasePoint::getPoint_code, taskObj.getPoint_code2())
.set(SchBasePoint::getIng_task_code, "")
);
// 创建出去缠绕机或者空点位
List<SchBasePoint> pointList = pointService.getCRUsedDevice();
if (pointList.size() == 0) {
// 查找空位置, todo: 先不考虑二次分配
pointList = pointService.getNoTaskPointByRegionAndType("CRHCQ", "1", "1");
}
if (pointList.size() == 0) {
throw new BadRequestException("找不到可存放的空位!");
}
SchBasePoint point = pointList.get(0);
JSONObject taskParam = new JSONObject();
taskParam.put("point_code1", taskObj.getPoint_code2());
taskParam.put("point_code2", point.getPoint_code());
taskParam.put("vehicle_code", taskObj.getVehicle_code());
taskParam.put("material_id", taskObj.getMaterial_id());
taskParam.put("material_qty", taskObj.getMaterial_qty());
taskParam.put("group_id", taskObj.getGroup_id());
palletizingAddTask.create(taskParam);
}
@Override
public void forceFinish(String task_code) {
SchBaseTask taskObj = taskService.getByCode(task_code);
if (ObjectUtil.isEmpty(taskObj)) {
throw new BadRequestException("该任务不存在");
}
this.finishTask(taskObj);
}
@Override
public void cancel(String task_code) {
SchBaseTask taskObj = taskService.getByCode(task_code);
if (ObjectUtil.isEmpty(taskObj)) {
throw new BadRequestException("该任务不存在");
}
if (!TaskStatus.CREATE.getCode().equals(taskObj.getTask_status())) {
throw new BadRequestException("任务状态必须为生成才能取消任务");
}
this.cancelTask(taskObj);
}
@Override
public void taskConfirm(String task_code) {
}
}

View File

@@ -36,7 +36,7 @@ import java.util.List;
import java.util.Map;
/**
* 压片入库
* 压片/包衣入库
* @Author: lyd
* @Date: 2025/12/4
*/
@@ -146,13 +146,6 @@ public class TabletingInTask extends AbstractTask {
}
public void cancelTask(SchBaseTask taskObj) {
// 取消任务
taskService.update(new LambdaUpdateWrapper<SchBaseTask>()
.set(SchBaseTask::getIs_delete, BaseDataEnum.IS_YES_NOT.code(""))
.set(SchBaseTask::getTask_status, TaskStatus.CANCELED.getCode())
.set(SchBaseTask::getRemark, "已取消")
.eq(SchBaseTask::getTask_id, taskObj.getTask_id())
);
// 更新任务状态
taskObj.setTask_status(TaskStatus.CANCELED.getCode());
@@ -171,8 +164,11 @@ public class TabletingInTask extends AbstractTask {
new UpdateWrapper<SchBasePoint>().lambda()
.set(SchBasePoint::getVehicle_code, "")
.set(SchBasePoint::getPoint_status, IOSEnum.POINT_STATUS.code("空位"))
.eq(SchBasePoint::getPoint_code, taskObj.getPoint_code1())
.set(SchBasePoint::getUpdate_id, SecurityUtils.getCurrentUserId())
.set(SchBasePoint::getUpdate_time, DateUtil.now())
.set(SchBasePoint::getUpdate_name, SecurityUtils.getCurrentNickName())
.set(SchBasePoint::getIng_task_code, "")
.eq(SchBasePoint::getPoint_code, taskObj.getPoint_code1())
);
SchBasePoint startPoint = pointService.getByPointCode(taskObj.getPoint_code2(), false);
if (ObjectUtil.isEmpty(startPoint.getIn_sect())) {

View File

@@ -0,0 +1,193 @@
package org.nl.wms.sch_manage.service.util.tasks;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.nl.common.exception.BadRequestException;
import org.nl.common.utils.CodeUtil;
import org.nl.common.utils.SecurityUtils;
import org.nl.config.IdUtil;
import org.nl.wms.sch_manage.enums.TaskEnum;
import org.nl.wms.sch_manage.enums.TaskStatus;
import org.nl.wms.sch_manage.service.ISchBasePointService;
import org.nl.wms.sch_manage.service.ISchBaseTaskService;
import org.nl.wms.sch_manage.service.dao.SchBasePoint;
import org.nl.wms.sch_manage.service.dao.SchBaseTask;
import org.nl.wms.sch_manage.service.util.ACSTaskTypeEnum;
import org.nl.wms.sch_manage.service.util.AbstractTask;
import org.nl.wms.sch_manage.service.util.AcsTaskDto;
import org.nl.wms.warehouse_management.enums.IOSConstant;
import org.nl.wms.warehouse_management.enums.IOSEnum;
import org.nl.wms.warehouse_management.service.IMdPbGroupplateService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
/**
*
* @author: lyd
* @date: 2026/1/12
*/
@Component("WrappingDownTask")
public class WrappingDownTask extends AbstractTask {
@Resource
private ISchBasePointService pointService;
@Resource
private ISchBaseTaskService taskService;
@Resource
private IMdPbGroupplateService groupplateService;
@Override
public String create(JSONObject json) {
// 查找空闲的需要缠绕的点
List<SchBasePoint> list = pointService.getNoTaskPointByRegionAndType("CRHCQ", "4", "1");
if (list.size() == 0) {
throw new BadRequestException("没有需要缠绕的点!");
}
SchBasePoint basePoint = list.get(0);
SchBasePoint parentPoint = pointService.getById(json.getString("device_code"));
SchBasePoint point = pointService.getById(parentPoint.getParent_point_code());
List<JSONObject> palletViewByVehicleCode = groupplateService.getPalletViewByVehicleCode(point.getVehicle_code(), Collections.singletonList("1"));
if (palletViewByVehicleCode.size() == 0) {
throw new BadRequestException("托盘信息不存在!");
}
JSONObject jsonObject = palletViewByVehicleCode.get(0);
SchBaseTask task = new SchBaseTask();
task.setTask_id(IdUtil.getStringId());
task.setTask_code(CodeUtil.getNewCode("TASK_CODE"));
task.setTask_status(TaskStatus.CREATED.getCode());
task.setConfig_code(WrappingDownTask.class.getSimpleName());
task.setPoint_code1(json.getString("device_code"));
task.setPoint_code2(basePoint.getPoint_code());
task.setPoint_code3(parentPoint.getPoint_code());
task.setVehicle_code(point.getVehicle_code());
task.setMaterial_id(jsonObject.getString("material_id"));
task.setMaterial_qty(jsonObject.getBigDecimal("qty"));
task.setGroup_id(jsonObject.getString("group_id"));
task.setRequest_param(json.toString());
task.setPriority(json.getString("Priority"));
task.setTask_type(TaskEnum.TASK_TYPE.code("料箱"));
task.setIs_wait(json.getString("is_wait"));
task.setCreate_id(SecurityUtils.getCurrentUserId());
task.setCreate_name(SecurityUtils.getCurrentNickName());
task.setCreate_time(DateUtil.now());
taskService.save(task);
// 下发任务
// this.sendTaskOne(task.getTask_id());
return task.getTask_id();
}
@Override
public AcsTaskDto sendAcsParam(String taskId) {
SchBaseTask taskDao = taskService.getById(taskId);
// 组织下发给acs的数据
AcsTaskDto acsTaskDto = new AcsTaskDto();
acsTaskDto.setExt_task_id(taskDao.getTask_id());
acsTaskDto.setTask_code(taskDao.getTask_code());
acsTaskDto.setStart_device_code(taskDao.getPoint_code1());
acsTaskDto.setNext_device_code(taskDao.getPoint_code2());
acsTaskDto.setVehicle_code(taskDao.getVehicle_code());
acsTaskDto.setVehicle_type(IOSConstant.ONE);
acsTaskDto.setIs_wait(IOSConstant.ZERO);
acsTaskDto.setTask_type(ACSTaskTypeEnum.AGV_TASK.getCode());
acsTaskDto.setPriority(IOSConstant.ONE);
acsTaskDto.setAgv_system_type(IOSConstant.THREE);
acsTaskDto.setIs_get_pause(IOSConstant.ZERO);
acsTaskDto.setIs_put_pause(IOSConstant.ZERO);
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("执行中");
taskService.updateById(taskObj);
}
if (status.equals(TaskStatus.FINISHED)) {
this.finishTask(taskObj);
}
if (status.equals(TaskStatus.CANCELED)) {
this.cancelTask(taskObj);
}
}
public void cancelTask(SchBaseTask taskObj) {
// 更新任务状态
taskObj.setTask_status(TaskStatus.CANCELED.getCode());
taskObj.setRemark("已取消");
taskService.updateById(taskObj);
}
@Transactional(rollbackFor = Exception.class)
public void finishTask(SchBaseTask taskObj) {
// 任务完成
taskObj.setTask_status(TaskStatus.FINISHED.getCode());
taskObj.setRemark("已完成");
taskService.updateById(taskObj);
// 更新
pointService.update(
new UpdateWrapper<SchBasePoint>().lambda()
.set(SchBasePoint::getVehicle_code, taskObj.getVehicle_code())
.set(SchBasePoint::getPoint_status, IOSEnum.POINT_STATUS.code("有箱有料"))
.set(SchBasePoint::getUpdate_time, DateUtil.now())
.set(SchBasePoint::getUpdate_id, SecurityUtils.getCurrentUserId())
.set(SchBasePoint::getUpdate_name, SecurityUtils.getCurrentNickName())
.set(SchBasePoint::getIng_task_code, "")
.eq(SchBasePoint::getPoint_code, taskObj.getPoint_code2())
);
pointService.update(
new UpdateWrapper<SchBasePoint>().lambda()
.set(SchBasePoint::getVehicle_code, "")
.set(SchBasePoint::getPoint_status, IOSEnum.POINT_STATUS.code("空位"))
.set(SchBasePoint::getUpdate_time, DateUtil.now())
.set(SchBasePoint::getUpdate_id, SecurityUtils.getCurrentUserId())
.set(SchBasePoint::getUpdate_name, SecurityUtils.getCurrentNickName())
.set(SchBasePoint::getIng_task_code, "")
.eq(SchBasePoint::getPoint_code, taskObj.getPoint_code3())
);
}
@Override
public void forceFinish(String task_code) {
SchBaseTask taskObj = taskService.getByCode(task_code);
if (ObjectUtil.isEmpty(taskObj)) {
throw new BadRequestException("该任务不存在");
}
this.finishTask(taskObj);
}
@Override
public void cancel(String task_code) {
SchBaseTask taskObj = taskService.getByCode(task_code);
if (ObjectUtil.isEmpty(taskObj)) {
throw new BadRequestException("该任务不存在");
}
if (!TaskStatus.CREATE.getCode().equals(taskObj.getTask_status())) {
throw new BadRequestException("任务状态必须为生成才能取消任务");
}
this.cancelTask(taskObj);
}
@Override
public void taskConfirm(String task_code) {
}
}

View File

@@ -0,0 +1,191 @@
package org.nl.wms.sch_manage.service.util.tasks;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.nl.common.exception.BadRequestException;
import org.nl.common.utils.CodeUtil;
import org.nl.common.utils.SecurityUtils;
import org.nl.config.IdUtil;
import org.nl.wms.sch_manage.enums.TaskEnum;
import org.nl.wms.sch_manage.enums.TaskStatus;
import org.nl.wms.sch_manage.service.ISchBasePointService;
import org.nl.wms.sch_manage.service.ISchBaseTaskService;
import org.nl.wms.sch_manage.service.dao.SchBasePoint;
import org.nl.wms.sch_manage.service.dao.SchBaseTask;
import org.nl.wms.sch_manage.service.util.ACSTaskTypeEnum;
import org.nl.wms.sch_manage.service.util.AbstractTask;
import org.nl.wms.sch_manage.service.util.AcsTaskDto;
import org.nl.wms.warehouse_management.enums.IOSConstant;
import org.nl.wms.warehouse_management.enums.IOSEnum;
import org.nl.wms.warehouse_management.service.IMdPbGroupplateService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
*
* @author: lyd
* @date: 2026/1/12
*/
@Component("WrappingUpTask")
public class WrappingUpTask extends AbstractTask {
@Resource
private ISchBasePointService pointService;
@Resource
private ISchBaseTaskService taskService;
@Resource
private IMdPbGroupplateService groupplateService;
@Override
public String create(JSONObject json) {
// 查找空闲的需要缠绕的点
List<SchBasePoint> list = pointService.getNoTaskPointByRegionAndType("CRHCQ", "1", "2");
if (list.size() == 0) {
throw new BadRequestException("没有需要缠绕的点!");
}
SchBasePoint basePoint = list.get(0);
List<JSONObject> palletViewByVehicleCode = groupplateService.getPalletViewByVehicleCode(basePoint.getVehicle_code(), Collections.singletonList("1"));
if (palletViewByVehicleCode.size() == 0) {
throw new BadRequestException("托盘信息不存在!");
}
JSONObject jsonObject = palletViewByVehicleCode.get(0);
SchBaseTask task = new SchBaseTask();
task.setTask_id(IdUtil.getStringId());
task.setTask_code(CodeUtil.getNewCode("TASK_CODE"));
task.setTask_status(TaskStatus.CREATED.getCode());
task.setConfig_code(WrappingUpTask.class.getSimpleName());
task.setPoint_code1(basePoint.getPoint_code());
task.setPoint_code2(json.getString("device_code"));
task.setVehicle_code(basePoint.getVehicle_code());
task.setMaterial_id(jsonObject.getString("material_id"));
task.setMaterial_qty(jsonObject.getBigDecimal("qty"));
task.setGroup_id(jsonObject.getString("group_id"));
task.setRequest_param(json.toString());
task.setPriority(json.getString("Priority"));
task.setTask_type(TaskEnum.TASK_TYPE.code("料箱"));
task.setIs_wait(json.getString("is_wait"));
task.setCreate_id(SecurityUtils.getCurrentUserId());
task.setCreate_name(SecurityUtils.getCurrentNickName());
task.setCreate_time(DateUtil.now());
taskService.save(task);
// 下发任务
// this.sendTaskOne(task.getTask_id());
return task.getTask_id();
}
@Override
public AcsTaskDto sendAcsParam(String taskId) {
SchBaseTask taskDao = taskService.getById(taskId);
// 组织下发给acs的数据
AcsTaskDto acsTaskDto = new AcsTaskDto();
acsTaskDto.setExt_task_id(taskDao.getTask_id());
acsTaskDto.setTask_code(taskDao.getTask_code());
acsTaskDto.setStart_device_code(taskDao.getPoint_code1());
acsTaskDto.setNext_device_code(taskDao.getPoint_code2());
acsTaskDto.setVehicle_code(taskDao.getVehicle_code());
acsTaskDto.setVehicle_type(IOSConstant.ONE);
acsTaskDto.setIs_wait(IOSConstant.ZERO);
acsTaskDto.setTask_type(ACSTaskTypeEnum.AGV_TASK.getCode());
acsTaskDto.setPriority(IOSConstant.ONE);
acsTaskDto.setAgv_system_type(IOSConstant.THREE);
acsTaskDto.setIs_get_pause(IOSConstant.ZERO);
acsTaskDto.setIs_put_pause(IOSConstant.ZERO);
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("执行中");
taskService.updateById(taskObj);
}
if (status.equals(TaskStatus.FINISHED)) {
this.finishTask(taskObj);
}
if (status.equals(TaskStatus.CANCELED)) {
this.cancelTask(taskObj);
}
}
public void cancelTask(SchBaseTask taskObj) {
// 更新任务状态
taskObj.setTask_status(TaskStatus.CANCELED.getCode());
taskObj.setRemark("已取消");
taskService.updateById(taskObj);
}
@Transactional(rollbackFor = Exception.class)
public void finishTask(SchBaseTask taskObj) {
// 任务完成
taskObj.setTask_status(TaskStatus.FINISHED.getCode());
taskObj.setRemark("已完成");
taskService.updateById(taskObj);
// 更新
pointService.update(
new UpdateWrapper<SchBasePoint>().lambda()
.set(SchBasePoint::getVehicle_code, taskObj.getVehicle_code())
.set(SchBasePoint::getPoint_status, IOSEnum.POINT_STATUS.code("有箱有料"))
.set(SchBasePoint::getIng_task_code, "")
.set(SchBasePoint::getUpdate_time, DateUtil.now())
.set(SchBasePoint::getUpdate_id, SecurityUtils.getCurrentUserId())
.set(SchBasePoint::getUpdate_name, SecurityUtils.getCurrentNickName())
.eq(SchBasePoint::getPoint_code, taskObj.getPoint_code2())
);pointService.update(
new UpdateWrapper<SchBasePoint>().lambda()
.set(SchBasePoint::getVehicle_code, "")
.set(SchBasePoint::getPoint_status, IOSEnum.POINT_STATUS.code("空位"))
.set(SchBasePoint::getIng_task_code, "")
.set(SchBasePoint::getUpdate_time, DateUtil.now())
.set(SchBasePoint::getUpdate_id, SecurityUtils.getCurrentUserId())
.set(SchBasePoint::getUpdate_name, SecurityUtils.getCurrentNickName())
.eq(SchBasePoint::getPoint_code, taskObj.getPoint_code1())
);
}
@Override
public void forceFinish(String task_code) {
SchBaseTask taskObj = taskService.getByCode(task_code);
if (ObjectUtil.isEmpty(taskObj)) {
throw new BadRequestException("该任务不存在");
}
this.finishTask(taskObj);
}
@Override
public void cancel(String task_code) {
SchBaseTask taskObj = taskService.getByCode(task_code);
if (ObjectUtil.isEmpty(taskObj)) {
throw new BadRequestException("该任务不存在");
}
if (!TaskStatus.CREATE.getCode().equals(taskObj.getTask_status())) {
throw new BadRequestException("任务状态必须为生成才能取消任务");
}
this.cancelTask(taskObj);
}
@Override
public void taskConfirm(String task_code) {
}
}

View File

@@ -68,7 +68,8 @@ public enum IOSEnum {
"1003", "IntermediateOutTask"
)),
// 下料任务配置编码
DOWN_CONFIG_CODE(MapOf.of("YPQ", "TabletingInTask"
DOWN_CONFIG_CODE(MapOf.of("YPQ", "TabletingInTask",
"BYQ", "TabletingInTask"
)),
// 移库任务配置类编码
MOVE_CONFIG_CODE(MapOf.of("2001","InsideMoveTask", "2004", "CheckMoveTask"