zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
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
package com.changhong.epc.tenant.service.norm.impl.value;
 
import com.changhong.epc.bean.count.MeInfo;
import com.changhong.epc.bean.tenant.master.AutoMasterVal;
import com.changhong.epc.bean.tenant.master.MasterElement;
import com.changhong.epc.bean.tenant.master.extend.MasterDefinesExtend;
import com.changhong.epc.config.service.MasterValueService;
import com.changhong.epc.rely.api.epc.admin.AdminMasterApi;
import com.changhong.epc.tenant.service.norm.impl.SimplAbstractMasterTools;
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
 
/**
 * 自定义查询主数据值
 */
@Service
@Slf4j
public class AutoMasterTools extends SimplAbstractMasterTools<AutoMasterVal, String> {
 
    @Resource
    private MasterValueService masterValueService;
 
    @Resource
    private AdminMasterApi adminMasterApi;
 
    @Override
    protected String adminOneDimensional(MasterDefinesExtend masterDefine, AutoMasterVal autoMasterVal) {
        return adminMasterApi.adminOneDimensional(autoMasterVal);
    }
 
    @Override
    protected String adminTwoDimensional(MasterDefinesExtend masterDefine, AutoMasterVal autoMasterVal) {
        return adminMasterApi.adminTwoDimensional(
                getTwoDimensionalParam(masterDefine, autoMasterVal));
    }
 
    @Override
    protected String tenantOneDimensional(MasterDefinesExtend masterDefine, AutoMasterVal autoMasterVal) {
        return masterValueService.getValString(
                autoMasterVal.getMdCode()
                , autoMasterVal.getMeCode()
                , autoMasterVal.getParams());
    }
 
    @Override
    protected String tenantTwoDimensional(MasterDefinesExtend masterDefine, AutoMasterVal autoMasterVal) {
        AutoMasterVal towDimensional = getTwoDimensionalParam(masterDefine, autoMasterVal);
        return masterValueService.getValTwoDimensional(
                towDimensional.getMdCode()
                , towDimensional.getMeCode()
                , towDimensional.getParams()
        );
    }
 
    public AutoMasterVal getTwoDimensionalParam(MasterDefinesExtend masterDefine, AutoMasterVal autoMasterVal){
        MasterElement field = getMasterElement(masterDefine.getEleList(), autoMasterVal.getMeCode());
        if(ObjectUtil.empty(field) || ObjectUtil.empty(field.getDefMapTalbeField())){
            log.warn("twoDimensional'{}'返回元素没有映射!", autoMasterVal.getMeCode());
            return null;
        }
 
        List<MeInfo> params =
                autoMasterVal.getParams().stream().filter(param->{
                    MasterElement paramField = getMasterElement(masterDefine.getEleList(), param.getLeftMeCode());
                    if(ObjectUtil.empty(paramField) || ObjectUtil.empty(paramField.getDefMapTalbeField())){
                        log.warn("twoDimensional'{}'条件元素没有映射!", param.getLeftMeCode());
                        return false;
                    }
                    param.setFieldName(paramField.getDefMapTalbeField());
                    return true;
                }).collect(Collectors.toList());
 
        return new AutoMasterVal(masterDefine.getDefMapTableName(), field.getDefMapTalbeField(), params);
    }
 
    public MasterElement getMasterElement(List<MasterElement> masterElementList, String meCode){
        if(ObjectUtil.empty(masterElementList)){
            return null;
        }
        return masterElementList.stream().filter(ele->Objects.equals(ele.getCode(), meCode)).findFirst().orElse(null);
    }
}