package cn.autoform.web.client.impl; import cn.autoform.bean.*; import cn.autoform.bean.page.PageResult; import cn.autoform.bean.power.PowerButton; import cn.autoform.bean.system.UserInfo; import cn.autoform.db.entity.IpAndPortEntity; import cn.autoform.db.exten.SelectForm; import cn.autoform.db.exten.ServicesFormData; import cn.autoform.db.exten.TableStructure; import cn.autoform.fw.exception.FormClientException; import cn.autoform.fw.exception.FormClientTimeout; import cn.autoform.fw.exception.RestResult; import cn.autoform.log.bean.OperationLog; import cn.autoform.util.tool.GetFormClientResult; import cn.autoform.util.tool.JSONTool; import cn.autoform.util.tool.ObjectUtil; import cn.autoform.util.tool.RequestContext; import cn.autoform.web.client.FormClient; import cn.autoform.web.client.util.HttpClientTool; import cn.autoform.web.client.util.IpAndPortTool; import com.alibaba.fastjson.TypeReference; import com.iemsoft.framework.cloud.core.tools.http.Http; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.ui.ModelMap; import java.util.*; import java.util.concurrent.TimeoutException; @Service public class FormClientImpl implements FormClient { @Value("${autoForm.businessSystem}") private String autoFormClient; @Autowired IpAndPortTool ipAndPortTool; private static final Map ipMap = new HashMap<>(); public static final String CLIENT_CONTEXT_PATH = "/auto-form-client"; static { ipMap.put("dataInsert", "%s/epc/epc-form" + CLIENT_CONTEXT_PATH + "/data/insert"); ipMap.put("impDatas", "%s/epc/epc-form" + CLIENT_CONTEXT_PATH + "/data/impDatas"); ipMap.put("dataUpdate", "%s/epc/epc-form" + CLIENT_CONTEXT_PATH + "/data/update"); ipMap.put("dataDelete", "%s/epc/epc-form" + CLIENT_CONTEXT_PATH + "/data/delete"); ipMap.put("dataSelectAll", "%s/epc/epc-form" + CLIENT_CONTEXT_PATH + "/data/selectAll"); ipMap.put("dataSelectPage", "%s/epc/epc-form" + CLIENT_CONTEXT_PATH + "/data/selectPage"); ipMap.put("dataSelectOne", "%s/epc/epc-form" + CLIENT_CONTEXT_PATH + "/data/selectOne"); ipMap.put("createTable", "%s/epc/epc-form" + CLIENT_CONTEXT_PATH + "/create/table"); ipMap.put("updateTable", "%s/epc/epc-form" + CLIENT_CONTEXT_PATH + "/update/table"); ipMap.put("selectFormValue", "%s/epc/epc-form" + CLIENT_CONTEXT_PATH + "/select/formFieldMainValue"); ipMap.put("getAssociateDataSourse", "%s/epc/epc-form" + CLIENT_CONTEXT_PATH + "/select/associateDataSourse"); ipMap.put("getAssociateData", "%s/epc/epc-form" + CLIENT_CONTEXT_PATH + "/select/associateData"); ipMap.put("getAssociateTitle", "%s/epc/epc-form" + CLIENT_CONTEXT_PATH + "/select/associateTitle"); ipMap.put("operationLog", "%s/epc/epc-form" + "/form/operationLog"); ipMap.put("workFlowOver", "%s/epc/epc-form" + CLIENT_CONTEXT_PATH + "/WorkFlow/over"); ipMap.put("workFlowBefor", "%s/epc/epc-form" + CLIENT_CONTEXT_PATH + "/WorkFlow/befor"); ipMap.put("workFlowAfter", "%s/epc/epc-form" + CLIENT_CONTEXT_PATH + "/WorkFlow/after"); ipMap.put("workFlowRollback", "%s/epc/epc-form" + CLIENT_CONTEXT_PATH + "/WorkFlow/rollback"); ipMap.put("workFlowCreate", "%s/epc/epc-form" + CLIENT_CONTEXT_PATH + "/WorkFlow/create"); ipMap.put("budget", "%s/epc/epc-form" + CLIENT_CONTEXT_PATH + "/form/data/budget"); ipMap.put("getUserInfo", "%s/epc/epc-tenant/tenant/getUserCode"); // ipMap.put("getHigorg", "%s/epc/epc-tenant/tenant/data/budget"); ipMap.put("getCode", "%s/epc/epc-form" + CLIENT_CONTEXT_PATH + "/select/higCode"); ipMap.put("getUserName", "%s/epc/epc-form" + CLIENT_CONTEXT_PATH + "/data/getUserName"); ipMap.put("updateState", "%s/epc/epc-form/form/data/updateState"); //费用云内部请求 ipMap.put("selectState", "%s/epc/epc-form/form/data/selectState"); //费用云内部请求 ipMap.put("getAllButton", "%s/epc/epc-form/form/button/getAllButton");//费用云 自定义按钮权限 ipMap.put("formSolidiFication", "%s/epc/epc-form/data/formSolidiFication");//单据固化 ipMap.put("addExcelLog", "%s/epc/epc-form/form/excel/addExcelLog"); ipMap.put("updateExcelLog", "%s/epc/epc-form/form/excel/updateExcelLog"); ipMap.put("selectLog", "%s/epc/epc-form/form/select/operationLog");//操作日志查询接口 // ipMap.put("dataInsert", "%s/data/insert"); // ipMap.put("dataUpdate", "%s/data/update"); // ipMap.put("dataDelete", "%s/data/delete"); // ipMap.put("dataSelectAll", "%s/data/selectAll"); // ipMap.put("dataSelectPage", "%s/data/selectPage"); // ipMap.put("dataSelectOne", "%s/data/selectOne"); // ipMap.put("createTable", "%s/create/table"); // ipMap.put("updateTable", "%s/update/table"); // ipMap.put("selectFormValue", "%s/select/formFieldMainValue"); // ipMap.put("getAssociateDataSourse", "%s/select/associateDataSourse"); // ipMap.put("getAssociateData", "%s/select/associateData"); // ipMap.put("getAssociateTitle", "%s/select/associateTitle"); } @SuppressWarnings({"unchecked", "rawtypes"}) @Override public Object addFormDataClient(ServicesFormData formData) throws TimeoutException, FormClientException { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); HttpClientTool hc = new HttpClientTool(String.format(ipMap.get("dataInsert"), ipAndPortEntity.getIp())); hc.setBodyInfos(formData); RestResult result = hc.sendPost( j -> JSONTool.toObj(j, new TypeReference() { })); return GetFormClientResult.getRightResult(result); } @SuppressWarnings({"unchecked", "rawtypes"}) @Override public PageResult> selectOperationLog(Map map) throws TimeoutException, FormClientException { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); HttpClientTool hc = new HttpClientTool(String.format(ipMap.get("selectLog"), ipAndPortEntity.getIp())); hc.setBodyInfos(map); RestResult result = hc.sendPost( j -> JSONTool.toObj(j, new TypeReference() { })); return GetFormClientResult.getRightResult(result); } @Override public Object addOperationLog(Map map) throws TimeoutException, FormClientException { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); HttpClientTool hc = new HttpClientTool(String.format(ipMap.get("operationLog"), ipAndPortEntity.getIp())); hc.setBodyInfos(map); RestResult result = hc.sendPost( j -> JSONTool.toObj(j, new TypeReference() { })); return GetFormClientResult.getRightResult(result); } @SuppressWarnings({"unchecked", "rawtypes"}) @Override public String mmp(String org) throws TimeoutException, FormClientException { Map map = new HashMap(); map.put("code", org); IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); HttpClientTool hc = new HttpClientTool(String.format(ipMap.get("getCode"), ipAndPortEntity.getIp())); hc.setBodyInfos(map); RestResult result = hc.sendPost( j -> JSONTool.toObj(j, new TypeReference() { })); Map res = JSONTool.toObj(JSONTool.toJson(result.getData()), Map.class); Object a = res.get("data"); if (a != null) { Map orgs = JSONTool.toObj(JSONTool.toJson(a), Map.class); return orgs.get("parentCode"); } return null; } @SuppressWarnings({"unchecked", "rawtypes"}) @Override public void updateFormDataClient(ServicesFormData formData) throws TimeoutException, FormClientException { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); HttpClientTool hc = new HttpClientTool(String.format(ipMap.get("dataUpdate"), ipAndPortEntity.getIp())); hc.setBodyInfos(formData); System.out.println("回写状态:" + JSONTool.toJson(formData)); RestResult result = hc.sendPost( j -> JSONTool.toObj(j, new TypeReference() { })); GetFormClientResult.getRightResult(result); } @SuppressWarnings({"rawtypes", "unchecked"}) @Override public void deleteFormDataClient(ServicesFormData formData) throws TimeoutException, FormClientException { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); HttpClientTool hc = new HttpClientTool(String.format(ipMap.get("dataDelete"), ipAndPortEntity.getIp())); hc.setBodyInfos(formData); RestResult result = hc.sendPost( j -> JSONTool.toObj(j, new TypeReference() { })); GetFormClientResult.getRightResult(result); } @SuppressWarnings({"rawtypes", "unchecked"}) @Override public List> queryFormDataList(SelectForm selectForm) throws FormClientException { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); HttpClientTool>>> hc = new HttpClientTool(String.format(ipMap.get("dataSelectAll"), ipAndPortEntity.getIp())); hc.setBodyInfos(selectForm); RestResult>> result; try { result = hc.sendPost( j -> JSONTool.toObj(j, new TypeReference>>>() { })); return GetFormClientResult.getRightResult(result); } catch (TimeoutException e) { throw new FormClientTimeout(); } } @SuppressWarnings({"rawtypes", "unchecked"}) @Override public Map queryFormDataOne(SelectForm selectForm) throws TimeoutException, FormClientException { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); HttpClientTool>> hc = new HttpClientTool(String.format(ipMap.get("dataSelectOne"), ipAndPortEntity.getIp())); hc.setBodyInfos(selectForm); RestResult> result = hc.sendPost( j -> JSONTool.toObj(j, new TypeReference>>() { }.getType())); return GetFormClientResult.getRightResult(result); } @SuppressWarnings({"rawtypes", "unchecked"}) @Override public PageResult> queryFormDataPage(SelectForm selectForm) throws FormClientException { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); HttpClientTool>>> hc = new HttpClientTool(String.format(ipMap.get("dataSelectPage"), ipAndPortEntity.getIp())); hc.setBodyInfos(selectForm); try { return GetFormClientResult.getRightResult(hc.sendPost( j -> JSONTool.toObj(j, new TypeReference>>>() { }))); } catch (TimeoutException e) { e.printStackTrace(); throw new FormClientTimeout(); } } @SuppressWarnings({"rawtypes", "unchecked"}) @Override public void createTable(TableStructure tableStructure) throws TimeoutException, FormClientException { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); // System.out.println(JSONTool.toJson(tableStructure)); // System.out.println(String.format(ipMap.get("createTable"), ipAndPortEntity.getIp())); HttpClientTool> hc = new HttpClientTool(String.format(ipMap.get("createTable"), ipAndPortEntity.getIp())); hc.setBodyInfos(tableStructure); GetFormClientResult.getRightResult(hc.sendPost( j -> JSONTool.toObj(j, new TypeReference>() { }))); } @SuppressWarnings({"rawtypes", "unchecked"}) @Override public void updateTable(TableStructure tableStructure) throws Exception { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); HttpClientTool> hc = new HttpClientTool(String.format(ipMap.get("updateTable"), ipAndPortEntity.getIp())); hc.setBodyInfos(tableStructure); hc.sendPost( j -> JSONTool.toObj(j, new TypeReference>() { })); // GetFormClientResult.getRightResult(); } @SuppressWarnings({"rawtypes", "unchecked"}) @Override public List getFormFieldMainValue(String field, String tableName, String formID, String tenantID) throws TimeoutException, FormClientException { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); HttpClientTool>> hc = new HttpClientTool(String.format(ipMap.get("selectFormValue"), ipAndPortEntity.getIp())); Map BodyInfos = new HashMap<>(); BodyInfos.put("field", field); BodyInfos.put("tableName", tableName); hc.setBodyInfos(BodyInfos); RestResult> result = hc.sendPost( j -> JSONTool.toObj(j, new TypeReference>>() { })); return GetFormClientResult.getRightResult(result); } @SuppressWarnings({"rawtypes", "unchecked"}) @Override public List> getAssociateDataSourse() throws TimeoutException, FormClientException { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); HttpClientTool>>> hc = new HttpClientTool(String.format(ipMap.get("getAssociateDataSourse"), ipAndPortEntity.getIp())); RestResult>> result = hc.sendPost( j -> JSONTool.toObj(j, new TypeReference>>>() { })); return GetFormClientResult.getRightResult(result); } @SuppressWarnings({"unchecked", "rawtypes"}) @Override public Map getAssociateData(BudgetData budgetData) throws TimeoutException, FormClientException { System.err.println(JSONTool.toJson(budgetData)); IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); HttpClientTool>> hc = new HttpClientTool(String.format(ipMap.get("getAssociateData"), ipAndPortEntity.getIp())); hc.setBodyInfos(budgetData); RestResult> result = hc.sendPost( j -> JSONTool.toObj(j, new TypeReference>>() { })); return GetFormClientResult.getRightResult(result); } @SuppressWarnings("rawtypes") @Override public List getAssociateTitle(Map key) throws TimeoutException, FormClientException { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); @SuppressWarnings("unchecked") HttpClientTool>> hc = new HttpClientTool(String.format(ipMap.get("getAssociateTitle"), ipAndPortEntity.getIp())); hc.setBodyInfos(key); RestResult> result = hc.sendPost( j -> JSONTool.toObj(j, new TypeReference>>() { })); return GetFormClientResult.getRightResult(result); } @SuppressWarnings("rawtypes") @Override public Object getBudget(ProcessBudget processBudget) throws TimeoutException, FormClientException { System.err.println(JSONTool.toJson(processBudget)); IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); @SuppressWarnings("unchecked") HttpClientTool> hc = new HttpClientTool(String.format(ipMap.get("budget"), ipAndPortEntity.getIp())); hc.setBodyInfos(processBudget); RestResult result = hc.sendPost( j -> JSONTool.toObj(j, new TypeReference>() { })); return GetFormClientResult.getRightResult(result); } @SuppressWarnings({"unchecked", "rawtypes"}) @Override public void workFlowOver(WorkFlowStateEntity workFlowStateEntity) throws TimeoutException, FormClientException { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); RestResult result = (RestResult) Http.post(String.format(ipMap.get("workFlowOver"), ipAndPortEntity.getIp()), RestResult.class) .addBody(workFlowStateEntity) .addHeader(RequestContext.getHeader()) .execute(new TypeReference>() { }.getType()) .orElse(RestResult.newInstance()); GetFormClientResult.getRightResult(result); } @Override public void workFlowAfter(WorkFlowStateEntity workFlowStateEntity) throws TimeoutException, FormClientException { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); RestResult result = (RestResult) Http.post(String.format(ipMap.get("workFlowAfter"), ipAndPortEntity.getIp()), RestResult.class) .addBody(workFlowStateEntity) .addHeader(RequestContext.getHeader()) .execute(new TypeReference>() { }.getType()) .orElse(RestResult.newInstance()); GetFormClientResult.getRightResult(result); } @Override public void workFlowBefor(WorkFlowStateEntity workFlowStateEntity) throws TimeoutException, FormClientException { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); RestResult result = (RestResult) Http.post(String.format(ipMap.get("workFlowBefor"), ipAndPortEntity.getIp()), RestResult.class) .addBody(workFlowStateEntity) .addHeader(RequestContext.getHeader()) .execute(new TypeReference>() { }.getType()) .orElse(RestResult.newInstance()); GetFormClientResult.getRightResult(result); } @SuppressWarnings("rawtypes") @Override public String getUserName(String formID, String tenantID, Integer dataRowNum) throws TimeoutException, FormClientException { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); @SuppressWarnings("unchecked") HttpClientTool> hc = new HttpClientTool(String.format(ipMap.get("getUserName"), ipAndPortEntity.getIp())); hc.setBodyInfos(new ModelMap("formID", formID) .addAttribute("tenantID", tenantID) .addAttribute("dataRowNum", dataRowNum) .addAttribute("formName", "formdata_" + tenantID + "_" + formID)); RestResult result = hc.sendPost( j -> JSONTool.toObj(j, new TypeReference>() { })); return GetFormClientResult.getRightResult(result); } @SuppressWarnings("rawtypes") @Override public int updateState(ProcessState process) throws FormClientException, TimeoutException { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); Map result = (Map) Http.post(String.format(ipMap.get("updateState"), ipAndPortEntity.getIp()), Map.class) .addBody(process) .addHeader(RequestContext.getHeader()) .execute(new TypeReference>() { }.getType()) .orElse(Collections.EMPTY_MAP); return Integer.parseInt(Objects.toString(JSONTool.toJson(result.get("data")), "-1")); } @Override public ProcessState selectState(ProcessState process) throws TimeoutException { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); HttpClientTool> hc = new HttpClientTool>(String.format(ipMap.get("selectState"), ipAndPortEntity.getIp())); hc.setBodyInfos(process); Map result = hc.sendPost( j -> JSONTool.toObj(j, new TypeReference>() { })); System.out.println("查询返回结果:" + JSONTool.toJson(result)); Object o = result.get("data"); if (!ObjectUtil.empty(o)) { return JSONTool.toObj(JSONTool.toJson(o), ProcessState.class); } else { return null; } } @Override public PowerButton getAllButton(String formId, ProcessState state) throws TimeoutException { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); HttpClientTool> hc = new HttpClientTool>(String.format(ipMap.get("getAllButton"), ipAndPortEntity.getIp())); hc.setBodyInfos(new ModelMap("formId", formId).addAttribute("state", state)); Map result = hc.sendPost( j -> JSONTool.toObj(j, new TypeReference>() { })); Object obj = result.get("data"); return JSONTool.toObj(JSONTool.toJson(obj), PowerButton.class); } @Override public int formSolidiFication(FormSolidiFication map) throws TimeoutException { @SuppressWarnings("unchecked") IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); HttpClientTool> hc = new HttpClientTool>(String.format(ipMap.get("formSolidiFication"), ipAndPortEntity.getIp())); hc.setBodyInfos(map); Map ma = hc.sendPost( j -> JSONTool.toObj(j, new TypeReference>() { })); return Integer.parseInt(Objects.toString(ma.get("data"), "-1")); } @Override public Integer impDatas(List allFormDataList) throws TimeoutException { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); HttpClientTool> hc = new HttpClientTool>(String.format(ipMap.get("impDatas"), ipAndPortEntity.getIp())); hc.setBodyInfos(allFormDataList); Map ma = hc.sendPost( j -> JSONTool.toObj(j, new TypeReference>() { })); return Integer.parseInt(Objects.toString(ma.get("data"), "-1")); } @Override public Integer addExcelLog(ExcelLog excelLog) throws TimeoutException { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); HttpClientTool> hc = new HttpClientTool>(String.format(ipMap.get("addExcelLog"), ipAndPortEntity.getIp())); hc.setBodyInfos(excelLog); Map ma = hc.sendPost( j -> JSONTool.toObj(j, new TypeReference>() { })); return Integer.parseInt(Objects.toString(ma.get("data"), "-1")); } @Override public Integer updateExcelLog(ExcelLog excelLog) throws TimeoutException { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); HttpClientTool> hc = new HttpClientTool>(String.format(ipMap.get("updateExcelLog"), ipAndPortEntity.getIp())); hc.setBodyInfos(excelLog); Map ma = hc.sendPost( j -> JSONTool.toObj(j, new TypeReference>() { })); return Integer.parseInt(Objects.toString(ma.get("data"), "-1")); } @Override public void workFlowRollback(WorkFlowStateEntity workFlowStateEntity) { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); RestResult result = (RestResult) Http.post(String.format(ipMap.get("workFlowRollback"), ipAndPortEntity.getIp()), RestResult.class) .addBody(workFlowStateEntity) .addHeader(RequestContext.getHeader()) .execute(new TypeReference>() { }.getType()) .orElse(RestResult.newInstance()); GetFormClientResult.getRightResult(result); } @Override public void workFlowCreate(WorkFlowStateEntity workFlowStateEntity) { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); RestResult result = (RestResult) Http.post(String.format(ipMap.get("workFlowCreate"), ipAndPortEntity.getIp()), RestResult.class) .addBody(workFlowStateEntity) .addHeader(RequestContext.getHeader()) .execute(new TypeReference>() { }.getType()) .orElse(RestResult.newInstance()); GetFormClientResult.getRightResult(result); } @Override public UserInfo getUserInfo() { IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(autoFormClient); RestResult result = (RestResult) Http.post(String.format(ipMap.get("getUserInfo"), ipAndPortEntity.getIp()), RestResult.class) .addBody(new UserInfo()) .addHeader(RequestContext.getHeader()) .execute(new TypeReference>() { }.getType()) .orElse(RestResult.newInstance()); GetFormClientResult.getRightResultGetUserCode(result); return result.getData(); } }