李永德
1 year ago
14 changed files with 382 additions and 19 deletions
@ -1,12 +1,14 @@ |
|||
package org.nl.wms.database.material.service.dto; |
|||
|
|||
import org.nl.common.domain.query.BaseQuery; |
|||
import org.nl.wms.database.material.service.dao.MdBaseMaterial; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @author lyd |
|||
* @date 2023-05-05 |
|||
**/ |
|||
public class MdBaseMaterialQuery extends BaseQuery<MdBaseMaterial> { |
|||
|
|||
@Data |
|||
public class MdBaseMaterialQuery implements Serializable { |
|||
private String blurry; |
|||
} |
|||
|
@ -0,0 +1,281 @@ |
|||
package org.nl.wms.sch.task_manage.task.tasks.fj; |
|||
|
|||
import cn.hutool.core.date.DateUtil; |
|||
import cn.hutool.core.util.IdUtil; |
|||
import cn.hutool.core.util.ObjectUtil; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import org.nl.common.exception.BadRequestException; |
|||
import org.nl.system.service.notice.ISysNoticeService; |
|||
import org.nl.wms.pdm.workorder.service.IPdmBdWorkorderService; |
|||
import org.nl.wms.pdm.workorder.service.dao.PdmBdWorkorder; |
|||
import org.nl.wms.sch.group.service.ISchBaseVehiclematerialgroupService; |
|||
import org.nl.wms.sch.group.service.dao.SchBaseVehiclematerialgroup; |
|||
import org.nl.wms.sch.point.service.ISchBasePointService; |
|||
import org.nl.wms.sch.point.service.dao.SchBasePoint; |
|||
import org.nl.wms.sch.task.service.ISchBaseTaskService; |
|||
import org.nl.wms.sch.task.service.ISchBaseTaskconfigService; |
|||
import org.nl.wms.sch.task.service.dao.SchBaseTask; |
|||
import org.nl.wms.sch.task.service.dao.SchBaseTaskconfig; |
|||
import org.nl.wms.sch.task_manage.AbstractTask; |
|||
import org.nl.wms.sch.task_manage.GeneralDefinition; |
|||
import org.nl.wms.sch.task_manage.enums.*; |
|||
import org.nl.wms.sch.task_manage.task.TaskType; |
|||
import org.nl.wms.sch.task_manage.task.core.TaskStatus; |
|||
import org.nl.wms.util.PointUtils; |
|||
import org.nl.wms.util.TaskUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
import java.util.stream.Collectors; |
|||
|
|||
/** |
|||
* @Author: lyd |
|||
* @Description: rgv - 分拣强制入库任务 - 2点 |
|||
* @Date: 2023/6/21 |
|||
*/ |
|||
@Component |
|||
@TaskType("FJQZRKTask") |
|||
public class FJQZRKTask extends AbstractTask { |
|||
private static String TASK_CONFIG_CODE = "FJQZRKTask"; |
|||
@Autowired |
|||
private ISchBasePointService pointService; |
|||
@Autowired |
|||
private ISchBaseTaskService taskService; |
|||
@Autowired |
|||
private ISchBaseTaskconfigService taskConfigService; |
|||
@Autowired |
|||
private ISysNoticeService noticeService; |
|||
|
|||
@Autowired |
|||
private IPdmBdWorkorderService workorderService; |
|||
@Autowired |
|||
private ISchBaseVehiclematerialgroupService vehiclematerialgroupService; |
|||
@Override |
|||
protected void create() throws BadRequestException { |
|||
// 最后一坨不需要呼叫空盘
|
|||
// 获取任务
|
|||
List<SchBaseTask> tasks = taskService.findTasksByTaskStatus(TASK_CONFIG_CODE, TaskStatus.APPLY); |
|||
// 配置信息
|
|||
SchBaseTaskconfig taskConfig = taskConfigService.getOne(new LambdaQueryWrapper<SchBaseTaskconfig>() |
|||
.eq(SchBaseTaskconfig::getConfig_code, TASK_CONFIG_CODE)); |
|||
for (SchBaseTask task : tasks) { |
|||
TaskUtils.setUpdateByAcs(task); |
|||
List<String> nextRegionStr = Arrays.stream(taskConfig.getNext_region_str().split(",")).collect(Collectors.toList()); |
|||
// 找终点
|
|||
SchBasePoint point = findNextPoint(nextRegionStr); |
|||
if (ObjectUtil.isEmpty(point)) { |
|||
task.setRemark("未找到所需点位!"); |
|||
taskService.updateById(task); |
|||
// 消息通知
|
|||
noticeService.createNotice(task.getRemark(), TASK_CONFIG_CODE + task.getTask_code(), |
|||
NoticeTypeEnum.WARN.getCode()); |
|||
continue; |
|||
} |
|||
// 设置终点并修改创建成功状态
|
|||
task.setPoint_code2(point.getPoint_code()); |
|||
task.setTask_status(TaskStatus.CREATED.getCode()); |
|||
task.setRemark(""); |
|||
taskService.updateById(task); |
|||
|
|||
point.setIng_task_code(task.getTask_code()); |
|||
PointUtils.setUpdateByAcs(point); |
|||
pointService.updateById(point); |
|||
|
|||
//下发
|
|||
//this.renotifyAcs(task);
|
|||
} |
|||
} |
|||
|
|||
@Override |
|||
@Transactional |
|||
protected void createCompletion(SchBaseTask task) { |
|||
// 配置信息
|
|||
SchBaseTaskconfig taskConfig = taskConfigService.getOne(new LambdaQueryWrapper<SchBaseTaskconfig>() |
|||
.eq(SchBaseTaskconfig::getConfig_code, TASK_CONFIG_CODE)); |
|||
TaskUtils.setUpdateByAcs(task); |
|||
List<String> nextRegionStr = Arrays.stream(taskConfig.getNext_region_str().split(",")).collect(Collectors.toList()); |
|||
// 找终点
|
|||
SchBasePoint point = findNextPoint(nextRegionStr); |
|||
if (ObjectUtil.isEmpty(point)) { |
|||
// 消息通知
|
|||
noticeService.createNotice("找不到可用的包装位!", TASK_CONFIG_CODE + task.getPoint_code1(), |
|||
NoticeTypeEnum.WARN.getCode()); |
|||
throw new BadRequestException("找不到可用的包装位!"); |
|||
} |
|||
// 设置终点并修改创建成功状态
|
|||
task.setPoint_code2(point.getPoint_code()); |
|||
task.setTask_status(TaskStatus.CREATED.getCode()); |
|||
task.setRemark(""); |
|||
taskService.save(task); |
|||
|
|||
point.setIng_task_code(task.getTask_code()); |
|||
PointUtils.setUpdateByAcs(point); |
|||
pointService.updateById(point); |
|||
} |
|||
|
|||
/** |
|||
* 到对应的区域中获取放置点 |
|||
* @param nextRegionStr |
|||
* @return |
|||
*/ |
|||
private SchBasePoint findNextPoint(List<String> nextRegionStr) { |
|||
LambdaQueryWrapper<SchBasePoint> lam = new LambdaQueryWrapper<>(); |
|||
lam.in(SchBasePoint::getRegion_code, nextRegionStr) |
|||
.and(la -> la.isNull(SchBasePoint::getIng_task_code) // 当前执行的任务为空或者NULL,有数据表示锁住
|
|||
.or() |
|||
.eq(SchBasePoint::getIng_task_code, "")) |
|||
.eq(SchBasePoint::getPoint_type, GeneralDefinition.DOCKING_POINT) |
|||
.eq(SchBasePoint::getIs_used, true); |
|||
List<SchBasePoint> schBasePoints = pointService.list(lam); |
|||
return ObjectUtil.isNotEmpty(schBasePoints) ? schBasePoints.get(0) : null; |
|||
} |
|||
|
|||
@Override |
|||
public String setGroupPlate(JSONObject param) { |
|||
// 强制入库组盘
|
|||
// 组盘,返回组盘标识,设置待绑定,搬运结束就设置已绑定
|
|||
String deviceCode = param.getString("device_code"); |
|||
JSONObject stackParameters = param.getJSONObject("palletize"); |
|||
String vehicleCode = param.getString("vehicle_code"); |
|||
// 砖块数量
|
|||
Integer qty = param.getInteger("qty"); |
|||
SchBasePoint basePoint = pointService.getById(deviceCode); |
|||
PdmBdWorkorder workorderObject = workorderService.getDeviceProductionTask(basePoint.getParent_point_code()); |
|||
String vehicleType = workorderObject.getVehicle_type(); |
|||
// 找到相同组盘信息就直接返回id,避免任务取消组盘信息还存在,重复插入
|
|||
SchBaseVehiclematerialgroup groupEntity = new SchBaseVehiclematerialgroup(); |
|||
groupEntity.setGroup_id(IdUtil.getSnowflake(1, 1).nextIdStr()); |
|||
SchBaseVehiclematerialgroup groupObject = vehiclematerialgroupService.getGroupInfo(vehicleCode, vehicleType, |
|||
GroupBindMaterialStatusEnum.BOUND.getValue(), workorderObject.getMaterial_id()); |
|||
if (groupObject != null) { |
|||
groupEntity = groupObject; |
|||
} |
|||
// 要把数据存到组盘表
|
|||
groupEntity.setMaterial_id(ObjectUtil.isNotEmpty(workorderObject) |
|||
? workorderObject.getMaterial_id() |
|||
: ""); |
|||
groupEntity.setStanding_time(ObjectUtil.isNotEmpty(workorderObject) |
|||
? workorderObject.getStanding_time() |
|||
: 0); |
|||
groupEntity.setWorkorder_code(ObjectUtil.isNotEmpty(workorderObject) |
|||
? workorderObject.getWorkorder_code() |
|||
: ""); |
|||
groupEntity.setCreate_id(GeneralDefinition.ACS_ID); |
|||
groupEntity.setCreate_name(GeneralDefinition.ACS_NAME); |
|||
groupEntity.setCreate_time(DateUtil.now()); |
|||
groupEntity.setVehicle_code(vehicleCode); |
|||
groupEntity.setVehicle_type(vehicleType); |
|||
groupEntity.setMaterial_qty(qty); |
|||
groupEntity.setExt_data(JSONObject.toJSONString(stackParameters)); // 垛型参数
|
|||
groupEntity.setPoint_code(basePoint.getPoint_code()); // 对接位
|
|||
groupEntity.setPoint_name(basePoint.getPoint_name()); |
|||
groupEntity.setSource_vehicle_code(basePoint.getPoint_code()); |
|||
groupEntity.setMove_way(basePoint.getPoint_code()); |
|||
groupEntity.setPcsn(DateUtil.format(DateUtil.date(), "yyyyMMdd")); // todo: ???
|
|||
groupEntity.setInstorage_time(DateUtil.now()); |
|||
groupEntity.setGroup_bind_material_status(GroupBindMaterialStatusEnum.BOUND.getValue()); // 绑定
|
|||
groupEntity.setGroup_status(GroupStatusEnum.IN_STORAGE.getType()); // 暂时不维护。
|
|||
groupEntity.setIs_delete(false); |
|||
vehiclematerialgroupService.saveOrUpdate(groupEntity); |
|||
// 将所有当前位置的砖块设置组盘标识
|
|||
// baseBrickInfoService.setGroupByCurrentAllBrick(deviceCode, groupEntity.getGroup_id());
|
|||
// 返回组盘id记录任务中
|
|||
return groupEntity.getGroup_id(); |
|||
} |
|||
|
|||
@Override |
|||
protected void updateStatus(String task_code, TaskStatus status) { |
|||
// 校验任务
|
|||
SchBaseTask taskObj = taskService.getByCode(task_code); |
|||
if (taskObj.getTask_status().equals(TaskStatus.FINISHED.getCode())) { |
|||
throw new BadRequestException("该任务已完成!"); |
|||
} |
|||
if (taskObj.getTask_status().equals(TaskStatus.CANCELED.getCode())) { |
|||
throw new BadRequestException("该任务已取消!"); |
|||
} |
|||
|
|||
// 根据传来的类型去对任务进行操作
|
|||
if (status.equals(TaskStatus.EXECUTING)) { // 执行中
|
|||
taskObj.setTask_status(TaskStatus.EXECUTING.getCode()); |
|||
taskObj.setRemark("执行中"); |
|||
TaskUtils.setUpdateByAcs(taskObj); |
|||
taskService.updateById(taskObj); |
|||
} |
|||
if (status.equals(TaskStatus.FINISHED)) { // 完成
|
|||
this.finishTask(taskObj, TaskFinishedTypeEnum.AUTO_ACS); |
|||
} |
|||
if (status.equals(TaskStatus.CANCELED)) { // 取消
|
|||
this.cancelTask(taskObj, TaskFinishedTypeEnum.AUTO_ACS); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void forceFinish(String task_code) { |
|||
SchBaseTask taskObj = taskService.getByCode(task_code); |
|||
if (ObjectUtil.isEmpty(taskObj)) { |
|||
throw new BadRequestException("该任务不存在"); |
|||
} |
|||
this.finishTask(taskObj, TaskFinishedTypeEnum.MANUAL_PC); |
|||
} |
|||
|
|||
@Override |
|||
public void cancel(String task_code) { |
|||
SchBaseTask taskObj = taskService.getByCode(task_code); |
|||
if (ObjectUtil.isEmpty(taskObj)) { |
|||
throw new BadRequestException("该任务不存在"); |
|||
} |
|||
this.cancelTask(taskObj, TaskFinishedTypeEnum.MANUAL_PC); |
|||
} |
|||
|
|||
public void finishTask(SchBaseTask taskObj, TaskFinishedTypeEnum taskFinishedType) { |
|||
// 获取参数
|
|||
String endPoint = taskObj.getPoint_code2(); // 获取终点
|
|||
String startPoint = taskObj.getPoint_code1(); // 获取终点
|
|||
SchBasePoint startPointObj = pointService.getById(startPoint); |
|||
SchBasePoint endPointObj = pointService.getById(endPoint); |
|||
// 设置载具类型、点位状态、释放点位
|
|||
if (ObjectUtil.isNotEmpty(endPoint)) { |
|||
endPointObj.setIng_task_code(""); |
|||
PointUtils.setUpdateByType(endPointObj, taskFinishedType); |
|||
pointService.updateById(endPointObj); |
|||
|
|||
// 组盘设置已经解绑
|
|||
SchBaseVehiclematerialgroup vehicleMaterialGroupObj = |
|||
vehiclematerialgroupService.getById(taskObj.getGroup_id()); |
|||
vehicleMaterialGroupObj.setGroup_bind_material_status(GroupBindMaterialStatusEnum.UNBOUND.getValue()); |
|||
vehicleMaterialGroupObj.setPoint_code(endPointObj.getPoint_code()); // 当前位置
|
|||
vehicleMaterialGroupObj.setPoint_name(endPointObj.getPoint_name()); |
|||
vehicleMaterialGroupObj.setMove_way(vehicleMaterialGroupObj.getMove_way() + " -> " + endPointObj.getPoint_code()); |
|||
TaskUtils.setGroupUpdateByType(vehicleMaterialGroupObj, taskFinishedType); |
|||
vehiclematerialgroupService.updateById(vehicleMaterialGroupObj); |
|||
} |
|||
PointUtils.setUpdateByType(startPointObj, taskFinishedType); |
|||
PointUtils.clearPoint(startPointObj); |
|||
taskObj.setTask_status(TaskStatus.FINISHED.getCode()); |
|||
taskObj.setRemark(GeneralDefinition.TASK_FINISH); |
|||
taskObj.setFinished_type(taskFinishedType.getCode()); |
|||
TaskUtils.setUpdateByType(taskObj, taskFinishedType); |
|||
taskService.updateById(taskObj); |
|||
} |
|||
|
|||
public void cancelTask(SchBaseTask taskObj, TaskFinishedTypeEnum taskFinishedType) { |
|||
// 获取参数
|
|||
String endPoint = taskObj.getPoint_code2(); // 获取终点
|
|||
SchBasePoint endPointObj = pointService.getById(endPoint); |
|||
// 释放点位
|
|||
if (ObjectUtil.isNotEmpty(endPoint)) { |
|||
endPointObj.setIng_task_code(""); |
|||
PointUtils.setUpdateByType(endPointObj, taskFinishedType); |
|||
pointService.updateById(endPointObj); |
|||
} |
|||
taskObj.setTask_status(TaskStatus.CANCELED.getCode()); |
|||
taskObj.setRemark(GeneralDefinition.TASK_CANCEL); |
|||
taskObj.setFinished_type(taskFinishedType.getCode()); |
|||
TaskUtils.setUpdateByType(taskObj, taskFinishedType); |
|||
taskService.updateById(taskObj); |
|||
} |
|||
} |
Loading…
Reference in new issue