| | |
| | | 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.BaseSelect; |
| | | import com.ycl.platform.domain.entity.YwPeople; |
| | | import com.ycl.platform.domain.entity.YwPoint; |
| | | import com.ycl.platform.domain.entity.YwUnit; |
| | | 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.vo.YwPointVO; |
| | | import com.ycl.platform.domain.excel.PointExport; |
| | | import com.ycl.platform.domain.excel.PointSelectHandler; |
| | | import com.ycl.platform.mapper.YwPeopleMapper; |
| | | import com.ycl.platform.mapper.YwPointMapper; |
| | | import com.ycl.platform.service.YwPointService; |
| | |
| | | import com.ycl.system.Result; |
| | | import com.ycl.system.mapper.SysDeptMapper; |
| | | import com.ycl.system.page.PageUtil; |
| | | import com.ycl.thread.PointImportCallable; |
| | | import com.ycl.utils.DateUtils; |
| | | import com.ycl.utils.SecurityUtils; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.Assert; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.*; |
| | | import java.util.concurrent.*; |
| | | import java.util.function.Consumer; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | private final SysDeptMapper sysDeptMapper; |
| | | private final YwUnitService unitService; |
| | | private final YwPeopleMapper ywPeopleMapper; |
| | | |
| | | private static final ExecutorService executorService = new ThreadPoolExecutor(8, |
| | | 24, |
| | | 5000, |
| | | TimeUnit.SECONDS, |
| | | new ArrayBlockingQueue<>(10), |
| | | new ThreadPoolExecutor.CallerRunsPolicy() |
| | | ); |
| | | |
| | | /** |
| | | * 添加 |
| | |
| | | .eq(YwPoint::getUnitId, unitId) |
| | | .like(YwPoint::getPointName, keyword) |
| | | .list(); |
| | | List<BaseSelect> data = list.stream().map(item -> { |
| | | BaseSelect baseSelect = new BaseSelect(); |
| | | baseSelect.setId(item.getId()); |
| | | baseSelect.setValue(item.getPointName()); |
| | | return baseSelect; |
| | | 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); |
| | | } |
| | |
| | | public void export(YwPointQuery query, HttpServletResponse response) throws IOException { |
| | | // 导出数据 |
| | | List<PointExport> exportData = baseMapper.export(query); |
| | | |
| | | EasyExcel.write(response.getOutputStream(), PointExport.class) |
| | | .sheet("点位更换运维单位") |
| | | .doWrite(exportData); |
| | | } |
| | | |
| | | @Override |
| | | public Result importData(MultipartFile file, Integer unitId, Date startTime, Date endTime, Boolean provinceTag, Boolean importantTag, Boolean importantCommandImageTag) throws IOException { |
| | | public Result importData(MultipartFile file, Integer unitId, Date startTime, Date endTime) throws IOException { |
| | | Consumer<List<PointExport>> consumer = (dataList) -> { |
| | | this.updatePoint(dataList, unitId, startTime, endTime, provinceTag, importantTag, importantCommandImageTag); |
| | | try { |
| | | this.updatePoint(dataList, unitId, startTime, endTime); |
| | | } 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(); |
| | |
| | | * @param dataList |
| | | * @param unitId |
| | | */ |
| | | private void updatePoint(List<PointExport> dataList, Integer unitId, Date startTime, Date endTime, Boolean provinceTag, Boolean importantTag, Boolean importantCommandImageTag) { |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updatePoint(List<PointExport> dataList, Integer unitId, Date startTime, Date endTime) throws ExecutionException, InterruptedException { |
| | | if (CollectionUtils.isEmpty(dataList)) { |
| | | throw new RuntimeException("导入数据不能为空"); |
| | | } |
| | | List<String> pointList = dataList.stream().map(PointExport::getSerialNumber).collect(Collectors.toList()); |
| | | new LambdaUpdateChainWrapper<>(baseMapper) |
| | | .in(YwPoint::getSerialNumber, pointList) |
| | | .set(YwPoint::getUnitId, unitId) |
| | | .set(YwPoint::getStartTime, startTime) |
| | | .set(YwPoint::getEndTime, endTime) |
| | | .set(YwPoint::getProvinceTag, provinceTag) |
| | | .set(YwPoint::getImportantTag, importantTag) |
| | | .set(YwPoint::getImportantCommandImageTag, importantCommandImageTag) |
| | | .update(); |
| | | List<YwPoint> pointList = dataList.stream().map(item -> { |
| | | YwPoint point = new YwPoint(); |
| | | point.setImportantCommandImageTag("是".equals(item.getImportantCommandImageTagString())); |
| | | point.setProvinceTag("是".equals(item.getProvinceTagString())); |
| | | if (Objects.nonNull(unitId)) { |
| | | point.setUnitId(Long.valueOf(unitId)); |
| | | } |
| | | point.setStartTime(startTime); |
| | | point.setEndTime(endTime); |
| | | 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 { |
| | | List<FutureTask<Boolean>> resultList = new ArrayList<>(512); |
| | | List<Boolean> data = new ArrayList<>(512); |
| | | int start = 0; |
| | | Date startTime = new Date(); |
| | | while (true) { |
| | | if (dataList.size() < start + 100) { |
| | | List<YwPoint> list = dataList.subList(start, dataList.size() - 1); |
| | | this.baseMapper.updatePoint(list); |
| | | break; |
| | | } else { |
| | | List<YwPoint> list = dataList.subList(start, start + 100); |
| | | this.baseMapper.updatePoint(list); |
| | | start += 100; |
| | | } |
| | | } |
| | | Date endTime = new Date(); |
| | | log.error("总共耗时:" + (endTime.getTime() - startTime.getTime())); |
| | | } |
| | | |
| | | } |