package com.changhong.epc.rely.api.service.workFlow.impl; import com.alibaba.fastjson.TypeReference; import com.changhong.epc.constter.base.Context; import com.changhong.epc.constter.system.SystemClients; import com.changhong.epc.constter.system.prop.ChangHongProperties; import com.changhong.epc.constter.system.prop.ChangHongProperties.PassPortName; import com.changhong.epc.rely.api.service.workFlow.WorkFlowService; import com.changhong.epc.rely.api.tool.HttpUtil; import com.changhong.epc.rely.api.tool.WorkflowTool; import com.iemsoft.framework.cloud.core.constant.BaseConst; import com.iemsoft.framework.cloud.core.exception.IEMRuntimeException; import com.iemsoft.framework.cloud.core.thread.Keys; import com.iemsoft.framework.cloud.core.thread.ThreadData; import com.iemsoft.framework.cloud.core.tools.SpringUtil; import com.iemsoft.framework.cloud.core.tools.http.Http; import com.iemsoft.framework.cloud.core.tools.http.IEMHttpException; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.ui.ModelMap; import java.util.Map; import java.util.Objects; import java.util.concurrent.TimeoutException; @Slf4j @Service("workFlowServiceImpl") public class WorkFlowServiceImpl implements WorkFlowService,BaseConst,SystemClients { @Autowired private WorkflowTool workflowTool; @Autowired private ChangHongProperties changHongProperties; /** * 删除流程定义,批量 */ @Override public Map defineDelete(Map maps) throws TimeoutException { Map map = null; try { map = HttpUtil.post(changHongProperties.getPassUrl(PassPortName.DEF_DELETE, null) , null,workflowTool.getProcess(maps).getFlowmap() , null, new TypeReference>(){}.getType()); // System.out.println("最后参数"+JSONTool.toJson(workflowTool.getProcess(maps).getFlowmap())); return map; } catch (Exception e) { throw new IEMRuntimeException(C0002).setchildIEMExc(changHongProperties.getPassUrl(PassPortName.FIND_TENANT_ORGANIZATION, null)); } } /** * 部署流程定义 */ @Override public Map definePeploy(Map maps) throws TimeoutException { Map map = null; try { map = HttpUtil.post(changHongProperties.getPassUrl(PassPortName.DEF_DEPLOY, null) , null,workflowTool.getProcess(maps).getFlowmap() , null, new TypeReference>(){}.getType()); // System.out.println("最后参数"+JSONTool.toJson(workflowTool.getProcess(maps).getFlowmap())); return map; } catch (Exception e) { throw new IEMRuntimeException(C0002).setchildIEMExc(changHongProperties.getPassUrl(PassPortName.FIND_TENANT_ORGANIZATION, null)); } } /** * 流程定义分页查询 */ @Override public Map defineSeache(Map maps) throws TimeoutException { Map map = null; try { map = HttpUtil.post(changHongProperties.getPassUrl(PassPortName.DEF_SEACHE, null) , null,workflowTool.getProcess(maps).getFlowmap() , null, new TypeReference>(){}.getType()); // System.out.println("最后参数"+JSONTool.toJson(workflowTool.getProcess(maps).getFlowmap())); return map; } catch (Exception e) { throw new IEMRuntimeException(C0002).setchildIEMExc(changHongProperties.getPassUrl(PassPortName.FIND_TENANT_ORGANIZATION, null)); } } /** * 创建流程定义 */ @Override public Map defineCreate(Map maps) throws TimeoutException { Map map = null; // System.out.println("进入方法2"); // System.out.println("参数:"+JSONTool.toJson(maps)); // System.out.println("入口参数"+ changHongProperties.getPassUrl(PassPortName.DEF_CREATE, null)); try { map = HttpUtil.post(changHongProperties.getPassUrl(PassPortName.DEF_CREATE, null) , null,workflowTool.getProcess(maps).getFlowmap() , null, new TypeReference>(){}.getType()); // System.out.println("最后参数"+JSONTool.toJson(workflowTool.getProcess(maps).getFlowmap())); return map; } catch (Exception e) { throw new IEMRuntimeException(C0002).setchildIEMExc(changHongProperties.getPassUrl(PassPortName.FIND_TENANT_ORGANIZATION, null)); } } /** * 退回流程实例 */ @Override public Map instBack(Map maps) throws TimeoutException { Map map = null; try { map = HttpUtil.post(changHongProperties.getPassUrl(PassPortName.INST_BACK, null) , null,workflowTool.getProcess(maps).getFlowmap() , null, new TypeReference>(){}.getType()); // System.out.println("最后参数"+JSONTool.toJson(workflowTool.getProcess(maps).getFlowmap())); return map; } catch (Exception e) { throw new IEMRuntimeException(C0002).setchildIEMExc(changHongProperties.getPassUrl(PassPortName.FIND_TENANT_ORGANIZATION, null)); } } /** * 设置代理 */ @Override public Map agentCreat(Map maps) throws TimeoutException { Map map = null; try { map = HttpUtil.post(changHongProperties.getPassUrl(PassPortName.CREATE_AGENT, null) , null,workflowTool.getProcess(maps).getFlowmap() , null, new TypeReference>(){}.getType()); // System.out.println("最后参数"+JSONTool.toJson(workflowTool.getProcess(maps).getFlowmap())); return map; } catch (Exception e) { throw new IEMRuntimeException(C0002).setchildIEMExc(changHongProperties.getPassUrl(PassPortName.FIND_TENANT_ORGANIZATION, null)); } } /** * 创建流程实例 */ @Override public Map instCreat(Map maps) throws TimeoutException { Map map = null; try { map = HttpUtil.post(changHongProperties.getPassUrl(PassPortName.INST_CREATE, null) , null,workflowTool.getProcess(maps).getFlowmap() , null, new TypeReference>(){}.getType()); // System.out.println("最后参数"+JSONTool.toJson(workflowTool.getProcess(maps).getFlowmap())); return map; } catch (Exception e) { throw new IEMRuntimeException(C0002).setchildIEMExc(changHongProperties.getPassUrl(PassPortName.FIND_TENANT_ORGANIZATION, null)); } } /** * 撤销流程实例 */ @Override public Map instDrawBack(Map maps) throws TimeoutException { Map map = null; try { map = HttpUtil.post(changHongProperties.getPassUrl(PassPortName.INST_DRAWBACK, null) , null,workflowTool.getProcess(maps).getFlowmap() , null, new TypeReference>(){}.getType()); // System.out.println("最后参数"+JSONTool.toJson(workflowTool.getProcess(maps).getFlowmap())); return map; } catch (Exception e) { throw new IEMRuntimeException(C0002).setchildIEMExc(changHongProperties.getPassUrl(PassPortName.FIND_TENANT_ORGANIZATION, null)); } } /** * 结束流程实例 */ @Override public Map instOver(Map maps) throws TimeoutException { Map map = null; try { map = HttpUtil.post(changHongProperties.getPassUrl(PassPortName.INST_OVER, null) , null,workflowTool.getProcess(maps).getFlowmap() , null, new TypeReference>(){}.getType()); // System.out.println("最后参数"+JSONTool.toJson(workflowTool.getProcess(maps).getFlowmap())); return map; } catch (Exception e) { throw new IEMRuntimeException(C0002).setchildIEMExc(changHongProperties.getPassUrl(PassPortName.FIND_TENANT_ORGANIZATION, null)); } } /** * 设置代办 */ @Override public Map chargeCreate(Map maps) throws TimeoutException { Map map = null; try { map = HttpUtil.post(changHongProperties.getPassUrl(PassPortName.CREATE_CHARGE, null) , null,workflowTool.getProcess(maps).getFlowmap() , null, new TypeReference>(){}.getType()); // System.out.println("最后参数"+JSONTool.toJson(workflowTool.getProcess(maps).getFlowmap())); return map; } catch (Exception e) { throw new IEMRuntimeException(C0002).setchildIEMExc(changHongProperties.getPassUrl(PassPortName.FIND_TENANT_ORGANIZATION, null)); } } /** * 执行流程实例 */ @Override public Map instFinish(Map maps) throws TimeoutException { Map map = null; try { map = HttpUtil.post(changHongProperties.getPassUrl(PassPortName.INST_FINISH, null) , null,workflowTool.getProcess(maps).getFlowmap() , null, new TypeReference>(){}.getType()); // System.out.println("最后参数"+JSONTool.toJson(workflowTool.getProcess(maps).getFlowmap())); return map; } catch (Exception e) { throw new IEMRuntimeException(C0002).setchildIEMExc(changHongProperties.getPassUrl(PassPortName.FIND_TENANT_ORGANIZATION, null)); } } /** * 查询流程待办 */ @Override public Map instSeacheHandle(Map maps) throws TimeoutException { Map map; try { maps.put("tenantId", ThreadData.get(Keys.TENANT_ID)); maps.put("compId", ThreadData.get(Keys.COMPANY_ID)); maps.put("appId", SpringUtil.getBean(ChangHongProperties.class).getProcessServiceId()); maps.put("openId", Context.getOpenId()); maps.put("sourceSystem", "epc"); map = HttpUtil.post(changHongProperties.getPassUrl(PassPortName.SEACHE_HANDLE, null) , null,workflowTool.getProcess(maps).getFlowmap() , null, new TypeReference>(){}.getType()); // System.out.println("最后参数"+JSONTool.toJson(workflowTool.getProcess(maps).getFlowmap())); return map; } catch (Exception e) { throw new IEMRuntimeException(C0002).setchildIEMExc(changHongProperties.getPassUrl(PassPortName.FIND_TENANT_ORGANIZATION, null)); } } /** * 流程实例log(参数为空即查询所有) */ @Override public Map instLog(Map maps) throws TimeoutException { Map map = null; try { map = HttpUtil.post(changHongProperties.getPassUrl(PassPortName.INST_LOG, null) , null,workflowTool.getProcess(maps).getFlowmap() , null, new TypeReference>(){}.getType()); // System.out.println("最后参数"+JSONTool.toJson(workflowTool.getProcess(maps).getFlowmap())); return map; } catch (Exception e) { throw new IEMRuntimeException(C0002).setchildIEMExc(changHongProperties.getPassUrl(PassPortName.FIND_TENANT_ORGANIZATION, null)); } } /** * 获取所有可退回项目 */ @Override public Map getBack(Map maps) throws TimeoutException { Map map = null; try { map = HttpUtil.post(changHongProperties.getPassUrl(PassPortName.GET_BACK, null) , null,workflowTool.getProcess(maps).getFlowmap() , null, new TypeReference>(){}.getType()); // System.out.println("最后参数"+JSONTool.toJson(workflowTool.getProcess(maps).getFlowmap())); return map; } catch (Exception e) { throw new IEMRuntimeException(C0002).setchildIEMExc(changHongProperties.getPassUrl(PassPortName.FIND_TENANT_ORGANIZATION, null)); } } /** * 查询代理(参数为空即查询所有信息) */ @Override public Map instAgent(Map maps) throws TimeoutException { Map map = null; try { map = HttpUtil.post(changHongProperties.getPassUrl(PassPortName.INST_AGENT, null) , null,workflowTool.getProcess(maps).getFlowmap() , null, new TypeReference>(){}.getType()); // System.out.println("最后参数"+JSONTool.toJson(workflowTool.getProcess(maps).getFlowmap())); return map; } catch (Exception e) { throw new IEMRuntimeException(C0002).setchildIEMExc(changHongProperties.getPassUrl(PassPortName.FIND_TENANT_ORGANIZATION, null)); } } /** * 查询代理去除流程定义信息 */ @Override public Map instAgentDefMsg(Map maps) throws TimeoutException { Map map = null; try { map = HttpUtil.post(changHongProperties.getPassUrl(PassPortName.AGENT_DEFMSG, null) , null,workflowTool.getProcess(maps).getFlowmap() , null, new TypeReference>(){}.getType()); // System.out.println("最后参数"+JSONTool.toJson(workflowTool.getProcess(maps).getFlowmap())); return map; } catch (Exception e) { throw new IEMRuntimeException(C0002).setchildIEMExc(changHongProperties.getPassUrl(PassPortName.FIND_TENANT_ORGANIZATION, null)); } } /** * 查询流程实例(参数都为空,即查询所有) */ @Override public Map instSeache(Map maps) throws TimeoutException { Map map = null; try { maps.put("sourceSystem", "epc"); maps.put("openId", Context.getOpenId()); map = HttpUtil.post(changHongProperties.getPassUrl(PassPortName.INST_SEACHE, null) , null,workflowTool.getProcess(maps).getFlowmap() , null, new TypeReference>(){}.getType()); // System.out.println("最后参数"+JSONTool.toJson(workflowTool.getProcess(maps).getFlowmap())); return map; } catch (Exception e) { throw new IEMRuntimeException(C0002).setchildIEMExc(changHongProperties.getPassUrl(PassPortName.FIND_TENANT_ORGANIZATION, null)); } } /** * 租户注册系统 */ @Override public Map appCreate(Map maps) throws TimeoutException { Map map = null; try { map = HttpUtil.post(changHongProperties.getPassUrl(PassPortName.APP_CREATE, null) , null,workflowTool.getProcess(maps).getFlowmap() , null, new TypeReference>(){}.getType()); // System.out.println("最后参数"+JSONTool.toJson(workflowTool.getProcess(maps).getFlowmap())); return map; } catch (Exception e) { throw new IEMRuntimeException(C0002).setchildIEMExc(changHongProperties.getPassUrl(PassPortName.FIND_TENANT_ORGANIZATION, null)); } } @Override public Integer initialization(Integer tenantId, Integer companyId) { if(check(tenantId, companyId)){ return 1; } return Http.post(changHongProperties.getPassUrl(PassPortName.UBP_INITIALIZATION, null), Map.class) .addUrlParam(workflowTool.getProcess( new ModelMap("tenantId", tenantId) .addAttribute("companyId", companyId) .addAttribute("serviceId", changHongProperties.getProcessServiceId()) ).getChackmap() ) .addValidate(res->{ if(!Objects.equals(res.get("resCode"), "00000")){ throw new IEMHttpException(Objects.toString(res.get("resMsg"))); } }) .execute(new TypeReference>(){}.getType()) .map(res->res.get("data")) .map(Object::toString) .map(Integer::valueOf) .orElse(0); } @Override public Boolean check(Integer tenantId, Integer companyId) { return Http.post(changHongProperties.getPassUrl(PassPortName.UBP_CHECK, null), Map.class) .addUrlParam(workflowTool.getProcess( new ModelMap("tenantId", tenantId) .addAttribute("companyId", companyId) .addAttribute("serviceId", changHongProperties.getProcessServiceId()) ).getChackmap() ) .addValidate(res->{ if(!Objects.equals(res.get("resCode"), "00000")){ throw new IEMHttpException(Objects.toString(res.get("resMsg"))); } }) .execute(new TypeReference>(){}.getType()) .map(res->res.get("data")) .map(Object::toString) .map(Boolean::valueOf) .orElse(false); } }