| | |
| | | public class MdmUtils { |
| | | |
| | | @Value("${MDM_ADRESS}") |
| | | private static String MDM_ADRESS; |
| | | private String MDM_ADRESS; |
| | | |
| | | @Autowired |
| | | private MdmService mdmService; |
| | |
| | | * MDM局域物料名称编码数据获取 |
| | | * @return |
| | | */ |
| | | public String queryMaterial(){ |
| | | public String queryMaterial(String name){ |
| | | StringBuffer returnJson = new StringBuffer(); |
| | | Map<String,String> params = new HashMap<>(); |
| | | params.put("code","1560000581165.1560000576507.a94a779e9e6d3ecbb646e39477dad6ec");//授权码 |
| | | params.put("current","1");//页码 |
| | | params.put("size","1000");//每页记录数(最大1000) |
| | | params.put("queryValue","");//模糊查询 |
| | | MdmEnum anEnum = MdmEnum.getMdmEnumByAddress("局域物料名称编码数据获取"); |
| | | MdmEnum anEnum = MdmEnum.getMdmEnumByAddress(name); |
| | | String address = anEnum.getAddress(); |
| | | try { |
| | | HttpClientResult httpClientResult = MdmApiUtils.doPost(MDM_ADRESS+address, null, params); |
| | |
| | | if(200 == code){ |
| | | //成功 |
| | | String records = httpClientResult.getContent(); |
| | | /*String records = "{\n" + |
| | | " \"current\": 1,\n" + |
| | | " \"orders\": [],\n" + |
| | | " \"pages\": 303,\n" + |
| | | " \"records\": [\n" + |
| | | " {\n" + |
| | | " \"aliascode\": \"000\",\n" + |
| | | " \"appfrom\": \"1\",\n" + |
| | | " \"applicationaccountid\": \"D15600005811650001\",\n" + |
| | | " \"applicationname\": \"审核管理员\",\n" + |
| | | " \"attri1\": \"\",\n" + |
| | | " \"attri10\": \"\",\n" + |
| | | " \"attri11\": \"\",\n" + |
| | | " \"attri12\": \"产品\",\n" + |
| | | " \"attri13\": \"1667957805944\",\n" + |
| | | " \"attri14\": \"\",\n" + |
| | | " \"attri15\": \"0003.000\",\n" + |
| | | " \"attri2\": \"\",\n" + |
| | | " \"attri3\": \"\",\n" + |
| | | " \"attri4\": \"\",\n" + |
| | | " \"attri5\": \"\",\n" + |
| | | " \"attri6\": \"\",\n" + |
| | | " \"attri7\": \"\",\n" + |
| | | " \"attri8\": \"\",\n" + |
| | | " \"attri9\": \"\",\n" + |
| | | " \"companyid\": \"1560000581165\",\n" + |
| | | " \"employeeid\": \"\",\n" + |
| | | " \"globtgccode\": \"\",\n" + |
| | | " \"id\": 1668994782539,\n" + |
| | | " \"industrycode\": \"517\",\n" + |
| | | " \"industryname\": \"医药卫生保健化妆品业\",\n" + |
| | | " \"name\": \"感冒药\",\n" + |
| | | " \"nameen\": \"abc\",\n" + |
| | | " \"note\": \"\",\n" + |
| | | " \"ontologynamecode\": \"9000000003\",\n" + |
| | | " \"pym\": \"gmy\",\n" + |
| | | " \"rebacklockflag\": \"\",\n" + |
| | | " \"regioncode\": \"\",\n" + |
| | | " \"regionlevel\": \"\",\n" + |
| | | " \"repeatflag\": \"\",\n" + |
| | | " \"status\": \"200\",\n" + |
| | | " \"tgcoriginalcode\": \"9000000003.000\",\n" + |
| | | " \"updatedat\": 1668995367562,\n" + |
| | | " \"updatetime\": 1668995367562\n" + |
| | | " }\n" + |
| | | " ],\n" + |
| | | " \"searchCount\": true,\n" + |
| | | " \"size\": 1,\n" + |
| | | " \"total\": 303\n" + |
| | | "}";*/ |
| | | records = records.replaceAll("\\p{Z}", ""); |
| | | JSONObject jsonObj = JSON.parseObject(records); |
| | | records = jsonObj.getString("records"); |
| | | records = records.replaceAll("attri2","unitName"); |
| | | records = records.replaceAll("brand","supplierName"); |
| | | records = records.replaceAll("jzgg","specification"); |
| | | records = records.replaceAll("model","specificationDisplayName"); |
| | | records = records.replaceAll("namecn","code"); |
| | | records = records.replaceAll("hyflmc","typeCode"); |
| | | JSONArray recordArray = JSON.parseArray(records);//物料数据信息 |
| | | //将数据保存至数据库 |
| | | JSONArray newJson = mdmService.saveMdmData(recordArray); |
| | | JSONArray newJson = mdmService.saveMdmData(recordArray,name); |
| | | if(newJson.size()!=0){ |
| | | //定义返回json格式 |
| | | returnJson.append("{\n" + |
| | | /*returnJson.append("{\n" + |
| | | " \"current\": 1,\n" + |
| | | " \"orders\": [],\n" + |
| | | " \"pages\": 303,"); |
| | | returnJson.append("\"records\": "+newJson.toJSONString()); |
| | | returnJson.append(",\n" + |
| | | " \"pages\": 303,");*/ |
| | | returnJson.append("{\"records\": "+newJson.toJSONString()+"}"); |
| | | /*returnJson.append(",\n" + |
| | | " \"searchCount\": true,\n" + |
| | | " \"size\": 1,\n" + |
| | | " \"total\": 303\n" + |
| | | "}");*/ |
| | | //返回json格式参数 |
| | | String toString = returnJson.toString(); |
| | | System.out.println("响应参数分发:"+toString); |
| | | //分发增量数据至异构系统 |
| | | distributeDataToSys(toString,name); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | /** |
| | | * MDM计量单位数据获取 |
| | | * @return |
| | | */ |
| | | public String queryUnit(String name){ |
| | | MdmEnum anEnum = MdmEnum.getMdmEnumByAddress(name); |
| | | StringBuffer returnJson = new StringBuffer(); |
| | | Map<String,String> params = new HashMap<>(); |
| | | params.put("code","1560000581165.1560000576507.a94a779e9e6d3ecbb646e39477dad6ec");//授权码 |
| | | params.put("type",anEnum.getType());//类型 |
| | | String address = anEnum.getAddress(); |
| | | try { |
| | | HttpClientResult httpClientResult = MdmApiUtils.doPost(MDM_ADRESS+address, null, params); |
| | | int code = httpClientResult.getCode(); |
| | | if(200 == code){ |
| | | //成功 |
| | | String records = httpClientResult.getContent(); |
| | | records = records.replaceAll("\\p{Z}", ""); |
| | | JSONObject jsonObj = JSON.parseObject(records); |
| | | records = jsonObj.getString("data"); |
| | | JSONArray recordArray = JSON.parseArray(records);//物料数据信息 |
| | | //将数据保存至数据库 |
| | | JSONArray newJson = mdmService.saveMdmUnitData(recordArray,name); |
| | | if(newJson.size()!=0){ |
| | | //定义返回json格式 |
| | | returnJson.append("{\n" + |
| | | " \"code\": 200,\n" + |
| | | " \"data\":"+newJson.toJSONString()); |
| | | returnJson.append(",\n" + |
| | | " \"message\": \"请求成功\",\n" + |
| | | " \"success\": true\n" + |
| | | "}"); |
| | | //返回json格式参数 |
| | | String toString = returnJson.toString(); |
| | | System.out.println(toString); |
| | | //分发增量数据至异构系统 |
| | | distributeDataToSys(toString,"局域物料名称编码数据获取"); |
| | | distributeDataToSys(toString,name); |
| | | } |
| | | } |
| | | } catch (Exception e) { |