| | |
| | | import javax.annotation.PostConstruct; |
| | | import javax.annotation.Resource; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.lang.reflect.Field; |
| | | import java.util.*; |
| | | |
| | | import org.springframework.http.client.ClientHttpResponse; |
| | | import java.util.Objects; |
| | | |
| | | @Service |
| | | @Slf4j |
| | | public class MesReportServiceImpl implements MesReportService { |
| | | |
| | | private static String MES_REPORT_URL; |
| | | @Resource |
| | | private PlatformProperties.WmsApi wmsApi; |
| | | |
| | | @Resource |
| | | private PlatformProperties.MesApi mesApi; |
| | |
| | | } |
| | | } |
| | | |
| | | public String callMaterial(MatPreparationOrder order) { |
| | | if (Objects.isNull(order.getOrderNo()) || order.getOrderNo().isEmpty()) { |
| | | throw new CoolException("订单号不能为空!!"); |
| | | } |
| | | /**WMS基础配置链接*/ |
| | | String wmsUrl = wmsApi.getHost() + ":" + wmsApi.getPort() + "/rsf-server/mes/callMaterial"; |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.add("Content-Type", "application/json"); |
| | | headers.add("api-version", "v2.0"); |
| | | |
| | | // List<Map<String, Object>> maps = new ArrayList<>(); |
| | | // Map<String, Object> mapParams = new HashMap<>(); |
| | | ////// mapParams.put("orderNo", params.getOrderNo()); |
| | | ////// mapParams.put("anfme", params.getAnfme()); |
| | | ////// mapParams.put("type", params.getType()); |
| | | ////// mapParams.put("wkType", params.getWkType()); |
| | | ////// mapParams.put("exceStatus", params.getExceStatus()); |
| | | ////// mapParams.put("orderItems", params.getOrderItems()); |
| | | ////// maps.add(mapParams); |
| | | //// |
| | | //// JSONObject params = JSONObject.parseObject(JSON.toJSONString(order)); |
| | | //// JSONObject mappedData = ParamsMapUtils.apiMaps("mes", "orderId", params); |
| | | //// mappedData.put("updateBy", "mes"); |
| | | //// mapParams = objectToMap(mappedData); |
| | | //// maps.add(mapParams); |
| | | // log.info("修改订单信息及状态: {}, 请求参数: {}", wmsUrl, JSONArray.toJSONString(order)); |
| | | // HttpEntity<List<Map<String, Object>>> httpEntity = new HttpEntity<>(maps, headers); |
| | | //// ArrayList<Order> orders = new ArrayList<>(); |
| | | //// orders.add(order); |
| | | HttpEntity httpEntity = new HttpEntity<>(order, headers); |
| | | // mes/callMaterial |
| | | ResponseEntity<String> exchange = restTemplate.exchange(wmsUrl, HttpMethod.POST, httpEntity, 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()); |
| | | } |
| | | } |
| | | |
| | | |
| | | // ErpOpParams erpOpParams = new ErpOpParams(); |
| | | // erpOpParams.set |
| | | // |
| | | // wmsErpService.updateOrderDetl(ErpOpParams params); |
| | | |
| | | // CommonResponse updateOrderDetl() |
| | | // |
| | | // asnOrderService.saveOrderAndItems(params, getLoginUserId()); |
| | | } |
| | | |
| | | public static Map<String, Object> objectToMap(Object obj) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | Field[] fields = obj.getClass().getDeclaredFields(); |
| | | for (Field field : fields) { |
| | | field.setAccessible(true); // 设置私有字段也可以访问 |
| | | try { |
| | | map.put(field.getName(), field.get(obj)); |
| | | } catch (IllegalAccessException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | } |