From 078ea76528dbb553785b3e961b0f88592205712b Mon Sep 17 00:00:00 2001 From: zhangming Date: Sat, 28 Aug 2021 15:39:47 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9solution=5Fresult=20?= =?UTF-8?q?=E8=A1=A8=20=E5=B0=86=E6=89=80=E6=9C=89=E7=8A=B6=E6=80=81=20sta?= =?UTF-8?q?tus=3D2=20=E4=BF=AE=E6=94=B9=E4=B8=BA=20status=3D0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prevention/model/mapper/SwFloodPointDao.java | 2 ++ .../prevention/model/service/ModelResolutionService.java | 1 + .../model/service/impl/ModelResolutionServiceImpl.java | 4 ++++ .../model/service/impl/MonitorTaskServiceImpl.java | 8 ++++++++ .../src/main/resources/mapper/SwfloodPointMapper.xml | 4 ++++ 5 files changed, 19 insertions(+) diff --git a/flood-model/src/main/java/com/prevention/model/mapper/SwFloodPointDao.java b/flood-model/src/main/java/com/prevention/model/mapper/SwFloodPointDao.java index 665e17ab8..8da686e5c 100644 --- a/flood-model/src/main/java/com/prevention/model/mapper/SwFloodPointDao.java +++ b/flood-model/src/main/java/com/prevention/model/mapper/SwFloodPointDao.java @@ -20,4 +20,6 @@ public interface SwFloodPointDao extends BaseMapper { List getFloodAddress(Integer type); List getContactSwRainStation(String swCode); + + int updateSolutionResult(); } \ No newline at end of file diff --git a/flood-model/src/main/java/com/prevention/model/service/ModelResolutionService.java b/flood-model/src/main/java/com/prevention/model/service/ModelResolutionService.java index ceab37767..d52e7e5ab 100644 --- a/flood-model/src/main/java/com/prevention/model/service/ModelResolutionService.java +++ b/flood-model/src/main/java/com/prevention/model/service/ModelResolutionService.java @@ -82,4 +82,5 @@ public interface ModelResolutionService { Integer pullSwDataTriggerModel(); + int updateSolutionResult(); } diff --git a/flood-model/src/main/java/com/prevention/model/service/impl/ModelResolutionServiceImpl.java b/flood-model/src/main/java/com/prevention/model/service/impl/ModelResolutionServiceImpl.java index 952cc9d39..02f648c70 100644 --- a/flood-model/src/main/java/com/prevention/model/service/impl/ModelResolutionServiceImpl.java +++ b/flood-model/src/main/java/com/prevention/model/service/impl/ModelResolutionServiceImpl.java @@ -1239,4 +1239,8 @@ public class ModelResolutionServiceImpl implements ModelResolutionService { times.add(parse); } } + + public int updateSolutionResult(){ + return swFloodPointDao.updateSolutionResult(); + } } diff --git a/flood-model/src/main/java/com/prevention/model/service/impl/MonitorTaskServiceImpl.java b/flood-model/src/main/java/com/prevention/model/service/impl/MonitorTaskServiceImpl.java index 53fabef55..83a670d5d 100644 --- a/flood-model/src/main/java/com/prevention/model/service/impl/MonitorTaskServiceImpl.java +++ b/flood-model/src/main/java/com/prevention/model/service/impl/MonitorTaskServiceImpl.java @@ -17,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; +import javax.annotation.PostConstruct; import java.util.*; import java.util.stream.Collectors; @@ -155,4 +156,11 @@ public class MonitorTaskServiceImpl implements MonitorTaskService { } log.info("解析方案===========solutionId" + integer + " " + DateUtils.dateTimeFormat(new Date())); } + + @PostConstruct + public void updateSolutionResult(){ + log.info("========================开始更新solution_result======================================="); + int count = modelResolutionService.updateSolutionResult(); + log.info("=========================共更新{}列数据==============================================",count); + } } diff --git a/flood-model/src/main/resources/mapper/SwfloodPointMapper.xml b/flood-model/src/main/resources/mapper/SwfloodPointMapper.xml index 47630a618..1fbc0ee00 100644 --- a/flood-model/src/main/resources/mapper/SwfloodPointMapper.xml +++ b/flood-model/src/main/resources/mapper/SwfloodPointMapper.xml @@ -28,4 +28,8 @@ on a.flow_point_code =b. sw_code and a.flag_time = b.flag_time where c.type=4 and d.sw_code=#{swCode} + + + update solution_result set status = 0 where status = 2 + \ No newline at end of file -- Gitee From 5ed79f19184b56075984527ebed93de65cfa9dbe Mon Sep 17 00:00:00 2001 From: "lwk27617@163.com" Date: Sat, 28 Aug 2021 16:35:50 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E9=83=A8=E5=88=86?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AnalysisModelFloodResultServiceImpl.java | 2 +- ...nalysisModelStagnantResultServiceImpl.java | 7 +-- .../AnalysisModelFloodResultMapper.xml | 2 +- .../AnalysisModelStagnantResultMapper.xml | 2 +- .../model/entity/AnalysisRiskResults.java | 5 +- .../model/service/ModelHandlerService.java | 47 +++++++++---------- .../impl/ModelResolutionServiceImpl.java | 16 +++---- .../service/impl/MonitorTaskServiceImpl.java | 4 ++ 8 files changed, 41 insertions(+), 44 deletions(-) diff --git a/flood-application/src/main/java/com/prevention/flood/application/service/analysis/impl/AnalysisModelFloodResultServiceImpl.java b/flood-application/src/main/java/com/prevention/flood/application/service/analysis/impl/AnalysisModelFloodResultServiceImpl.java index 53f8abc95..599303c2e 100644 --- a/flood-application/src/main/java/com/prevention/flood/application/service/analysis/impl/AnalysisModelFloodResultServiceImpl.java +++ b/flood-application/src/main/java/com/prevention/flood/application/service/analysis/impl/AnalysisModelFloodResultServiceImpl.java @@ -181,9 +181,9 @@ public class AnalysisModelFloodResultServiceImpl extends ServiceImpl map = new HashMap<>(); List list = new ArrayList<>(); List dateList = new ArrayList<>(); + //方法可以优化 但为了适配老数据 优化就出问题 if (gridRainData != null) { Integer steps = gridRainData.getSteps(); Long stime = gridRainData.getStartTime().getTime(); diff --git a/flood-application/src/main/java/com/prevention/flood/application/service/analysis/impl/AnalysisModelStagnantResultServiceImpl.java b/flood-application/src/main/java/com/prevention/flood/application/service/analysis/impl/AnalysisModelStagnantResultServiceImpl.java index 999dab1f1..114953976 100644 --- a/flood-application/src/main/java/com/prevention/flood/application/service/analysis/impl/AnalysisModelStagnantResultServiceImpl.java +++ b/flood-application/src/main/java/com/prevention/flood/application/service/analysis/impl/AnalysisModelStagnantResultServiceImpl.java @@ -63,12 +63,7 @@ public class AnalysisModelStagnantResultServiceImpl extends ServiceImpl 0.5){ ModelResultGrid stagnantResultGrid = new ModelResultGrid(); stagnantResultGrid.setDepth(p.getDepth()); - int length = p.getDepthString().split(";").length; - DecimalFormat decimalFormat=new DecimalFormat("0.##"); - Double v = (p.getDuration() * length) / 3600.0; - if(v!=null){ - stagnantResultGrid.setDuration(Double.valueOf(decimalFormat.format(v))); - } + stagnantResultGrid.setDuration(p.getDuration()); stagnantResultGrid.setId(p.getShpId()); collect.add(stagnantResultGrid); } diff --git a/flood-application/src/main/resources/mapper/analysis/AnalysisModelFloodResultMapper.xml b/flood-application/src/main/resources/mapper/analysis/AnalysisModelFloodResultMapper.xml index 1f395b9dd..c7a64f684 100644 --- a/flood-application/src/main/resources/mapper/analysis/AnalysisModelFloodResultMapper.xml +++ b/flood-application/src/main/resources/mapper/analysis/AnalysisModelFloodResultMapper.xml @@ -53,7 +53,7 @@ select a.MAX_LEVEL as depth,a.SUMMARY_INDEX as summaryIndex,a.SUMMARY_TIME as summaryTime,a.DEPTH_STRING as depthString, - round((unix_timestamp(t.ComputerEndTime) - unix_timestamp(t.ComputerStartTime)) / a.steps) as duration, + ROUND((a.SUMMARY_TIME/3600000),2) as duration, b.OBJ_TYPE as objType,a.SHP_ID as shpId,b.OBJ_ID as objId1 ,c.OBJ_ID as objId2,f.OBJ_ID as objId3, b2.name as streetName, n.name as wayName,n.id as wayId, diff --git a/flood-model/src/main/java/com/prevention/model/entity/AnalysisRiskResults.java b/flood-model/src/main/java/com/prevention/model/entity/AnalysisRiskResults.java index b92ebc0b2..81ea6b53c 100644 --- a/flood-model/src/main/java/com/prevention/model/entity/AnalysisRiskResults.java +++ b/flood-model/src/main/java/com/prevention/model/entity/AnalysisRiskResults.java @@ -11,6 +11,7 @@ import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; +import java.util.Date; /** * @Program: flood @@ -25,7 +26,7 @@ import java.io.Serializable; @NoArgsConstructor public class AnalysisRiskResults extends Model { - @TableId(value = "id",type = IdType.AUTO) + @TableId(value = "id", type = IdType.AUTO) private Integer id; @TableField("solution_id") @@ -52,6 +53,8 @@ public class AnalysisRiskResults extends Model { @TableField("sub_area") private Double subArea; + @TableField("create_time") + private Date createTime; @Override protected Serializable pkVal() { diff --git a/flood-model/src/main/java/com/prevention/model/service/ModelHandlerService.java b/flood-model/src/main/java/com/prevention/model/service/ModelHandlerService.java index 21f445f23..99bdda789 100644 --- a/flood-model/src/main/java/com/prevention/model/service/ModelHandlerService.java +++ b/flood-model/src/main/java/com/prevention/model/service/ModelHandlerService.java @@ -5,27 +5,21 @@ import com.google.common.collect.Lists; import com.prevention.model.config.ModelConfig; import com.prevention.model.config.ModelPathConfig; import com.prevention.model.entity.Solution; -import com.prevention.model.mapper.AnalysisModelFloodResultMapper; -import com.prevention.model.mapper.AnalysisRiskMapper; -import com.prevention.model.mapper.BaseAreaMapper; +import com.prevention.model.util.DateUtils; import com.prevention.sky.ifms.util.Datadeal; import com.prevention.sky.ifsm.bean.Model2DResultData; import com.prevention.sky.ifsm.bean.ProgressLinkData; import com.prevention.sky.ifsm.bean.ProgressNodeData; import com.prevention.sky.ifsm.model.DealPipeNetworkResult; import com.prevention.sky.ifsm.model.ProcessDataPackReader; -import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import javax.annotation.Resource; import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; -import java.math.BigDecimal; -import java.text.DecimalFormat; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; @@ -39,14 +33,8 @@ public class ModelHandlerService { @Autowired private ModelPathConfig modelPathConfig; - @Resource - private AnalysisModelFloodResultMapper floodResMapper; - - - @Autowired - private BaseAreaMapper baseAreaMapper; @Autowired - private AnalysisRiskMapper riskMapper; + private ISolutionService solutionService; /** @@ -56,7 +44,7 @@ public class ModelHandlerService { * @return 网格点位积水统计信息 */ public List handleShpDetail(Class className, Solution solution, Integer calcId) { - log.info("开始解析 solutionId" +solution.getId()); + log.info(DateUtils.dateTimeFormat(new Date()) + " 开始解析 solutionId:" + solution.getId()); ProcessDataPackReader reader = new ProcessDataPackReader(getStationPath(solution) + ModelConfig.X2DPROCESSPATH); reader.beginRead(); // 模型计算结果的开始时间 @@ -69,25 +57,32 @@ public class ModelHandlerService { Map> maps = new ConcurrentHashMap<>(); List result = new ArrayList<>(); try { - List> dataLevelMaps = Lists.newArrayList(); + List> dataLevelMaps = Lists.newArrayList(); for (int i = 0; i < steps; i++) { Model2DResultData data = reader.getDataFromIndex(i); dataLevelMaps.add(data.getLevelList()); } Map shpMaps = dataLevelMaps.stream().flatMap(m -> m.entrySet().stream()) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> a + "," + b)); - shpMaps.keySet().forEach(shpId->{ - List depts= Lists.newArrayList(shpMaps.get(shpId).split(",")); + shpMaps.keySet().forEach(shpId -> { + List depts = Lists.newArrayList(shpMaps.get(shpId).split(",")); Map shp = new HashMap<>(); shp.put("shpId", shpId); shp.put("startIndex", -1); shp.put("endIndex", -1); shp.put("maxIndex", -1); shp.put("summaryIndex", 0); - shp.put("steps",steps); + shp.put("steps", steps); shp.put("maxLevel", depts.stream().map(Double::parseDouble).max(Double::compareTo).get()); - shp.put("depthString", StringUtils.join(depts, ",")); - AtomicInteger index=new AtomicInteger(); + StringBuilder sb = new StringBuilder(""); + for (int i = 0; i < depts.size(); i++) { + sb.append(depts.get(i)).append(",").append(i + 1); + if (i != depts.size()) { + sb.append(";"); + } + } + shp.put("depthString",sb.toString()); + AtomicInteger index = new AtomicInteger(); depts.stream().forEach(x -> { index.getAndIncrement(); if (Double.parseDouble(x) > 0.25) { @@ -101,10 +96,10 @@ public class ModelHandlerService { } } }); - shp.put("startTime", new Date(startTime + (int)shp.get("startIndex") * perStepTime)); - shp.put("summaryTime", (int)shp.get("summaryIndex") * perStepTime); - shp.put("endTime", new Date(startTime + (int)shp.get("endIndex") * perStepTime)); - shp.put("maxTime", new Date(startTime + (int)shp.get("maxIndex") * perStepTime)); + shp.put("startTime", new Date(startTime + (int) shp.get("startIndex") * perStepTime)); + shp.put("summaryTime", (int) shp.get("summaryIndex") * perStepTime); + shp.put("endTime", new Date(startTime + (int) shp.get("endIndex") * perStepTime)); + shp.put("maxTime", new Date(startTime + (int) shp.get("maxIndex") * perStepTime)); shp.put("modelId", calcId); result.add(JSONObject.parseObject(JSONObject.toJSONString(shp), className)); }); @@ -115,8 +110,10 @@ public class ModelHandlerService { log.error(e.getMessage(), e); } finally { reader.endRead(); + log.info(DateUtils.dateTimeFormat(new Date()) + " 解析完成 solutionId:" + solution.getId()); maps = null; } + return null; } diff --git a/flood-model/src/main/java/com/prevention/model/service/impl/ModelResolutionServiceImpl.java b/flood-model/src/main/java/com/prevention/model/service/impl/ModelResolutionServiceImpl.java index 02f648c70..5bbea5049 100644 --- a/flood-model/src/main/java/com/prevention/model/service/impl/ModelResolutionServiceImpl.java +++ b/flood-model/src/main/java/com/prevention/model/service/impl/ModelResolutionServiceImpl.java @@ -314,13 +314,9 @@ public class ModelResolutionServiceImpl implements ModelResolutionService { String address = swFloodPoint.getAddress(); Double level = 0.0; // 落雁河对应水位写死 442 - if (Objects.equals("LYH01", name)) { - level = 442.0; - } else { - Optional first = list1.stream().filter(p -> Objects.equals(stationCode, p.getStationCode())).findFirst(); - if (first.isPresent()) { - level = first.get().getLevel(); - } + Optional first = list1.stream().filter(p -> Objects.equals(stationCode, p.getStationCode())).findFirst(); + if (first.isPresent()) { + level = first.get().getLevel(); } //调用方获取水位对应的的流量 @@ -588,7 +584,9 @@ public class ModelResolutionServiceImpl implements ModelResolutionService { //街道id String streetName = entry.getKey(); String[] s = streetName.split("_"); + //当前街道对应的应急物资数量 Integer goodsRank = cacheGoods.get(s[1]); + //当前街道对应的应急队伍数量 Integer teamRank = cacheTeams.get(s[1]); //对当前街道内的所有网格进行评分 List value = entry.getValue(); @@ -1240,7 +1238,7 @@ public class ModelResolutionServiceImpl implements ModelResolutionService { } } - public int updateSolutionResult(){ - return swFloodPointDao.updateSolutionResult(); + public int updateSolutionResult() { + return swFloodPointDao.updateSolutionResult(); } } diff --git a/flood-model/src/main/java/com/prevention/model/service/impl/MonitorTaskServiceImpl.java b/flood-model/src/main/java/com/prevention/model/service/impl/MonitorTaskServiceImpl.java index 83a670d5d..05a68006a 100644 --- a/flood-model/src/main/java/com/prevention/model/service/impl/MonitorTaskServiceImpl.java +++ b/flood-model/src/main/java/com/prevention/model/service/impl/MonitorTaskServiceImpl.java @@ -146,6 +146,7 @@ public class MonitorTaskServiceImpl implements MonitorTaskService { /** * 每十分钟获取一次已计算未解析的方案 + * */ @Scheduled(cron = " 0 */10 * * * ?") public void testModelParsing() { @@ -157,6 +158,9 @@ public class MonitorTaskServiceImpl implements MonitorTaskService { log.info("解析方案===========solutionId" + integer + " " + DateUtils.dateTimeFormat(new Date())); } + /** + * 将由于意外停止或者手动停止的状态为计算中的方案改为 未解析 + */ @PostConstruct public void updateSolutionResult(){ log.info("========================开始更新solution_result======================================="); -- Gitee