diff --git a/src/main/java/com/sczx/sync/controller/SendDataController.java b/src/main/java/com/sczx/sync/controller/SendDataController.java index 3c8c485..96f26ca 100644 --- a/src/main/java/com/sczx/sync/controller/SendDataController.java +++ b/src/main/java/com/sczx/sync/controller/SendDataController.java @@ -75,44 +75,44 @@ public class SendDataController { return sendDataService.sendStoreInfoToBattery(Long.parseLong(id)); } -// @ApiOperation(value = "接收充电同步数据接口") -// @GetMapping("/subOrder/{id}") -// public Map sendSubOrderToBattery(@PathVariable String id){ -// log.info("/subOrder 接收充电数据:{}",id); -// return sendDataService.sendSubOrderToBattery(Long.parseLong(id)); -// } - - - @ApiOperation(value = "异步接收充电同步数据接口") + @ApiOperation(value = "接收充电同步数据接口") @GetMapping("/subOrder/{id}") - public CompletableFuture>> sendSubOrderToBattery(@PathVariable String id){ + public Map sendSubOrderToBattery(@PathVariable String id){ log.info("/subOrder 接收充电数据:{}",id); - return CompletableFuture - .supplyAsync(() -> { - try { - return sendDataService.sendSubOrderToBattery(Long.parseLong(id)); - } catch (Exception e) { - log.error("处理用户数据时发生异常", e); - Map errorResponse = new HashMap<>(); - errorResponse.put("code", "9999"); - errorResponse.put("msg", "处理失败: " + e.getMessage()); - return errorResponse; - } - }, taskExecutor) - .thenApply(result -> { - log.info("用户数据处理完成,返回结果: {}", result); - return ResponseEntity.ok(result); - }) - .exceptionally(throwable -> { - log.error("异步处理用户数据时发生异常", throwable); - Map errorResponse = new HashMap<>(); - errorResponse.put("code", "9999"); - errorResponse.put("msg", "系统异常"); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse); - }); + return sendDataService.sendSubOrderToBattery(Long.parseLong(id)); } +// @ApiOperation(value = "异步接收充电同步数据接口") +// @GetMapping("/subOrder/{id}") +// public CompletableFuture>> sendSubOrderToBattery(@PathVariable String id){ +// log.info("/subOrder 接收充电数据:{}",id); +// return CompletableFuture +// .supplyAsync(() -> { +// try { +// return sendDataService.sendSubOrderToBattery(Long.parseLong(id)); +// } catch (Exception e) { +// log.error("处理用户数据时发生异常", e); +// Map errorResponse = new HashMap<>(); +// errorResponse.put("code", "9999"); +// errorResponse.put("msg", "处理失败: " + e.getMessage()); +// return errorResponse; +// } +// }, taskExecutor) +// .thenApply(result -> { +// log.info("用户数据处理完成,返回结果: {}", result); +// return ResponseEntity.ok(result); +// }) +// .exceptionally(throwable -> { +// log.error("异步处理用户数据时发生异常", throwable); +// Map errorResponse = new HashMap<>(); +// errorResponse.put("code", "9999"); +// errorResponse.put("msg", "系统异常"); +// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse); +// }); +// } + + // // @ApiOperation(value = "接收需同步数据接口") diff --git a/src/main/java/com/sczx/sync/service/impl/SendDataServiceImpl.java b/src/main/java/com/sczx/sync/service/impl/SendDataServiceImpl.java index 029d1c7..86ea2c2 100644 --- a/src/main/java/com/sczx/sync/service/impl/SendDataServiceImpl.java +++ b/src/main/java/com/sczx/sync/service/impl/SendDataServiceImpl.java @@ -268,62 +268,76 @@ public class SendDataServiceImpl implements SendDataService { OrderBatteryInfo orderBatteryInfo = orderBatteryInfoMapper.selectOrderBatteryInfoById(id); Map map = new HashMap<>(); - if(orderBatteryInfo == null){ - map.put("msg","未找到此租电订单信息"); - map.put("code","500"); - return map; - } - if (orderBatteryInfo.getPhone() == null || orderBatteryInfo.getPhone().isEmpty()){ - map.put("msg","租电订单手机号不能为空"); - map.put("code","500"); - return map; - } - if (orderBatteryInfo.getStart_date() == null || orderBatteryInfo.getStart_date().isEmpty()){ - map.put("msg","租电订单开始时间不能为空"); - map.put("code","500"); - return map; - } - if(orderBatteryInfo.getEnd_date() == null || orderBatteryInfo.getEnd_date().isEmpty()){ - map.put("msg","租电订单结束时间不能为空"); - map.put("code","500"); - return map; - } - if (orderBatteryInfo.getCity() == null ) { - map.put("msg","租电订单城市不能为空"); - map.put("code","500"); - return map; - } - if (orderBatteryInfo.getStore() == null){ - map.put("msg","租电订单门店不能为空"); - map.put("code","500"); - return map; - } - if (orderBatteryInfo.getCategory() == null){ - map.put("msg","电池类别不能为空"); - map.put("code","500"); - return map; - } - if (orderBatteryInfo.getOperator_id() == null){ - map.put("msg","运营商ID不能为空"); - map.put("code","500"); - return map; - } - if (orderBatteryInfo.getOrder_no() == null){ - map.put("msg","租电订单编号不能为空"); - map.put("code","500"); - return map; - } +// if(orderBatteryInfo == null){ +// map.put("msg","未找到此租电订单信息"); +// map.put("code","500"); +// return map; +// } +// if (orderBatteryInfo.getPhone() == null || orderBatteryInfo.getPhone().isEmpty()){ +// map.put("msg","租电订单手机号不能为空"); +// map.put("code","500"); +// return map; +// } +// if (orderBatteryInfo.getStart_date() == null || orderBatteryInfo.getStart_date().isEmpty()){ +// map.put("msg","租电订单开始时间不能为空"); +// map.put("code","500"); +// return map; +// } +// if(orderBatteryInfo.getEnd_date() == null || orderBatteryInfo.getEnd_date().isEmpty()){ +// map.put("msg","租电订单结束时间不能为空"); +// map.put("code","500"); +// return map; +// } +// if (orderBatteryInfo.getCity() == null ) { +// map.put("msg","租电订单城市不能为空"); +// map.put("code","500"); +// return map; +// } +// if (orderBatteryInfo.getStore() == null){ +// map.put("msg","租电订单门店不能为空"); +// map.put("code","500"); +// return map; +// } +// if (orderBatteryInfo.getCategory() == null){ +// map.put("msg","电池类别不能为空"); +// map.put("code","500"); +// return map; +// } +// if (orderBatteryInfo.getOperator_id() == null){ +// map.put("msg","运营商ID不能为空"); +// map.put("code","500"); +// return map; +// } +// if (orderBatteryInfo.getOrder_no() == null){ +// map.put("msg","租电订单编号不能为空"); +// map.put("code","500"); +// return map; +// } SyncRequest syncRequest = new SyncRequest(); syncRequest.setData(orderBatteryInfo); - if (saveRecord(syncRequest,URL+"/batteryorder",id,"batteryorder")){ + + String response = thirdPartyForwardService.forwardData(URL+"/batteryorder",JSON.toJSONString(syncRequest)); + JSONObject jsonObject = JSON.parseObject(response); + String status = jsonObject.get("status").toString(); + + if (status.equals("40001") || status.equals("40002") || status.equals("40003") || status.equals("40005") || status.equals("40006")){ + map.put("code",status); + map.put("msg",jsonObject.get("msg").toString()); + return map; + }else if (status.equals("200")){ + String bOrdNo = jsonObject.get("order_no").toString(); + companyStoreMapper.updateOdId(bOrdNo,id); + map.put("code",status); map.put("msg","发送成功"); - map.put("code","200"); - } - else { - map.put("msg","发送失败"); - map.put("code","500"); + return map; + }else if (status.equals("401")){ + map.put("code",status); + map.put("msg","鉴权失败"); + return map; } + map.put("code","500"); + map.put("msg","系统异常"); return map; }