From 506168ae540c5aabb34f97a46a6248cd73b77f8b Mon Sep 17 00:00:00 2001 From: whycxzp <glperry@163.com> Date: 星期三, 02 四月 2025 00:46:03 +0800 Subject: [PATCH] 更新计算 --- src/main/java/com/whyc/service/BattStationTempAlarmService.java | 35 +++++++++++++++++ src/main/java/com/whyc/pojo/db_alarm/BattStationTempAlarm.java | 9 ++++ src/main/java/com/whyc/service/BattStationTempHisService.java | 7 ++- src/main/java/com/whyc/util/PointUtil.java | 59 ++++++++++++++++++++++++++++- src/main/java/com/whyc/pojo/db_batt/BattCamera.java | 2 + 5 files changed, 107 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/whyc/pojo/db_alarm/BattStationTempAlarm.java b/src/main/java/com/whyc/pojo/db_alarm/BattStationTempAlarm.java index 2581ac6..5114624 100644 --- a/src/main/java/com/whyc/pojo/db_alarm/BattStationTempAlarm.java +++ b/src/main/java/com/whyc/pojo/db_alarm/BattStationTempAlarm.java @@ -44,6 +44,8 @@ private Date endTime; + private String maxTempPoint; + @TableField(exist = false) private String battGroupName; @@ -53,5 +55,12 @@ @TableField(exist = false) private String powerName; + @TableField(exist = false) + @ApiModelProperty("鏈�楂樻俯搴︾偣鍦ㄧ鏉$殑鏂逛綅") + private String position; + + @TableField(exist = false) + private double pointPercentage; + } diff --git a/src/main/java/com/whyc/pojo/db_batt/BattCamera.java b/src/main/java/com/whyc/pojo/db_batt/BattCamera.java index d59bcf8..2f4116a 100644 --- a/src/main/java/com/whyc/pojo/db_batt/BattCamera.java +++ b/src/main/java/com/whyc/pojo/db_batt/BattCamera.java @@ -17,5 +17,7 @@ private String cameraIp; private Integer battGroupId; private Integer stationId; + /**纾佹潯璧风偣,缁堢偣,鏍煎紡涓簒1*y1,x2*y2*/ + private String mstPoints; } diff --git a/src/main/java/com/whyc/service/BattStationTempAlarmService.java b/src/main/java/com/whyc/service/BattStationTempAlarmService.java index 90275be..94ef711 100644 --- a/src/main/java/com/whyc/service/BattStationTempAlarmService.java +++ b/src/main/java/com/whyc/service/BattStationTempAlarmService.java @@ -4,9 +4,12 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import com.whyc.dto.Point; import com.whyc.dto.Response; import com.whyc.mapper.BattStationTempAlarmMapper; import com.whyc.pojo.db_alarm.BattStationTempAlarm; +import com.whyc.util.HikTempUtil; +import com.whyc.util.PointUtil; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -21,6 +24,37 @@ public Response<PageInfo<BattStationTempAlarm>> getPage(int pageNum, int pageSize, Integer level) { PageHelper.startPage(pageNum,pageSize); List<BattStationTempAlarm> list = mapper.getList(level); + //瀵硅繖浜涘憡璀﹁繘琛岃绠楀湪纾佹潯鍝竟,骞惰绠椾笌纾佹潯鐨勫瀭鐩寸嚎鐨勭櫨鍒嗘瘮 + list.forEach(alarm->{ + Integer battGroupId = alarm.getBattGroupId(); + //灏唌axTempPoint杩涜瑙f瀽锛屽緱鍒皒,y鍧愭爣,骞舵斁鍏oint瀵硅薄涓� TODO 杩欓噷鏆傚畾鏈�澶ф俯搴﹀搴旂殑鐐逛负1涓潗鏍� + String maxTempPoint = alarm.getMaxTempPoint(); + String[] split = maxTempPoint.split("\\*"); + Point tempPoint = new Point(Integer.valueOf(split[0]),Integer.valueOf(split[1])); + //纾佹潯鐨勫潗鏍�,鏍煎紡涓� x1*y1,x2*y2 + String mstPoints = HikTempUtil.cameraInfoList.stream().filter(c -> c.getBattGroupId().equals(battGroupId)).findFirst().get().getMstPoints(); + String[] mstPointsSplit = mstPoints.split(","); + Point mstPointStart = null; + Point mstPointEnd = null; + for (int i = 0; i < mstPointsSplit.length; i++) { + String mstPointsStr = mstPointsSplit[i]; + if (i == 0) { + mstPointStart = new Point(Integer.valueOf(mstPointsStr.split("\\*")[0]),Integer.valueOf(mstPointsStr.split("\\*")[1])); + }else{ + mstPointEnd = new Point(Integer.valueOf(mstPointsStr.split("\\*")[0]),Integer.valueOf(mstPointsStr.split("\\*")[1])); + } + } + //璁$畻tempPoint鍧愭爣鐐瑰湪 mstPointStart鍜宮stPointEnd缁勬垚鐨勭嚎鐨勫摢杈� + String position = PointUtil.determinePosition(mstPointStart.getX(), mstPointEnd.getX(), mstPointStart.getY(), mstPointEnd.getY(), tempPoint.getX(), tempPoint.getY()); + //璁$畻tempPoint涓庣嚎鐨勫瀭瓒� + Point footPoint = PointUtil.findIntersection2(mstPointStart, mstPointEnd, tempPoint); + //鍒ゆ柇鍨傝冻footPoint涓巑stPointStart鍜宮stPointEnd缁勬垚鐨勭嚎娈�,鍦ㄧ嚎涓婅繕鏄湪寤堕暱绾夸笂 + double pointPercentage = PointUtil.calculateProportion(footPoint.getX(), footPoint.getY(), mstPointStart.getX(), mstPointStart.getY(), mstPointEnd.getX(), mstPointEnd.getY()); + + alarm.setPosition(position); + alarm.setPointPercentage(pointPercentage); + + }); PageInfo<BattStationTempAlarm> pageInfo = new PageInfo<>(list); return new Response<PageInfo<BattStationTempAlarm>>().set(1,pageInfo); } @@ -35,6 +69,7 @@ public BattStationTempAlarm getByBattGroupId(int battGroupId) { QueryWrapper<BattStationTempAlarm> query = Wrappers.query(); query.eq("batt_group_id",battGroupId); + query.isNull("end_time"); return mapper.selectOne(query); } diff --git a/src/main/java/com/whyc/service/BattStationTempHisService.java b/src/main/java/com/whyc/service/BattStationTempHisService.java index ed88be7..6319dcf 100644 --- a/src/main/java/com/whyc/service/BattStationTempHisService.java +++ b/src/main/java/com/whyc/service/BattStationTempHisService.java @@ -80,12 +80,13 @@ } public boolean existTempHisTableByMonth(Integer battGroupId, String yearMonth) { - return commonMapper.existTable("db_power_history","db_batt_station_temp_history_"+battGroupId+"_"+yearMonth); + return commonMapper.existTable("db_power_history","tb_batt_station_temp_history_"+battGroupId+"_"+yearMonth); } public void add(Integer battGroupId, String yearMonth, BattStationTempHistory tempHistory) { - jdbcSqlExecuteService.execute("INSERT INTO `db_power_history`.`db_batt_station_temp_history_"+battGroupId+"_"+yearMonth+"` (`batt_group_id`, `station_id`, `pixel_x`, `pixel_y`, `max_temp`, `min_temp`, `min_temp_point`, `max_temp_point`, `camera_id`, `record_time`)" + - "\n values("+tempHistory.getBattGroupId()+","+tempHistory.getStationId()+","+tempHistory.getPixelX()+","+tempHistory.getPixelY()+","+tempHistory.getMaxTemp()+","+tempHistory.getMinTemp()+",'"+tempHistory.getMinTempPoint()+"','"+tempHistory.getMaxTempPoint()+"','"+tempHistory.getCameraId()+"','"+tempHistory.getRecordTime()); + String sql = "INSERT INTO `db_power_history`.`tb_batt_station_temp_history_"+battGroupId+"_"+yearMonth+"` (`batt_group_id`, `station_id`, `pixel_x`, `pixel_y`, `max_temp`, `min_temp`, `min_temp_point`, `max_temp_point`, `camera_id`, `record_time`)" + + "\n values("+tempHistory.getBattGroupId()+","+tempHistory.getStationId()+","+tempHistory.getPixelX()+","+tempHistory.getPixelY()+","+tempHistory.getMaxTemp()+","+tempHistory.getMinTemp()+",'"+tempHistory.getMinTempPoint()+"','"+tempHistory.getMaxTempPoint()+"','"+tempHistory.getCameraId()+"','"+tempHistory.getRecordTime()+"')"; + jdbcSqlExecuteService.execute(sql); } public Response getPageByCameraId(int pageNum, int pageSize, String cameraId, String startTime, String endTime) throws ParseException, InterruptedException { diff --git a/src/main/java/com/whyc/util/PointUtil.java b/src/main/java/com/whyc/util/PointUtil.java index a8aff9b..0289312 100644 --- a/src/main/java/com/whyc/util/PointUtil.java +++ b/src/main/java/com/whyc/util/PointUtil.java @@ -4,7 +4,7 @@ public class PointUtil { public static void main(String[] args) { - double a1 = 1, b1 = 2; + /*double a1 = 1, b1 = 2; double a2 = 3, b2 = 4; double x0 = 9, y0 = 9; Point p1 = new Point(1, 2); @@ -18,7 +18,17 @@ System.out.println("Intersection Point P3: (" + p3[0] + ", " + p3[1] + ")"); String position = determinePosition(a1, b1, a2, b2, x0, y0); - System.out.println("Point P is on the " + position + " of the line P1P2."); + System.out.println("Point P is on the " + position + " of the line P1P2.");*/ + double x0 = 5, y0 = 5; + double x1 = 0, y1 = 0; + double x2 = 2, y2 = 2; + + double proportion = calculateProportion(x0, y0, x1, y1, x2, y2); + if (proportion >= 0) { + System.out.println("鍨傝冻鍒癿stPointStart鐨勮窛绂诲崰鏁存潯绾挎闀垮害鐨勬瘮渚嬫槸: " + proportion); + } else { + System.out.println("鍨傝冻涓嶅湪绾挎涓�"); + } } public static double[] findIntersection(double a1, double b1, double a2, double b2, double x0, double y0) { @@ -77,5 +87,50 @@ return "line"; } } + + /** + * 璁$畻鐐瑰埌绾挎鐨勮窛绂诲崰绾挎闀垮害鐨勬瘮渚� + * @param x0 鍨傝冻x鐐� + * @param y0 鍨傝冻y鐐� + * @param x1 璧风偣x鐐� + * @param y1 璧风偣y鐐� + * @param x2 缁堢偣x鐐� + * @param y2 缁堢偣y鐐� + * @return + */ + public static double calculateProportion(double x0, double y0, double x1, double y1, double x2, double y2) { + // 鍚戦噺 AB + double ABx = x2 - x1; + double ABy = y2 - y1; + + // 鍚戦噺 AP + double APx = x0 - x1; + double APy = y0 - y1; + + // 鍚戦噺绉� AB 脳 AP + double crossProduct = ABx * APy - APx * ABy; + + if (crossProduct == 0) { + // 鐐瑰湪鐩寸嚎涓婏紝鍒ゆ柇鏄惁鍦ㄧ嚎娈典笂 + double dotProduct = APx * ABx + APy * ABy; + double squaredLengthAB = ABx * ABx + ABy * ABy; + double t = dotProduct / squaredLengthAB; + + if (t >= 0 && t <= 1) { + return t; // 鍨傝冻鍒癿stPointStart鐨勮窛绂诲崰鏁存潯绾挎闀垮害鐨勬瘮渚� + } else if (t < 0) { + //鐐瑰湪mstPointStart鐨勫欢闀跨嚎涓� + return 0; + } else { + //鐐瑰湪mstPointEnd鐨勫欢闀跨嚎涓� + return 1; + } + } else { + return -1; // 鐐逛笉鍦ㄧ洿绾夸笂 + } + } + + + } -- Gitblit v1.9.1