Commit 243c36fb by 袁伟铭

1.0.0

parent 06d70504
......@@ -27,8 +27,7 @@ public class ApiController {
private final ApiService apiService;
// 允许用户未登录状态下执行的方法名
private String[] allowMethod = {"test", "phoneLogin", "getSessionKey", "getPhoneNumber", "wxLogin", "login", "sendCode", "register",
"getHospitalList", "getDoctorList", "uploadImage", "getVersion", "wxAuthorizeLogin"};
private String[] allowMethod = {"te4st"};
/**
* 获取信息入口
......
package com.zq.api.feign;
import com.zq.common.vo.ResultVo;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.util.Map;
@Component
public class CmsFeign {
private RestTemplate restTemplate = new RestTemplate();
private static String cmsServer = "http://127.0.0.1:9889/cms";
public ResultVo test(Map<String, Object> paramsMap) {
return restTemplate.getForObject(cmsServer + "/adviceFeedback/getAdviceFeedbackById", ResultVo.class);
}
}
package com.zq.api.form;
import com.alibaba.fastjson.JSON;
import com.zq.api.constant.ApiCodeEnum;
import com.zq.common.vo.ResultVo;
import lombok.Data;
import java.util.HashMap;
......@@ -36,15 +34,6 @@ public class ApiResp {
this.msg = apiCodeEnum.msg();
}
public static ApiResp of(ApiForm form, ResultVo resultVo) {
if (resultVo.isSuccess()) {
return new ApiResp(form).addData("data", resultVo.getData());
} else {
System.out.println(JSON.toJSONString(resultVo));
return new ApiResp(form).setCode(ApiCodeEnum.BUSINESS_ERROR.code()).setMsg(resultVo.getErrMsg());
}
}
public ApiResp setFrom(ApiForm from) {
if (from != null) {
this.apiNo = from.getApiNo();
......
package com.zq.api.service;
import cn.hutool.core.exceptions.ExceptionUtil;
import com.zq.api.constant.ApiCodeEnum;
import com.zq.api.dao.ApiLogDao;
import com.zq.api.form.ApiForm;
......@@ -8,9 +9,11 @@ import com.zq.api.utils.ApiUtils;
import com.zq.api.utils.ReflectionUtils;
import com.zq.common.entity.ApiLog;
import com.zq.common.utils.DateUtils;
import com.zq.common.vo.ResultVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
import java.lang.reflect.Method;
import java.util.ArrayList;
......@@ -65,7 +68,10 @@ public class ApiService {
try {
return (ApiResp) ReflectionUtils.invokeMethod(apiLogic, form.getMethod(), new Class<?>[]{ApiForm.class}, new Object[]{form});
} catch (Exception e) {
e.printStackTrace();
// 判断指定异常是否来自或者包含指定异常
if (ExceptionUtil.isFromOrSuppressedThrowable(e, HttpClientErrorException.Unauthorized.class)) {
return ApiUtils.toApiResp(form, ResultVo.fail(401, "Unauthorized"));
}
return ApiUtils.getMethodHandlerError(form);
}
}
......
package com.zq.api.service.impl;
import com.zq.api.feign.CmsFeign;
import com.zq.api.form.ApiForm;
import com.zq.api.form.ApiResp;
import com.zq.api.service.IApiLogic;
import com.zq.api.utils.ApiUtils;
import org.springframework.stereotype.Component;
@Component
public class ApiV100Logic extends BaseApiLogic implements IApiLogic {
private CmsFeign cmsFeign = new CmsFeign();
/**
* 测试连接
*
......@@ -14,6 +20,6 @@ public class ApiV100Logic extends BaseApiLogic implements IApiLogic {
*/
@Override
public ApiResp test(ApiForm form) {
return new ApiResp(form);
return ApiUtils.toApiResp(form, cmsFeign.test(form.getParamsMap()));
}
}
......@@ -7,6 +7,7 @@ import com.zq.api.form.ApiResp;
import com.zq.api.service.IApiLogic;
import com.zq.api.service.impl.ApiV100Logic;
import com.zq.api.service.impl.ApiV101Logic;
import com.zq.common.vo.ResultVo;
import org.apache.commons.codec.binary.Base64;
import java.io.UnsupportedEncodingException;
......@@ -104,6 +105,16 @@ public class ApiUtils {
return new ApiResp(form, ApiCodeEnum.METHOD_HANDLER_ERROR);
}
public static ApiResp toApiResp(ApiForm form, ResultVo resultVo) {
ApiResp apiResp = new ApiResp(form);
if (resultVo.isSuccess()) {
apiResp.addData("data", resultVo.getData());
} else {
return apiResp.setCode(String.valueOf(resultVo.getErrCode())).setMsg(resultVo.getErrMsg());
}
return apiResp;
}
/**
* 解码
* <p>
......
......@@ -34,6 +34,6 @@ public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
HttpServletResponse response,
AuthenticationException authException) throws IOException {
// 当用户尝试访问安全的REST资源而不提供任何凭据时,将调用此方法发送401 响应
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, authException==null?"Unauthorized":authException.getMessage());
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, authException == null ? "Unauthorized" : authException.getMessage());
}
}
......@@ -29,7 +29,7 @@ public final class AssertUtils {
* @param errMsg 错误信息
*/
public static void isImgExt(String ext, String errMsg) {
isImgExt(ext, 0, errMsg);
isImgExt(ext, 400, errMsg);
}
/**
......@@ -54,7 +54,7 @@ public final class AssertUtils {
* @throws BusinessException
*/
public static void notTrue(boolean expression, String message) throws BusinessException {
notTrue(expression, 0, message);
notTrue(expression, 400, message);
}
/**
......@@ -79,7 +79,7 @@ public final class AssertUtils {
* @throws BusinessException
*/
public static void isTrue(boolean expression, String message) throws BusinessException {
isTrue(expression, 0, message);
isTrue(expression, 400, message);
}
/**
......@@ -114,7 +114,7 @@ public final class AssertUtils {
* @throws BusinessException
*/
public static void notNull(Object object, String message) throws BusinessException {
notNull(object, 0, message);
notNull(object, 400, message);
}
/**
......@@ -138,7 +138,7 @@ public final class AssertUtils {
* @throws BusinessException
*/
public static void hasText(String text) throws BusinessException {
hasText(text, 0, "参数不能为空字符串");
hasText(text, 400, "参数不能为空字符串");
}
/**
......@@ -149,7 +149,7 @@ public final class AssertUtils {
* @throws BusinessException
*/
public static void hasText(String text, String message) throws BusinessException {
hasText(text, 0, message);
hasText(text, 400, message);
}
/**
......@@ -175,7 +175,7 @@ public final class AssertUtils {
* @throws BusinessException
*/
public static <T> void notEmpty(T[] array, String message) throws BusinessException {
notEmpty(array, 0, message);
notEmpty(array, 400, message);
}
/**
......@@ -202,7 +202,7 @@ public final class AssertUtils {
* @throws BusinessException
*/
public static <T> void noNullElements(T[] array, String message) throws BusinessException {
noNullElements(array, 0, message);
noNullElements(array, 400, message);
}
/**
......@@ -232,7 +232,7 @@ public final class AssertUtils {
* @throws BusinessException
*/
public static void notEmpty(Collection<?> collection, String message) throws BusinessException {
notEmpty(collection, 0, message);
notEmpty(collection, 400, message);
}
/**
......@@ -257,7 +257,7 @@ public final class AssertUtils {
* @throws BusinessException
*/
public static void notEmpty(Map<?, ?> map, String message) throws BusinessException {
notEmpty(map, 0, message);
notEmpty(map, 400, message);
}
/**
......
......@@ -13,7 +13,7 @@ api.name: API-SERVER
cms.port: 9700
cms.name: CMS-SERVER
gateway.port: 9888
gateway.port: 9889
gateway.name: GATEWAY-SERVER
redis.url: 127.0.0.1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment