rev:代码优化
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package org.nl.acs.agv;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
@@ -43,75 +44,60 @@ public class QueryAGVStatus {
|
||||
@Autowired
|
||||
private DeviceAppService deviceAppService;
|
||||
|
||||
public void run() {
|
||||
public void run() throws Exception{
|
||||
InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class);
|
||||
TaskService taskService = SpringContextHolder.getBean(TaskService.class);
|
||||
ISysParamService paramService = SpringContextHolder.getBean(ISysParamService.class);
|
||||
List<Instruction> allInstFromCache = instructionService.findAllInstFromCache();
|
||||
List<Instruction> instructionList = allInstFromCache.stream().filter(item -> Integer.parseInt(item.getInstruction_status()) <= Integer.parseInt(InstructionStatusEnum.BUSY.getIndex())).collect(Collectors.toList());
|
||||
// List<Instruction> agvInstruction = allInstFromCache.stream().filter(item -> AgvSystemTypeEnum.One_NDC_System_Type.getIndex().equals(item.getAgv_system_type()) || AgvSystemTypeEnum.XG_System_Type.getIndex().equals(item.getAgv_system_type())).collect(Collectors.toList());
|
||||
if (CollUtil.isEmpty(instructionList) || instructionList.size() < 1) {
|
||||
String agvurl = paramService.findByCode(AcsConfig.AGVURL).getValue();
|
||||
String agvport = paramService.findByCode(AcsConfig.AGVPORT).getValue();
|
||||
JSONObject param = new JSONObject();
|
||||
agvurl = agvurl + ":" + agvport + "/api/fms/allTaskStatus";
|
||||
HttpResponse result = HttpRequest.get(agvurl)
|
||||
.body(String.valueOf(param))
|
||||
.timeout(20000)//超时,毫秒
|
||||
.execute();
|
||||
if (result == null) {
|
||||
return;
|
||||
}
|
||||
for (Instruction instruction : allInstFromCache) {
|
||||
String agvurl = paramService.findByCode(AcsConfig.AGVURL).getValue();
|
||||
String agvport = paramService.findByCode(AcsConfig.AGVPORT).getValue();
|
||||
JSONObject param = new JSONObject();
|
||||
agvurl = agvurl + ":" + agvport + "/api/fms/taskStatus ";
|
||||
param.put("TaskNo", instruction.getInstruction_code());
|
||||
log.info("根据运单号查询运单状态的请求:{}", agvurl+ param);
|
||||
HttpResponse result = HttpRequest.get(agvurl)
|
||||
.body(String.valueOf(param))
|
||||
.timeout(20000)//超时,毫秒
|
||||
.execute();
|
||||
log.info("指令号:"+instruction.getInstruction_code()+"根据运单号查询运单状态的请求反馈:{}", result);
|
||||
if (result == null) {
|
||||
JSONObject jo = JSONArray.parseObject(result.body());
|
||||
JSONArray ja = jo.getJSONArray("TaskStatus");
|
||||
for (int i = 0; i < ja.size(); i++) {
|
||||
JSONObject one = (JSONObject) ja.get(i);
|
||||
String inst_code = one.getString("TaskNo");
|
||||
Instruction inst = instructionService.findByCodeFromCache(inst_code);
|
||||
if (ObjectUtil.isEmpty(inst))
|
||||
continue;
|
||||
}
|
||||
String body = result.body();
|
||||
JSONObject json = JSONObject.parseObject(body);
|
||||
JSONObject taskStatus = json.getJSONObject("TaskStatus");
|
||||
String instructionCode = taskStatus.getString("TaskNo");
|
||||
if (instructionCode == null) {
|
||||
continue;
|
||||
}
|
||||
if ("true".equals(json.getString("Result")) && instructionCode.equals(instruction.getInstruction_code())) {
|
||||
// 正在执行=running,
|
||||
// 完成=finish,
|
||||
// 失败=failed(主动失败),
|
||||
// 终止=aborted(被人为终止),
|
||||
String state = json.getString("Status");
|
||||
TaskDto task = taskService.findById(instruction.getTask_id());
|
||||
if (!StrUtil.isEmpty(json.getString("VehicleNo"))) {
|
||||
String carNo = json.getString("VehicleNo");
|
||||
instruction.setCarno(carNo);
|
||||
task.setCar_no(carNo);
|
||||
}
|
||||
if ("running".equals(state)||"idle".equals(state)) {
|
||||
if ("0".equals(instruction.getInstruction_status())) {
|
||||
instruction.setInstruction_status("1");
|
||||
instructionService.update(instruction);
|
||||
task.setTask_id(instruction.getTask_id());
|
||||
taskService.update(task);
|
||||
}
|
||||
|
||||
} else if ("finish".equals(state)) {
|
||||
if (!"2".equals(instruction.getInstruction_status())) {
|
||||
instruction.setInstruction_status("2");
|
||||
try {
|
||||
instructionService.finish(instruction);
|
||||
} catch (Exception e) {
|
||||
log.error("执行完成,但无法更新状态,可能由于参数错误导致的异常");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else if ("failed".equals(state) || "aborted".equals(state) || "deleted".equals(state)) {
|
||||
TaskDto taskDto = taskService.findById(instruction.getTask_id());
|
||||
String state = one.getString("Status");
|
||||
if (!StrUtil.isEmpty(one.getString("VehicleNo"))) {
|
||||
String carno = one.getString("VehicleNo");
|
||||
inst.setCarno(carno);
|
||||
}
|
||||
|
||||
// 正在执行=running,
|
||||
// // 完成=finish,
|
||||
// // 失败=failed(主动失败),
|
||||
// // 终止=aborted(被人为终止),
|
||||
|
||||
//执行中
|
||||
if ("running".equals(state)||"idle".equals(state)) {
|
||||
if (inst != null && "0".equals(inst.getInstruction_status())) {
|
||||
inst.setInstruction_status("1");
|
||||
instructionService.update(inst);
|
||||
}
|
||||
} else if ("finish".equals(state)) {
|
||||
if (inst != null) {
|
||||
inst.setInstruction_status("2");
|
||||
instructionService.finish(inst);
|
||||
}
|
||||
} else if ("failed".equals(state) || "aborted".equals(state) || "deleted".equals(state)) {
|
||||
if (inst != null) {
|
||||
TaskDto taskDto = taskService.findById(inst.getTask_id());
|
||||
List<String> list = Arrays.asList("0", "1");
|
||||
if (list.contains(instruction.getInstruction_status())) {
|
||||
instruction.setInstruction_status("3");
|
||||
instruction.setRemark("调度取消指令");
|
||||
instructionService.update(instruction);
|
||||
if (list.contains(inst.getInstruction_status())) {
|
||||
inst.setInstruction_status("3");
|
||||
inst.setRemark("调度取消指令");
|
||||
instructionService.update(inst);
|
||||
taskDto.setRemark("调度取消指令");
|
||||
taskService.update(taskDto);
|
||||
}
|
||||
|
||||
@@ -102,15 +102,16 @@ public class KeCongAgvServiceImpl implements KeCongAgvService {
|
||||
public HttpResponse addTask(Instruction inst) throws Exception {
|
||||
JSONObject jo = new JSONObject();
|
||||
JSONArray arr = new JSONArray();
|
||||
String priority = inst.getPriority();
|
||||
jo.put("TaskType", inst.getInstruction_type());
|
||||
JSONObject json1 = new JSONObject();
|
||||
json1.put("Key", "TaskNo");
|
||||
json1.put("Value", inst.getInstruction_code());
|
||||
arr.add(json1);
|
||||
// JSONObject json2 = new JSONObject();
|
||||
// json2.put("Key", "VehicleNo");
|
||||
// json2.put("Value", "3");
|
||||
// arr.add(json2);
|
||||
JSONObject json2 = new JSONObject();
|
||||
json2.put("Key", "Priority");
|
||||
json2.put("Value", priority);
|
||||
arr.add(json2);
|
||||
DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class);
|
||||
int startAddress = deviceService.queryAddressBydeviceCode(inst.getStart_point_code());
|
||||
int nextAddress = deviceService.queryAddressBydeviceCode(inst.getNext_point_code());
|
||||
@@ -150,7 +151,7 @@ public class KeCongAgvServiceImpl implements KeCongAgvService {
|
||||
.device_code("下发科聪任务")
|
||||
.content("任务号:" + inst.getTask_code() + ",指令号:" + inst.getInstruction_code() + ",下发科聪任务序列反馈参数:" + jo)
|
||||
.build();
|
||||
logDto.setLog_level(4);
|
||||
logDto1.setLog_level(4);
|
||||
luceneExecuteLogService.deviceExecuteLog(logDto1);
|
||||
log.info("任务号:{},指令号{},状态{},下发agv订单序列反馈:{}", inst.getTask_code(), inst.getInstruction_code(), result.getStatus(), result.body());
|
||||
|
||||
|
||||
@@ -72,8 +72,17 @@
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('task.txt_box.time')">
|
||||
<Search />
|
||||
<el-date-picker
|
||||
v-model="query.createTime"
|
||||
type="datetimerange"
|
||||
value-format="yyyy-MM-dd HH:mm:ss"
|
||||
start-placeholder="开始日期"
|
||||
end-placeholder="结束日期"
|
||||
align="right"
|
||||
@change="crud.toQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<rrOperation />
|
||||
</el-form>
|
||||
</div>
|
||||
<!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
|
||||
@@ -163,6 +172,7 @@ import pagination from '@crud/Pagination'
|
||||
import crudInstruction from '@/api/acs/instruction/instruction'
|
||||
import CRUD, { crud, form, header, presenter } from '@crud/crud'
|
||||
import crudOperation from '@crud/CRUD.operation'
|
||||
import rrOperation from '@crud/RR.operation'
|
||||
import { getDicts } from '@/views/system/dict/dict'
|
||||
import { download } from '@/api/data'
|
||||
import { downloadFile } from '@/utils'
|
||||
@@ -205,7 +215,7 @@ const defaultForm = {
|
||||
export default {
|
||||
dicts: ['task_status', 'task_type'],
|
||||
name: 'Instruction',
|
||||
components: { pagination, crudOperation, Search },
|
||||
components: { pagination, crudOperation, rrOperation, Search },
|
||||
mixins: [presenter(), header(), form(defaultForm), crud()],
|
||||
cruds() {
|
||||
return CRUD({
|
||||
|
||||
@@ -72,8 +72,17 @@
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('task.txt_box.time')">
|
||||
<Search />
|
||||
<el-date-picker
|
||||
v-model="query.createTime"
|
||||
type="datetimerange"
|
||||
value-format="yyyy-MM-dd HH:mm:ss"
|
||||
start-placeholder="开始日期"
|
||||
end-placeholder="结束日期"
|
||||
align="right"
|
||||
@change="crud.toQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<rrOperation />
|
||||
</el-form>
|
||||
<!-- <el-input-->
|
||||
<!-- v-if="false"-->
|
||||
@@ -301,6 +310,7 @@ import crudTask from '@/api/acs/task/task'
|
||||
import CRUD, { crud, form, header, presenter } from '@crud/crud'
|
||||
import crudOperation from '@crud/CRUD.operation'
|
||||
import pagination from '@crud/Pagination'
|
||||
import rrOperation from '@crud/RR.operation'
|
||||
import deviceCrud from '@/api/acs/device/device'
|
||||
import routeCurd from '@/api/acs/route/routePlan'
|
||||
import { getDicts } from '@/views/system/dict/dict'
|
||||
@@ -331,7 +341,7 @@ const defaultForm = {
|
||||
}
|
||||
export default {
|
||||
name: 'Task',
|
||||
components: { pagination, crudOperation, Search },
|
||||
components: { pagination, crudOperation,rrOperation, Search },
|
||||
dicts: ['task_status', 'task_type'],
|
||||
mixins: [presenter(), header(), form(defaultForm), crud()],
|
||||
cruds() {
|
||||
|
||||
@@ -72,8 +72,17 @@
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('task.txt_box.time')">
|
||||
<Search />
|
||||
<el-date-picker
|
||||
v-model="query.createTime"
|
||||
type="datetimerange"
|
||||
value-format="yyyy-MM-dd HH:mm:ss"
|
||||
start-placeholder="开始日期"
|
||||
end-placeholder="结束日期"
|
||||
align="right"
|
||||
@change="crud.toQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<rrOperation />
|
||||
</el-form>
|
||||
</div>
|
||||
<!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
|
||||
@@ -148,6 +157,7 @@ import crudInstruction from '@/api/acs/instruction/instruction'
|
||||
import CRUD, { presenter, header, form, crud } from '@crud/crud'
|
||||
import crudOperation from '@crud/CRUD.operation'
|
||||
import pagination from '@crud/Pagination'
|
||||
import rrOperation from '@crud/RR.operation'
|
||||
import deviceCrud from '@/api/acs/device/device'
|
||||
import routeCurd from '@/api/acs/route/routePlan'
|
||||
import { getDicts } from '@/views/system/dict/dict'
|
||||
@@ -168,7 +178,7 @@ const defaultForm = {
|
||||
remark: null }
|
||||
export default {
|
||||
name: 'Task',
|
||||
components: { pagination, crudOperation, Search },
|
||||
components: { pagination, crudOperation, rrOperation, Search },
|
||||
dicts: ['task_status', 'task_type'],
|
||||
mixins: [presenter(), header(), form(defaultForm), crud()],
|
||||
cruds() {
|
||||
|
||||
@@ -54,12 +54,11 @@
|
||||
|
||||
<el-date-picker
|
||||
v-model="query.createTime"
|
||||
type="datetimerange"
|
||||
format="yyyy-MM-dd HH:mm:ss"
|
||||
:picker-options="pickerOptions"
|
||||
range-separator="至"
|
||||
type="daterange"
|
||||
value-format="yyyy-MM-dd HH:mm:ss"
|
||||
start-placeholder="开始日期"
|
||||
end-placeholder="结束日期"
|
||||
:default-time="['00:00:00', '23:59:59']"
|
||||
align="right"
|
||||
/>
|
||||
<rrOperation />
|
||||
|
||||
Reference in New Issue
Block a user