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
125
126
127
128
129
130
131
132
133
package com.changhong.epc.tenant.service.system.math.impl;
 
import com.changhong.epc.bean.count.system.SystemMath;
import com.changhong.epc.bean.count.system.SystemMathExtend;
import com.changhong.epc.bean.count.system.SystemMathParam;
import com.changhong.epc.bean.tenant.cost.CostFromMapping;
import com.changhong.epc.constter.count.nomr.CountUrlConst;
import com.changhong.epc.constter.system.SystemClients;
import com.changhong.epc.constter.system.run.EpcRestInterface;
import com.changhong.epc.tenant.mapper.tenant.system.math.SystemMathMapper;
import com.changhong.epc.tenant.mapper.tenant.system.math.SystemMathParamMapper;
import com.changhong.epc.tenant.service.system.math.SystemMathService;
import com.esotericsoftware.minlog.Log;
import com.iemsoft.framework.cloud.core.base.ResMsg;
import com.iemsoft.framework.cloud.core.thread.Keys;
import com.iemsoft.framework.cloud.core.thread.ThreadData;
import com.iemsoft.framework.cloud.core.tools.JSONTool;
import com.iemsoft.framework.cloud.core.tools.SpringUtil;
import com.iemsoft.framework.cloud.ribbon.RestInterface;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
 
import javax.annotation.Resource;
import java.util.*;
 
/**
 * 系统变量业务层
 *
 * @author liush
 */
@Service("systemMathServiceImpl")
@Slf4j
public class SystemMathServiceImpl implements SystemMathService, SystemClients, CountUrlConst {
 
    @Resource
    private SystemMathMapper systemMathMapper;
 
    @Resource
    private SystemMathParamMapper systemMathParamMapper;
 
    @Override
    public List<SystemMathExtend> selectAllSystemMathExtend() {
        return systemMathMapper.selectAllSystemMathExtend();
    }
 
    @Override
    public List<SystemMath> selectSystemMathNameList() {
        return systemMathMapper.selectSystemMathNameList();
    }
 
    @Transactional
    @Override
    public Integer insert(SystemMathExtend systemMathExtend) {
        int count = 0;
        systemMathExtend.initParam();
        count += systemMathMapper.save(systemMathExtend);
        for (SystemMathParam sys : systemMathExtend.getSystemMathParam()) {
            sys.setMathId(systemMathExtend.getId());
            sys.initParam();
            count += systemMathParamMapper.insert(sys);
        }
        return count;
    }
 
    @Transactional
    @Override
    public Integer updateByPrimaryKey(SystemMathExtend systemMathExtend) {
        int count = 0;
        SystemMathParam systemMathParam = new SystemMathParam();
        systemMathParam.setMathId(systemMathExtend.getId());
        systemMathParamMapper.delete(systemMathParam);
        systemMathExtend.initParam();
        count += systemMathMapper.updateByPrimaryKey(systemMathExtend);
        for (SystemMathParam sys : systemMathExtend.getSystemMathParam()) {
            sys.setMathId(systemMathExtend.getId());
            sys.initParam();
            count += systemMathParamMapper.insert(sys);
        }
        return count;
    }
 
    @Transactional
    @Override
    public Integer deleteByPrimaryKey(SystemMathExtend systemMathExtend) {
        int count = 0;
        SystemMathParam systemMathParam = new SystemMathParam();
        systemMathParam.setMathId(systemMathExtend.getId());
        count += systemMathParamMapper.delete(systemMathParam);
        count += systemMathMapper.delete(systemMathExtend);
        return count;
    }
 
    @SuppressWarnings("unchecked")
    @Override
    public List<Map<String, String>> getFunction() {
        RestInterface restInterface = SpringUtil.getBean(SERVER_COUNT.getBeanName(), RestInterface.class);
        Object data = restInterface.post(CountUrlConst.COUNT_SYSTEM_FUNC_GETFUNCTION, new HashMap<>(), ResMsg.class, EpcRestInterface.getEpcHeads()).getData();
        Map<String, List<Map<String, String>>> data1 = JSONTool.toObj(JSONTool.toJson(data), Map.class);
        List<Map<String, String>> timeFunctions = data1.get("时间函数");
        List<Map<String, String>> basicFunctions = data1.get("基本函数");
        List<Map<String, String>> expendFunctions = data1.get("扩展函数");
        List<Map<String, String>> functions = new ArrayList<Map<String, String>>();
        functions.addAll(timeFunctions);
        functions.addAll(basicFunctions);
        functions.addAll(expendFunctions);
        return functions;
    }
    @Override
    public  Map<String,String> getCostTypeByFormId(Map<String,String> map) {
        log.debug("传递的map:---------------------------{}",map);
        String formId = Objects.toString(map.get("fId"),"");
        String dataRowNum = map.get("dataRowNum");
        String tenantId = ThreadData.get(Keys.TENANT_ID);
        String companyId = ThreadData.get(Keys.COMPANY_ID);
 
        /**
         费用类型     表名
         SQ        通用申请单智泽SQa-----------> 需要
         SQ     通用申请单智泽SQa486
         筛选出长度最短的表名,同时返回此bean
         */
        Map<String,String> list = systemMathMapper.getCostTypeByFormId(tenantId, companyId, formId,dataRowNum);
        Map<String,String> costFromMapping1 ;
        if(!CollectionUtils.isEmpty(list)){
            log.debug("查询出的费用类型为:{}", list.toString());
            costFromMapping1 = list;
            return costFromMapping1;
        }
        return null;
    }
}