|
|
@ -1,5 +1,6 @@ |
|
|
|
package org.nl.acs.ext.wms.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
@ -9,8 +10,10 @@ import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.SneakyThrows; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.nl.acs.agv.AgvUtil; |
|
|
|
import org.nl.acs.config.AcsConfig; |
|
|
|
import org.nl.acs.agv.server.XianGongAgvService; |
|
|
|
import org.nl.acs.device.service.DeviceService; |
|
|
|
import org.nl.acs.ext.UnifiedResponse; |
|
|
|
import org.nl.acs.ext.wms.data.ResultTaskMesDto; |
|
|
|
import org.nl.acs.ext.wms.data.wmsToAcsData.createTask.CreateTaskRequest; |
|
|
|
import org.nl.acs.ext.wms.data.wmsToAcsData.createTask.CreateTaskResponse; |
|
|
|
import org.nl.acs.ext.wms.service.WmsToAcsService; |
|
|
@ -24,18 +27,17 @@ import org.nl.acs.route.service.RouteLineService; |
|
|
|
import org.nl.acs.route.service.dto.RouteLineDto; |
|
|
|
import org.nl.acs.task.service.TaskService; |
|
|
|
import org.nl.acs.task.service.dto.TaskDto; |
|
|
|
import org.nl.modules.common.exception.BadRequestException; |
|
|
|
import org.nl.modules.common.utils.SecurityUtils; |
|
|
|
import org.nl.modules.lucene.service.LuceneExecuteLogService; |
|
|
|
import org.nl.modules.lucene.service.dto.LuceneLogDto; |
|
|
|
import org.nl.modules.quartz.task.DeviceStatusMonitor; |
|
|
|
import org.nl.modules.system.service.ParamService; |
|
|
|
import org.nl.modules.system.service.impl.ParamServiceImpl; |
|
|
|
import org.nl.modules.wql.WQL; |
|
|
|
import org.nl.modules.wql.core.bean.WQLObject; |
|
|
|
import org.nl.modules.wql.exception.WDKException; |
|
|
|
import org.nl.modules.wql.util.SpringContextHolder; |
|
|
|
import org.slf4j.MDC; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.http.HttpStatus; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
@ -49,6 +51,12 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { |
|
|
|
private final DeviceService DeviceService; |
|
|
|
private final RouteLineService RouteLineService; |
|
|
|
private final DeviceAppService deviceAppService; |
|
|
|
@Autowired |
|
|
|
private InstructionService instructionServiceTwo; |
|
|
|
@Autowired |
|
|
|
private XianGongAgvService agvService; |
|
|
|
@Autowired |
|
|
|
private XianGongAgvService xianGongAgvService; |
|
|
|
|
|
|
|
private String log_file_type = "log_file_type"; |
|
|
|
private String log_type = "WMS下发ACS"; |
|
|
@ -291,49 +299,50 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, Object> cancelFromWms(String param) throws Exception { |
|
|
|
@Transactional |
|
|
|
public JSONObject cancelFromWms(JSONObject jsonWhere) throws Exception { |
|
|
|
log.info("cancelFromWms - 请求参数 {}", jsonWhere.toString()); |
|
|
|
JSONObject result = new JSONObject(); |
|
|
|
|
|
|
|
InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); |
|
|
|
Instruction instDto = instructionService.findByTaskCode(jsonWhere.getString("TaskCode")); |
|
|
|
|
|
|
|
try { |
|
|
|
MDC.put(log_file_type, log_type); |
|
|
|
JSONArray tasks = JSONArray.parseArray(param); |
|
|
|
ParamService acsConfigService = SpringContextHolder.getBean(ParamServiceImpl.class); |
|
|
|
InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); |
|
|
|
log.debug(tasks.toString()); |
|
|
|
log.info("cancelFromWms - 请求参数 {}", tasks.toString()); |
|
|
|
for (int i = 0; i < tasks.size(); i++) { |
|
|
|
JSONObject task = tasks.getJSONObject(i); |
|
|
|
String task_uuid = task.getString("task_id"); |
|
|
|
String task_code = task.getString("task_code"); |
|
|
|
String vehicle_code = task.getString("vehicle_code"); |
|
|
|
String params = task.getString("params"); |
|
|
|
|
|
|
|
if (StrUtil.isEmpty(task_uuid)) { |
|
|
|
throw new WDKException("任务标识不能为空"); |
|
|
|
} |
|
|
|
if (StrUtil.isEmpty(task_code)) { |
|
|
|
throw new WDKException("任务号不能为空"); |
|
|
|
} |
|
|
|
String cancelTaskCheck = acsConfigService.findByCode(AcsConfig.CANCEL_TASK_CHECK).getValue(); |
|
|
|
if (StrUtil.equals(cancelTaskCheck, "1")) { |
|
|
|
TaskService.cancel(task_uuid); |
|
|
|
} else if (StrUtil.equals(cancelTaskCheck, "0")) { |
|
|
|
Instruction inst = instructionService.findByTaskCode(task_code); |
|
|
|
if (inst == null) { |
|
|
|
TaskService.cancel(task_uuid); |
|
|
|
} else { |
|
|
|
throw new RuntimeException("指令正在执行中,操作失败!"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (ObjectUtil.isEmpty(instDto)) { |
|
|
|
throw new BadRequestException("找不到对应任务号"+jsonWhere.getString("TaskCode")); |
|
|
|
} |
|
|
|
// 取消指令
|
|
|
|
String currentUsername = SecurityUtils.getCurrentUsername(); |
|
|
|
String now = DateUtil.now(); |
|
|
|
instDto.setUpdate_time(now); |
|
|
|
instDto.setUpdate_by(currentUsername); |
|
|
|
instDto.setInstruction_status("3"); |
|
|
|
instructionService.update(instDto); |
|
|
|
// 取消任务
|
|
|
|
TaskDto taskDto = TaskService.findByCode(instDto.getTask_code()); |
|
|
|
taskDto.setUpdate_time(now); |
|
|
|
taskDto.setUpdate_by(currentUsername); |
|
|
|
taskDto.setTask_status("3"); |
|
|
|
TaskService.updateTwo(taskDto); |
|
|
|
|
|
|
|
// 判断是否下发成功
|
|
|
|
if (instDto.getSend_status().equals("1")) { |
|
|
|
// 调用XG接口通知删除
|
|
|
|
JSONObject json = new JSONObject(); |
|
|
|
json.put("releaseSite",1); |
|
|
|
json.put("taskRecordId",instDto.getInstruction_code()); |
|
|
|
xianGongAgvService.stopTask(json); |
|
|
|
} |
|
|
|
JSONObject resultJson = new JSONObject(); |
|
|
|
resultJson.put("status", HttpStatus.OK); |
|
|
|
resultJson.put("message", "操作成功"); |
|
|
|
resultJson.put("data", new JSONObject()); |
|
|
|
log.info("cancelFromWms - 返回参数 {}", resultJson.toString()); |
|
|
|
return resultJson; |
|
|
|
} finally { |
|
|
|
MDC.remove(log_file_type); |
|
|
|
} catch (Exception e) { |
|
|
|
result.put("status", HttpStatus.BAD_REQUEST.value()); |
|
|
|
result.put("message", e.getMessage()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
result.put("status", HttpStatus.OK.value()); |
|
|
|
result.put("message", "操作成功"); |
|
|
|
log.info("cancelFromWms - 返回参数 {}", result.toString()); |
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -390,4 +399,61 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { |
|
|
|
resp.put("data", data); |
|
|
|
return resp; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public JSONObject SearchTasks() { |
|
|
|
// 需返回mes集合
|
|
|
|
List<ResultTaskMesDto> mesDtoList = new ArrayList<>(); |
|
|
|
// 获取当前所有任务
|
|
|
|
List<TaskDto> taskList = TaskService.findReadyAllTask(); |
|
|
|
// 获取当前所有内存指令
|
|
|
|
List<Instruction> instructionList = instructionServiceTwo.findAllInstFromCache(); |
|
|
|
// 调用接口查看任务状态
|
|
|
|
for (Instruction dto : instructionList) { |
|
|
|
String TaskStatus = "创建"; |
|
|
|
String ExecutingAGV = ""; |
|
|
|
|
|
|
|
// 等于就绪状态就不调用接口
|
|
|
|
if (dto.getSend_status().equals("1")) { |
|
|
|
UnifiedResponse<JSONObject> resp = agvService.queryXZAgvInstStatusByCode(dto.getInstruction_code(), JSONObject.class); |
|
|
|
// 状态
|
|
|
|
String state = resp.getData().getString("state"); |
|
|
|
if ("RUNNING".equals(state) || "TOBEDISPATCHED".equals(state) || "WAITING".equals(state)) { |
|
|
|
TaskStatus = "执行中"; |
|
|
|
} |
|
|
|
// 车号
|
|
|
|
ExecutingAGV = resp.getData().getString("vehicle"); |
|
|
|
} |
|
|
|
|
|
|
|
// 组织数据
|
|
|
|
TaskDto taskDto = taskList.stream() |
|
|
|
.filter(row -> row.getTask_code().equals(dto.getTask_code())) |
|
|
|
.findFirst().orElse(null); |
|
|
|
if (ObjectUtil.isEmpty(taskDto)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
// mes起点终点为空则不返回
|
|
|
|
if (ObjectUtil.isEmpty(taskDto.getStart_parent_code()) || ObjectUtil.isEmpty(taskDto.getNext_parent_code())) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
ResultTaskMesDto mesDto = ResultTaskMesDto.builder() |
|
|
|
.TaskCode(taskDto.getTask_code()) |
|
|
|
.PickingLocation(taskDto.getStart_parent_code()) |
|
|
|
.PlacedLocation(taskDto.getNext_parent_code()) |
|
|
|
.TaskStatus(TaskStatus) |
|
|
|
.ExecutingAGV(ExecutingAGV) |
|
|
|
.CreateTime(taskDto.getCreate_time()) |
|
|
|
.ExecuteTime(taskDto.getUpdate_time()) |
|
|
|
.build(); |
|
|
|
mesDtoList.add(mesDto); |
|
|
|
} |
|
|
|
// 返回结果
|
|
|
|
JSONObject result = new JSONObject(); |
|
|
|
result.put("ReturnStatus", 0); |
|
|
|
result.put("MsgTime", DateUtil.now()); |
|
|
|
result.put("TaskList", mesDtoList); |
|
|
|
log.info("SearchTasks - 返回参数 {}", result.toString()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|