UnitService.java
2.59 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
package com.huaheng.framework.web.service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.framework.web.entity.UnitRelation;
import com.huaheng.pc.config.materialUnit.domain.MaterialUnit;
import com.huaheng.pc.config.materialUnit.service.MaterialUnitService;
import com.huaheng.pc.system.dict.domain.DictData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* huaheng首创 html调用 thymeleaf 实现字典读取
*
* @author huaheng
*/
@Service("unit")
public class UnitService {
private static final Logger logger = LoggerFactory.getLogger(UnitService.class);
@Autowired
private MaterialUnitService materialUnitService;
public static List<UnitRelation> unitRelations = null;
public static Map<String, List<UnitRelation>> unitRelationMap = new HashMap<>();
/**
* 根据中文单位类型查询物料单位数据信息
*/
public List<UnitRelation> getType(String code) {
System.out.println(code);
if (StringUtils.isNotEmpty(code) && code.equals("refresh")) {
unitRelations = null;
}
if (unitRelations == null ||unitRelations.size()==0)
{
unitRelations = getUnitAll();
}
List<UnitRelation> result = unitRelations;
return result;
}
/**
* 根据根据中文单位查找英文单位
* @return 字典标签
*/
public String getEnCode(String code) {
if (unitRelations == null) {
unitRelations = getUnitAll();
}
String result = unitRelations.stream().
filter(x -> x.getCode().equals(code) ).
findFirst().
map(UnitRelation::getEnCode).
orElse(null);
return result;
}
public List<UnitRelation> getUnitAll(){
LambdaQueryWrapper<MaterialUnit> wrapper=new LambdaQueryWrapper<>();
wrapper.isNotNull(MaterialUnit::getUserDef1);
List<MaterialUnit> list=materialUnitService.list(wrapper);
if(list==null||list.size()==0)
{
return null;
}
return list.stream().map(x->{
UnitRelation relation=new UnitRelation();
relation.setCode(x.getUnit());
relation.setEnCode(x.getUserDef1());
return relation;
}).collect(Collectors.toList());
}
}