修改废箔称重业务

This commit is contained in:
USER-20220102CG\noblelift
2024-05-30 09:52:13 +08:00
parent 6ff9f9221d
commit ff8d323008

View File

@@ -578,20 +578,31 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
try {
//称重完成
if (StrUtil.equals("1", type)) {
wasteFoilWeighingStationDriver.writing("to_command", "6");
Thread.sleep(1000); //休眠1秒
if (wasteFoilWeighingStationDriver.getMode() == 6) {
jo.put("currentWeight", wasteFoilWeighingStationDriver.getWeight());//当前重量
jo.put("lastWeight", wasteFoilWeighingStationDriver.getGap_weight());//上一次重量
jo.put("weightGap", wasteFoilWeighingStationDriver.getOld_weight());//重量
wasteFoilWeighingStationDriver.writing("to_command", "6");
while (true) {
if (wasteFoilWeighingStationDriver.getMode()==6){
jo.put("currentWeight", wasteFoilWeighingStationDriver.getWeight());//当前重量
jo.put("lastWeight", wasteFoilWeighingStationDriver.getGap_weight());//上一次重量
jo.put("weightGap", wasteFoilWeighingStationDriver.getOld_weight());//重量差
break;
}
}
wasteFoilWeighingStationDriver.writing("to_command", "0");
}
//称重确认信号
else if (StrUtil.equals("2", type)) {
wasteFoilWeighingStationDriver.writing("to_command", "7");
Thread.sleep(1000); //休眠1秒
if (wasteFoilWeighingStationDriver.getMode() == 7) {
wasteFoilWeighingStationDriver.writing("to_command", "8");
while (true) {
if (wasteFoilWeighingStationDriver.getMode()==7){
jo.put("currentWeight", wasteFoilWeighingStationDriver.getWeight());//当前重量
jo.put("lastWeight", wasteFoilWeighingStationDriver.getGap_weight());//上一次重量
jo.put("weightGap", wasteFoilWeighingStationDriver.getOld_weight());//重量差
break;
}
}
wasteFoilWeighingStationDriver.writing("to_command", "0");
}
} catch (InterruptedException e) {
e.printStackTrace();
@@ -821,953 +832,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
public JSONObject notifyAcs(JSONObject param) {
return null;
}
/**
private final ApplicationContext applicationContext;
private final InstructionService instructionService;
private final TaskService taskService;
private final DeviceService deviceService;
private final DeviceAppService deviceAppService;
private final RouteLineService routeLineService;
private final AcsToLiKuService acsToLiKuService;
private final DictDetailService dictDetailService;
private final DictService dictService;
private String log_file_type = "log_file_type";
private String log_type = "LMS请求ACS";
@Override public CancelTaskResponse cancelFromWms(String param) throws Exception {
ParamService paramService = SpringContextHolder.getBean(ParamService.class);
InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class);
JSONArray datas = JSONArray.parseArray(param);
CancelTaskResponse response = new CancelTaskResponse();
JSONArray errArr = new JSONArray();
for (int i = 0; i < datas.size(); i++) {
String data = datas.get(i).toString();
CancelTaskRequest request = JsonUtl.format(param, CancelTaskRequest.class);
String task_uuid = request.getExt_task_id();
String task_code = request.getTask_code();
String vehicle_code = request.getVehicle_code();
if (StrUtil.isEmpty(task_uuid)) {
throw new WDKException("任务标识不能为空");
}
if (StrUtil.isEmpty(task_code)) {
throw new WDKException("任务号不能为空");
}
String cancelTaskCheck = paramService.findByCode(AcsConfig.CANCELTASKCHECK).getValue();
if (StrUtil.equals(cancelTaskCheck, CommonFinalParam.ONE)) {
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(errArr)) {
response.setStatus(200);
} else {
response.setStatus(400);
}
response.setMessage("success");
response.setErrArr(errArr);
log.info("cancelFromWms--------------:输出参数:" + response);
return response;
}
@Override public Map<String, Object> updateDeviceGoodsFromWms(String param) {
JSONArray datas = JSONArray.parseArray(param);
log.info("updateDeviceGoodsFromWms--------------:输入参数" + datas.toString());
for (int i = 0; i < datas.size(); i++) {
JSONObject data = datas.getJSONObject(i);
String device_code = data.getString("point_code");
String has_goods = data.getString("has_goods");
JSONObject jo = new JSONObject();
jo.put("device_code", device_code);
jo.put("hasGoodStatus", has_goods);
deviceService.changeDeviceStatus(jo);
}
JSONObject resultJson = new JSONObject();
resultJson.put("status", HttpStatus.OK);
resultJson.put("message", "操作成功");
resultJson.put("data", new JSONObject());
log.info("updateDeviceGoodsFromWms--------------:输出参数" + resultJson.toString());
return resultJson;
}
@Override public Map<String, Object> areaControl(JSONObject form) {
String device_code = form.getString("device_code");
String type = form.getString("type");
Device device = deviceAppService.findDeviceByCode(device_code);
JSONObject resultJson = new JSONObject();
resultJson.put("status", HttpStatus.OK);
resultJson.put("message", "操作成功");
resultJson.put("data", new JSONObject());
log.info("updateDeviceGoodsFromWms--------------:输出参数" + resultJson.toString());
return resultJson;
}
@Override public PutActionResponse putAction(String jsonObject) throws Exception {
try {
MDC.put(log_file_type, log_type);
log.info("putAction--------------:输出参数" + jsonObject);
JSONArray datas = JSONArray.parseArray(jsonObject);
PutActionResponse response = new PutActionResponse();
JSONArray errArr = new JSONArray();
for (int i = 0; i < datas.size(); i++) {
String data = datas.get(i).toString();
PutActionRequest request = JsonUtl.format(data, PutActionRequest.class);
String device_code = request.getDevice_code();
String code = request.getCode();
String value = request.getValue();
Device device = deviceAppService.findDeviceByCode(device_code);
if (ObjectUtil.isEmpty(device)) {
throw new Exception("未找到对应设备:" + device_code);
}
HongXiangStationDeviceDriver hongXiangStationDeviceDriver;
LampThreecolorDeviceDriver lampThreecolorDeviceDriver;
if (device.getDeviceDriver() instanceof HongXiangStationDeviceDriver) {
hongXiangStationDeviceDriver = (HongXiangStationDeviceDriver) device.getDeviceDriver();
hongXiangStationDeviceDriver.writing(code, value);
}
if (device.getDeviceDriver() instanceof LampThreecolorDeviceDriver) {
lampThreecolorDeviceDriver = (LampThreecolorDeviceDriver) device.getDeviceDriver();
lampThreecolorDeviceDriver.writing(code, value);
}
}
JSONObject resultJson = new JSONObject();
resultJson.put("status", HttpStatus.OK.value());
resultJson.put("message", "操作成功");
resultJson.put("data", backja);
// log.info("queryDevice--------------:输出参数" + resultJson.toString());
return resultJson;
} finally {
MDC.remove(log_file_type);
}
}
@Override public Map<String, Object> queryDeviceDBValue(String whereJson) {
JSONArray datas = JSONArray.parseArray(whereJson);
log.info("orderStatusUpdate--------------:输入参数" + datas.toString());
JSONObject map = new JSONObject();
if (datas.size() > 0) {
for (int i = 0; i < datas.size(); i++) {
JSONObject jsonObject = datas.getJSONObject(i);
String device_code = jsonObject.getString("device_code");
String dbName = jsonObject.getString("DB");
Device device = deviceAppService.findDeviceByCode(device_code);
List<DeviceExtraManageDto> extra = device.getExtra();
for (int j = 0; j < extra.size(); j++) {
DeviceExtraManageDto deviceExtraManageDto = extra.get(j);
String deviceCode = deviceExtraManageDto.getDevice_code();
String extra_name = deviceExtraManageDto.getExtra_name();
if (deviceCode.equals(device_code) && extra_name.equals(dbName)) {
String extra_code = deviceExtraManageDto.getExtra_code();
String[] split = extra_code.split("\\.");
extra_code = split[split.length - 1];
extra_code = extra_code.substring(0, 1).toUpperCase() + extra_code.substring(1);
IDriverService driverService = applicationContext.getBean(device.getDeviceDriverDefination().getDriverCode(), IDriverService.class);
Integer dbValue = driverService.getDbValue(device, extra_code);
map.put(dbName, dbValue);
break;
}
}
}
}
JSONObject resultJson = new JSONObject();
resultJson.put("status", HttpStatus.OK);
resultJson.put("message", "操作成功");
resultJson.put("data", map);
return resultJson;
}
@Override public Map<String, Object> querydevice(String whereJson) {
return null;
}
@Override public Map<String, Object> putPlusPullAction(String param) {
try {
MDC.put(log_file_type, log_type);
log.info("putPlusPullAction-----输入参数{}", param);
JSONObject jo = JSON.parseObject(param);
String device_code = jo.getString("device_code");
String size = jo.getString("size");
String type = jo.getString("type");
Device device = deviceAppService.findDeviceByCode(device_code);
if (ObjectUtil.isEmpty(device)) {
JSONObject resultJson = new JSONObject();
resultJson.put("status", HttpStatus.BAD_REQUEST.value());
resultJson.put("message", "未找到对应的设备:" + device_code);
return resultJson;
}
PlugPullDeviceSiteDeviceDriver plugPullDeviceSiteDeviceDriver;
if (device.getDeviceDriver() instanceof PlugPullDeviceSiteDeviceDriver) {
plugPullDeviceSiteDeviceDriver = (PlugPullDeviceSiteDeviceDriver) device.getDeviceDriver();
// 0 穿轴 1拔轴
if (StrUtil.equals(type, CommonFinalParam.ONE)) {
if (plugPullDeviceSiteDeviceDriver.getMode() == 1) {
JSONObject resultJson = new JSONObject();
resultJson.put("status", HttpStatus.BAD_REQUEST.value());
resultJson.put("message", "请求拔轴,当前设备工作模式未自动");
return resultJson;
}
if (plugPullDeviceSiteDeviceDriver.getAction() == 0) {
JSONObject resultJson = new JSONObject();
resultJson.put("status", HttpStatus.BAD_REQUEST.value());
resultJson.put("message", "请求拔轴,当前设备未全自动");
return resultJson;
}
if (plugPullDeviceSiteDeviceDriver.getStatus() != 0) {
JSONObject resultJson = new JSONObject();
resultJson.put("status", HttpStatus.BAD_REQUEST.value());
resultJson.put("message", "请求拔轴,当前设备未待机");
return resultJson;
}
if (plugPullDeviceSiteDeviceDriver.getControl() != 0) {
JSONObject resultJson = new JSONObject();
resultJson.put("status", HttpStatus.BAD_REQUEST.value());
resultJson.put("message", "请求拔轴,当前设备未远程控制");
return resultJson;
}
if (plugPullDeviceSiteDeviceDriver.getMove() != 0) {
JSONObject resultJson = new JSONObject();
resultJson.put("status", HttpStatus.BAD_REQUEST.value());
resultJson.put("message", "请求拔轴,当前设备有轴");
return resultJson;
}
if (plugPullDeviceSiteDeviceDriver.getMode() == 0 && plugPullDeviceSiteDeviceDriver.getAction() == 1
&& plugPullDeviceSiteDeviceDriver.getStatus() == 0 && plugPullDeviceSiteDeviceDriver.getMove() == 0
&& plugPullDeviceSiteDeviceDriver.getControl() == 0) {
List list = new ArrayList();
Map map = new HashMap();
map.put("code", "to_size");
map.put("value", size);
list.add(map);
Map map2 = new HashMap();
map2.put("code", "to_type");
map2.put("value", type);
list.add(map2);
Map map3 = new HashMap();
map3.put("code", "to_command");
map3.put("value", "1");
list.add(map3);
plugPullDeviceSiteDeviceDriver.writing(list);
} else {
JSONObject resultJson = new JSONObject();
resultJson.put("status", HttpStatus.BAD_REQUEST.value());
resultJson.put("message", "当前设备状态不满足下发条件");
return resultJson;
}
} else if (StrUtil.equals(type, "0")) {
if (plugPullDeviceSiteDeviceDriver.getMode() == 1) {
JSONObject resultJson = new JSONObject();
resultJson.put("status", HttpStatus.BAD_REQUEST.value());
resultJson.put("message", "请求插轴,当前设备工作模式未自动");
return resultJson;
}
if (plugPullDeviceSiteDeviceDriver.getAction() == 0) {
JSONObject resultJson = new JSONObject();
resultJson.put("status", HttpStatus.BAD_REQUEST.value());
resultJson.put("message", "请求插轴,当前设备未全自动");
return resultJson;
}
if (plugPullDeviceSiteDeviceDriver.getStatus() != 0) {
JSONObject resultJson = new JSONObject();
resultJson.put("status", HttpStatus.BAD_REQUEST.value());
resultJson.put("message", "请求插轴,当前设备未待机");
return resultJson;
}
if (plugPullDeviceSiteDeviceDriver.getControl() != 0) {
JSONObject resultJson = new JSONObject();
resultJson.put("status", HttpStatus.BAD_REQUEST.value());
resultJson.put("message", "请求插轴,当前设备未远程控制");
return resultJson;
}
if (plugPullDeviceSiteDeviceDriver.getMove() != 1) {
JSONObject resultJson = new JSONObject();
resultJson.put("status", HttpStatus.BAD_REQUEST.value());
resultJson.put("message", "请求插轴,当前设备没有轴");
return resultJson;
}
if (plugPullDeviceSiteDeviceDriver.getMode() == 0 && plugPullDeviceSiteDeviceDriver.getAction() == 1
&& plugPullDeviceSiteDeviceDriver.getStatus() == 0 && plugPullDeviceSiteDeviceDriver.getMove() == 1
&& plugPullDeviceSiteDeviceDriver.getControl() == 0) {
List list = new ArrayList();
Map map = new HashMap();
map.put("code", "to_size");
map.put("value", size);
list.add(map);
Map map2 = new HashMap();
map2.put("code", "to_type");
map2.put("value", type);
list.add(map2);
Map map3 = new HashMap();
map3.put("code", "to_command");
map3.put("value", CommonFinalParam.ONE);
list.add(map3);
plugPullDeviceSiteDeviceDriver.writing(list);
} else {
JSONObject resultJson = new JSONObject();
resultJson.put("status", HttpStatus.BAD_REQUEST.value());
resultJson.put("message", "当前设备状态不满足下发条件");
return resultJson;
}
}
}
JSONObject resultJson = new JSONObject();
resultJson.put("status", HttpStatus.OK.value());
resultJson.put("message", "操作成功");
log.info("putPlusPullAction--------------:输出参数" + resultJson.toString());
return resultJson;
} finally {
MDC.remove(log_file_type);
}
}
@Override public CreateTaskResponse crateTask(String param) {
try {
MDC.put(log_file_type, log_type);
log.info("crateTask-----输入参数{}", param);
JSONArray datas = JSONArray.parseArray(param);
CreateTaskResponse response = new CreateTaskResponse();
ParamService paramService = SpringContextHolder.getBean(ParamService.class);
String cancelTaskCheck = paramService.findByCode(AcsConfig.ISALLOWTASK).getValue();
JSONArray errArr = new JSONArray();
if (StrUtil.equals(cancelTaskCheck, "0")) {
response.setStatus(400);
response.setMessage("ACS系统需要更新请稍等");
response.setErrArr(datas);
return response;
}
for (int i = 0; i < datas.size(); i++) {
String data = datas.get(i).toString();
CreateTaskRequest request = JsonUtl.format(data, CreateTaskRequest.class);
String paper_array = request.getPaper_array();
String ext_task_id = request.getExt_task_id();
String task_code = request.getTask_code();
String start_device_code = request.getStart_device_code();
String start_device_code2 = request.getStart_device_code2();
String next_device_code = request.getNext_device_code();
String next_device_code2 = request.getNext_device_code2();
String put_device_code = request.getPut_device_code();
String priority = request.getPriority();
String vehicle_code = request.getVehicle_code();
String vehicle_type = request.getVehicle_type();
String route_plan_code = request.getRoute_plan_code();
String task_type = request.getTask_type();
String truss_type = request.getTruss_type();
String is_bushing = request.getIs_bushing();
String version = request.getVersion();
String bushing_num = request.getBushing_num();
String storage_task_type = request.getDtl_type();
String agv_system_type = request.getAgv_system_type();
String remark = request.getRemark();
double oven_time = 0.00d;
if (StrUtil.isNotEmpty(request.getOven_time())) {
oven_time = Double.parseDouble(request.getOven_time());
}
String temperature = request.getTemperature();
String start_height = request.getStart_height();
String next_height = request.getNext_height();
Map<String, String> params = request.getParams();
String start_point_code = "";
String start_point_code2 = "";
String next_point_code = "";
String next_point_code2 = "";
String put_point_code = "";
if (StrUtil.isEmpty(task_code)) {
JSONObject json = new JSONObject();
json.put("task_code", task_code);
json.put("ext_task_id", ext_task_id);
json.put("message", "任务号不能为空");
errArr.add(json);
continue;
}
if (StrUtil.isEmpty(start_device_code)) {
JSONObject json = new JSONObject();
json.put("task_code", task_code);
json.put("ext_task_id", ext_task_id);
json.put("message", "起点不能为空");
errArr.add(json);
continue;
}
if (StrUtil.isEmpty(next_device_code)) {
JSONObject json = new JSONObject();
json.put("task_code", task_code);
json.put("ext_task_id", ext_task_id);
json.put("message", "终点不能为空");
errArr.add(json);
continue;
}
if (StrUtil.equals(task_type, "8")) {
next_device_code = request.getPut_device_code();
put_device_code = request.getNext_device_code();
}
JSONObject start_device_json = WQLObject.getWQLObject("acs_storage_cell").query("parent_storage_code ='" + start_device_code + "'").uniqueResult(0);
if (!ObjectUtil.isEmpty(start_device_json)) {
start_point_code = (String) start_device_json.get("parent_storage_code") == null ? start_device_code : (String) start_device_json.get("storage_code");
}
JSONObject next_device_json = WQLObject.getWQLObject("acs_storage_cell").query("parent_storage_code ='" + next_device_code + "'").uniqueResult(0);
if (!ObjectUtil.isEmpty(next_device_json)) {
next_point_code = (String) next_device_json.get("parent_storage_code") == null ? next_point_code : (String) next_device_json.get("storage_code");
}
JSONObject start_device_json2 = WQLObject.getWQLObject("acs_storage_cell").query("parent_storage_code ='" + start_device_code2 + "'").uniqueResult(0);
if (!ObjectUtil.isEmpty(start_device_json2)) {
start_point_code2 = (String) start_device_json2.get("parent_storage_code") == null ? start_device_code2 : (String) start_device_json2.get("storage_code");
}
JSONObject next_device_json2 = WQLObject.getWQLObject("acs_storage_cell").query("parent_storage_code ='" + next_device_code2 + "'").uniqueResult(0);
if (!ObjectUtil.isEmpty(next_device_json2)) {
next_point_code2 = (String) next_device_json2.get("parent_storage_code") == null ? next_device_code2 : (String) next_device_json2.get("storage_code");
}
JSONObject put_device_json = WQLObject.getWQLObject("acs_storage_cell").query("parent_storage_code ='" + put_device_code + "'").uniqueResult(0);
if (!ObjectUtil.isEmpty(put_device_json)) {
put_point_code = (String) put_device_json.get("parent_storage_code") == null ? put_device_code : (String) put_device_json.get("storage_code");
}
if (StrUtil.isNotEmpty(start_point_code) && start_point_code.indexOf("-") > 0) {
String str[] = start_point_code.split("-");
start_device_code = str[0];
} else {
start_device_code = start_point_code;
}
if (StrUtil.isNotEmpty(next_point_code) && next_point_code.indexOf("-") > 0) {
String str[] = next_point_code.split("-");
next_device_code = str[0];
} else {
next_device_code = next_point_code;
}
if (StrUtil.isNotEmpty(start_point_code2) && start_point_code2.indexOf("-") > 0) {
String str[] = start_point_code2.split("-");
start_device_code2 = str[0];
} else {
start_device_code2 = start_point_code2;
}
if (StrUtil.isNotEmpty(next_point_code2) && next_point_code2.indexOf("-") > 0) {
String str[] = next_point_code2.split("-");
next_device_code2 = str[0];
} else {
next_device_code2 = next_point_code2;
}
if (StrUtil.isNotEmpty(put_point_code) && put_point_code.indexOf("-") > 0) {
String str[] = put_point_code.split("-");
put_device_code = str[0];
} else {
put_device_code = put_point_code;
}
if (StrUtil.isEmpty(route_plan_code)) {
route_plan_code = "normal";
}
if (StrUtil.equals(task_type, "5")) {
Device device = deviceAppService.findDeviceByCode(next_device_code);
SiemensConveyorDeviceDriver siemensConveyorDeviceDriver;
if (device.getDeviceDriver() instanceof SiemensConveyorDeviceDriver) {
siemensConveyorDeviceDriver = (SiemensConveyorDeviceDriver) device.getDeviceDriver();
if (ObjectUtil.equal("true", siemensConveyorDeviceDriver.getExtraValue().get("inspect_in_stock"))) {
if (siemensConveyorDeviceDriver.getMove() == 1) {
JSONObject json = new JSONObject();
json.put("task_code", task_code);
json.put("ext_task_id", ext_task_id);
json.put("message", "终点" + siemensConveyorDeviceDriver.getDevice_code() + "有货无法生成任务");
errArr.add(json);
continue;
}
}
}
if (taskService.querySameDeviceReadyTask(start_device_code, next_device_code, "0") > 1) {
JSONObject json = new JSONObject();
json.put("task_code", task_code);
json.put("ext_task_id", ext_task_id);
json.put("message", "已存在相同的起点:" + start_device_code + "终点:" + next_device_code + "未执行的输送任务");
errArr.add(json);
continue;
}
}
TaskDto taskDto = taskService.findByCodeFromCache(task_code);
if (taskDto != null) {
JSONObject json = new JSONObject();
json.put("task_code", task_code);
json.put("ext_task_id", ext_task_id);
json.put("message", "存在相同的任务号:" + task_code);
errArr.add(json);
continue;
}
if (!StrUtil.isEmpty(vehicle_code)) {
TaskDto vehicle_dto = taskService.findByContainer(vehicle_code);
if (vehicle_dto != null) {
JSONObject json = new JSONObject();
json.put("task_code", task_code);
json.put("ext_task_id", ext_task_id);
json.put("message", "已存在任务编号为" + vehicle_dto.getTask_code() + "托盘号:" + vehicle_code);
errArr.add(json);
continue;
}
}
if (StrUtil.isEmpty(start_point_code)) {
JSONObject json = new JSONObject();
json.put("task_code", task_code);
json.put("ext_task_id", ext_task_id);
json.put("message", request.getStart_device_code() + " 该设备号未找到对应点位");
errArr.add(json);
continue;
}
if (StrUtil.isEmpty(next_point_code)) {
JSONObject json = new JSONObject();
json.put("task_code", task_code);
json.put("ext_task_id", ext_task_id);
json.put("message", request.getNext_device_code() + " 该设备号未找到对应点位");
errArr.add(json);
continue;
}
JSONObject jo = new JSONObject();
jo.put("task_id", IdUtil.simpleUUID());
jo.put("task_code", task_code);
jo.put("start_point_code", start_point_code);
jo.put("next_point_code", next_point_code);
jo.put("start_point_code2", start_point_code2);
jo.put("next_point_code2", next_point_code2);
jo.put("put_point_code", put_point_code);
jo.put("start_parent_code", start_point_code);
jo.put("next_parent_code", next_point_code);
jo.put("start_device_code", start_device_code);
jo.put("next_device_code", next_device_code);
jo.put("start_device_code2", start_device_code2);
jo.put("next_device_code2", next_device_code2);
jo.put("put_device_code", put_device_code);
jo.put("priority", priority);
jo.put("vehicle_code", vehicle_code);
jo.put("vehicle_type", vehicle_type);
jo.put("storage_task_type", storage_task_type);
jo.put("agv_system_type", agv_system_type);
jo.put("start_height", start_height);
jo.put("next_height", next_height);
jo.put("oven_time", (int) Math.ceil(oven_time));
jo.put("remark", remark);
jo.put("params", params);
jo.put("task_type", StrUtil.isEmpty(task_type) ? 1 : Integer.parseInt(task_type));
jo.put("paper_array", JSONUtil.toJsonStr(paper_array));
jo.put("truss_type", JSONUtil.toJsonStr(truss_type));
jo.put("is_bushing", JSONUtil.toJsonStr(is_bushing));
jo.put("version", JSONUtil.toJsonStr(version));
jo.put("bushing_num", JSONUtil.toJsonStr(bushing_num));
if (!StrUtil.isEmpty(ext_task_id)) {
jo.put("ext_task_id", ext_task_id);
}
TaskDto task_dto = jo.toJavaObject(TaskDto.class);
try {
// task_type=7 则是立库任务需要下刻下发
if (StrUtil.equals(task_dto.getTask_type(), "7")) {
//创建临时指令 不创建、不生成
//等立库反馈成功才能创建任务和指令
Instruction inst = null;
try {
inst = taskService.createTemporaryInst(task_dto);
} catch (Exception e) {
JSONObject json = new JSONObject();
json.put("task_code", task_code);
json.put("ext_task_id", ext_task_id);
json.put("message", "起始点:"+ task_dto.getStart_point_code() + ",终点:"+
task_dto.getNext_point_code()+",条码:" + task_dto.getVehicle_code() +
"," + e.getMessage());
errArr.add(json);
continue;
}
Resp resp = acsToLiKuService.sendInst(task_dto.getStorage_task_type(), inst);
if (StrUtil.equals(resp.result, "true")) {
//创建任务和指令
taskService.create(task_dto);
inst.setSend_status(CommonFinalParam.ONE);
taskService.extCreateInst(inst);
} else {
JSONObject json = new JSONObject();
json.put("task_code", task_code);
json.put("ext_task_id", ext_task_id);
json.put("message", resp.getComment());
json.put("code", resp.code);
json.put("data", data);
errArr.add(json);
continue;
}
} else {
taskService.create(task_dto);
}
} catch (Exception e) {
// e.printStackTrace();
JSONObject json = new JSONObject();
json.put("task_code", task_code);
json.put("ext_task_id", ext_task_id);
json.put("message", e.getMessage());
errArr.add(json);
continue;
}
}
if (ObjectUtil.isEmpty(errArr)) {
response.setStatus(200);
response.setMessage("success");
} else {
response.setStatus(400);
if (ObjectUtil.isNotEmpty(errArr)) {
response.setMessage(errArr.getJSONObject(0).getString("message"));
} else {
response.setMessage("false");
}
response.setErrArr(errArr);
}
log.info("createFromWms--------------:输出参数:" + JSON.toJSONString(response));
return response;
} finally {
MDC.remove(log_file_type);
}
}
@Override public Map<String, Object> unLock(String param) {
try {
MDC.put(log_file_type, log_type);
log.info("unLock--------------:输入参数" + param);
JSONObject jo = JSONObject.parseObject(param);
String task_code = String.valueOf(jo.get("task_code"));
if (StrUtil.isEmpty(task_code)) {
throw new BadRequestException("任务号不能为空");
}
String device_code = String.valueOf(jo.get("device_code"));
if (StrUtil.isEmpty(device_code)) {
throw new BadRequestException("设备号不能为空");
}
String vehicle_code = String.valueOf(jo.get("vehicle_code"));
if (StrUtil.isEmpty(vehicle_code)) {
throw new BadRequestException("载具号不能为空");
}
OutConfirmRequest outConfirmRequest = new OutConfirmRequest();
outConfirmRequest.setOutPortNo(device_code);
outConfirmRequest.setPalletCode(vehicle_code);
Instruction instruction = instructionService.findByCode(String.valueOf(task_code));
if (ObjectUtil.isNotEmpty(instruction)) {
task_code = instruction.getInstruction_code();
outConfirmRequest.setOrderId(task_code);
}
Resp<OutConfirmReportResponse> resp = acsToLiKuService.outConfirm(outConfirmRequest);
if (StrUtil.equals(resp.getResult(), "false")) {
JSONObject resultJson = new JSONObject();
resultJson.put("status", 400);
resultJson.put("message", resp.getComment());
log.info("unLock--------------:输出参数" + resultJson);
return resultJson;
}
} catch (Exception e) {
e.printStackTrace();
JSONObject resultJson = new JSONObject();
resultJson.put("status", 400);
resultJson.put("message", e.getMessage());
log.info("unLock--------------:输出参数" + resultJson);
return resultJson;
} finally {
MDC.remove(log_file_type);
}
JSONObject resultJson = new JSONObject();
resultJson.put("status", HttpStatus.OK.value());
resultJson.put("message", "操作成功");
log.info("unLock--------------:输出参数" + resultJson);
return resultJson;
}
// @Override
// public Map<String, Object> sendAgvChargeTask(JSONObject param) {
// log.info("sendAgvChargeTask--------------:输入参数" + param.toString());
// String agv_system = param.getString("agv_system");
// String car_no = param.getString("car_no");
// if (StrUtil.isEmpty(agv_system)) {
// throw new BadRequestException("AGV系统类型不能为空");
// }
// if (StrUtil.isEmpty(car_no)) {
// throw new BadRequestException("AGV车号不能为空");
// }
// Device device = deviceAppService.findDeviceByCode(car_no);
// if (device == null) {
// throw new BadRequestException("agv车号在ACS系统中不存在!");
// }
// NDCAgvService agvService = SpringContextHolder.getBean(NDCAgvServiceImpl.class);
// agvService.createChargingTaskToNDC(agv_system, car_no);
// JSONObject resp = new JSONObject();
// resp.put("status", 200);
// resp.put("message", "操作成功");
// return resp;
// }
//
// @Override
// public Map<String, Object> queryDeviceInfo(JSONObject param) {
// log.info("queryDeviceInfo--------------:输入参数" + param.toString());
// String region_code = param.getString("region_code");
//// if (StrUtil.isEmpty(region_code)) {
//// throw new BadRequestException("区域编码不能为空");
//// }
// AgvNdcTwoDeviceDriver agvNdcTwoDeviceDriver;
// AgvNdcOneDeviceDriver agvNdcOneDeviceDriver;
// List<Device> devices = deviceAppService.findDevice(DeviceType.agv);
// JSONArray data = new JSONArray();
// if (StrUtil.isEmpty(region_code)) {
// throw new BadRequestException("区域编码不能为空");
// }
AgvNdcTwoDeviceDriver agvNdcTwoDeviceDriver;
AgvNdcOneDeviceDriver agvNdcOneDeviceDriver;
List<Device> devices = deviceAppService.findDevice(DeviceType.agv);
JSONArray data = new JSONArray();
if (StrUtil.isEmpty(region_code)) {
if (ObjectUtil.isNotEmpty(devices)) {
for (int i = 0; i < devices.size(); i++) {
Device device = devices.get(i);
Device agvDevice = deviceAppService.findDeviceByCode(device.getDevice_code());
if (agvDevice.getDeviceDriver() instanceof DeviceStageMonitor) {
DeviceStageMonitor deviceStageMonitor = (DeviceStageMonitor) agvDevice.getDeviceDriver();
try {
JSONObject jo = deviceStageMonitor.getDeviceStatusName();
data.add(jo);
} catch (Exception e) {
log.error("反馈AGV信息失败:{}", e.getMessage());
}
}
}
}
} else {
if (ObjectUtil.isNotEmpty(devices)) {
for (int i = 0; i < devices.size(); i++) {
Device device = devices.get(i);
Device agvDevice = deviceAppService.findDeviceByCode(device.getDevice_code());
if (agvDevice.getDeviceDriver() instanceof AgvNdcTwoDeviceDriver) {
if (StrUtil.equals(region_code, "1")) {
agvNdcTwoDeviceDriver = (AgvNdcTwoDeviceDriver) agvDevice.getDeviceDriver();
JSONObject jo = agvNdcTwoDeviceDriver.getDeviceStatusName();
data.add(jo);
}
}
if (agvDevice.getDeviceDriver() instanceof AgvNdcOneDeviceDriver) {
if (StrUtil.equals(region_code, "5")) {
agvNdcOneDeviceDriver = (AgvNdcOneDeviceDriver) agvDevice.getDeviceDriver();
JSONObject jo = agvNdcOneDeviceDriver.getDeviceStatusName();
data.add(jo);
}
}
}
}
}
JSONObject resp = new JSONObject();
resp.put("status", 200);
resp.put("message", "操作成功");
resp.put("data", data);
return resp;
}
@Override public Map<String, Object> syncfaultInfo() {
log.info("syncfaultInfo--------------:输入参数");
JSONArray data = new JSONArray();
List<Dict> dicts = dictService.queryAll();
if (ObjectUtil.isNotEmpty(dicts)) {
List<Dict> error_dists = dicts
.stream()
.filter(dict -> dict.getName().contains("error_type"))
.collect(Collectors.toList());
if (ObjectUtil.isNotEmpty(error_dists)) {
for (int i = 0; i < error_dists.size(); i++) {
Dict dict = error_dists.get(i);
String dictName = dict.getName();
List<DictDetailDto> dictDetailDtos = dictDetailService.getDictByName(dictName);
for (DictDetailDto dictDetailDto : dictDetailDtos) {
JSONObject faultInfo = new JSONObject();
faultInfo.put("fault_type", dictName);
faultInfo.put("fault_code", dictDetailDto.getValue());
faultInfo.put("fault_info", dictDetailDto.getLabel());
data.add(faultInfo);
}
}
}
}
JSONObject resp = new JSONObject();
resp.put("status", 200);
resp.put("message", "操作成功");
resp.put("data", data);
return resp;
}
@Override public Map<String, Object> realTimefaultInfo(JSONObject param) {
log.info("realTimefaultInfo--------------:输入参数" + param.toString());
String device_code = param.getString("device_code");
JSONArray data = new JSONArray();
if (StrUtil.isNotEmpty(device_code)) {
String[] devices = device_code.split(",");
Device device = null;
for (String deviceCode : devices) {
device = deviceAppService.findDeviceByCode(deviceCode);
if (device == null) {
continue;
}
if (device.getDeviceDriver() instanceof FeedLmsRealFailed) {
FeedLmsRealFailed feedLmsRealFailed = (FeedLmsRealFailed) device.getDeviceDriver();
JSONObject jsonObject = feedLmsRealFailed.feedLmsRealFailedInfo();
data.add(jsonObject);
}
}
}
JSONObject resp = new JSONObject();
resp.put("status", 200);
resp.put("message", "操作成功");
resp.put("data", data);
return resp;
}
@Override public Map<String, Object> paperTubeAction(JSONObject param) {
log.info("paperTubeAction--------------:输入参数" + param.toString());
JSONObject resp = new JSONObject();
String device_code = param.getString("device_code");
String type = param.getString("type");
String material_code = param.getString("material_code");
String qty = param.getString("qty");
if (StrUtil.isNotEmpty(device_code)) {
Device device = deviceAppService.findDeviceByCode(device_code);
if (device == null) {
resp.put("status", 400);
resp.put("message", "未找到对应设备");
log.info("paperTubeAction--------------:输出参数" + resp.toString());
return resp;
}
if (device.getDeviceDriver() instanceof PaperTubeConveyorDeviceDriver) {
PaperTubeConveyorDeviceDriver paperTubeConveyorDeviceDriver = (PaperTubeConveyorDeviceDriver) device.getDeviceDriver();
if (paperTubeConveyorDeviceDriver.getMode() != 2) {
resp.put("status", 400);
resp.put("message", "设备:" + device_code + "未待机,无法下发信号");
log.info("paperTubeAction--------------:输出参数" + resp.toString());
return resp;
}
if (StrUtil.equals(type, "1")) {
if (paperTubeConveyorDeviceDriver.getInventory_qty() > 0) {
resp.put("status", 400);
resp.put("message", "设备:" + device_code + "当前数量为" + paperTubeConveyorDeviceDriver.getInventory_qty() + "无法设置物料");
log.info("paperTubeAction--------------:输出参数" + resp.toString());
return resp;
}
try{
List list = new ArrayList();
Map map = new HashMap();
map.put("code", "to_material");
map.put("value", material_code);
list.add(map);
paperTubeConveyorDeviceDriver.writing(list);
} catch (Exception e){
e.printStackTrace();
}
} else if (StrUtil.equals(type, "2")) {
if (paperTubeConveyorDeviceDriver.getInventory_qty() < Integer.parseInt(qty)) {
resp.put("status", 400);
resp.put("message", "设备:" + device_code + "当前数量为" + paperTubeConveyorDeviceDriver.getInventory_qty() + "小于出库数量" + qty);
log.info("paperTubeAction--------------:输出参数" + resp.toString());
return resp;
}
if (StrUtil.isEmpty(paperTubeConveyorDeviceDriver.getMaterial())) {
resp.put("status", 400);
resp.put("message", "设备:" + device_code + "设备上报物料为空无法出库");
log.info("paperTubeAction--------------:输出参数" + resp.toString());
return resp;
} else {
if (!StrUtil.equals(paperTubeConveyorDeviceDriver.getMaterial(), material_code)) {
resp.put("status", 400);
resp.put("message", "设备:" + device_code + "设备上报物料为" + paperTubeConveyorDeviceDriver.getMaterial() + "与出库物料" + material_code + "不匹配");
log.info("paperTubeAction--------------:输出参数" + resp.toString());
return resp;
}
}
if (paperTubeConveyorDeviceDriver.getTo_command() != 0 || paperTubeConveyorDeviceDriver.getTo_target() != 0) {
resp.put("status", 400);
resp.put("message", "设备:" + device_code + "下发命令信号值为" + paperTubeConveyorDeviceDriver.getTo_command() + ",下发目标站:" + paperTubeConveyorDeviceDriver.getTo_target() + ",已存在待执行的任务");
log.info("paperTubeAction--------------:输出参数" + resp.toString());
return resp;
}
List list = new ArrayList();
Map map = new HashMap();
map.put("code", "to_out_qty");
map.put("value", qty);
list.add(map);
Map map2 = new HashMap();
map2.put("code", "to_target");
map2.put("value", device.getAddress());
list.add(map2);
Map map3 = new HashMap();
map3.put("code", "to_command");
map3.put("value", 2);
list.add(map3);
try{
// paperTubeConveyorDeviceDriver.writing("to_out_qty", qty);
// paperTubeConveyorDeviceDriver.writing("to_target", device.getAddress());
// paperTubeConveyorDeviceDriver.writing("to_command", "2");
paperTubeConveyorDeviceDriver.writing(list);
} catch (Exception e){
e.printStackTrace();
}
} else if(StrUtil.equals(type, "3")){
List list = new ArrayList();
Map map = new HashMap();
map.put("code", "to_command");
map.put("value", 3);
list.add(map);
paperTubeConveyorDeviceDriver.writing(list);
}
}
}
resp.put("status", 200);
resp.put("message", "操作成功");
return resp;
}**/
}