Quellcode durchsuchen

Merge branch 'master' of http://192.168.101.10:13000/boman/boman-framwork

sr vor 4 Jahren
Ursprung
Commit
d3d67558fc

+ 7 - 0
boman-auth/pom.xml

@@ -15,6 +15,13 @@
     </description>
     
     <dependencies>
+
+        <!--集成第三方登录-->
+        <dependency>
+            <groupId>com.xkcoding.justauth</groupId>
+            <artifactId>justauth-spring-boot-starter</artifactId>
+            <version>1.4.0</version>
+        </dependency>
         
         <!-- SpringCloud Ailibaba Nacos -->
         <dependency>

+ 74 - 0
boman-auth/src/main/java/com/boman/auth/controller/OauthController.java

@@ -0,0 +1,74 @@
+package com.boman.auth.controller;
+
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSON;
+import com.boman.common.core.utils.JSONArrayUtils;
+import com.boman.common.core.utils.StringUtils;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.xkcoding.justauth.AuthRequestFactory;
+import io.micrometer.core.instrument.util.JsonUtils;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import me.zhyd.oauth.config.AuthSource;
+import me.zhyd.oauth.model.AuthCallback;
+import me.zhyd.oauth.model.AuthResponse;
+import me.zhyd.oauth.request.AuthRequest;
+import me.zhyd.oauth.utils.AuthStateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * @author tjf
+ * @Date: 2021/05/24/11:41
+ */
+@Slf4j
+@RestController
+@RequestMapping("/oauth")
+@RequiredArgsConstructor(onConstructor_ = @Autowired)
+public class OauthController {
+    private final AuthRequestFactory factory;
+
+    @GetMapping
+    public List<String> list() {
+        return factory.oauthList();
+    }
+
+    @GetMapping("/login/{type}")
+    public void login(@PathVariable String type, HttpServletResponse response) throws IOException {
+        AuthRequest authRequest = factory.get(type);
+        //生成授权地址,并重定向
+        String authorize = authRequest.authorize(type + "::" + AuthStateUtils.createState());
+        response.sendRedirect(authorize);
+    }
+
+    /**
+     * 回调登录
+     * @param type
+     * @param callback
+     * @return
+     */
+    @RequestMapping("/{type}/callback")
+    public AuthResponse login(@PathVariable String type, AuthCallback callback) {
+        AuthRequest authRequest = factory.get(getAuthSource(type));
+        AuthResponse response = authRequest.login(callback);
+        log.info("【response】= {}", JSON.toJSONString(response));
+        return response;
+    }
+
+    private String getAuthSource(String type) {
+        if (StrUtil.isNotBlank(type)) {
+            return type.toUpperCase();
+        } else {
+            throw new RuntimeException("类型为空");
+        }
+    }
+}

+ 11 - 0
boman-auth/src/main/resources/bootstrap.yml

@@ -23,3 +23,14 @@ spring:
         # 共享配置
         shared-configs:
           - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
+justauth:
+  enabled: true
+  type:
+    WECHAT_OPEN:
+      client-id: wxbd7b37548b5433ea
+      client-secret: 1a3c713279e80163ae1e39b0713ca711
+      redirect-uri: http://tx.xhsoftware.cn:9070/oauth/WECHAT_OPEN/callback
+  cache:
+    type: redis
+    prefix: 'SOCIAL::STATE::'
+    timeout: 1h

+ 55 - 0
boman-common/boman-common-core/src/main/java/com/boman/common/core/enums/MiniAppProperties.java

@@ -0,0 +1,55 @@
+package com.boman.common.core.enums;
+
+/**
+ * @author tjf
+ * @Date: 2021/05/24/11:16
+ */
+public enum MiniAppProperties {
+    //https://api.weixin.qq.com/sns/oauth2/access_token?
+    // appid=APPID&
+    // secret=SECRET&
+    // code=CODE&
+    // grant_type=authorization_code
+    WeChat("https://api.weixin.qq.com/sns/oauth2/access_token?appid=","WeChat","","","","authorization_code");
+
+    private final String platForm;
+    private final String url;
+    private final String appId;
+    //应用密钥AppSecret,在微信开放平台提交应用审核通过后获得
+    private final String secret;
+    private final String code;
+    private final String grantType;
+
+    MiniAppProperties(String platForm, String url, String appId, String secret, String code, String grantType) {
+        this.platForm = platForm;
+        this.url = url;
+        this.appId = appId;
+        this.secret = secret;
+        this.code = code;
+        this.grantType = grantType;
+    }
+
+    public String getPlatForm() {
+        return platForm;
+    }
+
+    public String getUrl() {
+        return url;
+    }
+
+    public String getAppId() {
+        return appId;
+    }
+
+    public String getSecret() {
+        return secret;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public String getGrantType() {
+        return grantType;
+    }
+}

+ 1 - 0
boman-modules/boman-gen/src/main/java/com/boman/gen/service/GenTableServiceImpl.java

@@ -630,6 +630,7 @@ public class GenTableServiceImpl implements IGenTableService {
             }
         }
         String isMenu = genTable.getIsMenu();
+        //是新增
         if (StringUtils.isNotBlank(isMenu) && isMenu.equals(UserConstants.ISMENU)) {
             SysMenu sysMenu = new SysMenu();
             sysMenu.setSysTableName(tableName);

+ 19 - 1
boman-web-core/src/main/java/com/boman/web/core/service/TableServiceCmdService.java

@@ -42,6 +42,7 @@ import javax.annotation.Resource;
 import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Iterator;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Predicate;
@@ -359,7 +360,7 @@ public class TableServiceCmdService {
             }
         }
         JSONObject result = new JSONObject();
-        result.put(SHOW_DATA, parentColumns);
+        result.put(SHOW_DATA, removeHr(parentColumns));
         result.put(BUTTON_LIST, getButton(tableName));
         Integer tableColumn = genTable.getTableColumn();
         if (tableColumn != null){
@@ -368,6 +369,23 @@ public class TableServiceCmdService {
         return AjaxResult.success(result);
     }
 
+    /**
+     * 判断hr字段里面是否有值
+     * @param parentColumns
+     * @return
+     */
+    private List<GenTableColumn> removeHr(List<GenTableColumn> parentColumns){
+        Iterator<GenTableColumn> iterator = parentColumns.iterator();
+        while (iterator.hasNext()){
+            GenTableColumn next = iterator.next();
+            List<GenTableColumn> hrChildren = next.getHrChildren();
+            if (hrChildren.size() == 0){
+                iterator.remove();
+            }
+        }
+        return parentColumns;
+    }
+
     /**
      * 功能描述: 获取表单查询字段、按钮、表头
      * 注意: 都是从redis中拿的,如果数据库和redis不一致,则需刷新一下redis

+ 15 - 8
boman-web-core/src/main/java/com/boman/web/core/utils/ColumnUtils.java

@@ -269,15 +269,22 @@ public class ColumnUtils {
      */
     public static void handleInputType(JSONObject commitData, List<GenTableColumn> columns) {
         for (Map.Entry<String, Object> entry : commitData.entrySet()) {
-            Object value =entry.getValue();
+            Object value = entry.getValue();
             for (GenTableColumn column : columns) {
-                if (entry.getKey().equals(column.getColumnName())
-                        && ArrayUtils.arraysContains(GenConstants.COLUMNTYPE_NUMBER, getDbType(column.getColumnType()))) {
-                    if ((value instanceof Number)) {
-                        // ignore 这里的if不能删掉,因为else if有一个强转
-                    } else if (!NumberUtils.isCreatable(((String) value))) {
-                        throw new IllegalArgumentException(column.getColumnComment() + "只能输入数字");
-                    }
+                // 对必填项做校验, 非必填项不管他
+                if (!GenTableColumn.IS_REQUIRED.equalsIgnoreCase(column.getIsRequired())) {
+                    continue;
+                }
+                if (!entry.getKey().equals(column.getColumnName())) {
+                    continue;
+                }
+
+                if (!ArrayUtils.arraysContains(GenConstants.COLUMNTYPE_NUMBER, getDbType(column.getColumnType()))) {
+                    continue;
+                }
+
+                if ((value instanceof String) && !NumberUtils.isCreatable(((String) value))) {
+                    throw new IllegalArgumentException(column.getColumnComment() + "只能输入数字");
                 }
             }
         }