12 changed files with 562 additions and 130 deletions
@ -0,0 +1,174 @@ |
|||||
|
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.IStructattrService; |
||||
|
import org.nl.wms.basedata_manage.service.dao.Structattr; |
||||
|
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.AbstractTask; |
||||
|
import org.nl.wms.sch_manage.service.util.AcsTaskDto; |
||||
|
import org.nl.wms.sch_manage.service.util.TaskType; |
||||
|
import org.nl.wms.warehouse_management.enums.IOSEnum; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
|
||||
|
/** |
||||
|
* @Author: gbx |
||||
|
* @Description: 空载具入库任务 |
||||
|
* @Date: 2025/7/3 |
||||
|
*/ |
||||
|
@Component(value = "VehicleInTask") |
||||
|
@TaskType("VehicleInTask") |
||||
|
public class VehicleInTask extends AbstractTask { |
||||
|
|
||||
|
/** |
||||
|
* 任务服务类 |
||||
|
*/ |
||||
|
@Autowired |
||||
|
private ISchBaseTaskService taskService; |
||||
|
|
||||
|
/** |
||||
|
* 点位服务 |
||||
|
*/ |
||||
|
@Autowired |
||||
|
private ISchBasePointService iSchBasePointService; |
||||
|
|
||||
|
/** |
||||
|
* 仓位服务 |
||||
|
*/ |
||||
|
@Autowired |
||||
|
private IStructattrService iStructattrService; |
||||
|
|
||||
|
@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.CREATE.getCode()); |
||||
|
task.setConfig_code(json.getString("config_code")); |
||||
|
task.setPoint_code1(json.getString("point_code1")); |
||||
|
task.setPoint_code2(json.getString("point_code2")); |
||||
|
task.setVehicle_code(json.getString("vehicle_code")); |
||||
|
task.setRequest_param(json.toString()); |
||||
|
task.setPriority(json.getString("Priority")); |
||||
|
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.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("执行中"); |
||||
|
taskService.updateById(taskObj); |
||||
|
} |
||||
|
if (status.equals(TaskStatus.FINISHED)) { |
||||
|
this.finishTask(taskObj); |
||||
|
} |
||||
|
if (status.equals(TaskStatus.CANCELED)) { |
||||
|
this.cancelTask(taskObj); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@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 (Integer.parseInt(taskObj.getTask_status()) > Integer.parseInt(TaskStatus.CREATE.getCode())) { |
||||
|
throw new BadRequestException("只能取消生成中的任务!"); |
||||
|
} |
||||
|
this.cancelTask(taskObj); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void backMes(String task_code) { |
||||
|
} |
||||
|
|
||||
|
@Transactional |
||||
|
public void finishTask(SchBaseTask taskObj) { |
||||
|
// 更新终点
|
||||
|
iStructattrService.update( |
||||
|
new UpdateWrapper<Structattr>().lambda() |
||||
|
.eq(Structattr::getStruct_code, taskObj.getPoint_code2()) |
||||
|
.set(Structattr::getStoragevehicle_code, taskObj.getVehicle_code()) |
||||
|
.set(Structattr::getTaskdtl_id, null) |
||||
|
.set(Structattr::getLock_type, IOSEnum.LOCK_TYPE.code("未锁定")) |
||||
|
); |
||||
|
// 更新起点
|
||||
|
iSchBasePointService.update( |
||||
|
new UpdateWrapper<SchBasePoint>().lambda() |
||||
|
.eq(SchBasePoint::getPoint_code, taskObj.getPoint_code1()) |
||||
|
.set(SchBasePoint::getVehicle_code, null) |
||||
|
.set(SchBasePoint::getIos_id, null) |
||||
|
); |
||||
|
// 更新任务
|
||||
|
taskObj.setRemark("已完成"); |
||||
|
taskObj.setTask_status(TaskStatus.FINISHED.getCode()); |
||||
|
taskService.updateById(taskObj); |
||||
|
} |
||||
|
|
||||
|
@Transactional |
||||
|
public void cancelTask(SchBaseTask taskObj) { |
||||
|
// 更新终点
|
||||
|
iStructattrService.update( |
||||
|
new UpdateWrapper<Structattr>().lambda() |
||||
|
.eq(Structattr::getStruct_code, taskObj.getPoint_code2()) |
||||
|
.set(Structattr::getTaskdtl_id, null) |
||||
|
.set(Structattr::getLock_type, IOSEnum.LOCK_TYPE.code("未锁定")) |
||||
|
); |
||||
|
// 更新任务
|
||||
|
taskObj.setRemark("已取消"); |
||||
|
taskObj.setTask_status(TaskStatus.CANCELED.getCode()); |
||||
|
taskService.updateById(taskObj); |
||||
|
} |
||||
|
} |
@ -0,0 +1,166 @@ |
|||||
|
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 org.nl.common.exception.BadRequestException; |
||||
|
import org.nl.common.utils.SecurityUtils; |
||||
|
import org.nl.config.IdUtil; |
||||
|
import org.nl.wms.basedata_manage.enums.BaseDataEnum; |
||||
|
import org.nl.wms.sch_manage.enums.TaskStatus; |
||||
|
import org.nl.wms.sch_manage.service.ISchBaseTaskService; |
||||
|
import org.nl.wms.sch_manage.service.dao.SchBaseTask; |
||||
|
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.TaskType; |
||||
|
import org.nl.wms.warehouse_management.enums.IOSEnum; |
||||
|
import org.nl.wms.warehouse_management.service.IOutBillService; |
||||
|
import org.nl.wms.warehouse_management.service.dao.IOStorInvDis; |
||||
|
import org.nl.wms.warehouse_management.service.dao.mapper.IOStorInvDisMapper; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
|
||||
|
/** |
||||
|
* @Author: gbx |
||||
|
* @Description: 空载具出库任务 |
||||
|
* @Date: 2025/7/3 |
||||
|
*/ |
||||
|
@Component(value = "VehicleOutTask") |
||||
|
@TaskType("VehicleOutTask") |
||||
|
public class VehicleOutTask extends AbstractTask { |
||||
|
@Autowired |
||||
|
private ISchBaseTaskService taskService; |
||||
|
|
||||
|
@Resource |
||||
|
private IOutBillService outBillService; |
||||
|
|
||||
|
@Resource |
||||
|
private IOStorInvDisMapper ioStorInvDisMapper; |
||||
|
|
||||
|
@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.setVehicle_code(json.getString("vehicle_code")); |
||||
|
task.setGroup_id(json.getString("group_id")); |
||||
|
task.setRequest_param(json.toString()); |
||||
|
task.setPriority(json.getString("Priority")); |
||||
|
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()); |
||||
|
if (taskDao.getPoint_code2().contains("-")) { |
||||
|
acsTaskDto.setNext_device_code(taskDao.getPoint_code2().replace('-', '_')); |
||||
|
} |
||||
|
acsTaskDto.setPriority(taskDao.getPriority()); |
||||
|
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("执行中"); |
||||
|
taskService.updateById(taskObj); |
||||
|
} |
||||
|
if (status.equals(TaskStatus.FINISHED)) { |
||||
|
this.finishTask(taskObj); |
||||
|
} |
||||
|
if (status.equals(TaskStatus.CANCELED)) { |
||||
|
this.cancelTask(taskObj); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@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 backMes(String task_code) { |
||||
|
} |
||||
|
|
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void finishTask(SchBaseTask taskObj) { |
||||
|
// 任务完成
|
||||
|
taskObj.setTask_status(TaskStatus.FINISHED.getCode()); |
||||
|
taskObj.setRemark("已完成"); |
||||
|
taskService.updateById(taskObj); |
||||
|
outBillService.taskFinish(taskObj); |
||||
|
} |
||||
|
|
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
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()) |
||||
|
); |
||||
|
|
||||
|
//分配表清除任务
|
||||
|
ioStorInvDisMapper.update(new IOStorInvDis(),new LambdaUpdateWrapper<>(IOStorInvDis.class) |
||||
|
.set(IOStorInvDis::getTask_id,null) |
||||
|
.set(IOStorInvDis::getPoint_code,null) |
||||
|
.set(IOStorInvDis::getIs_issued,0) |
||||
|
.set(IOStorInvDis::getWork_status, IOSEnum.INBILL_DIS_STATUS.code("未生成")) |
||||
|
.eq(IOStorInvDis::getTask_id,taskObj.getTask_id()) |
||||
|
); |
||||
|
|
||||
|
// 更新任务状态
|
||||
|
taskObj.setTask_status(TaskStatus.CANCELED.getCode()); |
||||
|
taskObj.setRemark("已取消"); |
||||
|
taskService.updateById(taskObj); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue