| | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.ExcelWriter; |
| | | import com.alibaba.excel.write.metadata.WriteSheet; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.dataListener.CurrencyDataListener; |
| | | import com.ycl.platform.base.AbsVo; |
| | | import com.ycl.platform.domain.entity.ReportAuditingRecord; |
| | | import com.ycl.platform.domain.entity.YwPeople; |
| | | import com.ycl.platform.domain.entity.YwPoint; |
| | | import com.ycl.platform.domain.entity.*; |
| | | import com.ycl.platform.domain.excel.PointExport; |
| | | import com.ycl.platform.domain.form.BatchEditPointForm; |
| | | import com.ycl.platform.domain.form.YwPointForm; |
| | |
| | | import com.ycl.platform.mapper.TMonitorMapper; |
| | | import com.ycl.platform.mapper.YwPeopleMapper; |
| | | import com.ycl.platform.mapper.YwPointMapper; |
| | | import com.ycl.platform.service.DynamicColumnService; |
| | | import com.ycl.platform.service.YwPointService; |
| | | import com.ycl.platform.service.YwUnitService; |
| | | import com.ycl.system.Result; |
| | |
| | | import com.ycl.utils.DateUtils; |
| | | import com.ycl.utils.SecurityUtils; |
| | | import com.ycl.utils.poi.EasyExcelImportUtils; |
| | | import com.ycl.utils.uuid.IdUtils; |
| | | import constant.CheckConstants; |
| | | import constant.PointHeaderConstant; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.context.ApplicationContext; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.Assert; |
| | |
| | | private final SysDeptMapper sysDeptMapper; |
| | | private final TMonitorMapper monitorMapper; |
| | | private final DynamicColumnMapper dynamicColumnMapper; |
| | | private final ApplicationContext context; |
| | | |
| | | /** |
| | | * 添加 |
| | |
| | | YwPoint entity = baseMapper.selectById(form.getId()); |
| | | Assert.notNull(entity, "记录不存在"); |
| | | BeanUtils.copyProperties(form, entity); |
| | | if (form.getUnitId() != null) { |
| | | entity.setUnitId(Long.valueOf(form.getUnitId())); |
| | | }else { |
| | | entity.setUnitId(null); |
| | | } |
| | | Date now = new Date(); |
| | | entity.setUpdateTime(now); |
| | | baseMapper.updateById(entity); |
| | | baseMapper.myUpdateById(entity); |
| | | return Result.ok("修改成功"); |
| | | } |
| | | |
| | |
| | | Assert.notNull(entity, "记录不存在"); |
| | | YwPointVO vo = YwPointVO.getVoByEntity(entity, null); |
| | | if (Objects.nonNull(entity.getDeptId())) { |
| | | vo.setDeptIds(sysDeptMapper.selectParents(entity.getDeptId())); |
| | | //TODO:方法待完善 简单处理 |
| | | List<Long> deptIds = sysDeptMapper.selectParents(entity.getDeptId()); |
| | | deptIds.remove(deptIds.size()-1); |
| | | deptIds.add(entity.getDeptId()); |
| | | vo.setDeptIds(deptIds); |
| | | } |
| | | return Result.ok().data(vo); |
| | | } |
| | |
| | | List<DynamicColumnVO> dynamics = dynamicColumnMapper.getData(); |
| | | Map<Integer, List<DynamicColumnVO>> dynamicMap = new HashMap<>(); |
| | | if (!CollectionUtils.isEmpty(dynamics)) { |
| | | dynamicMap = dynamics.stream().filter(vo ->vo.getId()!=null).collect(Collectors.groupingBy(AbsVo::getId)); |
| | | dynamicMap = dynamics.stream().filter(vo -> vo.getRefId() != null).collect(Collectors.groupingBy(DynamicColumnVO::getRefId)); |
| | | } |
| | | //定义表头列表 |
| | | LinkedHashSet<String> headers = new LinkedHashSet<>(); |
| | | headers.add(PointHeaderConstant.ID); |
| | | headers.add(PointHeaderConstant.Point_Name); |
| | | headers.add(PointHeaderConstant.Serial_Number); |
| | | headers.add(PointHeaderConstant.IP); |
| | | headers.add(PointHeaderConstant.Province_Tag); |
| | | headers.add(PointHeaderConstant.Area); |
| | | headers.add(PointHeaderConstant.Unit); |
| | | headers.add(PointHeaderConstant.Province_Tag_Video); |
| | | headers.add(PointHeaderConstant.Province_Tag_Car); |
| | | headers.add(PointHeaderConstant.Province_Tag_Face); |
| | | headers.add(PointHeaderConstant.Impotrant_Command_Image); |
| | | headers.add(PointHeaderConstant.Dept_Tag); |
| | | List<String> headersList = new LinkedList<>(); |
| | |
| | | for (PointExport export : exportData) { |
| | | List<Object> list = new ArrayList<>(); |
| | | //需要保证顺序一致 |
| | | list.add(export.getId()); |
| | | list.add(export.getPointName()); |
| | | list.add(export.getSerialNumber()); |
| | | list.add(export.getPointIP()); |
| | | list.add(export.getProvinceTagString()); |
| | | list.add(export.getArea()); |
| | | list.add(export.getUnitName()); |
| | | list.add(export.getProvinceTagVideoString()); |
| | | list.add(export.getProvinceTagCarString()); |
| | | list.add(export.getProvinceTagFaceString()); |
| | | list.add(export.getImportantCommandImageTagString()); |
| | | list.add(export.getDeptTag()); |
| | | list.add(export.getDeptTagString()); |
| | | for (String header : headersList) { |
| | | //创建一个变量记录找没找到这个header |
| | | boolean flag = false; |
| | |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result importData(MultipartFile file, Integer unitId, Date startTime, Date endTime, Boolean |
| | | needUpdateUnit) throws IOException { |
| | | // List<Map<String,String>> list = EasyExcelImportUtils.makeData(file); |
| | | Consumer<List<PointExport>> consumer = (dataList) -> { |
| | | try { |
| | | this.updatePoint(dataList, unitId, startTime, endTime, needUpdateUnit); |
| | | } catch (ExecutionException e) { |
| | | e.printStackTrace(); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | needUpdateUnit) throws IOException, ExecutionException, InterruptedException { |
| | | List<Map<String, String>> list = EasyExcelImportUtils.makeData(file); |
| | | List<PointExport> dataList = new ArrayList<>(); |
| | | // Consumer<List<PointExport>> consumer = (dataList) -> { |
| | | // try { |
| | | // this.updatePoint(dataList, unitId, startTime, endTime, needUpdateUnit); |
| | | // } catch (ExecutionException e) { |
| | | // e.printStackTrace(); |
| | | // } catch (InterruptedException e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // }; |
| | | // EasyExcel.read(file.getInputStream(), PointExport.class, new CurrencyDataListener(consumer)).headRowNumber(1).doReadAll(); |
| | | for (Map<String, String> map : list) { |
| | | PointExport pointExport = new PointExport(); |
| | | pointExport.setId(Integer.valueOf(map.get(PointHeaderConstant.ID))); |
| | | pointExport.setPointName(map.get(PointHeaderConstant.Point_Name)); |
| | | pointExport.setPointIP(map.get(PointHeaderConstant.IP)); |
| | | pointExport.setSerialNumber(map.get(PointHeaderConstant.Serial_Number)); |
| | | pointExport.setProvinceTagVideo("是".equals(map.get(PointHeaderConstant.Province_Tag_Video))); |
| | | pointExport.setProvinceTagCar("是".equals(map.get(PointHeaderConstant.Province_Tag_Car))); |
| | | pointExport.setProvinceTagFace("是".equals(map.get(PointHeaderConstant.Province_Tag_Face))); |
| | | pointExport.setImportantCommandImageTag("是".equals(map.get(PointHeaderConstant.Impotrant_Command_Image))); |
| | | pointExport.setDeptTag("是".equals(map.get(PointHeaderConstant.Dept_Tag))); |
| | | List<DynamicColumnVO> dynamics = new ArrayList<>(); |
| | | // 处理动态列 |
| | | for (Map.Entry<String, String> entry : map.entrySet()) { |
| | | String key = entry.getKey(); |
| | | if (!PointHeaderConstant.KNOWN_KEYS.contains(key)) { |
| | | DynamicColumnVO dynamicColumnVO = new DynamicColumnVO(); |
| | | dynamicColumnVO.setRefId(pointExport.getId()); |
| | | dynamicColumnVO.setLabelValue(entry.getKey()); |
| | | dynamicColumnVO.setColumnValue(entry.getValue()); |
| | | dynamicColumnVO.setPropName(IdUtils.randomNO(new Date())); |
| | | dynamicColumnVO.setTableName("t_yw_point"); |
| | | dynamics.add(dynamicColumnVO); |
| | | } |
| | | } |
| | | }; |
| | | EasyExcel.read(file.getInputStream(), PointExport.class, new CurrencyDataListener(consumer)).headRowNumber(1).doReadAll(); |
| | | // for (Map<String, String> map : list) { |
| | | // PointExport pointExport = new PointExport(); |
| | | // pointExport.setPointName(map.get(PointHeaderConstant.Point_Name)); |
| | | // pointExport.setPointIP(map.get(PointHeaderConstant.IP)); |
| | | // pointExport.setSerialNumber(map.get(PointHeaderConstant.Serial_Number)); |
| | | // } |
| | | // this.updatePoint(dataList, unitId, startTime, endTime, needUpdateUnit); |
| | | // System.out.println(list); |
| | | pointExport.setDynamicData(dynamics); |
| | | dataList.add(pointExport); |
| | | } |
| | | YwPointServiceImpl self = context.getBean(YwPointServiceImpl.class); |
| | | self.updatePoint(dataList, unitId, startTime, endTime, needUpdateUnit); |
| | | self.updateDynamic(dataList); |
| | | return Result.ok(); |
| | | } |
| | | |
| | |
| | | * @param dataList |
| | | * @param unitId |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updatePoint(List<PointExport> dataList, Integer unitId, Date startTime, Date endTime, Boolean |
| | | needUpdateUnit) throws ExecutionException, InterruptedException { |
| | | if (CollectionUtils.isEmpty(dataList)) { |
| | |
| | | } |
| | | List<YwPoint> pointList = dataList.stream().map(item -> { |
| | | YwPoint point = new YwPoint(); |
| | | point.setImportantCommandImageTag("是".equals(item.getImportantCommandImageTagString())); |
| | | point.setProvinceTag("是".equals(item.getProvinceTagString())); |
| | | point.setDeptTag("是".equals(item.getDeptTag())); |
| | | point.setImportantCommandImageTag(item.getImportantCommandImageTag()); |
| | | point.setProvinceTagVideo(item.getProvinceTagVideo()); |
| | | point.setProvinceTagCar(item.getProvinceTagCar()); |
| | | point.setProvinceTagFace(item.getProvinceTagFace()); |
| | | point.setDeptTag(item.getDeptTag()); |
| | | if (needUpdateUnit) { |
| | | if (Objects.nonNull(unitId)) { |
| | | point.setUnitId(Long.valueOf(unitId)); |
| | | } else { |
| | | point.setUnitId(null); |
| | | } |
| | | point.setStartTime(startTime); |
| | | point.setEndTime(endTime); |
| | |
| | | point.setSerialNumber(item.getSerialNumber()); |
| | | return point; |
| | | }).collect(Collectors.toList()); |
| | | this.waitAllFinishAndGetResult(pointList); |
| | | this.waitAllFinishAndGetResult(pointList, needUpdateUnit); |
| | | } |
| | | |
| | | public void waitAllFinishAndGetResult(List<YwPoint> dataList) { |
| | | @Override |
| | | public void updateDynamic(List<PointExport> dataList) { |
| | | List<DynamicColumnValue> insertList = new ArrayList<>(); |
| | | List<DynamicColumnValue> updateList = new ArrayList<>(); |
| | | List<Integer> deleteList = new ArrayList<>(); |
| | | //查出所有种类动态列作为字典 |
| | | Map<String, Integer> dictionary = new LambdaQueryChainWrapper<>(dynamicColumnMapper) |
| | | .list().stream().collect(Collectors.toMap(DynamicColumn::getLabelValue, DynamicColumn::getId)); |
| | | //查出点位表的所有动态列 |
| | | List<DynamicColumnVO> dynamicVOList = dynamicColumnMapper.getData(); |
| | | Map<Integer, List<DynamicColumnVO>> dynamicVOMap = new HashMap<>(); |
| | | if (!CollectionUtils.isEmpty(dynamicVOList)) { |
| | | dynamicVOMap = dynamicVOList.stream().filter(vo -> vo.getRefId() != null).collect(Collectors.groupingBy(DynamicColumnVO::getRefId)); |
| | | } |
| | | //根据label_value和ref_id判断是否是同一数据 |
| | | for (PointExport pointExport : dataList) { |
| | | //数据库中的动态列 |
| | | List<DynamicColumnVO> dynamicColumnVOS = dynamicVOMap.getOrDefault(pointExport.getId(), Collections.emptyList()); |
| | | Map<String, DynamicColumnVO> databaseMap = dynamicColumnVOS.stream() |
| | | .collect(Collectors.toMap(DynamicColumnVO::getLabelValue, Function.identity())); |
| | | |
| | | for (DynamicColumnVO excelVo : pointExport.getDynamicData()) { |
| | | String labelValue = excelVo.getLabelValue(); |
| | | DynamicColumnVO databaseVo = databaseMap.get(labelValue); |
| | | //如果excel值不为空判定为新增或修改 |
| | | if (excelVo.getColumnValue() != null) { |
| | | Integer dynamicId = dictionary.get(labelValue); |
| | | DynamicColumnValue entity = new DynamicColumnValue(); |
| | | entity.setColumnValue(excelVo.getColumnValue()); |
| | | entity.setRefId(pointExport.getId()); |
| | | //数据库找不到为新增否则为修改 |
| | | if (databaseVo != null) { |
| | | entity.setDynamicColumnId(databaseVo.getId()); |
| | | entity.setId(databaseVo.getValueId()); |
| | | updateList.add(entity); |
| | | } else { |
| | | entity.setDynamicColumnId(dynamicId); |
| | | insertList.add(entity); |
| | | } |
| | | } else if (databaseVo != null) { |
| | | //excel里为空但是数据库存在 删除 |
| | | deleteList.add(databaseVo.getValueId()); |
| | | } |
| | | } |
| | | } |
| | | //mybaits方法 |
| | | //插入 |
| | | if (!CollectionUtils.isEmpty(insertList)) dynamicColumnMapper.saveBatch(insertList); |
| | | //更新 |
| | | if (!CollectionUtils.isEmpty(updateList)) dynamicColumnMapper.updateBatch(updateList); |
| | | //删除 |
| | | if (!CollectionUtils.isEmpty(deleteList)) dynamicColumnMapper.deleteBatch(deleteList); |
| | | } |
| | | |
| | | /** |
| | | * 根据设备编码查询点位信息 |
| | | * |
| | | * @param serialNumber 序列号 |
| | | * @return {@link YwPoint } |
| | | * @author |
| | | */ |
| | | @Override |
| | | public YwPoint selectBySerialNumber(String serialNumber) { |
| | | return baseMapper.selectOne(new LambdaQueryWrapper<>(YwPoint.class).eq(YwPoint::getSerialNumber, serialNumber).eq(YwPoint::getDeleted, "0")); |
| | | } |
| | | |
| | | public void waitAllFinishAndGetResult(List<YwPoint> dataList, Boolean needUpdateUnit) { |
| | | Date startTime = new Date(); |
| | | this.baseMapper.updatePoint(dataList); |
| | | this.baseMapper.updatePoint(dataList, needUpdateUnit); |
| | | Date endTime = new Date(); |
| | | log.error("总共耗时:" + (endTime.getTime() - startTime.getTime())); |
| | | } |
| | | |
| | | @Override |
| | | public <T extends BaseResult> void setDeviceTagByGB(List<T> dataList) { |
| | | public <T extends BaseResult> void setDeviceTagByGB(List<T> dataList,Short category) { |
| | | List<String> gbList = dataList.stream().map(BaseResult::getNo).collect(Collectors.toList()); |
| | | List<CheckTagVO> pointList = baseMapper.getTagsByGB(gbList); |
| | | Map<String, CheckTagVO> pointMap = pointList.stream().collect(Collectors.toMap(CheckTagVO::getNo, item -> item)); |
| | |
| | | CheckTagVO tag = pointMap.get(data.getNo()); |
| | | if (Objects.nonNull(tag)) { |
| | | BeanUtils.copyProperties(tag, data); |
| | | //通过设备类型打省厅标签 |
| | | if(CheckConstants.Rule_Category_Video.equals(category)){ |
| | | data.setProvinceTag(tag.getProvinceTagVideo()); |
| | | }else if(CheckConstants.Rule_Category_Car.equals(category)){ |
| | | data.setProvinceTag(tag.getProvinceTagCar()); |
| | | }else if(CheckConstants.Rule_Category_Face.equals(category)){ |
| | | data.setProvinceTag(tag.getProvinceTagFace()); |
| | | }else if(CheckConstants.Rule_Category_Or.equals(category)){ |
| | | if(tag.getProvinceTagVideo() || tag.getProvinceTagCar() || tag.getProvinceTagFace()) { |
| | | data.setProvinceTag(Boolean.TRUE); |
| | | }else { |
| | | data.setProvinceTag(Boolean.FALSE); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |