feat1
This commit is contained in:
parent
e5407d70b2
commit
af5fe0c8c0
4
pom.xml
4
pom.xml
@ -115,6 +115,10 @@
|
||||
<groupId>org.springframework.session</groupId>
|
||||
<artifactId>spring-session-data-redis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
|
@ -13,9 +13,13 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import top.xinsin.pojo.AuthAccount;
|
||||
import top.xinsin.pojo.vo.AccountAndStoreAdmin;
|
||||
import top.xinsin.service.AccountService;
|
||||
import top.xinsin.util.R;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* @author xinsin
|
||||
* Created On 2023/4/24 21:05
|
||||
@ -44,15 +48,25 @@ public class AccountController {
|
||||
public R<JSONObject> getUser(@RequestParam("page") Integer page, @RequestParam("num") Integer num) {return this.accountService.getUser(page, num);}
|
||||
@RequestMapping(path = "/getUserInfo",method = RequestMethod.GET)
|
||||
public R<JSONObject> getUserInfo(){
|
||||
GrantedAuthority grantedAuthority = ((User) SecurityContextHolder
|
||||
Collection<GrantedAuthority> authorities = ((User) SecurityContextHolder
|
||||
.getContext()
|
||||
.getAuthentication()
|
||||
.getPrincipal())
|
||||
.getAuthorities()
|
||||
.stream()
|
||||
.filter(e -> e.getAuthority().startsWith("ROLE_roleId="))
|
||||
.findFirst()
|
||||
.get();
|
||||
return accountService.getUserInfo(Integer.parseInt(grantedAuthority.getAuthority().replace("ROLE_roleId=","")));
|
||||
.getAuthorities();
|
||||
R<JSONObject> userInfo = accountService.getUserInfo(Integer.parseInt(authorities.stream().filter(e -> e.getAuthority().startsWith("ROLE_roleId=")).findFirst().get().getAuthority().replace("ROLE_roleId=", "")));
|
||||
userInfo.getData()
|
||||
.fluentPut("id",authorities.stream().filter(e -> e.getAuthority().startsWith("ROLE_id=")).findFirst().get().getAuthority().replace("ROLE_id=",""))
|
||||
.fluentPut("roleId",authorities.stream().filter(e -> e.getAuthority().startsWith("ROLE_roleId=")).findFirst().get().getAuthority().replace("ROLE_roleId=", ""))
|
||||
.fluentPut("auth",authorities.stream().filter(e -> e.getAuthority().startsWith("ROLE_auth=")).findFirst().get().getAuthority().replace("ROLE_auth=",""));
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
@RequestMapping(path = "/addStoreAdmin",method = RequestMethod.POST)
|
||||
public R<JSONObject> addStoreAdmin(@RequestBody AccountAndStoreAdmin accountAndStoreAdmin){
|
||||
return accountService.addStoreAdmin(accountAndStoreAdmin);
|
||||
}
|
||||
/* @RequestMapping(path = "/debug",method = RequestMethod.GET)
|
||||
public void debug(){accountService.debug();}
|
||||
@RequestMapping(path = "/debugs",method = RequestMethod.GET)
|
||||
public long debugs(){return accountService.debugs();}*/
|
||||
}
|
||||
|
@ -35,4 +35,6 @@ public class AuthRolesController {
|
||||
public R<String> changeAuthRolesStats(@RequestParam("authRolesId") Integer authPermissionId, @RequestParam("status") Boolean status) {return authPermissionsService.changeAuthRolesStats(authPermissionId, status);}
|
||||
@RequestMapping(path = "/getAuthRolesId",method = RequestMethod.GET)
|
||||
public R<List<JSONObject>> getAuthRolesId(){return authPermissionsService.getAuthRolesId();}
|
||||
@RequestMapping(path = "/getAuthPermissionId",method = RequestMethod.GET)
|
||||
public R<List<JSONObject>> getAuthPermissionId(@RequestParam("roleId") Integer roleId){return authPermissionsService.getAuthPermissionId(roleId);}
|
||||
}
|
@ -26,12 +26,10 @@ public class AuthRolesPermissionController {
|
||||
@RequestMapping(path = "/changeAuthRolesPermissions",method = RequestMethod.POST)
|
||||
public R<Boolean> changeAuthRolesPermissions(@RequestBody AuthRolesPermissions authPermissions){return authRolesPermissionsService.changeAuthRolesPermissions(authPermissions);}
|
||||
@RequestMapping(path = "/delAuthRolesPermissions",method = RequestMethod.GET)
|
||||
public R<Boolean> delAuthRolesPermissions(@RequestParam("id")Integer id){return authRolesPermissionsService.delAuthRolesPermissions(id);}
|
||||
public R<Boolean> delAuthRolesPermissions(@RequestParam("roleId")Integer roleId,@RequestParam("permissionId")Integer permissionId){return authRolesPermissionsService.delAuthRolesPermissions(roleId,permissionId);}
|
||||
@RequestMapping(path = "/getAuthRolesPermissions",method = RequestMethod.GET)
|
||||
public R<JSONObject> getAuthRolesPermissions(@RequestParam("page")Integer page, @RequestParam("num")Integer num){return authRolesPermissionsService.getAuthRolesPermissions(page,num);}
|
||||
@RequestMapping(path = "/changeAuthRolesPermissionsStats", method = RequestMethod.GET)
|
||||
public R<String> changeAuthRolesPermissionsStats(@RequestParam("authRolesPermissionsId") Integer authPermissionId, @RequestParam("status") Boolean status) {return authRolesPermissionsService.changeAuthRolesPermissionsStats(authPermissionId, status);}
|
||||
// @RequestMapping(path = "/getAuthRolesPermissions",method = RequestMethod.GET)
|
||||
// public R<List<JSONObject>> getAuthRolesPermissions(){return authRolesPermissionsService.getAuthRolesPermissions();}
|
||||
|
||||
}
|
||||
|
@ -23,13 +23,14 @@ public class AuthorizeController {
|
||||
private AccountService accountService;
|
||||
|
||||
@RequestMapping(path = "/register", method = RequestMethod.POST)
|
||||
public R<String> register(@RequestParam("username") String username, @RequestParam("relName") String relName, @RequestParam("email") String email, @RequestParam("password") String password, @RequestParam("roleId") Integer roleId) {
|
||||
public R<String> register(@RequestParam("auth")String auth,@RequestParam("username") String username, @RequestParam("relName") String relName, @RequestParam("email") String email, @RequestParam("password") String password, @RequestParam("roleId") Integer roleId) {
|
||||
AuthAccount authAccount = new AuthAccount();
|
||||
authAccount.setUsername(username);
|
||||
authAccount.setPassword(password);
|
||||
authAccount.setRelName(relName);
|
||||
authAccount.setEmail(email);
|
||||
authAccount.setRoleId(roleId);
|
||||
authAccount.setAuth(auth);
|
||||
return this.accountService.register(authAccount);
|
||||
}
|
||||
}
|
||||
|
33
src/main/java/top/xinsin/controller/VerifyController.java
Normal file
33
src/main/java/top/xinsin/controller/VerifyController.java
Normal file
@ -0,0 +1,33 @@
|
||||
package top.xinsin.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.xinsin.service.VerifyService;
|
||||
import top.xinsin.util.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/verify")
|
||||
public class VerifyController {
|
||||
@Autowired
|
||||
private VerifyService verifyService;
|
||||
|
||||
@RequestMapping(path = "/getRemainderTime",method = RequestMethod.GET)
|
||||
public R<JSONObject> getRemainderTime(@RequestParam("id")Integer id){
|
||||
return verifyService.getRemainderTime(id);
|
||||
}
|
||||
@RequestMapping(path = "/verify",method = RequestMethod.GET)
|
||||
public R<Boolean> verify(@RequestParam("id")Integer id,@RequestParam("name")String name,@RequestParam("phone")String phone){
|
||||
return verifyService.verify(id,name,phone);
|
||||
}
|
||||
@RequestMapping(path = "/getVerifyMessage",method = RequestMethod.GET)
|
||||
public R<List<JSONObject>> getVerifyMessage(@RequestParam("createId")Integer createId){
|
||||
return verifyService.getVerifyMessage(createId);
|
||||
}
|
||||
@RequestMapping(path = "/confirmVerify",method = RequestMethod.GET)
|
||||
public R<JSONObject> confirmVerify(@RequestParam("createId") Integer createId,@RequestParam("storeId")Integer storeId,@RequestParam("status")Boolean status){
|
||||
return verifyService.confirmVerify(createId,storeId,status);
|
||||
}
|
||||
}
|
9
src/main/java/top/xinsin/mapper/VerifyMapper.java
Normal file
9
src/main/java/top/xinsin/mapper/VerifyMapper.java
Normal file
@ -0,0 +1,9 @@
|
||||
package top.xinsin.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xinsin.pojo.Verify;
|
||||
|
||||
@Mapper
|
||||
public interface VerifyMapper extends BaseMapper<Verify> {
|
||||
}
|
@ -3,6 +3,7 @@ package top.xinsin.pojo;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serial;
|
||||
@ -16,6 +17,7 @@ import java.util.Date;
|
||||
*/
|
||||
@Data
|
||||
@TableName("auth_account")
|
||||
@NoArgsConstructor
|
||||
public class AuthAccount implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
@ -23,6 +25,8 @@ public class AuthAccount implements Serializable {
|
||||
private Integer id;
|
||||
@TableField("username")
|
||||
private String username;
|
||||
@TableField("auth")
|
||||
private String auth;
|
||||
@TableField("email")
|
||||
private String email;
|
||||
@TableField("rel_name")
|
||||
@ -44,4 +48,15 @@ public class AuthAccount implements Serializable {
|
||||
@TableField("del")
|
||||
@TableLogic
|
||||
private Boolean del;
|
||||
|
||||
public AuthAccount(String username, String auth, String email, String relName, String password, Boolean status, Integer roleId, Date createTime) {
|
||||
this.username = username;
|
||||
this.auth = auth;
|
||||
this.email = email;
|
||||
this.relName = relName;
|
||||
this.password = password;
|
||||
this.status = status;
|
||||
this.roleId = roleId;
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
||||
|
50
src/main/java/top/xinsin/pojo/Verify.java
Normal file
50
src/main/java/top/xinsin/pojo/Verify.java
Normal file
@ -0,0 +1,50 @@
|
||||
package top.xinsin.pojo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class Verify {
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
private Integer createId;
|
||||
private Integer storeId;
|
||||
private Long countdown;
|
||||
private String verifyName;
|
||||
private String verifyPhone;
|
||||
private String verifyResult;
|
||||
private Integer num;
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date updateTime;
|
||||
@TableLogic
|
||||
private Integer del;
|
||||
|
||||
public Verify(Integer createId, Integer storeId, Long countdown) {
|
||||
this.createId = createId;
|
||||
this.storeId = storeId;
|
||||
this.countdown = countdown;
|
||||
}
|
||||
|
||||
public Verify(String verifyName,String verifyPhone, String verifyResult, Integer num, Date updateTime) {
|
||||
this.verifyName = verifyName;
|
||||
this.verifyPhone = verifyPhone;
|
||||
this.verifyResult = verifyResult;
|
||||
this.num = num;
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public Verify(String verifyResult, Integer num, Date updateTime) {
|
||||
this.verifyResult = verifyResult;
|
||||
this.num = num;
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
}
|
20
src/main/java/top/xinsin/pojo/vo/AccountAndStoreAdmin.java
Normal file
20
src/main/java/top/xinsin/pojo/vo/AccountAndStoreAdmin.java
Normal file
@ -0,0 +1,20 @@
|
||||
package top.xinsin.pojo.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class AccountAndStoreAdmin {
|
||||
private String username;
|
||||
private String auth;
|
||||
private String email;
|
||||
private String relName;
|
||||
private String password;
|
||||
private Boolean status;
|
||||
private Integer roleId;
|
||||
private Date createTime;
|
||||
private Date updateTime;
|
||||
private Integer createId;
|
||||
private Long countdown;
|
||||
}
|
@ -4,28 +4,28 @@ import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.xinsin.mapper.AccountMapper;
|
||||
import top.xinsin.mapper.AuthPermissionsMapper;
|
||||
import top.xinsin.mapper.AuthRolesMapper;
|
||||
import top.xinsin.mapper.AuthRolesPermissionsMapper;
|
||||
import top.xinsin.pojo.AuthAccount;
|
||||
import top.xinsin.pojo.AuthPermissions;
|
||||
import top.xinsin.pojo.AuthRoles;
|
||||
import top.xinsin.pojo.AuthRolesPermissions;
|
||||
import top.xinsin.mapper.*;
|
||||
import top.xinsin.pojo.*;
|
||||
import top.xinsin.pojo.vo.AccountAndStoreAdmin;
|
||||
import top.xinsin.util.HttpCodes;
|
||||
import top.xinsin.util.R;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author xinsin
|
||||
@ -43,6 +43,10 @@ public class AccountService implements UserDetailsService {
|
||||
private AuthRolesMapper authRolesMapper;
|
||||
@Autowired
|
||||
private AuthPermissionsMapper authPermissionsMapper;
|
||||
@Autowired
|
||||
private VerifyMapper verifyMapper;
|
||||
@Resource
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
|
||||
|
||||
@ -58,10 +62,21 @@ public class AccountService implements UserDetailsService {
|
||||
if (authAccount == null) {
|
||||
throw new UsernameNotFoundException("用户名或密码错误");
|
||||
} else {
|
||||
if (authAccount.getAuth().equals("商户")){
|
||||
Long expire = redisTemplate.getExpire(String.valueOf(authAccount.getId()), TimeUnit.SECONDS);
|
||||
if (expire.longValue() == -1L || expire.longValue() == -2L){
|
||||
log.info("当前商户已过期");
|
||||
Verify verify = verifyMapper.selectOne(new LambdaQueryWrapper<Verify>().eq(Verify::getStoreId, authAccount.getId()));
|
||||
if (verify.getVerifyResult().equals("false")){
|
||||
log.info("无法登录,因为商户管理员已拒绝");
|
||||
return User.withUsername(authAccount.getUsername()).password("").build();
|
||||
}
|
||||
}
|
||||
}
|
||||
return User
|
||||
.withUsername(authAccount.getUsername())
|
||||
.password(authAccount.getPassword())
|
||||
.roles("id=" + authAccount.getId(),"roleId=" + authAccount.getRoleId())
|
||||
.roles("id=" + authAccount.getId(),"roleId=" + authAccount.getRoleId(),"auth=" + authAccount.getAuth())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@ -109,7 +124,25 @@ public class AccountService implements UserDetailsService {
|
||||
|
||||
public R<JSONObject> getUser(Integer page, Integer num) {
|
||||
Page<AuthAccount> accountPage = new Page<>(page, num);
|
||||
Page<AuthAccount> accountPage1 = this.accountMapper.selectPage(accountPage, null);
|
||||
String auth = ((User) SecurityContextHolder
|
||||
.getContext()
|
||||
.getAuthentication()
|
||||
.getPrincipal())
|
||||
.getAuthorities()
|
||||
.stream()
|
||||
.filter(e -> e.getAuthority().startsWith("ROLE_auth="))
|
||||
.findFirst()
|
||||
.get()
|
||||
.getAuthority().replace("ROLE_auth=","");
|
||||
LambdaQueryWrapper<AuthAccount> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
if (auth.equals("租户管理员")){
|
||||
userLambdaQueryWrapper.in(AuthAccount::getAuth,"商户管理员","商户");
|
||||
}
|
||||
if (auth.equals("商户管理员")){
|
||||
userLambdaQueryWrapper.in(AuthAccount::getAuth,"商户");
|
||||
}
|
||||
System.out.println(auth);
|
||||
Page<AuthAccount> accountPage1 = this.accountMapper.selectPage(accountPage, userLambdaQueryWrapper);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
List<AuthAccount> collect = accountPage1.getRecords().stream().peek((e) -> e.setPassword(null)).toList();
|
||||
jsonObject
|
||||
@ -124,7 +157,6 @@ public class AccountService implements UserDetailsService {
|
||||
}
|
||||
|
||||
public R<JSONObject> getUserInfo(int rolesId) {
|
||||
System.out.println(rolesId);
|
||||
JSONObject globalReturnData = new JSONObject();
|
||||
JSONArray globalReturnPermissionList = new JSONArray();
|
||||
List<AuthRolesPermissions> authRolesPermissions = authRolesPermissionsMapper
|
||||
@ -147,4 +179,18 @@ public class AccountService implements UserDetailsService {
|
||||
.fluentPut("roleName",roleName);
|
||||
return R.success(globalReturnData);
|
||||
}
|
||||
|
||||
public R<JSONObject> addStoreAdmin(AccountAndStoreAdmin accountAndStoreAdmin) {
|
||||
AuthAccount authAccount = new AuthAccount(accountAndStoreAdmin.getUsername(), accountAndStoreAdmin.getAuth(), accountAndStoreAdmin.getEmail(), accountAndStoreAdmin.getRelName(), this.encoder.encode(accountAndStoreAdmin.getPassword()), accountAndStoreAdmin.getStatus(), accountAndStoreAdmin.getRoleId(), new Date());
|
||||
int insert = accountMapper.insert(authAccount);
|
||||
if (insert == 1){
|
||||
Verify verify = new Verify(accountAndStoreAdmin.getCreateId(), authAccount.getId(), accountAndStoreAdmin.getCountdown());
|
||||
int insert1 = verifyMapper.insert(verify);
|
||||
if (insert1 == 1){
|
||||
redisTemplate.opsForValue().set(String.valueOf(authAccount.getId()),authAccount.getUsername(),verify.getCountdown(), TimeUnit.SECONDS);
|
||||
return R.success(new JSONObject().fluentPut("status","添加该商户成功").fluentPut("nextVerificationTime",verify.getCountdown()));
|
||||
}
|
||||
}
|
||||
return R.failed(HttpCodes.HTTP_CODES500,new JSONObject().fluentPut("status","添加商户失败"));
|
||||
}
|
||||
}
|
||||
|
@ -11,11 +11,9 @@ import top.xinsin.mapper.AccountMapper;
|
||||
import top.xinsin.mapper.AuthPermissionsMapper;
|
||||
import top.xinsin.mapper.AuthRolesMapper;
|
||||
import top.xinsin.mapper.AuthRolesPermissionsMapper;
|
||||
import top.xinsin.pojo.AuthAccount;
|
||||
import top.xinsin.pojo.AuthPermissions;
|
||||
import top.xinsin.pojo.AuthRoles;
|
||||
import top.xinsin.pojo.AuthRolesPermissions;
|
||||
import top.xinsin.pojo.vo.AuthPermissionsAndUserVo;
|
||||
import top.xinsin.util.HttpCodes;
|
||||
import top.xinsin.util.R;
|
||||
|
||||
@ -55,8 +53,10 @@ public class AuthRolesPermissionsService {
|
||||
return update == 1 ? R.success(true) : R.failed(HttpCodes.HTTP_CODES555, false);
|
||||
}
|
||||
|
||||
public R<Boolean> delAuthRolesPermissions(Integer id) {
|
||||
int delete = authRolesPermissionsMapper.deleteById(id);
|
||||
public R<Boolean> delAuthRolesPermissions(Integer roleId, Integer permissionId) {
|
||||
int delete = authRolesPermissionsMapper.delete(new LambdaQueryWrapper<AuthRolesPermissions>()
|
||||
.eq(AuthRolesPermissions::getRoleId,roleId)
|
||||
.eq(AuthRolesPermissions::getPermissionId,permissionId));
|
||||
return delete == 1 ? R.success(true) : R.failed(HttpCodes.HTTP_CODES555, false);
|
||||
}
|
||||
|
||||
|
@ -10,9 +10,11 @@ import org.springframework.stereotype.Service;
|
||||
import top.xinsin.mapper.AccountMapper;
|
||||
import top.xinsin.mapper.AuthPermissionsMapper;
|
||||
import top.xinsin.mapper.AuthRolesMapper;
|
||||
import top.xinsin.mapper.AuthRolesPermissionsMapper;
|
||||
import top.xinsin.pojo.AuthAccount;
|
||||
import top.xinsin.pojo.AuthPermissions;
|
||||
import top.xinsin.pojo.AuthRoles;
|
||||
import top.xinsin.pojo.AuthRolesPermissions;
|
||||
import top.xinsin.pojo.vo.AuthPermissionsAndUserVo;
|
||||
import top.xinsin.util.HttpCodes;
|
||||
import top.xinsin.util.R;
|
||||
@ -29,6 +31,10 @@ public class AuthRolesService {
|
||||
|
||||
@Autowired
|
||||
private AuthRolesMapper authRolesMapper;
|
||||
@Autowired
|
||||
private AuthPermissionsMapper authPermissionsMapper;
|
||||
@Autowired
|
||||
private AuthRolesPermissionsMapper authRolesPermissionsMapper;
|
||||
public R<Boolean> addAuthRoles(AuthRoles authPermissions) {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
authentication.getAuthorities().forEach(e -> {
|
||||
@ -71,4 +77,23 @@ public class AuthRolesService {
|
||||
});
|
||||
return R.success(jsonObjects);
|
||||
}
|
||||
|
||||
public R<List<JSONObject>> getAuthPermissionId(Integer roleId) {
|
||||
LambdaQueryWrapper<AuthRolesPermissions> authRolesPermissionsLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
authRolesPermissionsLambdaQueryWrapper.eq(AuthRolesPermissions::getRoleId,roleId);
|
||||
List<AuthRolesPermissions> authRolesPermissions = authRolesPermissionsMapper.selectList(authRolesPermissionsLambdaQueryWrapper);
|
||||
ArrayList<JSONObject> jsonObjects = new ArrayList<>();
|
||||
authRolesPermissions.forEach(e ->{
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
AuthPermissions authPermissions = authPermissionsMapper.selectOne(new LambdaQueryWrapper<AuthPermissions>().eq(AuthPermissions::getId, e.getPermissionId()));
|
||||
jsonObject
|
||||
.fluentPut("name",authPermissions.getPermissionName())
|
||||
.fluentPut("id",authPermissions.getId())
|
||||
.fluentPut("description",authPermissions.getDescription())
|
||||
.fluentPut("status",authPermissions.getStatus())
|
||||
.fluentPut("code",authPermissions.getPermissionCode());
|
||||
jsonObjects.add(jsonObject);
|
||||
});
|
||||
return R.success(jsonObjects);
|
||||
}
|
||||
}
|
||||
|
81
src/main/java/top/xinsin/service/VerifyService.java
Normal file
81
src/main/java/top/xinsin/service/VerifyService.java
Normal file
@ -0,0 +1,81 @@
|
||||
package top.xinsin.service;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.xinsin.mapper.VerifyMapper;
|
||||
import top.xinsin.pojo.Verify;
|
||||
import top.xinsin.util.HttpCodes;
|
||||
import top.xinsin.util.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Service
|
||||
public class VerifyService {
|
||||
|
||||
@Autowired
|
||||
private VerifyMapper verifyMapper;
|
||||
@Resource
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
public R<JSONObject> getRemainderTime(Integer id) {
|
||||
Long storeName = redisTemplate.getExpire(String.valueOf(id), TimeUnit.SECONDS);
|
||||
System.out.println(storeName);
|
||||
return R.success(new JSONObject().fluentPut("remainderTime",storeName));
|
||||
}
|
||||
|
||||
public R<Boolean> verify(Integer id, String name, String phone) {
|
||||
Verify verify = new Verify();
|
||||
verify.setVerifyPhone(phone);
|
||||
verify.setVerifyName(name);
|
||||
int update = verifyMapper.update(verify, new LambdaQueryWrapper<Verify>().eq(Verify::getStoreId, id));
|
||||
return update == 1 ? R.success(true) : R.failed(HttpCodes.HTTP_CODES555, false);
|
||||
}
|
||||
|
||||
public R<List<JSONObject>> getVerifyMessage(Integer createId) {
|
||||
LambdaQueryWrapper<Verify> verifyLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
verifyLambdaQueryWrapper.eq(Verify::getCreateId,createId);
|
||||
List<Verify> verifies = verifyMapper.selectList(verifyLambdaQueryWrapper);
|
||||
ArrayList<JSONObject> jsonObjects = new ArrayList<>();
|
||||
verifies.forEach(e -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.fluentPut("storeId",e.getStoreId())
|
||||
.fluentPut("storeName",e.getVerifyName())
|
||||
.fluentPut("phone",e.getVerifyPhone());
|
||||
jsonObjects.add(jsonObject);
|
||||
});
|
||||
return R.success(jsonObjects);
|
||||
}
|
||||
|
||||
public R<JSONObject> confirmVerify(Integer createId, Integer storeId, Boolean status) {
|
||||
if (status){
|
||||
LambdaQueryWrapper<Verify> verifyLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
verifyLambdaQueryWrapper
|
||||
.eq(Verify::getCreateId,createId)
|
||||
.eq(Verify::getStoreId,storeId);
|
||||
Verify verify1 = verifyMapper.selectOne(verifyLambdaQueryWrapper);
|
||||
Verify verify = new Verify("","",String.valueOf(true),verify1.getNum() + 1,new Date());
|
||||
int update = verifyMapper.update(verify, verifyLambdaQueryWrapper);
|
||||
if (update == 1){
|
||||
return R.success(new JSONObject().fluentPut("info","确认验证信息成功,请通知商户重新登录"));
|
||||
}
|
||||
}else {
|
||||
LambdaQueryWrapper<Verify> verifyLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
verifyLambdaQueryWrapper
|
||||
.eq(Verify::getCreateId,createId)
|
||||
.eq(Verify::getStoreId,storeId);
|
||||
Verify verify1 = verifyMapper.selectOne(verifyLambdaQueryWrapper);
|
||||
Verify verify = new Verify(String.valueOf(false),verify1.getNum() + 1,new Date());
|
||||
int update = verifyMapper.update(verify, verifyLambdaQueryWrapper);
|
||||
if (update == 1){
|
||||
return R.success(new JSONObject().fluentPut("info","确认验证信息成功,该用户将不可登录"));
|
||||
}
|
||||
}
|
||||
return R.failed(HttpCodes.ACCESS_DENIED,new JSONObject());
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ public class MainTest {
|
||||
public void test01(){
|
||||
System.out.println(new BCryptPasswordEncoder().encode(DigestUtils.md5Hex("xinsin")));
|
||||
System.out.println(DigestUtils.md5Hex("w433200w"));
|
||||
System.out.println(new BCryptPasswordEncoder().encode("996c24dbd061aeacb928fe4892d7a70b"));
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws ClassNotFoundException, SQLException {
|
||||
|
Loading…
x
Reference in New Issue
Block a user