| | |
| | | package com.ycl.platform.service.impl; |
| | | |
| | | import com.ycl.platform.domain.entity.YwPoint; |
| | | import com.ycl.platform.domain.entity.YwUnit; |
| | | import com.ycl.platform.mapper.YwPointMapper; |
| | | import com.ycl.platform.mapper.YwUnitMapper; |
| | | import com.ycl.platform.service.YwPointService; |
| | | import com.ycl.system.Result; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.platform.domain.form.YwPointForm; |
| | | import com.ycl.platform.domain.vo.YwPointVO; |
| | | import com.ycl.platform.domain.query.YwPointQuery; |
| | | import java.util.List; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.ExcelWriter; |
| | | import com.alibaba.excel.write.metadata.WriteSheet; |
| | | 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.excel.PointExport; |
| | | import com.ycl.platform.domain.form.BatchEditPointForm; |
| | | import com.ycl.platform.domain.form.YwPointForm; |
| | | import com.ycl.platform.domain.query.YwPointQuery; |
| | | import com.ycl.platform.domain.result.BaseResult; |
| | | import com.ycl.platform.domain.vo.CheckTagVO; |
| | | import com.ycl.platform.domain.vo.DynamicColumnVO; |
| | | import com.ycl.platform.domain.vo.ReportAuditingRecordVO; |
| | | import com.ycl.platform.domain.vo.YwPointVO; |
| | | import com.ycl.platform.mapper.DynamicColumnMapper; |
| | | import com.ycl.platform.mapper.TMonitorMapper; |
| | | import com.ycl.platform.mapper.YwPeopleMapper; |
| | | import com.ycl.platform.mapper.YwPointMapper; |
| | | import com.ycl.platform.service.YwPointService; |
| | | import com.ycl.platform.service.YwUnitService; |
| | | import com.ycl.system.Result; |
| | | import com.ycl.system.mapper.SysDeptMapper; |
| | | import com.ycl.system.page.PageUtil; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | import com.ycl.thread.PointImportCallable; |
| | | import com.ycl.utils.DateUtils; |
| | | import com.ycl.utils.SecurityUtils; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.Assert; |
| | | import java.util.ArrayList; |
| | | import java.util.stream.Collectors; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.*; |
| | | import java.util.concurrent.*; |
| | | import java.util.function.Consumer; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 运维点位 服务实现类 |
| | |
| | | @RequiredArgsConstructor |
| | | public class YwPointServiceImpl extends ServiceImpl<YwPointMapper, YwPoint> implements YwPointService { |
| | | |
| | | private final YwPointMapper ywPointMapper; |
| | | private final YwUnitMapper ywUnitMapper; |
| | | private final SysDeptMapper sysDeptMapper; |
| | | private final TMonitorMapper monitorMapper; |
| | | private final DynamicColumnMapper dynamicColumnMapper; |
| | | |
| | | /** |
| | | * 添加 |
| | | * |
| | | * @param form |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result add(YwPointForm form) { |
| | | YwPoint entity = YwPointForm.getEntityByForm(form, null); |
| | | if(baseMapper.insert(entity) > 0) { |
| | | Date now = new Date(); |
| | | entity.setCreateTime(now); |
| | | entity.setUpdateTime(now); |
| | | if (baseMapper.insert(entity) > 0) { |
| | | return Result.ok("添加成功"); |
| | | } |
| | | return Result.error("添加失败"); |
| | |
| | | .forEach(form -> { |
| | | YwPoint entity = YwPointForm.getEntityByForm(form, null); |
| | | entity.setStatus("未开始"); |
| | | Date now = new Date(); |
| | | entity.setCreateTime(now); |
| | | entity.setUpdateTime(now); |
| | | baseMapper.insert(entity); |
| | | }); |
| | | return Result.ok("添加成功"); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result batchEdit(BatchEditPointForm form) { |
| | | if (Objects.nonNull(form.getUnitId())) { |
| | | new LambdaUpdateChainWrapper<>(baseMapper) |
| | | .in(YwPoint::getId, form.getIds()) |
| | | .set(YwPoint::getUnitId, form.getUnitId()) |
| | | .set(YwPoint::getUpdateTime, new Date()) |
| | | .update(); |
| | | } else { |
| | | new LambdaUpdateChainWrapper<>(baseMapper) |
| | | .in(YwPoint::getId, form.getIds()) |
| | | .set(YwPoint::getUnitId, form.getUnitId()) |
| | | .set(YwPoint::getStartTime, null) |
| | | .set(YwPoint::getEndTime, null) |
| | | .set(YwPoint::getUpdateTime, new Date()) |
| | | .update(); |
| | | } |
| | | return Result.ok("修改成功"); |
| | | } |
| | | |
| | | /** |
| | | * 修改 |
| | | * |
| | | * @param form |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result update(YwPointForm form) { |
| | | |
| | | YwPoint entity = baseMapper.selectById(form.getId()); |
| | | |
| | | // 为空抛IllegalArgumentException,做全局异常处理 |
| | | Assert.notNull(entity, "记录不存在"); |
| | | BeanUtils.copyProperties(form, entity); |
| | | if (baseMapper.updateById(entity) > 0) { |
| | | return Result.ok("修改成功"); |
| | | } |
| | | return Result.error("修改失败"); |
| | | Date now = new Date(); |
| | | entity.setUpdateTime(now); |
| | | baseMapper.updateById(entity); |
| | | return Result.ok("修改成功"); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除 |
| | | * |
| | | * @param ids |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result remove(List<String> ids) { |
| | | if(baseMapper.deleteBatchIds(ids) > 0) { |
| | | if (baseMapper.deleteBatchIds(ids) > 0) { |
| | | return Result.ok("删除成功"); |
| | | } |
| | | return Result.error("删除失败"); |
| | |
| | | |
| | | /** |
| | | * id删除 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result removeById(String id) { |
| | | if(baseMapper.deleteById(id) > 0) { |
| | | if (baseMapper.deleteById(id) > 0) { |
| | | return Result.ok("删除成功"); |
| | | } |
| | | return Result.error("删除失败"); |
| | |
| | | |
| | | /** |
| | | * 分页查询 |
| | | * |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result page(YwPointQuery query) { |
| | | |
| | | IPage<YwPoint> page = new LambdaQueryChainWrapper<>(baseMapper) |
| | | .like(StringUtils.hasText(query.getPointName()), YwPoint::getPointName, query.getPointName()) |
| | | .orderByDesc(YwPoint::getCreateTime) |
| | | .page(PageUtil.getPage(query, YwPoint.class)); |
| | | |
| | | List<YwPointVO> vos = page.getRecords().stream() |
| | | .map( |
| | | entity -> { |
| | | YwPointVO vo = YwPointVO.getVoByEntity(entity, null); |
| | | YwUnit unit = ywUnitMapper.selectById(vo.getUnitId()); |
| | | vo.setUnitName(unit.getUnitName()); |
| | | return vo; |
| | | } |
| | | ) |
| | | .collect(Collectors.toList()); |
| | | return Result.ok().data(vos).total(page.getTotal()); |
| | | IPage<YwPointVO> page = PageUtil.getPage(query, YwPointVO.class); |
| | | baseMapper.page(page, query); |
| | | return Result.ok().data(page.getRecords()).total(page.getTotal()); |
| | | } |
| | | |
| | | /** |
| | | * 根据id查找 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result detail(String id) { |
| | | |
| | | YwPoint entity = baseMapper.selectById(id); |
| | | Assert.notNull(entity, "记录不存在"); |
| | | YwPointVO vo = YwPointVO.getVoByEntity(entity, null); |
| | | if (Objects.nonNull(entity.getDeptId())) { |
| | | vo.setDeptIds(sysDeptMapper.selectParents(entity.getDeptId())); |
| | | } |
| | | return Result.ok().data(vo); |
| | | } |
| | | |
| | | /** |
| | | * 列表 |
| | | * |
| | | * @return |
| | | */ |
| | | @Override |
| | |
| | | .collect(Collectors.toList()); |
| | | return Result.ok().data(vos); |
| | | } |
| | | |
| | | @Override |
| | | public Result select(String keyword) { |
| | | Integer unitId = SecurityUtils.getUnitId(); |
| | | List<YwPoint> list = baseMapper.select(keyword, unitId); |
| | | List data = list.stream().map(item -> { |
| | | Map map = new HashMap<String, Object>(); |
| | | map.put("id", item.getSerialNumber()); |
| | | map.put("value", item.getPointName()); |
| | | return map; |
| | | }).collect(Collectors.toList()); |
| | | return Result.ok().data(data); |
| | | } |
| | | |
| | | @Override |
| | | public boolean updateRecovery(List<String> serialNumberList, int recovery) { |
| | | return new LambdaUpdateChainWrapper<>(baseMapper) |
| | | .in(YwPoint::getSerialNumber, serialNumberList) |
| | | .set(YwPoint::getRecovery, recovery) |
| | | .set(YwPoint::getUpdateTime, new Date()) |
| | | .set(recovery == 0, YwPoint::getRecoveryTime, DateUtils.getNowDate()) |
| | | .update(); |
| | | } |
| | | |
| | | @Override |
| | | public List<YwPoint> home() { |
| | | return baseMapper.home(); |
| | | } |
| | | |
| | | @Override |
| | | public void export(YwPointQuery query, HttpServletResponse response) throws IOException { |
| | | // 导出数据 |
| | | List<PointExport> exportData = baseMapper.export(query); |
| | | //获取动态列数据 |
| | | List<String> dynamicsHeaders = dynamicColumnMapper.getHeader("t_yw_point"); |
| | | 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)); |
| | | } |
| | | //定义表头列表 |
| | | LinkedHashSet<String> headers = new LinkedHashSet<>(); |
| | | headers.add("点位名称(可修改)"); |
| | | headers.add("国标码(不可修改)"); |
| | | headers.add("点位IP(可修改)"); |
| | | headers.add("是否省厅标签(可修改)"); |
| | | headers.add("是否重点指挥图像(可修改)"); |
| | | headers.add("是否部级标签(可修改)"); |
| | | List<String> headersList = new LinkedList<>(); |
| | | if (!CollectionUtils.isEmpty(dynamicsHeaders)) { |
| | | //使用链表保证后续补充数据时获取数据顺序一致 |
| | | headersList.addAll(dynamicsHeaders); |
| | | headers.addAll(headersList); |
| | | } |
| | | // 定义数据 |
| | | List<List<Object>> data = new ArrayList<>(); |
| | | for (PointExport export : exportData) { |
| | | List<Object> list = new ArrayList<>(); |
| | | //需要保证顺序一致 |
| | | list.add(export.getPointName()); |
| | | list.add(export.getSerialNumber()); |
| | | list.add(export.getPointIP()); |
| | | list.add(export.getProvinceTagString()); |
| | | list.add(export.getImportantCommandImageTagString()); |
| | | list.add(export.getDeptTag()); |
| | | for (String header : headersList) { |
| | | //创建一个变量记录找没找到这个header |
| | | boolean flag = false; |
| | | List<DynamicColumnVO> columnVOS = dynamicMap.get(export.getId()); |
| | | if (!CollectionUtils.isEmpty(columnVOS)) { |
| | | for (DynamicColumnVO columnVO : columnVOS) { |
| | | if (header.equals(columnVO.getLabelValue())) { |
| | | list.add(columnVO.getColumnValue()); |
| | | flag = true; |
| | | } |
| | | } |
| | | } |
| | | //没找到用空串占位 |
| | | if (!flag) list.add(""); |
| | | } |
| | | data.add(list); |
| | | } |
| | | |
| | | List<List<String>> headList = new ArrayList<>(); |
| | | for (String header : headers) { |
| | | headList.add(Collections.singletonList(header)); |
| | | } |
| | | |
| | | EasyExcel.write(response.getOutputStream()) |
| | | .head(headList) // 设置表头 |
| | | .sheet("点位更换运维单位") // 设置sheet名称 |
| | | .doWrite(data); // 写入数据 |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Result importData(MultipartFile file, Integer unitId, Date startTime, Date endTime, Boolean |
| | | needUpdateUnit) throws IOException { |
| | | 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(); |
| | | return Result.ok(); |
| | | } |
| | | |
| | | @Override |
| | | public ReportAuditingRecordVO getReportResult(String serialNumber, String reportType) { |
| | | return baseMapper.getReportResult(serialNumber, reportType); |
| | | } |
| | | |
| | | /** |
| | | * 修改点位的运维单位 |
| | | * |
| | | * @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)) { |
| | | throw new RuntimeException("导入数据不能为空"); |
| | | } |
| | | 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())); |
| | | if (needUpdateUnit) { |
| | | if (Objects.nonNull(unitId)) { |
| | | point.setUnitId(Long.valueOf(unitId)); |
| | | } |
| | | point.setStartTime(startTime); |
| | | point.setEndTime(endTime); |
| | | } else { |
| | | point.setUnitId(null); |
| | | point.setStartTime(null); |
| | | point.setEndTime(null); |
| | | } |
| | | |
| | | point.setPointName(item.getPointName()); |
| | | point.setSerialNumber(item.getSerialNumber()); |
| | | return point; |
| | | }).collect(Collectors.toList()); |
| | | this.waitAllFinishAndGetResult(pointList); |
| | | } |
| | | |
| | | public void waitAllFinishAndGetResult(List<YwPoint> dataList) throws |
| | | InterruptedException, ExecutionException { |
| | | int start = 0; |
| | | Date startTime = new Date(); |
| | | while (true) { |
| | | if (dataList.size() < start + 800) { |
| | | List<YwPoint> list = dataList.subList(start, dataList.size() - 1); |
| | | this.baseMapper.updatePoint(list); |
| | | break; |
| | | } else { |
| | | List<YwPoint> list = dataList.subList(start, start + 800); |
| | | this.baseMapper.updatePoint(list); |
| | | start += 800; |
| | | } |
| | | } |
| | | Date endTime = new Date(); |
| | | log.error("总共耗时:" + (endTime.getTime() - startTime.getTime())); |
| | | } |
| | | |
| | | @Override |
| | | public <T extends BaseResult> void setDeviceTagByGB(List<T> dataList) { |
| | | 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)); |
| | | for (BaseResult data : dataList) { |
| | | CheckTagVO tag = pointMap.get(data.getNo()); |
| | | if (Objects.nonNull(tag)) { |
| | | BeanUtils.copyProperties(tag, data); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public <T extends BaseResult> void setNew(List<T> dataList) { |
| | | List<String> gbList = dataList.stream().map(BaseResult::getNo).collect(Collectors.toList()); |
| | | Map<String, BaseResult> pointMap = dataList.stream().collect(Collectors.toMap(BaseResult::getNo, item -> item)); |
| | | List<String> dbGBList = monitorMapper.getGBbyGB(gbList); |
| | | for (String s : gbList) { |
| | | BaseResult baseResult = pointMap.get(s); |
| | | baseResult.setNewDevice(!dbGBList.contains(s)); |
| | | } |
| | | } |
| | | |
| | | } |