psh
10 months ago
6 changed files with 241 additions and 1 deletions
@ -0,0 +1,216 @@ |
|||||
|
package org.nl.wms.sch.task_manage.task.tasks; |
||||
|
|
||||
|
import cn.hutool.core.date.DateUtil; |
||||
|
import cn.hutool.core.lang.Assert; |
||||
|
import cn.hutool.core.util.ObjectUtil; |
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.nl.common.exception.BadRequestException; |
||||
|
import org.nl.wms.ext.service.WmsToAcsService; |
||||
|
import org.nl.wms.ext.service.dto.to.BaseResponse; |
||||
|
import org.nl.wms.pdm.service.IPdmBdWorkorderService; |
||||
|
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.GroupBindMaterialStatusEnum; |
||||
|
import org.nl.wms.sch.task_manage.task.TaskType; |
||||
|
import org.nl.wms.sch.task_manage.task.core.TaskStatus; |
||||
|
import org.nl.wms.sch.task_manage.task.tasks.mapper.PointMapper; |
||||
|
import org.nl.wms.util.PointUtils; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.context.annotation.Lazy; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import java.util.Arrays; |
||||
|
import java.util.List; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
/** |
||||
|
* @Author: psh |
||||
|
* @Description: 正极板空固化架入库任务 |
||||
|
* @Date: 2024/1/31 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Component |
||||
|
@TaskType("ZJBKGHJRKTask") |
||||
|
@Lazy |
||||
|
public class ZJBKGHJRKTask extends AbstractTask { |
||||
|
private static String TASK_CONFIG_CODE = "ZJBKGHJRKTask"; |
||||
|
/** |
||||
|
* 入口 |
||||
|
*/ |
||||
|
private static String ENTRANCE = "1"; |
||||
|
@Autowired |
||||
|
private ISchBasePointService pointService; |
||||
|
@Autowired |
||||
|
private ISchBaseTaskService taskService; |
||||
|
@Autowired |
||||
|
private ISchBaseTaskconfigService taskConfigService; |
||||
|
@Autowired |
||||
|
private IPdmBdWorkorderService workorderService; |
||||
|
@Autowired |
||||
|
private ISchBaseVehiclematerialgroupService vehiclematerialgroupService; |
||||
|
@Autowired |
||||
|
private PointMapper pointMapper; |
||||
|
@Autowired |
||||
|
private WmsToAcsService wmsToAcsService; |
||||
|
|
||||
|
/** |
||||
|
* 正极板空固化架入库任务,检测到正极板空固化架对接位堆满三层, |
||||
|
* 则自动生成到HCQ06正极板空固化架缓存区的任务 |
||||
|
*/ |
||||
|
@Override |
||||
|
// @Transactional(rollbackFor = Exception.class)
|
||||
|
protected void create() throws BadRequestException { |
||||
|
List<SchBasePoint> schBasePointList = pointMapper.findPointByRegion2("ZJBKGHJDJW"); |
||||
|
for (SchBasePoint schBasePoint : schBasePointList) { |
||||
|
if (schBasePoint.getVehicle_qty() == 3 && ObjectUtil.isEmpty(schBasePoint.getIng_task_code())) { |
||||
|
log.info("正极板空固化架对接位{}已经放满,开始进行后续判断", schBasePoint.getPoint_code()); |
||||
|
List<SchBasePoint> nextPointList = pointMapper.findPointByRegion2("HCQ6"); |
||||
|
for(SchBasePoint nextPoint : nextPointList){ |
||||
|
if(ObjectUtil.isEmpty(nextPoint.getIng_task_code())&&nextPoint.getVehicle_qty()==0){ |
||||
|
//生成任务并下发
|
||||
|
log.info("找到目标点{}",nextPoint.getPoint_code()); |
||||
|
this.createTask(schBasePoint, nextPoint.getPoint_code()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 创建任务并下发 |
||||
|
* |
||||
|
* @param schBasePoint |
||||
|
* @param endPoint |
||||
|
* @return |
||||
|
*/ |
||||
|
private void createTask(SchBasePoint schBasePoint, String endPoint) { |
||||
|
// 申请任务
|
||||
|
SchBaseTask task = new SchBaseTask(); // 任务实体
|
||||
|
String apply_point_code = schBasePoint.getPoint_code(); // 请求点
|
||||
|
String config_code = "ZJBKGHJRKTask"; |
||||
|
// 1、校验数据
|
||||
|
SchBaseTaskconfig taskConfig = taskConfigService.getOne(new LambdaQueryWrapper<SchBaseTaskconfig>() |
||||
|
.eq(SchBaseTaskconfig::getConfig_code, config_code)); |
||||
|
Assert.notNull(taskConfig, "找不到配置文件,请确认[" + config_code + "]配置是否存在!"); |
||||
|
// 最大任务数
|
||||
|
Integer tcmn = taskConfig.getTask_create_max_num(); |
||||
|
// 获取执行中的任务
|
||||
|
List<SchBaseTask> unFinishTasksByTaskConfig = taskService.findUnFinishTasksByTaskConfig( |
||||
|
taskConfig.getConfig_code(), apply_point_code , taskConfig.getTask_direction()); |
||||
|
|
||||
|
Assert.isFalse(unFinishTasksByTaskConfig.size() >= tcmn, |
||||
|
"该点位申请的任务未完成数已超过上限,无法申请任务"); |
||||
|
// 获取对接位点位对象
|
||||
|
SchBasePoint pointObj = pointService.getOne(new LambdaQueryWrapper<SchBasePoint>() |
||||
|
.eq(SchBasePoint::getPoint_code, apply_point_code)); |
||||
|
// 校验是否需要自动agv
|
||||
|
if (!pointObj.getIs_auto()) { |
||||
|
// 如果不需要自动,则不创建任务
|
||||
|
return; |
||||
|
} |
||||
|
// 2、创建申请任务
|
||||
|
task.setConfig_code(config_code); |
||||
|
task.setCreate_mode(GeneralDefinition.ACS_CREATION); |
||||
|
task.setVehicle_code(schBasePoint.getVehicle_code()); |
||||
|
task.setVehicle_qty(schBasePoint.getVehicle_qty()); |
||||
|
task.setTask_status(TaskStatus.APPLY.getCode()); |
||||
|
task.setWorkshop_code(taskConfig.getWorkshop_code()); // 车间编码
|
||||
|
task.setPoint_code1(apply_point_code); |
||||
|
task.setTask_type("2"); |
||||
|
task.setPoint_code2(endPoint); |
||||
|
task.setTask_status(TaskStatus.CREATED.getCode()); |
||||
|
task.setRemark(""); |
||||
|
// 设置起/终点
|
||||
|
// this.setTaskPoint(taskConfig, task, apply_point_code);
|
||||
|
taskService.create(task); |
||||
|
|
||||
|
//下发
|
||||
|
this.renotifyAcs(task); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 修改任务状态 |
||||
|
* 1.任务完成时,无需再次组盘,将点位表起点货位三个组盘信息移动到终点 |
||||
|
* 2.组盘表中三个点位增加移动动作,并且修改当前点位到目标地点 |
||||
|
* 3. |
||||
|
* |
||||
|
* @param task_code |
||||
|
* @param status |
||||
|
* @return |
||||
|
*/ |
||||
|
@Override |
||||
|
// @Transactional(rollbackFor = Exception.class)
|
||||
|
protected void updateStatus(String task_code, TaskStatus status) { |
||||
|
// 校验任务
|
||||
|
SchBaseTask taskObj = taskService.getById(task_code); |
||||
|
if (taskObj.getTask_status().equals(TaskStatus.FINISHED.getCode())) { |
||||
|
throw new BadRequestException("该任务已完成!"); |
||||
|
} |
||||
|
if (taskObj.getTask_status().equals(TaskStatus.CANCELED.getCode())) { |
||||
|
throw new BadRequestException("该任务已取消!"); |
||||
|
} |
||||
|
String startPoint = taskObj.getPoint_code1().substring(0, taskObj.getPoint_code1().length() - 2); // 获取起点
|
||||
|
String endPoint = taskObj.getPoint_code2(); // 获取终点
|
||||
|
SchBasePoint startPointObj = pointService.getById(startPoint); |
||||
|
SchBasePoint endPointObj = pointService.getById(endPoint); |
||||
|
// 根据传来的类型去对任务进行操作
|
||||
|
if (status.equals(TaskStatus.EXECUTING)) { // 执行中
|
||||
|
taskObj.setTask_status(TaskStatus.EXECUTING.getCode()); |
||||
|
taskObj.setRemark("执行中"); |
||||
|
} |
||||
|
if (status.equals(TaskStatus.FINISHED)) { // 完成
|
||||
|
StringBuilder group_id = new StringBuilder(); |
||||
|
// 终点解锁
|
||||
|
endPointObj.setIng_task_code(""); |
||||
|
endPointObj.setVehicle_type(startPointObj.getVehicle_type()); |
||||
|
endPointObj.setVehicle_code(startPointObj.getVehicle_code()); |
||||
|
endPointObj.setVehicle_qty(startPointObj.getVehicle_qty()); |
||||
|
endPointObj.setUpdate_time(DateUtil.now()); |
||||
|
pointService.update(endPointObj); |
||||
|
// 起点清空
|
||||
|
if (ObjectUtil.isNotEmpty(startPointObj)) { |
||||
|
PointUtils.clearPoint(startPointObj); |
||||
|
} |
||||
|
// 任务完成
|
||||
|
taskObj.setTask_status(TaskStatus.FINISHED.getCode()); |
||||
|
taskObj.setGroup_id(group_id.toString()); |
||||
|
taskObj.setRemark("任务完成"); |
||||
|
} |
||||
|
if (status.equals(TaskStatus.CANCELED)) { // 取消
|
||||
|
// 终点解锁
|
||||
|
if (ObjectUtil.isNotEmpty(endPointObj)) { |
||||
|
endPointObj.setIng_task_code(""); |
||||
|
pointService.update(endPointObj); |
||||
|
} |
||||
|
taskObj.setRemark("任务取消"); |
||||
|
taskObj.setTask_status(TaskStatus.CANCELED.getCode()); |
||||
|
} |
||||
|
taskService.update(taskObj); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void forceFinish(String task_code) { |
||||
|
this.updateStatus(task_code, TaskStatus.FINISHED); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void cancel(String task_code) { |
||||
|
this.updateStatus(task_code, TaskStatus.CANCELED); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
protected void feedbackTaskState(JSONObject param, SchBaseTask schBaseTask, BaseResponse result) { |
||||
|
//无需重算最优点
|
||||
|
} |
||||
|
} |
Loading…
Reference in new issue