rev:修改
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
|
||||
package org.nl.acs.ext.kit.rest;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author ludj
|
||||
* @date 2021-07-21
|
||||
**/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/wms")
|
||||
@Slf4j
|
||||
public class AcsToKitController {
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
|
||||
package org.nl.acs.ext.kit.rest;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.ext.kit.service.KitToAcsService;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.common.logging.annotation.Log;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "acs套件回传接口")
|
||||
@RequestMapping("/api/kitToAcs")
|
||||
@Slf4j
|
||||
public class KitToAcsController {
|
||||
|
||||
@Autowired
|
||||
private KitToAcsService kitToAcsService;
|
||||
|
||||
|
||||
@SaIgnore
|
||||
@PostMapping("/agvCallback")
|
||||
@Log("kit->ACS")
|
||||
public ResponseEntity<Object> agvCallback(@RequestParam Map<String,Object> kitToAcsParam) throws Exception{
|
||||
JSONObject param = null;
|
||||
if (kitToAcsParam == null || CollectionUtils.isEmpty(kitToAcsParam)){
|
||||
throw new BadRequestException("请求参数不能为空");
|
||||
}
|
||||
for (String o : kitToAcsParam.keySet()) {
|
||||
param = JSONObject.parseObject(o);
|
||||
}
|
||||
log.info("---kit上报请求---"+param.toString());
|
||||
System.out.println("---kit上报请求---"+param.toString());
|
||||
return new ResponseEntity<>(kitToAcsService.agvCallback(param), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.nl.acs.ext.kit.service;
|
||||
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import org.nl.acs.instruction.domain.Instruction;
|
||||
|
||||
public interface AcsToKitService {
|
||||
HttpResponse genAgvSchedulingTask(Instruction instruction, int type);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.nl.acs.ext.kit.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
public interface KitToAcsService {
|
||||
|
||||
/**
|
||||
* NDC反馈状态
|
||||
* @param requestParam
|
||||
* @return
|
||||
*/
|
||||
JSONObject agvCallback(JSONObject requestParam) throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package org.nl.acs.ext.kit.service.impl;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.AcsConfig;
|
||||
import org.nl.acs.address.service.AddressService;
|
||||
import org.nl.acs.device.service.DeviceService;
|
||||
import org.nl.acs.device.service.impl.DeviceServiceImpl;
|
||||
import org.nl.acs.ext.kit.service.AcsToKitService;
|
||||
import org.nl.acs.instruction.domain.Instruction;
|
||||
import org.nl.config.MapOf;
|
||||
import org.nl.config.SpringContextHolder;
|
||||
import org.nl.config.lucene.enums.LogDirectEnum;
|
||||
import org.nl.config.lucene.enums.LogLevelEnum;
|
||||
import org.nl.config.lucene.enums.LogTypeEnum;
|
||||
import org.nl.config.lucene.service.LuceneExecuteLogService;
|
||||
import org.nl.config.lucene.service.dto.LuceneLogDto;
|
||||
import org.nl.system.service.param.ISysParamService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class AcsToKitServiceImpl implements AcsToKitService {
|
||||
@Autowired
|
||||
private ISysParamService paramService;
|
||||
@Autowired
|
||||
private LuceneExecuteLogService luceneExecuteLogService;
|
||||
@Autowired
|
||||
AddressService addressService;
|
||||
|
||||
public static Map<String,String> TYPE_MAP = MapOf.of(3,"下发任务",9,"取消任务",10,"取放货应答");
|
||||
|
||||
/**
|
||||
* 生成任务单
|
||||
*
|
||||
* @param instruction
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public HttpResponse genAgvSchedulingTask(Instruction instruction, int type) {
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("receiver", "NDC");
|
||||
jo.put("sender", "ACS");
|
||||
jo.put("type", type);
|
||||
JSONObject ja = new JSONObject();
|
||||
long start = System.currentTimeMillis();
|
||||
//type 3:下发任务
|
||||
if (type==3) {
|
||||
ja.put("taskId", Integer.valueOf(instruction.getInstruction_code()));
|
||||
DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class);
|
||||
int startAddress = deviceService.queryAddressBydeviceCode(instruction.getStart_point_code());
|
||||
int nextAddress = deviceService.queryAddressBynextdeviceCode(instruction.getNext_point_code());
|
||||
ja.put("pickId", startAddress);
|
||||
ja.put("pickName", instruction.getStart_point_code());
|
||||
ja.put("releaseId", nextAddress);
|
||||
ja.put("releaseName", instruction.getNext_point_code());
|
||||
ja.put("taskType", 5);
|
||||
ja.put("vehicleId", 0);
|
||||
ja.put("priority", 0);
|
||||
jo.put("params", ja);
|
||||
}
|
||||
//34 9:取消任务
|
||||
else if (type==9){
|
||||
ja.put("taskId", Integer.valueOf(instruction.getInstruction_code()));
|
||||
jo.put("params", ja);
|
||||
}
|
||||
//type 10:取放货请求应答
|
||||
else if (type==10){
|
||||
ja.put("taskId", Integer.valueOf(instruction.getInstruction_code()));
|
||||
ja.put("taskPhase", Integer.valueOf(instruction.getExecute_status()));
|
||||
ja.put("height", 0);
|
||||
ja.put("offset", instruction.getOffSet());
|
||||
ja.put("location_name", instruction.getOffSetName());
|
||||
jo.put("params", ja);
|
||||
}
|
||||
String wmsurl = paramService.findByCode(AcsConfig.WCSURL).getValue();
|
||||
String url = wmsurl;
|
||||
log.info("任务号:{},指令号{},下发agv订单序列下发:{}", instruction.getTask_code(), instruction.getInstruction_code(), JSON.toJSONString(jo));
|
||||
LuceneLogDto logDto =
|
||||
LuceneLogDto.builder()
|
||||
.log(LogLevelEnum.INFO, LogTypeEnum.接口请求, LogDirectEnum.ACS_TO_KIT)
|
||||
.request(wmsurl,"genAgvSchedulingTask","反馈NDC套件",JSON.toJSONString(jo),start)
|
||||
.content("开始请求NDC"+TYPE_MAP.get(type))
|
||||
.build();
|
||||
luceneExecuteLogService.interfaceExecuteLog(logDto);
|
||||
HttpResponse result = null;
|
||||
try {
|
||||
result = HttpRequest.post(url)
|
||||
//表单内容
|
||||
.body(String.valueOf(jo))
|
||||
//超时,毫秒
|
||||
.timeout(8000)
|
||||
.execute();
|
||||
LuceneLogDto end =
|
||||
LuceneLogDto.builder()
|
||||
.log(LogLevelEnum.INFO, LogTypeEnum.接口响应, LogDirectEnum.ACS_TO_KIT)
|
||||
.request(wmsurl,"genAgvSchedulingTask","反馈NDC套件",JSON.toJSONString(jo),start)
|
||||
.content("NDC请求完成"+TYPE_MAP.get(type))
|
||||
.response(result, HttpStatus.OK,System.currentTimeMillis()-start)
|
||||
.build();
|
||||
luceneExecuteLogService.interfaceExecuteLog(end);
|
||||
log.info("任务号:{},指令号{},状态{},下发agv订单序列反馈:{}", instruction.getTask_code(), instruction.getInstruction_code(), result.getStatus(), result.body());
|
||||
}catch (Exception ex){
|
||||
LuceneLogDto error =
|
||||
LuceneLogDto.builder()
|
||||
.log(LogLevelEnum.ERROR, LogTypeEnum.接口响应, LogDirectEnum.ACS_TO_KIT)
|
||||
.request(wmsurl,"genAgvSchedulingTask","反馈NDC套件",JSON.toJSONString(jo),start)
|
||||
.content("NDC请求失败:"+ex.getMessage())
|
||||
.response(result, HttpStatus.BAD_REQUEST,System.currentTimeMillis()-start)
|
||||
.build();
|
||||
luceneExecuteLogService.interfaceExecuteLog(error);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
package org.nl.acs.ext.kit.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.device.domain.Device;
|
||||
import org.nl.acs.device_driver.DeviceDriver;
|
||||
import org.nl.acs.ext.kit.enums.MsgTypeEnum;
|
||||
import org.nl.acs.ext.kit.enums.TaskPhaseEnum;
|
||||
import org.nl.acs.ext.kit.enums.TaskStateEnum;
|
||||
import org.nl.acs.ext.kit.service.KitToAcsService;
|
||||
import org.nl.acs.instruction.domain.Instruction;
|
||||
import org.nl.acs.instruction.enums.InstructionStatusEnum;
|
||||
import org.nl.acs.instruction.service.InstructionService;
|
||||
import org.nl.acs.opc.DeviceAppService;
|
||||
import org.nl.acs.storage_cell.service.StorageCellService;
|
||||
import org.nl.acs.storage_cell.service.dto.StorageCellDto;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class KitToAcsServiceImpl implements KitToAcsService {
|
||||
@Autowired
|
||||
private InstructionService instructionService;
|
||||
@Autowired
|
||||
private StorageCellService storageCellService;
|
||||
@Autowired
|
||||
private DeviceAppService deviceAppService;
|
||||
|
||||
@Override
|
||||
public JSONObject agvCallback(JSONObject requestParam) throws Exception{
|
||||
JSONObject resp = new JSONObject();
|
||||
Integer type = requestParam.getInteger("type");
|
||||
JSONObject params = requestParam.getJSONObject("params");
|
||||
//任务状态上报
|
||||
if (MsgTypeEnum.TASK_STATE_RPT.getValue().equals(type)) {
|
||||
String instTaskId = params.getString("taskId");
|
||||
String taskPhase = params.getString("taskPhase");
|
||||
String taskState = params.getString("taskState");
|
||||
String taskPoint = params.getString("taskPoint");//请求进入/离开需要上报站点号
|
||||
if (StrUtil.isEmpty(taskPhase)){
|
||||
resp.put("code", "400");
|
||||
resp.put("message", "taskPhase参数异常");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
Instruction instruction = instructionService.findByCodeFromCache(instTaskId);
|
||||
if (ObjectUtil.isEmpty(instruction)) {
|
||||
instruction = instructionService.findByCode(instTaskId);
|
||||
if (ObjectUtil.isEmpty(instruction)){
|
||||
resp.put("code", "400");
|
||||
resp.put("message", "请求失败,任务信息不存在,指令号:" + instTaskId);
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
instructionService.reload();
|
||||
}
|
||||
|
||||
//taskPhase 任务取消
|
||||
if (TaskStateEnum.CANCELED.getValue().equals(taskState)){
|
||||
instructionService.cancel(instruction.getInstruction_id());
|
||||
resp.put("code", "200");
|
||||
resp.put("message", "取消任务成功");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
Device device = null;
|
||||
TaskPhaseEnum taskPhaseEnum = TaskPhaseEnum.fromPhase(taskPhase);
|
||||
switch (taskPhaseEnum){
|
||||
case ENTER_REQUEST_OR_ALLOWED:
|
||||
case LEAVE_NOTICE_OR_ALLOWED:
|
||||
StorageCellDto storageCellDto = storageCellService.findByAddress(taskPoint);
|
||||
if (ObjectUtil.isEmpty(storageCellDto)) {
|
||||
resp.put("code", "400");
|
||||
resp.put("message", "请求失败,点位信息不存在,点位站点号:" + taskPoint);
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
device = deviceAppService.findDeviceByCode(storageCellDto.getStorage_code());
|
||||
if (ObjectUtil.isEmpty(device)) {
|
||||
resp.put("code", "400");
|
||||
resp.put("message", "请求失败,请求位置编号不存在!");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
DeviceDriver deviceDriver = device.getDeviceDriver();
|
||||
deviceDriver.setDeviceInnerParam(instTaskId,taskPhase);
|
||||
break;
|
||||
case PICKUP_REQUEST_OR_RESPONSE:
|
||||
case PICKUP_COMPLETE:
|
||||
case RELEASE_REQUEST_OR_RESPONSE:
|
||||
case RELEASE_COMPLETE:
|
||||
if (TaskPhaseEnum.PICKUP_REQUEST_OR_RESPONSE.getValue().equals(taskPhase) || TaskPhaseEnum.PICKUP_COMPLETE.getValue().equals(taskPhase)){
|
||||
device = deviceAppService.findDeviceByCode(instruction.getStart_point_code());
|
||||
}
|
||||
//taskPhase 请求放货上报,放货完成上报
|
||||
if (TaskPhaseEnum.RELEASE_REQUEST_OR_RESPONSE.getValue().equals(taskPhase)||TaskPhaseEnum.RELEASE_COMPLETE.getValue().equals(taskPhase)){
|
||||
device = deviceAppService.findDeviceByCode(instruction.getNext_point_code());
|
||||
}
|
||||
if (device == null){
|
||||
resp.put("code", "400");
|
||||
resp.put("message", "点位驱动不存在");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
device.getDeviceDriver().setDeviceInnerParam(instTaskId,taskPhase);
|
||||
if (!taskPhase.equals(instruction.getExecute_status())){
|
||||
instruction.setExecute_status(taskPhase);
|
||||
instructionService.update(instruction);
|
||||
}
|
||||
//taskPhase 任务完成
|
||||
if (TaskStateEnum.COMPLETED.getValue().equals(taskState)){
|
||||
resp.put("code", "200");
|
||||
resp.put("message", "完成任务成功");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
resp.put("code", "400");
|
||||
resp.put("message", "taskPhase值不存在");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
resp.put("code", "200");
|
||||
resp.put("message", taskPhaseEnum.getDescription()+"处理完毕");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
//任务分配车辆上报
|
||||
else if (MsgTypeEnum.AGV_ID_RPT.getValue().equals(type)){
|
||||
String taskId = params.getString("taskId");
|
||||
String agvId = params.getString("agvId");
|
||||
Instruction instruction = instructionService.findByCodeFromCache(taskId);
|
||||
if (ObjectUtil.isEmpty(instruction)) {
|
||||
resp.put("code", "400");
|
||||
resp.put("message", "请求失败,任务信息不存在,指令号:" + taskId);
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
//更新车号
|
||||
instruction.setCarno(agvId);
|
||||
instruction.setInstruction_status(InstructionStatusEnum.BUSY.getCode());
|
||||
instruction.setUpdate_time(DateUtil.now());
|
||||
instructionService.update(instruction);
|
||||
resp.put("code", "200");
|
||||
resp.put("message", "更新车号成功");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
else if (MsgTypeEnum.TASK_RUN_RPT.getValue().equals(type)){
|
||||
System.out.println("------");
|
||||
resp.put("code", "200");
|
||||
resp.put("message", "更新车号成功");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
//车辆任务生成上报
|
||||
else if (MsgTypeEnum.TASK_INDEX_RPT.getValue().equals(type)){
|
||||
String taskId = params.getString("taskId");
|
||||
Instruction instruction = instructionService.findByCodeFromCache(taskId);
|
||||
if (ObjectUtil.isEmpty(instruction)) {
|
||||
resp.put("code", "400");
|
||||
resp.put("message", "请求失败,任务信息不存在,指令号:" + taskId);
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
//修改指令状态执行中
|
||||
instruction.setInstruction_status(InstructionStatusEnum.BUSY.getCode());
|
||||
instruction.setUpdate_time(DateUtil.now());
|
||||
instructionService.update(instruction);
|
||||
resp.put("code", "200");
|
||||
resp.put("message", "更新指令执行中成功");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
else if (MsgTypeEnum.AGV_POWER_RPT.getValue().equals(type)){
|
||||
int agvId = params.getIntValue("agvId");
|
||||
int stateValue = params.getIntValue("stateValue");
|
||||
resp.put("code", "200");
|
||||
resp.put("message", "更新指令执行中成功");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
else if (MsgTypeEnum.AGV_STATE_RPT.getValue().equals(type)){
|
||||
int agvId = params.getIntValue("agvId");
|
||||
int stateValue = params.getIntValue("stateValue");
|
||||
int xLocation = params.getIntValue("xLocation");
|
||||
int yLocation = params.getIntValue("yLocation");
|
||||
int angle = params.getIntValue("angle");
|
||||
int speed = params.getIntValue("speed");
|
||||
resp.put("code", "200");
|
||||
resp.put("message", "更新指令执行中成功");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
else if (MsgTypeEnum.AGV_ERROR_RPT.getValue().equals(type)){
|
||||
int agvId = params.getIntValue("agvId");
|
||||
int errorCode = params.getIntValue("errState");
|
||||
resp.put("code", "200");
|
||||
resp.put("message", "更新指令执行中成功");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
resp.put("code", "400");
|
||||
resp.put("message", type+"type类型未定义");
|
||||
log.info("---响应kit请求---"+resp.toString());
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.nl.config.lucene.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum LogDirectEnum {
|
||||
MES_TO_ACS,
|
||||
WMS_TO_ACS,
|
||||
KIT_TO_ACS,
|
||||
TO_ACS,
|
||||
ACS_TO_HJX,
|
||||
ACS_TO_MES,
|
||||
ACS_TO_KIT,
|
||||
ACS_TO_WMS;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.nl.config.lucene.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum LogLevelEnum {
|
||||
INFO(1),
|
||||
WARN(2),
|
||||
ERROR(3);
|
||||
|
||||
private Integer code;
|
||||
|
||||
LogLevelEnum(Integer i) {
|
||||
this.code=i;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user