Commit 766a9386 authored by 王俊权's avatar 王俊权

Merge remote-tracking branch 'origin/v1' into v1

parents e20d6103 b14ffbc1
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.api.channel.util.ChannelConfUtil;
import cn.quantgroup.cashloanflowboss.core.annotation.RoleDataLoad;
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.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.web.bind.annotation.GetMapping; import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map; import javax.validation.Valid;
/** /**
* Created with suntao on 2019/8/2 * Created with suntao on 2019/8/2
* @author suntao * @author suntao
*/ */
@RestController @RestController
@RequestMapping("channel/cfg") @RequestMapping("channel")
public class ChannelConfController { public class ChannelConfController {
...@@ -22,16 +26,18 @@ public class ChannelConfController { ...@@ -22,16 +26,18 @@ public class ChannelConfController {
private ChannelConfService channelConfService; private ChannelConfService channelConfService;
@GetMapping("/info") @RoleDataLoad
public Result channelConfInfo(Integer channelId) { @PostMapping("/info")
public Page<ChannelListModel> channelInfo(Long channelId, Integer pageNumber, Integer pageSize) {
return channelConfService.getChannelInfo(pageNumber, pageSize, channelId);
}
Map<String, Object> channelConf = channelConfService.getChannelConf(channelId);
if (channelConf == null) { @GetMapping("/cfg/info")
return new Result(); public Result channelConfInfo(Long channelId) {
} else { return Result.buildSuccess(channelConfService.getChannelConf(channelId), "success");
// TODO
return null;
}
} }
} }
...@@ -18,7 +18,7 @@ public class ChannelConf extends Primary { ...@@ -18,7 +18,7 @@ public class ChannelConf extends Primary {
* 渠道id * 渠道id
*/ */
@Column(name = "channel_id") @Column(name = "channel_id")
private Integer channelId; private Long channelId;
/** /**
* 渠道code * 渠道code
......
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.repository.boss; package cn.quantgroup.cashloanflowboss.api.channel.repository.boss;
import cn.quantgroup.cashloanflowboss.api.channel.entity.boss.ChannelConf; import cn.quantgroup.cashloanflowboss.api.channel.entity.boss.ChannelConf;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
/** /**
* Created by suntao on 2019/7/22. * Created by suntao on 2019/7/22.
* @author suntao * @author suntao
*/ */
@Repository @Repository
public interface ChannelConfRepository { public interface ChannelConfRepository extends JpaRepository<ChannelConf, Long> {
/** /**
* 获取用户 * 获取用户
...@@ -16,7 +18,7 @@ public interface ChannelConfRepository { ...@@ -16,7 +18,7 @@ public interface ChannelConfRepository {
* @param channelId 用户名 * @param channelId 用户名
* @return * @return
*/ */
ChannelConf getByChannelId(Integer channelId); ChannelConf getByChannelId(Long channelId);
} }
package cn.quantgroup.cashloanflowboss.api.channel.service; package cn.quantgroup.cashloanflowboss.api.channel.service;
import java.util.*;
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.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.api.channel.util.ChannelConfUtil; import cn.quantgroup.cashloanflowboss.api.channel.util.ChannelConfUtil;
import cn.quantgroup.cashloanflowboss.api.user.model.Pagination;
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.PageRequest;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Map; import javax.persistence.criteria.Predicate;
/** /**
* function: * function:
...@@ -18,20 +26,52 @@ import java.util.Map; ...@@ -18,20 +26,52 @@ import java.util.Map;
@Service @Service
public class ChannelConfService { public class ChannelConfService {
// @Autowired @Autowired
// private ChannelConfRepository channelConfRepository; private ChannelConfRepository channelConfRepository;
@Autowired
private ChannelConfigurationRepository clfChannelConfigurationRepository;
public Map<String, Object> getChannelConf(Integer channelId) {
public Page<ChannelListModel> getChannelInfo(Integer pageNumber, Integer pageSize, Long channelId) {
// ChannelConf channelConf = channelConfRepository.getByChannelId(channelId); Page<ChannelConfiguration> page = this.clfChannelConfigurationRepository.findAll((root, criteriaQuery, criteriaBuilder) -> {
// if (channelConf == null) {
// return null; List<Predicate> predicates = new ArrayList<>();
// }
// // 指定渠道号
// return ChannelConfUtil.channelConfConvertVOModel(channelConf); if (Objects.nonNull(channelId)) {
return null; predicates.add(criteriaBuilder.equal(root.get("registeredFrom"), channelId.longValue()));
}
// 设置查询条件
criteriaQuery.where(criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()])));
// 指定排序
criteriaQuery.orderBy(criteriaBuilder.desc(root.get("id")));
return criteriaQuery.getRestriction();
}, new PageRequest(pageNumber, pageSize));
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;
}
public Map<String, Object> getChannelConf(Long channelId) {
ChannelConf channelConf = channelConfRepository.getByChannelId(channelId);
return ChannelConfUtil.channelConfConvertVOModel(channelConf);
} }
} }
...@@ -2,6 +2,7 @@ package cn.quantgroup.cashloanflowboss.api.log.controller; ...@@ -2,6 +2,7 @@ package cn.quantgroup.cashloanflowboss.api.log.controller;
import cn.quantgroup.cashloanflowboss.api.log.model.LoginFormModel; import cn.quantgroup.cashloanflowboss.api.log.model.LoginFormModel;
import cn.quantgroup.cashloanflowboss.api.log.service.LogService; import cn.quantgroup.cashloanflowboss.api.log.service.LogService;
import cn.quantgroup.cashloanflowboss.component.security.Authority;
import cn.quantgroup.cashloanflowboss.component.security.annotiation.Security; import cn.quantgroup.cashloanflowboss.component.security.annotiation.Security;
import cn.quantgroup.cashloanflowboss.core.base.Result; import cn.quantgroup.cashloanflowboss.core.base.Result;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus; import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus;
...@@ -38,8 +39,8 @@ public class LogController { ...@@ -38,8 +39,8 @@ public class LogController {
* *
* @return * @return
*/ */
@Security(authorityId = "Log.logout")
@DeleteMapping("/logout") @DeleteMapping("/logout")
@Security(authorityId = "Log.logout", authorities = Authority.READ)
public Result<Boolean> logout() { public Result<Boolean> logout() {
return new Result<>(ApplicationStatus.SUCCESS, this.logService.logout()); return new Result<>(ApplicationStatus.SUCCESS, this.logService.logout());
} }
......
...@@ -3,19 +3,16 @@ package cn.quantgroup.cashloanflowboss.api.log.service; ...@@ -3,19 +3,16 @@ package cn.quantgroup.cashloanflowboss.api.log.service;
import cn.quantgroup.cashloanflowboss.api.user.dictionary.UserStatus; import cn.quantgroup.cashloanflowboss.api.user.dictionary.UserStatus;
import cn.quantgroup.cashloanflowboss.api.user.entity.boss.User; import cn.quantgroup.cashloanflowboss.api.user.entity.boss.User;
import cn.quantgroup.cashloanflowboss.api.user.service.UserService; import cn.quantgroup.cashloanflowboss.api.user.service.UserService;
import cn.quantgroup.cashloanflowboss.component.security.Authority; import cn.quantgroup.cashloanflowboss.api.user.service.UserSessionService;
import cn.quantgroup.cashloanflowboss.core.asserts.Assert; import cn.quantgroup.cashloanflowboss.core.asserts.Assert;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationDictionary; import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationDictionary;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus; import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus;
import cn.quantgroup.cashloanflowboss.utils.JSONTools;
import cn.quantgroup.cashloanflowboss.utils.MD5Tools; import cn.quantgroup.cashloanflowboss.utils.MD5Tools;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
/** /**
* Created by WeiWei on 2019/7/22. * Created by WeiWei on 2019/7/22.
...@@ -26,6 +23,8 @@ public class LogService { ...@@ -26,6 +23,8 @@ public class LogService {
@Autowired @Autowired
private UserService userService; private UserService userService;
@Autowired
private UserSessionService userSessionService;
@Autowired @Autowired
private HttpServletRequest request; private HttpServletRequest request;
...@@ -50,10 +49,8 @@ public class LogService { ...@@ -50,10 +49,8 @@ public class LogService {
// 检查密码是否正确 // 检查密码是否正确
Assert.isFalse(user.getPassword().equalsIgnoreCase(MD5Tools.md5(password)), ApplicationStatus.USERNAME_OR_PASSWORD_ERROR); Assert.isFalse(user.getPassword().equalsIgnoreCase(MD5Tools.md5(password)), ApplicationStatus.USERNAME_OR_PASSWORD_ERROR);
HttpSession session = this.request.getSession(true); // set user session info
session.setAttribute(ApplicationDictionary.SECURITY_KEY, JSONTools.serialize(new HashMap<String, Authority>() {{ userSessionService.setUserSessionInfo(user);
put("Log.logout", Authority.CREATE);
}}));
return true; return true;
......
package cn.quantgroup.cashloanflowboss.api.role.entity; package cn.quantgroup.cashloanflowboss.api.role.entity.boss;
import cn.quantgroup.cashloanflowboss.component.security.Authority; import cn.quantgroup.cashloanflowboss.component.security.Authority;
import lombok.Data; import lombok.Data;
......
package cn.quantgroup.cashloanflowboss.api.role.entity; package cn.quantgroup.cashloanflowboss.api.role.entity.boss;
import cn.quantgroup.cashloanflowboss.component.security.Authority; import cn.quantgroup.cashloanflowboss.api.role.entity.boss.Permission;
import cn.quantgroup.cashloanflowboss.core.persistence.Primary; import cn.quantgroup.cashloanflowboss.core.persistence.Primary;
import lombok.Data; import lombok.Data;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.List; import java.util.List;
/** /**
...@@ -29,6 +30,8 @@ public class Role extends Primary { ...@@ -29,6 +30,8 @@ public class Role extends Primary {
/** /**
* 授权列表 * 授权列表
*/ */
private List<Authority> authorities; @Transient
private List<Permission> permissions;
} }
package cn.quantgroup.cashloanflowboss.api.role.entity.boss;
import cn.quantgroup.cashloanflowboss.core.persistence.Primary;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
@Data
@Entity
@Table(name = "role_user")
public class RoleUser extends Primary {
@Column(name = "role_id")
private Long roleId;
@Column(name = "user_id")
private Long userId;
}
package cn.quantgroup.cashloanflowboss.api.role.repository;
import org.springframework.stereotype.Repository;
/**
* Created by WeiWei on 2019/7/30.
*/
@Repository
public interface RoleRepository {
}
package cn.quantgroup.cashloanflowboss.api.role.repository.boss;
import cn.quantgroup.cashloanflowboss.api.role.entity.boss.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* Created by WeiWei on 2019/7/30.
*/
@Repository
public interface RoleRepository extends JpaRepository<Role, Long> {
}
package cn.quantgroup.cashloanflowboss.api.role.repository.boss;
import cn.quantgroup.cashloanflowboss.api.role.entity.boss.RoleUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface RoleUserRepository extends JpaRepository<RoleUser, Long> {
RoleUser findByUserId(Long userId);
}
package cn.quantgroup.cashloanflowboss.api.role.service;
import cn.quantgroup.cashloanflowboss.api.role.entity.boss.Role;
import cn.quantgroup.cashloanflowboss.api.role.entity.boss.RoleUser;
import cn.quantgroup.cashloanflowboss.api.role.repository.boss.RoleRepository;
import cn.quantgroup.cashloanflowboss.api.role.repository.boss.RoleUserRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class RoleService {
@Autowired
private RoleRepository roleRepository;
@Autowired
private RoleUserRepository roleUserRepository;
public Role findRoleByUserId(Long userId) {
RoleUser roleUser = roleUserRepository.findByUserId(userId);
if (null == roleUser) {
return null;
}
Long roleId = roleUser.getRoleId();
Role role = findRoleByRoleId(roleId);
return role;
}
public Role findRoleByRoleId(Long roleId) {
return roleRepository.findOne(roleId);
}
}
package cn.quantgroup.cashloanflowboss.api.test.controller;
import cn.quantgroup.cashloanflowboss.api.user.model.UserSessionInfo;
import cn.quantgroup.cashloanflowboss.api.user.service.UserSessionService;
import cn.quantgroup.cashloanflowboss.core.base.Result;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/test")
public class TestController {
@Autowired
private UserSessionService userSessionService;
@GetMapping("/user/info")
public Result findUserFromSession() {
UserSessionInfo userSessionInfo = userSessionService.findUserSessionInfo();
return new Result<>(ApplicationStatus.SUCCESS, userSessionInfo);
}
}
...@@ -4,9 +4,6 @@ import cn.quantgroup.cashloanflowboss.api.user.entity.boss.User; ...@@ -4,9 +4,6 @@ import cn.quantgroup.cashloanflowboss.api.user.entity.boss.User;
import cn.quantgroup.cashloanflowboss.api.user.model.Pagination; import cn.quantgroup.cashloanflowboss.api.user.model.Pagination;
import cn.quantgroup.cashloanflowboss.api.user.model.RegisterUserFormModel; import cn.quantgroup.cashloanflowboss.api.user.model.RegisterUserFormModel;
import cn.quantgroup.cashloanflowboss.api.user.service.UserService; import cn.quantgroup.cashloanflowboss.api.user.service.UserService;
import cn.quantgroup.cashloanflowboss.component.security.Power;
import cn.quantgroup.cashloanflowboss.component.security.annotiation.Security;
import cn.quantgroup.cashloanflowboss.component.validator.constraints.NotEmpty;
import cn.quantgroup.cashloanflowboss.component.validator.constraints.NotEmpty; import cn.quantgroup.cashloanflowboss.component.validator.constraints.NotEmpty;
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;
......
package cn.quantgroup.cashloanflowboss.api.user.entity.boss;
import cn.quantgroup.cashloanflowboss.core.persistence.Primary;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
@Data
@Entity
@Table(name = "channel_user")
public class ChannelUser extends Primary {
@Column(name = "channel_id")
private Long channelId;
@Column(name = "user_id")
private Long userId;
}
package cn.quantgroup.cashloanflowboss.api.user.model;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
@AllArgsConstructor
public class RoleInfo {
private Long roleId;
private String roleName;
}
package cn.quantgroup.cashloanflowboss.api.user.model;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
@AllArgsConstructor
public class UserInfo {
private Long userId;
private String userName;
}
package cn.quantgroup.cashloanflowboss.api.user.model;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
@AllArgsConstructor
public class UserSessionInfo {
private UserInfo userInfo;
private RoleInfo roleInfo;
private Long channelId;
}
package cn.quantgroup.cashloanflowboss.api.user.repository.boss;
import cn.quantgroup.cashloanflowboss.api.user.entity.boss.ChannelUser;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;
/**
* Created by WeiWei on 2019/7/22.
*/
@Repository
public interface ChannelUserRepository extends PagingAndSortingRepository<ChannelUser, String> {
ChannelUser findByUserId(Long userId);
}
package cn.quantgroup.cashloanflowboss.api.user.service;
import cn.quantgroup.cashloanflowboss.api.user.entity.boss.ChannelUser;
import cn.quantgroup.cashloanflowboss.api.user.repository.boss.ChannelUserRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class ChannelUserService {
@Autowired
private ChannelUserRepository channelUserRepository;
public ChannelUser findChannelUserByUserId(Long userId) {
return channelUserRepository.findByUserId(userId);
}
}
...@@ -2,16 +2,23 @@ package cn.quantgroup.cashloanflowboss.api.user.service; ...@@ -2,16 +2,23 @@ package cn.quantgroup.cashloanflowboss.api.user.service;
import cn.quantgroup.cashloanflowboss.api.user.dictionary.UserStatus; import cn.quantgroup.cashloanflowboss.api.user.dictionary.UserStatus;
import cn.quantgroup.cashloanflowboss.api.user.entity.boss.User; import cn.quantgroup.cashloanflowboss.api.user.entity.boss.User;
import cn.quantgroup.cashloanflowboss.api.user.model.UserSessionInfo;
import cn.quantgroup.cashloanflowboss.api.user.repository.boss.UserRepository; import cn.quantgroup.cashloanflowboss.api.user.repository.boss.UserRepository;
import cn.quantgroup.cashloanflowboss.core.asserts.Assert; import cn.quantgroup.cashloanflowboss.core.asserts.Assert;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationDictionary;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus; import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus;
import cn.quantgroup.cashloanflowboss.utils.JSONTools;
import cn.quantgroup.cashloanflowboss.utils.MD5Tools; import cn.quantgroup.cashloanflowboss.utils.MD5Tools;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
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.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpSession;
import java.util.Objects; import java.util.Objects;
/** /**
...@@ -130,4 +137,5 @@ public class UserService { ...@@ -130,4 +137,5 @@ public class UserService {
} }
} }
package cn.quantgroup.cashloanflowboss.api.user.service;
import cn.quantgroup.cashloanflowboss.api.role.entity.boss.Permission;
import cn.quantgroup.cashloanflowboss.api.role.entity.boss.Role;
import cn.quantgroup.cashloanflowboss.api.role.service.RoleService;
import cn.quantgroup.cashloanflowboss.api.user.entity.boss.ChannelUser;
import cn.quantgroup.cashloanflowboss.api.user.entity.boss.User;
import cn.quantgroup.cashloanflowboss.api.user.model.RoleInfo;
import cn.quantgroup.cashloanflowboss.api.user.model.UserInfo;
import cn.quantgroup.cashloanflowboss.api.user.model.UserSessionInfo;
import cn.quantgroup.cashloanflowboss.component.security.Authority;
import cn.quantgroup.cashloanflowboss.core.asserts.Assert;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationDictionary;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus;
import cn.quantgroup.cashloanflowboss.utils.JSONTools;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpSession;
import java.util.Arrays;
@Slf4j
@Service
public class UserSessionService {
@Autowired
private RoleService roleService;
@Autowired
private ChannelUserService channelUserService;
public void setUserSessionInfo(User user) {
//set user,role,channel or permission info
Role role = roleService.findRoleByUserId(user.getId());
String roleName = null, userName = user.getUsername();
Long roleId = null, channelId = null, userId = user.getId();
if (null != role) {
roleName = role.getName();
roleId = role.getId();
}
ChannelUser channelUser = channelUserService.findChannelUserByUserId(userId);
if (null != channelUser) {
channelId = channelUser.getChannelId();
}
UserSessionInfo userSessionInfo = UserSessionInfo.builder()
.roleInfo(RoleInfo.builder().roleId(roleId).roleName(roleName).build())
.userInfo(UserInfo.builder().userId(userId).userName(userName).build())
.channelId(channelId)
.build();
HttpSession session = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession();
session.setAttribute(ApplicationDictionary.USER_KEY, JSONTools.serialize(userSessionInfo));
//todo permission后续放入UserSessionInfo结构中吧
Permission permission = new Permission();
permission.setId("Log.logout");
permission.setAuthorities(Arrays.asList(Authority.READ));
session.setAttribute(ApplicationDictionary.SECURITY_KEY, JSONTools.serialize(Arrays.asList(permission)));
}
public UserSessionInfo findUserSessionInfo() {
HttpSession session = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession();
Assert.isNull(session.getAttribute(ApplicationDictionary.USER_KEY), ApplicationStatus.INVALID_USER);
UserSessionInfo userSessionInfo = JSONTools.deserialize(String.valueOf(session.getAttribute(ApplicationDictionary.USER_KEY)), new TypeReference<UserSessionInfo>() {
});
return userSessionInfo;
}
}
package cn.quantgroup.cashloanflowboss.component.security;
/**
* Created by WeiWei on 2019/7/26.
*/
public enum Power {
/**
* 新建
*/
CREATE,
/**
* 更新
*/
UPDATE,
/**
* 删除
*/
DELETE
}
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.channel.model.ChannelListModel;
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.BossPageImpl;
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.core.convert.converter.Converter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component;
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.List;
/**
* 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();
// todo channel_role 定义为常量吧
if (annotation != null && "channel_role".equals(userSessionInfo.getRoleInfo().getRoleName())) {
args[0] = userSessionInfo.getChannelId();
}
try {
return pjp.proceed(args);
} catch (Throwable throwable) {
log.error("查询渠道列表错误e={}", ExceptionUtils.getStackTrace(throwable));
return new BossPageImpl<>();
}
}
}
package cn.quantgroup.cashloanflowboss.core.base;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import java.util.Iterator;
import java.util.List;
/**
* function:
* date: 2019/8/6
*
* @author: suntao
*/
public class BossPageImpl<T> implements Page {
@Override
public int getTotalPages() {
return 0;
}
@Override
public long getTotalElements() {
return 0;
}
@Override
public Page map(Converter converter) {
return null;
}
@Override
public int getNumber() {
return 0;
}
@Override
public int getSize() {
return 0;
}
@Override
public int getNumberOfElements() {
return 0;
}
@Override
public List getContent() {
return null;
}
@Override
public boolean hasContent() {
return false;
}
@Override
public Sort getSort() {
return null;
}
@Override
public boolean isFirst() {
return false;
}
@Override
public boolean isLast() {
return false;
}
@Override
public boolean hasNext() {
return false;
}
@Override
public boolean hasPrevious() {
return false;
}
@Override
public Pageable nextPageable() {
return null;
}
@Override
public Pageable previousPageable() {
return null;
}
@Override
public Iterator iterator() {
return null;
}
}
package cn.quantgroup.cashloanflowboss.core.base; package cn.quantgroup.cashloanflowboss.core.base;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus;
import cn.quantgroup.cashloanflowboss.core.dictionary.Status; import cn.quantgroup.cashloanflowboss.core.dictionary.Status;
import lombok.Data; import lombok.Data;
...@@ -50,4 +51,32 @@ public class Result<T> { ...@@ -50,4 +51,32 @@ public class Result<T> {
} }
@SuppressWarnings("unchecked")
public static<T> Result buildSuccess(T data) {
return new Result(ApplicationStatus.SUCCESS, data);
}
@SuppressWarnings("unchecked")
public static<T> Result buildSuccess(T data, String message) {
return new Result(ApplicationStatus.SUCCESS, data, message);
}
@SuppressWarnings("unchecked")
public static<T> Result buildFial(T 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")
public static<T> Result buildFial(T data, String message) {
return new Result(ApplicationStatus.FAILURE, data, message);
}
} }
...@@ -36,7 +36,6 @@ public class ApplicationExceptionConfiguration { ...@@ -36,7 +36,6 @@ public class ApplicationExceptionConfiguration {
*/ */
@ExceptionHandler({ApplicationException.class}) @ExceptionHandler({ApplicationException.class})
public Result applicationExceptionHandler(ApplicationException e) { public Result applicationExceptionHandler(ApplicationException e) {
log.error("程序员开小差了,系统异常信息:{}", e.getMessage());
return new Result<>(e.getStatus(), null, e.getStatus().getMessage()); return new Result<>(e.getStatus(), null, e.getStatus().getMessage());
} }
...@@ -96,19 +95,9 @@ public class ApplicationExceptionConfiguration { ...@@ -96,19 +95,9 @@ public class ApplicationExceptionConfiguration {
@ExceptionHandler({Throwable.class}) @ExceptionHandler({Throwable.class})
public Result generalException(Throwable e) { public Result generalException(Throwable e) {
Throwable cause = e; log.error(e.getMessage(), e);
while ((cause = cause.getCause()) != null) { return new Result<>(ApplicationStatus.INTERNAL_SERVICE_ERROR);
if (ApplicationException.class.isAssignableFrom(cause.getClass())) {
cause = cause.getCause();
break;
}
}
String errorMessage = ApplicationException.class.isAssignableFrom(e.getClass()) ? cause.getMessage() : e.getMessage();
log.error("程序员开小差了,未明确的异常信息:{}", errorMessage);
return new Result<>(ApplicationStatus.INTERNAL_SERVICE_ERROR, ApplicationStatus.INTERNAL_SERVICE_ERROR.getMessage());
} }
......
package cn.quantgroup.cashloanflowboss.core.configuration; package cn.quantgroup.cashloanflowboss.core.configuration;
import cn.quantgroup.cashloanflowboss.api.role.entity.Permission; import cn.quantgroup.cashloanflowboss.api.role.entity.boss.Permission;
import cn.quantgroup.cashloanflowboss.component.security.Authority; import cn.quantgroup.cashloanflowboss.component.security.Authority;
import cn.quantgroup.cashloanflowboss.component.security.SecurityHandler; import cn.quantgroup.cashloanflowboss.component.security.SecurityHandler;
import cn.quantgroup.cashloanflowboss.core.asserts.Assert; import cn.quantgroup.cashloanflowboss.core.asserts.Assert;
...@@ -34,7 +34,7 @@ public class ApplicationSecurityConfiguration implements SecurityHandler { ...@@ -34,7 +34,7 @@ public class ApplicationSecurityConfiguration implements SecurityHandler {
HttpSession session = this.request.getSession(false); HttpSession session = this.request.getSession(false);
// 检查是否已登录 // 检查是否已登录
Assert.isNull(session.getAttribute(ApplicationDictionary.SECURITY_KEY), ApplicationStatus.AUTHENTICATION_FAILURE); Assert.isTrue((Objects.isNull(session) || Objects.isNull(session.getAttribute(ApplicationDictionary.SECURITY_KEY))), ApplicationStatus.AUTHENTICATION_FAILURE);
// 读取Session授权内容 // 读取Session授权内容
List<Permission> permissions = JSONTools.deserialize(String.valueOf(session.getAttribute(ApplicationDictionary.SECURITY_KEY)), new TypeReference<List<Permission>>() {}); List<Permission> permissions = JSONTools.deserialize(String.valueOf(session.getAttribute(ApplicationDictionary.SECURITY_KEY)), new TypeReference<List<Permission>>() {});
......
...@@ -65,7 +65,7 @@ public class BossDSConfig { ...@@ -65,7 +65,7 @@ public class BossDSConfig {
public LocalContainerEntityManagerFactoryBean entityManager(EntityManagerFactoryBuilder builder) { public LocalContainerEntityManagerFactoryBean entityManager(EntityManagerFactoryBuilder builder) {
return builder.dataSource(createDataSource()) return builder.dataSource(createDataSource())
.packages("cn.quantgroup.cashloanflowboss.api.user.entity.boss") .packages("cn.quantgroup.cashloanflowboss.api.*.entity.boss")
.persistenceUnit(uniquename) .persistenceUnit(uniquename)
.build(); .build();
} }
......
package cn.quantgroup.cashloanflowboss.core.configuration.data;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = {"cn.quantgroup.cashloanflowboss.spi.clf.repository"},
entityManagerFactoryRef = "clfEntityManager",
transactionManagerRef = "clfTransactionManager")
public class ClfDSConfig {
@Value("${data.clf.url}")
private String jdbcUrl;
@Value("${data.clf.password}")
private String password;
@Value("${data.clf.username}")
private String user;
private String uniquename = "clfDS";
@Value("${data.clf.pool-size}")
private Integer poolSize;
@Bean(name = "clfDataSource")
@ConfigurationProperties(prefix = "data.clf")
public DataSource createDataSource() {
DruidDataSource source = DruidDataSourceBuilder.create().build();
source.setMaxActive(200);
source.setMinIdle(10);
source.setInitialSize(10);
source.setMaxWait(500000);
source.setTimeBetweenEvictionRunsMillis(60000);
source.setMinEvictableIdleTimeMillis(300000);
source.setValidationQuery("SELECT 'x'");
source.setTestWhileIdle(true);
source.setTestOnBorrow(false);
source.setTestOnReturn(false);
source.setPoolPreparedStatements(Boolean.FALSE);
return source;
}
@Bean(name = "clfEntityManager")
public LocalContainerEntityManagerFactoryBean entityManager(EntityManagerFactoryBuilder builder) {
return builder.dataSource(createDataSource())
.packages("cn.quantgroup.cashloanflowboss.spi.clf.entity")
.persistenceUnit(uniquename)
.build();
}
@Bean(name = "clfTransactionManager")
public PlatformTransactionManager transactionManager(@Qualifier("clfEntityManager") EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory);
}
}
...@@ -9,5 +9,7 @@ public final class ApplicationDictionary { ...@@ -9,5 +9,7 @@ public final class ApplicationDictionary {
// 权限Session Key // 权限Session Key
public static final String SECURITY_KEY = "PERMISSION"; public static final String SECURITY_KEY = "PERMISSION";
// user Session key
public static final String USER_KEY = "USER";
} }
...@@ -27,11 +27,11 @@ public enum ApplicationStatus implements Status<ApplicationStatus> { ...@@ -27,11 +27,11 @@ public enum ApplicationStatus implements Status<ApplicationStatus> {
INVALID_AUTHORITY(501001, "无效的授权"), INVALID_AUTHORITY(501001, "无效的授权"),
INVALID_USER(501001, "无效的用户"), INVALID_USER(501002, "无效的用户"),
DISABLED_USER(501002, "用户已被禁用"), DISABLED_USER(501003, "用户已被禁用"),
USERNAME_OR_PASSWORD_ERROR(501003, "用户名或密码错误"); USERNAME_OR_PASSWORD_ERROR(501004, "用户名或密码错误");
private int code; private int code;
......
package cn.quantgroup.cashloanflowboss.spi.clf.entity;
import cn.quantgroup.cashloanflowboss.spi.clf.model.EncType;
import lombok.Data;
import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* Created by wudi on 2016/11/28.
*/
@Data
@Entity
@Table(name = "channel_configuration", catalog = "cash_loan_flow")
public class ChannelConfiguration implements Serializable {
private static final long serialVersionUID = -1L;
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "channel_name")
private String channelName;
@Column(name = "channel_code")
private String channelCode;
@Column(name = "registered_from")
private Long registeredFrom;
/**
* 默认有效
*/
@Column(name = "is_active")
private Boolean isActive = Boolean.TRUE;
@Column(name = "created_at")
private Timestamp createdAt = new Timestamp(System.currentTimeMillis());
/**
* 请求是否使用标准api
*/
@Column(name = "is_request_standard")
private Boolean isRequestStandard = Boolean.FALSE;
/**
* 加密类型
*/
@Column(name = "enc_type")
private EncType encType = EncType.AES;
/**
* aes加密key
*/
@Column(name = "aes_key")
private String aesKey;
/**
* md5摘要key
*/
@Column(name = "md5_key")
private String md5Key;
/**
* 授信中心channelCode, 爬虫提交channelCode
*/
@Column(name = "spider_center_channel_code")
private String spiderCenterChannelCode;
/**
* 授信中心商户渠道channelCode,授信授权提交channelCode
*/
@Column(name = "spider_center_merchant_channel_code")
private String spiderCenterMerchantChannelCode;
/**
* 渠道认证选项
*/
@Column(name = "auth_option")
private String authOption;
/**
* 免密登陆跳转url
*/
@Column(name = "login_page_url")
private String loginPageUrl;
}
\ No newline at end of file
package cn.quantgroup.cashloanflowboss.spi.clf.model;
/**
* Created by liqing on 2017/4/26 0026.
* 加解密方式
*/
public enum EncType {
AES("AES", "aesStandardCryptoService"),RSA("RSA", "rsaStandardCryptoService"),NONE("NONE", "noneStandardCryptoService");
public String text;
public String serviceClass;
EncType(String text, String serviceClass){
this.text = text;
this.serviceClass = serviceClass;
}
}
package cn.quantgroup.cashloanflowboss.spi.clf.repository;
import cn.quantgroup.cashloanflowboss.spi.clf.entity.ChannelConfiguration;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface ChannelConfigurationRepository extends PagingAndSortingRepository<ChannelConfiguration, Long>, JpaSpecificationExecutor<ChannelConfiguration> {
}
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