177 lines
4.8 KiB
Plaintext
177 lines
4.8 KiB
Plaintext
package com.securityControl.system.service.impl;
|
|
|
|
import com.securityControl.common.core.utils.StringUtils;
|
|
import com.securityControl.common.redis.service.RedisService;
|
|
import com.securityControl.system.domain.vo.ReturnCodeEntity;
|
|
import com.securityControl.system.domain.vo.SysDictVo;
|
|
import com.securityControl.system.domain.vo.SysMenuEntity;
|
|
import com.securityControl.system.mapper.SysDictDao;
|
|
import com.securityControl.system.service.SysDictService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.util.List;
|
|
|
|
@Slf4j
|
|
@Service
|
|
public class SysDictServiceImpl implements SysDictService {
|
|
|
|
@Autowired
|
|
private SysDictDao dao;
|
|
|
|
@Resource
|
|
private RedisService redisUtil;
|
|
|
|
@Override
|
|
public List<SysMenuEntity> getDictList(SysDictVo sysDictVo) {
|
|
return dao.getDictList(sysDictVo);
|
|
}
|
|
|
|
/**
|
|
* 查询上级节点数据
|
|
* @param param
|
|
* @return
|
|
*/
|
|
@Override
|
|
public List<SysDictVo> getPDict(String param) {
|
|
return dao.getPDict(param);
|
|
}
|
|
|
|
/**
|
|
* 新增字典
|
|
* @param typeVo
|
|
* @return
|
|
*/
|
|
@Override
|
|
public ReturnCodeEntity addDict(SysDictVo typeVo) {
|
|
ReturnCodeEntity entity=new ReturnCodeEntity();
|
|
try{
|
|
if(StringUtils.isEmpty(typeVo.getpId())){//父节点
|
|
typeVo.setpId("0");
|
|
}
|
|
int num=dao.getNumByName(typeVo);
|
|
if(num>0){
|
|
entity.setCode("201");
|
|
entity.setMsg("字典名称已存在");
|
|
return entity;
|
|
}
|
|
|
|
int num2=dao.getNumByCode(typeVo);
|
|
if(num2>0){
|
|
entity.setCode("201");
|
|
entity.setMsg("字典编码已存在");
|
|
return entity;
|
|
}
|
|
int num3=dao.addDict(typeVo);
|
|
if(num3>0){
|
|
entity.setMsg("添加成功");
|
|
entity.setCode("200");
|
|
}else{
|
|
entity.setMsg("添加失败,请联系管理员");
|
|
entity.setCode("202");
|
|
}
|
|
|
|
}catch (Exception e){
|
|
entity.setCode("202");
|
|
entity.setMsg("网络异常,请联系管理员");
|
|
}
|
|
|
|
return entity;
|
|
}
|
|
|
|
@Override
|
|
public ReturnCodeEntity updateDict(SysDictVo typeVo) {
|
|
ReturnCodeEntity entity=new ReturnCodeEntity();
|
|
try{
|
|
if(StringUtils.isEmpty(typeVo.getpId())){//父节点
|
|
typeVo.setpId("0");
|
|
}
|
|
int num=dao.getNumByName(typeVo);
|
|
if(num>0){
|
|
entity.setCode("201");
|
|
entity.setMsg("字典名称已存在");
|
|
return entity;
|
|
}
|
|
|
|
int num2=dao.getNumByCode(typeVo);
|
|
if(num2>0){
|
|
entity.setCode("201");
|
|
entity.setMsg("字典编码已存在");
|
|
return entity;
|
|
}
|
|
int num3=dao.updateDict(typeVo);
|
|
|
|
try{
|
|
SysDictVo sys=dao.getDictDetail(typeVo.getpId());
|
|
if (sys!=null){
|
|
if("video_config".equals(sys.getCode())){
|
|
redisUtil.set("video:config",typeVo.getCode());
|
|
}
|
|
}
|
|
}catch (Exception e){
|
|
|
|
}
|
|
if(num3>0){
|
|
entity.setMsg("修改成功");
|
|
entity.setCode("200");
|
|
}else{
|
|
entity.setMsg("修改失败,请联系管理员");
|
|
entity.setCode("202");
|
|
}
|
|
|
|
}catch (Exception e){
|
|
entity.setCode("202");
|
|
entity.setMsg("网络异常,请联系管理员");
|
|
}
|
|
|
|
return entity;
|
|
}
|
|
|
|
/**
|
|
* 查询子节点数据
|
|
* @param keyId
|
|
* @return
|
|
*/
|
|
@Override
|
|
public SysDictVo getDictDetail(String keyId) {
|
|
return dao.getDictDetail(keyId);
|
|
}
|
|
|
|
/**
|
|
*删除数据
|
|
* @param keyId
|
|
* @return
|
|
*/
|
|
@Override
|
|
public ReturnCodeEntity deleteDict(String keyId) {
|
|
ReturnCodeEntity entity=new ReturnCodeEntity();
|
|
try {
|
|
int num=dao.getNumByPId(keyId);
|
|
if(num>0) {
|
|
entity.setCode("201");
|
|
entity.setMsg("请先删除子节点");
|
|
return entity;
|
|
}
|
|
int num2=dao.deleteDict(keyId);
|
|
if(num2>0){
|
|
entity.setMsg("删除成功");
|
|
entity.setCode("200");
|
|
}else{
|
|
entity.setMsg("删除成功,请联系管理员");
|
|
entity.setCode("202");
|
|
}
|
|
|
|
}catch (Exception e){
|
|
entity.setCode("202");
|
|
entity.setMsg("网络异常,请联系管理员");
|
|
}
|
|
|
|
|
|
return entity;
|
|
}
|
|
|
|
|
|
}
|