Browse Source

添加统计用户企业注册数量接口

wangmh 7 years ago
parent
commit
b07f6ec6b2

File diff suppressed because it is too large
+ 0 - 51
sso-common/src/test/java/test/Test.java


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

@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.*;
 
 import java.io.*;
 import java.text.SimpleDateFormat;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.Set;
 
@@ -397,7 +398,7 @@ public class UserManagerController extends BaseController {
     }
 
     /**
-     * 根据企业uu号和用户uu号获取用户和企业信息
+     * (消息)根据企业uu号和用户uu号获取用户和企业信息
      * @param userUU 用户uu号
      * @param spaceUU 企业uu号
      * @return
@@ -424,4 +425,39 @@ public class UserManagerController extends BaseController {
         return success(data);
     }
 
+    /**
+     * 优软云个人用户注册总数
+     */
+    @RequestMapping(value = "/count", method = RequestMethod.GET)
+    public long getUserCount() {
+        return userService.getPersonalUserCount();
+    }
+
+    /**
+     * 获取本月用户注册数量
+     * @return
+     */
+    @RequestMapping(value = "/currentMonth/user/count", method = RequestMethod.GET)
+    public long 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();
+        start.set(start.get(Calendar.YEAR), start.get(Calendar.MONTH) + 1, 1, 0, 0, 0);
+        return userService.getCountByRegisterDate(start, end);
+    }
+
+    /**
+     * 获取上个月用户注册数量
+     * @return
+     */
+    @RequestMapping(value = "/lastMonth/user/count", method = RequestMethod.GET)
+    public long 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();
+        start.set(start.get(Calendar.YEAR), start.get(Calendar.MONTH), 1, 0, 0, 0);
+        return userService.getCountByRegisterDate(start, end);
+    }
 }

+ 37 - 0
sso-server/src/main/java/com/uas/sso/controller/UserspaceManagerController.java

@@ -397,4 +397,41 @@ public class UserspaceManagerController extends BaseController {
         applyUserSpaceService.auditApply(userUU, id, status);
         return success();
     }
+
+    /**
+     * 企业信息库总数
+     */
+    @RequestMapping(value = "/count", method = RequestMethod.GET)
+    public long getEnterpriseCount() {
+        return userspaceService.getCount();
+    }
+
+    /**
+     * 获取本月企业注册数量
+     * @return
+     */
+    @RequestMapping(value = "/currentMonth/count", method = RequestMethod.GET)
+    public long 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();
+        start.set(start.get(Calendar.YEAR), start.get(Calendar.MONTH) + 1, 1, 0, 0, 0);
+        return userspaceService.getCountByRegisterDate(start, end);
+    }
+
+    /**
+     * 获取上个月企业注册数量
+     * @return
+     */
+    @RequestMapping(value = "/lastMonth/enterprise/count", method = RequestMethod.GET)
+    public long 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();
+        start.set(start.get(Calendar.YEAR), start.get(Calendar.MONTH), 1, 0, 0, 0);
+        return userspaceService.getCountByRegisterDate(start, end);
+    }
+
 }

+ 15 - 0
sso-server/src/main/java/com/uas/sso/service/UserService.java

@@ -6,6 +6,7 @@ import com.uas.sso.entity.UserRecord;
 import com.uas.sso.entity.UserSpaceDetailInfo;
 import org.springframework.data.domain.Page;
 
+import java.util.Calendar;
 import java.util.List;
 
 /**
@@ -252,4 +253,18 @@ public interface UserService {
      * @return
      */
     User updateUser(Long userUU, User userView);
+
+    /**
+     * 获取用户数量
+     * @return
+     */
+    long getPersonalUserCount();
+
+    /**
+     * 统计某个时间段注册数量
+     * @param start 开始时间
+     * @param end 结束时间
+     * @return
+     */
+    long getCountByRegisterDate(Calendar start, Calendar end);
 }

+ 15 - 0
sso-server/src/main/java/com/uas/sso/service/UserspaceService.java

@@ -4,6 +4,7 @@ import com.uas.sso.entity.User;
 import com.uas.sso.entity.Userspace;
 import org.springframework.data.domain.Page;
 
+import java.util.Calendar;
 import java.util.List;
 
 /**
@@ -163,4 +164,18 @@ public interface UserspaceService {
      * @return
      */
     Page<Userspace> findByKeyword(String keyword, int pageNumber, int pageSize);
+
+    /**
+     * 获取企业数量
+     * @return
+     */
+    long getCount();
+
+    /**
+     * 根据注册时间统计企业注册数量
+     * @param start
+     * @param end
+     * @return
+     */
+    long getCountByRegisterDate(Calendar start, Calendar end);
 }

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

@@ -32,10 +32,7 @@ import org.springframework.util.StringUtils;
 import javax.persistence.criteria.*;
 import javax.validation.constraints.NotNull;
 import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 
 
 /**
@@ -600,6 +597,23 @@ public class UserServiceImpl implements UserService {
         return oldUser;
     }
 
+    @Override
+    public long getPersonalUserCount() {
+        return userDao.count();
+    }
+
+    @Override
+    public long getCountByRegisterDate(final Calendar start, final Calendar end) {
+        return userDao.count(new Specification<User>() {
+            @Override
+            public Predicate toPredicate(Root<User> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
+                Predicate predicate = cb.between(root.get("registerDate").as(Calendar.class), start, end);
+                query.where(predicate);
+                return null;
+            }
+        });
+    }
+
     /**
      * 同步用户信息到各个应用
      * @param userUU 用户uu号

+ 17 - 2
sso-server/src/main/java/com/uas/sso/service/impl/UserspaceServiceImpl.java

@@ -27,8 +27,6 @@ import javax.persistence.criteria.*;
 import java.sql.Timestamp;
 import java.util.*;
 
-import static antlr.build.ANTLR.root;
-
 /**
  * 企业信息service层
  *
@@ -370,4 +368,21 @@ public class UserspaceServiceImpl implements UserspaceService {
         }, pageable);
         return new PageInfo<Userspace>(page.getContent(), pageable, page.getTotalElements());
     }
+
+    @Override
+    public long getCount() {
+        return userspaceDao.count();
+    }
+
+    @Override
+    public long getCountByRegisterDate(final Calendar start, final Calendar end) {
+        return userspaceDao.count(new Specification<Userspace>() {
+            @Override
+            public Predicate toPredicate(Root<Userspace> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
+                Predicate predicate = cb.between(root.get("registerDate").as(Calendar.class), start, end);
+                query.where(predicate);
+                return null;
+            }
+        });
+    }
 }

Some files were not shown because too many files changed in this diff