DictService.java
4.14 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
package com.huaheng.framework.web.service;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.pc.system.dict.domain.DictData;
import com.huaheng.pc.system.dict.service.IDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* huaheng首创 html调用 thymeleaf 实现字典读取
*
* @author huaheng
*/
@Service("dict")
public class DictService {
@Autowired
private IDictDataService dictDataService;
public static List<DictData> dictDataList = null;
public static Map<String, List<DictData>> dictDataMap = new HashMap<>();
/**
* 根据字典类型查询字典数据信息
*
* @param dictType 字典类型
* @return 参数键值
*/
public List<DictData> getType(String dictType) {
System.out.println(dictType);
String warehosueCode = ShiroUtils.getWarehouseCode();
if (StringUtils.isNotEmpty(dictType) && dictType.equals("refresh")) {
dictDataMap = new HashMap<>();
}
List<DictData> result = null;
if (dictDataMap == null) {
DictData dictData = new DictData();
dictData.setEnable(true);
dictData.setDeleted(false);
dictData.setWarehouseCode(warehosueCode);
List<DictData> dictDataList = dictDataService.selectDictDataList(dictData);
dictDataMap.put(warehosueCode, dictDataList);
result = dictDataList.stream().
filter(x -> x.getDictType().equals(dictType)).
collect(Collectors.toList());
result.sort(Comparator.comparing(DictData::getDictSort));
} else if (dictDataMap.get(warehosueCode) != null && dictDataMap.get(warehosueCode).size() > 0) {
List<DictData> list = dictDataMap.get(warehosueCode);
result = list.stream().
filter(x -> x.getDictType().equals(dictType)).
collect(Collectors.toList());
result.sort(Comparator.comparing(DictData::getDictSort));
} else {
DictData dictData = new DictData();
dictData.setEnable(true);
dictData.setDeleted(false);
dictData.setWarehouseCode(warehosueCode);
List<DictData> dictDataList = dictDataService.selectDictDataList(dictData);
dictDataMap.put(warehosueCode, dictDataList);
result = dictDataList.stream().
filter(x -> x.getDictType().equals(dictType)).
collect(Collectors.toList());
result.sort(Comparator.comparing(DictData::getDictSort));
}
// if (DictService.dictDataList == null || DictService.dictDataList.size() == 0) {
// DictData dictData = new DictData();
// dictData.setEnable(true);
// dictData.setDeleted(false);
// DictService.dictDataList = dictDataService.selectDictDataList(dictData);
// }
// List<DictData> result = DictService.dictDataList.stream().
// filter(x -> x.getDictType().equals(dictType)).
// collect(Collectors.toList());
// result.sort(Comparator.comparing(DictData::getDictSort));
return result;
}
/**
* 根据字典类型和字典键值查询字典数据信息
*
* @param dictType 字典类型
* @param dictValue 字典键值
* @return 字典标签
*/
public String getLabel(String dictType, String dictValue) {
if (DictService.dictDataList == null) {
DictData dictData = new DictData();
dictData.setEnable(true);
DictService.dictDataList = dictDataService.selectDictDataList(dictData);
}
String result = DictService.dictDataList.stream().
filter(x -> x.getDictType().equals(dictType) && x.getDictValue().equals(dictValue)).
findFirst().
map(DictData::getDictLabel).
orElse(null);
return result;
}
}