Commit 739cd248 authored by suntao's avatar suntao

渠道配置查询 编辑

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