Merge branch 'master' of https://codeup.aliyun.com/64d9c5feeceb191898f636d7/honor-dd-light-ds-java
commit
bd3304e628
@ -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…
Reference in New Issue