From 062823ae5351cad30e8d3c8f4501e2298b92c555 Mon Sep 17 00:00:00 2001 From: hello-hao <923453645@qq.com> Date: Fri, 19 May 2023 18:58:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=94=AF=E6=8C=81=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=9B=BE=E5=83=8F=EF=BC=8C=E8=87=AA=E5=8A=A8=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E6=96=B0=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AdminRootController.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/main/java/cn/hellohao/controller/AdminRootController.java b/src/main/java/cn/hellohao/controller/AdminRootController.java index b54d0c1..2e6ca46 100644 --- a/src/main/java/cn/hellohao/controller/AdminRootController.java +++ b/src/main/java/cn/hellohao/controller/AdminRootController.java @@ -4,7 +4,9 @@ import cn.hellohao.pojo.*; import cn.hellohao.service.*; import cn.hellohao.service.impl.*; import cn.hellohao.utils.NewSendEmail; +import cn.hellohao.utils.Print; import cn.hellohao.utils.SetFiles; +import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -19,6 +21,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.HashMap; import java.util.List; @Controller @@ -392,5 +397,50 @@ public class AdminRootController { return msg; } + @PostMapping("/sysVersion") + @ResponseBody + public Msg sysupdate(@RequestParam(value = "data", defaultValue = "") String data) { + final Msg msg = new Msg(); + JSONObject jsonObj = JSONObject.parseObject(data); + String dates = jsonObj.getString("dates"); + HashMap paramMap = new HashMap<>(); + String urls = "http://check.hellohao.cn:8090/getNoticeText"; + JSONObject jsonObject =null; + try { + URL u = new URL(urls); + HttpURLConnection uConnection = (HttpURLConnection) u.openConnection(); + uConnection.connect(); + if(uConnection.getResponseCode()==200){ + jsonObject =JSONObject.parseObject(HttpUtil.get(urls)); + String openv = jsonObject.getString("openv"); + String opentext = jsonObject.getString("opentext"); + JSONObject versionJson = new JSONObject(); + if(Double.valueOf(openv)>Double.valueOf(dates)){ + versionJson.put("code","110200"); + versionJson.put("newVersion",openv); + versionJson.put("versionMsg",opentext); + msg.setCode("110200"); + msg.setData(versionJson); + }else{ + versionJson.put("code","110300"); + versionJson.put("newVersion",openv); + versionJson.put("versionMsg","当前已是最新版本"); + msg.setCode("110300"); + msg.setData(versionJson); + } + }else{ + msg.setCode("110500"); + msg.setData("未获取到更新状态"); + } + uConnection.disconnect(); + } catch (Exception e) { + e.printStackTrace(); + Print.warning("connect failed"); + msg.setCode("110500"); + msg.setData("未获取到更新状态"); + } + return msg; + } + }