wangchaoxu 1 year ago
commit bd3304e628

@ -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\":[682805686164],\"pageSize\":\"20\"}"
}'

@ -1,47 +1,45 @@
package com.ms.api;
import com.alibaba.fastjson.JSON;
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;
import com.jinritemai.cloud.base.api.ExtensionServiceHandler;
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.tool.DsJsonRequestTemplate;
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;
import java.util.Map;
@ExtensionService("testSpi")
@Slf4j
public class TestSpiService extends SPIBaseService implements ExtensionServiceHandler<ItemDTO, JSONObject> {
@Autowired
private DsJsonRequestTemplate dsJsonRequestTemplate;
public class TestSpiService implements ExtensionServiceHandler<ItemDTO, Ret> {
@Override
public BaseResponse<JSONObject> handle(BaseRequest<ItemDTO> req) {
initHandle(req);
getAuthCode();
String res = null;
HashMap<String, Object> params = new HashMap<>();
params.put("platformItemId", 1);
params.put("sourceItemId", 33);
params.put("authCode", authCode);
try {
res = dsJsonRequestTemplate.execute("/micro_move/add_platform_item_to_source_item_relation", params);
log.info(res);
} catch (Exception e) {
public BaseResponse<Ret> handle(BaseRequest<ItemDTO> req) {
String resourceFileName = "/getProductCatTree.txt"; // 注意路径的开头是一个斜杠
String lines = null;
try (InputStream is = InputStream.class.getResourceAsStream(resourceFileName);
BufferedReader reader = new BufferedReader(new InputStreamReader(is))) {
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
lines = lines + line;
}
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage());
}
return R.ok(JSON.parseObject(res));
Map<String, Object> result = new HashMap<>();
result.put("line", lines);
return R.ok(Ret.success(result));
}
}

@ -0,0 +1,46 @@
package com.ms.config;
import com.jinritemai.cloud.base.api.BaseResponse;
import com.ms.api.common.R;
import com.ms.api.common.Ret;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
/**
*
* * @author admin
*/
@Slf4j
@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {
/**
*
*/
@ExceptionHandler(value = RuntimeException.class)
public BaseResponse<Ret> bizExceptionHandler(RuntimeException e) {
log.error("发生业务异常! msg: -> ", e);
return R.ok(Ret.fail(e.getMessage()));
}
/**
*
*/
@ExceptionHandler(value = NullPointerException.class)
public BaseResponse<Ret> exceptionHandler(NullPointerException e) {
log.error("发生空指针异常! msg: -> ", e);
return R.ok(Ret.fail(e.getMessage()));
}
/**
*
*/
@ExceptionHandler(Exception.class)
public BaseResponse<Ret> exception(Exception e) {
log.error("服务器异常! msg: -> ", e);
return R.ok(Ret.fail(e.getMessage()));
}
}
Loading…
Cancel
Save