Compare commits
4 Commits
9e97575a54
...
6d41c1ddef
| Author | SHA1 | Date |
|---|---|---|
|
|
6d41c1ddef | |
|
|
0df66f733c | |
|
|
781d104afb | |
|
|
e5126b4a95 |
|
|
@ -311,14 +311,14 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
|||
}
|
||||
|
||||
curreCharIsUpperCase = Character.isUpperCase(c);
|
||||
|
||||
boolean isB=((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase);
|
||||
if (i < (str.length() - 1)) {
|
||||
nexteCharIsUpperCase = Character.isUpperCase(str.charAt(i + 1));
|
||||
}
|
||||
|
||||
if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase) {
|
||||
sb.append(SEPARATOR);
|
||||
} else if ((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase) {
|
||||
} else if (isB) {
|
||||
sb.append(SEPARATOR);
|
||||
}
|
||||
sb.append(Character.toLowerCase(c));
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package com.securitycontrol.common.core.utils.aes;
|
||||
|
||||
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* @author HeiZi
|
||||
|
|
@ -37,4 +39,14 @@ public class ListHelper {
|
|||
return strs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 集合校验
|
||||
* @param keyExtractor
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
|
||||
Map<Object, Boolean> seen = new ConcurrentHashMap<>(10);
|
||||
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -312,50 +312,8 @@ public class ExcelUtil<T>
|
|||
Excel attr = (Excel) entry.getValue()[1];
|
||||
// 取得类型,并根据对象类型设置值.
|
||||
Class<?> fieldType = field.getType();
|
||||
if (String.class == fieldType) {
|
||||
String s = Convert.toStr(val);
|
||||
if (StringUtils.endsWith(s, ".0")) {
|
||||
val = StringUtils.substringBefore(s, ".0");
|
||||
} else {
|
||||
String dateFormat = field.getAnnotation(Excel.class).dateFormat();
|
||||
if (StringUtils.isNotEmpty(dateFormat)) {
|
||||
val = parseDateToStr(dateFormat, val);
|
||||
} else {
|
||||
val = Convert.toStr(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((Integer.TYPE == fieldType || Integer.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val))) {
|
||||
val = Convert.toInt(val);
|
||||
} else if ((Long.TYPE == fieldType || Long.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val))) {
|
||||
val = Convert.toLong(val);
|
||||
} else if (Double.TYPE == fieldType || Double.class == fieldType) {
|
||||
val = Convert.toDouble(val);
|
||||
} else if (Float.TYPE == fieldType || Float.class == fieldType) {
|
||||
val = Convert.toFloat(val);
|
||||
} else if (BigDecimal.class == fieldType) {
|
||||
val = Convert.toBigDecimal(val);
|
||||
} else if (Date.class == fieldType) {
|
||||
if (val instanceof String) {
|
||||
val = DateTimeHelper.parseDates(val);
|
||||
} else if (val instanceof Double) {
|
||||
val = DateUtil.getJavaDate((Double) val);
|
||||
}
|
||||
} else if (Boolean.TYPE == fieldType || Boolean.class == fieldType) {
|
||||
val = Convert.toBool(val, false);
|
||||
}if (StringUtils.isNotNull(fieldType)) {
|
||||
String propertyName = field.getName();
|
||||
if (StringUtils.isNotEmpty(attr.targetAttr())) {
|
||||
propertyName = field.getName() + "." + attr.targetAttr();
|
||||
} else if (StringUtils.isNotEmpty(attr.readConverterExp())) {
|
||||
val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator());
|
||||
}
|
||||
else if (!attr.handler().equals(ExcelHandlerAdapter.class))
|
||||
{
|
||||
val = dataFormatHandlerAdapter(val, attr);
|
||||
}
|
||||
ReflectUtils.invokeSetter(entity, propertyName, val);
|
||||
}
|
||||
val=fileTypeSetData(fieldType,field,val);
|
||||
fileTypeIsNotNull(fieldType,field,attr,val,entity);
|
||||
}
|
||||
list.add(entity);
|
||||
}
|
||||
|
|
@ -363,6 +321,64 @@ public class ExcelUtil<T>
|
|||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String endIndex=".0";
|
||||
|
||||
public Object fileTypeSetData(Class<?> fieldType,Field field, Object val){
|
||||
boolean isNum=StringUtils.isNumeric(Convert.toStr(val));
|
||||
boolean isLong=(Long.TYPE == fieldType || Long.class == fieldType);
|
||||
boolean isInt=(Integer.TYPE == fieldType || Integer.class == fieldType);
|
||||
if (String.class == fieldType) {
|
||||
String s = Convert.toStr(val);
|
||||
if (StringUtils.endsWith(s, endIndex)) {
|
||||
val = StringUtils.substringBefore(s, endIndex);
|
||||
} else {
|
||||
String dateFormat = field.getAnnotation(Excel.class).dateFormat();
|
||||
if (StringUtils.isNotEmpty(dateFormat)) {
|
||||
val = parseDateToStr(dateFormat, val);
|
||||
} else {
|
||||
val = Convert.toStr(val);
|
||||
}
|
||||
}
|
||||
} else if (isInt && isNum) {
|
||||
val = Convert.toInt(val);
|
||||
} else if (isLong && isNum) {
|
||||
val = Convert.toLong(val);
|
||||
} else if (Double.TYPE == fieldType || Double.class == fieldType) {
|
||||
val = Convert.toDouble(val);
|
||||
} else if (Float.TYPE == fieldType || Float.class == fieldType) {
|
||||
val = Convert.toFloat(val);
|
||||
} else if (BigDecimal.class == fieldType) {
|
||||
val = Convert.toBigDecimal(val);
|
||||
} else if (Date.class == fieldType) {
|
||||
if (val instanceof String) {
|
||||
val = DateTimeHelper.parseDates(val);
|
||||
} else if (val instanceof Double) {
|
||||
val = DateUtil.getJavaDate((Double) val);
|
||||
}
|
||||
} else if (Boolean.TYPE == fieldType || Boolean.class == fieldType) {
|
||||
val = Convert.toBool(val, false);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
public void fileTypeIsNotNull( Class<?> type,Field field, Excel attr, Object val, T entity) {
|
||||
if(StringUtils.isNotNull(type)){
|
||||
String propertyName = field.getName();
|
||||
if (StringUtils.isNotEmpty(attr.targetAttr())) {
|
||||
propertyName = field.getName() + "." + attr.targetAttr();
|
||||
} else if (StringUtils.isNotEmpty(attr.readConverterExp())) {
|
||||
val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator());
|
||||
}
|
||||
else if (!attr.handler().equals(ExcelHandlerAdapter.class))
|
||||
{
|
||||
val = dataFormatHandlerAdapter(val, attr);
|
||||
}
|
||||
ReflectUtils.invokeSetter(entity, propertyName, val);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 对list数据源将其里面的数据导入到excel表单
|
||||
*
|
||||
|
|
@ -1175,10 +1191,12 @@ public class ExcelUtil<T>
|
|||
if (field.isAnnotationPresent(Excel.class))
|
||||
{
|
||||
Excel attr = field.getAnnotation(Excel.class);
|
||||
if (attr != null && (attr.type() == Type.ALL || attr.type() == type))
|
||||
{
|
||||
field.setAccessible(true);
|
||||
fields.add(new Object[] { field, attr });
|
||||
if (attr != null) {
|
||||
boolean typeTrue=(attr.type() == Type.ALL || attr.type() == type);
|
||||
if(typeTrue){
|
||||
field.setAccessible(true);
|
||||
fields.add(new Object[] { field, attr });
|
||||
}
|
||||
}
|
||||
if (Collection.class.isAssignableFrom(field.getType()))
|
||||
{
|
||||
|
|
@ -1188,19 +1206,19 @@ public class ExcelUtil<T>
|
|||
this.subFields = FieldUtils.getFieldsListWithAnnotation(subClass, Excel.class);
|
||||
}
|
||||
}
|
||||
|
||||
// 多注解
|
||||
if (field.isAnnotationPresent(Excels.class))
|
||||
{
|
||||
if (field.isAnnotationPresent(Excels.class)) {
|
||||
Excels attrs = field.getAnnotation(Excels.class);
|
||||
Excel[] excels = attrs.value();
|
||||
for (Excel attr : excels)
|
||||
{
|
||||
if (attr != null && (attr.type() == Type.ALL || attr.type() == type))
|
||||
{
|
||||
field.setAccessible(true);
|
||||
fields.add(new Object[] { field, attr });
|
||||
for (Excel attr : excels) {
|
||||
if (attr != null) {
|
||||
boolean typeTrue=(attr.type() == Type.ALL || attr.type() == type);
|
||||
if(typeTrue){
|
||||
field.setAccessible(true);
|
||||
fields.add(new Object[] { field, attr });
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -306,12 +306,14 @@ public class ReflectUtils
|
|||
/**
|
||||
* 改变private/protected的方法为public,尽量不调用实际改动的语句,避免JDK的SecurityManager抱怨。
|
||||
*/
|
||||
public static void makeAccessible(Method method)
|
||||
{
|
||||
if ((!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers()))
|
||||
&& !method.isAccessible())
|
||||
{
|
||||
method.setAccessible(true);
|
||||
public static void makeAccessible(Method method) {
|
||||
boolean isPublic=!Modifier.isPublic(method.getModifiers());
|
||||
boolean isPublic2=!Modifier.isPublic(method.getDeclaringClass().getModifiers());
|
||||
if (isPublic || isPublic2) {
|
||||
if(!method.isAccessible()){
|
||||
method.setAccessible(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -320,10 +322,14 @@ public class ReflectUtils
|
|||
*/
|
||||
public static void makeAccessible(Field field)
|
||||
{
|
||||
if ((!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers())
|
||||
|| Modifier.isFinal(field.getModifiers())) && !field.isAccessible())
|
||||
{
|
||||
field.setAccessible(true);
|
||||
boolean isPublic=!Modifier.isPublic(field.getModifiers());
|
||||
boolean isPublic2=!Modifier.isPublic(field.getDeclaringClass().getModifiers());
|
||||
boolean isPublic3=Modifier.isFinal(field.getModifiers());
|
||||
if (isPublic || isPublic2 || isPublic3){
|
||||
if(!field.isAccessible()){
|
||||
field.setAccessible(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,15 @@
|
|||
package com.securitycontrol.entity.system.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 字典查询
|
||||
* @author HeiZi
|
||||
*/
|
||||
@Data
|
||||
public class DictDto {
|
||||
|
||||
private String keyWord;
|
||||
|
||||
private String dictId;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,59 @@
|
|||
package com.securitycontrol.entity.system.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典管理 实体类
|
||||
* @author HeiZi
|
||||
*/
|
||||
@Data
|
||||
public class DictVo {
|
||||
/**字典id*/
|
||||
private Integer dictId;
|
||||
|
||||
/**
|
||||
* 字典编码
|
||||
*/
|
||||
private Integer dictCode;
|
||||
|
||||
/**
|
||||
* 上级节点编码
|
||||
*/
|
||||
private Integer pidCode;
|
||||
|
||||
/**
|
||||
* 字典名称
|
||||
*/
|
||||
|
||||
@NotBlank(message = "字典名称不能为空")
|
||||
@Length(max = 100,message = "字典名称长度不能超过100个字符")
|
||||
private String dictName;
|
||||
/**
|
||||
* 字典值
|
||||
*/
|
||||
private Integer dictValue;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Length(max = 100,message = "备注长度不能超过100个字符")
|
||||
private String remarks;
|
||||
/**
|
||||
* 是否删除
|
||||
*/
|
||||
private Integer delFlag;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private String createTime;
|
||||
/**
|
||||
* 子节点
|
||||
*/
|
||||
private List<DictVo> children;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -33,9 +33,10 @@ public class InnerAuthAspect implements Ordered
|
|||
String userid = ServletUtils.getRequest().getHeader(SecurityConstants.DETAILS_USER_ID);
|
||||
String username = ServletUtils.getRequest().getHeader(SecurityConstants.DETAILS_USERNAME);
|
||||
// 用户信息验证
|
||||
if (innerAuth.isUser() && (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username)))
|
||||
{
|
||||
throw new InnerAuthException("没有设置用户信息,不允许访问 ");
|
||||
if (innerAuth.isUser()) {
|
||||
if(StringUtils.isEmpty(userid) || StringUtils.isEmpty(username)){
|
||||
throw new InnerAuthException("没有设置用户信息,不允许访问 ");
|
||||
}
|
||||
}
|
||||
return point.proceed();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,5 +41,11 @@ public class SelectController extends BaseController {
|
|||
public AjaxResult getMenuTree(MenuDto dto){
|
||||
return service.getMenuTree(dto);
|
||||
}
|
||||
@ApiOperation(value = "字典下拉选")
|
||||
@PostMapping("getDictList")
|
||||
public AjaxResult getDictList(Integer code){
|
||||
return service.getDictList(code);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.securitycontrol.system.base.mapper;
|
|||
|
||||
import com.securitycontrol.entity.system.vo.SelectVo;
|
||||
import com.securitycontrol.entity.system.vo.TreeNode;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -43,4 +44,12 @@ public interface ISelectMapper {
|
|||
* @date 2024/2/26 13:35
|
||||
*/
|
||||
List<TreeNode> getMenuTree();
|
||||
|
||||
|
||||
/**
|
||||
* 查询字典下拉选
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
List<TreeNode> getDictList(@Param("code") Integer code);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,4 +39,12 @@ public interface ISelectService {
|
|||
* @date 2024/2/26 13:33
|
||||
*/
|
||||
AjaxResult getMenuTree(MenuDto dto);
|
||||
|
||||
/**
|
||||
* 查询字典集合
|
||||
* code 上级节点编码 null市查询全部
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
AjaxResult getDictList(Integer code);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,4 +72,25 @@ public class SelectServiceImpl implements ISelectService {
|
|||
}
|
||||
return AjaxResult.success(groupList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 字典下拉选
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult getDictList(Integer code) {
|
||||
List<TreeNode> groupList = new ArrayList<>();
|
||||
try {
|
||||
List<TreeNode> list = mapper.getDictList(code);
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
// 创建树形结构(数据集合作为参数)
|
||||
groupList= TreeBuild.transTreeList(list);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("组织机构树-查询失败", e);
|
||||
}
|
||||
return AjaxResult.success(groupList);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,15 @@
|
|||
package com.securitycontrol.system.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.securitycontrol.common.core.domain.Result;
|
||||
import com.securitycontrol.common.core.web.controller.BaseController;
|
||||
import com.securitycontrol.entity.system.dto.DictDto;
|
||||
import com.securitycontrol.entity.system.vo.DictVo;
|
||||
import com.securitycontrol.system.service.DictService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典管理层
|
||||
|
|
@ -9,5 +17,68 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/dict/")
|
||||
public class DictController {
|
||||
public class DictController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private DictService service;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("getDictList")
|
||||
public Result<List<DictVo>> getDictList(@Valid DictDto dto) {
|
||||
return service.getDictList(dto);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 新增組織機構
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("addDict")
|
||||
public Result<String> addDict(@RequestBody @Valid DictVo dto) {
|
||||
return service.addDict(dto);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*修改组织机构
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("updateDict")
|
||||
public Result<String> updateDict(@RequestBody @Valid DictVo dto) {
|
||||
return service.updateDict(dto);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增組織機構
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("delDict")
|
||||
public Result<String> delDict(@RequestBody DictDto dto) {
|
||||
return service.delDict(dto);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增組織機構
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("getDetails/{id}")
|
||||
public Result<DictVo> getDetails(@PathVariable("id")String id) {
|
||||
return service.getDetails(id);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,64 @@
|
|||
package com.securitycontrol.system.mapper;
|
||||
|
||||
import com.securitycontrol.entity.system.dto.DictDto;
|
||||
import com.securitycontrol.entity.system.vo.DictVo;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典管理接口层
|
||||
* @author HeiZi
|
||||
*/
|
||||
@Repository
|
||||
public interface DictMapper {
|
||||
|
||||
/**
|
||||
* 查询字典数据的集合
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
List<DictVo> getDictList(DictDto dto);
|
||||
|
||||
/**
|
||||
* 查询code编码数量
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
int getNumByCode(DictVo dto);
|
||||
|
||||
/**
|
||||
* 新增字典编码
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
int addDict(DictVo dto);
|
||||
|
||||
/**
|
||||
* 修改字典
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
int updateDict(DictVo dto);
|
||||
|
||||
/**
|
||||
* 查询子节点数量
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
int getChildNum(DictDto dto);
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
int delDict(DictDto dto);
|
||||
|
||||
/**
|
||||
* 查询数据
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
DictVo getDetails(String id);
|
||||
}
|
||||
|
|
@ -1,4 +1,49 @@
|
|||
package com.securitycontrol.system.service;
|
||||
|
||||
public interface DictService {
|
||||
import com.securitycontrol.common.core.domain.Result;
|
||||
import com.securitycontrol.entity.system.dto.DictDto;
|
||||
import com.securitycontrol.entity.system.vo.DictVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典管理
|
||||
* @author HeiZi
|
||||
*/
|
||||
public interface DictService {
|
||||
/**
|
||||
* 查询字典集合
|
||||
* 通过trer 集合模式
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
Result<List<DictVo>> getDictList(DictDto dto);
|
||||
|
||||
/**
|
||||
* 新增 字典管理
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
Result<String> addDict(DictVo dto);
|
||||
|
||||
/**
|
||||
* 修改字典数据
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
Result<String> updateDict(DictVo dto);
|
||||
|
||||
/**
|
||||
* 删除字典数据
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
Result<String> delDict(DictDto dto);
|
||||
|
||||
/**
|
||||
* 查询字典数据详情
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
Result<DictVo> getDetails(String id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,203 @@
|
|||
package com.securitycontrol.system.service;
|
||||
|
||||
public class DictServiceImpl {
|
||||
import com.securitycontrol.common.core.domain.Result;
|
||||
import com.securitycontrol.common.core.utils.aes.ListHelper;
|
||||
import com.securitycontrol.common.core.utils.aes.StringHelper;
|
||||
import com.securitycontrol.entity.system.dto.DictDto;
|
||||
import com.securitycontrol.entity.system.vo.DictVo;
|
||||
import com.securitycontrol.system.mapper.DictMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* 字典管理业务层
|
||||
* @author HeiZi
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DictServiceImpl implements DictService {
|
||||
|
||||
@Resource
|
||||
private DictMapper mapper;
|
||||
|
||||
public final static int P_CODE=0;
|
||||
|
||||
public final static int MIN_NUM=0;
|
||||
|
||||
/**
|
||||
* 查询字典集合
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Result<List<DictVo>> getDictList(DictDto dto) {
|
||||
try{
|
||||
List<DictVo> list=mapper.getDictList(dto);
|
||||
if(ListHelper.isEmpty(list)){
|
||||
return Result.ok(new ArrayList<>());
|
||||
}
|
||||
if(StringHelper.isNotEmpty(dto.getKeyWord())){
|
||||
List<DictVo> allList = new ArrayList<>(list);
|
||||
List<DictVo> list2=mapper.getDictList(null);
|
||||
for (DictVo dictVo :list) {
|
||||
if(P_CODE!=dictVo.getPidCode()){
|
||||
getParentDict(dictVo.getPidCode(),list2,allList);
|
||||
}
|
||||
}
|
||||
allList=allList.stream().filter(ListHelper.distinctByKey(DictVo::getDictId)).collect(Collectors.toList());
|
||||
return Result.ok(getChildList(allList));
|
||||
}
|
||||
return Result.ok(getChildList(list));
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
return Result.ok(new ArrayList<>(),e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> addDict(DictVo dto) {
|
||||
try{
|
||||
if(dto.getPidCode()==null){
|
||||
dto.setPidCode(0);
|
||||
}
|
||||
Result<String> res=dataVerify(dto);
|
||||
if(res!=null){
|
||||
return res;
|
||||
}
|
||||
int num=mapper.addDict(dto);
|
||||
if(num>0){
|
||||
return Result.ok("新增成功");
|
||||
}
|
||||
return Result.fail("新增失败");
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
return Result.fail("服务异常",e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> updateDict(DictVo dto) {
|
||||
try{
|
||||
if(dto.getPidCode()==null){
|
||||
dto.setPidCode(0);
|
||||
}
|
||||
Result<String> res=dataVerify(dto);
|
||||
if(res!=null){
|
||||
return res;
|
||||
}
|
||||
int num=mapper.updateDict(dto);
|
||||
if(num>0){
|
||||
return Result.ok("修改成功");
|
||||
}
|
||||
return Result.fail("修改失败");
|
||||
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
return Result.fail("服务异常",e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> delDict(DictDto dto) {
|
||||
try {
|
||||
int childNum=mapper.getChildNum(dto);
|
||||
if(childNum>MIN_NUM){
|
||||
return Result.fail("请先删除子节点数据");
|
||||
}
|
||||
int num=mapper.delDict(dto);
|
||||
if(num>0){
|
||||
return Result.ok("删除成功");
|
||||
}
|
||||
return Result.fail("删除失败");
|
||||
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
return Result.fail("服务异常",e.toString());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<DictVo> getDetails(String id) {
|
||||
try{
|
||||
if(StringHelper.isEmpty(id)){
|
||||
return Result.fail("主键不存在");
|
||||
}
|
||||
DictVo vo=mapper.getDetails(id);
|
||||
return Result.ok(vo);
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
return Result.fail(new DictVo(),e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public Result<String> dataVerify(DictVo dictVo){
|
||||
DictVo dto=new DictVo();
|
||||
dto.setPidCode(dictVo.getPidCode());
|
||||
dto.setDictId(dictVo.getDictId());
|
||||
dto.setDictCode(dictVo.getDictCode());
|
||||
int codeNum=mapper.getNumByCode(dto);
|
||||
if(codeNum>MIN_NUM){
|
||||
return Result.fail("字典编码已存在");
|
||||
}
|
||||
if(P_CODE==dictVo.getDictCode()){
|
||||
return Result.fail("字典编码不能为0");
|
||||
}
|
||||
dto.setDictCode(null);
|
||||
dto.setDictName(dictVo.getDictName());
|
||||
dto.setPidCode(dictVo.getPidCode());
|
||||
int nameNum=mapper.getNumByCode(dto);
|
||||
if(nameNum>MIN_NUM){
|
||||
return Result.fail("字典名称已存在");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* 依据下级节点查询上级节点
|
||||
* @param pidCode
|
||||
* @param list
|
||||
* @param list2
|
||||
*/
|
||||
public void getParentDict(int pidCode, List<DictVo> list, List<DictVo> list2){
|
||||
DictVo vo= list.stream().filter(dictVo->pidCode==dictVo.getDictCode()).findFirst().orElse(null);
|
||||
assert vo != null;
|
||||
list2.add(vo);
|
||||
if(P_CODE!=vo.getPidCode()){
|
||||
getParentDict(vo.getPidCode(),list,list2);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 遍历获取
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
public List<DictVo> getChildList(List<DictVo> list){
|
||||
//map
|
||||
list.stream().map(orgVo -> {
|
||||
orgVo.setChildren(this.fromTree(orgVo, list));
|
||||
return orgVo;
|
||||
}).collect(Collectors.toList());
|
||||
//过滤出最上级的菜单
|
||||
return list.stream()
|
||||
.filter(ele -> P_CODE==ele.getPidCode())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
/**
|
||||
* 找寻指定菜单的下级菜单
|
||||
* @param dictVo 当前菜单
|
||||
* @param list 所有的菜单list
|
||||
* @return 下级菜单
|
||||
*/
|
||||
private List<DictVo> fromTree(DictVo dictVo, List<DictVo> list) {
|
||||
return list.stream()
|
||||
.filter(ele -> dictVo.getDictCode().toString().equals(ele.getPidCode().toString()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public class OrgServiceImpl implements OrgService{
|
|||
|
||||
|
||||
static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
|
||||
Map<Object, Boolean> seen = new ConcurrentHashMap<>();
|
||||
Map<Object, Boolean> seen = new ConcurrentHashMap<>(30);
|
||||
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
|
||||
}
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,73 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.securitycontrol.system.mapper.DictMapper">
|
||||
|
||||
<resultMap id="MenuMap" type="com.securitycontrol.entity.system.vo.DictVo">
|
||||
<id property="dictId" column="dict_id" />
|
||||
<result property="dictCode" column="dict_code"/>
|
||||
<result property="pidCode" column="p_code"/>
|
||||
<result property="dictName" column="dict_name"/>
|
||||
<result property="dictValue" column="dict_sort"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="remarks" column="remarks"/>
|
||||
</resultMap>
|
||||
|
||||
<!--查询 -->
|
||||
<select id="getDictList" resultMap="MenuMap">
|
||||
select dict_id,dict_code,dict_name,dict_sort,p_code,create_time,remarks
|
||||
from sys_dict
|
||||
where del_flag=0
|
||||
<if test="keyWord!=null and keyWord!=''">
|
||||
and(
|
||||
dict_name like concat('%',#{keyWord},'%')
|
||||
or dict_code =#{keyWord}
|
||||
)
|
||||
</if>
|
||||
order by dict_sort
|
||||
</select>
|
||||
<!--依据字典查询-->
|
||||
<select id="getNumByCode" resultType="java.lang.Integer">
|
||||
select count(1)
|
||||
from sys_dict
|
||||
where del_flag=0
|
||||
<if test="dictCode!=null and dictCode!='' and dictCode!=0 ">
|
||||
and dict_code=#{dictCode}
|
||||
</if>
|
||||
<if test="dictName!=null and dictName!=''">
|
||||
and dict_name=#{dictName} and p_code=#{pidCode}
|
||||
</if>
|
||||
<if test="dictId!=null and dictId!=''">
|
||||
and dict_id!=#{dictId}
|
||||
</if>
|
||||
</select>
|
||||
<!--子节点数量-->
|
||||
<select id="getChildNum" resultType="java.lang.Integer">
|
||||
select count(sd1.dict_id)
|
||||
from sys_dict sd1
|
||||
left join sys_dict sd2 on sd1.p_code=sd2.dict_code
|
||||
where sd1.del_flag=0 and sd2.dict_id=#{dictId}
|
||||
</select>
|
||||
<select id="getDetails" resultMap="MenuMap">
|
||||
select dict_id,dict_code,dict_name,dict_sort,p_code,create_time,remarks
|
||||
from sys_dict
|
||||
where del_flag=0 and dict_id=#{id}
|
||||
</select>
|
||||
<!--新增字典-->
|
||||
<insert id="addDict">
|
||||
insert into sys_dict (dict_code, dict_name, dict_sort, create_time, del_flag, remarks,p_code) value (
|
||||
#{dictCode},#{dictName},#{dictValue},now(),0,#{remarks},#{pidCode}
|
||||
)
|
||||
</insert>
|
||||
<!--修改-->
|
||||
<update id="updateDict">
|
||||
update sys_dict
|
||||
set dict_code=#{dictCode},dict_name=#{dictName},dict_sort=#{dictValue},remarks=#{remarks}
|
||||
where dict_id=#{dictId};
|
||||
</update>
|
||||
<!--删除-->
|
||||
<delete id="delDict">
|
||||
update sys_dict
|
||||
set p_code=1
|
||||
where dict_id=#{dictId};
|
||||
</delete>
|
||||
</mapper>
|
||||
|
|
@ -27,4 +27,14 @@
|
|||
FROM sys_menu
|
||||
WHERE del_flag = 0
|
||||
</select>
|
||||
<!--字典下拉选-->
|
||||
<select id="getDictList" resultType="com.securitycontrol.entity.system.vo.TreeNode">
|
||||
select dict_code as id, dict_name label, p_code AS parentId
|
||||
from sys_dict
|
||||
WHERE del_flag = 0
|
||||
<if test="code!=null and code!=''">
|
||||
and p_code=#{code}
|
||||
</if>
|
||||
ORDER BY dict_sort desc
|
||||
</select>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue