代码更新

This commit is contained in:
2023-04-18 14:02:15 +08:00
parent 8bf407e5f0
commit ad64980050
8 changed files with 589 additions and 1 deletions

View File

@@ -104,5 +104,26 @@ public class WmsToAcsController {
return new ResponseEntity<>(wmsToAcsService.putPlusPullAction(jo), HttpStatus.OK);
}
@PostMapping("/unLock")
@Log(value = "给ACS下发修立库点位解锁", isInterfaceLog = true, interfaceLogType = InterfaceLogType.LMS_TO_ACS)
@ApiOperation("给ACS下发修立库点位解锁")
public ResponseEntity<Object> unLock(@RequestBody JSONObject jo) {
return new ResponseEntity<>(wmsToAcsService.unLock(jo), HttpStatus.OK);
}
@PostMapping("/queryDeviceInfo")
@Log(value = "LMS向acs请求设备信息", isInterfaceLog = true, interfaceLogType = InterfaceLogType.LMS_TO_ACS)
@ApiOperation("LMS向acs请求设备信息")
public ResponseEntity<Object> queryDeviceInfo(@RequestBody JSONObject jo) {
return new ResponseEntity<>(wmsToAcsService.queryDeviceInfo(jo), HttpStatus.OK);
}
@PostMapping("/sendAgvChargeTask")
@Log(value = "LMS下发AGV充电任务", isInterfaceLog = true, interfaceLogType = InterfaceLogType.LMS_TO_ACS)
@ApiOperation("LMS下发AGV充电任务")
public ResponseEntity<Object> sendAgvChargeTask(@RequestBody JSONObject jo) {
return new ResponseEntity<>(wmsToAcsService.sendAgvChargeTask(jo), HttpStatus.OK);
}
}

View File

@@ -77,5 +77,24 @@ public interface WmsToAcsService {
*/
JSONObject putPlusPullAction(JSONObject jo);
/**
* 给ACS下发修立库点位解锁
* @param jo /
* @return JSONObject
*/
JSONObject unLock(JSONObject jo);
/**
* lms向acs请求设备信息
* @param jo /
* @return JSONObject
*/
JSONObject queryDeviceInfo(JSONObject jo);
/**
* LMS下发AGV充电任务
* @param jo /
* @return JSONObject
*/
JSONObject sendAgvChargeTask(JSONObject jo);
}

View File

@@ -111,4 +111,225 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
return result;
}
@Override
public JSONObject unLock(JSONObject whereJson) {
String api = "api/wms/unLock";
//判断是否连接ACS系统
String isConnect = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("is_connect_acs").getValue();
JSONObject result = new JSONObject();
if (StrUtil.equals("0", isConnect)) {
result.put("status", HttpStatus.OK.value());
result.put("message", "下发成功但未连接ACS!");
result.put("data", new JSONObject());
return result;
}
//ACS地址127.0.0.1:8010
String acsUrl = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("acs_url").getValue();
String url = acsUrl + api;
try {
String resultMsg = HttpRequest.post(url)
.body(String.valueOf(whereJson))
.execute().body();
result = JSONObject.parseObject(resultMsg);
} catch (Exception e) {
String msg = e.getMessage();
//ConnectException: Connection refused: connect
//网络不通
System.out.println(msg);
result.put("status", HttpStatus.BAD_REQUEST);
result.put("message", "网络不通,操作失败!");
result.put("data", new JSONObject());
}
//acs抛异常这里
if (!StrUtil.equals(result.getString("status"), "200")) {
throw new BadRequestException("解锁失败:"+result.getString("message"));
}
return result;
}
/*
对应车间:
A1车间对应车号2,3
A2车间对应车号
A3车间对应车号
A4车间对应车号
LK车间对应车号1
*/
@Override
public JSONObject queryDeviceInfo(JSONObject whereJson) {
String api = "api/wms/queryDeviceInfo";
//判断是否连接ACS系统
String isConnect = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("is_connect_acs").getValue();
JSONObject result = new JSONObject();
if (StrUtil.equals("0", isConnect)) {
result.put("status", HttpStatus.OK.value());
result.put("message", "下发成功但未连接ACS!");
result.put("data", new JSONArray());
/* // 测试数据
JSONArray data = result.getJSONArray("data");
JSONObject a = new JSONObject();
a.put("electricity", "86");
a.put("status_name", "空闲");
a.put("car_no", "1");
a.put("task_code", "");
a.put("fault", "");
data.add(a);
JSONObject b = new JSONObject();
b.put("electricity", "13");
b.put("status_name", "执行中");
b.put("car_no", "2");
b.put("task_code", "000001");
b.put("fault", "取货失败");
data.add(b);
JSONObject c = new JSONObject();
c.put("electricity", "100");
c.put("status_name", "充电中");
c.put("car_no", "3");
c.put("task_code", "000002");
c.put("fault", "");
data.add(c);
JSONObject nowJson = new JSONObject(); // 返回数据
JSONArray ArrA1 = new JSONArray(); // A1车间
JSONArray ArrLk = new JSONArray(); // LK车间
for (int i = 0; i < data.size(); i++) {
JSONObject json = data.getJSONObject(i);
if ("2,3".contains(json.getString("car_no"))) {
ArrA1.add(json);
}
if ("1".contains(json.getString("car_no"))) {
ArrLk.add(json);
}
}
nowJson.put("jsonA1",ArrA1);
nowJson.put("jsonLK",ArrLk);
result.put("data", nowJson);*/
return result;
}
//ACS地址127.0.0.1:8010
String acsUrl = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("acs_url").getValue();
String url = acsUrl + api;
try {
String resultMsg = HttpRequest.post(url)
.body(String.valueOf(whereJson))
.execute().body();
result = JSONObject.parseObject(resultMsg);
// 重新组织数据
JSONArray data = result.getJSONArray("data");
JSONObject nowJson = new JSONObject(); // 返回数据
JSONArray ArrA1 = new JSONArray(); // A1车间
JSONArray ArrLk = new JSONArray(); // LK车间
for (int i = 0; i < data.size(); i++) {
JSONObject json = data.getJSONObject(i);
if ("2,3".contains(json.getString("car_no"))) {
ArrA1.add(json);
}
if ("1".contains(json.getString("car_no"))) {
ArrLk.add(json);
}
}
nowJson.put("jsonA1",ArrA1);
nowJson.put("jsonLK",ArrLk);
result.put("data", nowJson);
} catch (Exception e) {
String msg = e.getMessage();
//ConnectException: Connection refused: connect
//网络不通
System.out.println(msg);
result.put("status", HttpStatus.BAD_REQUEST);
result.put("message", "网络不通,操作失败!");
result.put("data", new JSONArray());
}
//acs抛异常这里
if (!StrUtil.equals(result.getString("status"), "200")) {
throw new BadRequestException("查询失败:"+result.getString("message"));
}
return result;
}
/*
对应系统:
车号1对应系统1
车号2、3对应系统2
*/
@Override
public JSONObject sendAgvChargeTask(JSONObject whereJson) {
String api = "api/wms/sendAgvChargeTask";
//判断是否连接ACS系统
String isConnect = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("is_connect_acs").getValue();
JSONObject result = new JSONObject();
if (StrUtil.equals("0", isConnect)) {
result.put("status", HttpStatus.OK.value());
result.put("message", "下发成功但未连接ACS!");
result.put("data", new JSONObject());
/* // 测试数据
String car_no = whereJson.getString("car_no");
JSONObject jsonParam = new JSONObject();
if ("2,3".contains(car_no)) {
jsonParam.put("avg_system", "2");
jsonParam.put("car_no", car_no);
} else if ("1".contains(car_no)) {
jsonParam.put("avg_system", "1");
jsonParam.put("car_no", car_no);
}*/
return result;
}
//ACS地址127.0.0.1:8010
String acsUrl = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("acs_url").getValue();
String url = acsUrl + api;
// 判断此此号属于哪个系统
String car_no = whereJson.getString("car_no");
JSONObject jsonParam = new JSONObject();
if ("2,3".contains(car_no)) {
jsonParam.put("avg_system", "2");
jsonParam.put("car_no", car_no);
} else if ("1".contains(car_no)) {
jsonParam.put("avg_system", "1");
jsonParam.put("car_no", car_no);
}
try {
String resultMsg = HttpRequest.post(url)
.body(String.valueOf(jsonParam))
.execute().body();
result = JSONObject.parseObject(resultMsg);
} catch (Exception e) {
String msg = e.getMessage();
//网络不通
System.out.println(msg);
result.put("status", HttpStatus.BAD_REQUEST);
result.put("message", "网络不通,操作失败!");
result.put("data", new JSONObject());
}
//acs抛异常这里
if (!StrUtil.equals(result.getString("status"), "200")) {
throw new BadRequestException("下发失败:"+result.getString("message"));
}
return result;
}
}