From 1cbb3ed5c0c412cd407b7d32e7978f491857d670 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期一, 31 七月 2023 14:43:52 +0800 Subject: [PATCH] 1 --- src/main/java/com/yssh/mapper/SuYuanMapper.java | 2 + src/main/resources/mapper/SuYuanMapper.xml | 30 +++++++++----- src/main/java/com/yssh/utils/CalculateUtils.java | 10 +++++ src/main/java/com/yssh/service/WarningAnalyseService.java | 29 +++++++++++++- 4 files changed, 57 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/yssh/mapper/SuYuanMapper.java b/src/main/java/com/yssh/mapper/SuYuanMapper.java index f529011..24471c2 100644 --- a/src/main/java/com/yssh/mapper/SuYuanMapper.java +++ b/src/main/java/com/yssh/mapper/SuYuanMapper.java @@ -21,6 +21,8 @@ DistanceSuYuan getSuYuan500Max(@Param("tableName") String tableName, @Param("ids") List<String> ids); + DistanceSuYuan getSuYuan500MaxByFilter(@Param("tableName") String tableName, @Param("filter") String filter); + DistanceSuYuan getSuYuanById(@Param("tableName") String tableName, @Param("id") String id); List<Temporary> getTemporary(@Param("tableName") String tableName, @Param("ids") List<String> ids); diff --git a/src/main/java/com/yssh/service/WarningAnalyseService.java b/src/main/java/com/yssh/service/WarningAnalyseService.java index 2557340..5fc3490 100644 --- a/src/main/java/com/yssh/service/WarningAnalyseService.java +++ b/src/main/java/com/yssh/service/WarningAnalyseService.java @@ -46,7 +46,7 @@ @Resource private VocValsService vocValsService; - private SimpleDateFormat ym = new SimpleDateFormat("yyyyMM%"); + private static HashMap<String, String> filterMap = new HashMap<>(); @Async("threadPoolTaskExecutor") public void insertWarningDetails(List<WarningDetail> warning) throws Exception { @@ -168,8 +168,12 @@ WarningDetail wd = new WarningDetail(0L, tab, suYuanId, qxsh.getName(), null, 0, qxsh.getValue()); DistanceSuYuan suYuan = suYuanMapper.getSuYuanById(tab, suYuanId); - List<String> ids3d = CalculateUtils.aloneCrosswiseExtend(point, 50); - DistanceSuYuan suMax = suYuanMapper.getSuYuan500Max(tab, ids3d); + //List<String> ids3d = CalculateUtils.aloneCrosswiseExtend(point, 50); + //DistanceSuYuan suMax = suYuanMapper.getSuYuan500Max(tab, ids3d); + + //String filter = CalculateUtils.getFilterByExtend(point, 50); + String filter = getFilterByPoint(point, 50); + DistanceSuYuan suMax = suYuanMapper.getSuYuan500MaxByFilter(tab, filter); suMax.setAddr(getAddr(suMax.getId())); Report report = Report.calcReport(wd, suYuan, suMax); @@ -184,6 +188,25 @@ return list; } + public static String getFilterByPoint(MonitorPointPosition point, int range) { + String key = String.format("%d_%d_%d", point.getX(), point.getY(), range); + if (filterMap.containsKey(key)) { + return filterMap.get(key); + } + + List<String> ids = CalculateUtils.aloneCrosswiseExtend(point, range); + for (int i = 0, c = ids.size(); i < c; i++) { + ids.set(i, "'" + ids.get(i) + "'"); + } + + String filter = "id in (" + StringUtils.join(ids, ",") + ")"; + if (!filterMap.containsKey(key)) { + filterMap.put(key, filter); + } + + return filter; + } + private Hashtable<String, Boolean> getExistTabDict(List<Qxsh> rsList) { Hashtable<String, Boolean> dict = new Hashtable<>(); for (Qxsh qxsh : rsList) { diff --git a/src/main/java/com/yssh/utils/CalculateUtils.java b/src/main/java/com/yssh/utils/CalculateUtils.java index 73871a4..6eefb01 100644 --- a/src/main/java/com/yssh/utils/CalculateUtils.java +++ b/src/main/java/com/yssh/utils/CalculateUtils.java @@ -210,6 +210,16 @@ return ids; } + /** + * 鏍规嵁鑼冨洿鑾峰彇鏌ヨ鏉′欢 + */ + public static String getFilterByExtend(MonitorPointPosition point, int range) { + Integer x = point.getX(); + Integer y = point.getY(); + + return String.format("x between %d and %d and y between %d and %d", x - range / 2, x + range / 2, y - range / 2, y + range / 2); + } + public static List<String> temporary(MonitorPointPosition point, int range) { List<String> ids3d = new ArrayList<>(); Integer x = point.getX(); diff --git a/src/main/resources/mapper/SuYuanMapper.xml b/src/main/resources/mapper/SuYuanMapper.xml index b751ee2..7b2dc56 100644 --- a/src/main/resources/mapper/SuYuanMapper.xml +++ b/src/main/resources/mapper/SuYuanMapper.xml @@ -113,6 +113,14 @@ limit 1; </select> + <select id="getSuYuan500MaxByFilter" resultMap="DistanceSuYuanResult"> + select id, x, y, format(c, 2) "c", u, v + from ${tableName} + where ${filter} + order by c desc + limit 1; + </select> + <select id="getSuYuanById" resultMap="DistanceSuYuanResult"> select id, x, y, format(c, 2) "c", u, v from ${tableName} @@ -209,17 +217,17 @@ </select> <update id="createTable" parameterType="java.lang.String"> - CREATE TABLE ${tableName} ( - `id` varchar(255) NOT NULL COMMENT '涓婚敭', - `x` int(7) NULL DEFAULT NULL, - `y` int(7) NULL DEFAULT NULL, - `z` int(7) NULL DEFAULT NULL, - `u` double NULL DEFAULT NULL, - `v` double NULL DEFAULT NULL, - `w` double NULL DEFAULT NULL, - `c` double NULL DEFAULT NULL, - PRIMARY KEY (`id`) USING BTREE - ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; + create table ${tablename} ( + `id` varchar(10) not null comment '涓婚敭', + `x` int(3) null default null, + `y` int(3) null default null, + `z` int(2) null default null, + `u` double null default null, + `v` double null default null, + `w` double null default null, + `c` double null default null, + primary key (`id`) using btree + ) engine = innodb character set = utf8 collate = utf8_general_ci row_format = dynamic; </update> <update id="update" > -- Gitblit v1.9.3