diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/modules/security/rest/AuthorizationController.java b/mes/hd/nladmin-system/src/main/java/org/nl/modules/security/rest/AuthorizationController.java index 2c282009..9800d6bc 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/modules/security/rest/AuthorizationController.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/modules/security/rest/AuthorizationController.java @@ -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 与 用户信息 diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/modules/system/repository/DictDetailRepository.java b/mes/hd/nladmin-system/src/main/java/org/nl/modules/system/repository/DictDetailRepository.java index a16ac273..dee68cb5 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/modules/system/repository/DictDetailRepository.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/modules/system/repository/DictDetailRepository.java @@ -33,4 +33,11 @@ public interface DictDetailRepository extends JpaRepository, J * @return / */ List findByDictName(String name); -} \ No newline at end of file + + /** + * 根据标签找数据 + * @param label + * @return + */ + List findByLabelAndDict_Id(String label, Long dict_id); +} diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/modules/system/repository/DictRepository.java b/mes/hd/nladmin-system/src/main/java/org/nl/modules/system/repository/DictRepository.java index 059278c1..721d1f6b 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/modules/system/repository/DictRepository.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/modules/system/repository/DictRepository.java @@ -40,4 +40,11 @@ public interface DictRepository extends JpaRepository, JpaSpecificat * @return / */ List findByIdIn(Set ids); -} \ No newline at end of file + + /** + * 根据名字找字典 + * @param name + * @return + */ + Dict findByName(String name); +} diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/modules/system/service/impl/DeptServiceImpl.java b/mes/hd/nladmin-system/src/main/java/org/nl/modules/system/service/impl/DeptServiceImpl.java index 9a3ddef4..d2356bc4 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/modules/system/service/impl/DeptServiceImpl.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/modules/system/service/impl/DeptServiceImpl.java @@ -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 deptList = this.findByPid(id); + for (Dept dep : deptList) { + dep.setEnabled(resources.getEnabled()); + deptRepository.save(dep); + } + } + deptRepository.save(resources); // 修改 + // 更新父节点中子节点数目 updateSubCnt(oldPid); updateSubCnt(newPid); diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/modules/system/service/impl/DictDetailServiceImpl.java b/mes/hd/nladmin-system/src/main/java/org/nl/modules/system/service/impl/DictDetailServiceImpl.java index 21833edf..935e83d6 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/modules/system/service/impl/DictDetailServiceImpl.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/modules/system/service/impl/DictDetailServiceImpl.java @@ -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 label = dictDetailRepository.findByLabelAndDict_Id(resources.getLabel(), resources.getDict().getId()); + 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()); } -} \ No newline at end of file +} diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/modules/system/service/impl/DictServiceImpl.java b/mes/hd/nladmin-system/src/main/java/org/nl/modules/system/service/impl/DictServiceImpl.java index 903f0294..4bf2a119 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/modules/system/service/impl/DictServiceImpl.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/modules/system/service/impl/DictServiceImpl.java @@ -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); } diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/modules/system/service/impl/UserServiceImpl.java b/mes/hd/nladmin-system/src/main/java/org/nl/modules/system/service/impl/UserServiceImpl.java index a6727c6b..1711b56a 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/modules/system/service/impl/UserServiceImpl.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/modules/system/service/impl/UserServiceImpl.java @@ -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; diff --git a/mes/qd/src/views/system/dept/index.vue b/mes/qd/src/views/system/dept/index.vue index ccdeae3c..bbd738a8 100644 --- a/mes/qd/src/views/system/dept/index.vue +++ b/mes/qd/src/views/system/dept/index.vue @@ -107,7 +107,7 @@ @@ -284,6 +285,7 @@ export default { }).then(() => { crudDept.edit(data).then(res => { this.crud.notify(this.dict.label.dept_status[val] + '成功', CRUD.NOTIFICATION_TYPE.SUCCESS) + // this.crud.toQuery() }).catch(err => { data.enabled = !data.enabled console.log(err.response.data.message) diff --git a/mes/qd/src/views/system/user/index.vue b/mes/qd/src/views/system/user/index.vue index 52e3c83d..ba889ee1 100644 --- a/mes/qd/src/views/system/user/index.vue +++ b/mes/qd/src/views/system/user/index.vue @@ -266,7 +266,12 @@ export default { name: 'User', components: { Treeselect, crudOperation, rrOperation, udOperation, pagination, DateRangePicker }, cruds() { - return CRUD({ title: '用户', url: 'api/users', crudMethod: { ...crudUser }}) + return CRUD({ + title: '用户', + url: 'api/users', + sort: ['deptId', 'nickName', 'username'], + crudMethod: { ...crudUser } + }) }, mixins: [presenter(), header(), form(defaultForm), crud()], // 数据字典