Ver Fonte

Merge remote-tracking branch 'origin/dev' into feature-smsLogin-wangmh

wangmh há 7 anos atrás
pai
commit
cce9c1b34e

+ 22 - 0
sso-common/src/main/java/com/uas/sso/util/AccountUtils.java

@@ -1312,4 +1312,26 @@ public class AccountUtils {
         }
         return null;
     }
+
+    public static Map<String, Object> getUserInfo(Long userUU, Long spaceUU) throws Exception {
+        String url = AccountConfig.getUserSaveUrl();
+        if (!StringUtils.isEmpty(url)) {
+            url = url + "/info/userUU";
+            ModelMap data = new ModelMap();
+            data.put("userUU", userUU);
+            data.put("spaceUU", spaceUU);
+            HttpUtil.ResponseWrap res = HttpUtil.doGet(url, data);
+            if (!res.isSuccess()) {
+                throw new Exception(res.getContent());
+            } else {
+                ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
+                if (!result.isSuccess()) {
+                    throw new Exception(result.getErrMsg());
+                } else if (result.getContent() != null) {
+                    return JSON.parseObject(result.getContent().toString());
+                }
+            }
+        }
+        return null;
+    }
 }

+ 1 - 1
sso-server/src/main/java/com/uas/sso/controller/PersonalRegisterController.java

@@ -87,7 +87,7 @@ public class PersonalRegisterController extends BaseController {
         }
 
         // 注册并添加注册日志
-        user.setFromApp(StringUtils.isEmpty(appId) ? "sso" : appId);
+        appId = StringUtils.isEmpty(appId) ? "sso" : appId;
         user = userService.register(user, appId);
         registerLogger.info(Type.REGISTER_PERSONAL.getValue(), Step.FIRST.getValue(), "个人注册成功", user, user.getFromApp());
 

+ 51 - 19
sso-server/src/main/java/com/uas/sso/controller/UserManagerController.java

@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.*;
 
 import java.io.*;
 import java.text.SimpleDateFormat;
-import java.util.Calendar;
+import java.util.Arrays;
 import java.util.Date;
 import java.util.Set;
 
@@ -323,7 +323,7 @@ public class UserManagerController extends BaseController {
      * @return
      */
     @RequestMapping(value = "/sysUserdata/uuzc", method = RequestMethod.POST)
-    public ModelMap uuzcRegister(User user) {
+    public ModelMap uuzcRegister(User user, @RequestParam String appId) {
         // 校验手机号
         checkMobile(user.getMobile(), null);
 
@@ -342,7 +342,7 @@ public class UserManagerController extends BaseController {
 
         // 传来的值可能带有uu号,去除uu号
         user.setUserUU(null);
-        user = userService.register(user, "uuzc");
+        user = userService.register(user, appId);
         return success(user.getUserUU());
     }
 
@@ -429,8 +429,8 @@ public class UserManagerController extends BaseController {
      * 优软云个人用户注册总数
      */
     @RequestMapping(value = "/count", method = RequestMethod.GET)
-    public ModelMap getUserCount() {
-        return new ModelMap("count", userService.getCount());
+    public ModelMap count() {
+        return new ModelMap("count", userService.count());
     }
 
     /**
@@ -438,13 +438,8 @@ public class UserManagerController extends BaseController {
      * @return
      */
     @RequestMapping(value = "/currentMonth/count", method = RequestMethod.GET)
-    public ModelMap getCurrentMonthUserCount() {
-        Calendar start = Calendar.getInstance();
-        start.setTime(new Date());
-        start.set(start.get(Calendar.YEAR), start.get(Calendar.MONTH), 1, 0, 0, 0);
-        Calendar end = Calendar.getInstance();
-        end.set(start.get(Calendar.YEAR), start.get(Calendar.MONTH) + 1, 1, 0, 0, 0);
-        return new ModelMap("count", userService.getCountByRegisterDate(start, end));
+    public ModelMap countInCurrentMonth() {
+        return new ModelMap("count",  userService.countInCurrentMonth());
     }
 
     /**
@@ -452,12 +447,49 @@ public class UserManagerController extends BaseController {
      * @return
      */
     @RequestMapping(value = "/lastMonth/count", method = RequestMethod.GET)
-    public ModelMap getLastMonthUserCount() {
-        Calendar start = Calendar.getInstance();
-        start.setTime(new Date());
-        start.set(start.get(Calendar.YEAR), start.get(Calendar.MONTH) - 1, 1, 0, 0, 0);
-        Calendar end = Calendar.getInstance();
-        end.set(start.get(Calendar.YEAR), start.get(Calendar.MONTH) + 1, 1, 0, 0, 0);
-        return new ModelMap("count", userService.getCountByRegisterDate(start, end));
+    public ModelMap countInLastMonth() {
+        return new ModelMap("count",  userService.countInLastMonth());
+    }
+
+    /**
+     * 获取本周用户注册数量
+     * @return
+     */
+    @RequestMapping(value = "/currentWeek/count", method = RequestMethod.GET)
+    public ModelMap countInCurrentWeek() {
+        return new ModelMap("count",  userService.countInCurrentWeek());
+    }
+
+    /**
+     * 获取指定应用注册数量
+     * @param fromApps 应用id,逗号分隔
+     * @return
+     */
+    @RequestMapping(value = "/count/app", method = RequestMethod.GET)
+    public ModelMap count(String fromApps) {
+        String[] apps = fromApps.split(",");
+        return success(userService.count(Arrays.asList(apps)));
+    }
+
+    /**
+     * 获取指定应用本月注册数量
+     * @param fromApps 应用id,逗号分隔
+     * @return
+     */
+    @RequestMapping(value = "/currentMonth/count/app", method = RequestMethod.GET)
+    public ModelMap countInCurrentMonth(String fromApps) {
+        String[] apps = fromApps.split(",");
+        return success(userService.countInCurrentMonth(Arrays.asList(apps)));
+    }
+
+    /**
+     * 获取指定应用本周注册数量
+     * @param fromApps 应用id,逗号分隔
+     * @return
+     */
+    @RequestMapping(value = "/currentWeek/count/app", method = RequestMethod.GET)
+    public ModelMap countInCurrentWeek(String fromApps) {
+        String[] apps = fromApps.split(",");
+        return success(userService.countInCurrentWeek(Arrays.asList(apps)));
     }
 }

+ 15 - 16
sso-server/src/main/java/com/uas/sso/controller/UserspaceManagerController.java

@@ -402,8 +402,8 @@ public class UserspaceManagerController extends BaseController {
      * 企业信息库总数
      */
     @RequestMapping(value = "/count", method = RequestMethod.GET)
-    public ModelMap getEnterpriseCount() {
-        return new ModelMap("count", userspaceService.getCount());
+    public ModelMap count() {
+        return new ModelMap("count", userspaceService.count());
     }
 
     /**
@@ -411,13 +411,8 @@ public class UserspaceManagerController extends BaseController {
      * @return
      */
     @RequestMapping(value = "/currentMonth/count", method = RequestMethod.GET)
-    public ModelMap getCurrentMonthCount() {
-        Calendar start = Calendar.getInstance();
-        start.setTime(new Date());
-        start.set(start.get(Calendar.YEAR), start.get(Calendar.MONTH), 1, 0, 0, 0);
-        Calendar end = Calendar.getInstance();
-        end.set(start.get(Calendar.YEAR), start.get(Calendar.MONTH) + 1, 1, 0, 0, 0);
-        return new ModelMap("count", userspaceService.getCountByRegisterDate(start, end));
+    public ModelMap countInCurrentMonth() {
+        return new ModelMap("count", userspaceService.countInCurrentMonth());
     }
 
     /**
@@ -425,13 +420,17 @@ public class UserspaceManagerController extends BaseController {
      * @return
      */
     @RequestMapping(value = "/lastMonth/count", method = RequestMethod.GET)
-    public ModelMap getLastMonthEnterpriseCount() {
-        Calendar start = Calendar.getInstance();
-        start.setTime(new Date());
-        start.set(start.get(Calendar.YEAR), start.get(Calendar.MONTH) - 1, 1, 0, 0, 0);
-        Calendar end = Calendar.getInstance();
-        end.set(start.get(Calendar.YEAR), start.get(Calendar.MONTH) + 1, 1, 0, 0, 0);
-        return new ModelMap("count", userspaceService.getCountByRegisterDate(start, end));
+    public ModelMap countInLastMonth() {
+        return new ModelMap("count", userspaceService.countInLastMonth());
+    }
+
+    /**
+     * 获取上个月企业注册数量
+     * @return
+     */
+    @RequestMapping(value = "/currentWeek/count", method = RequestMethod.GET)
+    public ModelMap countInCurrentWeek() {
+        return new ModelMap("count", userspaceService.countInCurrentWeek());
     }
 
 }

+ 20 - 0
sso-server/src/main/java/com/uas/sso/dao/UserDao.java

@@ -7,7 +7,9 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.repository.query.Param;
 
+import java.sql.Timestamp;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 用户信息dao
@@ -106,4 +108,22 @@ public interface UserDao extends JpaRepository<User, Long>, JpaSpecificationExec
      */
     @Query("select u from User u where u.mobile in :tels")
     List<User> findUsersByTels(@Param("tels") List<String> tels);
+
+    /**
+     * 获取指定应用指定时间用户注册量
+     * @param start 开始时间
+     * @param end 结束时间
+     * @param fromApps 应用集合
+     * @return
+     */
+    @Query("select u.fromApp as appId , count(u) as count from User u where u.fromApp in ?3 and u.registerDate between ?1 and ?2 group by u.fromApp")
+    List<Map<String, Object>> getCountByRegisterDate(Timestamp start, Timestamp end, List<String> fromApps);
+
+    /**
+     * 获取指定应用所有用户注册量
+     * @param fromApps 应用集合
+     * @return
+     */
+    @Query("select u.fromApp as appId , count(u) as count from User u where u.fromApp in ?1 group by u.fromApp")
+    List<Map<String,Object>> getCountByRegisterDate(List<String> fromApps);
 }

+ 19 - 0
sso-server/src/main/java/com/uas/sso/i/CountCallBack.java

@@ -0,0 +1,19 @@
+package com.uas.sso.i;
+
+import java.util.Calendar;
+
+/**
+ * @author wangmh
+ * @create 2018-06-13 10:15
+ * @desc 统计接口
+ **/
+public interface CountCallBack<T> {
+
+    /**
+     * 接口回调,根据时间统计
+     * @return
+     * @param start 开始时间
+     * @param end 结束时间
+     */
+    T countByTime(Calendar start, Calendar end);
+}

+ 53 - 2
sso-server/src/main/java/com/uas/sso/service/UserService.java

@@ -6,8 +6,10 @@ import com.uas.sso.entity.UserRecord;
 import com.uas.sso.entity.UserSpaceDetailInfo;
 import org.springframework.data.domain.Page;
 
+import java.sql.Timestamp;
 import java.util.Calendar;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 用户信息service
@@ -259,7 +261,7 @@ public interface UserService {
      * 获取用户数量
      * @return
      */
-    long getCount();
+    long count();
 
     /**
      * 统计某个时间段注册数量
@@ -267,5 +269,54 @@ public interface UserService {
      * @param end 结束时间
      * @return
      */
-    long getCountByRegisterDate(Calendar start, Calendar end);
+    long countByRegisterDate(Calendar start, Calendar end);
+
+    /**
+     * 统计某个时间段指定应用注册数量
+     * @param start 开始时间
+     * @param end 结束时间
+     * @param fromApps 指定应用集合
+     * @return
+     */
+    Map<String, Long> countByRegisterDate(Timestamp start, Timestamp end, List<String> fromApps);
+
+    /**
+     * 获取当前月注册数量
+     * @return
+     */
+    long countInCurrentMonth();
+
+    /**
+     * 获取上个月注册数量
+     * @return
+     */
+    long countInLastMonth();
+
+    /**
+     * 获取本周注册数量
+     * @return
+     */
+    long countInCurrentWeek();
+
+    /**
+     * 获取指定应用注册量
+     * @param fromApps 应用id集合
+     * @return key: appId, value: count
+     */
+    Map<String, Long> count(List<String> fromApps);
+
+    /**
+     * 获取指定应用本月注册量
+     * @param fromApps 应用id集合
+     * @return key: appId, value: count
+     */
+    Map<String, Long> countInCurrentMonth(List<String> fromApps);
+
+    /**
+     * 获取指定应用本周注册量
+     * @param fromApps 应用id集合
+     * @return key: appId, value: count
+     */
+    Map<String, Long> countInCurrentWeek(List<String> fromApps);
+
 }

+ 19 - 1
sso-server/src/main/java/com/uas/sso/service/UserspaceService.java

@@ -169,7 +169,7 @@ public interface UserspaceService {
      * 获取企业数量
      * @return
      */
-    long getCount();
+    long count();
 
     /**
      * 根据注册时间统计企业注册数量
@@ -178,4 +178,22 @@ public interface UserspaceService {
      * @return
      */
     long getCountByRegisterDate(Calendar start, Calendar end);
+
+    /**
+     * 获取当前月企业注册量
+     * @return
+     */
+    long countInCurrentMonth();
+
+    /**
+     * 获取上个月企业注册量
+     * @return
+     */
+    long countInLastMonth();
+
+    /**
+     * 获取本周
+     * @return
+     */
+    long countInCurrentWeek();
 }

+ 79 - 4
sso-server/src/main/java/com/uas/sso/service/impl/UserServiceImpl.java

@@ -5,20 +5,20 @@ import com.alibaba.fastjson.JSONObject;
 import com.uas.sso.common.encrypt.MD5;
 import com.uas.sso.common.util.HttpUtil;
 import com.uas.sso.core.Const;
-import com.uas.sso.core.ICallable;
 import com.uas.sso.core.Status;
 import com.uas.sso.core.Type;
 import com.uas.sso.dao.UserDao;
 import com.uas.sso.dao.UserRecordDao;
 import com.uas.sso.entity.*;
 import com.uas.sso.exception.VisibleError;
+import com.uas.sso.i.CountCallBack;
 import com.uas.sso.logging.LoggerManager;
 import com.uas.sso.logging.SyncBufferedLogger;
 import com.uas.sso.logging.UserBufferedLogger;
 import com.uas.sso.service.*;
 import com.uas.sso.support.SyncFail;
 import com.uas.sso.util.AccountTypeUtils;
-import com.uas.sso.util.ExecuteUtils;
+import com.uas.sso.util.CountUtils;
 import com.uas.sso.util.PasswordLevelUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
@@ -604,12 +604,12 @@ public class UserServiceImpl implements UserService {
     }
 
     @Override
-    public long getCount() {
+    public long count() {
         return userDao.count();
     }
 
     @Override
-    public long getCountByRegisterDate(final Calendar start, final Calendar end) {
+    public long countByRegisterDate(final Calendar start, final Calendar end) {
         return userDao.count(new Specification<User>() {
             @Override
             public Predicate toPredicate(Root<User> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
@@ -620,6 +620,81 @@ public class UserServiceImpl implements UserService {
         });
     }
 
+    @Override
+    public Map<String, Long> countByRegisterDate(Timestamp start, Timestamp end, List<String> fromApps) {
+        Map<String, Long> data = new HashMap<>();
+        List<Map<String, Object>> counts = userDao.getCountByRegisterDate(start, end, fromApps);
+        for (Map<String, Object> count : counts) {
+            data.put((String) count.get("appId"), (Long) count.get("count"));
+        }
+        return data;
+    }
+
+    @Override
+    public long countInCurrentMonth() {
+        return CountUtils.countInCurrentMonth(new CountCallBack<Long>() {
+
+            @Override
+            public Long countByTime(Calendar start, Calendar end) {
+                return countByRegisterDate(start, end);
+            }
+        });
+    }
+
+    @Override
+    public long countInLastMonth() {
+        return CountUtils.countInLastMonth(new CountCallBack<Long>() {
+
+            @Override
+            public Long countByTime(Calendar start, Calendar end) {
+                return countByRegisterDate(start, end);
+            }
+        });
+    }
+
+    @Override
+    public long countInCurrentWeek() {
+        return CountUtils.countInCurrentWeek(new CountCallBack<Long>() {
+
+            @Override
+            public Long countByTime(Calendar start, Calendar end) {
+                return countByRegisterDate(start, end);
+            }
+        });
+    }
+
+    @Override
+    public Map<String, Long> count(final List<String> fromApps) {
+        Map<String, Long> data = new HashMap<>();
+        List<Map<String, Object>> counts = userDao.getCountByRegisterDate(fromApps);
+        for (Map<String, Object> count : counts) {
+            data.put((String) count.get("appId"), (Long) count.get("count"));
+        }
+        return data;
+    }
+
+    @Override
+    public Map<String, Long> countInCurrentMonth(final List<String> fromApps) {
+        return CountUtils.countInCurrentMonth(new CountCallBack<Map<String, Long>>() {
+
+            @Override
+            public Map<String, Long> countByTime(Calendar start, Calendar end) {
+                return countByRegisterDate(new Timestamp(start.getTimeInMillis()), new Timestamp(end.getTimeInMillis()), fromApps);
+            }
+        });
+    }
+
+    @Override
+    public Map<String, Long> countInCurrentWeek(final List<String> fromApps) {
+        return CountUtils.countInCurrentWeek(new CountCallBack<Map<String, Long>>() {
+
+            @Override
+            public Map<String, Long> countByTime(Calendar start, Calendar end) {
+                return countByRegisterDate(new Timestamp(start.getTimeInMillis()), new Timestamp(end.getTimeInMillis()), fromApps);
+            }
+        });
+    }
+
     /**
      * 同步用户信息到各个应用
      * @param user 用户信息

+ 34 - 1
sso-server/src/main/java/com/uas/sso/service/impl/UserspaceServiceImpl.java

@@ -7,11 +7,13 @@ import com.uas.sso.core.Status;
 import com.uas.sso.dao.UserspaceDao;
 import com.uas.sso.entity.*;
 import com.uas.sso.exception.VisibleError;
+import com.uas.sso.i.CountCallBack;
 import com.uas.sso.logging.LoggerManager;
 import com.uas.sso.logging.SyncBufferedLogger;
 import com.uas.sso.service.*;
 import com.uas.sso.support.SyncFail;
 import com.uas.sso.util.ChineseUtils;
+import com.uas.sso.util.CountUtils;
 import com.uas.sso.util.StringUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
@@ -389,7 +391,7 @@ public class UserspaceServiceImpl implements UserspaceService {
     }
 
     @Override
-    public long getCount() {
+    public long count() {
         return userspaceDao.count();
     }
 
@@ -404,4 +406,35 @@ public class UserspaceServiceImpl implements UserspaceService {
             }
         });
     }
+
+    @Override
+    public long countInCurrentMonth() {
+        return CountUtils.countInCurrentMonth(new CountCallBack<Long>() {
+            @Override
+            public Long countByTime(Calendar start, Calendar end) {
+                return getCountByRegisterDate(start, end);
+            }
+        });
+    }
+
+    @Override
+    public long countInLastMonth() {
+        return CountUtils.countInLastMonth(new CountCallBack<Long>() {
+            @Override
+            public Long countByTime(Calendar start, Calendar end) {
+                return getCountByRegisterDate(start, end);
+            }
+        });
+    }
+
+    @Override
+    public long countInCurrentWeek() {
+        return CountUtils.countInCurrentWeek(new CountCallBack<Long>() {
+            @Override
+            public Long countByTime(Calendar start, Calendar end) {
+                return getCountByRegisterDate(start, end);
+            }
+        });
+    }
+
 }

+ 66 - 0
sso-server/src/main/java/com/uas/sso/util/CountUtils.java

@@ -0,0 +1,66 @@
+package com.uas.sso.util;
+
+import com.uas.sso.exception.VisibleError;
+import com.uas.sso.i.CountCallBack;
+
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ * @author wangmh
+ * @create 2018-06-13 10:13
+ * @desc 统计工具类
+ **/
+public class CountUtils {
+
+    /**
+     * 获取当前月的数量
+     * @param countCallBack 用于给调用者自定义统计方法
+     * @return
+     */
+    public static <T> T countInCurrentMonth(CountCallBack<T> countCallBack) {
+        Calendar start = Calendar.getInstance();
+        start.setTime(new Date());
+        start.set(start.get(Calendar.YEAR), start.get(Calendar.MONTH), 1, 0, 0, 0);
+        Calendar end = Calendar.getInstance();
+        end.set(start.get(Calendar.YEAR), start.get(Calendar.MONTH) + 1, 1, 0, 0, 0);
+        return countCallBack.countByTime(start, end);
+    }
+
+    /**
+     * 获取上个月的数量
+     * @param countCallBack 用于给调用者自定义统计方法
+     * @return
+     */
+    public static <T> T countInLastMonth(CountCallBack<T> countCallBack) {
+        Calendar start = Calendar.getInstance();
+        start.setTime(new Date());
+        start.set(start.get(Calendar.YEAR), start.get(Calendar.MONTH) - 1, 1, 0, 0, 0);
+        Calendar end = Calendar.getInstance();
+        end.set(start.get(Calendar.YEAR), start.get(Calendar.MONTH) + 1, 1, 0, 0, 0);
+        return countCallBack.countByTime(start, end);
+    }
+
+    /**
+     * 获取上个月的数量
+     * @param countCallBack 用于给调用者自定义统计方法
+     * @return
+     */
+    public static <T> T countInCurrentWeek(CountCallBack<T> countCallBack) {
+        Date date = new Date();
+        if (date == null) {
+            throw new VisibleError("获取当前时间失败");
+        }
+        Calendar start = Calendar.getInstance();
+        start.setTime(date);
+        int dayofweek = start.get(Calendar.DAY_OF_WEEK);
+        if (dayofweek == 1) {
+            dayofweek += 7;
+        }
+        start.add(Calendar.DATE, 2 - dayofweek);
+        Calendar end = Calendar.getInstance();
+        end.setTime(start.getTime());
+        end.add(Calendar.DAY_OF_WEEK, 6);
+        return countCallBack.countByTime(start, end);
+    }
+}

+ 2 - 1
sso-server/src/main/resources/dev/account.properties

@@ -4,7 +4,8 @@ sso.app=sso
 sso.secretkey=0taQcW073Z7G628g5H
 #sso.cookie.domain=ubtob.com
 sso.cookie.secure=false
-sso.front.url=http://192.168.253.118:3001
+sso.cookie.browser=false
+sso.front.url=http://192.168.253.6:32323
 
 ### crossdomain verify
 sso.authcookie.secretkey=Z318866alN6gA0piuO

+ 1 - 0
sso-server/src/main/resources/prod/account.properties

@@ -4,6 +4,7 @@ sso.app=sso
 sso.secretkey=0taQcW073Z7G628g5H
 sso.cookie.domain=ubtob.com
 sso.cookie.secure=false
+sso.cookie.browser=false
 sso.front.url=https://sso.ubtob.com,http://10.10.100.133:9990
 
 ### crossdomain verify

+ 1 - 0
sso-server/src/main/resources/test/account.properties

@@ -4,6 +4,7 @@ sso.app=sso
 sso.secretkey=0taQcW073Z7G628g5H
 #sso.cookie.domain=ubtob.com
 sso.cookie.secure=false
+sso.cookie.browser=false
 sso.front.url=http://192.168.253.12:32323
 
 ### crossdomain verify