Commit 7917df49 authored by suntao's avatar suntao

渠道配置 查询 做切面处理

parent e5fda3e4
package cn.quantgroup.cashloanflowboss.api.channel.controller; package cn.quantgroup.cashloanflowboss.api.channel.controller;
import cn.quantgroup.cashloanflowboss.api.channel.model.ChannelListModel;
import cn.quantgroup.cashloanflowboss.core.annotation.RoleDataLoad;
import cn.quantgroup.cashloanflowboss.spi.clf.entity.ChannelConfiguration; import cn.quantgroup.cashloanflowboss.spi.clf.entity.ChannelConfiguration;
import cn.quantgroup.cashloanflowboss.api.channel.service.ChannelConfService; import cn.quantgroup.cashloanflowboss.api.channel.service.ChannelConfService;
import cn.quantgroup.cashloanflowboss.api.user.model.Pagination; import cn.quantgroup.cashloanflowboss.api.user.model.Pagination;
import cn.quantgroup.cashloanflowboss.core.base.Result; import cn.quantgroup.cashloanflowboss.core.base.Result;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid; import javax.validation.Valid;
...@@ -26,8 +25,9 @@ public class ChannelConfController { ...@@ -26,8 +25,9 @@ public class ChannelConfController {
private ChannelConfService channelConfService; private ChannelConfService channelConfService;
@GetMapping("/info") @RoleDataLoad
public Page<ChannelConfiguration> channelInfo(Integer pageNumber, Integer pageSize, Integer channelId) { @PostMapping("/info")
public Page<ChannelListModel> channelInfo(Integer channelId, Integer pageNumber, Integer pageSize) {
return channelConfService.getChannelInfo(pageNumber, pageSize, channelId); return channelConfService.getChannelInfo(pageNumber, pageSize, channelId);
} }
......
package cn.quantgroup.cashloanflowboss.api.channel.model;
import lombok.Data;
import java.util.Date;
/**
* function:
* date: 2019/8/6
*
* @author: suntao
*/
@Data
public class ChannelListModel {
private Long channelId;
private String channelName;
private String channelCode;
private Integer bizType;
private Date createdAt;
}
package cn.quantgroup.cashloanflowboss.api.channel.service; package cn.quantgroup.cashloanflowboss.api.channel.service;
import java.util.Date;
import cn.quantgroup.cashloanflowboss.api.channel.entity.boss.ChannelConf; import cn.quantgroup.cashloanflowboss.api.channel.entity.boss.ChannelConf;
import cn.quantgroup.cashloanflowboss.api.channel.model.ChannelListModel;
import cn.quantgroup.cashloanflowboss.spi.clf.entity.ChannelConfiguration; import cn.quantgroup.cashloanflowboss.spi.clf.entity.ChannelConfiguration;
import cn.quantgroup.cashloanflowboss.api.channel.repository.boss.ChannelConfRepository; import cn.quantgroup.cashloanflowboss.api.channel.repository.boss.ChannelConfRepository;
import cn.quantgroup.cashloanflowboss.spi.clf.repository.ChannelConfigurationRepository; import cn.quantgroup.cashloanflowboss.spi.clf.repository.ChannelConfigurationRepository;
...@@ -35,7 +37,7 @@ public class ChannelConfService { ...@@ -35,7 +37,7 @@ public class ChannelConfService {
public Page<ChannelConfiguration> getChannelInfo(Integer pageNumber, Integer pageSize, Integer channelId) { public Page<ChannelListModel> getChannelInfo(Integer pageNumber, Integer pageSize, Integer channelId) {
Page<ChannelConfiguration> page = this.clfChannelConfigurationRepository.findAll((root, criteriaQuery, criteriaBuilder) -> { Page<ChannelConfiguration> page = this.clfChannelConfigurationRepository.findAll((root, criteriaQuery, criteriaBuilder) -> {
...@@ -53,8 +55,17 @@ public class ChannelConfService { ...@@ -53,8 +55,17 @@ public class ChannelConfService {
}, new PageRequest(pageNumber, pageSize)); }, new PageRequest(pageNumber, pageSize));
return page; Page<ChannelListModel> channelListModelPage = page.map(it -> {
ChannelListModel channelListModel = new ChannelListModel();
channelListModel.setChannelId(it.getRegisteredFrom());
channelListModel.setChannelName(it.getChannelName());
channelListModel.setChannelCode(it.getChannelCode());
channelListModel.setBizType(1);
channelListModel.setCreatedAt(it.getCreatedAt());
return channelListModel;
});
return channelListModelPage;
} }
......
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 RoleDataLoad {
}
package cn.quantgroup.cashloanflowboss.core.aspect;
import cn.quantgroup.cashloanflowboss.api.user.model.UserSessionInfo;
import cn.quantgroup.cashloanflowboss.api.user.service.UserSessionService;
import cn.quantgroup.cashloanflowboss.core.annotation.RoleDataLoad;
import cn.quantgroup.cashloanflowboss.core.base.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import java.lang.reflect.Method;
/**
* function:
* date: 2019/8/6
*
* @author: suntao
*/
@Slf4j
@Component
@Aspect
@Order(Ordered.HIGHEST_PRECEDENCE)
public class RoleDataLoadAspect {
@Autowired
private UserSessionService userSessionService;
@Pointcut("execution(* cn.quantgroup.cashloanflowboss.api.channel.controller.*.*(..))")
private void channelRoleInit() {}
@Around(value = "channelRoleInit()")
public Object around(ProceedingJoinPoint pjp) {
Object[] args = pjp.getArgs();
MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
Method method = methodSignature.getMethod();
RoleDataLoad annotation = method.getAnnotation(RoleDataLoad.class);
UserSessionInfo userSessionInfo = userSessionService.findUserSessionInfo();
if (annotation != null && "channel_role".equals(userSessionInfo.getRoleInfo().getRoleName())) {
System.out.println(userSessionInfo.getChannelId());
}
try {
return pjp.proceed(args);
} catch (Throwable throwable) {
return Result.buildFial(ExceptionUtils.getMessage(throwable));
}
}
}
...@@ -68,6 +68,11 @@ public class Result<T> { ...@@ -68,6 +68,11 @@ public class Result<T> {
return new Result(ApplicationStatus.FAILURE, data); return new Result(ApplicationStatus.FAILURE, data);
} }
@SuppressWarnings("unchecked")
public static<T> Result buildFial(String message) {
return new Result(ApplicationStatus.FAILURE, null, message);
}
@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