张延森 3 年 前
コミット
f468053c04

+ 6
- 2
pom.xml ファイルの表示

@@ -10,7 +10,7 @@
10 10
 	</parent>
11 11
 	<groupId>com.njyunzhi</groupId>
12 12
 	<artifactId>ubpa</artifactId>
13
-	<version>0.0.1-SNAPSHOT</version>
13
+	<version>0.0.1</version>
14 14
 	<name>ubpa</name>
15 15
 	<description>Demo project for Spring Boot</description>
16 16
 
@@ -24,7 +24,11 @@
24 24
 			<groupId>org.springframework.boot</groupId>
25 25
 			<artifactId>spring-boot-starter-web</artifactId>
26 26
 		</dependency>
27
-
27
+		<dependency>
28
+			<groupId>org.springframework.boot</groupId>
29
+			<artifactId>spring-boot-configuration-processor</artifactId>
30
+			<optional>true</optional>
31
+		</dependency>
28 32
 		<dependency>
29 33
 			<groupId>mysql</groupId>
30 34
 			<artifactId>mysql-connector-java</artifactId>

+ 5
- 0
src/main/java/com/njyunzhi/ubpa/UbpaApplication.java ファイルの表示

@@ -2,7 +2,12 @@ package com.njyunzhi.ubpa;
2 2
 
3 3
 import org.springframework.boot.SpringApplication;
4 4
 import org.springframework.boot.autoconfigure.SpringBootApplication;
5
+import org.springframework.scheduling.annotation.EnableAsync;
6
+import org.springframework.transaction.annotation.EnableTransactionManagement;
5 7
 
8
+
9
+@EnableAsync
10
+@EnableTransactionManagement
6 11
 @SpringBootApplication
7 12
 public class UbpaApplication {
8 13
 

+ 24
- 14
src/main/java/com/njyunzhi/ubpa/config/CorsConfig.java ファイルの表示

@@ -1,26 +1,36 @@
1 1
 package com.njyunzhi.ubpa.config;
2 2
 
3
-import org.springframework.boot.SpringBootConfiguration;
3
+import org.springframework.beans.factory.annotation.Value;
4
+import org.springframework.context.annotation.Configuration;
4 5
 import org.springframework.web.servlet.config.annotation.CorsRegistry;
5 6
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
6 7
 
7
-@SpringBootConfiguration
8
+// TODO
9
+// 这个配置实际上不生效,不知道为什么
10
+
11
+@Configuration
8 12
 public class CorsConfig implements WebMvcConfigurer {
13
+
14
+    @Value("${yz.cros}")
15
+    Boolean useCROS;
16
+
9 17
     @Override
10 18
     public void addCorsMappings(CorsRegistry registry) {
19
+        if (!useCROS) return;
20
+
11 21
 //        //添加映射路径
12
-//        registry.addMapping("/**")
13
-//                //是否发送Cookie
14
-//                .allowCredentials(true)
15
-//                //设置放行哪些原始域
16
-//                .allowedOrigins("*")
17
-//                //放行哪些请求方式
18
-//                .allowedMethods("GET", "POST", "PUT", "DELETE")
19
-//                //.allowedMethods("*") //或者放行全部
20
-//                //放行哪些原始请求头部信息
21
-//                .allowedHeaders("*")
22
-//                //暴露哪些原始请求头部信息
23
-//                .exposedHeaders("X-Authorization-JWT");
22
+        registry.addMapping("/**")
23
+                //是否发送Cookie
24
+                .allowCredentials(true)
25
+                //设置放行哪些原始域
26
+                .allowedOrigins("http://localhost:8000")
27
+                //放行哪些请求方式
28
+                .allowedMethods("GET", "POST", "PUT", "DELETE")
29
+                //.allowedMethods("*") //或者放行全部
30
+                //放行哪些原始请求头部信息
31
+                .allowedHeaders("*")
32
+                //暴露哪些原始请求头部信息
33
+                .exposedHeaders("Authorization");
24 34
     }
25 35
 }
26 36
 

+ 1
- 1
src/main/java/com/njyunzhi/ubpa/controller/LoginController.java ファイルの表示

@@ -58,7 +58,7 @@ public class LoginController extends BaseController {
58 58
         res.put("user", sysUser);
59 59
 
60 60
         // 生成 token
61
-        String token = JWTUtil.sign(sysUser.getUserId(), sysUser.getPassword());
61
+        String token = JWTUtil.sign(sysUser.getUserId(), sysUser.getUserId());
62 62
         res.put("token", token);
63 63
 
64 64
         return ResponseBean.success(res);

+ 11
- 6
src/main/java/com/njyunzhi/ubpa/controller/TaOrgController.java ファイルの表示

@@ -55,11 +55,13 @@ public class TaOrgController extends BaseController {
55 55
     @RequestMapping(value="/h5/org",method= RequestMethod.GET)
56 56
     @ApiOperation(value="客户端列表", notes = "客户端列表", httpMethod = "GET", response = ResponseBean.class)
57 57
     public ResponseBean taOrgList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
58
-                                  @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
58
+                                  @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
59
+                                  @ApiParam("企业名称") @RequestParam(value ="orgName", required = false) String orgName) throws Exception{
59 60
 
60 61
         IPage<TaOrg> pg = new Page<>(pageNum, pageSize);
61 62
         QueryWrapper<TaOrg> queryWrapper = new QueryWrapper<>();
62 63
         queryWrapper.eq("status", Constants.STATUS_NORMAL);
64
+        queryWrapper.like(!StringUtils.isEmpty(orgName), "org_name", "%" + orgName + "%");
63 65
         queryWrapper.orderByDesc("org_name");
64 66
         queryWrapper.orderByDesc("create_date");
65 67
 
@@ -77,11 +79,11 @@ public class TaOrgController extends BaseController {
77 79
     @ApiOperation(value="管理端列表", notes = "管理端列表", httpMethod = "GET", response = ResponseBean.class)
78 80
     public ResponseBean getList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
79 81
                                 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
80
-                                @ApiParam("机构名称") @RequestParam(value ="orgName", required = false) String orgName) throws Exception{
82
+                                @ApiParam("企业名称") @RequestParam(value ="orgName", required = false) String orgName) throws Exception{
81 83
 
82 84
         IPage<TaOrg> pg = new Page<>(pageNum, pageSize);
83 85
         QueryWrapper<TaOrg> queryWrapper = new QueryWrapper<>();
84
-        queryWrapper.like(StringUtils.isEmpty(orgName), "org_name", "%" + orgName + "%");
86
+        queryWrapper.like(!StringUtils.isEmpty(orgName), "org_name", "%" + orgName + "%");
85 87
         queryWrapper.gt("status", Constants.STATUS_DELETE);
86 88
         queryWrapper.orderByDesc("create_date");
87 89
 
@@ -108,6 +110,9 @@ public class TaOrgController extends BaseController {
108 110
         }
109 111
 
110 112
         taOrg.setOrgId(null);
113
+        if (null == taOrg.getStatus()) {
114
+            taOrg.setStatus(Constants.STATUS_NORMAL);
115
+        }
111 116
 
112 117
         if (iTaOrgService.save(taOrg)){
113 118
             return ResponseBean.success(taOrg);
@@ -120,7 +125,7 @@ public class TaOrgController extends BaseController {
120 125
      * 根据id删除对象
121 126
      * @param id  实体ID
122 127
      */
123
-    @RequestMapping(value="/admin/orgId/{id}", method= RequestMethod.DELETE)
128
+    @RequestMapping(value="/admin/org/{id}", method= RequestMethod.DELETE)
124 129
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
125 130
     public ResponseBean taOrgDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
126 131
 
@@ -148,7 +153,7 @@ public class TaOrgController extends BaseController {
148 153
      * @param taOrg 实体对象
149 154
      * @return
150 155
      */
151
-    @RequestMapping(value="/admin/orgId/{id}",method= RequestMethod.PUT)
156
+    @RequestMapping(value="/admin/org/{id}",method= RequestMethod.PUT)
152 157
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
153 158
     public ResponseBean taOrgUpdate(@ApiParam("对象ID") @PathVariable String id,
154 159
                                         @ApiParam("更新内容") @RequestBody TaOrg taOrg) throws Exception{
@@ -179,7 +184,7 @@ public class TaOrgController extends BaseController {
179 184
      * 根据id查询对象
180 185
      * @param id  实体ID
181 186
      */
182
-    @RequestMapping(value="/admin/taOrg/{id}",method= RequestMethod.GET)
187
+    @RequestMapping(value="/admin/org/{id}",method= RequestMethod.GET)
183 188
     @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
184 189
     public ResponseBean taOrgGet(@ApiParam("对象ID") @PathVariable String id) throws Exception{
185 190
         TaOrg taOrg = iTaOrgService.getById(id);

+ 2
- 0
src/main/java/com/njyunzhi/ubpa/controller/TaResumeWorkFormController.java ファイルの表示

@@ -52,6 +52,7 @@ public class TaResumeWorkFormController extends BaseController {
52 52
     public ResponseBean taResumeWorkFormList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
53 53
                                              @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
54 54
                                              @ApiParam("企业ID") @RequestParam(value ="orgId", required = false) String orgId,
55
+                                             @ApiParam("申请人") @RequestParam(value ="userName", required = false) String userName,
55 56
                                              @ApiParam(value = "起始时间", example = "2022-03-01") @RequestParam(value ="start", required = false) String start,
56 57
                                              @ApiParam(value = "结束时间", example = "2022-03-31") @RequestParam(value ="end", required = false) String end) throws Exception{
57 58
 
@@ -61,6 +62,7 @@ public class TaResumeWorkFormController extends BaseController {
61 62
         IPage<TaResumeWorkForm> pg = new Page<>(pageNum, pageSize);
62 63
         QueryWrapper<TaResumeWorkForm> queryWrapper = new QueryWrapper<>();
63 64
         queryWrapper.eq(!StringUtils.isEmpty(orgId), "org_id", orgId);
65
+        queryWrapper.like(!StringUtils.isEmpty(userName), "user_name", "%" + userName + "%");
64 66
         queryWrapper.ge(!StringUtils.isEmpty(start), "create_date", startDate);
65 67
         queryWrapper.le(!StringUtils.isEmpty(end), "create_date", endDate);
66 68
         queryWrapper.eq("status", Constants.STATUS_NORMAL);

+ 19
- 0
src/main/java/com/njyunzhi/ubpa/exception/GlobalExceptionHandler.java ファイルの表示

@@ -0,0 +1,19 @@
1
+package com.njyunzhi.ubpa.exception;
2
+
3
+import com.njyunzhi.ubpa.common.ResponseBean;
4
+import lombok.extern.slf4j.Slf4j;
5
+import org.springframework.web.bind.annotation.ExceptionHandler;
6
+import org.springframework.web.bind.annotation.ResponseBody;
7
+import org.springframework.web.bind.annotation.RestControllerAdvice;
8
+
9
+@Slf4j
10
+@RestControllerAdvice
11
+public class GlobalExceptionHandler {
12
+
13
+    @ResponseBody
14
+    @ExceptionHandler(Exception.class)
15
+    public ResponseBean handleException(Exception e){
16
+        log.error(e.getMessage(),e);
17
+        return ResponseBean.error(e.getMessage(), ResponseBean.ERROR_UNAVAILABLE);
18
+    }
19
+}

+ 17
- 0
src/main/java/com/njyunzhi/ubpa/shiro/FirstExceptionStrategy.java ファイルの表示

@@ -0,0 +1,17 @@
1
+package com.njyunzhi.ubpa.shiro;
2
+
3
+import org.apache.shiro.authc.AuthenticationException;
4
+import org.apache.shiro.authc.AuthenticationInfo;
5
+import org.apache.shiro.authc.AuthenticationToken;
6
+import org.apache.shiro.authc.pam.AtLeastOneSuccessfulStrategy;
7
+import org.apache.shiro.realm.Realm;
8
+
9
+public class FirstExceptionStrategy extends AtLeastOneSuccessfulStrategy {
10
+
11
+    @Override
12
+    public AuthenticationInfo afterAttempt(Realm realm, AuthenticationToken token, AuthenticationInfo singleRealmInfo, AuthenticationInfo aggregateInfo, Throwable t) throws AuthenticationException {
13
+        if ((t instanceof AuthenticationException)) throw (AuthenticationException) t;
14
+        return super.afterAttempt(realm, token, singleRealmInfo, aggregateInfo, t);
15
+    }
16
+
17
+}

+ 2
- 1
src/main/java/com/njyunzhi/ubpa/shiro/ShiroConfig.java ファイルの表示

@@ -79,7 +79,8 @@ public class ShiroConfig {
79 79
         // 修改多 Realm 的处理逻辑
80 80
         ModularRealmAuthenticator realmAuthenticator = (ModularRealmAuthenticator) manager.getAuthenticator();
81 81
         // 主要有一个 Realm 成功, 就立即返回
82
-        realmAuthenticator.setAuthenticationStrategy(new AtLeastOneSuccessfulStrategy());
82
+//        realmAuthenticator.setAuthenticationStrategy(new AtLeastOneSuccessfulStrategy());
83
+        realmAuthenticator.setAuthenticationStrategy(new FirstExceptionStrategy());
83 84
 
84 85
         //  Use your own realm
85 86
         List<Realm> realmList = new ArrayList<Realm>() {{

+ 10
- 0
src/main/java/com/njyunzhi/ubpa/shiro/filters/JWTFilter.java ファイルの表示

@@ -1,6 +1,7 @@
1 1
 package com.njyunzhi.ubpa.shiro.filters;
2 2
 
3 3
 import com.njyunzhi.ubpa.shiro.utils.JWTUtil;
4
+import org.apache.shiro.authc.AuthenticationException;
4 5
 import org.apache.shiro.authc.AuthenticationToken;
5 6
 import org.apache.shiro.subject.Subject;
6 7
 import org.apache.shiro.web.filter.authc.AuthenticatingFilter;
@@ -62,6 +63,15 @@ public abstract class JWTFilter extends AuthenticatingFilter {
62 63
         return true;
63 64
     }
64 65
 
66
+    @Override
67
+    protected boolean onLoginFailure(AuthenticationToken token, AuthenticationException e, ServletRequest request, ServletResponse response) {
68
+        if (e != null) {
69
+            response401(request, response, e);
70
+        }
71
+
72
+        return false;
73
+    }
74
+
65 75
     /**
66 76
      *Jump illegal request to / 401
67 77
      */

+ 6
- 3
src/main/resources/application-dev.yml ファイルの表示

@@ -5,12 +5,15 @@ spring:
5 5
       max-file-size: 10MB
6 6
       max-request-size: 50MB
7 7
   datasource:
8
-    url: jdbc:mysql://110.40.183.156:3306/nanyang_machinery?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true
9
-    username: nanyang_machinery
10
-    password: nanyang_machinery@ABCD1234
8
+    url: jdbc:mysql://110.40.183.156:3306/ubpa?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true
9
+    username: ubpa
10
+    password: ubpa@ABCD1234
11 11
 
12 12
 ###
13 13
 logging:
14 14
   level:
15 15
     root: info
16 16
     springfox: info
17
+
18
+yz:
19
+  cros: true

+ 5
- 3
src/main/resources/application-prod.yml ファイルの表示

@@ -5,7 +5,9 @@ spring:
5 5
       max-file-size: 10MB
6 6
       max-request-size: 50MB
7 7
   datasource:
8
-    url: jdbc:mysql://110.40.183.156:3306/nanyang_machinery?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true
9
-    username: nanyang_machinery
10
-    password: nanyang_machinery@ABCD1234
8
+    url: jdbc:mysql://110.40.183.156:3306/ubpa?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true
9
+    username: ubpa
10
+    password: ubpa@ABCD1234
11 11
 
12
+yz:
13
+  cros: false

+ 1
- 1
src/main/resources/application.yml ファイルの表示

@@ -31,7 +31,7 @@ mybatis-plus:
31 31
 sms:
32 32
   captcha:
33 33
     code: SMS_207555188
34
-    sign: ????
34
+    sign: 云致科技
35 35
 
36 36
 ###
37 37
 yz: