张延森 преди 3 години
родител
ревизия
c3e8adbc2c
променени са 58 файла, в които са добавени 1830 реда и са изтрити 315 реда
  1. 14
    0
      pom.xml
  2. 42
    2
      src/main/java/com/yunzhi/nanyang/common/BaseController.java
  3. 8
    0
      src/main/java/com/yunzhi/nanyang/common/Constants.java
  4. 107
    9
      src/main/java/com/yunzhi/nanyang/common/OSSUtils.java
  5. 62
    12
      src/main/java/com/yunzhi/nanyang/common/WxUtils.java
  6. 8
    7
      src/main/java/com/yunzhi/nanyang/config/AliyunConfig.java
  7. 119
    0
      src/main/java/com/yunzhi/nanyang/controller/CommController.java
  8. 119
    0
      src/main/java/com/yunzhi/nanyang/controller/SysMiniappController.java
  9. 4
    1
      src/main/java/com/yunzhi/nanyang/controller/SysSettingController.java
  10. 30
    10
      src/main/java/com/yunzhi/nanyang/controller/SysUserController.java
  11. 39
    13
      src/main/java/com/yunzhi/nanyang/controller/TaBannerController.java
  12. 40
    15
      src/main/java/com/yunzhi/nanyang/controller/TaExtendContentController.java
  13. 75
    75
      src/main/java/com/yunzhi/nanyang/controller/TaImagesController.java
  14. 68
    19
      src/main/java/com/yunzhi/nanyang/controller/TaMachineryController.java
  15. 68
    17
      src/main/java/com/yunzhi/nanyang/controller/TaNewsController.java
  16. 48
    8
      src/main/java/com/yunzhi/nanyang/controller/TaNewsTypeController.java
  17. 80
    61
      src/main/java/com/yunzhi/nanyang/controller/TaPersonController.java
  18. 62
    16
      src/main/java/com/yunzhi/nanyang/controller/TdMachineryTypeController.java
  19. 173
    0
      src/main/java/com/yunzhi/nanyang/controller/WxMaController.java
  20. 55
    0
      src/main/java/com/yunzhi/nanyang/entity/SysMiniapp.java
  21. 1
    1
      src/main/java/com/yunzhi/nanyang/entity/TaBanner.java
  22. 1
    1
      src/main/java/com/yunzhi/nanyang/entity/TaExtendContent.java
  23. 1
    1
      src/main/java/com/yunzhi/nanyang/entity/TaImages.java
  24. 8
    2
      src/main/java/com/yunzhi/nanyang/entity/TaMachinery.java
  25. 8
    2
      src/main/java/com/yunzhi/nanyang/entity/TaNews.java
  26. 1
    1
      src/main/java/com/yunzhi/nanyang/entity/TaNewsType.java
  27. 5
    2
      src/main/java/com/yunzhi/nanyang/entity/TaPerson.java
  28. 2
    2
      src/main/java/com/yunzhi/nanyang/entity/TdMachineryType.java
  29. 22
    0
      src/main/java/com/yunzhi/nanyang/mapper/SysMiniappMapper.java
  30. 4
    0
      src/main/java/com/yunzhi/nanyang/mapper/SysUserDataScopeMapper.java
  31. 4
    0
      src/main/java/com/yunzhi/nanyang/mapper/TaImagesMapper.java
  32. 4
    0
      src/main/java/com/yunzhi/nanyang/mapper/TaPersonMapper.java
  33. 17
    0
      src/main/java/com/yunzhi/nanyang/service/ISysMiniappService.java
  34. 6
    0
      src/main/java/com/yunzhi/nanyang/service/ISysUserDataScopeService.java
  35. 5
    0
      src/main/java/com/yunzhi/nanyang/service/ITaExtendContentService.java
  36. 5
    0
      src/main/java/com/yunzhi/nanyang/service/ITaMachineryService.java
  37. 1
    0
      src/main/java/com/yunzhi/nanyang/service/ITaPersonService.java
  38. 24
    0
      src/main/java/com/yunzhi/nanyang/service/impl/SysMiniappServiceImpl.java
  39. 42
    0
      src/main/java/com/yunzhi/nanyang/service/impl/SysUserDataScopeServiceImpl.java
  40. 40
    0
      src/main/java/com/yunzhi/nanyang/service/impl/TaExtendContentServiceImpl.java
  41. 113
    0
      src/main/java/com/yunzhi/nanyang/service/impl/TaMachineryServiceImpl.java
  42. 4
    0
      src/main/java/com/yunzhi/nanyang/service/impl/TaPersonServiceImpl.java
  43. 35
    5
      src/main/java/com/yunzhi/nanyang/shiro/ShiroConfig.java
  44. 7
    26
      src/main/java/com/yunzhi/nanyang/shiro/filters/JWTFilter.java
  45. 29
    0
      src/main/java/com/yunzhi/nanyang/shiro/filters/ManagerFilter.java
  46. 25
    0
      src/main/java/com/yunzhi/nanyang/shiro/filters/MiniappFilter.java
  47. 9
    0
      src/main/java/com/yunzhi/nanyang/shiro/realms/manager/ManagerRealm.java
  48. 44
    0
      src/main/java/com/yunzhi/nanyang/shiro/realms/miniapp/MiniappRealm.java
  49. 23
    0
      src/main/java/com/yunzhi/nanyang/shiro/utils/MiniappToken.java
  50. 3
    0
      src/main/java/com/yunzhi/nanyang/vo/LoginParam.java
  51. 17
    0
      src/main/java/com/yunzhi/nanyang/vo/PhoneParam.java
  52. 26
    0
      src/main/java/com/yunzhi/nanyang/vo/WxMaAuthParam.java
  53. 32
    0
      src/main/java/com/yunzhi/nanyang/vo/WxMaPreload.java
  54. 15
    6
      src/main/resources/application.yml
  55. 1
    1
      src/main/resources/mapper/SysMenuMapper.xml
  56. 5
    0
      src/main/resources/mapper/SysMiniappMapper.xml
  57. 8
    0
      src/main/resources/mapper/SysUserDataScopeMapper.xml
  58. 12
    0
      src/main/resources/mapper/TaImagesMapper.xml

+ 14
- 0
pom.xml Целия файл

@@ -25,6 +25,12 @@
25 25
 			<artifactId>spring-boot-starter-web</artifactId>
26 26
 		</dependency>
27 27
 
28
+		<dependency>
29
+			<groupId>org.springframework.boot</groupId>
30
+			<artifactId>spring-boot-configuration-processor</artifactId>
31
+			<optional>true</optional>
32
+		</dependency>
33
+
28 34
 		<dependency>
29 35
 			<groupId>org.springframework.boot</groupId>
30 36
 			<artifactId>spring-boot-starter-test</artifactId>
@@ -140,6 +146,14 @@
140 146
 					<plugin>
141 147
 						<groupId>org.springframework.boot</groupId>
142 148
 						<artifactId>spring-boot-maven-plugin</artifactId>
149
+						<configuration>
150
+							<excludes>
151
+								<exclude>
152
+									<groupId>org.springframework.boot</groupId>
153
+									<artifactId>spring-boot-configuration-processor</artifactId>
154
+								</exclude>
155
+							</excludes>
156
+						</configuration>
143 157
 					</plugin>
144 158
 				</plugins>
145 159
 				<resources>

+ 42
- 2
src/main/java/com/yunzhi/nanyang/common/BaseController.java Целия файл

@@ -1,27 +1,45 @@
1 1
 package com.yunzhi.nanyang.common;
2 2
 
3 3
 import com.yunzhi.nanyang.entity.SysUser;
4
+import com.yunzhi.nanyang.entity.TaPerson;
5
+import com.yunzhi.nanyang.service.ISysUserDataScopeService;
4 6
 import com.yunzhi.nanyang.service.ISysUserService;
7
+import com.yunzhi.nanyang.service.ITaPersonService;
8
+import com.yunzhi.nanyang.shiro.realms.manager.ManagerRealm;
5 9
 import com.yunzhi.nanyang.shiro.utils.JWTUtil;
6 10
 import org.apache.shiro.SecurityUtils;
7 11
 import org.apache.shiro.subject.Subject;
8 12
 import org.springframework.beans.factory.annotation.Autowired;
9 13
 import org.springframework.stereotype.Component;
10 14
 
15
+import java.util.Arrays;
16
+import java.util.Collection;
17
+import java.util.List;
18
+
11 19
 @Component
12 20
 public class BaseController {
13 21
 
14 22
     @Autowired
15 23
     ISysUserService iSysUserService;
16 24
 
17
-    public String currentLoginId() {
25
+    @Autowired
26
+    ITaPersonService iTaPersonService;
27
+
28
+    @Autowired
29
+    ISysUserDataScopeService iSysUserDataScopeService;
30
+
31
+    public String getLoginId() {
18 32
         Subject subject = SecurityUtils.getSubject();
19 33
         String token = subject.getPrincipal().toString();
34
+
35
+//        List<Object> list = Arrays.asList(subject.getPrincipals().fromRealm("managerRealm").toArray());
36
+//        String token = list.get(0).toString();
37
+
20 38
         return JWTUtil.getLoginId(token);
21 39
     }
22 40
 
23 41
     public SysUser currentUser() throws Exception {
24
-        String loginId = currentLoginId();
42
+        String loginId = getLoginId();
25 43
         if (StringUtils.isEmpty(loginId)) {
26 44
             throw new Exception("请先登录");
27 45
         }
@@ -33,4 +51,26 @@ public class BaseController {
33 51
 
34 52
         return user;
35 53
     }
54
+
55
+    public TaPerson currentPerson() throws Exception {
56
+        String personId = getLoginId();
57
+        if (StringUtils.isEmpty(personId)) {
58
+            throw new Exception("请先登录");
59
+        }
60
+
61
+        TaPerson taPerson = iTaPersonService.getById(personId);
62
+        if (taPerson == null || taPerson.getStatus() == Constants.STATUS_DELETE) {
63
+            throw new Exception("人员不存在");
64
+        }
65
+
66
+        return taPerson;
67
+    }
68
+
69
+    public boolean checkOrgAccess(String orgId, String userId) {
70
+        return iSysUserDataScopeService.checkOrgAccess(orgId, userId);
71
+    }
72
+
73
+    public List<String> getAccessOrgs(String userId) {
74
+        return iSysUserDataScopeService.getAccessOrgs(userId);
75
+    }
36 76
 }

+ 8
- 0
src/main/java/com/yunzhi/nanyang/common/Constants.java Целия файл

@@ -6,4 +6,12 @@ public class Constants {
6 6
     public final static int STATUS_DELETE = -1;
7 7
     public final static int STATUS_READY = 0;
8 8
     public final static int STATUS_NORMAL = 1;
9
+
10
+    //
11
+    public final static String CLIENT_WORKER = "worker";    // 农机手
12
+    public final static String CLIENT_FARMER = "farmer";    // 农户
13
+
14
+    // 资源类型
15
+    public final static String TARGET_MACHINERY = "machinery";  // 农机
16
+    public final static String TARGET_NEWS = "news";    // 资讯
9 17
 }

+ 107
- 9
src/main/java/com/yunzhi/nanyang/common/OSSUtils.java Целия файл

@@ -1,19 +1,73 @@
1 1
 package com.yunzhi.nanyang.common;
2 2
 
3 3
 import com.aliyun.oss.OSSClient;
4
+import com.aliyuncs.DefaultAcsClient;
5
+import com.aliyuncs.auth.sts.AssumeRoleRequest;
6
+import com.aliyuncs.auth.sts.AssumeRoleResponse;
7
+import com.aliyuncs.exceptions.ClientException;
8
+import com.aliyuncs.http.MethodType;
9
+import com.aliyuncs.profile.DefaultProfile;
10
+import com.aliyuncs.profile.IClientProfile;
4 11
 import com.yunzhi.nanyang.config.AliyunConfig;
12
+import lombok.extern.slf4j.Slf4j;
5 13
 import org.springframework.beans.factory.annotation.Autowired;
6 14
 import org.springframework.stereotype.Component;
7 15
 import org.springframework.web.multipart.MultipartFile;
8 16
 
9 17
 import java.io.*;
18
+import java.time.LocalDateTime;
19
+import java.time.format.DateTimeFormatter;
20
+import java.util.Base64;
21
+import java.util.HashMap;
22
+import java.util.Map;
10 23
 
24
+@Slf4j
11 25
 @Component
12 26
 public class OSSUtils {
13 27
 
28
+    private final static String STS_ENDPOINT = "sts.aliyuncs.com";
29
+
14 30
     @Autowired
15 31
     AliyunConfig aliyunConfig;
16 32
 
33
+    private String getMonth() {
34
+        return DateTimeFormatter.ofPattern("yyyyMM").format(LocalDateTime.now());
35
+    }
36
+
37
+    private String getUploadPath(String[] toDirs) {
38
+        String path = toDirs.length > 0 ? toDirs[0] : "/";
39
+        if (!path.endsWith("/")) {
40
+            path += "/";
41
+        }
42
+
43
+        return path + getMonth() + "/";
44
+    }
45
+
46
+    /**
47
+     * 上传 base64
48
+     * @param base64Str
49
+     * @param toDirs
50
+     * @return
51
+     * @throws IOException
52
+     */
53
+    public String putObject(String base64Str, String ...toDirs) throws IOException {
54
+        int index = base64Str.indexOf("base64,");
55
+
56
+        if (index > -1) {
57
+            index += 7;
58
+        } else {
59
+            index = 0;
60
+        }
61
+
62
+        String dataStr = base64Str.substring(index);
63
+        byte[] data = Base64.getDecoder().decode(dataStr);
64
+        ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
65
+        String toDir = getUploadPath(toDirs);
66
+        String nwFName = toDir + System.currentTimeMillis() + ".png";
67
+        nwFName = StringUtils.trim(nwFName,"/");
68
+        return putFile(nwFName, inputStream);
69
+    }
70
+
17 71
     /**
18 72
      * 上传文件
19 73
      * @param mf 上传的文件
@@ -23,10 +77,7 @@ public class OSSUtils {
23 77
     public String putObject(MultipartFile mf, String ... toDirs) throws IOException {
24 78
         String fName = formatFileName(mf.getOriginalFilename());
25 79
         String preFix = String.valueOf(System.currentTimeMillis());
26
-        String toDir = "/";
27
-        if (null != toDirs && toDirs.length > 0) {
28
-            toDir = toDirs[0];
29
-        }
80
+        String toDir = getUploadPath(toDirs);
30 81
         String nwFName = toDir + preFix + "-" + fName;
31 82
         nwFName = StringUtils.trim(nwFName,"/");
32 83
 
@@ -36,10 +87,7 @@ public class OSSUtils {
36 87
     public String putObject(File f, String ... toDirs) throws FileNotFoundException {
37 88
         String fName = formatFileName(f.getName());
38 89
         String preFix = String.valueOf(System.currentTimeMillis());
39
-        String toDir = "/";
40
-        if (null != toDirs && toDirs.length > 0) {
41
-            toDir = toDirs[0];
42
-        }
90
+        String toDir = getUploadPath(toDirs);
43 91
         String nwFName = toDir + preFix + "-" + fName;
44 92
         nwFName = StringUtils.trim(nwFName,"/");
45 93
 
@@ -47,6 +95,13 @@ public class OSSUtils {
47 95
         return putFile(nwFName, inputStream);
48 96
     }
49 97
 
98
+    public String putObject(InputStream inputStream, String fName, String ... toDirs) {
99
+        String toDir = getUploadPath(toDirs);
100
+        String nwFName = toDir + fName;
101
+        nwFName = StringUtils.trim(nwFName,"/");
102
+        return putFile(nwFName, inputStream);
103
+    }
104
+
50 105
     private String formatFileName(String fName) {
51 106
         return StringUtils.ifNull(fName, StringUtils.random(16) + ".png");
52 107
     }
@@ -63,6 +118,49 @@ public class OSSUtils {
63 118
             preURL += "/";
64 119
         }
65 120
 
66
-        return preURL + fname.replaceAll("\\ ", "%20");
121
+        return preURL + fname.replaceAll("\\ ", "%20").replaceAll("\\'", "%27");
67 122
     }
123
+
124
+    /**
125
+     * 获取上传凭证
126
+     * @return
127
+     * @throws Exception
128
+     */
129
+    public Map<String, Object> getSTSAKToken() throws Exception {
130
+        AliyunConfig.Oss oss = aliyunConfig.getOss();
131
+
132
+        try {
133
+            // 添加endpoint(直接使用STS endpoint,无需添加region ID)
134
+            DefaultProfile.addEndpoint("", "Sts", STS_ENDPOINT);
135
+            // 构造default profile(参数留空,无需添加region ID)
136
+            IClientProfile profile = DefaultProfile.getProfile("", oss.getAccessKeyId(), oss.getAccessKeySecret());
137
+
138
+            // 用profile构造client
139
+            DefaultAcsClient client = new DefaultAcsClient(profile);
140
+            final AssumeRoleRequest request = new AssumeRoleRequest();
141
+            request.setSysMethod(MethodType.POST);
142
+            request.setRoleArn(oss.getArn());
143
+            request.setRoleSessionName(oss.getRoleSessionName());
144
+            request.setPolicy(null); // 若policy为空,则用户将获得该角色下所有权限
145
+            request.setDurationSeconds(30 * 60L); // 设置凭证有效时间 1800 秒 = 30 分钟
146
+            final AssumeRoleResponse response = client.getAcsResponse(request);
147
+
148
+            AssumeRoleResponse.Credentials credentials = response.getCredentials();
149
+
150
+            Map<String, Object> res = new HashMap<>();
151
+            res.put("stsToken", credentials.getSecurityToken());
152
+            res.put("accessKeySecret", credentials.getAccessKeySecret());
153
+            res.put("accessKeyId", credentials.getAccessKeyId());
154
+            res.put("expiration", credentials.getExpiration());
155
+
156
+            return res;
157
+        } catch (ClientException e) {
158
+            e.printStackTrace();
159
+            log.error("Error code: " + e.getErrCode());
160
+            log.error("Error message: " + e.getErrMsg());
161
+            log.error("RequestId: " + e.getRequestId());
162
+            throw new Exception(e.getMessage());
163
+        }
164
+    }
165
+
68 166
 }

+ 62
- 12
src/main/java/com/yunzhi/nanyang/common/WxUtils.java Целия файл

@@ -4,31 +4,81 @@ import cn.binarywang.wx.miniapp.api.WxMaService;
4 4
 import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
5 5
 import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
6 6
 import com.yunzhi.nanyang.config.WeixinConfig;
7
+import com.yunzhi.nanyang.entity.SysMiniapp;
8
+import com.yunzhi.nanyang.service.ISysMiniappService;
7 9
 import org.springframework.beans.factory.annotation.Autowired;
8 10
 import org.springframework.stereotype.Component;
9 11
 
10 12
 @Component
11 13
 public class WxUtils {
12
-    private static WxMaService service;
14
+    // 农机手小程序
15
+    private static WxMaService workerService;
16
+    // 农户小程序
17
+    private static WxMaService farmerService;
18
+
19
+    // 此处不能使用变量注入方式, 否则会是 null
20
+    ISysMiniappService iSysMiniappService;
13 21
 
14 22
     @Autowired
15
-    public WxUtils(WeixinConfig config) {
16
-        setService(config);
23
+    public WxUtils(ISysMiniappService iSysMiniappService) {
24
+        this.iSysMiniappService = iSysMiniappService;
25
+
26
+        try {
27
+            setWorkerService();
28
+            setFarmerService();
29
+        } catch (Exception e) {
30
+            e.printStackTrace();
31
+        }
32
+    }
33
+
34
+    public WxMaService getWorkerService() throws Exception {
35
+        if (workerService == null) {
36
+            setWorkerService();
37
+        }
38
+
39
+        return workerService;
40
+    }
41
+
42
+    public WxMaService getFarmerService() throws Exception {
43
+        if (farmerService == null) {
44
+            setFarmerService();
45
+        }
46
+
47
+        return farmerService;
48
+    }
49
+
50
+    public WxMaService getService(String client) throws Exception {
51
+        return Constants.CLIENT_WORKER.equals(client) ? getWorkerService() : getFarmerService();
17 52
     }
18 53
 
19
-    private void setService(WeixinConfig config) {
54
+    private void setWorkerService() throws Exception {
55
+        SysMiniapp sysMiniapp = iSysMiniappService.getByClient(Constants.CLIENT_WORKER);
56
+        if (sysMiniapp == null) {
57
+            throw new Exception("未找到农机手小程序配置");
58
+        }
59
+
60
+        workerService = initService(sysMiniapp);
61
+    }
62
+
63
+    private void setFarmerService() throws Exception {
64
+        SysMiniapp sysMiniapp = iSysMiniappService.getByClient(Constants.CLIENT_FARMER);
65
+        if (sysMiniapp == null) {
66
+            throw new Exception("未找到农户小程序配置");
67
+        }
68
+
69
+        farmerService = initService(sysMiniapp);
70
+    }
71
+
72
+    private WxMaService initService(SysMiniapp sysMiniapp) {
20 73
         WxMaDefaultConfigImpl conf = new WxMaDefaultConfigImpl();
21
-        conf.setAppid(config.getMiniapp().getAppid());
22
-        conf.setSecret(config.getMiniapp().getSecret());
23
-        conf.setToken(config.getMiniapp().getToken());
24
-        conf.setAesKey(config.getMiniapp().getAesKey());
25
-        conf.setMsgDataFormat(config.getMiniapp().getMsgDataFormat());
74
+        conf.setAppid(sysMiniapp.getAppId());
75
+        conf.setSecret(sysMiniapp.getSecret());
76
+        conf.setToken(sysMiniapp.getToken());
77
+        conf.setAesKey(sysMiniapp.getAesKey());
78
+        conf.setMsgDataFormat("JSON");
26 79
 
27 80
         WxMaService service = new WxMaServiceImpl();
28 81
         service.setWxMaConfig(conf);
29
-    }
30
-
31
-    public WxMaService getService() {
32 82
         return service;
33 83
     }
34 84
 }

+ 8
- 7
src/main/java/com/yunzhi/nanyang/config/AliyunConfig.java Целия файл

@@ -2,7 +2,6 @@ package com.yunzhi.nanyang.config;
2 2
 
3 3
 import lombok.Data;
4 4
 import org.springframework.boot.context.properties.ConfigurationProperties;
5
-import org.springframework.boot.context.properties.NestedConfigurationProperty;
6 5
 import org.springframework.stereotype.Component;
7 6
 
8 7
 @Data
@@ -12,14 +11,17 @@ public class AliyunConfig {
12 11
     private String accessKeyId;
13 12
     private String accessKeySecret;
14 13
 
15
-    @NestedConfigurationProperty
16
-    private Oss oss = new Oss();
14
+    private Oss oss;
17 15
 
18
-    @NestedConfigurationProperty
19
-    private Sms sms = new Sms();
16
+    private Sms sms;
20 17
 
21 18
     @Data
22 19
     public  static class Oss {
20
+        private String roleSessionName;
21
+        private String accessKeyId;
22
+        private String accessKeySecret;
23
+        private String arn;
24
+        private String region;
23 25
         private String endpoint;
24 26
         private String bucketName;
25 27
         private String bucketURL;
@@ -27,8 +29,7 @@ public class AliyunConfig {
27 29
 
28 30
     @Data
29 31
     public static class Sms {
30
-        @NestedConfigurationProperty
31
-        private Captcha captcha = new Captcha();
32
+        private Captcha captcha;
32 33
     }
33 34
 
34 35
     @Data

+ 119
- 0
src/main/java/com/yunzhi/nanyang/controller/CommController.java Целия файл

@@ -0,0 +1,119 @@
1
+package com.yunzhi.nanyang.controller;
2
+
3
+import com.yunzhi.nanyang.common.BaseController;
4
+import com.yunzhi.nanyang.common.OSSUtils;
5
+import com.yunzhi.nanyang.common.ResponseBean;
6
+import com.yunzhi.nanyang.common.SMSCaptcha;
7
+import com.yunzhi.nanyang.config.AliyunConfig;
8
+import com.yunzhi.nanyang.service.ITaOrderService;
9
+import io.swagger.annotations.Api;
10
+import io.swagger.annotations.ApiOperation;
11
+import io.swagger.annotations.ApiParam;
12
+import org.springframework.beans.factory.annotation.Autowired;
13
+import org.springframework.web.bind.annotation.*;
14
+import org.springframework.web.multipart.MultipartFile;
15
+
16
+import java.io.IOException;
17
+import java.time.LocalDateTime;
18
+import java.time.format.DateTimeFormatter;
19
+import java.util.Map;
20
+
21
+@Api(tags = "通用")
22
+@RestController
23
+@RequestMapping("/{plat}")
24
+public class CommController extends BaseController {
25
+
26
+    @Autowired
27
+    OSSUtils ossUtils;
28
+
29
+    @Autowired
30
+    AliyunConfig aliyunConfig;
31
+
32
+    @Autowired
33
+    SMSCaptcha smsCaptcha;
34
+
35
+
36
+    @Autowired
37
+    ITaOrderService taOrderService;
38
+
39
+
40
+    /**
41
+     * 图片
42
+     * @param multipartFile
43
+     * @return
44
+     */
45
+    @ApiOperation(value = "图片上传", notes = "图片上传")
46
+    @PostMapping("/image")
47
+    public ResponseBean uploadImage(@ApiParam("客户端") @PathVariable String client,
48
+                                    @RequestParam("file") MultipartFile multipartFile) {
49
+        try {
50
+            String img = ossUtils.putObject(multipartFile);
51
+            return ResponseBean.success(img);
52
+        } catch (IOException e) {
53
+            return ResponseBean.error("上传图片失败: " + e.getMessage(), ResponseBean.ERROR_UNAVAILABLE);
54
+        }
55
+    }
56
+
57
+    /**
58
+     * base64 图片上传
59
+     * @param data
60
+     * @return
61
+     */
62
+    @ApiOperation(value = "base64 图片上传", notes = "base64 图片上传")
63
+    @PostMapping("/image/base64")
64
+    public ResponseBean uploadBase64Image(@ApiParam("客户端") @PathVariable String client,
65
+                                          @RequestBody Map<String, String> data) {
66
+        try {
67
+            String base64Str = data.get("base64");
68
+            String img = ossUtils.putObject(base64Str);
69
+            return ResponseBean.success(img);
70
+        } catch (IOException e) {
71
+            return ResponseBean.error("上传图片失败: " + e.getMessage(), ResponseBean.ERROR_UNAVAILABLE);
72
+        }
73
+    }
74
+
75
+    @ApiOperation(value = "发送手机验证码", notes = "发送手机验证码")
76
+    @PostMapping("/sms-captcha")
77
+    public ResponseBean sendCaptcha(@ApiParam("客户端") @PathVariable String client,
78
+                                    @ApiParam("手机号") @RequestParam String phone) throws Exception {
79
+        smsCaptcha.send(phone, smsCaptcha.randCaptcha(6));
80
+        return ResponseBean.success("发送成功");
81
+    }
82
+
83
+    @ApiOperation(value = "发送手机验证码", notes = "发送手机验证码")
84
+    @PostMapping("/{clientId}/sms-captcha")
85
+    public ResponseBean sendCaptcha2(@ApiParam("客户端") @PathVariable String client,
86
+                                     @ApiParam("客户端ID") @PathVariable String clientId,
87
+                                     @ApiParam("手机号") @RequestParam String phone) throws Exception {
88
+        smsCaptcha.send(phone, smsCaptcha.randCaptcha(6));
89
+        return ResponseBean.success("发送成功");
90
+    }
91
+
92
+    /**
93
+     * 获取文件上传凭证
94
+     * @return
95
+     */
96
+    @ApiOperation(value = "获取文件上传凭证", notes = "获取文件上传凭证")
97
+    @GetMapping("/oss-sts")
98
+    public ResponseBean getOSSSTS(@ApiParam("客户端") @PathVariable String client) {
99
+        AliyunConfig.Oss oss = aliyunConfig.getOss();
100
+
101
+        try {
102
+            Map<String, Object> res = ossUtils.getSTSAKToken();
103
+            res.put("endpoint", oss.getEndpoint());
104
+            res.put("bucket", oss.getBucketName());
105
+            res.put("bucketURL", oss.getBucketURL());
106
+            res.put("region", oss.getRegion());
107
+            res.put("path", getMonth());
108
+
109
+            return ResponseBean.success(res);
110
+        } catch (Exception e) {
111
+            return ResponseBean.error("获取上传凭证失败! ", ResponseBean.ERROR_UNAVAILABLE);
112
+        }
113
+    }
114
+
115
+    private String getMonth() {
116
+        return DateTimeFormatter.ofPattern("yyyy-MM").format(LocalDateTime.now());
117
+    }
118
+
119
+}

+ 119
- 0
src/main/java/com/yunzhi/nanyang/controller/SysMiniappController.java Целия файл

@@ -0,0 +1,119 @@
1
+package com.yunzhi.nanyang.controller;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
+import com.yunzhi.nanyang.common.BaseController;
7
+import com.yunzhi.nanyang.common.ResponseBean;
8
+import io.swagger.annotations.Api;
9
+import io.swagger.annotations.ApiOperation;
10
+import io.swagger.annotations.ApiParam;
11
+import org.slf4j.Logger;
12
+import org.slf4j.LoggerFactory;
13
+import org.springframework.beans.factory.annotation.Autowired;
14
+import org.springframework.web.bind.annotation.PathVariable;
15
+import org.springframework.web.bind.annotation.RequestBody;
16
+import org.springframework.web.bind.annotation.RequestMapping;
17
+import org.springframework.web.bind.annotation.RequestMethod;
18
+import org.springframework.web.bind.annotation.RequestParam;
19
+import com.yunzhi.nanyang.service.ISysMiniappService;
20
+import com.yunzhi.nanyang.entity.SysMiniapp;
21
+import org.springframework.web.bind.annotation.RestController;
22
+
23
+/**
24
+ * <p>
25
+    * 小程序表 前端控制器
26
+    * </p>
27
+ *
28
+ * @author yansen
29
+ * @since 2022-03-21
30
+ */
31
+
32
+@Api(tags = "小程序表")
33
+@RestController
34
+@RequestMapping("/")
35
+public class SysMiniappController extends BaseController {
36
+
37
+    private final Logger logger = LoggerFactory.getLogger(SysMiniappController.class);
38
+
39
+    @Autowired
40
+    public ISysMiniappService iSysMiniappService;
41
+
42
+//
43
+//    /**
44
+//     * 分页查询列表
45
+//     * @param pageNum
46
+//     * @param pageSize
47
+//     * @return
48
+//     */
49
+//    @RequestMapping(value="/sysMiniapp",method= RequestMethod.GET)
50
+//    @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
51
+//    public ResponseBean sysMiniappList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
+//									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
53
+//
54
+//		    IPage<SysMiniapp> pg = new Page<>(pageNum, pageSize);
55
+//            QueryWrapper<SysMiniapp> queryWrapper = new QueryWrapper<>();
56
+//            queryWrapper.orderByDesc("create_date");
57
+//
58
+//            IPage<SysMiniapp> result = iSysMiniappService.page(pg, queryWrapper);
59
+//            return ResponseBean.success(result);
60
+//    }
61
+//
62
+//    /**
63
+//     * 保存对象
64
+//     * @param sysMiniapp 实体对象
65
+//     * @return
66
+//     */
67
+//    @RequestMapping(value="/sysMiniapp",method= RequestMethod.POST)
68
+//    @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
69
+//    public ResponseBean sysMiniappAdd(@ApiParam("保存内容") @RequestBody SysMiniapp sysMiniapp) throws Exception{
70
+//
71
+//        if (iSysMiniappService.save(sysMiniapp)){
72
+//            return ResponseBean.success(sysMiniapp);
73
+//        }else {
74
+//            return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
75
+//        }
76
+//    }
77
+//
78
+//    /**
79
+//     * 根据id删除对象
80
+//     * @param id  实体ID
81
+//     */
82
+//    @RequestMapping(value="/sysMiniapp/{id}", method= RequestMethod.DELETE)
83
+//    @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
84
+//    public ResponseBean sysMiniappDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
85
+//        if(iSysMiniappService.removeById(id)){
86
+//            return ResponseBean.success("success");
87
+//        }else {
88
+//            return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
89
+//        }
90
+//    }
91
+//
92
+//    /**
93
+//     * 修改对象
94
+//     * @param id  实体ID
95
+//     * @param sysMiniapp 实体对象
96
+//     * @return
97
+//     */
98
+//    @RequestMapping(value="/sysMiniapp/{id}",method= RequestMethod.PUT)
99
+//    @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
100
+//    public ResponseBean sysMiniappUpdate(@ApiParam("对象ID") @PathVariable Integer id,
101
+//                                        @ApiParam("更新内容") @RequestBody SysMiniapp sysMiniapp) throws Exception{
102
+//
103
+//        if (iSysMiniappService.updateById(sysMiniapp)){
104
+//            return ResponseBean.success(iSysMiniappService.getById(id));
105
+//        }else {
106
+//            return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
107
+//        }
108
+//    }
109
+//
110
+//    /**
111
+//     * 根据id查询对象
112
+//     * @param id  实体ID
113
+//     */
114
+//    @RequestMapping(value="/sysMiniapp/{id}",method= RequestMethod.GET)
115
+//    @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
116
+//    public ResponseBean sysMiniappGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
117
+//        return ResponseBean.success(iSysMiniappService.getById(id));
118
+//    }
119
+}

+ 4
- 1
src/main/java/com/yunzhi/nanyang/controller/SysSettingController.java Целия файл

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 4
 import com.baomidou.mybatisplus.core.metadata.IPage;
5 5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 6
 import com.yunzhi.nanyang.common.BaseController;
7
+import com.yunzhi.nanyang.common.Constants;
7 8
 import com.yunzhi.nanyang.common.ResponseBean;
8 9
 import io.swagger.annotations.Api;
9 10
 import io.swagger.annotations.ApiOperation;
@@ -54,7 +55,9 @@ public class SysSettingController extends BaseController {
54 55
 
55 56
         IPage<SysSetting> pg = new Page<>(pageNum, pageSize);
56 57
         QueryWrapper<SysSetting> queryWrapper = new QueryWrapper<>();
57
-        queryWrapper.orderByDesc("create_date");
58
+        queryWrapper.lt("is_hidden", Constants.STATUS_NORMAL);
59
+        queryWrapper.gt("status", Constants.STATUS_DELETE);
60
+        queryWrapper.orderByAsc("sort_no");
58 61
 
59 62
         IPage<SysSetting> result = iSysSettingService.page(pg, queryWrapper);
60 63
         return ResponseBean.success(result);

+ 30
- 10
src/main/java/com/yunzhi/nanyang/controller/SysUserController.java Целия файл

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 6
 import com.yunzhi.nanyang.common.*;
7 7
 import com.yunzhi.nanyang.entity.SysLogin;
8 8
 import com.yunzhi.nanyang.service.ISysLoginService;
9
+import com.yunzhi.nanyang.service.ISysUserDataScopeService;
9 10
 import io.swagger.annotations.Api;
10 11
 import io.swagger.annotations.ApiOperation;
11 12
 import io.swagger.annotations.ApiParam;
@@ -45,6 +46,9 @@ public class SysUserController extends BaseController {
45 46
     @Autowired
46 47
     public ISysLoginService iSysLoginService;
47 48
 
49
+    @Autowired
50
+    public ISysUserDataScopeService iSysUserDataScopeService;
51
+
48 52
     @Value("${yz.default.password}")
49 53
     public String defaultPassword;
50 54
 
@@ -60,7 +64,7 @@ public class SysUserController extends BaseController {
60 64
     public ResponseBean sysUserList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
61 65
                                     @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
62 66
                                     @ApiParam("机构") @RequestParam(value ="org_id", required = false) String orgId,
63
-                                    @ApiParam("名称") @RequestParam(value ="name", required = false) String name,
67
+                                    @ApiParam("名称") @RequestParam(value ="userName", required = false) String userName,
64 68
                                     @ApiParam("手机号") @RequestParam(value ="phone", required = false) String phone) throws Exception{
65 69
 
66 70
         SysUser sysUser = currentUser();
@@ -73,7 +77,7 @@ public class SysUserController extends BaseController {
73 77
 
74 78
         IPage<SysUser> pg = new Page<>(pageNum, pageSize);
75 79
 
76
-        IPage<SysUser> result = iSysUserService.getPageBy(pg, userId, orgId, name, phone);
80
+        IPage<SysUser> result = iSysUserService.getPageBy(pg, userId, orgId, userName, phone);
77 81
         return ResponseBean.success(result);
78 82
     }
79 83
 
@@ -98,6 +102,10 @@ public class SysUserController extends BaseController {
98 102
             return ResponseBean.error("所属机构不能为空");
99 103
         }
100 104
 
105
+        if (!checkOrgAccess(sysUser.getOrgId(), userId)) {
106
+            return ResponseBean.error("无权限进行此操作");
107
+        }
108
+
101 109
         int cntPhone = iSysUserService.countBy("phone", sysUser.getPhone(), true);
102 110
         if (cntPhone > 0) {
103 111
             return ResponseBean.error("手机号码重复");
@@ -111,14 +119,10 @@ public class SysUserController extends BaseController {
111 119
         }
112 120
 
113 121
         if (iSysUserService.save(sysUser)){
122
+            iSysUserDataScopeService.addNew(sysUser.getOrgId(), sysUser.getUserId());
123
+
114 124
             if (!StringUtils.isEmpty(sysUser.getLoginName())) {
115
-                SysLogin sysLogin = new SysLogin();
116
-                sysLogin.setLoginId(StringUtils.uuid());
117
-                sysLogin.setUserId(sysUser.getUserId());
118
-                sysLogin.setLoginName(sysUser.getLoginName());
119
-                sysLogin.setPassword(EncryptUtils.md5(EncryptUtils.md5(defaultPassword), sysLogin.getLoginId()));
120
-                sysLogin.setStatus(Constants.STATUS_NORMAL);
121
-                iSysLoginService.save(sysLogin);
125
+                addNewSysLogin(sysUser);
122 126
             }
123 127
 
124 128
             return ResponseBean.success(sysUser);
@@ -177,6 +181,9 @@ public class SysUserController extends BaseController {
177 181
         if (StringUtils.isEmpty(sysUser.getOrgId())) {
178 182
             return ResponseBean.error("所属机构不能为空");
179 183
         }
184
+        if (!checkOrgAccess(sysUser.getOrgId(), userId)) {
185
+            return ResponseBean.error("无权限进行此操作");
186
+        }
180 187
 
181 188
         SysUser origin = iSysUserService.getByButNot("phone", sysUser.getPhone(), "user_id", id,true);
182 189
         if (origin != null) {
@@ -196,9 +203,12 @@ public class SysUserController extends BaseController {
196 203
         }
197 204
 
198 205
         if (iSysUserService.updateById(sysUser)){
206
+            iSysUserDataScopeService.addNew(sysUser.getOrgId(), sysUser.getUserId());
199 207
             if (!StringUtils.isEmpty(sysUser.getLoginName())) {
200 208
                 SysLogin sysLogin = iSysLoginService.getExistBy("user_id", id, false, true);
201
-                if (!sysLogin.getLoginName().equals(sysUser.getLoginName())) {
209
+                if (sysLogin == null) {
210
+                    addNewSysLogin(sysUser);
211
+                } else if (!sysLogin.getLoginName().equals(sysUser.getLoginName())) {
202 212
                     sysLogin.setLoginName(sysUser.getLoginName());
203 213
                     iSysLoginService.updateById(sysLogin);
204 214
                 }
@@ -210,6 +220,16 @@ public class SysUserController extends BaseController {
210 220
         }
211 221
     }
212 222
 
223
+    private SysLogin addNewSysLogin(SysUser sysUser) {
224
+        SysLogin sysLogin = new SysLogin();
225
+        sysLogin.setUserId(sysUser.getUserId());
226
+        sysLogin.setLoginName(sysUser.getLoginName());
227
+        sysLogin.setPassword(EncryptUtils.md5(EncryptUtils.md5(defaultPassword), sysLogin.getUserId()));
228
+        sysLogin.setStatus(Constants.STATUS_NORMAL);
229
+        iSysLoginService.save(sysLogin);
230
+        return sysLogin;
231
+    }
232
+
213 233
     /**
214 234
      * 根据id查询对象
215 235
      * @param id  实体ID

+ 39
- 13
src/main/java/com/yunzhi/nanyang/controller/TaBannerController.java Целия файл

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 6
 import com.yunzhi.nanyang.common.BaseController;
7 7
 import com.yunzhi.nanyang.common.Constants;
8 8
 import com.yunzhi.nanyang.common.ResponseBean;
9
+import com.yunzhi.nanyang.common.StringUtils;
9 10
 import io.swagger.annotations.Api;
10 11
 import io.swagger.annotations.ApiOperation;
11 12
 import io.swagger.annotations.ApiParam;
@@ -50,13 +51,16 @@ public class TaBannerController extends BaseController {
50 51
      */
51 52
     @RequestMapping(value="/admin/banner",method= RequestMethod.GET)
52 53
     @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
53
-    @RequiresPermissions("banner")
54 54
     public ResponseBean taBannerList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
55
-									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
55
+									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
56
+                                     @ApiParam("名称") @RequestParam(value ="title", required = false) String title,
57
+                                     @ApiParam("类型") @RequestParam(value ="position", required = false) String position) throws Exception{
56 58
 
57 59
         IPage<TaBanner> pg = new Page<>(pageNum, pageSize);
58 60
         QueryWrapper<TaBanner> queryWrapper = new QueryWrapper<>();
59
-        queryWrapper.gt("status", Constants.STATUS_NORMAL);
61
+        queryWrapper.like(!StringUtils.isEmpty(title), "title", "%" + title + "%");
62
+        queryWrapper.eq(!StringUtils.isEmpty(position), "position", position);
63
+        queryWrapper.gt("status", Constants.STATUS_DELETE);
60 64
         queryWrapper.orderByDesc("create_date");
61 65
 
62 66
         IPage<TaBanner> result = iTaBannerService.page(pg, queryWrapper);
@@ -68,10 +72,21 @@ public class TaBannerController extends BaseController {
68 72
      * @param taBanner 实体对象
69 73
      * @return
70 74
      */
71
-    @RequestMapping(value="/taBanner",method= RequestMethod.POST)
75
+    @RequestMapping(value="/admin/banner",method= RequestMethod.POST)
72 76
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
73
-    @RequiresPermissions("banner")
77
+    @RequiresPermissions("banner:add")
74 78
     public ResponseBean taBannerAdd(@ApiParam("保存内容") @RequestBody TaBanner taBanner) throws Exception{
79
+        if (StringUtils.isEmpty(taBanner.getTitle())) {
80
+            return ResponseBean.error("标题不能为空");
81
+        }
82
+        if (StringUtils.isEmpty(taBanner.getThumb())) {
83
+            return ResponseBean.error("图片不能为空");
84
+        }
85
+        if (StringUtils.isEmpty(taBanner.getPosition())) {
86
+            return ResponseBean.error("位置不能为空");
87
+        }
88
+
89
+        taBanner.setBannerId(null);
75 90
 
76 91
         if (iTaBannerService.save(taBanner)){
77 92
             return ResponseBean.success(taBanner);
@@ -84,11 +99,11 @@ public class TaBannerController extends BaseController {
84 99
      * 根据id删除对象
85 100
      * @param id  实体ID
86 101
      */
87
-    @RequestMapping(value="/taBanner/{id}", method= RequestMethod.DELETE)
102
+    @RequestMapping(value="/admin/banner/{id}", method= RequestMethod.DELETE)
88 103
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
89
-    @RequiresPermissions("banner")
90
-    public ResponseBean taBannerDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
91
-        if(iTaBannerService.removeById(id)){
104
+    @RequiresPermissions("banner:delete")
105
+    public ResponseBean taBannerDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
106
+        if(iTaBannerService.removeLogicById(id)){
92 107
             return ResponseBean.success("success");
93 108
         }else {
94 109
             return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
@@ -101,14 +116,25 @@ public class TaBannerController extends BaseController {
101 116
      * @param taBanner 实体对象
102 117
      * @return
103 118
      */
104
-    @RequestMapping(value="/taBanner/{id}",method= RequestMethod.PUT)
119
+    @RequestMapping(value="/admin/banner/{id}",method= RequestMethod.PUT)
105 120
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
106
-    @RequiresPermissions("banner")
107
-    public ResponseBean taBannerUpdate(@ApiParam("对象ID") @PathVariable Integer id,
121
+    @RequiresPermissions("banner:update")
122
+    public ResponseBean taBannerUpdate(@ApiParam("对象ID") @PathVariable String id,
108 123
                                         @ApiParam("更新内容") @RequestBody TaBanner taBanner) throws Exception{
124
+        taBanner.setBannerId(id);
125
+
126
+        if (StringUtils.isEmpty(taBanner.getTitle())) {
127
+            return ResponseBean.error("标题不能为空");
128
+        }
129
+        if (StringUtils.isEmpty(taBanner.getThumb())) {
130
+            return ResponseBean.error("图片不能为空");
131
+        }
132
+        if (StringUtils.isEmpty(taBanner.getPosition())) {
133
+            return ResponseBean.error("位置不能为空");
134
+        }
109 135
 
110 136
         if (iTaBannerService.updateById(taBanner)){
111
-            return ResponseBean.success(iTaBannerService.getById(id));
137
+            return ResponseBean.success(taBanner);
112 138
         }else {
113 139
             return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
114 140
         }

+ 40
- 15
src/main/java/com/yunzhi/nanyang/controller/TaExtendContentController.java Целия файл

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
5 5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 6
 import com.yunzhi.nanyang.common.BaseController;
7 7
 import com.yunzhi.nanyang.common.ResponseBean;
8
+import com.yunzhi.nanyang.common.StringUtils;
8 9
 import io.swagger.annotations.Api;
9 10
 import io.swagger.annotations.ApiOperation;
10 11
 import io.swagger.annotations.ApiParam;
@@ -46,17 +47,21 @@ public class TaExtendContentController extends BaseController {
46 47
      * @param pageSize
47 48
      * @return
48 49
      */
49
-    @RequestMapping(value="/taExtendContent",method= RequestMethod.GET)
50
+    @RequestMapping(value="/admin/extend-content",method= RequestMethod.GET)
50 51
     @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
51 52
     public ResponseBean taExtendContentList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
-									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
53
+                                            @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
54
+                                            @ApiParam("资源分类") @RequestParam(value ="targetType") String targetType,
55
+                                            @ApiParam("资源ID") @RequestParam(value ="targetId") String targetId) throws Exception{
53 56
 
54
-		    IPage<TaExtendContent> pg = new Page<>(pageNum, pageSize);
55
-            QueryWrapper<TaExtendContent> queryWrapper = new QueryWrapper<>();
56
-            queryWrapper.orderByDesc("create_date");
57
+        IPage<TaExtendContent> pg = new Page<>(pageNum, pageSize);
58
+        QueryWrapper<TaExtendContent> queryWrapper = new QueryWrapper<>();
59
+        queryWrapper.eq("target_type", targetType);
60
+        queryWrapper.eq("target_id", targetId);
61
+        queryWrapper.orderByAsc("sort");
57 62
 
58
-            IPage<TaExtendContent> result = iTaExtendContentService.page(pg, queryWrapper);
59
-            return ResponseBean.success(result);
63
+        IPage<TaExtendContent> result = iTaExtendContentService.page(pg, queryWrapper);
64
+        return ResponseBean.success(result);
60 65
     }
61 66
 
62 67
     /**
@@ -64,10 +69,20 @@ public class TaExtendContentController extends BaseController {
64 69
      * @param taExtendContent 实体对象
65 70
      * @return
66 71
      */
67
-    @RequestMapping(value="/taExtendContent",method= RequestMethod.POST)
72
+    @RequestMapping(value="/admin/extend-content",method= RequestMethod.POST)
68 73
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
69 74
     public ResponseBean taExtendContentAdd(@ApiParam("保存内容") @RequestBody TaExtendContent taExtendContent) throws Exception{
70 75
 
76
+        if (StringUtils.isEmpty(taExtendContent.getTargetId()) || StringUtils.isEmpty(taExtendContent.getTargetType())) {
77
+            return ResponseBean.error("资源不能为空");
78
+        }
79
+
80
+        if (StringUtils.isEmpty(taExtendContent.getContent())) {
81
+            return ResponseBean.error("内容不能为空");
82
+        }
83
+
84
+        taExtendContent.setExtId(null);
85
+
71 86
         if (iTaExtendContentService.save(taExtendContent)){
72 87
             return ResponseBean.success(taExtendContent);
73 88
         }else {
@@ -79,9 +94,9 @@ public class TaExtendContentController extends BaseController {
79 94
      * 根据id删除对象
80 95
      * @param id  实体ID
81 96
      */
82
-    @RequestMapping(value="/taExtendContent/{id}", method= RequestMethod.DELETE)
97
+    @RequestMapping(value="/admin/extend-content/{id}", method= RequestMethod.DELETE)
83 98
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
84
-    public ResponseBean taExtendContentDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
99
+    public ResponseBean taExtendContentDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
85 100
         if(iTaExtendContentService.removeById(id)){
86 101
             return ResponseBean.success("success");
87 102
         }else {
@@ -95,13 +110,23 @@ public class TaExtendContentController extends BaseController {
95 110
      * @param taExtendContent 实体对象
96 111
      * @return
97 112
      */
98
-    @RequestMapping(value="/taExtendContent/{id}",method= RequestMethod.PUT)
113
+    @RequestMapping(value="/admin/extend-content/{id}",method= RequestMethod.PUT)
99 114
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
100
-    public ResponseBean taExtendContentUpdate(@ApiParam("对象ID") @PathVariable Integer id,
115
+    public ResponseBean taExtendContentUpdate(@ApiParam("对象ID") @PathVariable String id,
101 116
                                         @ApiParam("更新内容") @RequestBody TaExtendContent taExtendContent) throws Exception{
102 117
 
118
+        if (StringUtils.isEmpty(taExtendContent.getTargetId()) || StringUtils.isEmpty(taExtendContent.getTargetType())) {
119
+            return ResponseBean.error("资源不能为空");
120
+        }
121
+
122
+        if (StringUtils.isEmpty(taExtendContent.getContent())) {
123
+            return ResponseBean.error("内容不能为空");
124
+        }
125
+
126
+        taExtendContent.setExtId(id);
127
+
103 128
         if (iTaExtendContentService.updateById(taExtendContent)){
104
-            return ResponseBean.success(iTaExtendContentService.getById(id));
129
+            return ResponseBean.success(taExtendContent);
105 130
         }else {
106 131
             return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
107 132
         }
@@ -111,9 +136,9 @@ public class TaExtendContentController extends BaseController {
111 136
      * 根据id查询对象
112 137
      * @param id  实体ID
113 138
      */
114
-    @RequestMapping(value="/taExtendContent/{id}",method= RequestMethod.GET)
139
+    @RequestMapping(value="/admin/extend-content/{id}",method= RequestMethod.GET)
115 140
     @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
116
-    public ResponseBean taExtendContentGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
141
+    public ResponseBean taExtendContentGet(@ApiParam("对象ID") @PathVariable String id) throws Exception{
117 142
         return ResponseBean.success(iTaExtendContentService.getById(id));
118 143
     }
119 144
 }

+ 75
- 75
src/main/java/com/yunzhi/nanyang/controller/TaImagesController.java Целия файл

@@ -40,80 +40,80 @@ public class TaImagesController extends BaseController {
40 40
     public ITaImagesService iTaImagesService;
41 41
 
42 42
 
43
-    /**
44
-     * 分页查询列表
45
-     * @param pageNum
46
-     * @param pageSize
47
-     * @return
48
-     */
49
-    @RequestMapping(value="/taImages",method= RequestMethod.GET)
50
-    @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
51
-    public ResponseBean taImagesList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
-									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
43
+//    /**
44
+//     * 分页查询列表
45
+//     * @param pageNum
46
+//     * @param pageSize
47
+//     * @return
48
+//     */
49
+//    @RequestMapping(value="/taImages",method= RequestMethod.GET)
50
+//    @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
51
+//    public ResponseBean taImagesList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
+//									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
53
+//
54
+//        IPage<TaImages> pg = new Page<>(pageNum, pageSize);
55
+//        QueryWrapper<TaImages> queryWrapper = new QueryWrapper<>();
56
+//        queryWrapper.orderByDesc("create_date");
57
+//
58
+//        IPage<TaImages> result = iTaImagesService.page(pg, queryWrapper);
59
+//        return ResponseBean.success(result);
60
+//    }
53 61
 
54
-		    IPage<TaImages> pg = new Page<>(pageNum, pageSize);
55
-            QueryWrapper<TaImages> queryWrapper = new QueryWrapper<>();
56
-            queryWrapper.orderByDesc("create_date");
57
-
58
-            IPage<TaImages> result = iTaImagesService.page(pg, queryWrapper);
59
-            return ResponseBean.success(result);
60
-    }
61
-
62
-    /**
63
-     * 保存对象
64
-     * @param taImages 实体对象
65
-     * @return
66
-     */
67
-    @RequestMapping(value="/taImages",method= RequestMethod.POST)
68
-    @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
69
-    public ResponseBean taImagesAdd(@ApiParam("保存内容") @RequestBody TaImages taImages) throws Exception{
70
-
71
-        if (iTaImagesService.save(taImages)){
72
-            return ResponseBean.success(taImages);
73
-        }else {
74
-            return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
75
-        }
76
-    }
77
-
78
-    /**
79
-     * 根据id删除对象
80
-     * @param id  实体ID
81
-     */
82
-    @RequestMapping(value="/taImages/{id}", method= RequestMethod.DELETE)
83
-    @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
84
-    public ResponseBean taImagesDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
85
-        if(iTaImagesService.removeById(id)){
86
-            return ResponseBean.success("success");
87
-        }else {
88
-            return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
89
-        }
90
-    }
91
-
92
-    /**
93
-     * 修改对象
94
-     * @param id  实体ID
95
-     * @param taImages 实体对象
96
-     * @return
97
-     */
98
-    @RequestMapping(value="/taImages/{id}",method= RequestMethod.PUT)
99
-    @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
100
-    public ResponseBean taImagesUpdate(@ApiParam("对象ID") @PathVariable Integer id,
101
-                                        @ApiParam("更新内容") @RequestBody TaImages taImages) throws Exception{
102
-
103
-        if (iTaImagesService.updateById(taImages)){
104
-            return ResponseBean.success(iTaImagesService.getById(id));
105
-        }else {
106
-            return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
107
-        }
108
-    }
109
-
110
-    /**
111
-     * 根据id查询对象
112
-     * @param id  实体ID
113
-     */
114
-    @RequestMapping(value="/taImages/{id}",method= RequestMethod.GET)
115
-    @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
116
-    public ResponseBean taImagesGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
117
-        return ResponseBean.success(iTaImagesService.getById(id));
118
-    }
62
+//    /**
63
+//     * 保存对象
64
+//     * @param taImages 实体对象
65
+//     * @return
66
+//     */
67
+//    @RequestMapping(value="/admin/images",method= RequestMethod.POST)
68
+//    @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
69
+//    public ResponseBean taImagesAdd(@ApiParam("保存内容") @RequestBody TaImages taImages) throws Exception{
70
+//
71
+//        if (iTaImagesService.save(taImages)){
72
+//            return ResponseBean.success(taImages);
73
+//        }else {
74
+//            return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
75
+//        }
76
+//    }
77
+//
78
+//    /**
79
+//     * 根据id删除对象
80
+//     * @param id  实体ID
81
+//     */
82
+//    @RequestMapping(value="/taImages/{id}", method= RequestMethod.DELETE)
83
+//    @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
84
+//    public ResponseBean taImagesDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
85
+//        if(iTaImagesService.removeById(id)){
86
+//            return ResponseBean.success("success");
87
+//        }else {
88
+//            return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
89
+//        }
90
+//    }
91
+//
92
+//    /**
93
+//     * 修改对象
94
+//     * @param id  实体ID
95
+//     * @param taImages 实体对象
96
+//     * @return
97
+//     */
98
+//    @RequestMapping(value="/taImages/{id}",method= RequestMethod.PUT)
99
+//    @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
100
+//    public ResponseBean taImagesUpdate(@ApiParam("对象ID") @PathVariable Integer id,
101
+//                                        @ApiParam("更新内容") @RequestBody TaImages taImages) throws Exception{
102
+//
103
+//        if (iTaImagesService.updateById(taImages)){
104
+//            return ResponseBean.success(iTaImagesService.getById(id));
105
+//        }else {
106
+//            return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
107
+//        }
108
+//    }
109
+//
110
+//    /**
111
+//     * 根据id查询对象
112
+//     * @param id  实体ID
113
+//     */
114
+//    @RequestMapping(value="/taImages/{id}",method= RequestMethod.GET)
115
+//    @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
116
+//    public ResponseBean taImagesGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
117
+//        return ResponseBean.success(iTaImagesService.getById(id));
118
+//    }
119 119
 }

+ 68
- 19
src/main/java/com/yunzhi/nanyang/controller/TaMachineryController.java Целия файл

@@ -4,10 +4,14 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 4
 import com.baomidou.mybatisplus.core.metadata.IPage;
5 5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 6
 import com.yunzhi.nanyang.common.BaseController;
7
+import com.yunzhi.nanyang.common.Constants;
7 8
 import com.yunzhi.nanyang.common.ResponseBean;
9
+import com.yunzhi.nanyang.common.StringUtils;
10
+import com.yunzhi.nanyang.entity.SysUser;
8 11
 import io.swagger.annotations.Api;
9 12
 import io.swagger.annotations.ApiOperation;
10 13
 import io.swagger.annotations.ApiParam;
14
+import org.apache.shiro.authz.annotation.RequiresPermissions;
11 15
 import org.slf4j.Logger;
12 16
 import org.slf4j.LoggerFactory;
13 17
 import org.springframework.beans.factory.annotation.Autowired;
@@ -46,17 +50,25 @@ public class TaMachineryController extends BaseController {
46 50
      * @param pageSize
47 51
      * @return
48 52
      */
49
-    @RequestMapping(value="/taMachinery",method= RequestMethod.GET)
53
+    @RequestMapping(value="/admin/machinery",method= RequestMethod.GET)
50 54
     @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
51 55
     public ResponseBean taMachineryList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
-									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
56
+                                        @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
57
+                                        @ApiParam("名称") @RequestParam(value ="name", required = false) String name,
58
+                                        @ApiParam("类型") @RequestParam(value ="typeId", required = false) String typeId) throws Exception{
59
+        SysUser sysUser = currentUser();
60
+        boolean isAdmin = Constants.ADMIN_ID.equals(sysUser.getUserId());
53 61
 
54
-		    IPage<TaMachinery> pg = new Page<>(pageNum, pageSize);
55
-            QueryWrapper<TaMachinery> queryWrapper = new QueryWrapper<>();
56
-            queryWrapper.orderByDesc("create_date");
62
+        IPage<TaMachinery> pg = new Page<>(pageNum, pageSize);
63
+        QueryWrapper<TaMachinery> queryWrapper = new QueryWrapper<>();
64
+        queryWrapper.like(!StringUtils.isEmpty(name), "name", "%" + name + "%");
65
+        queryWrapper.eq(!StringUtils.isEmpty(typeId), "type_id", typeId);
66
+        queryWrapper.in(!isAdmin, "org_id", getAccessOrgs(sysUser.getUserId()));
67
+        queryWrapper.gt("status", Constants.STATUS_DELETE);
68
+        queryWrapper.orderByDesc("create_date");
57 69
 
58
-            IPage<TaMachinery> result = iTaMachineryService.page(pg, queryWrapper);
59
-            return ResponseBean.success(result);
70
+        IPage<TaMachinery> result = iTaMachineryService.page(pg, queryWrapper);
71
+        return ResponseBean.success(result);
60 72
     }
61 73
 
62 74
     /**
@@ -64,11 +76,24 @@ public class TaMachineryController extends BaseController {
64 76
      * @param taMachinery 实体对象
65 77
      * @return
66 78
      */
67
-    @RequestMapping(value="/taMachinery",method= RequestMethod.POST)
79
+    @RequestMapping(value="/admin/machinery",method= RequestMethod.POST)
68 80
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
81
+    @RequiresPermissions("machinery:add")
69 82
     public ResponseBean taMachineryAdd(@ApiParam("保存内容") @RequestBody TaMachinery taMachinery) throws Exception{
83
+        SysUser sysUser = currentUser();
70 84
 
71
-        if (iTaMachineryService.save(taMachinery)){
85
+        if (StringUtils.isEmpty(taMachinery.getOrgId())) {
86
+            return ResponseBean.error("请设置农机归属");
87
+        }
88
+
89
+        if (!checkOrgAccess(taMachinery.getOrgId(), sysUser.getUserId())) {
90
+            return ResponseBean.error("无权进行此操作");
91
+        }
92
+
93
+        taMachinery.setMachineryId(null);
94
+        taMachinery.setCreateUser(sysUser.getUserId());
95
+
96
+        if (iTaMachineryService.saveAll(taMachinery)){
72 97
             return ResponseBean.success(taMachinery);
73 98
         }else {
74 99
             return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
@@ -79,10 +104,22 @@ public class TaMachineryController extends BaseController {
79 104
      * 根据id删除对象
80 105
      * @param id  实体ID
81 106
      */
82
-    @RequestMapping(value="/taMachinery/{id}", method= RequestMethod.DELETE)
107
+    @RequestMapping(value="/admin/machinery/{id}", method= RequestMethod.DELETE)
83 108
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
84
-    public ResponseBean taMachineryDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
85
-        if(iTaMachineryService.removeById(id)){
109
+    @RequiresPermissions("machinery:delete")
110
+    public ResponseBean taMachineryDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
111
+        SysUser sysUser = currentUser();
112
+
113
+        TaMachinery taMachinery = iTaMachineryService.getExistBy("machinery_id", id, false, true);
114
+        if (null == taMachinery) {
115
+            return ResponseBean.success("success");
116
+        }
117
+
118
+        if (!checkOrgAccess(taMachinery.getOrgId(), sysUser.getUserId())) {
119
+            return ResponseBean.error("无权进行此操作");
120
+        }
121
+
122
+        if(iTaMachineryService.removeLogicById(id)){
86 123
             return ResponseBean.success("success");
87 124
         }else {
88 125
             return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
@@ -95,13 +132,25 @@ public class TaMachineryController extends BaseController {
95 132
      * @param taMachinery 实体对象
96 133
      * @return
97 134
      */
98
-    @RequestMapping(value="/taMachinery/{id}",method= RequestMethod.PUT)
135
+    @RequestMapping(value="/admin/machinery/{id}",method= RequestMethod.PUT)
99 136
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
100
-    public ResponseBean taMachineryUpdate(@ApiParam("对象ID") @PathVariable Integer id,
137
+    @RequiresPermissions("machinery:update")
138
+    public ResponseBean taMachineryUpdate(@ApiParam("对象ID") @PathVariable String id,
101 139
                                         @ApiParam("更新内容") @RequestBody TaMachinery taMachinery) throws Exception{
140
+        SysUser sysUser = currentUser();
141
+
142
+        if (StringUtils.isEmpty(taMachinery.getOrgId())) {
143
+            return ResponseBean.error("请设置农机归属");
144
+        }
102 145
 
103
-        if (iTaMachineryService.updateById(taMachinery)){
104
-            return ResponseBean.success(iTaMachineryService.getById(id));
146
+        if (!checkOrgAccess(taMachinery.getOrgId(), sysUser.getUserId())) {
147
+            return ResponseBean.error("无权进行此操作");
148
+        }
149
+
150
+        taMachinery.setMachineryId(id);
151
+
152
+        if (iTaMachineryService.updateAll(taMachinery)){
153
+            return ResponseBean.success(taMachinery);
105 154
         }else {
106 155
             return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
107 156
         }
@@ -111,9 +160,9 @@ public class TaMachineryController extends BaseController {
111 160
      * 根据id查询对象
112 161
      * @param id  实体ID
113 162
      */
114
-    @RequestMapping(value="/taMachinery/{id}",method= RequestMethod.GET)
163
+    @RequestMapping(value="/admin/machinery/{id}",method= RequestMethod.GET)
115 164
     @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
116
-    public ResponseBean taMachineryGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
117
-        return ResponseBean.success(iTaMachineryService.getById(id));
165
+    public ResponseBean taMachineryGet(@ApiParam("对象ID") @PathVariable String id) throws Exception{
166
+        return ResponseBean.success(iTaMachineryService.getDetail(id));
118 167
     }
119 168
 }

+ 68
- 17
src/main/java/com/yunzhi/nanyang/controller/TaNewsController.java Целия файл

@@ -4,10 +4,17 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 4
 import com.baomidou.mybatisplus.core.metadata.IPage;
5 5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 6
 import com.yunzhi.nanyang.common.BaseController;
7
+import com.yunzhi.nanyang.common.Constants;
7 8
 import com.yunzhi.nanyang.common.ResponseBean;
9
+import com.yunzhi.nanyang.common.StringUtils;
10
+import com.yunzhi.nanyang.entity.SysUser;
11
+import com.yunzhi.nanyang.entity.TaExtendContent;
12
+import com.yunzhi.nanyang.service.ITaExtendContentService;
13
+import com.yunzhi.nanyang.service.ITaNewsTypeService;
8 14
 import io.swagger.annotations.Api;
9 15
 import io.swagger.annotations.ApiOperation;
10 16
 import io.swagger.annotations.ApiParam;
17
+import org.apache.shiro.authz.annotation.RequiresPermissions;
11 18
 import org.slf4j.Logger;
12 19
 import org.slf4j.LoggerFactory;
13 20
 import org.springframework.beans.factory.annotation.Autowired;
@@ -20,6 +27,8 @@ import com.yunzhi.nanyang.service.ITaNewsService;
20 27
 import com.yunzhi.nanyang.entity.TaNews;
21 28
 import org.springframework.web.bind.annotation.RestController;
22 29
 
30
+import java.util.List;
31
+
23 32
 /**
24 33
  * <p>
25 34
     * 资讯表 前端控制器
@@ -39,6 +48,12 @@ public class TaNewsController extends BaseController {
39 48
     @Autowired
40 49
     public ITaNewsService iTaNewsService;
41 50
 
51
+    @Autowired
52
+    public ITaNewsTypeService iTaNewsTypeService;
53
+
54
+    @Autowired
55
+    public ITaExtendContentService iTaExtendContentService;
56
+
42 57
 
43 58
     /**
44 59
      * 分页查询列表
@@ -46,17 +61,25 @@ public class TaNewsController extends BaseController {
46 61
      * @param pageSize
47 62
      * @return
48 63
      */
49
-    @RequestMapping(value="/taNews",method= RequestMethod.GET)
64
+    @RequestMapping(value="/admin/news",method= RequestMethod.GET)
50 65
     @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
51 66
     public ResponseBean taNewsList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
-									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
67
+									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
68
+                                   @ApiParam("名称") @RequestParam(value ="title", required = false) String title,
69
+                                   @ApiParam("类型") @RequestParam(value ="typeId", required = false) String typeId) throws Exception{
70
+//        SysUser sysUser = currentUser();
71
+//        boolean isAdmin = Constants.ADMIN_ID.equals(sysUser.getUserId());
53 72
 
54
-		    IPage<TaNews> pg = new Page<>(pageNum, pageSize);
55
-            QueryWrapper<TaNews> queryWrapper = new QueryWrapper<>();
56
-            queryWrapper.orderByDesc("create_date");
73
+        IPage<TaNews> pg = new Page<>(pageNum, pageSize);
74
+        QueryWrapper<TaNews> queryWrapper = new QueryWrapper<>();
75
+        queryWrapper.like(!StringUtils.isEmpty(title), "title", "%" + title + "%");
76
+        queryWrapper.eq(!StringUtils.isEmpty(typeId), "type_id", typeId);
77
+//        queryWrapper.in(!isAdmin, "org_id", getAccessOrgs(sysUser.getUserId()));
78
+        queryWrapper.gt("status", Constants.STATUS_DELETE);
79
+        queryWrapper.orderByDesc("create_date");
57 80
 
58
-            IPage<TaNews> result = iTaNewsService.page(pg, queryWrapper);
59
-            return ResponseBean.success(result);
81
+        IPage<TaNews> result = iTaNewsService.page(pg, queryWrapper);
82
+        return ResponseBean.success(result);
60 83
     }
61 84
 
62 85
     /**
@@ -64,11 +87,20 @@ public class TaNewsController extends BaseController {
64 87
      * @param taNews 实体对象
65 88
      * @return
66 89
      */
67
-    @RequestMapping(value="/taNews",method= RequestMethod.POST)
90
+    @RequestMapping(value="/admin/news",method= RequestMethod.POST)
68 91
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
92
+    @RequiresPermissions("news:add")
69 93
     public ResponseBean taNewsAdd(@ApiParam("保存内容") @RequestBody TaNews taNews) throws Exception{
94
+        SysUser sysUser = currentUser();
95
+
96
+        if (StringUtils.isEmpty(taNews.getTitle()) || StringUtils.isEmpty(taNews.getTypeId())) {
97
+            return ResponseBean.error("标题或者分类不能为空");
98
+        }
99
+
100
+        taNews.setTypeName(iTaNewsTypeService.getById(taNews.getTypeId()).getName());
70 101
 
71 102
         if (iTaNewsService.save(taNews)){
103
+            iTaExtendContentService.editContent(Constants.TARGET_NEWS, taNews.getNewsId(), taNews.getContentList());
72 104
             return ResponseBean.success(taNews);
73 105
         }else {
74 106
             return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
@@ -79,10 +111,11 @@ public class TaNewsController extends BaseController {
79 111
      * 根据id删除对象
80 112
      * @param id  实体ID
81 113
      */
82
-    @RequestMapping(value="/taNews/{id}", method= RequestMethod.DELETE)
114
+    @RequestMapping(value="/admin/news/{id}", method= RequestMethod.DELETE)
83 115
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
84
-    public ResponseBean taNewsDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
85
-        if(iTaNewsService.removeById(id)){
116
+    @RequiresPermissions("news:delete")
117
+    public ResponseBean taNewsDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
118
+        if(iTaNewsService.removeLogicById(id)){
86 119
             return ResponseBean.success("success");
87 120
         }else {
88 121
             return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
@@ -95,13 +128,23 @@ public class TaNewsController extends BaseController {
95 128
      * @param taNews 实体对象
96 129
      * @return
97 130
      */
98
-    @RequestMapping(value="/taNews/{id}",method= RequestMethod.PUT)
131
+    @RequestMapping(value="/admin/news/{id}",method= RequestMethod.PUT)
99 132
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
100
-    public ResponseBean taNewsUpdate(@ApiParam("对象ID") @PathVariable Integer id,
133
+    @RequiresPermissions("news:update")
134
+    public ResponseBean taNewsUpdate(@ApiParam("对象ID") @PathVariable String id,
101 135
                                         @ApiParam("更新内容") @RequestBody TaNews taNews) throws Exception{
136
+        taNews.setNewsId(id);
137
+
138
+        if (StringUtils.isEmpty(taNews.getTitle()) || StringUtils.isEmpty(taNews.getTypeId())) {
139
+            return ResponseBean.error("标题或者分类不能为空");
140
+        }
141
+
142
+        taNews.setTypeName(iTaNewsTypeService.getById(taNews.getTypeId()).getName());
143
+
144
+        iTaExtendContentService.editContent(Constants.TARGET_NEWS, id, taNews.getContentList());
102 145
 
103 146
         if (iTaNewsService.updateById(taNews)){
104
-            return ResponseBean.success(iTaNewsService.getById(id));
147
+            return ResponseBean.success(taNews);
105 148
         }else {
106 149
             return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
107 150
         }
@@ -111,9 +154,17 @@ public class TaNewsController extends BaseController {
111 154
      * 根据id查询对象
112 155
      * @param id  实体ID
113 156
      */
114
-    @RequestMapping(value="/taNews/{id}",method= RequestMethod.GET)
157
+    @RequestMapping(value="/admin/news/{id}",method= RequestMethod.GET)
115 158
     @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
116
-    public ResponseBean taNewsGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
117
-        return ResponseBean.success(iTaNewsService.getById(id));
159
+    public ResponseBean taNewsGet(@ApiParam("对象ID") @PathVariable String id) throws Exception{
160
+        TaNews taNews = iTaNewsService.getExistBy("news_id", id, false, true);
161
+        if (null == taNews) {
162
+            return ResponseBean.error("内存不存在");
163
+        }
164
+
165
+        List<TaExtendContent> contentList = iTaExtendContentService.listByTarget(Constants.TARGET_NEWS, id);
166
+        taNews.setContentList(contentList);
167
+
168
+        return ResponseBean.success(taNews);
118 169
     }
119 170
 }

+ 48
- 8
src/main/java/com/yunzhi/nanyang/controller/TaNewsTypeController.java Целия файл

@@ -6,9 +6,12 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 6
 import com.yunzhi.nanyang.common.BaseController;
7 7
 import com.yunzhi.nanyang.common.Constants;
8 8
 import com.yunzhi.nanyang.common.ResponseBean;
9
+import com.yunzhi.nanyang.common.StringUtils;
10
+import com.yunzhi.nanyang.service.ITaNewsService;
9 11
 import io.swagger.annotations.Api;
10 12
 import io.swagger.annotations.ApiOperation;
11 13
 import io.swagger.annotations.ApiParam;
14
+import org.apache.shiro.authz.annotation.RequiresPermissions;
12 15
 import org.slf4j.Logger;
13 16
 import org.slf4j.LoggerFactory;
14 17
 import org.springframework.beans.factory.annotation.Autowired;
@@ -40,6 +43,8 @@ public class TaNewsTypeController extends BaseController {
40 43
     @Autowired
41 44
     public ITaNewsTypeService iTaNewsTypeService;
42 45
 
46
+    @Autowired
47
+    public ITaNewsService iTaNewsService;
43 48
 
44 49
     /**
45 50
      * 分页查询列表
@@ -50,10 +55,12 @@ public class TaNewsTypeController extends BaseController {
50 55
     @RequestMapping(value="/admin/news-type",method= RequestMethod.GET)
51 56
     @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
52 57
     public ResponseBean taNewsTypeList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
53
-									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
58
+                                       @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
59
+                                       @ApiParam("名称") @RequestParam(value ="name", required = false) String name) throws Exception{
54 60
 
55 61
         IPage<TaNewsType> pg = new Page<>(pageNum, pageSize);
56 62
         QueryWrapper<TaNewsType> queryWrapper = new QueryWrapper<>();
63
+        queryWrapper.like(!StringUtils.isEmpty(name), "name", "%" + name + "%");
57 64
         queryWrapper.gt("status", Constants.STATUS_DELETE);
58 65
         queryWrapper.orderByDesc("create_date");
59 66
 
@@ -66,9 +73,21 @@ public class TaNewsTypeController extends BaseController {
66 73
      * @param taNewsType 实体对象
67 74
      * @return
68 75
      */
69
-    @RequestMapping(value="/taNewsType",method= RequestMethod.POST)
76
+    @RequestMapping(value="/admin/news-type",method= RequestMethod.POST)
70 77
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
78
+    @RequiresPermissions("news:add")
71 79
     public ResponseBean taNewsTypeAdd(@ApiParam("保存内容") @RequestBody TaNewsType taNewsType) throws Exception{
80
+        taNewsType.setTypeId(null);
81
+
82
+        if (StringUtils.isEmpty(taNewsType.getName())) {
83
+            return ResponseBean.error("名称不能为空");
84
+        }
85
+
86
+        int cnt = iTaNewsTypeService.countBy("name", taNewsType.getName(), true);
87
+        if (cnt > 0) {
88
+            return ResponseBean.error("名称重复");
89
+        }
90
+
72 91
 
73 92
         if (iTaNewsTypeService.save(taNewsType)){
74 93
             return ResponseBean.success(taNewsType);
@@ -81,9 +100,20 @@ public class TaNewsTypeController extends BaseController {
81 100
      * 根据id删除对象
82 101
      * @param id  实体ID
83 102
      */
84
-    @RequestMapping(value="/taNewsType/{id}", method= RequestMethod.DELETE)
103
+    @RequestMapping(value="/admin/news-type/{id}", method= RequestMethod.DELETE)
85 104
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
86
-    public ResponseBean taNewsTypeDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
105
+    @RequiresPermissions("news:delete")
106
+    public ResponseBean taNewsTypeDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
107
+        TaNewsType taNewsType = iTaNewsTypeService.getExistBy("type_id", id, false, true);
108
+        if (null == taNewsType) {
109
+            return ResponseBean.success("success");
110
+        }
111
+
112
+        int cnt = iTaNewsService.countBy("type_id", id, true);
113
+        if (cnt > 0) {
114
+            return ResponseBean.error("请先移除当前分类下的资讯信息");
115
+        }
116
+
87 117
         if(iTaNewsTypeService.removeById(id)){
88 118
             return ResponseBean.success("success");
89 119
         }else {
@@ -97,10 +127,20 @@ public class TaNewsTypeController extends BaseController {
97 127
      * @param taNewsType 实体对象
98 128
      * @return
99 129
      */
100
-    @RequestMapping(value="/taNewsType/{id}",method= RequestMethod.PUT)
130
+    @RequestMapping(value="/admin/news-type/{id}",method= RequestMethod.PUT)
101 131
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
102
-    public ResponseBean taNewsTypeUpdate(@ApiParam("对象ID") @PathVariable Integer id,
132
+    @RequiresPermissions("news:update")
133
+    public ResponseBean taNewsTypeUpdate(@ApiParam("对象ID") @PathVariable String id,
103 134
                                         @ApiParam("更新内容") @RequestBody TaNewsType taNewsType) throws Exception{
135
+        taNewsType.setTypeId(id);
136
+
137
+        if (StringUtils.isEmpty(taNewsType.getName())) {
138
+            return ResponseBean.error("名称不能为空");
139
+        }
140
+        TaNewsType origin = iTaNewsTypeService.getByButNot("name", taNewsType.getName(), "type_id", id, true);
141
+        if (origin != null) {
142
+            return ResponseBean.error("名称重复");
143
+        }
104 144
 
105 145
         if (iTaNewsTypeService.updateById(taNewsType)){
106 146
             return ResponseBean.success(iTaNewsTypeService.getById(id));
@@ -113,9 +153,9 @@ public class TaNewsTypeController extends BaseController {
113 153
      * 根据id查询对象
114 154
      * @param id  实体ID
115 155
      */
116
-    @RequestMapping(value="/taNewsType/{id}",method= RequestMethod.GET)
156
+    @RequestMapping(value="/admin/news-type/{id}",method= RequestMethod.GET)
117 157
     @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
118 158
     public ResponseBean taNewsTypeGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
119
-        return ResponseBean.success(iTaNewsTypeService.getById(id));
159
+        return ResponseBean.success(iTaNewsTypeService.getExistBy("type_id", id, false, true));
120 160
     }
121 161
 }

+ 80
- 61
src/main/java/com/yunzhi/nanyang/controller/TaPersonController.java Целия файл

@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
5 5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 6
 import com.yunzhi.nanyang.common.BaseController;
7 7
 import com.yunzhi.nanyang.common.ResponseBean;
8
+import com.yunzhi.nanyang.common.SMSCaptcha;
9
+import com.yunzhi.nanyang.vo.PhoneParam;
8 10
 import io.swagger.annotations.Api;
9 11
 import io.swagger.annotations.ApiOperation;
10 12
 import io.swagger.annotations.ApiParam;
@@ -39,81 +41,98 @@ public class TaPersonController extends BaseController {
39 41
     @Autowired
40 42
     public ITaPersonService iTaPersonService;
41 43
 
44
+    @Autowired
45
+    public SMSCaptcha smsCaptcha;
42 46
 
43
-    /**
44
-     * 分页查询列表
45
-     * @param pageNum
46
-     * @param pageSize
47
-     * @return
48
-     */
49
-    @RequestMapping(value="/taPerson",method= RequestMethod.GET)
50
-    @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
51
-    public ResponseBean taPersonList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
-									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
53
-
54
-		    IPage<TaPerson> pg = new Page<>(pageNum, pageSize);
55
-            QueryWrapper<TaPerson> queryWrapper = new QueryWrapper<>();
56
-            queryWrapper.orderByDesc("create_date");
57
-
58
-            IPage<TaPerson> result = iTaPersonService.page(pg, queryWrapper);
59
-            return ResponseBean.success(result);
60
-    }
61 47
 
48
+//    /**
49
+//     * 分页查询列表
50
+//     * @param pageNum
51
+//     * @param pageSize
52
+//     * @return
53
+//     */
54
+//    @RequestMapping(value="/taPerson",method= RequestMethod.GET)
55
+//    @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
56
+//    public ResponseBean taPersonList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
57
+//									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
58
+//
59
+//		    IPage<TaPerson> pg = new Page<>(pageNum, pageSize);
60
+//            QueryWrapper<TaPerson> queryWrapper = new QueryWrapper<>();
61
+//            queryWrapper.orderByDesc("create_date");
62
+//
63
+//            IPage<TaPerson> result = iTaPersonService.page(pg, queryWrapper);
64
+//            return ResponseBean.success(result);
65
+//    }
66
+//
67
+//    /**
68
+//     * 保存对象
69
+//     * @param taPerson 实体对象
70
+//     * @return
71
+//     */
72
+//    @RequestMapping(value="/taPerson",method= RequestMethod.POST)
73
+//    @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
74
+//    public ResponseBean taPersonAdd(@ApiParam("保存内容") @RequestBody TaPerson taPerson) throws Exception{
75
+//
76
+//        if (iTaPersonService.save(taPerson)){
77
+//            return ResponseBean.success(taPerson);
78
+//        }else {
79
+//            return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
80
+//        }
81
+//    }
82
+//
83
+//    /**
84
+//     * 根据id删除对象
85
+//     * @param id  实体ID
86
+//     */
87
+//    @RequestMapping(value="/taPerson/{id}", method= RequestMethod.DELETE)
88
+//    @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
89
+//    public ResponseBean taPersonDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
90
+//        if(iTaPersonService.removeById(id)){
91
+//            return ResponseBean.success("success");
92
+//        }else {
93
+//            return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
94
+//        }
95
+//    }
96
+//
62 97
     /**
63
-     * 保存对象
64
-     * @param taPerson 实体对象
98
+     * 修改对象
99
+     * @param appid  实体ID
100
+     * @param id  实体ID
101
+     * @param phoneParam 实体对象
65 102
      * @return
66 103
      */
67
-    @RequestMapping(value="/taPerson",method= RequestMethod.POST)
68
-    @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
69
-    public ResponseBean taPersonAdd(@ApiParam("保存内容") @RequestBody TaPerson taPerson) throws Exception{
104
+    @RequestMapping(value="/wx/{appid}/person/{id}/phone",method= RequestMethod.PUT)
105
+    @ApiOperation(value="更新电话", notes = "更新电话", httpMethod = "PUT", response = ResponseBean.class)
106
+    public ResponseBean taPersonUpdate(@ApiParam("小程序ID") @PathVariable String appid,
107
+                                       @ApiParam("对象ID") @PathVariable String id,
108
+                                       @ApiParam("更新内容") @RequestBody PhoneParam phoneParam) throws Exception{
70 109
 
71
-        if (iTaPersonService.save(taPerson)){
72
-            return ResponseBean.success(taPerson);
73
-        }else {
74
-            return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
110
+        TaPerson taPerson = currentPerson();
111
+        if (!id.equals(taPerson.getPersonId())) {
112
+            return ResponseBean.error("待更新人员ID不正确");
75 113
         }
76
-    }
77 114
 
78
-    /**
79
-     * 根据id删除对象
80
-     * @param id  实体ID
81
-     */
82
-    @RequestMapping(value="/taPerson/{id}", method= RequestMethod.DELETE)
83
-    @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
84
-    public ResponseBean taPersonDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
85
-        if(iTaPersonService.removeById(id)){
86
-            return ResponseBean.success("success");
87
-        }else {
88
-            return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
115
+        boolean isOk = smsCaptcha.validate(phoneParam.getPhone(), phoneParam.getCaptcha());
116
+        if (!isOk) {
117
+            return ResponseBean.error("验证码不正确或者已过期");
89 118
         }
90
-    }
91 119
 
92
-    /**
93
-     * 修改对象
94
-     * @param id  实体ID
95
-     * @param taPerson 实体对象
96
-     * @return
97
-     */
98
-    @RequestMapping(value="/taPerson/{id}",method= RequestMethod.PUT)
99
-    @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
100
-    public ResponseBean taPersonUpdate(@ApiParam("对象ID") @PathVariable Integer id,
101
-                                        @ApiParam("更新内容") @RequestBody TaPerson taPerson) throws Exception{
120
+        taPerson.setPhone(phoneParam.getPhone());
102 121
 
103 122
         if (iTaPersonService.updateById(taPerson)){
104
-            return ResponseBean.success(iTaPersonService.getById(id));
123
+            return ResponseBean.success(taPerson);
105 124
         }else {
106 125
             return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
107 126
         }
108 127
     }
109
-
110
-    /**
111
-     * 根据id查询对象
112
-     * @param id  实体ID
113
-     */
114
-    @RequestMapping(value="/taPerson/{id}",method= RequestMethod.GET)
115
-    @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
116
-    public ResponseBean taPersonGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
117
-        return ResponseBean.success(iTaPersonService.getById(id));
118
-    }
128
+//
129
+//    /**
130
+//     * 根据id查询对象
131
+//     * @param id  实体ID
132
+//     */
133
+//    @RequestMapping(value="/taPerson/{id}",method= RequestMethod.GET)
134
+//    @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
135
+//    public ResponseBean taPersonGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
136
+//        return ResponseBean.success(iTaPersonService.getById(id));
137
+//    }
119 138
 }

+ 62
- 16
src/main/java/com/yunzhi/nanyang/controller/TdMachineryTypeController.java Целия файл

@@ -4,10 +4,14 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 4
 import com.baomidou.mybatisplus.core.metadata.IPage;
5 5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 6
 import com.yunzhi.nanyang.common.BaseController;
7
+import com.yunzhi.nanyang.common.Constants;
7 8
 import com.yunzhi.nanyang.common.ResponseBean;
9
+import com.yunzhi.nanyang.common.StringUtils;
10
+import com.yunzhi.nanyang.service.ITaMachineryService;
8 11
 import io.swagger.annotations.Api;
9 12
 import io.swagger.annotations.ApiOperation;
10 13
 import io.swagger.annotations.ApiParam;
14
+import org.apache.shiro.authz.annotation.RequiresPermissions;
11 15
 import org.slf4j.Logger;
12 16
 import org.slf4j.LoggerFactory;
13 17
 import org.springframework.beans.factory.annotation.Autowired;
@@ -39,6 +43,9 @@ public class TdMachineryTypeController extends BaseController {
39 43
     @Autowired
40 44
     public ITdMachineryTypeService iTdMachineryTypeService;
41 45
 
46
+    @Autowired
47
+    public ITaMachineryService iTaMachineryService;
48
+
42 49
 
43 50
     /**
44 51
      * 分页查询列表
@@ -46,17 +53,20 @@ public class TdMachineryTypeController extends BaseController {
46 53
      * @param pageSize
47 54
      * @return
48 55
      */
49
-    @RequestMapping(value="/tdMachineryType",method= RequestMethod.GET)
56
+    @RequestMapping(value="/admin/machinery-type",method= RequestMethod.GET)
50 57
     @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
51 58
     public ResponseBean tdMachineryTypeList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
-									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
59
+                                            @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
60
+                                            @ApiParam("单页数据量") @RequestParam(value ="name", required = false) String name) throws Exception{
53 61
 
54
-		    IPage<TdMachineryType> pg = new Page<>(pageNum, pageSize);
55
-            QueryWrapper<TdMachineryType> queryWrapper = new QueryWrapper<>();
56
-            queryWrapper.orderByDesc("create_date");
62
+        IPage<TdMachineryType> pg = new Page<>(pageNum, pageSize);
63
+        QueryWrapper<TdMachineryType> queryWrapper = new QueryWrapper<>();
64
+        queryWrapper.like(!StringUtils.isEmpty(name), "name", "%" + name + "%");
65
+        queryWrapper.gt("status", Constants.STATUS_DELETE);
66
+        queryWrapper.orderByDesc("create_date");
57 67
 
58
-            IPage<TdMachineryType> result = iTdMachineryTypeService.page(pg, queryWrapper);
59
-            return ResponseBean.success(result);
68
+        IPage<TdMachineryType> result = iTdMachineryTypeService.page(pg, queryWrapper);
69
+        return ResponseBean.success(result);
60 70
     }
61 71
 
62 72
     /**
@@ -64,10 +74,22 @@ public class TdMachineryTypeController extends BaseController {
64 74
      * @param tdMachineryType 实体对象
65 75
      * @return
66 76
      */
67
-    @RequestMapping(value="/tdMachineryType",method= RequestMethod.POST)
77
+    @RequestMapping(value="/admin/machinery-type",method= RequestMethod.POST)
68 78
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
79
+    @RequiresPermissions("machinetype:add")
69 80
     public ResponseBean tdMachineryTypeAdd(@ApiParam("保存内容") @RequestBody TdMachineryType tdMachineryType) throws Exception{
70 81
 
82
+        tdMachineryType.setTypeId(null);
83
+
84
+        if (StringUtils.isEmpty(tdMachineryType.getName())) {
85
+            return ResponseBean.error("名称不能为空");
86
+        }
87
+
88
+        int cnt = iTdMachineryTypeService.countBy("name", tdMachineryType.getName(), true);
89
+        if (cnt > 0) {
90
+            return ResponseBean.error("名称重复");
91
+        }
92
+
71 93
         if (iTdMachineryTypeService.save(tdMachineryType)){
72 94
             return ResponseBean.success(tdMachineryType);
73 95
         }else {
@@ -79,10 +101,23 @@ public class TdMachineryTypeController extends BaseController {
79 101
      * 根据id删除对象
80 102
      * @param id  实体ID
81 103
      */
82
-    @RequestMapping(value="/tdMachineryType/{id}", method= RequestMethod.DELETE)
104
+    @RequestMapping(value="/admin/machinery-type/{id}", method= RequestMethod.DELETE)
83 105
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
84
-    public ResponseBean tdMachineryTypeDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
85
-        if(iTdMachineryTypeService.removeById(id)){
106
+    @RequiresPermissions("machinetype:delete")
107
+    public ResponseBean tdMachineryTypeDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
108
+
109
+        TdMachineryType tdMachineryType = iTdMachineryTypeService.getExistBy("type_id", id, false, true);
110
+        if (null == tdMachineryType) {
111
+            return ResponseBean.success("success");
112
+        }
113
+
114
+        int cnt = iTaMachineryService.countBy("type_id", id, true);
115
+        if (cnt > 0) {
116
+            return ResponseBean.error("请先移除当前分类下的农机信息");
117
+        }
118
+
119
+
120
+        if(iTdMachineryTypeService.removeLogicById(id)){
86 121
             return ResponseBean.success("success");
87 122
         }else {
88 123
             return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
@@ -95,10 +130,21 @@ public class TdMachineryTypeController extends BaseController {
95 130
      * @param tdMachineryType 实体对象
96 131
      * @return
97 132
      */
98
-    @RequestMapping(value="/tdMachineryType/{id}",method= RequestMethod.PUT)
133
+    @RequestMapping(value="/admin/machinery-type/{id}",method= RequestMethod.PUT)
99 134
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
100
-    public ResponseBean tdMachineryTypeUpdate(@ApiParam("对象ID") @PathVariable Integer id,
135
+    @RequiresPermissions("machinetype:update")
136
+    public ResponseBean tdMachineryTypeUpdate(@ApiParam("对象ID") @PathVariable String id,
101 137
                                         @ApiParam("更新内容") @RequestBody TdMachineryType tdMachineryType) throws Exception{
138
+        tdMachineryType.setTypeId(id);
139
+
140
+        if (StringUtils.isEmpty(tdMachineryType.getName())) {
141
+            return ResponseBean.error("名称不能为空");
142
+        }
143
+
144
+        TdMachineryType origin = iTdMachineryTypeService.getByButNot("name", tdMachineryType.getName(), "type_id", id, true);
145
+        if (origin != null) {
146
+            return ResponseBean.error("名称重复");
147
+        }
102 148
 
103 149
         if (iTdMachineryTypeService.updateById(tdMachineryType)){
104 150
             return ResponseBean.success(iTdMachineryTypeService.getById(id));
@@ -111,9 +157,9 @@ public class TdMachineryTypeController extends BaseController {
111 157
      * 根据id查询对象
112 158
      * @param id  实体ID
113 159
      */
114
-    @RequestMapping(value="/tdMachineryType/{id}",method= RequestMethod.GET)
160
+    @RequestMapping(value="/admin/machinery-type/{id}",method= RequestMethod.GET)
115 161
     @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
116
-    public ResponseBean tdMachineryTypeGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
117
-        return ResponseBean.success(iTdMachineryTypeService.getById(id));
162
+    public ResponseBean tdMachineryTypeGet(@ApiParam("对象ID") @PathVariable String id) throws Exception{
163
+        return ResponseBean.success(iTdMachineryTypeService.getExistBy("type_id", id, false, true));
118 164
     }
119 165
 }

+ 173
- 0
src/main/java/com/yunzhi/nanyang/controller/WxMaController.java Целия файл

@@ -0,0 +1,173 @@
1
+package com.yunzhi.nanyang.controller;
2
+
3
+import cn.binarywang.wx.miniapp.api.WxMaService;
4
+import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
5
+import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
6
+import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
7
+import com.yunzhi.nanyang.common.*;
8
+import com.yunzhi.nanyang.entity.SysMiniapp;
9
+import com.yunzhi.nanyang.entity.TaPerson;
10
+import com.yunzhi.nanyang.service.ISysMiniappService;
11
+import com.yunzhi.nanyang.service.ITaPersonService;
12
+import com.yunzhi.nanyang.shiro.utils.JWTUtil;
13
+import com.yunzhi.nanyang.vo.LoginParam;
14
+import com.yunzhi.nanyang.vo.WxMaAuthParam;
15
+import com.yunzhi.nanyang.vo.WxMaPreload;
16
+import io.swagger.annotations.Api;
17
+import io.swagger.annotations.ApiOperation;
18
+import io.swagger.annotations.ApiParam;
19
+import org.springframework.beans.factory.annotation.Autowired;
20
+import org.springframework.web.bind.annotation.*;
21
+
22
+import java.time.LocalDateTime;
23
+import java.util.HashMap;
24
+import java.util.Map;
25
+
26
+@Api(tags = "小程序登入/登出")
27
+@RestController
28
+@RequestMapping("/wx/{appid}")
29
+public class WxMaController extends BaseController {
30
+
31
+    @Autowired
32
+    ISysMiniappService iSysMiniappService;
33
+
34
+    @Autowired
35
+    ITaPersonService iTaPersonService;
36
+
37
+    @Autowired
38
+    SMSCaptcha smsCaptcha;
39
+
40
+    @Autowired
41
+    WxUtils wxUtils;
42
+
43
+    private boolean checkLoginParam(LoginParam loginParam) {
44
+        return !StringUtils.isEmpty(loginParam.getCode())
45
+                && !StringUtils.isEmpty(loginParam.getUserName())
46
+                && !StringUtils.isEmpty(loginParam.getPassword());
47
+    }
48
+
49
+    private WxMaService getService(String appid) throws Exception {
50
+        SysMiniapp miniapp = iSysMiniappService.getById(appid);
51
+        if (null == miniapp || miniapp.getStatus() != Constants.STATUS_NORMAL) {
52
+            throw new Exception("未找到有效的小程序配置");
53
+        }
54
+
55
+        return wxUtils.getService(miniapp.getClient());
56
+    }
57
+
58
+    @GetMapping("/preload")
59
+    @ApiOperation(value="小程序登录", notes = "小程序登录", httpMethod = "POST", response = ResponseBean.class)
60
+    public ResponseBean preload(@ApiParam("小程序ID") @PathVariable String appid,
61
+                                @ApiParam("小程序预加载参数") @RequestParam WxMaPreload wxMaPreload) throws Exception {
62
+        if (!appid.equals(wxMaPreload.getAppid())) {
63
+            return ResponseBean.error("小程序预加载接口配置错误");
64
+        }
65
+
66
+        return ResponseBean.success(null);
67
+    }
68
+
69
+    /**
70
+     * 小程序
71
+     * @param loginParam
72
+     * @return
73
+     * @throws Exception
74
+     */
75
+    @PostMapping("/login")
76
+    @ApiOperation(value="小程序登录", notes = "小程序登录", httpMethod = "POST", response = ResponseBean.class)
77
+    public ResponseBean appLogin(@ApiParam("小程序ID") @PathVariable String appid,
78
+                                 @ApiParam("登录参数") @RequestBody LoginParam loginParam) throws Exception {
79
+
80
+        if (StringUtils.isEmpty(loginParam.getCode())) {
81
+            return ResponseBean.error("CODE 不能为空");
82
+        }
83
+
84
+        WxMaService service = getService(appid);
85
+
86
+        WxMaJscode2SessionResult sessionInfo = service.getUserService().getSessionInfo(loginParam.getCode());
87
+        String openid = sessionInfo.getOpenid();
88
+        String sessionKey = sessionInfo.getSessionKey();
89
+
90
+        TaPerson taPerson = iTaPersonService.getByOpenId(appid, openid);
91
+        if (null == taPerson) {
92
+            taPerson = new TaPerson();
93
+            taPerson.setOpenid(openid);
94
+            taPerson.setStatus(Constants.STATUS_NORMAL);
95
+            taPerson.setCreateDate(LocalDateTime.now());
96
+            iTaPersonService.save(taPerson);
97
+        }
98
+
99
+        // 生成 token
100
+        String token = JWTUtil.sign(taPerson.getPersonId(), taPerson.getPersonId());
101
+
102
+        Map<String, Object> res = new HashMap<>();
103
+        res.put("person", taPerson);
104
+        res.put("token", token);
105
+        res.put("sessionKey", sessionKey);
106
+
107
+        return ResponseBean.success(res);
108
+    }
109
+
110
+
111
+    @PutMapping("/auth-user")
112
+    @ApiOperation(value="授权头像", notes = "授权头像", httpMethod = "PUT", response = TaPerson.class)
113
+    public ResponseBean updateUserInfo(@ApiParam("小程序ID") @PathVariable String appid,
114
+                                       @ApiParam("授权头像的参数") @RequestBody WxMaAuthParam params) throws Exception {
115
+        WxMaService service = getService(appid);
116
+        checkAuthParams(service, params);
117
+
118
+        // 解密用户信息
119
+        WxMaUserInfo userInfo = service.getUserService().getUserInfo(params.getSessionKey(), params.getEncryptedData(), params.getIv());
120
+
121
+        TaPerson taPerson = currentPerson();
122
+        if (null == taPerson) {
123
+            throw new Exception("校验当前人员失败, 请重试");
124
+        }
125
+
126
+        taPerson.setAvatar(userInfo.getAvatarUrl());
127
+        taPerson.setNickName(userInfo.getNickName());
128
+        taPerson.setSex(Integer.parseInt(userInfo.getGender()));
129
+
130
+        iTaPersonService.updateById(taPerson);
131
+
132
+        return ResponseBean.success(taPerson);
133
+    }
134
+
135
+    @ApiOperation(value="授权手机", notes = "授权手机", httpMethod = "PUT", response = TaPerson.class)
136
+    @PutMapping("/auth-phone")
137
+    public ResponseBean updateUserPhone(@ApiParam("小程序ID") @PathVariable String appid,
138
+                                        @ApiParam("授权手机的参数") @RequestBody WxMaAuthParam params) throws Exception {
139
+
140
+        WxMaService service = getService(appid);
141
+
142
+        // 解密
143
+        WxMaPhoneNumberInfo phoneNoInfo = service.getUserService().getPhoneNoInfo(params.getSessionKey(), params.getEncryptedData(), params.getIv());
144
+
145
+        TaPerson taPerson = currentPerson();
146
+        if (null == taPerson) {
147
+            throw new Exception("校验当前人员失败, 请重试");
148
+        }
149
+
150
+        taPerson.setPhone(phoneNoInfo.getPhoneNumber());
151
+        iTaPersonService.updateById(taPerson);
152
+
153
+        return ResponseBean.success(taPerson);
154
+    }
155
+
156
+
157
+    private void checkAuthParams(WxMaService service, WxMaAuthParam params) throws Exception {
158
+        String signature = params.getSignature();
159
+        String rawData = params.getRawData();
160
+        String encryptedData = params.getEncryptedData();
161
+        String iv = params.getIv();
162
+        String sessionKey = params.getSessionKey();
163
+
164
+        if (StringUtils.isEmpty(signature) || StringUtils.isEmpty(rawData) || StringUtils.isEmpty(encryptedData) || StringUtils.isEmpty(iv) || StringUtils.isEmpty(sessionKey)) {
165
+            throw new Exception("缺失授权参数");
166
+        }
167
+
168
+        boolean isValid = service.getUserService().checkUserInfo(sessionKey, rawData, signature);
169
+        if (!isValid) {
170
+            throw new Exception("校验授权参数失败, 请重试");
171
+        }
172
+    }
173
+}

+ 55
- 0
src/main/java/com/yunzhi/nanyang/entity/SysMiniapp.java Целия файл

@@ -0,0 +1,55 @@
1
+package com.yunzhi.nanyang.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.IdType;
4
+import java.time.LocalDateTime;
5
+import com.baomidou.mybatisplus.annotation.TableId;
6
+import java.io.Serializable;
7
+import io.swagger.annotations.ApiModel;
8
+import io.swagger.annotations.ApiModelProperty;
9
+import lombok.Data;
10
+import lombok.EqualsAndHashCode;
11
+import lombok.experimental.Accessors;
12
+
13
+/**
14
+ * <p>
15
+ * 小程序表
16
+ * </p>
17
+ *
18
+ * @author yansen
19
+ * @since 2022-03-21
20
+ */
21
+@Data
22
+@EqualsAndHashCode(callSuper = false)
23
+@Accessors(chain = true)
24
+@ApiModel(value="SysMiniapp对象", description="小程序表")
25
+public class SysMiniapp implements Serializable {
26
+
27
+    private static final long serialVersionUID = 1L;
28
+
29
+    @ApiModelProperty(value = "appid")
30
+    @TableId(value = "app_id", type = IdType.INPUT)
31
+    private String appId;
32
+
33
+    @ApiModelProperty(value = "小程序名称")
34
+    private String name;
35
+
36
+    @ApiModelProperty(value = "secret")
37
+    private String secret;
38
+
39
+    @ApiModelProperty(value = "token")
40
+    private String token;
41
+
42
+    @ApiModelProperty(value = "aesKey")
43
+    private String aesKey;
44
+
45
+    @ApiModelProperty(value = "客户端")
46
+    private String client;
47
+
48
+    @ApiModelProperty(value = "状态")
49
+    private Integer status;
50
+
51
+    @ApiModelProperty(value = "创建时间")
52
+    private LocalDateTime createDate;
53
+
54
+
55
+}

+ 1
- 1
src/main/java/com/yunzhi/nanyang/entity/TaBanner.java Целия файл

@@ -27,7 +27,7 @@ public class TaBanner implements Serializable {
27 27
     private static final long serialVersionUID = 1L;
28 28
 
29 29
     @ApiModelProperty(value = "轮播图Id")
30
-    @TableId(value = "banner_id", type = IdType.INPUT)
30
+    @TableId(value = "banner_id", type = IdType.UUID)
31 31
     private String bannerId;
32 32
 
33 33
     @ApiModelProperty(value = "名称")

+ 1
- 1
src/main/java/com/yunzhi/nanyang/entity/TaExtendContent.java Целия файл

@@ -27,7 +27,7 @@ public class TaExtendContent implements Serializable {
27 27
     private static final long serialVersionUID = 1L;
28 28
 
29 29
     @ApiModelProperty(value = "租户号")
30
-    @TableId(value = "ext_id", type = IdType.INPUT)
30
+    @TableId(value = "ext_id", type = IdType.UUID)
31 31
     private String extId;
32 32
 
33 33
     @ApiModelProperty(value = "扩展对象类型;message消息表 bannar轮播图 info资讯")

+ 1
- 1
src/main/java/com/yunzhi/nanyang/entity/TaImages.java Целия файл

@@ -27,7 +27,7 @@ public class TaImages implements Serializable {
27 27
     private static final long serialVersionUID = 1L;
28 28
 
29 29
     @ApiModelProperty(value = "图片ID")
30
-    @TableId(value = "image_id", type = IdType.INPUT)
30
+    @TableId(value = "image_id", type = IdType.UUID)
31 31
     private String imageId;
32 32
 
33 33
     @ApiModelProperty(value = "图片地址")

+ 8
- 2
src/main/java/com/yunzhi/nanyang/entity/TaMachinery.java Целия файл

@@ -2,8 +2,12 @@ package com.yunzhi.nanyang.entity;
2 2
 
3 3
 import com.baomidou.mybatisplus.annotation.IdType;
4 4
 import java.time.LocalDateTime;
5
+
6
+import com.baomidou.mybatisplus.annotation.TableField;
5 7
 import com.baomidou.mybatisplus.annotation.TableId;
6 8
 import java.io.Serializable;
9
+import java.util.List;
10
+
7 11
 import io.swagger.annotations.ApiModel;
8 12
 import io.swagger.annotations.ApiModelProperty;
9 13
 import lombok.Data;
@@ -27,7 +31,7 @@ public class TaMachinery implements Serializable {
27 31
     private static final long serialVersionUID = 1L;
28 32
 
29 33
     @ApiModelProperty(value = "农机Id")
30
-    @TableId(value = "machinery_id", type = IdType.INPUT)
34
+    @TableId(value = "machinery_id", type = IdType.UUID)
31 35
     private String machineryId;
32 36
 
33 37
     @ApiModelProperty(value = "名称")
@@ -84,5 +88,7 @@ public class TaMachinery implements Serializable {
84 88
     @ApiModelProperty(value = "更新时间")
85 89
     private LocalDateTime updateDate;
86 90
 
87
-
91
+    @TableField(exist = false)
92
+    @ApiModelProperty(value = "主图")
93
+    private List<TaImages> images;
88 94
 }

+ 8
- 2
src/main/java/com/yunzhi/nanyang/entity/TaNews.java Целия файл

@@ -2,8 +2,12 @@ package com.yunzhi.nanyang.entity;
2 2
 
3 3
 import com.baomidou.mybatisplus.annotation.IdType;
4 4
 import java.time.LocalDateTime;
5
+
6
+import com.baomidou.mybatisplus.annotation.TableField;
5 7
 import com.baomidou.mybatisplus.annotation.TableId;
6 8
 import java.io.Serializable;
9
+import java.util.List;
10
+
7 11
 import io.swagger.annotations.ApiModel;
8 12
 import io.swagger.annotations.ApiModelProperty;
9 13
 import lombok.Data;
@@ -27,7 +31,7 @@ public class TaNews implements Serializable {
27 31
     private static final long serialVersionUID = 1L;
28 32
 
29 33
     @ApiModelProperty(value = "资讯Id")
30
-    @TableId(value = "news_id", type = IdType.INPUT)
34
+    @TableId(value = "news_id", type = IdType.UUID)
31 35
     private String newsId;
32 36
 
33 37
     @ApiModelProperty(value = "资讯标题")
@@ -51,5 +55,7 @@ public class TaNews implements Serializable {
51 55
     @ApiModelProperty(value = "创建时间")
52 56
     private LocalDateTime createDate;
53 57
 
54
-
58
+    @TableField(exist = false)
59
+    @ApiModelProperty(value = "内容详情")
60
+    private List<TaExtendContent> contentList;
55 61
 }

+ 1
- 1
src/main/java/com/yunzhi/nanyang/entity/TaNewsType.java Целия файл

@@ -27,7 +27,7 @@ public class TaNewsType implements Serializable {
27 27
     private static final long serialVersionUID = 1L;
28 28
 
29 29
     @ApiModelProperty(value = "分类Id")
30
-    @TableId(value = "type_id", type = IdType.INPUT)
30
+    @TableId(value = "type_id", type = IdType.UUID)
31 31
     private String typeId;
32 32
 
33 33
     @ApiModelProperty(value = "分类名")

+ 5
- 2
src/main/java/com/yunzhi/nanyang/entity/TaPerson.java Целия файл

@@ -27,9 +27,12 @@ public class TaPerson implements Serializable {
27 27
     private static final long serialVersionUID = 1L;
28 28
 
29 29
     @ApiModelProperty(value = "用户ID")
30
-    @TableId(value = "person_id", type = IdType.INPUT)
30
+    @TableId(value = "person_id", type = IdType.UUID)
31 31
     private String personId;
32 32
 
33
+    @ApiModelProperty(value = "appId")
34
+    private String appId;
35
+
33 36
     @ApiModelProperty(value = "openid")
34 37
     private String openid;
35 38
 
@@ -49,7 +52,7 @@ public class TaPerson implements Serializable {
49 52
     private String userId;
50 53
 
51 54
     @ApiModelProperty(value = "状态")
52
-    private Integer state;
55
+    private Integer status;
53 56
 
54 57
     @ApiModelProperty(value = "创建时间")
55 58
     private LocalDateTime createDate;

+ 2
- 2
src/main/java/com/yunzhi/nanyang/entity/TdMachineryType.java Целия файл

@@ -27,14 +27,14 @@ public class TdMachineryType implements Serializable {
27 27
     private static final long serialVersionUID = 1L;
28 28
 
29 29
     @ApiModelProperty(value = "农机类型Id")
30
-    @TableId(value = "type_id", type = IdType.INPUT)
30
+    @TableId(value = "type_id", type = IdType.UUID)
31 31
     private String typeId;
32 32
 
33 33
     @ApiModelProperty(value = "类型名")
34 34
     private String name;
35 35
 
36 36
     @ApiModelProperty(value = "状态")
37
-    private Integer state;
37
+    private Integer status;
38 38
 
39 39
     @ApiModelProperty(value = "创建时间")
40 40
     private LocalDateTime createDate;

+ 22
- 0
src/main/java/com/yunzhi/nanyang/mapper/SysMiniappMapper.java Целия файл

@@ -0,0 +1,22 @@
1
+package com.yunzhi.nanyang.mapper;
2
+
3
+import com.yunzhi.nanyang.entity.SysMiniapp;
4
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
+import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+import org.apache.ibatis.annotations.Select;
8
+
9
+/**
10
+ * <p>
11
+ * 小程序表 Mapper 接口
12
+ * </p>
13
+ *
14
+ * @author yansen
15
+ * @since 2022-03-21
16
+ */
17
+@Mapper
18
+public interface SysMiniappMapper extends BaseMapper<SysMiniapp> {
19
+
20
+    @Select("select * from sys_miniapp t where t.client = #{client} and t.`status` = 1")
21
+    SysMiniapp getByClient(@Param("client") String client);
22
+}

+ 4
- 0
src/main/java/com/yunzhi/nanyang/mapper/SysUserDataScopeMapper.java Целия файл

@@ -3,6 +3,9 @@ package com.yunzhi.nanyang.mapper;
3 3
 import com.yunzhi.nanyang.entity.SysUserDataScope;
4 4
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 5
 import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+
8
+import java.util.List;
6 9
 
7 10
 /**
8 11
  * <p>
@@ -15,4 +18,5 @@ import org.apache.ibatis.annotations.Mapper;
15 18
 @Mapper
16 19
 public interface SysUserDataScopeMapper extends BaseMapper<SysUserDataScope> {
17 20
 
21
+    List<String> getAccessOrgs(@Param("userId") String userId);
18 22
 }

+ 4
- 0
src/main/java/com/yunzhi/nanyang/mapper/TaImagesMapper.java Целия файл

@@ -3,6 +3,9 @@ package com.yunzhi.nanyang.mapper;
3 3
 import com.yunzhi.nanyang.entity.TaImages;
4 4
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 5
 import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+
8
+import java.util.List;
6 9
 
7 10
 /**
8 11
  * <p>
@@ -15,4 +18,5 @@ import org.apache.ibatis.annotations.Mapper;
15 18
 @Mapper
16 19
 public interface TaImagesMapper extends BaseMapper<TaImages> {
17 20
 
21
+    List<TaImages> getListBy(@Param("targetType") String targetType, @Param("targetId") String targetId);
18 22
 }

+ 4
- 0
src/main/java/com/yunzhi/nanyang/mapper/TaPersonMapper.java Целия файл

@@ -3,6 +3,8 @@ package com.yunzhi.nanyang.mapper;
3 3
 import com.yunzhi.nanyang.entity.TaPerson;
4 4
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 5
 import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+import org.apache.ibatis.annotations.Select;
6 8
 
7 9
 /**
8 10
  * <p>
@@ -15,4 +17,6 @@ import org.apache.ibatis.annotations.Mapper;
15 17
 @Mapper
16 18
 public interface TaPersonMapper extends BaseMapper<TaPerson> {
17 19
 
20
+    @Select("SELECT * FROM ta_person t WHERE t.app_id = #{appid} AND t.openid = #{openid} AND t.`status` > -1")
21
+    TaPerson getByOpenId(@Param("appid") String appid, @Param("openid") String openid);
18 22
 }

+ 17
- 0
src/main/java/com/yunzhi/nanyang/service/ISysMiniappService.java Целия файл

@@ -0,0 +1,17 @@
1
+package com.yunzhi.nanyang.service;
2
+
3
+import com.yunzhi.nanyang.entity.SysMiniapp;
4
+import com.baomidou.mybatisplus.extension.service.IService;
5
+
6
+/**
7
+ * <p>
8
+ * 小程序表 服务类
9
+ * </p>
10
+ *
11
+ * @author yansen
12
+ * @since 2022-03-21
13
+ */
14
+public interface ISysMiniappService extends IService<SysMiniapp> {
15
+
16
+    SysMiniapp getByClient(String client);
17
+}

+ 6
- 0
src/main/java/com/yunzhi/nanyang/service/ISysUserDataScopeService.java Целия файл

@@ -3,6 +3,8 @@ package com.yunzhi.nanyang.service;
3 3
 import com.yunzhi.nanyang.entity.SysUserDataScope;
4 4
 import com.baomidou.mybatisplus.extension.service.IService;
5 5
 
6
+import java.util.List;
7
+
6 8
 /**
7 9
  * <p>
8 10
  * 用户数据权限 服务类
@@ -12,5 +14,9 @@ import com.baomidou.mybatisplus.extension.service.IService;
12 14
  * @since 2022-03-08
13 15
  */
14 16
 public interface ISysUserDataScopeService extends IBaseService<SysUserDataScope> {
17
+    boolean checkOrgAccess(String orgId, String userId);
18
+
19
+    boolean addNew(String orgId, String userId);
15 20
 
21
+    List<String> getAccessOrgs(String userId);
16 22
 }

+ 5
- 0
src/main/java/com/yunzhi/nanyang/service/ITaExtendContentService.java Целия файл

@@ -3,6 +3,8 @@ package com.yunzhi.nanyang.service;
3 3
 import com.yunzhi.nanyang.entity.TaExtendContent;
4 4
 import com.baomidou.mybatisplus.extension.service.IService;
5 5
 
6
+import java.util.List;
7
+
6 8
 /**
7 9
  * <p>
8 10
  * 拓展内容表 服务类
@@ -13,4 +15,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
13 15
  */
14 16
 public interface ITaExtendContentService extends IBaseService<TaExtendContent> {
15 17
 
18
+    List<TaExtendContent> listByTarget(String targetType, String targetId);
19
+
20
+    boolean editContent(String targetType, String targetId, List<TaExtendContent> contentList) throws Exception;
16 21
 }

+ 5
- 0
src/main/java/com/yunzhi/nanyang/service/ITaMachineryService.java Целия файл

@@ -13,4 +13,9 @@ import com.baomidou.mybatisplus.extension.service.IService;
13 13
  */
14 14
 public interface ITaMachineryService extends IBaseService<TaMachinery> {
15 15
 
16
+    boolean saveAll(TaMachinery taMachinery) throws Exception;
17
+
18
+    boolean updateAll(TaMachinery taMachinery)  throws Exception;
19
+
20
+    TaMachinery getDetail(String machineryId);
16 21
 }

+ 1
- 0
src/main/java/com/yunzhi/nanyang/service/ITaPersonService.java Целия файл

@@ -13,4 +13,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
13 13
  */
14 14
 public interface ITaPersonService extends IBaseService<TaPerson> {
15 15
 
16
+    TaPerson getByOpenId(String appid, String openid);
16 17
 }

+ 24
- 0
src/main/java/com/yunzhi/nanyang/service/impl/SysMiniappServiceImpl.java Целия файл

@@ -0,0 +1,24 @@
1
+package com.yunzhi.nanyang.service.impl;
2
+
3
+import com.yunzhi.nanyang.entity.SysMiniapp;
4
+import com.yunzhi.nanyang.mapper.SysMiniappMapper;
5
+import com.yunzhi.nanyang.service.ISysMiniappService;
6
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7
+import org.springframework.stereotype.Service;
8
+
9
+/**
10
+ * <p>
11
+ * 小程序表 服务实现类
12
+ * </p>
13
+ *
14
+ * @author yansen
15
+ * @since 2022-03-21
16
+ */
17
+@Service
18
+public class SysMiniappServiceImpl extends ServiceImpl<SysMiniappMapper, SysMiniapp> implements ISysMiniappService {
19
+
20
+    @Override
21
+    public SysMiniapp getByClient(String client) {
22
+        return baseMapper.getByClient(client);
23
+    }
24
+}

+ 42
- 0
src/main/java/com/yunzhi/nanyang/service/impl/SysUserDataScopeServiceImpl.java Целия файл

@@ -1,11 +1,18 @@
1 1
 package com.yunzhi.nanyang.service.impl;
2 2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.yunzhi.nanyang.common.Constants;
5
+import com.yunzhi.nanyang.common.StringUtils;
3 6
 import com.yunzhi.nanyang.entity.SysUserDataScope;
4 7
 import com.yunzhi.nanyang.mapper.SysUserDataScopeMapper;
5 8
 import com.yunzhi.nanyang.service.ISysUserDataScopeService;
6 9
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7 10
 import org.springframework.stereotype.Service;
8 11
 
12
+import java.util.Collection;
13
+import java.util.HashMap;
14
+import java.util.List;
15
+
9 16
 /**
10 17
  * <p>
11 18
  * 用户数据权限 服务实现类
@@ -17,4 +24,39 @@ import org.springframework.stereotype.Service;
17 24
 @Service
18 25
 public class SysUserDataScopeServiceImpl extends BaseServiceImpl<SysUserDataScopeMapper, SysUserDataScope> implements ISysUserDataScopeService {
19 26
 
27
+    @Override
28
+    public boolean checkOrgAccess(String orgId, String userId) {
29
+        // 人员空
30
+        if (StringUtils.isEmpty(userId)) return false;
31
+        // 组织空或者管理员
32
+        if (StringUtils.isEmpty(orgId) || Constants.ADMIN_ID.equals(userId)) return true;
33
+
34
+        Collection<SysUserDataScope> sysUserDataScopes = listByMap(new HashMap<String, Object>() {{
35
+            put("org_id", orgId);
36
+            put("user_id", userId);
37
+        }});
38
+
39
+        return null != sysUserDataScopes && sysUserDataScopes.size() > 0;
40
+    }
41
+
42
+    @Override
43
+    public boolean addNew(String orgId, String userId) {
44
+        Collection<SysUserDataScope> sysUserDataScopes = listByMap(new HashMap<String, Object>() {{
45
+            put("org_id", orgId);
46
+            put("user_id", userId);
47
+        }});
48
+
49
+        if (null != sysUserDataScopes && sysUserDataScopes.size() > 0) return true;
50
+
51
+        SysUserDataScope sysUserDataScope = new SysUserDataScope();
52
+        sysUserDataScope.setOrgId(orgId);
53
+        sysUserDataScope.setUserId(userId);
54
+
55
+        return save(sysUserDataScope);
56
+    }
57
+
58
+    @Override
59
+    public List<String> getAccessOrgs(String userId) {
60
+        return baseMapper.getAccessOrgs(userId);
61
+    }
20 62
 }

+ 40
- 0
src/main/java/com/yunzhi/nanyang/service/impl/TaExtendContentServiceImpl.java Целия файл

@@ -1,10 +1,16 @@
1 1
 package com.yunzhi.nanyang.service.impl;
2 2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.yunzhi.nanyang.common.StringUtils;
3 5
 import com.yunzhi.nanyang.entity.TaExtendContent;
4 6
 import com.yunzhi.nanyang.mapper.TaExtendContentMapper;
5 7
 import com.yunzhi.nanyang.service.ITaExtendContentService;
6 8
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7 9
 import org.springframework.stereotype.Service;
10
+import org.springframework.transaction.annotation.Transactional;
11
+
12
+import java.util.HashMap;
13
+import java.util.List;
8 14
 
9 15
 /**
10 16
  * <p>
@@ -17,4 +23,38 @@ import org.springframework.stereotype.Service;
17 23
 @Service
18 24
 public class TaExtendContentServiceImpl extends BaseServiceImpl<TaExtendContentMapper, TaExtendContent> implements ITaExtendContentService {
19 25
 
26
+    @Override
27
+    public List<TaExtendContent> listByTarget(String targetType, String targetId) {
28
+        QueryWrapper<TaExtendContent> queryWrapper = new QueryWrapper<>();
29
+        queryWrapper.eq("target_type", targetType);
30
+        queryWrapper.eq("target_id", targetId);
31
+        queryWrapper.orderByAsc("sort");
32
+
33
+        return list(queryWrapper);
34
+    }
35
+
36
+    @Transactional(rollbackFor = Exception.class)
37
+    @Override
38
+    public boolean editContent(String targetType, String targetId, List<TaExtendContent> contentList) throws Exception {
39
+        // 先删除原有数据
40
+        removeByMap(new HashMap<String, Object>(){{
41
+            put("target_type", targetType);
42
+            put("target_id", targetId);
43
+        }});
44
+
45
+        if (contentList == null || contentList.isEmpty()) return true;
46
+
47
+        for (TaExtendContent content : contentList) {
48
+            content.setTargetType(targetType);
49
+            content.setTargetId(targetId);
50
+
51
+            if (StringUtils.isEmpty(content.getExtId())) {
52
+                save(content);
53
+            } else {
54
+                updateById(content);
55
+            }
56
+        }
57
+
58
+        return true;
59
+    }
20 60
 }

+ 113
- 0
src/main/java/com/yunzhi/nanyang/service/impl/TaMachineryServiceImpl.java Целия файл

@@ -1,10 +1,23 @@
1 1
 package com.yunzhi.nanyang.service.impl;
2 2
 
3
+import com.yunzhi.nanyang.common.Constants;
4
+import com.yunzhi.nanyang.common.StringUtils;
5
+import com.yunzhi.nanyang.entity.TaImages;
3 6
 import com.yunzhi.nanyang.entity.TaMachinery;
7
+import com.yunzhi.nanyang.entity.TaRegion;
8
+import com.yunzhi.nanyang.entity.TdMachineryType;
9
+import com.yunzhi.nanyang.mapper.TaImagesMapper;
4 10
 import com.yunzhi.nanyang.mapper.TaMachineryMapper;
11
+import com.yunzhi.nanyang.mapper.TaRegionMapper;
12
+import com.yunzhi.nanyang.mapper.TdMachineryTypeMapper;
5 13
 import com.yunzhi.nanyang.service.ITaMachineryService;
6 14
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
15
+import org.springframework.beans.factory.annotation.Autowired;
7 16
 import org.springframework.stereotype.Service;
17
+import org.springframework.transaction.annotation.Transactional;
18
+
19
+import java.util.HashMap;
20
+import java.util.List;
8 21
 
9 22
 /**
10 23
  * <p>
@@ -17,4 +30,104 @@ import org.springframework.stereotype.Service;
17 30
 @Service
18 31
 public class TaMachineryServiceImpl extends BaseServiceImpl<TaMachineryMapper, TaMachinery> implements ITaMachineryService {
19 32
 
33
+    @Autowired
34
+    TaImagesMapper taImagesMapper;
35
+
36
+    @Autowired
37
+    TdMachineryTypeMapper tdMachineryTypeMapper;
38
+
39
+    @Autowired
40
+    TaRegionMapper taRegionMapper;
41
+
42
+    @Transactional(rollbackFor = Exception.class)
43
+    @Override
44
+    public boolean saveAll(TaMachinery taMachinery) throws Exception {
45
+        setRedundanceName(taMachinery);
46
+
47
+        boolean isOk = save(taMachinery);
48
+        if (!isOk) return false;
49
+
50
+        // 图片保存失败不影响主记录
51
+        try {
52
+            saveImages(taMachinery);
53
+        } catch (Exception e) {
54
+            e.printStackTrace();
55
+        }
56
+
57
+        return true;
58
+    }
59
+
60
+    @Override
61
+    public boolean updateAll(TaMachinery taMachinery) throws Exception {
62
+        setRedundanceName(taMachinery);
63
+
64
+        boolean isOk = updateById(taMachinery);
65
+        if (!isOk) return false;
66
+
67
+        // 图片保存失败不影响主记录
68
+        try {
69
+            saveImages(taMachinery);
70
+        } catch (Exception e) {
71
+            e.printStackTrace();
72
+        }
73
+
74
+        return true;
75
+    }
76
+
77
+    @Override
78
+    public TaMachinery getDetail(String machineryId) {
79
+        TaMachinery taMachinery = getExistBy("machinery_id", machineryId, false, true);
80
+        if (null == taMachinery) return null;
81
+
82
+        setRedundanceName(taMachinery);
83
+
84
+        List<TaImages> images = taImagesMapper.getListBy(Constants.TARGET_MACHINERY, machineryId);
85
+        taMachinery.setImages(images);
86
+
87
+        return taMachinery;
88
+    }
89
+
90
+    private void saveImages(TaMachinery taMachinery) {
91
+        String machineryId = taMachinery.getMachineryId();
92
+        // 先删除所有
93
+        taImagesMapper.deleteByMap(new HashMap<String, Object>(){{
94
+            put("target_id", machineryId);
95
+            put("target_type", Constants.TARGET_MACHINERY);
96
+        }});
97
+
98
+        List<TaImages> images = taMachinery.getImages();
99
+        if (null != images && images.size() > 0) {
100
+            for (TaImages image : images) {
101
+                if (!StringUtils.isEmpty(image.getUrl())) {
102
+                    image.setTargetId(machineryId);
103
+                    image.setTargetType(Constants.TARGET_MACHINERY);
104
+                    taImagesMapper.insert(image);
105
+                }
106
+            }
107
+        }
108
+    }
109
+
110
+    private void setRedundanceName(TaMachinery taMachinery) {
111
+        // 分类
112
+        if (!StringUtils.isEmpty(taMachinery.getTypeId())) {
113
+            TdMachineryType tdMachineryType = tdMachineryTypeMapper.selectById(taMachinery.getTypeId());
114
+            if (null != tdMachineryType && tdMachineryType.getStatus() > Constants.STATUS_DELETE) {
115
+                taMachinery.setTypeName(tdMachineryType.getName());
116
+            } else {
117
+                taMachinery.setTypeId(null);
118
+                taMachinery.setTypeName(null);
119
+            }
120
+        }
121
+
122
+        // 所属区域
123
+        if (!StringUtils.isEmpty(taMachinery.getRegionId())) {
124
+            TaRegion taRegion = taRegionMapper.selectById(taMachinery.getRegionId());
125
+            if (null != taRegion && taRegion.getStatus() > Constants.STATUS_DELETE) {
126
+                taMachinery.setRegionName(taRegion.getName());
127
+            } else {
128
+                taMachinery.setRegionId(null);
129
+                taMachinery.setRegionName(null);
130
+            }
131
+        }
132
+    }
20 133
 }

+ 4
- 0
src/main/java/com/yunzhi/nanyang/service/impl/TaPersonServiceImpl.java Целия файл

@@ -17,4 +17,8 @@ import org.springframework.stereotype.Service;
17 17
 @Service
18 18
 public class TaPersonServiceImpl extends BaseServiceImpl<TaPersonMapper, TaPerson> implements ITaPersonService {
19 19
 
20
+    @Override
21
+    public TaPerson getByOpenId(String appid, String openid) {
22
+        return baseMapper.getByOpenId(appid, openid);
23
+    }
20 24
 }

+ 35
- 5
src/main/java/com/yunzhi/nanyang/shiro/ShiroConfig.java Целия файл

@@ -1,11 +1,20 @@
1 1
 package com.yunzhi.nanyang.shiro;
2 2
 
3 3
 import com.yunzhi.nanyang.shiro.filters.JWTFilter;
4
+import com.yunzhi.nanyang.shiro.filters.ManagerFilter;
5
+import com.yunzhi.nanyang.shiro.filters.MiniappFilter;
4 6
 import com.yunzhi.nanyang.shiro.matcher.JWTCredentialsMatcher;
5 7
 import com.yunzhi.nanyang.shiro.realms.manager.IManagerService;
6 8
 import com.yunzhi.nanyang.shiro.realms.manager.ManagerRealm;
9
+import com.yunzhi.nanyang.shiro.realms.miniapp.MiniappRealm;
10
+import org.apache.shiro.authc.Authenticator;
11
+import org.apache.shiro.authc.pam.AtLeastOneSuccessfulStrategy;
12
+import org.apache.shiro.authc.pam.FirstSuccessfulStrategy;
13
+import org.apache.shiro.authc.pam.ModularRealmAuthenticator;
14
+import org.apache.shiro.authz.Authorizer;
7 15
 import org.apache.shiro.mgt.DefaultSessionStorageEvaluator;
8 16
 import org.apache.shiro.mgt.DefaultSubjectDAO;
17
+import org.apache.shiro.realm.Realm;
9 18
 import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
10 19
 import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
11 20
 import org.springframework.beans.factory.annotation.Autowired;
@@ -14,7 +23,9 @@ import org.springframework.context.annotation.Bean;
14 23
 import org.springframework.context.annotation.Configuration;
15 24
 
16 25
 import javax.servlet.Filter;
26
+import java.util.ArrayList;
17 27
 import java.util.HashMap;
28
+import java.util.List;
18 29
 import java.util.Map;
19 30
 
20 31
 @Configuration
@@ -37,16 +48,26 @@ public class ShiroConfig {
37 48
         return realm;
38 49
     }
39 50
 
51
+    @Bean
52
+    public MiniappRealm miniappRealm() {
53
+        MiniappRealm realm = new MiniappRealm();
54
+        realm.setCredentialsMatcher(new JWTCredentialsMatcher());
55
+        return realm;
56
+    }
57
+
40 58
     @Bean("shiroFilterFactoryBean")
41 59
     public ShiroFilterFactoryBean factory(DefaultWebSecurityManager securityManager) {
42 60
         ShiroFilterFactoryBean factoryBean = new ShiroFilterFactoryBean();
43 61
 
44
-        // 手动加入 JWTFilter
45
-        JWTFilter jwtFilter = new JWTFilter();
46
-        jwtFilter.setUnauthorizedUrl(unauthorizedUrl);
62
+        // 手动加入 Filter
63
+        ManagerFilter managerFilter = new ManagerFilter();
64
+        managerFilter.setUnauthorizedUrl(unauthorizedUrl);
65
+        MiniappFilter miniappFilter = new MiniappFilter();
66
+        miniappFilter.setUnauthorizedUrl(unauthorizedUrl);
47 67
 
48 68
         Map<String, Filter> filterMap = new HashMap<>();
49
-        filterMap.put("jwt", jwtFilter);
69
+        filterMap.put("manager", managerFilter);
70
+        filterMap.put("miniapp", miniappFilter);
50 71
         factoryBean.setFilters(filterMap);
51 72
 
52 73
         factoryBean.setSecurityManager(securityManager);
@@ -59,8 +80,17 @@ public class ShiroConfig {
59 80
     @Bean("securityManager")
60 81
     public DefaultWebSecurityManager securityManager() {
61 82
         DefaultWebSecurityManager manager = new DefaultWebSecurityManager();
83
+        // 修改多 Realm 的处理逻辑
84
+        ModularRealmAuthenticator realmAuthenticator = (ModularRealmAuthenticator) manager.getAuthenticator();
85
+        // 主要有一个 Realm 成功, 就立即返回
86
+        realmAuthenticator.setAuthenticationStrategy(new AtLeastOneSuccessfulStrategy());
87
+
62 88
         //  Use your own realm
63
-        manager.setRealm(managerRealm());
89
+        List<Realm> realmList = new ArrayList<Realm>() {{
90
+            add(managerRealm());
91
+            add(miniappRealm());
92
+        }};
93
+        manager.setRealms(realmList);
64 94
 
65 95
         /*
66 96
          * 禁用 session

+ 7
- 26
src/main/java/com/yunzhi/nanyang/shiro/filters/JWTFilter.java Целия файл

@@ -1,8 +1,6 @@
1 1
 package com.yunzhi.nanyang.shiro.filters;
2 2
 
3
-import com.yunzhi.nanyang.shiro.utils.JWTToken;
4 3
 import com.yunzhi.nanyang.shiro.utils.JWTUtil;
5
-import org.apache.shiro.authc.AuthenticationException;
6 4
 import org.apache.shiro.authc.AuthenticationToken;
7 5
 import org.apache.shiro.subject.Subject;
8 6
 import org.apache.shiro.web.filter.authc.AuthenticatingFilter;
@@ -17,7 +15,7 @@ import java.io.IOException;
17 15
 import java.io.UnsupportedEncodingException;
18 16
 import java.net.URLEncoder;
19 17
 
20
-public class JWTFilter extends AuthenticatingFilter {
18
+public abstract class JWTFilter extends AuthenticatingFilter {
21 19
 
22 20
     private Logger LOGGER = LoggerFactory.getLogger(this.getClass());
23 21
 
@@ -31,35 +29,15 @@ public class JWTFilter extends AuthenticatingFilter {
31 29
         this.unauthorizedUrl = unauthorizedUrl;
32 30
     }
33 31
 
34
-    @Override
35
-    protected AuthenticationToken createToken(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception {
36
-        String authorization = WebUtils.toHttp(servletRequest).getHeader(JWT_HEADER);
37
-        if (authorization == null || "".equals(authorization)) {
38
-            throw new Exception("请先登录系统");
39
-        }
40
-
41
-        return new JWTToken(authorization);
42
-    }
43
-
44
-    @Override
45
-    protected boolean executeLogin(ServletRequest request, ServletResponse response) throws Exception {
46
-        AuthenticationToken token = this.createToken(request, response);
47
-        Subject subject = this.getSubject(request, response);
48
-        subject.login(token);
49
-        return this.onLoginSuccess(token, subject, request, response);
50
-    }
51
-
52 32
     @Override
53 33
     protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
54
-        boolean allowed = false;
55 34
         try {
56
-            allowed = executeLogin(request, response);
35
+            return executeLogin(request, response);
57 36
         } catch (Exception e) {
58 37
             response401(request, response, e);
59 38
         }
60 39
 
61
-        return allowed;
62
-//        return allowed || super.isPermissive(mappedValue);
40
+        return false;
63 41
     }
64 42
 
65 43
     @Override
@@ -67,6 +45,9 @@ public class JWTFilter extends AuthenticatingFilter {
67 45
         return false;
68 46
     }
69 47
 
48
+    @Override
49
+    protected abstract AuthenticationToken createToken(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception;
50
+
70 51
     // 主要用来刷新 token
71 52
     @Override
72 53
     protected boolean onLoginSuccess(AuthenticationToken token, Subject subject, ServletRequest request, ServletResponse response) throws Exception {
@@ -84,7 +65,7 @@ public class JWTFilter extends AuthenticatingFilter {
84 65
     /**
85 66
      *Jump illegal request to / 401
86 67
      */
87
-    private void response401(ServletRequest request, ServletResponse response, Exception e) {
68
+    protected void response401(ServletRequest request, ServletResponse response, Exception e) {
88 69
         String message = "";
89 70
         if (e != null) {
90 71
             try {

+ 29
- 0
src/main/java/com/yunzhi/nanyang/shiro/filters/ManagerFilter.java Целия файл

@@ -0,0 +1,29 @@
1
+package com.yunzhi.nanyang.shiro.filters;
2
+
3
+import com.yunzhi.nanyang.shiro.utils.JWTToken;
4
+import com.yunzhi.nanyang.shiro.utils.MiniappToken;
5
+import org.apache.shiro.authc.AuthenticationToken;
6
+import org.apache.shiro.web.util.WebUtils;
7
+
8
+import javax.servlet.ServletRequest;
9
+import javax.servlet.ServletResponse;
10
+import javax.servlet.http.HttpServletRequest;
11
+
12
+/**
13
+ * ManagerFilter 与 MiniappFilter 实际上是一样的,只是返回的 token 类型不一致
14
+ */
15
+public class ManagerFilter extends JWTFilter {
16
+
17
+    @Override
18
+    protected AuthenticationToken createToken(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception {
19
+        HttpServletRequest request = WebUtils.toHttp(servletRequest);
20
+        String authorization = request.getHeader(JWT_HEADER);
21
+        if (authorization == null || "".equals(authorization)) {
22
+            throw new Exception("请先登录系统");
23
+        }
24
+
25
+        return new JWTToken(authorization);
26
+    }
27
+
28
+
29
+}

+ 25
- 0
src/main/java/com/yunzhi/nanyang/shiro/filters/MiniappFilter.java Целия файл

@@ -0,0 +1,25 @@
1
+package com.yunzhi.nanyang.shiro.filters;
2
+
3
+import com.yunzhi.nanyang.shiro.utils.JWTToken;
4
+import com.yunzhi.nanyang.shiro.utils.MiniappToken;
5
+import org.apache.shiro.authc.AuthenticationToken;
6
+import org.apache.shiro.web.util.WebUtils;
7
+
8
+import javax.servlet.ServletRequest;
9
+import javax.servlet.ServletResponse;
10
+import javax.servlet.http.HttpServletRequest;
11
+
12
+public class MiniappFilter  extends JWTFilter {
13
+
14
+    @Override
15
+    protected AuthenticationToken createToken(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception {
16
+        HttpServletRequest request = WebUtils.toHttp(servletRequest);
17
+        String authorization = request.getHeader(JWT_HEADER);
18
+        if (authorization == null || "".equals(authorization)) {
19
+            throw new Exception("请先登录系统");
20
+        }
21
+
22
+        return new MiniappToken(authorization);
23
+    }
24
+
25
+}

+ 9
- 0
src/main/java/com/yunzhi/nanyang/shiro/realms/manager/ManagerRealm.java Целия файл

@@ -4,6 +4,7 @@ import com.auth0.jwt.exceptions.JWTDecodeException;
4 4
 import com.auth0.jwt.exceptions.TokenExpiredException;
5 5
 import com.yunzhi.nanyang.shiro.utils.JWTToken;
6 6
 import com.yunzhi.nanyang.shiro.utils.JWTUtil;
7
+import lombok.extern.slf4j.Slf4j;
7 8
 import org.apache.shiro.authc.*;
8 9
 import org.apache.shiro.authz.AuthorizationInfo;
9 10
 import org.apache.shiro.authz.SimpleAuthorizationInfo;
@@ -12,10 +13,16 @@ import org.apache.shiro.subject.PrincipalCollection;
12 13
 
13 14
 import java.util.Set;
14 15
 
16
+@Slf4j
15 17
 public class ManagerRealm extends AuthorizingRealm {
16 18
 
17 19
     IManagerService iManagerService;
18 20
 
21
+    @Override
22
+    public String getName() {
23
+        return "managerRealm";
24
+    }
25
+
19 26
     public void setManagerService(IManagerService iManagerService) {
20 27
         this.iManagerService = iManagerService;
21 28
     }
@@ -41,6 +48,8 @@ public class ManagerRealm extends AuthorizingRealm {
41 48
 
42 49
     @Override
43 50
     protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
51
+        log.info("===========ManagerRealm===========");
52
+
44 53
         String token = (String) authenticationToken.getPrincipal();
45 54
 
46 55
         // 这里进行 token 验证, CredentialsMatcher 就不做了

+ 44
- 0
src/main/java/com/yunzhi/nanyang/shiro/realms/miniapp/MiniappRealm.java Целия файл

@@ -0,0 +1,44 @@
1
+package com.yunzhi.nanyang.shiro.realms.miniapp;
2
+
3
+import com.auth0.jwt.exceptions.JWTDecodeException;
4
+import com.auth0.jwt.exceptions.TokenExpiredException;
5
+import com.yunzhi.nanyang.shiro.utils.JWTUtil;
6
+import com.yunzhi.nanyang.shiro.utils.MiniappToken;
7
+import lombok.extern.slf4j.Slf4j;
8
+import org.apache.shiro.authc.*;
9
+import org.apache.shiro.realm.AuthenticatingRealm;
10
+
11
+@Slf4j
12
+public class MiniappRealm extends AuthenticatingRealm {
13
+
14
+    @Override
15
+    public String getName() {
16
+        return "miniappRealm";
17
+    }
18
+
19
+    @Override
20
+    public boolean supports(AuthenticationToken token) {
21
+        return token instanceof MiniappToken;
22
+    }
23
+
24
+    @Override
25
+    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
26
+        log.info("===========MiniappRealm===========");
27
+
28
+        String token = (String) authenticationToken.getPrincipal();
29
+
30
+        // 这里进行 token 验证, CredentialsMatcher 就不做了
31
+        try {
32
+            JWTUtil.verify(token);
33
+        } catch (JWTDecodeException e1) {
34
+            throw new AuthenticationException("非法的权限凭证");
35
+        } catch (TokenExpiredException e2) {
36
+            throw new ExpiredCredentialsException("授权过期, 请重新登录");
37
+        } catch (Exception e) {
38
+            e.printStackTrace();
39
+            throw new AuthenticationException("凭证校验失败, 请重新登录");
40
+        }
41
+        // 交给 AuthenticatingRealm 使用 CredentialsMatcher 行校验
42
+        return new SimpleAuthenticationInfo(token, token, getName());
43
+    }
44
+}

+ 23
- 0
src/main/java/com/yunzhi/nanyang/shiro/utils/MiniappToken.java Целия файл

@@ -0,0 +1,23 @@
1
+package com.yunzhi.nanyang.shiro.utils;
2
+
3
+import org.apache.shiro.authc.AuthenticationToken;
4
+
5
+public class MiniappToken implements AuthenticationToken {
6
+
7
+    //Key
8
+    private String token;
9
+
10
+    public MiniappToken(String token) {
11
+        this.token = token;
12
+    }
13
+
14
+    @Override
15
+    public Object getPrincipal() {
16
+        return token;
17
+    }
18
+
19
+    @Override
20
+    public Object getCredentials() {
21
+        return token;
22
+    }
23
+}

+ 3
- 0
src/main/java/com/yunzhi/nanyang/vo/LoginParam.java Целия файл

@@ -11,6 +11,9 @@ public class LoginParam {
11 11
     @ApiModelProperty("登录方式")
12 12
     String loginType;
13 13
 
14
+    @ApiModelProperty("code")
15
+    String code;
16
+
14 17
     @ApiModelProperty("用户名")
15 18
     String userName;
16 19
 

+ 17
- 0
src/main/java/com/yunzhi/nanyang/vo/PhoneParam.java Целия файл

@@ -0,0 +1,17 @@
1
+package com.yunzhi.nanyang.vo;
2
+
3
+
4
+import io.swagger.annotations.ApiModel;
5
+import io.swagger.annotations.ApiModelProperty;
6
+import lombok.Data;
7
+
8
+@ApiModel(value = "手机号信息", description = "手机号信息")
9
+@Data
10
+public class PhoneParam {
11
+
12
+    @ApiModelProperty("手机号")
13
+    private String phone;
14
+
15
+    @ApiModelProperty("验证码")
16
+    private String captcha;
17
+}

+ 26
- 0
src/main/java/com/yunzhi/nanyang/vo/WxMaAuthParam.java Целия файл

@@ -0,0 +1,26 @@
1
+package com.yunzhi.nanyang.vo;
2
+
3
+
4
+import io.swagger.annotations.ApiModel;
5
+import io.swagger.annotations.ApiModelProperty;
6
+import lombok.Data;
7
+
8
+@ApiModel(value = "微信小程序授权", description = "微信小程序授权参数")
9
+@Data
10
+public class WxMaAuthParam {
11
+
12
+    @ApiModelProperty("signature")
13
+    String signature;
14
+
15
+    @ApiModelProperty("rawData")
16
+    String rawData;
17
+
18
+    @ApiModelProperty("encryptedData")
19
+    String encryptedData;
20
+
21
+    @ApiModelProperty("iv")
22
+    String iv;
23
+
24
+    @ApiModelProperty("sessionKey")
25
+    String sessionKey;
26
+}

+ 32
- 0
src/main/java/com/yunzhi/nanyang/vo/WxMaPreload.java Целия файл

@@ -0,0 +1,32 @@
1
+package com.yunzhi.nanyang.vo;
2
+
3
+
4
+import io.swagger.annotations.ApiModel;
5
+import io.swagger.annotations.ApiModelProperty;
6
+import lombok.Data;
7
+
8
+@ApiModel(description = "小程序预加载参数")
9
+@Data
10
+public class WxMaPreload {
11
+
12
+    @ApiModelProperty("小程序标识")
13
+    String appid;
14
+
15
+    @ApiModelProperty("用户设置的 TOKEN")
16
+    String token;
17
+
18
+    @ApiModelProperty("用户登录凭证")
19
+    String code;
20
+
21
+    @ApiModelProperty("时间戳,微信客户端发起请求的时间")
22
+    Integer timestamp;
23
+
24
+    @ApiModelProperty("打开小程序的路径")
25
+    String path;
26
+
27
+    @ApiModelProperty("打开小程序的query")
28
+    String query;
29
+
30
+    @ApiModelProperty("打开小程序的场景值")
31
+    Integer scene;
32
+}

+ 15
- 6
src/main/resources/application.yml Целия файл

@@ -10,7 +10,11 @@ shiro:
10 10
   unauthorizedUrl: /api/401
11 11
   filterRuleMap: '{
12 12
     "/admin/login": "anon",
13
-    "/admin/**": "jwt",
13
+    "/admin/**": "manager",
14
+    "/wx/**/login": "anon",
15
+    "/wx/**": "miniapp",
16
+    "/**/sms-captcha": "anon",
17
+    "/wx/**/sms-captcha": "anon",
14 18
     "/**": "anon"
15 19
   }'
16 20
 
@@ -40,12 +44,17 @@ yz:
40 44
 
41 45
 ###
42 46
 aliyun:
43
-  accessKeyId: LTAI4FdMQNh1xUoiqqbKJ15J
44
-  accessKeySecret: F7vmuXBu8IrhouQYYhFMLRhIRivIzb
47
+  accessKeyId: LTAI5tGjnZY6k799BHxhmqcm
48
+  accessKeySecret: eU1DmULbgHe2dnIg3P93634PO2vEh5
45 49
   oss:
46
-    endpoint: oss-cn-shanghai.aliyuncs.com
47
-    bucketName: njcj
48
-    bucketURL: https://njcj.oss-cn-shanghai.aliyuncs.com
50
+    roleSessionName: shigongli
51
+    accessKeyId: LTAI4G9zCefU1m7sKmmBnzTc
52
+    accessKeySecret: Vaax5O7wTL0KZdSgd8L9cGBf8AgUqJ
53
+    arn: acs:ram::1636896505560465:role/ramosssts
54
+    region: oss-cn-shanghai
55
+    endpoint: oss-accelerate.aliyuncs.com
56
+    bucketName: yz-shigongli
57
+    bucketURL: https://yz-shigongli.oss-accelerate.aliyuncs.com
49 58
   sms:
50 59
     captcha:
51 60
       code: SMS_195585471

+ 1
- 1
src/main/resources/mapper/SysMenuMapper.xml Целия файл

@@ -9,7 +9,7 @@
9 9
             1 AS can_access
10 10
         </if>
11 11
         <if test="!isAdmin">
12
-            IF ( s.role_id IS NULL, 0, 1 ) AS can_access
12
+            IF ( m.role_id IS NULL, 0, 1 ) AS can_access
13 13
         </if>
14 14
         FROM
15 15
             sys_menu t

+ 5
- 0
src/main/resources/mapper/SysMiniappMapper.xml Целия файл

@@ -0,0 +1,5 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.yunzhi.nanyang.mapper.SysMiniappMapper">
4
+
5
+</mapper>

+ 8
- 0
src/main/resources/mapper/SysUserDataScopeMapper.xml Целия файл

@@ -2,4 +2,12 @@
2 2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3 3
 <mapper namespace="com.yunzhi.nanyang.mapper.SysUserDataScopeMapper">
4 4
 
5
+    <select id="getAccessOrgs" resultType="java.lang.String">
6
+        SELECT
7
+            t.org_id
8
+        FROM
9
+            sys_user_data_scope t
10
+        WHERE
11
+            t.user_id = #{userId}
12
+    </select>
5 13
 </mapper>

+ 12
- 0
src/main/resources/mapper/TaImagesMapper.xml Целия файл

@@ -2,4 +2,16 @@
2 2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3 3
 <mapper namespace="com.yunzhi.nanyang.mapper.TaImagesMapper">
4 4
 
5
+    <select id="getListBy" resultType="com.yunzhi.nanyang.entity.TaImages">
6
+        SELECT
7
+            *
8
+        FROM
9
+            ta_images t
10
+        WHERE
11
+            t.target_type = #{targetType}
12
+          AND t.target_id = #{targetId}
13
+          AND t.`status` = 1
14
+        ORDER BY
15
+            t.create_date ASC
16
+    </select>
5 17
 </mapper>