2 Commits 6857ae4cba ... 6b92d90588

Autor SHA1 Mensaje Fecha
  aokunsang 6b92d90588 Merge branch 'saas-feature-dev' of http://git.platomix.net/aokunsang/platomix-gmetry-api into saas-feature-dev hace 3 semanas
  aokunsang e6feff5abb 升级springboot版本 hace 3 semanas

+ 22 - 11
pom.xml

@@ -5,14 +5,13 @@
     <parent>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-parent</artifactId>
-        <version>2.1.3.RELEASE</version>
+        <version>2.4.4</version>
         <relativePath/> <!-- lookup parent from repository -->
     </parent>
     <groupId>com.ff</groupId>
     <artifactId>apimngr</artifactId>
     <version>1.0.35</version>
     <name>platomix-gmetry-api</name>
-    <description>Demo project for Spring Boot</description>
 
     <properties>
         <java.version>1.8</java.version>
@@ -26,27 +25,35 @@
     </properties>
 
     <dependencies>
+
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
+            <!-- 排除Tomcat依赖 -->
+            <exclusions>
+                <exclusion>
+                    <groupId>org.springframework.boot</groupId>
+                    <artifactId>spring-boot-starter-tomcat</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
 
-        <!-- MybatisPlus -->
-        <dependency>
-            <groupId>com.baomidou</groupId>
-            <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
-            <version>${mybatis.plus.dynamic.version}</version>
-        </dependency>
         <dependency>
-            <groupId>com.baomidou</groupId>
-            <artifactId>mybatis-plus-boot-starter</artifactId>
-            <version>3.5.3</version>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-undertow</artifactId>
+            <exclusions>
+                <exclusion>
+                    <artifactId>undertow-websockets-jsr</artifactId>
+                    <groupId>io.undertow</groupId>
+                </exclusion>
+            </exclusions>
         </dependency>
 
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-data-redis</artifactId>
         </dependency>
+
         <dependency>
             <groupId>com.alibaba</groupId>
             <artifactId>druid</artifactId>
@@ -124,6 +131,10 @@
             <artifactId>commons-pool2</artifactId>
         </dependency>
         <dependency>
+            <groupId>javax.validation</groupId>
+            <artifactId>validation-api</artifactId>
+        </dependency>
+        <dependency>
             <groupId>org.apache.httpcomponents</groupId>
             <artifactId>httpmime</artifactId>
             <version>4.5.3</version>

+ 162 - 162
src/main/java/com/ff/apimngr/task/ScheduleTask.java

@@ -1,162 +1,162 @@
-package com.ff.apimngr.task;
-
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.annotation.Resource;
-
-import org.springframework.context.annotation.Configuration;
-import org.springframework.data.redis.core.StringRedisTemplate;
-import org.springframework.scheduling.annotation.EnableScheduling;
-import org.springframework.scheduling.annotation.Scheduled;
-
-import com.alibaba.fastjson.JSONObject;
-import com.ff.apimngr.controller.DemoController;
-import com.ff.apimngr.entity.App;
-import com.ff.apimngr.entity.AppApi;
-import com.ff.apimngr.service.ApiLogService;
-import com.ff.apimngr.service.AppApiService;
-import com.ff.apimngr.service.AppService;
-import com.ff.apimngr.util.Config;
-import com.ff.apimngr.util.HttpUtils;
-
-@Configuration
-@EnableScheduling
-public class ScheduleTask {
-
-    @Resource
-    ApiLogService apiLogService;
-
-    @Resource
-    AppService appService;
-
-    @Resource
-    private StringRedisTemplate stringRedisTemplate;
-
-    @Resource
-    AppApiService appApiService;
-    /**
-     * 更新日志表--日表
-     * 每天凌晨1点执行一次
-     */
-    @Scheduled(cron = "0 0 1 * * ?")
-    //@Scheduled(fixedRate = 300000) // 5分钟执行一次
-    public void updateDayApiDayLog() throws ParseException {
-        System.out.println("===日表定时任务开始...");
-        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
-        Date date = new Date();
-        Calendar calendar = Calendar.getInstance();
-        calendar.setTime(date);
-        calendar.add(Calendar.DAY_OF_MONTH, -1);
-        date = (Date) calendar.getTime();
-        String day = df.format(date);
-        System.out.println("===日表定时任务日期..." + day);
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        Date beginDay = sdf.parse(day + " 00:00:00");
-        Date endDay = sdf.parse(day + " 23:59:59");
-        long begin = beginDay.getTime();
-        long end = endDay.getTime();
-        apiLogService.insertToDayTable(begin, end);
-
-        System.out.println("===日表定时任务结束...");
-    }
-
-    /**
-     * 更新日志表--时表
-     * 每天01点30分执行
-     */
-//    @Scheduled(cron = "0 30 01 * * ?")
-    @Scheduled(fixedRate = 3600000) // 1小时执行一次
-    public void updateDayApiHourLog() throws ParseException {
-        System.out.println("===时表定时任务开始...");
-        Date today = new Date();
-        SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd");
-        String day = formatDate.format(today);
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        Date beginDay = sdf.parse(day + " 00:00:00");
-        long begin = beginDay.getTime();
-        long end = begin + 3600000;
-        for (int i = 0; i < 24; i++) {
-            apiLogService.insertToHourTable(begin, end);
-            begin += 3600000;
-            end = begin + 3600000;
-        }
-        System.out.println("===时表定时任务结束...");
-    }
-
-//    @Scheduled(fixedRate = 86400000) // 1天执行一次
-    public void getAccessToken() {
-        //fixme, 使用 “演示应用” appid=11来测试
-       try
-       {
-           App app = appService.findAppById(45);
-           Map<String, Object> param = new HashMap<>();
-           param.put("grant_type", "client_credentials");
-           param.put("client_id", app.getApiKey());
-           param.put("client_secret", app.getSecretKey());
-           String url = String.format("%s/oauth/2.0/token", Config.BASE_HOST) ;
-           JSONObject json = new JSONObject(param);
-           String PostString = HttpUtils.doPostByJson(url, null, json);
-           System.out.println(PostString);
-           JSONObject object = JSONObject.parseObject(PostString);
-
-           String accessToken = object.getString("access_token");
-           System.out.println(accessToken);
-           DemoController.accessToken = accessToken;
-       }
-       catch (Exception ee)
-       {
-           ee.printStackTrace();
-       }
-    }
-
-    @Scheduled(fixedRate = 300000) // 5分钟执行一次
-    public void updateAppApiUsed() {
-        //每5分钟获取一次调用已使用量redis数据,同步到mysql
-        System.out.println("定时任务开启" + System.currentTimeMillis());
-        //获取有多少个key需要同步
-        List<AppApi> list = appApiService.listAll();
-        if(null != list && list.size() > 0) {
-            System.out.println("===total:" + list.size() + "need read value from redis!");
-            for(AppApi appApi : list) {
-                String key = "CALL_LIMIT_S:" + appApi.getApp().getId() + ":" +  appApi.getApi().getId();
-                System.out.println("key: " + key);
-                String value = stringRedisTemplate.opsForValue().get(key);
-                System.out.println("value: " + value);
-                appApi.setUsed(value);
-                appApiService.updateAppApi(appApi);
-            }
-        }
-        System.out.println("定时任务结束" + System.currentTimeMillis());
-    }
-
-
-    /**
-     * 更新到期日期的app状态
-     * 每天01点10分执行
-     */
-//    @Scheduled(cron = "0 1 0 * * ?")
-    //@Scheduled(fixedRate = 300000)
-    public void updateAppExpireStatus() throws ParseException {
-        System.out.println("===更新到期日期的app状态 定时任务开始...");
-        Calendar calendar = Calendar.getInstance();
-        calendar.add(Calendar.DATE, -1);
-        Date yesterday = calendar.getTime();
-        SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd");
-        String day = formatDate.format(yesterday);
-        List<App> apps = appService.listAppsByExpireDate(day);
-        if (null != apps && apps.size() > 0) {
-            for (App app : apps) {
-                app.setStatus(0);
-                appService.updateApp(app);
-            }
-        }
-        System.out.println("===更新到期日期的app状态 定时任务结束...");
-    }
-}
+//package com.ff.apimngr.task;
+//
+//
+//import java.text.ParseException;
+//import java.text.SimpleDateFormat;
+//import java.util.Calendar;
+//import java.util.Date;
+//import java.util.HashMap;
+//import java.util.List;
+//import java.util.Map;
+//
+//import javax.annotation.Resource;
+//
+//import org.springframework.context.annotation.Configuration;
+//import org.springframework.data.redis.core.StringRedisTemplate;
+//import org.springframework.scheduling.annotation.EnableScheduling;
+//import org.springframework.scheduling.annotation.Scheduled;
+//
+//import com.alibaba.fastjson.JSONObject;
+//import com.ff.apimngr.controller.DemoController;
+//import com.ff.apimngr.entity.App;
+//import com.ff.apimngr.entity.AppApi;
+//import com.ff.apimngr.service.ApiLogService;
+//import com.ff.apimngr.service.AppApiService;
+//import com.ff.apimngr.service.AppService;
+//import com.ff.apimngr.util.Config;
+//import com.ff.apimngr.util.HttpUtils;
+//
+//@Configuration
+//@EnableScheduling
+//public class ScheduleTask {
+//
+//    @Resource
+//    ApiLogService apiLogService;
+//
+//    @Resource
+//    AppService appService;
+//
+//    @Resource
+//    private StringRedisTemplate stringRedisTemplate;
+//
+//    @Resource
+//    AppApiService appApiService;
+//    /**
+//     * 更新日志表--日表
+//     * 每天凌晨1点执行一次
+//     */
+//    @Scheduled(cron = "0 0 1 * * ?")
+//    //@Scheduled(fixedRate = 300000) // 5分钟执行一次
+//    public void updateDayApiDayLog() throws ParseException {
+//        System.out.println("===日表定时任务开始...");
+//        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
+//        Date date = new Date();
+//        Calendar calendar = Calendar.getInstance();
+//        calendar.setTime(date);
+//        calendar.add(Calendar.DAY_OF_MONTH, -1);
+//        date = (Date) calendar.getTime();
+//        String day = df.format(date);
+//        System.out.println("===日表定时任务日期..." + day);
+//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+//        Date beginDay = sdf.parse(day + " 00:00:00");
+//        Date endDay = sdf.parse(day + " 23:59:59");
+//        long begin = beginDay.getTime();
+//        long end = endDay.getTime();
+//        apiLogService.insertToDayTable(begin, end);
+//
+//        System.out.println("===日表定时任务结束...");
+//    }
+//
+//    /**
+//     * 更新日志表--时表
+//     * 每天01点30分执行
+//     */
+////    @Scheduled(cron = "0 30 01 * * ?")
+//    @Scheduled(fixedRate = 3600000) // 1小时执行一次
+//    public void updateDayApiHourLog() throws ParseException {
+//        System.out.println("===时表定时任务开始...");
+//        Date today = new Date();
+//        SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd");
+//        String day = formatDate.format(today);
+//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+//        Date beginDay = sdf.parse(day + " 00:00:00");
+//        long begin = beginDay.getTime();
+//        long end = begin + 3600000;
+//        for (int i = 0; i < 24; i++) {
+//            apiLogService.insertToHourTable(begin, end);
+//            begin += 3600000;
+//            end = begin + 3600000;
+//        }
+//        System.out.println("===时表定时任务结束...");
+//    }
+//
+////    @Scheduled(fixedRate = 86400000) // 1天执行一次
+//    public void getAccessToken() {
+//        //fixme, 使用 “演示应用” appid=11来测试
+//       try
+//       {
+//           App app = appService.findAppById(45);
+//           Map<String, Object> param = new HashMap<>();
+//           param.put("grant_type", "client_credentials");
+//           param.put("client_id", app.getApiKey());
+//           param.put("client_secret", app.getSecretKey());
+//           String url = String.format("%s/oauth/2.0/token", Config.BASE_HOST) ;
+//           JSONObject json = new JSONObject(param);
+//           String PostString = HttpUtils.doPostByJson(url, null, json);
+//           System.out.println(PostString);
+//           JSONObject object = JSONObject.parseObject(PostString);
+//
+//           String accessToken = object.getString("access_token");
+//           System.out.println(accessToken);
+//           DemoController.accessToken = accessToken;
+//       }
+//       catch (Exception ee)
+//       {
+//           ee.printStackTrace();
+//       }
+//    }
+//
+//    @Scheduled(fixedRate = 300000) // 5分钟执行一次
+//    public void updateAppApiUsed() {
+//        //每5分钟获取一次调用已使用量redis数据,同步到mysql
+//        System.out.println("定时任务开启" + System.currentTimeMillis());
+//        //获取有多少个key需要同步
+//        List<AppApi> list = appApiService.listAll();
+//        if(null != list && list.size() > 0) {
+//            System.out.println("===total:" + list.size() + "need read value from redis!");
+//            for(AppApi appApi : list) {
+//                String key = "CALL_LIMIT_S:" + appApi.getApp().getId() + ":" +  appApi.getApi().getId();
+//                System.out.println("key: " + key);
+//                String value = stringRedisTemplate.opsForValue().get(key);
+//                System.out.println("value: " + value);
+//                appApi.setUsed(value);
+//                appApiService.updateAppApi(appApi);
+//            }
+//        }
+//        System.out.println("定时任务结束" + System.currentTimeMillis());
+//    }
+//
+//
+//    /**
+//     * 更新到期日期的app状态
+//     * 每天01点10分执行
+//     */
+////    @Scheduled(cron = "0 1 0 * * ?")
+//    //@Scheduled(fixedRate = 300000)
+//    public void updateAppExpireStatus() throws ParseException {
+//        System.out.println("===更新到期日期的app状态 定时任务开始...");
+//        Calendar calendar = Calendar.getInstance();
+//        calendar.add(Calendar.DATE, -1);
+//        Date yesterday = calendar.getTime();
+//        SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd");
+//        String day = formatDate.format(yesterday);
+//        List<App> apps = appService.listAppsByExpireDate(day);
+//        if (null != apps && apps.size() > 0) {
+//            for (App app : apps) {
+//                app.setStatus(0);
+//                appService.updateApp(app);
+//            }
+//        }
+//        System.out.println("===更新到期日期的app状态 定时任务结束...");
+//    }
+//}

+ 2 - 1
src/main/java/com/ff/apimngr/util/RedisUtil.java

@@ -1,5 +1,6 @@
 package com.ff.apimngr.util;
 
+import cn.hutool.core.collection.CollectionUtil;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
@@ -104,7 +105,7 @@ public final class RedisUtil {
             if (key.length == 1) {
                 redisTemplate.delete(key[0]);
             } else {
-                redisTemplate.delete(CollectionUtils.arrayToList(key));
+                redisTemplate.delete(CollectionUtil.toList(key));
             }
         }
     }

+ 1 - 1
src/main/resources/application-dev.properties

@@ -38,7 +38,7 @@ spring.servlet.multipart.max-file-size=10MB
 spring.servlet.multipart.max-request-size=100MB
 
 #mybatis log
-#logging.level.com.ff.apimngr.dao=debug
+logging.level.com.ff.apimngr.dao=debug
 
 spring.redis.host=125.77.165.122
 spring.redis.password=Platomix@redis123

+ 0 - 7
src/main/resources/application-docker.properties

@@ -1,10 +1,3 @@
-server.port = 8081
-
-#spring.datasource.druid.one.url=jdbc:mysql://127.0.0.1/apimngr?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&useSSL=true
-#spring.datasource.druid.one.username=root
-#spring.datasource.druid.one.password=123456
-#spring.datasource.druid.one.driver-class-name=com.mysql.jdbc.Driver
-
 #druid
 spring.datasource.dynamic.druid.initialSize=5
 spring.datasource.dynamic.druid.minIdle=5

+ 2 - 11
src/main/resources/application-test.properties

@@ -1,12 +1,3 @@
-server.port = 7272
-
-#spring.datasource.druid.one.url=jdbc:mysql://127.0.0.1/apimngr?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&useSSL=true
-#spring.datasource.druid.one.username=root
-#spring.datasource.druid.one.password=123456
-#spring.datasource.druid.one.driver-class-name=com.mysql.jdbc.Driver
-
-#spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
-
 #druid
 spring.datasource.dynamic.druid.initialSize=5
 spring.datasource.dynamic.druid.minIdle=5
@@ -47,9 +38,9 @@ spring.servlet.multipart.max-request-size=100MB
 #logging.level.com.ff.apimngr.dao=info
 
 ## Redis
-spring.redis.host=125.77.165.122
+spring.redis.host=127.0.0.1
 spring.redis.password=Platomix@redis123
-spring.redis.port=4379
+spring.redis.port=6379
 spring.redis.timeout=10000
 spring.redis.database=0
 spring.redis.lettuce.pool.max-active=8

+ 3 - 3
src/main/resources/application.properties

@@ -1,5 +1,5 @@
-server.port = 7272
+server.port=7272
 
-spring.application.name = gmetry-bi
+spring.application.name=gmetry-api
 
-spring.profiles.active = test
+spring.profiles.active=dev

+ 16 - 16
src/test/java/com/ff/apimngr/ApimngrApplicationTests.java

@@ -1,16 +1,16 @@
-package com.ff.apimngr;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.junit4.SpringRunner;
-
-//@RunWith(SpringRunner.class)
-//@SpringBootTest
-public class ApimngrApplicationTests {
-
-    @Test
-    public void contextLoads() {
-    }
-
-}
+//package com.ff.apimngr;
+//
+//import org.junit.Test;
+//import org.junit.runner.RunWith;
+//import org.springframework.boot.test.context.SpringBootTest;
+//import org.springframework.test.context.junit4.SpringRunner;
+//
+////@RunWith(SpringRunner.class)
+////@SpringBootTest
+//public class ApimngrApplicationTests {
+//
+//    @Test
+//    public void contextLoads() {
+//    }
+//
+//}