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
package com.changhong.epc.rely.api.epc.admin;
 
import com.alibaba.fastjson.TypeReference;
import com.changhong.epc.bean.admin.InitCompany;
import com.changhong.epc.constter.admin.AdminUrlConst;
import com.changhong.epc.constter.base.Context;
import com.changhong.epc.constter.cache.admin.InitCompanyCache;
import com.changhong.epc.constter.form.utf.FormUrlConst;
import com.changhong.epc.constter.system.SystemClients;
import com.changhong.epc.constter.system.run.EpcRestInterface;
import com.changhong.epc.rely.api.bean.TenantnameAndCompanyname;
import com.changhong.epc.rely.api.epc.BaseApi;
import com.iemsoft.framework.cloud.core.base.ResMsg;
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
import com.iemsoft.framework.cloud.core.tools.SpringUtil;
import com.iemsoft.framework.cloud.redis.annotation.CacheRm;
import com.iemsoft.framework.cloud.redis.annotation.CacheSave;
import com.iemsoft.framework.cloud.ribbon.RestInterface;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Service
@Slf4j
public class InitCompanyApi extends BaseApi implements SystemClients, InitCompanyCache {
 
    @CacheSave(value = INIT_COMPANY_INFO, tenant = false, company = false)
    public InitCompany getInitCompany(Integer tenantId, Integer companyId) {
        InitCompany initCompany = new InitCompany();
        initCompany.setCompanyId(companyId);
        initCompany.setTenantId(tenantId);
        ResMsg<List<InitCompany>> resMsg =
                (ResMsg<List<InitCompany>>)
                        SpringUtil.getBean(SERVER_ADMIN.getBeanName(), RestInterface.class)
                                .post(AdminUrlConst.SELECT_INITCOMPANY
                                        , initCompany
                                        , new TypeReference<ResMsg<List<InitCompany>>>() {
                                        }.getType()
                                        , EpcRestInterface.getEpcHeads()
                                );
        assertSuccess(resMsg);
        return ObjectUtil.empty(resMsg.getData()) ? new InitCompany() : resMsg.getData().stream().findFirst().orElse(new InitCompany());
    }
    public Map<String,String> getInitCompanynameAndTenantname(Integer tenantId, Integer companyId) {
        ResMsg<List<Map<String,String>>> resMsg =
                (ResMsg<List<Map<String,String>>>)
                        SpringUtil.getBean(SERVER_ADMIN.getBeanName(), RestInterface.class)
                                .post(AdminUrlConst.SELECT_INITCOMPANY_COMPANYNAME_TENANTNAME
                                        , new ModelMap("tenantId",tenantId)
                                                .addAttribute("companyId",companyId)
                                        , new TypeReference<ResMsg<List<Map<String,String>>>>() {
                                        }.getType()
                                        , EpcRestInterface.getEpcHeads()
                                );
        assertSuccess(resMsg);
        return ObjectUtil.empty(resMsg.getData()) ? new HashMap<>(): resMsg.getData().stream().findFirst().orElse(new HashMap<>());
    }
 
    public InitCompany getInitCompany() {
        // 此方法调用触发缓存
        return SpringUtil.getBean(InitCompanyApi.class)
                .getInitCompany(Context.getTenantId(), Context.getCompanyId());
    }
 
    @CacheSave(value = INIT_COMPANY_INFO_LIST, tenant = false, company = false)
    public List<InitCompany> getAllInitCompany() {
        ResMsg<List<InitCompany>> resMsg =
                (ResMsg<List<InitCompany>>)
                        SpringUtil.getBean(SERVER_ADMIN.getBeanName(), RestInterface.class)
                                .post(AdminUrlConst.SELECT_INITCOMPANY
                                        , new InitCompany()
                                        , new TypeReference<ResMsg<List<InitCompany>>>() {
                                        }.getType()
                                        , EpcRestInterface.getEpcHeads()
                                );
        assertSuccess(resMsg);
        return resMsg.getData() == null ? new ArrayList<>() : resMsg.getData();
    }
 
    @CacheRm(value = {INIT_COMPANY_INFO, INIT_COMPANY_INFO_LIST}, tenant = false, company = false)
    public void removeInte() {
        System.out.println("清除了");
    }
 
    /**
     * @Author WangYX
     * @Description 初始化菜单列表,添加初始化公司数据
     * @Date 2019/4/1 1:54 PM
     */
    @CacheRm(value = {INIT_COMPANY_INFO, INIT_COMPANY_INFO_LIST}, tenant = false, company = false)
    public void initCompany(InitCompany initCompany) {
        ResMsg resMsg = SpringUtil.getBean(
                SERVER_ADMIN.getBeanName(), RestInterface.class)
                .post(AdminUrlConst.ADD_INITCOMPANY
                        , initCompany
                        , ResMsg.class
                        , EpcRestInterface.getEpcHeads()
                );
        assertSuccess(resMsg);
    }
 
    public void addOperationLog(String formId,String dataRowNum ,String operationoNum,String userName) {
        ResMsg resMsg = SpringUtil.getBean(SERVER_FORM.getBeanName(), RestInterface.class)
                .post(FormUrlConst.OPERATION_LOG_ADD,
                        new ModelMap().addAttribute("operationNum", operationoNum)
                                     .addAttribute("formId", formId)
                                     .addAttribute("dataRowNum",dataRowNum)
                                     .addAttribute("userName",userName)
                        , null
                        , EpcRestInterface.getEpcHeads()
                );
        assertSuccess(resMsg);
    }
}