pom.xml
@@ -79,6 +79,11 @@ <artifactId>commons-lang3</artifactId> <version>3.12.0</version> </dependency> <dependency> <groupId>org.gavaghan</groupId> <artifactId>geodesy</artifactId> <version>1.1.3</version> </dependency> </dependencies> <build> src/main/java/com/ard/alarm/radar/domain/ArdEquipRadar.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,70 @@ package com.ard.alarm.radar.domain; import java.util.Date; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; /** * radar对象 ard_equip_radar * * @author zj * @date 2023-03-11 */ @Data public class ArdEquipRadar { private static final long serialVersionUID = 1L; /** id */ private String id; /** åç§° */ private String name; /** ç«¯å£ */ private Integer port; /** æä½åid */ private String operate; /** å 餿 è®° */ private String delFlag; /** ç¨æ·id */ private String userId; /** ç»åº¦ */ private Double longitude; /** 维度 */ private Double latitude; /** é«ç¨ */ private Double altitude; /** å®è£ æ¶é´ */ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date radarDate; /** é¨é¨id */ private Long deptId; /** ä¿¯ä»°è§ */ private String pitch; /** å¡id */ private String towerId; private String towerName; /** å¾å宽度 */ private String imageWidth; /** å¾åé«åº¦ */ private String imageHeight; /** åå· */ private String type; /** ip */ private String ip; } src/main/java/com/ard/alarm/radar/domain/RadarAlarmInfo.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,23 @@ package com.ard.alarm.radar.domain; import lombok.Data; import java.util.Date; /** * @Description: * @ClassName: RadarAlarmInfo * @Author: åèä¹ * @Date: 2023å¹´06æ27æ¥15:49 * @Version: 1.0 **/ @Data public class RadarAlarmInfo { Integer id; String name; String alarmTime; Double longitude; Double lagitude; } src/main/java/com/ard/alarm/radar/mapper/ArdEquipRadarMapper.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,63 @@ package com.ard.alarm.radar.mapper; import java.util.List; import com.ard.alarm.radar.domain.ArdEquipRadar; import org.apache.ibatis.annotations.Mapper; /** * radarMapperæ¥å£ * * @author zj * @date 2023-03-11 */ @Mapper public interface ArdEquipRadarMapper { /** * æ¥è¯¢radar * * @param id radarä¸»é® * @return radar */ public ArdEquipRadar selectArdEquipRadarById(String id); /** * æ¥è¯¢radarå表 * * @param ardEquipRadar radar * @return radaréå */ public List<ArdEquipRadar> selectArdEquipRadarList(ArdEquipRadar ardEquipRadar); /** * æ°å¢radar * * @param ardEquipRadar radar * @return ç»æ */ public int insertArdEquipRadar(ArdEquipRadar ardEquipRadar); /** * ä¿®æ¹radar * * @param ardEquipRadar radar * @return ç»æ */ public int updateArdEquipRadar(ArdEquipRadar ardEquipRadar); /** * å é¤radar * * @param id radarä¸»é® * @return ç»æ */ public int deleteArdEquipRadarById(String id); /** * æ¹éå é¤radar * * @param ids éè¦å é¤çæ°æ®ä¸»é®éå * @return ç»æ */ public int deleteArdEquipRadarByIds(String[] ids); } src/main/java/com/ard/alarm/radar/service/IArdEquipRadarService.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,61 @@ package com.ard.alarm.radar.service; import java.util.List; import com.ard.alarm.radar.domain.ArdEquipRadar; /** * radarServiceæ¥å£ * * @author zj * @date 2023-03-11 */ public interface IArdEquipRadarService { /** * æ¥è¯¢radar * * @param id radarä¸»é® * @return radar */ public ArdEquipRadar selectArdEquipRadarById(String id); /** * æ¥è¯¢radarå表 * * @param ardEquipRadar radar * @return radaréå */ public List<ArdEquipRadar> selectArdEquipRadarList(ArdEquipRadar ardEquipRadar); /** * æ°å¢radar * * @param ardEquipRadar radar * @return ç»æ */ public int insertArdEquipRadar(ArdEquipRadar ardEquipRadar); /** * ä¿®æ¹radar * * @param ardEquipRadar radar * @return ç»æ */ public int updateArdEquipRadar(ArdEquipRadar ardEquipRadar); /** * æ¹éå é¤radar * * @param ids éè¦å é¤çradar主é®éå * @return ç»æ */ public int deleteArdEquipRadarByIds(String[] ids); /** * å é¤radarä¿¡æ¯ * * @param id radarä¸»é® * @return ç»æ */ public int deleteArdEquipRadarById(String id); } src/main/java/com/ard/alarm/radar/service/impl/ArdEquipRadarServiceImpl.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,121 @@ package com.ard.alarm.radar.service.impl; import java.util.List; import com.ard.alarm.radar.domain.ArdEquipRadar; import com.ard.alarm.radar.mapper.ArdEquipRadarMapper; import com.ard.alarm.radar.service.IArdEquipRadarService; import com.ard.utils.tcp.NettyTcpClient; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; import javax.annotation.Resource; /** * radarServiceä¸å¡å±å¤ç * * @author zj * @date 2023-03-11 */ @Service @Slf4j(topic = "radar") public class ArdEquipRadarServiceImpl implements IArdEquipRadarService { @Autowired private ArdEquipRadarMapper ardEquipRadarMapper; @Resource NettyTcpClient nettyTcpClient; @Value("${spring.netty.tcp.enabled}") private Boolean tcpClientEnable; @PostConstruct public void init() { if(!tcpClientEnable) { return; } List<ArdEquipRadar> ardEquipRadars = selectArdEquipRadarList(new ArdEquipRadar()); for (ArdEquipRadar ardEquipRadar:ardEquipRadars) { String host = ardEquipRadar.getIp(); Integer port = Integer.valueOf(ardEquipRadar.getPort()); log.info("TCP客æ·ç«¯å°è¯è¿æ¥ï¼"+host+":"+port); nettyTcpClient.init(ardEquipRadar); } } /** * æ¥è¯¢radar * * @param id radarä¸»é® * @return radar */ @Override public ArdEquipRadar selectArdEquipRadarById(String id) { return ardEquipRadarMapper.selectArdEquipRadarById(id); } /** * æ¥è¯¢radarå表 * * @param ardEquipRadar radar * @return radar */ @Override public List<ArdEquipRadar> selectArdEquipRadarList(ArdEquipRadar ardEquipRadar) { return ardEquipRadarMapper.selectArdEquipRadarList(ardEquipRadar); } /** * æ°å¢radar * * @param ardEquipRadar radar * @return ç»æ */ @Override public int insertArdEquipRadar(ArdEquipRadar ardEquipRadar) { return ardEquipRadarMapper.insertArdEquipRadar(ardEquipRadar); } /** * ä¿®æ¹radar * * @param ardEquipRadar radar * @return ç»æ */ @Override public int updateArdEquipRadar(ArdEquipRadar ardEquipRadar) { return ardEquipRadarMapper.updateArdEquipRadar(ardEquipRadar); } /** * æ¹éå é¤radar * * @param ids éè¦å é¤çradarä¸»é® * @return ç»æ */ @Override public int deleteArdEquipRadarByIds(String[] ids) { return ardEquipRadarMapper.deleteArdEquipRadarByIds(ids); } /** * å é¤radarä¿¡æ¯ * * @param id radarä¸»é® * @return ç»æ */ @Override public int deleteArdEquipRadarById(String id) { return ardEquipRadarMapper.deleteArdEquipRadarById(id); } } src/main/java/com/ard/alarm/tube/service/TubeAlarmService.java
@@ -14,8 +14,6 @@ import javax.annotation.Resource; import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * @Description: ç®¡çº¿æ³æ¼æ¥è¦æå¡ @@ -29,11 +27,10 @@ public class TubeAlarmService { @Resource NettyUdpServer nettyUdpServer; @Resource NettyTcpClient nettyTcpClient; @Value("${spring.netty.port}") @Value("${spring.netty.udp.port}") private Integer udpPort; @Value("${spring.netty.enabled}") @Value("${spring.netty.udp.enabled}") private String UdpServerEnable; @PostConstruct @@ -43,8 +40,6 @@ } nettyUdpServer.init(udpPort); log.info("UDPæå¡å·²å¯å¨"); nettyTcpClient.init("127.0.0.1",1200); log.info("TCP客æ·ç«¯å·²å¯å¨"); } @Async("alarm") src/main/java/com/ard/utils/LonlatConver.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,294 @@ package com.ard.utils; public class LonlatConver { /** * a */ public final static double a = 6378245.0; /** * ee */ public final static double ee = 0.00669342162296594323; //åå¨ç GCJ_02_To_WGS_84 public final static double pi = 3.14159265358979324; /** * @Description WGS84 to ç«æåæ ç³» (GCJ-02) * @param lon ç»åº¦ * @param lat 纬度 * @return */ public static double[] wgs84_To_Gcj02(double lon, double lat) { if (outOfChina(lat, lon)) { return null; } double dLat = transformLat(lon - 105.0, lat - 35.0); double dLon = transformLon(lon - 105.0, lat - 35.0); double radLat = lat / 180.0 * pi; double magic = Math.sin(radLat); magic = 1 - ee * magic * magic; double sqrtMagic = Math.sqrt(magic); dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi); dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi); double mgLat = lat + dLat; double mgLon = lon + dLon; return new double[] { mgLon, mgLat }; } /** * @Description ç«æåæ ç³» (GCJ-02) to WGS84 * @param lon * @param lat * @return */ public static double[] gcj02_To_Wgs84(double lon, double lat) { double[] gps = transform(lat, lon); double lontitude = lon * 2 - gps[1]; double latitude = lat * 2 - gps[0]; return new double[] { lontitude, latitude }; } /** * @Description ç«æåæ ç³» (GCJ-02) to ç¾åº¦åæ ç³» (BD-09) * @param gg_lon * @param gg_lat * @return */ public static double[] gcj02_To_Bd09(double gg_lon, double gg_lat) { double x = gg_lon, y = gg_lat; double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * pi); double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * pi); double bd_lon = z * Math.cos(theta) + 0.0065; double bd_lat = z * Math.sin(theta) + 0.006; return new double[] { bd_lon, bd_lat }; } /** * @Description ç¾åº¦åæ ç³» (BD-09) to ç«æåæ ç³» (GCJ-02) * @param bd_lon * @param bd_lat * @return */ public static double[] bd09_To_Gcj02(double bd_lon, double bd_lat) { double x = bd_lon - 0.0065, y = bd_lat - 0.006; double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * pi); double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * pi); double gg_lon = z * Math.cos(theta); double gg_lat = z * Math.sin(theta); return new double[] { gg_lon, gg_lat }; } /** * @Description ç¾åº¦åæ ç³» (BD-09) to WGS84 * @param bd_lat * @param bd_lon * @return */ public static double[] bd09_To_Wgs84(double bd_lon,double bd_lat) { double[] gcj02 = LonlatConver.bd09_To_Gcj02(bd_lon, bd_lat); double[] map84 = LonlatConver.gcj02_To_Wgs84(gcj02[0], gcj02[1]); return map84; } /** * @Description 夿æ¯å¦å¨ä¸å½èå´å * @param lat * @param lon * @return */ public static boolean outOfChina(double lat, double lon) { if (lon < 72.004 || lon > 137.8347) return true; if (lat < 0.8293 || lat > 55.8271) return true; return false; } /** * @Description transform * @param lat * @param lon * @return */ private static double[] transform(double lat, double lon) { if (outOfChina(lat, lon)) { return new double[] { lat, lon }; } double dLat = transformLat(lon - 105.0, lat - 35.0); double dLon = transformLon(lon - 105.0, lat - 35.0); double radLat = lat / 180.0 * pi; double magic = Math.sin(radLat); magic = 1 - ee * magic * magic; double sqrtMagic = Math.sqrt(magic); dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi); dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi); double mgLat = lat + dLat; double mgLon = lon + dLon; return new double[] { mgLat, mgLon }; } /** * @Description transformLat * @param x * @param y * @return */ private static double transformLat(double x, double y) { double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x)); ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0; ret += (20.0 * Math.sin(y * pi) + 40.0 * Math.sin(y / 3.0 * pi)) * 2.0 / 3.0; ret += (160.0 * Math.sin(y / 12.0 * pi) + 320 * Math.sin(y * pi / 30.0)) * 2.0 / 3.0; return ret; } /** * @Description transformLon * @param x * @param y * @return */ public static double transformLon(double x, double y) { double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x)); ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0; ret += (20.0 * Math.sin(x * pi) + 40.0 * Math.sin(x / 3.0 * pi)) * 2.0 / 3.0; ret += (150.0 * Math.sin(x / 12.0 * pi) + 300.0 * Math.sin(x / 30.0 * pi)) * 2.0 / 3.0; return ret; } /** * GPSç»çº¬åº¦è½¬æ¢ä¸º 度ï¼3114.1717,12122.1067 â 121.37300779ï¼31.23436014ï¼ * @param dms åæ * @param type åæ ç±»å E/N * @return String è§£æåçç»çº¬åº¦ */ public static String gpsToWgs84(String dms, String type) { if (dms == null || dms.equals("")) { return "0.0"; } double result = 0.0D; String temp = ""; if (type.equals("E")) {//ç»åº¦ String e1 = dms.substring(0, 3);//æªå3使°åï¼ç»åº¦å ±3ä½ï¼æå¤180度 //ç»åº¦æ¯ä¸ä¼¦æ¦ä¸ºç¹ä½åå两æç线为0度,ææå¾è¥¿åå¾ä¸å180度 String e2 = dms.substring(3, dms.length());//éè¦è¿ç®çå°æ° result = Double.parseDouble(e1); /* System.out.println("e2===="+e2); System.out.println("===="+Double.parseDouble(e2) / 60.0D);*/ result += (Double.parseDouble(e2) / 60.0D); temp = String.valueOf(result); if (temp.length() > 11) { temp = e1 + temp.substring(temp.indexOf("."), 11); } } else if (type.equals("N")) { //纬度ï¼çº¬åº¦æ¯ä»¥èµ¤é为åºå,ç¸å½äºæå°çå两å,两个åçé¢ä¸çç¹åå¹³é¢å¤¹è§0~90度 String n1 = dms.substring(0, 2);//æªå2ä½ï¼çº¬åº¦å ±2ä½ï¼æå¤90度 String n2 = dms.substring(2, dms.length()); result = Double.parseDouble(n1); /* System.out.println("n2===="+n2); System.out.println("===="+Double.parseDouble(n2) / 60.0D);*/ result += Double.parseDouble(n2) / 60.0D; temp = String.valueOf(result); if (temp.length() > 10) { temp = n1 + temp.substring(temp.indexOf("."), 10); } } return temp; } /** * * @title 计ç®ç¹ä¸ç¹çè·ç¦» * @param pointA * @param pointB * @description 注æpointA,pointBä¸çç»çº¬åº¦åæ 齿¯ç«æåæ * @return * @author huaqunzi */ /*public static double distanceToPoint(PointEntity pointA,PointEntity pointB){ //jtsæä¾çå ä½è¦ç´ å·¥åç±» GeometryFactory geometryFactory = new GeometryFactory(); //ç«æåæ (gcj02)转GPSåæ (WGS84) double[] wgsPntA = CoordinateUtil.gcj02_To_Wgs84(pointA.x,pointA.y); double[] wgsPntB = CoordinateUtil.gcj02_To_Wgs84(pointB.x,pointB.y); //WGS84->髿¯6度å带æå½± double[] gaussPntA = wgs84_To_Gauss6(wgsPntA[0], wgsPntA[1]); double[] gaussPntB = wgs84_To_Gauss6(wgsPntB[0], wgsPntB[1]); //éè¿å ä½è¦ç´ å·¥åå¾å°pointå®ä½ Point pntA = geometryFactory.createPoint(new Coordinate(gaussPntA[0], gaussPntA[1])); Point pntB = geometryFactory.createPoint(new Coordinate(gaussPntB[0], gaussPntB[1])); // 两ç¹è·ç¦» return pntA.distance(pntB); }*/ /** * @Description WGS84 to 髿¯æå½±(6度å带) * @param longitude ç»åº¦ * @param latitude 纬度 * @return double[] x y */ public static double[] wgs84_To_Gauss6(double longitude, double latitude) { int ProjNo = 0; int ZoneWide; // //带宽 double[] output = new double[2]; double longitude1, latitude1, longitude0, X0, Y0, xval, yval; double a, f, e2, ee, NN, T, C, A, M, iPI; iPI = 0.0174532925199433; // //3.1415926535898/180.0; ZoneWide = 6; //6度带宽 a = 6378137.0; f = 1.0 / 298.257223563; //WGS84åæ ç³»åæ° //a = 6378245.0;f = 1.0 / 298.3; // 54å¹´åäº¬åæ ç³»åæ° // //a=6378140.0; f=1/298.257; //80年西å®åæ ç³»åæ° ProjNo = (int) (longitude / ZoneWide); longitude0 = (double)(ProjNo * ZoneWide + ZoneWide / 2); longitude0 = longitude0 * iPI; longitude1 = longitude * iPI; // ç»åº¦è½¬æ¢ä¸ºå¼§åº¦ latitude1 = latitude * iPI; // 纬度转æ¢ä¸ºå¼§åº¦ e2 = 2 * f - f * f; ee = e2 / (1.0 - e2); NN = a / Math.sqrt(1.0 - e2 * Math.sin(latitude1) * Math.sin(latitude1)); T = Math.tan(latitude1) * Math.tan(latitude1); C = ee * Math.cos(latitude1) * Math.cos(latitude1); A = (longitude1 - longitude0) * Math.cos(latitude1); M = a * ((1 - e2 / 4 - 3 * e2 * e2 / 64 - 5 * e2 * e2 * e2 / 256) * latitude1 - (3 * e2 / 8 + 3 * e2 * e2 / 32 + 45 * e2 * e2 * e2 / 1024) * Math.sin(2 * latitude1) + (15 * e2 * e2 / 256 + 45 * e2 * e2 * e2 / 1024) * Math.sin(4 * latitude1) - (35 * e2 * e2 * e2 / 3072) * Math.sin(6 * latitude1)); // å 为æ¯ä»¥èµ¤é为Yè½´çï¼ä¸æä»¬åå为Yè½´æ¯ç¸åçï¼æä»¥xyä¸é«æ¯æå½±çæ åxyæ£å¥½ç¸å; xval = NN * (A + (1 - T + C) * A * A * A / 6 + (5 - 18 * T + T * T + 14 * C - 58 * ee) * A * A * A * A * A / 120); yval = M + NN * Math.tan(latitude1) * (A * A / 2 + (5 - T + 9 * C + 4 * C * C) * A * A * A * A / 24 + (61 - 58 * T + T * T + 270 * C - 330 * ee) * A * A * A * A * A * A / 720); X0 = 1000000L * (ProjNo + 1) + 500000L; Y0 = 0; xval = xval + X0; yval = yval + Y0; output[0] = xval; output[1] = yval; return output; } } src/main/java/com/ard/utils/tcp/NettyTcpClient.java
@@ -1,5 +1,6 @@ package com.ard.utils.tcp; import com.ard.alarm.radar.domain.ArdEquipRadar; import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; @@ -11,6 +12,8 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.stereotype.Component; import java.util.concurrent.TimeUnit; /** * @Description: @@ -24,33 +27,43 @@ @Slf4j(topic = "radar") public class NettyTcpClient { @Async public void init(String host, Integer port) { NioEventLoopGroup group = new NioEventLoopGroup(); try { Bootstrap bootstrap = new Bootstrap(); bootstrap.group(group) .channel(NioSocketChannel.class) .handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new NettyTcpClientHandler()); } }); ChannelFuture future = bootstrap.connect(host, port).sync(); // æ·»å è¿æ¥æåççå¬å¨ future.addListener((ChannelFutureListener) future1 -> { if (future1.isSuccess()) { log.info("tcpè¿æ¥æå"+host+":"+port); } else { log.info("tcpè¿æ¥å¤±è´¥"+host+":"+port); } }); future.channel().closeFuture().sync(); public void init(ArdEquipRadar ardEquipRadar) { } catch (Exception ex) { log.error("nettyTcp客æ·ç«¯åå§åå¼å¸¸:" + ex.getMessage()); } finally { group.shutdownGracefully(); while (true) { NioEventLoopGroup group = new NioEventLoopGroup(); try { Bootstrap bootstrap = new Bootstrap(); bootstrap.group(group) .channel(NioSocketChannel.class) .handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new NettyTcpClientHandler(ardEquipRadar)); } }); String host = ardEquipRadar.getIp(); Integer port = ardEquipRadar.getPort(); ChannelFuture future = bootstrap.connect(host, port).sync(); // æ·»å è¿æ¥æåççå¬å¨ future.addListener((ChannelFutureListener) future1 -> { if (future1.isSuccess()) { log.info("tcpè¿æ¥æå" + host + ":" + port); } else { log.info("tcpè¿æ¥å¤±è´¥" + host + ":" + port); } }); future.channel().closeFuture().sync(); } catch (Exception e) { log.error("nettyTcp客æ·ç«¯åå§åå¼å¸¸:" + e.getMessage()); try { TimeUnit.SECONDS.sleep(5); // çå¾ 5ç§åéæ°è¿æ¥ } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } } finally { group.shutdownGracefully(); } } } } src/main/java/com/ard/utils/tcp/NettyTcpClientHandler.java
@@ -1,17 +1,30 @@ package com.ard.utils.tcp; import com.alibaba.fastjson2.JSON; import com.ard.alarm.radar.domain.ArdEquipRadar; import com.ard.alarm.radar.domain.RadarAlarmInfo; import com.ard.hiksdk.domain.alarmEventInfo; import com.ard.utils.LonlatConver; import com.ard.utils.SpringTool; import com.ard.utils.mqtt.MqttConsumer; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import lombok.extern.slf4j.Slf4j; import org.gavaghan.geodesy.Ellipsoid; import org.gavaghan.geodesy.GeodeticCalculator; import org.gavaghan.geodesy.GlobalCoordinates; import sun.nio.cs.ext.GBK; import javax.xml.bind.DatatypeConverter; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; /** * @Description: tcp客æ·ç«¯å¤ç @@ -23,6 +36,23 @@ @Slf4j(topic = "radar") public class NettyTcpClientHandler extends SimpleChannelInboundHandler<ByteBuf> { private String host; private Integer port; private Double longitude; private Double lagitude; private String name; public NettyTcpClientHandler(ArdEquipRadar ardEquipRadar) { this.host = ardEquipRadar.getIp(); this.port = ardEquipRadar.getPort(); this.longitude = ardEquipRadar.getLongitude(); this.lagitude = ardEquipRadar.getLatitude(); this.name=ardEquipRadar.getName(); } private ChannelHandlerContext context; private ScheduledFuture<?> heartbeatTask; @Override protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) { // å¤çæ¥æ¶å°çæ¶æ¯ @@ -30,155 +60,198 @@ msg.getBytes(msg.readerIndex(), byteArray); byte[] bytes = receiveCompletePacket(byteArray); if (bytes != null) { String hexString = DatatypeConverter.printHexBinary(bytes); log.info(hexString); // String hexString = DatatypeConverter.printHexBinary(bytes); // log.info(hexString); processData(bytes); } } @Override public void channelActive(ChannelHandlerContext ctx) { // å½å®¢æ·ç«¯è¿æ¥æååï¼åéæ¶æ¯ç»æå¡å¨ TimerTask timerTask = new TimerTask() { @Override public void run() { ByteBuf message = ctx.alloc().buffer(); byte[] heart = {0x01, 0x02, 0x01, 0x10, 0x00, 0x00, 0x00, (byte) 0x83, (byte) 0x88, 0x5d, 0x71, 0x01, 0x02, 0x00}; String hexString = DatatypeConverter.printHexBinary(heart); log.info("åéå¿è·³:" + hexString); message.writeBytes(heart); ctx.writeAndFlush(message); } }; Timer timer = new Timer(); // timer.schedule(timerTask, 0, 6000); context = ctx; startHeartbeatTask();//å¼å§åéå¿è·³ } /** * å¼å§å¿è·³ä»»å¡ */ private void startHeartbeatTask() { heartbeatTask = context.executor().scheduleAtFixedRate(() -> { // åéå¿è·³æ¶æ¯ ByteBuf message = context.alloc().buffer(); byte[] heart = {0x01, 0x02, 0x01, 0x10, 0x00, 0x00, 0x00, (byte) 0x83, (byte) 0x88, 0x5d, 0x71, 0x01, 0x02, 0x00}; String hexString = DatatypeConverter.printHexBinary(heart); log.info("åéå¿è·³:" + hexString); message.writeBytes(heart); context.writeAndFlush(message); }, 0, 5, TimeUnit.SECONDS); } /** * 忢å¿è·³ä»»å¡ */ private void stopHeartbeatTask() { if (heartbeatTask != null) { heartbeatTask.cancel(false); heartbeatTask = null; } } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { log.error("è¿æ¥å¼å¸¸"); log.info("tcp客æ·ç«¯è¿æ¥å¼å¸¸"); // åçå¼å¸¸æ¶çå¤ç cause.printStackTrace(); ctx.close(); stopHeartbeatTask();//忢å¿è·³åé } public static void processData(byte[] data) { /** * è§£ææ¥è¦æ°æ® */ public void processData(byte[] data) { try { data = transferData(data);//廿å 头åå å°¾åè½¬ä¹ String s = DatatypeConverter.printHexBinary(data); log.info(s); byte[] type = Arrays.copyOfRange(data, index.type[0], index.type[1]);//å½ä»¤ç±»å data = transferData(data);//廿å 头åå å°¾ãæ ¡éªåè½¬ä¹ byte[] type = Arrays.copyOfRange(data, 0, 1);//å½ä»¤ç±»å log.info("å½ä»¤ç±»å:" + DatatypeConverter.printHexBinary(type)); byte[] cmdId = Arrays.copyOfRange(data, index.funcc[0], index.funcc[1]);//å½ä»¤ID byte[] cmdId = Arrays.copyOfRange(data, 1, 2);//å½ä»¤ID log.info("å½ä»¤ID:" + DatatypeConverter.printHexBinary(cmdId)); byte[] payloadSize = Arrays.copyOfRange(data, index.payloadSize[0], index.payloadSize[1]);//ææè´è½½å¤§å° // log.info("ææè´è½½å¤§å°:" + DatatypeConverter.printHexBinary(payloadSize)); byte[] payloadSize = Arrays.copyOfRange(data, 2, 4);//ææè´è½½å¤§å° payloadSize = toLittleEndian(payloadSize); // log.info("ææè´è½½å¤§å°(转å°ç«¯):" + DatatypeConverter.printHexBinary(payloadSize)); int payloadSizeToDecimal = byteArrayToDecimal(payloadSize); log.info("ææè´è½½å¤§å°(转æ´å):" + payloadSizeToDecimal); if (Arrays.equals(cmdId, new byte[]{0x01})) { byte[] dwTim = Arrays.copyOfRange(data, index.dwTim[0], index.dwTim[1]); // log.info("å¨è§å¾åçåºç°æ¶é´:" + DatatypeConverter.printHexBinary(dwTim)); byte[] dwTim = Arrays.copyOfRange(data, 4, 8); dwTim = toLittleEndian(dwTim); // log.info("å¨è§å¾åçåºç°æ¶é´(转å°ç«¯):" + DatatypeConverter.printHexBinary(dwTim)); // log.info("å¨è§å¾åçåºç°æ¶é´(转æ´å):" + byteArrayToDecimal(dwTim)); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); long l = byteArrayToDecimal(dwTim); String format = sdf.format(l * 1000); log.info("å¨è§å¾åçåºç°æ¶é´(转date):" + format); String alarmTime = sdf.format(l * 1000); log.info("å¨è§å¾åçåºç°æ¶é´(转date):" + alarmTime); byte[] wTargetNum = Arrays.copyOfRange(data, index.wTargetNum[0], index.wTargetNum[1]); byte[] wTargetNum = Arrays.copyOfRange(data, 8, 10); wTargetNum = toLittleEndian(wTargetNum); // log.info("ç®æ æ»ç¹æ°(转å°ç«¯):" + DatatypeConverter.printHexBinary(wTargetNum)); int targetNum = byteArrayToDecimal(wTargetNum); log.info("ç®æ æ»ç¹æ°(转æ´å):" + targetNum); //è§£æNET_TARGET_UNIT(64æ¯NET_TARGET_HEADçåèæ°) int unitIndex = index.acRes[1]; log.info("ææè´è½½æ 头起å§ä½:" + unitIndex); // byte datum = data[unitIndex]; // log.info("æ 头起å§åèï¼" + SpringTool.byteToHex(datum)); int UNITNum = (payloadSizeToDecimal - 64) / targetNum; log.info("å个Unit大å°:" + UNITNum); int uintSize = (payloadSizeToDecimal - 64) / targetNum; log.info("åæ¡æ¥è¦å¤§å°:" + uintSize); for (int i = 0; i < targetNum; i++) { Integer index = unitIndex + UNITNum * i; Integer index = 68 + uintSize * i; byte[] dwID = Arrays.copyOfRange(data, index, index + 4); dwID = toLittleEndian(dwID); // log.info("dwIDï¼" + DatatypeConverter.printHexBinary(dwID)); int id = byteArrayToDecimal(dwID); log.info("ç®æ IDå·ï¼" + id); byte[] dwGSum = Arrays.copyOfRange(data, index + 4, index + 8); dwGSum = toLittleEndian(dwGSum); int GSum = byteArrayToDecimal(dwGSum); log.info("ç®æ å½ååç´ ç°åº¦åï¼" + GSum); // log.info("ç®æ IDå·ï¼" + id); byte[] iDistance = Arrays.copyOfRange(data, index + 8, index + 12); iDistance = toLittleEndian(iDistance); int Distance = byteArrayToDecimal(iDistance); log.info("ç®æ å½åè·ç¦»(m):" + Distance); byte[] iTw = Arrays.copyOfRange(data, index + 12, index + 16); iTw = toLittleEndian(iTw); int Tw = byteArrayToDecimal(iTw); log.info("ç®æ å½åçåç´ å®½åº¦:" + Tw); byte[] iTh = Arrays.copyOfRange(data, index + 16, index + 20); iTh = toLittleEndian(iTh); int Th = byteArrayToDecimal(iTh); log.info("ç®æ å½åçåç´ é«åº¦:" + Th); byte[] wPxlArea = Arrays.copyOfRange(data, index + 20, index + 22); wPxlArea = toLittleEndian(wPxlArea); int PxlArea = byteArrayToDecimal(wPxlArea); log.info("ç®æ å½ååç´ é¢ç§¯:" + PxlArea); byte[] cTrkNum = Arrays.copyOfRange(data, index + 22, index + 23); cTrkNum = toLittleEndian(cTrkNum); int TrkNum = byteArrayToDecimal(cTrkNum); log.info("è½¨è¿¹ç¹æ°:" + TrkNum); byte[] cStat = Arrays.copyOfRange(data, index + 23, index + 24); cStat = toLittleEndian(cStat); int Stat = byteArrayToDecimal(cStat); log.info("ç®æ å½åç¶æ:" + Stat); byte[] sVx = Arrays.copyOfRange(data, index + 24, index + 26); sVx = toLittleEndian(sVx); int Vx = byteArrayToDecimal(sVx); log.info("ç®æ å½åé度ç¢é(åç´ è·ç¦»)X:" + Vx); byte[] sVy = Arrays.copyOfRange(data, index + 26, index + 28); sVy = toLittleEndian(sVy); int Vy = byteArrayToDecimal(sVy); log.info("ç®æ å½åé度ç¢é(åç´ è·ç¦»)Y:" + Vy); byte[] sAreaNo = Arrays.copyOfRange(data, index + 28, index + 30); sAreaNo = toLittleEndian(sAreaNo); int AreaNo = byteArrayToDecimal(sAreaNo); log.info("ç®æ å½å±çåè¦åºåå·:" + AreaNo); byte[] cGrp = Arrays.copyOfRange(data, index + 30, index + 31); cGrp = toLittleEndian(cGrp); int Grp = byteArrayToDecimal(cGrp); log.info("æå±ç»:" + Grp); // log.info("ç®æ å½åè·ç¦»(m):" + Distance); //region ä¸éè¦çåæ®µ // byte[] dwGSum = Arrays.copyOfRange(data, index + 4, index + 8); // dwGSum = toLittleEndian(dwGSum); // int GSum = byteArrayToDecimal(dwGSum); // log.info("ç®æ å½ååç´ ç°åº¦åï¼" + GSum); // byte[] iTw = Arrays.copyOfRange(data, index + 12, index + 16); // iTw = toLittleEndian(iTw); // int Tw = byteArrayToDecimal(iTw); // log.info("ç®æ å½åçåç´ å®½åº¦:" + Tw); // // byte[] iTh = Arrays.copyOfRange(data, index + 16, index + 20); // iTh = toLittleEndian(iTh); // int Th = byteArrayToDecimal(iTh); // log.info("ç®æ å½åçåç´ é«åº¦:" + Th); // // byte[] wPxlArea = Arrays.copyOfRange(data, index + 20, index + 22); // wPxlArea = toLittleEndian(wPxlArea); // int PxlArea = byteArrayToDecimal(wPxlArea); // log.info("ç®æ å½ååç´ é¢ç§¯:" + PxlArea); // // byte[] cTrkNum = Arrays.copyOfRange(data, index + 22, index + 23); // cTrkNum = toLittleEndian(cTrkNum); // int TrkNum = byteArrayToDecimal(cTrkNum); // log.info("è½¨è¿¹ç¹æ°:" + TrkNum); // // byte[] cStat = Arrays.copyOfRange(data, index + 23, index + 24); // cStat = toLittleEndian(cStat); // int Stat = byteArrayToDecimal(cStat); // log.info("ç®æ å½åç¶æ:" + Stat); // // byte[] sVx = Arrays.copyOfRange(data, index + 24, index + 26); // sVx = toLittleEndian(sVx); // int Vx = byteArrayToDecimal(sVx); // log.info("ç®æ å½åé度ç¢é(åç´ è·ç¦»)X:" + Vx); // // byte[] sVy = Arrays.copyOfRange(data, index + 26, index + 28); // sVy = toLittleEndian(sVy); // int Vy = byteArrayToDecimal(sVy); // log.info("ç®æ å½åé度ç¢é(åç´ è·ç¦»)Y:" + Vy); // // byte[] sAreaNo = Arrays.copyOfRange(data, index + 28, index + 30); // sAreaNo = toLittleEndian(sAreaNo); // int AreaNo = byteArrayToDecimal(sAreaNo); // log.info("ç®æ å½å±çåè¦åºåå·:" + AreaNo); // // byte[] cGrp = Arrays.copyOfRange(data, index + 30, index + 31); // cGrp = toLittleEndian(cGrp); // int Grp = byteArrayToDecimal(cGrp); // log.info("æå±ç»:" + Grp); //endregion byte[] szName = Arrays.copyOfRange(data, index + 64, index + 96); String str = new String(szName, "GBK"); log.info("æå±åè¦åºååç§°:" + str); int position = findIndexOfDoubleZero(szName); String alarmPointName = ""; if (position != -1) { byte[] result = new byte[position]; System.arraycopy(szName, 0, result, 0, position); alarmPointName = new String(result, "GBK"); } else { alarmPointName = new String(szName, "GBK"); } // log.info("æå±åè¦åºååç§°:" + alarmPointName); byte[] afTx = Arrays.copyOfRange(data, index + 96, index + 100); afTx = toLittleEndian(afTx); float fTx = bytesToFloat(afTx); // log.info("æ°´å¹³è§åº¦:" + fTx); byte[] afTy = Arrays.copyOfRange(data, index + 112, index + 116); afTy = toLittleEndian(afTy); float fTy = bytesToFloat(afTy); // log.info("åç´è§åº¦:" + fTy); log.info("é·è¾¾ä¿¡æ¯ï¼" + host + "ãportã" + port + "ãXã" + longitude + "ãYã" + lagitude); Double[] radarXY = {longitude, lagitude}; Double[] alarmXY = CalculateCoordinates(radarXY, Distance, (double) fTx); log.info("æ¥è¦ä¿¡æ¯ï¼" + "ãidã" + id + "ãnameã" + alarmPointName + "ãalarmTimeã" + alarmTime + "ãdistanceã" + Distance + "ãPã" + fTx + "ãTã" + fTy + "ãXã" + alarmXY[0] + "ãYã" + alarmXY[1]); RadarAlarmInfo alarmInfo=new RadarAlarmInfo(); alarmInfo.setId(id); alarmInfo.setAlarmTime(alarmTime); alarmInfo.setName(alarmPointName+"("+name+")"); alarmInfo.setLongitude(alarmXY[0]); alarmInfo.setLagitude(alarmXY[1]); MqttConsumer.publish(2, false, "radar", JSON.toJSONString(alarmInfo)); } } } catch (Exception ex) { log.error(ex.getMessage()); } } /** * byteæ°ç»è½¬float */ private float bytesToFloat(byte[] bytes) { ByteBuffer buffer = ByteBuffer.wrap(bytes); return buffer.getFloat(); } public static int byteArrayToDecimal(byte[] byteArray) { /** * byteæ°ç»è½¬æ´å */ public int byteArrayToDecimal(byte[] byteArray) { int decimalValue = 0; for (int i = 0; i < byteArray.length; i++) { @@ -188,7 +261,10 @@ return decimalValue; } public static byte[] toLittleEndian(byte[] bigEndianBytes) { /** * 大端转å°ç«¯ */ public byte[] toLittleEndian(byte[] bigEndianBytes) { byte[] littleEndianBytes = new byte[bigEndianBytes.length]; for (int i = 0; i < bigEndianBytes.length; i++) { @@ -200,84 +276,12 @@ } public static Integer processPayloadSize(String payloadSize) {//è§£æææè´è½½å¤§å° Integer payloadSizeInfo = 0; String[] payloadSizeArr = payloadSize.split(""); for (int i = 0; i <= payloadSizeArr.length - 1; i++) { Integer num = null; switch (payloadSizeArr[i]) { case "0": num = 0; break; case "1": num = 1; break; case "2": num = 2; break; case "3": num = 3; break; case "4": num = 4; break; case "5": num = 5; break; case "6": num = 6; break; case "7": num = 7; break; case "8": num = 8; break; case "9": num = 9; break; case "a": num = 10; break; case "b": num = 11; break; case "c": num = 12; break; case "d": num = 13; break; case "e": num = 14; break; case "f": num = 15; break; default: break; } if (i % 2 == 0) { payloadSizeInfo = payloadSizeInfo + num * 16; } else { payloadSizeInfo = payloadSizeInfo + num * 256; } } return payloadSizeInfo; } public static Boolean checkPayloadSize(Integer payloadSizeInfo, String data) {//æ ¡éªææè´è½½å¤§å° Integer payloadSize = (data.length() - 8 - 8) / 2;//å»é¤å 头8ä½åæ ¡éª8ä½ if (payloadSize.equals(payloadSizeInfo)) { return true; } else { return false; } } // å建ç¼å²åºå表 List<Byte> buffer = new ArrayList<>(); /** * æ¥æ¶å®æ´å */ public byte[] receiveCompletePacket(byte[] receivedData) { // å®ä¹å å°¾åèåºå byte[] packetEnd = {0x01, 0x02, 0x00}; @@ -302,7 +306,10 @@ return null; } public static int findPacketEndIndex(List<Byte> buffer, byte[] packetEnd) { /** * è·åå ç»æç´¢å¼ */ public int findPacketEndIndex(List<Byte> buffer, byte[] packetEnd) { for (int i = 0; i <= buffer.size() - packetEnd.length; i++) { boolean isMatch = true; for (int j = 0; j < packetEnd.length; j++) { @@ -318,7 +325,10 @@ return -1; } public static byte[] extractPacketFromBuffer(List<Byte> buffer, int endIndex) { /** * ä»ç¼å²åºæåæ°æ®å */ public byte[] extractPacketFromBuffer(List<Byte> buffer, int endIndex) { byte[] packet = new byte[endIndex]; for (int i = 0; i < endIndex; i++) { packet[i] = buffer.get(i); @@ -327,8 +337,10 @@ return packet; } //廿å 头åå å°¾æ ¡éªåè½¬ä¹ public static byte[] transferData(byte[] data) { /** * 廿å 头åå å°¾æ ¡éªåè½¬ä¹ */ public byte[] transferData(byte[] data) { data = Arrays.copyOfRange(data, 3, data.length); data = Arrays.copyOfRange(data, 0, data.length - 7); String dataStr = DatatypeConverter.printHexBinary(data); @@ -344,4 +356,32 @@ data = DatatypeConverter.parseHexBinary(dataStr); return data; } /** * æ¾å°00çç´¢å¼ä½ç½® */ private int findIndexOfDoubleZero(byte[] bytes) { for (int i = 0; i < bytes.length - 1; i++) { if (bytes[i] == 0x00) { return i; } } return -1; } /** * éè¿Aç¹åæ ï¼é¿åº¦åYè½´è§åº¦è®¡ç®Bç¹åæ */ public Double[] CalculateCoordinates(Double[] radarCoordinates, Integer distance, Double angle) { double[] to_wgs84 = LonlatConver.gcj02_To_Wgs84(radarCoordinates[0], radarCoordinates[1]); double Ax = to_wgs84[0]; // A ç¹ç X åæ double Ay = to_wgs84[1]; // A ç¹ç Y åæ double AB = distance; // AB çé¿åº¦ double angleWithYAxisDegrees = angle; // AB ä¸ Y è½´çè§åº¦ï¼ä»¥åº¦æ°è¡¨ç¤ºï¼ GeodeticCalculator calculator = new GeodeticCalculator(); GlobalCoordinates globalCoordinates = new GlobalCoordinates(Ay, Ax); GlobalCoordinates globalCoordinates1 = calculator.calculateEndingGlobalCoordinates(Ellipsoid.WGS84, globalCoordinates, angleWithYAxisDegrees, AB); return new Double[]{globalCoordinates1.getLongitude(), globalCoordinates1.getLatitude()}; } } src/main/java/com/ard/utils/tcp/index.java
ÎļþÒÑɾ³ý src/main/resources/application.yml
@@ -1,7 +1,12 @@ spring: netty: port: 40000 enabled: true udp: port: 40000 enabled: true tcp: host: 112.98.126.2 port: 1200 enabled: true mqtt: host: tcp://192.168.1.15:1883 clientId: c3 @@ -15,15 +20,15 @@ url: http://iot.zhdk.net:8090/Warning/GetWarning?userName=cy4oil datasource: driver-class-name: org.postgresql.Driver # url: jdbc:postgresql://111.40.46.199:15432/ry-vue?stringtype=unspecified # username: postgres # password: Yykj.2021 url: jdbc:postgresql://192.168.1.15:5432/ry-vue?stringtype=unspecified url: jdbc:postgresql://111.40.46.199:15432/ry-vue?stringtype=unspecified username: postgres password: postgres password: Yykj.2021 # url: jdbc:postgresql://192.168.1.15:5432/ry-vue?stringtype=unspecified # username: postgres # password: postgres mybatis: type-aliases-package: com.ard.alarm.camera.domain.ArdCameras mapper-locations: classpath:/mapper/*.xml typeAliasesPackage: com.ard.alarm.**.domain mapperLocations: classpath:/mapper/*.xml # minioé ç½® minio: endpoint: http://192.168.1.15:9001 src/main/resources/mapper/ArdEquipRadarMapper.xml
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,180 @@ <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.ard.alarm.radar.mapper.ArdEquipRadarMapper"> <resultMap type="ArdEquipRadar" id="ArdEquipRadarResult"> <result property="id" column="id" /> <result property="name" column="name" /> <result property="port" column="port" /> <result property="operate" column="operate" /> <result property="delFlag" column="del_flag" /> <result property="userId" column="user_id" /> <result property="longitude" column="longitude" /> <result property="latitude" column="latitude" /> <result property="altitude" column="altitude" /> <result property="radarDate" column="radar_date" /> <result property="deptId" column="dept_id" /> <result property="pitch" column="pitch" /> <result property="towerId" column="tower_id" /> <result property="imageWidth" column="image_width" /> <result property="imageHeight" column="image_height" /> <result property="type" column="type" /> <result property="ip" column="ip" /> <result property="towerName" column="name" /> </resultMap> <sql id="selectArdEquipRadarVo"> select c.id, c.name, c.create_by, c.port, c.operate, c.create_time, c.update_by, c.update_time, c.del_flag, c.user_id, c.longitude, c.latitude, c.altitude, c.radar_date, c.dept_id, c.pitch, c.tower_id, c.image_width, c.image_height, c.type, c.ip from ard_equip_radar c </sql> <select id="selectArdEquipRadarList" parameterType="ArdEquipRadar" resultMap="ArdEquipRadarResult"> select c.id,c.name, c.create_by, c.port, c.operate, c.create_time, c.update_by, c.update_time, c.del_flag, c.user_id, c.longitude, c.latitude, c.altitude, c.radar_date, c.dept_id, c.pitch, c.tower_id, c.image_width, c.image_height, c.type, c.ip, t.name from ard_equip_radar c left join sys_dept d on d.dept_id = c.dept_id left join sys_user u on u.user_id = c.user_id left join ard_towers t on t.id = c.tower_id <where> <if test="towerId != null and towerId != ''"> and c.tower_id = #{towerId}</if> <if test="userId != null and userId != ''">and c.user_id = #{userId}</if> <if test="deptId != null ">and (c.dept_id = #{deptId} OR c.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE cast(#{deptId} as varchar) = any(string_to_array(ancestors,',')) )) </if> </where> </select> <select id="selectArdEquipRadarById" parameterType="String" resultMap="ArdEquipRadarResult"> <include refid="selectArdEquipRadarVo"/> where id = #{id} </select> <insert id="insertArdEquipRadar" parameterType="ArdEquipRadar"> insert into ard_equip_radar <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null">id,</if> <if test="name != null">name,</if> <if test="createBy != null">create_by,</if> <if test="port != null">port,</if> <if test="operate != null">operate,</if> <if test="createTime != null">create_time,</if> <if test="updateBy != null">update_by,</if> <if test="updateTime != null">update_time,</if> <if test="delFlag != null">del_flag,</if> <if test="userId != null">user_id,</if> <if test="longitude != null">longitude,</if> <if test="latitude != null">latitude,</if> <if test="altitude != null">altitude,</if> <if test="radarDate != null">radar_date,</if> <if test="deptId != null">dept_id,</if> <if test="pitch != null">pitch,</if> <if test="towerId != null">tower_id,</if> <if test="imageWidth != null">image_width,</if> <if test="imageHeight != null">image_height,</if> <if test="type != null">type,</if> <if test="ip != null">ip,</if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="id != null">#{id},</if> <if test="name != null">#{name},</if> <if test="createBy != null">#{createBy},</if> <if test="port != null">#{port},</if> <if test="operate != null">#{operate},</if> <if test="createTime != null">#{createTime},</if> <if test="updateBy != null">#{updateBy},</if> <if test="updateTime != null">#{updateTime},</if> <if test="delFlag != null">#{delFlag},</if> <if test="userId != null">#{userId},</if> <if test="longitude != null">#{longitude},</if> <if test="latitude != null">#{latitude},</if> <if test="altitude != null">#{altitude},</if> <if test="radarDate != null">#{radarDate},</if> <if test="deptId != null">#{deptId},</if> <if test="pitch != null">#{pitch},</if> <if test="towerId != null">#{towerId},</if> <if test="imageWidth != null">#{imageWidth},</if> <if test="imageHeight != null">#{imageHeight},</if> <if test="type != null">#{type},</if> <if test="ip != null">#{ip},</if> </trim> </insert> <update id="updateArdEquipRadar" parameterType="ArdEquipRadar"> update ard_equip_radar <trim prefix="SET" suffixOverrides=","> <if test="name != null">name = #{name},</if> <if test="createBy != null">create_by = #{createBy},</if> <if test="port != null">port = #{port},</if> <if test="operate != null">operate = #{operate},</if> <if test="createTime != null">create_time = #{createTime},</if> <if test="updateBy != null">update_by = #{updateBy},</if> <if test="updateTime != null">update_time = #{updateTime},</if> <if test="delFlag != null">del_flag = #{delFlag},</if> <if test="userId != null">user_id = #{userId},</if> <if test="longitude != null">longitude = #{longitude},</if> <if test="latitude != null">latitude = #{latitude},</if> <if test="altitude != null">altitude = #{altitude},</if> <if test="radarDate != null">radar_date = #{radarDate},</if> <if test="deptId != null">dept_id = #{deptId},</if> <if test="pitch != null">pitch = #{pitch},</if> <if test="towerId != null">tower_id = #{towerId},</if> <if test="imageWidth != null">image_width = #{imageWidth},</if> <if test="imageHeight != null">image_height = #{imageHeight},</if> <if test="type != null">type = #{type},</if> <if test="ip != null">ip = #{ip},</if> </trim> where id = #{id} </update> <delete id="deleteArdEquipRadarById" parameterType="String"> delete from ard_equip_radar where id = #{id} </delete> <delete id="deleteArdEquipRadarByIds" parameterType="String"> delete from ard_equip_radar where id in <foreach item="id" collection="array" open="(" separator="," close=")"> #{id} </foreach> </delete> </mapper>