张延森 před 3 roky
rodič
revize
3f9466d660
28 změnil soubory, kde provedl 982 přidání a 197 odebrání
  1. 1
    0
      .gitignore
  2. 47
    1
      pom.xml
  3. 25
    0
      src/main/java/com/yunzhi/drawlots/common/CurrentContext.java
  4. 107
    0
      src/main/java/com/yunzhi/drawlots/common/JWTUtils.java
  5. 4
    0
      src/main/java/com/yunzhi/drawlots/common/ResponseBean.java
  6. 35
    0
      src/main/java/com/yunzhi/drawlots/config/BaseConfig.java
  7. 32
    0
      src/main/java/com/yunzhi/drawlots/config/InterceptorConfig.java
  8. 21
    0
      src/main/java/com/yunzhi/drawlots/config/LoggingFilterConfig.java
  9. 14
    0
      src/main/java/com/yunzhi/drawlots/config/MybatisPlusConfig.java
  10. 20
    0
      src/main/java/com/yunzhi/drawlots/config/SMSConfig.java
  11. 24
    0
      src/main/java/com/yunzhi/drawlots/config/SwagggerConfig.java
  12. 13
    0
      src/main/java/com/yunzhi/drawlots/controller/CommController.java
  13. 115
    0
      src/main/java/com/yunzhi/drawlots/controller/LoginController.java
  14. 83
    83
      src/main/java/com/yunzhi/drawlots/controller/TaLunarController.java
  15. 113
    53
      src/main/java/com/yunzhi/drawlots/controller/TaPersonController.java
  16. 70
    57
      src/main/java/com/yunzhi/drawlots/controller/TaPrizeController.java
  17. 31
    0
      src/main/java/com/yunzhi/drawlots/entity/TaPerson.java
  18. 3
    0
      src/main/java/com/yunzhi/drawlots/entity/TaPrize.java
  19. 19
    0
      src/main/java/com/yunzhi/drawlots/exception/GlobalExceptionHandler.java
  20. 48
    0
      src/main/java/com/yunzhi/drawlots/interceptor/PermissionInterceptor.java
  21. 8
    0
      src/main/java/com/yunzhi/drawlots/mapper/TaPersonMapper.java
  22. 13
    0
      src/main/java/com/yunzhi/drawlots/service/ITaPersonService.java
  23. 53
    0
      src/main/java/com/yunzhi/drawlots/service/impl/TaPersonServiceImpl.java
  24. 1
    1
      src/main/java/com/yunzhi/drawlots/service/impl/TaPrizeServiceImpl.java
  25. 16
    0
      src/main/java/com/yunzhi/drawlots/vo/LoginParam.java
  26. 20
    0
      src/main/java/com/yunzhi/drawlots/vo/MPLogin.java
  27. 25
    2
      src/main/resources/application.yml
  28. 21
    0
      src/main/resources/mapper/TaPersonMapper.xml

+ 1
- 0
.gitignore Zobrazit soubor

@@ -1,5 +1,6 @@
1 1
 HELP.md
2 2
 target/
3
+deploy/
3 4
 !.mvn/wrapper/maven-wrapper.jar
4 5
 !**/src/main/**/target/
5 6
 !**/src/test/**/target/

+ 47
- 1
pom.xml Zobrazit soubor

@@ -10,7 +10,7 @@
10 10
 	</parent>
11 11
 	<groupId>com.yunzhi</groupId>
12 12
 	<artifactId>drawlots</artifactId>
13
-	<version>0.0.1-SNAPSHOT</version>
13
+	<version>0.0.2</version>
14 14
 	<name>drawlots</name>
15 15
 	<description>红鹤抽奖</description>
16 16
 	<properties>
@@ -56,6 +56,25 @@
56 56
 			<artifactId>weixin-java-mp</artifactId>
57 57
 			<version>3.8.0</version>
58 58
 		</dependency>
59
+		<!--jwt start-->
60
+		<dependency>
61
+			<groupId>io.jsonwebtoken</groupId>
62
+			<artifactId>jjwt-api</artifactId>
63
+			<version>0.11.2</version>
64
+		</dependency>
65
+		<dependency>
66
+			<groupId>io.jsonwebtoken</groupId>
67
+			<artifactId>jjwt-impl</artifactId>
68
+			<version>0.11.2</version>
69
+			<scope>runtime</scope>
70
+		</dependency>
71
+		<dependency>
72
+			<groupId>io.jsonwebtoken</groupId>
73
+			<artifactId>jjwt-jackson</artifactId> <!-- or jjwt-gson if Gson is preferred -->
74
+			<version>0.11.2</version>
75
+			<scope>runtime</scope>
76
+		</dependency>
77
+		<!--jwt end-->
59 78
 		<!--swagger start-->
60 79
 		<dependency>
61 80
 			<groupId>io.springfox</groupId>
@@ -77,8 +96,35 @@
77 96
 							<artifactId>lombok</artifactId>
78 97
 						</exclude>
79 98
 					</excludes>
99
+<!--					<mainClass>com.yunzhi.drawlots.DrawlotsApplication</mainClass>-->
100
+<!--					<layout>ZIP</layout>-->
101
+<!--					<includes>-->
102
+<!--						<include>-->
103
+<!--							<groupId>nothing</groupId>-->
104
+<!--							<artifactId>nothing</artifactId>-->
105
+<!--						</include>-->
106
+<!--					</includes>-->
80 107
 				</configuration>
81 108
 			</plugin>
109
+<!--			<plugin>-->
110
+<!--				<groupId>org.apache.maven.plugins</groupId>-->
111
+<!--				<artifactId>maven-dependency-plugin</artifactId>-->
112
+<!--				<executions>-->
113
+<!--					<execution>-->
114
+<!--						<goals>-->
115
+<!--							<goal>copy-dependencies</goal>-->
116
+<!--						</goals>-->
117
+<!--						<configuration>-->
118
+<!--							&lt;!&ndash; ${project.build.directory}是maven变量,内置的,表示target目录,如果不写,将在跟目录下创建/lib &ndash;&gt;-->
119
+<!--							<outputDirectory>${project.build.directory}/lib</outputDirectory>-->
120
+<!--							&lt;!&ndash; excludeTransitive:是否不包含间接依赖包,比如我们依赖A,但是A又依赖了B,我们是否也要把B打进去 默认不打&ndash;&gt;-->
121
+<!--							<excludeTransitive>false</excludeTransitive>-->
122
+<!--							&lt;!&ndash; 复制的jar文件去掉版本信息 true去掉 false 不去&ndash;&gt;-->
123
+<!--							<stripVersion>false</stripVersion>-->
124
+<!--						</configuration>-->
125
+<!--					</execution>-->
126
+<!--				</executions>-->
127
+<!--			</plugin>-->
82 128
 		</plugins>
83 129
 	</build>
84 130
 

+ 25
- 0
src/main/java/com/yunzhi/drawlots/common/CurrentContext.java Zobrazit soubor

@@ -0,0 +1,25 @@
1
+package com.yunzhi.drawlots.common;
2
+
3
+import java.util.Map;
4
+
5
+public class CurrentContext {
6
+
7
+    /**
8
+     * TokenParam 相关
9
+     */
10
+    private static final ThreadLocal<Map<String, Object>> tokenParamHolder = new ThreadLocal<>();
11
+
12
+    public static void setTokenParam(Map<String, Object> tokenParam) {
13
+        tokenParamHolder.remove();
14
+        tokenParamHolder.set(tokenParam);
15
+    }
16
+
17
+    public static void clear() {
18
+        tokenParamHolder.remove();
19
+    }
20
+
21
+    public static Map<String, Object> getTokenParam() {
22
+        Map<String, Object> params = tokenParamHolder.get();
23
+        return params;
24
+    }
25
+}

+ 107
- 0
src/main/java/com/yunzhi/drawlots/common/JWTUtils.java Zobrazit soubor

@@ -0,0 +1,107 @@
1
+package com.yunzhi.drawlots.common;
2
+
3
+import io.jsonwebtoken.Claims;
4
+import io.jsonwebtoken.Jws;
5
+import io.jsonwebtoken.Jwts;
6
+import io.jsonwebtoken.security.Keys;
7
+import org.slf4j.Logger;
8
+import org.slf4j.LoggerFactory;
9
+
10
+import javax.crypto.SecretKey;
11
+import javax.servlet.http.HttpServletRequest;
12
+import javax.servlet.http.HttpServletResponse;
13
+import java.time.LocalDateTime;
14
+import java.time.ZoneId;
15
+import java.util.Base64;
16
+import java.util.Date;
17
+import java.util.Map;
18
+
19
+/**
20
+ * JWTUtils
21
+ * jwt 辅助类
22
+ * https://github.com/jwtk/jjwt
23
+ */
24
+public class JWTUtils {
25
+    private static final Logger log = LoggerFactory.getLogger(JWTUtils.class);
26
+
27
+    // 过期时间 30 分钟
28
+    public static final long EXPIRE_TIME = 30 * 60 * 24;
29
+
30
+    // 私钥
31
+    static final SecretKey SECRET_KEY = Keys.hmacShaKeyFor(Base64.getEncoder().encode("Yansen is so handsome. He is a good man. Everyone like him !!!".getBytes()));
32
+
33
+    // 请求头
34
+    public static final String AUTH_HEADER = "X-Authorization-JWT";
35
+
36
+    /**
37
+     * 生成 token, claims 里必须要有 userId
38
+     * @param claims
39
+     * @return
40
+     */
41
+    public static String encode(Map<String, Object> claims) {
42
+        Date[] datePair = getDatePair();
43
+        Date iat = datePair[0];
44
+        Date exp = datePair[1];
45
+
46
+        return Jwts.builder().setIssuer(claims.get("userId").toString()).setIssuedAt(iat).setExpiration(exp).addClaims(claims).signWith(SECRET_KEY).compact();
47
+    }
48
+
49
+    public static Map<String, Object> decode(String token) throws Exception {
50
+        return parse(token);
51
+    }
52
+
53
+    public static String refresh(String token) {
54
+        try {
55
+            Claims claims = parse(token);
56
+
57
+            Integer iat = (Integer) claims.get("iat");
58
+            if (null != iat) {
59
+                long currentTime = System.currentTimeMillis() / 1000;
60
+                int oneMinute = 60;
61
+                if (currentTime - iat < oneMinute) {
62
+                    return token;
63
+                }
64
+            }
65
+
66
+            claims.remove("iat");
67
+            claims.remove("exp");
68
+
69
+            return encode(claims);
70
+        } catch (Exception e) {
71
+            log.error("解析 JWT Token 失败: {}", e.getMessage());
72
+        }
73
+        return null;
74
+    }
75
+
76
+    public static void refresh(String jws, HttpServletResponse response) {
77
+        if (!StringUtils.isEmpty(jws)) {
78
+            String token =  refresh(jws);
79
+            response.addHeader(AUTH_HEADER, token);
80
+        }
81
+    }
82
+
83
+    public static String getToken(HttpServletRequest request) {
84
+        return request.getHeader(AUTH_HEADER);
85
+    }
86
+
87
+    public static void verify(String token) throws Exception {
88
+        parse(token);
89
+    }
90
+
91
+    private static Date[] getDatePair() {
92
+        LocalDateTime now = LocalDateTime.now();
93
+        Date iat = Date.from(now.atZone(ZoneId.systemDefault()).toInstant());
94
+        Date exp = Date.from(now.plusSeconds(EXPIRE_TIME).atZone(ZoneId.systemDefault()).toInstant());
95
+        return new Date[]{iat, exp};
96
+    }
97
+
98
+    private static Claims parse(String token) throws Exception {
99
+        if (token == null || "".equals(token)) {
100
+            throw new Exception("Token 不能为空");
101
+        }
102
+
103
+        long skew = 5;
104
+        Jws<Claims> claimsJws = Jwts.parserBuilder().setAllowedClockSkewSeconds(skew).setSigningKey(SECRET_KEY).build().parseClaimsJws(token);
105
+        return claimsJws.getBody();
106
+    }
107
+}

+ 4
- 0
src/main/java/com/yunzhi/drawlots/common/ResponseBean.java Zobrazit soubor

@@ -73,4 +73,8 @@ public class ResponseBean<T> implements Serializable {
73 73
     public String toString() {
74 74
         return  "{ code: "+code+", message: "+message+", data: <T> }";
75 75
     }
76
+
77
+    public String toJSON() {
78
+        return String.format("{ \"code\": %d, \"message\": %s }", code, message);
79
+    }
76 80
 }

+ 35
- 0
src/main/java/com/yunzhi/drawlots/config/BaseConfig.java Zobrazit soubor

@@ -0,0 +1,35 @@
1
+package com.yunzhi.drawlots.config;
2
+
3
+import com.yunzhi.drawlots.interceptor.PermissionInterceptor;
4
+import lombok.Data;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.context.annotation.Configuration;
7
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
8
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
9
+
10
+import javax.annotation.PostConstruct;
11
+
12
+@Data
13
+@Configuration
14
+public class BaseConfig implements WebMvcConfigurer {
15
+
16
+    @Autowired
17
+    private PermissionInterceptor permissionInterceptor;
18
+
19
+    @Autowired
20
+    private InterceptorConfig interceptorConfig;
21
+
22
+    @PostConstruct
23
+    public void init() {
24
+    }
25
+
26
+    @Override
27
+    public void addInterceptors(InterceptorRegistry registry) {
28
+        // 自定义拦截器,添加拦截路径和排除拦截路径
29
+        if (interceptorConfig.getPermission().isEnable()) {
30
+            registry.addInterceptor(permissionInterceptor)
31
+                    .addPathPatterns(interceptorConfig.getPermission().getIncludePaths())
32
+                    .excludePathPatterns(interceptorConfig.getPermission().getExcludePaths());
33
+        }
34
+    }
35
+}

+ 32
- 0
src/main/java/com/yunzhi/drawlots/config/InterceptorConfig.java Zobrazit soubor

@@ -0,0 +1,32 @@
1
+package com.yunzhi.drawlots.config;
2
+
3
+import lombok.Data;
4
+import org.springframework.boot.context.properties.ConfigurationProperties;
5
+import org.springframework.stereotype.Component;
6
+
7
+@Data
8
+@Component
9
+@ConfigurationProperties(prefix = "interceptor")
10
+public class InterceptorConfig {
11
+
12
+    private Config permission;
13
+
14
+    @Data
15
+    public static class Config {
16
+
17
+        /**
18
+         * 是否启用
19
+         */
20
+        private boolean enable;
21
+
22
+        /**
23
+         * 包含的路径
24
+         */
25
+        private String[] includePaths = new String[]{};
26
+
27
+        /**
28
+         * 排除路径
29
+         */
30
+        private String[] excludePaths = new String[]{};
31
+    }
32
+}

+ 21
- 0
src/main/java/com/yunzhi/drawlots/config/LoggingFilterConfig.java Zobrazit soubor

@@ -0,0 +1,21 @@
1
+package com.yunzhi.drawlots.config;
2
+
3
+import lombok.extern.slf4j.Slf4j;
4
+import org.springframework.context.annotation.Configuration;
5
+
6
+import javax.servlet.*;
7
+import javax.servlet.http.HttpServletRequest;
8
+import java.io.IOException;
9
+
10
+@Slf4j
11
+@Configuration
12
+public class LoggingFilterConfig implements Filter {
13
+    @Override
14
+    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
15
+        HttpServletRequest req = (HttpServletRequest) request;
16
+        log.info("Request URI: [{}] {}", req.getMethod() , req.getRequestURI());
17
+
18
+        // 继续执行
19
+        chain.doFilter(request, response);
20
+    }
21
+}

+ 14
- 0
src/main/java/com/yunzhi/drawlots/config/MybatisPlusConfig.java Zobrazit soubor

@@ -0,0 +1,14 @@
1
+package com.yunzhi.drawlots.config;
2
+
3
+import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
4
+import org.springframework.context.annotation.Bean;
5
+import org.springframework.context.annotation.Configuration;
6
+
7
+@Configuration
8
+public class MybatisPlusConfig {
9
+
10
+    @Bean
11
+    public PaginationInterceptor paginationInterceptor() {
12
+        return new PaginationInterceptor();
13
+    }
14
+}

+ 20
- 0
src/main/java/com/yunzhi/drawlots/config/SMSConfig.java Zobrazit soubor

@@ -0,0 +1,20 @@
1
+package com.yunzhi.drawlots.config;
2
+
3
+import lombok.Data;
4
+import org.springframework.boot.context.properties.ConfigurationProperties;
5
+import org.springframework.stereotype.Component;
6
+
7
+@Data
8
+@Component
9
+@ConfigurationProperties(prefix = "sms")
10
+public class SMSConfig {
11
+    private String server;
12
+    private Captcha captcha;
13
+
14
+    @Data
15
+    public static class Captcha {
16
+        private String plat;
17
+        private String template;
18
+        private String sign;
19
+    }
20
+}

+ 24
- 0
src/main/java/com/yunzhi/drawlots/config/SwagggerConfig.java Zobrazit soubor

@@ -0,0 +1,24 @@
1
+package com.yunzhi.drawlots.config;
2
+
3
+import io.swagger.annotations.Api;
4
+import org.springframework.context.annotation.Bean;
5
+import org.springframework.context.annotation.Configuration;
6
+import springfox.documentation.builders.PathSelectors;
7
+import springfox.documentation.builders.RequestHandlerSelectors;
8
+import springfox.documentation.spi.DocumentationType;
9
+import springfox.documentation.spring.web.plugins.Docket;
10
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
11
+
12
+@Configuration
13
+@EnableSwagger2
14
+public class SwagggerConfig {
15
+    @Bean
16
+    public Docket docket() {
17
+        return new Docket(DocumentationType.SWAGGER_2)
18
+                .select()
19
+                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
20
+                .paths(PathSelectors.any())
21
+                .build();
22
+
23
+    }
24
+}

+ 13
- 0
src/main/java/com/yunzhi/drawlots/controller/CommController.java Zobrazit soubor

@@ -0,0 +1,13 @@
1
+package com.yunzhi.drawlots.controller;
2
+
3
+import com.yunzhi.drawlots.common.BaseController;
4
+import io.swagger.annotations.Api;
5
+import org.springframework.web.bind.annotation.RequestMapping;
6
+import org.springframework.web.bind.annotation.RestController;
7
+
8
+@Api(tags = "通用")
9
+@RestController
10
+@RequestMapping("/")
11
+public class CommController  extends BaseController {
12
+
13
+}

+ 115
- 0
src/main/java/com/yunzhi/drawlots/controller/LoginController.java Zobrazit soubor

@@ -0,0 +1,115 @@
1
+package com.yunzhi.drawlots.controller;
2
+
3
+import com.yunzhi.drawlots.common.BaseController;
4
+import com.yunzhi.drawlots.common.JWTUtils;
5
+import com.yunzhi.drawlots.common.ResponseBean;
6
+import com.yunzhi.drawlots.common.StringUtils;
7
+import com.yunzhi.drawlots.entity.TaPerson;
8
+import com.yunzhi.drawlots.service.ITaPersonService;
9
+import com.yunzhi.drawlots.vo.LoginParam;
10
+import com.yunzhi.drawlots.vo.MPLogin;
11
+import io.swagger.annotations.Api;
12
+import io.swagger.annotations.ApiOperation;
13
+import io.swagger.annotations.ApiParam;
14
+import org.springframework.beans.factory.annotation.Autowired;
15
+import org.springframework.beans.factory.annotation.Value;
16
+import org.springframework.util.DigestUtils;
17
+import org.springframework.web.bind.annotation.*;
18
+
19
+import java.nio.charset.StandardCharsets;
20
+import java.util.HashMap;
21
+import java.util.Map;
22
+
23
+@Api(tags = "登入/登出")
24
+@RestController
25
+public class LoginController extends BaseController {
26
+
27
+    @Value("${biz.admin.account}")
28
+    String adminAccount;
29
+
30
+    @Value("${biz.admin.password}")
31
+    String adminPassword;
32
+
33
+    @Autowired
34
+    ITaPersonService iTaPersonService;
35
+
36
+    @PostMapping("/admin/login")
37
+    @ApiOperation(value="后端登录", notes = "后端登录", httpMethod = "POST", response = ResponseBean.class)
38
+    public ResponseBean login(@ApiParam("登录参数") @RequestBody LoginParam loginParam) throws Exception {
39
+        if (null == loginParam) {
40
+            return ResponseBean.error("账户或密码不能为空", ResponseBean.ERROR_ILLEGAL_PARAMS);
41
+        }
42
+
43
+        String userName = loginParam.getUserName();
44
+        String password = loginParam.getPassword();
45
+
46
+        if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password)) {
47
+            return ResponseBean.error("账户或密码不能为空", ResponseBean.ERROR_ILLEGAL_PARAMS);
48
+        }
49
+
50
+        if (!adminAccount.equals(userName)) {
51
+            return ResponseBean.error("账户或密码不正确", ResponseBean.ERROR_ILLEGAL_PARAMS);
52
+        }
53
+
54
+        String targetPassword = md5(md5(adminPassword) + adminAccount);
55
+
56
+        if (!checkPassword(password, targetPassword, adminAccount)) {
57
+            return ResponseBean.error("账户或密码不正确", ResponseBean.ERROR_ILLEGAL_PARAMS);
58
+        }
59
+
60
+        // 生成 token
61
+        Map<String, Object> tokenMap = new HashMap<String, Object>() {{
62
+           put("userId", adminAccount);
63
+        }};
64
+        String token = JWTUtils.encode(tokenMap);
65
+
66
+        Map<String, Object> res = new HashMap<String, Object>() {{
67
+//            put("user", sysUser);
68
+            put("token", token);
69
+        }};
70
+        return ResponseBean.success(res);
71
+    }
72
+
73
+    /**
74
+     * 根据id查询对象
75
+     * @param params  登录参数
76
+     */
77
+    @RequestMapping(value="/wx/login",method= RequestMethod.POST)
78
+    @ApiOperation(value="微信登录", notes = "微信登录", httpMethod = "POST", response = ResponseBean.class)
79
+    public ResponseBean taPersonGet(@ApiParam("对象ID") @RequestBody MPLogin params) throws Exception{
80
+        String openid = params.getOpenid();
81
+        if (StringUtils.isEmpty(openid)) {
82
+            return ResponseBean.error("登录参数不正确", ResponseBean.ERROR_ILLEGAL_PARAMS);
83
+        }
84
+
85
+        TaPerson taPerson = iTaPersonService.getByOpenId(openid);
86
+
87
+        // 更新人员信息
88
+        if (!StringUtils.isEmpty(params.getNickname())) {
89
+            taPerson.setName(params.getNickname());
90
+            taPerson.setAvatar(params.getHeadImgUrl());
91
+            iTaPersonService.updateById(taPerson);
92
+        }
93
+
94
+        // 生成 token
95
+        Map<String, Object> tokenMap = new HashMap<String, Object>() {{
96
+            put("userId", taPerson.getPersonId());
97
+        }};
98
+        String token = JWTUtils.encode(tokenMap);
99
+
100
+        Map<String, Object> res = new HashMap<String, Object>() {{
101
+            put("user", taPerson);
102
+            put("token", token);
103
+        }};
104
+
105
+        return ResponseBean.success(res);
106
+    }
107
+
108
+    private boolean checkPassword(String src, String targ, String salt) {
109
+        return md5((src+salt)).equals(targ);
110
+    }
111
+
112
+    private String md5(String src) {
113
+        return DigestUtils.md5DigestAsHex(src.getBytes(StandardCharsets.UTF_8));
114
+    }
115
+}

+ 83
- 83
src/main/java/com/yunzhi/drawlots/controller/TaLunarController.java Zobrazit soubor

@@ -33,87 +33,87 @@ import org.springframework.web.bind.annotation.RestController;
33 33
 @RestController
34 34
 @RequestMapping("/")
35 35
 public class TaLunarController extends BaseController {
36
-
37
-    private final Logger logger = LoggerFactory.getLogger(TaLunarController.class);
38
-
39
-    @Autowired
40
-    public ITaLunarService iTaLunarService;
41
-
42
-
43
-    /**
44
-     * 分页查询列表
45
-     * @param pageNum
46
-     * @param pageSize
47
-     * @return
48
-     */
49
-    @RequestMapping(value="/taLunar",method= RequestMethod.GET)
50
-    @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
51
-    public ResponseBean taLunarList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
-									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
53
-
54
-		    IPage<TaLunar> pg = new Page<>(pageNum, pageSize);
55
-            QueryWrapper<TaLunar> queryWrapper = new QueryWrapper<>();
56
-            queryWrapper.orderByDesc("create_date");
57
-
58
-            IPage<TaLunar> result = iTaLunarService.page(pg, queryWrapper);
59
-            return ResponseBean.success(result);
60
-    }
61
-
62
-    /**
63
-     * 保存对象
64
-     * @param taLunar 实体对象
65
-     * @return
66
-     */
67
-    @RequestMapping(value="/taLunar",method= RequestMethod.POST)
68
-    @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
69
-    public ResponseBean taLunarAdd(@ApiParam("保存内容") @RequestBody TaLunar taLunar) throws Exception{
70
-
71
-        if (iTaLunarService.save(taLunar)){
72
-            return ResponseBean.success(taLunar);
73
-        }else {
74
-            return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
75
-        }
76
-    }
77
-
78
-    /**
79
-     * 根据id删除对象
80
-     * @param id  实体ID
81
-     */
82
-    @RequestMapping(value="/taLunar/{id}", method= RequestMethod.DELETE)
83
-    @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
84
-    public ResponseBean taLunarDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
85
-        if(iTaLunarService.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 taLunar 实体对象
96
-     * @return
97
-     */
98
-    @RequestMapping(value="/taLunar/{id}",method= RequestMethod.PUT)
99
-    @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
100
-    public ResponseBean taLunarUpdate(@ApiParam("对象ID") @PathVariable Integer id,
101
-                                        @ApiParam("更新内容") @RequestBody TaLunar taLunar) throws Exception{
102
-
103
-        if (iTaLunarService.updateById(taLunar)){
104
-            return ResponseBean.success(iTaLunarService.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="/taLunar/{id}",method= RequestMethod.GET)
115
-    @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
116
-    public ResponseBean taLunarGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
117
-        return ResponseBean.success(iTaLunarService.getById(id));
118
-    }
36
+//
37
+//    private final Logger logger = LoggerFactory.getLogger(TaLunarController.class);
38
+//
39
+//    @Autowired
40
+//    public ITaLunarService iTaLunarService;
41
+//
42
+//
43
+//    /**
44
+//     * 分页查询列表
45
+//     * @param pageNum
46
+//     * @param pageSize
47
+//     * @return
48
+//     */
49
+//    @RequestMapping(value="/taLunar",method= RequestMethod.GET)
50
+//    @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
51
+//    public ResponseBean taLunarList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
+//									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
53
+//
54
+//		    IPage<TaLunar> pg = new Page<>(pageNum, pageSize);
55
+//            QueryWrapper<TaLunar> queryWrapper = new QueryWrapper<>();
56
+//            queryWrapper.orderByDesc("create_date");
57
+//
58
+//            IPage<TaLunar> result = iTaLunarService.page(pg, queryWrapper);
59
+//            return ResponseBean.success(result);
60
+//    }
61
+//
62
+//    /**
63
+//     * 保存对象
64
+//     * @param taLunar 实体对象
65
+//     * @return
66
+//     */
67
+//    @RequestMapping(value="/taLunar",method= RequestMethod.POST)
68
+//    @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
69
+//    public ResponseBean taLunarAdd(@ApiParam("保存内容") @RequestBody TaLunar taLunar) throws Exception{
70
+//
71
+//        if (iTaLunarService.save(taLunar)){
72
+//            return ResponseBean.success(taLunar);
73
+//        }else {
74
+//            return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
75
+//        }
76
+//    }
77
+//
78
+//    /**
79
+//     * 根据id删除对象
80
+//     * @param id  实体ID
81
+//     */
82
+//    @RequestMapping(value="/taLunar/{id}", method= RequestMethod.DELETE)
83
+//    @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
84
+//    public ResponseBean taLunarDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
85
+//        if(iTaLunarService.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 taLunar 实体对象
96
+//     * @return
97
+//     */
98
+//    @RequestMapping(value="/taLunar/{id}",method= RequestMethod.PUT)
99
+//    @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
100
+//    public ResponseBean taLunarUpdate(@ApiParam("对象ID") @PathVariable Integer id,
101
+//                                        @ApiParam("更新内容") @RequestBody TaLunar taLunar) throws Exception{
102
+//
103
+//        if (iTaLunarService.updateById(taLunar)){
104
+//            return ResponseBean.success(iTaLunarService.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="/taLunar/{id}",method= RequestMethod.GET)
115
+//    @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
116
+//    public ResponseBean taLunarGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
117
+//        return ResponseBean.success(iTaLunarService.getById(id));
118
+//    }
119 119
 }

+ 113
- 53
src/main/java/com/yunzhi/drawlots/controller/TaPersonController.java Zobrazit soubor

@@ -1,10 +1,9 @@
1 1
 package com.yunzhi.drawlots.controller;
2 2
 
3
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 3
 import com.baomidou.mybatisplus.core.metadata.IPage;
5 4
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
-import com.yunzhi.drawlots.common.BaseController;
7
-import com.yunzhi.drawlots.common.ResponseBean;
5
+import com.yunzhi.drawlots.common.*;
6
+import com.yunzhi.drawlots.service.ITaPrizeService;
8 7
 import io.swagger.annotations.Api;
9 8
 import io.swagger.annotations.ApiOperation;
10 9
 import io.swagger.annotations.ApiParam;
@@ -12,7 +11,6 @@ import org.slf4j.Logger;
12 11
 import org.slf4j.LoggerFactory;
13 12
 import org.springframework.beans.factory.annotation.Autowired;
14 13
 import org.springframework.web.bind.annotation.PathVariable;
15
-import org.springframework.web.bind.annotation.RequestBody;
16 14
 import org.springframework.web.bind.annotation.RequestMapping;
17 15
 import org.springframework.web.bind.annotation.RequestMethod;
18 16
 import org.springframework.web.bind.annotation.RequestParam;
@@ -20,6 +18,10 @@ import com.yunzhi.drawlots.service.ITaPersonService;
20 18
 import com.yunzhi.drawlots.entity.TaPerson;
21 19
 import org.springframework.web.bind.annotation.RestController;
22 20
 
21
+import javax.servlet.http.HttpServletResponse;
22
+import java.time.LocalDateTime;
23
+import java.util.List;
24
+
23 25
 /**
24 26
  * <p>
25 27
     * 用户表 前端控制器
@@ -39,6 +41,9 @@ public class TaPersonController extends BaseController {
39 41
     @Autowired
40 42
     public ITaPersonService iTaPersonService;
41 43
 
44
+    @Autowired
45
+    public ITaPrizeService iTaPrizeService;
46
+
42 47
 
43 48
     /**
44 49
      * 分页查询列表
@@ -49,71 +54,126 @@ public class TaPersonController extends BaseController {
49 54
     @RequestMapping(value="/taPerson",method= RequestMethod.GET)
50 55
     @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
51 56
     public ResponseBean taPersonList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
-									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
57
+									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
58
+                                     @ApiParam(value = "开始时间", example = "2021-01-01") @RequestParam(value ="startDate", required = false) String startDate,
59
+                                     @ApiParam(value = "结束时间", example = "2021-10-31") @RequestParam(value ="endDate", required = false) String endDate) throws Exception{
53 60
 
54
-        IPage<TaPerson> pg = new Page<>(pageNum, pageSize);
55
-        QueryWrapper<TaPerson> queryWrapper = new QueryWrapper<>();
56
-        queryWrapper.orderByDesc("create_date");
61
+        LocalDateTime start = null, end = null;
62
+
63
+        if (!StringUtils.isEmpty(startDate)) {
64
+            start = DateUtils.from(startDate + " 00:00:00", "yyyy-MM-dd HH:mm:ss");
65
+        }
66
+        if (!StringUtils.isEmpty(endDate)) {
67
+            end = DateUtils.from(endDate + " 23:59:59", "yyyy-MM-dd HH:mm:ss");
68
+        }
57 69
 
58
-        IPage<TaPerson> result = iTaPersonService.page(pg, queryWrapper);
70
+        IPage<TaPerson> pg = new Page<>(pageNum, pageSize);
71
+        IPage<TaPerson> result = iTaPersonService.getPageBy(pg, start, end);
59 72
         return ResponseBean.success(result);
60 73
     }
61 74
 
62
-    /**
63
-     * 保存对象
64
-     * @param taPerson 实体对象
65
-     * @return
66
-     */
67 75
     @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{
76
+    @ApiOperation(value="导出Excel", notes = "导出Excel", httpMethod = "POST", response = ResponseBean.class)
77
+    public void exportXls(@ApiParam(value = "开始时间", example = "2021-01-01") @RequestParam(value ="startDate", required = false) String startDate,
78
+                          @ApiParam(value = "结束时间", example = "2021-10-31") @RequestParam(value ="endDate", required = false) String endDate,
79
+                          HttpServletResponse response) throws Exception {
80
+        LocalDateTime start = null, end = null;
70 81
 
71
-        if (iTaPersonService.save(taPerson)){
72
-            return ResponseBean.success(taPerson);
73
-        }else {
74
-            return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
82
+        if (!StringUtils.isEmpty(startDate)) {
83
+            start = DateUtils.from(startDate + " 00:00:00", "yyyy-MM-dd HH:mm:ss");
75 84
         }
85
+        if (!StringUtils.isEmpty(endDate)) {
86
+            end = DateUtils.from(endDate + " 23:59:59", "yyyy-MM-dd HH:mm:ss");
87
+        }
88
+
89
+        List<TaPerson> result = iTaPersonService.getListBy(start, end);
90
+        ExcelUtils.flush(response, TaPerson.class, result, "参与人员名单");
76 91
     }
77 92
 
93
+//    /**
94
+//     * 保存对象
95
+//     * @param taPerson 实体对象
96
+//     * @return
97
+//     */
98
+//    @RequestMapping(value="/taPerson",method= RequestMethod.POST)
99
+//    @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
100
+//    public ResponseBean taPersonAdd(@ApiParam("保存内容") @RequestBody TaPerson taPerson) throws Exception{
101
+//
102
+//        if (iTaPersonService.save(taPerson)){
103
+//            return ResponseBean.success(taPerson);
104
+//        }else {
105
+//            return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
106
+//        }
107
+//    }
108
+//
109
+//    /**
110
+//     * 根据id删除对象
111
+//     * @param id  实体ID
112
+//     */
113
+//    @RequestMapping(value="/taPerson/{id}", method= RequestMethod.DELETE)
114
+//    @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
115
+//    public ResponseBean taPersonDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
116
+//        if(iTaPersonService.removeById(id)){
117
+//            return ResponseBean.success("success");
118
+//        }else {
119
+//            return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
120
+//        }
121
+//    }
122
+
123
+//    /**
124
+//     * 修改对象
125
+//     * @param id  实体ID
126
+//     * @param taPerson 实体对象
127
+//     * @return
128
+//     */
129
+//    @RequestMapping(value="/wx/taPerson/{id}",method= RequestMethod.PUT)
130
+//    @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
131
+//    public ResponseBean taPersonUpdate(@ApiParam("对象ID") @PathVariable String id,
132
+//                                        @ApiParam("更新内容") @RequestBody TaPerson taPerson) throws Exception{
133
+//
134
+//        TaPerson origin = iTaPersonService.getByPhone(taPerson.getPhone());
135
+//        if (null != origin && !id.equals(origin.getPersonId())) {
136
+//            return ResponseBean.error("手机号已存在, 请重新填写", ResponseBean.ERROR_UNAVAILABLE);
137
+//        }
138
+//
139
+//        origin = iTaPersonService.getById(id);
140
+//        if (null == origin) {
141
+//            return ResponseBean.error("人员信息校验失败, 请刷新重试", ResponseBean.ERROR_UNAVAILABLE);
142
+//        }
143
+//
144
+//        taPerson.setPersonId(id);
145
+//
146
+//        if (iTaPersonService.updateName(taPerson)){
147
+//            return ResponseBean.success(iTaPersonService.getById(id));
148
+//        }else {
149
+//            return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
150
+//        }
151
+//    }
152
+
153
+
78 154
     /**
79
-     * 根据id删除对象
155
+     * 抽奖
80 156
      * @param id  实体ID
81 157
      */
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);
158
+    @RequestMapping(value="/wx/taPerson/{id}/prize",method= RequestMethod.GET)
159
+    @ApiOperation(value="抽奖", notes = "抽奖", httpMethod = "GET", response = ResponseBean.class)
160
+    public ResponseBean getPrize(@ApiParam("人员ID") @PathVariable String id) throws Exception{
161
+        TaPerson taPerson = iTaPersonService.getById(id);
162
+
163
+        if (taPerson.getIsJoined() || taPerson.getIsWinning()) {
164
+            return ResponseBean.error("您已参与抽奖!", ResponseBean.ERROR_UNAVAILABLE);
89 165
         }
90
-    }
91 166
 
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{
102
-
103
-        if (iTaPersonService.updateById(taPerson)){
104
-            return ResponseBean.success(iTaPersonService.getById(id));
105
-        }else {
106
-            return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
167
+        try {
168
+            iTaPrizeService.drawLottery(taPerson);
169
+        } catch (Exception e) {
170
+            if (e.getMessage().equals("no-prize")) {
171
+                return ResponseBean.error("奖品已抽完", 9999);
172
+            }
173
+
174
+            throw e;
107 175
         }
108
-    }
109 176
 
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));
177
+        return ResponseBean.success(taPerson);
118 178
     }
119 179
 }

+ 70
- 57
src/main/java/com/yunzhi/drawlots/controller/TaPrizeController.java Zobrazit soubor

@@ -11,14 +11,11 @@ import io.swagger.annotations.ApiParam;
11 11
 import org.slf4j.Logger;
12 12
 import org.slf4j.LoggerFactory;
13 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;
14
+import org.springframework.web.bind.annotation.*;
19 15
 import com.yunzhi.drawlots.service.ITaPrizeService;
20 16
 import com.yunzhi.drawlots.entity.TaPrize;
21
-import org.springframework.web.bind.annotation.RestController;
17
+
18
+import java.util.List;
22 19
 
23 20
 /**
24 21
  * <p>
@@ -53,67 +50,83 @@ public class TaPrizeController extends BaseController {
53 50
 
54 51
         IPage<TaPrize> pg = new Page<>(pageNum, pageSize);
55 52
         QueryWrapper<TaPrize> queryWrapper = new QueryWrapper<>();
56
-        queryWrapper.orderByDesc("sort_no");
53
+        queryWrapper.orderByAsc("sort_no");
57 54
 
58 55
         IPage<TaPrize> result = iTaPrizeService.page(pg, queryWrapper);
59 56
         return ResponseBean.success(result);
60 57
     }
61 58
 
59
+
62 60
     /**
63
-     * 保存对象
64
-     * @param taPrize 实体对象
61
+     * 获取奖品列表
65 62
      * @return
66 63
      */
67
-    @RequestMapping(value="/taPrize",method= RequestMethod.POST)
68
-    @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
69
-    public ResponseBean taPrizeAdd(@ApiParam("保存内容") @RequestBody TaPrize taPrize) throws Exception{
70
-
71
-        if (iTaPrizeService.save(taPrize)){
72
-            return ResponseBean.success(taPrize);
73
-        }else {
74
-            return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
75
-        }
76
-    }
64
+    @RequestMapping(value="/wx/taPrize",method= RequestMethod.GET)
65
+    @ApiOperation(value="获取奖品列表", notes = "获取奖品列表", httpMethod = "GET", response = ResponseBean.class)
66
+    public ResponseBean getPrizeList() throws Exception{
77 67
 
78
-    /**
79
-     * 根据id删除对象
80
-     * @param id  实体ID
81
-     */
82
-    @RequestMapping(value="/taPrize/{id}", method= RequestMethod.DELETE)
83
-    @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
84
-    public ResponseBean taPrizeDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
85
-        if(iTaPrizeService.removeById(id)){
86
-            return ResponseBean.success("success");
87
-        }else {
88
-            return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
89
-        }
90
-    }
68
+        QueryWrapper<TaPrize> queryWrapper = new QueryWrapper<>();
69
+        queryWrapper.orderByAsc("sort_no");
91 70
 
92
-    /**
93
-     * 修改对象
94
-     * @param id  实体ID
95
-     * @param taPrize 实体对象
96
-     * @return
97
-     */
98
-    @RequestMapping(value="/taPrize/{id}",method= RequestMethod.PUT)
99
-    @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
100
-    public ResponseBean taPrizeUpdate(@ApiParam("对象ID") @PathVariable Integer id,
101
-                                        @ApiParam("更新内容") @RequestBody TaPrize taPrize) throws Exception{
102
-
103
-        if (iTaPrizeService.updateById(taPrize)){
104
-            return ResponseBean.success(iTaPrizeService.getById(id));
105
-        }else {
106
-            return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
107
-        }
71
+        List<TaPrize> result = iTaPrizeService.list(queryWrapper);
72
+        return ResponseBean.success(result);
108 73
     }
109 74
 
110
-    /**
111
-     * 根据id查询对象
112
-     * @param id  实体ID
113
-     */
114
-    @RequestMapping(value="/taPrize/{id}",method= RequestMethod.GET)
115
-    @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
116
-    public ResponseBean taPrizeGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
117
-        return ResponseBean.success(iTaPrizeService.getById(id));
118
-    }
75
+//    /**
76
+//     * 保存对象
77
+//     * @param taPrize 实体对象
78
+//     * @return
79
+//     */
80
+//    @RequestMapping(value="/taPrize",method= RequestMethod.POST)
81
+//    @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
82
+//    public ResponseBean taPrizeAdd(@ApiParam("保存内容") @RequestBody TaPrize taPrize) throws Exception{
83
+//
84
+//        if (iTaPrizeService.save(taPrize)){
85
+//            return ResponseBean.success(taPrize);
86
+//        } else {
87
+//            return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
88
+//        }
89
+//    }
90
+
91
+//    /**
92
+//     * 根据id删除对象
93
+//     * @param id  实体ID
94
+//     */
95
+//    @RequestMapping(value="/taPrize/{id}", method= RequestMethod.DELETE)
96
+//    @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
97
+//    public ResponseBean taPrizeDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
98
+//        if(iTaPrizeService.removeById(id)){
99
+//            return ResponseBean.success("success");
100
+//        }else {
101
+//            return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
102
+//        }
103
+//    }
104
+
105
+//    /**
106
+//     * 修改对象
107
+//     * @param id  实体ID
108
+//     * @param taPrize 实体对象
109
+//     * @return
110
+//     */
111
+//    @RequestMapping(value="/taPrize/{id}",method= RequestMethod.PUT)
112
+//    @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
113
+//    public ResponseBean taPrizeUpdate(@ApiParam("对象ID") @PathVariable Integer id,
114
+//                                        @ApiParam("更新内容") @RequestBody TaPrize taPrize) throws Exception{
115
+//
116
+//        if (iTaPrizeService.updateById(taPrize)){
117
+//            return ResponseBean.success(iTaPrizeService.getById(id));
118
+//        }else {
119
+//            return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
120
+//        }
121
+//    }
122
+
123
+//    /**
124
+//     * 根据id查询对象
125
+//     * @param id  实体ID
126
+//     */
127
+//    @RequestMapping(value="/taPrize/{id}",method= RequestMethod.GET)
128
+//    @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
129
+//    public ResponseBean taPrizeGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
130
+//        return ResponseBean.success(iTaPrizeService.getById(id));
131
+//    }
119 132
 }

+ 31
- 0
src/main/java/com/yunzhi/drawlots/entity/TaPerson.java Zobrazit soubor

@@ -1,9 +1,16 @@
1 1
 package com.yunzhi.drawlots.entity;
2 2
 
3
+import com.alibaba.excel.annotation.ExcelIgnore;
4
+import com.alibaba.excel.annotation.ExcelProperty;
5
+import com.alibaba.excel.annotation.write.style.ColumnWidth;
3 6
 import com.baomidou.mybatisplus.annotation.IdType;
4 7
 import java.time.LocalDateTime;
8
+
9
+import com.baomidou.mybatisplus.annotation.TableField;
5 10
 import com.baomidou.mybatisplus.annotation.TableId;
6 11
 import java.io.Serializable;
12
+
13
+import com.yunzhi.drawlots.common.excelConverter.LocalDateTimeConverter;
7 14
 import io.swagger.annotations.ApiModel;
8 15
 import io.swagger.annotations.ApiModelProperty;
9 16
 import lombok.Data;
@@ -26,31 +33,55 @@ public class TaPerson implements Serializable {
26 33
 
27 34
     private static final long serialVersionUID = 1L;
28 35
 
36
+    @ExcelIgnore
29 37
     @ApiModelProperty(value = "用户ID")
30 38
     @TableId(value = "person_id", type = IdType.UUID)
31 39
     private String personId;
32 40
 
41
+    @ExcelProperty(value = "姓名", index = 0)
42
+    @ColumnWidth(80)
33 43
     @ApiModelProperty(value = "用户名")
34 44
     private String name;
35 45
 
46
+    @ExcelIgnore
47
+    @ApiModelProperty(value = "头像")
48
+    private String avatar;
49
+
50
+    @ExcelIgnore
36 51
     @ApiModelProperty(value = "手机号")
37 52
     private String phone;
38 53
 
54
+    @ExcelIgnore
55
+    @ApiModelProperty(value = "openid")
56
+    private String openid;
57
+
58
+    @ExcelIgnore
39 59
     @ApiModelProperty(value = "创建时间")
40 60
     private LocalDateTime createDate;
41 61
 
62
+    @ExcelIgnore
42 63
     @ApiModelProperty(value = "是否参与")
43 64
     private Boolean isJoined;
44 65
 
66
+    @ExcelIgnore
45 67
     @ApiModelProperty(value = "参与时间")
46 68
     private LocalDateTime joinedDate;
47 69
 
70
+    @ExcelIgnore
48 71
     @ApiModelProperty(value = "是否中奖")
49 72
     private Boolean isWinning;
50 73
 
74
+    @ExcelIgnore
51 75
     @ApiModelProperty(value = "中奖ID")
52 76
     private String prizeId;
53 77
 
78
+    @ExcelProperty(value = "中奖时间", converter = LocalDateTimeConverter.class, index = 2)
79
+    @ColumnWidth(160)
54 80
     @ApiModelProperty(value = "中奖时间")
55 81
     private LocalDateTime prizeDate;
82
+
83
+    @ExcelProperty(value = "奖品", index = 1)
84
+    @ApiModelProperty("中奖名称")
85
+    @TableField(exist = false)
86
+    private String prizeName;
56 87
 }

+ 3
- 0
src/main/java/com/yunzhi/drawlots/entity/TaPrize.java Zobrazit soubor

@@ -35,6 +35,9 @@ public class TaPrize implements Serializable {
35 35
     @ApiModelProperty(value = "图片")
36 36
     private String thumb;
37 37
 
38
+    @ApiModelProperty(value = "图片2")
39
+    private String thumb2;
40
+
38 41
     @ApiModelProperty(value = "库存")
39 42
     private Integer totalNum;
40 43
 

+ 19
- 0
src/main/java/com/yunzhi/drawlots/exception/GlobalExceptionHandler.java Zobrazit soubor

@@ -0,0 +1,19 @@
1
+package com.yunzhi.drawlots.exception;
2
+
3
+import com.yunzhi.drawlots.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
+}

+ 48
- 0
src/main/java/com/yunzhi/drawlots/interceptor/PermissionInterceptor.java Zobrazit soubor

@@ -0,0 +1,48 @@
1
+package com.yunzhi.drawlots.interceptor;
2
+
3
+import com.yunzhi.drawlots.common.JWTUtils;
4
+import com.yunzhi.drawlots.common.ResponseBean;
5
+import com.yunzhi.drawlots.common.StringUtils;
6
+import lombok.extern.slf4j.Slf4j;
7
+import org.springframework.stereotype.Component;
8
+import org.springframework.web.servlet.HandlerInterceptor;
9
+
10
+import javax.servlet.http.HttpServletRequest;
11
+import javax.servlet.http.HttpServletResponse;
12
+import java.io.IOException;
13
+import java.nio.charset.StandardCharsets;
14
+import java.util.Map;
15
+
16
+
17
+@Slf4j
18
+@Component
19
+public class PermissionInterceptor implements HandlerInterceptor {
20
+
21
+    @Override
22
+    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj) throws Exception {
23
+//        log.info("Request URI: {}", request.getRequestURI());
24
+
25
+        // JWT
26
+        String jws = JWTUtils.getToken(request);
27
+        if (StringUtils.isEmpty(jws)) {
28
+            responseTokenError(response, "鉴权失败, 请先进行登录操作");
29
+            return false;
30
+        }
31
+
32
+        try {
33
+            Map<String, Object> tokenMap = JWTUtils.decode(jws);
34
+        } catch (Exception e) {
35
+            log.error("鉴权失败: {}", e.getMessage());
36
+            responseTokenError(response, "鉴权失败, 请重新登录");
37
+            return false;
38
+        }
39
+
40
+        return true;
41
+    }
42
+
43
+    private void responseTokenError(HttpServletResponse response, String error) throws IOException {
44
+        response.addHeader("Content-type", "application/json");
45
+        response.getOutputStream().write(
46
+                ResponseBean.error(error, ResponseBean.ERROR_AUTH_FAIL).toJSON().getBytes(StandardCharsets.UTF_8));
47
+    }
48
+}

+ 8
- 0
src/main/java/com/yunzhi/drawlots/mapper/TaPersonMapper.java Zobrazit soubor

@@ -1,8 +1,13 @@
1 1
 package com.yunzhi.drawlots.mapper;
2 2
 
3
+import com.baomidou.mybatisplus.core.metadata.IPage;
3 4
 import com.yunzhi.drawlots.entity.TaPerson;
4 5
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 6
 import org.apache.ibatis.annotations.Mapper;
7
+import org.apache.ibatis.annotations.Param;
8
+
9
+import java.time.LocalDateTime;
10
+import java.util.List;
6 11
 
7 12
 /**
8 13
  * <p>
@@ -15,4 +20,7 @@ import org.apache.ibatis.annotations.Mapper;
15 20
 @Mapper
16 21
 public interface TaPersonMapper extends BaseMapper<TaPerson> {
17 22
 
23
+    IPage<TaPerson> getPageBy(IPage<TaPerson> pg, @Param("start") LocalDateTime start, @Param("end")  LocalDateTime end);
24
+
25
+    List<TaPerson> getListBy(@Param("start") LocalDateTime start, @Param("end") LocalDateTime end);
18 26
 }

+ 13
- 0
src/main/java/com/yunzhi/drawlots/service/ITaPersonService.java Zobrazit soubor

@@ -1,8 +1,12 @@
1 1
 package com.yunzhi.drawlots.service;
2 2
 
3
+import com.baomidou.mybatisplus.core.metadata.IPage;
3 4
 import com.yunzhi.drawlots.entity.TaPerson;
4 5
 import com.baomidou.mybatisplus.extension.service.IService;
5 6
 
7
+import java.time.LocalDateTime;
8
+import java.util.List;
9
+
6 10
 /**
7 11
  * <p>
8 12
  * 用户表 服务类
@@ -13,4 +17,13 @@ import com.baomidou.mybatisplus.extension.service.IService;
13 17
  */
14 18
 public interface ITaPersonService extends IService<TaPerson> {
15 19
 
20
+    TaPerson getByOpenId(String openid);
21
+
22
+    boolean updateName(TaPerson taPerson);
23
+
24
+    TaPerson getByPhone(String phone);
25
+
26
+    IPage<TaPerson> getPageBy(IPage<TaPerson> pg, LocalDateTime start, LocalDateTime end);
27
+
28
+    List<TaPerson> getListBy(LocalDateTime start, LocalDateTime end);
16 29
 }

+ 53
- 0
src/main/java/com/yunzhi/drawlots/service/impl/TaPersonServiceImpl.java Zobrazit soubor

@@ -1,11 +1,17 @@
1 1
 package com.yunzhi.drawlots.service.impl;
2 2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
5
+import com.baomidou.mybatisplus.core.metadata.IPage;
3 6
 import com.yunzhi.drawlots.entity.TaPerson;
4 7
 import com.yunzhi.drawlots.mapper.TaPersonMapper;
5 8
 import com.yunzhi.drawlots.service.ITaPersonService;
6 9
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7 10
 import org.springframework.stereotype.Service;
8 11
 
12
+import java.time.LocalDateTime;
13
+import java.util.List;
14
+
9 15
 /**
10 16
  * <p>
11 17
  * 用户表 服务实现类
@@ -17,4 +23,51 @@ import org.springframework.stereotype.Service;
17 23
 @Service
18 24
 public class TaPersonServiceImpl extends ServiceImpl<TaPersonMapper, TaPerson> implements ITaPersonService {
19 25
 
26
+    @Override
27
+    public TaPerson getByOpenId(String openid) {
28
+
29
+        QueryWrapper<TaPerson> queryWrapper = new QueryWrapper<>();
30
+        queryWrapper.eq("openid", openid);
31
+        queryWrapper.last("limit 1");
32
+
33
+        TaPerson taPerson = getOne(queryWrapper);
34
+        if (null == taPerson) {
35
+            taPerson = new TaPerson();
36
+            taPerson.setOpenid(openid);
37
+            taPerson.setCreateDate(LocalDateTime.now());
38
+            save(taPerson);
39
+        }
40
+
41
+        return taPerson;
42
+    }
43
+
44
+    @Override
45
+    public boolean updateName(TaPerson taPerson) {
46
+        UpdateWrapper<TaPerson> updateWrapper = new UpdateWrapper<>();
47
+        updateWrapper.set("name", taPerson.getName());
48
+        updateWrapper.set("phone", taPerson.getPhone());
49
+        updateWrapper.eq("person_id", taPerson.getPersonId());
50
+
51
+        return update(updateWrapper);
52
+    }
53
+
54
+    @Override
55
+    public TaPerson getByPhone(String phone) {
56
+
57
+        QueryWrapper<TaPerson> queryWrapper = new QueryWrapper<>();
58
+        queryWrapper.eq("phone", phone);
59
+        queryWrapper.last("limit 1");
60
+
61
+        return getOne(queryWrapper);
62
+    }
63
+
64
+    @Override
65
+    public IPage<TaPerson> getPageBy(IPage<TaPerson> pg, LocalDateTime start, LocalDateTime end) {
66
+        return baseMapper.getPageBy(pg, start, end);
67
+    }
68
+
69
+    @Override
70
+    public List<TaPerson> getListBy(LocalDateTime start, LocalDateTime end) {
71
+        return baseMapper.getListBy(start, end);
72
+    }
20 73
 }

+ 1
- 1
src/main/java/com/yunzhi/drawlots/service/impl/TaPrizeServiceImpl.java Zobrazit soubor

@@ -43,7 +43,7 @@ public class TaPrizeServiceImpl extends ServiceImpl<TaPrizeMapper, TaPrize> impl
43 43
             try {
44 44
                 List<TaPrize> taPrizeList = baseMapper.getStock();
45 45
                 if (null == taPrizeList || taPrizeList.size() < 1) {
46
-                    return;
46
+                    throw new Exception("no-prize");
47 47
                 }
48 48
 
49 49
                 LocalDateTime now = LocalDateTime.now();

+ 16
- 0
src/main/java/com/yunzhi/drawlots/vo/LoginParam.java Zobrazit soubor

@@ -0,0 +1,16 @@
1
+package com.yunzhi.drawlots.vo;
2
+
3
+import io.swagger.annotations.ApiModel;
4
+import io.swagger.annotations.ApiModelProperty;
5
+import lombok.Data;
6
+
7
+@ApiModel(description = "登录参数")
8
+@Data
9
+public class LoginParam {
10
+
11
+    @ApiModelProperty("用户名")
12
+    String userName;
13
+
14
+    @ApiModelProperty("密码, MD5 加密后数据")
15
+    String password;
16
+}

+ 20
- 0
src/main/java/com/yunzhi/drawlots/vo/MPLogin.java Zobrazit soubor

@@ -0,0 +1,20 @@
1
+package com.yunzhi.drawlots.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 MPLogin {
11
+
12
+    @ApiModelProperty("OpenID")
13
+    String openid;
14
+
15
+    @ApiModelProperty("昵称")
16
+    String nickname;
17
+
18
+    @ApiModelProperty("头像")
19
+    String headImgUrl;
20
+}

+ 25
- 2
src/main/resources/application.yml Zobrazit soubor

@@ -1,6 +1,6 @@
1 1
 ###
2 2
 server:
3
-  port: 8080
3
+  port: 9000
4 4
   servlet:
5 5
     context-path: /api
6 6
 
@@ -11,7 +11,8 @@ spring:
11 11
       max-file-size: 10MB
12 12
       max-request-size: 50MB
13 13
   datasource:
14
-    url: jdbc:mysql://110.40.183.156:3306/hh_draw_lots?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true
14
+#    url: jdbc:mysql://110.40.183.156:3306/hh_draw_lots?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true
15
+    url: jdbc:mysql://rm-uf6z3z6jq11x653d77o.mysql.rds.aliyuncs.com:3306/hh_draw_lots?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true
15 16
     username: hh_draw_lots
16 17
     password: hh_draw_lots@ABC123
17 18
 
@@ -21,3 +22,25 @@ mybatis-plus:
21 22
     log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
22 23
     call-setters-on-nulls: true
23 24
   mapper-locations: classpath:mapper/**/*.xml
25
+
26
+
27
+###
28
+interceptor:
29
+  permission:
30
+    enable: true
31
+    include-paths: /**
32
+    exclude-paths:
33
+      - /admin/login
34
+      - /wx/login
35
+      - /wx/taPrize
36
+      - /swagger-ui/**
37
+      - /swagger-resources/**
38
+      - /v2/**
39
+
40
+# 业务
41
+biz:
42
+  admin:
43
+    # 账户名
44
+    account: admin
45
+    # 密码
46
+    password: 888888

+ 21
- 0
src/main/resources/mapper/TaPersonMapper.xml Zobrazit soubor

@@ -2,4 +2,25 @@
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.drawlots.mapper.TaPersonMapper">
4 4
 
5
+    <sql id="listSQL">
6
+        SELECT
7
+            t.*,
8
+            s.`name` AS prize_name
9
+        FROM
10
+            ta_person t
11
+            LEFT JOIN ta_prize s ON t.prize_id = s.prize_id
12
+        WHERE
13
+            1 = 1
14
+            <if test="start != null">AND t.create_date &gt;= #{start}</if>
15
+            <if test="end != null">AND t.create_date &lt;= #{end}</if>
16
+        ORDER BY
17
+            IFNULL(t.joined_date, t.create_date) DESC
18
+    </sql>
19
+
20
+    <select id="getPageBy" resultType="com.yunzhi.drawlots.entity.TaPerson">
21
+        <include refid="listSQL"></include>
22
+    </select>
23
+    <select id="getListBy" resultType="com.yunzhi.drawlots.entity.TaPerson">
24
+        <include refid="listSQL"></include>
25
+    </select>
5 26
 </mapper>