Merge branch 'preview' of https://gitea.qinmian.online/CY/mcwl-ai
commit
12b00c70ed
|
@ -55,12 +55,38 @@
|
||||||
<artifactId>mcwl-quartz</artifactId>
|
<artifactId>mcwl-quartz</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 我的邀请模块-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mcwl</groupId>
|
||||||
|
<artifactId>mcwl-myInvitation</artifactId>
|
||||||
|
<version>3.8.8</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mcwl</groupId>
|
||||||
|
<artifactId>mcwl-memberCenter</artifactId>
|
||||||
|
<version>3.8.8</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- 代码生成-->
|
<!-- 代码生成-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mcwl</groupId>
|
<groupId>com.mcwl</groupId>
|
||||||
<artifactId>mcwl-generator</artifactId>
|
<artifactId>mcwl-generator</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- rabbitmq依赖 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||||
|
<version>3.1.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.mcwl;
|
package com.mcwl;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.mcwl.web.controller.myInvitation;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController()
|
||||||
|
@RequestMapping("/consume")
|
||||||
|
public class ConsumeController {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.mcwl.web.controller.myInvitation;
|
||||||
|
|
||||||
|
|
||||||
|
import com.mcwl.common.annotation.Anonymous;
|
||||||
|
import com.mcwl.common.core.domain.AjaxResult;
|
||||||
|
import com.mcwl.common.utils.SecurityUtils;
|
||||||
|
import com.mcwl.myInvitation.domain.Invitation;
|
||||||
|
import com.mcwl.myInvitation.service.InvitationService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.mcwl.common.core.domain.AjaxResult.success;
|
||||||
|
|
||||||
|
@RestController()
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/invitation")
|
||||||
|
public class InvitationController {
|
||||||
|
|
||||||
|
private final InvitationService invitationService;
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/getInvitationCode")
|
||||||
|
public AjaxResult getInvitationCode() {
|
||||||
|
// 获取当前用户
|
||||||
|
Long userId = SecurityUtils.getUserId();
|
||||||
|
String invitationCode = invitationService.getInvitationCode(userId);
|
||||||
|
return success("操作成功", invitationCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/list")
|
||||||
|
public AjaxResult list() {
|
||||||
|
List<Invitation> list = invitationService.list();
|
||||||
|
return success(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/getById")
|
||||||
|
public AjaxResult getById(Long id) {
|
||||||
|
Invitation invitation = invitationService.getById(id);
|
||||||
|
return success(invitation);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.mcwl.web.controller.rabbitmq.config;
|
||||||
|
|
||||||
|
import com.mcwl.common.constant.QueueConstants;
|
||||||
|
import org.springframework.amqp.core.Queue;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化发送短信服雾队列
|
||||||
|
*
|
||||||
|
* @author DaiZibo
|
||||||
|
* @date 2024/12/30
|
||||||
|
* @apiNote
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class CodeMQConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Queue queue() {
|
||||||
|
return new Queue(QueueConstants.CODE_QUEUE, true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.mcwl.web.controller.rabbitmq.consumer;
|
||||||
|
|
||||||
|
import com.mcwl.common.constant.QueueConstants;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机号登录短信验证码消费者
|
||||||
|
* @author DaiZibo
|
||||||
|
* @date 2024/12/30
|
||||||
|
* @apiNote
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class CodeConsumer {
|
||||||
|
|
||||||
|
@RabbitListener(queues = QueueConstants.CODE_QUEUE)
|
||||||
|
public void code(String msg) {
|
||||||
|
|
||||||
|
log.info("消费者获取到的数据:{}", msg);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,18 +1,5 @@
|
||||||
package com.mcwl.web.controller.system;
|
package com.mcwl.web.controller.system;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import com.mcwl.common.annotation.Log;
|
import com.mcwl.common.annotation.Log;
|
||||||
import com.mcwl.common.constant.UserConstants;
|
import com.mcwl.common.constant.UserConstants;
|
||||||
import com.mcwl.common.core.controller.BaseController;
|
import com.mcwl.common.core.controller.BaseController;
|
||||||
|
@ -21,6 +8,13 @@ import com.mcwl.common.core.domain.entity.SysDept;
|
||||||
import com.mcwl.common.enums.BusinessType;
|
import com.mcwl.common.enums.BusinessType;
|
||||||
import com.mcwl.common.utils.StringUtils;
|
import com.mcwl.common.utils.StringUtils;
|
||||||
import com.mcwl.system.service.ISysDeptService;
|
import com.mcwl.system.service.ISysDeptService;
|
||||||
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 部门信息
|
* 部门信息
|
||||||
|
|
|
@ -1,29 +1,40 @@
|
||||||
package com.mcwl.web.controller.system;
|
package com.mcwl.web.controller.system;
|
||||||
|
|
||||||
import java.util.List;
|
import com.mcwl.common.annotation.Anonymous;
|
||||||
import java.util.Set;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import com.mcwl.common.constant.Constants;
|
import com.mcwl.common.constant.Constants;
|
||||||
|
import com.mcwl.common.constant.QueueConstants;
|
||||||
|
import com.mcwl.common.constant.RedisConstants;
|
||||||
import com.mcwl.common.core.domain.AjaxResult;
|
import com.mcwl.common.core.domain.AjaxResult;
|
||||||
import com.mcwl.common.core.domain.entity.SysMenu;
|
import com.mcwl.common.core.domain.entity.SysMenu;
|
||||||
import com.mcwl.common.core.domain.entity.SysUser;
|
import com.mcwl.common.core.domain.entity.SysUser;
|
||||||
import com.mcwl.common.core.domain.model.LoginBody;
|
import com.mcwl.common.core.domain.model.LoginBody;
|
||||||
import com.mcwl.common.core.domain.model.LoginUser;
|
import com.mcwl.common.core.domain.model.LoginUser;
|
||||||
|
import com.mcwl.common.core.domain.model.PhoneLoginBody;
|
||||||
|
import com.mcwl.common.core.redis.RedisCache;
|
||||||
|
import com.mcwl.common.utils.CodeUtils;
|
||||||
import com.mcwl.common.utils.SecurityUtils;
|
import com.mcwl.common.utils.SecurityUtils;
|
||||||
|
import com.mcwl.common.utils.StringUtils;
|
||||||
import com.mcwl.framework.web.service.SysLoginService;
|
import com.mcwl.framework.web.service.SysLoginService;
|
||||||
import com.mcwl.framework.web.service.SysPermissionService;
|
import com.mcwl.framework.web.service.SysPermissionService;
|
||||||
import com.mcwl.framework.web.service.TokenService;
|
import com.mcwl.framework.web.service.TokenService;
|
||||||
import com.mcwl.system.service.ISysMenuService;
|
import com.mcwl.system.service.ISysMenuService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录验证
|
* 登录验证
|
||||||
*
|
*
|
||||||
* @author mcwl
|
* @author mcwl
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
public class SysLoginController
|
public class SysLoginController
|
||||||
{
|
{
|
||||||
|
@ -39,6 +50,46 @@ public class SysLoginController
|
||||||
@Autowired
|
@Autowired
|
||||||
private TokenService tokenService;
|
private TokenService tokenService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisCache redisCache;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
|
|
||||||
|
@Anonymous
|
||||||
|
@GetMapping("/getCode")
|
||||||
|
public AjaxResult code(@RequestParam String phone){
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(phone)){
|
||||||
|
return AjaxResult.error("请输入手机号");
|
||||||
|
}
|
||||||
|
|
||||||
|
//校验验证码是否存在
|
||||||
|
if (redisCache.hasKey(RedisConstants.CODE_PHONE+phone)){
|
||||||
|
|
||||||
|
return AjaxResult.error("请勿重复发送");
|
||||||
|
}
|
||||||
|
|
||||||
|
//生成验证码
|
||||||
|
String s = CodeUtils.generateCaptcha();
|
||||||
|
|
||||||
|
log.info("获取到的验证码:{}",s);
|
||||||
|
//存储redis
|
||||||
|
redisCache.setCacheObject(RedisConstants.CODE_PHONE+phone,s,1, TimeUnit.MINUTES);
|
||||||
|
|
||||||
|
//发送短信服务
|
||||||
|
// 构建 sendDataMap
|
||||||
|
Map<String, String> sendDataMap = new HashMap<>();
|
||||||
|
sendDataMap.put("code:", s);
|
||||||
|
// TelSmsUtils.sendSms(phone,"SMS_460535072",sendDataMap);
|
||||||
|
|
||||||
|
rabbitTemplate.convertAndSend(QueueConstants.CODE_QUEUE,s);
|
||||||
|
|
||||||
|
return AjaxResult.success();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录方法
|
* 登录方法
|
||||||
*
|
*
|
||||||
|
@ -56,6 +107,20 @@ public class SysLoginController
|
||||||
return ajax;
|
return ajax;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/phoneLogin")
|
||||||
|
@Anonymous
|
||||||
|
public AjaxResult phoneLogin(@RequestBody PhoneLoginBody phoneLoginBody){
|
||||||
|
|
||||||
|
AjaxResult ajax = AjaxResult.success();
|
||||||
|
// 生成令牌
|
||||||
|
String token = loginService.phoneLogin(phoneLoginBody.getPhone(),phoneLoginBody.getCode());
|
||||||
|
ajax.put(Constants.TOKEN, token);
|
||||||
|
return ajax;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户信息
|
* 获取用户信息
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,21 +1,5 @@
|
||||||
package com.mcwl.web.controller.system;
|
package com.mcwl.web.controller.system;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
import com.mcwl.common.annotation.Log;
|
import com.mcwl.common.annotation.Log;
|
||||||
import com.mcwl.common.core.controller.BaseController;
|
import com.mcwl.common.core.controller.BaseController;
|
||||||
import com.mcwl.common.core.domain.AjaxResult;
|
import com.mcwl.common.core.domain.AjaxResult;
|
||||||
|
@ -31,6 +15,16 @@ import com.mcwl.system.service.ISysDeptService;
|
||||||
import com.mcwl.system.service.ISysPostService;
|
import com.mcwl.system.service.ISysPostService;
|
||||||
import com.mcwl.system.service.ISysRoleService;
|
import com.mcwl.system.service.ISysRoleService;
|
||||||
import com.mcwl.system.service.ISysUserService;
|
import com.mcwl.system.service.ISysUserService;
|
||||||
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户信息
|
* 用户信息
|
||||||
|
|
|
@ -0,0 +1,117 @@
|
||||||
|
package com.mcwl.web.controller.system;
|
||||||
|
|
||||||
|
import com.mcwl.common.annotation.Anonymous;
|
||||||
|
import com.mcwl.common.constant.CacheConstants;
|
||||||
|
import com.mcwl.common.core.domain.AjaxResult;
|
||||||
|
import com.mcwl.common.core.domain.entity.SysUser;
|
||||||
|
import com.mcwl.common.core.domain.model.LoginUser;
|
||||||
|
import com.mcwl.common.core.redis.RedisCache;
|
||||||
|
import com.mcwl.common.utils.uuid.IdUtils;
|
||||||
|
import com.mcwl.framework.web.service.SysPermissionService;
|
||||||
|
import com.mcwl.framework.web.service.TokenService;
|
||||||
|
import com.mcwl.system.domain.SysUserThirdAccount;
|
||||||
|
import com.mcwl.system.service.ISysUserThirdAccountService;
|
||||||
|
import com.mcwl.system.service.IWXService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对接微信扫码登录
|
||||||
|
*
|
||||||
|
* @author DaiZibo
|
||||||
|
* @date 2024/12/30
|
||||||
|
* @apiNote
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/wx")
|
||||||
|
public class WXController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisCache redisCache;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ISysUserThirdAccountService iSysUserThirdAccountService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IWXService iwxService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TokenService tokenService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SysPermissionService permissionService;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扫码登录用uuid生成
|
||||||
|
*/
|
||||||
|
@Anonymous
|
||||||
|
@GetMapping("/uuid/get")
|
||||||
|
public AjaxResult getUUID() throws IOException {
|
||||||
|
AjaxResult ajax = AjaxResult.success();
|
||||||
|
String uuid = IdUtils.simpleUUID();
|
||||||
|
String verifyKey = CacheConstants.WX_OPENID_KEY + uuid;
|
||||||
|
redisCache.setCacheObject(verifyKey, null, 1, TimeUnit.MINUTES);
|
||||||
|
ajax.put("uuid", uuid);
|
||||||
|
return ajax;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* uuid绑定openid
|
||||||
|
*/
|
||||||
|
@Anonymous
|
||||||
|
@GetMapping("/uuid/bind/openid")
|
||||||
|
public AjaxResult bindOpenid(@RequestParam("code") String code, @RequestParam("uuid") String uuid) throws IOException {
|
||||||
|
AjaxResult ajax = AjaxResult.success();
|
||||||
|
SysUserThirdAccount user = iwxService.getOpenid(code);
|
||||||
|
String openid = user.getOpenid();
|
||||||
|
String wxNickName = user.getOpenName();
|
||||||
|
String verifyKey = CacheConstants.WX_OPENID_KEY + uuid;
|
||||||
|
long expire = redisCache.getExpire(verifyKey);
|
||||||
|
redisCache.setCacheObject(verifyKey, openid);
|
||||||
|
if (expire > 0) {
|
||||||
|
redisCache.expire(verifyKey, expire, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
ajax.put("openid", openid);
|
||||||
|
ajax.put("wxNickName", wxNickName);
|
||||||
|
return ajax;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* uuid登录
|
||||||
|
*/
|
||||||
|
@Anonymous
|
||||||
|
@GetMapping("/uuid/login")
|
||||||
|
public AjaxResult loginByOpenId(@RequestParam("uuid") String uuid) throws IOException {
|
||||||
|
AjaxResult ajax = AjaxResult.success();
|
||||||
|
String verifyKey = CacheConstants.WX_OPENID_KEY + uuid;
|
||||||
|
String openid = redisCache.getCacheObject(verifyKey);
|
||||||
|
ajax.put("status", 0);
|
||||||
|
System.out.println("openid:{}" + openid);
|
||||||
|
if (openid != null) {
|
||||||
|
SysUser user = iSysUserThirdAccountService.selectUserByOpenId(openid);
|
||||||
|
System.out.println("用户:{}" + user);
|
||||||
|
if (user == null) {
|
||||||
|
System.out.println("用户不存在");
|
||||||
|
return AjaxResult.error("用户不存在");
|
||||||
|
}
|
||||||
|
LoginUser loginUser = new LoginUser(user.getUserId(), user.getDeptId(), user, permissionService.getMenuPermission(user));
|
||||||
|
// 生成token
|
||||||
|
String token = tokenService.createToken(loginUser);
|
||||||
|
ajax.put("token", token);
|
||||||
|
ajax.put("status", 1);
|
||||||
|
redisCache.deleteObject(verifyKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ajax;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,22 @@
|
||||||
# 数据源配置
|
# 数据源配置
|
||||||
spring:
|
spring:
|
||||||
|
#mq
|
||||||
|
rabbitmq:
|
||||||
|
host: 1.13.246.108
|
||||||
|
port: 5672
|
||||||
|
username: guest
|
||||||
|
password: guest
|
||||||
|
virtualHost: /
|
||||||
|
listener:
|
||||||
|
simple:
|
||||||
|
prefetch: 1 # 每次之能获取一条
|
||||||
|
acknowledge-mode: manual # 设置消费端手动ack确认
|
||||||
|
retry:
|
||||||
|
enabled: true # 是否支持重试
|
||||||
|
# 生产者配置
|
||||||
|
publisher-confirm-type: correlated #确认消息已发送到交换机(Exchange)
|
||||||
|
publisher-returns: true #确认消息已发送到队列(Queue)
|
||||||
|
|
||||||
datasource:
|
datasource:
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
driverClassName: com.mysql.cj.jdbc.Driver
|
driverClassName: com.mysql.cj.jdbc.Driver
|
||||||
|
@ -59,3 +76,11 @@ spring:
|
||||||
wall:
|
wall:
|
||||||
config:
|
config:
|
||||||
multi-statement-allow: true
|
multi-statement-allow: true
|
||||||
|
|
||||||
|
# 公众号配置
|
||||||
|
wechat:
|
||||||
|
# 应用ID
|
||||||
|
appid: wx82d4c3c96f0ffa5b
|
||||||
|
# 应用密钥
|
||||||
|
secret: abbabcf1da711a3bbd95387ec83edcac
|
||||||
|
|
||||||
|
|
|
@ -97,14 +97,51 @@ token:
|
||||||
# 令牌有效期(默认30分钟)
|
# 令牌有效期(默认30分钟)
|
||||||
expireTime: 30
|
expireTime: 30
|
||||||
|
|
||||||
# MyBatis配置
|
# MyBatis Plus配置
|
||||||
mybatis:
|
mybatis-plus:
|
||||||
# 搜索指定包别名
|
# 不支持多包, 如有需要可在注解配置 或 提升扫包等级
|
||||||
typeAliasesPackage: com.mcwl.**.domain
|
# 例如 com.**.**.mapper
|
||||||
# 配置mapper的扫描,找到所有的mapper.xml映射文件
|
mapperPackage: com.mcwl.**.mapper
|
||||||
|
# 对应的 XML 文件位置
|
||||||
mapperLocations: classpath*:mapper/**/*Mapper.xml
|
mapperLocations: classpath*:mapper/**/*Mapper.xml
|
||||||
# 加载全局的配置文件
|
# 实体扫描,多个package用逗号或者分号分隔
|
||||||
configLocation: classpath:mybatis/mybatis-config.xml
|
typeAliasesPackage: com.mcwl.**.domain
|
||||||
|
# 启动时是否检查 MyBatis XML 文件的存在,默认不检查
|
||||||
|
checkConfigLocation: false
|
||||||
|
configuration:
|
||||||
|
# 自动驼峰命名规则(camel case)映射
|
||||||
|
mapUnderscoreToCamelCase: true
|
||||||
|
# MyBatis 自动映射策略
|
||||||
|
# NONE:不启用 PARTIAL:只对非嵌套 resultMap 自动映射 FULL:对所有 resultMap 自动映射
|
||||||
|
autoMappingBehavior: PARTIAL
|
||||||
|
# MyBatis 自动映射时未知列或未知属性处理策
|
||||||
|
# NONE:不做处理 WARNING:打印相关警告 FAILING:抛出异常和详细信息
|
||||||
|
autoMappingUnknownColumnBehavior: NONE
|
||||||
|
# 更详细的日志输出 会有性能损耗 org.apache.ibatis.logging.stdout.StdOutImpl
|
||||||
|
# 关闭日志记录 (可单纯使用 p6spy 分析) org.apache.ibatis.logging.nologging.NoLoggingImpl
|
||||||
|
# 默认日志输出 org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||||
|
logImpl: org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||||
|
global-config:
|
||||||
|
# 是否打印 Logo banner
|
||||||
|
banner: false
|
||||||
|
dbConfig:
|
||||||
|
# 主键类型
|
||||||
|
# AUTO 自增 NONE 空 INPUT 用户输入 ASSIGN_ID 雪花 ASSIGN_UUID 唯一 UUID
|
||||||
|
idType: auto
|
||||||
|
logic-delete-field: del_flag
|
||||||
|
# 逻辑已删除值
|
||||||
|
logicDeleteValue: '2'
|
||||||
|
# 逻辑未删除值
|
||||||
|
logicNotDeleteValue: '0'
|
||||||
|
# 数据库字段下划线命名规则
|
||||||
|
table-underline: true
|
||||||
|
# 字段验证策略之 insert,在 insert 的时候的字段验证策略
|
||||||
|
# IGNORED 忽略 NOT_NULL 非NULL NOT_EMPTY 非空 DEFAULT 默认 NEVER 不加入 SQL
|
||||||
|
insertStrategy: NOT_NULL
|
||||||
|
# 字段验证策略之 update,在 update 的时候的字段验证策略
|
||||||
|
updateStrategy: NOT_NULL
|
||||||
|
# 字段验证策略之 select,在 select 的时候的字段验证策略既 wrapper 根据内部 entity 生成的 where 条件
|
||||||
|
where-strategy: NOT_NULL
|
||||||
|
|
||||||
# PageHelper分页插件
|
# PageHelper分页插件
|
||||||
pagehelper:
|
pagehelper:
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<!DOCTYPE configuration
|
|
||||||
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
|
|
||||||
"http://mybatis.org/dtd/mybatis-3-config.dtd">
|
|
||||||
<configuration>
|
|
||||||
<!-- 全局参数 -->
|
|
||||||
<settings>
|
|
||||||
<!-- 使全局的映射器启用或禁用缓存 -->
|
|
||||||
<setting name="cacheEnabled" value="true" />
|
|
||||||
<!-- 允许JDBC 支持自动生成主键 -->
|
|
||||||
<setting name="useGeneratedKeys" value="true" />
|
|
||||||
<!-- 配置默认的执行器.SIMPLE就是普通执行器;REUSE执行器会重用预处理语句(prepared statements);BATCH执行器将重用语句并执行批量更新 -->
|
|
||||||
<setting name="defaultExecutorType" value="SIMPLE" />
|
|
||||||
<!-- 指定 MyBatis 所用日志的具体实现 -->
|
|
||||||
<setting name="logImpl" value="SLF4J" />
|
|
||||||
<!-- 使用驼峰命名法转换字段 -->
|
|
||||||
<!-- <setting name="mapUnderscoreToCamelCase" value="true"/> -->
|
|
||||||
</settings>
|
|
||||||
|
|
||||||
</configuration>
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.mcwl.memberCenter;
|
||||||
|
|
||||||
|
import com.mcwl.McWlApplication;
|
||||||
|
import com.mcwl.memberCenter.service.MemberService;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest(classes = McWlApplication.class)
|
||||||
|
public class MemberTest {
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MemberService memberService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void memberServiceTest() {
|
||||||
|
System.out.println(memberService.list());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -63,7 +63,11 @@
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.qiniu</groupId>
|
||||||
|
<artifactId>qiniu-java-sdk</artifactId>
|
||||||
|
<version>7.4.0</version>
|
||||||
|
</dependency>
|
||||||
<!-- JSON工具类 -->
|
<!-- JSON工具类 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
@ -282,6 +286,20 @@
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 阿里大鱼 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.aliyun</groupId>
|
||||||
|
<artifactId>dysmsapi20170525</artifactId>
|
||||||
|
<version>2.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- mybatis-plus -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<version>3.5.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.mcwl.common.config;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 七牛云配置
|
||||||
|
*
|
||||||
|
* @date 2024/5/5 下午5:01
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@ConfigurationProperties(prefix = "oss.qiniu")
|
||||||
|
@Data
|
||||||
|
public class QiNiuConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AccessKey
|
||||||
|
*/
|
||||||
|
private String accessKey;
|
||||||
|
/**
|
||||||
|
* SecretKey
|
||||||
|
*/
|
||||||
|
private String secretKey;
|
||||||
|
/**
|
||||||
|
* 图片存储空间名
|
||||||
|
*/
|
||||||
|
private String bucketPictureName;
|
||||||
|
/**
|
||||||
|
* 图片外链
|
||||||
|
*/
|
||||||
|
private String domainPicture;
|
||||||
|
/**
|
||||||
|
* 文件存储空间名
|
||||||
|
*/
|
||||||
|
private String bucketFileName;
|
||||||
|
/**
|
||||||
|
* 文件外链
|
||||||
|
*/
|
||||||
|
private String domainFile;
|
||||||
|
}
|
|
@ -41,4 +41,11 @@ public class CacheConstants
|
||||||
* 登录账户密码错误次数 redis key
|
* 登录账户密码错误次数 redis key
|
||||||
*/
|
*/
|
||||||
public static final String PWD_ERR_CNT_KEY = "pwd_err_cnt:";
|
public static final String PWD_ERR_CNT_KEY = "pwd_err_cnt:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信openid redis key
|
||||||
|
*/
|
||||||
|
public static final String WX_OPENID_KEY = "wx_openid:";
|
||||||
|
|
||||||
|
public static final String WE_CHAT = "we_chat";
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.mcwl.common.constant;
|
||||||
|
|
||||||
|
public class JwtConstants {
|
||||||
|
/**
|
||||||
|
* 用户ID字段
|
||||||
|
*/
|
||||||
|
public static final String DETAILS_USER_ID = "user_id";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名字段
|
||||||
|
*/
|
||||||
|
public static final String DETAILS_USERNAME = "user_name";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户标识
|
||||||
|
*/
|
||||||
|
public static final String USER_KEY = "user_key";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 令牌秘钥
|
||||||
|
*/
|
||||||
|
public final static String SECRET = "abcdefghijklmnopqrstuvwxyz";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机
|
||||||
|
*/
|
||||||
|
public static final String USER_PHONE = "user_phone";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户token 的键的前缀
|
||||||
|
*/
|
||||||
|
public static final String LOGIN_TOKEN = "login_token:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* token过期时间 1h = 60 * 60 * 1000L
|
||||||
|
*/
|
||||||
|
public static final Long EXPIRATION = 60 * 60 * 1000L;
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.mcwl.common.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* rabbitmq队列常量
|
||||||
|
*
|
||||||
|
* @author DaiZibo
|
||||||
|
* @date 2024/12/30
|
||||||
|
* @apiNote
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class QueueConstants {
|
||||||
|
|
||||||
|
//发送手机号验证码短信的mq队列
|
||||||
|
public static final String CODE_QUEUE = "codeQueue";
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.mcwl.common.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* redis存储前缀常量
|
||||||
|
*
|
||||||
|
* @author DaiZibo
|
||||||
|
* @date 2024/12/28
|
||||||
|
* @apiNote
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class RedisConstants {
|
||||||
|
|
||||||
|
public static final String CODE_PHONE = "code_phone:";
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.mcwl.common.core.domain.model;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机号登录对象
|
||||||
|
*
|
||||||
|
* @author DaiZibo
|
||||||
|
* @date 2024/12/28
|
||||||
|
* @apiNote
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Data
|
||||||
|
public class PhoneLoginBody {
|
||||||
|
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.mcwl.common.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回值状态码
|
||||||
|
*
|
||||||
|
* @author DaiZibo
|
||||||
|
* @date 2024/12/30
|
||||||
|
* @apiNote
|
||||||
|
*/
|
||||||
|
|
||||||
|
public enum ResultCode {
|
||||||
|
|
||||||
|
SUCCESS(200),//成功
|
||||||
|
|
||||||
|
FAIL(400),//失败
|
||||||
|
|
||||||
|
FAIL_SIGN_IN(401),//登录失败
|
||||||
|
|
||||||
|
TOKEN_OVERDUE(402),//token过期
|
||||||
|
|
||||||
|
NOT_FOUND(404),//接口不存在
|
||||||
|
|
||||||
|
INTERNAL_SERVICE_ERROR(500);//服务器内部错误
|
||||||
|
|
||||||
|
private final Integer code;
|
||||||
|
|
||||||
|
ResultCode(Integer code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer code() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.mcwl.common.exception;
|
||||||
|
|
||||||
|
import com.mcwl.common.enums.ResultCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义异常类
|
||||||
|
* @author DaiZibo
|
||||||
|
* @date 2024/12/30
|
||||||
|
* @apiNote
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ErrorCodeException extends RuntimeException {
|
||||||
|
|
||||||
|
private Integer code;
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public ErrorCodeException(ResultCode resultCode, String msg) {
|
||||||
|
this.code = resultCode.getCode();
|
||||||
|
this.message = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCode(Integer code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
|
||||||
|
package com.mcwl.common.interfaces;
|
||||||
|
/**
|
||||||
|
* @author 苏三,该项目是知识星球:java突击队 的内部项目
|
||||||
|
* @date 2024/6/11 下午4:12
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import com.mcwl.common.valid.MaxMoneyConstraintValidator;
|
||||||
|
|
||||||
|
import javax.validation.Constraint;
|
||||||
|
import javax.validation.Payload;
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最大值约束.
|
||||||
|
*
|
||||||
|
* @author 苏三,该项目是知识星球:java突击队 的内部项目
|
||||||
|
* @date 2024/6/11 下午4:13
|
||||||
|
*/
|
||||||
|
@Target({ElementType.METHOD, ElementType.FIELD})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Constraint(validatedBy = MaxMoneyConstraintValidator.class)
|
||||||
|
public @interface MaxMoney {
|
||||||
|
/**
|
||||||
|
* message.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String message() default "{minMoney.message.error}";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* max value.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
double value() default 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* group.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Class<?>[] groups() default {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* payload.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Class<? extends Payload>[] payload() default {};
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.mcwl.common.interfaces;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @date 2024/6/11 下午4:12
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
import com.mcwl.common.valid.MinMoneyConstraintValidator;
|
||||||
|
|
||||||
|
import javax.validation.Constraint;
|
||||||
|
import javax.validation.Payload;
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最小值约束.
|
||||||
|
*
|
||||||
|
|
||||||
|
* @date 2024/6/11 下午4:13
|
||||||
|
*/
|
||||||
|
@Target({ElementType.METHOD, ElementType.FIELD})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Constraint(validatedBy = MinMoneyConstraintValidator.class)
|
||||||
|
public @interface MinMoney {
|
||||||
|
/**
|
||||||
|
* message.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String message() default "{minMoney.message.error}";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* min value.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
double value() default 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* group.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Class<?>[] groups() default {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* payload.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Class<? extends Payload>[] payload() default {};
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.mcwl.common.interfaces;
|
||||||
|
|
||||||
|
import com.mcwl.common.valid.PhoneValidator;
|
||||||
|
|
||||||
|
import javax.validation.Constraint;
|
||||||
|
import javax.validation.Payload;
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 苏三
|
||||||
|
* @date 2024/9/24 下午3:09
|
||||||
|
*/
|
||||||
|
@Documented
|
||||||
|
@Constraint(validatedBy = {PhoneValidator.class})
|
||||||
|
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface ValidPhone {
|
||||||
|
/**
|
||||||
|
* 返回信息
|
||||||
|
*/
|
||||||
|
String message() default "手机号码格式不正确";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分组
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Class<?>[] groups() default {};
|
||||||
|
|
||||||
|
Class<? extends Payload>[] payload() default {};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.mcwl.common.utils;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证码工具类
|
||||||
|
*
|
||||||
|
* @author DaiZibo
|
||||||
|
* @date 2024/12/28
|
||||||
|
* @apiNote
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class CodeUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成一个随机的4位数验证码
|
||||||
|
*
|
||||||
|
* @return 返回生成的验证码字符串
|
||||||
|
*/
|
||||||
|
public static String generateCaptcha() {
|
||||||
|
// 创建Random对象用于生成随机数
|
||||||
|
Random random = new Random();
|
||||||
|
// 生成1000到9999之间的随机整数(包括1000和9999)
|
||||||
|
int captcha = 1000 + random.nextInt(9000);
|
||||||
|
// 将整数转换为字符串并返回
|
||||||
|
return String.valueOf(captcha);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,114 @@
|
||||||
|
package com.mcwl.common.utils;
|
||||||
|
|
||||||
|
import com.mcwl.common.constant.JwtConstants;
|
||||||
|
import io.jsonwebtoken.Claims;
|
||||||
|
import io.jsonwebtoken.Jwts;
|
||||||
|
import io.jsonwebtoken.SignatureAlgorithm;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: Jwt工具类
|
||||||
|
* @author DongZl
|
||||||
|
*/
|
||||||
|
public class JwtUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 秘钥
|
||||||
|
*/
|
||||||
|
public static String secret = JwtConstants.SECRET;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从数据声明生成令牌
|
||||||
|
*
|
||||||
|
* @param claims 数据声明
|
||||||
|
* @return 令牌
|
||||||
|
*/
|
||||||
|
public static String createToken(Map<String, Object> claims){
|
||||||
|
String token = Jwts.builder()
|
||||||
|
.addClaims(claims)
|
||||||
|
.signWith(SignatureAlgorithm.HS512, secret)
|
||||||
|
.setExpiration(new Date(System.currentTimeMillis() + JwtConstants.EXPIRATION))
|
||||||
|
.compact();
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从令牌中获取数据声明
|
||||||
|
*
|
||||||
|
* @param token 令牌
|
||||||
|
* @return 数据声明
|
||||||
|
*/
|
||||||
|
public static Claims parseToken(String token){
|
||||||
|
return Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 根据令牌获取用户标识
|
||||||
|
*
|
||||||
|
* @param token 令牌
|
||||||
|
* @return 用户ID
|
||||||
|
*/
|
||||||
|
public static String getUserKey(String token){
|
||||||
|
Claims claims = parseToken(token);
|
||||||
|
return getValue(claims, JwtConstants.USER_KEY);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 根据令牌获取用户标识
|
||||||
|
*
|
||||||
|
* @param claims 身份信息
|
||||||
|
* @return 用户ID
|
||||||
|
*/
|
||||||
|
public static String getUserKey(Claims claims){
|
||||||
|
return getValue(claims, JwtConstants.USER_KEY);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 根据令牌获取用户ID
|
||||||
|
*
|
||||||
|
* @param token 令牌
|
||||||
|
* @return 用户ID
|
||||||
|
*/
|
||||||
|
public static String getUserId(String token){
|
||||||
|
Claims claims = parseToken(token);
|
||||||
|
return getValue(claims, JwtConstants.DETAILS_USER_ID);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 根据身份信息获取用户ID
|
||||||
|
*
|
||||||
|
* @param claims 身份信息
|
||||||
|
* @return 用户ID
|
||||||
|
*/
|
||||||
|
public static String getUserId(Claims claims){
|
||||||
|
return getValue(claims, JwtConstants.DETAILS_USER_ID);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 根据令牌获取用户名
|
||||||
|
*
|
||||||
|
* @param token 令牌
|
||||||
|
* @return 用户名
|
||||||
|
*/
|
||||||
|
public static String getUserName(String token){
|
||||||
|
Claims claims = parseToken(token);
|
||||||
|
return getValue(claims, JwtConstants.DETAILS_USERNAME);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 根据身份信息获取用户名
|
||||||
|
*
|
||||||
|
* @param claims 身份信息
|
||||||
|
* @return 用户名
|
||||||
|
*/
|
||||||
|
public static String getUserName(Claims claims){
|
||||||
|
return getValue(claims, JwtConstants.DETAILS_USERNAME);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 根据身份信息获取键值
|
||||||
|
*
|
||||||
|
* @param claims 身份信息
|
||||||
|
* @param key 键
|
||||||
|
* @return 值
|
||||||
|
*/
|
||||||
|
public static String getValue(Claims claims, String key){
|
||||||
|
Object obj = claims.get(key);
|
||||||
|
return obj == null ? "" : obj.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
package com.mcwl.common.utils;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单编号生成工具
|
||||||
|
*
|
||||||
|
* @date 2024/5/30 下午6:02
|
||||||
|
*/
|
||||||
|
public class OrderCodeUtil {
|
||||||
|
|
||||||
|
public static final int ORDER_CODE_LENGTH = 24;
|
||||||
|
private static final String ORDER_CODE_DATA_FORMAT = "yyyyMMddHHmmss";
|
||||||
|
private static final int ORDER_CODE_RANDOM_NUMBER = 10;
|
||||||
|
private static final int ORDER_CODE_RANDOM_LENGTH = 6;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成订单编号
|
||||||
|
*
|
||||||
|
* @return 订单编号
|
||||||
|
*/
|
||||||
|
public static String generateOrderCode() {
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat(ORDER_CODE_DATA_FORMAT);
|
||||||
|
String random = getRandom(ORDER_CODE_RANDOM_LENGTH);
|
||||||
|
Date date = new Date();
|
||||||
|
String time = dateFormat.format(date);
|
||||||
|
String code = "XS" + time + random;
|
||||||
|
while (code.length() < ORDER_CODE_LENGTH) {
|
||||||
|
code = code + 0;
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getRandom(int len) {
|
||||||
|
Random r = new Random();
|
||||||
|
StringBuilder rs = new StringBuilder();
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
rs.append(r.nextInt(ORDER_CODE_RANDOM_NUMBER));
|
||||||
|
}
|
||||||
|
return rs.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package com.mcwl.common.utils;
|
||||||
|
|
||||||
|
import com.qiniu.http.Response;
|
||||||
|
import com.qiniu.storage.Configuration;
|
||||||
|
import com.qiniu.storage.Region;
|
||||||
|
import com.qiniu.storage.UploadManager;
|
||||||
|
import com.qiniu.storage.model.DefaultPutRet;
|
||||||
|
import com.qiniu.util.Auth;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.mcwl.common.config.QiNiuConfig;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 七牛云上传工具
|
||||||
|
*
|
||||||
|
* @date 2024/5/5 下午5:02
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class QiNiuUtil {
|
||||||
|
public static final String IMAGE = "image";
|
||||||
|
public static final String FILE = "file";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private QiNiuConfig qiNiuConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将图片上传到七牛云
|
||||||
|
*/
|
||||||
|
public String upload(InputStream file, String fileType, String fileContextType) throws Exception {
|
||||||
|
Configuration cfg = new Configuration(Region.region2());
|
||||||
|
UploadManager uploadManager = new UploadManager(cfg);
|
||||||
|
Auth auth = Auth.create(qiNiuConfig.getAccessKey(), qiNiuConfig.getSecretKey());
|
||||||
|
String upToken = null;
|
||||||
|
String path = null;
|
||||||
|
if (fileType.equals(IMAGE)) {
|
||||||
|
upToken = auth.uploadToken(qiNiuConfig.getBucketPictureName());
|
||||||
|
path = qiNiuConfig.getDomainFile();
|
||||||
|
} else if (fileType.equals(FILE)) {
|
||||||
|
upToken = auth.uploadToken(qiNiuConfig.getBucketFileName());
|
||||||
|
path = qiNiuConfig.getDomainFile();
|
||||||
|
}
|
||||||
|
Response response = uploadManager.put(file, null, upToken, null, fileContextType);
|
||||||
|
DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
|
||||||
|
return path + putRet.key;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,87 @@
|
||||||
|
package com.mcwl.common.utils.uuid;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.aliyun.dysmsapi20170525.Client;
|
||||||
|
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
|
||||||
|
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
|
||||||
|
import com.aliyun.teaopenapi.models.Config;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信工具类
|
||||||
|
*/
|
||||||
|
@Log4j2
|
||||||
|
public class TelSmsUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 阿里云主账号AccessKey,accessKeySecret拥有所有API的访问权限
|
||||||
|
*/
|
||||||
|
private static String accessKeyId = "LTAIEVXszCmcd1T5";
|
||||||
|
private static String accessKeySecret = "2zHwciQXln8wExSEnkIYtRTSwLeRNd";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信访问域名
|
||||||
|
*/
|
||||||
|
private static String endpoint = "dysmsapi.aliyuncs.com";
|
||||||
|
/**
|
||||||
|
* 短信签名
|
||||||
|
*/
|
||||||
|
private static String signName = "帝宇";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例化短信对象
|
||||||
|
*/
|
||||||
|
private static Client client;
|
||||||
|
|
||||||
|
static {
|
||||||
|
log.info("初始化短信服务开始");
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
try {
|
||||||
|
client = initClient();
|
||||||
|
log.info("初始化短信成功:{}",signName);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
log.info("初始化短信服务结束:耗时:{}MS",(System.currentTimeMillis()-startTime));
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 初始化短信对象
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private static Client initClient() throws Exception{
|
||||||
|
Config config = new Config()
|
||||||
|
// 您的AccessKey ID
|
||||||
|
.setAccessKeyId(accessKeyId)
|
||||||
|
// 您的AccessKey Secret
|
||||||
|
.setAccessKeySecret(accessKeySecret);
|
||||||
|
// 访问的域名
|
||||||
|
config.endpoint = endpoint;
|
||||||
|
return new Client(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送单条短信
|
||||||
|
* @param tel
|
||||||
|
* @param templateCode SMS_153991546
|
||||||
|
* @param sendDataMap
|
||||||
|
*/
|
||||||
|
public static String sendSms(String tel , String templateCode , Map<String,String> sendDataMap){
|
||||||
|
SendSmsRequest sendSmsRequest = new SendSmsRequest()
|
||||||
|
.setPhoneNumbers(tel)
|
||||||
|
.setSignName(signName)
|
||||||
|
.setTemplateCode(templateCode)
|
||||||
|
.setTemplateParam(JSONObject.toJSONString(sendDataMap));
|
||||||
|
SendSmsResponse sendSmsResponse = null;
|
||||||
|
try {
|
||||||
|
log.info("发送短信验证码:消息内容是:【{}】", JSONObject.toJSONString(sendDataMap));
|
||||||
|
sendSmsResponse = client.sendSms(sendSmsRequest);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("短信发送异常,手机号:【{}】,短信内容:【{}】,异常信息:【{}】", tel, sendDataMap, e);
|
||||||
|
}
|
||||||
|
return JSONObject.toJSONString(sendSmsResponse.getBody());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.mcwl.common.valid;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import com.mcwl.common.interfaces.MaxMoney;
|
||||||
|
|
||||||
|
import javax.validation.ConstraintValidator;
|
||||||
|
import javax.validation.ConstraintValidatorContext;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最大金额校验
|
||||||
|
* @date 2024/6/11 下午4:13
|
||||||
|
*/
|
||||||
|
public class MaxMoneyConstraintValidator implements ConstraintValidator<MaxMoney, BigDecimal> {
|
||||||
|
|
||||||
|
private MaxMoney constraint;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize(MaxMoney constraint) {
|
||||||
|
this.constraint = constraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid(BigDecimal value, ConstraintValidatorContext context) {
|
||||||
|
return value != null && value.doubleValue() < constraint.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.mcwl.common.valid;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import com.mcwl.common.interfaces.MinMoney;
|
||||||
|
|
||||||
|
import javax.validation.ConstraintValidator;
|
||||||
|
import javax.validation.ConstraintValidatorContext;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最小金额校验
|
||||||
|
*
|
||||||
|
* @date 2024/6/11 下午4:13
|
||||||
|
*/
|
||||||
|
public class MinMoneyConstraintValidator implements ConstraintValidator<MinMoney, BigDecimal> {
|
||||||
|
|
||||||
|
private MinMoney constraint;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize(MinMoney constraint) {
|
||||||
|
this.constraint = constraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid(BigDecimal value, ConstraintValidatorContext context) {
|
||||||
|
return value != null && value.doubleValue() >= constraint.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.mcwl.common.valid;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import com.mcwl.common.interfaces.ValidPhone;
|
||||||
|
|
||||||
|
import javax.validation.ConstraintValidator;
|
||||||
|
import javax.validation.ConstraintValidatorContext;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机号校验
|
||||||
|
*
|
||||||
|
* @author 苏三
|
||||||
|
* @date 2024/9/24 下午3:12
|
||||||
|
*/
|
||||||
|
public class PhoneValidator implements ConstraintValidator<ValidPhone, String> {
|
||||||
|
private static final String PHONE_REGEX = "^1([38][0-9]|4[5-9]|5[0-3,5-9]|6[6]|7[0-8]|9[89])[0-9]{8}$";
|
||||||
|
private final Pattern pattern = Pattern.compile(PHONE_REGEX);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid(String value, ConstraintValidatorContext context) {
|
||||||
|
if (value == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return pattern.matcher(value).matches();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,132 +1,153 @@
|
||||||
package com.mcwl.framework.config;
|
//package com.mcwl.framework.config;
|
||||||
|
//
|
||||||
import java.io.IOException;
|
//import com.baomidou.mybatisplus.autoconfigure.SpringBootVFS;
|
||||||
import java.util.ArrayList;
|
//import org.apache.ibatis.io.VFS;
|
||||||
import java.util.Arrays;
|
//import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
import java.util.HashSet;
|
//import org.mybatis.spring.SqlSessionFactoryBean;
|
||||||
import java.util.List;
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import javax.sql.DataSource;
|
//import org.springframework.context.annotation.Bean;
|
||||||
import org.apache.ibatis.io.VFS;
|
//import org.springframework.context.annotation.Configuration;
|
||||||
import org.apache.ibatis.session.SqlSessionFactory;
|
//import org.springframework.core.env.Environment;
|
||||||
import org.mybatis.spring.SqlSessionFactoryBean;
|
//import org.springframework.core.io.DefaultResourceLoader;
|
||||||
import org.mybatis.spring.boot.autoconfigure.SpringBootVFS;
|
//import org.springframework.core.io.Resource;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||||
import org.springframework.context.annotation.Bean;
|
//import org.springframework.core.io.support.ResourcePatternResolver;
|
||||||
import org.springframework.context.annotation.Configuration;
|
//import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
|
||||||
import org.springframework.core.env.Environment;
|
//import org.springframework.core.type.classreading.MetadataReader;
|
||||||
import org.springframework.core.io.DefaultResourceLoader;
|
//import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||||
import org.springframework.core.io.Resource;
|
//import org.springframework.util.ClassUtils;
|
||||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
//import org.springframework.util.StringUtils;
|
||||||
import org.springframework.core.io.support.ResourcePatternResolver;
|
//
|
||||||
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
|
//import javax.sql.DataSource;
|
||||||
import org.springframework.core.type.classreading.MetadataReader;
|
//import java.io.IOException;
|
||||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
//import java.util.ArrayList;
|
||||||
import org.springframework.util.ClassUtils;
|
//import java.util.Arrays;
|
||||||
import com.mcwl.common.utils.StringUtils;
|
//import java.util.HashSet;
|
||||||
|
//import java.util.List;
|
||||||
/**
|
//
|
||||||
* Mybatis支持*匹配扫描包
|
///**
|
||||||
*
|
// * Mybatis支持*匹配扫描包
|
||||||
* @author mcwl
|
// *
|
||||||
*/
|
// * @author mcwl
|
||||||
@Configuration
|
// */
|
||||||
public class MyBatisConfig
|
//@Configuration
|
||||||
{
|
//public class MyBatisConfig
|
||||||
@Autowired
|
//{
|
||||||
private Environment env;
|
// @Autowired
|
||||||
|
// private Environment env;
|
||||||
static final String DEFAULT_RESOURCE_PATTERN = "**/*.class";
|
//
|
||||||
|
// static final String DEFAULT_RESOURCE_PATTERN = "**/*.class";
|
||||||
public static String setTypeAliasesPackage(String typeAliasesPackage)
|
//
|
||||||
{
|
// public static String setTypeAliasesPackage(String typeAliasesPackage)
|
||||||
ResourcePatternResolver resolver = (ResourcePatternResolver) new PathMatchingResourcePatternResolver();
|
// {
|
||||||
MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);
|
// ResourcePatternResolver resolver = (ResourcePatternResolver) new PathMatchingResourcePatternResolver();
|
||||||
List<String> allResult = new ArrayList<String>();
|
// MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);
|
||||||
try
|
// List<String> allResult = new ArrayList<String>();
|
||||||
{
|
// try
|
||||||
for (String aliasesPackage : typeAliasesPackage.split(","))
|
// {
|
||||||
{
|
// for (String aliasesPackage : typeAliasesPackage.split(","))
|
||||||
List<String> result = new ArrayList<String>();
|
// {
|
||||||
aliasesPackage = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
|
// List<String> result = new ArrayList<String>();
|
||||||
+ ClassUtils.convertClassNameToResourcePath(aliasesPackage.trim()) + "/" + DEFAULT_RESOURCE_PATTERN;
|
// aliasesPackage = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
|
||||||
Resource[] resources = resolver.getResources(aliasesPackage);
|
// + ClassUtils.convertClassNameToResourcePath(aliasesPackage.trim()) + "/" + DEFAULT_RESOURCE_PATTERN;
|
||||||
if (resources != null && resources.length > 0)
|
// Resource[] resources = resolver.getResources(aliasesPackage);
|
||||||
{
|
// if (resources != null && resources.length > 0)
|
||||||
MetadataReader metadataReader = null;
|
// {
|
||||||
for (Resource resource : resources)
|
// MetadataReader metadataReader = null;
|
||||||
{
|
// for (Resource resource : resources)
|
||||||
if (resource.isReadable())
|
// {
|
||||||
{
|
// if (resource.isReadable())
|
||||||
metadataReader = metadataReaderFactory.getMetadataReader(resource);
|
// {
|
||||||
try
|
// metadataReader = metadataReaderFactory.getMetadataReader(resource);
|
||||||
{
|
// try
|
||||||
result.add(Class.forName(metadataReader.getClassMetadata().getClassName()).getPackage().getName());
|
// {
|
||||||
}
|
// result.add(Class.forName(metadataReader.getClassMetadata().getClassName()).getPackage().getName());
|
||||||
catch (ClassNotFoundException e)
|
// }
|
||||||
{
|
// catch (ClassNotFoundException e)
|
||||||
e.printStackTrace();
|
// {
|
||||||
}
|
// e.printStackTrace();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if (result.size() > 0)
|
// }
|
||||||
{
|
// if (result.size() > 0)
|
||||||
HashSet<String> hashResult = new HashSet<String>(result);
|
// {
|
||||||
allResult.addAll(hashResult);
|
// HashSet<String> hashResult = new HashSet<String>(result);
|
||||||
}
|
// allResult.addAll(hashResult);
|
||||||
}
|
// }
|
||||||
if (allResult.size() > 0)
|
// }
|
||||||
{
|
// if (allResult.size() > 0)
|
||||||
typeAliasesPackage = String.join(",", (String[]) allResult.toArray(new String[0]));
|
// {
|
||||||
}
|
// typeAliasesPackage = String.join(",", (String[]) allResult.toArray(new String[0]));
|
||||||
else
|
// }
|
||||||
{
|
// else
|
||||||
throw new RuntimeException("mybatis typeAliasesPackage 路径扫描错误,参数typeAliasesPackage:" + typeAliasesPackage + "未找到任何包");
|
// {
|
||||||
}
|
// throw new RuntimeException("mybatis typeAliasesPackage 路径扫描错误,参数typeAliasesPackage:" + typeAliasesPackage + "未找到任何包");
|
||||||
}
|
// }
|
||||||
catch (IOException e)
|
// }
|
||||||
{
|
// catch (IOException e)
|
||||||
e.printStackTrace();
|
// {
|
||||||
}
|
// e.printStackTrace();
|
||||||
return typeAliasesPackage;
|
// }
|
||||||
}
|
// return typeAliasesPackage;
|
||||||
|
// }
|
||||||
public Resource[] resolveMapperLocations(String[] mapperLocations)
|
//
|
||||||
{
|
// public Resource[] resolveMapperLocations(String[] mapperLocations)
|
||||||
ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
|
// {
|
||||||
List<Resource> resources = new ArrayList<Resource>();
|
// ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
|
||||||
if (mapperLocations != null)
|
// List<Resource> resources = new ArrayList<Resource>();
|
||||||
{
|
// if (mapperLocations != null)
|
||||||
for (String mapperLocation : mapperLocations)
|
// {
|
||||||
{
|
// for (String mapperLocation : mapperLocations)
|
||||||
try
|
// {
|
||||||
{
|
// try
|
||||||
Resource[] mappers = resourceResolver.getResources(mapperLocation);
|
// {
|
||||||
resources.addAll(Arrays.asList(mappers));
|
// Resource[] mappers = resourceResolver.getResources(mapperLocation);
|
||||||
}
|
// resources.addAll(Arrays.asList(mappers));
|
||||||
catch (IOException e)
|
// }
|
||||||
{
|
// catch (IOException e)
|
||||||
// ignore
|
// {
|
||||||
}
|
// // ignore
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return resources.toArray(new Resource[resources.size()]);
|
// }
|
||||||
}
|
// return resources.toArray(new Resource[resources.size()]);
|
||||||
|
// }
|
||||||
@Bean
|
//
|
||||||
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception
|
// @Bean
|
||||||
{
|
// public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception
|
||||||
String typeAliasesPackage = env.getProperty("mybatis.typeAliasesPackage");
|
// {
|
||||||
String mapperLocations = env.getProperty("mybatis.mapperLocations");
|
// String typeAliasesPackage = env.getProperty("mybatis.typeAliasesPackage");
|
||||||
String configLocation = env.getProperty("mybatis.configLocation");
|
// String mapperLocations = env.getProperty("mybatis.mapperLocations");
|
||||||
typeAliasesPackage = setTypeAliasesPackage(typeAliasesPackage);
|
// String configLocation = env.getProperty("mybatis.configLocation");
|
||||||
VFS.addImplClass(SpringBootVFS.class);
|
// typeAliasesPackage = setTypeAliasesPackage(typeAliasesPackage);
|
||||||
|
// VFS.addImplClass(SpringBootVFS.class);
|
||||||
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
|
//
|
||||||
sessionFactory.setDataSource(dataSource);
|
// final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
|
||||||
sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
|
// sessionFactory.setDataSource(dataSource);
|
||||||
sessionFactory.setMapperLocations(resolveMapperLocations(StringUtils.split(mapperLocations, ",")));
|
// sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
|
||||||
sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation));
|
// sessionFactory.setMapperLocations(resolveMapperLocations(StringUtils.split(mapperLocations, ",")));
|
||||||
return sessionFactory.getObject();
|
// sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation));
|
||||||
}
|
// return sessionFactory.getObject();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//// @Bean
|
||||||
|
//// public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception
|
||||||
|
//// {
|
||||||
|
//// String typeAliasesPackage = env.getProperty("mybatis.typeAliasesPackage");
|
||||||
|
//// String mapperLocations = env.getProperty("mybatis.mapperLocations");
|
||||||
|
//// String configLocation = env.getProperty("mybatis.configLocation");
|
||||||
|
//// typeAliasesPackage = setTypeAliasesPackage(typeAliasesPackage);
|
||||||
|
//// VFS.addImplClass(SpringBootVFS.class);
|
||||||
|
////
|
||||||
|
//// //final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
|
||||||
|
//// // SqlSessionFactoryBean 替换为 ⬇ MybatisSqlSessionFactoryBean
|
||||||
|
//// final MybatisSqlSessionFactoryBean sessionFactory = new MybatisSqlSessionFactoryBean();
|
||||||
|
//// sessionFactory.setDataSource(dataSource);
|
||||||
|
//// sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
|
||||||
|
//// sessionFactory.setMapperLocations(resolveMapperLocations(StringUtils.split(mapperLocations, ",")));
|
||||||
|
//// sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation));
|
||||||
|
//// return sessionFactory.getObject();
|
||||||
|
//// }
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
package com.mcwl.framework.config;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.DbType;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MybatisPlus
|
||||||
|
* @author DaiZibo
|
||||||
|
* @date 2024/12/31
|
||||||
|
* @apiNote
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@EnableTransactionManagement(proxyTargetClass = true)
|
||||||
|
@Configuration
|
||||||
|
public class MybatisPlusConfig {
|
||||||
|
@Bean
|
||||||
|
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||||
|
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||||
|
// 分页插件
|
||||||
|
interceptor.addInnerInterceptor(paginationInnerInterceptor());
|
||||||
|
// 乐观锁插件
|
||||||
|
interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor());
|
||||||
|
// 阻断插件
|
||||||
|
interceptor.addInnerInterceptor(blockAttackInnerInterceptor());
|
||||||
|
return interceptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页插件,自动识别数据库类型 https://baomidou.com/guide/interceptor-pagination.html
|
||||||
|
*/
|
||||||
|
public PaginationInnerInterceptor paginationInnerInterceptor() {
|
||||||
|
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
|
||||||
|
// 设置数据库类型为mysql
|
||||||
|
paginationInnerInterceptor.setDbType(DbType.MYSQL);
|
||||||
|
// 设置最大单页限制数量,默认 500 条,-1 不受限制
|
||||||
|
paginationInnerInterceptor.setMaxLimit(-1L);
|
||||||
|
return paginationInnerInterceptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 乐观锁插件 https://baomidou.com/guide/interceptor-optimistic-locker.html
|
||||||
|
*/
|
||||||
|
public OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor() {
|
||||||
|
return new OptimisticLockerInnerInterceptor();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 如果是对全表的删除或更新操作,就会终止该操作 https://baomidou.com/guide/interceptor-block-attack.html
|
||||||
|
*/
|
||||||
|
public BlockAttackInnerInterceptor blockAttackInnerInterceptor() {
|
||||||
|
return new BlockAttackInnerInterceptor();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,11 @@
|
||||||
package com.mcwl.framework.config;
|
package com.mcwl.framework.config;
|
||||||
|
|
||||||
|
import com.mcwl.framework.config.properties.PermitAllUrlProperties;
|
||||||
|
import com.mcwl.framework.security.core.OtherUserDetailsService;
|
||||||
|
import com.mcwl.framework.security.filter.JwtAuthenticationTokenFilter;
|
||||||
|
import com.mcwl.framework.security.handle.AuthenticationEntryPointImpl;
|
||||||
|
import com.mcwl.framework.security.handle.LogoutSuccessHandlerImpl;
|
||||||
|
import com.mcwl.framework.security.sms.SmsCodeByEmailAuthenticationProvider;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
@ -16,10 +22,6 @@ import org.springframework.security.web.SecurityFilterChain;
|
||||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||||
import org.springframework.security.web.authentication.logout.LogoutFilter;
|
import org.springframework.security.web.authentication.logout.LogoutFilter;
|
||||||
import org.springframework.web.filter.CorsFilter;
|
import org.springframework.web.filter.CorsFilter;
|
||||||
import com.mcwl.framework.config.properties.PermitAllUrlProperties;
|
|
||||||
import com.mcwl.framework.security.filter.JwtAuthenticationTokenFilter;
|
|
||||||
import com.mcwl.framework.security.handle.AuthenticationEntryPointImpl;
|
|
||||||
import com.mcwl.framework.security.handle.LogoutSuccessHandlerImpl;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* spring security配置
|
* spring security配置
|
||||||
|
@ -36,6 +38,13 @@ public class SecurityConfig
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserDetailsService userDetailsService;
|
private UserDetailsService userDetailsService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义用户(手机号验证码)认证逻辑
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
private OtherUserDetailsService userDetailsServiceByPhone;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 认证失败处理类
|
* 认证失败处理类
|
||||||
*/
|
*/
|
||||||
|
@ -78,6 +87,15 @@ public class SecurityConfig
|
||||||
return new ProviderManager(daoAuthenticationProvider);
|
return new ProviderManager(daoAuthenticationProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public AuthenticationManager authenticationManagerPhone() {
|
||||||
|
SmsCodeByEmailAuthenticationProvider daoAuthenticationProvider = new SmsCodeByEmailAuthenticationProvider();
|
||||||
|
daoAuthenticationProvider.setUserDetailsService(userDetailsServiceByPhone);
|
||||||
|
return new ProviderManager(daoAuthenticationProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* anyRequest | 匹配所有请求路径
|
* anyRequest | 匹配所有请求路径
|
||||||
* access | SpringEl表达式结果为true时可以访问
|
* access | SpringEl表达式结果为true时可以访问
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.mcwl.framework.security.core;
|
||||||
|
|
||||||
|
import com.mcwl.framework.security.core.otherUserdetails.OtherLoginNotFoundException;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DaiZibo
|
||||||
|
* @date 2024/12/30
|
||||||
|
* @apiNote
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface OtherUserDetailsService {
|
||||||
|
|
||||||
|
UserDetails otherLoadUser(String o, int num) throws OtherLoginNotFoundException;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.mcwl.framework.security.core.otherUserdetails;
|
||||||
|
|
||||||
|
import org.springframework.security.core.AuthenticationException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DaiZibo
|
||||||
|
* @date 2024/12/30
|
||||||
|
* @apiNote
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
public class OtherLoginNotFoundException extends AuthenticationException {
|
||||||
|
public OtherLoginNotFoundException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OtherLoginNotFoundException(String msg, Throwable cause) {
|
||||||
|
super(msg, cause);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,74 @@
|
||||||
|
package com.mcwl.framework.security.sms;
|
||||||
|
|
||||||
|
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
||||||
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
|
|
||||||
|
import javax.security.auth.Subject;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信登录 AuthenticationToken,模仿 UsernamePasswordAuthenticationToken 实现
|
||||||
|
*
|
||||||
|
* @author DaiZibo
|
||||||
|
* @date 2024/12/30
|
||||||
|
* @apiNote
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class SmsCodeAuthenticationToken extends AbstractAuthenticationToken {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 550L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在 UsernamePasswordAuthenticationToken 中该字段代表登录的用户名,
|
||||||
|
* 在这里就代表登录的手机号码或邮箱
|
||||||
|
*/
|
||||||
|
private final Object principal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建一个没有鉴权的 SmsCodeAuthenticationToken
|
||||||
|
*/
|
||||||
|
public SmsCodeAuthenticationToken(Object principal) {
|
||||||
|
super(null);
|
||||||
|
this.principal = principal;
|
||||||
|
setAuthenticated(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建拥有鉴权的 SmsCodeAuthenticationToken
|
||||||
|
*/
|
||||||
|
public SmsCodeAuthenticationToken(Object principal, Collection<? extends GrantedAuthority> authorities) {
|
||||||
|
super(authorities);
|
||||||
|
this.principal = principal;
|
||||||
|
super.setAuthenticated(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getCredentials() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getPrincipal() {
|
||||||
|
return this.principal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
|
||||||
|
if (isAuthenticated) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
|
||||||
|
}
|
||||||
|
|
||||||
|
super.setAuthenticated(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void eraseCredentials() {
|
||||||
|
super.eraseCredentials();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean implies(Subject subject) {
|
||||||
|
return super.implies(subject);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package com.mcwl.framework.security.sms;
|
||||||
|
|
||||||
|
import com.mcwl.framework.security.core.OtherUserDetailsService;
|
||||||
|
import org.springframework.security.authentication.AuthenticationProvider;
|
||||||
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
import org.springframework.security.core.AuthenticationException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DaiZibo
|
||||||
|
* @date 2024/12/30
|
||||||
|
* @apiNote
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
public class SmsCodeByEmailAuthenticationProvider implements AuthenticationProvider {
|
||||||
|
private OtherUserDetailsService userDetailsService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
|
||||||
|
SmsCodeAuthenticationToken authenticationToken = (SmsCodeAuthenticationToken) authentication;
|
||||||
|
|
||||||
|
String email = (String) authenticationToken.getPrincipal();
|
||||||
|
UserDetails userDetails = userDetailsService.otherLoadUser(email, 1);
|
||||||
|
|
||||||
|
// 此时鉴权成功后,应当重新 new 一个拥有鉴权的 authenticationResult 返回
|
||||||
|
SmsCodeAuthenticationToken authenticationResult = new SmsCodeAuthenticationToken(userDetails, userDetails.getAuthorities());
|
||||||
|
authenticationResult.setDetails(authenticationToken.getDetails());
|
||||||
|
|
||||||
|
return authenticationResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supports(Class<?> authentication) {
|
||||||
|
// 判断 authentication 是不是 SmsCodeAuthenticationToken 的子类或子接口
|
||||||
|
return SmsCodeAuthenticationToken.class.isAssignableFrom(authentication);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OtherUserDetailsService getUserDetailsService() {
|
||||||
|
return userDetailsService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserDetailsService(OtherUserDetailsService userDetailsService) {
|
||||||
|
this.userDetailsService = userDetailsService;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,13 @@
|
||||||
package com.mcwl.framework.web.exception;
|
package com.mcwl.framework.web.exception;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import com.mcwl.common.constant.HttpStatus;
|
||||||
|
import com.mcwl.common.core.domain.AjaxResult;
|
||||||
|
import com.mcwl.common.core.text.Convert;
|
||||||
|
import com.mcwl.common.exception.DemoModeException;
|
||||||
|
import com.mcwl.common.exception.ErrorCodeException;
|
||||||
|
import com.mcwl.common.exception.ServiceException;
|
||||||
|
import com.mcwl.common.utils.StringUtils;
|
||||||
|
import com.mcwl.common.utils.html.EscapeUtil;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.security.access.AccessDeniedException;
|
import org.springframework.security.access.AccessDeniedException;
|
||||||
|
@ -11,13 +18,8 @@ import org.springframework.web.bind.MissingPathVariableException;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
|
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
|
||||||
import com.mcwl.common.constant.HttpStatus;
|
|
||||||
import com.mcwl.common.core.domain.AjaxResult;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import com.mcwl.common.core.text.Convert;
|
|
||||||
import com.mcwl.common.exception.DemoModeException;
|
|
||||||
import com.mcwl.common.exception.ServiceException;
|
|
||||||
import com.mcwl.common.utils.StringUtils;
|
|
||||||
import com.mcwl.common.utils.html.EscapeUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局异常处理器
|
* 全局异常处理器
|
||||||
|
@ -29,6 +31,21 @@ public class GlobalExceptionHandler
|
||||||
{
|
{
|
||||||
private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
|
private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 仿照业务异常——自定义异常抛出
|
||||||
|
*/
|
||||||
|
@ExceptionHandler(ErrorCodeException.class)
|
||||||
|
public AjaxResult UserDefinedException(ErrorCodeException e){
|
||||||
|
System.out.println("StringUtils.isNull(e.getCode()):"+StringUtils.isNull(e.getCode()));
|
||||||
|
if (StringUtils.isNull(e.getCode()))
|
||||||
|
{
|
||||||
|
return AjaxResult.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return AjaxResult.error(e.getCode(), e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 权限校验异常
|
* 权限校验异常
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
package com.mcwl.framework.web.service;
|
package com.mcwl.framework.web.service;
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
import com.mcwl.common.constant.Constants;
|
import com.mcwl.common.constant.Constants;
|
||||||
import com.mcwl.common.core.domain.entity.SysRole;
|
import com.mcwl.common.core.domain.entity.SysRole;
|
||||||
import com.mcwl.common.core.domain.model.LoginUser;
|
import com.mcwl.common.core.domain.model.LoginUser;
|
||||||
import com.mcwl.common.utils.SecurityUtils;
|
import com.mcwl.common.utils.SecurityUtils;
|
||||||
import com.mcwl.common.utils.StringUtils;
|
import com.mcwl.common.utils.StringUtils;
|
||||||
import com.mcwl.framework.security.context.PermissionContextHolder;
|
import com.mcwl.framework.security.context.PermissionContextHolder;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* McWl首创 自定义权限实现,ss取自SpringSecurity首字母
|
* McWl首创 自定义权限实现,ss取自SpringSecurity首字母
|
||||||
|
|
|
@ -1,24 +1,16 @@
|
||||||
package com.mcwl.framework.web.service;
|
package com.mcwl.framework.web.service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
|
||||||
import org.springframework.security.authentication.BadCredentialsException;
|
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
||||||
import org.springframework.security.core.Authentication;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import com.mcwl.common.constant.CacheConstants;
|
import com.mcwl.common.constant.CacheConstants;
|
||||||
import com.mcwl.common.constant.Constants;
|
import com.mcwl.common.constant.Constants;
|
||||||
|
import com.mcwl.common.constant.RedisConstants;
|
||||||
import com.mcwl.common.constant.UserConstants;
|
import com.mcwl.common.constant.UserConstants;
|
||||||
import com.mcwl.common.core.domain.entity.SysUser;
|
import com.mcwl.common.core.domain.entity.SysUser;
|
||||||
import com.mcwl.common.core.domain.model.LoginUser;
|
import com.mcwl.common.core.domain.model.LoginUser;
|
||||||
import com.mcwl.common.core.redis.RedisCache;
|
import com.mcwl.common.core.redis.RedisCache;
|
||||||
|
import com.mcwl.common.enums.ResultCode;
|
||||||
|
import com.mcwl.common.exception.ErrorCodeException;
|
||||||
import com.mcwl.common.exception.ServiceException;
|
import com.mcwl.common.exception.ServiceException;
|
||||||
import com.mcwl.common.exception.user.BlackListException;
|
import com.mcwl.common.exception.user.*;
|
||||||
import com.mcwl.common.exception.user.CaptchaException;
|
|
||||||
import com.mcwl.common.exception.user.CaptchaExpireException;
|
|
||||||
import com.mcwl.common.exception.user.UserNotExistsException;
|
|
||||||
import com.mcwl.common.exception.user.UserPasswordNotMatchException;
|
|
||||||
import com.mcwl.common.utils.DateUtils;
|
import com.mcwl.common.utils.DateUtils;
|
||||||
import com.mcwl.common.utils.MessageUtils;
|
import com.mcwl.common.utils.MessageUtils;
|
||||||
import com.mcwl.common.utils.StringUtils;
|
import com.mcwl.common.utils.StringUtils;
|
||||||
|
@ -26,8 +18,17 @@ import com.mcwl.common.utils.ip.IpUtils;
|
||||||
import com.mcwl.framework.manager.AsyncManager;
|
import com.mcwl.framework.manager.AsyncManager;
|
||||||
import com.mcwl.framework.manager.factory.AsyncFactory;
|
import com.mcwl.framework.manager.factory.AsyncFactory;
|
||||||
import com.mcwl.framework.security.context.AuthenticationContextHolder;
|
import com.mcwl.framework.security.context.AuthenticationContextHolder;
|
||||||
|
import com.mcwl.framework.security.sms.SmsCodeAuthenticationToken;
|
||||||
import com.mcwl.system.service.ISysConfigService;
|
import com.mcwl.system.service.ISysConfigService;
|
||||||
import com.mcwl.system.service.ISysUserService;
|
import com.mcwl.system.service.ISysUserService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
|
import org.springframework.security.authentication.BadCredentialsException;
|
||||||
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录校验方法
|
* 登录校验方法
|
||||||
|
@ -37,12 +38,19 @@ import com.mcwl.system.service.ISysUserService;
|
||||||
@Component
|
@Component
|
||||||
public class SysLoginService
|
public class SysLoginService
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserDetailsServiceImpl userDetailsService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TokenService tokenService;
|
private TokenService tokenService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private AuthenticationManager authenticationManager;
|
private AuthenticationManager authenticationManager;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AuthenticationManager authenticationManagerPhone;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisCache redisCache;
|
private RedisCache redisCache;
|
||||||
|
|
||||||
|
@ -178,4 +186,81 @@ public class SysLoginService
|
||||||
sysUser.setLoginDate(DateUtils.getNowDate());
|
sysUser.setLoginDate(DateUtils.getNowDate());
|
||||||
userService.updateUserProfile(sysUser);
|
userService.updateUserProfile(sysUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String phoneLogin(String phone, String code) {
|
||||||
|
|
||||||
|
//校验验证码
|
||||||
|
validateCaptcha(phone, code);
|
||||||
|
|
||||||
|
//根据手机号查询数据
|
||||||
|
SysUser sysUser = userService.selectUserByPhone(phone);
|
||||||
|
if (sysUser == null){
|
||||||
|
throw new UserNotExistsException();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 登录前置校验
|
||||||
|
otherLoginPreCheck(sysUser.getUserName());
|
||||||
|
|
||||||
|
// 用户验证
|
||||||
|
Authentication authentication;
|
||||||
|
try {
|
||||||
|
SmsCodeAuthenticationToken smsCodeAuthenticationToken = new SmsCodeAuthenticationToken(sysUser.getPhonenumber());
|
||||||
|
System.out.println(smsCodeAuthenticationToken);
|
||||||
|
AuthenticationContextHolder.setContext(smsCodeAuthenticationToken);
|
||||||
|
authentication = authenticationManagerPhone.authenticate(smsCodeAuthenticationToken);
|
||||||
|
}
|
||||||
|
// SmsCodeAuthenticationToken [Principal=admin, Credentials=[PROTECTED], Authenticated=false, Details=null, Granted Authorities=[]]
|
||||||
|
catch (Exception e) {
|
||||||
|
if (e instanceof BadCredentialsException) {
|
||||||
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(sysUser.getUserName(), Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
|
||||||
|
throw new UserPasswordNotMatchException();
|
||||||
|
} else {
|
||||||
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(sysUser.getUserName(), Constants.LOGIN_FAIL, e.getMessage()));
|
||||||
|
throw new ServiceException(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
AuthenticationContextHolder.clearContext();
|
||||||
|
}
|
||||||
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(sysUser.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
|
||||||
|
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
||||||
|
return tokenService.createToken(loginUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateCaptcha(String phone, String code) {
|
||||||
|
//校验验证码
|
||||||
|
Object cacheObject = redisCache.getCacheObject(RedisConstants.CODE_PHONE + phone);
|
||||||
|
System.out.println("验证码:"+cacheObject);
|
||||||
|
if (cacheObject == null) {
|
||||||
|
// 处理未找到验证码的情况
|
||||||
|
throw new ErrorCodeException(ResultCode.FAIL,"验证码已过期或未发送");
|
||||||
|
}
|
||||||
|
|
||||||
|
String c = (String) cacheObject;
|
||||||
|
if (!c.equals(code)){
|
||||||
|
//验证码错误
|
||||||
|
throw new ErrorCodeException(ResultCode.FAIL,"验证码错误");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void otherLoginPreCheck(String username) {
|
||||||
|
// 用户名为空 错误
|
||||||
|
if (StringUtils.isEmpty(username)) {
|
||||||
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("not.null")));
|
||||||
|
throw new UserNotExistsException();
|
||||||
|
}
|
||||||
|
// 用户名不在指定范围内 错误
|
||||||
|
if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
||||||
|
|| username.length() > UserConstants.USERNAME_MAX_LENGTH) {
|
||||||
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
|
||||||
|
throw new UserPasswordNotMatchException();
|
||||||
|
}
|
||||||
|
// IP黑名单校验
|
||||||
|
String blackStr = configService.selectConfigByKey("sys.login.blackIPList");
|
||||||
|
if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr())) {
|
||||||
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("login.blocked")));
|
||||||
|
throw new BlackListException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
package com.mcwl.framework.web.service;
|
package com.mcwl.framework.web.service;
|
||||||
|
|
||||||
|
import com.mcwl.common.core.domain.entity.SysUser;
|
||||||
|
import com.mcwl.common.core.domain.model.LoginUser;
|
||||||
|
import com.mcwl.common.enums.UserStatus;
|
||||||
|
import com.mcwl.common.exception.ServiceException;
|
||||||
|
import com.mcwl.common.utils.MessageUtils;
|
||||||
|
import com.mcwl.common.utils.StringUtils;
|
||||||
|
import com.mcwl.framework.security.core.OtherUserDetailsService;
|
||||||
|
import com.mcwl.system.service.ISysUserService;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -7,13 +15,6 @@ import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.mcwl.common.core.domain.entity.SysUser;
|
|
||||||
import com.mcwl.common.core.domain.model.LoginUser;
|
|
||||||
import com.mcwl.common.enums.UserStatus;
|
|
||||||
import com.mcwl.common.exception.ServiceException;
|
|
||||||
import com.mcwl.common.utils.MessageUtils;
|
|
||||||
import com.mcwl.common.utils.StringUtils;
|
|
||||||
import com.mcwl.system.service.ISysUserService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户验证处理
|
* 用户验证处理
|
||||||
|
@ -21,10 +22,12 @@ import com.mcwl.system.service.ISysUserService;
|
||||||
* @author mcwl
|
* @author mcwl
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class UserDetailsServiceImpl implements UserDetailsService
|
public class UserDetailsServiceImpl implements UserDetailsService, OtherUserDetailsService {
|
||||||
{
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(UserDetailsServiceImpl.class);
|
private static final Logger log = LoggerFactory.getLogger(UserDetailsServiceImpl.class);
|
||||||
|
|
||||||
|
private int num = 0;
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysUserService userService;
|
private ISysUserService userService;
|
||||||
|
|
||||||
|
@ -35,32 +38,41 @@ public class UserDetailsServiceImpl implements UserDetailsService
|
||||||
private SysPermissionService permissionService;
|
private SysPermissionService permissionService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException
|
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||||
{
|
SysUser user = null;
|
||||||
SysUser user = userService.selectUserByUserName(username);
|
if (num == 0 ){
|
||||||
if (StringUtils.isNull(user))
|
user = userService.selectUserByUserName(username);
|
||||||
{
|
}else {
|
||||||
|
user = userService.selectUserByPhone(username);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNull(user)) {
|
||||||
log.info("登录用户:{} 不存在.", username);
|
log.info("登录用户:{} 不存在.", username);
|
||||||
throw new ServiceException(MessageUtils.message("user.not.exists"));
|
throw new ServiceException(MessageUtils.message("user.not.exists"));
|
||||||
}
|
} else if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
|
||||||
else if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
|
|
||||||
{
|
|
||||||
log.info("登录用户:{} 已被删除.", username);
|
log.info("登录用户:{} 已被删除.", username);
|
||||||
throw new ServiceException(MessageUtils.message("user.password.delete"));
|
throw new ServiceException(MessageUtils.message("user.password.delete"));
|
||||||
}
|
} else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
|
||||||
else if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
|
|
||||||
{
|
|
||||||
log.info("登录用户:{} 已被停用.", username);
|
log.info("登录用户:{} 已被停用.", username);
|
||||||
throw new ServiceException(MessageUtils.message("user.blocked"));
|
throw new ServiceException(MessageUtils.message("user.blocked"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// passwordService.validate(user);
|
||||||
|
if (num == 0) {
|
||||||
passwordService.validate(user);
|
passwordService.validate(user);
|
||||||
|
}
|
||||||
|
num = 0;
|
||||||
|
|
||||||
return createLoginUser(user);
|
return createLoginUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserDetails createLoginUser(SysUser user)
|
public UserDetails createLoginUser(SysUser user) {
|
||||||
{
|
|
||||||
return new LoginUser(user.getUserId(), user.getDeptId(), user, permissionService.getMenuPermission(user));
|
return new LoginUser(user.getUserId(), user.getDeptId(), user, permissionService.getMenuPermission(user));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserDetails otherLoadUser(String username, int num) throws UsernameNotFoundException {
|
||||||
|
this.num = num;
|
||||||
|
return loadUserByUsername(username);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.mcwl</groupId>
|
||||||
|
<artifactId>mcwl</artifactId>
|
||||||
|
<version>3.8.8</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>mcwl-memberCenter</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<mybatis-plus.version>3.5.2</mybatis-plus.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- 通用工具-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mcwl</groupId>
|
||||||
|
<artifactId>mcwl-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<version>${mybatis-plus.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.mcwl.memberCenter.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.mcwl.common.core.domain.BaseEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("mem_member")
|
||||||
|
public class Member extends BaseEntity {
|
||||||
|
|
||||||
|
@TableId
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
// 会员类型
|
||||||
|
private String member_type;
|
||||||
|
|
||||||
|
// 会员名称
|
||||||
|
private String member_name;
|
||||||
|
|
||||||
|
// 会员价格
|
||||||
|
private Double unit_price;
|
||||||
|
|
||||||
|
// 会员原价
|
||||||
|
private Double original_price;
|
||||||
|
|
||||||
|
// 删除标志(0代表存在 2代表删除)
|
||||||
|
private String delFlag;
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
package com.mcwl.memberCenter.domain;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.EnumValue;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.mcwl.common.core.domain.BaseEntity;
|
||||||
|
import com.mcwl.memberCenter.enums.MemberMenu;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("mem_member")
|
||||||
|
public class UserMember extends BaseEntity {
|
||||||
|
|
||||||
|
@TableId
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
// 用户ID
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
// 会员ID
|
||||||
|
private Long memberId;
|
||||||
|
|
||||||
|
// 会员开始时间
|
||||||
|
private Date startDate;
|
||||||
|
|
||||||
|
// 会员结束时间
|
||||||
|
private Date endDate;
|
||||||
|
|
||||||
|
// 会员积分
|
||||||
|
private Integer points;
|
||||||
|
|
||||||
|
// 订阅状态 active(活跃)、inactive(非活跃)、pending(待支付)和expired(过期)
|
||||||
|
@EnumValue
|
||||||
|
private MemberMenu subscriptionStatus;
|
||||||
|
|
||||||
|
// 支付方式
|
||||||
|
private String paymentMethod;
|
||||||
|
|
||||||
|
// 上次支付时间
|
||||||
|
private Date lastPaymentDate;
|
||||||
|
|
||||||
|
// 下次计费时间
|
||||||
|
private Date nextBillingDate;
|
||||||
|
|
||||||
|
// 上次登录时间
|
||||||
|
private Date lastLoginDate;
|
||||||
|
|
||||||
|
// 状态(0:正常 1:禁用)
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
// 删除标志(0代表存在 2代表删除)
|
||||||
|
private String delFlag;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.mcwl.memberCenter.enums;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum MemberMenu {
|
||||||
|
MEMBER_CENTER_ACTIVE("active", "活跃"),
|
||||||
|
MEMBER_CENTER_INACTIVE("inactive", "非活跃"),
|
||||||
|
MEMBER_CENTER_PENDING("pending", "待支付"),
|
||||||
|
MEMBER_CENTER_EXPIRED("expired", "过期");
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
private final String value;
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.mcwl.memberCenter.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.mcwl.memberCenter.domain.Member;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
//@Mapper
|
||||||
|
public interface MemberMapper extends BaseMapper<Member> {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.mcwl.memberCenter.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.mcwl.memberCenter.domain.UserMember;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
//@Mapper
|
||||||
|
public interface UserMemberMapper extends BaseMapper<UserMember> {
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.mcwl.memberCenter.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.mcwl.memberCenter.domain.Member;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface MemberService extends IService<Member> {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.mcwl.memberCenter.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.mcwl.memberCenter.domain.UserMember;
|
||||||
|
|
||||||
|
public interface UserMemberService extends IService<UserMember> {
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.mcwl.memberCenter.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.mcwl.memberCenter.domain.Member;
|
||||||
|
import com.mcwl.memberCenter.mapper.MemberMapper;
|
||||||
|
import com.mcwl.memberCenter.service.MemberService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> implements MemberService {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.mcwl.memberCenter.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.mcwl.memberCenter.domain.UserMember;
|
||||||
|
import com.mcwl.memberCenter.mapper.UserMemberMapper;
|
||||||
|
import com.mcwl.memberCenter.service.UserMemberService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class UserMemberServiceImpl extends ServiceImpl<UserMemberMapper, UserMember> implements UserMemberService {
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?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.mcwl.memberCenter.mapper.MemberMapper">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.mcwl</groupId>
|
||||||
|
<artifactId>mcwl</artifactId>
|
||||||
|
<version>3.8.8</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>mcwl-myInvitation</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<mybatis-plus.version>3.5.2</mybatis-plus.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- 通用工具-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mcwl</groupId>
|
||||||
|
<artifactId>mcwl-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<version>${mybatis-plus.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.mcwl.myInvitation.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.mcwl.common.core.domain.BaseEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
// 提成表
|
||||||
|
@Data
|
||||||
|
@TableName("commissions")
|
||||||
|
public class Commission extends BaseEntity {
|
||||||
|
|
||||||
|
@TableId
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
// 用户id
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
// 消费id
|
||||||
|
private Long consumeId;
|
||||||
|
|
||||||
|
// 提成金额
|
||||||
|
private Double amount;
|
||||||
|
|
||||||
|
// 支付状态
|
||||||
|
private Integer payStatus;
|
||||||
|
|
||||||
|
// 删除标志(0代表存在 2代表删除)
|
||||||
|
private String delFlag;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Commission that = (Commission) o;
|
||||||
|
return Objects.equals(id, that.id) && Objects.equals(userId, that.userId) && Objects.equals(consumeId, that.consumeId) && Objects.equals(amount, that.amount) && Objects.equals(payStatus, that.payStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(id, userId, consumeId, amount, payStatus);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.mcwl.myInvitation.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.mcwl.common.core.domain.BaseEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
// 消费表
|
||||||
|
@Data
|
||||||
|
@TableName("consumes")
|
||||||
|
public class Consume extends BaseEntity {
|
||||||
|
|
||||||
|
@TableId
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
// 用户id
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
// 消费金额
|
||||||
|
private Double amount;
|
||||||
|
|
||||||
|
// 消费时间
|
||||||
|
private Date consumeDate;
|
||||||
|
|
||||||
|
// 删除标志(0代表存在 2代表删除)
|
||||||
|
private String delFlag;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Consume consume = (Consume) o;
|
||||||
|
return Objects.equals(id, consume.id) && Objects.equals(userId, consume.userId) && Objects.equals(amount, consume.amount) && Objects.equals(consumeDate, consume.consumeDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(id, userId, amount, consumeDate);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.mcwl.myInvitation.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.mcwl.common.core.domain.BaseEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
// 邀请表
|
||||||
|
@Data
|
||||||
|
@TableName("invitations")
|
||||||
|
public class Invitation extends BaseEntity {
|
||||||
|
|
||||||
|
@TableId
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
// 邀请者
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
// 被邀请者
|
||||||
|
private Long userInviteId ;
|
||||||
|
|
||||||
|
// 邀请码
|
||||||
|
private String invitationCode;
|
||||||
|
|
||||||
|
// 删除标志(0代表存在 2代表删除)
|
||||||
|
private String delFlag;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Invitation that = (Invitation) o;
|
||||||
|
return Objects.equals(id, that.id) && Objects.equals(userId, that.userId) && Objects.equals(userInviteId, that.userInviteId) && Objects.equals(invitationCode, that.invitationCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(id, userId, userInviteId, invitationCode);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.mcwl.myInvitation.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.mcwl.myInvitation.domain.Commission;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface CommissionMapper extends BaseMapper<Commission> {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.mcwl.myInvitation.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.mcwl.myInvitation.domain.Commission;
|
||||||
|
import com.mcwl.myInvitation.domain.Consume;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface ConsumeMapper extends BaseMapper<Consume> {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.mcwl.myInvitation.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.mcwl.myInvitation.domain.Commission;
|
||||||
|
import com.mcwl.myInvitation.domain.Invitation;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface InvitationMapper extends BaseMapper<Invitation> {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package com.mcwl.myInvitation.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.mcwl.myInvitation.domain.Commission;
|
||||||
|
|
||||||
|
public interface CommissionService extends IService<Commission> {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package com.mcwl.myInvitation.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.mcwl.myInvitation.domain.Consume;
|
||||||
|
|
||||||
|
public interface ConsumeService extends IService<Consume> {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.mcwl.myInvitation.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.mcwl.myInvitation.domain.Invitation;
|
||||||
|
|
||||||
|
public interface InvitationService extends IService<Invitation> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取邀请码
|
||||||
|
* @param userId 用户id
|
||||||
|
* @return 邀请码
|
||||||
|
*/
|
||||||
|
String getInvitationCode(Long userId);
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.mcwl.myInvitation.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.mcwl.myInvitation.domain.Commission;
|
||||||
|
import com.mcwl.myInvitation.mapper.CommissionMapper;
|
||||||
|
import com.mcwl.myInvitation.service.CommissionService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commission> implements CommissionService {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.mcwl.myInvitation.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.mcwl.myInvitation.domain.Consume;
|
||||||
|
import com.mcwl.myInvitation.mapper.ConsumeMapper;
|
||||||
|
import com.mcwl.myInvitation.service.ConsumeService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ConsumeServiceImpl extends ServiceImpl<ConsumeMapper, Consume> implements ConsumeService {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.mcwl.myInvitation.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.mcwl.common.constant.JwtConstants;
|
||||||
|
import com.mcwl.common.utils.JwtUtils;
|
||||||
|
import com.mcwl.myInvitation.domain.Invitation;
|
||||||
|
import com.mcwl.myInvitation.mapper.InvitationMapper;
|
||||||
|
import com.mcwl.myInvitation.service.InvitationService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class InvitationServiceImpl extends ServiceImpl<InvitationMapper, Invitation> implements InvitationService {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getInvitationCode(Long userId) {
|
||||||
|
// 生成邀请码
|
||||||
|
Map<String, Object> claims = new HashMap<>() ;
|
||||||
|
claims.put(JwtConstants.DETAILS_USER_ID, userId);
|
||||||
|
String invitationCode = JwtUtils.createToken(claims);
|
||||||
|
return invitationCode;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?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.mcwl.myInvitation.mapper.CommissionMapper">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?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.mcwl.myInvitation.mapper.ConsumeMapper">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?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.mcwl.myInvitation.mapper.InvitationMapper">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
|
@ -8,9 +8,7 @@
|
||||||
<artifactId>mcwl</artifactId>
|
<artifactId>mcwl</artifactId>
|
||||||
<version>3.8.8</version>
|
<version>3.8.8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>mcwl-resource</artifactId>
|
<artifactId>mcwl-resource</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
resource资源中心模块
|
resource资源中心模块
|
||||||
</description>
|
</description>
|
||||||
|
|
|
@ -0,0 +1,106 @@
|
||||||
|
package com.mcwl.system.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方登录表
|
||||||
|
*
|
||||||
|
* @author DaiZibo
|
||||||
|
* @date 2024/12/30
|
||||||
|
* @apiNote
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Data
|
||||||
|
@TableName("sys_user_third_account")
|
||||||
|
public class SysUserThirdAccount {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键ID
|
||||||
|
*/
|
||||||
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户ID
|
||||||
|
*/
|
||||||
|
@TableField(value = "user_id")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方唯一ID
|
||||||
|
*/
|
||||||
|
@TableField(value = "openid")
|
||||||
|
private String openid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方昵称
|
||||||
|
*/
|
||||||
|
@TableField(value = "open_name")
|
||||||
|
private String openName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方头像
|
||||||
|
*/
|
||||||
|
@TableField(value = "src")
|
||||||
|
private String src;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方(qq/微信)
|
||||||
|
*/
|
||||||
|
@TableField(value = "bind_type")
|
||||||
|
private String bindType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标志是否绑定
|
||||||
|
*/
|
||||||
|
@TableField(value = "bind_flag")
|
||||||
|
private String bindFlag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绑定时间
|
||||||
|
*/
|
||||||
|
@TableField(value = "bind_date")
|
||||||
|
private Date bindDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建者
|
||||||
|
*/
|
||||||
|
@TableField(value = "create_by")
|
||||||
|
private String createBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@TableField(value = "create_time")
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新着
|
||||||
|
*/
|
||||||
|
@TableField(value = "update_by")
|
||||||
|
private String updateBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
@TableField(value = "update_time")
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除标志(0代表存在 2代表删除)
|
||||||
|
*/
|
||||||
|
@TableField(value = "del_flag")
|
||||||
|
private Integer delFlag;
|
||||||
|
}
|
|
@ -1,8 +1,9 @@
|
||||||
package com.mcwl.system.mapper;
|
package com.mcwl.system.mapper;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
import com.mcwl.common.core.domain.entity.SysUser;
|
import com.mcwl.common.core.domain.entity.SysUser;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户表 数据层
|
* 用户表 数据层
|
||||||
|
@ -124,4 +125,7 @@ public interface SysUserMapper
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public SysUser checkEmailUnique(String email);
|
public SysUser checkEmailUnique(String email);
|
||||||
|
|
||||||
|
SysUser selectUserByPhone(@Param("phone") String phone);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.mcwl.system.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.mcwl.system.domain.SysUserThirdAccount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DaiZibo
|
||||||
|
* @date 2024/12/30
|
||||||
|
* @apiNote
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface SysUserThirdAccountMapper extends BaseMapper<SysUserThirdAccount> {
|
||||||
|
}
|
|
@ -1,8 +1,9 @@
|
||||||
package com.mcwl.system.service;
|
package com.mcwl.system.service;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import com.mcwl.common.core.domain.entity.SysUser;
|
import com.mcwl.common.core.domain.entity.SysUser;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户 业务层
|
* 用户 业务层
|
||||||
*
|
*
|
||||||
|
@ -203,4 +204,7 @@ public interface ISysUserService
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName);
|
public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName);
|
||||||
|
|
||||||
|
SysUser selectUserByPhone(String phone);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.mcwl.system.service;
|
||||||
|
|
||||||
|
import com.mcwl.common.core.domain.entity.SysUser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方登录表
|
||||||
|
* @author DaiZibo
|
||||||
|
* @date 2024/12/30
|
||||||
|
* @apiNote
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface ISysUserThirdAccountService {
|
||||||
|
SysUser selectUserByOpenId(String openid);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.mcwl.system.service;
|
||||||
|
|
||||||
|
import com.mcwl.system.domain.SysUserThirdAccount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信登录业务层
|
||||||
|
* @author DaiZibo
|
||||||
|
* @date 2024/12/31
|
||||||
|
* @apiNote
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface IWXService {
|
||||||
|
SysUserThirdAccount getOpenid(String code);
|
||||||
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
package com.mcwl.system.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.mcwl.system.domain.SysUserThirdAccount;
|
||||||
|
import com.mcwl.system.service.IWXService;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信登录 业务处理层
|
||||||
|
*
|
||||||
|
* @author DaiZibo
|
||||||
|
* @date 2024/12/31
|
||||||
|
* @apiNote
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class IWXServiceImpl implements IWXService {
|
||||||
|
|
||||||
|
@Value("${wechat.appid}")
|
||||||
|
private String appId;
|
||||||
|
|
||||||
|
@Value("${wechat.secret}")
|
||||||
|
private String secret;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SysUserThirdAccount getOpenid(String code) {
|
||||||
|
|
||||||
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
|
JSONObject jsonData = null;
|
||||||
|
|
||||||
|
// 构建获取access_token的URL
|
||||||
|
String url = "https://api.weixin.qq.com/sns/oauth2/access_token?"
|
||||||
|
+ "appid=" + appId
|
||||||
|
+ "&secret=" + secret
|
||||||
|
+ "&code=" + code
|
||||||
|
+ "&grant_type=authorization_code";
|
||||||
|
|
||||||
|
System.out.println("url: " + url);
|
||||||
|
ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class);
|
||||||
|
|
||||||
|
System.out.println("responseEntity: " + responseEntity);
|
||||||
|
if (responseEntity.getStatusCodeValue() == 200 && responseEntity.getBody() != null) {
|
||||||
|
jsonData = JSONObject.parseObject(responseEntity.getBody());
|
||||||
|
}
|
||||||
|
|
||||||
|
String userInfoUrl = "https://api.weixin.qq.com/sns/userinfo?lang=zh_CN"
|
||||||
|
+ "&access_token=" + jsonData.getString("access_token")
|
||||||
|
+ "&openid=" + jsonData.getString("openid");
|
||||||
|
|
||||||
|
ResponseEntity<String> responseUserEntity = restTemplate.getForEntity(userInfoUrl, String.class);
|
||||||
|
if (responseUserEntity.getStatusCodeValue() == 200 && responseUserEntity.getBody() != null) {
|
||||||
|
JSONObject jsonUserData = JSONObject.parseObject(new String(responseUserEntity.getBody().getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8));
|
||||||
|
System.out.println("jsonUserData: " + jsonUserData);
|
||||||
|
SysUserThirdAccount sysUserThirdAccount = new SysUserThirdAccount();
|
||||||
|
sysUserThirdAccount.setOpenid(jsonUserData.getString("openid"));
|
||||||
|
sysUserThirdAccount.setOpenName(jsonUserData.getString("nickname"));
|
||||||
|
return sysUserThirdAccount;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,15 +1,5 @@
|
||||||
package com.mcwl.system.service.impl;
|
package com.mcwl.system.service.impl;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import javax.validation.Validator;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
import com.mcwl.common.annotation.DataScope;
|
import com.mcwl.common.annotation.DataScope;
|
||||||
import com.mcwl.common.constant.UserConstants;
|
import com.mcwl.common.constant.UserConstants;
|
||||||
import com.mcwl.common.core.domain.entity.SysRole;
|
import com.mcwl.common.core.domain.entity.SysRole;
|
||||||
|
@ -22,14 +12,21 @@ import com.mcwl.common.utils.spring.SpringUtils;
|
||||||
import com.mcwl.system.domain.SysPost;
|
import com.mcwl.system.domain.SysPost;
|
||||||
import com.mcwl.system.domain.SysUserPost;
|
import com.mcwl.system.domain.SysUserPost;
|
||||||
import com.mcwl.system.domain.SysUserRole;
|
import com.mcwl.system.domain.SysUserRole;
|
||||||
import com.mcwl.system.mapper.SysPostMapper;
|
import com.mcwl.system.mapper.*;
|
||||||
import com.mcwl.system.mapper.SysRoleMapper;
|
|
||||||
import com.mcwl.system.mapper.SysUserMapper;
|
|
||||||
import com.mcwl.system.mapper.SysUserPostMapper;
|
|
||||||
import com.mcwl.system.mapper.SysUserRoleMapper;
|
|
||||||
import com.mcwl.system.service.ISysConfigService;
|
import com.mcwl.system.service.ISysConfigService;
|
||||||
import com.mcwl.system.service.ISysDeptService;
|
import com.mcwl.system.service.ISysDeptService;
|
||||||
import com.mcwl.system.service.ISysUserService;
|
import com.mcwl.system.service.ISysUserService;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import javax.validation.Validator;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户 业务层处理
|
* 用户 业务层处理
|
||||||
|
@ -547,4 +544,10 @@ public class SysUserServiceImpl implements ISysUserService
|
||||||
}
|
}
|
||||||
return successMsg.toString();
|
return successMsg.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SysUser selectUserByPhone(String phone) {
|
||||||
|
|
||||||
|
return userMapper.selectUserByPhone(phone);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
package com.mcwl.system.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.mcwl.common.core.domain.entity.SysUser;
|
||||||
|
import com.mcwl.system.domain.SysUserThirdAccount;
|
||||||
|
import com.mcwl.system.mapper.SysUserThirdAccountMapper;
|
||||||
|
import com.mcwl.system.service.ISysUserService;
|
||||||
|
import com.mcwl.system.service.ISysUserThirdAccountService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三方登录表 业务层处理
|
||||||
|
* @author DaiZibo
|
||||||
|
* @date 2024/12/30
|
||||||
|
* @apiNote
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class SysUserThirdAccountServiceImpl implements ISysUserThirdAccountService {
|
||||||
|
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ISysUserService sysUserService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SysUserThirdAccountMapper sysUserThirdAccountMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SysUser selectUserByOpenId(String openid) {
|
||||||
|
|
||||||
|
//根据openid查询第三方登录表数据
|
||||||
|
LambdaQueryWrapper<SysUserThirdAccount> sysUserThirdAccountLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
sysUserThirdAccountLambdaQueryWrapper.eq(SysUserThirdAccount::getBindType,"WeChat");
|
||||||
|
sysUserThirdAccountLambdaQueryWrapper.eq(SysUserThirdAccount::getOpenid,openid);
|
||||||
|
sysUserThirdAccountLambdaQueryWrapper.eq(SysUserThirdAccount::getDelFlag,0);
|
||||||
|
SysUserThirdAccount sysUserThirdAccount = sysUserThirdAccountMapper.selectOne(sysUserThirdAccountLambdaQueryWrapper);
|
||||||
|
|
||||||
|
//未查询到返回空对象
|
||||||
|
if (sysUserThirdAccount == null){
|
||||||
|
|
||||||
|
return new SysUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
//根据信息查登录人信息
|
||||||
|
return sysUserService.selectUserById(sysUserThirdAccount.getUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -142,6 +142,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
select user_id, email from sys_user where email = #{email} and del_flag = '0' limit 1
|
select user_id, email from sys_user where email = #{email} and del_flag = '0' limit 1
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectUserByPhone" resultMap="SysUserResult">
|
||||||
|
<include refid="selectUserVo"/>
|
||||||
|
where u.phonenumber = #{phone} and u.del_flag = '0'
|
||||||
|
</select>
|
||||||
|
|
||||||
<insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId">
|
<insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId">
|
||||||
insert into sys_user(
|
insert into sys_user(
|
||||||
<if test="userId != null and userId != 0">user_id,</if>
|
<if test="userId != null and userId != 0">user_id,</if>
|
||||||
|
|
9
pom.xml
9
pom.xml
|
@ -41,6 +41,13 @@
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
<!-- mybatis-plus -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<version>3.5.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- 覆盖SpringFramework的依赖配置-->
|
<!-- 覆盖SpringFramework的依赖配置-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
|
@ -228,7 +235,9 @@
|
||||||
<module>mcwl-quartz</module>
|
<module>mcwl-quartz</module>
|
||||||
<module>mcwl-generator</module>
|
<module>mcwl-generator</module>
|
||||||
<module>mcwl-common</module>
|
<module>mcwl-common</module>
|
||||||
|
<module>mcwl-myInvitation</module>
|
||||||
<module>mcwl-resource</module>
|
<module>mcwl-resource</module>
|
||||||
|
<module>mcwl-memberCenter</module>
|
||||||
</modules>
|
</modules>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue