TRX před 1 rokem
rodič
revize
d10b84ded6

+ 4 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/orgModel/OrgBindUserAllParam.java

@@ -1,5 +1,6 @@
 package com.zhongshu.card.client.model.orgModel;
 
+import com.zhongshu.card.client.type.Sex;
 import com.zhongshu.card.client.type.UserState;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.AllArgsConstructor;
@@ -31,6 +32,9 @@ public class OrgBindUserAllParam {
     @Schema(description = "工号-学号")
     private String code;
 
+    @Schema(description = "性别")
+    private Sex sex;
+
     @Schema(description = "职位")
     private String positionId;
 

+ 39 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/userStatistics/PlatformUserStatisModel.java

@@ -0,0 +1,39 @@
+package com.zhongshu.card.client.model.userStatistics;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.math.BigDecimal;
+
+/**
+ * 平台用户统计
+ *
+ * @author TRX
+ * @date 2024/12/11
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class PlatformUserStatisModel {
+
+    @Schema(description = "总数")
+    private Long total = 0l;
+
+    @Schema(description = "男")
+    private Long manTotal = 0l;
+
+    @Schema(description = "男士比例")
+    private BigDecimal manScale = BigDecimal.ZERO;
+
+    @Schema(description = "女")
+    private Long womanTotal = 0l;
+
+    @Schema(description = "女士比例")
+    private BigDecimal womanScale = BigDecimal.ZERO;
+
+    @Schema(description = "未设置性别的")
+    private Long unSetTotal = 0l;
+
+}

+ 38 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/user/UserStatisticsController.java

@@ -0,0 +1,38 @@
+package com.zhongshu.card.server.core.controller.user;
+
+import com.github.microservice.auth.security.annotations.ResourceAuth;
+import com.github.microservice.auth.security.helper.AuthHelper;
+import com.github.microservice.auth.security.type.AuthType;
+import com.github.microservice.net.ResultContent;
+import com.zhongshu.card.client.model.userStatistics.PlatformUserStatisModel;
+import com.zhongshu.card.server.core.service.userStatistics.UserStatisticsService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author TRX
+ * @date 2024/6/4
+ */
+@RestController
+@RequestMapping("userStatistics")
+@Tag(name = "用户统计")
+public class UserStatisticsController {
+
+    @Autowired
+    private AuthHelper authHelper;
+
+    @Autowired
+    private UserStatisticsService userStatisticsService;
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "平台用户信息统计", description = "用户信息统计")
+    @RequestMapping(value = {"statisticsPlatformUserInfo"}, method = {RequestMethod.GET})
+    public ResultContent<PlatformUserStatisModel> statisticsPlatformUserInfo() {
+        return userStatisticsService.statisticsPlatformUserInfo();
+    }
+
+}

+ 6 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/org/UserCountDao.java

@@ -1,6 +1,7 @@
 package com.zhongshu.card.server.core.dao.org;
 
 import com.github.microservice.components.data.mongo.mongo.dao.MongoDao;
+import com.zhongshu.card.client.type.Sex;
 import com.zhongshu.card.server.core.dao.org.extend.UserCountDaoExtend;
 import com.zhongshu.card.server.core.domain.org.UserAccount;
 
@@ -21,4 +22,9 @@ public interface UserCountDao extends MongoDao<UserAccount>, UserCountDaoExtend
     UserAccount findTopByPhone(String phone);
 
     UserAccount findTopByLoginName(String loginName);
+
+    long countByIsDeleted(Boolean isDeleted);
+
+    long countByIsDeleteAndSex(Boolean isDeleted, Sex sex);
+
 }

+ 3 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/org/extend/UserCountDaoExtend.java

@@ -11,5 +11,8 @@ import org.springframework.data.domain.Pageable;
  * @Version: 1.0
  */
 public interface UserCountDaoExtend {
+
     Page<UserAccount> page(Pageable pageable, UserCountSearchParam param);
+
+
 }

+ 12 - 8
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/org/impl/UserCountDaoImpl.java

@@ -36,9 +36,17 @@ public class UserCountDaoImpl extends BaseImpl implements UserCountDaoExtend {
 
     @Override
     public Page<UserAccount> page(Pageable pageable, UserCountSearchParam param) {
+        Criteria criteria = buildCriteria(param);
+
+        Sort sort = buildSort(param);
+        Query query = Query.query(criteria);
+        query.with(sort);
+        return dbHelper.pages(query, pageable, UserAccount.class);
+    }
+
+    public Criteria buildCriteria(UserCountSearchParam param) {
         Criteria criteria = new Criteria();
 
-        //
         if (ObjectUtils.isNotEmpty(param.getUserId())) {
             criteria.and("userId").is(param.getUserId());
         }
@@ -47,12 +55,12 @@ public class UserCountDaoImpl extends BaseImpl implements UserCountDaoExtend {
             criteria.and("sex").is(param.getSex());
         }
 
-        if(param.getUserType() != null) {
+        if (param.getUserType() != null) {
             criteria.and("userType").is(param.getUserType());
         }
 
         if (!CommonUtil.longIsEmpty(param.getStartTime()) && !CommonUtil.longIsEmpty(param.getEndTime())) {
-            criteria.and("createTime").gte(param.getStartTime()).and("createTime").lte(param.getEndTime());
+            criteria.and("createTime").gte(param.getStartTime()).lte(param.getEndTime());
         }
 
         // 模糊搜索
@@ -77,12 +85,8 @@ public class UserCountDaoImpl extends BaseImpl implements UserCountDaoExtend {
             Pattern pattern = Pattern.compile("^.*" + param.getKeyWord() + ".*$");
             criteria.orOperator(Criteria.where("name").regex(pattern), Criteria.where("phone").regex(pattern));
         }
-
         criteria.and("isDelete").is(Boolean.FALSE);
-        Sort sort = buildSort(param);
-        Query query = Query.query(criteria);
-        query.with(sort);
-        return dbHelper.pages(query, pageable, UserAccount.class);
+        return criteria;
     }
 
 }

+ 4 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/org/OrganizationUser.java

@@ -3,6 +3,7 @@ package com.zhongshu.card.server.core.domain.org;
 import com.github.microservice.auth.security.type.AuthType;
 import com.zhongshu.card.client.type.CertificateType;
 import com.zhongshu.card.client.type.OrganizationUserType;
+import com.zhongshu.card.client.type.Sex;
 import com.zhongshu.card.client.type.UserState;
 import com.zhongshu.card.server.core.domain.base.SuperMain;
 import com.zhongshu.card.server.core.domain.school.DictInfo;
@@ -59,6 +60,9 @@ public class OrganizationUser extends SuperMain {
     @Indexed
     private String name;
 
+    @Schema(description = "性别")
+    private Sex sex;
+
     @Schema(description = "用户在机构的类型 学生 老师")
     private OrganizationUserType userType;
 

+ 1 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/org/OrganizationUserServiceImpl.java

@@ -294,6 +294,7 @@ public class OrganizationUserServiceImpl extends SuperService {
         organizationUser.setUser(userAccount);
         organizationUser.setUserId(userAccount.getUserId());
         organizationUser.setCreateUserId(getCurrentUserId());
+        organizationUser.setSex(userAccount.getSex());
 
         List<Role> roles = new ArrayList<>();
         Department department = null;

+ 60 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/userStatistics/UserStatisticsService.java

@@ -0,0 +1,60 @@
+package com.zhongshu.card.server.core.service.userStatistics;
+
+import com.github.microservice.net.ResultContent;
+import com.zhongshu.card.client.model.userStatistics.PlatformUserStatisModel;
+import com.zhongshu.card.client.type.Sex;
+import com.zhongshu.card.server.core.dao.org.UserCountDao;
+import com.zhongshu.card.server.core.service.base.SuperService;
+import com.zhongshu.card.server.core.util.CommonUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * 用户统计服务
+ *
+ * @author TRX
+ * @date 2024/12/11
+ */
+@Slf4j
+@Service
+public class UserStatisticsService extends SuperService {
+
+    @Autowired
+    private UserCountDao userCountDao;
+
+
+    public ResultContent<PlatformUserStatisModel> statisticsPlatformUserInfo() {
+        return ResultContent.buildSuccess(statisticsPlatformUser());
+    }
+
+    /**
+     * 统计平台的用户信息
+     *
+     * @return
+     */
+    public PlatformUserStatisModel statisticsPlatformUser() {
+        PlatformUserStatisModel model = new PlatformUserStatisModel();
+        long total = userCountDao.countByIsDeleted(Boolean.FALSE);
+        model.setTotal(total);
+
+        // 男士
+        long manTotal = userCountDao.countByIsDeleteAndSex(Boolean.FALSE, Sex.Male);
+        model.setManTotal(manTotal);
+        model.setManScale(CommonUtil.countScale(manTotal, total));
+
+        // 女士
+        long womanTotal = userCountDao.countByIsDeleteAndSex(Boolean.FALSE, Sex.Female);
+        model.setWomanTotal(womanTotal);
+        model.setWomanScale(CommonUtil.countScale(womanTotal, total));
+
+        if (total > 0) {
+            model.setUnSetTotal(total - womanTotal - manTotal);
+        }
+
+
+        return model;
+    }
+
+
+}

+ 1 - 10
FullCardServer/src/main/java/com/zhongshu/card/server/core/test/Test.java

@@ -54,15 +54,6 @@ public class Test {
 //        } catch (Exception e) {
 //            e.printStackTrace();
 //        }
-        String phone = "766";
-        System.out.println(CommonUtil.getPhoneLast4(phone));
-
-        Calendar calendar = Calendar.getInstance();
-
-        System.out.println("上周的最后一天是:" + DateUtils.paresTime(DateUtils.getPreWeekLastTime(), DateUtils.FORMAT_LONG));
-
-
-        System.out.println("上月的最后一天是:" + DateUtils.paresTime(DateUtils.getPreMonthLastTime(), DateUtils.FORMAT_LONG));
-
+        System.out.println(CommonUtil.idCardDesen("511304198608153312"));
     }
 }

+ 92 - 2
FullCardServer/src/main/java/com/zhongshu/card/server/core/util/CommonUtil.java

@@ -8,10 +8,10 @@ import com.google.zxing.client.j2se.MatrixToImageWriter;
 import com.google.zxing.common.BitMatrix;
 import com.google.zxing.qrcode.QRCodeWriter;
 import com.zhongshu.card.client.model.operLogs.OperationLogsAddParam;
-import com.zhongshu.card.client.utils.DateUtils;
-import com.zhongshu.card.client.utils.ITree;
 import com.zhongshu.card.client.type.Sex;
 import com.zhongshu.card.client.type.school.CardType;
+import com.zhongshu.card.client.utils.DateUtils;
+import com.zhongshu.card.client.utils.ITree;
 import com.zhongshu.card.server.core.domain.base.SuperMain;
 import com.zhongshu.card.server.core.util.exception.BusinessException;
 import jakarta.servlet.http.HttpServletRequest;
@@ -566,6 +566,12 @@ public class CommonUtil {
         return param;
     }
 
+    /**
+     * 取电话号码后4位 ,如:18723497100 -> 7100
+     *
+     * @param phone
+     * @return
+     */
     public static String getPhoneLast4(String phone) {
         if (StringUtils.isNotEmpty(phone) && phone.length() >= 4) {
             int len = phone.length();
@@ -574,4 +580,88 @@ public class CommonUtil {
         return phone;
     }
 
+    /**
+     * 手机号码脱敏,如:18723497100 -> 187****7100
+     *
+     * @param phone
+     * @return
+     */
+    public static String turnPhoneDesen(String phone) {
+        if (StringUtils.isNotEmpty(phone) && phone.length() == 11) {
+            return phone.substring(0, 3) + "****" + phone.substring(7, 11);
+        }
+        return phone;
+    }
+
+    /**
+     * 名字脱敏,如:张三 -> 张*
+     *
+     * @param name
+     * @return
+     */
+    public static String turnNameDesen(String name) {
+        if (StringUtils.isNotEmpty(name) && name.length() > 1) {
+            if (name.length() == 2) {
+                return name.substring(0, 1) + "*";
+            } else {
+                return String.format("%s*%s", name.substring(0, 1), name.substring((name.length() - 1), name.length()));
+            }
+        }
+        return name;
+    }
+
+    /**
+     * 身份证脱敏显示
+     *
+     * @param idCardNo
+     * @return
+     */
+    public static String idCardDesen(String idCardNo) {
+        if (StringUtils.isNotEmpty(idCardNo) && idCardNo.length() == 18) {
+            return idCardNo.substring(0, 6) + "****" + idCardNo.substring(12, 18);
+        }
+        return idCardNo;
+    }
+
+    /**
+     * 计算环比,如:83.2 (最多保留2未小数)
+     * `
+     *
+     * @param currentNumber 当期的值
+     * @param preNumber     上期的值
+     * @return
+     */
+    public BigDecimal chainScale(Long currentNumber, Long preNumber) {
+        BigDecimal number = BigDecimal.ZERO;
+        if (currentNumber != null) {
+            if (preNumber == null || preNumber == 0) {
+                number = BigDecimal.valueOf(100);
+            } else {
+                number = BigDecimal.valueOf(((currentNumber - preNumber) * 100)).divide(new BigDecimal(preNumber), 2, RoundingMode.HALF_UP).stripTrailingZeros();
+            }
+        }
+        return number;
+    }
+
+    /**
+     * 计算比例 (最多保留2位小数)
+     *
+     * @param number
+     * @param totalNumber
+     * @return
+     */
+    public static BigDecimal countScale(Long number, Long totalNumber) {
+        if (number != null && totalNumber != null && totalNumber > 0) {
+            return countScale(BigDecimal.valueOf(number), BigDecimal.valueOf(totalNumber));
+        }
+        return BigDecimal.ZERO;
+    }
+
+    public static BigDecimal countScale(BigDecimal number, BigDecimal totalNumber) {
+        if (number != null && totalNumber.compareTo(BigDecimal.ZERO) != 0) {
+            return number.multiply(BigDecimal.valueOf(100)).divide(totalNumber, 2, RoundingMode.HALF_UP).stripTrailingZeros();
+        }
+        return BigDecimal.ZERO;
+    }
+
 }