基础模块修改
This commit is contained in:
parent
9e97575a54
commit
e5126b4a95
|
|
@ -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()==ele.getPidCode())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue