mdf:用户,部门去jpa
This commit is contained in:
@@ -1,41 +1,41 @@
|
|||||||
package org.nl.modules.common.base;
|
package org.nl.modules.common.base;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
|
import org.hibernate.annotations.CreationTimestamp;
|
||||||
|
import org.hibernate.annotations.UpdateTimestamp;
|
||||||
|
import org.springframework.data.annotation.CreatedBy;
|
||||||
|
import org.springframework.data.annotation.LastModifiedBy;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.sql.Date;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Zheng Jie
|
* @author Zheng Jie
|
||||||
* @date 2019年10月24日20:48:53
|
* @date 2019年10月24日20:48:53
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Data
|
||||||
@Setter
|
|
||||||
public class BaseDTO implements Serializable {
|
public class BaseDTO implements Serializable {
|
||||||
|
|
||||||
private String createBy;
|
private String create_name;
|
||||||
|
|
||||||
private String updatedBy;
|
private Long create_id;
|
||||||
|
|
||||||
private Timestamp createTime;
|
|
||||||
|
|
||||||
private Timestamp updateTime;
|
private String update_optname;
|
||||||
|
|
||||||
|
private Long update_optid;
|
||||||
|
|
||||||
|
|
||||||
|
private Date create_time;
|
||||||
|
|
||||||
|
|
||||||
|
private Date update_time;
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
ToStringBuilder builder = new ToStringBuilder(this);
|
|
||||||
Field[] fields = this.getClass().getDeclaredFields();
|
|
||||||
try {
|
|
||||||
for (Field f : fields) {
|
|
||||||
f.setAccessible(true);
|
|
||||||
builder.append(f.getName(), f.get(this)).append("\n");
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
builder.append("toString builder encounter an error");
|
|
||||||
}
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class Dept extends BaseEntity implements Serializable {
|
|||||||
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "排序")
|
@ApiModelProperty(value = "排序")
|
||||||
private Integer deptSort;
|
private Integer dept_sort;
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
@ApiModelProperty(value = "部门名称")
|
@ApiModelProperty(value = "部门名称")
|
||||||
@@ -48,12 +48,12 @@ public class Dept extends BaseEntity implements Serializable {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ApiModelProperty(value = "是否启用")
|
@ApiModelProperty(value = "是否启用")
|
||||||
private Boolean enabled;
|
private Boolean is_used;
|
||||||
|
|
||||||
@ApiModelProperty(value = "上级部门")
|
@ApiModelProperty(value = "上级部门")
|
||||||
private Long pid;
|
private Long pid;
|
||||||
|
|
||||||
@ApiModelProperty(value = "子节点数目", hidden = true)
|
@ApiModelProperty(value = "子节点数目", hidden = true)
|
||||||
private Integer subCount = 0;
|
private Integer sub_count = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import cn.hutool.core.collection.CollectionUtil;
|
|||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.apache.poi.ss.formula.functions.T;
|
||||||
import org.nl.modules.common.exception.BadRequestException;
|
import org.nl.modules.common.exception.BadRequestException;
|
||||||
import org.nl.modules.common.utils.PageUtil;
|
import org.nl.modules.common.utils.PageUtil;
|
||||||
import org.nl.modules.logging.annotation.Log;
|
import org.nl.modules.logging.annotation.Log;
|
||||||
@@ -28,6 +29,7 @@ import org.nl.modules.system.domain.Dept;
|
|||||||
import org.nl.modules.system.service.DeptService;
|
import org.nl.modules.system.service.DeptService;
|
||||||
import org.nl.modules.system.service.dto.DeptDto;
|
import org.nl.modules.system.service.dto.DeptDto;
|
||||||
import org.nl.modules.system.service.dto.DeptQueryCriteria;
|
import org.nl.modules.system.service.dto.DeptQueryCriteria;
|
||||||
|
import org.nl.modules.system.service.dto.DeptTree;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
@@ -52,7 +54,7 @@ public class DeptController {
|
|||||||
@GetMapping
|
@GetMapping
|
||||||
@SaCheckPermission(value = {"user:list", "dept:list"}, mode = SaMode.AND)
|
@SaCheckPermission(value = {"user:list", "dept:list"}, mode = SaMode.AND)
|
||||||
public ResponseEntity<Object> query(DeptQueryCriteria criteria) throws Exception {
|
public ResponseEntity<Object> query(DeptQueryCriteria criteria) throws Exception {
|
||||||
List<DeptDto> deptDtos = deptService.queryAll(criteria, true);
|
List<Dept> deptDtos = deptService.queryAll(criteria, true);
|
||||||
return new ResponseEntity<>(PageUtil.toPage(deptDtos, deptDtos.size()),HttpStatus.OK);
|
return new ResponseEntity<>(PageUtil.toPage(deptDtos, deptDtos.size()),HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,11 +62,11 @@ public class DeptController {
|
|||||||
@PostMapping("/superior")
|
@PostMapping("/superior")
|
||||||
@SaCheckPermission(value = {"user:list", "dept:list"}, mode = SaMode.AND)
|
@SaCheckPermission(value = {"user:list", "dept:list"}, mode = SaMode.AND)
|
||||||
public ResponseEntity<Object> getSuperior(@RequestBody List<Long> ids) {
|
public ResponseEntity<Object> getSuperior(@RequestBody List<Long> ids) {
|
||||||
Set<DeptDto> deptDtos = new LinkedHashSet<>();
|
Set<DeptTree> deptDtos = new LinkedHashSet<>();
|
||||||
for (Long id : ids) {
|
for (Long id : ids) {
|
||||||
DeptDto deptDto = deptService.findById(id);
|
DeptTree deptTree = deptService.findById(id, DeptTree.class);
|
||||||
List<DeptDto> depts = deptService.getSuperior(deptDto, new ArrayList<>());
|
List<DeptTree> superior = deptService.getSuperior(deptTree, new ArrayList<>());
|
||||||
deptDtos.addAll(depts);
|
deptDtos.addAll(superior);
|
||||||
}
|
}
|
||||||
return new ResponseEntity<>(deptService.buildTree(new ArrayList<>(deptDtos)),HttpStatus.OK);
|
return new ResponseEntity<>(deptService.buildTree(new ArrayList<>(deptDtos)),HttpStatus.OK);
|
||||||
}
|
}
|
||||||
@@ -95,7 +97,7 @@ public class DeptController {
|
|||||||
@DeleteMapping
|
@DeleteMapping
|
||||||
@SaCheckPermission("dept:del")
|
@SaCheckPermission("dept:del")
|
||||||
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids){
|
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids){
|
||||||
Set<DeptDto> deptDtos = new HashSet<>();
|
Set<Dept> deptDtos = new HashSet<>();
|
||||||
for (Long id : ids) {
|
for (Long id : ids) {
|
||||||
List<Dept> deptList = deptService.findByPid(id);
|
List<Dept> deptList = deptService.findByPid(id);
|
||||||
deptDtos.add(deptService.findById(id));
|
deptDtos.add(deptService.findById(id));
|
||||||
|
|||||||
@@ -112,10 +112,11 @@ public class UserController {
|
|||||||
public ResponseEntity<Object> create(@Validated @RequestBody User resources){
|
public ResponseEntity<Object> create(@Validated @RequestBody User resources){
|
||||||
checkLevel(resources);
|
checkLevel(resources);
|
||||||
// 默认密码 123456
|
// 默认密码 123456
|
||||||
if (ObjectUtil.isEmpty(resources.getPassword()))
|
if (ObjectUtil.isEmpty(resources.getPassword())) {
|
||||||
resources.setPassword(SaSecureUtil.md5BySalt("123456", "salt"));
|
resources.setPassword(SaSecureUtil.md5BySalt("123456", "salt"));
|
||||||
else
|
} else {
|
||||||
resources.setPassword(SaSecureUtil.md5BySalt(resources.getPassword(), "salt"));
|
resources.setPassword(SaSecureUtil.md5BySalt(resources.getPassword(), "salt"));
|
||||||
|
}
|
||||||
userService.create(resources);
|
userService.create(resources);
|
||||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.nl.modules.system.service;
|
package org.nl.modules.system.service;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.formula.functions.T;
|
||||||
import org.nl.modules.system.domain.Dept;
|
import org.nl.modules.system.domain.Dept;
|
||||||
import org.nl.modules.system.service.dto.DeptDto;
|
import org.nl.modules.system.service.dto.DeptDto;
|
||||||
import org.nl.modules.system.service.dto.DeptQueryCriteria;
|
import org.nl.modules.system.service.dto.DeptQueryCriteria;
|
||||||
|
import org.nl.modules.system.service.dto.DeptTree;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -36,7 +38,7 @@ public interface DeptService {
|
|||||||
* @return /
|
* @return /
|
||||||
* @throws Exception /
|
* @throws Exception /
|
||||||
*/
|
*/
|
||||||
List<DeptDto> queryAll(DeptQueryCriteria criteria, Boolean isQuery) throws Exception;
|
List<Dept> queryAll(DeptQueryCriteria criteria, Boolean isQuery) throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取
|
* 获取
|
||||||
@@ -52,7 +54,9 @@ public interface DeptService {
|
|||||||
* @param id /
|
* @param id /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
DeptDto findById(Long id);
|
Dept findById(Long id);
|
||||||
|
|
||||||
|
List<Dept> findByPid(Long pid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建
|
* 创建
|
||||||
@@ -73,16 +77,14 @@ public interface DeptService {
|
|||||||
*
|
*
|
||||||
* @param deptDtos /
|
* @param deptDtos /
|
||||||
*/
|
*/
|
||||||
void delete(Set<DeptDto> deptDtos);
|
void delete(Set<Dept> deptDtos);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据PID查询
|
* 根据PID查询
|
||||||
*
|
*
|
||||||
* @param pid /
|
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
List<Dept> findByPid(long pid);
|
<T> T findById(Long id, Class<T> tagert);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据角色ID查询
|
* 根据角色ID查询
|
||||||
*
|
*
|
||||||
@@ -96,10 +98,9 @@ public interface DeptService {
|
|||||||
* 获取待删除的部门
|
* 获取待删除的部门
|
||||||
*
|
*
|
||||||
* @param deptList /
|
* @param deptList /
|
||||||
* @param deptDtos /
|
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
Set<DeptDto> getDeleteDepts(List<Dept> deptList, Set<DeptDto> deptDtos);
|
Set<Dept> getDeleteDepts(List<Dept> deptList, Set<Dept> depts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据ID获取同级与上级数据
|
* 根据ID获取同级与上级数据
|
||||||
@@ -108,7 +109,7 @@ public interface DeptService {
|
|||||||
* @param depts /
|
* @param depts /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
List<DeptDto> getSuperior(DeptDto deptDto, List<Dept> depts);
|
List<DeptTree> getSuperior(DeptTree deptDto, List<DeptTree> depts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建树形数据
|
* 构建树形数据
|
||||||
@@ -116,7 +117,7 @@ public interface DeptService {
|
|||||||
* @param deptDtos /
|
* @param deptDtos /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
Object buildTree(List<DeptDto> deptDtos);
|
Object buildTree(List<DeptTree> deptDtos);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -124,7 +125,7 @@ public interface DeptService {
|
|||||||
*
|
*
|
||||||
* @param deptDtos /
|
* @param deptDtos /
|
||||||
*/
|
*/
|
||||||
void verification(Set<DeptDto> deptDtos);
|
void verification(Set<Dept> deptDtos);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前节点的所有子类节点集合数据
|
* 获取当前节点的所有子类节点集合数据
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import org.nl.modules.common.annotation.DataPermission;
|
|||||||
import org.nl.modules.common.annotation.Query;
|
import org.nl.modules.common.annotation.Query;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,7 +38,7 @@ public class DeptQueryCriteria{
|
|||||||
private String code;
|
private String code;
|
||||||
|
|
||||||
@Query
|
@Query
|
||||||
private Boolean enabled;
|
private Boolean is_used;
|
||||||
|
|
||||||
@Query
|
@Query
|
||||||
private Long pid;
|
private Long pid;
|
||||||
@@ -46,5 +47,7 @@ public class DeptQueryCriteria{
|
|||||||
private Boolean pidIsNull;
|
private Boolean pidIsNull;
|
||||||
|
|
||||||
@Query(type = Query.Type.BETWEEN)
|
@Query(type = Query.Type.BETWEEN)
|
||||||
private List<Timestamp> createTime;
|
private Date startTime;
|
||||||
|
|
||||||
|
private Date endTime;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Zheng Jie
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.nl.modules.system.service.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.nl.modules.common.base.BaseDTO;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Zheng Jie
|
||||||
|
* @date 2019-03-25
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class DeptTree extends BaseDTO implements Serializable {
|
||||||
|
|
||||||
|
private Long Dept_id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private Boolean is_used;
|
||||||
|
|
||||||
|
private Integer dept_sort;
|
||||||
|
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||||
|
private List<DeptTree> children;
|
||||||
|
|
||||||
|
private Long pid;
|
||||||
|
|
||||||
|
private Integer sub_count;
|
||||||
|
|
||||||
|
private String versionId;
|
||||||
|
|
||||||
|
public Boolean getHasChildren() {
|
||||||
|
return sub_count > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getLeaf() {
|
||||||
|
return sub_count <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -16,12 +16,16 @@
|
|||||||
package org.nl.modules.system.service.impl;
|
package org.nl.modules.system.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.db.Db;
|
import cn.hutool.db.Db;
|
||||||
import cn.hutool.db.Entity;
|
import cn.hutool.db.Entity;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.apache.poi.ss.formula.functions.T;
|
||||||
import org.nl.modules.common.exception.BadRequestException;
|
import org.nl.modules.common.exception.BadRequestException;
|
||||||
import org.nl.modules.common.utils.CacheKey;
|
import org.nl.modules.common.utils.CacheKey;
|
||||||
import org.nl.modules.common.utils.QueryHelp;
|
import org.nl.modules.common.utils.QueryHelp;
|
||||||
@@ -35,7 +39,11 @@ import org.nl.modules.system.repository.UserRepository;
|
|||||||
import org.nl.modules.system.service.DeptService;
|
import org.nl.modules.system.service.DeptService;
|
||||||
import org.nl.modules.system.service.dto.DeptDto;
|
import org.nl.modules.system.service.dto.DeptDto;
|
||||||
import org.nl.modules.system.service.dto.DeptQueryCriteria;
|
import org.nl.modules.system.service.dto.DeptQueryCriteria;
|
||||||
|
import org.nl.modules.system.service.dto.DeptTree;
|
||||||
import org.nl.modules.system.service.mapstruct.DeptMapper;
|
import org.nl.modules.system.service.mapstruct.DeptMapper;
|
||||||
|
import org.nl.modules.tools.MapOf;
|
||||||
|
import org.nl.modules.wql.WQL;
|
||||||
|
import org.nl.modules.wql.core.bean.ResultBean;
|
||||||
import org.nl.modules.wql.core.bean.WQLObject;
|
import org.nl.modules.wql.core.bean.WQLObject;
|
||||||
import org.nl.modules.wql.util.SpringContextHolder;
|
import org.nl.modules.wql.util.SpringContextHolder;
|
||||||
import org.springframework.cache.annotation.CacheConfig;
|
import org.springframework.cache.annotation.CacheConfig;
|
||||||
@@ -43,11 +51,13 @@ import org.springframework.cache.annotation.Cacheable;
|
|||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -66,52 +76,42 @@ public class DeptServiceImpl implements DeptService {
|
|||||||
private final RoleRepository roleRepository;
|
private final RoleRepository roleRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DeptDto> queryAll(DeptQueryCriteria criteria, Boolean isQuery) throws Exception {
|
public List<Dept> queryAll(DeptQueryCriteria criteria, Boolean isQuery) throws Exception {
|
||||||
Sort sort = Sort.by(Sort.Direction.ASC, "deptSort");
|
JSONObject o = (JSONObject) JSON.toJSON(criteria);
|
||||||
// String dataScopeType = SecurityUtils.getDataScopeType();
|
HashMap map = MapOf.of("name", MapUtil.getStr(o, "name")
|
||||||
if (isQuery) {
|
, "code", MapUtil.getStr(o, "code")
|
||||||
// if (dataScopeType.equals(DataScopeEnum.ALL.getValue())) {
|
, "is_used", MapUtil.getStr(o, "is_used")
|
||||||
criteria.setPidIsNull(true);
|
, "startTime", MapUtil.getStr(o, "startTime")
|
||||||
// }
|
, "endTime", MapUtil.getStr(o, "endTime")
|
||||||
List<Field> fields = QueryHelp.getAllFields(criteria.getClass(), new ArrayList<>());
|
, "pid", MapUtil.getStr(o, "pid")
|
||||||
List<String> fieldNames = new ArrayList<String>() {{
|
, "pidIsNull", MapUtil.getStr(o, "pidIsNull")
|
||||||
add("pidIsNull");
|
);
|
||||||
add("enabled");
|
JSONArray array = WQL.getWO("SYS_DEPT").addParamMap(map).process().getResultJSONArray(0);
|
||||||
}};
|
return array.toJavaList(Dept.class);
|
||||||
for (Field field : fields) {
|
|
||||||
//设置对象的访问权限,保证对private的属性的访问
|
|
||||||
field.setAccessible(true);
|
|
||||||
Object val = field.get(criteria);
|
|
||||||
if (fieldNames.contains(field.getName())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (ObjectUtil.isNotNull(val)) {
|
|
||||||
criteria.setPidIsNull(null);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
List<DeptDto> list = deptMapper.toDto(deptRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), sort));
|
|
||||||
// 如果为空,就代表为自定义权限或者本级权限,就需要去重,不理解可以注释掉,看查询结果
|
|
||||||
// if (StrUtil.isEmpty(dataScopeType)) {
|
|
||||||
// return deduplication(list);
|
|
||||||
// }
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Cacheable(key = "'id:' + #p0")
|
public <T> T findById(Long id,Class<T> tagert) {
|
||||||
public DeptDto findById(Long id) {
|
if (id==null){
|
||||||
Dept dept = deptRepository.findById(id).orElseGet(Dept::new);
|
return null;
|
||||||
ValidationUtil.isNull(dept.getDept_id(), "Dept", "id", id);
|
}
|
||||||
return deptMapper.toDto(dept);
|
JSONObject result = WQLObject.getWQLObject("sys_dept").query("dept_id ='" + id + "'").uniqueResult(0);
|
||||||
|
return result.toJavaObject(tagert);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Dept> findByPid(long pid) {
|
public Dept findById(Long id) {
|
||||||
return deptRepository.findByPid(pid);
|
JSONObject result = WQLObject.getWQLObject("sys_dept").query("dept_id ='" + id + "'").uniqueResult(0);
|
||||||
|
return result.toJavaObject(Dept.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Dept> findByPid(Long pid) {
|
||||||
|
JSONArray result = WQLObject.getWQLObject("sys_dept").query("pid ='" + pid + "'").getResultJSONArray(0);
|
||||||
|
return result.toJavaList(Dept.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Dept> findByRoleId(Long id) {
|
public Set<Dept> findByRoleId(Long id) {
|
||||||
return deptRepository.findByRoleId(id);
|
return deptRepository.findByRoleId(id);
|
||||||
@@ -120,9 +120,9 @@ public class DeptServiceImpl implements DeptService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void create(Dept resources) {
|
public void create(Dept resources) {
|
||||||
deptRepository.save(resources);
|
WQLObject.getWQLObject("sys_user").insert((JSONObject)JSON.toJSON(resources));
|
||||||
// 计算子节点数目
|
// 计算子节点数目
|
||||||
resources.setSubCount(0);
|
resources.setSub_count(0);
|
||||||
// 清理缓存
|
// 清理缓存
|
||||||
updateSubCnt(resources.getPid());
|
updateSubCnt(resources.getPid());
|
||||||
}
|
}
|
||||||
@@ -136,10 +136,9 @@ public class DeptServiceImpl implements DeptService {
|
|||||||
if (resources.getPid() != null && resources.getDept_id().equals(resources.getPid())) {
|
if (resources.getPid() != null && resources.getDept_id().equals(resources.getPid())) {
|
||||||
throw new BadRequestException("上级不能为自己");
|
throw new BadRequestException("上级不能为自己");
|
||||||
}
|
}
|
||||||
Dept dept = deptRepository.findById(resources.getDept_id()).orElseGet(Dept::new);
|
Dept dept = findById(resources.getDept_id());
|
||||||
ValidationUtil.isNull(dept.getDept_id(), "Dept", "id", resources.getDept_id());
|
|
||||||
resources.setDept_id(dept.getDept_id());
|
resources.setDept_id(dept.getDept_id());
|
||||||
deptRepository.save(resources);
|
WQLObject.getWQLObject("sys_user").update((JSONObject)JSON.toJSON(resources),"dept_id = '"+resources.getDept_id()+"'");
|
||||||
// 更新父节点中子节点数目
|
// 更新父节点中子节点数目
|
||||||
updateSubCnt(oldPid);
|
updateSubCnt(oldPid);
|
||||||
updateSubCnt(newPid);
|
updateSubCnt(newPid);
|
||||||
@@ -149,19 +148,22 @@ public class DeptServiceImpl implements DeptService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void delete(Set<DeptDto> deptDtos) {
|
public void delete(Set<Dept> deptDtos) {
|
||||||
for (DeptDto deptDto : deptDtos) {
|
if (!CollectionUtils.isEmpty(deptDtos)){
|
||||||
|
String collectSql = deptDtos.stream().map(a -> String.valueOf(a.getDept_id())).collect(Collectors.joining("','"));
|
||||||
|
WQLObject.getWQLObject("sys_user").delete("dept_id in ('" + collectSql + "')");
|
||||||
|
for (Dept deptDto : deptDtos) {
|
||||||
// 清理缓存
|
// 清理缓存
|
||||||
delCaches(deptDto.getId());
|
delCaches(deptDto.getDept_id());
|
||||||
deptRepository.deleteById(deptDto.getId());
|
|
||||||
updateSubCnt(deptDto.getPid());
|
updateSubCnt(deptDto.getPid());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<DeptDto> getDeleteDepts(List<Dept> menuList, Set<DeptDto> deptDtos) {
|
public Set<Dept> getDeleteDepts(List<Dept> menuList, Set<Dept> deptDtos) {
|
||||||
for (Dept dept : menuList) {
|
for (Dept dept : menuList) {
|
||||||
deptDtos.add(deptMapper.toDto(dept));
|
deptDtos.add(dept);
|
||||||
List<Dept> depts = deptRepository.findByPid(dept.getDept_id());
|
List<Dept> depts = deptRepository.findByPid(dept.getDept_id());
|
||||||
if (depts != null && depts.size() != 0) {
|
if (depts != null && depts.size() != 0) {
|
||||||
getDeleteDepts(depts, deptDtos);
|
getDeleteDepts(depts, deptDtos);
|
||||||
@@ -171,28 +173,27 @@ public class DeptServiceImpl implements DeptService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DeptDto> getSuperior(DeptDto deptDto, List<Dept> depts) {
|
public List<DeptTree> getSuperior(DeptTree deptDto, List<DeptTree> depts) {
|
||||||
|
depts.add(deptDto);
|
||||||
if (deptDto.getPid() == null) {
|
if (deptDto.getPid() == null) {
|
||||||
depts.addAll(deptRepository.findByPidIsNull());
|
return depts;
|
||||||
return deptMapper.toDto(depts);
|
|
||||||
}
|
}
|
||||||
depts.addAll(deptRepository.findByPid(deptDto.getPid()));
|
return getSuperior(findById(deptDto.getPid(),DeptTree.class), depts);
|
||||||
return getSuperior(findById(deptDto.getPid()), depts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object buildTree(List<DeptDto> deptDtos) {
|
public Object buildTree(List<DeptTree> deptDtos) {
|
||||||
Set<DeptDto> trees = new LinkedHashSet<>();
|
Set<DeptTree> trees = new LinkedHashSet<>();
|
||||||
Set<DeptDto> depts = new LinkedHashSet<>();
|
Set<DeptTree> depts = new LinkedHashSet<>();
|
||||||
List<String> deptNames = deptDtos.stream().map(DeptDto::getName).collect(Collectors.toList());
|
List<String> deptNames = deptDtos.stream().map(DeptTree::getName).collect(Collectors.toList());
|
||||||
boolean isChild;
|
boolean isChild;
|
||||||
for (DeptDto deptDTO : deptDtos) {
|
for (DeptTree deptDTO : deptDtos) {
|
||||||
isChild = false;
|
isChild = false;
|
||||||
if (deptDTO.getPid() == null) {
|
if (deptDTO.getPid() == null) {
|
||||||
trees.add(deptDTO);
|
trees.add(deptDTO);
|
||||||
}
|
}
|
||||||
for (DeptDto it : deptDtos) {
|
for (DeptTree it : deptDtos) {
|
||||||
if (it.getPid() != null && deptDTO.getId().equals(it.getPid())) {
|
if (it.getPid() != null && deptDTO.getDept_id().equals(it.getPid())) {
|
||||||
isChild = true;
|
isChild = true;
|
||||||
if (deptDTO.getChildren() == null) {
|
if (deptDTO.getChildren() == null) {
|
||||||
deptDTO.setChildren(new ArrayList<>());
|
deptDTO.setChildren(new ArrayList<>());
|
||||||
@@ -217,21 +218,21 @@ public class DeptServiceImpl implements DeptService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void verification(Set<DeptDto> deptDtos) {
|
public void verification(Set<Dept> deptDtos) {
|
||||||
Set<Long> deptIds = deptDtos.stream().map(DeptDto::getId).collect(Collectors.toSet());
|
if (!CollectionUtils.isEmpty(deptDtos)){
|
||||||
if (userRepository.countByDepts(deptIds) > 0) {
|
String collectSql = deptDtos.stream().map(a -> String.valueOf(a.getDept_id())).collect(Collectors.joining("','"));
|
||||||
throw new BadRequestException("所选部门存在用户关联,请解除后再试!");
|
ResultBean result = WQLObject.getWQLObject("sys_user_dept").query("dept_id in ('" + collectSql + "')");
|
||||||
|
if (result.getResultCount()>0){
|
||||||
|
throw new BadRequestException("部门存在绑定的人员,请先解绑人员对应部门");
|
||||||
}
|
}
|
||||||
if (roleRepository.countByDepts(deptIds) > 0) {
|
|
||||||
throw new BadRequestException("所选部门存在角色关联,请解除后再试!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void updateSubCnt(Long deptId) {
|
private void updateSubCnt(Long deptId) {
|
||||||
if (deptId != null) {
|
if (deptId != null) {
|
||||||
int count = deptRepository.countByPid(deptId);
|
List<Dept> byPid = findByPid(deptId);
|
||||||
deptRepository.updateSubCntById(count, deptId);
|
WQLObject.getWQLObject("sys_user").update(MapOf.of("sub_count",byPid.size()),"dept_id = '"+deptId+"'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,7 +269,7 @@ public class DeptServiceImpl implements DeptService {
|
|||||||
public List<Long> getDeptChildren(List<Dept> deptList) {
|
public List<Long> getDeptChildren(List<Dept> deptList) {
|
||||||
List<Long> list = new ArrayList<>();
|
List<Long> list = new ArrayList<>();
|
||||||
deptList.forEach(dept -> {
|
deptList.forEach(dept -> {
|
||||||
if (dept != null && dept.getEnabled()) {
|
if (dept != null && dept.getIs_used()) {
|
||||||
List<Dept> depts = deptRepository.findByPid(dept.getDept_id());
|
List<Dept> depts = deptRepository.findByPid(dept.getDept_id());
|
||||||
if (deptList.size() != 0) {
|
if (deptList.size() != 0) {
|
||||||
list.addAll(getDeptChildren(depts));
|
list.addAll(getDeptChildren(depts));
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public class DictServiceImpl implements DictService {
|
|||||||
map.put("字典描述", dictDTO.getDescription());
|
map.put("字典描述", dictDTO.getDescription());
|
||||||
map.put("字典标签", dictDetail.getLabel());
|
map.put("字典标签", dictDetail.getLabel());
|
||||||
map.put("字典值", dictDetail.getValue());
|
map.put("字典值", dictDetail.getValue());
|
||||||
map.put("创建日期", dictDetail.getCreateTime());
|
map.put("创建日期", dictDetail.getCreate_time());
|
||||||
list.add(map);
|
list.add(map);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -109,7 +109,7 @@ public class DictServiceImpl implements DictService {
|
|||||||
map.put("字典描述", dictDTO.getDescription());
|
map.put("字典描述", dictDTO.getDescription());
|
||||||
map.put("字典标签", null);
|
map.put("字典标签", null);
|
||||||
map.put("字典值", null);
|
map.put("字典值", null);
|
||||||
map.put("创建日期", dictDTO.getCreateTime());
|
map.put("创建日期", dictDTO.getCreate_time());
|
||||||
list.add(map);
|
list.add(map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ public class RoleServiceImpl implements RoleService {
|
|||||||
map.put("角色名称", role.getName());
|
map.put("角色名称", role.getName());
|
||||||
map.put("角色级别", role.getLevel());
|
map.put("角色级别", role.getLevel());
|
||||||
map.put("描述", role.getDescription());
|
map.put("描述", role.getDescription());
|
||||||
map.put("创建日期", role.getCreateTime());
|
map.put("创建日期", role.getCreate_time());
|
||||||
list.add(map);
|
list.add(map);
|
||||||
}
|
}
|
||||||
FileUtil.downloadExcel(list, response);
|
FileUtil.downloadExcel(list, response);
|
||||||
|
|||||||
@@ -131,8 +131,8 @@ public class LocalStorageServiceImpl implements LocalStorageService {
|
|||||||
map.put("备注名", localStorageDTO.getName());
|
map.put("备注名", localStorageDTO.getName());
|
||||||
map.put("文件类型", localStorageDTO.getType());
|
map.put("文件类型", localStorageDTO.getType());
|
||||||
map.put("文件大小", localStorageDTO.getSize());
|
map.put("文件大小", localStorageDTO.getSize());
|
||||||
map.put("创建者", localStorageDTO.getCreateBy());
|
map.put("创建者", localStorageDTO.getCreate_name());
|
||||||
map.put("创建日期", localStorageDTO.getCreateTime());
|
map.put("创建日期", localStorageDTO.getCreate_time());
|
||||||
list.add(map);
|
list.add(map);
|
||||||
}
|
}
|
||||||
FileUtil.downloadExcel(list, response);
|
FileUtil.downloadExcel(list, response);
|
||||||
|
|||||||
Reference in New Issue
Block a user