|
@@ -3,6 +3,7 @@ package com.judong.chuanyiserver.service.impl;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.judong.chuanyiserver.dao.DictDao;
|
|
|
import com.judong.chuanyiserver.entity.Dict;
|
|
|
+import com.judong.chuanyiserver.entity.DictType;
|
|
|
import com.judong.chuanyiserver.enums.ResultEnum;
|
|
|
import com.judong.chuanyiserver.service.DictService;
|
|
|
import com.judong.chuanyiserver.util.Blank;
|
|
@@ -11,9 +12,9 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.HashMap;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+
|
|
|
|
|
|
|
|
|
@Service
|
|
@@ -24,12 +25,17 @@ public class DictServiceImpl implements DictService {
|
|
|
private DictDao dictDao;
|
|
|
|
|
|
@Override
|
|
|
- public Result queryAll() {
|
|
|
- List<Dict> dicts = dictDao.queryAll();
|
|
|
+ public Result queryAll(Integer page,Integer num) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ Integer count = dictDao.queryAllnum();
|
|
|
+ Integer startNum=(page-1)*num;
|
|
|
+ List<Dict> dicts = dictDao.queryAll(startNum,num);
|
|
|
if (dicts.size()<=0){
|
|
|
return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "暂无数据");
|
|
|
}
|
|
|
- return Result.ok(dicts);
|
|
|
+ jsonObject.put("count",count);
|
|
|
+ jsonObject.put("dicts",dicts);
|
|
|
+ return Result.ok(jsonObject);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -61,26 +67,28 @@ public class DictServiceImpl implements DictService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Map<String, Dict> queryByParentId(Integer parentId) {
|
|
|
+ public List<Dict> queryByParentId(Integer parentId) {
|
|
|
//存放节点数据
|
|
|
- Map<String, Dict> map = new HashMap<>();
|
|
|
+ List<Dict> dicts = new ArrayList<>();
|
|
|
//根据父节点获取子节点对象
|
|
|
List<Dict> dictSon = dictDao.queryByParentId(parentId);
|
|
|
//判断子节点是否为其他节点的父节点
|
|
|
for (Dict d:dictSon){
|
|
|
d.setChildren(queryByParentId(d.getId()));
|
|
|
- map.put(d.getDictKey(),d);
|
|
|
+ dicts.add(d);
|
|
|
}
|
|
|
- return map;
|
|
|
+ return dicts;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Result addDict(Dict dict) {
|
|
|
- if (Blank.isEmpty(dict.getParentId(),dict.getDictKey(),dict.getDictValue(),dict.getSortNum())){
|
|
|
- return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "父id,字典key,字典值以及序号不能为空");
|
|
|
+ if (Blank.isEmpty(dict.getParentId(),dict.getDictKey(),dict.getDictValue(),dict.getSortNum(),dict.getDictTypeId())){
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "父id,字典key,字典值,类型以及序号不能为空");
|
|
|
}
|
|
|
- if (Blank.isNotEmpty(dictDao.queryByDictKeyIsExist(dict.getDictKey()))){
|
|
|
- return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "字典key已存在");
|
|
|
+ //判断数据是否存在
|
|
|
+ Dict dictIsExist = dictDao.queryIsExist(dict);
|
|
|
+ if (dictIsExist !=null){
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "不可添加重复数据");
|
|
|
}
|
|
|
dictDao.addDict(dict);
|
|
|
return Result.ok("新增成功");
|
|
@@ -88,17 +96,13 @@ public class DictServiceImpl implements DictService {
|
|
|
|
|
|
@Override
|
|
|
public Result updataById(Dict dict) {
|
|
|
- if (Blank.isEmpty(dict.getParentId(),dict.getDictKey(),dict.getDictValue(),dict.getSortNum(),dict.getId())){
|
|
|
- return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "id,父id,字典key,字典值以及序号不能为空");
|
|
|
- }
|
|
|
- //判断是否有数据
|
|
|
- Dict dictShow = dictDao.queryById(dict.getId());
|
|
|
- if (dictShow==null){
|
|
|
- return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "修改失败");
|
|
|
+ if (Blank.isEmpty(dict.getParentId(),dict.getDictKey(),dict.getDictValue(),dict.getSortNum(),dict.getId(),dict.getDictTypeId())){
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "id,父id,字典key,字典值,类型以及序号不能为空");
|
|
|
}
|
|
|
- //判断key是否重复
|
|
|
- if (Blank.isNotEmpty(dictDao.queryByDictKeyIsExist(dict.getDictKey()))){
|
|
|
- return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "key已存在,修改失败");
|
|
|
+ //判断数据是否存在
|
|
|
+ Dict dictIsExist = dictDao.queryIsExist(dict);
|
|
|
+ if (dictIsExist !=null){
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "不可更改为重复数据");
|
|
|
}
|
|
|
if (dictDao.updataById(dict)<=0){
|
|
|
throw new ClassCastException("修改失败");
|
|
@@ -116,14 +120,76 @@ public class DictServiceImpl implements DictService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Map<String, Object> queryByDictKey(List<String> dictKeys) {
|
|
|
+ public List<Dict> queryByDictKey(List<String> dictKeys) {
|
|
|
//存储数据
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
+ List<Dict> dictAll = new ArrayList<>();
|
|
|
List<Dict> dicts = dictDao.queryByDictKey(dictKeys);
|
|
|
for (Dict d:dicts){
|
|
|
d.setChildren(queryByParentId(d.getId()));
|
|
|
- map.put(d.getDictKey(),d);
|
|
|
+ dictAll.add(d);
|
|
|
+ }
|
|
|
+ return dictAll;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result queryType() {
|
|
|
+ List<DictType> dictTypes = dictDao.queryType();
|
|
|
+ if (dictTypes.size()<=0){
|
|
|
+ throw new ClassCastException("暂无数据");
|
|
|
+ }
|
|
|
+ return Result.ok(dictTypes);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result queryByType(String keyType, Integer page, Integer num) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ if (Blank.isEmpty(keyType)){
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "字典类型不能为空");
|
|
|
+ }
|
|
|
+ Integer count = dictDao.queryByTypeNum(keyType);
|
|
|
+ Integer startNum=(page-1)*num;
|
|
|
+ List<Dict> dicts = dictDao.queryByType(keyType, startNum, num);
|
|
|
+ jsonObject.put("count",count);
|
|
|
+ jsonObject.put("dicts",dicts);
|
|
|
+ return Result.ok(jsonObject);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result addDictType(DictType dictType) {
|
|
|
+ if (Blank.isEmpty(dictType.getDictKeyType(),dictType.getDictKeyValue(),dictType.getSortNum(),dictType.getDescription())){
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(),"字典类型,字典值,序号以及描述不能为空");
|
|
|
+ }
|
|
|
+ //判断类型key是否重复
|
|
|
+ if (dictDao.queryDictTypeByKeyType(dictType.getDictKeyType())!=null){
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(),"字典类型已被占用");
|
|
|
+ }
|
|
|
+ if (dictDao.addDictType(dictType)<=0){
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(),"新增失败");
|
|
|
+ }
|
|
|
+ return Result.ok("新增成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result updataDictType(DictType dictType) {
|
|
|
+ if (Blank.isEmpty(dictType.getDictKeyType(),dictType.getDictKeyValue(),dictType.getSortNum(),dictType.getDescription())){
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(),"字典类型,字典值,序号以及描述不能为空");
|
|
|
+ }
|
|
|
+ //判断类型key是否重复
|
|
|
+ if (dictDao.queryDictTypeByKeyType(dictType.getDictKeyType())!=null){
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(),"字典类型已被占用");
|
|
|
+ }
|
|
|
+ if (dictDao.updataDictType(dictType)<=0){
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(),"编辑失败");
|
|
|
+ }
|
|
|
+ return Result.ok("编辑成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result deleteDictTypeById(List<Integer> ids) {
|
|
|
+ if (ids.size()<=0){
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(),"参数错误");
|
|
|
}
|
|
|
- return map;
|
|
|
+ Integer num = dictDao.deleteDictTypeById(ids);
|
|
|
+ return Result.ok(num);
|
|
|
}
|
|
|
}
|