DataDictionaryServiceImpl.java
4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package com.diligrp.website.service.impl;
import java.util.List;
import javax.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import com.diligrp.website.domain.DataDictionary;
import com.diligrp.website.domain.DataDictionaryValue;
import com.diligrp.website.manager.DataDictionaryManager;
import com.diligrp.website.service.DataDictionaryService;
import com.diligrp.website.util.dao.BaseQuery;
import com.diligrp.website.util.domain.Result;
import com.diligrp.website.util.web.PageTemplate;
import com.google.common.base.Objects;
@Component("dataDictionaryService")
public class DataDictionaryServiceImpl implements DataDictionaryService {
@Resource
private DataDictionaryManager dataDictionaryManager;
@Override
public DataDictionary getDataDictionaryByCode(String code) {
return dataDictionaryManager.getDataDictionaryByCode(code);
}
@Override
public DataDictionaryValue getDataDicValById(Long id) {
return dataDictionaryManager.getDataDicValById(id);
}
@Override
public List<DataDictionaryValue> getDataDictionaryValue(Long id) {
return dataDictionaryManager.getDataDictionaryValue(id);
}
@Override
public PageTemplate query(BaseQuery query) {
return dataDictionaryManager.query(query);
}
@Override
public Result deleteValue(Long id) {
boolean flag = dataDictionaryManager.deleteValue(id);
return Result.create(flag);
}
@Override
public Result delete(Long id) {
List<DataDictionaryValue> list = dataDictionaryManager.getDataDictionaryValue(id);
if (!CollectionUtils.isEmpty(list)) {
// code 1000 有字典值,不允许删除
return Result.create(false).setCode(1000);
}
boolean flag = dataDictionaryManager.delete(id);
return Result.create(flag);
}
@Override
public Result save(DataDictionary dic) {
if (dic == null) {
// 10000 : 参数错误
return Result.create(false).setCode(10000);
}
if (StringUtils.isEmpty(dic.getCode()) || StringUtils.isEmpty(dic.getName())) {
return Result.create(false).setCode(10000);
}
DataDictionary dbDic = dataDictionaryManager.getDataDictionaryByCode(dic.getCode().trim());
if (dbDic != null) {
// 10100 : 字典已经存在
return Result.create(false).setCode(10100);
}
boolean flag = dataDictionaryManager.save(dic);
return Result.create(flag);
}
@Override
public Result saveValue(DataDictionaryValue dicv) {
if (dicv == null) {
// 10000 : 参数错误
return Result.create(false).setCode(10000);
}
if (StringUtils.isEmpty(dicv.getCode()) || StringUtils.isEmpty(dicv.getName())
|| StringUtils.isEmpty(dicv.getRemark()) || dicv.getSort() == null) {
return Result.create(false).setCode(10000);
}
DataDictionaryValue dbDic = dataDictionaryManager.getDataDicValByCode(dicv.getCode(), dicv.getDdId());
if (dbDic != null) {
// 10100 : 字典已经存在
return Result.create(false).setCode(10100);
}
dbDic = dataDictionaryManager.getDataDicValBySort(dicv.getSort(), dicv.getDdId());
if (dbDic != null) {
// 10200 : 顺序值已经存在
return Result.create(false).setCode(10300);
}
/*
* 值名称不需要判断是否重复 dbDic =
* dataDictionaryManager.getDataDicValByName(dicv.getName(),
* dicv.getDdId()); if(dbDic != null){ // 10100 : 字典已经存在 return
* Result.create(false).setCode(10100); }
*/
boolean flag = dataDictionaryManager.saveValue(dicv);
return Result.create(flag);
}
@Override
public Result edit(DataDictionary dic) {
if (dic == null || StringUtils.isEmpty(dic.getName())) {
// 10000 : 参数错误
return Result.create(false).setCode(10000);
}
DataDictionary dbDic = dataDictionaryManager.getDataDictionaryById(dic.getId());
if (dbDic == null) {
// 10300 : 字典已经不存在
return Result.create(false).setCode(10100);
}
boolean flag = dataDictionaryManager.edit(dic);
return Result.create(flag).setMsg(dbDic.getCode());
}
@Override
public Result editValue(DataDictionaryValue dicv) {
if (dicv == null) {
// 10000 : 参数错误
return Result.create(false).setCode(10000);
}
if (dicv.getId() == null || StringUtils.isEmpty(dicv.getName()) || StringUtils.isEmpty(dicv.getRemark())
|| dicv.getSort() == null) {
return Result.create(false).setCode(10000);
}
DataDictionaryValue dbDic = dataDictionaryManager.getDataDicValById(dicv.getId());
if (dbDic == null) {
// 10200 : 字典已经不存在
return Result.create(false).setCode(10100);
}
dbDic = dataDictionaryManager.getDataDicValBySort(dicv.getSort(), dbDic.getDdId());
if (dbDic != null && !Objects.equal(dbDic.getId(), dicv.getId())) {
// 10300 : 顺序值已经存在
return Result.create(false).setCode(10300);
}
boolean flag = dataDictionaryManager.editValue(dicv);
return Result.create(flag);
}
@Override
public DataDictionary findById(Long id) {
return this.dataDictionaryManager.getDataDictionaryById(id);
}
}