mirror of
https://gitee.com/lab1024/smart-admin.git
synced 2025-11-12 13:43:49 +08:00
v1.1.0
This commit is contained in:
@@ -21,7 +21,7 @@ public enum IdGeneratorEnum {
|
||||
|
||||
ORDER(1, "order");
|
||||
|
||||
private int id;
|
||||
private long id;
|
||||
private String keyName;
|
||||
|
||||
IdGeneratorEnum(int id, String keyName) {
|
||||
@@ -34,7 +34,7 @@ public enum IdGeneratorEnum {
|
||||
return "IdGeneratorEnum{" + "id=" + id + ", keyName='" + keyName + '\'' + '}';
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,12 @@ public class PrivilegeResponseCodeConst extends ResponseCodeConst {
|
||||
|
||||
public static final PrivilegeResponseCodeConst ROUTER_KEY_NO_REPEAT = new PrivilegeResponseCodeConst(7002, "模块和页面的“功能Key”值不能重复!");
|
||||
|
||||
public static final PrivilegeResponseCodeConst MENU_NOT_EXIST = new PrivilegeResponseCodeConst(7003, "菜单不存在,清先保存菜单!");
|
||||
|
||||
public static final PrivilegeResponseCodeConst POINT_NOT_EXIST = new PrivilegeResponseCodeConst(7004, "功能点不存在,清先保存功能点!");
|
||||
|
||||
public PrivilegeResponseCodeConst(int code, String msg) {
|
||||
super(code, msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,8 +41,8 @@ public class PrivilegeController {
|
||||
@ApiOperation(value = "菜单批量保存")
|
||||
@PostMapping("/privilege/menu/batchSaveMenu")
|
||||
public ResponseDTO<String> menuBatchSave(@Valid @RequestBody ValidateList<PrivilegeMenuDTO> menuList) {
|
||||
// return privilegeService.menuBatchSave(menuList);
|
||||
return ResponseDTO.succ();
|
||||
return privilegeService.menuBatchSave(menuList);
|
||||
// return ResponseDTO.succ();
|
||||
}
|
||||
|
||||
|
||||
@@ -56,10 +56,18 @@ public class PrivilegeController {
|
||||
@ApiOperation(value = "保存更新功能点")
|
||||
@PostMapping("/privilege/function/saveOrUpdate")
|
||||
public ResponseDTO<String> functionSaveOrUpdate(@Valid @RequestBody PrivilegeFunctionDTO privilegeFunctionDTO) {
|
||||
// return privilegeService.functionSaveOrUpdate(privilegeFunctionDTO);
|
||||
return ResponseDTO.succ();
|
||||
return privilegeService.functionSaveOrUpdate(privilegeFunctionDTO);
|
||||
// return ResponseDTO.succ();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "批量保存功能点")
|
||||
@PostMapping("/privilege/function/batchSave")
|
||||
public ResponseDTO<String> batchSaveFunctionList(@Valid @RequestBody ValidateList<PrivilegeFunctionDTO> functionList) {
|
||||
return privilegeService.batchSaveFunctionList(functionList);
|
||||
// return ResponseDTO.succ();
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "查询菜单功能点", notes = "更新")
|
||||
@PostMapping("/privilege/function/query/{menuKey}")
|
||||
public ResponseDTO<List<PrivilegeFunctionVO>> functionQuery(@PathVariable String menuKey) {
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
package net.lab1024.smartadmin.module.system.privilege.service;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import net.lab1024.smartadmin.common.domain.ResponseDTO;
|
||||
import net.lab1024.smartadmin.common.domain.ValidateList;
|
||||
import net.lab1024.smartadmin.module.system.privilege.constant.PrivilegeResponseCodeConst;
|
||||
import net.lab1024.smartadmin.module.system.privilege.constant.PrivilegeTypeEnum;
|
||||
import net.lab1024.smartadmin.module.system.privilege.dao.PrivilegeDao;
|
||||
import net.lab1024.smartadmin.module.system.privilege.domain.dto.*;
|
||||
import net.lab1024.smartadmin.module.system.privilege.domain.entity.PrivilegeEntity;
|
||||
import net.lab1024.smartadmin.module.system.role.roleprivilege.RolePrivilegeDao;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.lab1024.smartadmin.module.system.privilege.domain.dto.*;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -150,7 +149,7 @@ public class PrivilegeService {
|
||||
return ResponseDTO.succData(Lists.newArrayList());
|
||||
}
|
||||
|
||||
List<PrivilegeMenuVO> voList = privilegeEntityList.stream().map(e-> {
|
||||
List<PrivilegeMenuVO> voList = privilegeEntityList.stream().map(e -> {
|
||||
PrivilegeMenuVO vo = new PrivilegeMenuVO();
|
||||
vo.setMenuKey(e.getKey());
|
||||
vo.setMenuName(e.getName());
|
||||
@@ -174,23 +173,14 @@ public class PrivilegeService {
|
||||
String functionKey = privilegeFunctionDTO.getFunctionKey();
|
||||
PrivilegeEntity functionEntity = privilegeDao.selectByKey(functionKey);
|
||||
if (functionEntity == null) {
|
||||
functionEntity = new PrivilegeEntity();
|
||||
functionEntity.setName(privilegeFunctionDTO.getFunctionName());
|
||||
functionEntity.setParentKey(privilegeFunctionDTO.getMenuKey());
|
||||
functionEntity.setType(PrivilegeTypeEnum.POINTS.getValue());
|
||||
functionEntity.setUrl(privilegeFunctionDTO.getUrl());
|
||||
functionEntity.setKey(privilegeFunctionDTO.getFunctionKey());
|
||||
functionEntity.setSort(privilegeFunctionDTO.getSort());
|
||||
functionEntity.setCreateTime(new Date());
|
||||
functionEntity.setUpdateTime(new Date());
|
||||
privilegeDao.insert(functionEntity);
|
||||
} else {
|
||||
functionEntity.setUrl(privilegeFunctionDTO.getUrl());
|
||||
functionEntity.setName(privilegeFunctionDTO.getFunctionName());
|
||||
functionEntity.setParentKey(privilegeFunctionDTO.getMenuKey());
|
||||
functionEntity.setSort(privilegeFunctionDTO.getSort());
|
||||
privilegeDao.updateById(functionEntity);
|
||||
return ResponseDTO.wrap(PrivilegeResponseCodeConst.POINT_NOT_EXIST);
|
||||
}
|
||||
functionEntity.setUrl(privilegeFunctionDTO.getUrl());
|
||||
functionEntity.setName(privilegeFunctionDTO.getFunctionName());
|
||||
functionEntity.setParentKey(privilegeFunctionDTO.getMenuKey());
|
||||
functionEntity.setSort(privilegeFunctionDTO.getSort());
|
||||
privilegeDao.updateById(functionEntity);
|
||||
|
||||
return ResponseDTO.succ();
|
||||
}
|
||||
|
||||
@@ -206,9 +196,8 @@ public class PrivilegeService {
|
||||
return ResponseDTO.succData(Lists.newArrayList());
|
||||
}
|
||||
List<PrivilegeFunctionVO> functionList = Lists.newArrayList();
|
||||
PrivilegeFunctionVO functionDTO;
|
||||
for (PrivilegeEntity functionEntity : functionPrivilegeList) {
|
||||
functionDTO = new PrivilegeFunctionVO();
|
||||
PrivilegeFunctionVO functionDTO = new PrivilegeFunctionVO();
|
||||
functionDTO.setFunctionKey(functionEntity.getKey());
|
||||
functionDTO.setFunctionName(functionEntity.getName());
|
||||
functionDTO.setMenuKey(functionEntity.getParentKey());
|
||||
@@ -219,4 +208,70 @@ public class PrivilegeService {
|
||||
return ResponseDTO.succData(functionList);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseDTO<String> batchSaveFunctionList(ValidateList<PrivilegeFunctionDTO> functionList) {
|
||||
String menuKey = functionList.get(0).getMenuKey();
|
||||
PrivilegeEntity privilegeEntity = privilegeDao.selectByKey(menuKey);
|
||||
if (privilegeEntity == null) {
|
||||
return ResponseDTO.wrap(PrivilegeResponseCodeConst.MENU_NOT_EXIST);
|
||||
}
|
||||
|
||||
//数据库中存在的数据
|
||||
List<PrivilegeEntity> existFunctionList = privilegeDao.selectByParentKey(menuKey);
|
||||
Map<String, PrivilegeEntity> privilegeEntityMap = existFunctionList.stream().collect(Collectors.toMap(PrivilegeEntity::getKey, e -> e));
|
||||
|
||||
//如果没有,则保存全部
|
||||
if (existFunctionList.isEmpty()) {
|
||||
List<PrivilegeEntity> privilegeEntityList = functionList.stream().map(e -> function2Privilege(e)).collect(Collectors.toList());
|
||||
privilegeDao.batchInsert(privilegeEntityList);
|
||||
return ResponseDTO.succ();
|
||||
}
|
||||
|
||||
Set<String> functionKeySet = functionList.stream().map(PrivilegeFunctionDTO::getFunctionKey).collect(Collectors.toSet());
|
||||
//删除的
|
||||
List<Long> deleteIdList = existFunctionList.stream().filter(e -> !functionKeySet.contains(e.getKey())).map(PrivilegeEntity::getId).collect(Collectors.toList());
|
||||
List<String> deleteKeyList = existFunctionList.stream().filter(e -> !functionKeySet.contains(e.getKey())).map(PrivilegeEntity::getKey).collect(Collectors.toList());
|
||||
if (!deleteIdList.isEmpty()) {
|
||||
privilegeDao.deleteBatchIds(deleteIdList);
|
||||
rolePrivilegeDao.deleteByPrivilegeKey(deleteKeyList);
|
||||
}
|
||||
|
||||
//需要更新的
|
||||
ArrayList<PrivilegeEntity> batchUpdateList = Lists.newArrayList();
|
||||
for (PrivilegeFunctionDTO privilegeFunctionDTO : functionList) {
|
||||
PrivilegeEntity existPrivilege = privilegeEntityMap.get(privilegeFunctionDTO.getFunctionKey());
|
||||
if (existPrivilege != null) {
|
||||
existPrivilege.setSort(privilegeFunctionDTO.getSort());
|
||||
existPrivilege.setName(privilegeFunctionDTO.getFunctionName());
|
||||
batchUpdateList.add(existPrivilege);
|
||||
}
|
||||
}
|
||||
|
||||
if (!batchUpdateList.isEmpty()) {
|
||||
privilegeDao.batchUpdate(batchUpdateList);
|
||||
}
|
||||
|
||||
//新增的
|
||||
List<PrivilegeEntity> batchInsertList = functionList.stream()
|
||||
.filter(e -> !privilegeEntityMap.containsKey(e.getFunctionKey()))
|
||||
.map(e -> function2Privilege(e))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!batchInsertList.isEmpty()) {
|
||||
privilegeDao.batchInsert(batchInsertList);
|
||||
}
|
||||
|
||||
return ResponseDTO.succ();
|
||||
}
|
||||
|
||||
private PrivilegeEntity function2Privilege(PrivilegeFunctionDTO privilegeFunction) {
|
||||
PrivilegeEntity privilegeEntity = new PrivilegeEntity();
|
||||
privilegeEntity.setKey(privilegeFunction.getFunctionKey());
|
||||
privilegeEntity.setName(privilegeFunction.getFunctionName());
|
||||
privilegeEntity.setParentKey(privilegeFunction.getMenuKey());
|
||||
privilegeEntity.setType(PrivilegeTypeEnum.POINTS.getValue());
|
||||
privilegeEntity.setSort(privilegeFunction.getSort());
|
||||
privilegeEntity.setUrl("");
|
||||
return privilegeEntity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +82,9 @@ public class SystemConfigService {
|
||||
*/
|
||||
public ResponseDTO<PageResultDTO<SystemConfigVO>> getSystemConfigPage(SystemConfigQueryDTO queryDTO) {
|
||||
Page page = SmartPageUtil.convert2QueryPage(queryDTO);
|
||||
if(queryDTO.getKey() != null){
|
||||
queryDTO.setKey(queryDTO.getKey().toLowerCase());
|
||||
}
|
||||
List<SystemConfigEntity> entityList = systemConfigDao.selectSystemSettingList(page, queryDTO);
|
||||
PageResultDTO<SystemConfigVO> pageResultDTO = SmartPageUtil.convert2PageResult(page, entityList, SystemConfigVO.class);
|
||||
return ResponseDTO.succData(pageResultDTO);
|
||||
@@ -94,7 +97,9 @@ public class SystemConfigService {
|
||||
* @return
|
||||
*/
|
||||
public ResponseDTO<SystemConfigVO> selectByKey(String configKey) {
|
||||
configKey = configKey.toLowerCase();
|
||||
if(configKey != null){
|
||||
configKey = configKey.toLowerCase();
|
||||
}
|
||||
SystemConfigEntity entity = systemConfigDao.getByKey(configKey);
|
||||
if (entity == null) {
|
||||
return ResponseDTO.wrap(SystemConfigResponseCodeConst.NOT_EXIST);
|
||||
@@ -112,7 +117,9 @@ public class SystemConfigService {
|
||||
* @return
|
||||
*/
|
||||
public <T> T selectByKey2Obj(String configKey, Class<T> clazz) {
|
||||
configKey = configKey.toLowerCase();
|
||||
if(configKey != null){
|
||||
configKey = configKey.toLowerCase();
|
||||
}
|
||||
SystemConfigEntity entity = systemConfigDao.getByKey(configKey);
|
||||
if (entity == null) {
|
||||
return null;
|
||||
@@ -150,6 +157,7 @@ public class SystemConfigService {
|
||||
if(!valueValid.isSuccess()){
|
||||
return valueValid;
|
||||
}
|
||||
configAddDTO.setConfigKey(configAddDTO.getConfigKey().toLowerCase());
|
||||
SystemConfigEntity addEntity = SmartBeanUtil.copy(configAddDTO, SystemConfigEntity.class);
|
||||
addEntity.setIsUsing(JudgeEnum.YES.getValue());
|
||||
systemConfigDao.insert(addEntity);
|
||||
@@ -171,7 +179,7 @@ public class SystemConfigService {
|
||||
if (entity == null) {
|
||||
return ResponseDTO.wrap(SystemConfigResponseCodeConst.NOT_EXIST);
|
||||
}
|
||||
SystemConfigEntity alreadyEntity = systemConfigDao.getByKeyExcludeId(updateDTO.getConfigKey(), updateDTO.getId());
|
||||
SystemConfigEntity alreadyEntity = systemConfigDao.getByKeyExcludeId(updateDTO.getConfigKey().toLowerCase(), updateDTO.getId());
|
||||
if (alreadyEntity != null) {
|
||||
return ResponseDTO.wrap(SystemConfigResponseCodeConst.ALREADY_EXIST);
|
||||
}
|
||||
@@ -180,6 +188,7 @@ public class SystemConfigService {
|
||||
return valueValid;
|
||||
}
|
||||
entity = SmartBeanUtil.copy(updateDTO, SystemConfigEntity.class);
|
||||
updateDTO.setConfigKey(updateDTO.getConfigKey().toLowerCase());
|
||||
systemConfigDao.updateById(entity);
|
||||
|
||||
//刷新缓存
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user