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 getTenants(@RequestBody Tenant tenant) { return initGuideService.getTenants(tenant); } /** * 查询公司 */ @PostMapping(SELECT_COMPANYS) public PageResult 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, @PathVariable Integer costTypeTempId) { return initGuideService.initCompanys(batchInitCompany, costTypeTempId); } /** * @Author WangYX * @Description 查询初始化进度 * @Date 2019/3/28 3:19 PM */ @PostMapping(ADMIN_SELECT_COMPANYS) public List selectInitCompanys(@PathVariable String groupId) { return initGuideService.selectInitCompanys(groupId); } /** * 初始化公司(创建表) */ @PostMapping(DO_INIT_COMPANY) public int doInit(@RequestBody String data) { // List companys = JSON.parseArray(JSON.toJSONString(map.get("company")),Company.class); // List 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 getInitCompany(@RequestBody InitCompany initCompany) { return initGuideService.getInitCompany(initCompany); } /** * 获取初始化过的公司名字和租户名字 */ @PostMapping(SELECT_INITCOMPANY_COMPANYNAME_TENANTNAME) public List> getInitCompanyAndTenantnameAndCompanyname(@RequestBody Map map){ return initCompanyMapper.selectTenantnameAndCompanynameByid(map.get("tenantId"),map.get("companyId")); } @PostMapping(ADMIN_SELECT_BATCH_COMPANY) public List 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 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 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(); } }