wangguangyuan 8 months ago
parent
commit
f9e54bda1f
4 changed files with 116 additions and 123 deletions
  1. +3
    -0
      inspect-job/src/main/java/com/inspect/job/client/TaskExecClient.java
  2. +96
    -117
      inspect-job/src/main/java/com/inspect/job/task/JobMainTask.java
  3. +11
    -0
      inspect-main/inspect-main-task-exec/src/main/java/com/inspect/exec/controller/PatrolTaskExecController.java
  4. +6
    -6
      inspect-main/inspect-main-task/src/main/java/com/inspect/taskstatus/controller/PatrolTaskStatusController.java

+ 3
- 0
inspect-job/src/main/java/com/inspect/job/client/TaskExecClient.java View File

@ -22,6 +22,9 @@ public interface TaskExecClient {
@PostMapping({"/exec/selectTaskInfoList"})
List<PatrolTaskInfo> selectTaskInfoList(PatrolTaskInfo taskInfo);
@PostMapping({"/exec/getConfigByKey"})
String getConfigByKey(String key);
@PostMapping({"/exec/selectPatrolPresetPosList"})
List<PatrolPresetPos> selectPatrolPresetPosList(PatrolPresetPos presetPos);


+ 96
- 117
inspect-job/src/main/java/com/inspect/job/task/JobMainTask.java View File

@ -384,20 +384,17 @@ public class JobMainTask {
log.info(Color.CYAN + "************************** executing patrolPoint, patrolPointId: {}, patrolPresetPos: {}" + Color.END, patrolTaskInfo.getDeviceId(), JSONObject.toJSONString(presetPosList, true));
PatrolPresetPos presetPos = !presetPosList.isEmpty() ? presetPosList.get(0) : PatrolPresetPos.builder().presetPosId("0").build();
boolean bPointFinished = isPointFinished(patrolTaskInfo, taskExecRecord);
String taskPatrolId = taskExecRecord.getTaskPatrolId();
log.info("taskPatrolId: {}, bPointFinished: {}", taskPatrolId, bPointFinished);
if (!bPointFinished) {
/*摄像头转到预置位*/
boolean noError = setCameraToPreset(presetPos);
if ("prod".equals(activeProfile) && noError) {
log.info("setCameraToPreset no error, delay 20 seconds");
myDelay(20000);
} else {
log.info("setCameraToPreset has error, delay 2 seconds");
myDelay(2000);
}
log.info("taskPatrolId: {}", taskPatrolId);
/*摄像头转到预置位*/
boolean noError = setCameraToPreset(presetPos);
if ("prod".equals(activeProfile) && noError) {
log.info("setCameraToPreset no error, delay 20 seconds");
myDelay(20000);
} else {
log.info("setCameraToPreset has error, delay 2 seconds");
myDelay(2000);
}
StringBuffer fileTypes = new StringBuffer();
@ -421,45 +418,45 @@ public class JobMainTask {
int delayMilliSeconds = presetAction.getPhotoGap() * 1000;
final long photoCount = presetAction.getPhotoCount();
boolean bOk = false;
if (!bPointFinished) {
try {
log.info("PHOTO PresetType chanType: {}, videoNvrCode: {}, channelCode: {}", chanType, presetPos.getVideoNvrCode(), presetPos.getChannelCode());
if ("vl".equals(chanType)) {
String paramUrl = liveIVS_URL + "/api/v1/device/channelsnap?serial=" + presetPos.getVideoNvrCode() + "&realtime=true&code=" + presetPos.getChannelCode();
String paramFileName = taskPatrolId.split(StringUtils.UNDERLINE)[1] + StringUtils.UNDERLINE
+ taskPatrolId.split(StringUtils.UNDERLINE)[2] + StringUtils.UNDERLINE
+ presetPos.getPatrolPointId() + StringUtils.UNDERLINE
+ taskExecRecord.getDevNo() + ".jpg";
String paramFileDir = basePath + "CCD";
log.info("paramUrl: {}, paramFileName: {}, paramFileDir: {}", paramUrl, paramFileName, paramFileDir);
FtpResult ftpResult = saveFile(paramUrl, paramFileName, paramFileDir);
if (ftpResult != null && StringUtils.isNotEmpty(ftpResult.getFilepath())) {
log.info("filePath: {}", ftpResult.getFilepath());
bOk = ftpResult.isOk();
filePaths.append("/" + ftpResult.getFilepath());
}
} else if ("ir".equals(chanType)) {
InfraredModel infraredModel = new InfraredModel();
infraredModel.setChannelSerial(presetPos.getChannelCode());
infraredModel.setPresetId(Integer.parseInt(presetPos.getPresetPosCode()));
EqpBook eqpbook = new EqpBook();
eqpbook.setPatrolDeviceCode(presetPos.getPatrolDeviceCode());
List<EqpBook> eqpBookListList = taskExecClient.selectBasedataEqpBookList(eqpbook);
if (!eqpBookListList.isEmpty()) {
Response ir_gen = remoteInvokeService.invoke("IR_GEN", presetPos.getPatrolDeviceCode().split("#")[0], new HashMap<>());
log.info("ir_gen: {}", JSONObject.toJSONString(ir_gen));
Object data = ir_gen.getData();
String path = JSONObject.parseObject(JSONObject.toJSONString(data)).getString("filePath");
path = path.split("33333")[1];
filePaths.append(path).append(",");
log.info("INFRA:{}", taskExecRecord.getTaskName() + " path : " + path);
}
try {
log.info("PHOTO PresetType chanType: {}, videoNvrCode: {}, channelCode: {}", chanType, presetPos.getVideoNvrCode(), presetPos.getChannelCode());
if ("vl".equals(chanType)) {
String paramUrl = liveIVS_URL + "/api/v1/device/channelsnap?serial=" + presetPos.getVideoNvrCode() + "&realtime=true&code=" + presetPos.getChannelCode();
String paramFileName = taskPatrolId.split(StringUtils.UNDERLINE)[1] + StringUtils.UNDERLINE
+ taskPatrolId.split(StringUtils.UNDERLINE)[2] + StringUtils.UNDERLINE
+ presetPos.getPatrolPointId() + StringUtils.UNDERLINE
+ taskExecRecord.getDevNo() + ".jpg";
String paramFileDir = basePath + "CCD";
log.info("paramUrl: {}, paramFileName: {}, paramFileDir: {}", paramUrl, paramFileName, paramFileDir);
FtpResult ftpResult = saveFile(paramUrl, paramFileName, paramFileDir);
if (ftpResult != null && StringUtils.isNotEmpty(ftpResult.getFilepath())) {
log.info("filePath: {}", ftpResult.getFilepath());
bOk = ftpResult.isOk();
filePaths.append("/" + ftpResult.getFilepath());
}
} else if ("ir".equals(chanType)) {
InfraredModel infraredModel = new InfraredModel();
infraredModel.setChannelSerial(presetPos.getChannelCode());
infraredModel.setPresetId(Integer.parseInt(presetPos.getPresetPosCode()));
EqpBook eqpbook = new EqpBook();
eqpbook.setPatrolDeviceCode(presetPos.getPatrolDeviceCode());
List<EqpBook> eqpBookListList = taskExecClient.selectBasedataEqpBookList(eqpbook);
if (!eqpBookListList.isEmpty()) {
Response ir_gen = remoteInvokeService.invoke("IR_GEN", presetPos.getPatrolDeviceCode().split("#")[0], new HashMap<>());
log.info("ir_gen: {}", JSONObject.toJSONString(ir_gen));
Object data = ir_gen.getData();
String path = JSONObject.parseObject(JSONObject.toJSONString(data)).getString("filePath");
path = path.split("33333")[1];
filePaths.append(path).append(",");
log.info("INFRA:{}", taskExecRecord.getTaskName() + " path : " + path);
}
} catch (Exception e) {
log.error("error", e);
}
} catch (Exception e) {
log.error("error", e);
}
recordPersist(bOk, bPointFinished, taskExecRecord, infoListSize, patrolTaskInfo, presetPos, fileTypes, filePaths);
recordPersist(bOk, taskExecRecord, infoListSize, patrolTaskInfo, presetPos, fileTypes, filePaths);
} else if (PresetAction.VIDEO.getCode().equals(presetAction.getActionType())) {
log.info("VIDEO PresetType videoNvrCode: {}, channelCode: {}", presetPos.getVideoNvrCode(), presetPos.getChannelCode());
fileTypes.append(4).append(",");
@ -522,11 +519,9 @@ public class JobMainTask {
String rectangle = getRectangle(presetPos.getPresetPosId());
String taskPatrolId = getTaskPatrolledId(taskInfo.getDevNo(), taskExecRecord.getTaskPatrolId());
final String deviceId = taskInfo.getDeviceId();
log.info("taskPatrolId: {}, deviceId: {}", taskPatrolId, deviceId);
List<PatrolTaskPointExecRecord> pointExecRecords = taskExecClient.selectPatrolTaskPointExecRecordList(PatrolTaskPointExecRecord.builder().taskPatrolledId(taskPatrolId).deviceId(deviceId).build());
PatrolTaskPointExecRecord pointExecRecord;
if (pointExecRecords.isEmpty()) {
pointExecRecord = PatrolTaskPointExecRecord
log.info("pointExecRecord crud add taskPatrolId: {}, deviceId: {}", taskPatrolId, deviceId);
PatrolTaskPointExecRecord pointExecRecord = PatrolTaskPointExecRecord
.builder()
.patrolDeviceName(taskInfo.getEbookName())
.patrolDeviceCode(taskInfo.getDevNo())
@ -544,19 +539,7 @@ public class JobMainTask {
.time(new Date())
.isOk(bOk ? 1 : 0)
.build();
taskExecClient.addPatrolTaskPointExecRecord(pointExecRecord);
} else {
log.info("update record, pointExecRecords size: {}", pointExecRecords.size());
pointExecRecord = pointExecRecords.get(0);
int isOk = pointExecRecord.getIsOk();
if (isOk == 0) { // 上一次未成功的才更新
pointExecRecord.setIsOk(bOk ? 1 : 0);
int tries = pointExecRecord.getTries();
pointExecRecord.setTries(tries + 1);
pointExecRecord.setTime(new Date());
taskExecClient.updatePatrolTaskPointExecRecord(pointExecRecord);
}
}
taskExecClient.addPatrolTaskPointExecRecord(pointExecRecord);
if (bOk) {
String patrolId = taskExecRecord.getTaskPatrolId();
@ -628,32 +611,31 @@ public class JobMainTask {
}
}
private int addCursorNumber(String taskPatrolId, boolean bPointFinished, boolean bOk) {
private int addCursorNumber(String taskPatrolId,boolean bOk) {
PatrolTaskExecRecord taskExecRecord = taskExecClient.selectPatrolTaskExecRecordByTaskPatrolId(taskPatrolId);
int total = taskExecRecord.getTotalNumber();
int success = taskExecRecord.getFinishNumber();
int cursor;
if (taskExecRecord.getCursorNumber() == null) {
cursor = 1;
} else {
int total = taskExecRecord.getTotalNumber();
cursor = taskExecRecord.getCursorNumber();
if (cursor < total)
if (cursor < total) {
cursor = taskExecRecord.getCursorNumber() + 1;
}
}
log.info("addCursorNumber cursor: {}", cursor);
taskExecRecord.setCursorNumber(cursor);
if (!bPointFinished && bOk) {
int finish = taskExecRecord.getFinishNumber();
int total = taskExecRecord.getTotalNumber();
int value = finish + 1;
log.info("addFinishNumber finish: {}, total: {}", value, total);
taskExecRecord.setFinishNumber(value);
String taskProgress = decimalFormatNum(finish, total);
if (bOk) {
success++;
log.info("execute point success, cursor: {}, success: {}, total: {}", cursor, success, total);
taskExecRecord.setFinishNumber(success);
String taskProgress = decimalFormatNum(success, total);// task_progress=success/total -> patrol_task_exec_record
taskExecRecord.setTaskProgress(taskProgress);
List<PatrolTaskInfo> totalInfos = getInfosByTaskCode(taskExecRecord);
List<PatrolTaskInfo> totalInfos = getInfosByRecord(taskExecRecord);
List<PatrolTaskPointExecRecord> finishedInfos = taskExecClient.selectPatrolTaskPointExecRecordList(PatrolTaskPointExecRecord.builder().oldTaskPatrolledId(taskExecRecord.getOldTaskPatrolId()).build());
String totalProgress = decimalFormatNum(finishedInfos.size(), totalInfos.size());
String totalProgress = decimalFormatNum(finishedInfos.size(), totalInfos.size());// task_progress=finish/total -> patrol_task_status
log.info("totalProgress: {}, finish: {}, total: {}", totalProgress, finishedInfos.size(), totalInfos.size());
callRemoteSendMsgRunMode(
taskExecRecord.getTaskCode(),
@ -662,6 +644,8 @@ public class JobMainTask {
totalProgress,
TaskStatus.RUNNING.getCode()/*运行中百分比上报*/
);
} else {
log.info("execute point fail, cursor: {}, success: {}, total: {}", cursor, success, total);
}
taskExecClient.updatePatrolTaskExecRecord(taskExecRecord);
return cursor;
@ -698,7 +682,7 @@ public class JobMainTask {
String taskProgress = decimalFormatNum(finish, total);
execRecord.setTaskProgress(taskProgress);
execRecord.setTaskState(TaskStatus.DONE.getCode()); // 子任务在当前轮回中遍历完成标记
List<PatrolTaskInfo> totalInfos = getInfosByTaskCode(execRecord);
List<PatrolTaskInfo> totalInfos = getInfosByRecord(execRecord);
List<PatrolTaskPointExecRecord> finishedInfos = taskExecClient.selectPatrolTaskPointExecRecordList(PatrolTaskPointExecRecord.builder().oldTaskPatrolledId(execRecord.getOldTaskPatrolId()).build());
String totalProgress = decimalFormatNum(finishedInfos.size(), totalInfos.size());
log.info("totalProgress: {}, finish: {}, total: {}", totalProgress, finishedInfos.size(), totalInfos.size());
@ -719,7 +703,7 @@ public class JobMainTask {
} else { // 该record下的点没有全部执行成功
//设置本record的执行状态为终止
execRecord.setTaskState(TaskStatus.HALTED.getCode());
List<PatrolTaskInfo> totalInfos = getInfosByTaskCode(execRecord);
List<PatrolTaskInfo> totalInfos = getInfosByRecord(execRecord);
List<PatrolTaskPointExecRecord> finishedInfos = taskExecClient.selectPatrolTaskPointExecRecordList(PatrolTaskPointExecRecord.builder().oldTaskPatrolledId(execRecord.getOldTaskPatrolId()).build());
String totalProgress = decimalFormatNum(finishedInfos.size(), totalInfos.size());
log.info("totalProgress: {}, finish: {}, total: {}", totalProgress, finishedInfos.size(), totalInfos.size());
@ -743,31 +727,29 @@ public class JobMainTask {
}
synchronized private PatrolTaskExecRecord recordPersist(boolean bOk,
boolean bPointFinished,
PatrolTaskExecRecord taskExecRecord,
int infoListSize,
PatrolTaskInfo taskInfo,
PatrolPresetPos presetPos,
StringBuffer fileTypes,
StringBuffer filePaths) {
if (!bPointFinished) {
log.info(Color.CYAN + "**************************addPointRecord start" + Color.END);
try {
addPointRecord(bOk, taskExecRecord, taskInfo, presetPos, fileTypes, filePaths);
} catch (Exception e) {
log.error("error", e);
}
log.info(Color.CYAN + "**************************addPointRecord end" + Color.END);
log.info(Color.CYAN + "**************************addPointRecord start" + Color.END);
try {
addPointRecord(bOk, taskExecRecord, taskInfo, presetPos, fileTypes, filePaths);
} catch (Exception e) {
log.error("error", e);
}
log.info(Color.CYAN + "**************************addPointRecord end" + Color.END);
log.info(Color.CYAN + "**************************addCursorNumber start" + Color.END);
int cursorNumber = 0;
try {
cursorNumber = addCursorNumber(taskExecRecord.getTaskPatrolId(), bPointFinished, bOk);
cursorNumber = addCursorNumber(taskExecRecord.getTaskPatrolId(), bOk);
} catch (Exception e) {
log.error("error", e);
}
log.info(Color.CYAN + "**************************addCursorNumber end, CUR:{},DEV:{},OK:{},FIN:{},CAM:{},ID:{}" + Color.END, cursorNumber, taskExecRecord.getTaskPatrolId(), bOk, bPointFinished, presetPos.getChannelCode(), presetPos.getPatrolPointId());
log.info(Color.CYAN + "**************************addCursorNumber end" + Color.END);
if (cursorNumber == infoListSize) {// devNo下对应的点执行完毕
log.info(Color.CYAN + "**************************windUpRecord start" + Color.END);
@ -844,10 +826,10 @@ public class JobMainTask {
@PostMapping({"/immediatelyExecTask"})
public void immediatelyExecTask(@RequestBody PatrolTask patrolTask) {
String taskCode = redisService.getCacheObjectOfTask(RedisConst.TASK_CURRENT_CODE, patrolTask.getTaskCode());
if (StringUtils.isNotEmpty(taskCode)) {
log.info(Color.CYAN + "TASK SLOT IS TAKEN BY: {}" + Color.END, taskCode);
return;
}
// if (StringUtils.isNotEmpty(taskCode)) {
// log.info(Color.CYAN + "TASK SLOT IS TAKEN BY: {}" + Color.END, taskCode);
// return;
// }
PatrolTaskInfo patrolTaskInfo = new PatrolTaskInfo();
List<PatrolTask> patrolTaskList = new ArrayList<>();
@ -855,10 +837,10 @@ public class JobMainTask {
List<PatrolTask> cameraPatrolTasks = new ArrayList<>();
assembleVideoTask(patrolTaskList, cameraPatrolTasks);
String redisImmediatelyExecTaskTime = redisService.getCacheObjectOfTask(RedisConst.IMMEDIATELY_EXEC_TASK_TIME, patrolTask.getTaskCode());
if (redisImmediatelyExecTaskTime != null) {
log.info(Color.CYAN + "IMMEDIATELY_EXEC_TASK_TIME TASK TAKEN :{}" + Color.END, redisImmediatelyExecTaskTime);
return;
}
// if (redisImmediatelyExecTaskTime != null) {
// log.info(Color.CYAN + "IMMEDIATELY_EXEC_TASK_TIME TASK TAKEN :{}" + Color.END, redisImmediatelyExecTaskTime);
// return;
// }
if (shaoXinBigModel.isSwitchStatus()) {
log.info("[BIG] Temporary gathering, close bigSwitch in nacos");
@ -906,20 +888,6 @@ public class JobMainTask {
}
}
private List<PatrolTaskInfo> getInfosByTaskCode(final PatrolTaskExecRecord record) {
List<PatrolTaskInfo> patrolTaskInfoList = new ArrayList<>();
try {
patrolTaskInfoList = taskExecClient.selectTaskInfoList(PatrolTaskInfo.builder()
.taskMajorId(record.getTaskId().toString())
.devType("2")
.build());
return patrolTaskInfoMaintainAreaRemove(patrolTaskInfoList);
} catch (Exception e) {
log.error("error", e);
return patrolTaskInfoList;
}
}
private List<PatrolTaskInfo> getInfosByRecord(final PatrolTaskExecRecord record) {
List<PatrolTaskInfo> patrolTaskInfoList = new ArrayList<>();
try {
@ -936,13 +904,24 @@ public class JobMainTask {
private void assembleVideoTask(List<PatrolTask> patrolTaskList, List<PatrolTask> cameraPatrolTasks) {
if (patrolTaskList != null) {
String jobAreas = taskExecClient.getConfigByKey("JOB_AREAS");
log.info("jobAreas: {}", jobAreas);
List<String> jobAreaList = new ArrayList<>();
if(StringUtils.isNotBlank(jobAreas)) {
String[] jobAreaArr = jobAreas.split(",");
for(int i = 0; i < jobAreaArr.length; i++) {
jobAreaList.add(jobAreaArr[i]);
}
}
log.info("jobAreaList: {}", JSONObject.toJSONString(jobAreaList));
for (PatrolTask task : patrolTaskList) {
if (!StringUtils.isEmpty(task.getDevType())) {
String[] devTypes = task.getDevType().split(StringUtils.COMMA);
String[] devNos = task.getDevNo().split(StringUtils.COMMA);
for (int i = 0; i < devTypes.length; ++i) {
if ("2".equals(devTypes[i])) {
if("camera".equals(devNos[i])) {//武汉站手动任务台账编码
if(jobAreaList.size() == 0 || jobAreaList.contains(devNos[i])) {
PatrolTask cameraPatrolTask = new PatrolTask();
cameraPatrolTask.setTaskId(task.getTaskId());
cameraPatrolTask.setStationName(task.getStationName());
@ -995,7 +974,7 @@ public class JobMainTask {
//patrolTaskInfoList size: 12 devNo: camera, taskId: 10032
log.info("EXEC patrolTaskInfoList size: {} devNo: {}, taskId: {}", patrolTaskInfoList.size(), patrolTaskExecRecord.getDevNo(), patrolTaskExecRecord.getTaskId());
for (final PatrolTaskInfo taskInfo : patrolTaskInfoList) {
log.info("EXEC Immediate Progress: {}, id: {}, taskInfo: {}", patrolTaskExecRecord.getTaskProgress(), patrolTaskExecRecord.getTaskPatrolId() + "@@@" + patrolTaskExecRecord.getTaskPatrolId(), "deviceId:" + taskInfo.getDeviceId() + " LineId=" + taskInfo.getLineId());
log.info("EXEC Immediate taskPatrolId: {}, deviceId: {}, lineId: {}", patrolTaskExecRecord.getTaskPatrolId(), taskInfo.getDeviceId(), taskInfo.getLineId());
prePointExec(patrolTaskExecRecord, taskInfo, patrolTaskInfoList.size());
}
}


+ 11
- 0
inspect-main/inspect-main-task-exec/src/main/java/com/inspect/exec/controller/PatrolTaskExecController.java View File

@ -719,6 +719,17 @@ public class PatrolTaskExecController extends BaseController {
return CollectionUtils.isNotEmpty(list) ? list.get(0) : null;
}
@PostMapping({"/getConfigByKey"})
public String getConfigByKey(@RequestBody String key) {
String value = patrolTaskService.selectConfigByKey(key);
logger.info("-------------------getConfigByKey key: {}, value: {}", key, value);
if(StringUtils.isBlank(value)) {
return "";
} else {
return value.trim();
}
}
public static void main(String[] args) {
String dateString = DateUtils.format(DateUtils.yyyyMMddHHmmss2, new Date());
System.out.println(dateString);


+ 6
- 6
inspect-main/inspect-main-task/src/main/java/com/inspect/taskstatus/controller/PatrolTaskStatusController.java View File

@ -657,13 +657,13 @@ public class PatrolTaskStatusController extends BaseController {
String str = JSONObject.toJSONString(sendTask);
this.feignTaskClient.sendCommand(str);
} else {
String taskCode = redisService.getCacheObjectOfTask(RedisConst.TASK_CURRENT_CODE, String.valueOf(patrolTask.getTaskId()));
if (!StringUtils.isEmpty(taskCode)) {
log.info("[TASK] CURRENT EXEC TASK: {}", taskCode);
return AjaxResult.error(501, "THERE TASK IS RUNNING!");
} else {
// String taskCode = redisService.getCacheObjectOfTask(RedisConst.TASK_CURRENT_CODE, String.valueOf(patrolTask.getTaskId()));
// if (!StringUtils.isEmpty(taskCode)) {
// log.info("[TASK] CURRENT EXEC TASK: {}", taskCode);
// return AjaxResult.error(501, "THERE TASK IS RUNNING!");
// } else {
sendTaskToVideo(patrolTask);
}
// }
}
}
}


Loading…
Cancel
Save