任务结束 解绑

liweidong
liweidong-hj 1 month ago
parent 1ee98e6290
commit 8714355dfd
  1. 120
      blade-service/blade-desk/src/main/java/org/springblade/desk/logistics/service/impl/TaskExecuteRecordServiceImpl.java

@ -15,6 +15,7 @@ import org.springblade.core.tool.api.R;
import org.springblade.desk.logistics.constant.AgvConstant;
import org.springblade.desk.logistics.mapper.TaskExecuteRecordMapper;
import org.springblade.desk.logistics.pojo.dto.AGVCallBackDto;
import org.springblade.desk.logistics.pojo.dto.BoxBindingDto;
import org.springblade.desk.logistics.pojo.entity.*;
import org.springblade.desk.logistics.pojo.vo.AgvSchedulingTaskVO;
import org.springblade.desk.logistics.service.*;
@ -22,6 +23,7 @@ import org.springblade.desk.logistics.utils.AgvTaskTypeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -43,8 +45,7 @@ import static org.springblade.desk.logistics.pojo.entity.Station.DROPOFF_CONVEYO
*/
@Service
@Slf4j
public class TaskExecuteRecordServiceImpl extends BaseServiceImpl<TaskExecuteRecordMapper, TaskExecuteRecord> implements ITaskExecuteRecordService {
public class TaskExecuteRecordServiceImpl extends BaseServiceImpl<TaskExecuteRecordMapper, TaskExecuteRecord> implements ITaskExecuteRecordService {
@Autowired
@ -63,6 +64,9 @@ public class TaskExecuteRecordServiceImpl extends BaseServiceImpl<TaskExecuteRe
@Autowired
IVirtualShelvesService virtualShelvesService;
@Autowired
IOrderBindService iOrderBindService;
/**
* AGV小车任务状态回调接口
* <p>
@ -75,8 +79,8 @@ public class TaskExecuteRecordServiceImpl extends BaseServiceImpl<TaskExecuteRe
*
* @param agvCallBack AGV小车回调参数实体包含任务单号执行方法当前位置等信息
* @return R<?> 统一返回结果
* - 成功R.success()
* - 失败R.fail(错误信息)
* - 成功R.success()
* - 失败R.fail(错误信息)
*/
@Override
public R agvCallback(AGVCallBackDto agvCallBack) {
@ -123,7 +127,7 @@ public class TaskExecuteRecordServiceImpl extends BaseServiceImpl<TaskExecuteRe
}
// 4. 保存更新后的任务记录
log.info("agv回调接口位置记录,任务单号{}:起点位置{},终点位置{}",agvCallBack.getTaskCode(),taskExecuteRecord.getStartPos(),taskExecuteRecord.getEndPos()) ;
log.info("agv回调接口位置记录,任务单号{}:起点位置{},终点位置{}", agvCallBack.getTaskCode(), taskExecuteRecord.getStartPos(), taskExecuteRecord.getEndPos());
boolean updateResult = updateById(taskExecuteRecord);
if (!updateResult) {
log.error("AGV回调失败:任务单号{}的执行记录更新保存失败", agvCallBack.getTaskCode());
@ -135,45 +139,45 @@ public class TaskExecuteRecordServiceImpl extends BaseServiceImpl<TaskExecuteRe
log.info("任务单号{}已完成,准备调用东哥接口", agvCallBack.getTaskCode());
Long taskId = taskExecuteRecord.getTaskId();
if(null == taskId){
return R.fail("任务TaskId不存在"+taskId);
if (null == taskId) {
return R.fail("任务TaskId不存在" + taskId);
}
Task task = taskService.getById(taskId);
if(null == task){
if (null == task) {
return R.fail("任务Task不存在");
}
//释放虚拟货架
if(null != taskExecuteRecord.getVirtualShelvesCode()){
if (null != taskExecuteRecord.getVirtualShelvesCode()) {
VirtualShelves virtualShelves = virtualShelvesService.selectByVirtualShelvesCode(taskExecuteRecord.getVirtualShelvesCode());
if(null == virtualShelves){
if (null == virtualShelves) {
log.info("虚拟货架号不存在,无需释放:{}", taskExecuteRecord.getVirtualShelvesCode());
}else {
} else {
virtualShelves.setIsBound(VirtualShelves.BOUND_NO);
boolean update = virtualShelvesService.updateById(virtualShelves);
if(update){
if (update) {
log.info("虚拟货架号释放成功:{}", taskExecuteRecord.getVirtualShelvesCode());
}
}
}
log.info("当前Task状态为{},任务TaskCode为{}", task.getTaskStatus(),agvCallBack.getTaskCode());
log.info("当前Task状态为{},任务TaskCode为{}", task.getTaskStatus(), agvCallBack.getTaskCode());
//状态为暂存 需要调用
if(Task.STATUS_TEMPORARY_STORAGE.equals(task.getTaskStatus())){
if (Task.STATUS_TEMPORARY_STORAGE.equals(task.getTaskStatus())) {
//判断是否需要调用agv接口
boolean conAgvReturn = containerToAgv(agvCallBack.getTaskCode());
log.info("AGV小车接口调用返回值:{}",conAgvReturn);
log.info("AGV小车接口调用返回值:{}", conAgvReturn);
if (!conAgvReturn) {
return R.fail("AGV小车接口调用失败");
}
}
if(Task.STATUS_CONVEYOR_END.equals(task.getTaskStatus())){
if (Task.STATUS_CONVEYOR_END.equals(task.getTaskStatus())) {
//判断是否需要调用ctu接口
containerToCtu(agvCallBack.getTaskCode());
boolean conCtuReturn =containerToCtu(agvCallBack.getTaskCode());
log.info("CTU小车接口调用返回值:{}",conCtuReturn);
boolean conCtuReturn = containerToCtu(agvCallBack.getTaskCode());
log.info("CTU小车接口调用返回值:{}", conCtuReturn);
if (!conCtuReturn) {
return R.fail("CTU小车接口调用失败");
}
@ -190,13 +194,12 @@ public class TaskExecuteRecordServiceImpl extends BaseServiceImpl<TaskExecuteRe
}
@Override
public boolean boundVirtualShelves(String virtualShelvesCode, String stationCode) {
String url = "http://172.22.252.10:8181/rcms/services/rest/hikRpcService/bindPodAndBerth";
Map<String, Object> requestBody = new HashMap<>();
requestBody.put("reqCode", IdUtil.fastSimpleUUID());
requestBody.put("reqCode", IdUtil.fastSimpleUUID());
requestBody.put("podCode", virtualShelvesCode);
requestBody.put("positionCode", stationCode);
requestBody.put("podDir", "0");
@ -226,7 +229,7 @@ public class TaskExecuteRecordServiceImpl extends BaseServiceImpl<TaskExecuteRe
}
@Override
public AgvSchedulingTaskVO genAgvSchedulingTask(String taskTyp, String startPos, String endPos, String type,String virtualShelvesCode) {
public AgvSchedulingTaskVO genAgvSchedulingTask(String taskTyp, String startPos, String endPos, String type, String virtualShelvesCode) {
// 接口地址
String url = "http://172.22.252.10:8181/rcms/services/rest/hikRpcService/genAgvSchedulingTask";
@ -283,13 +286,13 @@ public class TaskExecuteRecordServiceImpl extends BaseServiceImpl<TaskExecuteRe
log.info("AGV调度任务创建成功,任务类型:{},任务单号:{},起始位置:{},目标位置:{}",
taskTyp, taskCode, startPos, endPos);
return AgvSchedulingTaskVO.success( taskCode, taskTyp, startPos, endPos, type);
return AgvSchedulingTaskVO.success(taskCode, taskTyp, startPos, endPos, type);
} else {
// code不等于0,输出错误信息
log.error("AGV调度任务创建失败,错误码:{},错误信息:{},任务类型:{},起始位置:{},目标位置:{}",
code, message, taskTyp, startPos, endPos);
return AgvSchedulingTaskVO.fail(code,message);
return AgvSchedulingTaskVO.fail(code, message);
}
} catch (Exception e) {
@ -300,15 +303,15 @@ public class TaskExecuteRecordServiceImpl extends BaseServiceImpl<TaskExecuteRe
}
@Override
public boolean inboundRecord(AgvSchedulingTaskVO agvSchedulingTaskVO, Task task,String virtualShelvesCode) {
if(null == agvSchedulingTaskVO ){
public boolean inboundRecord(AgvSchedulingTaskVO agvSchedulingTaskVO, Task task, String virtualShelvesCode) {
if (null == agvSchedulingTaskVO) {
return false;
}
if(null == task){
if (null == task) {
return false;
}
log.info("新增执行记录,taskCode:{},起始位置:{},终点位置:{}", agvSchedulingTaskVO.getTaskCode(), agvSchedulingTaskVO.getStartPos(),agvSchedulingTaskVO.getEndPos());
log.info("新增执行记录,taskCode:{},起始位置:{},终点位置:{}", agvSchedulingTaskVO.getTaskCode(), agvSchedulingTaskVO.getStartPos(), agvSchedulingTaskVO.getEndPos());
TaskExecuteRecord taskExecuteRecord = new TaskExecuteRecord();
taskExecuteRecord.setTaskId(task.getId());
taskExecuteRecord.setTaskCode(agvSchedulingTaskVO.getTaskCode());
@ -327,19 +330,19 @@ public class TaskExecuteRecordServiceImpl extends BaseServiceImpl<TaskExecuteRe
try {
// 1. 查询任务执行记录
TaskExecuteRecord taskExecuteRecord = baseMapper.selectByTaskCode(taskCode);
if(null == taskExecuteRecord){
if (null == taskExecuteRecord) {
log.error("未根据taskCode查询到有效数据,请求参数:{}", taskCode);
return false;
}
// 2. 查询任务
Task task = taskService.getById(taskExecuteRecord.getTaskId());
if(null == task){
if (null == task) {
log.error("查询不到Task数据,证明任务不存在,无需接续,请求参数:{}", taskExecuteRecord.getTaskId());
return true;
}
if(StringUtils.isEmpty(taskExecuteRecord.getEndPos())){
if (StringUtils.isEmpty(taskExecuteRecord.getEndPos())) {
log.error("任务执行记录的终点位置为空,taskCode:{}", taskCode);
return false;
}
@ -352,38 +355,47 @@ public class TaskExecuteRecordServiceImpl extends BaseServiceImpl<TaskExecuteRe
* 3.2 执行记录的终点是 站点
* 3.3 执行记录的终点是 输送线终点
*/
if(null == task.getLocationId() || null != station || DROPOFF_CONVEYOR_LINE.equals(taskExecuteRecord.getEndPos())){
if (null == task.getLocationId() || null != station || DROPOFF_CONVEYOR_LINE.equals(taskExecuteRecord.getEndPos())) {
log.info("任务{}不需要送到库位,直接完成", taskCode);
log.info("终点位置为站点信息:{},直接完成",taskExecuteRecord.getEndPos());
log.info("终点位置为站点信息:{},直接完成", taskExecuteRecord.getEndPos());
// 直接更新任务状态为完成
task.setTaskStatus(Task.STATUS_FINISHED);
boolean taskUpdate = taskService.updateById(task);
if(taskUpdate){
String boxBarcode = task.getBoxBarcode();
//解绑
if (boxBarcode != null && !boxBarcode.trim().isEmpty()) {
BoxBindingDto boxBindingDto = new BoxBindingDto();
boxBindingDto.setBoxBarcode(boxBarcode);
R ret = iOrderBindService.boxUnbind(boxBindingDto);
}
if (taskUpdate) {
log.info("Task状态修改成功,taskCode:{}", taskCode);
return true;
} else {
log.error("Task状态修改失败,taskCode:{}", taskCode);
return false;
}
}
// 4. 查询目标库位信息
Location location = locationService.getById(task.getLocationId());
if(null == location){
if (null == location) {
log.error("根据locationId未查询到位置信息,locationId:{}", task.getLocationId());
return false;
}
// 5. 校验必要参数
if(StringUtils.isEmpty(task.getBoxBarcode())){
if (StringUtils.isEmpty(task.getBoxBarcode())) {
log.error("任务箱码为空,taskCode:{}", taskCode);
return false;
}
// 6. 生成CTU调度任务
AgvSchedulingTaskVO ctuSchedulingTask = genCtuSchedulingTask(
AgvConstant.CTU_TASK_TYP,
@ -394,14 +406,14 @@ public class TaskExecuteRecordServiceImpl extends BaseServiceImpl<TaskExecuteRe
AgvConstant.EQUIPMENT_TYPE_CTU
);
if(!ctuSchedulingTask.getCode().equals("0")){
if (!ctuSchedulingTask.getCode().equals("0")) {
log.error("生成CTU调度任务失败,taskCode:{}", taskCode);
return false;
}
// 7. 添加入库记录
boolean record = inboundRecord(ctuSchedulingTask, task,null);
if(!record){
boolean record = inboundRecord(ctuSchedulingTask, task, null);
if (!record) {
log.error("添加入库记录失败,taskCode:{}", taskCode);
return false;
}
@ -409,7 +421,7 @@ public class TaskExecuteRecordServiceImpl extends BaseServiceImpl<TaskExecuteRe
// 8. 所有操作成功后,更新任务状态
task.setTaskStatus(Task.STATUS_TEMPORARY_STORAGE);
boolean taskUpdate = taskService.updateById(task);
if(!taskUpdate){
if (!taskUpdate) {
log.error("Task状态修改失败,但CTU调度已成功,taskCode:{}", taskCode);
}
@ -417,16 +429,16 @@ public class TaskExecuteRecordServiceImpl extends BaseServiceImpl<TaskExecuteRe
// 9.将库位状态设置为占用
location.setLocationStatus(Location.STATUS_OCCUPIED);
boolean updateLocation = locationService.updateById(location);
if(!updateLocation){
if (!updateLocation) {
log.error("库位状态修改失败,但CTU调度已成功,库位:{}", location.getId());
}
// 10.将梳齿架子状态修改为空闲
Location location1 = locationService.selectByLocationCode(taskExecuteRecord.getEndPos(), 1);
location1.setLocationStatus(Location.STATUS_FREE);
boolean updateLocation1 = locationService.updateById(location1);
if(updateLocation1){
if (updateLocation1) {
log.info("梳齿架子状态修改成功:{}", taskExecuteRecord.getEndPos());
}else {
} else {
log.error("梳齿架子状态修改失败:{}", taskExecuteRecord.getEndPos());
}
@ -442,10 +454,9 @@ public class TaskExecuteRecordServiceImpl extends BaseServiceImpl<TaskExecuteRe
}
@Override
public AgvSchedulingTaskVO genCtuSchedulingTask(String taskTyp, String ctnrTyp, String ctnrCode,
String startPos, String endPos, String type) {
String startPos, String endPos, String type) {
// 接口地址
String url = "http://172.22.252.10:8181/rcms/services/rest/hikRpcService/genAgvSchedulingTask";
@ -502,12 +513,12 @@ public class TaskExecuteRecordServiceImpl extends BaseServiceImpl<TaskExecuteRe
if ("0".equals(code)) {
log.info("CTU调度任务创建成功,任务类型:{},任务单号:{},容器编号:{},起始位置:{},目标位置:{}",
taskTyp, taskCode, ctnrCode, startPos, endPos);
return AgvSchedulingTaskVO.success(taskCode,taskTyp,startPos,endPos,type);
return AgvSchedulingTaskVO.success(taskCode, taskTyp, startPos, endPos, type);
} else {
// code不等于0,输出错误信息
log.error("CTU调度任务创建失败,错误码:{},错误信息:{},任务类型:{},容器编号:{},起始位置:{},目标位置:{}",
code, message, taskTyp, ctnrCode, startPos, endPos);
return AgvSchedulingTaskVO.fail(code,message);
return AgvSchedulingTaskVO.fail(code, message);
}
} catch (Exception e) {
@ -538,7 +549,7 @@ public class TaskExecuteRecordServiceImpl extends BaseServiceImpl<TaskExecuteRe
// 3. 查询任务
Task task = taskService.getById(taskExecuteRecord.getTaskId());
if(null == task){
if (null == task) {
log.error("查询不到Task数据,证明任务不存在,无需接续,请求参数:{}", taskExecuteRecord.getTaskId());
return true;
}
@ -555,7 +566,7 @@ public class TaskExecuteRecordServiceImpl extends BaseServiceImpl<TaskExecuteRe
if (null == location) {
log.info("根据终点位置未查询到位置信息,endPos:{}", endPos);
log.info("不需要调再次调用AGV小车,整体任务到此结束");
log.info("进行解绑");
return true;
}
@ -609,8 +620,8 @@ public class TaskExecuteRecordServiceImpl extends BaseServiceImpl<TaskExecuteRe
location.setLocationStatus(Location.STATUS_FREE);
boolean locationUpdate = locationService.updateById(location);
if(locationUpdate){
log.info("梳齿架状态修改为空闲:{}",location.getLocationCode());
if (locationUpdate) {
log.info("梳齿架状态修改为空闲:{}", location.getLocationCode());
}
} else {
@ -628,11 +639,12 @@ public class TaskExecuteRecordServiceImpl extends BaseServiceImpl<TaskExecuteRe
/**
* 生成请求唯一标识
*
* @return 唯一标识
*/
private String generateReqCode() {
// 使用Hutool的IdUtil生成唯一ID
return IdUtil.fastSimpleUUID();
return IdUtil.fastSimpleUUID();
}
@Override
@ -651,7 +663,7 @@ public class TaskExecuteRecordServiceImpl extends BaseServiceImpl<TaskExecuteRe
);
if (!shelves) {
throw new ServiceException("站点绑定虚拟货架失败");
}else {
} else {
virtualShelves.setIsBound(VirtualShelves.BOUND_YES);
virtualShelvesService.updateById(virtualShelves);
}
@ -673,7 +685,7 @@ public class TaskExecuteRecordServiceImpl extends BaseServiceImpl<TaskExecuteRe
return false;
}
boolean record = inboundRecord(agvSchedulingTaskVO, task,virtualShelves.getVirtualShelvesCode());
boolean record = inboundRecord(agvSchedulingTaskVO, task, virtualShelves.getVirtualShelvesCode());
if (!record) {
throw new ServiceException("入库记录保存失败");
}

Loading…
Cancel
Save