| | |
| | | package com.ycl.platform.service.impl; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | |
| | | import com.mongodb.client.MongoCollection; |
| | | import com.mongodb.client.MongoDatabase; |
| | | import com.ycl.platform.domain.entity.*; |
| | | import com.ycl.platform.domain.excel.RecordingAvailabilityExport; |
| | | import com.ycl.platform.domain.excel.TMonitorExp; |
| | | import com.ycl.platform.domain.form.UpdateDynamicValueForm; |
| | | import com.ycl.platform.domain.query.DataCenterQuery; |
| | | import com.ycl.platform.domain.result.HK.*; |
| | | import com.ycl.platform.domain.result.SYS.TMonitorResult; |
| | |
| | | import com.ycl.platform.domain.vo.DataCenter.BigPicUsefulVO; |
| | | import com.ycl.platform.domain.vo.DataCenter.MonitorQualifyResultVO; |
| | | import com.ycl.platform.domain.vo.DataCenter.SnapClockVO; |
| | | import com.ycl.platform.domain.vo.DynamicColumnVO; |
| | | import com.ycl.platform.domain.vo.PointDetailVO; |
| | | import com.ycl.platform.domain.vo.home.HomeFaceVO; |
| | | import com.ycl.platform.mapper.DynamicColumnMapper; |
| | | import com.ycl.platform.mapper.ImageResourceSecurityDetailMapper; |
| | | import com.ycl.platform.mapper.YwPointMapper; |
| | | import com.ycl.platform.service.*; |
| | |
| | | import com.ycl.utils.poi.ExcelUtil; |
| | | import constant.ApiConstants; |
| | | import constant.CheckConstants; |
| | | import constant.RecordingAvailability; |
| | | import enumeration.general.AreaDeptEnum; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.bson.Document; |
| | | import org.springframework.data.domain.Sort; |
| | |
| | | import org.springframework.data.mongodb.core.query.TextCriteria; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.DecimalFormat; |
| | |
| | | */ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | @Slf4j |
| | | public class DataCenterServiceImpl implements DataCenterService { |
| | | |
| | | private final MongoTemplate mongoTemplate; |
| | |
| | | private final ICheckIndexVideoService checkIndexVideoService; |
| | | private final ICheckIndexCarService checkIndexCarService; |
| | | private final ICheckIndexFaceService checkIndexFaceService; |
| | | private final DynamicColumnMapper dynamicColumnMapper; |
| | | |
| | | |
| | | |
| | | private final static String TIME_FIELD = "mongoCreateTime"; |
| | | |
| | | private static DecimalFormat DF = new DecimalFormat("#.####"); |
| | | |
| | | @Override |
| | | public void recordingAvailabilityExport(HttpServletResponse response,DataCenterQuery params) throws IOException { |
| | | List<String> likeFileds = Arrays.asList("deviceId", "deviceName"); |
| | | Query query = MongoUtil.getQuery(params, "createTime", likeFileds, null); |
| | | //下拉框录像情况查询条件 |
| | | if (params.getOption() != null) { |
| | | query.addCriteria(Criteria.where("recordStatus").is(params.getOption())); |
| | | } |
| | | List<RecordMetaDSumResult> resultList = mongoTemplate.find(query, RecordMetaDSumResult.class); |
| | | List<DynamicColumnVO> dynamicColumnVOList = dynamicColumnMapper.getDynamicColumnByTableName("uy_record_meta_d_sum"); |
| | | //翻译行政区域 |
| | | resultList.forEach(item -> { |
| | | String areaCode = item.getArealayername().substring(0, 6); |
| | | AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromCode(areaCode); |
| | | if (areaDeptEnum != null) item.setArealayername(areaDeptEnum.getName()); |
| | | }); |
| | | Map<String,List<DynamicColumnVO>> groupByRefStringIdMap = dynamicColumnVOList.stream().collect(Collectors.groupingBy(DynamicColumnVO::getRefStringId)); |
| | | //提那家固定表头 |
| | | LinkedHashSet<String> headers = new LinkedHashSet<>(); |
| | | headers.add(RecordingAvailability.arealayername); |
| | | headers.add(RecordingAvailability.arealayerno); |
| | | headers.add(RecordingAvailability.createTime); |
| | | headers.add(RecordingAvailability.deviceId); |
| | | headers.add(RecordingAvailability.missDuration); |
| | | headers.add(RecordingAvailability.platId); |
| | | headers.add(RecordingAvailability.recordDuration); |
| | | headers.add(RecordingAvailability.recordStatusText); |
| | | headers.add(RecordingAvailability.statTime); |
| | | |
| | | List<String> headersList = new LinkedList<>(); |
| | | List<String> dynamicsHeaders = dynamicColumnMapper.getHeader("uy_record_meta_d_sum"); |
| | | |
| | | //添加动态表头 |
| | | if (!org.springframework.util.CollectionUtils.isEmpty(dynamicsHeaders)) { |
| | | //使用链表保证后续补充数据时获取数据顺序一致 |
| | | headersList.addAll(dynamicsHeaders); |
| | | headers.addAll(headersList); |
| | | } |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
| | | SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | List<List<Object>> data = new ArrayList<>(); |
| | | for (RecordMetaDSumResult result : resultList){ |
| | | List<Object> row = new ArrayList<>(); |
| | | row.add(result.getArealayername()); |
| | | row.add(result.getArealayerno()); |
| | | row.add(dateFormat2.format(result.getCreateTime())); |
| | | row.add(result.getDeviceId()); |
| | | row.add(result.getMissDuration()); |
| | | row.add(result.getPlatId()); |
| | | row.add(result.getRecordDuration()); |
| | | row.add(result.getRecordStatusText()); |
| | | row.add(dateFormat2.format(result.getCreateTime())); |
| | | //添加动态列数据 |
| | | for (String header : headersList){ |
| | | boolean flag = false; |
| | | List<DynamicColumnVO> columnVOS = groupByRefStringIdMap.get(result.getId()); |
| | | if (!CollectionUtils.isEmpty(columnVOS)) { |
| | | for (DynamicColumnVO columnVO : columnVOS) { |
| | | if (header.equals(columnVO.getLabelValue())) { |
| | | row.add(columnVO.getColumnValue()); |
| | | flag = true; |
| | | } |
| | | } |
| | | } |
| | | //没找到用空串占位 |
| | | if (!flag) row.add(""); |
| | | } |
| | | data.add(row); |
| | | } |
| | | List<List<String>> headList = new ArrayList<>(); |
| | | for (String header : headers) { |
| | | headList.add(Collections.singletonList(header)); |
| | | } |
| | | EasyExcel.write(response.getOutputStream()) |
| | | .head(headList) // 设置表头 |
| | | .sheet("录像可用率") // 设置sheet名称 |
| | | .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) |
| | | .doWrite(data); // 写入数据 |
| | | } |
| | | |
| | | @Override |
| | | public void pointOnlineExport(HttpServletResponse response,DataCenterQuery query) throws IOException { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public Result updateDynamicValue(UpdateDynamicValueForm form) { |
| | | List<DynamicColumnVO> list = form.getDynamicColumnVOList(); |
| | | |
| | | if (CollectionUtils.isEmpty(list) || StringUtils.isEmpty(form.getId())) { |
| | | throw new RuntimeException("修改自定义列的传入值为null或传入id为null"); |
| | | } |
| | | List<DynamicColumnValue> updateList = new ArrayList<>(); |
| | | List<DynamicColumnValue> addList = new ArrayList<>(); |
| | | |
| | | for (DynamicColumnVO dynamicColumnVO : list){ |
| | | if(dynamicColumnVO.getColumnValue() == null){ |
| | | continue; |
| | | } |
| | | DynamicColumnValue dynamicColumnValue = new DynamicColumnValue(); |
| | | dynamicColumnValue.setColumnValue(dynamicColumnVO.getColumnValue()); |
| | | dynamicColumnValue.setDynamicColumnId(dynamicColumnVO.getId()); |
| | | dynamicColumnValue.setRefStringId(form.getId()); |
| | | dynamicColumnValue.setRefId(0); |
| | | if(dynamicColumnVO.getValueId() == null){ |
| | | addList.add(dynamicColumnValue); |
| | | }else { |
| | | dynamicColumnValue.setId(dynamicColumnVO.getValueId()); |
| | | updateList.add(dynamicColumnValue); |
| | | } |
| | | } |
| | | log.error("addList:{}",addList); |
| | | log.error("updateList:{}",updateList); |
| | | if (CollectionUtils.isNotEmpty(addList)){ |
| | | dynamicColumnMapper.saveBatch(addList); |
| | | } |
| | | if (CollectionUtils.isNotEmpty(updateList)) { |
| | | dynamicColumnMapper.updateBatch(updateList); |
| | | } |
| | | return Result.ok("修改成功"); |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 视频:点位在线率 |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | |
| | | public Result videoAvailabilityRate(DataCenterQuery params) { |
| | | List<String> likeFileds = Arrays.asList("deviceId", "deviceName"); |
| | | Query query = MongoUtil.getQuery(params, "createTime", likeFileds, null); |
| | |
| | | long total = mongoTemplate.count(query, RecordMetaDSumResult.class); |
| | | MongoUtil.setPage(query, params, "createTime"); |
| | | List<RecordMetaDSumResult> resultList = mongoTemplate.find(query, RecordMetaDSumResult.class); |
| | | //查询动态列数据 |
| | | //查询动态列数据更具id查询 |
| | | // List<DynamicColumnVO> dynamicColumnNames = dynamicColumnMapper.getDynamicColumnByTableName("uy_record_meta_d_sum"); |
| | | //翻译行政区域 |
| | | resultList.forEach(item -> { |
| | | String areaCode = item.getArealayername().substring(0, 6); |
| | | AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromCode(areaCode); |
| | | if (areaDeptEnum != null) item.setArealayername(areaDeptEnum.getName()); |
| | | |
| | | List<DynamicColumnVO> list = dynamicColumnMapper.getDynamicColumnByTable("uy_record_meta_d_sum",item.getId()); |
| | | item.setDynamicColumnList(list); |
| | | |
| | | }); |
| | | // 统计数量 |
| | | MongoDatabase database = mongoTemplate.getDb(); |
| | |
| | | resultCount.add(0, totalCount + ""); |
| | | |
| | | BigDecimal onlineRate = BigDecimal.ZERO; |
| | | // 1:完整 0:间歇 -1:异常 | |
| | | if (!StringUtils.isEmpty(resultCount.get(0)) && !"0".equals(resultCount.get(0))) { |
| | | //resultCount.get(0) |
| | | onlineRate = new BigDecimal(resultCount.get(1)).divide(new BigDecimal(resultCount.get(0)), 3,RoundingMode.DOWN).multiply(new BigDecimal("100")); |
| | | } |
| | | resultCount.add(this.remove0(onlineRate)); |
| | | |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | log.error("resultCount:{}",resultCount.get(3)); |
| | | map.put("count", resultCount); |
| | | map.put("list", resultList); |
| | | return Result.ok().data(map).total(total); |
| | |
| | | sampleCount = doc.getInteger("sampleCount"); |
| | | expCount = doc.getInteger("expCount"); |
| | | } |
| | | |
| | | |
| | | //新构建聚合查询离线时间 |
| | | |
| | | List<String> countList = new ArrayList<>(); |
| | | |
| | | // 统计数 |
| | |
| | | onlineRate = new BigDecimal(sampleCount-expCount).divide(new BigDecimal(sampleCount), 3,RoundingMode.DOWN).multiply(new BigDecimal("100")); |
| | | } |
| | | countList.add(this.remove0(onlineRate)); |
| | | |
| | | |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("count", countList); |
| | | map.put("list", voList); |