This commit is contained in:
xinsin 2023-05-11 22:09:44 +08:00
parent 21b07d3628
commit 73ba7a60f1
9 changed files with 226 additions and 10 deletions

View File

@ -9,6 +9,8 @@ import top.xinsin.service.AuthPermissionsService;
import top.xinsin.service.AuthRolesService;
import top.xinsin.util.R;
import java.util.List;
/**
* @author xinsin
* Created On 2023/4/24 21:07
@ -31,4 +33,6 @@ public class AuthPermissionsController {
public R<JSONObject> getAuthPermissions(@RequestParam("page")Integer page, @RequestParam("num")Integer num){return authPermissionsService.getAuthPermissions(page,num);}
@RequestMapping(path = "/changeAuthPermissionsStats", method = RequestMethod.GET)
public R<String> changeAuthPermissionsStats(@RequestParam("authPermissionId") Integer authPermissionId, @RequestParam("status") Boolean status) {return authPermissionsService.changeAuthPermissionsStats(authPermissionId, status);}
@RequestMapping(path = "/getAuthPermissionsId",method = RequestMethod.GET)
public R<List<JSONObject>> getAuthPermissionsId(){return authPermissionsService.getAuthPermissionsId();}
}

View File

@ -1,7 +1,15 @@
package top.xinsin.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.xinsin.pojo.AuthPermissions;
import top.xinsin.pojo.AuthRoles;
import top.xinsin.service.AuthPermissionsService;
import top.xinsin.service.AuthRolesService;
import top.xinsin.util.R;
import java.util.List;
/**
* @author xinsin
@ -12,4 +20,19 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/authRoles")
public class AuthRolesController {
@Autowired
private AuthRolesService authPermissionsService;
@RequestMapping(path = "/addAuthRoles",method = RequestMethod.POST)
public R<Boolean> addAuthRoles(@RequestBody AuthRoles authPermissions){return authPermissionsService.addAuthRoles(authPermissions);}
@RequestMapping(path = "/changeAuthRoles",method = RequestMethod.POST)
public R<Boolean> changeAuthRoles(@RequestBody AuthRoles authPermissions){return authPermissionsService.changeAuthRoles(authPermissions);}
@RequestMapping(path = "/delAuthRoles",method = RequestMethod.GET)
public R<Boolean> delAuthRoles(@RequestParam("id")Integer id){return authPermissionsService.delAuthRoles(id);}
@RequestMapping(path = "/getAuthRoles",method = RequestMethod.GET)
public R<JSONObject> getAuthRoles(@RequestParam("page")Integer page, @RequestParam("num")Integer num){return authPermissionsService.getAuthRoles(page,num);}
@RequestMapping(path = "/changeAuthRoles", method = RequestMethod.GET)
public R<String> changeAuthRoles(@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();}
}

View File

@ -1,9 +1,14 @@
package top.xinsin.controller;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import top.xinsin.pojo.AuthPermissions;
import top.xinsin.pojo.AuthRolesPermissions;
import top.xinsin.service.AuthRolesPermissionsService;
import top.xinsin.util.R;
import java.util.List;
/**
* @author xinsin
@ -16,5 +21,17 @@ public class AuthRolesPermissionController {
@Autowired
private AuthRolesPermissionsService authRolesPermissionsService;
@RequestMapping(path = "/addAuthRolesPermissions",method = RequestMethod.POST)
public R<Boolean> addAuthRolesPermissions(@RequestBody AuthRolesPermissions authPermissions){return authRolesPermissionsService.addAuthRolesPermissions(authPermissions);}
@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);}
@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();}
}

View File

@ -8,6 +8,7 @@ import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;
/**
* @author xinsin
@ -30,11 +31,11 @@ public class AuthRoles implements Serializable {
@TableField("create_time")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime createTime;
private Date createTime;
@TableField("update_time")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime updateTime;
private Date updateTime;
@TableField("status")
private Boolean status;
@TableField("del")

View File

@ -0,0 +1,8 @@
package top.xinsin.pojo.vo;
import lombok.Data;
@Data
public class AuthRolesAndAuthPermissionsAndUserVo {
}

View File

@ -61,10 +61,8 @@ public class AccountService implements UserDetailsService {
return User
.withUsername(authAccount.getUsername())
.password(authAccount.getPassword())
.roles("id=" + authAccount.getId())
.roles("roleId=" + authAccount.getRoleId())
.roles("id=" + authAccount.getId(),"roleId=" + authAccount.getRoleId())
.build();
}
}
}

View File

@ -5,11 +5,15 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Service;
import top.xinsin.mapper.AccountMapper;
import top.xinsin.mapper.AuthPermissionsMapper;
import top.xinsin.pojo.AuthAccount;
import top.xinsin.pojo.AuthPermissions;
import top.xinsin.pojo.AuthRoles;
import top.xinsin.pojo.vo.AuthPermissionsAndUserVo;
import top.xinsin.util.HttpCodes;
import top.xinsin.util.R;
@ -31,6 +35,13 @@ public class AuthPermissionsService {
@Autowired
private AccountMapper accountMapper;
public R<Boolean> addAuthPermissions(AuthPermissions authPermissions) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
authentication.getAuthorities().forEach(e -> {
String authority = e.getAuthority();
if (authority.startsWith("ROLE_id=")){
authPermissions.setCreateId(Integer.parseInt(authority.replace("ROLE_id=", "")));
}
});
authPermissions.setCreateTime(new Date());
int insert = authPermissionsMapper.insert(authPermissions);
return insert == 1 ? R.success(true) : R.failed(HttpCodes.HTTP_CODES555, false);
@ -64,4 +75,13 @@ public class AuthPermissionsService {
public R<String> changeAuthPermissionsStats(Integer authPermissionId, Boolean status) {
return R.success("");
}
public R<List<JSONObject>> getAuthPermissionsId() {
List<AuthPermissions> authRoles = authPermissionsMapper.selectList(null);
ArrayList<JSONObject> jsonObjects = new ArrayList<>();
authRoles.forEach(e -> {
jsonObjects.add(new JSONObject().fluentPut("id",e.getId()).fluentPut("permissionName",e.getPermissionName()));
});
return R.success(jsonObjects);
}
}

View File

@ -1,6 +1,25 @@
package top.xinsin.service;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
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;
import java.util.*;
/**
* @author xinsin
@ -9,5 +28,73 @@ import org.springframework.stereotype.Service;
*/
@Service
public class AuthRolesPermissionsService {
@Autowired
private AuthRolesPermissionsMapper authRolesPermissionsMapper;
@Autowired
private AuthRolesMapper authRolesMapper;
@Autowired
private AuthPermissionsMapper authPermissionsMapper;
@Autowired
private AccountMapper accountMapper;
public R<Boolean> addAuthRolesPermissions(AuthRolesPermissions authPermissions) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
authentication.getAuthorities().forEach(e -> {
String authority = e.getAuthority();
if (authority.startsWith("ROLE_id=")){
authPermissions.setCreateId(Integer.parseInt(authority.replace("ROLE_id=", "")));
}
});
authPermissions.setCreateTime(new Date());
int insert = authRolesPermissionsMapper.insert(authPermissions);
return insert == 1 ? R.success(true) : R.failed(HttpCodes.HTTP_CODES555, false);
}
public R<Boolean> changeAuthRolesPermissions(AuthRolesPermissions authPermissions) {
authPermissions.setUpdateTime(new Date());
int update = authRolesPermissionsMapper.updateById(authPermissions);
return update == 1 ? R.success(true) : R.failed(HttpCodes.HTTP_CODES555, false);
}
public R<Boolean> delAuthRolesPermissions(Integer id) {
int delete = authRolesPermissionsMapper.deleteById(id);
return delete == 1 ? R.success(true) : R.failed(HttpCodes.HTTP_CODES555, false);
}
public R<JSONObject> getAuthRolesPermissions(Integer page, Integer num) {
Page<AuthRoles> authRolesPage = new Page<>(page, num);
Page<AuthRoles> authRolesPage1 = authRolesMapper.selectPage(authRolesPage, null);
ArrayList<JSONObject> jsonObjects1 = new ArrayList<>();
authRolesPage1.getRecords().forEach(e -> {
JSONObject jsonObject = new JSONObject();
jsonObject.fluentPut("roleName",e.getRoleName());
LambdaQueryWrapper<AuthRolesPermissions> authRolesPermissionsLambdaQueryWrapper = new LambdaQueryWrapper<>();
authRolesPermissionsLambdaQueryWrapper.eq(AuthRolesPermissions::getRoleId,e.getId());
List<AuthRolesPermissions> authRolesPermissions = authRolesPermissionsMapper.selectList(authRolesPermissionsLambdaQueryWrapper);
ArrayList<JSONObject> jsonObjects = new ArrayList<>();
authRolesPermissions.forEach(a -> {
JSONObject jsonObject1 = new JSONObject();
LambdaQueryWrapper<AuthPermissions> authPermissionsLambdaQueryWrapper = new LambdaQueryWrapper<>();
authPermissionsLambdaQueryWrapper.eq(AuthPermissions::getId,a.getPermissionId());
AuthPermissions authPermissions = authPermissionsMapper.selectOne(authPermissionsLambdaQueryWrapper);
jsonObject1.fluentPut("permissionName",authPermissions.getPermissionName()).fluentPut("permissionCode",authPermissions.getPermissionCode());
jsonObjects.add(jsonObject1);
});
jsonObject.fluentPut("permissions",jsonObjects);
jsonObjects1.add(jsonObject);
});
return R.success(new JSONObject().fluentPut("info",jsonObjects1).fluentPut("total",authRolesPage.getTotal()));
}
public R<String> changeAuthRolesPermissionsStats(Integer authPermissionId, Boolean status) {
return R.success("");
}
// public R<List<JSONObject>> getAuthRolesPermissions() {
// List<AuthRolesPermissions> authRoles = authRolesPermissionsMapper.selectList(null);
// ArrayList<JSONObject> jsonObjects = new ArrayList<>();
// authRoles.forEach(e -> {
// jsonObjects.add(new JSONObject().fluentPut("id",e.getId()).fluentPut("permissionName",e.getPermissionName()));
// });
// return R.success(jsonObjects);
// }
}

View File

@ -1,8 +1,23 @@
package top.xinsin.service;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import top.xinsin.mapper.AccountMapper;
import top.xinsin.mapper.AuthPermissionsMapper;
import top.xinsin.mapper.AuthRolesMapper;
import top.xinsin.pojo.AuthAccount;
import top.xinsin.pojo.AuthPermissions;
import top.xinsin.pojo.AuthRoles;
import top.xinsin.pojo.vo.AuthPermissionsAndUserVo;
import top.xinsin.util.HttpCodes;
import top.xinsin.util.R;
import java.util.*;
/**
* @author xinsin
@ -11,6 +26,49 @@ import top.xinsin.mapper.AuthRolesMapper;
*/
@Service
public class AuthRolesService {
@Autowired
@Autowired
private AuthRolesMapper authRolesMapper;
public R<Boolean> addAuthRoles(AuthRoles authPermissions) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
authentication.getAuthorities().forEach(e -> {
String authority = e.getAuthority();
if (authority.startsWith("ROLE_id=")){
authPermissions.setCreateId(Integer.parseInt(authority.replace("ROLE_id=", "")));
}
});
authPermissions.setCreateTime(new Date());
int insert = authRolesMapper.insert(authPermissions);
return insert == 1 ? R.success(true) : R.failed(HttpCodes.HTTP_CODES555, false);
}
public R<Boolean> changeAuthRoles(AuthRoles authPermissions) {
authPermissions.setUpdateTime(new Date());
int update = authRolesMapper.updateById(authPermissions);
return update == 1 ? R.success(true) : R.failed(HttpCodes.HTTP_CODES555, false);
}
public R<Boolean> delAuthRoles(Integer id) {
int delete = authRolesMapper.deleteById(id);
return delete == 1 ? R.success(true) : R.failed(HttpCodes.HTTP_CODES555, false);
}
public R<JSONObject> getAuthRoles(Integer page, Integer num) {
Page<AuthRoles> authPermissionsPage = new Page<>(page, num);
Page<AuthRoles> authRolesPage = authRolesMapper.selectPage(authPermissionsPage, null);
return R.success(new JSONObject().fluentPut("info",authRolesPage.getRecords()).fluentPut("total",authPermissionsPage.getTotal()));
}
public R<String> changeAuthRolesStats(Integer authPermissionId, Boolean status) {
return R.success("");
}
public R<List<JSONObject>> getAuthRolesId() {
List<AuthRoles> authRoles = authRolesMapper.selectList(null);
ArrayList<JSONObject> jsonObjects = new ArrayList<>();
authRoles.forEach(e -> {
jsonObjects.add(new JSONObject().fluentPut("id",e.getId()).fluentPut("roleName",e.getRoleName()));
});
return R.success(jsonObjects);
}
}