| | |
| | | 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.Material; |
| | | import com.vincent.rsf.openApi.entity.phyz.Order; |
| | | import com.vincent.rsf.openApi.entity.phyz.Warehouse; |
| | | 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; |
| | |
| | | } |
| | | } |
| | | } |
| | | @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 字段 |
| | |
| | | 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()) { |