From 16a09540001bd00f01b848f0ca125d16bf314450 Mon Sep 17 00:00:00 2001
From: zhang <zc857179121@qq.com>
Date: 星期五, 29 八月 2025 15:45:18 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/devlop' into devlop

---
 rsf-open-api/src/main/java/com/vincent/rsf/openApi/service/impl/WmsRcsServiceImpl.java |   93 +++++++++++++++++++++++++++++++++-------------
 1 files changed, 67 insertions(+), 26 deletions(-)

diff --git a/rsf-open-api/src/main/java/com/vincent/rsf/openApi/service/impl/WmsRcsServiceImpl.java b/rsf-open-api/src/main/java/com/vincent/rsf/openApi/service/impl/WmsRcsServiceImpl.java
index 37caa2c..f94be28 100644
--- a/rsf-open-api/src/main/java/com/vincent/rsf/openApi/service/impl/WmsRcsServiceImpl.java
+++ b/rsf-open-api/src/main/java/com/vincent/rsf/openApi/service/impl/WmsRcsServiceImpl.java
@@ -1,15 +1,22 @@
 package com.vincent.rsf.openApi.service.impl;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.cfg.CoercionAction;
 import com.fasterxml.jackson.databind.cfg.CoercionInputShape;
 import com.vincent.rsf.framework.common.R;
 import com.vincent.rsf.framework.exception.CoolException;
-import com.vincent.rsf.openApi.entity.CommonResponse;
+import com.vincent.rsf.openApi.config.PlatformProperties;
+import com.vincent.rsf.openApi.entity.Loc;
+import com.vincent.rsf.openApi.entity.dto.CommonResponse;
 import com.vincent.rsf.openApi.entity.constant.RcsConstant;
+import com.vincent.rsf.openApi.entity.dto.SyncLocsDto;
 import com.vincent.rsf.openApi.entity.params.RcsPubTaskParams;
+import com.vincent.rsf.openApi.entity.params.SyncRcsLocsParam;
+import com.vincent.rsf.openApi.mapper.LocMapper;
 import com.vincent.rsf.openApi.service.WmsRcsService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -21,24 +28,24 @@
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.client.RestTemplate;
 
+import java.util.List;
 import java.util.Map;
 import java.util.Objects;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
+
 
 @Slf4j
-@Service("wmsRcsServiceImpl")
-public class WmsRcsServiceImpl implements WmsRcsService {
+@Service("wmsRcsService")
+public class WmsRcsServiceImpl extends ServiceImpl<LocMapper, Loc> implements WmsRcsService {
 
-//    @Autowired
-//    private RemotesInfoProperties.RcsApi rcsApi;
+    @Autowired
+    private PlatformProperties rcsApi;
+
+    @Autowired
+    private PlatformProperties.WmsApi wmsApi;
 
     @Autowired
     private RestTemplate restTemplate;
 
-    /**RCS鍩虹閰嶇疆閾炬帴*/
-//    private final String rcsUrl =  rcsApi.getHost() + rcsApi.getPort();
 
     /**
      * @author Ryan
@@ -47,14 +54,16 @@
      * @version 1.0
      */
     @Override
-    @Transactional(timeout = 60, rollbackFor = Exception.class)
+    @Transactional(rollbackFor = Exception.class)
     public R pubTasks(RcsPubTaskParams params)  {
-        log.info("浠诲姟涓嬪彂锛岃姹傚湴鍧�锛� {}锛� 璇锋眰鍙傛暟锛� {}", "" + RcsConstant.pubTask, JSONObject.toJSONString(params));
+        /**RCS鍩虹閰嶇疆閾炬帴*/
+        String rcsUrl =  rcsApi.getHost() + ":" + rcsApi.getPort() + RcsConstant.pubTask;
+        log.info("浠诲姟涓嬪彂锛岃姹傚湴鍧�锛� {}锛� 璇锋眰鍙傛暟锛� {}", rcsUrl , JSONObject.toJSONString(params));
         HttpHeaders headers = new HttpHeaders();
         headers.add("Content-Type", "application/json");
         headers.add("api-version", "v2.0");
         HttpEntity httpEntity = new HttpEntity(params, headers);
-        ResponseEntity<String> exchange = restTemplate.exchange("rcsUrl" + RcsConstant.pubTask, HttpMethod.POST, httpEntity, String.class);
+        ResponseEntity<String> exchange = restTemplate.exchange(rcsUrl, HttpMethod.POST, httpEntity, String.class);
         log.info("浠诲姟涓嬪彂鍚庯紝鍝嶅簲缁撴灉锛� {}", exchange);
         if (Objects.isNull(exchange.getBody())) {
             throw new CoolException("浠诲姟涓嬪彂澶辫触锛侊紒");
@@ -65,7 +74,7 @@
             try {
                 CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
                 if (result.getCode() == 200) {
-                    return R.ok(result);
+                    return R.ok();
                 } else {
                     throw new CoolException("浠诲姟涓嬪彂澶辫触锛侊紒");
                 }
@@ -83,7 +92,7 @@
      */
     @Override
     public R cancelTasks(Map<String, Object> params) {
-        return null;
+        return  R.ok();
     }
 
     /**
@@ -94,7 +103,9 @@
      */
     @Override
     public R callBackEvent(Map<String, Object> params) {
-        return null;
+        String rcsUrl =  wmsApi.getHost() + ":" + wmsApi.getPort() + RcsConstant.pubTask;
+
+        return R.ok();
     }
 
     /**
@@ -104,16 +115,46 @@
      * @version 1.0
      */
     @Override
-    public void syncLocs() {
-        ScheduledExecutorService scheduled = Executors.newScheduledThreadPool(1);
-        scheduled.scheduleWithFixedDelay(new Runnable() {
-            int current = 1;
-            @Override
-            public void run() {
-                log.info("<UNK>{}<UNK>", current);
-                current ++;
-                log.info("{}", current);
+    public List<SyncLocsDto> syncLocs(SyncRcsLocsParam params) {
+         return syncRcsLocs(params);
+    }
+
+    /**
+     * @author Ryan
+     * @date 2025/8/28
+     * @description: 鎷夊彇RCS搴撲綅锛屽悓姝ヨ嚦鏈湴
+     * @version 1.0
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public List<SyncLocsDto> syncRcsLocs(SyncRcsLocsParam  params) {
+        /**RCS鍩虹閰嶇疆閾炬帴*/
+        String rcsUrl =  rcsApi.getHost() + ":" + rcsApi.getPort() + RcsConstant.syncLocs;
+        log.info("浠诲姟涓嬪彂锛岃姹傚湴鍧�锛� {}锛� 璇锋眰鍙傛暟锛� {}", rcsUrl , JSONObject.toJSONString(params));
+        HttpHeaders headers = new HttpHeaders();
+        headers.add("Content-Type", "application/json");
+        headers.add("api-version", "v2.0");
+        HttpEntity httpEntity = new HttpEntity(params, headers);
+        ResponseEntity<String> exchange = restTemplate.exchange(rcsUrl, HttpMethod.POST, httpEntity, String.class);
+        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 jsonObject = JSONObject.parseObject(exchange.getBody()).getJSONObject("data");
+                    List<SyncLocsDto> array =  JSONArray.parseArray(jsonObject.getJSONArray("records").toJSONString(), SyncLocsDto.class);
+                    log.info("records缁撴灉锛� {}",  array);
+                    return array;
+                } else {
+                    throw new CoolException("浠诲姟涓嬪彂澶辫触锛侊紒");
+                }
+            } catch (JsonProcessingException e) {
+                throw new CoolException(e.getMessage());
             }
-        }, 3, 3, TimeUnit.SECONDS);
+        }
     }
 }

--
Gitblit v1.9.1