部门管理、用户管理、字典管理
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
package org.nl.modules.security.rest;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.wf.captcha.base.Captcha;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -34,6 +35,8 @@ import org.nl.modules.security.security.TokenProvider;
|
||||
import org.nl.modules.security.service.OnlineUserService;
|
||||
import org.nl.modules.security.service.dto.AuthUserDto;
|
||||
import org.nl.modules.security.service.dto.JwtUserDto;
|
||||
import org.nl.modules.system.service.DeptService;
|
||||
import org.nl.modules.system.service.dto.DeptDto;
|
||||
import org.nl.utils.RedisUtils;
|
||||
import org.nl.utils.RsaUtils;
|
||||
import org.nl.utils.SecurityUtils;
|
||||
@@ -71,6 +74,7 @@ public class AuthorizationController {
|
||||
private final OnlineUserService onlineUserService;
|
||||
private final TokenProvider tokenProvider;
|
||||
private final AuthenticationManagerBuilder authenticationManagerBuilder;
|
||||
private final DeptService deptService;
|
||||
|
||||
@Resource
|
||||
private LoginProperties loginProperties;
|
||||
@@ -98,6 +102,15 @@ public class AuthorizationController {
|
||||
// 生成令牌
|
||||
String token = tokenProvider.createToken(authentication);
|
||||
final JwtUserDto jwtUserDto = (JwtUserDto) authentication.getPrincipal();
|
||||
// 判断部门是否存在或删除
|
||||
if (ObjectUtil.isEmpty(jwtUserDto.getUser().getDept())) {
|
||||
throw new BadRequestException("部门不存在");
|
||||
}
|
||||
Long id = jwtUserDto.getUser().getDept().getId();
|
||||
DeptDto deptDto = deptService.findById(id);
|
||||
if (!deptDto.getEnabled()) {
|
||||
throw new BadRequestException("部门已禁用");
|
||||
}
|
||||
// 保存在线信息
|
||||
onlineUserService.save(jwtUserDto, token, request);
|
||||
// 返回 token 与 用户信息
|
||||
|
||||
@@ -33,4 +33,11 @@ public interface DictDetailRepository extends JpaRepository<DictDetail, Long>, J
|
||||
* @return /
|
||||
*/
|
||||
List<DictDetail> findByDictName(String name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据标签找数据
|
||||
* @param label
|
||||
* @return
|
||||
*/
|
||||
List<DictDetail> findByLabel(String label);
|
||||
}
|
||||
|
||||
@@ -40,4 +40,11 @@ public interface DictRepository extends JpaRepository<Dict, Long>, JpaSpecificat
|
||||
* @return /
|
||||
*/
|
||||
List<Dict> findByIdIn(Set<Long> ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据名字找字典
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
Dict findByName(String name);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.db.Db;
|
||||
import cn.hutool.db.Entity;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import org.nl.exception.BadRequestException;
|
||||
@@ -43,6 +44,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.sql.DataSource;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.SQLException;
|
||||
@@ -138,7 +140,17 @@ public class DeptServiceImpl implements DeptService {
|
||||
Dept dept = deptRepository.findById(resources.getId()).orElseGet(Dept::new);
|
||||
ValidationUtil.isNull(dept.getId(), "Dept", "id", resources.getId());
|
||||
resources.setId(dept.getId());
|
||||
deptRepository.save(resources);
|
||||
// 判断如果是修改了启用/禁用,要包括子级一起禁用/启用
|
||||
if (resources.getEnabled() != dept.getEnabled()) {
|
||||
Long id = resources.getId();
|
||||
List<Dept> deptList = this.findByPid(id);
|
||||
for (Dept dep : deptList) {
|
||||
dep.setEnabled(resources.getEnabled());
|
||||
deptRepository.save(dep);
|
||||
}
|
||||
}
|
||||
deptRepository.save(resources); // 修改
|
||||
|
||||
// 更新父节点中子节点数目
|
||||
updateSubCnt(oldPid);
|
||||
updateSubCnt(newPid);
|
||||
|
||||
@@ -15,7 +15,9 @@
|
||||
*/
|
||||
package org.nl.modules.system.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.exception.BadRequestException;
|
||||
import org.nl.modules.system.domain.Dict;
|
||||
import org.nl.modules.system.domain.DictDetail;
|
||||
import org.nl.modules.system.repository.DictRepository;
|
||||
@@ -60,6 +62,8 @@ public class DictDetailServiceImpl implements DictDetailService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void create(DictDetail resources) {
|
||||
List<DictDetail> label = dictDetailRepository.findByLabel(resources.getLabel());
|
||||
if (ObjectUtil.isNotEmpty(label)) throw new BadRequestException("字典[" + resources.getLabel() + "]已存在");
|
||||
dictDetailRepository.save(resources);
|
||||
// 清理缓存
|
||||
delCaches(resources);
|
||||
@@ -95,4 +99,4 @@ public class DictDetailServiceImpl implements DictDetailService {
|
||||
Dict dict = dictRepository.findById(dictDetail.getDict().getId()).orElseGet(Dict::new);
|
||||
redisUtils.del("dict::name:" + dict.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,10 @@
|
||||
package org.nl.modules.system.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.exception.BadRequestException;
|
||||
import org.nl.modules.system.domain.Dict;
|
||||
import org.nl.modules.system.repository.DictRepository;
|
||||
import org.nl.modules.system.service.DictService;
|
||||
@@ -25,6 +28,8 @@ import org.nl.modules.system.service.dto.DictDto;
|
||||
import org.nl.modules.system.service.dto.DictQueryCriteria;
|
||||
import org.nl.modules.system.service.mapstruct.DictMapper;
|
||||
import org.nl.utils.*;
|
||||
import org.nl.wql.WQL;
|
||||
import org.nl.wql.core.bean.WQLObject;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -63,6 +68,8 @@ public class DictServiceImpl implements DictService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void create(Dict resources) {
|
||||
Dict dict = dictRepository.findByName(resources.getName());
|
||||
if (ObjectUtil.isNotEmpty(dict)) throw new BadRequestException("字典[" + resources.getName() + "]已存在");
|
||||
dictRepository.save(resources);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,11 +36,16 @@ import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.File;
|
||||
|
||||
Reference in New Issue
Block a user