| | |
| | | import com.vincent.rsf.openApi.config.PlatformProperties; |
| | | import com.vincent.rsf.openApi.entity.constant.WmsConstant; |
| | | import com.vincent.rsf.openApi.entity.dto.CommonResponse; |
| | | import com.vincent.rsf.openApi.entity.phyz.ErpReportParams; |
| | | import com.vincent.rsf.openApi.entity.phyz.Order; |
| | | import com.vincent.rsf.openApi.entity.phyz.*; |
| | | import com.vincent.rsf.openApi.service.WmsErpService; |
| | | import com.vincent.rsf.openApi.service.phyz.ErpReportService; |
| | | import com.vincent.rsf.openApi.utils.ParamsMapUtils; |
| | |
| | | ERP_REPORT_URL = erpApi.getErpUrl(); |
| | | } |
| | | |
| | | @Override |
| | | public String syncMaterial(List<Material> materialList){ |
| | | if (materialList.isEmpty()) { |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | | /**WMS基础配置链接*/ |
| | | String wmsUrl = wmsApi.getHost() + ":" + wmsApi.getPort() + WmsConstant.SYNC_MATNRS; |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.add("Content-Type", "application/json"); |
| | | headers.add("api-version", "v2.0"); |
| | | // Material -> BaseMatParms 字段一一对应后再下发 |
| | | List<Map<String, Object>> baseMatParamsList = materialToBaseMatParams(materialList); |
| | | HttpEntity httpEntity2 = new HttpEntity<>(baseMatParamsList, headers);//cs |
| | | // sync/warehouse |
| | | ResponseEntity<String> exchange = restTemplate.exchange(wmsUrl, HttpMethod.POST, httpEntity2, String.class);//cs |
| | | log.info("同步物料信息返回结果: {}", exchange); |
| | | if (Objects.isNull(exchange.getBody())) { |
| | | throw new CoolException("查询失败!!"); |
| | | } else { |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | objectMapper.coercionConfigDefaults().setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty); |
| | | try { |
| | | CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class); |
| | | if (result.getCode() == 200) { |
| | | // JSONObject object = JSONObject.parseObject(JSONObject.toJSONString(result.getData())); |
| | | return "200"; |
| | | } else { |
| | | return result.getMsg(); |
| | | // throw new CoolException("查询失败!!"); |
| | | } |
| | | } catch (JsonProcessingException e) { |
| | | return e.getMessage(); |
| | | // throw new CoolException(e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Material 字段映射为 server 端 BaseMatParms 字段 |
| | | */ |
| | | private List<Map<String, Object>> materialToBaseMatParams(List<Material> materialList) { |
| | | List<Map<String, Object>> mappedList = new ArrayList<>(); |
| | | for (Material material : materialList) { |
| | | if (Objects.isNull(material)) { |
| | | continue; |
| | | } |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("maktx", material.getMakTx()); |
| | | map.put("matnr", material.getMatNr()); |
| | | map.put("groupName", material.getGroupName()); |
| | | map.put("model", material.getModel()); |
| | | map.put("weight", material.getWeight() == null ? null : material.getWeight().toString()); |
| | | map.put("color", material.getColor()); |
| | | map.put("size", material.getSize()); |
| | | map.put("spec", material.getSpec()); |
| | | map.put("describle", material.getDescribe()); |
| | | map.put("unit", material.getUnit()); |
| | | mappedList.add(map); |
| | | } |
| | | return mappedList; |
| | | } |
| | | |
| | | @Override |
| | | public String syncWareHouse(List<Warehouse> warehouseList){ |
| | | if (warehouseList.isEmpty()) { |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | | /**WMS基础配置链接*/ |
| | | String wmsUrl = wmsApi.getHost() + ":" + wmsApi.getPort() + WmsConstant.SYNC_WAREHOUSE; |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.add("Content-Type", "application/json"); |
| | | headers.add("api-version", "v2.0"); |
| | | // Warehouse -> WarehouseParams 字段一一对应后再下发 |
| | | List<Map<String, Object>> warehouseParamsList = warehouseToWarehouseParams(warehouseList); |
| | | HttpEntity httpEntity2 = new HttpEntity<>(warehouseParamsList, headers);//cs |
| | | // sync/warehouse |
| | | ResponseEntity<String> exchange = restTemplate.exchange(wmsUrl, HttpMethod.POST, httpEntity2, String.class);//cs |
| | | log.info("同步仓库信息返回结果: {}", exchange); |
| | | if (Objects.isNull(exchange.getBody())) { |
| | | throw new CoolException("查询失败!!"); |
| | | } else { |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | objectMapper.coercionConfigDefaults().setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty); |
| | | try { |
| | | CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class); |
| | | if (result.getCode() == 200) { |
| | | // JSONObject object = JSONObject.parseObject(JSONObject.toJSONString(result.getData())); |
| | | return "200"; |
| | | } else { |
| | | return result.getMsg(); |
| | | // throw new CoolException("查询失败!!"); |
| | | } |
| | | } catch (JsonProcessingException e) { |
| | | return e.getMessage(); |
| | | // throw new CoolException(e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | | @Override |
| | | public String syncCustomer(List<Customer> customerList){ |
| | | if (customerList.isEmpty()) { |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | | /**WMS基础配置链接*/ |
| | | String wmsUrl = wmsApi.getHost() + ":" + wmsApi.getPort() + WmsConstant.SYNC_COMPANIES; |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.add("Content-Type", "application/json"); |
| | | headers.add("api-version", "v2.0"); |
| | | // Customer -> CompaniesParam 字段一一对应后再下发 |
| | | List<Map<String, Object>> companiesParamsList = customerToCompaniesParams(customerList); |
| | | HttpEntity httpEntity2 = new HttpEntity<>(companiesParamsList, headers);//cs |
| | | ResponseEntity<String> exchange = restTemplate.exchange(wmsUrl, HttpMethod.POST, httpEntity2, String.class);//cs |
| | | log.info("同步客户信息返回结果: {}", exchange); |
| | | if (Objects.isNull(exchange.getBody())) { |
| | | throw new CoolException("查询失败!!"); |
| | | } else { |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | objectMapper.coercionConfigDefaults().setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty); |
| | | try { |
| | | CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class); |
| | | if (result.getCode() == 200) { |
| | | return "200"; |
| | | } else { |
| | | return result.getMsg(); |
| | | } |
| | | } catch (JsonProcessingException e) { |
| | | return e.getMessage(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public String syncSupplier(List<Supplier> supplierList){ |
| | | if (supplierList.isEmpty()) { |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | | /**WMS基础配置链接*/ |
| | | String wmsUrl = wmsApi.getHost() + ":" + wmsApi.getPort() + WmsConstant.SYNC_COMPANIES; |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.add("Content-Type", "application/json"); |
| | | headers.add("api-version", "v2.0"); |
| | | // Supplier -> supplierParams 字段一一对应后再下发 |
| | | List<Map<String, Object>> supplierParamsList = customerToSupplierParams(supplierList); |
| | | HttpEntity httpEntity2 = new HttpEntity<>(supplierParamsList, headers);//cs |
| | | ResponseEntity<String> exchange = restTemplate.exchange(wmsUrl, HttpMethod.POST, httpEntity2, String.class);//cs |
| | | log.info("同步客户信息返回结果: {}", exchange); |
| | | if (Objects.isNull(exchange.getBody())) { |
| | | throw new CoolException("查询失败!!"); |
| | | } else { |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | objectMapper.coercionConfigDefaults().setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty); |
| | | try { |
| | | CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class); |
| | | if (result.getCode() == 200) { |
| | | return "200"; |
| | | } else { |
| | | return result.getMsg(); |
| | | } |
| | | } catch (JsonProcessingException e) { |
| | | return e.getMessage(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Warehouse 字段映射为 server 端 WarehouseParams 字段 |
| | | */ |
| | | private List<Map<String, Object>> warehouseToWarehouseParams(List<Warehouse> warehouseList) { |
| | | List<Map<String, Object>> mappedList = new ArrayList<>(); |
| | | for (Warehouse warehouse : warehouseList) { |
| | | if (Objects.isNull(warehouse)) { |
| | | continue; |
| | | } |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("name", warehouse.getWareHouseName()); |
| | | map.put("code", warehouse.getUseOrgId()); |
| | | map.put("factory", warehouse.getUseOrgName()); |
| | | map.put("address", warehouse.getAddress()); |
| | | map.put("type", null); |
| | | map.put("longitude", null); |
| | | map.put("latitude", null); |
| | | mappedList.add(map); |
| | | } |
| | | return mappedList; |
| | | } |
| | | |
| | | /** |
| | | * Customer 字段映射为 server 端 CompaniesParam 字段 |
| | | */ |
| | | private List<Map<String, Object>> customerToCompaniesParams(List<Customer> customerList) { |
| | | List<Map<String, Object>> mappedList = new ArrayList<>(); |
| | | for (Customer customer : customerList) { |
| | | if (Objects.isNull(customer)) { |
| | | continue; |
| | | } |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("name", customer.getCustomerName()); |
| | | map.put("nameEn", null); |
| | | map.put("breifCode", customer.getCustomerNickName()); |
| | | // server 端类型转换使用中文描述 |
| | | map.put("type", customer.getType()); |
| | | map.put("contact", customer.getContact()); |
| | | map.put("tel", customer.getTelephone()); |
| | | map.put("email", customer.getEmail()); |
| | | map.put("pcode", null); |
| | | map.put("city", customer.getCustomerGroup()); |
| | | map.put("province", null); |
| | | map.put("address", customer.getAddress()); |
| | | map.put("code", customer.getCustomerId()); |
| | | mappedList.add(map); |
| | | } |
| | | return mappedList; |
| | | } |
| | | |
| | | /** |
| | | * Customer 字段映射为 server 端 CompaniesParam 字段 |
| | | */ |
| | | private List<Map<String, Object>> customerToSupplierParams(List<Supplier> supplierList) { |
| | | List<Map<String, Object>> mappedList = new ArrayList<>(); |
| | | for (Supplier supplier : supplierList) { |
| | | if (Objects.isNull(supplier)) { |
| | | continue; |
| | | } |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("name", supplier.getSupplierName()); |
| | | map.put("nameEn", null); |
| | | map.put("breifCode", supplier.getSupplierName()); |
| | | // server 端类型转换使用中文描述 |
| | | map.put("type", supplier.getType()); |
| | | map.put("contact", supplier.getContact()); |
| | | map.put("tel", supplier.getTelephone()); |
| | | map.put("email", supplier.getEmail()); |
| | | map.put("pcode", null); |
| | | map.put("city", supplier.getSupplierGroup()); |
| | | map.put("province", null); |
| | | map.put("address", supplier.getAddress()); |
| | | map.put("code", supplier.getSupplierId()); |
| | | mappedList.add(map); |
| | | } |
| | | return mappedList; |
| | | } |
| | | |
| | | @Override |
| | | public String addOrderToServer(Order order) { |
| | | if (Objects.isNull(order.getOrderNo()) || order.getOrderNo().isEmpty()) { |
| | | throw new CoolException("订单号不能为空!!"); |