This commit is contained in:
parent
6f83ad86da
commit
ef5d90621f
|
|
@ -6,10 +6,12 @@ import org.springframework.boot.SpringApplication;
|
|||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = {"com.hxkj"})
|
||||
@MapperScan(basePackages = {"com.hxkj.*.mapper"})
|
||||
@EnableTransactionManagement
|
||||
@SpringBootApplication(exclude = {MPJSqlInjector.class})
|
||||
public class LikeAdminApplication {
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,90 @@
|
|||
package com.hxkj.admin.config;
|
||||
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
import org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class JwtFilter extends BasicHttpAuthenticationFilter {
|
||||
|
||||
/**
|
||||
* 执行登录认证(判断请求头是否带上token)
|
||||
* @param request
|
||||
* @param response
|
||||
* @param mappedValue
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
|
||||
System.out.println("酷酷酷酷酷");
|
||||
// 如果请求头不存在token,则可能是执行登陆操作或是游客状态访问,直接返回true
|
||||
if (isLoginAttempt(request, response)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 如果存在,则进入executeLogin方法执行登入,检查token 是否正确
|
||||
try {
|
||||
executeLogin(request, response);return true;
|
||||
} catch (Exception e) {
|
||||
throw new AuthenticationException("Token失效请重新登录");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断用户是否是登入,检测headers里是否包含token字段
|
||||
*/
|
||||
@Override
|
||||
protected boolean isLoginAttempt(ServletRequest request, ServletResponse response) {
|
||||
|
||||
HttpServletRequest req = (HttpServletRequest) request;
|
||||
// if(antPathMatcher.match("/userLogin",req.getRequestURI())){
|
||||
// return true;
|
||||
// }
|
||||
// String token = req.getHeader("token");
|
||||
// if (token == null) {
|
||||
// return false;
|
||||
// }
|
||||
// Object o = redisUtil.get(CommonConstant.PREFIX_USER_TOKEN + token);
|
||||
// if(ObjectUtils.isEmpty(o)){
|
||||
// return false;
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写AuthenticatingFilter的executeLogin方法丶执行登陆操作
|
||||
*/
|
||||
@Override
|
||||
protected boolean executeLogin(ServletRequest request, ServletResponse response) throws Exception {
|
||||
|
||||
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
|
||||
String token = httpServletRequest.getHeader("token");//Access-Token
|
||||
JwtToken jwtToken = new JwtToken(token);
|
||||
// 提交给realm进行登入,如果错误他会抛出异常并被捕获, 反之则代表登入成功,返回true
|
||||
getSubject(request, response).login(jwtToken);return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对跨域提供支持
|
||||
*/
|
||||
@Override
|
||||
protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception {
|
||||
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
|
||||
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
|
||||
httpServletResponse.setHeader("Access-control-Allow-Origin", httpServletRequest.getHeader("Origin"));
|
||||
httpServletResponse.setHeader("Access-Control-Allow-Methods", "GET,POST,OPTIONS,PUT,DELETE");
|
||||
httpServletResponse.setHeader("Access-Control-Allow-Headers", httpServletRequest.getHeader("Access-Control-Request-Headers"));
|
||||
if (httpServletRequest.getMethod().equals(RequestMethod.OPTIONS.name())) {
|
||||
httpServletResponse.setStatus(HttpStatus.OK.value());
|
||||
return false;
|
||||
}
|
||||
return super.preHandle(request, response);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package com.hxkj.admin.config;
|
||||
|
||||
import org.apache.shiro.authc.AuthenticationToken;
|
||||
|
||||
/**
|
||||
* 主要是为了将用户信息改为Token传递
|
||||
* 重写Token,通过token方式进行验证
|
||||
*/
|
||||
public class JwtToken implements AuthenticationToken {
|
||||
|
||||
private final String token;
|
||||
|
||||
public JwtToken(String token) {
|
||||
System.out.println("就将计就计");
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPrincipal() {
|
||||
return token;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getCredentials() {
|
||||
return token;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package com.hxkj.admin.config;
|
||||
|
||||
import org.apache.catalina.User;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authc.*;
|
||||
import org.apache.shiro.authz.AuthorizationInfo;
|
||||
import org.apache.shiro.authz.SimpleAuthorizationInfo;
|
||||
import org.apache.shiro.realm.AuthorizingRealm;
|
||||
import org.apache.shiro.subject.PrincipalCollection;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
|
||||
public class RealmConfig extends AuthorizingRealm {
|
||||
|
||||
/**
|
||||
* 授权
|
||||
* @param principals 主要
|
||||
* @return AuthorizationInfo
|
||||
*/
|
||||
@Override
|
||||
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
|
||||
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
|
||||
info.addStringPermission("user:add");
|
||||
|
||||
// 拿到当前登录对象
|
||||
Subject subject = SecurityUtils.getSubject();
|
||||
User currentUser = (User) subject.getPrincipal();
|
||||
//info.addStringPermission(currentUser.getPerms());
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 认证
|
||||
* @param token 令牌
|
||||
* @return AuthenticationInfo
|
||||
*/
|
||||
@Override
|
||||
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
|
||||
String name = "root";
|
||||
String password = "123456";
|
||||
|
||||
UsernamePasswordToken userToken = (UsernamePasswordToken) token;
|
||||
if (!userToken.getUsername().equals(name)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 密码认证
|
||||
return new SimpleAuthenticationInfo("", password, "");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,59 +1,111 @@
|
|||
package com.hxkj.admin.config;
|
||||
|
||||
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
|
||||
import org.apache.shiro.mgt.DefaultSessionStorageEvaluator;
|
||||
import org.apache.shiro.mgt.DefaultSubjectDAO;
|
||||
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
|
||||
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.filter.DelegatingFilterProxy;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
//@Configuration
|
||||
@Configuration
|
||||
public class ShiroConfig {
|
||||
|
||||
/**
|
||||
* 拦截过滤器配置
|
||||
* @return ShiroFilterFactoryBean
|
||||
* 安全管理器
|
||||
*
|
||||
* @param realmConfig realmConfig
|
||||
* @return DefaultWebSecurityManager
|
||||
*/
|
||||
@Bean
|
||||
public ShiroFilterFactoryBean getShiroFactoryFilterBean(DefaultWebSecurityManager defaultWebSecurityManager) {
|
||||
public DefaultWebSecurityManager doDefaultWebSecurityManager(ShiroRealm realmConfig) {
|
||||
DefaultWebSecurityManager defaultWebSecurityManager = new DefaultWebSecurityManager();
|
||||
defaultWebSecurityManager.setRealm(realmConfig);
|
||||
|
||||
DefaultSubjectDAO subjectDAO = new DefaultSubjectDAO();
|
||||
DefaultSessionStorageEvaluator defaultSessionStorageEvaluator = new DefaultSessionStorageEvaluator();
|
||||
defaultSessionStorageEvaluator.setSessionStorageEnabled(false);
|
||||
subjectDAO.setSessionStorageEvaluator(defaultSessionStorageEvaluator);
|
||||
defaultWebSecurityManager.setSubjectDAO(subjectDAO);
|
||||
|
||||
return defaultWebSecurityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拦截过滤器配置
|
||||
* anon: 无需认证就可以访问
|
||||
* authc: 必须认证了才能访问
|
||||
* perms: 拥有某个资源权限才能访问
|
||||
* role: 拥有某个角色权限才能访问
|
||||
* @return ShiroFilterFactoryBean
|
||||
*/
|
||||
@Bean(name = "shiroFilter")
|
||||
public ShiroFilterFactoryBean doShiroFactoryFilterBean(DefaultWebSecurityManager defaultWebSecurityManager) {
|
||||
// 设置安全管理器
|
||||
ShiroFilterFactoryBean bean = new ShiroFilterFactoryBean();
|
||||
bean.setSecurityManager(defaultWebSecurityManager);
|
||||
|
||||
/*
|
||||
* 设置内置过滤器
|
||||
* anon: 无需认证就可以访问
|
||||
* authc: 必须认证了才能访问
|
||||
* perms: 拥有某个资源权限才能访问
|
||||
* role: 拥有某个角色权限才能访问
|
||||
*/
|
||||
// Map<String, String> filterMap = new LinkedHashMap<>();
|
||||
// filterMap.put("/user/add", "authc");
|
||||
// filterMap.put("/user/update", "authc");
|
||||
// bean.setFilterChainDefinitionMap(filterMap);
|
||||
// 设置内置过滤器
|
||||
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
|
||||
filterChainDefinitionMap .put("/user/add", "authc");
|
||||
filterChainDefinitionMap .put("/user/update", "authc");
|
||||
bean.setFilterChainDefinitionMap(filterChainDefinitionMap );
|
||||
|
||||
// 未登录
|
||||
// bean.setLoginUrl("/toLogin");
|
||||
|
||||
// 未授权
|
||||
// bean.setUnauthorizedUrl("/auth");
|
||||
// 设置自定过滤器
|
||||
LinkedHashMap<String, Filter> filterMap = new LinkedHashMap<>();
|
||||
filterMap.put("jwt", jwtFilter());
|
||||
bean.setFilters(filterMap);
|
||||
|
||||
// 返回构建配置
|
||||
return bean;
|
||||
}
|
||||
|
||||
// 安全管理器
|
||||
/**
|
||||
* SpringShiroFilter首先注册到spring容器
|
||||
* 然后被包装成FilterRegistrationBean
|
||||
* 最后通过FilterRegistrationBean注册到servlet容器
|
||||
*
|
||||
* @return FilterRegistrationBean
|
||||
*/
|
||||
@Bean
|
||||
public DefaultWebSecurityManager getDefaultWebSecurityManager(RealmConfig realmConfig) {
|
||||
DefaultWebSecurityManager defaultWebSecurityManager = new DefaultWebSecurityManager();
|
||||
defaultWebSecurityManager.setRealm(realmConfig);
|
||||
return defaultWebSecurityManager;
|
||||
public FilterRegistrationBean<DelegatingFilterProxy> delegatingFilterProxy(){
|
||||
FilterRegistrationBean<DelegatingFilterProxy> filterRegistrationBean = new FilterRegistrationBean<>();
|
||||
DelegatingFilterProxy proxy = new DelegatingFilterProxy();
|
||||
proxy.setTargetFilterLifecycle(true);
|
||||
proxy.setTargetBeanName("shiroFilter");
|
||||
filterRegistrationBean.setFilter(proxy);
|
||||
return filterRegistrationBean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置加密次数
|
||||
*
|
||||
* @return HashedCredentialsMatcher
|
||||
*/
|
||||
@Bean(name = "hashedCredentialsMatcher")
|
||||
public HashedCredentialsMatcher hashedCredentialsMatcher() {
|
||||
HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher();
|
||||
hashedCredentialsMatcher.setHashAlgorithmName("MD5");
|
||||
hashedCredentialsMatcher.setHashIterations(1024);// 设置加密次数
|
||||
return hashedCredentialsMatcher;
|
||||
}
|
||||
|
||||
|
||||
// 自定realm
|
||||
@Bean
|
||||
public RealmConfig userRealm() {
|
||||
return new RealmConfig();
|
||||
public ShiroRealm userRealm() {
|
||||
return new ShiroRealm();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JwtFilter jwtFilter() {
|
||||
return new JwtFilter();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,89 @@
|
|||
package com.hxkj.admin.config;
|
||||
|
||||
import com.hxkj.admin.service.ISysAdminService;
|
||||
import com.hxkj.common.entity.system.SysAdmin;
|
||||
import org.apache.catalina.User;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authc.*;
|
||||
import org.apache.shiro.authz.AuthorizationInfo;
|
||||
import org.apache.shiro.authz.SimpleAuthorizationInfo;
|
||||
import org.apache.shiro.realm.AuthorizingRealm;
|
||||
import org.apache.shiro.subject.PrincipalCollection;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ShiroRealm extends AuthorizingRealm {
|
||||
|
||||
@Resource
|
||||
ISysAdminService iSysAdminService;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean supports(AuthenticationToken token) {
|
||||
return token instanceof JwtToken;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 授权: 根据认证数据验证用户权限
|
||||
*
|
||||
* @param principals 包含了所有已认证的安全数据
|
||||
* @return AuthorizationInfo 授权数据
|
||||
*/
|
||||
@Override
|
||||
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
|
||||
// 1、获取用户安全数据
|
||||
Integer adminId = (Integer) principals.getPrimaryPrincipal();
|
||||
|
||||
// 2、根据用户ID查询用户
|
||||
|
||||
// 3、查询用户角色权限
|
||||
List<String> perms = new ArrayList<>();
|
||||
perms.add("user:add");
|
||||
perms.add("user:update");
|
||||
|
||||
List<String> roles = new ArrayList<>();
|
||||
roles.add("role1");
|
||||
roles.add("role2");
|
||||
|
||||
// 4、构造返回
|
||||
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
|
||||
info.addStringPermissions(perms);
|
||||
info.addRoles(roles);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 认证: 校验用户名和密码是否一致
|
||||
*
|
||||
* @param auth 令牌
|
||||
* @return AuthenticationInfo
|
||||
*/
|
||||
@Override
|
||||
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken auth) {
|
||||
|
||||
System.out.println("靠靠靠靠靠靠靠");
|
||||
String token = (String) auth.getCredentials();
|
||||
|
||||
// 登录参数
|
||||
// UsernamePasswordToken upToken = (UsernamePasswordToken) token;
|
||||
// String username = upToken.getUsername();
|
||||
// String password = new String(upToken.getPassword());
|
||||
//
|
||||
// // 验证用户
|
||||
// SysAdmin sysAdmin = iSysAdminService.findByUsername(username);
|
||||
// if (sysAdmin == null) {
|
||||
// return null;
|
||||
// } else if (!password.equals(sysAdmin.getPassword())) {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// 登录成功
|
||||
return new SimpleAuthenticationInfo(1, "13", "shiroRealm");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -3,10 +3,10 @@ package com.hxkj.admin.controller.system;
|
|||
import com.hxkj.admin.service.ISysAdminService;
|
||||
import com.hxkj.admin.validate.PageParam;
|
||||
import com.hxkj.admin.validate.SysAdminParam;
|
||||
import com.hxkj.admin.vo.system.SysAdminDetailVo;
|
||||
import com.hxkj.admin.vo.system.SysAdminListVo;
|
||||
import com.hxkj.common.core.AjaxResult;
|
||||
import com.hxkj.common.core.PageResult;
|
||||
import com.hxkj.common.entity.system.SysAdmin;
|
||||
import com.hxkj.common.validator.annotation.IDMust;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
|
@ -42,8 +42,8 @@ public class SysAdminController {
|
|||
*/
|
||||
@GetMapping("/detail")
|
||||
public Object detail(@Validated @IDMust() @RequestParam("id") Integer id) {
|
||||
SysAdmin sysAdmin = iSysAdminService.detail(id);
|
||||
return AjaxResult.success(sysAdmin);
|
||||
SysAdminDetailVo vo = iSysAdminService.detail(id);
|
||||
return AjaxResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
package com.hxkj.admin.controller.system;
|
||||
|
||||
import com.hxkj.admin.validate.SysLoginParam;
|
||||
import com.hxkj.common.core.AjaxResult;
|
||||
import com.hxkj.common.utils.JwtUtil;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
import org.apache.shiro.authc.IncorrectCredentialsException;
|
||||
import org.apache.shiro.authc.UnknownAccountException;
|
||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/system")
|
||||
public class SysLoginController {
|
||||
|
||||
/**
|
||||
* 登录系统
|
||||
*
|
||||
* @author fzr
|
||||
* @param sysLoginParam 登录参数
|
||||
* @return Object
|
||||
*/
|
||||
@PostMapping("/login")
|
||||
public Object login(@Validated() @RequestBody SysLoginParam sysLoginParam) {
|
||||
|
||||
|
||||
String username = sysLoginParam.getUsername();
|
||||
String password = sysLoginParam.getPassword();
|
||||
UsernamePasswordToken token = new UsernamePasswordToken(username, password);
|
||||
System.out.println("斤斤计较");
|
||||
Subject subject = SecurityUtils.getSubject();
|
||||
try {
|
||||
subject.login(token);
|
||||
return AjaxResult.success();
|
||||
} catch (AuthenticationException e) {
|
||||
String msg = "用户或密码错误";
|
||||
if (!e.getMessage().equals("")) {
|
||||
msg = e.getMessage();
|
||||
}
|
||||
return AjaxResult.failed(msg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,11 +2,11 @@ package com.hxkj.admin.controller.system;
|
|||
|
||||
import com.hxkj.admin.service.ISysRoleService;
|
||||
import com.hxkj.admin.validate.PageParam;
|
||||
import com.hxkj.admin.validate.SysAdminParam;
|
||||
import com.hxkj.admin.validate.SysRoleParam;
|
||||
import com.hxkj.admin.vo.system.SysRoleListVo;
|
||||
import com.hxkj.common.core.AjaxResult;
|
||||
import com.hxkj.common.core.PageResult;
|
||||
import com.hxkj.common.validator.annotation.IDMust;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
|
@ -19,32 +19,66 @@ public class SysRoleController {
|
|||
@Resource
|
||||
ISysRoleService iSysRoleService;
|
||||
|
||||
/**
|
||||
* 角色列表
|
||||
*
|
||||
* @author fzr
|
||||
* @param pageParam 分页参数
|
||||
* @return Object
|
||||
*/
|
||||
@GetMapping("/lists")
|
||||
public Object lists(@Validated PageParam pageParam) {
|
||||
PageResult<SysRoleListVo> lists = iSysRoleService.lists(pageParam);
|
||||
return AjaxResult.success(lists);
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色详情
|
||||
*
|
||||
* @author fzr
|
||||
* @return Object
|
||||
*/
|
||||
@GetMapping("/detail")
|
||||
public Object detail() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增角色
|
||||
*
|
||||
* @author fzr
|
||||
* @param sysRoleParam 角色参数
|
||||
* @return Object
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public Object add(@Validated(value = SysRoleParam.create.class) @RequestBody SysRoleParam sysRoleParam) {
|
||||
iSysRoleService.add(sysRoleParam);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑角色
|
||||
*
|
||||
* @author fzr
|
||||
* @param sysRoleParam 角色参数
|
||||
* @return Object
|
||||
*/
|
||||
@PostMapping("/edit")
|
||||
public Object edit(@Validated(value = SysRoleParam.create.class) @RequestBody SysRoleParam sysRoleParam) {
|
||||
iSysRoleService.edit(sysRoleParam);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除角色
|
||||
*
|
||||
* @author fzr
|
||||
* @param id 角色ID
|
||||
* @return Object
|
||||
*/
|
||||
@PostMapping("/del")
|
||||
public Object del(@Validated(value = SysRoleParam.create.class) @RequestBody SysRoleParam sysRoleParam) {
|
||||
iSysRoleService.del(sysRoleParam.getId());
|
||||
public Object del(@Validated @IDMust() @RequestBody Integer id) {
|
||||
iSysRoleService.del(id);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package com.hxkj.admin.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.hxkj.admin.validate.PageParam;
|
||||
import com.hxkj.admin.validate.SysAdminParam;
|
||||
import com.hxkj.admin.vo.system.SysAdminDetailVo;
|
||||
import com.hxkj.admin.vo.system.SysAdminListVo;
|
||||
import com.hxkj.common.core.BaseService;
|
||||
import com.hxkj.common.basics.BaseService;
|
||||
import com.hxkj.common.core.PageResult;
|
||||
import com.hxkj.common.entity.system.SysAdmin;
|
||||
|
||||
|
|
@ -13,7 +13,16 @@ import java.util.Map;
|
|||
public interface ISysAdminService extends BaseService<SysAdmin> {
|
||||
|
||||
/**
|
||||
* 获取管理员列表
|
||||
* 根据账号查找管理员
|
||||
*
|
||||
* @author fzr
|
||||
* @param username 主键ID
|
||||
* @return SysAdmin
|
||||
*/
|
||||
SysAdmin findByUsername(String username);
|
||||
|
||||
/**
|
||||
* 管理员列表
|
||||
*
|
||||
* @author fzr
|
||||
* @param pageParam 分页参数
|
||||
|
|
@ -22,13 +31,13 @@ public interface ISysAdminService extends BaseService<SysAdmin> {
|
|||
PageResult<SysAdminListVo> lists(PageParam pageParam, Map<String, String> params);
|
||||
|
||||
/**
|
||||
* 获取管理员详情
|
||||
* 管理员详情
|
||||
*
|
||||
* @author fzr
|
||||
* @param id 主键参数
|
||||
* @return SysAdmin
|
||||
*/
|
||||
SysAdmin detail(Integer id);
|
||||
SysAdminDetailVo detail(Integer id);
|
||||
|
||||
/**
|
||||
* 新增管理员
|
||||
|
|
|
|||
|
|
@ -1,20 +1,50 @@
|
|||
package com.hxkj.admin.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.hxkj.admin.validate.SysMenuParam;
|
||||
import com.hxkj.common.basics.BaseService;
|
||||
import com.hxkj.common.entity.system.SysMenu;
|
||||
|
||||
public interface ISysMenuService extends IService<SysMenu> {
|
||||
public interface ISysMenuService extends BaseService<SysMenu> {
|
||||
|
||||
/**
|
||||
* 菜单列表
|
||||
*
|
||||
* @return JSONArray
|
||||
*/
|
||||
JSONArray lists();
|
||||
|
||||
/**
|
||||
* 菜单详情
|
||||
*
|
||||
* @author fzr
|
||||
* @param id 主键
|
||||
* @return SysMenu
|
||||
*/
|
||||
SysMenu detail(Integer id);
|
||||
|
||||
/**
|
||||
* 新增菜单
|
||||
*
|
||||
* @author fzr
|
||||
* @param sysMenuParam 参数
|
||||
*/
|
||||
void add(SysMenuParam sysMenuParam);
|
||||
|
||||
/**
|
||||
* 编辑菜单
|
||||
*
|
||||
* @author fzr
|
||||
* @param sysMenuParam 参数
|
||||
*/
|
||||
void edit(SysMenuParam sysMenuParam);
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
*
|
||||
* @author fzr
|
||||
* @param id 主键
|
||||
*/
|
||||
void del(Integer id);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
package com.hxkj.admin.service;
|
||||
|
||||
import com.hxkj.common.basics.BaseService;
|
||||
import com.hxkj.common.entity.system.SysRoleMenu;
|
||||
|
||||
public interface ISysRoleMenuService extends BaseService<SysRoleMenu> {
|
||||
|
||||
/**
|
||||
* 批量写入角色菜单
|
||||
*
|
||||
* @author fzr
|
||||
* @param roleId 角色ID
|
||||
* @param ids 菜单ID组
|
||||
*/
|
||||
void batchSaveByMenuIds(Integer roleId, String ids);
|
||||
|
||||
|
||||
/**
|
||||
* 根据ID批量删除角色菜单
|
||||
*
|
||||
* @author fzr
|
||||
* @param roleId 角色ID
|
||||
*/
|
||||
void batchDeleteByRoleId(Integer roleId);
|
||||
|
||||
}
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
package com.hxkj.admin.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.hxkj.admin.validate.PageParam;
|
||||
import com.hxkj.admin.validate.SysRoleParam;
|
||||
import com.hxkj.admin.vo.system.SysRoleListVo;
|
||||
import com.hxkj.common.basics.BaseService;
|
||||
import com.hxkj.common.core.PageResult;
|
||||
import com.hxkj.common.entity.system.SysRole;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
public interface ISysRoleService extends IService<SysRole> {
|
||||
public interface ISysRoleService extends BaseService<SysRole> {
|
||||
|
||||
/**
|
||||
* 根据id获取角色名称
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import com.hxkj.admin.service.ISysAdminService;
|
|||
import com.hxkj.admin.service.ISysRoleService;
|
||||
import com.hxkj.admin.validate.PageParam;
|
||||
import com.hxkj.admin.validate.SysAdminParam;
|
||||
import com.hxkj.admin.vo.system.SysAdminDetailVo;
|
||||
import com.hxkj.admin.vo.system.SysAdminListVo;
|
||||
import com.hxkj.common.core.PageResult;
|
||||
import com.hxkj.common.entity.system.SysAdmin;
|
||||
|
|
@ -28,6 +29,20 @@ public class ISysAdminServiceImpl extends MPJBaseServiceImpl<SysAdminMapper, Sys
|
|||
@Resource
|
||||
ISysRoleService iSysRoleService;
|
||||
|
||||
/**
|
||||
* 根据账号查找管理员
|
||||
*
|
||||
* @author fzr
|
||||
* @param username 主键ID
|
||||
* @return SysAdmin
|
||||
*/
|
||||
@Override
|
||||
public SysAdmin findByUsername(String username) {
|
||||
return this.getOne(new QueryWrapper<SysAdmin>()
|
||||
.eq("username", username)
|
||||
.last("limit 1"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取管理员列表
|
||||
*
|
||||
|
|
@ -50,11 +65,11 @@ public class ISysAdminServiceImpl extends MPJBaseServiceImpl<SysAdminMapper, Sys
|
|||
.orderByDesc("sort");
|
||||
|
||||
this.setSearch(queryWrapper, params, new String[]{
|
||||
"eq:username"
|
||||
"like:username:str",
|
||||
"like:nickname:str",
|
||||
"=:role:int"
|
||||
});
|
||||
|
||||
// String[] a = {"str:username:=", ""};
|
||||
|
||||
IPage<SysAdmin> iPage = this.page(new Page<>(page, limit), queryWrapper);
|
||||
|
||||
List<SysAdminListVo> adminVoArrayList = new ArrayList<>();
|
||||
|
|
@ -80,7 +95,7 @@ public class ISysAdminServiceImpl extends MPJBaseServiceImpl<SysAdminMapper, Sys
|
|||
* @return SysAdmin
|
||||
*/
|
||||
@Override
|
||||
public SysAdmin detail(Integer id) {
|
||||
public SysAdminDetailVo detail(Integer id) {
|
||||
SysAdmin sysAdmin = this.getOne(new QueryWrapper<SysAdmin>()
|
||||
.select(SysAdmin.class, info->
|
||||
!info.getColumn().equals("salt") &&
|
||||
|
|
@ -93,7 +108,12 @@ public class ISysAdminServiceImpl extends MPJBaseServiceImpl<SysAdminMapper, Sys
|
|||
|
||||
Assert.notNull(sysAdmin, "账号已不存在!");
|
||||
|
||||
return sysAdmin;
|
||||
SysAdminDetailVo vo = new SysAdminDetailVo();
|
||||
BeanUtils.copyProperties(sysAdmin, vo);
|
||||
|
||||
vo.setAvatar(UrlUtil.toAbsoluteUrl(sysAdmin.getAvatar()));
|
||||
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ public class ISysMenuServiceImpl extends MPJBaseServiceImpl<SysMenuMapper, SysMe
|
|||
!info.getColumn().equals("salt") &&
|
||||
!info.getColumn().equals("is_delete") &&
|
||||
!info.getColumn().equals("delete_time"))
|
||||
.eq("is_delete", 0)
|
||||
.orderByDesc(Arrays.asList("menu_sort", "id"));
|
||||
|
||||
List<SysMenu> sysMenus = this.list( queryWrapper);
|
||||
|
|
@ -56,17 +55,14 @@ public class ISysMenuServiceImpl extends MPJBaseServiceImpl<SysMenuMapper, SysMe
|
|||
/**
|
||||
* 菜单详情
|
||||
*
|
||||
* @author fzr
|
||||
* @param id 主键参数
|
||||
* @return SysMenu
|
||||
*/
|
||||
@Override
|
||||
public SysMenu detail(Integer id) {
|
||||
SysMenu model = this.getOne(new QueryWrapper<SysMenu>()
|
||||
.eq("id", id)
|
||||
.eq("is_delete", 0));
|
||||
|
||||
SysMenu model = this.getOne(new QueryWrapper<SysMenu>().eq("id", id));
|
||||
Assert.notNull(model, "菜单已不存在!");
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
|
|
@ -99,10 +95,7 @@ public class ISysMenuServiceImpl extends MPJBaseServiceImpl<SysMenuMapper, SysMe
|
|||
*/
|
||||
@Override
|
||||
public void edit(SysMenuParam sysMenuParam) {
|
||||
SysMenu model = this.getOne(new QueryWrapper<SysMenu>()
|
||||
.eq("id", sysMenuParam.getId())
|
||||
.eq("is_delete", 0));
|
||||
|
||||
SysMenu model = this.getOne(new QueryWrapper<SysMenu>().eq("id", sysMenuParam.getId()));
|
||||
Assert.notNull(model, "菜单已不存在!");
|
||||
|
||||
model.setMenuType(sysMenuParam.getMenuType());
|
||||
|
|
@ -124,16 +117,9 @@ public class ISysMenuServiceImpl extends MPJBaseServiceImpl<SysMenuMapper, SysMe
|
|||
*/
|
||||
@Override
|
||||
public void del(Integer id) {
|
||||
SysMenu model = this.getOne(new QueryWrapper<SysMenu>()
|
||||
.eq("id", id)
|
||||
.eq("is_delete", 0));
|
||||
|
||||
SysMenu model = this.getOne(new QueryWrapper<SysMenu>().eq("id", id));
|
||||
Assert.notNull(model, "菜单已不存在!");
|
||||
|
||||
model.setId(id);
|
||||
model.setIsDelete(1);
|
||||
model.setDeleteTime(System.currentTimeMillis() / 1000);
|
||||
this.updateById(model);
|
||||
this.removeById(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
package com.hxkj.admin.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.github.yulichang.base.MPJBaseServiceImpl;
|
||||
import com.hxkj.admin.service.ISysRoleMenuService;
|
||||
import com.hxkj.common.entity.system.SysRoleMenu;
|
||||
import com.hxkj.common.mapper.system.SysRoleMenuMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ISysRoleMenuServiceImpl extends MPJBaseServiceImpl<SysRoleMenuMapper, SysRoleMenu> implements ISysRoleMenuService {
|
||||
|
||||
/**
|
||||
* 批量写入角色菜单
|
||||
*
|
||||
* @author fzr
|
||||
* @param roleId 角色ID
|
||||
* @param ids 菜单ID组
|
||||
*/
|
||||
@Override
|
||||
public void batchSaveByMenuIds(Integer roleId, String ids) {
|
||||
if (ids != null && !ids.equals("")) {
|
||||
List<SysRoleMenu> arrayList = new ArrayList<>();
|
||||
for (String menuId : ids.split(",")) {
|
||||
SysRoleMenu model = new SysRoleMenu();
|
||||
model.setRoleId(roleId);
|
||||
model.setMenuId(Integer.parseInt(menuId));
|
||||
arrayList.add(model);
|
||||
}
|
||||
|
||||
this.saveBatch(arrayList);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除角色菜单
|
||||
*
|
||||
* @author fzr
|
||||
* @param roleId 角色ID
|
||||
*/
|
||||
@Override
|
||||
public void batchDeleteByRoleId(Integer roleId) {
|
||||
this.remove(new QueryWrapper<SysRoleMenu>().eq("role_id", roleId));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -5,18 +5,23 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.yulichang.base.MPJBaseServiceImpl;
|
||||
import com.hxkj.admin.service.ISysMenuService;
|
||||
import com.hxkj.admin.service.ISysRoleMenuService;
|
||||
import com.hxkj.admin.service.ISysRoleService;
|
||||
import com.hxkj.admin.validate.PageParam;
|
||||
import com.hxkj.admin.validate.SysRoleParam;
|
||||
import com.hxkj.admin.vo.system.SysRoleListVo;
|
||||
import com.hxkj.common.core.PageResult;
|
||||
import com.hxkj.common.entity.system.SysRole;
|
||||
import com.hxkj.common.mapper.system.SysMenuMapper;
|
||||
import com.hxkj.common.mapper.system.SysRoleMapper;
|
||||
import com.hxkj.common.utils.TimeUtil;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
|
@ -24,6 +29,10 @@ import java.util.List;
|
|||
@Service
|
||||
public class ISysRoleServiceImpl extends MPJBaseServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {
|
||||
|
||||
@Resource
|
||||
ISysRoleMenuService iSysRoleMenuService;
|
||||
|
||||
|
||||
/**
|
||||
* 根据ID获取角色名称
|
||||
*
|
||||
|
|
@ -34,10 +43,9 @@ public class ISysRoleServiceImpl extends MPJBaseServiceImpl<SysRoleMapper, SysRo
|
|||
@Override
|
||||
public String getRoleNameById(Integer id) {
|
||||
QueryWrapper<SysRole> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.select("id", "name");
|
||||
queryWrapper.eq("id", id);
|
||||
queryWrapper.eq("is_delete", 0);
|
||||
queryWrapper.last("limit 1");
|
||||
queryWrapper.select("id", "name")
|
||||
.eq("id", id)
|
||||
.last("limit 1");
|
||||
|
||||
SysRole sysRole = this.getOne(queryWrapper, false);
|
||||
if (sysRole == null) {
|
||||
|
|
@ -62,7 +70,6 @@ public class ISysRoleServiceImpl extends MPJBaseServiceImpl<SysRoleMapper, SysRo
|
|||
queryWrapper.select(SysRole.class, info->
|
||||
!info.getColumn().equals("is_delete") &&
|
||||
!info.getColumn().equals("delete_time"))
|
||||
.eq("is_delete", 0)
|
||||
.orderByDesc(Arrays.asList("sort", "id"));
|
||||
|
||||
IPage<SysRole> iPage = this.page(new Page<>(page, limit), queryWrapper);
|
||||
|
|
@ -91,7 +98,6 @@ public class ISysRoleServiceImpl extends MPJBaseServiceImpl<SysRoleMapper, SysRo
|
|||
public SysRole detail(Integer id) {
|
||||
SysRole sysRole = this.getOne(new QueryWrapper<SysRole>()
|
||||
.eq("id", id)
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
|
||||
Assert.notNull(sysRole, "角色已不存在!");
|
||||
|
|
@ -106,21 +112,22 @@ public class ISysRoleServiceImpl extends MPJBaseServiceImpl<SysRoleMapper, SysRo
|
|||
* @param sysRoleParam 参数
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void add(SysRoleParam sysRoleParam) {
|
||||
Assert.isNull(this.getOne(new QueryWrapper<SysRole>()
|
||||
.select("id,name")
|
||||
.eq("name", sysRoleParam.getName().trim())
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1")), "角色名称已存在!");
|
||||
|
||||
SysRole model = new SysRole();
|
||||
model.setName(sysRoleParam.getName().trim());
|
||||
model.setRemark(sysRoleParam.getRemark());
|
||||
model.setMenuIds(sysRoleParam.getMenuIds());
|
||||
model.setIsDisable(sysRoleParam.getIsDisable());
|
||||
model.setCreateTime(System.currentTimeMillis() / 1000);
|
||||
model.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
this.save(model);
|
||||
|
||||
iSysRoleMenuService.batchSaveByMenuIds(sysRoleParam.getId(), sysRoleParam.getMenuIds());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -130,28 +137,29 @@ public class ISysRoleServiceImpl extends MPJBaseServiceImpl<SysRoleMapper, SysRo
|
|||
* @param sysRoleParam 参数
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void edit(SysRoleParam sysRoleParam) {
|
||||
Assert.notNull(this.getOne(new QueryWrapper<SysRole>()
|
||||
.select("id,name")
|
||||
.eq("id", sysRoleParam.getId())
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1")), "角色已不存在!");
|
||||
|
||||
Assert.isNull(this.getOne(new QueryWrapper<SysRole>()
|
||||
.select("id,name")
|
||||
.ne("id", sysRoleParam.getId())
|
||||
.eq("name", sysRoleParam.getName().trim())
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1")), "角色名称已存在!");
|
||||
|
||||
SysRole model = new SysRole();
|
||||
model.setId(sysRoleParam.getId());
|
||||
model.setName(sysRoleParam.getName().trim());
|
||||
model.setRemark(sysRoleParam.getRemark());
|
||||
model.setMenuIds(sysRoleParam.getMenuIds());
|
||||
model.setIsDisable(sysRoleParam.getIsDisable());
|
||||
model.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
this.updateById(model);
|
||||
|
||||
iSysRoleMenuService.batchDeleteByRoleId(sysRoleParam.getId());
|
||||
iSysRoleMenuService.batchSaveByMenuIds(sysRoleParam.getId(), sysRoleParam.getMenuIds());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -161,19 +169,17 @@ public class ISysRoleServiceImpl extends MPJBaseServiceImpl<SysRoleMapper, SysRo
|
|||
* @param id 主键参数
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void del(Integer id) {
|
||||
SysRole sysRole = this.getOne(new QueryWrapper<SysRole>()
|
||||
.select("id,name")
|
||||
.eq("id", id)
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
Assert.notNull(
|
||||
this.getOne(new QueryWrapper<SysRole>()
|
||||
.select("id,name")
|
||||
.eq("id", id)
|
||||
.last("limit 1")),
|
||||
"角色已不存在!");
|
||||
|
||||
Assert.notNull(sysRole, "角色已不存在!");
|
||||
|
||||
sysRole.setId(id);
|
||||
sysRole.setIsDelete(1);
|
||||
sysRole.setDeleteTime(System.currentTimeMillis() / 1000);
|
||||
this.updateById(sysRole);
|
||||
this.removeById(id);
|
||||
iSysRoleMenuService.batchDeleteByRoleId(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
package com.hxkj.admin.validate;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 系统登录参数
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class SysLoginParam implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotEmpty(message = "账号不能为空")
|
||||
@Length(min = 2, max = 20, message = "账号或密码错误")
|
||||
private String username;
|
||||
|
||||
@NotEmpty(message = "密码不能为空")
|
||||
@Length(min = 6, max = 18, message = "账号或密码错误")
|
||||
private String password;
|
||||
|
||||
}
|
||||
|
|
@ -13,9 +13,8 @@ public class SysRoleParam {
|
|||
|
||||
public interface create{}
|
||||
public interface update{}
|
||||
public interface delete{}
|
||||
|
||||
@IDMust(message = "id参数必传且需大于0", groups = {update.class, delete.class})
|
||||
@IDMust(message = "id参数必传且需大于0", groups = {update.class})
|
||||
private Integer id;
|
||||
|
||||
@NotNull(message = "缺少参数name", groups = {create.class, update.class})
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
package com.hxkj.admin.vo.system;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class SysAdminDetailVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Integer id;
|
||||
private String username;
|
||||
private String nickname;
|
||||
private String avatar;
|
||||
private Integer role;
|
||||
private Integer isDisable;
|
||||
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@ package com.hxkj.admin.vo.system;
|
|||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class SysAdminListVo implements Serializable {
|
||||
|
|
@ -15,7 +14,7 @@ public class SysAdminListVo implements Serializable {
|
|||
private String nickname;
|
||||
private String avatar;
|
||||
private String role;
|
||||
private Boolean isDisable;
|
||||
private Integer isDisable;
|
||||
private String lastLoginIp;
|
||||
private String lastLoginTime;
|
||||
private String createTime;
|
||||
|
|
|
|||
|
|
@ -62,11 +62,16 @@
|
|||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<!-- fastjson -->
|
||||
<!-- Fastjson -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
<!-- JWT -->
|
||||
<dependency>
|
||||
<groupId>com.auth0</groupId>
|
||||
<artifactId>java-jwt</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.hxkj.common.basics;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
|
||||
/**
|
||||
* 基类Mapper
|
||||
* @param <T>
|
||||
*/
|
||||
@Mapper
|
||||
public interface BaseMapper<T> extends MPJBaseMapper<T> {
|
||||
}
|
||||
|
|
@ -0,0 +1,152 @@
|
|||
package com.hxkj.common.basics;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.hxkj.common.core.PageResult;
|
||||
import com.hxkj.common.entity.system.SysAdmin;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 基础服务接口类
|
||||
*/
|
||||
public interface BaseService<T> extends IService<T> {
|
||||
|
||||
/**
|
||||
* 设置搜索条件
|
||||
*
|
||||
* @author fzr
|
||||
* @param queryWrapper 条件构造器
|
||||
* @param params 参数[条件:键@数据库字段:类型]
|
||||
* @param conditions 条件
|
||||
*/
|
||||
default void setSearch(QueryWrapper<T> queryWrapper, Map<String, String> params, String[] conditions) {
|
||||
|
||||
for (String condition : conditions) {
|
||||
String[] array = condition.split(":");
|
||||
String type = array.length > 2 ? array[2].trim() : "";
|
||||
String where = array[0].trim();
|
||||
String[] keyArr = array[1].trim().split("@");
|
||||
String key = keyArr[0].trim();
|
||||
String field = keyArr.length > 1 ? keyArr[1].trim() : keyArr[0].trim();
|
||||
String value = params.getOrDefault(key, "");
|
||||
|
||||
if (value.equals("")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((!type.equals("") && !Arrays.asList("int", "long", "str").contains(type))) {
|
||||
System.out.println("搜索参数类型不在固定值内[int,long,str]");
|
||||
continue;
|
||||
}
|
||||
|
||||
Object val = value;
|
||||
switch (where) {
|
||||
case "=":
|
||||
case "<>":
|
||||
case ">":
|
||||
case ">=":
|
||||
case "<":
|
||||
case "<=":
|
||||
if (type.equals("int")) {
|
||||
val = Integer.parseInt(value);
|
||||
} else if (type.equals("long")) {
|
||||
val = Long.parseLong(value);
|
||||
}
|
||||
case "in":
|
||||
case "notIn":
|
||||
if (type.equals("int")) {
|
||||
List<Integer> intData = new ArrayList<>();
|
||||
for (String v : value.split(",")) {
|
||||
intData.add(Integer.parseInt(v.trim()));
|
||||
}
|
||||
val = intData;
|
||||
} else if (type.equals("long")){
|
||||
List<Long> longData = new ArrayList<>();
|
||||
for (String v : value.split(",")) {
|
||||
longData.add(Long.parseLong(v.trim()));
|
||||
}
|
||||
val = longData;
|
||||
}
|
||||
}
|
||||
|
||||
switch (where) {
|
||||
case "=":
|
||||
queryWrapper.eq(field, val);
|
||||
break;
|
||||
case "<>":
|
||||
queryWrapper.ne(field, val);
|
||||
break;
|
||||
case ">":
|
||||
queryWrapper.gt(field, val);
|
||||
break;
|
||||
case ">=":
|
||||
queryWrapper.ge(field, val);
|
||||
break;
|
||||
case "<":
|
||||
queryWrapper.lt(field, val);
|
||||
break;
|
||||
case "<=":
|
||||
queryWrapper.le(field, val);
|
||||
break;
|
||||
case "between":
|
||||
String[] betArr = value.split(",");
|
||||
if (type.equals("int")) {
|
||||
queryWrapper.between(field, Integer.parseInt(betArr[0]), Integer.parseInt(betArr[1]));
|
||||
} else if (type.equals("long")){
|
||||
queryWrapper.between(field, Long.parseLong(betArr[0]), Long.parseLong(betArr[1]));
|
||||
} else {
|
||||
queryWrapper.between(field, betArr[0], betArr[1]);
|
||||
}
|
||||
break;
|
||||
case "notBetween":
|
||||
String[] notBetArr = value.split(",");
|
||||
if (type.equals("int")) {
|
||||
queryWrapper.notBetween(field, Integer.parseInt(notBetArr[0]), Integer.parseInt(notBetArr[1]));
|
||||
} else if (type.equals("long")){
|
||||
queryWrapper.notBetween(field, Long.parseLong(notBetArr[0]), Long.parseLong(notBetArr[1]));
|
||||
} else {
|
||||
queryWrapper.notBetween(field, notBetArr[0], notBetArr[1]);
|
||||
}
|
||||
break;
|
||||
case "like":
|
||||
queryWrapper.like(field, val);
|
||||
break;
|
||||
case "notLike":
|
||||
queryWrapper.notLike(field, val);
|
||||
break;
|
||||
case "likeLeft":
|
||||
queryWrapper.likeLeft(field, val);
|
||||
break;
|
||||
case "likeRight":
|
||||
queryWrapper.likeRight(field, val);
|
||||
break;
|
||||
case "in":
|
||||
queryWrapper.in(field, val);
|
||||
break;
|
||||
case "notIn":
|
||||
queryWrapper.notIn(field, val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 求和聚合
|
||||
*
|
||||
* @param field 字段名
|
||||
* @param queryWrapper 条件构造器
|
||||
* @return Long
|
||||
*/
|
||||
default BigDecimal sum(String field, QueryWrapper<T> queryWrapper) {
|
||||
queryWrapper.select("IFNULL(sum("+field+"), 0) as totalValue");
|
||||
Map<String, Object> map = this.getMap(queryWrapper);
|
||||
return (BigDecimal) map.get("totalValue");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,105 +0,0 @@
|
|||
package com.hxkj.common.core;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface BaseService<T> extends IService<T> {
|
||||
|
||||
default void setSearch(QueryWrapper<T> queryWrapper, Map<String, String> params, String[] conditions) {
|
||||
|
||||
for (String condition : conditions) {
|
||||
String[] array = condition.split(":");
|
||||
String type = array[0].trim();
|
||||
String where = array[2].trim();
|
||||
String[] arr = array[1].trim().split("@");
|
||||
String key = arr[0].trim();
|
||||
String field = arr.length > 1 ? arr[1].trim() : arr[0].trim();
|
||||
String value = params.getOrDefault(key, "");
|
||||
|
||||
if (value.equals("")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Object val = value;
|
||||
switch (type) {
|
||||
case "int":
|
||||
val = Integer.parseInt(value);
|
||||
break;
|
||||
case "long":
|
||||
val = Long.parseLong(value);
|
||||
break;
|
||||
case "strList":
|
||||
val = Arrays.asList(value.split(","));
|
||||
break;
|
||||
case "intList":
|
||||
List<Integer> intData = new ArrayList<>();
|
||||
for (String v : value.split(",")) {
|
||||
intData.add(Integer.parseInt(v.trim()));
|
||||
}
|
||||
val = intData;
|
||||
break;
|
||||
case "longList":
|
||||
List<Long> longData = new ArrayList<>();
|
||||
for (String v : value.split(",")) {
|
||||
longData.add(Long.parseLong(v.trim()));
|
||||
}
|
||||
val = longData;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (where) {
|
||||
case "=":
|
||||
queryWrapper.eq(field, val);
|
||||
break;
|
||||
case "<>":
|
||||
queryWrapper.ne(field, val);
|
||||
break;
|
||||
case ">":
|
||||
queryWrapper.gt(field, val);
|
||||
break;
|
||||
case ">=":
|
||||
queryWrapper.ge(field, val);
|
||||
break;
|
||||
case "<":
|
||||
queryWrapper.lt(field, val);
|
||||
break;
|
||||
case "<=":
|
||||
queryWrapper.le(field, val);
|
||||
break;
|
||||
case "between":
|
||||
String[] betArr = value.split(",");
|
||||
queryWrapper.between(field, Integer.parseInt(betArr[0]), Integer.parseInt(betArr[1]));
|
||||
break;
|
||||
case "notBetween":
|
||||
String[] notBetArr = value.split(",");
|
||||
queryWrapper.notBetween(field, Integer.parseInt(notBetArr[0]), Integer.parseInt(notBetArr[1]));
|
||||
break;
|
||||
case "like":
|
||||
queryWrapper.like(field, val);
|
||||
break;
|
||||
case "notLike":
|
||||
queryWrapper.notLike(field, val);
|
||||
break;
|
||||
case "likeLeft":
|
||||
queryWrapper.likeLeft(field, val);
|
||||
break;
|
||||
case "likeRight":
|
||||
queryWrapper.likeRight(field, val);
|
||||
break;
|
||||
case "in":
|
||||
queryWrapper.in(field, val);
|
||||
break;
|
||||
case "notIn":
|
||||
queryWrapper.notIn(field, val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -23,9 +23,7 @@ public class SysMenu implements Serializable {
|
|||
private Integer menuSort;
|
||||
private String perms;
|
||||
private Integer isDisable;
|
||||
private Integer isDelete;
|
||||
private Long createTime;
|
||||
private Long updateTime;
|
||||
private Long deleteTime;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,11 +19,8 @@ public class SysRole implements Serializable {
|
|||
private String name;
|
||||
private String remark;
|
||||
private Integer sort;
|
||||
private String menuIds;
|
||||
private Integer isDisable;
|
||||
private Integer isDelete;
|
||||
private Long createTime;
|
||||
private Long updateTime;
|
||||
private Long deleteTime;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package com.hxkj.common.entity.system;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
|
@ -10,13 +10,16 @@ import java.io.Serializable;
|
|||
* 系统角色菜单实体
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class SysRoleMenu implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value="id", type= IdType.AUTO)
|
||||
private Integer id;
|
||||
// 角色ID
|
||||
private Integer roleId;
|
||||
|
||||
// 菜单ID
|
||||
private Integer menuId;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,12 @@
|
|||
package com.hxkj.common.mapper.system;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.hxkj.common.basics.BaseMapper;
|
||||
import com.hxkj.common.entity.system.SysAdmin;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统管理员
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysAdminMapper extends MPJBaseMapper<SysAdmin> {
|
||||
public interface SysAdminMapper extends BaseMapper<SysAdmin> {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.hxkj.common.mapper.system;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.hxkj.common.basics.BaseMapper;
|
||||
import com.hxkj.common.entity.system.SysMenu;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
|
|
@ -8,5 +8,5 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
* 系统菜单
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysMenuMapper extends MPJBaseMapper<SysMenu> {
|
||||
public interface SysMenuMapper extends BaseMapper<SysMenu> {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.hxkj.common.mapper.system;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.hxkj.common.basics.BaseMapper;
|
||||
import com.hxkj.common.entity.system.SysRole;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
|
|
@ -8,5 +8,5 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
* 系统角色
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysRoleMapper extends MPJBaseMapper<SysRole> {
|
||||
public interface SysRoleMapper extends BaseMapper<SysRole> {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
package com.hxkj.common.mapper.system;
|
||||
|
||||
import com.hxkj.common.basics.BaseMapper;
|
||||
import com.hxkj.common.entity.system.SysRoleMenu;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 角色菜单
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysRoleMenuMapper extends BaseMapper<SysRoleMenu> {
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
package com.hxkj.common.utils;
|
||||
|
||||
import com.auth0.jwt.JWT;
|
||||
import com.auth0.jwt.JWTCreator;
|
||||
import com.auth0.jwt.algorithms.Algorithm;
|
||||
import com.auth0.jwt.interfaces.DecodedJWT;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
public class JwtUtil {
|
||||
|
||||
/**
|
||||
* 过期时间(秒)
|
||||
*/
|
||||
|
||||
private static final Integer expire = 7200;
|
||||
|
||||
/**
|
||||
* 加密密钥
|
||||
*/
|
||||
|
||||
private static final String secret = "EEE";
|
||||
|
||||
/**
|
||||
* 请求头字段名
|
||||
*/
|
||||
|
||||
private static final String header = "token";
|
||||
|
||||
/**
|
||||
* 创建token
|
||||
*
|
||||
* @author fzr
|
||||
* @param map 参数
|
||||
*/
|
||||
public static String createToken(Map<String, String> map) {
|
||||
Calendar instance = Calendar.getInstance();
|
||||
instance.add(Calendar.SECOND, expire);
|
||||
|
||||
JWTCreator.Builder builder = JWT.create();
|
||||
map.forEach(builder::withClaim);
|
||||
return builder.withExpiresAt(instance.getTime())
|
||||
.withIssuedAt(new Date())
|
||||
.sign(Algorithm.HMAC256(secret));
|
||||
}
|
||||
|
||||
/**
|
||||
* token是否过期
|
||||
* @author fzr
|
||||
* @param token token
|
||||
*/
|
||||
public void isTokenExpired(String token) {
|
||||
JWT.require(Algorithm.HMAC256(secret)).build().verify(token);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取token中的payload
|
||||
* @author fzr
|
||||
* @param token token
|
||||
* @return DecodedJWT
|
||||
*/
|
||||
public static DecodedJWT getToken(String token) {
|
||||
return JWT.require(Algorithm.HMAC256(secret)).build().verify(token);
|
||||
}
|
||||
|
||||
}
|
||||
7
pom.xml
7
pom.xml
|
|
@ -29,6 +29,7 @@
|
|||
<shiro-spring.version>1.8.0</shiro-spring.version>
|
||||
<lombok.version>1.18.22</lombok.version>
|
||||
<fastJson.version>1.2.78</fastJson.version>
|
||||
<java-jwt.version>3.18.2</java-jwt.version>
|
||||
</properties>
|
||||
|
||||
<!-- 依赖声明 -->
|
||||
|
|
@ -84,6 +85,12 @@
|
|||
<artifactId>fastjson</artifactId>
|
||||
<version>${fastJson.version}</version>
|
||||
</dependency>
|
||||
<!-- Jwt -->
|
||||
<dependency>
|
||||
<groupId>com.auth0</groupId>
|
||||
<artifactId>java-jwt</artifactId>
|
||||
<version>${java-jwt.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue