|
|
@@ -0,0 +1,177 @@
|
|
|
+package com.xunmei.host.video.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
+import com.xunmei.common.core.constant.ErrorMsgConstants;
|
|
|
+import com.xunmei.common.core.domain.iot.domain.*;
|
|
|
+import com.xunmei.common.core.utils.JacksonUtils;
|
|
|
+import com.xunmei.common.core.utils.bean.BeanUtils;
|
|
|
+import com.xunmei.host.video.dto.templateAndPlan.DvsPlanTimeDto;
|
|
|
+import com.xunmei.host.video.dto.templateAndPlan.DvsPlanTypeDto;
|
|
|
+import com.xunmei.host.video.dto.templateAndPlan.DvsTemplateChannelDto;
|
|
|
+import com.xunmei.host.video.dto.templateAndPlan.DvsTemplateDto;
|
|
|
+import com.xunmei.host.video.service.*;
|
|
|
+import com.xunmei.host.websocket.constant.WebSocketConstants;
|
|
|
+import com.xunmei.host.websocket.dto.WebsocketExecuteReq;
|
|
|
+import com.xunmei.host.websocket.dto.WebsocketResult;
|
|
|
+import com.xunmei.host.websocket.enums.ProductEnums;
|
|
|
+import com.xunmei.host.websocket.service.RouterService;
|
|
|
+import com.xunmei.system.api.util.LogUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.StringJoiner;
|
|
|
+
|
|
|
+
|
|
|
+@Service
|
|
|
+public class IotDvsTemplateAndPlanServiceImpl implements IotDvsTemplateAndPlanService, RouterService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private IotDvsTemplateService dvsTemplateService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private IotDvsTemplateChannelService dvsTemplateChannelService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private IotDvsPlanTypeService dvsPlanTypeService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private IotDvsPlanTimeService dvsPlanTimeService;
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void handDvsTemplateAndPlan(List<DvsTemplateDto> dataList, IotServerInfo serverInfo) {
|
|
|
+ //先删除数据
|
|
|
+ deleteDvsTemplateAndPlanByIotCode(serverInfo.getIotCode());
|
|
|
+ //处理录像模板和录像计划数据
|
|
|
+ for (DvsTemplateDto dvsTemplateDto : dataList) {
|
|
|
+ IotDvsTemplate dvsTemplate = new IotDvsTemplate();
|
|
|
+ BeanUtils.copyProperties(dvsTemplateDto, dvsTemplate);
|
|
|
+ dvsTemplate.setIotToken(serverInfo.getIotCode());
|
|
|
+ dvsTemplate.setId(IdWorker.getId());
|
|
|
+
|
|
|
+ List<IotDvsTemplateChannel> dvsTemplateChannels = handleTemplateChannelList(dvsTemplateDto.getChannelList(), dvsTemplate.getTemplateMd5(), serverInfo.getIotCode());
|
|
|
+ List<IotDvsPlantype> iotDvsPlanTypes = handlePlanTypeList(dvsTemplateDto.getPlanTypeList(), serverInfo.getIotCode());
|
|
|
+ List<IotDvsPlantime> iotDvsPlanTimes = handlePlanTimeList(dvsTemplateDto.getPlanTimeList(), serverInfo.getIotCode());
|
|
|
+
|
|
|
+ dvsTemplateService.save(dvsTemplate);
|
|
|
+ if (dvsTemplateChannels.size() > 0) {
|
|
|
+ dvsTemplateChannelService.saveBatch(dvsTemplateChannels);
|
|
|
+ }
|
|
|
+ if (iotDvsPlanTypes.size() > 0) {
|
|
|
+ dvsPlanTypeService.saveBatch(iotDvsPlanTypes);
|
|
|
+ }
|
|
|
+ if (iotDvsPlanTimes.size() > 0) {
|
|
|
+ dvsPlanTimeService.saveBatch(iotDvsPlanTimes);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<IotDvsTemplateChannel> handleTemplateChannelList(List<DvsTemplateChannelDto> channelList,String templateMd5,String iotCode){
|
|
|
+ ArrayList<IotDvsTemplateChannel> list = new ArrayList<>();
|
|
|
+ for (DvsTemplateChannelDto dvsTemplateChannelDto : channelList) {
|
|
|
+ IotDvsTemplateChannel templateChannel = new IotDvsTemplateChannel();
|
|
|
+ BeanUtils.copyProperties(dvsTemplateChannelDto, templateChannel);
|
|
|
+ templateChannel.setTemplateMd5(templateMd5);
|
|
|
+ templateChannel.setIotToken(iotCode);
|
|
|
+ templateChannel.setId(IdWorker.getId());
|
|
|
+ list.add(templateChannel);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<IotDvsPlantype> handlePlanTypeList(List<DvsPlanTypeDto> planTypeList, String iotCode){
|
|
|
+ ArrayList<IotDvsPlantype> list = new ArrayList<>();
|
|
|
+ for (DvsPlanTypeDto dvsPlanTypeDto : planTypeList) {
|
|
|
+ IotDvsPlantype plantype = new IotDvsPlantype();
|
|
|
+ BeanUtils.copyProperties(dvsPlanTypeDto, plantype);
|
|
|
+ plantype.setIotToken(iotCode);
|
|
|
+ plantype.setId(IdWorker.getId());
|
|
|
+ list.add(plantype);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<IotDvsPlantime> handlePlanTimeList(List<DvsPlanTimeDto> planTimeList, String iotCode){
|
|
|
+ ArrayList<IotDvsPlantime> list = new ArrayList<>();
|
|
|
+ for( DvsPlanTimeDto dvsPlanTimeDto : planTimeList){
|
|
|
+ IotDvsPlantime plantime = new IotDvsPlantime();
|
|
|
+ BeanUtils.copyProperties(dvsPlanTimeDto, plantime);
|
|
|
+ plantime.setEndTime(dvsPlanTimeDto.getStopTime());
|
|
|
+ plantime.setIotToken(iotCode);
|
|
|
+ plantime.setId(IdWorker.getId());
|
|
|
+ list.add(plantime);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void deleteDvsTemplateAndPlanByIotCode(String iotCode) {
|
|
|
+ //IotDvsTemplate表
|
|
|
+ QueryWrapper<IotDvsTemplate> templateWrapper = new QueryWrapper<>();
|
|
|
+ templateWrapper.lambda().eq(IotDvsTemplate::getIotToken, iotCode);
|
|
|
+ dvsTemplateService.remove(templateWrapper);
|
|
|
+
|
|
|
+ //IotDvsTemplateChannel表
|
|
|
+ QueryWrapper<IotDvsTemplateChannel> templateChannelWrapper = new QueryWrapper<>();
|
|
|
+ templateChannelWrapper.lambda().eq(IotDvsTemplateChannel::getIotToken, iotCode);
|
|
|
+ dvsTemplateChannelService.remove(templateChannelWrapper);
|
|
|
+
|
|
|
+ //IotDvsPlantype表
|
|
|
+ QueryWrapper<IotDvsPlantype> planTypeWrapper = new QueryWrapper<>();
|
|
|
+ planTypeWrapper.lambda().eq(IotDvsPlantype::getIotToken, iotCode);
|
|
|
+ dvsPlanTypeService.remove(planTypeWrapper);
|
|
|
+
|
|
|
+ //IotDvsPlantime表
|
|
|
+ QueryWrapper<IotDvsPlantime> planTimeWrapper = new QueryWrapper<>();
|
|
|
+ planTimeWrapper.lambda().eq(IotDvsPlantime::getIotToken, iotCode);
|
|
|
+ dvsPlanTimeService.remove(planTimeWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ProductEnums product() {
|
|
|
+ return ProductEnums.DETECTION_HOST;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String routerKey() {
|
|
|
+ StringJoiner result = new StringJoiner(",");
|
|
|
+ //全量录像模板和录像计划
|
|
|
+ result.add(WebSocketConstants.DVS_TEMPLATE_AND_PLAN);
|
|
|
+ return result.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRES_NEW)
|
|
|
+ public WebsocketResult execute(WebsocketExecuteReq req) {
|
|
|
+ try {
|
|
|
+ LogUtils.SOCKET_DVS_TEMPLATE_INFO.info("收到消息:{}", JacksonUtils.toJSONString(req));
|
|
|
+ Object data = req.getData();
|
|
|
+ JSONArray dataArray = (JSONArray) data;
|
|
|
+ if (ObjectUtil.isEmpty(dataArray)) {
|
|
|
+ return WebsocketResult.replySuccess(req);
|
|
|
+ }
|
|
|
+ IotServerInfo serverInfo = req.getServerInfo();
|
|
|
+ String event = req.getEvent();
|
|
|
+ if (event.equals(WebSocketConstants.DVS_TEMPLATE_AND_PLAN)) {
|
|
|
+ List<DvsTemplateDto> dataList = dataArray.toJavaList(DvsTemplateDto.class);
|
|
|
+ handDvsTemplateAndPlan(dataList, serverInfo);
|
|
|
+ }else {
|
|
|
+ return WebsocketResult.replyError(req, ErrorMsgConstants.ERROR_ROUTE);
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ LogUtils.SOCKET_DVS_TEMPLATE_INFO.error("dvs录像模板和录像计划,处理失败", e);
|
|
|
+ throw new RuntimeException("dvs录像模板和录像计划,处理失败",e);
|
|
|
+ }
|
|
|
+ return WebsocketResult.replySuccess(req);
|
|
|
+ }
|
|
|
+}
|