Commit 739cd248 authored by suntao's avatar suntao

渠道配置查询 编辑

parent 0aeda08d
...@@ -5,6 +5,7 @@ import cn.quantgroup.cashloanflowboss.api.channel.model.ChannelConfBaseModel; ...@@ -5,6 +5,7 @@ import cn.quantgroup.cashloanflowboss.api.channel.model.ChannelConfBaseModel;
import cn.quantgroup.cashloanflowboss.api.channel.model.ChannelConfVo; import cn.quantgroup.cashloanflowboss.api.channel.model.ChannelConfVo;
import cn.quantgroup.cashloanflowboss.core.annotation.ChannelIdInit; import cn.quantgroup.cashloanflowboss.core.annotation.ChannelIdInit;
import cn.quantgroup.cashloanflowboss.api.channel.service.ChannelConfService; import cn.quantgroup.cashloanflowboss.api.channel.service.ChannelConfService;
import cn.quantgroup.cashloanflowboss.core.annotation.CheckChannelRole;
import cn.quantgroup.cashloanflowboss.core.base.Result; import cn.quantgroup.cashloanflowboss.core.base.Result;
import cn.quantgroup.cashloanflowboss.utils.JSONTools; import cn.quantgroup.cashloanflowboss.utils.JSONTools;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
...@@ -41,6 +42,7 @@ public class ChannelConfController { ...@@ -41,6 +42,7 @@ public class ChannelConfController {
} }
@CheckChannelRole
@GetMapping("/cfg/info") @GetMapping("/cfg/info")
public Result getChannelConfInfo(Long channelId) { public Result getChannelConfInfo(Long channelId) {
return Result.buildSuccess(channelConfService.getChannelConf(channelId), "success"); return Result.buildSuccess(channelConfService.getChannelConf(channelId), "success");
...@@ -49,7 +51,6 @@ public class ChannelConfController { ...@@ -49,7 +51,6 @@ public class ChannelConfController {
@PostMapping("/cfg/info") @PostMapping("/cfg/info")
public Result editChannelConfInfo(@RequestBody @Valid ChannelConfVo channelConfVo) { public Result editChannelConfInfo(@RequestBody @Valid ChannelConfVo channelConfVo) {
return Result.buildSuccess(channelConfService.editChannelConfInfo(channelConfVo)); return Result.buildSuccess(channelConfService.editChannelConfInfo(channelConfVo));
} }
......
...@@ -16,9 +16,9 @@ public class ChannelConfBaseModel { ...@@ -16,9 +16,9 @@ public class ChannelConfBaseModel {
private String channelName; private String channelName;
private String channelCode; private String channelCode;
private String env; private String env;
private String fundId; private Integer fundId;
private String p2pFundId; private Integer p2pFundId;
private String bizType; private Integer bizType;
private String aesKey; private String aesKey;
private String md5Key; private String md5Key;
private String authCode; private String authCode;
......
...@@ -27,6 +27,9 @@ import org.springframework.beans.BeanUtils; ...@@ -27,6 +27,9 @@ import org.springframework.beans.BeanUtils;
public class ChannelConfUtil { public class ChannelConfUtil {
public static final String channelRoleName = "channel_role";
public static final String channelIdParamName = "channelId";
public static ChannelConfVo channelConfConvertVOModel(ChannelConf channelConf) { public static ChannelConfVo channelConfConvertVOModel(ChannelConf channelConf) {
ChannelConfBaseModel channelConfBaseModel = new ChannelConfBaseModel(); ChannelConfBaseModel channelConfBaseModel = new ChannelConfBaseModel();
BeanUtils.copyProperties(channelConf, channelConfBaseModel); BeanUtils.copyProperties(channelConf, channelConfBaseModel);
...@@ -34,8 +37,6 @@ public class ChannelConfUtil { ...@@ -34,8 +37,6 @@ public class ChannelConfUtil {
ChannelConfAddModel channelConfAddModel = new ChannelConfAddModel(); ChannelConfAddModel channelConfAddModel = new ChannelConfAddModel();
BeanUtils.copyProperties(channelConf, channelConfAddModel); BeanUtils.copyProperties(channelConf, channelConfAddModel);
channelConfAddModel.setEnvPath(String.format("http://qapi-%s.liangkebang.net/", channelConfBaseModel.getEnv()));
ChannelConfVo channelConfVo = new ChannelConfVo(); ChannelConfVo channelConfVo = new ChannelConfVo();
channelConfVo.setBasicInfo(channelConfBaseModel); channelConfVo.setBasicInfo(channelConfBaseModel);
channelConfVo.setAddInfo(channelConfAddModel); channelConfVo.setAddInfo(channelConfAddModel);
...@@ -49,10 +50,10 @@ public class ChannelConfUtil { ...@@ -49,10 +50,10 @@ public class ChannelConfUtil {
ChannelConfAddModel channelConfAddModel = channelConfVo.getAddInfo(); ChannelConfAddModel channelConfAddModel = channelConfVo.getAddInfo();
ChannelConf channelConf = new ChannelConf(); ChannelConf channelConf = new ChannelConf();
BeanUtils.copyProperties(channelConfBaseModel, channelConf); BeanUtils.copyProperties(channelConfBaseModel, channelConf);
channelConf.setChannelIp(channelConfAddModel.getChannelIp()); channelConf.setChannelIp(channelConfAddModel.getChannelIp());
channelConf.setEnvPath(String.format("http://qapi-%s.liangkebang.net/", channelConfBaseModel.getEnv()));
channelConf.setApproveCallBackUrl(channelConfAddModel.getApproveCallBackUrl()); channelConf.setApproveCallBackUrl(channelConfAddModel.getApproveCallBackUrl());
channelConf.setOrderStatusCallBackUrl(channelConfAddModel.getOrderStatusCallBackUrl()); channelConf.setOrderStatusCallBackUrl(channelConfAddModel.getOrderStatusCallBackUrl());
channelConf.setRepayResultCallBackUrl(channelConfAddModel.getRepayResultCallBackUrl()); channelConf.setRepayResultCallBackUrl(channelConfAddModel.getRepayResultCallBackUrl());
......
package cn.quantgroup.cashloanflowboss.core.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* function:
* date: 2019/8/6
*
* @author: suntao
*/
@Target({METHOD})
@Retention(RUNTIME)
public @interface CheckChannelRole {
}
package cn.quantgroup.cashloanflowboss.core.aspect; package cn.quantgroup.cashloanflowboss.core.aspect;
import cn.quantgroup.cashloanflowboss.api.channel.util.ChannelConfUtil;
import cn.quantgroup.cashloanflowboss.api.user.model.UserSessionInfo; import cn.quantgroup.cashloanflowboss.api.user.model.UserSessionInfo;
import cn.quantgroup.cashloanflowboss.api.user.service.UserSessionService; import cn.quantgroup.cashloanflowboss.api.user.service.UserSessionService;
import cn.quantgroup.cashloanflowboss.core.annotation.ChannelIdInit; import cn.quantgroup.cashloanflowboss.core.annotation.ChannelIdInit;
import cn.quantgroup.cashloanflowboss.core.annotation.CheckChannelRole;
import cn.quantgroup.cashloanflowboss.core.base.BossPageImpl; import cn.quantgroup.cashloanflowboss.core.base.BossPageImpl;
import cn.quantgroup.cashloanflowboss.core.base.Result;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.exception.ExceptionUtils;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
...@@ -29,7 +33,7 @@ import java.lang.reflect.Method; ...@@ -29,7 +33,7 @@ import java.lang.reflect.Method;
@Component @Component
@Aspect @Aspect
@Order(Ordered.HIGHEST_PRECEDENCE) @Order(Ordered.HIGHEST_PRECEDENCE)
public class RoleDataLoadAspect { public class RoleLoadAspect {
@Autowired @Autowired
private UserSessionService userSessionService; private UserSessionService userSessionService;
...@@ -42,23 +46,46 @@ public class RoleDataLoadAspect { ...@@ -42,23 +46,46 @@ public class RoleDataLoadAspect {
Object[] args = pjp.getArgs(); Object[] args = pjp.getArgs();
MethodSignature methodSignature = (MethodSignature) pjp.getSignature(); MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
Method method = methodSignature.getMethod(); Method method = methodSignature.getMethod();
// 如果是渠道用户登陆 默认加载channelId
ChannelIdInit annotation = method.getAnnotation(ChannelIdInit.class); ChannelIdInit annotation = method.getAnnotation(ChannelIdInit.class);
UserSessionInfo userSessionInfo = userSessionService.findUserSessionInfo(); UserSessionInfo userSessionInfo = userSessionService.findUserSessionInfo();
// todo channel_role 定义为常量吧 final Long channelIdInSession = userSessionInfo.getChannelId();
if (annotation != null && "channel_role".equals(userSessionInfo.getRoleInfo().getRoleName())) { if (annotation != null && ChannelConfUtil.channelRoleName.equals(userSessionInfo.getRoleInfo().getRoleName())) {
String[] paramNames = ((CodeSignature)pjp.getSignature()).getParameterNames();
for (int i = 0; i < paramNames.length; i++) {
if (ChannelConfUtil.channelIdParamName.equals(paramNames[i])) {
args[i] = channelIdInSession;
}
}
}
// 如果是渠道用户登陆,参数中channelId 不是登陆用户channelId,返回 拒绝请求
CheckChannelRole checkChannelRole = method.getAnnotation(CheckChannelRole.class);
if (checkChannelRole != null && ChannelConfUtil.channelRoleName.equals(userSessionInfo.getRoleInfo().getRoleName())) {
String[] paramNames = ((CodeSignature)pjp.getSignature()).getParameterNames(); String[] paramNames = ((CodeSignature)pjp.getSignature()).getParameterNames();
for (int i = 0; i < paramNames.length; i++) { for (int i = 0; i < paramNames.length; i++) {
if ("channelId".equals(paramNames[i])) { if (ChannelConfUtil.channelIdParamName.equals(paramNames[i])) {
args[i] = userSessionInfo.getChannelId(); Object requestChannelIdObj = args[i];
if (requestChannelIdObj == null) {
log.info("[CheckChannelRole]无channelId数据");
return Result.buildFial(ApplicationStatus.ARGUMENT_VALID_EXCEPTION);
}
final Integer channelIdInteger = Integer.valueOf(String.valueOf(requestChannelIdObj));
if (channelIdInteger != channelIdInSession.intValue()) {
log.info("[CheckChannelRole]渠道用户,登陆channelId与查询channelId不是同一个");
return Result.buildFial(ApplicationStatus.INVALID_AUTHORITY);
} }
} }
} }
}
try { try {
return pjp.proceed(args); return pjp.proceed(args);
} catch (Throwable throwable) { } catch (Throwable throwable) {
log.error("查询渠道列表错误e={}", ExceptionUtils.getStackTrace(throwable)); log.error("请求失败,e={}", ExceptionUtils.getStackTrace(throwable));
return new BossPageImpl<>(); return Result.buildFial();
} }
} }
......
...@@ -73,6 +73,16 @@ public class Result<T> { ...@@ -73,6 +73,16 @@ public class Result<T> {
return new Result(ApplicationStatus.FAILURE, null, message); return new Result(ApplicationStatus.FAILURE, null, message);
} }
@SuppressWarnings("unchecked")
public static<T> Result buildFial() {
return new Result(ApplicationStatus.FAILURE, null, null);
}
@SuppressWarnings("unchecked")
public static<T> Result buildFial(ApplicationStatus applicationStatus) {
return new Result(applicationStatus, null, null);
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static<T> Result buildFial(T data, String message) { public static<T> Result buildFial(T data, String message) {
return new Result(ApplicationStatus.FAILURE, data, message); return new Result(ApplicationStatus.FAILURE, data, message);
......
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