yang_shj
9 months ago
17 changed files with 405 additions and 28 deletions
@ -0,0 +1,28 @@ |
|||||||
|
package com.hnac.hzims.common.statistics; |
||||||
|
|
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
import java.lang.reflect.Array; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
|
||||||
|
@ApiModel("统计图表") |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode |
||||||
|
public class Charts implements Serializable { |
||||||
|
|
||||||
|
@ApiModelProperty("类别") |
||||||
|
private List<String> legends; |
||||||
|
|
||||||
|
@ApiModelProperty("x轴分区") |
||||||
|
private List<String> xAxis; |
||||||
|
|
||||||
|
@ApiModelProperty("展示数据") |
||||||
|
private List<List> series; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,8 @@ |
|||||||
|
package com.hnac.hzims.message.constants; |
||||||
|
|
||||||
|
public interface DictKeyConstants { |
||||||
|
|
||||||
|
/**消息推送类型 [appPush-app推送 smsPush-短信推送 websocketPush-web推送 mailPush-邮件推送]**/ |
||||||
|
String MESSAGE_TYPE = "messageType"; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,34 @@ |
|||||||
|
package com.hnac.hzinfo.inspect.task.controller; |
||||||
|
|
||||||
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
||||||
|
import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; |
||||||
|
import com.hnac.hzinfo.inspect.task.service.ITaskObjectService; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import io.swagger.annotations.ApiParam; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import org.springblade.core.boot.ctrl.BladeController; |
||||||
|
import org.springblade.core.tool.api.R; |
||||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestParam; |
||||||
|
import org.springframework.web.bind.annotation.RestController; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
@AllArgsConstructor |
||||||
|
@Api(value = "任务对象管理",tags = "任务对象管理") |
||||||
|
@RestController |
||||||
|
@RequestMapping("/task/object") |
||||||
|
public class TaskObjectController extends BladeController { |
||||||
|
|
||||||
|
private final ITaskObjectService taskObjectService; |
||||||
|
|
||||||
|
@GetMapping("/getVideosByObjId") |
||||||
|
@ApiOperation("根据任务对象ID获取摄像头点位信息") |
||||||
|
@ApiOperationSupport(order = 1) |
||||||
|
public R<List<StationVideoTypeEntity>> getVideosByObjId(@RequestParam @ApiParam("任务ID") Long taskId, @RequestParam @ApiParam("对象ID") Long objId) { |
||||||
|
return R.data(taskObjectService.getVideosByObjId(taskId,objId)); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,217 @@ |
|||||||
|
package com.hnac.hzinfo.inspect.task.schedule; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON; |
||||||
|
import com.alibaba.fastjson.JSONArray; |
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||||
|
import com.google.common.collect.Lists; |
||||||
|
import com.hnac.hzinfo.datasearch.soe.ISoeClient; |
||||||
|
import com.hnac.hzinfo.datasearch.soe.vo.DeviceSoeVO; |
||||||
|
import com.hnac.hzinfo.inspect.ai.entity.CameraInfoEntity; |
||||||
|
import com.hnac.hzinfo.inspect.ai.entity.RobotTaskEntity; |
||||||
|
import com.hnac.hzinfo.inspect.ai.service.ICameraInfoService; |
||||||
|
import com.hnac.hzinfo.inspect.ai.service.IRobotTaskService; |
||||||
|
import com.hnac.hzinfo.inspect.areamonthly.vo.TaskObjectVO; |
||||||
|
import com.hnac.hzinfo.inspect.hikVideo.service.IHikApiService; |
||||||
|
import com.hnac.hzinfo.inspect.plan.PlanContants; |
||||||
|
import com.hnac.hzinfo.inspect.task.TaskContants; |
||||||
|
import com.hnac.hzinfo.inspect.task.entity.EventEntity; |
||||||
|
import com.hnac.hzinfo.inspect.task.entity.EventRecordEntity; |
||||||
|
import com.hnac.hzinfo.inspect.task.entity.TaskEntity; |
||||||
|
import com.hnac.hzinfo.inspect.task.entity.TaskUserEntity; |
||||||
|
import com.hnac.hzinfo.inspect.task.service.IEventRecordService; |
||||||
|
import com.hnac.hzinfo.inspect.task.service.IEventService; |
||||||
|
import com.hnac.hzinfo.inspect.task.service.ITaskService; |
||||||
|
import com.hnac.hzinfo.inspect.task.service.ITaskUserService; |
||||||
|
import com.hnac.hzinfo.sdk.core.response.HzPage; |
||||||
|
import com.hnac.hzinfo.sdk.core.response.Result; |
||||||
|
import com.xxl.job.core.biz.model.ReturnT; |
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob; |
||||||
|
import com.xxl.job.core.log.XxlJobLogger; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springblade.core.tool.utils.CollectionUtil; |
||||||
|
import org.springblade.core.tool.utils.DateUtil; |
||||||
|
import org.springblade.core.tool.utils.Func; |
||||||
|
import org.springblade.core.tool.utils.StringUtil; |
||||||
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
import org.springframework.transaction.TransactionDefinition; |
||||||
|
import org.springframework.transaction.annotation.Transactional; |
||||||
|
|
||||||
|
import java.time.LocalDateTime; |
||||||
|
import java.util.List; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
|
||||||
|
import static com.hnac.hzinfo.inspect.task.schedule.XxlJobConstants.EXECUTE_VIDEO_TASK; |
||||||
|
|
||||||
|
/** |
||||||
|
* 视频巡检任务定时调度 |
||||||
|
*/ |
||||||
|
@Component |
||||||
|
@AllArgsConstructor |
||||||
|
@Slf4j |
||||||
|
public class VideoTaskSchedule { |
||||||
|
|
||||||
|
private final ITaskService taskService; |
||||||
|
private final ITaskUserService taskUserService; |
||||||
|
private final IEventService eventService; |
||||||
|
private final IEventRecordService eventRecordService; |
||||||
|
private final IHikApiService hikApiService; |
||||||
|
private final IRobotTaskService robotTaskService; |
||||||
|
private final ICameraInfoService cameraInfoService; |
||||||
|
private final ISoeClient soeClient; |
||||||
|
private final DataSourceTransactionManager dataSourceTransactionManager; |
||||||
|
private final TransactionDefinition transactionDefinition; |
||||||
|
|
||||||
|
/** |
||||||
|
* 视频巡检任务执行 |
||||||
|
* @param params 任务ID |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@XxlJob(EXECUTE_VIDEO_TASK) |
||||||
|
@Transactional |
||||||
|
public ReturnT<String> execute(String params) throws InterruptedException { |
||||||
|
List<TaskEntity> taskList = Lists.newArrayList(); |
||||||
|
// 获取待执行的任务
|
||||||
|
if(StringUtil.isBlank(params)) { |
||||||
|
LambdaQueryWrapper<TaskEntity> queryWrapper = Wrappers.<TaskEntity>lambdaQuery() |
||||||
|
.eq(TaskEntity::getStatus, TaskContants.TaskStatusEnum.INIT_STATUS.getStatus()) |
||||||
|
.le(TaskEntity::getPlanStartTime, LocalDateTime.now()) |
||||||
|
.ge(TaskEntity::getPlanEndTime, LocalDateTime.now()) |
||||||
|
.eq(TaskEntity::getAutoVideo, PlanContants.InspectTypeEnum.VIDEO.getVal()); |
||||||
|
taskList.addAll(taskService.list(queryWrapper)); |
||||||
|
} |
||||||
|
else { |
||||||
|
LambdaQueryWrapper<TaskEntity> queryWrapper = Wrappers.<TaskEntity>lambdaQuery() |
||||||
|
.in(TaskEntity::getId, Func.toLongList(",", params)) |
||||||
|
.eq(TaskEntity::getStatus, TaskContants.TaskStatusEnum.UNDERWAY_STATUS.getStatus()) |
||||||
|
.eq(TaskEntity::getAutoVideo, PlanContants.InspectTypeEnum.VIDEO.getVal()); |
||||||
|
taskList.addAll(taskService.list(queryWrapper)); |
||||||
|
} |
||||||
|
taskList.forEach(this::executeVideoTask); |
||||||
|
return ReturnT.SUCCESS; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 执行视频巡检任务 |
||||||
|
* @param task 视频巡检任务 |
||||||
|
*/ |
||||||
|
private void executeVideoTask(TaskEntity task) { |
||||||
|
try { |
||||||
|
// 登记任务
|
||||||
|
this.registration(task); |
||||||
|
// 完善视频巡检执行情况
|
||||||
|
this.fillEvent(task); |
||||||
|
// 更新视频巡检任务状态
|
||||||
|
taskService.update(Wrappers.<TaskEntity>lambdaUpdate() |
||||||
|
.set(TaskEntity::getStatus,TaskContants.TaskStatusEnum.FINISH_STATUS.getStatus()) |
||||||
|
.set(TaskEntity::getEndTime,LocalDateTime.now()) |
||||||
|
.eq(TaskEntity::getId,task.getId())); |
||||||
|
} |
||||||
|
catch(Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
XxlJobLogger.log("【taskId:"+task.getId()+"】视频巡检任务执行失败,报错信息为:"+e.getMessage()); |
||||||
|
} |
||||||
|
try { |
||||||
|
Thread.sleep(3*1000); |
||||||
|
} catch (InterruptedException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 填充视频巡检执行情况 |
||||||
|
* @param task 视频巡检任务 |
||||||
|
*/ |
||||||
|
private void fillEvent(TaskEntity task) { |
||||||
|
List<com.hnac.hzinfo.inspect.task.vo.TaskObjectVO> taskObjects = taskService.getTaskById(task.getId()); |
||||||
|
List<TaskObjectVO> taskObjectList = JSONArray.parseArray(JSON.toJSONString(taskObjects),TaskObjectVO.class); |
||||||
|
taskObjectList.forEach(object -> object.getProjects().forEach(project -> { |
||||||
|
EventEntity event = new EventEntity(); |
||||||
|
event.setTaskId(task.getId()); |
||||||
|
event.setObjectId(object.getObjId()); |
||||||
|
event.setProjectId(project.getProjectId()); |
||||||
|
event.setIsProblem("0"); |
||||||
|
event.setTenantId(task.getTenantId()); |
||||||
|
event.setCreateUser(task.getCreateUser()); |
||||||
|
event.setCreateDept(task.getCreateDept()); |
||||||
|
event.setUpdateUser(task.getUpdateUser()); |
||||||
|
eventService.save(event); |
||||||
|
List<EventRecordEntity> recordList = project.getContents().stream().map(content -> { |
||||||
|
EventRecordEntity record = new EventRecordEntity(); |
||||||
|
record.setEventId(event.getId()); |
||||||
|
record.setObjectId(object.getObjId()); |
||||||
|
record.setProjectId(project.getProjectId()); |
||||||
|
record.setContentId(content.getContentId()); |
||||||
|
record.setTenantId(task.getTenantId()); |
||||||
|
record.setCreateUser(task.getCreateUser()); |
||||||
|
record.setCreateDept(task.getCreateDept()); |
||||||
|
record.setUpdateUser(task.getUpdateUser()); |
||||||
|
record.setCurrentStatus("1"); |
||||||
|
CameraInfoEntity camera = this.getCameraByProIdAndConId(project.getProjectId(), content.getContentId()); |
||||||
|
if(Func.isNotEmpty(camera)) { |
||||||
|
// 获取计划时间段内视频的告警信息设置是否异常
|
||||||
|
if(Func.isNotEmpty(camera.getEmCode())) { |
||||||
|
Result<HzPage<DeviceSoeVO>> deviceSoeR = soeClient.getDeviceCodeByTaosSoe(DateUtil.formatDateTime(task.getPlanStartTime()), DateUtil.formatDateTime(task.getPlanEndTime()), camera.getEmCode(), 0, String.valueOf(-1)); |
||||||
|
if(deviceSoeR.isSuccess() && CollectionUtil.isNotEmpty(deviceSoeR.getData().getRecords())) { |
||||||
|
record.setCurrentStatus("0"); |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
// 调用海康威视api实现手动截屏回传至fileUrl
|
||||||
|
if(Func.isNotEmpty(camera.getPointCode())) { |
||||||
|
String picUrl = hikApiService.manualCapture(camera.getPointCode()); |
||||||
|
record.setFileUrl(picUrl); |
||||||
|
record.setCurrentValue(picUrl); |
||||||
|
} |
||||||
|
} |
||||||
|
return record; |
||||||
|
}).collect(Collectors.toList()); |
||||||
|
eventRecordService.saveBatch(recordList); |
||||||
|
if(recordList.stream().anyMatch(r -> TaskContants.CurrentStatusEnum.abnormal.getType().equals(r.getCurrentStatus()))) { |
||||||
|
eventService.update(Wrappers.<EventEntity>lambdaUpdate().set(EventEntity::getIsProblem,"1").eq(EventEntity::getId,event.getId())); |
||||||
|
} |
||||||
|
})); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 登记任务 |
||||||
|
* @param task 视频巡检任务 |
||||||
|
*/ |
||||||
|
private void registration(TaskEntity task) { |
||||||
|
// 选择第一个人领用改任务
|
||||||
|
LambdaQueryWrapper<TaskUserEntity> userQueryWrapper = Wrappers.<TaskUserEntity>lambdaQuery().eq(TaskUserEntity::getTaskId, task.getId()); |
||||||
|
List<TaskUserEntity> taskUserList = taskUserService.list(userQueryWrapper); |
||||||
|
TaskUserEntity taskUserEntity = taskUserList.get(0); |
||||||
|
task.setUserId(taskUserEntity.getUserId()); |
||||||
|
taskUserEntity.setClaimStatus(TaskContants.ClaimStatusEnum.COLLECT.getStatus()); |
||||||
|
taskUserEntity.setClaimTime(LocalDateTime.now()); |
||||||
|
taskUserService.updateById(taskUserEntity); |
||||||
|
if(PlanContants.PlanMethodEnum.SEIZE.getMethod().equals(task.getMethod())) { |
||||||
|
taskUserService.removeByIds(taskUserList.stream().map(TaskUserEntity::getId).filter(id -> !taskUserEntity.getId().equals(id)).collect(Collectors.toList())); |
||||||
|
} |
||||||
|
// 更改任务状态
|
||||||
|
task.setStatus(Integer.valueOf(TaskContants.TaskStatusEnum.UNDERWAY_STATUS.getStatus())); |
||||||
|
task.setStartTime(LocalDateTime.now()); |
||||||
|
taskService.updateById(task); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 根据项目ID以及内容ID获取摄像头编号 |
||||||
|
* @param projectId 项目ID |
||||||
|
* @param contentId 内容ID |
||||||
|
* @return 摄像头编号 |
||||||
|
*/ |
||||||
|
private CameraInfoEntity getCameraByProIdAndConId(Long projectId,Long contentId) { |
||||||
|
RobotTaskEntity robotTaskEntity = robotTaskService.getOne(Wrappers.<RobotTaskEntity>lambdaQuery() |
||||||
|
.eq(RobotTaskEntity::getProjectId, projectId) |
||||||
|
.like(RobotTaskEntity::getContentIds, String.valueOf(contentId)) |
||||||
|
); |
||||||
|
if(Func.isNotEmpty(robotTaskEntity)) { |
||||||
|
return cameraInfoService.getById(robotTaskEntity.getCameraId()); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -1,3 +1,10 @@ |
|||||||
ALTER TABLE `hzims-inspect`.`hz_st_ex_task_user` MODIFY COLUMN `CLAIM_STATUS` char(1) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '领用状态 0:未领用 1:已领用 每条任务可以存在多个用户,但是只有一个领用人' AFTER `USER_ID`; |
ALTER TABLE `hzims-inspect`.`hz_st_ex_task_user` MODIFY COLUMN `CLAIM_STATUS` char(1) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '领用状态 0:未领用 1:已领用 每条任务可以存在多个用户,但是只有一个领用人' AFTER `USER_ID`; |
||||||
|
|
||||||
ALTER TABLE `hzims-inspect`.`hz_st_ex_task_user` ADD COLUMN `user_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL AFTER `TENANT_ID`; |
ALTER TABLE `hzims-inspect`.`hz_st_ex_task_user` ADD COLUMN `user_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL AFTER `TENANT_ID`; |
||||||
|
|
||||||
|
alter table `hz_st_ex_task` add column `hik_video_task_id` varchar(50) default null comment '海康录制视频任务ID'; |
||||||
|
alter table `hz_st_ex_task` add column `video_start_time` datetime default null comment '视频录制开始时间'; |
||||||
|
alter table `hz_st_ex_task` add column `video_end_time` datetime default null comment '视频录制开始时间'; |
||||||
|
alter table `hz_st_ex_task` add column `video_url` varchar(255) default null comment '手动录制视频地址'; |
||||||
|
-- 巡检摄像头管理添加设备编号 |
||||||
|
alter table `hz_st_camera_info` add column `em_code` varchar(50) default null comment '设备编号'; |
Loading…
Reference in new issue