Browse Source
Merge branch 'milestone-20250723-wwl' into wuweili/feature-20250715095139-抽奖众筹
Merge branch 'milestone-20250723-wwl' into wuweili/feature-20250715095139-抽奖众筹
# Conflicts:修改 # lottery-system/lottery-service/src/main/java/com/lottery/config/CorsConfig.javafeature/0725lihuilin
19 changed files with 487 additions and 61 deletions
-
17lottery-system/lottery-common/src/main/java/com/lottery/exception/GlobalExceptionHandler.java
-
12lottery-system/lottery-pojo/src/main/java/com/lottery/dto/AdminLogin.java
-
29lottery-system/lottery-pojo/src/main/java/com/lottery/dto/UserByJwcodeDto.java
-
24lottery-system/lottery-pojo/src/main/java/com/lottery/dto/UserByJwcodePageDto.java
-
26lottery-system/lottery-pojo/src/main/java/com/lottery/entity/JwcodeTable.java
-
26lottery-system/lottery-pojo/src/main/java/com/lottery/vo/LoginUserVo.java
-
50lottery-system/lottery-service/src/main/java/com/lottery/admin/controller/AdminIsLoginController.java
-
26lottery-system/lottery-service/src/main/java/com/lottery/admin/mapper/AdminIsLoginMapper.java
-
27lottery-system/lottery-service/src/main/java/com/lottery/admin/service/AdminIsLoginService.java
-
79lottery-system/lottery-service/src/main/java/com/lottery/admin/service/Impl/AdminIsLoginServiceImpl.java
-
24lottery-system/lottery-service/src/main/java/com/lottery/admin/service/Impl/AdminUserServiceImpl.java
-
12lottery-system/lottery-service/src/main/java/com/lottery/api/controller/ApiFundingController.java
-
17lottery-system/lottery-service/src/main/java/com/lottery/api/service/Impl/ApiFundingServiceImpl.java
-
32lottery-system/lottery-service/src/main/java/com/lottery/config/CorsConfig.java
-
41lottery-system/lottery-service/src/main/java/com/lottery/config/WebConfig.java
-
74lottery-system/lottery-service/src/main/java/com/lottery/interceptor/AuthInterceptor.java
-
9lottery-system/lottery-service/src/main/resources/application.yml
-
21lottery-system/lottery-service/src/main/resources/mapper/admin/AdminIsLoginMapper.xml
-
0lottery-system/lottery-service/src/main/resources/mapper/api/AdminIsLoginMapper.xml
@ -0,0 +1,29 @@ |
|||||
|
package com.lottery.dto; |
||||
|
|
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Data; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
|
||||
|
import javax.validation.constraints.NotNull; |
||||
|
import javax.validation.constraints.Pattern; |
||||
|
import javax.validation.constraints.Size; |
||||
|
|
||||
|
/** |
||||
|
* @program: lottery-system |
||||
|
* @ClassName UserByJwcodeDto |
||||
|
* @description: |
||||
|
* @author:jihaipeng |
||||
|
* @create: 2025−07-22 11:51 |
||||
|
* @Version 1.0 |
||||
|
**/ |
||||
|
@Data |
||||
|
@AllArgsConstructor |
||||
|
@NoArgsConstructor |
||||
|
@Slf4j |
||||
|
public class UserByJwcodeDto { |
||||
|
@NotNull(message = "jwcode不能为空") |
||||
|
@Size(min = 8, max = 8, message = "jwcode必须是8位") |
||||
|
@Pattern(regexp = "^\\d{8}$", message = "jwcode必须全是数字") |
||||
|
private String jwcode; |
||||
|
} |
@ -0,0 +1,24 @@ |
|||||
|
package com.lottery.dto; |
||||
|
|
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Data; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
|
||||
|
/** |
||||
|
* @program: lottery-system |
||||
|
* @ClassName UserByJwcodePageDto |
||||
|
* @description: |
||||
|
* @author:jihaipeng |
||||
|
* @create: 2025−07-22 15:03 |
||||
|
* @Version 1.0 |
||||
|
**/ |
||||
|
@Data |
||||
|
@AllArgsConstructor |
||||
|
@NoArgsConstructor |
||||
|
@Slf4j |
||||
|
public class UserByJwcodePageDto { |
||||
|
private String jwcode; |
||||
|
private int pageNum = 1; |
||||
|
private int pageSize = 10; |
||||
|
} |
@ -0,0 +1,26 @@ |
|||||
|
package com.lottery.entity; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Data; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
|
||||
|
import java.time.LocalDate; |
||||
|
import java.time.LocalDateTime; |
||||
|
|
||||
|
/** |
||||
|
* @program: lottery-system |
||||
|
* @ClassName JwcodeTable |
||||
|
* @description: |
||||
|
* @author:jihaipeng |
||||
|
* @create: 2025−07-22 15:11 |
||||
|
* @Version 1.0 |
||||
|
**/ |
||||
|
@Data |
||||
|
@NoArgsConstructor |
||||
|
@AllArgsConstructor |
||||
|
@TableName("jwcode_table") |
||||
|
public class JwcodeTable { |
||||
|
private String jwcode; |
||||
|
private LocalDateTime createTime; |
||||
|
} |
@ -0,0 +1,26 @@ |
|||||
|
package com.lottery.vo; |
||||
|
|
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Data; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
|
||||
|
import java.time.LocalDate; |
||||
|
import java.time.LocalDateTime; |
||||
|
|
||||
|
/** |
||||
|
* @program: lottery-system |
||||
|
* @ClassName LoginUserVo |
||||
|
* @description: |
||||
|
* @author:jihaipeng |
||||
|
* @create: 2025−07-22 15:00 |
||||
|
* @Version 1.0 |
||||
|
**/ |
||||
|
@Data |
||||
|
@Slf4j |
||||
|
@NoArgsConstructor |
||||
|
@AllArgsConstructor |
||||
|
public class LoginUserVo { |
||||
|
private String jwcode; |
||||
|
private LocalDateTime createTime; |
||||
|
} |
@ -0,0 +1,50 @@ |
|||||
|
package com.lottery.admin.controller; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
|
import com.lottery.admin.service.AdminIsLoginService; |
||||
|
import com.lottery.dto.UserByJwcodeDto; |
||||
|
import com.lottery.dto.UserByJwcodePageDto; |
||||
|
import com.lottery.result.Result; |
||||
|
import com.lottery.vo.LoginUserVo; |
||||
|
import com.lottery.vo.PageInfo; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
import javax.validation.Valid; |
||||
|
|
||||
|
/** |
||||
|
* @program: lottery-system |
||||
|
* @ClassName LoginController |
||||
|
* @description: |
||||
|
* @author:jihaipeng |
||||
|
* @create: 2025−07-22 11:15 |
||||
|
* @Version 1.0 |
||||
|
**/ |
||||
|
@RestController |
||||
|
@RequestMapping("/admin/isLogin") |
||||
|
public class AdminIsLoginController { |
||||
|
|
||||
|
@Autowired |
||||
|
private AdminIsLoginService adminIsLoginService; |
||||
|
//添加精网号 |
||||
|
@RequestMapping("/addUser") |
||||
|
public Result<String> addUser(@RequestBody @Valid UserByJwcodeDto userDto) { |
||||
|
return adminIsLoginService.addUser(userDto.getJwcode()); |
||||
|
} |
||||
|
|
||||
|
//删除精网号 |
||||
|
@RequestMapping("/deleteUser") |
||||
|
public Result<String> deleteUser(@RequestBody @Valid UserByJwcodeDto userDto) { |
||||
|
return adminIsLoginService.deleteUser(userDto.getJwcode()); |
||||
|
} |
||||
|
|
||||
|
//分页返回数据 |
||||
|
@RequestMapping("/selectByJwcode") |
||||
|
public Result<PageInfo<LoginUserVo>> selectByJwcode(@RequestBody UserByJwcodePageDto userByJwcodePageDto) { |
||||
|
return adminIsLoginService.selectByJwcode(userByJwcodePageDto.getJwcode(), userByJwcodePageDto.getPageNum(), userByJwcodePageDto.getPageSize(),userByJwcodePageDto.getPageNum()); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,26 @@ |
|||||
|
package com.lottery.admin.mapper; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.lottery.entity.JwcodeTable; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
|
||||
|
import java.time.LocalDateTime; |
||||
|
|
||||
|
/** |
||||
|
* @program: lottery-system |
||||
|
* @ClassName AdminIsLoginMappper |
||||
|
* @description: |
||||
|
* @author:jihaipeng |
||||
|
* @create: 2025−07-22 14:09 |
||||
|
* @Version 1.0 |
||||
|
**/ |
||||
|
@Mapper |
||||
|
public interface AdminIsLoginMapper extends BaseMapper<JwcodeTable> { |
||||
|
|
||||
|
|
||||
|
void addUser(String jwcode, LocalDateTime now); |
||||
|
|
||||
|
Integer selectByJwcode(String jwcode); |
||||
|
|
||||
|
int deleteUser(String jwcode); |
||||
|
} |
@ -0,0 +1,27 @@ |
|||||
|
package com.lottery.admin.service; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
import com.lottery.entity.JwcodeTable; |
||||
|
import com.lottery.result.Result; |
||||
|
import com.lottery.vo.LoginUserVo; |
||||
|
import com.lottery.vo.PageInfo; |
||||
|
import org.apache.tomcat.Jar; |
||||
|
|
||||
|
/** |
||||
|
* @program: lottery-system |
||||
|
* @ClassName AdminIsLoginService |
||||
|
* @description: |
||||
|
* @author:jihaipeng |
||||
|
* @create: 2025−07-22 11:32 |
||||
|
* @Version 1.0 |
||||
|
**/ |
||||
|
|
||||
|
public interface AdminIsLoginService extends IService<JwcodeTable> { |
||||
|
Result<String> addUser(String jwcode); |
||||
|
|
||||
|
Result<String> deleteUser(String jwcode); |
||||
|
|
||||
|
|
||||
|
Result<PageInfo<LoginUserVo>> selectByJwcode(String jwcode, int pageNum, int pageSize, int pageNum1); |
||||
|
} |
@ -0,0 +1,79 @@ |
|||||
|
package com.lottery.admin.service.Impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
import com.lottery.admin.mapper.AdminIsLoginMapper; |
||||
|
import com.lottery.admin.service.AdminIsLoginService; |
||||
|
import com.lottery.entity.JwcodeTable; |
||||
|
import com.lottery.result.Result; |
||||
|
import com.lottery.utils.ConvertBeanUtil; |
||||
|
import com.lottery.vo.LoginUserVo; |
||||
|
import com.lottery.vo.PageInfo; |
||||
|
import org.springframework.beans.ConversionNotSupportedException; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.beans.factory.annotation.Qualifier; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.time.LocalDateTime; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @program: lottery-system |
||||
|
* @ClassName AdminIsLoginServiceImpl |
||||
|
* @description: |
||||
|
* @author:jihaipeng |
||||
|
* @create: 2025−07-22 11:36 |
||||
|
* @Version 1.0 |
||||
|
**/ |
||||
|
@Service |
||||
|
public class AdminIsLoginServiceImpl extends ServiceImpl<AdminIsLoginMapper, JwcodeTable> implements AdminIsLoginService { |
||||
|
|
||||
|
@Autowired |
||||
|
private AdminIsLoginMapper adminIsLoginMappper; |
||||
|
|
||||
|
@Override |
||||
|
public Result<String> addUser(String jwcode) { |
||||
|
Integer isLogin = adminIsLoginMappper.selectByJwcode(jwcode); |
||||
|
//检查一下是否已经添加过了 |
||||
|
if(isLogin != null && isLogin > 0){ |
||||
|
return Result.failure("该用户已经添加过了"); |
||||
|
} |
||||
|
LocalDateTime now = LocalDateTime.now(); |
||||
|
adminIsLoginMappper.addUser(jwcode,now); |
||||
|
return Result.success("添加成功"); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Result<String> deleteUser(String jwcode) { |
||||
|
|
||||
|
Long total = adminIsLoginMappper.selectCount(null); |
||||
|
|
||||
|
System.out.println(total); |
||||
|
if(total <= 1) { |
||||
|
return Result.failure("至少要保留一个用户"); |
||||
|
} |
||||
|
|
||||
|
int count = adminIsLoginMappper.deleteUser(jwcode); |
||||
|
|
||||
|
if(count > 0){ |
||||
|
return Result.success("删除成功"); |
||||
|
}else { |
||||
|
return Result.failure("删除失败,可能该用户不存在"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Result<PageInfo<LoginUserVo>> selectByJwcode(String jwcode, int pageNum, int pageSize, int pageNum1) { |
||||
|
Page<JwcodeTable> usePage = new Page<>(pageNum, pageSize); |
||||
|
LambdaQueryWrapper<JwcodeTable> jwcodeTableLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
if (jwcode != null){ |
||||
|
jwcodeTableLambdaQueryWrapper.like(JwcodeTable::getJwcode, jwcode); |
||||
|
} |
||||
|
Page<JwcodeTable> jwcodeTablePage = adminIsLoginMappper.selectPage(usePage, jwcodeTableLambdaQueryWrapper); |
||||
|
List<JwcodeTable> records = jwcodeTablePage.getRecords(); |
||||
|
List<LoginUserVo> loginUserVos = ConvertBeanUtil.convertList(records, LoginUserVo.class); |
||||
|
return Result.success(PageInfo.of(jwcodeTablePage, loginUserVos)); |
||||
|
} |
||||
|
} |
@ -1,32 +0,0 @@ |
|||||
package com.lottery.config; |
|
||||
|
|
||||
import org.springframework.context.annotation.Configuration; |
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry; |
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
|
||||
|
|
||||
/** |
|
||||
* @program: lottery |
|
||||
* @ClassName CorsConfig |
|
||||
* @description: |
|
||||
* @author: wwl |
|
||||
* @create: 2025-07-18 10:21 |
|
||||
* @Version 1.0 |
|
||||
**/ |
|
||||
|
|
||||
@Configuration |
|
||||
public class CorsConfig implements WebMvcConfigurer { |
|
||||
@Override |
|
||||
public void addCorsMappings(CorsRegistry registry) { |
|
||||
registry.addMapping("/**") |
|
||||
.allowedOrigins("*") // 允许所有来源 |
|
||||
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") |
|
||||
.allowedHeaders("*"); |
|
||||
|
|
||||
// registry.addMapping("/**") |
|
||||
// .allowedOriginPatterns("*") // 允许所有来源模式 |
|
||||
// .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") |
|
||||
// .allowedHeaders("*") |
|
||||
// .allowCredentials(true); // 允许携带凭证(如cookie、认证头) |
|
||||
|
|
||||
} |
|
||||
} |
|
@ -0,0 +1,41 @@ |
|||||
|
package com.lottery.config; |
||||
|
|
||||
|
import com.lottery.interceptor.AuthInterceptor; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.context.annotation.Configuration; |
||||
|
import org.springframework.web.servlet.config.annotation.CorsRegistry; |
||||
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
||||
|
|
||||
|
/** |
||||
|
* @program: lottery-system |
||||
|
* @ClassName WebConfig |
||||
|
* @description: |
||||
|
* @author:jihaipeng |
||||
|
* @create: 2025−07-22 16:46 |
||||
|
* @Version 1.0 |
||||
|
**/ |
||||
|
|
||||
|
@Configuration |
||||
|
public class WebConfig implements WebMvcConfigurer { |
||||
|
|
||||
|
@Autowired |
||||
|
private AuthInterceptor authInterceptor; |
||||
|
|
||||
|
@Override |
||||
|
public void addInterceptors(InterceptorRegistry registry) { |
||||
|
registry.addInterceptor(authInterceptor) |
||||
|
.addPathPatterns("/**") // 拦截所有请求 |
||||
|
.excludePathPatterns( // 放行不需要校验的路径 |
||||
|
"/login" // 登录接口 |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void addCorsMappings(CorsRegistry registry) { |
||||
|
registry.addMapping("/**") |
||||
|
.allowedOrigins("*") // 允许所有来源 |
||||
|
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") |
||||
|
.allowedHeaders("*"); |
||||
|
} |
||||
|
} |
@ -0,0 +1,74 @@ |
|||||
|
package com.lottery.interceptor; |
||||
|
|
||||
|
import com.lottery.exception.BusinessException; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.data.redis.core.StringRedisTemplate; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
import org.springframework.web.servlet.HandlerInterceptor; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletRequest; |
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
|
||||
|
/** |
||||
|
* @program: lottery-system |
||||
|
* @ClassName AuthInterceptor |
||||
|
* @description: |
||||
|
* @author:jihaipeng |
||||
|
* @create: 2025−07-22 16:19 |
||||
|
* @Version 1.0 |
||||
|
**/ |
||||
|
@Component |
||||
|
public class AuthInterceptor implements HandlerInterceptor { |
||||
|
|
||||
|
@Autowired |
||||
|
private StringRedisTemplate redisTemplate; |
||||
|
|
||||
|
@Override |
||||
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
||||
|
// 放行 OPTIONS 预检请求 |
||||
|
if ("OPTIONS".equals(request.getMethod())) { |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
// 1. 放行登录接口(/login) |
||||
|
if ("/admin/user/login".equals(request.getRequestURI())) { |
||||
|
return true; |
||||
|
} |
||||
|
if("/api/prize/list".equals(request.getRequestURI())) { |
||||
|
return true; |
||||
|
} |
||||
|
if("/api/user/list".equals(request.getRequestURI())) { |
||||
|
return true; |
||||
|
} |
||||
|
if("/admin/win/list".equals(request.getRequestURI())) { |
||||
|
return true; |
||||
|
} |
||||
|
if("/api/lottery/start".equals(request.getRequestURI())) { |
||||
|
return true; |
||||
|
} |
||||
|
if("/api/funding/addRecord".equals(request.getRequestURI())) { |
||||
|
return true; |
||||
|
} |
||||
|
if("/api/funding/getActivity".equals(request.getRequestURI())) { |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// 2. 检查其他接口是否携带 Token |
||||
|
String token = request.getHeader("Token"); |
||||
|
if (token == null || token.isEmpty()) { |
||||
|
|
||||
|
throw new BusinessException(400,"登录缺失凭证,请重新登录"); |
||||
|
} |
||||
|
|
||||
|
// 3. 校验 Token 是否在 Redis 中存在 |
||||
|
String redisKey = "token:" + token; |
||||
|
if (!Boolean.TRUE.equals(redisTemplate.hasKey(redisKey))) { |
||||
|
throw new BusinessException(400,"用户登录已失效,请重新登录"); |
||||
|
} |
||||
|
// 4. Token 校验通过,放行请求 |
||||
|
return true; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,21 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
|
<mapper namespace="com.lottery.admin.mapper.AdminIsLoginMapper"> |
||||
|
|
||||
|
|
||||
|
<insert id="addUser"> |
||||
|
INSERT INTO jwcode_table(jwcode,create_time) VALUES (#{jwcode},#{now}) |
||||
|
</insert> |
||||
|
<delete id="deleteUser" parameterType="java.lang.String"> |
||||
|
DELETE FROM jwcode_table WHERE jwcode = #{jwcode} |
||||
|
</delete> |
||||
|
<select id="selectByJwcode" resultType="java.lang.Integer" parameterType="java.lang.String"> |
||||
|
SELECT |
||||
|
count(*) |
||||
|
FROM |
||||
|
jwcode_table |
||||
|
WHERE |
||||
|
jwcode = #{jwcode} |
||||
|
</select> |
||||
|
|
||||
|
</mapper> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue