mdf:用户,部门去jpa2
This commit is contained in:
@@ -39,13 +39,13 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@EnableCreateCacheAnnotation
|
@EnableCreateCacheAnnotation
|
||||||
@ComponentScan(
|
@ComponentScan(
|
||||||
excludeFilters = {
|
excludeFilters = {
|
||||||
@ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.nl.modules.quartz.*")}
|
@ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.nl.modules.quartz.*"),
|
||||||
|
@ComponentScan.Filter(type = FilterType.REGEX, pattern = "com.github.loki4j.*")}
|
||||||
)
|
)
|
||||||
public class AppRun {
|
public class AppRun {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
|
||||||
SpringApplication.run(AppRun.class, args);
|
SpringApplication.run(AppRun.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,12 +15,15 @@
|
|||||||
*/
|
*/
|
||||||
package org.nl.modules.common.base;
|
package org.nl.modules.common.base;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.springframework.data.annotation.CreatedBy;
|
import org.springframework.data.annotation.CreatedBy;
|
||||||
import org.springframework.data.annotation.LastModifiedBy;
|
import org.springframework.data.annotation.LastModifiedBy;
|
||||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.EntityListeners;
|
import javax.persistence.EntityListeners;
|
||||||
@@ -55,10 +58,16 @@ public class BaseEntity implements Serializable {
|
|||||||
|
|
||||||
@Column(name = "create_time", updatable = false)
|
@Column(name = "create_time", updatable = false)
|
||||||
@ApiModelProperty(value = "创建时间", hidden = true)
|
@ApiModelProperty(value = "创建时间", hidden = true)
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JSONField(format="yyyy-MM-dd HH:mm:ss")
|
||||||
private Date create_time;
|
private Date create_time;
|
||||||
|
|
||||||
@Column(name = "update_time")
|
@Column(name = "update_time")
|
||||||
@ApiModelProperty(value = "更新时间", hidden = true)
|
@ApiModelProperty(value = "更新时间", hidden = true)
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JSONField(format="yyyy-MM-dd HH:mm:ss")
|
||||||
private Date update_time;
|
private Date update_time;
|
||||||
|
|
||||||
/* 分组校验 */
|
/* 分组校验 */
|
||||||
|
|||||||
@@ -62,15 +62,12 @@ public class Role extends BaseEntity implements Serializable {
|
|||||||
@ApiModelProperty(value = "名称", hidden = true)
|
@ApiModelProperty(value = "名称", hidden = true)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@ApiModelProperty(value = "数据权限,全部 、 本级 、 自定义")
|
|
||||||
private String dataScope = DataScopeEnum.THIS_LEVEL.getValue();
|
|
||||||
|
|
||||||
@Column(name = "level")
|
@Column(name = "level")
|
||||||
@ApiModelProperty(value = "级别,数值越小,级别越大")
|
@ApiModelProperty(value = "级别,数值越小,级别越大")
|
||||||
private Integer level = 3;
|
private Integer level = 3;
|
||||||
|
|
||||||
@ApiModelProperty(value = "描述")
|
@ApiModelProperty(value = "描述")
|
||||||
private String description;
|
private String remark;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ public class User extends BaseEntity implements Serializable {
|
|||||||
|
|
||||||
@Id
|
@Id
|
||||||
@Column(name = "role_id")
|
@Column(name = "role_id")
|
||||||
@NotNull(groups = {Update.class})
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@ApiModelProperty(value = "ID", hidden = true)
|
@ApiModelProperty(value = "ID", hidden = true)
|
||||||
private Long id;
|
private Long id;
|
||||||
@@ -79,7 +78,7 @@ public class User extends BaseEntity implements Serializable {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ApiModelProperty(value = "是否启用")
|
@ApiModelProperty(value = "是否启用")
|
||||||
private Boolean is_used;
|
private String is_used;
|
||||||
|
|
||||||
@ApiModelProperty(value = "是否为admin账号", hidden = true)
|
@ApiModelProperty(value = "是否为admin账号", hidden = true)
|
||||||
private Boolean isAdmin = false;
|
private Boolean isAdmin = false;
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public interface RoleRepository extends JpaRepository<Role, Long>, JpaSpecificat
|
|||||||
*/
|
*/
|
||||||
@Query(value = "SELECT r.* FROM sys_role r, sys_users_roles u WHERE " +
|
@Query(value = "SELECT r.* FROM sys_role r, sys_users_roles u WHERE " +
|
||||||
"r.role_id = u.role_id AND u.user_id = ?1",nativeQuery = true)
|
"r.role_id = u.role_id AND u.user_id = ?1",nativeQuery = true)
|
||||||
Set<Role> findByUserId(Long id);
|
List<Role> findByUserId(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解绑角色菜单
|
* 解绑角色菜单
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ public class RoleController {
|
|||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
private int getLevels(Integer level){
|
private int getLevels(Integer level){
|
||||||
List<Integer> levels = roleService.findByUsersId(StpUtil.getLoginIdAsLong()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList());
|
List<Integer> levels = roleService.findByUsersId(StpUtil.getLoginIdAsLong()).stream().map(Role::getLevel).collect(Collectors.toList());
|
||||||
int min = Collections.min(levels);
|
int min = Collections.min(levels);
|
||||||
if(level != null){
|
if(level != null){
|
||||||
if(level < min){
|
if(level < min){
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import org.nl.modules.common.utils.RedisUtils;
|
|||||||
import org.nl.modules.common.utils.RsaUtils;
|
import org.nl.modules.common.utils.RsaUtils;
|
||||||
import org.nl.modules.common.utils.SecurityUtils;
|
import org.nl.modules.common.utils.SecurityUtils;
|
||||||
import org.nl.modules.logging.annotation.Log;
|
import org.nl.modules.logging.annotation.Log;
|
||||||
|
import org.nl.modules.system.domain.Role;
|
||||||
import org.nl.modules.system.domain.User;
|
import org.nl.modules.system.domain.User;
|
||||||
import org.nl.modules.system.domain.vo.UserPassVo;
|
import org.nl.modules.system.domain.vo.UserPassVo;
|
||||||
import org.nl.modules.system.service.DataService;
|
import org.nl.modules.system.service.DataService;
|
||||||
@@ -148,8 +149,8 @@ public class UserController {
|
|||||||
@SaCheckPermission("user:del")
|
@SaCheckPermission("user:del")
|
||||||
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids) {
|
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids) {
|
||||||
for (Long id : ids) {
|
for (Long id : ids) {
|
||||||
Integer currentLevel = Collections.min(roleService.findByUsersId(StpUtil.getLoginIdAsLong()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList()));
|
Integer currentLevel = Collections.min(roleService.findByUsersId(StpUtil.getLoginIdAsLong()).stream().map(Role::getLevel).collect(Collectors.toList()));
|
||||||
Integer optLevel = Collections.min(roleService.findByUsersId(id).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList()));
|
Integer optLevel = Collections.min(roleService.findByUsersId(id).stream().map(Role::getLevel).collect(Collectors.toList()));
|
||||||
if (currentLevel > optLevel) {
|
if (currentLevel > optLevel) {
|
||||||
throw new BadRequestException("角色权限不足,不能删除:" + userService.findById(id).getUsername());
|
throw new BadRequestException("角色权限不足,不能删除:" + userService.findById(id).getUsername());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public interface RoleService {
|
|||||||
* @param id 用户ID
|
* @param id 用户ID
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
List<RoleSmallDto> findByUsersId(Long id);
|
List<Role> findByUsersId(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据角色查询角色级别
|
* 根据角色查询角色级别
|
||||||
|
|||||||
@@ -32,5 +32,4 @@ public class RoleSmallDto implements Serializable {
|
|||||||
|
|
||||||
private Integer level;
|
private Integer level;
|
||||||
|
|
||||||
private String dataScope;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,23 +56,23 @@ public class DataServiceImpl implements DataService {
|
|||||||
// 用于存储部门id
|
// 用于存储部门id
|
||||||
Set<Long> deptIds = new HashSet<>();
|
Set<Long> deptIds = new HashSet<>();
|
||||||
// 查询用户角色
|
// 查询用户角色
|
||||||
List<RoleSmallDto> roleSet = roleService.findByUsersId(user.getUser_id());
|
// List<RoleSmallDto> roleSet = roleService.findByUsersId(user.getUser_id());
|
||||||
// 获取对应的部门ID
|
// 获取对应的部门ID
|
||||||
for (RoleSmallDto role : roleSet) {
|
// for (RoleSmallDto role : roleSet) {
|
||||||
DataScopeEnum dataScopeEnum = DataScopeEnum.find(role.getDataScope());
|
// DataScopeEnum dataScopeEnum = DataScopeEnum.
|
||||||
switch (Objects.requireNonNull(dataScopeEnum)) {
|
// switch (Objects.requireNonNull(dataScopeEnum)) {
|
||||||
case THIS_LEVEL:
|
// case THIS_LEVEL:
|
||||||
/*if (ObjectUtil.isNotEmpty(user.getDept())){
|
// /*if (ObjectUtil.isNotEmpty(user.getDept())){
|
||||||
deptIds.add(user.getDept().getId());
|
// deptIds.add(user.getDept().getId());
|
||||||
}*/
|
// }*/
|
||||||
break;
|
// break;
|
||||||
case CUSTOMIZE:
|
// case CUSTOMIZE:
|
||||||
deptIds.addAll(getCustomize(deptIds, role));
|
// deptIds.addAll(getCustomize(deptIds, role));
|
||||||
break;
|
// break;
|
||||||
default:
|
// default:
|
||||||
return new ArrayList<>(deptIds);
|
// return new ArrayList<>(deptIds);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return new ArrayList<>(deptIds);
|
return new ArrayList<>(deptIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ package org.nl.modules.system.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -122,8 +123,7 @@ public class RoleServiceImpl implements RoleService {
|
|||||||
throw new EntityExistException(Role.class, "username", resources.getName());
|
throw new EntityExistException(Role.class, "username", resources.getName());
|
||||||
}
|
}
|
||||||
role.setName(resources.getName());
|
role.setName(resources.getName());
|
||||||
role.setDescription(resources.getDescription());
|
role.setRemark(resources.getRemark());
|
||||||
role.setDataScope(resources.getDataScope());
|
|
||||||
role.setLevel(resources.getLevel());
|
role.setLevel(resources.getLevel());
|
||||||
roleRepository.save(role);
|
roleRepository.save(role);
|
||||||
// 更新相关缓存
|
// 更新相关缓存
|
||||||
@@ -163,8 +163,8 @@ public class RoleServiceImpl implements RoleService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<RoleSmallDto> findByUsersId(Long id) {
|
public List<Role> findByUsersId(Long id) {
|
||||||
return roleSmallMapper.toDto(new ArrayList<>(roleRepository.findByUserId(id)));
|
return roleRepository.findByUserId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import cn.hutool.core.util.StrUtil;
|
|||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.serializer.SerializeConfig;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@@ -136,7 +137,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
User user = this.findById(resources.getUser_id());
|
User user = this.findById(resources.getUser_id());
|
||||||
redisUtils.del("user::username:" + user.getUsername());
|
redisUtils.del("user::username:" + user.getUsername());
|
||||||
// 如果用户被禁用,则清除用户登录信息
|
// 如果用户被禁用,则清除用户登录信息
|
||||||
if(!resources.getIs_used()){
|
if("0".equals(resources.getIs_used())){
|
||||||
onlineUserService.kickOutForUsername(resources.getUsername());
|
onlineUserService.kickOutForUsername(resources.getUsername());
|
||||||
}
|
}
|
||||||
resources.setPassword(SaSecureUtil.md5BySalt(resources.getPassword(), "salt"));
|
resources.setPassword(SaSecureUtil.md5BySalt(resources.getPassword(), "salt"));
|
||||||
@@ -226,7 +227,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
map.put("用户名", userDTO.getUsername());
|
map.put("用户名", userDTO.getUsername());
|
||||||
map.put("角色", userDTO.getRoles());
|
map.put("角色", userDTO.getRoles());
|
||||||
map.put("邮箱", userDTO.getEmail());
|
map.put("邮箱", userDTO.getEmail());
|
||||||
map.put("状态", userDTO.getIs_used() ? "启用" : "禁用");
|
map.put("状态", "1".equals(userDTO.getIs_used()) ? "启用" : "禁用");
|
||||||
map.put("手机号码", userDTO.getPhone());
|
map.put("手机号码", userDTO.getPhone());
|
||||||
map.put("修改密码的时间", userDTO.getPwdResetTime());
|
map.put("修改密码的时间", userDTO.getPwdResetTime());
|
||||||
map.put("创建日期", userDTO.getCreate_time());
|
map.put("创建日期", userDTO.getCreate_time());
|
||||||
|
|||||||
@@ -49,11 +49,12 @@
|
|||||||
IF 输入.flag = "1"
|
IF 输入.flag = "1"
|
||||||
PAGEQUERY
|
PAGEQUERY
|
||||||
SELECT
|
SELECT
|
||||||
sys_user.*,GROUP_CONCAT(DISTINCT dept_id),GROUP_CONCAT(DISTINCT role_id)
|
sys_user.*,GROUP_CONCAT(DISTINCT sys_dept.dept_id) as depts,GROUP_CONCAT(DISTINCT sys_dept.name) as deptnames,GROUP_CONCAT(DISTINCT role_id) as roles
|
||||||
FROM
|
FROM
|
||||||
sys_user
|
sys_user
|
||||||
left join sys_user_dept on sys_user.user_id = sys_user_dept.user_id
|
left join sys_user_dept on sys_user.user_id = sys_user_dept.user_id
|
||||||
left join sys_users_roles on sys_users_roles.user_id = sys_user.user_id
|
left join sys_users_roles on sys_users_roles.user_id = sys_user.user_id
|
||||||
|
left join sys_dept on sys_user_dept.dept_id = sys_dept.dept_id
|
||||||
WHERE 1=1
|
WHERE 1=1
|
||||||
OPTION 输入.id <> ""
|
OPTION 输入.id <> ""
|
||||||
sys_user.id = 输入.id
|
sys_user.id = 输入.id
|
||||||
|
|||||||
Reference in New Issue
Block a user