Ver Fonte

【feat】 添加对外服务 api

523096025 há 1 ano atrás
pai
commit
b919a80072

+ 2 - 2
huimv-eartag2-platform/huimv-eartag2-admin/src/main/java/com/huimv/eartag2/admin/service/impl/LoginServiceImpl.java

@@ -36,8 +36,8 @@ public class LoginServiceImpl implements ILoginService {
 
 
         if (accountMultilevel.getAccountStatus() == 0){
-            return new Result(10002, "账号未启用.", false);
-        }
+            return new Result(10002, "该服务器已暂停.", false);
+    }
         return new Result(ResultCode.SUCCESS,accountMultilevel);
     }
 }

+ 2 - 1
huimv-eartag2-platform/huimv-eartag2-admin/src/main/resources/application.properties

@@ -1,7 +1,8 @@
 #±¾µØÊý¾Ý¿â
 #spring.profiles.active=dev
 #Ô¶³ÌÊý¾Ý¿â
-spring.profiles.active=prod2
+#spring.profiles.active=prod2
+spring.profiles.active=prod
 
 device.register.prefix=device_register_
 redis.expire.eartag_online_set=25

+ 5 - 2
huimv-eartag2-platform/huimv-eartag2-api/src/main/java/com/huimv/eartag2/api/HuimvApiApplication.java

@@ -1,9 +1,11 @@
 package com.huimv.eartag2.api;
 
+import com.huimv.eartag2.api.netty.EartagServer;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.domain.EntityScan;
+import org.springframework.context.ApplicationContext;
 import org.springframework.context.annotation.Bean;
 import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
 import org.springframework.scheduling.annotation.EnableScheduling;
@@ -24,8 +26,9 @@ import org.springframework.web.client.RestTemplate;
 @EnableJpaRepositories(basePackages = "com.huimv.eartag2.common.dao.repo")
 //@Import(InterceptorConfig.class)
 public class HuimvApiApplication {
-    public static void main(String[] args)   {
-        SpringApplication.run(HuimvApiApplication.class, args);
+    public static void main(String[] args) throws InterruptedException {
+        ApplicationContext applicationContext =SpringApplication.run(HuimvApiApplication.class, args);
+        applicationContext.getBean(EartagServer.class).run();
     }
     @Bean
     public static RestTemplate getRestTemplate(){

+ 87 - 0
huimv-eartag2-platform/huimv-eartag2-api/src/main/java/com/huimv/eartag2/api/config/DbJob.java

@@ -0,0 +1,87 @@
+package com.huimv.eartag2.api.config;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.core.env.Environment;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.io.File;
+import java.io.IOException;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+
+/**
+ * 数据库定时备份任务
+ * 在backup文件夹中备份最近七日的数据库文件, 备份文件夹 与当前程序同一目录
+ */
+@Component
+@Slf4j
+public class DbJob {
+
+    private final Environment environment;
+
+    public DbJob(Environment environment) {
+        this.environment = environment;
+    }
+
+    /**
+     * 定时时间是每天凌晨5点。
+     */
+    @Scheduled(cron = "0 0 5 * * ?")
+    public void backup() throws IOException {
+        LocalDateTime now = LocalDateTime.now();
+        
+        log.info("*******************时间:【{}】, 系统开启定时任务数据库备份*******************", now);
+        
+		// 数据库配置信息
+        String user = environment.getProperty("spring.datasource.druid.username");
+
+        String password = environment.getProperty("spring.datasource.druid.password");
+
+        String url = environment.getProperty("spring.datasource.druid.url");
+
+        // 第三个 :号下标
+        int subStrIndex = url.indexOf(":", url.indexOf(":", url.indexOf(":") + 1) + 1);
+
+        // IP
+        String host = url.substring(url.indexOf("//") + 2, subStrIndex);
+
+        // 端口
+        String subStr2 = url.substring(subStrIndex);
+        String port = subStr2.substring(1, subStr2.indexOf("/"));
+
+        // 数据库名
+        String dataBaseName = subStr2.substring(subStr2.indexOf("/") + 1, subStr2.indexOf("?"));
+
+        // 环境
+        String os = System.getProperties().getProperty("os.name");
+
+        log.info("备份环境信息:【{}】, 用户名:【{}】,密码:【{}】, 地址:【{}】, 端口:【{}】,数据库:【{}】", os, url, password, host, port, dataBaseName);
+
+
+        LocalDate localDate = LocalDate.now();
+
+        String fileName = localDate + ".sql";
+
+        File file = new File("backup", fileName);
+
+        file.getParentFile().mkdirs();
+
+        file.createNewFile();
+
+        // 备份今天数据库
+        DbUtil.backup("10.0.0.77", "3309", user, password, dataBaseName, file);
+        //备份->对历史数据进行冷处理,减轻数据库压力
+        DbUtil.load(file,user,password,dataBaseName);
+        // 删除七天前数据库备份文件 LocalDate
+        LocalDate before = localDate.minusDays(7);
+        String fileBeforeName = before + ".sql";
+        File fileBefore = new File("backup", fileBeforeName);
+        if (fileBefore.exists()) {
+            fileBefore.delete();
+        }
+        log.info("*******************时间:【{}】, 系统结束定时任务数据库备份*******************", now);
+    }
+
+}
+

+ 146 - 0
huimv-eartag2-platform/huimv-eartag2-api/src/main/java/com/huimv/eartag2/api/config/DbUtil.java

@@ -0,0 +1,146 @@
+package com.huimv.eartag2.api.config;
+
+import java.io.*;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+
+
+public class DbUtil {
+    /**
+     * 导出sql文件
+     *
+     * @param host     ip地址
+     * @param port     端口
+     * @param userName 用户名
+     * @param password 密码
+     * @param dbName   数据库名
+     * @param file     文件对象
+     */
+    public static void backup(String host, String port, String userName, String password, String dbName, File file) {
+
+        String cmd = "mysqldump --single-transaction" + " -h" + host + " -P" + port + " -u" + userName + " -p" + password + " " + dbName + " > " + file.getPath();
+        String os = System.getProperties().getProperty("os.name");
+        if(os.contains("Windows")){
+            // Windows 需要加上 cmd /c
+            cmd = "cmd /c " + cmd;
+        }
+        System.out.printf("cmd命令为:%s%n", cmd);
+        try {
+            Process process = Runtime.getRuntime().exec(cmd);
+
+            if (process.waitFor() == 0) {
+                System.out.printf(" 数据库:%s 备份成功!%n", dbName);
+            } else {
+                System.out.printf(" 数据库:%s 备份失败!%n", dbName);
+            }
+        } catch (IOException | InterruptedException e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 导入sql文件
+     *
+     * @param host         ip地址
+     * @param port         端口
+     * @param userName     用户名
+     * @param password     密码
+     * @param databaseName 数据库名
+     * @param file         文件对象
+     */
+    public static void reduction(String host, String port, String userName, String password, String databaseName, File file) throws Exception {
+        if (!file.exists()) {
+            System.out.printf("文件:%s 不存在,请检查%n", file.getPath());
+            return;
+        }
+        String filePath = file.getPath();
+        String cmd = "mysql -h" + host + " -P" + port + " -u" + userName + " -p" + password + " " + databaseName + " < " + filePath;
+        System.out.println("系统环境:" + System.getProperties().getProperty("os.name"));
+        String os = System.getProperties().getProperty("os.name");
+        if(os.contains("Windows")){
+            // Windows 需要加上 cmd /c
+            cmd = "cmd /c " + cmd;
+        }
+        System.out.printf("数据库还原命令:%s%n", cmd);
+
+
+        //拼接cmd命令
+        Process exec = Runtime.getRuntime().exec(cmd);
+        if (exec.waitFor() == 0) {
+            System.out.printf("数据库:%s 还原成功,还原的文件为:%s%n", databaseName, filePath);
+        } else {
+            System.out.println(databaseName + "数据库还原失败");
+            System.out.printf("数据库:%s 还原失败", databaseName);
+        }
+    }
+
+
+
+    /**
+     * 导入sql文件
+     *
+     * @param file     文件对象
+     * @param user     用户
+     * @param password 密码
+     * @param db       数据库
+     */
+    public static void load(File file, String user, String password, String db) {
+
+        //拼接cmd命令
+        try {
+            Runtime rt = Runtime.getRuntime();
+            String command = "mysql -u" + user + " -p" + password + " --default-character-set=utf8 " + db;
+            Process child = rt.exec(command);
+            OutputStream outputStream = child.getOutputStream();
+            BufferedReader bufferedReader = new BufferedReader(
+                    new InputStreamReader(Files.newInputStream(file.toPath()), StandardCharsets.UTF_8));
+            OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8);
+            String str;
+            while ((str = bufferedReader.readLine()) != null) {
+                outputStreamWriter.write(str + "\r\n");
+            }
+            outputStreamWriter.flush();
+            outputStream.close();
+            bufferedReader.close();
+            outputStreamWriter.close();
+            System.out.println("数据库导入完成");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+
+/*
+    public static void main(String[] args) throws Exception {
+        File file = new File("C:\\Users\\hansonh\\Desktop\\jar", "backup.sql");
+
+
+        System.out.println("系统环境:" + System.getProperties().getProperty("os.name"));
+
+        String subStr = "jdbc:mysql://127.0.0.1:3306/pms?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&verifyServerCertificate=false&useSSL=false&rewriteBatchedStatements=true&zeroDateTimeBehavior=convertToNull";
+
+
+        // 第三个 :号下标
+        int subStrIndex = subStr.indexOf(":", subStr.indexOf(":", subStr.indexOf(":") + 1) + 1);
+        // IP
+        String host = subStr.substring(subStr.indexOf("//") + 2, subStrIndex);
+        System.out.println("IP:" + host);
+
+        // 端口
+        String subStr2 = subStr.substring(subStrIndex);
+        String port = subStr2.substring(1, subStr2.indexOf("/"));
+        System.out.println("端口:" + port);
+
+        // 数据库名
+        String dataBaseName = subStr2.substring(subStr2.indexOf("/") + 1, subStr2.indexOf("?"));
+
+        System.out.println("数据库名:" + dataBaseName);
+
+        // 备份数据库
+        DbUtil.backup( "127.0.0.1","3306", "dev1", "dev1", "pms", file);
+        // 恢复数据库
+//        DbUtil.reduction( "127.0.0.1","3306", "root", "123456", "pms", file);
+    }
+
+ */
+}

+ 1 - 1
huimv-eartag2-platform/huimv-eartag2-api/src/main/java/com/huimv/eartag2/api/mapper/xml/BaseFarmMapper.xml

@@ -1,6 +1,6 @@
 <?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.huimv.eartag2.api.mapper.BaseFarmMapper">
+<mapper namespace="com.huimv.eartag2.manage2.mapper.BaseFarmMapper">
 
     <!-- 通用查询映射结果 -->
     <resultMap id="BaseResultMap" type="com.huimv.eartag2.api.pojo.BaseFarm">

+ 0 - 1
huimv-eartag2-platform/huimv-eartag2-api/src/main/java/com/huimv/eartag2/api/mapper/xml/BasePigpenMapper.xml

@@ -8,7 +8,6 @@
         <result column="pigpen_name" property="pigpenName" />
         <result column="pigpen_code" property="pigpenCode" />
         <result column="parent_id" property="parentId" />
-        <result column="f_type" property="fType" />
         <result column="farm_code" property="farmCode" />
         <result column="sort" property="sort" />
         <result column="stage_code" property="stageCode" />

+ 111 - 0
huimv-eartag2-platform/huimv-eartag2-api/src/main/java/com/huimv/eartag2/api/netty/EartagServer.java

@@ -0,0 +1,111 @@
+package com.huimv.eartag2.api.netty;
+
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.*;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioServerSocketChannel;
+import io.netty.handler.logging.LogLevel;
+import io.netty.handler.logging.LoggingHandler;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@Component
+public class EartagServer {
+    @Autowired
+    private EartagServerHandler2 serverHandler;
+    //监听端口
+    private int port = 10023;
+//    private int port2 = 10024;
+    //创建构造方法
+    public EartagServer(){
+    }
+
+    public static void main(String[] args) throws InterruptedException {
+        new EartagServer().run();
+    }
+/**
+ *
+ * 功能描述: 启动方法前台多个服务  处理多个线程
+ *
+ * @param:
+ * @return:
+ * @auther: LiGang
+ * @date: 2019/3/26 11:31
+ */
+    /**
+     * 启动流程
+     */
+    public void run() throws InterruptedException {
+        //配置服务端线程组
+        EventLoopGroup bossGroup=new NioEventLoopGroup();
+        EventLoopGroup workGroup=new NioEventLoopGroup();
+
+        try{
+            //引导整个server的启动
+            ServerBootstrap serverBootstrap = new ServerBootstrap();
+
+           serverBootstrap.group(bossGroup, workGroup)
+                    .channel(NioServerSocketChannel.class)    //指定处理的连接类型
+                    .option(ChannelOption.SO_REUSEADDR, true)
+                    .childHandler(new ChannelInitializer<SocketChannel>() {
+                        @Override
+                        protected void initChannel(SocketChannel socketChannel) throws Exception {
+                            socketChannel.pipeline().addLast(serverHandler);
+                        }
+                    });
+            System.out.println("# 耳标及采集器设备数据接收服务器已经启动。#");
+            System.out.println("# 准备接收数据:");
+            //绑定端口,同步等待成功
+            ChannelFuture cf = serverBootstrap.bind(port).sync();
+//            ChannelFuture cf2 = serverBootstrap.bind(port2).sync();
+            // 等待服务端监听端口关闭
+            cf.channel().closeFuture().sync();
+//            cf2.channel().closeFuture().sync();
+        }finally {
+            //优雅的退出
+            bossGroup.shutdownGracefully();
+            workGroup.shutdownGracefully();
+        }
+    }
+
+    public void run2() throws InterruptedException {
+        ServerBootstrap b = new ServerBootstrap();
+        EventLoopGroup bossGroup = new NioEventLoopGroup();
+        EventLoopGroup workerGroup = new NioEventLoopGroup();
+
+        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
+                .option(ChannelOption.SO_REUSEADDR, true)
+                .childHandler(new ChannelInitializer() {
+                    @Override
+                    protected void initChannel(Channel ch) throws Exception {
+                        ch.pipeline()
+                                .addLast("logging", new LoggingHandler(LogLevel.INFO))
+                                .addLast(new SimpleChannelInboundHandler() {
+                                    @Override
+                                    protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
+                                        ByteBuf data = (ByteBuf) msg;
+                                        String clientAskText = data.toString(io.netty.util.CharsetUtil.UTF_8);
+//                                        String strMsg = msg.toString(CharsetUtil.UTF_8);
+                                        System.out.println("clientAskText>>"+clientAskText);
+                                    }
+                                });
+                    }
+                });
+
+//        b.bind(port).sync();
+//        System.out.println("tcp server("+port+") is started..");
+
+//        b.bind(port2).sync();
+//        System.out.println("tcp server("+port2+") is started..");
+    }
+}

+ 298 - 0
huimv-eartag2-platform/huimv-eartag2-api/src/main/java/com/huimv/eartag2/api/netty/EartagServerHandler2.java

@@ -0,0 +1,298 @@
+package com.huimv.eartag2.api.netty;
+
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.json.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.huimv.eartag2.api.config.WebSocket;
+import com.huimv.eartag2.api.pojo.EartagDeviceRegister;
+import com.huimv.eartag2.api.pojo.EartagEartagRegister2;
+import com.huimv.eartag2.api.pojo.PliersDemo;
+import com.huimv.eartag2.api.pojo.StationLib;
+import com.huimv.eartag2.api.service.IEartagDeviceRegisterService;
+import com.huimv.eartag2.api.service.IEartagEartagRegister2Service;
+import com.huimv.eartag2.api.service.IPliersDemoService;
+import com.huimv.eartag2.api.service.IStationLibService;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.ChannelHandler;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.util.CharsetUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+
+import java.text.ParseException;
+import java.util.Date;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@ChannelHandler.Sharable
+@Component
+@Slf4j
+public class EartagServerHandler2 extends ChannelInboundHandlerAdapter {
+    private StringBuilder askTextSb = null;
+@Autowired
+private IEartagEartagRegister2Service eartagRegisterService;
+    @Autowired
+    private IEartagDeviceRegisterService deviceRegisterService;
+
+    @Autowired
+    private IStationLibService stationLibService;
+
+    @Autowired
+    private IPliersDemoService pliersDemoService;
+
+    @Autowired
+    private RestTemplate restTemplate ;
+    //
+    public void appendClientAsk(String text){
+        if(this.askTextSb == null){
+            askTextSb = new StringBuilder();
+        }
+        askTextSb.append(text);
+    }
+
+    @Override
+    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
+        ByteBuf data = (ByteBuf) msg;
+        String clientAskText = data.toString(CharsetUtil.UTF_8);
+//        System.out.println((++num)+"次, 客户端消息clientAskText>>"+clientAskText);
+        //保存实例内的客户端请求
+        appendClientAsk(clientAskText);
+    }
+
+    @Override
+    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
+//        ctx.writeAndFlush("111");
+//        System.out.println("EchoServerHandle channelReadComplete");
+        if(askTextSb.toString().indexOf("end") != -1){
+//            System.out.println("askTextSb.内容()>>"+askTextSb.toString());
+//            System.out.println("askTextSb.内容长度>>"+askTextSb.length());
+//            System.out.println("输入完成.");
+            // 处理客户端消息
+            handleClientEartagMessage(askTextSb.toString(),ctx);
+            //清空重置;
+            askTextSb.delete(0,askTextSb.length());
+//            System.out.println("清空sb实例. 长度>>"+askTextSb.length());
+        }
+    }
+
+    @Override
+    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
+//        System.out.println("cause.getMessage()>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+cause.getMessage());
+        if(cause.getMessage().indexOf("Connection reset") != -1){
+            log.info("相关采集器设备正在重启:"+cause.toString());
+        }
+//        cause.printStackTrace();
+        ctx.close();
+    }
+
+
+
+    private   void handleClientEartagMessage(String clientAskText, ChannelHandlerContext ctx) throws ParseException, JsonProcessingException {
+        clientAskText = clientAskText.replaceAll("\r","").replaceAll("\n","");
+        System.out.println("clientAskText--------------->" +clientAskText);
+//hm+7+868977051335099+122083123610011+0+end
+
+        String[] split = clientAskText.split("\\+");
+
+        if ("6".equals(split[1])){
+            System.out.println("pliersDemo------------->" +clientAskText);
+            ctx.writeAndFlush(Unpooled.copiedBuffer("hm+6+0+119.3.44.183+10023+8+end".getBytes()));
+        }
+        if ("7".equals(split[1])){
+            System.out.println("1");
+            ctx.writeAndFlush(Unpooled.copiedBuffer("hm+7+8+end".getBytes()));
+            String device = split[2];
+            String eartag = split[3];
+            EartagDeviceRegister deviceRegister = deviceRegisterService.getOne(new QueryWrapper<EartagDeviceRegister>().eq("chip_id", device));
+            System.out.println("2");
+            if(ObjectUtil.isNotEmpty(deviceRegister)){
+                Integer upgrade = deviceRegister.getUpgrade();
+                if (upgrade ==1){
+                    saveMoneyData(split,deviceRegister.getChipId());
+                }else {
+                    saveData(split);
+                }
+                EartagEartagRegister2 eartagRegister = eartagRegisterService.getOne(new QueryWrapper<EartagEartagRegister2>().eq("earmark", eartag));
+                if (ObjectUtil.isNotEmpty(eartagRegister)){
+                    eartagRegister.setEarmark(eartag);
+                    eartagRegister.setFirstDevice(device);
+                    eartagRegister.setRegisterTime(new Date());
+                    eartagRegister.setRegisterType(2);
+                    eartagRegister.setFarmId(deviceRegister.getFarmId());
+                    eartagRegister.setCreateDate(new Date());
+                    eartagRegisterService.updateById(eartagRegister);
+                }else {
+                    EartagEartagRegister2 eartagEartagRegister = new EartagEartagRegister2();
+                    eartagEartagRegister.setEarmark(eartag);
+                    eartagEartagRegister.setFirstDevice(device);
+                    eartagEartagRegister.setRegisterTime(new Date());
+                    eartagEartagRegister.setRegisterType(2);
+                    eartagEartagRegister.setFarmId(deviceRegister.getFarmId());
+                    eartagEartagRegister.setCreateDate(new Date());
+                    eartagRegisterService.save(eartagEartagRegister);
+                }
+                WebSocket.sendMessage("true");
+            }
+        }
+    }
+    private  final  String URL = "http://apilocate.amap.com/position";
+    private  final  String KEY = "9ccbad3db267cd800084179fe58c5ce9";
+
+    private void saveMoneyData(String[] split,String imei ) {
+        String eartag = split[3];
+        String device = split[2];
+        String lac = split[4];
+        String ci = split[5];
+        StationLib stationLib = stationLibService.getOne(new QueryWrapper<StationLib>().eq("ci", ci).eq("lac", lac));
+        String lat ="";
+        String lon ="";
+        String address ="";
+        JSONObject body= new JSONObject();
+        if (ObjectUtil.isEmpty(stationLib)){
+            try {
+                ResponseEntity<JSONObject>  forEntity = restTemplate.getForEntity(URL+"?accesstype=0&imei="+imei+"&cdma=0&bts=460,0,"+lac+","+ci+",-30&output=json&key="+KEY+"&network=GSM", JSONObject.class);
+                System.out.println("forEntity" + forEntity);
+                body = forEntity.getBody();
+            }catch (Exception e){
+                System.out.println(e);
+            }
+            if (ObjectUtil.isNotEmpty(body)){
+                Object infocode = body.get("infocode");
+                if ("10000".equals(infocode)){
+                    JSONObject result = (JSONObject)body.get("result");
+                    address = (String) result.get("desc");
+                    String radius = (String) result.get("radius");
+                    String locations = (String) result.get("location");
+                    String[] location = locations.split(",");
+
+                    lat = location[1];
+                    lon = location[0];
+
+                    StationLib stationLib1 = new StationLib();
+                    stationLib1.setAddress(address);
+                    stationLib1.setCi(ci);
+                    stationLib1.setLac(lac);
+                    stationLib1.setLat(lat);
+                    stationLib1.setLon(lon);
+                    stationLib1.setRadius(Integer.parseInt(radius));
+                    stationLibService.save(stationLib1);
+                }else {
+                    StationLib id = stationLibService.getOne(new QueryWrapper<StationLib>().orderByDesc("id").last("limit 1"));
+                    lat = id.getLat();
+                    lon = id.getLon();
+                    address = id.getAddress();
+                    System.out.println(body);
+                    System.out.println("高德接口出错,取上一个记录接口");
+                }
+            }
+
+        }else {
+            lat = stationLib.getLat();
+            lon = stationLib.getLon();
+            address = stationLib.getAddress();
+        }
+
+        int countEarmark = (int)pliersDemoService.count(new QueryWrapper<PliersDemo>().eq("earmark", eartag));
+        PliersDemo pliersDemo = new PliersDemo();
+        pliersDemo.setEarmark(eartag);
+        pliersDemo.setPliersId(device);
+        pliersDemo.setUpdateTime(new Date());
+        pliersDemo.setUsegeTimes(1+countEarmark);
+
+        pliersDemo.setLat(lat);
+        pliersDemo.setLon(lon);
+        pliersDemo.setAddress(address);
+        pliersDemoService.save(pliersDemo);
+        System.out.println("存储成功");
+    }
+
+    private void saveData( String[] split  ) {
+
+            //耳标记录,加上webSoket
+            //hm+7+868977051335099+122083123610011+22450+184902913+0+end
+        String eartag = split[3];
+            String lac = split[4];
+            String ci = split[5];
+            String pliersId = split[2];
+            StationLib stationLib = stationLibService.getOne(new QueryWrapper<StationLib>().eq("ci", ci).eq("lac", lac));
+            String lat ="";
+            String lon ="";
+            String address ="";
+
+            JSONObject body= new JSONObject();
+            if (ObjectUtil.isEmpty(stationLib)){
+                try {
+                    ResponseEntity<JSONObject>  forEntity = restTemplate.getForEntity("http://api.cellocation.com:82/cell/?mcc=460&mnc=1&lac="+lac+"&ci="+ci+"&output=json", JSONObject.class);
+                    System.out.println("forEntity"+forEntity);
+                    body = forEntity.getBody();
+                }catch (Exception e){
+                    System.out.println(e);
+                }
+
+                lat = (String)body.get("lat");
+                lon =  (String)body.get("lon");
+                address = (String)body.get("address");
+                String    radius = (String)body.get("radius");
+                Integer  errcode = (Integer)body.get("errcode");
+                if (errcode == 0){
+                    StationLib stationLib1 = new StationLib();
+                    stationLib1.setAddress(address);
+                    stationLib1.setCi(ci);
+                    stationLib1.setErrcode(errcode+"");
+                    stationLib1.setLac(lac);
+                    stationLib1.setLat(lat);
+                    stationLib1.setLon(lon);
+                    stationLib1.setRadius(Integer.parseInt(radius));
+
+                    stationLibService.save(stationLib1);
+                }
+                if (errcode == 10001){
+                    StationLib id = stationLibService.getOne(new QueryWrapper<StationLib>().orderByDesc("id").last("limit 1"));
+                    lat = id.getLat();
+                    lon = id.getLon();
+                    address = id.getAddress();
+                }
+
+            }else {
+                lat = stationLib.getLat();
+                lon = stationLib.getLon();
+                address = stationLib.getAddress();
+            }
+
+
+            int countEarmark = (int)pliersDemoService.count(new QueryWrapper<PliersDemo>().eq("earmark", eartag));
+            PliersDemo pliersDemo = new PliersDemo();
+            pliersDemo.setEarmark(eartag);
+            pliersDemo.setPliersId(pliersId);
+            pliersDemo.setUpdateTime(new Date());
+            pliersDemo.setUsegeTimes(1+countEarmark);
+
+
+            pliersDemo.setLat(lat);
+            pliersDemo.setLon(lon);
+            pliersDemo.setAddress(address);
+            pliersDemoService.save(pliersDemo);
+
+//                List<PliersDemo> id = pliersDemoService.list(new QueryWrapper<PliersDemo>().eq("pliers_id",pliersId).orderByDesc("id").last("limit 50"));
+//                String resultJson= new ObjectMapper().writeValueAsString(true);
+
+
+    }
+
+
+//hm+7+868977051335099+122083123610011+0+end
+    //hm+6+868977051335099+0+end
+
+}

+ 6 - 3
huimv-eartag2-platform/huimv-eartag2-api/src/main/java/com/huimv/eartag2/api/service/impl/EartagAbnormalAlarmServiceImpl.java

@@ -194,7 +194,7 @@ public class EartagAbnormalAlarmServiceImpl extends ServiceImpl<EartagAbnormalAl
         queryWrapper.eq("add_date",todayDate);
 
         queryWrapper.orderByDesc("add_time");
-        queryWrapper.last("limit 50");
+        queryWrapper.last("limit 30");
 
         List<EartagAbnormalAlarm> eartagAbnormalAlarmList =  eartagAbnormalAlarmMapper.selectList(queryWrapper);
         JSONArray newJa = new JSONArray();
@@ -213,7 +213,8 @@ public class EartagAbnormalAlarmServiceImpl extends ServiceImpl<EartagAbnormalAl
 
     @Override
     public Result getNewPig(Map<String, String> paramsMap) {
-        String areaId = paramsMap.get("areaId");
+//        String areaId = paramsMap.get("areaId");
+        String areaId = "331102001";
         QueryWrapper<EartagEartagRegister2> wrapper = new QueryWrapper<>();
 
         List endList = new ArrayList();
@@ -299,12 +300,14 @@ public class EartagAbnormalAlarmServiceImpl extends ServiceImpl<EartagAbnormalAl
 
     @Override
     public Result getFarmerAndPig(Map<String, Object> paramsMap) {
+//        List<BaseFarmer> farmers = baseFargetAssetStatisticsmerMapper.selectList(new QueryWrapper<BaseFarmer>().eq("farm_code", "330727001"));
         List<BaseFarmer> farmers = baseFarmerMapper.selectList(new QueryWrapper<BaseFarmer>().eq("farm_code", "330727001"));
 
         List endList = new ArrayList();
         for (BaseFarmer farmer : farmers) {
             Map map = new HashMap();
-            List<EartagDeviceRegister> eartagDeviceRegisters = eartagDeviceRegisterMapper.selectList(new QueryWrapper<EartagDeviceRegister>().eq("farmer_id", farmer.getId()).eq("farm_id","330727001"));
+//            List<EartagDeviceRegister> eartagDeviceRegisters = eartagDeviceRegisterMapper.selectList(new QueryWrapper<EartagDeviceRegister>().eq("farmer_id", farmer.getId()).eq("farm_id","330727001"));
+            List<EartagDeviceRegister> eartagDeviceRegisters = eartagDeviceRegisterMapper.selectList(new QueryWrapper<EartagDeviceRegister>().eq("device_code","330112002000001"));
             map.put( "data",new ArrayList<>());
             map.put("id",farmer.getId());
             map.put("farmer",farmer.getFarmer());

+ 3 - 2
huimv-eartag2-platform/huimv-eartag2-api/src/main/resources/application-prod2.yml

@@ -1,11 +1,12 @@
 server:
-  port: 8093
+  port: 8099
 spring:
   application:
     name: huimv-eartag2-api
 
   datasource:
-    url: jdbc:mysql://10.0.0.77:3309/huimv-demo-eartag20?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&serverTimezone=Asia/Shanghai
+#    url: jdbc:mysql://10.0.0.77:3309/huimv-demo-eartag20?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&serverTimezone=Asia/Shanghai
+    url: jdbc:mysql://139.9.172.209:3309/huimv-demo-eartag20?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&serverTimezone=Asia/Shanghai
     username: eartag
     password: eartag@2022
     driver-class-name: com.mysql.cj.jdbc.Driver

+ 1 - 1
huimv-eartag2-platform/huimv-eartag2-manage2/src/main/java/com/huimv/eartag2/manage2/HuimvManageApplication.java

@@ -31,7 +31,7 @@ public class HuimvManageApplication {
     public static void main(String[] args) throws InterruptedException {
 
         ApplicationContext applicationContext =   SpringApplication.run(HuimvManageApplication.class, args);
-        applicationContext.getBean(EartagServer.class).run();
+//        applicationContext.getBean(EartagServer.class).run();
     }
     @Bean
     public static RestTemplate getRestTemplate(){