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
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
package com.changhong.epc.tenant.service.norm.impl;
 
import com.changhong.epc.bean.tenant.master.MasterAlias;
import com.changhong.epc.bean.tenant.master.MasterEleValue;
import com.changhong.epc.bean.tenant.master.MasterElement;
import com.changhong.epc.bean.tenant.master.MasterValue;
import com.changhong.epc.bean.tenant.master.extend.MasterElementExtend;
import com.changhong.epc.config.service.MasterElementService;
import com.changhong.epc.constter.admin.AdminUrlConst;
import com.changhong.epc.tenant.mapper.tenant.norm.MasterDefineMapper;
import com.changhong.epc.tenant.mapper.tenant.norm.MasterElementMapper;
import com.changhong.epc.tenant.mapper.tenant.norm.MasterValueMapper;
import com.iemsoft.framework.cloud.core.tools.JSONTool;
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
@Service("masterElementServiceImpl")
public class MasterElementServiceImpl extends MasterElementService {
 
    @Resource
    private MasterElementMapper masterElementMapper;
    
    @Resource
    private MasterDefineMapper masterDefineMapper;
    
    /**
     * MasterValueMapper引用
     */
    @Resource
    private MasterValueMapper masterValueMapper;
    
    public static final String VALUE = "value";
    
    public static final String CODE = "code";
    
    
    @Override
    public List<MasterElementExtend> selectByCode(String defineCode) {
//        int o = masterDefineMapper.queryMaster(defineCode);
//        if(o>0){
            return masterElementMapper.selectByCode(defineCode);
//        }else{
//            Object obj = MasterDefineServiceImpl.masterRPC(AdminUrlConst.ELEMENT_SELECTBYCODE,new ModelMap("defineCode",defineCode) );
//            return obj!= null?JSONTool.toList(JSONTool.toJson(obj), MasterElementExtend.class):null;
//        }
    }
 
 
    /**
     * 查询所有主数据关联
     */
    @Override
    public List<MasterEleValue> selectCode(MasterEleValue master) {
        List<MasterEleValue> masterList = new ArrayList<MasterEleValue>();
        this.getCode(masterList,this.selectByCode(master.getDefineCode()),master);
        
        return masterList;
    }
 
    @Override
    public String getValFunc(MasterEleValue value) {
        int o = masterDefineMapper.queryMaster(value.getDefineCode());
        if(o>0){
            return Objects.toString(masterValueMapper.getVal(value),"");
        }else{
            Object obj = MasterDefineServiceImpl.masterRPC(AdminUrlConst.MASTER_VALUE_GETVAL,value );
            return obj!=null?JSONTool.toObj(JSONTool.toJson(obj), MasterValue.class).getValue():"";
        }
        
    }
 
 
    @Override
    public List<MasterElement> elementInfos(MasterElement masterList) {
        return masterElementMapper.elementInfos(masterList.getDefineCode());
    }
 
 
    @Override
    public List<MasterEleValue> selectCodes(List<MasterEleValue> masterList) {
        if(ObjectUtil.empty(masterList)){
            return Collections.EMPTY_LIST;
        }
        for(MasterEleValue o : masterList){
            if(o.getDefineCode().equals("") || o.getDefineCode() == null){
                continue;
            }else{
                o.setJoinDefines(this.selectCode(o));
            }
        };
        return masterList;
    }
 
    @Override
    @Transactional
    public int updateAlias(MasterAlias alias) {
        String defCode = alias.getDefineCode();
        int o = masterDefineMapper.queryMaster(defCode);
        if(o>0){
            int count = -1;
            //清空原有alias
            masterElementMapper.updateAlias(defCode, null, "");
            //修改新得元素code
            if(alias.getCode()!=null && !"".equals(alias.getCode())){
            count += masterElementMapper.updateAlias(defCode, alias.getCode(), "code");
            }
            //修改新的得value
            if(alias.getName()!=null && !"".equals(alias.getName())){
            count += masterElementMapper.updateAlias(defCode, alias.getName(), "value");
            }
            return count;
        }else{
            Object ob = MasterDefineServiceImpl.masterRPC(AdminUrlConst.ELEMENT_UPDATEALIAS,alias);
            return Integer.parseInt(Objects.toString(ob, "-1"));
        }
    }
 
}