duhongyu 3 maanden geleden
bovenliggende
commit
bd9bef3775
33 gewijzigde bestanden met toevoegingen van 1786 en 290 verwijderingen
  1. 3 1
      smart-steward-api/src/main/java/com/smartSteward/web/controller/common/CaptchaController.java
  2. 37 5
      smart-steward-api/src/main/java/com/smartSteward/web/controller/dingTalk/DingTalkCallbackController.java
  3. 0 2
      smart-steward-api/src/main/java/com/smartSteward/web/controller/system/SysLoginController.java
  4. 2 0
      smart-steward-api/src/main/java/com/smartSteward/web/core/config/SwaggerConfig.java
  5. 19 6
      smart-steward-api/src/main/resources/application-dev.yml
  6. 20 6
      smart-steward-api/src/main/resources/application-production.yml
  7. 3 9
      smart-steward-api/src/main/resources/application.yml
  8. 2 0
      smart-steward-api/src/main/resources/mybatis/mybatis-config.xml
  9. 22 0
      smart-steward-api/src/main/resources/mybatis/mybatis-production-config.xml
  10. 29 0
      smart-steward-common/src/main/java/com/smartSteward/common/core/database/system/SysDept.java
  11. 16 0
      smart-steward-common/src/main/java/com/smartSteward/common/core/database/system/SysUser.java
  12. 54 0
      smart-steward-common/src/main/java/com/smartSteward/common/utils/dingTalk/DingTalkEncryptException.java
  13. 207 0
      smart-steward-common/src/main/java/com/smartSteward/common/utils/dingTalk/DingTalkEncryptor.java
  14. 47 0
      smart-steward-common/src/main/java/com/smartSteward/common/utils/dingTalk/PKCS7Padding.java
  15. 48 0
      smart-steward-common/src/main/java/com/smartSteward/common/utils/dingTalk/Utils.java
  16. 1 1
      smart-steward-common/src/main/java/com/smartSteward/common/utils/http/HttpUtils.java
  17. 10 0
      smart-steward-entity/pom.xml
  18. 41 0
      smart-steward-entity/src/main/java/com/smartSteward/entity/input/dingTalk/AddressListRegister.java
  19. 22 0
      smart-steward-entity/src/main/java/com/smartSteward/entity/view/dingTalk/DingTalkDept.java
  20. 53 0
      smart-steward-entity/src/main/java/com/smartSteward/entity/view/dingTalk/DingTalkUser.java
  21. 1 1
      smart-steward-framework/pom.xml
  22. 14 30
      smart-steward-framework/src/main/java/com/smartSteward/framework/web/service/SysLoginService.java
  23. 13 1
      smart-steward-mapper/src/main/java/com/smartSteward/mapper/system/SysDeptMapper.java
  24. 10 1
      smart-steward-mapper/src/main/java/com/smartSteward/mapper/system/SysUserMapper.java
  25. 2 2
      smart-steward-mapper/src/main/resources/generator.yml
  26. 27 3
      smart-steward-mapper/src/main/resources/mapper/system/SysDeptMapper.xml
  27. 16 7
      smart-steward-mapper/src/main/resources/mapper/system/SysUserMapper.xml
  28. 8 1
      smart-steward-service/src/main/java/com/smartSteward/service/dingTalk/IDingTalkService.java
  29. 1007 206
      smart-steward-service/src/main/java/com/smartSteward/service/dingTalk/impl/DingTalkServiceImpl.java
  30. 5 0
      smart-steward-service/src/main/java/com/smartSteward/service/system/ISysDeptService.java
  31. 13 2
      smart-steward-service/src/main/java/com/smartSteward/service/system/ISysUserService.java
  32. 10 2
      smart-steward-service/src/main/java/com/smartSteward/service/system/impl/SysDeptServiceImpl.java
  33. 24 4
      smart-steward-service/src/main/java/com/smartSteward/service/system/impl/SysUserServiceImpl.java

+ 3 - 1
smart-steward-api/src/main/java/com/smartSteward/web/controller/common/CaptchaController.java

@@ -82,7 +82,9 @@ public class CaptchaController
82 82
         FastByteArrayOutputStream os = new FastByteArrayOutputStream();
83 83
         try
84 84
         {
85
-            ImageIO.write(image, "jpg", os);
85
+            if (image != null) {
86
+                ImageIO.write(image, "jpg", os);
87
+            }
86 88
         }
87 89
         catch (IOException e)
88 90
         {

+ 37 - 5
smart-steward-api/src/main/java/com/smartSteward/web/controller/dingTalk/DingTalkCallbackController.java

@@ -1,13 +1,21 @@
1 1
 package com.smartSteward.web.controller.dingTalk;
2 2
 
3
+import com.smartSteward.common.annotation.Anonymous;
3 4
 import com.smartSteward.common.config.smartStewardConfig;
5
+import com.smartSteward.common.constant.Constants;
6
+import com.smartSteward.common.core.AjaxResult;
4 7
 import com.smartSteward.common.utils.StringUtils;
5 8
 import com.smartSteward.common.utils.file.FileUtils;
9
+import com.smartSteward.service.dingTalk.IDingTalkService;
10
+import com.smartSteward.web.controller.BaseController;
11
+import lombok.var;
12
+import org.springframework.beans.factory.annotation.Autowired;
6 13
 import org.springframework.http.MediaType;
7 14
 import org.springframework.web.bind.annotation.*;
8 15
 
9 16
 import javax.servlet.http.HttpServletRequest;
10 17
 import javax.servlet.http.HttpServletResponse;
18
+import java.util.concurrent.CompletableFuture;
11 19
 
12 20
 /**
13 21
  * 钉钉回调事件接口
@@ -16,8 +24,9 @@ import javax.servlet.http.HttpServletResponse;
16 24
  */
17 25
 @RestController
18 26
 @RequestMapping("/dingTalk")
19
-public class DingTalkCallbackController {
20
-
27
+public class DingTalkCallbackController extends BaseController {
28
+    @Autowired
29
+    private IDingTalkService dingTalkService;
21 30
     /**
22 31
      * 通用下载请求
23 32
      *
@@ -27,13 +36,36 @@ public class DingTalkCallbackController {
27 36
      * @param requestBody 数据包数据中的加密数据
28 37
      */
29 38
     @PostMapping("/receive")
30
-    public void receive( @RequestParam("signature") String signature,
39
+    @Anonymous
40
+    public AjaxResult receive( @RequestParam("signature") String signature,
31 41
                               @RequestParam("timestamp") String timestamp,
32 42
                               @RequestParam("nonce") String nonce,
33 43
                               @RequestBody String requestBody)
34 44
     {
35 45
 
36
-
37
-
46
+        //异步处理事件订阅
47
+        CompletableFuture.supplyAsync(() -> dingTalkService.
48
+                receive(signature,timestamp,nonce,requestBody)).
49
+                thenAccept(result -> System.out.println("Result: " + result));
50
+        return success();
51
+    }
52
+    /**
53
+     * 同步钉钉数据
54
+     *
55
+     */
56
+    @PostMapping("/synchronize")
57
+    @Anonymous
58
+    public AjaxResult synchronize( )
59
+    {
60
+        //异步处理事件订阅
61
+       CompletableFuture.supplyAsync(() -> {
62
+           try {
63
+               dingTalkService. synchronize();
64
+           } catch (Exception e) {
65
+               throw new RuntimeException(e);
66
+           }
67
+           return null;
68
+    }).thenAccept(result -> System.out.println("Result: " + result));
69
+        return success();
38 70
     }
39 71
 }

+ 0 - 2
smart-steward-api/src/main/java/com/smartSteward/web/controller/system/SysLoginController.java

@@ -3,8 +3,6 @@ package com.smartSteward.web.controller.system;
3 3
 import java.util.Date;
4 4
 import java.util.List;
5 5
 import java.util.Set;
6
-
7
-import com.smartSteward.service.dingTalk.IDingTalkService;
8 6
 import io.swagger.annotations.Api;
9 7
 import io.swagger.annotations.ApiOperation;
10 8
 import org.springframework.beans.factory.annotation.Autowired;

+ 2 - 0
smart-steward-api/src/main/java/com/smartSteward/web/core/config/SwaggerConfig.java

@@ -2,6 +2,8 @@ package com.smartSteward.web.core.config;
2 2
 
3 3
 import java.util.ArrayList;
4 4
 import java.util.List;
5
+
6
+import io.swagger.annotations.Api;
5 7
 import org.springframework.beans.factory.annotation.Autowired;
6 8
 import org.springframework.beans.factory.annotation.Value;
7 9
 import org.springframework.context.annotation.Bean;

+ 19 - 6
smart-steward-api/src/main/resources/application-dev.yml

@@ -47,7 +47,7 @@ spring:
47 47
                 allow:
48 48
                 url-pattern: /druid/*
49 49
                 # 控制台管理用户名和密码
50
-                login-username: ruoyi
50
+                login-username: smartSteward
51 51
                 login-password: 123456
52 52
             filter:
53 53
                 stat:
@@ -82,15 +82,28 @@ spring:
82 82
                 # #连接池最大阻塞等待时间(使用负值表示没有限制)
83 83
                 max-wait: -1ms
84 84
     dingTalk:
85
-        # 钥匙
86
-        app_key: ding77tk1okpuoxhitxs
87
-        # 密钥
88
-        app_secret: lrV9pt51pjxUY00qCkPdoZ-393can29IujDFdlR9SZnechH_pSG1Tl1maWocWrDB
89
-
85
+        # 钉钉应用Key
86
+        app_key: ding0na3clg9jd7svbxm
87
+        # 钉钉应用密钥
88
+        app_secret: WE90y569RWtS4NZy7bS2ZniX2zXv2udwwkZ487eBVZynWZ9hwLycpHM-GO9mosxr
89
+        # 加密密钥
90
+        aes_kes: 43fafsarvvIvxKpQOh8b8MzhSqc4SmOlSgmBjevlcba
91
+        # 回调Token
92
+        token: 9uX6tAw5GRUQsH8DoNQTxhC
93
+        # 企业ID
94
+        corpId : ding3d771cecb9f68bfe35c2f4657eb6378f
90 95
     # Swagger配置
91 96
     swagger:
92 97
         # 是否开启swagger
93 98
         enabled: true
94 99
         # 请求前缀
95 100
         pathMapping: /dev-api
101
+# MyBatis配置
102
+mybatis:
103
+    # 搜索指定包别名
104
+    typeAliasesPackage: com.smartSteward.**.database.*
105
+    # 配置mapper的扫描,找到所有的mapper.xml映射文件
106
+    mapperLocations: classpath*:mapper/**/*Mapper.xml
107
+    # 加载全局的配置文件
108
+    configLocation: classpath:mybatis/mybatis-dev-config.xml
96 109
 

+ 20 - 6
smart-steward-api/src/main/resources/application-production.yml

@@ -47,7 +47,7 @@ spring:
47 47
                 allow:
48 48
                 url-pattern: /druid/*
49 49
                 # 控制台管理用户名和密码
50
-                login-username: ruoyi
50
+                login-username: smartSteward
51 51
                 login-password: 123456
52 52
             filter:
53 53
                 stat:
@@ -82,14 +82,28 @@ spring:
82 82
                 # #连接池最大阻塞等待时间(使用负值表示没有限制)
83 83
                 max-wait: -1ms
84 84
     dingTalk:
85
-        # 钥匙
86
-        app_key: ding77tk1okpuoxhitxs
87
-        # 密钥
88
-        app_secret: lrV9pt51pjxUY00qCkPdoZ-393can29IujDFdlR9SZnechH_pSG1Tl1maWocWrDB
85
+        # 钉钉应用Key
86
+        app_key: ding0na3clg9jd7svbxm
87
+        # 钉钉应用密钥
88
+        app_secret: WE90y569RWtS4NZy7bS2ZniX2zXv2udwwkZ487eBVZynWZ9hwLycpHM-GO9mosxr
89
+        # 加密密钥
90
+        aes_kes: 43fafsarvvIvxKpQOh8b8MzhSqc4SmOlSgmBjevlcba
91
+        # 回调Token
92
+        token: 9uX6tAw5GRUQsH8DoNQTxhC
93
+        # 企业ID
94
+        corpId: ding3d771cecb9f68bfe35c2f4657eb6378f
89 95
 
90 96
     # Swagger配置
91 97
     swagger:
92 98
         # 是否开启swagger
93 99
         enabled: false
94 100
         # 请求前缀
95
-        pathMapping: /dev-api
101
+        pathMapping: /dev-api
102
+# MyBatis配置
103
+mybatis:
104
+    # 搜索指定包别名
105
+    typeAliasesPackage: com.smartSteward.**.database.*
106
+    # 配置mapper的扫描,找到所有的mapper.xml映射文件
107
+    mapperLocations: classpath*:mapper/**/*Mapper.xml
108
+    # 加载全局的配置文件
109
+    configLocation: classpath:mybatis/mybatis-production-config.xml

+ 3 - 9
smart-steward-api/src/main/resources/application.yml

@@ -34,7 +34,7 @@ server:
34 34
 # 日志配置
35 35
 logging:
36 36
   level:
37
-    com.ruoyi: debug
37
+    com.smart-steward: debug
38 38
     org.springframework: warn
39 39
 
40 40
 # 用户配置
@@ -53,6 +53,7 @@ spring:
53 53
     basename: i18n/messages
54 54
   profiles:
55 55
     active: dev
56
+    #active: production
56 57
   # 文件上传
57 58
   servlet:
58 59
     multipart:
@@ -77,14 +78,7 @@ token:
77 78
   # 令牌有效期(默认30分钟)
78 79
   expireTime: 30
79 80
 
80
-# MyBatis配置
81
-mybatis:
82
-  # 搜索指定包别名
83
-  typeAliasesPackage: com.smartSteward.**.database.*
84
-  # 配置mapper的扫描,找到所有的mapper.xml映射文件
85
-  mapperLocations: classpath*:mapper/**/*Mapper.xml
86
-  # 加载全局的配置文件
87
-  configLocation: classpath:mybatis/mybatis-config.xml
81
+
88 82
 
89 83
 # PageHelper分页插件
90 84
 pagehelper:

+ 2 - 0
smart-steward-api/src/main/resources/mybatis/mybatis-config.xml

@@ -15,6 +15,8 @@ PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
15 15
         <setting name="logImpl"                  value="SLF4J"  />
16 16
         <!-- 使用驼峰命名法转换字段 -->
17 17
 		<!-- <setting name="mapUnderscoreToCamelCase" value="true"/> -->
18
+        <!-- mybatis日志 -->
19
+        <setting name="logImpl" value="STDOUT_LOGGING"/>
18 20
 	</settings>
19 21
 	
20 22
 </configuration>

+ 22 - 0
smart-steward-api/src/main/resources/mybatis/mybatis-production-config.xml

@@ -0,0 +1,22 @@
1
+<?xml version="1.0" encoding="UTF-8" ?>
2
+<!DOCTYPE configuration
3
+PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
4
+"http://mybatis.org/dtd/mybatis-3-config.dtd">
5
+<configuration>
6
+    <!-- 全局参数 -->
7
+    <settings>
8
+        <!-- 使全局的映射器启用或禁用缓存 -->
9
+        <setting name="cacheEnabled"             value="true"   />
10
+        <!-- 允许JDBC 支持自动生成主键 -->
11
+        <setting name="useGeneratedKeys"         value="true"   />
12
+        <!-- 配置默认的执行器.SIMPLE就是普通执行器;REUSE执行器会重用预处理语句(prepared statements);BATCH执行器将重用语句并执行批量更新 -->
13
+        <setting name="defaultExecutorType"      value="SIMPLE" />
14
+		<!-- 指定 MyBatis 所用日志的具体实现 -->
15
+        <setting name="logImpl"                  value="SLF4J"  />
16
+        <!-- 使用驼峰命名法转换字段 -->
17
+		<!-- <setting name="mapUnderscoreToCamelCase" value="true"/> -->
18
+        <!-- mybatis日志 -->
19
+        <!--<setting name="logImpl" value="STDOUT_LOGGING"/> -->
20
+	</settings>
21
+	
22
+</configuration>

+ 29 - 0
smart-steward-common/src/main/java/com/smartSteward/common/core/database/system/SysDept.java

@@ -53,6 +53,10 @@ public class SysDept extends BaseEntity
53 53
 
54 54
     /** 父部门名称 */
55 55
     private String parentName;
56
+    /** 钉钉部门id */
57
+    private String dingDeptId;
58
+    /** 钉钉父级部门id */
59
+    private String dingParentId;
56 60
     
57 61
     /** 子部门 */
58 62
     private List<SysDept> children = new ArrayList<SysDept>();
@@ -173,6 +177,29 @@ public class SysDept extends BaseEntity
173 177
         this.parentName = parentName;
174 178
     }
175 179
 
180
+
181
+    public String getDingDeptId()
182
+    {
183
+        return dingDeptId;
184
+    }
185
+
186
+    public void setDingDeptId(String dingDeptId)
187
+    {
188
+        this.dingDeptId = dingDeptId;
189
+    }
190
+
191
+    public String getDingParentId()
192
+    {
193
+        return dingParentId;
194
+    }
195
+
196
+    public void setDingParentId(String dingParentId)
197
+    {
198
+        this.dingParentId = dingParentId;
199
+    }
200
+
201
+
202
+
176 203
     public List<SysDept> getChildren()
177 204
     {
178 205
         return children;
@@ -200,6 +227,8 @@ public class SysDept extends BaseEntity
200 227
             .append("createTime", getCreateTime())
201 228
             .append("updateBy", getUpdateBy())
202 229
             .append("updateTime", getUpdateTime())
230
+            .append("dingDeptId", getDingDeptId())
231
+            .append("dingParentId", getDingParentId())
203 232
             .toString();
204 233
     }
205 234
 }

+ 16 - 0
smart-steward-common/src/main/java/com/smartSteward/common/core/database/system/SysUser.java

@@ -93,6 +93,10 @@ public class SysUser extends BaseEntity
93 93
     /** 角色ID */
94 94
     private Long roleId;
95 95
 
96
+    /** 钉钉用户userId */
97
+    private String dingUserId;
98
+
99
+
96 100
     public SysUser()
97 101
     {
98 102
 
@@ -311,6 +315,17 @@ public class SysUser extends BaseEntity
311 315
         this.roleId = roleId;
312 316
     }
313 317
 
318
+
319
+    public String getDingUserId()
320
+    {
321
+        return dingUserId;
322
+    }
323
+
324
+    public void setDingUserId(String dingUserId)
325
+    {
326
+        this.dingUserId = dingUserId;
327
+    }
328
+
314 329
     @Override
315 330
     public String toString() {
316 331
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
@@ -334,6 +349,7 @@ public class SysUser extends BaseEntity
334 349
             .append("updateTime", getUpdateTime())
335 350
             .append("remark", getRemark())
336 351
             .append("dept", getDept())
352
+            .append("dingUserId", getDingUserId())
337 353
             .toString();
338 354
     }
339 355
 }

+ 54 - 0
smart-steward-common/src/main/java/com/smartSteward/common/utils/dingTalk/DingTalkEncryptException.java

@@ -0,0 +1,54 @@
1
+package com.smartSteward.common.utils.dingTalk;
2
+
3
+import java.util.HashMap;
4
+import java.util.Map;
5
+
6
+/**
7
+ * 加解密异常类
8
+ * @author smart_Steward
9
+ */
10
+public class DingTalkEncryptException extends Exception {
11
+    /**成功**/
12
+    public static final int SUCCESS = 0;
13
+    /**加密明文文本非法**/
14
+    public final static int  ENCRYPTION_PLAINTEXT_ILLEGAL = 900001;
15
+    /**加密时间戳参数非法**/
16
+    public final static int  ENCRYPTION_TIMESTAMP_ILLEGAL = 900002;
17
+    /**加密随机字符串参数非法**/
18
+    public final static int  ENCRYPTION_NONCE_ILLEGAL = 900003;
19
+    /**不合法的aeskey**/
20
+    public final static int AES_KEY_ILLEGAL = 900004;
21
+    /**签名不匹配**/
22
+    public final static int SIGNATURE_NOT_MATCH = 900005;
23
+    /**计算签名错误**/
24
+    public final static int COMPUTE_SIGNATURE_ERROR = 900006;
25
+    /**计算加密文字错误**/
26
+    public final static int COMPUTE_ENCRYPT_TEXT_ERROR  = 900007;
27
+    /**计算解密文字错误**/
28
+    public final static int COMPUTE_DECRYPT_TEXT_ERROR  = 900008;
29
+    /**计算解密文字长度不匹配**/
30
+    public final static int COMPUTE_DECRYPT_TEXT_LENGTH_ERROR  = 900009;
31
+    /**计算解密文字suiteKey(ISV)或者corpid(普通企业)不匹配**/
32
+    public final static int COMPUTE_DECRYPT_TEXT_CORPID_ERROR  = 900010;
33
+
34
+    private static final Map<Integer,String> MSG_MAP = new HashMap<Integer,String>();
35
+    static{
36
+        MSG_MAP.put(SUCCESS,"成功");
37
+        MSG_MAP.put(ENCRYPTION_PLAINTEXT_ILLEGAL,"加密明文文本非法");
38
+        MSG_MAP.put(ENCRYPTION_TIMESTAMP_ILLEGAL,"加密时间戳参数非法");
39
+        MSG_MAP.put(ENCRYPTION_NONCE_ILLEGAL,"加密随机字符串参数非法");
40
+        MSG_MAP.put(SIGNATURE_NOT_MATCH,"签名不匹配");
41
+        MSG_MAP.put(COMPUTE_SIGNATURE_ERROR,"签名计算失败");
42
+        MSG_MAP.put(AES_KEY_ILLEGAL,"不合法的aes key");
43
+        MSG_MAP.put(COMPUTE_ENCRYPT_TEXT_ERROR,"计算加密文字错误");
44
+        MSG_MAP.put(COMPUTE_DECRYPT_TEXT_ERROR,"计算解密文字错误");
45
+        MSG_MAP.put(COMPUTE_DECRYPT_TEXT_LENGTH_ERROR,"计算解密文字长度不匹配");
46
+        MSG_MAP.put(COMPUTE_DECRYPT_TEXT_CORPID_ERROR,"计算解密文字suiteKey(ISV)或者corpid(普通企业)不匹配");
47
+    }
48
+
49
+    public Integer  code;
50
+    public DingTalkEncryptException(Integer exceptionCode){
51
+        super(MSG_MAP.get(exceptionCode));
52
+        this.code = exceptionCode;
53
+    }
54
+}

+ 207 - 0
smart-steward-common/src/main/java/com/smartSteward/common/utils/dingTalk/DingTalkEncryptor.java

@@ -0,0 +1,207 @@
1
+package com.smartSteward.common.utils.dingTalk;
2
+
3
+import java.io.ByteArrayOutputStream;
4
+import java.nio.charset.Charset;
5
+import java.nio.charset.StandardCharsets;
6
+import java.security.MessageDigest;
7
+import java.util.*;
8
+
9
+import javax.crypto.Cipher;
10
+import javax.crypto.spec.IvParameterSpec;
11
+import javax.crypto.spec.SecretKeySpec;
12
+
13
+import org.apache.commons.codec.binary.Base64;
14
+
15
+
16
+/**
17
+ * @author smart_Steward
18
+ */
19
+public class DingTalkEncryptor {
20
+
21
+    private static final Charset CHARSET = StandardCharsets.UTF_8;
22
+    private static final Base64 BASE64 = new Base64();
23
+    private final byte[] aesKey;
24
+    private final String token;
25
+    private final String corpId;
26
+    /**
27
+     * ask getPaddingBytes key固定长度
28
+     **/
29
+    private static final Integer AES_ENCODE_KEY_LENGTH = 43;
30
+    /**
31
+     * 加密随机字符串字节长度
32
+     **/
33
+    private static final Integer RANDOM_LENGTH = 16;
34
+
35
+    /**
36
+     * 构造函数
37
+     *
38
+     * @param token          钉钉开放平台上,开发者设置的token
39
+     * @param encodingAesKey 钉钉开放台上,开发者设置的EncodingAESKey
40
+     * @param corpId         ISV进行配置的时候应该传对应套件的SUITE_KEY(第一次创建时传的是默认的CREATE_SUITE_KEY),普通企业是Corpid
41
+     */
42
+    public DingTalkEncryptor(String token, String encodingAesKey, String corpId) throws DingTalkEncryptException {
43
+        if (null == encodingAesKey || encodingAesKey.length() != AES_ENCODE_KEY_LENGTH) {
44
+            throw new DingTalkEncryptException(DingTalkEncryptException.AES_KEY_ILLEGAL);
45
+        }
46
+        this.token = token;
47
+        this.corpId = corpId;
48
+        aesKey = Base64.decodeBase64(encodingAesKey + "=");
49
+    }
50
+
51
+    /**
52
+     * 将和钉钉开放平台同步的消息体加密,返回加密Map
53
+     *
54
+     * @param plaintext 传递的消息体明文
55
+     * @param timeStamp 时间戳
56
+     * @param nonce     随机字符串
57
+     */
58
+    public Map<String, String> getEncryptedMap(String plaintext, Long timeStamp, String nonce) throws DingTalkEncryptException {
59
+        if (null == plaintext) {
60
+            throw new DingTalkEncryptException(DingTalkEncryptException.ENCRYPTION_PLAINTEXT_ILLEGAL);
61
+        }
62
+        if (null == timeStamp) {
63
+            throw new DingTalkEncryptException(DingTalkEncryptException.ENCRYPTION_TIMESTAMP_ILLEGAL);
64
+        }
65
+        if (null == nonce) {
66
+            throw new DingTalkEncryptException(DingTalkEncryptException.ENCRYPTION_NONCE_ILLEGAL);
67
+        }
68
+        // 加密
69
+        String encrypt = encrypt(Utils.getRandomStr(RANDOM_LENGTH), plaintext);
70
+        String signature = getSignature(token, String.valueOf(timeStamp), nonce, encrypt);
71
+        Map<String, String> resultMap = new HashMap<String, String>();
72
+        resultMap.put("msg_signature", signature);
73
+        resultMap.put("encrypt", encrypt);
74
+        resultMap.put("timeStamp", String.valueOf(timeStamp));
75
+        resultMap.put("nonce", nonce);
76
+        return resultMap;
77
+    }
78
+
79
+    /**
80
+     * 密文解密
81
+     *
82
+     * @param msgSignature 签名串
83
+     * @param timeStamp    时间戳
84
+     * @param nonce        随机串
85
+     * @param encryptMsg   密文
86
+     * @return 解密后的原文
87
+     */
88
+    public String getDecryptMsg(String msgSignature, String timeStamp, String nonce, String encryptMsg) throws DingTalkEncryptException {
89
+        //校验签名
90
+        String signature = getSignature(token, timeStamp, nonce, encryptMsg);
91
+        if (!signature.equals(msgSignature)) {
92
+            throw new DingTalkEncryptException(DingTalkEncryptException.COMPUTE_SIGNATURE_ERROR);
93
+        }
94
+        // 解密
95
+        return decrypt(encryptMsg);
96
+    }
97
+
98
+
99
+    /*
100
+     * 对明文加密.
101
+     * @param text 需要加密的明文
102
+     * @return 加密后base64编码的字符串
103
+     */
104
+    private String encrypt(String random, String plaintext) throws DingTalkEncryptException {
105
+        try {
106
+            byte[] randomBytes = random.getBytes(CHARSET);
107
+            byte[] plainTextBytes = plaintext.getBytes(CHARSET);
108
+            byte[] lengthByte = Utils.int2Bytes(plainTextBytes.length);
109
+            byte[] corpidBytes = corpId.getBytes(CHARSET);
110
+            ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
111
+            byteStream.write(randomBytes);
112
+            byteStream.write(lengthByte);
113
+            byteStream.write(plainTextBytes);
114
+            byteStream.write(corpidBytes);
115
+            byte[] padBytes = PKCS7Padding.getPaddingBytes(byteStream.size());
116
+            byteStream.write(padBytes);
117
+            byte[] unencrypted = byteStream.toByteArray();
118
+            byteStream.close();
119
+            Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
120
+            SecretKeySpec keySpec = new SecretKeySpec(aesKey, "AES");
121
+            IvParameterSpec iv = new IvParameterSpec(aesKey, 0, 16);
122
+            cipher.init(Cipher.ENCRYPT_MODE, keySpec, iv);
123
+            byte[] encrypted = cipher.doFinal(unencrypted);
124
+            return BASE64.encodeToString(encrypted);
125
+        } catch (Exception e) {
126
+            throw new DingTalkEncryptException(DingTalkEncryptException.COMPUTE_ENCRYPT_TEXT_ERROR);
127
+        }
128
+    }
129
+
130
+    /*
131
+     * 对密文进行解密.
132
+     * @param text 需要解密的密文
133
+     * @return 解密得到的明文
134
+     */
135
+    private String decrypt(String text) throws DingTalkEncryptException {
136
+        byte[] originalArr;
137
+        try {
138
+            // 设置解密模式为AES的CBC模式
139
+            Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
140
+            SecretKeySpec keySpec = new SecretKeySpec(aesKey, "AES");
141
+            IvParameterSpec iv = new IvParameterSpec(Arrays.copyOfRange(aesKey, 0, 16));
142
+            cipher.init(Cipher.DECRYPT_MODE, keySpec, iv);
143
+            // 使用BASE64对密文进行解码
144
+            byte[] encrypted = Base64.decodeBase64(text);
145
+            // 解密
146
+            originalArr = cipher.doFinal(encrypted);
147
+        } catch (Exception e) {
148
+            throw new DingTalkEncryptException(DingTalkEncryptException.COMPUTE_DECRYPT_TEXT_ERROR);
149
+        }
150
+
151
+        String plainText;
152
+        String fromCorpid;
153
+        try {
154
+            // 去除补位字符
155
+            byte[] bytes = PKCS7Padding.removePaddingBytes(originalArr);
156
+            // 分离16位随机字符串,网络字节序和corpId
157
+            byte[] networkOrder = Arrays.copyOfRange(bytes, 16, 20);
158
+            int plainTextLegth = Utils.bytes2int(networkOrder);
159
+            plainText = new String(Arrays.copyOfRange(bytes, 20, 20 + plainTextLegth), CHARSET);
160
+            fromCorpid = new String(Arrays.copyOfRange(bytes, 20 + plainTextLegth, bytes.length), CHARSET);
161
+        } catch (Exception e) {
162
+            throw new DingTalkEncryptException(DingTalkEncryptException.COMPUTE_DECRYPT_TEXT_LENGTH_ERROR);
163
+        }
164
+
165
+        // corpid不相同的情况
166
+        if (!fromCorpid.equals(corpId)) {
167
+            throw new DingTalkEncryptException(DingTalkEncryptException.COMPUTE_DECRYPT_TEXT_CORPID_ERROR);
168
+        }
169
+        return plainText;
170
+    }
171
+
172
+    /**
173
+     * 数字签名
174
+     *
175
+     * @param token     isv token
176
+     * @param timestamp 时间戳
177
+     * @param nonce     随机串
178
+     * @param encrypt   加密文本
179
+     */
180
+    public String getSignature(String token, String timestamp, String nonce, String encrypt) throws DingTalkEncryptException {
181
+        try {
182
+            String[] array = new String[]{token, timestamp, nonce, encrypt};
183
+            Arrays.sort(array);
184
+            StringBuilder sb = new StringBuilder();
185
+            for (int i = 0; i < 4; i++) {
186
+                sb.append(array[i]);
187
+            }
188
+            String str = sb.toString();
189
+            MessageDigest md = MessageDigest.getInstance("SHA-1");
190
+            md.update(str.getBytes());
191
+            byte[] digest = md.digest();
192
+
193
+            StringBuilder hexStr = new StringBuilder();
194
+            String shaHex = "";
195
+            for (byte b : digest) {
196
+                shaHex = Integer.toHexString(b & 0xFF);
197
+                if (shaHex.length() < 2) {
198
+                    hexStr.append(0);
199
+                }
200
+                hexStr.append(shaHex);
201
+            }
202
+            return hexStr.toString();
203
+        } catch (Exception e) {
204
+            throw new DingTalkEncryptException(DingTalkEncryptException.COMPUTE_SIGNATURE_ERROR);
205
+        }
206
+    }
207
+}

+ 47 - 0
smart-steward-common/src/main/java/com/smartSteward/common/utils/dingTalk/PKCS7Padding.java

@@ -0,0 +1,47 @@
1
+package com.smartSteward.common.utils.dingTalk;
2
+
3
+import java.nio.charset.Charset;
4
+import java.nio.charset.StandardCharsets;
5
+import java.util.Arrays;
6
+
7
+/*
8
+ * PCS7算法的加密填充
9
+ */
10
+
11
+/**
12
+ * @author smart_Steward
13
+ */
14
+public class PKCS7Padding {
15
+    private final static Charset CHARSET    = StandardCharsets.UTF_8;
16
+    private final static int     BLOCK_SIZE = 32;
17
+
18
+    /**
19
+     * 填充mode字节
20
+     */
21
+    public static byte[] getPaddingBytes(int count) {
22
+        int amountToPad = BLOCK_SIZE - (count % BLOCK_SIZE);
23
+        char padChr = chr(amountToPad);
24
+        StringBuilder tmp = new StringBuilder();
25
+        for (int index = 0; index < amountToPad; index++) {
26
+            tmp.append(padChr);
27
+        }
28
+        return tmp.toString().getBytes(CHARSET);
29
+    }
30
+
31
+    /**
32
+     * 移除mode填充字节
33
+     */
34
+    public static byte[] removePaddingBytes(byte[] decrypted) {
35
+        int pad = (int) decrypted[decrypted.length - 1];
36
+        if (pad < 1 || pad > BLOCK_SIZE) {
37
+            pad = 0;
38
+        }
39
+        return Arrays.copyOfRange(decrypted, 0, decrypted.length - pad);
40
+    }
41
+
42
+    private static char chr(int a) {
43
+        byte target = (byte) (a & 0xFF);
44
+        return (char) target;
45
+    }
46
+
47
+}

+ 48 - 0
smart-steward-common/src/main/java/com/smartSteward/common/utils/dingTalk/Utils.java

@@ -0,0 +1,48 @@
1
+package com.smartSteward.common.utils.dingTalk;
2
+
3
+import java.util.Random;
4
+
5
+/**
6
+ * 加解密工具类
7
+ * @author smart_Steward
8
+ */
9
+public class Utils {
10
+    /**
11
+     *
12
+     */
13
+    public static String getRandomStr(int count) {
14
+        String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
15
+        Random random = new Random();
16
+        StringBuilder sb = new StringBuilder();
17
+        for (int i = 0; i < count; i++) {
18
+            int number = random.nextInt(base.length());
19
+            sb.append(base.charAt(number));
20
+        }
21
+        return sb.toString();
22
+    }
23
+
24
+
25
+    /*
26
+     * int转byte数组,高位在前
27
+     */
28
+    public static byte[] int2Bytes(int count) {
29
+        byte[] byteArr = new byte[4];
30
+        byteArr[3] = (byte) (count & 0xFF);
31
+        byteArr[2] = (byte) (count >> 8 & 0xFF);
32
+        byteArr[1] = (byte) (count >> 16 & 0xFF);
33
+        byteArr[0] = (byte) (count >> 24 & 0xFF);
34
+        return byteArr;
35
+    }
36
+
37
+    /**
38
+     * 高位在前bytes数组转int
39
+     */
40
+    public static int bytes2int(byte[] byteArr) {
41
+        int count = 0;
42
+        for (int i = 0; i < 4; i++) {
43
+            count <<= 8;
44
+            count |= byteArr[i] & 0xff;
45
+        }
46
+        return count;
47
+    }
48
+}

+ 1 - 1
smart-steward-common/src/main/java/com/smartSteward/common/utils/http/HttpUtils.java

@@ -127,7 +127,7 @@ public class HttpUtils
127 127
      */
128 128
     public static String sendPost(String url, String param)
129 129
     {
130
-        return sendPost(url, param, MediaType.APPLICATION_FORM_URLENCODED_VALUE);
130
+        return sendPost(url, param, MediaType.APPLICATION_JSON_VALUE);
131 131
     }
132 132
 
133 133
     /**

+ 10 - 0
smart-steward-entity/pom.xml

@@ -12,6 +12,16 @@
12 12
             <groupId>com.smartSteward</groupId>
13 13
             <artifactId>smart-steward-common</artifactId>
14 14
         </dependency>
15
+        <dependency>
16
+            <groupId>org.projectlombok</groupId>
17
+            <artifactId>lombok</artifactId>
18
+        </dependency>
19
+        <dependency>
20
+            <groupId>io.swagger</groupId>
21
+            <artifactId>swagger-annotations</artifactId>
22
+            <version>1.6.2</version>
23
+            <scope>compile</scope>
24
+        </dependency>
15 25
     </dependencies>
16 26
     <modelVersion>4.0.0</modelVersion>
17 27
 

+ 41 - 0
smart-steward-entity/src/main/java/com/smartSteward/entity/input/dingTalk/AddressListRegister.java

@@ -0,0 +1,41 @@
1
+package com.smartSteward.entity.input.dingTalk;
2
+
3
+import lombok.Data;
4
+import org.springframework.beans.factory.annotation.Value;
5
+
6
+/**
7
+ * @author smart_Steward
8
+ */
9
+@Data
10
+public class AddressListRegister {
11
+    /**通讯录用户增加 */
12
+    public static final String USER_ADD_ORG = "user_add_org";
13
+    /**通讯录用户更改*/
14
+    public static final String USER_MODIFY_ORG = "user_modify_org";
15
+    /** 通讯录用户离职 */
16
+    public static final String USER_LEAVE_ORG = "user_leave_org";
17
+    /** 通讯录用户被设为管理员 */
18
+    public static final String ORG_ADMIN_ADD = "org_admin_add";
19
+    /** 通讯录用户被取消设置管理员 */
20
+    public static final String ORG_ADMIN_REMOVE = "org_admin_remove";
21
+    /**通讯录企业部门创建*/
22
+    public static final String ORG_DEPT_CREATE = "org_dept_create";
23
+    /** 通讯录企业部门修改 */
24
+    public static final String ORG_DEPT_MODIFY = "org_dept_modify";
25
+    /**通讯录企业部门删除*/
26
+    public static final String ORG_DEPT_REMOVE = "org_dept_remove";
27
+    /**企业被解散*/
28
+    public static final String ORG_REMOVE = "org_remove";
29
+    /**企业信息发生变更*/
30
+    public static final String ORG_CHANGE = "org_change";
31
+    /**员工角色信息发生变更*/
32
+    public static final String LABEL_USER_CHANGE = "label_user_change";
33
+    /**增加角色或者角色组*/
34
+    public static final String LABEL_CONF_ADD = "label_conf_add";
35
+    /**删除角色或者角色组*/
36
+    public static final String LABEL_CONF_DEL = "label_conf_del";
37
+    /**修改角色或者角色组*/
38
+    public static final String LABEL_CONF_MODIFY = "label_conf_modify";
39
+    /**测试回调接口事件类型*/
40
+    public static final String CHECK_URL = "check_url";
41
+}

+ 22 - 0
smart-steward-entity/src/main/java/com/smartSteward/entity/view/dingTalk/DingTalkDept.java

@@ -0,0 +1,22 @@
1
+package com.smartSteward.entity.view.dingTalk;
2
+
3
+import com.fasterxml.jackson.annotation.JsonProperty;
4
+import io.swagger.annotations.ApiModelProperty;
5
+import lombok.Data;
6
+
7
+/**
8
+ * @author smart_Steward
9
+ */
10
+@Data
11
+public class DingTalkDept {
12
+    @JsonProperty("dept_id")
13
+    @ApiModelProperty("部门ID")
14
+    private  Long deptId;
15
+    @JsonProperty("name")
16
+    @ApiModelProperty("部门名称")
17
+    private  String name;
18
+    @JsonProperty("parent_id")
19
+    @ApiModelProperty("父部门ID")
20
+    private  Long parentId;
21
+
22
+}

+ 53 - 0
smart-steward-entity/src/main/java/com/smartSteward/entity/view/dingTalk/DingTalkUser.java

@@ -0,0 +1,53 @@
1
+package com.smartSteward.entity.view.dingTalk;
2
+
3
+import com.fasterxml.jackson.annotation.JsonProperty;
4
+import io.swagger.annotations.ApiModelProperty;
5
+import lombok.Data;
6
+
7
+import java.util.List;
8
+
9
+/**
10
+ * @author smart_Steward
11
+ */
12
+@Data
13
+public class DingTalkUser {
14
+    @JsonProperty("userid")
15
+    @ApiModelProperty("员工的userId")
16
+    private  String userid;
17
+    @JsonProperty("unionid")
18
+    @ApiModelProperty("员工在当前开发者企业账号范围内的唯一标识")
19
+    private  String unionId;
20
+    @ApiModelProperty("员工姓名")
21
+    @JsonProperty("name")
22
+    private  String name;
23
+    @ApiModelProperty("头像")
24
+    @JsonProperty("avatar")
25
+    private  String avatar;
26
+    @ApiModelProperty("员工直属主管")
27
+    @JsonProperty("manager_userid")
28
+    private  String managerUserid;
29
+    @ApiModelProperty("手机号")
30
+    @JsonProperty("mobile")
31
+    private  String mobile;
32
+    @ApiModelProperty("分机号")
33
+    @JsonProperty("telephone")
34
+    private  String telephone;
35
+    @ApiModelProperty("工号")
36
+    @JsonProperty("job_number")
37
+    private  String jobNumber;
38
+    @ApiModelProperty("职位")
39
+    @JsonProperty("title")
40
+    private  String title;
41
+    @ApiModelProperty("邮箱")
42
+    @JsonProperty("email")
43
+    private  String email;
44
+    @ApiModelProperty("办公地点")
45
+    @JsonProperty("work_place")
46
+    private  String workPlace;
47
+    @ApiModelProperty("备注")
48
+    @JsonProperty("remark")
49
+    private  String remark;
50
+    @ApiModelProperty("所属部门id列表")
51
+    @JsonProperty("dept_id_list")
52
+    private List<Long> deptIdList;
53
+}

+ 1 - 1
smart-steward-framework/pom.xml

@@ -60,7 +60,7 @@
60 60
         <dependency>
61 61
             <groupId>com.github.oshi</groupId>
62 62
             <artifactId>oshi-core</artifactId>
63
-            <version>6.8.3</version>
63
+            <version>6.4.0</version>
64 64
         </dependency>
65 65
         <dependency>
66 66
             <groupId>com.smartSteward</groupId>

+ 14 - 30
smart-steward-framework/src/main/java/com/smartSteward/framework/web/service/SysLoginService.java

@@ -120,28 +120,33 @@ public class SysLoginService
120 120
      */
121 121
     public String loginByDingTalk(String authCode)
122 122
     {
123
-        //通过Code获取钉钉用户手机号
124
-        String mobile=dingTalkService.getUserMobile(authCode);
125
-        // 手机号前置校验
126
-        loginByMobilePreCheck(mobile);
123
+        //通过Code获取钉钉用户userid
124
+        String dingUser =dingTalkService.getUserByUserId(authCode);
125
+        // IP黑名单校验
126
+        String blackStr = configService.selectConfigByKey("sys.login.blackIPList");
127
+        if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr()))
128
+        {
129
+            AsyncManager.me().execute(AsyncFactory.recordLogininfor(dingUser, Constants.LOGIN_FAIL, MessageUtils.message("login.blocked")));
130
+            throw new BlackListException();
131
+        }
127 132
 
128
-        // 通过手机号获取用户
129
-        SysUser user = userService.selectUserByMobile(mobile);
133
+        // 通过钉钉UserId获取用户
134
+        SysUser user = userService.selectUserByDingUserId(dingUser);
130 135
         if (StringUtils.isNull(user))
131 136
         {
132
-            AsyncManager.me().execute(AsyncFactory.recordLogininfor(mobile, Constants.LOGIN_FAIL, MessageUtils.message("user.not.exists")));
137
+            AsyncManager.me().execute(AsyncFactory.recordLogininfor(dingUser, Constants.LOGIN_FAIL, MessageUtils.message("user.not.exists")));
133 138
             throw new UserNotExistsException();
134 139
         }
135 140
 
136 141
         // 检查用户状态
137 142
         if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
138 143
         {
139
-            AsyncManager.me().execute(AsyncFactory.recordLogininfor(mobile, Constants.LOGIN_FAIL, MessageUtils.message("user.password.delete")));
144
+            AsyncManager.me().execute(AsyncFactory.recordLogininfor(dingUser, Constants.LOGIN_FAIL, MessageUtils.message("user.password.delete")));
140 145
             throw new ServiceException(MessageUtils.message("user.password.delete"));
141 146
         }
142 147
         if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
143 148
         {
144
-            AsyncManager.me().execute(AsyncFactory.recordLogininfor(mobile, Constants.LOGIN_FAIL, MessageUtils.message("user.blocked", user.getRemark())));
149
+            AsyncManager.me().execute(AsyncFactory.recordLogininfor(dingUser, Constants.LOGIN_FAIL, MessageUtils.message("user.blocked", user.getRemark())));
145 150
             throw new ServiceException(MessageUtils.message("user.blocked", user.getRemark()));
146 151
         }
147 152
         // 构建登录用户信息
@@ -159,34 +164,13 @@ public class SysLoginService
159 164
         return tokenService.createToken(loginUser);
160 165
     }
161 166
 
162
-    /**
163
-     * 手机号登录前置校验
164
-     * @param mobile 手机号
165
-     */
166
-    public void loginByMobilePreCheck(String mobile)
167
-    {
168
-        // 手机号为空 错误
169
-        if (StringUtils.isEmpty(mobile))
170
-        {
171
-            AsyncManager.me().execute(AsyncFactory.recordLogininfor("", Constants.LOGIN_FAIL, MessageUtils.message("user.mobile.not.null")));
172
-            throw new UserNotExistsException();
173
-        }
174 167
 
175
-        // IP黑名单校验
176
-        String blackStr = configService.selectConfigByKey("sys.login.blackIPList");
177
-        if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr()))
178
-        {
179
-            AsyncManager.me().execute(AsyncFactory.recordLogininfor(mobile, Constants.LOGIN_FAIL, MessageUtils.message("login.blocked")));
180
-            throw new BlackListException();
181
-        }
182
-    }
183 168
     /**
184 169
      * 校验验证码
185 170
      * 
186 171
      * @param username 用户名
187 172
      * @param code 验证码
188 173
      * @param uuid 唯一标识
189
-     * @return 结果
190 174
      */
191 175
     public void validateCaptcha(String username, String code, String uuid)
192 176
     {

+ 13 - 1
smart-steward-mapper/src/main/java/com/smartSteward/mapper/system/SysDeptMapper.java

@@ -43,6 +43,13 @@ public interface SysDeptMapper
43 43
      * @return 部门列表
44 44
      */
45 45
     public List<SysDept> selectChildrenDeptById(Long deptId);
46
+    /**
47
+     * 查询钉钉部门
48
+     *
49
+     * @param dingDeptId 钉钉部门id
50
+     * @return 部门列表
51
+     */
52
+    public List<SysDept> selectDingDeptList(List<Long>dingDeptId);
46 53
 
47 54
     /**
48 55
      * 根据ID查询所有子部门(正常状态)
@@ -51,7 +58,6 @@ public interface SysDeptMapper
51 58
      * @return 子部门数
52 59
      */
53 60
     public int selectNormalChildrenDeptById(Long deptId);
54
-
55 61
     /**
56 62
      * 是否存在子节点
57 63
      * 
@@ -85,6 +91,9 @@ public interface SysDeptMapper
85 91
      */
86 92
     public int insertDept(SysDept dept);
87 93
 
94
+
95
+
96
+
88 97
     /**
89 98
      * 修改部门信息
90 99
      * 
@@ -100,6 +109,9 @@ public interface SysDeptMapper
100 109
      */
101 110
     public void updateDeptStatusNormal(Long[] deptIds);
102 111
 
112
+
113
+
114
+
103 115
     /**
104 116
      * 修改子元素关系
105 117
      * 

+ 10 - 1
smart-steward-mapper/src/main/java/com/smartSteward/mapper/system/SysUserMapper.java

@@ -21,6 +21,15 @@ public interface SysUserMapper
21 21
     public List<SysUser> selectUserList(SysUser sysUser);
22 22
 
23 23
     /**
24
+     * 查询所有用户
25
+     *
26
+     * @return 用户信息集合信息
27
+     */
28
+    public List<SysUser> selectAllUserList();
29
+
30
+
31
+
32
+    /**
24 33
      * 根据条件分页查询已配用户角色列表
25 34
      * 
26 35
      * @param user 用户信息
@@ -52,7 +61,7 @@ public interface SysUserMapper
52 61
      */
53 62
     public SysUser selectUserById(Long userId);
54 63
 
55
-    public SysUser selectUserByMobile(String mobile);
64
+    public SysUser selectUserByDingUserId(String dingUserId);
56 65
 
57 66
     /**
58 67
      * 新增用户信息

+ 2 - 2
smart-steward-mapper/src/main/resources/generator.yml

@@ -1,9 +1,9 @@
1 1
 # 代码生成
2 2
 gen:
3 3
   # 作者
4
-  author: ruoyi
4
+  author: smart-steward
5 5
   # 默认生成包路径 system 需改成自己的模块名称 如 system monitor tool
6
-  packageName: com.ruoyi.system
6
+  packageName: com.smartSteward.system
7 7
   # 自动去除表前缀,默认是false
8 8
   autoRemovePre: false
9 9
   # 表前缀(生成类名不会包含表前缀,多个用逗号分隔)

+ 27 - 3
smart-steward-mapper/src/main/resources/mapper/system/SysDeptMapper.xml

@@ -20,10 +20,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
20 20
 		<result property="createTime" column="create_time" />
21 21
 		<result property="updateBy"   column="update_by"   />
22 22
 		<result property="updateTime" column="update_time" />
23
+		<result property="dingDeptId" column="ding_dept_id" />
24
+		<result property="dingParentId" column="ding_parent_id" />
23 25
 	</resultMap>
24 26
 	
25 27
 	<sql id="selectDeptVo">
26
-        select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time 
28
+        select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time ,d.ding_dept_id ,ding_parent_id
27 29
         from sys_dept d
28 30
     </sql>
29 31
     
@@ -46,6 +48,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
46 48
 		${params.dataScope}
47 49
 		order by d.parent_id, d.order_num
48 50
     </select>
51
+
52
+
53
+
54
+	<select id="selectDingDeptList" parameterType="SysDept" resultMap="SysDeptResult">
55
+		<include refid="selectDeptVo"/>
56
+		where d.del_flag = '0' and ding_dept_id in
57
+		<foreach collection="array" item="dingDeptId" open="(" separator="," close=")">
58
+			#{dingDeptId}
59
+		</foreach>
60
+		order by d.dept_id desc
61
+	</select>
62
+
49 63
     
50 64
     <select id="selectDeptListByRoleId" resultType="Long">
51 65
 		select d.dept_id
@@ -59,7 +73,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
59 73
 	</select>
60 74
     
61 75
     <select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult">
62
-		select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status,
76
+		select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status,ding_dept_id,ding_parent_id,
63 77
 			(select dept_name from sys_dept where dept_id = d.parent_id) parent_name
64 78
 		from sys_dept d
65 79
 		where d.dept_id = #{deptId}
@@ -87,7 +101,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
87 101
 		where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
88 102
 	</select>
89 103
     
90
-    <insert id="insertDept" parameterType="SysDept">
104
+    <insert id="insertDept" parameterType="SysDept" useGeneratedKeys="true" keyProperty="deptId">
91 105
  		insert into sys_dept(
92 106
  			<if test="deptId != null and deptId != 0">dept_id,</if>
93 107
  			<if test="parentId != null and parentId != 0">parent_id,</if>
@@ -99,6 +113,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
99 113
  			<if test="email != null and email != ''">email,</if>
100 114
  			<if test="status != null">status,</if>
101 115
  			<if test="createBy != null and createBy != ''">create_by,</if>
116
+		    <if test="dingDeptId != null and dingDeptId != ''">ding_dept_id,</if>
117
+		    <if test="dingParentId != null and dingParentId != ''">ding_parent_id,</if>
102 118
  			create_time
103 119
  		)values(
104 120
  			<if test="deptId != null and deptId != 0">#{deptId},</if>
@@ -111,6 +127,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
111 127
  			<if test="email != null and email != ''">#{email},</if>
112 128
  			<if test="status != null">#{status},</if>
113 129
  			<if test="createBy != null and createBy != ''">#{createBy},</if>
130
+		    <if test="dingDeptId != null and dingDeptId !='' ">#{dingDeptId},</if>
131
+		    <if test="dingParentId != null and dingParentId !='' ">#{dingParentId},</if>
114 132
  			sysdate()
115 133
  		)
116 134
 	</insert>
@@ -127,6 +145,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
127 145
  			<if test="email != null">email = #{email},</if>
128 146
  			<if test="status != null and status != ''">status = #{status},</if>
129 147
  			<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
148
+			<if test="dingDeptId != null and dingDeptId !=''  ">ding_dept_id = #{dingDeptId},</if>
149
+			<if test="dingParentId != null and dingParentId !=''  ">ding_parent_id = #{dingParentId},</if>
130 150
  			update_time = sysdate()
131 151
  		</set>
132 152
  		where dept_id = #{deptId}
@@ -156,4 +176,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
156 176
 		update sys_dept set del_flag = '2' where dept_id = #{deptId}
157 177
 	</delete>
158 178
 
179
+
180
+
181
+
182
+
159 183
 </mapper> 

+ 16 - 7
smart-steward-mapper/src/main/resources/mapper/system/SysUserMapper.xml

@@ -24,6 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
24 24
         <result property="updateBy"      column="update_by"       />
25 25
         <result property="updateTime"    column="update_time"     />
26 26
         <result property="remark"        column="remark"          />
27
+		<result property="dingUserId"    column="ding_user_id"    />
27 28
         <association property="dept"     javaType="SysDept"         resultMap="deptResult" />
28 29
         <collection  property="roles"    javaType="java.util.List"  resultMap="RoleResult" />
29 30
     </resultMap>
@@ -48,8 +49,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
48 49
     </resultMap>
49 50
 	
50 51
 	<sql id="selectUserVo">
51
-        select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.pwd_update_date, u.create_by, u.create_time, u.remark, 
52
-        d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status,
52
+        select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.pwd_update_date, u.create_by, u.create_time, u.remark, u.ding_user_id,
53
+        d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status ,
53 54
         r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
54 55
         from sys_user u
55 56
 		    left join sys_dept d on u.dept_id = d.dept_id
@@ -58,7 +59,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
58 59
     </sql>
59 60
     
60 61
     <select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult">
61
-		select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from sys_user u
62
+		select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, u.ding_user_id, d.dept_name, d.leader from sys_user u
62 63
 		left join sys_dept d on u.dept_id = d.dept_id
63 64
 		where u.del_flag = '0'
64 65
 		<if test="userId != null and userId != 0">
@@ -120,6 +121,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
120 121
 		<!-- 数据范围过滤 -->
121 122
 		${params.dataScope}
122 123
 	</select>
124
+
125
+	<select id="selectAllUserList"  resultMap="SysUserResult">
126
+		<include refid="selectUserVo"/>
127
+		where u.del_flag = '0'
128
+	</select>
123 129
 	
124 130
 	<select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult">
125 131
 	    <include refid="selectUserVo"/>
@@ -131,9 +137,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
131 137
 		where u.user_id = #{userId}
132 138
 	</select>
133 139
 
134
-	<select id="selectUserByMobile" parameterType="String" resultMap="SysUserResult">
140
+	<select id="selectUserByDingUserID" parameterType="String" resultMap="SysUserResult">
135 141
 		<include refid="selectUserVo"/>
136
-		where u.phonenumber = #{mobile}  limit 1
142
+		where u.ding_user_id = #{dingUserId}  limit 1
137 143
 	</select>
138 144
 	
139 145
 	<select id="checkUserNameUnique" parameterType="String" resultMap="SysUserResult">
@@ -163,10 +169,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
163 169
  			<if test="pwdUpdateDate != null">pwd_update_date,</if>
164 170
  			<if test="createBy != null and createBy != ''">create_by,</if>
165 171
  			<if test="remark != null and remark != ''">remark,</if>
172
+		    <if test="dingUserId != null and dingUserId != ''">ding_user_id,</if>
166 173
  			create_time
167 174
  		)values(
168
- 			<if test="userId != null and userId != ''">#{userId},</if>
169
- 			<if test="deptId != null and deptId != ''">#{deptId},</if>
175
+ 			<if test="userId != null and userId != 0">#{userId},</if>
176
+ 			<if test="deptId != null and deptId != 0">#{deptId},</if>
170 177
  			<if test="userName != null and userName != ''">#{userName},</if>
171 178
  			<if test="nickName != null and nickName != ''">#{nickName},</if>
172 179
  			<if test="email != null and email != ''">#{email},</if>
@@ -178,6 +185,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
178 185
  			<if test="pwdUpdateDate != null">#{pwdUpdateDate},</if>
179 186
  			<if test="createBy != null and createBy != ''">#{createBy},</if>
180 187
  			<if test="remark != null and remark != ''">#{remark},</if>
188
+		    <if test="dingUserId != null and dingUserId != ''">#{dingUserId},</if>
181 189
  			sysdate()
182 190
  		)
183 191
 	</insert>
@@ -197,6 +205,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
197 205
  			<if test="loginDate != null">login_date = #{loginDate},</if>
198 206
  			<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
199 207
  			<if test="remark != null">remark = #{remark},</if>
208
+			<if test="dingUserId != null">ding_user_id = #{dingUserId},</if>
200 209
  			update_time = sysdate()
201 210
  		</set>
202 211
  		where user_id = #{userId}

+ 8 - 1
smart-steward-service/src/main/java/com/smartSteward/service/dingTalk/IDingTalkService.java

@@ -1,10 +1,17 @@
1 1
 package com.smartSteward.service.dingTalk;
2 2
 
3
+import org.springframework.transaction.annotation.Transactional;
4
+
3 5
 /**
4 6
  * 通用钉钉访问
5 7
  *
6 8
  * @author smart-steward
7 9
  */
8 10
 public interface IDingTalkService {
9
-    String getUserMobile(String authCode) ;
11
+    @Transactional(rollbackFor = Exception.class)
12
+    void synchronize() throws Exception;
13
+
14
+    String getUserByUserId(String authCode) ;
15
+
16
+    boolean receive(String signature, String timestamp, String nonce, String requestBody);
10 17
 }

File diff suppressed because it is too large
+ 1007 - 206
smart-steward-service/src/main/java/com/smartSteward/service/dingTalk/impl/DingTalkServiceImpl.java


+ 5 - 0
smart-steward-service/src/main/java/com/smartSteward/service/system/ISysDeptService.java

@@ -106,6 +106,9 @@ public interface ISysDeptService
106 106
      */
107 107
     public int insertDept(SysDept dept);
108 108
 
109
+
110
+    int insertDingDept(SysDept dept);
111
+
109 112
     /**
110 113
      * 修改保存部门信息
111 114
      * 
@@ -114,6 +117,8 @@ public interface ISysDeptService
114 117
      */
115 118
     public int updateDept(SysDept dept);
116 119
 
120
+    List<SysDept> selectDingDeptList(List<Long> dingDeptId);
121
+
117 122
     /**
118 123
      * 删除部门管理信息
119 124
      * 

+ 13 - 2
smart-steward-service/src/main/java/com/smartSteward/service/system/ISysUserService.java

@@ -3,6 +3,7 @@ package com.smartSteward.service.system;
3 3
 import java.util.Date;
4 4
 import java.util.List;
5 5
 import com.smartSteward.common.core.database.system.SysUser;
6
+import org.springframework.transaction.annotation.Transactional;
6 7
 
7 8
 /**
8 9
  * 用户 业务层
@@ -43,6 +44,8 @@ public interface ISysUserService
43 44
      */
44 45
     public SysUser selectUserByUserName(String userName);
45 46
 
47
+    List<SysUser> selectAllUserList();
48
+
46 49
     /**
47 50
      * 通过用户ID查询用户
48 51
      * 
@@ -50,8 +53,13 @@ public interface ISysUserService
50 53
      * @return 用户对象信息
51 54
      */
52 55
     public SysUser selectUserById(Long userId);
53
-
54
-    SysUser selectUserByMobile(String mobile);
56
+    /**
57
+     * 根据钉钉UserId查询用户信息
58
+     *
59
+     * @param dingUserId 用户名
60
+     * @return 结果
61
+     */
62
+    SysUser selectUserByDingUserId(String dingUserId);
55 63
 
56 64
     /**
57 65
      * 根据用户ID查询用户所属角色组
@@ -131,6 +139,9 @@ public interface ISysUserService
131 139
      */
132 140
     public int updateUser(SysUser user);
133 141
 
142
+    @Transactional
143
+    int updateDingUser(SysUser user);
144
+
134 145
     /**
135 146
      * 用户授权角色
136 147
      * 

+ 10 - 2
smart-steward-service/src/main/java/com/smartSteward/service/system/impl/SysDeptServiceImpl.java

@@ -220,7 +220,11 @@ public class SysDeptServiceImpl implements ISysDeptService
220 220
         dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
221 221
         return deptMapper.insertDept(dept);
222 222
     }
223
-
223
+    @Override
224
+    public int insertDingDept(SysDept dept)
225
+    {
226
+        return deptMapper.insertDept(dept);
227
+    }
224 228
     /**
225 229
      * 修改保存部门信息
226 230
      * 
@@ -280,7 +284,11 @@ public class SysDeptServiceImpl implements ISysDeptService
280 284
             deptMapper.updateDeptChildren(children);
281 285
         }
282 286
     }
283
-
287
+    @Override
288
+    public List<SysDept> selectDingDeptList(List<Long> dingDeptId)
289
+    {
290
+        return deptMapper.selectDingDeptList(dingDeptId);
291
+    }
284 292
     /**
285 293
      * 删除部门管理信息
286 294
      * 

+ 24 - 4
smart-steward-service/src/main/java/com/smartSteward/service/system/impl/SysUserServiceImpl.java

@@ -118,6 +118,18 @@ public class SysUserServiceImpl implements ISysUserService
118 118
     }
119 119
 
120 120
     /**
121
+     * 查询所有用户
122
+     *
123
+     * @return 用户对象信息
124
+     */
125
+    @Override
126
+    public List<SysUser> selectAllUserList()
127
+    {
128
+        return userMapper.selectAllUserList();
129
+    }
130
+
131
+
132
+    /**
121 133
      * 通过用户ID查询用户
122 134
      * 
123 135
      * @param userId 用户ID
@@ -130,14 +142,14 @@ public class SysUserServiceImpl implements ISysUserService
130 142
     }
131 143
 
132 144
     /**
133
-     * 通过用户手机号查询用户
145
+     * 通过用户钉钉useId查询用户
134 146
      *
135
-     * @param mobile 用户手机号
147
+     * @param dingUserId 用户手机号
136 148
      * @return 用户对象信息
137 149
      */
138 150
     @Override
139
-    public SysUser selectUserByMobile(String mobile) {
140
-        return userMapper.selectUserByMobile(mobile);
151
+    public SysUser selectUserByDingUserId(String dingUserId) {
152
+        return userMapper.selectUserByDingUserId(dingUserId);
141 153
     }
142 154
 
143 155
     /**
@@ -315,6 +327,13 @@ public class SysUserServiceImpl implements ISysUserService
315 327
         return userMapper.updateUser(user);
316 328
     }
317 329
 
330
+    @Override
331
+    @Transactional
332
+    public int updateDingUser(SysUser user)
333
+    {
334
+        return userMapper.updateUser(user);
335
+    }
336
+
318 337
     /**
319 338
      * 用户授权角色
320 339
      * 
@@ -374,6 +393,7 @@ public class SysUserServiceImpl implements ISysUserService
374 393
      * @param loginDate 登录时间
375 394
      * @return 结果
376 395
      */
396
+    @Override
377 397
     public void updateLoginInfo(Long userId, String loginIp, Date loginDate)
378 398
     {
379 399
         userMapper.updateLoginInfo(userId, loginIp, loginDate);