From 44137e717170d9a9333e33a5237f3a468bd41113 Mon Sep 17 00:00:00 2001 From: ZY <zc857179121@qq.com> Date: 星期一, 28 四月 2025 12:49:35 +0800 Subject: [PATCH] 双数据源 --- src/main/java/com/zy/asrs/service/impl/ReportToThirdServiceImpl.java | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 103 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/zy/asrs/service/impl/ReportToThirdServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/ReportToThirdServiceImpl.java new file mode 100644 index 0000000..dc7520a --- /dev/null +++ b/src/main/java/com/zy/asrs/service/impl/ReportToThirdServiceImpl.java @@ -0,0 +1,103 @@ +package com.zy.asrs.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.core.common.Cools; +import com.core.exception.CoolException; +import com.zy.asrs.entity.DocType; +import com.zy.asrs.entity.Order; +import com.zy.asrs.entity.OrderDetl; +import com.zy.asrs.service.ApiLogService; +import com.zy.asrs.service.OrderService; +import com.zy.asrs.service.ReportToThirdService; +import com.zy.common.utils.HttpHandler; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.io.IOException; +import java.util.List; + +@Service +@Slf4j +public class ReportToThirdServiceImpl implements ReportToThirdService { + + @Autowired + private ApiLogService apiLogService; + + @Autowired + private OrderService orderService; + + @Value("${NYNC.ip}") + private String nyncIp; + + @Value("${NYNC.port}") + private String port; + + @Value("${NYNC.saveRefDelivery}") + private String saveRefDelivery; + + + @Override + public void report(Order order, List<OrderDetl> orderDetls, DocType docType) { + Boolean http = false; + switch (order.getDocType().toString()) { + case "閿�鍞彂璐�": + http = http("", docType.getDocName(), nyncIp + port, saveRefDelivery); + if (Cools.isEmpty(order.getShipCode()) || order.getShipCode().equalsIgnoreCase("1")) { + + } + break; + case "浜ф垚鍝佸叆搴�": + break; + case "杈呮枡閲囪喘鍏ュ簱": + break; + case "杈呮枡鍙婃垚鍝佽浆搴�": + break; + case "鑷姩鍖呰鍏ュ簱": + break; + case "鍐呴儴璋冩嫧": + break; + default: + break; + } + if (http) { + // 淇敼璁㈠崟鐘舵�� 4.瀹屾垚 ===>> 6.宸蹭笂鎶� + if (!orderService.updateSettle(order.getId(), 6L, null)) { + throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳"); + } + } + } + + private Boolean http(Object data, String docType, String url, String path) { + String response = ""; + boolean success = false; + try { + response = new HttpHandler.Builder() + .setUri(url) + .setPath(path) + .setJson(JSON.toJSONString(data)) + .build() + .doPost(); + JSONObject jsonObject = JSON.parseObject(response); + if (jsonObject.getInteger("code").equals(1)) { + return true; + } + log.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", url + path, JSON.toJSONString(data), response); + } catch (IOException e) { + e.printStackTrace(); + } finally { + apiLogService.save( + docType, + url + path, + null, + "127.0.0.1", + JSON.toJSONString(data), + response, + success + ); + } + return false; + } +} -- Gitblit v1.9.1