From 2546987df58d05ca1d02254d8f849a559b23ef43 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 18 Aug 2021 17:55:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 14 +++++------ .../com/update/update/UpdateApplication.java | 6 +++++ .../update/controller/freshController.java | 5 ++-- .../com/update/update/dao/freshMapper.java | 14 ++++------- .../update/update/{bean => entity}/fresh.java | 2 +- .../update/update/service/freshService.java | 2 +- .../update/service/impl/freshServiceImpl.java | 3 ++- .../service/impl/refreshServiceImpl.java | 19 ++++++--------- .../update/update/service/refreshService.java | 4 ++-- .../update/util/APKVersionCodeUtils.java | 24 ------------------- .../controller/freshControllerTest.java | 22 ++++++++++++++++- 11 files changed, 54 insertions(+), 61 deletions(-) rename src/main/java/com/update/update/{bean => entity}/fresh.java (94%) delete mode 100644 src/main/java/com/update/update/util/APKVersionCodeUtils.java diff --git a/pom.xml b/pom.xml index acaedf0..288b7d1 100644 --- a/pom.xml +++ b/pom.xml @@ -41,13 +41,7 @@ pagehelper 5.2.0 - - - com.google.android - android - 4.1.1.4 - provided - + com.google.code.gson @@ -74,6 +68,12 @@ log4j 1.2.12 + + com.vaadin.external.google + android-json + 0.0.20131108.vaadin1 + compile + diff --git a/src/main/java/com/update/update/UpdateApplication.java b/src/main/java/com/update/update/UpdateApplication.java index aebb0c1..4a0b0cf 100644 --- a/src/main/java/com/update/update/UpdateApplication.java +++ b/src/main/java/com/update/update/UpdateApplication.java @@ -1,10 +1,15 @@ package com.update.update; + import org.mybatis.spring.annotation.MapperScan; + import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; + +import javax.sql.DataSource; + @SpringBootApplication @MapperScan("com.update.update.dao.freshMapper") @@ -15,4 +20,5 @@ public class UpdateApplication { } + } diff --git a/src/main/java/com/update/update/controller/freshController.java b/src/main/java/com/update/update/controller/freshController.java index e1ac79a..153c1ec 100644 --- a/src/main/java/com/update/update/controller/freshController.java +++ b/src/main/java/com/update/update/controller/freshController.java @@ -1,7 +1,7 @@ package com.update.update.controller; -import com.update.update.bean.fresh; +import com.update.update.entity.fresh; import com.update.update.util.GJson; import org.json.JSONException; import org.json.JSONObject; @@ -62,6 +62,7 @@ public class freshController { } @RequestMapping(value = "/updating",method = RequestMethod.POST) public void updating(HttpServletRequest request, HttpServletResponse response) throws Exception { - ServletUtil.createSuccessResponse(200, GJson.toJson(new refreshServiceImpl().new_version()),response); + String oldVersionId = request.getParameter("oldVersionId"); + ServletUtil.createSuccessResponse(200, GJson.toJson(new refreshServiceImpl().new_version(oldVersionId)),response); } } diff --git a/src/main/java/com/update/update/dao/freshMapper.java b/src/main/java/com/update/update/dao/freshMapper.java index 9b674a3..fdb684d 100644 --- a/src/main/java/com/update/update/dao/freshMapper.java +++ b/src/main/java/com/update/update/dao/freshMapper.java @@ -1,11 +1,14 @@ package com.update.update.dao; -import com.update.update.bean.fresh; +import com.update.update.entity.fresh; import org.apache.ibatis.annotations.*; +import org.apache.ibatis.jdbc.SQL; import org.springframework.stereotype.Component; +import java.util.List; + @Component @Mapper @@ -14,16 +17,7 @@ public interface freshMapper { int add(fresh learnResouce); - @DeleteProvider(type = fresh.class, method = "deleteByids") - int deleteByIds(@Param("ids") String[] ids); - - @Select("SELECT * FROM fresh ORDER BY id DESC LIMIT 1") - @Results(value = { - @Result(column = "VersionId", property = "VersionId", javaType = String.class), - @Result(property = "apkUrl", column = "apkUrl", javaType = String.class), - @Result(property = "updateDescription", column = "updateDescription", javaType = String.class) - }) fresh query(); } \ No newline at end of file diff --git a/src/main/java/com/update/update/bean/fresh.java b/src/main/java/com/update/update/entity/fresh.java similarity index 94% rename from src/main/java/com/update/update/bean/fresh.java rename to src/main/java/com/update/update/entity/fresh.java index 84a24c3..4ccaf71 100644 --- a/src/main/java/com/update/update/bean/fresh.java +++ b/src/main/java/com/update/update/entity/fresh.java @@ -1,4 +1,4 @@ -package com.update.update.bean; +package com.update.update.entity; public class fresh { public String VersionId; diff --git a/src/main/java/com/update/update/service/freshService.java b/src/main/java/com/update/update/service/freshService.java index 98d3e53..c44a4c4 100644 --- a/src/main/java/com/update/update/service/freshService.java +++ b/src/main/java/com/update/update/service/freshService.java @@ -1,6 +1,6 @@ package com.update.update.service; -import com.update.update.bean.fresh; +import com.update.update.entity.fresh; public interface freshService { int add(fresh version); diff --git a/src/main/java/com/update/update/service/impl/freshServiceImpl.java b/src/main/java/com/update/update/service/impl/freshServiceImpl.java index b2c16dc..33bde98 100644 --- a/src/main/java/com/update/update/service/impl/freshServiceImpl.java +++ b/src/main/java/com/update/update/service/impl/freshServiceImpl.java @@ -1,7 +1,7 @@ package com.update.update.service.impl; -import com.update.update.bean.fresh; +import com.update.update.entity.fresh; import com.update.update.dao.freshMapper; import com.update.update.service.freshService; import org.springframework.beans.factory.annotation.Autowired; @@ -10,6 +10,7 @@ import org.springframework.stereotype.Service; @Service public class freshServiceImpl implements freshService { + @Autowired freshMapper f; @Override public int add(fresh newOne) { diff --git a/src/main/java/com/update/update/service/impl/refreshServiceImpl.java b/src/main/java/com/update/update/service/impl/refreshServiceImpl.java index d1fb345..8efc1a9 100644 --- a/src/main/java/com/update/update/service/impl/refreshServiceImpl.java +++ b/src/main/java/com/update/update/service/impl/refreshServiceImpl.java @@ -1,20 +1,17 @@ package com.update.update.service.impl; -import android.app.Application; - -import android.content.Context; -import com.update.update.bean.fresh; +import com.update.update.entity.fresh; import com.update.update.service.refreshService; -import com.update.update.util.APKVersionCodeUtils; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class refreshServiceImpl implements refreshService { - @Autowired - freshServiceImpl ser; + + freshServiceImpl ser=new freshServiceImpl(); //version1大返回一个正数,小返回一个负数,相等返回0 public static int compareVersion(String version1, String version2) throws Exception { @@ -36,12 +33,10 @@ public class refreshServiceImpl implements refreshService { return diff; } - Application application = new Application(); - Context ass = application.getApplicationContext(); - String oldVersion = APKVersionCodeUtils.getVerName(ass); - String newVersion = ser.query().VersionId; @Override - public fresh new_version() throws Exception { + public fresh new_version(String oldVersion) throws Exception { + freshServiceImpl ser=new freshServiceImpl(); + String newVersion = ser.query().VersionId; if (compareVersion(oldVersion, newVersion) < 0){ return ser.query(); } diff --git a/src/main/java/com/update/update/service/refreshService.java b/src/main/java/com/update/update/service/refreshService.java index 6909b39..bbb685d 100644 --- a/src/main/java/com/update/update/service/refreshService.java +++ b/src/main/java/com/update/update/service/refreshService.java @@ -1,8 +1,8 @@ package com.update.update.service; -import com.update.update.bean.fresh; +import com.update.update.entity.fresh; public interface refreshService { //判断是否需要更新,比对是否有新的版本 - public fresh new_version() throws Exception; + public fresh new_version(String old_version) throws Exception; } diff --git a/src/main/java/com/update/update/util/APKVersionCodeUtils.java b/src/main/java/com/update/update/util/APKVersionCodeUtils.java deleted file mode 100644 index ec003e5..0000000 --- a/src/main/java/com/update/update/util/APKVersionCodeUtils.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.update.update.util; -import android.content.Context; - -import android.content.pm.PackageManager; -public class APKVersionCodeUtils { - - /** - * 获取版本号名称 - * - * @param context 上下文 - * @return - */ - public static String getVerName(Context context) { - String verName = ""; - try { - verName = context.getPackageManager(). - getPackageInfo(context.getPackageName(), 0).versionName; - } catch (PackageManager.NameNotFoundException e) { - e.printStackTrace(); - } - return verName; - } - -} \ No newline at end of file diff --git a/src/test/java/com/update/update/controller/freshControllerTest.java b/src/test/java/com/update/update/controller/freshControllerTest.java index 440570b..51226e9 100644 --- a/src/test/java/com/update/update/controller/freshControllerTest.java +++ b/src/test/java/com/update/update/controller/freshControllerTest.java @@ -1,11 +1,31 @@ package com.update.update.controller; +import com.update.update.dao.freshMapper; +import com.update.update.entity.fresh; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; import org.junit.jupiter.api.Test; -class freshControllerTest { +class freshControllerTest { + private static SqlSessionFactory sqlSessionFactory; + public SqlSession getSqlSession(){ + return sqlSessionFactory.openSession(); + } @Test void addVersion() { } + + @Test + void updating() { + SqlSession sqlSession = getSqlSession(); + try{ + freshMapper sysUserMapper = sqlSession.getMapper(freshMapper.class); + fresh a= sysUserMapper.query(); + System.out.println(a); + }catch (Exception e){ + e.printStackTrace(); + } + } } \ No newline at end of file