From aa40f4d096a6c02c54f146ee32e9b0ae148f9974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cxxxxxxx=E8=AF=A6?= <286460656@qq.com> Date: Mon, 11 Sep 2023 18:19:06 +0800 Subject: [PATCH] =?UTF-8?q?=E9=93=BA=E8=B4=A7=E8=BF=94=E5=9B=9E=E6=8A=96?= =?UTF-8?q?=E5=BA=97=E7=B1=BB=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- .../main/java/com/ms/api/TestSpiService.java | 55 +++++++++---------- .../spi/move/GetProductInfoByProductId.java | 50 ++++++++++------- 3 files changed, 56 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 45626648..77839e87 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ curl --location --request POST 'localhost:8080/base/cloud/spi' \ --data-raw '{ "appId":"7264840234423027259", "authId":"4463798", -"method":"getProductInfoByProductId", +"method":"testSpi", "data":"{\"productIds\":[1000137090,588529442342]}" }' diff --git a/ms-biz/src/main/java/com/ms/api/TestSpiService.java b/ms-biz/src/main/java/com/ms/api/TestSpiService.java index 94d4fe52..060f5849 100644 --- a/ms-biz/src/main/java/com/ms/api/TestSpiService.java +++ b/ms-biz/src/main/java/com/ms/api/TestSpiService.java @@ -1,9 +1,7 @@ package com.ms.api; import com.alibaba.fastjson.JSON; -import com.doudian.open.api.open_getAuthInfo.OpenGetAuthInfoRequest; -import com.doudian.open.api.open_getAuthInfo.OpenGetAuthInfoResponse; -import com.doudian.open.api.open_getAuthInfo.param.OpenGetAuthInfoParam; +import com.alibaba.fastjson.JSONObject; import com.jinritemai.cloud.base.api.BaseRequest; import com.jinritemai.cloud.base.api.BaseResponse; import com.jinritemai.cloud.base.api.ExtensionService; @@ -12,42 +10,39 @@ import com.ms.api.common.R; import com.ms.api.common.Ret; import com.ms.api.common.SPIBaseService; import com.ms.api.dto.ItemDTO; -import com.ms.api.paas.RedisService; -import com.ms.api.service.MoveProductPublishQueueService; -import com.ms.api.tool.ImageTool; +import com.ms.api.tool.DsJsonRequestTemplate; +import com.ms.api.tool.SecurityTool; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.HashMap; + @ExtensionService("testSpi") @Slf4j -public class TestSpiService extends SPIBaseService implements ExtensionServiceHandler { - - @Autowired - MoveProductPublishQueueService moveProductPublishQueueService; - +public class TestSpiService extends SPIBaseService implements ExtensionServiceHandler { @Autowired - RedisService redisFIFOService; - + private DsJsonRequestTemplate dsJsonRequestTemplate; @Override - public BaseResponse handle(BaseRequest req) { - try{ - initHandle(req); - ItemDTO itemDTO = req.getData(); - String result = ""; - if(itemDTO.getTitle().equals("authInfo")){ - OpenGetAuthInfoRequest request = new OpenGetAuthInfoRequest(); - OpenGetAuthInfoParam param = request.getParam(); - param.setAuthId(shopId + ""); - OpenGetAuthInfoResponse response = request.execute(); - result = JSON.toJSONString(response); - System.out.println(); - } - - return R.ok(result); - }catch (Throwable e){ + public BaseResponse handle(BaseRequest req) { + initHandle(req); + getAuthCode(); + String res = null; + HashMap params = new HashMap<>(); + params.put("platformItemId", SecurityTool.encodeByAES("3638605009077281167")); + params.put("sourceItemId", "1000090775"); + params.put("authCode", authCode); + try { + res = dsJsonRequestTemplate.execute("/micro_move/add_platform_item_to_source_item_relation", params); + log.info("rrrr"+res); + } catch (Exception e) { e.printStackTrace(); - return R.ok(e.getMessage()); + log.error(e.getMessage()); } + return R.ok(JSON.parseObject(res)); } } diff --git a/ms-biz/src/main/java/com/ms/api/spi/move/GetProductInfoByProductId.java b/ms-biz/src/main/java/com/ms/api/spi/move/GetProductInfoByProductId.java index 02e8bb1a..53a75b0d 100644 --- a/ms-biz/src/main/java/com/ms/api/spi/move/GetProductInfoByProductId.java +++ b/ms-biz/src/main/java/com/ms/api/spi/move/GetProductInfoByProductId.java @@ -19,10 +19,7 @@ import org.phprpc.util.AssocArray; import org.phprpc.util.PHPSerializer; import org.springframework.beans.factory.annotation.Autowired; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -68,24 +65,21 @@ public class GetProductInfoByProductId extends SPIBaseService implements Extensi MoveSystemSourceCategory moveSystemSourceCategory = moveSystemSourceCategoryService.selectBySourceCategoryId(sourceCategoryId.toString()); if (!ObjectUtil.isEmpty(moveSystemSourceCategory)) { Long moveSystemSourceCategoryId = moveSystemSourceCategory.getMoveSystemSourceCategoryId(); - product.put("dsCid", moveSystemSourceCategoryId); PHPSerializer p = new PHPSerializer(); -// Map map = (Map) p.unserialize(moveSystemSourceCategory.getMatchCategoryList().getBytes()); -// map = sortByKey(map); -// String content = moveSystemSourceCategory.getMatchCategoryList(); - String content ="a:10:{i:0;s:18:\"舞蹈(私教)\";i:1;s:5:\"Zumba\";i:2;s:12:\"完美塑造\";i:3;s:12:\"战斗有氧\";i:4;s:12:\"杠铃雕塑\";i:5;s:12:\"核心特训\";i:6;s:12:\"漫步舞林\";i:7;s:12:\"身体平衡\";i:8;s:12:\"高效冲击\";i:9;s:12:\"魅力热舞\";}"; -// String content ="a:2:{i:26953;a:2:{s:4:\"type\";s:6:\"manual\";s:4:\"path\";s:32:\"内衣裤袜>女士内衣>抹胸\";}i:24928;a:2:{s:4:\"type\";s:6:\"manual\";s:4:\"path\";s:112:\"童装/婴儿装/亲子装>帽子/围巾/口罩/手套/耳套/脚套>多件套 帽子、围巾、手套等组合\";}}"; - log.info("dsCategoryList:::" + content); - Object unserialize = p.unserialize(content.getBytes("utf-8"));//数据转格式 - AssocArray array = (AssocArray) unserialize; - log.info("dsCategoryList:::" + array); - List listResult = new ArrayList(); - for (int s = 0; s < array.size(); s++) { - log.info("arrayList:::" + array.toHashMap()); - listResult.add(new String((byte[])array.get(s))); - } + String content = moveSystemSourceCategory.getMatchCategoryList(); + AssocArray assocArray = (AssocArray) p.unserialize(content.getBytes()); + Map assocMap = assocArrayToHash(assocArray); + List assocMapValues = new ArrayList<>(assocMap.values()); + Map inMap = (Map) assocMapValues.get(assocMapValues.size() - 1); + List assocMapKeys = new ArrayList<>(assocMap.keySet()); - product.put("dsCategoryList", listResult); + log.info("assocArrayToHash" + inMap.get("path")); + log.info("assocArrayToHash" + assocMapKeys.get(assocMapKeys.size() - 1)); + product.put("ddCid", inMap.get("path")); + product.put("ddCategoryList", assocMapKeys.get(assocMapKeys.size() - 1)); + } else { + product.put("ddCid", ""); + product.put("ddCategoryList", ""); } productInfo.add(resObj.getJSONObject("productInfo")); log.info(res); @@ -103,4 +97,20 @@ public class GetProductInfoByProductId extends SPIBaseService implements Extensi // ----结果返回---- return R.ok(Ret.success(result)); } + + private static Map assocArrayToHash(AssocArray assocArray) { + HashMap hashMap = assocArray.toHashMap(); + Map result = new HashMap(); + for (Object key : hashMap.keySet()) { + if(hashMap.get(key) instanceof AssocArray) { + result.put(key.toString(),assocArrayToHash((AssocArray) hashMap.get(key))); + }else if(hashMap.get(key) instanceof byte[]) { + result.put(key.toString(),new String((byte[]) hashMap.get(key))); + }else { + result.put(key.toString(),hashMap.get(key)); + } + } + log.info(result + "result"); + return result; + } }