package com.newfiber.termite.schedule; import cn.hutool.core.io.FileUtil; import com.alibaba.fastjson.JSONObject; import com.newfiber.common.core.constant.HttpStatus; import com.newfiber.common.core.domain.R; import com.newfiber.common.core.utils.file.FileUtils; import com.newfiber.common.webgis.utils.RainUtils; import com.newfiber.system.api.RemoteFileService; import com.newfiber.system.api.domain.SysFile; import com.newfiber.termite.domain.DeviceInfo; import com.newfiber.termite.domain.ProjectInfo; import com.newfiber.termite.domain.request.statistic.SiteWarnTotalCountStatisticRequest; import com.newfiber.termite.domain.response.statistic.SiteTotalWarnCount; import com.newfiber.termite.service.IDeviceInfoService; import com.newfiber.termite.service.IStatisticsService; import com.newfiber.termite.service.impl.ProjectInfoServiceImpl; import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; import java.util.stream.Collectors; import javax.annotation.Resource; import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Component; @Component @SuppressWarnings("unchecked") public class HeatMapSchedule { @Resource private ProjectInfoServiceImpl projectInfoService; @Resource private IStatisticsService statisticsService; @Resource private IDeviceInfoService deviceInfoService; @Resource private RemoteFileService remoteFileService; // @Scheduled(cron = "0 0 0 * * ? ") public void generator(){ List<ProjectInfo> projectInfoList = projectInfoService.selectWithGeometry(); String filePath = FileUtil.getTmpDirPath(); for(ProjectInfo projectInfo : projectInfoList){ try{ HashMap<String, String> geometryMap = JSONObject.parseObject(projectInfo.getGeometrys(), HashMap.class); List<SiteTotalWarnCount> siteTotalWarnCountList = statisticsService.siteWarnTotalCountStatistic(new SiteWarnTotalCountStatisticRequest(projectInfo.getProjectCode())); List<DeviceInfo> deviceInfoList = deviceInfoService.selectList(projectInfo.getProjectCode()); List<String> filePathList = new ArrayList<>(); for(Entry<String, String> entry : geometryMap.entrySet()){ List<DeviceInfo> subDeviceInfoList = deviceInfoList.stream().filter(t -> entry.getKey().equals(t.getGeometryNumber())).collect(Collectors.toList()); List<String> subSnList = subDeviceInfoList.stream().map(DeviceInfo::getSn).collect(Collectors.toList()); List<SiteTotalWarnCount> subSiteTotalWarnCountList = siteTotalWarnCountList.stream().filter(t -> subSnList.contains(t.getSn())).collect(Collectors.toList()); double[][] rainData = new double[subSiteTotalWarnCountList.size()][3]; for(int i = 0; i < subSiteTotalWarnCountList.size(); i++){ SiteTotalWarnCount siteTotalWarnCount = subSiteTotalWarnCountList.get(i); String lon = siteTotalWarnCount.getLonandlat().split(",")[0].substring(0, 10); String lat = siteTotalWarnCount.getLonandlat().split(",")[1].substring(0, 9); rainData[i][0] = Double.parseDouble(lon); rainData[i][1] = Double.parseDouble(lat); rainData[i][2] = siteTotalWarnCount.getCount().doubleValue(); } String fileName = RainUtils.weatherWarning(rainData, entry.getValue(), filePath,1); R<SysFile> sysFileR = remoteFileService.upload(FileUtils.getMultipartFile(new File(fileName))); if(HttpStatus.SUCCESS == sysFileR.getCode()){ filePathList.add(sysFileR.getData().getUrl()); } } if(CollectionUtils.isNotEmpty(filePathList)){ ProjectInfo projectInfoCondition = new ProjectInfo(); projectInfoCondition.setId(projectInfo.getId()); projectInfoCondition.setHeatmap(String.join("\\|", filePathList)); projectInfoService.updateById(projectInfoCondition); } }catch (Exception e){ e.printStackTrace(); } } } }