刘先源
1 week ago
3 changed files with 169 additions and 0 deletions
@ -0,0 +1,146 @@ |
|||||
|
package org.nl.wms.sch.task_manage.task.tasks.fj; |
||||
|
|
||||
|
import cn.hutool.core.date.DateUtil; |
||||
|
import cn.hutool.core.util.ObjectUtil; |
||||
|
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.ext.mes.service.WmsToMesService; |
||||
|
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_manage.AbstractTask; |
||||
|
import org.nl.wms.sch.task_manage.AcsTaskDto; |
||||
|
import org.nl.wms.sch.task_manage.GeneralDefinition; |
||||
|
import org.nl.wms.sch.task_manage.enums.TaskFinishedTypeEnum; |
||||
|
import org.nl.wms.sch.task_manage.task.TaskType; |
||||
|
import org.nl.wms.sch.task_manage.task.core.TaskStatus; |
||||
|
import org.nl.wms.util.TaskUtils; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
|
||||
|
/** |
||||
|
* @Author: lxy |
||||
|
* @Description: 移库公共类 |
||||
|
* @Date: 2024/9/24 |
||||
|
*/ |
||||
|
@Component(value = "PUBMOVETask") |
||||
|
@TaskType("PUBMOVETask") |
||||
|
public class PUBMOVETask extends AbstractTask { |
||||
|
@Autowired |
||||
|
private ISchBaseTaskService taskService; |
||||
|
|
||||
|
@Autowired |
||||
|
private ISchBaseTaskconfigService taskConfigService; |
||||
|
|
||||
|
@Autowired |
||||
|
private WmsToMesService wmsToMesService; |
||||
|
|
||||
|
@Override |
||||
|
public String create(JSONObject json) { |
||||
|
SchBaseTask task = new SchBaseTask(); |
||||
|
task.setTask_id(IdUtil.getStringId()); |
||||
|
task.setTask_code(json.getString("TaskCode")); |
||||
|
task.setTask_status(TaskStatus.CREATE.getCode()); |
||||
|
task.setConfig_code(json.getString("task_type")); |
||||
|
task.setPoint_code1(json.getString("PickingLocation")); |
||||
|
task.setPoint_code2(json.getString("PlacedLocation")); |
||||
|
task.setRequest_param(json.toString()); |
||||
|
task.setPriority(json.getString("Priority")); |
||||
|
task.setIs_vehicle(json.getString("IsPanCode")); |
||||
|
task.setCreate_id(SecurityUtils.getCurrentUserId()); |
||||
|
task.setCreate_name(SecurityUtils.getCurrentNickName()); |
||||
|
task.setCreate_time(DateUtil.now()); |
||||
|
taskService.save(task); |
||||
|
return task.getTask_id(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public AcsTaskDto sendAcsParam(String taskId) { |
||||
|
SchBaseTask taskDao = taskService.getById(taskId); |
||||
|
|
||||
|
// 组织下发给acs的数据
|
||||
|
AcsTaskDto acsTaskDto = new AcsTaskDto(); |
||||
|
acsTaskDto.setExt_task_uuid(taskDao.getTask_id()); |
||||
|
acsTaskDto.setTask_code(taskDao.getTask_code()); |
||||
|
acsTaskDto.setStart_device_code(taskDao.getPoint_code1()); |
||||
|
acsTaskDto.setNext_device_code(taskDao.getPoint_code2()); |
||||
|
acsTaskDto.setPriority(taskDao.getPriority()); |
||||
|
acsTaskDto.setIs_vehicle(taskDao.getIs_vehicle()); |
||||
|
acsTaskDto.setTask_type("1"); |
||||
|
|
||||
|
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("执行中"); |
||||
|
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 backMes(String task_code) { |
||||
|
wmsToMesService.receiveTaskStatusMesData(taskService.getByCode(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, 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); |
||||
|
} |
||||
|
|
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void finishTask(SchBaseTask taskObj, TaskFinishedTypeEnum taskFinishedType) { |
||||
|
// 任务完成
|
||||
|
taskObj.setTask_status(TaskStatus.FINISHED.getCode()); |
||||
|
taskObj.setRemark(GeneralDefinition.TASK_FINISH); |
||||
|
taskObj.setFinished_type(taskFinishedType.getCode()); |
||||
|
TaskUtils.setUpdateByType(taskObj, taskFinishedType); |
||||
|
taskService.updateById(taskObj); |
||||
|
|
||||
|
// 通知mes任务完成
|
||||
|
wmsToMesService.receiveTaskStatusMesData(taskObj); |
||||
|
} |
||||
|
|
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void cancelTask(SchBaseTask taskObj, TaskFinishedTypeEnum taskFinishedType) { |
||||
|
taskObj.setRemark(GeneralDefinition.TASK_CANCEL); |
||||
|
taskObj.setTask_status(TaskStatus.CANCELED.getCode()); |
||||
|
taskObj.setFinished_type(taskFinishedType.getCode()); |
||||
|
TaskUtils.setUpdateByType(taskObj, taskFinishedType); |
||||
|
taskService.updateById(taskObj); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue