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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package com.changhong.epc.admin.controller.initguide;
 
import com.changhong.epc.admin.mapper.centen.initguide.InitCompanyMapper;
import com.changhong.epc.admin.service.initguide.InitGuideService;
import com.changhong.epc.bean.PageResult;
import com.changhong.epc.bean.admin.BatchInitCompany;
import com.changhong.epc.bean.admin.InitCompany;
import com.changhong.epc.bean.admin.InitPowerInfo;
import com.changhong.epc.constter.admin.AdminUrlConst;
import com.changhong.epc.rely.api.bean.Company;
import com.changhong.epc.rely.api.bean.Tenant;
import com.changhong.epc.rely.api.bean.TenantnameAndCompanyname;
import com.changhong.epc.rely.api.tool.CscUtils;
import com.changhong.epc.rely.api.tool.WorkflowTool;
import com.iemsoft.framework.cloud.core.tools.JSONTool;
import com.iemsoft.framework.cloud.core.tools.http.Http;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
 
 
@RestController
public class InitGuideController implements AdminUrlConst {
 
    @Resource
    private InitGuideService initGuideService;
 
    @Autowired
    private WorkflowTool workflowTool;
 
    @Resource
    private InitCompanyMapper initCompanyMapper;
 
    /**
     * 查询租户
     */
    @PostMapping(SELECT_ALL_TENANTS)
    public PageResult<Tenant> getTenants(@RequestBody Tenant tenant) {
        return initGuideService.getTenants(tenant);
    }
 
    /**
     * 查询公司
     */
    @PostMapping(SELECT_COMPANYS)
    public PageResult<Company> getCompanys(@RequestBody Company company) {
        return initGuideService.getCompanys(company);
    }
 
    /**
     * 添加权限信息
     *
     * @param data
     * @return
     */
    @PostMapping(PUSH_POWER)
    public InitCompany pushPower(@RequestParam String data) {
        return initGuideService.addCompanyPowerInfo(JSONTool.toObj(data, InitPowerInfo.class));
    }
 
    @PostMapping(ADD_INITCOMPANY)
    public int addInitCompany(@RequestBody InitCompany initCompany) {
        return initGuideService.addInitCompany(initCompany);
    }
 
    /**
     * @Author WangYX
     * @Description 批量初始化租户公司
     * @Date 2019/3/28 3:14 PM
     */
    @PostMapping(ADMIN_INIT_COMPANYS)
    public String initCompanys(@RequestBody List<BatchInitCompany> batchInitCompany, @PathVariable Integer costTypeTempId) {
        return initGuideService.initCompanys(batchInitCompany, costTypeTempId);
    }
 
    /**
     * @Author WangYX
     * @Description 查询初始化进度
     * @Date 2019/3/28 3:19 PM
     */
    @PostMapping(ADMIN_SELECT_COMPANYS)
    public List<BatchInitCompany> selectInitCompanys(@PathVariable String groupId) {
        return initGuideService.selectInitCompanys(groupId);
    }
 
    /**
     * 初始化公司(创建表)
     */
    @PostMapping(DO_INIT_COMPANY)
    public int doInit(@RequestBody String data) {
//        List<Company> companys = JSON.parseArray(JSON.toJSONString(map.get("company")),Company.class);
//        List<Tenant> tenants=JSON.parseArray(JSON.toJSONString(map.get("tenant")),Tenant.class);
//        Integer id=(Integer) map.get("id");//选中模板的id
//        try{
//
//            int num = initGuideServiceImpl.doInit(companys, id,tenants);
//            //int num = 0;
//            if(num > 0){
//                return "";
//            }else{
//                return Optional.ofNullable(companys).orElse(Collections.emptyList()).stream().findFirst().map(Company::getName).orElse("");
//            }
//        }catch (Exception e) {
//            return Optional.ofNullable(companys).orElse(Collections.emptyList()).stream().findFirst().map(Company::getName).orElse("");
//        }
        return initGuideService.initTenantCompany(JSONTool.toObj(data, InitCompany.class));
    }
 
 
    /**
     * 获取初始化过的公司
     */
    @PostMapping(SELECT_INITCOMPANY)
    public List<InitCompany> getInitCompany(@RequestBody InitCompany initCompany) {
        return initGuideService.getInitCompany(initCompany);
    }
    /**
     * 获取初始化过的公司名字和租户名字
     */
    @PostMapping(SELECT_INITCOMPANY_COMPANYNAME_TENANTNAME)
    public List<Map<String,String>> getInitCompanyAndTenantnameAndCompanyname(@RequestBody Map<String,String> map){
        return initCompanyMapper.selectTenantnameAndCompanynameByid(map.get("tenantId"),map.get("companyId"));
    }
 
    @PostMapping(ADMIN_SELECT_BATCH_COMPANY)
    public List<BatchInitCompany> selectBatchCompanys() {
        return initGuideService.selectBatchCompanys();
    }
 
    @PostMapping(ADMIN_UPDATE_BATCH_COMPANY)
    public int updateBatchCompanys(@RequestBody BatchInitCompany batchInitCompany) {
        return initGuideService.updateBatchCompanys(batchInitCompany);
    }
 
    /**
     * 用于手动初始化初始化参数
     *
     * @param tenantId   租户id
     * @param cscId      云尚行请求接口id   epc.changhong.csc-id = 1000000
     * @param privateKey 云尚行私钥           epc.changhong.csc-private-key = fa5e4cca8dc79ad8aa333e867b2ecb10
     * @return
     */
    @PostMapping(ADMIN_HANDLE_INIT01)
    public Map<String, Object> handleInit(@RequestParam(value = "tenantId", required = false) String tenantId,
                                          @RequestParam(value = "cscId", required = false) String cscId,
                                          @RequestParam(value = "privateKey", required = false) String privateKey) {
        return CscUtils.getParam(
                new ModelMap("tenantId", tenantId)
                , cscId
                , privateKey
        );
    }
 
    /**
     * 用于手动初始化初始化参数
     *
     * @param tenantId  租户id
     * @param companyId 公司id
     * @param serviceId 流程引擎业务系统id  epc.changhong.process-service-id = 9
     * @return
     */
    @PostMapping(ADMIN_HANDLE_INIT02)
    public Map<String, Object> handleInitWorkFlow(@RequestParam(value = "tenantId", required = false) String tenantId,
                                                  @RequestParam(value = "companyId", required = false) String companyId,
                                                  @RequestParam(value = "serviceId", required = false) String serviceId) {
        return workflowTool.getProcess(
                new ModelMap("tenantId", tenantId)
                        .addAttribute("companyId", companyId)
                        .addAttribute("serviceId", serviceId)
        ).getChackmap();
    }
 
}