TRX 1 éve
szülő
commit
697d6cecb1

+ 37 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/setting/PlatFormBasicInfo.java

@@ -0,0 +1,37 @@
+package com.zhongshu.card.client.model.setting;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.NotEmpty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author TRX
+ * @date 2024/10/8
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class PlatFormBasicInfo {
+
+    @NotEmpty
+    @Schema(description = "平台名称")
+    private String name;
+
+    @Schema(description = "logo")
+    private String logo;
+
+    @Schema(description = "备案编号")
+    private String recordNumber;
+
+    @Schema(description = "版权所有")
+    private String copyright;
+
+    @Schema(description = "平台开启访问")
+    private Boolean isOpen = Boolean.TRUE;
+
+    @Schema(description = "网站关闭提示")
+    private String closeTip;
+
+}

+ 28 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/setting/PlatFormLoginConfig.java

@@ -0,0 +1,28 @@
+package com.zhongshu.card.client.model.setting;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * 登录注册 配置
+ *
+ * @author TRX
+ * @date 2024/10/8
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class PlatFormLoginConfig {
+
+    @Schema(description = "登录验证码开关")
+    private Boolean isOpenVerCode = Boolean.FALSE;
+
+    @Schema(description = "最大登录失败次数")
+    private Integer maxLoginFail = 3;
+
+    @Schema(description = "锁定登录时间")
+    private Integer lockMinute = 20;
+
+}

+ 19 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/type/setting/SettingType.java

@@ -0,0 +1,19 @@
+package com.zhongshu.card.client.type.setting;
+
+import lombok.Getter;
+
+/**
+ *
+ */
+public enum SettingType {
+    BasicInfo("平台基本信息"),
+    LoginConfig("登录注册"),
+    ;
+
+    @Getter
+    private String remark;
+
+    SettingType(String remark) {
+        this.remark = remark;
+    }
+}

+ 0 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/orgManager/OrganizationManagerController.java

@@ -36,7 +36,6 @@ public class OrganizationManagerController {
 
     //------------------------------机构管理 start----------------------
 
-    //    @ResourceAuth(value = "orgPage", type = AuthType.Platform, remark = "机构管理_机构列表_1_Menu")
     @ResourceAuth(value = "user", type = AuthType.User)
     @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform)
     @Operation(summary = "机构列表-分页查询", description = "机构列表-分页查询")

+ 80 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/setting/PlatFormConfigInfoController.java

@@ -0,0 +1,80 @@
+package com.zhongshu.card.server.core.controller.setting;
+
+import com.github.microservice.auth.security.annotations.ResourceAuth;
+import com.github.microservice.auth.security.type.AuthType;
+import com.github.microservice.net.ResultContent;
+import com.google.common.collect.Lists;
+import com.zhongshu.card.client.model.setting.PlatFormBasicInfo;
+import com.zhongshu.card.client.model.setting.PlatFormLoginConfig;
+import com.zhongshu.card.client.type.setting.SettingType;
+import com.zhongshu.card.server.core.domain.setting.PlatFormConfigInfo;
+import com.zhongshu.card.server.core.service.setting.PlatFormConfigInfoService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.apache.commons.lang3.ObjectUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.validation.Valid;
+
+/**
+ * 系统设置
+ */
+@RestController
+@RequestMapping("/setting")
+@Tag(name = "系统设置")
+public class PlatFormConfigInfoController {
+
+    @Autowired
+    private PlatFormConfigInfoService platFormConfigInfoService;
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "保存平台基本信息", description = "保存平台基本信息")
+    @RequestMapping(value = "saveBasicInfo", method = {RequestMethod.POST})
+    public ResultContent saveBasicInfo(@RequestBody @Valid PlatFormBasicInfo param) {
+        platFormConfigInfoService.saveEntity(param, SettingType.BasicInfo);
+        return ResultContent.buildSuccess();
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "得到平台基本信息", description = "得到平台基本信息")
+    @RequestMapping(value = "getBasicInfo", method = {RequestMethod.GET})
+    public ResultContent getBasicInfo() {
+        PlatFormConfigInfo entity = platFormConfigInfoService.getEntity(SettingType.BasicInfo);
+        PlatFormBasicInfo basicInfo = null;
+        if (ObjectUtils.isNotEmpty(entity)) {
+            Object info = entity.getInfo();
+            if (info != null) {
+                basicInfo = (PlatFormBasicInfo) info;
+            }
+        }
+        return ResultContent.buildSuccess(basicInfo);
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "保存登录注册", description = "保存登录注册")
+    @RequestMapping(value = "saveLoginConfig", method = {RequestMethod.POST})
+    public ResultContent saveLoginConfig(@RequestBody @Valid PlatFormLoginConfig param) {
+        platFormConfigInfoService.saveEntity(param, SettingType.LoginConfig);
+        return ResultContent.buildSuccess();
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "得到登录注册", description = "得到登录注册")
+    @RequestMapping(value = "getLoginConfig", method = {RequestMethod.GET})
+    public ResultContent getLoginConfig() {
+        PlatFormConfigInfo entity = platFormConfigInfoService.getEntity(SettingType.LoginConfig);
+        PlatFormLoginConfig basicInfo = null;
+        if (ObjectUtils.isNotEmpty(entity)) {
+            Object info = entity.getInfo();
+            if (info != null) {
+                basicInfo = (PlatFormLoginConfig) info;
+            }
+        }
+        return ResultContent.buildSuccess(basicInfo);
+    }
+
+}

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

@@ -0,0 +1,18 @@
+package com.zhongshu.card.server.core.dao.org;
+
+import com.github.microservice.components.data.mongo.mongo.dao.MongoDao;
+import com.zhongshu.card.client.type.setting.SettingType;
+import com.zhongshu.card.server.core.domain.org.Department;
+import com.zhongshu.card.server.core.domain.setting.PlatFormConfigInfo;
+
+import java.util.List;
+
+/**
+ * @author TRX
+ * @date 2024/3/21
+ */
+public interface PlatFormConfigInfoDao extends MongoDao<PlatFormConfigInfo> {
+
+    PlatFormConfigInfo findTopBySettingType(SettingType settingType);
+
+}

+ 31 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/setting/PlatFormConfigInfo.java

@@ -0,0 +1,31 @@
+package com.zhongshu.card.server.core.domain.setting;
+
+import com.zhongshu.card.client.type.setting.SettingType;
+import com.zhongshu.card.server.core.domain.base.SuperMain;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.checkerframework.common.aliasing.qual.NonLeaked;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+/**
+ * 平台配置信息
+ *
+ * @author TRX
+ * @date 2024/10/8
+ */
+@Data
+@Document
+@AllArgsConstructor
+@NoArgsConstructor
+@NonLeaked
+public class PlatFormConfigInfo extends SuperMain {
+
+    @Schema(description = "配置类型")
+    private SettingType settingType;
+
+    @Schema(description = "内容")
+    private Object info;
+
+}

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

@@ -32,6 +32,7 @@ public class OpenAPIRegisterService {
     public ResultContent initRegisterPAIS() {
         String str = restTemplate.getForObject("http://" + serviceId + "/v3/api-docs", String.class);
         List<JSONObject> openAPIS = OpenAPIScan.scanAPI(str);
+
 //        ResultContent content = restTemplate.postForObject("http://opengateway/v3/api-docs", openAPIS, ResultContent.class);
 //        if (content.isFailed()) {
 //            log.info("openApi注册错误: {}", content.getMsg());

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

@@ -12,15 +12,18 @@ import com.github.microservice.components.data.mongo.mongo.helper.DBHelper;
 import com.github.microservice.core.util.net.IPUtil;
 import com.zhongshu.card.client.model.login.LoginCommonModel;
 import com.zhongshu.card.client.model.org.*;
+import com.zhongshu.card.client.model.setting.PlatFormLoginConfig;
 import com.zhongshu.card.client.model.wechat.PhoneModel;
 import com.zhongshu.card.client.model.wechat.WechatPhoneNumber;
 import com.github.microservice.net.ResultContent;
 import com.zhongshu.card.client.type.LoginFromType;
 import com.zhongshu.card.client.type.OrganizationState;
 import com.zhongshu.card.client.type.UserState;
+import com.zhongshu.card.client.type.setting.SettingType;
 import com.zhongshu.card.server.core.dao.org.*;
 import com.zhongshu.card.server.core.domain.org.*;
 import com.zhongshu.card.server.core.service.base.RedisService;
+import com.zhongshu.card.server.core.service.setting.PlatFormConfigInfoService;
 import com.zhongshu.card.server.core.service.user.RoleServiceImpl;
 import com.zhongshu.card.server.core.service.user.UserAccountServiceImpl;
 import com.zhongshu.card.server.core.util.CommonUtil;
@@ -93,6 +96,9 @@ public class IndexService {
     @Autowired
     OrganizationServiceImpl organizationService;
 
+    @Autowired
+    PlatFormConfigInfoService platFormConfigInfoService;
+
     /**
      * 通用用户登录(返回所有权限数据)
      *
@@ -287,7 +293,9 @@ public class IndexService {
      * @return
      */
     public ResultContent<LoginTokenModel> commonLogin(UserAuthLoginModel userAuthLoginModel) {
+        // 登录名
         String phone = userAuthLoginModel.getLoginValue();
+
         userAuthLoginModel.setDeviceIp(IPUtil.getRemoteIp(request));
         userAuthLoginModel.setClientId(clientId);
         userAuthLoginModel.setClientSecret(clientSecret);
@@ -298,6 +306,21 @@ public class IndexService {
         if (userAuthLoginModel.getRefreshTokenTimeOut() == null) {
             userAuthLoginModel.setRefreshTokenTimeOut(31536000L);
         }
+        // 登录失败信息过期时间
+        Long lockTime = 2 * 24L * 60 * 60 * 1000L;
+        // 错误次数
+        int maxFail = 3;
+        Object config = platFormConfigInfoService.getInfo(SettingType.LoginConfig);
+        if (ObjectUtils.isNotEmpty(config)) {
+            PlatFormLoginConfig loginConfig = (PlatFormLoginConfig) config;
+            Integer lockMinute = loginConfig.getLockMinute();
+            if (lockMinute != null) {
+                lockTime = lockMinute * 60 * 60 * 1000L;
+            }
+            if (loginConfig.getMaxLoginFail() != null) {
+                maxFail = loginConfig.getMaxLoginFail();
+            }
+        }
 
         com.github.microservice.auth.client.content.ResultContent<LoginTokenModel> resultContent = userService.login(userAuthLoginModel);
         if (resultContent.getState() == com.github.microservice.auth.client.content.ResultState.Success) {
@@ -305,6 +328,12 @@ public class IndexService {
             if (ObjectUtils.isEmpty(userAccount)) {
                 return ResultContent.buildFail("账号或密码不正确");
             }
+
+            long number = userLoginFailRecordDao.countByUserName(userAccount.getLoginName());
+            if (number > maxFail) {
+                return ResultContent.buildFail(String.format("登录失败超过%d次,请稍后再试", maxFail));
+            }
+
             // 判断用户状态
             if (userAccount.getState() == UserState.Locked) {
                 return ResultContent.buildFail(String.format("该账号已被%s,不能登录", userAccount.getState().getRemark()));
@@ -331,7 +360,8 @@ public class IndexService {
             return ResultContent.buildSuccess(resultContent.getContent());
         } else {
             // 记录登录失败信息
-            userLoginFailRecordDao.save(UserLoginFailRecord.builder().userName(phone).ttl(new Date(dbHelper.getTime() + 2 * 24L * 60 * 60 * 1000L)).build());
+            userLoginFailRecordDao.save(UserLoginFailRecord.builder().userName(phone)
+                    .ttl(new Date(dbHelper.getTime() + lockTime)).build());
             String msg = resultContent.getMsg();
             if (StringUtils.isEmpty(msg)) {
                 msg = "账号或密码不正确.";

+ 70 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/setting/PlatFormConfigInfoService.java

@@ -0,0 +1,70 @@
+package com.zhongshu.card.server.core.service.setting;
+
+import com.zhongshu.card.client.type.setting.SettingType;
+import com.zhongshu.card.server.core.dao.org.PlatFormConfigInfoDao;
+import com.zhongshu.card.server.core.domain.setting.PlatFormConfigInfo;
+import com.zhongshu.card.server.core.service.base.SuperService;
+import jakarta.validation.constraints.NotNull;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.ObjectUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * 系统配置信息
+ *
+ * @author TRX
+ * @date 2024/10/8
+ */
+@Slf4j
+@Service
+public class PlatFormConfigInfoService extends SuperService {
+
+    @Autowired
+    private PlatFormConfigInfoDao platFormConfigInfoDao;
+
+    /**
+     * 得到配置 实体
+     *
+     * @param settingType
+     * @return
+     */
+    public PlatFormConfigInfo getEntity(@NotNull SettingType settingType) {
+        return platFormConfigInfoDao.findTopBySettingType(settingType);
+    }
+
+    /**
+     * 得到配置信息
+     *
+     * @param settingType
+     * @return
+     */
+    public Object getInfo(@NotNull SettingType settingType) {
+        PlatFormConfigInfo configInfo = getEntity(settingType);
+        if (ObjectUtils.isNotEmpty(configInfo)) {
+            return configInfo.getInfo();
+        }
+        return null;
+    }
+
+    /**
+     * 保存配置信息
+     *
+     * @param info
+     * @param settingType
+     * @return
+     */
+    public boolean saveEntity(Object info, @NotNull SettingType settingType) {
+        PlatFormConfigInfo entity = platFormConfigInfoDao.findTopBySettingType(settingType);
+        if (ObjectUtils.isEmpty(entity)) {
+            entity = new PlatFormConfigInfo();
+            initEntity(entity);
+        } else {
+            initUpdateEntity(entity);
+        }
+        entity.setInfo(info);
+        platFormConfigInfoDao.save(entity);
+        return true;
+    }
+
+}