├── .gitignore ├── README.md ├── api-admin ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── lmxdawn │ │ │ └── api │ │ │ ├── ApiAdminApplication.java │ │ │ └── admin │ │ │ ├── annotation │ │ │ └── AuthRuleAnnotation.java │ │ │ ├── aspect │ │ │ └── AuthorizeAspect.java │ │ │ ├── config │ │ │ ├── CorsConfig.java │ │ │ ├── CorsFilter.java │ │ │ ├── DruidStatFilter.java │ │ │ ├── DruidStatViewServlet.java │ │ │ ├── PageHelperConfig.java │ │ │ └── PublicFileUrlConfig.java │ │ │ ├── constant │ │ │ ├── CookieConstant.java │ │ │ └── TestConstant.java │ │ │ ├── controller │ │ │ ├── HelloController.java │ │ │ ├── ad │ │ │ │ ├── AdController.java │ │ │ │ └── AdSiteController.java │ │ │ ├── auth │ │ │ │ ├── AuthAdminController.java │ │ │ │ ├── AuthPermissionRuleController.java │ │ │ │ ├── AuthRoleController.java │ │ │ │ └── LoginController.java │ │ │ └── file │ │ │ │ └── UploadController.java │ │ │ ├── converter │ │ │ └── AdSaveForm2AdConverter.java │ │ │ ├── dao │ │ │ ├── ad │ │ │ │ ├── AdDao.java │ │ │ │ └── AdSiteDao.java │ │ │ └── auth │ │ │ │ ├── AuthAdminDao.java │ │ │ │ ├── AuthPermissionDao.java │ │ │ │ ├── AuthPermissionRuleDao.java │ │ │ │ ├── AuthRoleAdminDao.java │ │ │ │ └── AuthRoleDao.java │ │ │ ├── dto │ │ │ └── auth │ │ │ │ └── TestDTO.java │ │ │ ├── entity │ │ │ ├── ad │ │ │ │ ├── Ad.java │ │ │ │ └── AdSite.java │ │ │ └── auth │ │ │ │ ├── AuthAdmin.java │ │ │ │ ├── AuthPermission.java │ │ │ │ ├── AuthPermissionRule.java │ │ │ │ ├── AuthRole.java │ │ │ │ └── AuthRoleAdmin.java │ │ │ ├── exception │ │ │ └── JsonException.java │ │ │ ├── handler │ │ │ └── GlobalExceptionHandler.java │ │ │ ├── req │ │ │ ├── ListPageRequest.java │ │ │ ├── ad │ │ │ │ ├── AdQueryRequest.java │ │ │ │ ├── AdSaveRequest.java │ │ │ │ ├── AdSiteQueryRequest.java │ │ │ │ └── AdSiteSaveRequest.java │ │ │ └── auth │ │ │ │ ├── AuthAdminQueryRequest.java │ │ │ │ ├── AuthAdminSaveRequest.java │ │ │ │ ├── AuthPermissionRuleSaveRequest.java │ │ │ │ ├── AuthRoleAuthRequest.java │ │ │ │ ├── AuthRoleQueryRequest.java │ │ │ │ ├── AuthRoleSaveRequest.java │ │ │ │ ├── LoginRequest.java │ │ │ │ └── UpdatePasswordRequest.java │ │ │ ├── res │ │ │ ├── PageSimpleResponse.java │ │ │ ├── ad │ │ │ │ ├── AdResponse.java │ │ │ │ ├── AdSimpleResponse.java │ │ │ │ └── AdSiteResponse.java │ │ │ └── auth │ │ │ │ ├── AuthAdminResponse.java │ │ │ │ ├── AuthAdminRoleResponse.java │ │ │ │ ├── AuthPermissionRuleMergeResponse.java │ │ │ │ ├── AuthRoleResponse.java │ │ │ │ └── LoginUserInfoResponse.java │ │ │ ├── service │ │ │ ├── ad │ │ │ │ ├── AdService.java │ │ │ │ ├── AdSiteService.java │ │ │ │ └── impl │ │ │ │ │ ├── AdServiceImpl.java │ │ │ │ │ └── AdSiteServiceImpl.java │ │ │ └── auth │ │ │ │ ├── AuthAdminService.java │ │ │ │ ├── AuthLoginService.java │ │ │ │ ├── AuthPermissionRuleService.java │ │ │ │ ├── AuthPermissionService.java │ │ │ │ ├── AuthRoleAdminService.java │ │ │ │ ├── AuthRoleService.java │ │ │ │ └── impl │ │ │ │ ├── AuthAdminServiceImpl.java │ │ │ │ ├── AuthLoginServiceImpl.java │ │ │ │ ├── AuthPermissionRuleServiceImpl.java │ │ │ │ ├── AuthPermissionServiceImpl.java │ │ │ │ ├── AuthRoleAdminServiceImpl.java │ │ │ │ └── AuthRoleServiceImpl.java │ │ │ └── util │ │ │ ├── CacheUtils.java │ │ │ ├── IpUtils.java │ │ │ ├── JwtUtils.java │ │ │ ├── PasswordUtils.java │ │ │ ├── PermissionRuleTreeUtils.java │ │ │ ├── PublicFileUtils.java │ │ │ ├── TreeUtils.java │ │ │ └── serializer │ │ │ └── Date2LongSerializer.java │ └── resources │ │ ├── application-dev.properties │ │ ├── application-pro.properties │ │ ├── application-test.properties │ │ ├── application.properties │ │ ├── mybatis │ │ ├── mapper │ │ │ ├── ad │ │ │ │ ├── AdDao.xml │ │ │ │ └── AdSiteDao.xml │ │ │ └── auth │ │ │ │ ├── AuthAdminDao.xml │ │ │ │ ├── AuthPermissionDao.xml │ │ │ │ ├── AuthPermissionRuleDao.xml │ │ │ │ ├── AuthRoleAdminDao.xml │ │ │ │ └── AuthRoleDao.xml │ │ └── mybatis-config.xml │ │ ├── static │ │ └── .gitignore │ │ └── templates │ │ └── .gitignore │ └── test │ └── java │ └── com │ └── lmxdawn │ └── api │ ├── BaseApiAdminApplicationTest.java │ └── admin │ ├── service │ └── auth │ │ └── impl │ │ ├── AuthAdminServiceImplTest.java │ │ ├── AuthLoginServiceImplTest.java │ │ ├── AuthPermissionRuleServiceImplTest.java │ │ ├── AuthRoleAdminServiceImplTest.java │ │ └── AuthRoleServiceImplTest.java │ └── util │ ├── JwtUtilsTest.java │ └── PermissionRuleTreeUtilsTest.java ├── api-common ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── lmxdawn │ │ │ └── api │ │ │ └── common │ │ │ ├── constant │ │ │ └── CacheConstant.java │ │ │ ├── converter │ │ │ ├── LongList2StringConverter.java │ │ │ ├── String2LongListConverter.java │ │ │ └── String2StringListConverter.java │ │ │ ├── enums │ │ │ └── ResultEnum.java │ │ │ ├── req │ │ │ ├── BaseLimitRequest.java │ │ │ └── BaseRequest.java │ │ │ ├── res │ │ │ └── BaseResponse.java │ │ │ └── util │ │ │ └── ResultVOUtils.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── lmxdawn │ └── api │ └── common │ └── util │ └── ResultVOUtilsTest.java ├── pom.xml └── scripts └── vue-admin.sql /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | 5 |

6 | 7 | vue 8 | 9 | 10 | vue 11 | 12 | 13 | element-ui 14 | 15 |

16 | 17 | # 前言 18 | 19 | 20 | **项目JAVA前端地址:** https://github.com/lmxdawn/vue-admin-html-java 21 | 22 | **项目JAVA后端地址:** https://github.com/lmxdawn/vue-admin-java 23 | 24 | 25 | # 欢迎 star 26 | 27 | > 要求 java8 版本 28 | 29 | # 整体效果 30 | 31 | ![donate](https://lmxdawn.github.io/images/show-how1.jpg) 32 | 33 | 34 | 35 | # 功能 36 | - [x] 管理员登录 37 | - [x] 登录 38 | - [x] 修改密码 39 | - [x] 角色管理 40 | - [x] 权限管理 41 | - [x] 401/404错误页面 42 | - [x] 动态面包屑 43 | - [x] 动态侧边栏 44 | - [x] 广告管理 45 | 46 | # Online Demo 47 | (建议使用最新版Chrome浏览器) 48 | [在线 Demo](https://lmxdawn.github.io/vue-admin-java) 49 | 50 | # Donate 51 | 鼓励鼓励鼓励,重要的事情说三遍 52 | ![donate](https://lmxdawn.github.io/images/pay.png) 53 | 54 | # License 55 | 56 | [MIT](https://github.com/lmxdawn/vue-admin-java/blob/master/LICENSE) 57 | 58 | Copyright (c) 2018 lmxdawn 59 | -------------------------------------------------------------------------------- /api-admin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | api 7 | com.lmxdawn 8 | 0.0.1 9 | 10 | 4.0.0 11 | 12 | api-admin 13 | 14 | 15 | 16 | 17 | 18 | com.lmxdawn 19 | api-common 20 | 21 | 22 | 23 | org.apache.commons 24 | commons-lang3 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-web 30 | 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-configuration-processor 36 | true 37 | 38 | 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-starter-aop 43 | 44 | 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-starter-data-redis 49 | 50 | 51 | 52 | 53 | org.springframework.boot 54 | spring-boot-devtools 55 | true 56 | 57 | 58 | 59 | 60 | 61 | mysql 62 | mysql-connector-java 63 | runtime 64 | 65 | 66 | 67 | com.alibaba 68 | druid-spring-boot-starter 69 | 1.1.10 70 | 71 | 72 | 73 | org.mybatis.spring.boot 74 | mybatis-spring-boot-starter 75 | 1.3.2 76 | 77 | 78 | 79 | com.github.pagehelper 80 | pagehelper 81 | 5.1.7 82 | 83 | 84 | 85 | 86 | org.projectlombok 87 | lombok 88 | true 89 | 90 | 91 | 92 | 93 | io.jsonwebtoken 94 | jjwt 95 | 0.9.1 96 | 97 | 98 | 99 | 100 | com.alibaba 101 | fastjson 102 | 103 | 104 | 105 | 106 | org.springframework.boot 107 | spring-boot-starter-test 108 | test 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | org.springframework.boot 117 | spring-boot-maven-plugin 118 | 119 | true 120 | 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/ApiAdminApplication.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.web.servlet.ServletComponentScan; 7 | 8 | @SpringBootApplication 9 | @ServletComponentScan 10 | public class ApiAdminApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(ApiAdminApplication.class, args); 14 | } 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/annotation/AuthRuleAnnotation.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * 后台登录授权/权限验证的注解 10 | */ 11 | //此注解只能修饰方法 12 | @Target(ElementType.METHOD) 13 | //当前注解如何去保持 14 | @Retention(RetentionPolicy.RUNTIME) 15 | public @interface AuthRuleAnnotation { 16 | String value(); 17 | } 18 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/aspect/AuthorizeAspect.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.aspect; 2 | 3 | import com.lmxdawn.api.admin.annotation.AuthRuleAnnotation; 4 | import com.lmxdawn.api.common.enums.ResultEnum; 5 | import com.lmxdawn.api.admin.exception.JsonException; 6 | import com.lmxdawn.api.admin.service.auth.AuthLoginService; 7 | import com.lmxdawn.api.admin.util.JwtUtils; 8 | import io.jsonwebtoken.Claims; 9 | import lombok.extern.slf4j.Slf4j; 10 | import org.aspectj.lang.JoinPoint; 11 | import org.aspectj.lang.annotation.Aspect; 12 | import org.aspectj.lang.annotation.Before; 13 | import org.aspectj.lang.annotation.Pointcut; 14 | import org.aspectj.lang.reflect.MethodSignature; 15 | import org.springframework.stereotype.Component; 16 | import org.springframework.web.context.request.RequestContextHolder; 17 | import org.springframework.web.context.request.ServletRequestAttributes; 18 | 19 | import javax.annotation.Resource; 20 | import javax.servlet.http.HttpServletRequest; 21 | import java.lang.reflect.Method; 22 | import java.util.List; 23 | 24 | /** 25 | * 登录验证 AOP 26 | */ 27 | @Aspect 28 | @Component 29 | @Slf4j 30 | public class AuthorizeAspect { 31 | 32 | @Resource 33 | private AuthLoginService authLoginService; 34 | 35 | @Pointcut("@annotation(com.lmxdawn.api.admin.annotation.AuthRuleAnnotation)") 36 | public void adminLoginVerify() { 37 | } 38 | 39 | /** 40 | * 登录验证 41 | * 42 | * @param joinPoint 43 | */ 44 | @Before("adminLoginVerify()") 45 | public void doAdminAuthVerify(JoinPoint joinPoint) { 46 | 47 | ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); 48 | if (attributes == null) { 49 | throw new JsonException(ResultEnum.NOT_NETWORK); 50 | } 51 | HttpServletRequest request = attributes.getRequest(); 52 | 53 | String id = request.getHeader("X-Adminid"); 54 | Long adminId = null; 55 | try { 56 | adminId = Long.valueOf(id); 57 | }catch (Exception e) { 58 | throw new JsonException(ResultEnum.LOGIN_VERIFY_FALL); 59 | } 60 | 61 | String token = request.getHeader("X-Token"); 62 | if (token == null) { 63 | throw new JsonException(ResultEnum.LOGIN_VERIFY_FALL); 64 | } 65 | 66 | // 验证 token 67 | Claims claims = JwtUtils.parse(token); 68 | if (claims == null) { 69 | throw new JsonException(ResultEnum.LOGIN_VERIFY_FALL); 70 | } 71 | Long jwtAdminId = Long.valueOf(claims.get("admin_id").toString()); 72 | if (adminId.compareTo(jwtAdminId) != 0) { 73 | throw new JsonException(ResultEnum.LOGIN_VERIFY_FALL); 74 | } 75 | 76 | // 判断是否进行权限验证 77 | MethodSignature signature = (MethodSignature) joinPoint.getSignature(); 78 | //从切面中获取当前方法 79 | Method method = signature.getMethod(); 80 | //得到了方,提取出他的注解 81 | AuthRuleAnnotation action = method.getAnnotation(AuthRuleAnnotation.class); 82 | // 进行权限验证 83 | authRuleVerify(action.value(), adminId); 84 | } 85 | 86 | /** 87 | * 权限验证 88 | * 89 | * @param authRule 90 | */ 91 | private void authRuleVerify(String authRule, Long adminId) { 92 | 93 | if (authRule != null && authRule.length() > 0) { 94 | 95 | List authRules = authLoginService.listRuleByAdminId(adminId); 96 | // admin 为最高权限 97 | for (String item : authRules) { 98 | if (item.equals("admin") || item.equals(authRule)) { 99 | return; 100 | } 101 | } 102 | throw new JsonException(ResultEnum.AUTH_FAILED); 103 | } 104 | 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/config/CorsConfig.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | * 跨域配置 9 | */ 10 | @Data 11 | @Configuration 12 | @ConfigurationProperties(prefix = "cors") 13 | public class CorsConfig { 14 | 15 | // 允许的域 16 | private String allowedOrigins; 17 | // 允许的方法 18 | private String allowedMethods; 19 | // 允许的头信息 20 | private String allowedHeaders; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/config/CorsFilter.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.config; 2 | 3 | import com.lmxdawn.api.admin.config.CorsConfig; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | 6 | import java.io.IOException; 7 | 8 | import javax.servlet.Filter; 9 | import javax.servlet.FilterChain; 10 | import javax.servlet.FilterConfig; 11 | import javax.servlet.ServletException; 12 | import javax.servlet.ServletRequest; 13 | import javax.servlet.ServletResponse; 14 | import javax.servlet.annotation.WebFilter; 15 | import javax.servlet.http.HttpServletResponse; 16 | 17 | @WebFilter(urlPatterns = "/*", filterName = "corsFilter") 18 | public class CorsFilter implements Filter{ 19 | 20 | @Autowired 21 | private CorsConfig corsConfig; 22 | 23 | @Override 24 | public void destroy() { 25 | 26 | } 27 | 28 | @Override 29 | public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) 30 | throws IOException, ServletException { 31 | HttpServletResponse response = (HttpServletResponse) res; 32 | response.setHeader("Access-Control-Allow-Origin", corsConfig.getAllowedOrigins()); 33 | response.setHeader("Access-Control-Allow-Methods", corsConfig.getAllowedMethods()); 34 | 35 | response.setHeader("Access-Control-Allow-Headers", corsConfig.getAllowedHeaders()); 36 | chain.doFilter(req, res); 37 | } 38 | 39 | @Override 40 | public void init(FilterConfig arg0) throws ServletException { 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/config/DruidStatFilter.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.config; 2 | 3 | import com.alibaba.druid.support.http.WebStatFilter; 4 | 5 | import javax.servlet.annotation.WebFilter; 6 | import javax.servlet.annotation.WebInitParam; 7 | 8 | /** 9 | * 配置监控拦截器 (过滤不需要监控的后缀) 10 | * druid监控拦截器 11 | */ 12 | @WebFilter(filterName = "druidWebStatFilter", urlPatterns = "/*", 13 | initParams = { 14 | @WebInitParam(name = "exclusions", value = "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*")//忽略资源 15 | } 16 | ) 17 | public class DruidStatFilter extends WebStatFilter { 18 | } 19 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/config/DruidStatViewServlet.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.config; 2 | 3 | import com.alibaba.druid.support.http.StatViewServlet; 4 | 5 | import javax.servlet.annotation.WebInitParam; 6 | import javax.servlet.annotation.WebServlet; 7 | 8 | /** 9 | * druid监控视图配置 (监控视图配置) 10 | */ 11 | @WebServlet(urlPatterns = "/druid/*", initParams={ 12 | @WebInitParam(name="allow",value="127.0.0.1"),// IP白名单 (没有配置或者为空,则允许所有访问) 13 | @WebInitParam(name="deny",value="192.168.16.111"),// IP黑名单 (存在共同时,deny优先于allow) 14 | @WebInitParam(name="loginUsername",value="api"),// 用户名 15 | @WebInitParam(name="loginPassword",value="api"),// 密码 16 | @WebInitParam(name="resetEnable",value="true")// 禁用HTML页面上的“Reset All”功能 17 | }) 18 | public class DruidStatViewServlet extends StatViewServlet { 19 | private static final long serialVersionUID = 2359758657306626394L; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/config/PageHelperConfig.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.config; 2 | 3 | import com.github.pagehelper.PageHelper; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | import java.util.Properties; 8 | 9 | @Configuration 10 | public class PageHelperConfig { 11 | 12 | /** 13 | * 注入pagehelper配置 14 | * 15 | * @return 16 | */ 17 | @Bean 18 | public PageHelper getPageHelper() { 19 | PageHelper pageHelper = new PageHelper(); 20 | Properties properties = new Properties(); 21 | properties.setProperty("helperDialect", "mysql"); 22 | properties.setProperty("reasonable", "true"); 23 | properties.setProperty("supportMethodsArguments", "true"); 24 | properties.setProperty("params", "count=countSql"); 25 | pageHelper.setProperties(properties); 26 | return pageHelper; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/config/PublicFileUrlConfig.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.config; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | /** 7 | * 公共文件的配置 8 | */ 9 | 10 | @Configuration 11 | @ConfigurationProperties(prefix = "public-file") 12 | public class PublicFileUrlConfig { 13 | 14 | /** 15 | * 上传的地址 16 | */ 17 | private static String uploadUrl; 18 | 19 | public void setUploadUrl(String uploadUrl) { 20 | PublicFileUrlConfig.uploadUrl = uploadUrl; 21 | } 22 | 23 | public static String getUploadUrl() { 24 | return uploadUrl; 25 | } 26 | 27 | /** 28 | * 资源的域名 29 | */ 30 | private static String domain; 31 | 32 | public void setDomain(String domain) { 33 | PublicFileUrlConfig.domain = domain; 34 | } 35 | 36 | public static String getDomain() { 37 | return domain; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/constant/CookieConstant.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.constant; 2 | 3 | /** 4 | * cookie常量 5 | */ 6 | public interface CookieConstant { 7 | 8 | String TOKEN = "token"; 9 | 10 | Integer EXPIRE = 7200; 11 | } 12 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/constant/TestConstant.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.constant; 2 | 3 | /** 4 | * cookie常量 5 | */ 6 | public interface TestConstant { 7 | 8 | String TOKEN = "token"; 9 | 10 | Integer EXPIRE = 7200; 11 | } 12 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/controller/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.controller; 2 | 3 | import com.lmxdawn.api.admin.service.auth.AuthAdminService; 4 | import com.lmxdawn.api.common.util.ResultVOUtils; 5 | import com.lmxdawn.api.common.res.BaseResponse; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | @RestController 12 | public class HelloController { 13 | 14 | @Autowired 15 | private AuthAdminService authAdminService; 16 | 17 | @GetMapping("/hello") 18 | public BaseResponse hello( 19 | @RequestParam(value = "offset") Integer offset 20 | , @RequestParam("offset") Integer limit 21 | ) { 22 | return ResultVOUtils.error(1, "ssss"); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/controller/ad/AdController.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.controller.ad; 2 | 3 | import com.github.pagehelper.PageInfo; 4 | import com.lmxdawn.api.admin.annotation.AuthRuleAnnotation; 5 | import com.lmxdawn.api.admin.converter.AdSaveForm2AdConverter; 6 | import com.lmxdawn.api.admin.entity.ad.Ad; 7 | import com.lmxdawn.api.common.enums.ResultEnum; 8 | import com.lmxdawn.api.admin.req.ad.AdQueryRequest; 9 | import com.lmxdawn.api.admin.req.ad.AdSaveRequest; 10 | import com.lmxdawn.api.admin.service.ad.AdService; 11 | import com.lmxdawn.api.admin.res.PageSimpleResponse; 12 | import com.lmxdawn.api.common.res.BaseResponse; 13 | import com.lmxdawn.api.admin.res.ad.AdResponse; 14 | import com.lmxdawn.api.common.converter.String2StringListConverter; 15 | import com.lmxdawn.api.common.util.ResultVOUtils; 16 | import org.springframework.beans.BeanUtils; 17 | import org.springframework.util.ObjectUtils; 18 | import org.springframework.validation.BindingResult; 19 | import org.springframework.web.bind.annotation.*; 20 | 21 | import javax.annotation.Resource; 22 | import javax.validation.Valid; 23 | import java.util.*; 24 | import java.util.stream.Collectors; 25 | 26 | /** 27 | * 管理员相关 28 | */ 29 | @RestController 30 | public class AdController { 31 | 32 | @Resource 33 | private AdService adService; 34 | 35 | /** 36 | * 获取列表 37 | */ 38 | @AuthRuleAnnotation("admin/ad/ad/index") 39 | @GetMapping("/admin/ad/ad/index") 40 | public BaseResponse index(@Valid AdQueryRequest adQueryRequest, 41 | BindingResult bindingResult) { 42 | 43 | if (bindingResult.hasErrors()) { 44 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); 45 | } 46 | 47 | List adList = adService.listAdminPage(adQueryRequest); 48 | 49 | List adResponseList = adList.stream().map(item -> { 50 | AdResponse adResponse = new AdResponse(); 51 | BeanUtils.copyProperties(item, adResponse); 52 | List channelList = String2StringListConverter.convert(item.getChannelList(), ","); 53 | adResponse.setChannelList(channelList); 54 | List androidVersionList = String2StringListConverter.convert(item.getAndroidVersionList(), ","); 55 | adResponse.setAndroidVersionList(androidVersionList); 56 | List iosVersionList = String2StringListConverter.convert(item.getIosVersionList(), ","); 57 | adResponse.setIosVersionList(iosVersionList); 58 | return adResponse; 59 | }).collect(Collectors.toList()); 60 | 61 | PageInfo pageInfo = new PageInfo<>(adList); 62 | PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); 63 | pageSimpleResponse.setTotal(pageInfo.getTotal()); 64 | pageSimpleResponse.setList(adResponseList); 65 | return ResultVOUtils.success(pageSimpleResponse); 66 | 67 | } 68 | 69 | 70 | /** 71 | * 新增 72 | * 73 | * @return 74 | */ 75 | @AuthRuleAnnotation("admin/ad/ad/save") 76 | @PostMapping("/admin/ad/ad/save") 77 | public BaseResponse save(@RequestBody @Valid AdSaveRequest adSaveRequest, 78 | BindingResult bindingResult) { 79 | 80 | if (bindingResult.hasErrors()) { 81 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); 82 | } 83 | 84 | Ad ad = AdSaveForm2AdConverter.convert(adSaveRequest); 85 | 86 | if (null == ad) { 87 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "参数错误"); 88 | } 89 | 90 | Date nowDate = new Date(); 91 | ad.setCreateTime(nowDate); 92 | ad.setModifiedTime(nowDate); 93 | 94 | boolean b = adService.insertAd(ad); 95 | if (!b) { 96 | return ResultVOUtils.error(ResultEnum.NOT_NETWORK); 97 | } 98 | 99 | Map res = new HashMap<>(); 100 | res.put("adId", ad.getAdId()); 101 | return ResultVOUtils.success(res); 102 | } 103 | 104 | /** 105 | * 修改 106 | * 107 | * @return 108 | */ 109 | @AuthRuleAnnotation("admin/ad/ad/edit") 110 | @PostMapping("/admin/ad/ad/edit") 111 | public BaseResponse edit(@RequestBody @Valid AdSaveRequest adSaveRequest, 112 | BindingResult bindingResult) { 113 | 114 | if (bindingResult.hasErrors()) { 115 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); 116 | } 117 | 118 | if (ObjectUtils.isEmpty(adSaveRequest.getAdId())) { 119 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "参数错误!"); 120 | } 121 | 122 | Ad ad = AdSaveForm2AdConverter.convert(adSaveRequest); 123 | 124 | if (null == ad) { 125 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "参数错误"); 126 | } 127 | 128 | Date nowDate = new Date(); 129 | ad.setModifiedTime(nowDate); 130 | 131 | boolean b = adService.updateAd(ad); 132 | 133 | if (!b) { 134 | return ResultVOUtils.error(ResultEnum.NOT_NETWORK); 135 | } 136 | 137 | return ResultVOUtils.success(); 138 | } 139 | 140 | /** 141 | * 删除 142 | * 143 | * @return 144 | */ 145 | @AuthRuleAnnotation("admin/ad/ad/delete") 146 | @PostMapping("/admin/ad/ad/delete") 147 | public BaseResponse delete(@RequestBody AdSaveRequest adSaveRequest) { 148 | 149 | if (ObjectUtils.isEmpty(adSaveRequest.getAdId())) { 150 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "参数错误!"); 151 | } 152 | 153 | boolean b = adService.deleteByAdId(adSaveRequest.getAdId()); 154 | if (!b) { 155 | return ResultVOUtils.error(ResultEnum.NOT_NETWORK); 156 | } 157 | return ResultVOUtils.success(); 158 | } 159 | 160 | 161 | } 162 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/controller/ad/AdSiteController.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.controller.ad; 2 | 3 | import com.github.pagehelper.PageInfo; 4 | import com.lmxdawn.api.admin.annotation.AuthRuleAnnotation; 5 | import com.lmxdawn.api.admin.entity.ad.AdSite; 6 | import com.lmxdawn.api.common.enums.ResultEnum; 7 | import com.lmxdawn.api.admin.req.ad.AdSiteQueryRequest; 8 | import com.lmxdawn.api.admin.req.ad.AdSiteSaveRequest; 9 | import com.lmxdawn.api.admin.service.ad.AdSiteService; 10 | import com.lmxdawn.api.admin.res.PageSimpleResponse; 11 | import com.lmxdawn.api.common.res.BaseResponse; 12 | import com.lmxdawn.api.admin.res.ad.AdSimpleResponse; 13 | import com.lmxdawn.api.admin.res.ad.AdSiteResponse; 14 | import com.lmxdawn.api.common.converter.LongList2StringConverter; 15 | import com.lmxdawn.api.common.converter.String2LongListConverter; 16 | import com.lmxdawn.api.common.util.ResultVOUtils; 17 | import org.springframework.beans.BeanUtils; 18 | import org.springframework.util.ObjectUtils; 19 | import org.springframework.validation.BindingResult; 20 | import org.springframework.web.bind.annotation.*; 21 | 22 | import javax.annotation.Resource; 23 | import javax.validation.Valid; 24 | import java.util.*; 25 | import java.util.stream.Collectors; 26 | 27 | /** 28 | * 管理员相关 29 | */ 30 | @RestController 31 | public class AdSiteController { 32 | 33 | @Resource 34 | private AdSiteService adSiteService; 35 | 36 | /** 37 | * 获取管理员列表 38 | */ 39 | @AuthRuleAnnotation("admin/ad/site/index") 40 | @GetMapping("/admin/ad/site/index") 41 | public BaseResponse index(@Valid AdSiteQueryRequest adSiteQueryRequest, 42 | BindingResult bindingResult) { 43 | 44 | if (bindingResult.hasErrors()) { 45 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); 46 | } 47 | 48 | List adSiteList = adSiteService.listAdminPage(adSiteQueryRequest); 49 | 50 | Set adIds = new HashSet<>(); 51 | for (AdSite item: adSiteList) { 52 | List ads = String2LongListConverter.convert(item.getAdIds(), ","); 53 | adIds.addAll(ads); 54 | } 55 | 56 | // 查询根据所有广告id查询广告列表 57 | List adList = adSiteService.listAdminByAdIdsIn(new ArrayList<>(adIds)); 58 | 59 | List adSiteResponseList = adSiteList.stream().map(item -> { 60 | AdSiteResponse adSiteResponse = new AdSiteResponse(); 61 | List ads = String2LongListConverter.convert(item.getAdIds(), ","); 62 | List adSimpleResponseList = new ArrayList<>(); 63 | if (!ads.isEmpty()) { 64 | for (AdSimpleResponse adSimpleVo: adList) { 65 | if (ads.contains(adSimpleVo.getAdId())) { 66 | adSimpleResponseList.add(adSimpleVo); 67 | } 68 | } 69 | } 70 | adSiteResponse.setAds(adSimpleResponseList); 71 | BeanUtils.copyProperties(item, adSiteResponse); 72 | return adSiteResponse; 73 | }).collect(Collectors.toList()); 74 | 75 | PageInfo pageInfo = new PageInfo<>(adSiteList); 76 | PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); 77 | pageSimpleResponse.setTotal(pageInfo.getTotal()); 78 | pageSimpleResponse.setList(adSiteResponseList); 79 | return ResultVOUtils.success(pageSimpleResponse); 80 | 81 | } 82 | 83 | /** 84 | * 获取广告列表 85 | */ 86 | @AuthRuleAnnotation("admin/ad/site/adList") 87 | @PostMapping("/admin/ad/site/adList") 88 | public BaseResponse adList(@RequestBody Long[] adIds) { 89 | 90 | List adIdList = new ArrayList<>(); 91 | if (adIds.length > 0) { 92 | adIdList = Arrays.asList(adIds); 93 | } 94 | 95 | List adSimpleResponseList = adSiteService.listAdminByAdIdsIn(adIdList); 96 | 97 | PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); 98 | pageSimpleResponse.setTotal(1L); 99 | pageSimpleResponse.setList(adSimpleResponseList); 100 | return ResultVOUtils.success(pageSimpleResponse); 101 | 102 | } 103 | 104 | 105 | /** 106 | * 新增 107 | * 108 | * @return 109 | */ 110 | @AuthRuleAnnotation("admin/ad/site/save") 111 | @PostMapping("/admin/ad/site/save") 112 | public BaseResponse save(@RequestBody @Valid AdSiteSaveRequest adSiteSaveRequest, 113 | BindingResult bindingResult) { 114 | 115 | if (bindingResult.hasErrors()) { 116 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); 117 | } 118 | 119 | AdSite adSite = new AdSite(); 120 | BeanUtils.copyProperties(adSiteSaveRequest, adSite); 121 | adSite.setAdIds(LongList2StringConverter.convert(adSiteSaveRequest.getAdIds(), ",")); 122 | Date nowDate = new Date(); 123 | adSite.setCreateTime(nowDate); 124 | adSite.setModifiedTime(nowDate); 125 | 126 | boolean b = adSiteService.insertAdSite(adSite); 127 | if (!b) { 128 | return ResultVOUtils.error(ResultEnum.NOT_NETWORK); 129 | } 130 | 131 | Map res = new HashMap<>(); 132 | res.put("siteId", adSite.getSiteId()); 133 | return ResultVOUtils.success(res); 134 | } 135 | 136 | /** 137 | * 修改 138 | * 139 | * @return 140 | */ 141 | @AuthRuleAnnotation("admin/ad/site/edit") 142 | @PostMapping("/admin/ad/site/edit") 143 | public BaseResponse edit(@RequestBody @Valid AdSiteSaveRequest adSiteSaveRequest, 144 | BindingResult bindingResult) { 145 | 146 | if (bindingResult.hasErrors()) { 147 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); 148 | } 149 | 150 | AdSite adSite = new AdSite(); 151 | BeanUtils.copyProperties(adSiteSaveRequest, adSite); 152 | adSite.setAdIds(LongList2StringConverter.convert(adSiteSaveRequest.getAdIds(), ",")); 153 | Date nowDate = new Date(); 154 | adSite.setModifiedTime(nowDate); 155 | boolean b = adSiteService.updateAdSite(adSite); 156 | if (!b) { 157 | return ResultVOUtils.error(ResultEnum.NOT_NETWORK); 158 | } 159 | return ResultVOUtils.success(); 160 | } 161 | 162 | /** 163 | * 删除 // TODO 这个接口讲道理的话,是不应该存在的 164 | * 165 | * @return 166 | */ 167 | @AuthRuleAnnotation("admin/ad/site/delete") 168 | @PostMapping("/admin/ad/site/delete") 169 | public BaseResponse delete(@RequestBody AdSiteSaveRequest adSiteSaveRequest) { 170 | 171 | if (ObjectUtils.isEmpty(adSiteSaveRequest.getSiteId())) { 172 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "参数错误!"); 173 | } 174 | 175 | boolean b = adSiteService.deleteBySiteId(adSiteSaveRequest.getSiteId()); 176 | if (!b) { 177 | return ResultVOUtils.error(ResultEnum.NOT_NETWORK); 178 | } 179 | return ResultVOUtils.success(); 180 | } 181 | 182 | 183 | } 184 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/controller/auth/AuthAdminController.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.controller.auth; 2 | 3 | import com.github.pagehelper.PageInfo; 4 | import com.lmxdawn.api.admin.annotation.AuthRuleAnnotation; 5 | import com.lmxdawn.api.admin.entity.auth.AuthAdmin; 6 | import com.lmxdawn.api.admin.entity.auth.AuthRole; 7 | import com.lmxdawn.api.admin.entity.auth.AuthRoleAdmin; 8 | import com.lmxdawn.api.common.enums.ResultEnum; 9 | import com.lmxdawn.api.admin.req.auth.AuthAdminSaveRequest; 10 | import com.lmxdawn.api.admin.req.auth.AuthAdminQueryRequest; 11 | import com.lmxdawn.api.admin.service.auth.AuthAdminService; 12 | import com.lmxdawn.api.admin.service.auth.AuthRoleAdminService; 13 | import com.lmxdawn.api.admin.service.auth.AuthRoleService; 14 | import com.lmxdawn.api.admin.util.PasswordUtils; 15 | import com.lmxdawn.api.admin.res.auth.AuthAdminRoleResponse; 16 | import com.lmxdawn.api.common.util.ResultVOUtils; 17 | import com.lmxdawn.api.admin.res.PageSimpleResponse; 18 | import com.lmxdawn.api.common.res.BaseResponse; 19 | import com.lmxdawn.api.admin.res.auth.AuthAdminResponse; 20 | import org.springframework.beans.BeanUtils; 21 | import org.springframework.validation.BindingResult; 22 | import org.springframework.web.bind.annotation.*; 23 | 24 | import javax.annotation.Resource; 25 | import javax.validation.Valid; 26 | import java.util.*; 27 | import java.util.stream.Collectors; 28 | 29 | /** 30 | * 管理员相关 31 | */ 32 | @RestController 33 | public class AuthAdminController { 34 | 35 | @Resource 36 | private AuthAdminService authAdminService; 37 | 38 | @Resource 39 | private AuthRoleService authRoleService; 40 | 41 | @Resource 42 | private AuthRoleAdminService authRoleAdminService; 43 | 44 | /** 45 | * 获取管理员列表 46 | */ 47 | @AuthRuleAnnotation("admin/auth/admin/index") 48 | @GetMapping("/admin/auth/admin/index") 49 | public BaseResponse index(@Valid AuthAdminQueryRequest authAdminQueryRequest, 50 | BindingResult bindingResult) { 51 | 52 | if (bindingResult.hasErrors()) { 53 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); 54 | } 55 | 56 | if (authAdminQueryRequest.getRoleId() != null) { 57 | List authRoleAdmins = authRoleAdminService.listByRoleId(authAdminQueryRequest.getRoleId()); 58 | List ids = new ArrayList<>(); 59 | if (authRoleAdmins != null && !authRoleAdmins.isEmpty()) { 60 | ids = authRoleAdmins.stream().map(AuthRoleAdmin::getAdminId).collect(Collectors.toList()); 61 | } 62 | authAdminQueryRequest.setIds(ids); 63 | } 64 | List authAdminList = authAdminService.listAdminPage(authAdminQueryRequest); 65 | 66 | // 查询所有的权限 67 | List adminIds = authAdminList.stream().map(AuthAdmin::getId).collect(Collectors.toList()); 68 | List authRoleAdminList = authRoleAdminService.listByAdminIdIn(adminIds); 69 | 70 | // 视图列表 71 | List authAdminResponseList = authAdminList.stream().map(item -> { 72 | AuthAdminResponse authAdminResponse = new AuthAdminResponse(); 73 | BeanUtils.copyProperties(item, authAdminResponse); 74 | List roles = authRoleAdminList.stream() 75 | .filter(authRoleAdmin -> authAdminResponse.getId().equals(authRoleAdmin.getAdminId())) 76 | .map(AuthRoleAdmin::getRoleId) 77 | .collect(Collectors.toList()); 78 | authAdminResponse.setRoles(roles); 79 | return authAdminResponse; 80 | }).collect(Collectors.toList()); 81 | 82 | PageInfo authAdminPageInfo = new PageInfo<>(authAdminList); 83 | PageSimpleResponse authAdminPageSimpleResponse = new PageSimpleResponse<>(); 84 | authAdminPageSimpleResponse.setTotal(authAdminPageInfo.getTotal()); 85 | authAdminPageSimpleResponse.setList(authAdminResponseList); 86 | 87 | return ResultVOUtils.success(authAdminPageSimpleResponse); 88 | 89 | } 90 | 91 | 92 | /** 93 | * 获取角色列表 94 | */ 95 | @AuthRuleAnnotation("admin/auth/admin/roleList") 96 | @GetMapping("/admin/auth/admin/roleList") 97 | public BaseResponse roleList(@RequestParam(value = "page", defaultValue = "1") Integer page, 98 | @RequestParam(value = "limit", defaultValue = "100") Integer limit) { 99 | 100 | List authRoleList = authRoleService.listAuthAdminRolePage(page, limit, null); 101 | PageInfo pageInfo = new PageInfo<>(authRoleList); 102 | PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); 103 | pageSimpleResponse.setTotal(pageInfo.getTotal()); 104 | List authAdminRoleResponses = authRoleList.stream().map(e -> { 105 | AuthAdminRoleResponse authAdminRoleResponse = new AuthAdminRoleResponse(); 106 | BeanUtils.copyProperties(e, authAdminRoleResponse); 107 | return authAdminRoleResponse; 108 | }).collect(Collectors.toList()); 109 | pageSimpleResponse.setList(authAdminRoleResponses); 110 | 111 | return ResultVOUtils.success(pageSimpleResponse); 112 | 113 | } 114 | 115 | 116 | /** 117 | * 新增 118 | * 119 | * @return 120 | */ 121 | @AuthRuleAnnotation("admin/auth/admin/save") 122 | @PostMapping("/admin/auth/admin/save") 123 | public BaseResponse save(@RequestBody @Valid AuthAdminSaveRequest authAdminSaveRequest, 124 | BindingResult bindingResult) { 125 | 126 | if (bindingResult.hasErrors()) { 127 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); 128 | } 129 | 130 | // 检查是否存在相同名称的管理员 131 | AuthAdmin byUserName = authAdminService.findByUserName(authAdminSaveRequest.getUsername()); 132 | if (byUserName != null) { 133 | return ResultVOUtils.error(ResultEnum.DATA_REPEAT, "当前管理员已存在"); 134 | } 135 | 136 | AuthAdmin authAdmin = new AuthAdmin(); 137 | BeanUtils.copyProperties(authAdminSaveRequest, authAdmin); 138 | 139 | if (authAdmin.getPassword() != null) { 140 | authAdmin.setPassword(PasswordUtils.authAdminPwd(authAdmin.getPassword())); 141 | } 142 | 143 | boolean b = authAdminService.insertAuthAdmin(authAdmin); 144 | 145 | if (!b) { 146 | return ResultVOUtils.error(ResultEnum.NOT_NETWORK); 147 | } 148 | 149 | // 插入角色 150 | if (authAdminSaveRequest.getRoles() != null) { 151 | authRoleAdminService.insertRolesAdminIdAll(authAdminSaveRequest.getRoles(), authAdmin.getId()); 152 | } 153 | 154 | Map res = new HashMap<>(); 155 | res.put("id", authAdmin.getId()); 156 | return ResultVOUtils.success(res); 157 | } 158 | 159 | /** 160 | * 修改 161 | * 162 | * @return 163 | */ 164 | @AuthRuleAnnotation("admin/auth/admin/edit") 165 | @PostMapping("/admin/auth/admin/edit") 166 | public BaseResponse edit(@RequestBody @Valid AuthAdminSaveRequest authAdminSaveRequest, 167 | BindingResult bindingResult) { 168 | 169 | if (bindingResult.hasErrors()) { 170 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); 171 | } 172 | 173 | if (authAdminSaveRequest.getId() == null) { 174 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "参数错误!"); 175 | } 176 | 177 | // 检查是否存在除了当前管理员的其它名称的管理员 178 | AuthAdmin byUserName = authAdminService.findByUserName(authAdminSaveRequest.getUsername()); 179 | if (byUserName != null && !authAdminSaveRequest.getId().equals(byUserName.getId())) { 180 | return ResultVOUtils.error(ResultEnum.DATA_REPEAT, "当前管理员已存在"); 181 | } 182 | 183 | AuthAdmin authAdmin = new AuthAdmin(); 184 | BeanUtils.copyProperties(authAdminSaveRequest, authAdmin); 185 | if (authAdmin.getPassword() != null) { 186 | authAdmin.setPassword(PasswordUtils.authAdminPwd(authAdmin.getPassword())); 187 | } 188 | 189 | boolean b = authAdminService.updateAuthAdmin(authAdmin); 190 | 191 | if (!b) { 192 | return ResultVOUtils.error(ResultEnum.NOT_NETWORK); 193 | } 194 | 195 | // 修改角色 196 | if (authAdminSaveRequest.getRoles() != null) { 197 | // 先删除之前的 198 | authRoleAdminService.deleteByAdminId(authAdmin.getId()); 199 | authRoleAdminService.insertRolesAdminIdAll(authAdminSaveRequest.getRoles(), authAdmin.getId()); 200 | } 201 | 202 | return ResultVOUtils.success(); 203 | } 204 | 205 | /** 206 | * 删除 207 | * 208 | * @return 209 | */ 210 | @AuthRuleAnnotation("admin/auth/admin/delete") 211 | @PostMapping("/admin/auth/admin/delete") 212 | public BaseResponse delete(@RequestBody AuthAdminSaveRequest authAdminSaveRequest) { 213 | 214 | if (authAdminSaveRequest.getId() == null) { 215 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "参数错误!"); 216 | } 217 | 218 | boolean b = authAdminService.deleteById(authAdminSaveRequest.getId()); 219 | if (!b) { 220 | return ResultVOUtils.error(ResultEnum.NOT_NETWORK); 221 | } 222 | // 先删除之前的角色 223 | authRoleAdminService.deleteByAdminId(authAdminSaveRequest.getId()); 224 | 225 | return ResultVOUtils.success(); 226 | } 227 | 228 | 229 | } 230 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/controller/auth/AuthPermissionRuleController.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.controller.auth; 2 | 3 | import com.lmxdawn.api.admin.annotation.AuthRuleAnnotation; 4 | import com.lmxdawn.api.admin.entity.auth.AuthPermissionRule; 5 | import com.lmxdawn.api.common.enums.ResultEnum; 6 | import com.lmxdawn.api.admin.req.auth.AuthPermissionRuleSaveRequest; 7 | import com.lmxdawn.api.admin.service.auth.AuthPermissionRuleService; 8 | import com.lmxdawn.api.admin.util.PermissionRuleTreeUtils; 9 | import com.lmxdawn.api.common.res.BaseResponse; 10 | import com.lmxdawn.api.admin.res.auth.AuthPermissionRuleMergeResponse; 11 | import com.lmxdawn.api.common.util.ResultVOUtils; 12 | import org.springframework.beans.BeanUtils; 13 | import org.springframework.validation.BindingResult; 14 | import org.springframework.web.bind.annotation.*; 15 | 16 | import javax.annotation.Resource; 17 | import javax.validation.Valid; 18 | import java.util.HashMap; 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | /** 23 | * 权限规则相关 24 | */ 25 | @RestController 26 | public class AuthPermissionRuleController { 27 | 28 | @Resource 29 | private AuthPermissionRuleService authPermissionRuleService; 30 | 31 | /** 32 | * 列表 33 | * @return 34 | */ 35 | @AuthRuleAnnotation("admin/auth/permission_rule/index") 36 | @GetMapping("/admin/auth/permission_rule/index") 37 | public BaseResponse index() { 38 | 39 | 40 | List authPermissionRuleList = authPermissionRuleService.listAll(); 41 | List merge = PermissionRuleTreeUtils.merge(authPermissionRuleList,0L); 42 | 43 | Map restMap = new HashMap<>(); 44 | restMap.put("list", merge); 45 | return ResultVOUtils.success(restMap); 46 | } 47 | 48 | /** 49 | * 新增 50 | * @param authPermissionRuleSaveRequest 51 | * @param bindingResult 52 | * @return 53 | */ 54 | @AuthRuleAnnotation("admin/auth/permission_rule/save") 55 | @PostMapping("/admin/auth/permission_rule/save") 56 | public BaseResponse save(@RequestBody @Valid AuthPermissionRuleSaveRequest authPermissionRuleSaveRequest, 57 | BindingResult bindingResult) { 58 | 59 | if (bindingResult.hasErrors()) { 60 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); 61 | } 62 | 63 | if (authPermissionRuleSaveRequest.getPid() == null) { 64 | authPermissionRuleSaveRequest.setPid(0L); // 默认设置 65 | } 66 | AuthPermissionRule authPermissionRule = new AuthPermissionRule(); 67 | BeanUtils.copyProperties(authPermissionRuleSaveRequest, authPermissionRule); 68 | 69 | boolean b = authPermissionRuleService.insertAuthPermissionRule(authPermissionRule); 70 | if (!b) { 71 | return ResultVOUtils.error(ResultEnum.NOT_NETWORK); 72 | } 73 | 74 | Map res = new HashMap<>(); 75 | res.put("id", authPermissionRule.getId()); 76 | return ResultVOUtils.success(res); 77 | } 78 | 79 | /** 80 | * 编辑 81 | * @param authPermissionRuleSaveRequest 82 | * @param bindingResult 83 | * @return 84 | */ 85 | @AuthRuleAnnotation("admin/auth/permission_rule/edit") 86 | @PostMapping("/admin/auth/permission_rule/edit") 87 | public BaseResponse edit(@RequestBody @Valid AuthPermissionRuleSaveRequest authPermissionRuleSaveRequest, 88 | BindingResult bindingResult) { 89 | 90 | if (bindingResult.hasErrors()) { 91 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); 92 | } 93 | 94 | if (authPermissionRuleSaveRequest.getId() == null) { 95 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL); 96 | } 97 | 98 | authPermissionRuleSaveRequest.setPid(null); // 不能修改父级 pid 99 | 100 | AuthPermissionRule authPermissionRule = new AuthPermissionRule(); 101 | BeanUtils.copyProperties(authPermissionRuleSaveRequest, authPermissionRule); 102 | 103 | boolean b = authPermissionRuleService.updateAuthPermissionRule(authPermissionRule); 104 | if (!b) { 105 | return ResultVOUtils.error(ResultEnum.NOT_NETWORK); 106 | } 107 | 108 | return ResultVOUtils.success(); 109 | } 110 | 111 | /** 112 | * 删除 113 | * @param authPermissionRuleSaveRequest 114 | * @return 115 | */ 116 | @AuthRuleAnnotation("admin/auth/permission_rule/delete") 117 | @PostMapping("/admin/auth/permission_rule/delete") 118 | public BaseResponse delete(@RequestBody AuthPermissionRuleSaveRequest authPermissionRuleSaveRequest) { 119 | 120 | if (authPermissionRuleSaveRequest.getId() == null) { 121 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL); 122 | } 123 | 124 | boolean b = authPermissionRuleService.deleteById(authPermissionRuleSaveRequest.getId()); 125 | if (!b) { 126 | return ResultVOUtils.error(ResultEnum.NOT_NETWORK); 127 | } 128 | 129 | return ResultVOUtils.success(); 130 | } 131 | 132 | 133 | } 134 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/controller/auth/AuthRoleController.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.controller.auth; 2 | 3 | import com.github.pagehelper.PageInfo; 4 | import com.lmxdawn.api.admin.annotation.AuthRuleAnnotation; 5 | import com.lmxdawn.api.admin.entity.auth.AuthPermission; 6 | import com.lmxdawn.api.admin.entity.auth.AuthPermissionRule; 7 | import com.lmxdawn.api.admin.entity.auth.AuthRole; 8 | import com.lmxdawn.api.common.enums.ResultEnum; 9 | import com.lmxdawn.api.admin.req.auth.AuthRoleAuthRequest; 10 | import com.lmxdawn.api.admin.req.auth.AuthRoleQueryRequest; 11 | import com.lmxdawn.api.admin.req.auth.AuthRoleSaveRequest; 12 | import com.lmxdawn.api.admin.service.auth.AuthPermissionRuleService; 13 | import com.lmxdawn.api.admin.service.auth.AuthPermissionService; 14 | import com.lmxdawn.api.admin.service.auth.AuthRoleService; 15 | import com.lmxdawn.api.admin.util.PermissionRuleTreeUtils; 16 | import com.lmxdawn.api.admin.res.PageSimpleResponse; 17 | import com.lmxdawn.api.common.res.BaseResponse; 18 | import com.lmxdawn.api.admin.res.auth.AuthPermissionRuleMergeResponse; 19 | import com.lmxdawn.api.admin.res.auth.AuthRoleResponse; 20 | import com.lmxdawn.api.common.util.ResultVOUtils; 21 | import org.springframework.beans.BeanUtils; 22 | import org.springframework.validation.BindingResult; 23 | import org.springframework.web.bind.annotation.*; 24 | 25 | import javax.annotation.Resource; 26 | import javax.validation.Valid; 27 | import java.util.HashMap; 28 | import java.util.List; 29 | import java.util.Map; 30 | import java.util.stream.Collectors; 31 | 32 | /** 33 | * 角色相关 34 | */ 35 | @RestController 36 | public class AuthRoleController { 37 | 38 | @Resource 39 | private AuthRoleService authRoleService; 40 | 41 | @Resource 42 | private AuthPermissionRuleService authPermissionRuleService; 43 | 44 | @Resource 45 | private AuthPermissionService authPermissionService; 46 | 47 | /** 48 | * 角色列表 49 | */ 50 | @AuthRuleAnnotation("admin/auth/role/index") 51 | @GetMapping("/admin/auth/role/index") 52 | public BaseResponse index(@Valid AuthRoleQueryRequest authRoleQueryRequest, 53 | BindingResult bindingResult) { 54 | 55 | if (bindingResult.hasErrors()) { 56 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); 57 | } 58 | 59 | List authRoleList = authRoleService.listAdminPage(authRoleQueryRequest); 60 | List authRoleResponseList = authRoleList.stream().map(item -> { 61 | AuthRoleResponse authRoleResponse = new AuthRoleResponse(); 62 | BeanUtils.copyProperties(item, authRoleResponse); 63 | return authRoleResponse; 64 | }).collect(Collectors.toList()); 65 | 66 | PageInfo pageInfo = new PageInfo<>(authRoleList); 67 | PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); 68 | pageSimpleResponse.setTotal(pageInfo.getTotal()); 69 | pageSimpleResponse.setList(authRoleResponseList); 70 | return ResultVOUtils.success(pageSimpleResponse); 71 | } 72 | 73 | /** 74 | * 获取授权列表 75 | * 76 | * @param id 77 | * @return 78 | */ 79 | @AuthRuleAnnotation("admin/auth/role/authList") 80 | @GetMapping("/admin/auth/role/authList") 81 | public BaseResponse authList(@RequestParam("id") Long id) { 82 | 83 | // 查询当前角色拥有的权限id 84 | List authPermissionList = authPermissionService.listByRoleId(id); 85 | List checkedKeys = authPermissionList.stream() 86 | .map(AuthPermission::getPermissionRuleId) 87 | .collect(Collectors.toList()); 88 | 89 | // 查询所有权限规则 90 | List authPermissionRuleList = authPermissionRuleService.listAll(); 91 | List merge = PermissionRuleTreeUtils.merge(authPermissionRuleList, 0L); 92 | 93 | Map restMap = new HashMap<>(); 94 | restMap.put("list", merge); 95 | restMap.put("checkedKeys", checkedKeys); 96 | return ResultVOUtils.success(restMap); 97 | } 98 | 99 | @AuthRuleAnnotation("admin/auth/role/auth") 100 | @PostMapping("/admin/auth/role/auth") 101 | public BaseResponse auth(@RequestBody @Valid AuthRoleAuthRequest authRoleAuthRequest, 102 | BindingResult bindingResult) { 103 | 104 | if (bindingResult.hasErrors()) { 105 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); 106 | } 107 | 108 | // 先删除之前的授权 109 | authPermissionService.deleteByRoleId(authRoleAuthRequest.getRoleId()); 110 | 111 | List authPermissionList = authRoleAuthRequest.getAuthRules().stream() 112 | .map(aLong -> { 113 | AuthPermission authPermission = new AuthPermission(); 114 | authPermission.setRoleId(authRoleAuthRequest.getRoleId()); 115 | authPermission.setPermissionRuleId(aLong); 116 | authPermission.setType("admin"); 117 | return authPermission; 118 | }).collect(Collectors.toList()); 119 | 120 | int i = authPermissionService.insertAuthPermissionAll(authPermissionList); 121 | 122 | return ResultVOUtils.success(); 123 | } 124 | 125 | /** 126 | * 新增 127 | * 128 | * @param authRoleSaveRequest 129 | * @param bindingResult 130 | * @return 131 | */ 132 | @AuthRuleAnnotation("admin/auth/role/save") 133 | @PostMapping("/admin/auth/role/save") 134 | public BaseResponse save(@RequestBody @Valid AuthRoleSaveRequest authRoleSaveRequest, 135 | BindingResult bindingResult) { 136 | 137 | if (bindingResult.hasErrors()) { 138 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); 139 | } 140 | 141 | AuthRole byName = authRoleService.findByName(authRoleSaveRequest.getName()); 142 | if (byName != null) { 143 | return ResultVOUtils.error(ResultEnum.DATA_REPEAT, "当前角色已存在"); 144 | } 145 | 146 | AuthRole authRole = new AuthRole(); 147 | BeanUtils.copyProperties(authRoleSaveRequest, authRole); 148 | 149 | boolean b = authRoleService.insertAuthRole(authRole); 150 | if (!b) { 151 | return ResultVOUtils.error(ResultEnum.NOT_NETWORK); 152 | } 153 | 154 | Map res = new HashMap<>(); 155 | res.put("id", authRole.getId()); 156 | return ResultVOUtils.success(res); 157 | } 158 | 159 | /** 160 | * 编辑 161 | * 162 | * @param authRoleSaveRequest 163 | * @param bindingResult 164 | * @return 165 | */ 166 | @AuthRuleAnnotation("admin/auth/role/edit") 167 | @PostMapping("/admin/auth/role/edit") 168 | public BaseResponse edit(@RequestBody @Valid AuthRoleSaveRequest authRoleSaveRequest, 169 | BindingResult bindingResult) { 170 | 171 | if (bindingResult.hasErrors()) { 172 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); 173 | } 174 | 175 | if (authRoleSaveRequest.getId() == null) { 176 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL); 177 | } 178 | 179 | // 检查是否存在当前角色 180 | AuthRole byName = authRoleService.findByName(authRoleSaveRequest.getName()); 181 | if (byName != null && !authRoleSaveRequest.getId().equals(byName.getId())) { 182 | return ResultVOUtils.error(ResultEnum.DATA_REPEAT, "当前角色已存在"); 183 | } 184 | 185 | AuthRole authRole = new AuthRole(); 186 | BeanUtils.copyProperties(authRoleSaveRequest, authRole); 187 | 188 | boolean b = authRoleService.updateAuthRole(authRole); 189 | if (!b) { 190 | return ResultVOUtils.error(ResultEnum.NOT_NETWORK); 191 | } 192 | 193 | return ResultVOUtils.success(); 194 | } 195 | 196 | /** 197 | * 删除 198 | * 199 | * @param authRoleSaveRequest 200 | * @return 201 | */ 202 | @AuthRuleAnnotation("admin/auth/role/delete") 203 | @PostMapping("/admin/auth/role/delete") 204 | public BaseResponse delete(@RequestBody AuthRoleSaveRequest authRoleSaveRequest) { 205 | 206 | if (authRoleSaveRequest.getId() == null) { 207 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL); 208 | } 209 | 210 | boolean b = authRoleService.deleteById(authRoleSaveRequest.getId()); 211 | if (!b) { 212 | return ResultVOUtils.error(ResultEnum.NOT_NETWORK); 213 | } 214 | 215 | //TODO 删除角色后先前授权的缓存不会消失 216 | 217 | // 再删除之前的授权 218 | authPermissionService.deleteByRoleId(authRoleSaveRequest.getId()); 219 | 220 | return ResultVOUtils.success(); 221 | } 222 | 223 | 224 | } 225 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/controller/auth/LoginController.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.controller.auth; 2 | 3 | import com.lmxdawn.api.admin.annotation.AuthRuleAnnotation; 4 | import com.lmxdawn.api.admin.entity.auth.AuthAdmin; 5 | import com.lmxdawn.api.common.enums.ResultEnum; 6 | import com.lmxdawn.api.admin.exception.JsonException; 7 | import com.lmxdawn.api.admin.req.auth.LoginRequest; 8 | import com.lmxdawn.api.admin.req.auth.UpdatePasswordRequest; 9 | import com.lmxdawn.api.admin.service.auth.AuthAdminService; 10 | import com.lmxdawn.api.admin.service.auth.AuthLoginService; 11 | import com.lmxdawn.api.admin.util.PasswordUtils; 12 | import com.lmxdawn.api.admin.res.auth.LoginUserInfoResponse; 13 | import com.lmxdawn.api.admin.util.IpUtils; 14 | import com.lmxdawn.api.admin.util.JwtUtils; 15 | import com.lmxdawn.api.common.util.ResultVOUtils; 16 | import com.lmxdawn.api.common.res.BaseResponse; 17 | import lombok.extern.slf4j.Slf4j; 18 | import org.springframework.beans.BeanUtils; 19 | import org.springframework.beans.factory.annotation.Autowired; 20 | import org.springframework.validation.BindingResult; 21 | import org.springframework.web.bind.annotation.GetMapping; 22 | import org.springframework.web.bind.annotation.PostMapping; 23 | import org.springframework.web.bind.annotation.RequestBody; 24 | import org.springframework.web.bind.annotation.RestController; 25 | 26 | import javax.servlet.http.HttpServletRequest; 27 | import javax.validation.Valid; 28 | import java.util.*; 29 | 30 | /** 31 | * 登录相关 32 | */ 33 | @RestController 34 | @Slf4j 35 | public class LoginController { 36 | 37 | @Autowired 38 | private AuthLoginService authLoginService; 39 | 40 | @Autowired 41 | private AuthAdminService authAdminService; 42 | 43 | /** 44 | * 用户登录 45 | * @return 46 | */ 47 | @PostMapping(value = "/admin/auth/login/index") 48 | public BaseResponse index(@RequestBody @Valid LoginRequest loginRequest, 49 | BindingResult bindingResult, 50 | HttpServletRequest request) { 51 | if (bindingResult.hasErrors()) { 52 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); 53 | } 54 | 55 | AuthAdmin authAdmin = authAdminService.findByUserName(loginRequest.getUserName()); 56 | if (authAdmin == null) { 57 | throw new JsonException(ResultEnum.DATA_NOT, "用户名或密码错误"); 58 | } 59 | 60 | if (!PasswordUtils.authAdminPwd(loginRequest.getPwd()).equals(authAdmin.getPassword())) { 61 | throw new JsonException(ResultEnum.DATA_NOT, "用户名或密码错误"); 62 | } 63 | 64 | // 更新登录状态 65 | AuthAdmin authAdminUp = new AuthAdmin(); 66 | authAdminUp.setId(authAdmin.getId()); 67 | authAdminUp.setLastLoginTime(new Date()); 68 | authAdminUp.setLastLoginIp(IpUtils.getIpAddr(request)); 69 | authAdminService.updateAuthAdmin(authAdminUp); 70 | 71 | // 登录成功后获取权限,这里面会设置到缓存 72 | authLoginService.listRuleByAdminId(authAdmin.getId()); 73 | 74 | Map claims = new HashMap<>(); 75 | claims.put("admin_id", authAdmin.getId()); 76 | String token = JwtUtils.createToken(claims, 86400L); // 一天后过期 77 | 78 | Map map = new HashMap<>(); 79 | map.put("id", authAdmin.getId()); 80 | map.put("token", token); 81 | 82 | return ResultVOUtils.success(map); 83 | } 84 | 85 | /** 86 | * 获取登录用户信息 87 | * @return 88 | */ 89 | @AuthRuleAnnotation("") 90 | @GetMapping("/admin/auth/login/userInfo") 91 | public BaseResponse userInfo(HttpServletRequest request) { 92 | String adminId = request.getHeader("X-Adminid"); 93 | Long id = Long.valueOf(adminId); 94 | 95 | AuthAdmin authAdmin = authAdminService.findById(id); 96 | 97 | List authRules = authLoginService.listRuleByAdminId(authAdmin.getId()); 98 | 99 | LoginUserInfoResponse loginUserInfoResponse = new LoginUserInfoResponse(); 100 | BeanUtils.copyProperties(authAdmin, loginUserInfoResponse); 101 | loginUserInfoResponse.setAuthRules(authRules); 102 | 103 | return ResultVOUtils.success(loginUserInfoResponse); 104 | } 105 | 106 | /** 107 | * 登出 108 | * @return 109 | */ 110 | @PostMapping("/admin/auth/login/out") 111 | public BaseResponse out(){ 112 | return ResultVOUtils.success(); 113 | } 114 | 115 | /** 116 | * 修改密码 117 | * @return 118 | */ 119 | @AuthRuleAnnotation("") // 需要登录验证,但是不需要权限验证时,value 值填空字符串 120 | @PostMapping("/admin/auth/login/password") 121 | public BaseResponse password(@RequestBody @Valid UpdatePasswordRequest updatePasswordRequest, 122 | BindingResult bindingResult) { 123 | if (bindingResult.hasErrors()) { 124 | return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL.getCode(), 125 | bindingResult.getFieldError().getDefaultMessage()); 126 | } 127 | 128 | AuthAdmin authAdmin = authAdminService.findPwdById(updatePasswordRequest.getAdminId()); 129 | if (authAdmin == null) { 130 | throw new JsonException(ResultEnum.DATA_NOT); 131 | } 132 | String oldPwd = PasswordUtils.authAdminPwd(updatePasswordRequest.getOldPassword()); 133 | // 旧密码不对 134 | if (authAdmin.getPassword() != null 135 | && !authAdmin.getPassword().equals(oldPwd)) { 136 | throw new JsonException(ResultEnum.DATA_NOT, "旧密码匹配失败"); 137 | } 138 | 139 | AuthAdmin authAdminUp = new AuthAdmin(); 140 | authAdminUp.setId(authAdmin.getId()); 141 | String newPwd = PasswordUtils.authAdminPwd(updatePasswordRequest.getNewPassword()); 142 | authAdminUp.setPassword(newPwd); 143 | 144 | boolean b = authAdminService.updateAuthAdmin(authAdminUp); 145 | if (b) { 146 | return ResultVOUtils.success(); 147 | } 148 | 149 | return ResultVOUtils.error(ResultEnum.DATA_CHANGE); 150 | } 151 | 152 | } 153 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/controller/file/UploadController.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.controller.file; 2 | 3 | import com.lmxdawn.api.common.res.BaseResponse; 4 | import com.lmxdawn.api.common.util.ResultVOUtils; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.PostMapping; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | /** 14 | * 上传相关 15 | */ 16 | @RestController 17 | @RequestMapping("/admin/file/upload") 18 | public class UploadController { 19 | 20 | /** 21 | * 上传的token 22 | * @return 23 | */ 24 | @GetMapping("/qiuNiuUpToken") 25 | public BaseResponse qiuNiuUpToken() { 26 | 27 | // TODO 这里接入 七牛云 的SDK 就可以了 28 | Map res = new HashMap<>(); 29 | res.put("uploadUrl", "/admin/file/upload/createFile"); // 这里可以直接设置成七牛云的上传 url,不用服务端这边去post请求七牛云的上传接口 30 | res.put("upToken", "xxxxxxx"); 31 | 32 | return ResultVOUtils.success(res); 33 | } 34 | 35 | /** 36 | * 上传文件(如果是接入的第三方的建议这个接口废弃) 37 | * @return 38 | */ 39 | @PostMapping("/createFile") 40 | public BaseResponse createFile() { 41 | 42 | // TODO 这里做上传文件的逻辑,返回文件的 key (也就是路径) 43 | 44 | Map res = new HashMap<>(); 45 | res.put("key", "xxxx.jpg"); 46 | return ResultVOUtils.success(res); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/converter/AdSaveForm2AdConverter.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.converter; 2 | 3 | 4 | import com.lmxdawn.api.admin.entity.ad.Ad; 5 | import com.lmxdawn.api.admin.req.ad.AdSaveRequest; 6 | import org.apache.commons.lang3.StringUtils; 7 | import org.springframework.beans.BeanUtils; 8 | 9 | import java.util.ArrayList; 10 | import java.util.HashSet; 11 | import java.util.List; 12 | import java.util.stream.Collectors; 13 | 14 | /** 15 | * 将 广告的表单 转为 广告实体类 16 | */ 17 | public class AdSaveForm2AdConverter { 18 | 19 | /** 20 | * 将 广告的表单 转为 广告实体类 21 | * @param adSaveRequest 表单 22 | * @return 如果为 null ,证明参数有误 23 | */ 24 | public static Ad convert(AdSaveRequest adSaveRequest) { 25 | 26 | // 判断 27 | if (null != adSaveRequest.getChannelType() && 28 | adSaveRequest.getChannelType() > 0 && 29 | (null == adSaveRequest.getChannelList() || 30 | adSaveRequest.getChannelList().isEmpty())) { 31 | return null; 32 | } 33 | if (null != adSaveRequest.getAndroidVersionType() && 34 | adSaveRequest.getAndroidVersionType() > 0 && 35 | (null == adSaveRequest.getAndroidVersionList() || 36 | adSaveRequest.getAndroidVersionList().isEmpty())) { 37 | return null; 38 | } 39 | if (null != adSaveRequest.getIosVersionType() && 40 | adSaveRequest.getIosVersionType() > 0 && 41 | (null == adSaveRequest.getIosVersionList() || 42 | adSaveRequest.getIosVersionList().isEmpty())) { 43 | return null; 44 | } 45 | 46 | Ad ad = new Ad(); 47 | BeanUtils.copyProperties(adSaveRequest, ad); 48 | 49 | if (null != adSaveRequest.getChannelList()) { 50 | List channelList = adSaveRequest.getChannelList().stream() 51 | .map(v -> v.replace(",", "")) 52 | .collect(Collectors.toList()); 53 | channelList = new ArrayList<>(new HashSet<>(channelList)); 54 | if (!channelList.isEmpty()) 55 | ad.setChannelList(StringUtils.join(channelList, ",")); 56 | } 57 | 58 | if (null != adSaveRequest.getAndroidVersionList()) { 59 | List androidVersionList = adSaveRequest.getAndroidVersionList().stream() 60 | .map(v -> v.replace(",", "")) 61 | .collect(Collectors.toList()); 62 | androidVersionList = new ArrayList<>(new HashSet<>(androidVersionList)); 63 | if (!androidVersionList.isEmpty()) 64 | ad.setAndroidVersionList(StringUtils.join(androidVersionList, ",")); 65 | } 66 | if (null != adSaveRequest.getIosVersionList()) { 67 | List iosVersionList = adSaveRequest.getIosVersionList().stream() 68 | .map(v -> v.replace(",", "")) 69 | .collect(Collectors.toList()); 70 | iosVersionList = new ArrayList<>(new HashSet<>(iosVersionList)); 71 | if (!iosVersionList.isEmpty()) 72 | ad.setIosVersionList(StringUtils.join(iosVersionList, ",")); 73 | } 74 | return ad; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/dao/ad/AdDao.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.dao.ad; 2 | 3 | import com.lmxdawn.api.admin.entity.ad.Ad; 4 | import com.lmxdawn.api.admin.req.ad.AdQueryRequest; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | import java.util.List; 8 | 9 | @Mapper 10 | public interface AdDao { 11 | 12 | /** 13 | * 后台业务查询列表 14 | * @return 列表 15 | */ 16 | List listAdmin(AdQueryRequest adQueryRequest); 17 | 18 | /** 19 | * 根据adIds 查询 20 | * @return 列表 21 | */ 22 | List listAdminByAdIdsIn(List adIds); 23 | 24 | /** 25 | * 插入 26 | * @param ad 27 | * @return 28 | */ 29 | boolean insertAd(Ad ad); 30 | 31 | /** 32 | * 更新 33 | * @param ad 34 | * @return 35 | */ 36 | boolean updateAd(Ad ad); 37 | 38 | /** 39 | * 删除 40 | * @param adId 41 | * @return 42 | */ 43 | boolean deleteByAdId(Long adId); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/dao/ad/AdSiteDao.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.dao.ad; 2 | 3 | import com.lmxdawn.api.admin.entity.ad.AdSite; 4 | import com.lmxdawn.api.admin.req.ad.AdSiteQueryRequest; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | import java.util.List; 8 | 9 | @Mapper 10 | public interface AdSiteDao { 11 | 12 | /** 13 | * 后台业务查询列表 14 | * @return 列表 15 | */ 16 | List listAdmin(AdSiteQueryRequest adSiteQueryRequest); 17 | 18 | /** 19 | * 插入 20 | * @param adSite 21 | * @return 22 | */ 23 | boolean insertAdSite(AdSite adSite); 24 | 25 | /** 26 | * 更新 27 | * @param adSite 28 | * @return 29 | */ 30 | boolean updateAdSite(AdSite adSite); 31 | 32 | /** 33 | * 删除 34 | * @param siteId 35 | * @return 36 | */ 37 | boolean deleteBySiteId(Long siteId); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/dao/auth/AuthAdminDao.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.dao.auth; 2 | 3 | import com.lmxdawn.api.admin.entity.auth.AuthAdmin; 4 | import com.lmxdawn.api.admin.req.auth.AuthAdminQueryRequest; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | import java.util.List; 8 | 9 | @Mapper 10 | public interface AuthAdminDao { 11 | 12 | /** 13 | * 后台业务查询列表 14 | * @return 列表 15 | */ 16 | List listAdminPage(AuthAdminQueryRequest authAdminQueryRequest); 17 | 18 | /** 19 | * 根据id查询 20 | * @param id 传入的id 21 | * @return 22 | */ 23 | AuthAdmin findById(Long id); 24 | 25 | /** 26 | * 根据id查询 password 27 | * @param id 传入的id 28 | * @return 29 | */ 30 | AuthAdmin findPwdById(Long id); 31 | 32 | /** 33 | * 根据Name 34 | * @param userName 用户名 35 | * @return 36 | */ 37 | AuthAdmin findByUserName(String userName); 38 | 39 | /** 40 | * 插入 41 | * @param authAdmin 42 | * @return 43 | */ 44 | boolean insertAuthAdmin(AuthAdmin authAdmin); 45 | 46 | /** 47 | * 更新 48 | * @param authAdmin 49 | * @return 50 | */ 51 | boolean updateAuthAdmin(AuthAdmin authAdmin); 52 | 53 | /** 54 | * 删除 55 | * @param id 56 | * @return 57 | */ 58 | boolean deleteById(Long id); 59 | 60 | } 61 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/dao/auth/AuthPermissionDao.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.dao.auth; 2 | 3 | import com.lmxdawn.api.admin.entity.auth.AuthPermission; 4 | import org.apache.ibatis.annotations.Mapper; 5 | 6 | import java.util.List; 7 | 8 | @Mapper 9 | public interface AuthPermissionDao { 10 | 11 | /** 12 | * 根据roleIds查询 13 | * @param roleIds 传入的id 14 | * @return 15 | */ 16 | List listByRoleIdIn(List roleIds); 17 | 18 | /** 19 | * 根据 roleId 查询 20 | * @param roleId 传入的id 21 | * @return 22 | */ 23 | List listByRoleId(Long roleId); 24 | 25 | 26 | /** 27 | * 批量插入 28 | * @param authPermissionList 29 | * @return 30 | */ 31 | int insertAuthPermissionAll(List authPermissionList); 32 | 33 | /** 34 | * 根据角色id删除 35 | * @param roleId 36 | * @return 37 | */ 38 | boolean deleteByRoleId(Long roleId); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/dao/auth/AuthPermissionRuleDao.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.dao.auth; 2 | 3 | import com.lmxdawn.api.admin.entity.auth.AuthPermissionRule; 4 | import org.apache.ibatis.annotations.Mapper; 5 | 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | 10 | @Mapper 11 | public interface AuthPermissionRuleDao { 12 | 13 | /** 14 | * 根据ids查询 规则名称 15 | * @param ids 传入的ids 16 | * @return 17 | */ 18 | List listByIdIn(List ids); 19 | 20 | /** 21 | * 查询所有 22 | * @param map 23 | * @return 24 | */ 25 | List listAll(); 26 | 27 | /** 28 | * 根据 父级 pid 查询 29 | * @param pid 30 | * @return 31 | */ 32 | List listByPid(Long pid); 33 | 34 | /** 35 | * 根据 规则名称查询 36 | * @param name 37 | * @return 38 | */ 39 | AuthPermissionRule findByName(String name); 40 | 41 | /** 42 | * 插入 43 | * @param authPermissionRule 44 | * @return 45 | */ 46 | boolean insertAuthPermissionRule(AuthPermissionRule authPermissionRule); 47 | 48 | /** 49 | * 更新 50 | * @param authPermissionRule 51 | * @return 52 | */ 53 | boolean updateAuthPermissionRule(AuthPermissionRule authPermissionRule); 54 | 55 | /** 56 | * 删除 57 | * @param id 58 | * @return 59 | */ 60 | boolean deleteById(Long id); 61 | 62 | } 63 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/dao/auth/AuthRoleAdminDao.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.dao.auth; 2 | 3 | import com.lmxdawn.api.admin.entity.auth.AuthRoleAdmin; 4 | import org.apache.ibatis.annotations.Mapper; 5 | 6 | import java.util.List; 7 | 8 | 9 | @Mapper 10 | public interface AuthRoleAdminDao { 11 | 12 | /** 13 | * 根据 adminId 查询 14 | * @param adminId 传入的 adminId 15 | * @return 16 | */ 17 | List listByAdminId(Long adminId); 18 | 19 | /** 20 | * 根据 多个 adminId 查询 21 | * @param adminIds 传入的 adminIds 22 | * @return 23 | */ 24 | List listByAdminIdIn(List adminIds); 25 | 26 | /** 27 | * 根据 role_id 查询 admin_id 28 | * @param roleId 传入的 roleId 29 | * @return 30 | */ 31 | List listByRoleId(Long roleId); 32 | 33 | /** 34 | * 批量插入 35 | * @param authRoleAdminList 36 | * @return 37 | */ 38 | int insertAuthRoleAdminAll(List authRoleAdminList); 39 | 40 | 41 | /** 42 | * 根据 adminId 删除 43 | * @param adminId 44 | * @return 45 | */ 46 | boolean deleteByAdminId(Long adminId); 47 | } 48 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/dao/auth/AuthRoleDao.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.dao.auth; 2 | 3 | import com.lmxdawn.api.admin.entity.auth.AuthRole; 4 | import com.lmxdawn.api.admin.req.auth.AuthRoleQueryRequest; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | import java.util.List; 8 | 9 | @Mapper 10 | public interface AuthRoleDao { 11 | 12 | /** 13 | * 后台管理业务查询列表 14 | * @return 列表 15 | */ 16 | List listAdminPage(AuthRoleQueryRequest authRoleQueryRequest); 17 | 18 | /** 19 | * 返回id,name 字段的列表 20 | * @return 列表 21 | */ 22 | List listAuthAdminRolePage(Integer status); 23 | 24 | AuthRole findByName(String name); 25 | 26 | /** 27 | * 插入 28 | * @param authAdmin 29 | * @return 30 | */ 31 | boolean insertAuthRole(AuthRole authAdmin); 32 | 33 | /** 34 | * 更新 35 | * @param authAdmin 36 | * @return 37 | */ 38 | boolean updateAuthRole(AuthRole authAdmin); 39 | 40 | /** 41 | * 删除 42 | * @param id 43 | * @return 44 | */ 45 | boolean deleteById(Long id); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/dto/auth/TestDTO.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.dto.auth; 2 | 3 | public class TestDTO { 4 | } 5 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/entity/ad/Ad.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.entity.ad; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Date; 6 | 7 | /** 8 | * 广告实体类 9 | */ 10 | @Data 11 | public class Ad { 12 | 13 | private Long adId; 14 | private String title; 15 | private String describe; 16 | private String pic; 17 | private Integer jumpType; 18 | private String jumpUrl; 19 | private String iosUrl; 20 | private String androidUrl; 21 | private String wxaAppid; 22 | private Integer channelType; 23 | private String channelList; 24 | private Integer androidVersionType; 25 | private String androidVersionList; 26 | private Integer iosVersionType; 27 | private String iosVersionList; 28 | private Integer newShowStartNum; 29 | private Integer newShowMaxNum; 30 | private Integer oldShowStartNum; 31 | private Integer oldShowMaxNum; 32 | private Date startTime; 33 | private Date endTime; 34 | private String eventName; 35 | private Integer status; 36 | private Date createTime; 37 | private Date modifiedTime; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/entity/ad/AdSite.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.entity.ad; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Date; 6 | 7 | /** 8 | * 广告位实体类 9 | */ 10 | @Data 11 | public class AdSite { 12 | 13 | private Long siteId; 14 | private String siteName; 15 | private String describe; 16 | private String adIds; 17 | private Date createTime; 18 | private Date modifiedTime; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/entity/auth/AuthAdmin.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.entity.auth; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Date; 6 | 7 | @Data 8 | public class AuthAdmin { 9 | 10 | // 主键 11 | private Long id; 12 | // 昵称 13 | private String username; 14 | // 登录密码 15 | private String password; 16 | // 手机号 17 | private String tel; 18 | // 邮箱 19 | private String email; 20 | // 头像 21 | private String avatar; 22 | // 性别 23 | private Integer sex; 24 | // 最后登录ip 25 | private String lastLoginIp; 26 | // 最后登录时间 27 | private Date lastLoginTime; 28 | // 创建时间 29 | private Date createTime; 30 | // 状态 31 | private Integer status; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/entity/auth/AuthPermission.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.entity.auth; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * 权限授权表 7 | */ 8 | @Data 9 | public class AuthPermission { 10 | 11 | private Long id; 12 | 13 | private Long roleId; 14 | 15 | private Long permissionRuleId; 16 | 17 | private String type; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/entity/auth/AuthPermissionRule.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.entity.auth; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Date; 6 | 7 | /** 8 | * 规则表 9 | */ 10 | @Data 11 | public class AuthPermissionRule { 12 | 13 | private Long id; 14 | private Long pid; 15 | private String name; 16 | private String title; 17 | private Integer status; 18 | private String condition; 19 | private Integer listorder; 20 | private Date createTime; 21 | private Date updateTime; 22 | } 23 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/entity/auth/AuthRole.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.entity.auth; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Date; 6 | 7 | /** 8 | * 角色表 9 | */ 10 | @Data 11 | public class AuthRole { 12 | 13 | private Long id; 14 | private String name; 15 | private Long pid; 16 | private Long status; 17 | private String remark; 18 | private Long listorder; 19 | private Date createTime; 20 | private Date updateTime; 21 | } 22 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/entity/auth/AuthRoleAdmin.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.entity.auth; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * 用户角色对应表 7 | */ 8 | @Data 9 | public class AuthRoleAdmin { 10 | private Long id; 11 | private Long roleId; 12 | private Long adminId; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/exception/JsonException.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.exception; 2 | 3 | import com.lmxdawn.api.common.enums.ResultEnum; 4 | import lombok.Getter; 5 | 6 | /** 7 | * 错误处理类 8 | */ 9 | @Getter 10 | public class JsonException extends RuntimeException{ 11 | 12 | private Integer code; 13 | 14 | public JsonException(ResultEnum resultEnum) { 15 | super(resultEnum.getMessage()); 16 | this.code = resultEnum.getCode(); 17 | } 18 | 19 | public JsonException(ResultEnum resultEnum, String message) { 20 | super(message); 21 | this.code = resultEnum.getCode(); 22 | } 23 | 24 | public JsonException(Integer code, String message) { 25 | super(message); 26 | this.code = code; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/handler/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.handler; 2 | 3 | import com.lmxdawn.api.common.enums.ResultEnum; 4 | import com.lmxdawn.api.admin.exception.JsonException; 5 | import com.lmxdawn.api.common.util.ResultVOUtils; 6 | import com.lmxdawn.api.common.res.BaseResponse; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.web.bind.annotation.ExceptionHandler; 9 | import org.springframework.web.bind.annotation.RestControllerAdvice; 10 | 11 | /** 12 | * 错误回调 13 | */ 14 | @RestControllerAdvice 15 | @Slf4j 16 | public class GlobalExceptionHandler { 17 | 18 | // 拦截API异常 19 | @ExceptionHandler(value = JsonException.class) 20 | public BaseResponse handlerJsonException(JsonException e) { 21 | // 返回对应的错误信息 22 | return ResultVOUtils.error(e.getCode(), e.getMessage()); 23 | } 24 | 25 | // 拦截API异常 26 | @ExceptionHandler(value = RuntimeException.class) 27 | public BaseResponse handlerRuntimeException(RuntimeException e) { 28 | log.error(e.getMessage()); 29 | // 返回对应的错误信息 30 | return ResultVOUtils.error(ResultEnum.NOT_NETWORK); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/req/ListPageRequest.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.req; 2 | 3 | import lombok.Data; 4 | 5 | import javax.validation.constraints.Max; 6 | import javax.validation.constraints.Min; 7 | import javax.validation.constraints.NotNull; 8 | 9 | /** 10 | * 分页的表单 11 | */ 12 | @Data 13 | public class ListPageRequest { 14 | 15 | @NotNull(message = "请选择第几页") 16 | @Min(message = "分页参数错误", value = 1) 17 | private Integer page; 18 | 19 | @NotNull(message = "请填写每页查询数量") 20 | @Min(value = 1, message = "分页参数不能小于1") 21 | @Max(value = 50, message = "分页参数不能大于50") 22 | private Integer limit; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/req/ad/AdQueryRequest.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.req.ad; 2 | 3 | import com.lmxdawn.api.admin.req.ListPageRequest; 4 | import lombok.Data; 5 | import lombok.EqualsAndHashCode; 6 | 7 | @EqualsAndHashCode(callSuper = true) 8 | @Data 9 | public class AdQueryRequest extends ListPageRequest { 10 | 11 | private String title; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/req/ad/AdSaveRequest.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.req.ad; 2 | 3 | import lombok.Data; 4 | 5 | import javax.validation.constraints.*; 6 | import java.util.Date; 7 | import java.util.List; 8 | 9 | /** 10 | * 广告的保存表单 11 | */ 12 | @Data 13 | public class AdSaveRequest { 14 | 15 | private Long adId; 16 | @NotEmpty(message = "请输入广告名称") 17 | private String title; 18 | private String describe; 19 | @NotEmpty(message = "请选择广告的封面图片") 20 | private String pic; 21 | @NotNull(message = "请选择状态") 22 | @Min(value = 0, message = "参数错误") 23 | @Max(value = 2, message = "参数错误") 24 | private Integer jumpType; 25 | private String jumpUrl; 26 | private String iosUrl; 27 | private String androidUrl; 28 | private String wxaAppid; 29 | @NotNull(message = "请选择状态") 30 | @Min(value = 0, message = "参数错误") 31 | @Max(value = 2, message = "参数错误") 32 | private Integer channelType; 33 | private List channelList; 34 | @NotNull(message = "请选择状态") 35 | @Min(value = 0, message = "参数错误") 36 | @Max(value = 2, message = "参数错误") 37 | private Integer androidVersionType; 38 | private List androidVersionList; 39 | @NotNull(message = "请选择状态") 40 | @Min(value = 0, message = "参数错误") 41 | @Max(value = 2, message = "参数错误") 42 | private Integer iosVersionType; 43 | private List iosVersionList; 44 | private Integer newShowStartNum; 45 | private Integer newShowMaxNum; 46 | private Integer oldShowStartNum; 47 | private Integer oldShowMaxNum; 48 | private Date startTime; 49 | private Date endTime; 50 | private String eventName; 51 | @NotNull(message = "请选择状态") 52 | @Min(value = 0, message = "参数错误") 53 | @Max(value = 1, message = "参数错误") 54 | private Integer status; 55 | 56 | } 57 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/req/ad/AdSiteQueryRequest.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.req.ad; 2 | 3 | import com.lmxdawn.api.admin.req.ListPageRequest; 4 | import lombok.Data; 5 | import lombok.EqualsAndHashCode; 6 | 7 | @EqualsAndHashCode(callSuper = true) 8 | @Data 9 | public class AdSiteQueryRequest extends ListPageRequest { 10 | 11 | private Long siteId; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/req/ad/AdSiteSaveRequest.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.req.ad; 2 | 3 | import lombok.Data; 4 | 5 | import javax.validation.constraints.NotEmpty; 6 | import java.util.Date; 7 | import java.util.List; 8 | 9 | /** 10 | * 广告的保存表单 11 | */ 12 | @Data 13 | public class AdSiteSaveRequest { 14 | 15 | private Long siteId; 16 | @NotEmpty(message = "请输入广告位名称") 17 | private String siteName; 18 | private String describe; 19 | private List adIds; 20 | private Date createTime; 21 | private Date modifiedTime; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/req/auth/AuthAdminQueryRequest.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.req.auth; 2 | 3 | import com.lmxdawn.api.admin.req.ListPageRequest; 4 | import lombok.Data; 5 | import lombok.EqualsAndHashCode; 6 | 7 | import java.util.List; 8 | 9 | @EqualsAndHashCode(callSuper = true) 10 | @Data 11 | public class AuthAdminQueryRequest extends ListPageRequest { 12 | 13 | private String username; 14 | 15 | private Integer status; 16 | 17 | private Long roleId; 18 | 19 | private List ids; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/req/auth/AuthAdminSaveRequest.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.req.auth; 2 | 3 | import lombok.Data; 4 | 5 | import javax.validation.constraints.NotEmpty; 6 | import javax.validation.constraints.NotNull; 7 | import java.util.List; 8 | 9 | /** 10 | * 管理员的提交保存表单 11 | */ 12 | @Data 13 | public class AuthAdminSaveRequest { 14 | // id 15 | private Long id; 16 | // 昵称 17 | @NotEmpty(message = "请输入用户名") 18 | private String username; 19 | // 登录密码 20 | private String password; 21 | // 状态 22 | @NotNull(message = "请选择状态") 23 | private Integer status; 24 | // 角色ids 25 | private List roles; 26 | } 27 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/req/auth/AuthPermissionRuleSaveRequest.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.req.auth; 2 | 3 | import lombok.Data; 4 | 5 | import javax.validation.constraints.NotEmpty; 6 | import javax.validation.constraints.NotNull; 7 | 8 | /** 9 | * 权限规则的提交保存表单 10 | */ 11 | @Data 12 | public class AuthPermissionRuleSaveRequest { 13 | private Long id; 14 | private Long pid; 15 | @NotEmpty(message = "请输入规则名称") 16 | private String name; 17 | @NotEmpty(message = "请输入规则标题") 18 | private String title; 19 | @NotNull(message = "请选择状态") 20 | private Integer status; 21 | private String condition; 22 | private Integer listorder; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/req/auth/AuthRoleAuthRequest.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.req.auth; 2 | 3 | import lombok.Data; 4 | 5 | import javax.validation.constraints.NotEmpty; 6 | import javax.validation.constraints.NotNull; 7 | import java.util.List; 8 | 9 | /** 10 | * 角色的授权提交表单 11 | */ 12 | @Data 13 | public class AuthRoleAuthRequest { 14 | @NotNull(message = "请选择角色") 15 | private Long roleId; 16 | @NotEmpty(message = "请选择授权的权限规则") 17 | private List authRules; 18 | } 19 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/req/auth/AuthRoleQueryRequest.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.req.auth; 2 | 3 | import com.lmxdawn.api.admin.req.ListPageRequest; 4 | import lombok.Data; 5 | import lombok.EqualsAndHashCode; 6 | 7 | /** 8 | * 角色的查询表单 9 | */ 10 | @EqualsAndHashCode(callSuper = true) 11 | @Data 12 | public class AuthRoleQueryRequest extends ListPageRequest { 13 | private String name; 14 | private Integer status; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/req/auth/AuthRoleSaveRequest.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.req.auth; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * 角色的提交保存表单 7 | */ 8 | @Data 9 | public class AuthRoleSaveRequest { 10 | private Long id; 11 | private String name; 12 | private Long pid; 13 | private Long status; 14 | private String remark; 15 | private Long listorder; 16 | } 17 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/req/auth/LoginRequest.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.req.auth; 2 | 3 | import lombok.Data; 4 | 5 | import javax.validation.constraints.NotEmpty; 6 | 7 | /** 8 | * 登录验证 9 | */ 10 | @Data 11 | public class LoginRequest { 12 | 13 | @NotEmpty(message = "用户名不能为空") 14 | private String userName; 15 | 16 | @NotEmpty(message = "密码不能为空") 17 | private String pwd; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/req/auth/UpdatePasswordRequest.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.req.auth; 2 | 3 | import lombok.Data; 4 | 5 | import javax.validation.constraints.NotEmpty; 6 | import javax.validation.constraints.NotNull; 7 | 8 | /** 9 | * 修改密码的表单 10 | */ 11 | @Data 12 | public class UpdatePasswordRequest { 13 | 14 | @NotNull(message = "参数错误!") 15 | private Long adminId; 16 | 17 | @NotEmpty(message = "请输入旧密码") 18 | private String oldPassword; 19 | 20 | @NotEmpty(message = "请输入新密码") 21 | private String newPassword; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/res/PageSimpleResponse.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.res; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * 简单的分页返回对象 9 | */ 10 | @Data 11 | public class PageSimpleResponse { 12 | // 总数 13 | private Long total; 14 | // 列表 15 | private List list; 16 | } 17 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/res/ad/AdResponse.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.res.ad; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Date; 6 | import java.util.List; 7 | 8 | /** 9 | * 后台管理的 广告的 VO 10 | */ 11 | @Data 12 | public class AdResponse { 13 | 14 | private Long adId; 15 | private String title; 16 | private String describe; 17 | private String pic; 18 | private Integer jumpType; 19 | private String jumpUrl; 20 | private String iosUrl; 21 | private String androidUrl; 22 | private String wxaAppid; 23 | private Integer channelType; 24 | private List channelList; 25 | private Integer androidVersionType; 26 | private List androidVersionList; 27 | private Integer iosVersionType; 28 | private List iosVersionList; 29 | private Integer newShowStartNum; 30 | private Integer newShowMaxNum; 31 | private Integer oldShowStartNum; 32 | private Integer oldShowMaxNum; 33 | private Date startTime; 34 | private Date endTime; 35 | private String eventName; 36 | private Integer status; 37 | 38 | } 39 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/res/ad/AdSimpleResponse.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.res.ad; 2 | 3 | import lombok.Data; 4 | 5 | 6 | /** 7 | * 后台管理的 广告的简单的 VO 8 | */ 9 | @Data 10 | public class AdSimpleResponse { 11 | 12 | private Long adId; 13 | private String title; 14 | private String describe; 15 | private Integer status; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/res/ad/AdSiteResponse.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.res.ad; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Date; 6 | import java.util.List; 7 | 8 | /** 9 | * 后台管理的 广告位的 VO 10 | */ 11 | @Data 12 | public class AdSiteResponse { 13 | private Long siteId; 14 | private String siteName; 15 | private String describe; 16 | private List ads; 17 | private Date modifiedTime; 18 | } 19 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/res/auth/AuthAdminResponse.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.res.auth; 2 | 3 | import com.fasterxml.jackson.annotation.JsonInclude; 4 | import lombok.Data; 5 | 6 | import java.util.Date; 7 | import java.util.List; 8 | 9 | /** 10 | * 后台管理的 管理员管理页面的 VO 11 | */ 12 | @Data 13 | @JsonInclude(JsonInclude.Include.NON_NULL) 14 | public class AuthAdminResponse { 15 | 16 | // 主键 17 | private Long id; 18 | // 昵称 19 | private String username; 20 | // 最后登录ip 21 | private String lastLoginIp; 22 | // 最后登录时间 23 | private Date lastLoginTime; 24 | // 状态 25 | private Integer status; 26 | // 角色ids 27 | private List roles; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/res/auth/AuthAdminRoleResponse.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.res.auth; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * 管理员页面的赛选的角色列表 7 | */ 8 | @Data 9 | public class AuthAdminRoleResponse { 10 | 11 | private Long id; 12 | 13 | private String name; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/res/auth/AuthPermissionRuleMergeResponse.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.res.auth; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * 权限列表整合为多维数组的视图 9 | */ 10 | @Data 11 | public class AuthPermissionRuleMergeResponse { 12 | 13 | private Long id; 14 | private Long pid; 15 | private String name; 16 | private String title; 17 | private Long status; 18 | private String condition; 19 | private Long listorder; 20 | 21 | // 一次性加载所有权限规则生成 tree 树形节点时需要 22 | private List children; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/res/auth/AuthRoleResponse.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.res.auth; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * 角色视图 7 | */ 8 | @Data 9 | public class AuthRoleResponse { 10 | 11 | private Long id; 12 | private String name; 13 | private Long pid; 14 | private Long status; 15 | private String remark; 16 | private Long listorder; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/res/auth/LoginUserInfoResponse.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.res.auth; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * 登录用户的信息视图 9 | */ 10 | @Data 11 | public class LoginUserInfoResponse { 12 | 13 | private Long id; 14 | private String username; 15 | private String avatar; 16 | // 权限列表 17 | private List authRules; 18 | } 19 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/service/ad/AdService.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.service.ad; 2 | 3 | 4 | import com.lmxdawn.api.admin.entity.ad.Ad; 5 | import com.lmxdawn.api.admin.req.ad.AdQueryRequest; 6 | 7 | import java.util.List; 8 | 9 | public interface AdService { 10 | 11 | List listAdminPage(AdQueryRequest adQueryRequest); 12 | 13 | List listAdminByAdIdsIn(List adIds); 14 | 15 | boolean insertAd(Ad ad); 16 | 17 | boolean updateAd(Ad ad); 18 | 19 | boolean deleteByAdId(Long id); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/service/ad/AdSiteService.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.service.ad; 2 | 3 | 4 | import com.lmxdawn.api.admin.entity.ad.AdSite; 5 | import com.lmxdawn.api.admin.req.ad.AdSiteQueryRequest; 6 | import com.lmxdawn.api.admin.res.ad.AdSimpleResponse; 7 | 8 | import java.util.List; 9 | 10 | public interface AdSiteService { 11 | 12 | List listAdminPage(AdSiteQueryRequest adSiteQueryRequest); 13 | 14 | List listAdminByAdIdsIn(List adIds); 15 | 16 | boolean insertAdSite(AdSite adSite); 17 | 18 | boolean updateAdSite(AdSite adSite); 19 | 20 | boolean deleteBySiteId(Long siteId); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/service/ad/impl/AdServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.service.ad.impl; 2 | 3 | import com.github.pagehelper.PageHelper; 4 | import com.lmxdawn.api.admin.dao.ad.AdDao; 5 | import com.lmxdawn.api.admin.entity.ad.Ad; 6 | import com.lmxdawn.api.admin.req.ad.AdQueryRequest; 7 | import com.lmxdawn.api.admin.service.ad.AdService; 8 | import org.springframework.stereotype.Service; 9 | 10 | import javax.annotation.Resource; 11 | import java.util.Collections; 12 | import java.util.List; 13 | 14 | @Service 15 | public class AdServiceImpl implements AdService { 16 | 17 | @Resource 18 | private AdDao adDao; 19 | 20 | @Override 21 | public List listAdminPage(AdQueryRequest adQueryRequest) { 22 | if (adQueryRequest == null) { 23 | return Collections.emptyList(); 24 | } 25 | int offset = (adQueryRequest.getPage() - 1) * adQueryRequest.getLimit(); 26 | PageHelper.offsetPage(offset, adQueryRequest.getLimit()); 27 | return adDao.listAdmin(adQueryRequest); 28 | } 29 | 30 | @Override 31 | public List listAdminByAdIdsIn(List adIds) { 32 | return adDao.listAdminByAdIdsIn(adIds); 33 | } 34 | 35 | @Override 36 | public boolean insertAd(Ad ad) { 37 | return adDao.insertAd(ad); 38 | } 39 | 40 | @Override 41 | public boolean updateAd(Ad ad) { 42 | return adDao.updateAd(ad); 43 | } 44 | 45 | @Override 46 | public boolean deleteByAdId(Long adId) { 47 | return adDao.deleteByAdId(adId); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/service/ad/impl/AdSiteServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.service.ad.impl; 2 | 3 | import com.github.pagehelper.PageHelper; 4 | import com.lmxdawn.api.admin.dao.ad.AdDao; 5 | import com.lmxdawn.api.admin.dao.ad.AdSiteDao; 6 | import com.lmxdawn.api.admin.entity.ad.AdSite; 7 | import com.lmxdawn.api.admin.req.ad.AdSiteQueryRequest; 8 | import com.lmxdawn.api.admin.service.ad.AdSiteService; 9 | import com.lmxdawn.api.admin.res.ad.AdSimpleResponse; 10 | import org.springframework.beans.BeanUtils; 11 | import org.springframework.stereotype.Service; 12 | 13 | import javax.annotation.Resource; 14 | import java.util.Collections; 15 | import java.util.List; 16 | import java.util.stream.Collectors; 17 | 18 | @Service 19 | public class AdSiteServiceImpl implements AdSiteService { 20 | 21 | @Resource 22 | private AdDao adDao; 23 | 24 | @Resource 25 | private AdSiteDao adSiteDao; 26 | 27 | @Override 28 | public List listAdminPage(AdSiteQueryRequest adSiteQueryRequest) { 29 | if (adSiteQueryRequest == null) { 30 | return Collections.emptyList(); 31 | } 32 | int offset = (adSiteQueryRequest.getPage() - 1) * adSiteQueryRequest.getLimit(); 33 | PageHelper.offsetPage(offset, adSiteQueryRequest.getLimit()); 34 | 35 | return adSiteDao.listAdmin(adSiteQueryRequest); 36 | } 37 | 38 | @Override 39 | public List listAdminByAdIdsIn(List adIds) { 40 | if (adIds.isEmpty()) { 41 | return Collections.emptyList(); 42 | } 43 | List adSimpleResponseList = adDao.listAdminByAdIdsIn(adIds).stream() 44 | .map(item -> { 45 | AdSimpleResponse adSimpleResponse = new AdSimpleResponse(); 46 | BeanUtils.copyProperties(item, adSimpleResponse); 47 | return adSimpleResponse; 48 | }).collect(Collectors.toList()); 49 | 50 | return adSimpleResponseList; 51 | } 52 | 53 | @Override 54 | public boolean insertAdSite(AdSite adSite) { 55 | return adSiteDao.insertAdSite(adSite); 56 | } 57 | 58 | @Override 59 | public boolean updateAdSite(AdSite adSite) { 60 | return adSiteDao.updateAdSite(adSite); 61 | } 62 | 63 | @Override 64 | public boolean deleteBySiteId(Long siteId) { 65 | return adSiteDao.deleteBySiteId(siteId); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/service/auth/AuthAdminService.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.service.auth; 2 | 3 | 4 | import com.lmxdawn.api.admin.entity.auth.AuthAdmin; 5 | import com.lmxdawn.api.admin.req.auth.AuthAdminQueryRequest; 6 | 7 | import java.util.List; 8 | 9 | public interface AuthAdminService { 10 | 11 | List listAdminPage(AuthAdminQueryRequest authAdminQueryRequest); 12 | 13 | AuthAdmin findByUserName(String userName); 14 | 15 | 16 | AuthAdmin findById(Long id); 17 | 18 | 19 | AuthAdmin findPwdById(Long id); 20 | 21 | boolean insertAuthAdmin(AuthAdmin authAdmin); 22 | 23 | boolean updateAuthAdmin(AuthAdmin authAdmin); 24 | 25 | boolean deleteById(Long id); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/service/auth/AuthLoginService.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.service.auth; 2 | 3 | import java.util.List; 4 | 5 | public interface AuthLoginService { 6 | 7 | List listRuleByAdminId(Long adminId); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/service/auth/AuthPermissionRuleService.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.service.auth; 2 | 3 | 4 | import com.lmxdawn.api.admin.entity.auth.AuthPermissionRule; 5 | 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | public interface AuthPermissionRuleService { 10 | 11 | 12 | List listByIdIn(List ids); 13 | 14 | 15 | List listByPid(Long pid); 16 | 17 | List listAll(); 18 | 19 | boolean insertAuthPermissionRule(AuthPermissionRule authPermissionRule); 20 | 21 | boolean updateAuthPermissionRule(AuthPermissionRule authPermissionRule); 22 | 23 | boolean deleteById(Long id); 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/service/auth/AuthPermissionService.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.service.auth; 2 | 3 | 4 | import com.lmxdawn.api.admin.entity.auth.AuthPermission; 5 | 6 | import java.util.List; 7 | 8 | public interface AuthPermissionService { 9 | 10 | 11 | List listByRoleIdIn(List roleIds); 12 | 13 | List listByRoleId(Long roleId); 14 | 15 | int insertAuthPermissionAll(List authPermissionList); 16 | 17 | boolean deleteByRoleId(Long roleId); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/service/auth/AuthRoleAdminService.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.service.auth; 2 | 3 | 4 | import com.lmxdawn.api.admin.entity.auth.AuthRoleAdmin; 5 | 6 | import java.util.List; 7 | 8 | public interface AuthRoleAdminService { 9 | 10 | List listByAdminId(Long adminId); 11 | 12 | List listByAdminIdIn(List adminIds); 13 | 14 | List listByRoleId(Long roleId); 15 | 16 | int insertAuthRoleAdminAll(List authRoleAdminList); 17 | 18 | int insertRolesAdminIdAll(List roles, Long adminId); 19 | 20 | boolean deleteByAdminId(Long adminId); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/service/auth/AuthRoleService.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.service.auth; 2 | 3 | 4 | import com.lmxdawn.api.admin.entity.auth.AuthRole; 5 | import com.lmxdawn.api.admin.req.auth.AuthRoleQueryRequest; 6 | 7 | import java.util.List; 8 | 9 | public interface AuthRoleService { 10 | 11 | List listAdminPage(AuthRoleQueryRequest authRoleQueryRequest); 12 | 13 | List listAuthAdminRolePage(Integer page, Integer limit, Integer status); 14 | 15 | AuthRole findByName(String name); 16 | 17 | boolean insertAuthRole(AuthRole authRole); 18 | 19 | boolean updateAuthRole(AuthRole authRole); 20 | 21 | boolean deleteById(Long id); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/service/auth/impl/AuthAdminServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.service.auth.impl; 2 | 3 | import com.github.pagehelper.PageHelper; 4 | import com.lmxdawn.api.admin.dao.auth.AuthAdminDao; 5 | import com.lmxdawn.api.admin.entity.auth.AuthAdmin; 6 | import com.lmxdawn.api.common.enums.ResultEnum; 7 | import com.lmxdawn.api.admin.exception.JsonException; 8 | import com.lmxdawn.api.admin.req.auth.AuthAdminQueryRequest; 9 | import com.lmxdawn.api.admin.service.auth.AuthAdminService; 10 | import org.springframework.stereotype.Service; 11 | 12 | import javax.annotation.Resource; 13 | import java.util.Collections; 14 | import java.util.Date; 15 | import java.util.List; 16 | 17 | @Service 18 | public class AuthAdminServiceImpl implements AuthAdminService { 19 | 20 | @Resource 21 | private AuthAdminDao authAdminDao; 22 | 23 | @Override 24 | public List listAdminPage(AuthAdminQueryRequest authAdminQueryRequest) { 25 | if (authAdminQueryRequest == null) { 26 | return Collections.emptyList(); 27 | } 28 | int offset = (authAdminQueryRequest.getPage() - 1) * authAdminQueryRequest.getLimit(); 29 | PageHelper.offsetPage(offset, authAdminQueryRequest.getLimit()); 30 | return authAdminDao.listAdminPage(authAdminQueryRequest); 31 | } 32 | 33 | @Override 34 | public AuthAdmin findByUserName(String userName) { 35 | return authAdminDao.findByUserName(userName); 36 | } 37 | 38 | /** 39 | * 根据id 获取需要的info 40 | * @param id 41 | * @return 42 | */ 43 | @Override 44 | public AuthAdmin findById(Long id) { 45 | return authAdminDao.findById(id); 46 | } 47 | 48 | /** 49 | * 根据 id 获取密码字段 50 | * @param id 51 | * @return 52 | */ 53 | @Override 54 | public AuthAdmin findPwdById(Long id) { 55 | return authAdminDao.findPwdById(id); 56 | } 57 | 58 | /** 59 | * 新增 60 | * @param authAdmin 61 | * @return 62 | */ 63 | @Override 64 | public boolean insertAuthAdmin(AuthAdmin authAdmin) { 65 | 66 | if (authAdmin.getUsername() != null) { 67 | AuthAdmin byUserName = authAdminDao.findByUserName(authAdmin.getUsername()); 68 | if (byUserName != null) { 69 | throw new JsonException(ResultEnum.DATA_REPEAT, "当前管理员已存在"); 70 | } 71 | } 72 | authAdmin.setCreateTime(new Date()); 73 | return authAdminDao.insertAuthAdmin(authAdmin); 74 | } 75 | 76 | /** 77 | * 更新 78 | * @param authAdmin 79 | * @return 80 | */ 81 | @Override 82 | public boolean updateAuthAdmin(AuthAdmin authAdmin) { 83 | 84 | if (authAdmin.getId() == null) { 85 | return false; 86 | } 87 | // 当用户名不为空时,检查是否存在 88 | if (authAdmin.getUsername() != null) { 89 | AuthAdmin byUserName = authAdminDao.findByUserName(authAdmin.getUsername()); 90 | // 判断是否存在,剔除自己 91 | if (byUserName != null && !authAdmin.getId().equals(byUserName.getId())) { 92 | throw new JsonException(ResultEnum.DATA_REPEAT, "当前管理员已存在"); 93 | } 94 | } 95 | 96 | return authAdminDao.updateAuthAdmin(authAdmin); 97 | } 98 | 99 | /** 100 | * 根据id删除 101 | * @param id 102 | * @return 103 | */ 104 | @Override 105 | public boolean deleteById(Long id) { 106 | return authAdminDao.deleteById(id); 107 | } 108 | 109 | 110 | } 111 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/service/auth/impl/AuthLoginServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.service.auth.impl; 2 | 3 | import com.lmxdawn.api.admin.entity.auth.AuthPermission; 4 | import com.lmxdawn.api.admin.entity.auth.AuthPermissionRule; 5 | import com.lmxdawn.api.admin.entity.auth.AuthRoleAdmin; 6 | import com.lmxdawn.api.admin.service.auth.*; 7 | import com.lmxdawn.api.common.constant.CacheConstant; 8 | import com.lmxdawn.api.admin.util.CacheUtils; 9 | import lombok.extern.slf4j.Slf4j; 10 | import org.springframework.stereotype.Service; 11 | 12 | import javax.annotation.Resource; 13 | import java.util.*; 14 | import java.util.stream.Collectors; 15 | 16 | @Service 17 | @Slf4j 18 | public class AuthLoginServiceImpl implements AuthLoginService { 19 | 20 | @Resource 21 | private AuthRoleAdminService authRoleAdminService; 22 | 23 | @Resource 24 | private AuthPermissionService authPermissionService; 25 | 26 | @Resource 27 | private AuthPermissionRuleService authPermissionRuleService; 28 | 29 | 30 | /** 31 | * 根据 管理员id 获取权限 32 | * @param adminId 33 | * @return 34 | */ 35 | @Override 36 | public List listRuleByAdminId(Long adminId) { 37 | 38 | List authRules = new ArrayList<>(); 39 | // 超级管理员 40 | if (adminId.equals(1L)) { 41 | authRules.add("admin"); 42 | return authRules; 43 | } 44 | 45 | // 如果存在,先从缓存中获取权限 46 | String aarKey = String.format(CacheConstant.ADMIN_AUTH_RULES, adminId); 47 | if (CacheUtils.hasKey(aarKey)) { 48 | return new ArrayList<>(CacheUtils.sGetMembers(aarKey)); 49 | } 50 | log.info("开始获取数据库中的用户的权限规则列表"); 51 | 52 | // 获取角色ids 53 | List authRoleAdmins = authRoleAdminService.listByAdminId(adminId); 54 | 55 | List roleIds = authRoleAdmins.stream().map(AuthRoleAdmin::getRoleId).collect(Collectors.toList()); 56 | 57 | // 角色授权列表 58 | List authPermissions = authPermissionService.listByRoleIdIn(roleIds); 59 | List permissionRuleIds = authPermissions.stream().map(AuthPermission::getPermissionRuleId).collect(Collectors.toList()); 60 | 61 | // 获取授权的规则 62 | List authPermissionRules = authPermissionRuleService.listByIdIn(permissionRuleIds); 63 | 64 | // 获取权限列表 65 | authRules = authPermissionRules.stream().map(AuthPermissionRule::getName).collect(Collectors.toList()); 66 | 67 | // 如果为空,则添加一个空值 68 | if (authRules.isEmpty()) { 69 | authRules.add(""); 70 | } 71 | 72 | String[] strings = authRules.toArray(new String[0]); 73 | CacheUtils.sAdd(aarKey, strings); 74 | CacheUtils.expire(aarKey, 7200L); // 两小时后过期 75 | 76 | return authRules; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/service/auth/impl/AuthPermissionRuleServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.service.auth.impl; 2 | 3 | import com.lmxdawn.api.admin.dao.auth.AuthPermissionRuleDao; 4 | import com.lmxdawn.api.admin.entity.auth.AuthPermissionRule; 5 | import com.lmxdawn.api.common.enums.ResultEnum; 6 | import com.lmxdawn.api.admin.exception.JsonException; 7 | import com.lmxdawn.api.admin.service.auth.AuthPermissionRuleService; 8 | import org.springframework.stereotype.Service; 9 | 10 | import javax.annotation.Resource; 11 | import java.util.Collections; 12 | import java.util.Date; 13 | import java.util.List; 14 | 15 | /** 16 | * 17 | */ 18 | @Service 19 | public class AuthPermissionRuleServiceImpl implements AuthPermissionRuleService { 20 | 21 | @Resource 22 | private AuthPermissionRuleDao authPermissionRuleDao; 23 | 24 | /** 25 | * 根据多个id查询 26 | * 27 | * @param ids 28 | * @return 29 | */ 30 | @Override 31 | public List listByIdIn(List ids) { 32 | if (ids.isEmpty()) { 33 | return Collections.emptyList(); 34 | } 35 | return authPermissionRuleDao.listByIdIn(ids); 36 | } 37 | 38 | /** 39 | * 根据父级 pid 查询 40 | * 41 | * @param pid 42 | * @return 43 | */ 44 | @Override 45 | public List listByPid(Long pid) { 46 | return authPermissionRuleDao.listByPid(pid); 47 | } 48 | 49 | /** 50 | * 查询所有 51 | * @return 52 | */ 53 | @Override 54 | public List listAll() { 55 | return authPermissionRuleDao.listAll(); 56 | } 57 | 58 | /** 59 | * 插入 60 | * @param authPermissionRule 61 | * @return 62 | */ 63 | @Override 64 | public boolean insertAuthPermissionRule(AuthPermissionRule authPermissionRule) { 65 | 66 | // 查询是否存在 67 | AuthPermissionRule byName = authPermissionRuleDao.findByName(authPermissionRule.getName()); 68 | if (byName != null) { 69 | throw new JsonException(ResultEnum.DATA_REPEAT, "当前权限规则已存在"); 70 | } 71 | 72 | authPermissionRule.setCreateTime(new Date()); 73 | authPermissionRule.setUpdateTime(new Date()); 74 | if (authPermissionRule.getListorder() == null) { 75 | authPermissionRule.setListorder(999); 76 | } 77 | return authPermissionRuleDao.insertAuthPermissionRule(authPermissionRule); 78 | } 79 | 80 | /** 81 | * 更新 82 | * @param authPermissionRule 83 | * @return 84 | */ 85 | @Override 86 | public boolean updateAuthPermissionRule(AuthPermissionRule authPermissionRule) { 87 | 88 | if (authPermissionRule.getName() != null) { 89 | // 查询是否存在 90 | AuthPermissionRule byName = authPermissionRuleDao.findByName(authPermissionRule.getName()); 91 | if (byName != null && !authPermissionRule.getId().equals(byName.getId())) { 92 | throw new JsonException(ResultEnum.DATA_REPEAT, "当前权限规则已存在"); 93 | } 94 | } 95 | 96 | authPermissionRule.setUpdateTime(new Date()); 97 | return authPermissionRuleDao.updateAuthPermissionRule(authPermissionRule); 98 | } 99 | 100 | /** 101 | * 删除 102 | * 103 | * @param id 104 | * @return 105 | */ 106 | @Override 107 | public boolean deleteById(Long id) { 108 | return authPermissionRuleDao.deleteById(id); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/service/auth/impl/AuthPermissionServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.service.auth.impl; 2 | 3 | import com.lmxdawn.api.admin.dao.auth.AuthPermissionDao; 4 | import com.lmxdawn.api.admin.entity.auth.AuthPermission; 5 | import com.lmxdawn.api.admin.service.auth.AuthPermissionService; 6 | import org.springframework.stereotype.Service; 7 | 8 | import javax.annotation.Resource; 9 | import java.util.Collections; 10 | import java.util.List; 11 | 12 | @Service 13 | public class AuthPermissionServiceImpl implements AuthPermissionService { 14 | 15 | @Resource 16 | private AuthPermissionDao authPermissionDao; 17 | 18 | /** 19 | * 根据 多个角色id 查询 20 | * @param roleIds 21 | * @return 22 | */ 23 | @Override 24 | public List listByRoleIdIn(List roleIds) { 25 | if (roleIds.isEmpty()) { 26 | return Collections.emptyList(); 27 | } 28 | return authPermissionDao.listByRoleIdIn(roleIds); 29 | } 30 | 31 | /** 32 | * 根据某个角色id 查询 33 | * @param roleId 34 | * @return 35 | */ 36 | @Override 37 | public List listByRoleId(Long roleId) { 38 | return authPermissionDao.listByRoleId(roleId); 39 | } 40 | 41 | /** 42 | * 批量插入 43 | * @param authPermissionList 44 | * @return 45 | */ 46 | @Override 47 | public int insertAuthPermissionAll(List authPermissionList) { 48 | return authPermissionDao.insertAuthPermissionAll(authPermissionList); 49 | } 50 | 51 | /** 52 | * 根据角色id删除 53 | * @param roleId 54 | * @return 55 | */ 56 | @Override 57 | public boolean deleteByRoleId(Long roleId) { 58 | return authPermissionDao.deleteByRoleId(roleId); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/service/auth/impl/AuthRoleAdminServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.service.auth.impl; 2 | 3 | import com.lmxdawn.api.admin.dao.auth.AuthRoleAdminDao; 4 | import com.lmxdawn.api.admin.entity.auth.AuthRoleAdmin; 5 | import com.lmxdawn.api.admin.service.auth.AuthRoleAdminService; 6 | import com.lmxdawn.api.common.constant.CacheConstant; 7 | import com.lmxdawn.api.admin.util.CacheUtils; 8 | import org.springframework.stereotype.Service; 9 | 10 | import javax.annotation.Resource; 11 | import java.util.Collections; 12 | import java.util.List; 13 | import java.util.stream.Collectors; 14 | 15 | @Service 16 | public class AuthRoleAdminServiceImpl implements AuthRoleAdminService { 17 | 18 | @Resource 19 | private AuthRoleAdminDao authRoleAdminDao; 20 | 21 | /** 22 | * 根据 adminid 获取角色id 23 | * @param adminId 24 | * @return 25 | */ 26 | @Override 27 | public List listByAdminId(Long adminId) { 28 | return authRoleAdminDao.listByAdminId(adminId); 29 | } 30 | 31 | /** 32 | * 根据多个 adminId 查询角色列表 33 | * @param adminIds 34 | * @return 35 | */ 36 | @Override 37 | public List listByAdminIdIn(List adminIds) { 38 | if (adminIds.isEmpty()) { 39 | return Collections.emptyList(); 40 | } 41 | return authRoleAdminDao.listByAdminIdIn(adminIds); 42 | } 43 | 44 | /** 45 | * 根据 roleId 获取 管理员id 46 | * @param roleId 47 | * @return 48 | */ 49 | @Override 50 | public List listByRoleId(Long roleId) { 51 | return authRoleAdminDao.listByRoleId(roleId); 52 | } 53 | 54 | /** 55 | * 批量插入 56 | * @param authRoleAdminList 57 | * @return 58 | */ 59 | @Override 60 | public int insertAuthRoleAdminAll(List authRoleAdminList) { 61 | 62 | if (authRoleAdminList == null || authRoleAdminList.isEmpty()) { 63 | return 0; 64 | } 65 | 66 | return authRoleAdminDao.insertAuthRoleAdminAll(authRoleAdminList); 67 | } 68 | 69 | /** 70 | * 根据 角色ids 和 管理员 adminId 批量插入 71 | * @param roles 72 | * @param adminId 73 | * @return 74 | */ 75 | @Override 76 | public int insertRolesAdminIdAll(List roles, Long adminId) { 77 | 78 | List authRoleAdminList = roles.stream().map(aLong -> { 79 | AuthRoleAdmin authRoleAdmin = new AuthRoleAdmin(); 80 | authRoleAdmin.setRoleId(aLong); 81 | authRoleAdmin.setAdminId(adminId); 82 | return authRoleAdmin; 83 | }).collect(Collectors.toList()); 84 | if (!authRoleAdminList.isEmpty()) { 85 | return insertAuthRoleAdminAll(authRoleAdminList); 86 | } 87 | 88 | return 0; 89 | } 90 | 91 | /** 92 | * 根据 adminId 删除对应的权限 93 | * @param adminId 94 | * @return 95 | */ 96 | @Override 97 | public boolean deleteByAdminId(Long adminId) { 98 | 99 | // 删除之前缓存权限规则 100 | String aarKey = String.format(CacheConstant.ADMIN_AUTH_RULES, adminId); 101 | CacheUtils.delete(aarKey); 102 | 103 | return authRoleAdminDao.deleteByAdminId(adminId); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/service/auth/impl/AuthRoleServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.service.auth.impl; 2 | 3 | import com.github.pagehelper.PageHelper; 4 | import com.lmxdawn.api.admin.dao.auth.AuthRoleDao; 5 | import com.lmxdawn.api.admin.entity.auth.AuthRole; 6 | import com.lmxdawn.api.admin.req.auth.AuthRoleQueryRequest; 7 | import com.lmxdawn.api.admin.service.auth.AuthRoleService; 8 | import org.springframework.stereotype.Service; 9 | 10 | import javax.annotation.Resource; 11 | import java.util.Date; 12 | import java.util.List; 13 | 14 | @Service 15 | public class AuthRoleServiceImpl implements AuthRoleService { 16 | 17 | @Resource 18 | private AuthRoleDao authRoleDao; 19 | 20 | /** 21 | * 查询列表 22 | * @return 23 | */ 24 | @Override 25 | public List listAdminPage(AuthRoleQueryRequest authRoleQueryRequest) { 26 | int offset = (authRoleQueryRequest.getPage() - 1) * authRoleQueryRequest.getLimit(); 27 | PageHelper.offsetPage(offset, authRoleQueryRequest.getLimit()); 28 | List list = authRoleDao.listAdminPage(authRoleQueryRequest); 29 | return list; 30 | } 31 | 32 | /** 33 | * 查询管理员页面的列表 34 | * @param page 35 | * @param limit 36 | * @param status 37 | * @return 38 | */ 39 | @Override 40 | public List listAuthAdminRolePage(Integer page, Integer limit, Integer status) { 41 | page = page != null && page > 0 ? page : 1; 42 | limit = limit != null && limit > 0 && limit < 100 ? limit : 100; 43 | int offset = (page - 1) * limit; 44 | PageHelper.offsetPage(offset, limit); 45 | List list = authRoleDao.listAuthAdminRolePage(status); 46 | return list; 47 | } 48 | 49 | /** 50 | * 根据名称查询 51 | * @param name 52 | * @return 53 | */ 54 | @Override 55 | public AuthRole findByName(String name) { 56 | return authRoleDao.findByName(name); 57 | } 58 | 59 | /** 60 | * 插入 61 | * @param authRole 62 | * @return 63 | */ 64 | @Override 65 | public boolean insertAuthRole(AuthRole authRole) { 66 | 67 | authRole.setCreateTime(new Date()); 68 | authRole.setUpdateTime(new Date()); 69 | 70 | return authRoleDao.insertAuthRole(authRole); 71 | } 72 | 73 | /** 74 | * 修改 75 | * @param authRole 76 | * @return 77 | */ 78 | @Override 79 | public boolean updateAuthRole(AuthRole authRole) { 80 | authRole.setUpdateTime(new Date()); 81 | return authRoleDao.updateAuthRole(authRole); 82 | } 83 | 84 | /** 85 | * 删除 86 | * @param id 87 | * @return 88 | */ 89 | @Override 90 | public boolean deleteById(Long id) { 91 | return authRoleDao.deleteById(id); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/util/CacheUtils.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.util; 2 | 3 | import java.util.Collection; 4 | import java.util.Set; 5 | import java.util.concurrent.TimeUnit; 6 | 7 | import javax.annotation.PostConstruct; 8 | 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.data.redis.core.RedisTemplate; 11 | import org.springframework.stereotype.Component; 12 | 13 | /** 14 | * 缓存操作类 15 | */ 16 | @Component 17 | public class CacheUtils { 18 | @Autowired 19 | private RedisTemplate redisTemplate; 20 | 21 | // 维护一个本类的静态变量 22 | private static CacheUtils cacheUtils; 23 | 24 | @PostConstruct 25 | public void init() { 26 | cacheUtils = this; 27 | cacheUtils.redisTemplate = this.redisTemplate; 28 | } 29 | 30 | /** 31 | * 将参数中的字符串值设置为键的值,不设置过期时间 32 | * @param key 33 | * @param value 必须要实现 Serializable 接口 34 | */ 35 | public static void set(String key, String value) { 36 | cacheUtils.redisTemplate.opsForValue().set(key, value); 37 | } 38 | 39 | /** 40 | * 将参数中的字符串值设置为键的值,设置过期时间 41 | * @param key 42 | * @param value 必须要实现 Serializable 接口 43 | * @param timeout 44 | */ 45 | public static void set(String key, String value, Long timeout) { 46 | cacheUtils.redisTemplate.opsForValue().set(key, value, timeout, TimeUnit.SECONDS); 47 | } 48 | 49 | /** 50 | * 获取与指定键相关的值 51 | * @param key 52 | * @return 53 | */ 54 | public static Object get(String key) { 55 | return cacheUtils.redisTemplate.opsForValue().get(key); 56 | } 57 | 58 | /** 59 | * 设置某个键的过期时间 60 | * @param key 键值 61 | * @param ttl 过期秒数 62 | */ 63 | public static boolean expire(String key, Long ttl) { 64 | return cacheUtils.redisTemplate.expire(key, ttl, TimeUnit.SECONDS); 65 | } 66 | 67 | /** 68 | * 判断某个键是否存在 69 | * @param key 键值 70 | */ 71 | public static boolean hasKey(String key) { 72 | return cacheUtils.redisTemplate.hasKey(key); 73 | } 74 | 75 | /** 76 | * 向集合添加元素 77 | * @param key 78 | * @param value 79 | * @return 返回值为设置成功的value数 80 | */ 81 | public static Long sAdd(String key, String... value) { 82 | return cacheUtils.redisTemplate.opsForSet().add(key, value); 83 | } 84 | 85 | /** 86 | * 获取集合中的某个元素 87 | * @param key 88 | * @return 返回值为redis中键值为key的value的Set集合 89 | */ 90 | public static Set sGetMembers(String key) { 91 | return cacheUtils.redisTemplate.opsForSet().members(key); 92 | } 93 | 94 | /** 95 | * 将给定分数的指定成员添加到键中存储的排序集合中 96 | * @param key 97 | * @param value 98 | * @param score 99 | * @return 100 | */ 101 | public static Boolean zAdd(String key, String value, double score) { 102 | return cacheUtils.redisTemplate.opsForZSet().add(key, value, score); 103 | } 104 | 105 | /** 106 | * 返回指定排序集中给定成员的分数 107 | * @param key 108 | * @param value 109 | * @return 110 | */ 111 | public static Double zScore(String key, String value) { 112 | return cacheUtils.redisTemplate.opsForZSet().score(key, value); 113 | } 114 | 115 | /** 116 | * 删除指定的键 117 | * @param key 118 | * @return 119 | */ 120 | public static Boolean delete(String key) { 121 | return cacheUtils.redisTemplate.delete(key); 122 | } 123 | 124 | /** 125 | * 删除多个键 126 | * @param keys 127 | * @return 128 | */ 129 | public static Long delete(Collection keys) { 130 | return cacheUtils.redisTemplate.delete(keys); 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/util/IpUtils.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.util; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import java.net.InetAddress; 5 | 6 | public class IpUtils { 7 | 8 | /** 9 | * 获取客户端IP地址 10 | * 11 | * @param request 12 | * @return 13 | */ 14 | public static String getIpAddr(HttpServletRequest request) { 15 | String ip = request.getHeader("x-forwarded-for"); 16 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 17 | ip = request.getHeader("Proxy-Client-IP"); 18 | } 19 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 20 | ip = request.getHeader("WL-Proxy-Client-IP"); 21 | } 22 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 23 | ip = request.getRemoteAddr(); 24 | if (ip.equals("127.0.0.1")) { 25 | //根据网卡取本机配置的IP 26 | InetAddress inet = null; 27 | try { 28 | inet = InetAddress.getLocalHost(); 29 | ip = inet.getHostAddress(); 30 | } catch (Exception e) { 31 | e.printStackTrace(); 32 | } 33 | } 34 | } 35 | // 多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割 36 | if (ip != null && ip.length() > 15) { 37 | if (ip.indexOf(",") > 0) { 38 | ip = ip.substring(0, ip.indexOf(",")); 39 | } 40 | } 41 | return ip; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/util/JwtUtils.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.util; 2 | 3 | import io.jsonwebtoken.*; 4 | import org.apache.tomcat.util.codec.binary.Base64; 5 | 6 | import javax.crypto.SecretKey; 7 | import javax.crypto.spec.SecretKeySpec; 8 | import java.security.Key; 9 | import java.util.Date; 10 | import java.util.Map; 11 | 12 | /** 13 | * jwt 14 | */ 15 | public class JwtUtils { 16 | 17 | /** 18 | * 生成 token 19 | * 20 | * @param claims 自定义的 map 21 | * @param ttl 过期时间 22 | * @return 23 | */ 24 | public static String createToken(Map claims, Long ttl) { 25 | Key key = generateKey(); 26 | SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256; 27 | Long nowMillis = System.currentTimeMillis(); //生成JWT的时间 28 | JwtBuilder builder = Jwts.builder() 29 | .setHeaderParam("typ", "JWT") //设置header 30 | .setHeaderParam("alg", "HS256") 31 | .setClaims(claims) //设置payload的键值对 32 | // .setIssuedAt(now) //设置iat 33 | // .setIssuer("vue-api") 34 | .signWith(signatureAlgorithm, key); //签名,需要算法和key 35 | if (ttl != null && ttl >= 0) { 36 | Long expMillis = nowMillis + ttl * 1000; 37 | Date exp = new Date(expMillis); 38 | builder.setExpiration(exp); //设置过期时间 39 | } 40 | return builder.compact(); 41 | } 42 | 43 | /** 44 | * 生成 token ,没有过期时间 45 | * 46 | * @param claims 自定义的 map 47 | * @return 48 | */ 49 | public static String createToken(Map claims) { 50 | return createToken(claims, null); 51 | } 52 | 53 | /** 54 | * 解密 jwt 55 | * @param jwt 创建的 jwt 字符串 56 | * @return 57 | */ 58 | public static Claims parse(String jwt) { 59 | 60 | if (jwt == null) { 61 | return null; 62 | } 63 | 64 | try { 65 | return Jwts.parser() 66 | .setSigningKey(generateKey()) //此处的key要与之前创建的key一致 67 | .parseClaimsJws(jwt) 68 | .getBody(); 69 | }catch (ExpiredJwtException e){ 70 | return null; 71 | } 72 | } 73 | 74 | /** 75 | * 获取 key 76 | * 77 | * @return 78 | */ 79 | private static SecretKey generateKey() { 80 | String stringKey = "veu-api"; 81 | byte[] encodedKey = Base64.decodeBase64(stringKey); 82 | return new SecretKeySpec(encodedKey, 0, encodedKey.length, "AES"); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/util/PasswordUtils.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.util; 2 | 3 | import org.springframework.util.DigestUtils; 4 | 5 | /** 6 | * 密码相关的工具类 7 | */ 8 | public class PasswordUtils { 9 | 10 | public static String authAdminPwd(String pwd) { 11 | return DigestUtils.md5DigestAsHex(DigestUtils.md5DigestAsHex(pwd.getBytes()).getBytes()); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/util/PermissionRuleTreeUtils.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.util; 2 | 3 | import com.lmxdawn.api.admin.entity.auth.AuthPermissionRule; 4 | import com.lmxdawn.api.admin.res.auth.AuthPermissionRuleMergeResponse; 5 | import org.springframework.beans.BeanUtils; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | /** 11 | * 权限规则生成树形节点工具类 12 | */ 13 | public class PermissionRuleTreeUtils { 14 | 15 | /** 16 | * 多维数组 17 | */ 18 | public static List merge(List authPermissionRuleList, 19 | Long pid) { 20 | 21 | List authPermissionRuleMergeResponseList = new ArrayList<>(); 22 | for (AuthPermissionRule v : authPermissionRuleList) { 23 | AuthPermissionRuleMergeResponse authPermissionRuleMergeResponse = new AuthPermissionRuleMergeResponse(); 24 | BeanUtils.copyProperties(v, authPermissionRuleMergeResponse); 25 | if (pid.equals(v.getPid())) { 26 | authPermissionRuleMergeResponse.setChildren(merge(authPermissionRuleList, v.getId())); 27 | authPermissionRuleMergeResponseList.add(authPermissionRuleMergeResponse); 28 | } 29 | } 30 | 31 | return authPermissionRuleMergeResponseList; 32 | } 33 | 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/util/PublicFileUtils.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.util; 2 | 3 | import com.lmxdawn.api.admin.config.PublicFileUrlConfig; 4 | 5 | /** 6 | * 公共文件管理工具 7 | */ 8 | public class PublicFileUtils { 9 | 10 | public static String createUploadUrl(String filePath) { 11 | 12 | if (filePath == null || filePath.isEmpty()) { 13 | return ""; 14 | } 15 | 16 | if (filePath.indexOf("http") == 0 || filePath.indexOf("/") == 0) { 17 | return filePath; 18 | } 19 | 20 | return PublicFileUrlConfig.getDomain() + "/" + filePath; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/util/TreeUtils.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.util; 2 | 3 | /** 4 | * 树形结构工具类 5 | */ 6 | public class TreeUtils { 7 | 8 | public static void Merge() { 9 | 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /api-admin/src/main/java/com/lmxdawn/api/admin/util/serializer/Date2LongSerializer.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.util.serializer; 2 | 3 | import com.fasterxml.jackson.core.JsonGenerator; 4 | import com.fasterxml.jackson.core.JsonProcessingException; 5 | import com.fasterxml.jackson.databind.JsonSerializer; 6 | import com.fasterxml.jackson.databind.SerializerProvider; 7 | 8 | import java.io.IOException; 9 | import java.util.Date; 10 | 11 | /** 12 | * 毫秒转成秒 13 | * 只需要在需要序列化的属性上面加上这个注解 | @JsonSerialize(using = Date2LongSerializer.class) 14 | */ 15 | public class Date2LongSerializer extends JsonSerializer { 16 | 17 | @Override 18 | public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { 19 | jsonGenerator.writeNumber(date.getTime() / 1000); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /api-admin/src/main/resources/application-dev.properties: -------------------------------------------------------------------------------- 1 | # 本地环境 2 | 3 | server.port=9998 4 | spring.datasource.url=jdbc:mysql://localhost/vue-admin?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull 5 | spring.datasource.username=root 6 | spring.datasource.password=root 7 | server.servlet.context-path= 8 | 9 | logging.level.com.lmxdawn.api.admin.dao=debug 10 | 11 | #公共文件的配置 12 | # 上传的地址 13 | public-file.uploadUrl=https://upload.qiniup.com 14 | # 资源的域名 15 | public-file.domain=https://upload.qiniup.com 16 | 17 | # 跨域设置 18 | cors.allowed-origins=http://localhost:8081 19 | cors.allowed-headers=Content-Type,X-Adminid,X-Token 20 | cors.allowed-methods=GET,POST,OPTIONS 21 | 22 | # Redis数据库索引(默认为0) 23 | spring.redis.database=0 24 | # Redis服务器地址 25 | spring.redis.host=localhost 26 | # Redis服务器连接端口 27 | spring.redis.port=6379 28 | # Redis服务器连接密码(默认为空) 29 | #spring.redis.password= 30 | #连接池最大连接数(使用负值表示没有限制) 31 | #spring.redis.jedis.pool.max-active=8 32 | # 连接池最大阻塞等待时间(使用负值表示没有限制) 33 | #spring.redis.jedis.pool.max-wait= 34 | # 连接池中的最大空闲连接 35 | #spring.redis.jedis.pool.max-idle=8 36 | # 连接池中的最小空闲连接 37 | #spring.redis.jedis.pool.min-idle=0 38 | # 连接超时时间(毫秒) 39 | #spring.redis.timeout=0 -------------------------------------------------------------------------------- /api-admin/src/main/resources/application-pro.properties: -------------------------------------------------------------------------------- 1 | # 生产环境 2 | 3 | server.port=9998 4 | #spring.datasource.url=jdbc:mysql://localhost/vue-api?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull 5 | spring.datasource.url= 6 | spring.datasource.username= 7 | spring.datasource.password= 8 | server.servlet.context-path= 9 | 10 | #公共文件的配置 11 | # 上传的地址 12 | public-file.uploadUrl=https://upload.qiniup.com 13 | # 资源的域名 14 | public-file.domain=https://upload.qiniup.com 15 | 16 | # 跨域设置 17 | cors.allowed-origins=http://pro.com 18 | cors.allowed-headers=Content-Type,X-Adminid,X-Token 19 | cors.allowed-methods=GET,POST,PUT,DELETE,PATCH,OPTIONS 20 | 21 | # Redis数据库索引(默认为0) 22 | spring.redis.database=0 23 | # Redis服务器地址 24 | spring.redis.host=localhost 25 | # Redis服务器连接端口 26 | spring.redis.port=6379 27 | # Redis服务器连接密码(默认为空) 28 | #spring.redis.password= 29 | #连接池最大连接数(使用负值表示没有限制) 30 | #spring.redis.jedis.pool.max-active=8 31 | # 连接池最大阻塞等待时间(使用负值表示没有限制) 32 | #spring.redis.jedis.pool.max-wait= 33 | # 连接池中的最大空闲连接 34 | #spring.redis.jedis.pool.max-idle=8 35 | # 连接池中的最小空闲连接 36 | #spring.redis.jedis.pool.min-idle=0 37 | # 连接超时时间(毫秒) 38 | #spring.redis.timeout=0 -------------------------------------------------------------------------------- /api-admin/src/main/resources/application-test.properties: -------------------------------------------------------------------------------- 1 | # 线上测试环境 2 | 3 | server.port=9998 4 | #spring.datasource.url=jdbc:mysql://localhost/vue-api?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull 5 | spring.datasource.url= 6 | spring.datasource.username= 7 | spring.datasource.password= 8 | server.servlet.context-path= 9 | 10 | logging.level.com.lmxdawn.api.admin.dao=debug 11 | 12 | #公共文件的配置 13 | # 上传的地址 14 | public-file.uploadUrl= 15 | # 资源的域名 16 | public-file.domain= 17 | 18 | # 跨域设置 19 | cors.allowed-origins=http://test.com 20 | cors.allowed-headers=Content-Type,X-Adminid,X-Token 21 | cors.allowed-methods=GET,POST,PUT,DELETE,PATCH,OPTIONS 22 | 23 | # Redis数据库索引(默认为0) 24 | spring.redis.database=0 25 | # Redis服务器地址 26 | spring.redis.host=localhost 27 | # Redis服务器连接端口 28 | spring.redis.port=6379 29 | # Redis服务器连接密码(默认为空) 30 | #spring.redis.password= 31 | #连接池最大连接数(使用负值表示没有限制) 32 | #spring.redis.jedis.pool.max-active=8 33 | # 连接池最大阻塞等待时间(使用负值表示没有限制) 34 | #spring.redis.jedis.pool.max-wait= 35 | # 连接池中的最大空闲连接 36 | #spring.redis.jedis.pool.max-idle=8 37 | # 连接池中的最小空闲连接 38 | #spring.redis.jedis.pool.min-idle=0 39 | # 连接超时时间(毫秒) 40 | #spring.redis.timeout=0 -------------------------------------------------------------------------------- /api-admin/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.profiles.active=dev 2 | 3 | spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver 4 | 5 | mybatis.config-location=classpath:mybatis/mybatis-config.xml 6 | mybatis.mapper-locations=classpath:mybatis/mapper/*/*.xml -------------------------------------------------------------------------------- /api-admin/src/main/resources/mybatis/mapper/ad/AdDao.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 27 | 28 | 29 | INSERT INTO ad(title,`describe`,pic,jump_type,jump_url,ios_url,android_url,wxa_appid,channel_type,channel_list,android_version_type,android_version_list,ios_version_type,ios_version_list,new_show_start_num,new_show_max_num,old_show_start_num,old_show_max_num,start_time,end_time,event_name,`status`,create_time,modified_time) 30 | values 31 | (#{title}, 32 | 33 | 34 | #{describe}, 35 | 36 | 37 | '', 38 | 39 | 40 | #{pic}, 41 | #{jumpType}, 42 | 43 | 44 | #{jumpUrl}, 45 | 46 | 47 | '', 48 | 49 | 50 | 51 | 52 | #{iosUrl}, 53 | 54 | 55 | '', 56 | 57 | 58 | 59 | 60 | #{androidUrl}, 61 | 62 | 63 | '', 64 | 65 | 66 | 67 | 68 | #{wxaAppid}, 69 | 70 | 71 | '', 72 | 73 | 74 | 75 | 76 | 77 | #{channelType}, 78 | 79 | 80 | 0, 81 | 82 | 83 | 84 | 85 | #{channelList}, 86 | 87 | 88 | '', 89 | 90 | 91 | 92 | 93 | #{androidVersionType}, 94 | 95 | 96 | 0, 97 | 98 | 99 | 100 | 101 | #{androidVersionList}, 102 | 103 | 104 | '', 105 | 106 | 107 | 108 | 109 | #{iosVersionType}, 110 | 111 | 112 | 0, 113 | 114 | 115 | 116 | 117 | #{iosVersionList}, 118 | 119 | 120 | '', 121 | 122 | 123 | 124 | 125 | 126 | #{newShowStartNum}, 127 | 128 | 129 | 0, 130 | 131 | 132 | 133 | 134 | #{newShowStartNum}, 135 | 136 | 137 | 0, 138 | 139 | 140 | 141 | 142 | #{oldShowStartNum}, 143 | 144 | 145 | 0, 146 | 147 | 148 | 149 | 150 | #{oldShowStartNum}, 151 | 152 | 153 | 0, 154 | 155 | 156 | #{startTime}, 157 | #{endTime}, 158 | 159 | 160 | #{eventName}, 161 | 162 | 163 | '', 164 | 165 | 166 | #{status}, 167 | #{createTime}, 168 | #{modifiedTime}) 169 | 170 | 171 | 172 | UPDATE ad 173 | 174 | `title`=#{title}, 175 | `describe`=#{describe}, 176 | pic=#{pic}, 177 | jump_type=#{jumpType}, 178 | jump_url=#{jumpUrl}, 179 | ios_url=#{iosUrl}, 180 | android_url=#{androidUrl}, 181 | wxa_appid=#{wxaAppid}, 182 | channel_type=#{channelType}, 183 | channel_list=#{channelList}, 184 | android_version_type=#{androidVersionType}, 185 | android_version_list=#{androidVersionList}, 186 | ios_version_type=#{iosVersionType}, 187 | ios_version_list=#{iosVersionList}, 188 | new_show_start_num=#{newShowStartNum}, 189 | new_show_max_num=#{newShowMaxNum}, 190 | old_show_start_num=#{oldShowStartNum}, 191 | old_show_max_num=#{oldShowMaxNum}, 192 | start_time=#{startTime}, 193 | end_time=#{endTime}, 194 | event_name=#{eventName}, 195 | status=#{status}, 196 | modified_time=#{modifiedTime} 197 | 198 | WHERE ad_id=#{adId} 199 | 200 | 201 | 202 | delete from ad where ad_id = #{adId} 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | -------------------------------------------------------------------------------- /api-admin/src/main/resources/mybatis/mapper/ad/AdSiteDao.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | INSERT INTO ad_site(site_name,`describe`,ad_ids,create_time,modified_time) 20 | values 21 | (#{siteName}, 22 | 23 | 24 | #{describe}, 25 | 26 | 27 | '', 28 | 29 | 30 | 31 | 32 | #{adIds}, 33 | 34 | 35 | '', 36 | 37 | 38 | #{createTime}, 39 | #{modifiedTime}) 40 | 41 | 42 | 43 | UPDATE ad_site 44 | 45 | site_name=#{siteName}, 46 | `describe`=#{describe}, 47 | ad_ids=#{adIds}, 48 | modified_time=#{modifiedTime} 49 | 50 | WHERE site_id=#{siteId} 51 | 52 | 53 | 54 | delete from ad_site where site_id = #{siteId} 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /api-admin/src/main/resources/mybatis/mapper/auth/AuthAdminDao.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 26 | 27 | 35 | 36 | 44 | 45 | 53 | 54 | 55 | INSERT INTO auth_admin(username,password,tel,email,avatar,sex,last_login_ip,last_login_time,create_time,status) 56 | values 57 | (#{username}, 58 | 59 | 60 | #{password}, 61 | 62 | 63 | '', 64 | 65 | 66 | 67 | 68 | #{tel}, 69 | 70 | 71 | '', 72 | 73 | 74 | 75 | 76 | #{email}, 77 | 78 | 79 | '', 80 | 81 | 82 | 83 | 84 | #{avatar}, 85 | 86 | 87 | '', 88 | 89 | 90 | 91 | 92 | #{sex}, 93 | 94 | 95 | 0, 96 | 97 | 98 | 99 | 100 | #{lastLoginIp}, 101 | 102 | 103 | '', 104 | 105 | 106 | 107 | 108 | #{lastLoginTime}, 109 | 110 | 111 | '0001-01-01 00:00:00', 112 | 113 | 114 | #{createTime}, 115 | #{status,jdbcType=INTEGER}) 116 | 117 | 118 | 119 | UPDATE auth_admin 120 | 121 | username=#{username}, 122 | avatar=#{avatar}, 123 | password=#{password}, 124 | last_login_ip=#{lastLoginIp}, 125 | last_login_time=#{lastLoginTime} 126 | status=#{status} 127 | 128 | WHERE id=#{id} 129 | 130 | 131 | 132 | delete from auth_admin where id = #{id} 133 | 134 | 135 | -------------------------------------------------------------------------------- /api-admin/src/main/resources/mybatis/mapper/auth/AuthPermissionDao.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 14 | 15 | 20 | 21 | 22 | 23 | INSERT INTO auth_permission 24 | (role_id, permission_rule_id,`type`) 25 | VALUES 26 | 27 | 28 | (#{item.roleId}, #{item.permissionRuleId}, #{item.type}) 29 | 30 | 31 | 32 | 33 | 34 | 35 | delete from auth_permission where role_id = #{roleId} 36 | 37 | 38 | -------------------------------------------------------------------------------- /api-admin/src/main/resources/mybatis/mapper/auth/AuthPermissionRuleDao.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 14 | 15 | 20 | 21 | 25 | 26 | 32 | 33 | 34 | INSERT INTO auth_permission_rule(pid,`name`,`title`,`status`,`condition`,`listorder`,create_time,update_time) 35 | values 36 | (#{pid}, 37 | #{name}, 38 | #{title}, 39 | #{status}, 40 | 41 | 42 | #{condition}, 43 | 44 | 45 | '', 46 | 47 | 48 | #{listorder}, 49 | #{createTime}, 50 | #{updateTime}) 51 | 52 | 53 | 54 | UPDATE auth_permission_rule 55 | 56 | pid=#{pid}, 57 | `name`=#{name}, 58 | title=#{title}, 59 | `status`=#{status}, 60 | `condition`=#{condition}, 61 | `listorder`=#{listorder}, 62 | update_time=#{updateTime}, 63 | 64 | WHERE id=#{id} 65 | 66 | 67 | 68 | delete from auth_permission_rule where id = #{id} 69 | 70 | 71 | -------------------------------------------------------------------------------- /api-admin/src/main/resources/mybatis/mapper/auth/AuthRoleAdminDao.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 11 | 12 | 20 | 21 | 26 | 27 | 28 | INSERT INTO auth_role_admin 29 | (role_id, admin_id) 30 | VALUES 31 | 32 | 33 | (#{item.roleId}, #{item.adminId}) 34 | 35 | 36 | 37 | 38 | 39 | delete from auth_role_admin where admin_id = #{adminId} 40 | 41 | 42 | -------------------------------------------------------------------------------- /api-admin/src/main/resources/mybatis/mapper/auth/AuthRoleDao.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 19 | 20 | 29 | 30 | 35 | 36 | 37 | 38 | INSERT INTO auth_role(`name`,pid,`status`,`remark`,`listorder`,create_time,update_time) 39 | values 40 | ( 41 | #{name}, 42 | 43 | 44 | #{pid}, 45 | 46 | 47 | 0, 48 | 49 | 50 | #{status}, 51 | 52 | 53 | #{remark}, 54 | 55 | 56 | '', 57 | 58 | 59 | 60 | 61 | #{listorder}, 62 | 63 | 64 | 999, 65 | 66 | 67 | #{createTime}, 68 | #{updateTime} 69 | ) 70 | 71 | 72 | 73 | UPDATE auth_role 74 | 75 | `name`=#{name}, 76 | pid=#{pid}, 77 | `status`=#{status}, 78 | remark=#{remark}, 79 | `listorder`=#{listorder}, 80 | update_time=#{updateTime}, 81 | 82 | WHERE id=#{id} 83 | 84 | 85 | 86 | delete from auth_role where id = #{id} 87 | 88 | 89 | -------------------------------------------------------------------------------- /api-admin/src/main/resources/mybatis/mybatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /api-admin/src/main/resources/static/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /api-admin/src/main/resources/templates/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /api-admin/src/test/java/com/lmxdawn/api/BaseApiAdminApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api; 2 | 3 | import org.junit.runner.RunWith; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | import org.springframework.test.context.junit4.SpringRunner; 6 | 7 | @RunWith(SpringRunner.class) 8 | @SpringBootTest 9 | public class BaseApiAdminApplicationTest { 10 | } 11 | -------------------------------------------------------------------------------- /api-admin/src/test/java/com/lmxdawn/api/admin/service/auth/impl/AuthAdminServiceImplTest.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.service.auth.impl; 2 | 3 | import com.github.pagehelper.PageInfo; 4 | import com.lmxdawn.api.BaseApiAdminApplicationTest; 5 | import com.lmxdawn.api.admin.entity.auth.AuthAdmin; 6 | import com.lmxdawn.api.admin.req.auth.AuthAdminQueryRequest; 7 | import com.lmxdawn.api.admin.service.auth.AuthAdminService; 8 | import org.junit.Test; 9 | 10 | import javax.annotation.Resource; 11 | 12 | import java.util.*; 13 | 14 | import static org.junit.Assert.*; 15 | 16 | public class AuthAdminServiceImplTest extends BaseApiAdminApplicationTest { 17 | 18 | @Resource 19 | private AuthAdminService authAdminService; 20 | 21 | @Test 22 | public void listAdminPage() { 23 | 24 | Integer page = 1; 25 | Integer limit = 20; 26 | Integer status = 1; 27 | String username = "api"; 28 | Long roleId = 1L; 29 | 30 | AuthAdminQueryRequest authAdminQueryForm = new AuthAdminQueryRequest(); 31 | authAdminQueryForm.setPage(page); 32 | authAdminQueryForm.setLimit(limit); 33 | authAdminQueryForm.setStatus(status); 34 | authAdminQueryForm.setUsername(username); 35 | 36 | List authAdminList = authAdminService.listAdminPage(authAdminQueryForm); 37 | PageInfo authAdminPageInfo = new PageInfo<>(authAdminList); 38 | System.out.println(authAdminPageInfo.getList()); 39 | assertTrue(authAdminPageInfo.getList().size() > 0); 40 | } 41 | 42 | @Test 43 | public void findByUserName() { 44 | } 45 | 46 | @Test 47 | public void findById() { 48 | } 49 | 50 | @Test 51 | public void findPwdById() { 52 | } 53 | 54 | @Test 55 | public void insertAuthAdmin() { 56 | 57 | AuthAdmin authAdmin = new AuthAdmin(); 58 | authAdmin.setUsername("sssfff4"); 59 | authAdmin.setCreateTime(new Date()); 60 | authAdmin.setStatus(1); 61 | 62 | boolean b = authAdminService.insertAuthAdmin(authAdmin); 63 | assertTrue(b); 64 | } 65 | 66 | @Test 67 | public void updateAuthAdmin() { 68 | } 69 | 70 | } -------------------------------------------------------------------------------- /api-admin/src/test/java/com/lmxdawn/api/admin/service/auth/impl/AuthLoginServiceImplTest.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.service.auth.impl; 2 | 3 | import com.lmxdawn.api.BaseApiAdminApplicationTest; 4 | import com.lmxdawn.api.admin.service.auth.AuthLoginService; 5 | import org.junit.Test; 6 | 7 | import javax.annotation.Resource; 8 | 9 | 10 | import java.util.List; 11 | 12 | public class AuthLoginServiceImplTest extends BaseApiAdminApplicationTest { 13 | 14 | @Resource 15 | private AuthLoginService authLoginService; 16 | 17 | @Test 18 | public void listRuleByAdminId() { 19 | 20 | Long adminId = 2L; 21 | 22 | List strings = authLoginService.listRuleByAdminId(adminId); 23 | 24 | 25 | } 26 | } -------------------------------------------------------------------------------- /api-admin/src/test/java/com/lmxdawn/api/admin/service/auth/impl/AuthPermissionRuleServiceImplTest.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.service.auth.impl; 2 | 3 | import com.lmxdawn.api.BaseApiAdminApplicationTest; 4 | import com.lmxdawn.api.admin.entity.auth.AuthPermissionRule; 5 | import com.lmxdawn.api.admin.service.auth.AuthPermissionRuleService; 6 | import org.junit.Test; 7 | 8 | import javax.annotation.Resource; 9 | 10 | import java.util.List; 11 | 12 | import static org.junit.Assert.*; 13 | 14 | public class AuthPermissionRuleServiceImplTest extends BaseApiAdminApplicationTest { 15 | 16 | @Resource 17 | private AuthPermissionRuleService authPermissionRuleService; 18 | 19 | @Test 20 | public void listByIdIn() { 21 | } 22 | 23 | @Test 24 | public void listByPid() { 25 | List authPermissionRuleList = authPermissionRuleService.listByPid(0L); 26 | 27 | assertTrue(authPermissionRuleList.size() > 0); 28 | } 29 | 30 | @Test 31 | public void listAll() { 32 | 33 | List authPermissionRuleList = authPermissionRuleService.listAll(); 34 | 35 | assertTrue(authPermissionRuleList.size() > 0); 36 | } 37 | } -------------------------------------------------------------------------------- /api-admin/src/test/java/com/lmxdawn/api/admin/service/auth/impl/AuthRoleAdminServiceImplTest.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.service.auth.impl; 2 | 3 | import com.lmxdawn.api.BaseApiAdminApplicationTest; 4 | import com.lmxdawn.api.admin.entity.auth.AuthRoleAdmin; 5 | import com.lmxdawn.api.admin.service.auth.AuthRoleAdminService; 6 | import org.junit.Test; 7 | 8 | import javax.annotation.Resource; 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | import static org.junit.Assert.*; 13 | 14 | public class AuthRoleAdminServiceImplTest extends BaseApiAdminApplicationTest { 15 | 16 | @Resource 17 | private AuthRoleAdminService authRoleAdminService; 18 | 19 | @Test 20 | public void listByAdminId() { 21 | } 22 | 23 | @Test 24 | public void listByRoleId() { 25 | } 26 | 27 | @Test 28 | public void insertAuthRoleAdminAll() { 29 | 30 | List authRoleAdminList = new ArrayList<>(); 31 | 32 | long len = 3; 33 | for (long i = 1; i <= len; i++) { 34 | AuthRoleAdmin authRoleAdmin = new AuthRoleAdmin(); 35 | if (i % 2 == 0) { 36 | authRoleAdmin.setRoleId(i); 37 | } 38 | authRoleAdmin.setAdminId(i + 1); 39 | authRoleAdminList.add(authRoleAdmin); 40 | } 41 | int i = authRoleAdminService.insertAuthRoleAdminAll(authRoleAdminList); 42 | 43 | System.out.println(i); 44 | assertEquals(1, i); 45 | } 46 | } -------------------------------------------------------------------------------- /api-admin/src/test/java/com/lmxdawn/api/admin/service/auth/impl/AuthRoleServiceImplTest.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.service.auth.impl; 2 | 3 | import com.lmxdawn.api.BaseApiAdminApplicationTest; 4 | import com.lmxdawn.api.admin.entity.auth.AuthRole; 5 | import com.lmxdawn.api.admin.service.auth.AuthRoleService; 6 | import org.junit.Test; 7 | 8 | import javax.annotation.Resource; 9 | 10 | import java.util.List; 11 | 12 | import static org.junit.Assert.*; 13 | 14 | public class AuthRoleServiceImplTest extends BaseApiAdminApplicationTest { 15 | 16 | @Resource 17 | private AuthRoleService authRoleService; 18 | 19 | @Test 20 | public void listAdminPage() { 21 | } 22 | 23 | @Test 24 | public void listAuthAdminRolePage() { 25 | 26 | Integer page = 1; 27 | Integer limit = 20; 28 | 29 | List authRoleList = authRoleService.listAuthAdminRolePage(page, limit, null); 30 | assertTrue(authRoleList.size() > 0); 31 | } 32 | } -------------------------------------------------------------------------------- /api-admin/src/test/java/com/lmxdawn/api/admin/util/JwtUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.util; 2 | 3 | import com.lmxdawn.api.BaseApiAdminApplicationTest; 4 | import io.jsonwebtoken.Claims; 5 | import org.junit.Test; 6 | 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | public class JwtUtilsTest extends BaseApiAdminApplicationTest { 13 | @Test 14 | public void createToken() { 15 | Map claims = new HashMap<>(); 16 | claims.put("admin_id", 12222222); 17 | String token = JwtUtils.createToken(claims, 86400L); 18 | System.out.println(token); 19 | System.out.println(token.length()); 20 | assertNotNull(token); 21 | } 22 | 23 | @Test 24 | public void createToken1() { 25 | Map claims = new HashMap<>(); 26 | String token = JwtUtils.createToken(claims); 27 | System.out.println(token); 28 | assertNotNull(token); 29 | } 30 | 31 | @Test 32 | public void parse() { 33 | Map claims = new HashMap<>(); 34 | claims.put("admin_id", 1); 35 | String token = JwtUtils.createToken(claims, 1000L); 36 | System.out.println(token); 37 | System.out.println(token.length()); 38 | Claims claim = JwtUtils.parse(token); 39 | System.out.println(claim); 40 | assertNotNull(claim); 41 | System.out.println(claim.get("admin_id")); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /api-admin/src/test/java/com/lmxdawn/api/admin/util/PermissionRuleTreeUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.admin.util; 2 | 3 | import com.lmxdawn.api.BaseApiAdminApplicationTest; 4 | import com.lmxdawn.api.admin.entity.auth.AuthPermissionRule; 5 | import com.lmxdawn.api.admin.service.auth.AuthPermissionRuleService; 6 | import com.lmxdawn.api.admin.res.auth.AuthPermissionRuleMergeResponse; 7 | import org.junit.Test; 8 | 9 | import javax.annotation.Resource; 10 | 11 | import java.util.List; 12 | 13 | public class PermissionRuleTreeUtilsTest extends BaseApiAdminApplicationTest { 14 | 15 | @Resource 16 | private AuthPermissionRuleService authPermissionRuleService; 17 | 18 | @Test 19 | public void merge() { 20 | 21 | List authPermissionRules = authPermissionRuleService.listAll(); 22 | List merge = PermissionRuleTreeUtils.merge(authPermissionRules,0L); 23 | System.out.println(merge); 24 | 25 | } 26 | } -------------------------------------------------------------------------------- /api-common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | api 7 | com.lmxdawn 8 | 0.0.1 9 | 10 | 4.0.0 11 | 12 | api-common 13 | 14 | 15 | 16 | 17 | org.projectlombok 18 | lombok 19 | true 20 | 21 | 22 | 23 | org.apache.commons 24 | commons-lang3 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /api-common/src/main/java/com/lmxdawn/api/common/constant/CacheConstant.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.common.constant; 2 | 3 | /** 4 | * redis 常量 5 | */ 6 | public interface CacheConstant { 7 | 8 | String ADMIN_AUTH_RULES = "admin_auth_rules:%s"; // 管理员的权限 9 | 10 | } 11 | -------------------------------------------------------------------------------- /api-common/src/main/java/com/lmxdawn/api/common/converter/LongList2StringConverter.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.common.converter; 2 | 3 | 4 | import org.apache.commons.lang3.StringUtils; 5 | 6 | import java.util.*; 7 | 8 | /** 9 | * Long 类型的 List 转为字符串 10 | */ 11 | public class LongList2StringConverter { 12 | 13 | /** 14 | * Long 类型的 List 转为字符串 15 | * @param longList 16 | * @param regex 17 | * @return 18 | */ 19 | public static String convert(List longList, String regex) { 20 | 21 | if (longList.isEmpty()) { 22 | return null; 23 | } 24 | Set stringSet = new HashSet<>(); 25 | for (Long value: longList){ 26 | stringSet.add(value.toString()); 27 | } 28 | if (stringSet.isEmpty()) { 29 | return null; 30 | } 31 | return StringUtils.join(stringSet, regex); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /api-common/src/main/java/com/lmxdawn/api/common/converter/String2LongListConverter.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.common.converter; 2 | 3 | 4 | import java.util.ArrayList; 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | /** 9 | * 字符串切割为 List 10 | */ 11 | public class String2LongListConverter { 12 | 13 | /** 14 | * 15 | * @param string 16 | * @param regex 切割的字符 17 | * @return 18 | */ 19 | public static List convert(String string, String regex) { 20 | try { 21 | if (null == string || "".equals(string)) { 22 | return Collections.emptyList(); 23 | } 24 | String[] strings = string.split(regex); 25 | if (strings.length == 0) { 26 | return Collections.emptyList(); 27 | } 28 | 29 | List longList = new ArrayList<>(); 30 | for (String str : strings) { 31 | longList.add(Long.valueOf(str)); 32 | } 33 | return longList; 34 | }catch (Exception e) { 35 | return Collections.emptyList(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /api-common/src/main/java/com/lmxdawn/api/common/converter/String2StringListConverter.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.common.converter; 2 | 3 | 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | import java.util.Collections; 7 | import java.util.List; 8 | 9 | /** 10 | * 字符串切割为 List 11 | */ 12 | public class String2StringListConverter { 13 | 14 | /** 15 | * 16 | * @param string 17 | * @param regex 切割的字符 18 | * @return 19 | */ 20 | public static List convert(String string, String regex) { 21 | try { 22 | if (null == string || "".equals(string)) { 23 | return Collections.emptyList(); 24 | } 25 | String[] strings = string.split(regex); 26 | if (strings.length == 0) { 27 | return Collections.emptyList(); 28 | } 29 | return new ArrayList<>(Arrays.asList(strings)); 30 | }catch (Exception e) { 31 | return Collections.emptyList(); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /api-common/src/main/java/com/lmxdawn/api/common/enums/ResultEnum.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.common.enums; 2 | 3 | import lombok.Getter; 4 | 5 | /** 6 | * 返回结果的枚举类 7 | */ 8 | @Getter 9 | public enum ResultEnum { 10 | 11 | SUCCESS(0, "success"), 12 | NOT_NETWORK(1, "系统繁忙,请稍后再试。"), 13 | LOGIN_VERIFY_FALL(2, "登录失效"), 14 | PARAM_VERIFY_FALL(3, "参数验证错误"), 15 | AUTH_FAILED(4, "权限验证失败"), 16 | DATA_NOT(5, "没有相关数据"), 17 | DATA_CHANGE(6, "数据没有任何更改"), 18 | DATA_REPEAT(7, "数据已存在"), 19 | 20 | ; 21 | 22 | private Integer code; 23 | 24 | private String message; 25 | 26 | ResultEnum(Integer code, String message) { 27 | this.code = code; 28 | this.message = message; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /api-common/src/main/java/com/lmxdawn/api/common/req/BaseLimitRequest.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.common.req; 2 | 3 | /** 4 | * 分页的请求 5 | */ 6 | public class BaseLimitRequest extends BaseRequest { 7 | 8 | /** 9 | * 页码 10 | */ 11 | private Integer page; 12 | 13 | /** 14 | * 数量 15 | */ 16 | private Integer limit; 17 | 18 | /** 19 | * 偏移量 20 | */ 21 | private Integer offset; 22 | 23 | public Integer getPage() { 24 | return page; 25 | } 26 | 27 | public void setPage(Integer page) { 28 | this.page = page; 29 | } 30 | 31 | public Integer getLimit() { 32 | return limit; 33 | } 34 | 35 | public void setLimit(Integer limit) { 36 | this.limit = limit; 37 | } 38 | 39 | public Integer getOffset() { 40 | return offset; 41 | } 42 | 43 | /** 44 | * 设置偏移量 45 | */ 46 | public void setOffset() { 47 | if (null == this.getPage() || this.getPage() <= 0) { 48 | this.setPage(1); 49 | } 50 | if (null == this.getLimit() || this.getLimit() <= 0) { 51 | this.setLimit(10); 52 | } 53 | this.offset = (this.getPage() - 1) * this.getLimit(); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /api-common/src/main/java/com/lmxdawn/api/common/req/BaseRequest.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.common.req; 2 | 3 | import java.util.UUID; 4 | 5 | public class BaseRequest { 6 | 7 | /** 8 | * 唯一请求号 9 | */ 10 | private String reqNo; 11 | 12 | /** 13 | * 请求的时间戳 14 | */ 15 | private Long timeStamp; 16 | 17 | public BaseRequest() { 18 | this.reqNo = UUID.randomUUID().toString(); 19 | this.timeStamp = System.currentTimeMillis(); 20 | } 21 | 22 | public String getReqNo() { 23 | return reqNo; 24 | } 25 | 26 | public void setReqNo(String reqNo) { 27 | this.reqNo = reqNo; 28 | } 29 | 30 | public Long getTimeStamp() { 31 | return timeStamp; 32 | } 33 | 34 | public void setTimeStamp(Long timeStamp) { 35 | this.timeStamp = timeStamp; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /api-common/src/main/java/com/lmxdawn/api/common/res/BaseResponse.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.common.res; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * 返回结果类 7 | * @param 8 | */ 9 | @Data 10 | public class BaseResponse { 11 | 12 | private Integer code; 13 | 14 | private String message; 15 | 16 | private T data; 17 | } 18 | -------------------------------------------------------------------------------- /api-common/src/main/java/com/lmxdawn/api/common/util/ResultVOUtils.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.common.util; 2 | 3 | import com.lmxdawn.api.common.enums.ResultEnum; 4 | import com.lmxdawn.api.common.res.BaseResponse; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | /** 10 | * 返回结果的操作类 11 | */ 12 | public class ResultVOUtils { 13 | 14 | /** 15 | * 成功时返回 16 | * @param data 返回的data对象 17 | * @return {@link BaseResponse} 18 | */ 19 | public static BaseResponse success(Object data) { 20 | BaseResponse baseResponse = new BaseResponse<>(); 21 | baseResponse.setCode(0); 22 | baseResponse.setMessage("success"); 23 | baseResponse.setData(data); 24 | return baseResponse; 25 | } 26 | 27 | /** 28 | * 成功时返回 29 | * @return {@link BaseResponse} 30 | */ 31 | public static BaseResponse success() { 32 | Map data = new HashMap(); 33 | return success(data); 34 | } 35 | 36 | /** 37 | * 错误时返回 38 | * @param code 错误码 39 | * @param message 错误信息 40 | * @return {@link BaseResponse} 41 | */ 42 | public static BaseResponse error(Integer code, String message) { 43 | BaseResponse baseResponse = new BaseResponse<>(); 44 | baseResponse.setCode(code); 45 | baseResponse.setMessage(message); 46 | Map data = new HashMap(); 47 | baseResponse.setData(data); 48 | return baseResponse; 49 | } 50 | 51 | /** 52 | * 错误时返回 53 | * @param resultEnum 错误枚举类 54 | * @return {@link BaseResponse} 55 | */ 56 | public static BaseResponse error(ResultEnum resultEnum) { 57 | return error(resultEnum.getCode(), resultEnum.getMessage()); 58 | } 59 | 60 | /** 61 | * 错误时返回 62 | * @param resultEnum 错误枚举类 63 | * @param message 错误的信息 64 | * @return {@link BaseResponse} 65 | */ 66 | public static BaseResponse error(ResultEnum resultEnum, String message) { 67 | return error(resultEnum.getCode(), message); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /api-common/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmxdawn/vue-admin-java/1895f509b421ccbccb0630e821e77841611cf0fb/api-common/src/main/resources/application.properties -------------------------------------------------------------------------------- /api-common/src/test/java/com/lmxdawn/api/common/util/ResultVOUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.lmxdawn.api.common.util; 2 | 3 | 4 | public class ResultVOUtilsTest { 5 | 6 | public void success() { 7 | } 8 | } -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.lmxdawn 7 | api 8 | 0.0.1 9 | 10 | api-admin 11 | api-common 12 | 13 | pom 14 | 15 | api 16 | vue后台管理系统 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-parent 21 | 2.1.3.RELEASE 22 | 23 | 24 | 25 | 26 | 1.8 27 | 28 | 29 | 30 | 31 | 32 | 33 | com.lmxdawn 34 | api-common 35 | ${version} 36 | 37 | 38 | 39 | 40 | com.alibaba 41 | fastjson 42 | 1.2.51 43 | 44 | 45 | 46 | 47 | org.apache.commons 48 | commons-lang3 49 | 3.9 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /scripts/vue-admin.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : php 5 | Source Server Version : 50553 6 | Source Host : localhost:3306 7 | Source Database : vue-admin 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 50553 11 | File Encoding : 65001 12 | 13 | Date: 2018-11-20 18:59:57 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS=0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for ad 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `ad`; 22 | CREATE TABLE `ad` ( 23 | `ad_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '广告ID', 24 | `title` varchar(255) NOT NULL COMMENT '广告标题', 25 | `describe` varchar(255) NOT NULL DEFAULT '' COMMENT '描述', 26 | `pic` varchar(255) NOT NULL DEFAULT '' COMMENT '图片的地址', 27 | `jump_type` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '跳转方式(0,web 页面,1:APP内链接,2:小程序)', 28 | `jump_url` varchar(255) NOT NULL DEFAULT '' COMMENT '跳转的url路径', 29 | `ios_url` varchar(255) NOT NULL DEFAULT '' COMMENT 'ios 的类名', 30 | `android_url` varchar(255) NOT NULL DEFAULT '' COMMENT 'android 的类名', 31 | `wxa_appid` varchar(50) NOT NULL DEFAULT '' COMMENT '微信小程序的APPID(跳转类型为 1 时有效)', 32 | `channel_type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '渠道名单类型(0:不做处理,1:白名单,2:黑名单)', 33 | `channel_list` varchar(255) NOT NULL DEFAULT '' COMMENT '渠道黑名单', 34 | `android_version_type` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT 'android 版本名单类型(0:不做处理,1:白名单,2:黑名单)', 35 | `android_version_list` varchar(255) NOT NULL DEFAULT '' COMMENT 'android 版本黑名单', 36 | `ios_version_type` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT 'ios 版本名单类型(0:不做处理,1:白名单,2:黑名单)', 37 | `ios_version_list` varchar(255) NOT NULL DEFAULT '' COMMENT 'ios 版本黑名单', 38 | `new_show_start_num` int(11) NOT NULL DEFAULT '0' COMMENT '新用户从第几次开始展示', 39 | `new_show_max_num` int(11) NOT NULL DEFAULT '0' COMMENT '新用户最大展示几次', 40 | `old_show_start_num` int(11) NOT NULL DEFAULT '0' COMMENT '老用户第几次开始展示', 41 | `old_show_max_num` int(11) NOT NULL DEFAULT '0' COMMENT '老用户最大展示几次', 42 | `start_time` datetime DEFAULT NULL COMMENT '开始时间', 43 | `end_time` datetime DEFAULT NULL COMMENT '结束时间', 44 | `event_name` varchar(255) NOT NULL DEFAULT '' COMMENT '统计事件名称', 45 | `status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '广告状态(0:禁用,1:正常)', 46 | `create_time` datetime NOT NULL COMMENT '创建时间', 47 | `modified_time` datetime NOT NULL COMMENT '更新时间', 48 | PRIMARY KEY (`ad_id`) 49 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='广告表'; 50 | 51 | -- ---------------------------- 52 | -- Table structure for ad_site 53 | -- ---------------------------- 54 | DROP TABLE IF EXISTS `ad_site`; 55 | CREATE TABLE `ad_site` ( 56 | `site_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '广告位id', 57 | `site_name` varchar(255) NOT NULL COMMENT '广告位名称', 58 | `describe` varchar(255) NOT NULL DEFAULT '' COMMENT '广告位描述', 59 | `ad_ids` varchar(255) NOT NULL DEFAULT '' COMMENT '广告位的广告id(用 , 隔开)', 60 | `create_time` datetime NOT NULL COMMENT '创建时间', 61 | `modified_time` datetime NOT NULL COMMENT '更新时间', 62 | PRIMARY KEY (`site_id`) 63 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='广告位'; 64 | 65 | -- ---------------------------- 66 | -- Table structure for auth_admin 67 | -- ---------------------------- 68 | DROP TABLE IF EXISTS `auth_admin`; 69 | CREATE TABLE `auth_admin` ( 70 | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 71 | `username` varchar(60) NOT NULL DEFAULT '' COMMENT '用户名', 72 | `password` varchar(64) NOT NULL DEFAULT '' COMMENT '登录密码;sp_password加密', 73 | `tel` varchar(50) NOT NULL DEFAULT '' COMMENT '用户手机号', 74 | `email` varchar(100) NOT NULL DEFAULT '' COMMENT '登录邮箱', 75 | `avatar` varchar(255) NOT NULL DEFAULT '' COMMENT '用户头像', 76 | `sex` smallint(1) NOT NULL DEFAULT '0' COMMENT '性别;0:保密,1:男;2:女', 77 | `last_login_ip` varchar(16) NOT NULL DEFAULT '' COMMENT '最后登录ip', 78 | `last_login_time` datetime NOT NULL COMMENT '最后登录时间', 79 | `create_time` datetime NOT NULL COMMENT '注册时间', 80 | `status` int(11) NOT NULL DEFAULT '1' COMMENT '用户状态 0:禁用; 1:正常 ;2:未验证', 81 | PRIMARY KEY (`id`), 82 | KEY `user_login_key` (`username`) 83 | ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='管理员表'; 84 | 85 | -- ---------------------------- 86 | -- Records of auth_admin 87 | -- ---------------------------- 88 | INSERT INTO `auth_admin` VALUES ('1', 'admin', 'c3284d0f94606de1fd2af172aba15bf3', 'admin', 'lmxdawn@gmail.com', 'sssss', '0', '127.0.0.1', '2018-07-06 17:19:00', '2018-07-06 17:19:00', '1'); 89 | 90 | -- ---------------------------- 91 | -- Table structure for auth_permission 92 | -- ---------------------------- 93 | DROP TABLE IF EXISTS `auth_permission`; 94 | CREATE TABLE `auth_permission` ( 95 | `role_id` int(11) unsigned NOT NULL COMMENT '角色', 96 | `permission_rule_id` int(11) NOT NULL DEFAULT '0' COMMENT '权限id', 97 | `type` varchar(30) DEFAULT NULL COMMENT '权限规则分类,请加应用前缀,如admin_' 98 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='权限授权表'; 99 | 100 | -- ---------------------------- 101 | -- Records of auth_permission 102 | -- ---------------------------- 103 | INSERT INTO `auth_permission` VALUES ('1', '4', 'admin'); 104 | INSERT INTO `auth_permission` VALUES ('1', '3', 'admin'); 105 | INSERT INTO `auth_permission` VALUES ('1', '2', 'admin'); 106 | INSERT INTO `auth_permission` VALUES ('1', '1', 'admin'); 107 | 108 | -- ---------------------------- 109 | -- Table structure for auth_permission_rule 110 | -- ---------------------------- 111 | DROP TABLE IF EXISTS `auth_permission_rule`; 112 | CREATE TABLE `auth_permission_rule` ( 113 | `id` int(8) unsigned NOT NULL AUTO_INCREMENT COMMENT '规则编号', 114 | `pid` int(11) NOT NULL DEFAULT '0' COMMENT '父级id', 115 | `name` char(80) NOT NULL DEFAULT '' COMMENT '规则唯一标识', 116 | `title` char(20) NOT NULL DEFAULT '' COMMENT '规则中文名称', 117 | `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态:为1正常,为0禁用', 118 | `condition` char(100) NOT NULL DEFAULT '' COMMENT '规则表达式,为空表示存在就验证,不为空表示按照条件验证', 119 | `listorder` int(10) NOT NULL DEFAULT '0' COMMENT '排序,优先级,越小优先级越高', 120 | `create_time` datetime NOT NULL COMMENT '创建时间', 121 | `update_time` datetime NOT NULL COMMENT '更新时间', 122 | PRIMARY KEY (`id`), 123 | UNIQUE KEY `name` (`name`) 124 | ) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8 COMMENT='规则表'; 125 | 126 | -- ---------------------------- 127 | -- Records of auth_permission_rule 128 | -- ---------------------------- 129 | INSERT INTO `auth_permission_rule` VALUES ('1', '0', 'user_manage', '用户管理', '1', '', '999', '2018-07-06 17:19:00', '2018-07-06 17:19:00'); 130 | INSERT INTO `auth_permission_rule` VALUES ('2', '1', 'user_manage/admin_manage', '管理组', '1', '', '999', '2018-07-06 17:19:00', '2018-07-06 17:19:00'); 131 | INSERT INTO `auth_permission_rule` VALUES ('3', '2', 'admin/auth_admin/index', '管理员管理', '1', '', '999', '2018-07-06 17:19:00', '2018-07-06 17:19:00'); 132 | INSERT INTO `auth_permission_rule` VALUES ('4', '3', 'admin/auth_admin/save', '添加管理员', '1', '', '999', '2018-07-06 17:19:00', '2018-07-06 17:19:00'); 133 | INSERT INTO `auth_permission_rule` VALUES ('5', '3', 'admin/auth_admin/edit', '编辑管理员', '1', '', '999', '2018-07-06 17:19:00', '2018-07-06 17:19:00'); 134 | INSERT INTO `auth_permission_rule` VALUES ('6', '3', 'admin/auth_admin/delete', '删除管理员', '1', '', '999', '2018-07-06 17:19:00', '2018-07-06 17:19:00'); 135 | INSERT INTO `auth_permission_rule` VALUES ('7', '2', 'admin/auth_role/index', '角色管理', '1', '', '999', '2018-07-06 17:19:00', '2018-07-06 17:19:00'); 136 | INSERT INTO `auth_permission_rule` VALUES ('8', '7', 'admin/auth_role/save', '添加角色', '1', '', '999', '2018-07-06 17:19:00', '2018-07-06 17:19:00'); 137 | INSERT INTO `auth_permission_rule` VALUES ('9', '7', 'admin/auth_role/edit', '编辑角色', '1', '', '999', '2018-07-06 17:19:00', '2018-07-06 17:19:00'); 138 | INSERT INTO `auth_permission_rule` VALUES ('10', '7', 'admin/auth_role/delete', '删除角色', '1', '', '999', '2018-07-06 17:19:00', '2018-07-06 17:19:00'); 139 | INSERT INTO `auth_permission_rule` VALUES ('11', '7', 'admin/auth_role/auth', '角色授权', '1', '', '999', '2018-07-06 17:19:00', '2018-07-06 17:19:00'); 140 | INSERT INTO `auth_permission_rule` VALUES ('12', '2', 'admin/auth_permission_rule/index', '权限管理', '1', '', '999', '2018-07-06 17:19:00', '2018-07-06 17:19:00'); 141 | INSERT INTO `auth_permission_rule` VALUES ('13', '12', 'admin/auth_permission_rule/save', '添加权限', '1', '', '999', '2018-07-06 17:19:00', '2018-07-06 17:19:00'); 142 | INSERT INTO `auth_permission_rule` VALUES ('14', '12', 'admin/auth_permission_rule/edit', '编辑权限', '1', '', '999', '2018-07-06 17:19:00', '2018-07-06 17:19:00'); 143 | INSERT INTO `auth_permission_rule` VALUES ('15', '12', 'admin/auth_permission_rule/delete', '删除权限', '1', '', '999', '2018-07-06 17:19:00', '2018-07-06 17:19:00'); 144 | INSERT INTO `auth_permission_rule` VALUES ('16', '0', 'ad_manage', '广告相关', '1', '', '999', '2018-07-06 17:19:00', '2018-07-06 17:19:00'); 145 | INSERT INTO `auth_permission_rule` VALUES ('17', '16', 'admin/ad_site/index', '广告位管理', '1', '', '999', '2018-07-06 17:19:00', '2018-07-06 17:19:00'); 146 | INSERT INTO `auth_permission_rule` VALUES ('18', '17', 'admin/ad_site/save', '广告位添加', '1', '', '999', '2018-07-06 17:19:00', '2018-07-06 17:19:00'); 147 | INSERT INTO `auth_permission_rule` VALUES ('19', '17', 'admin/ad_site/edit', '广告位编辑', '1', '', '999', '2018-07-06 17:19:00', '2018-07-06 17:19:00'); 148 | INSERT INTO `auth_permission_rule` VALUES ('20', '17', 'admin/ad_site/delete', '广告位删除', '1', '', '999', '2018-07-06 17:19:00', '2018-07-06 17:19:00'); 149 | INSERT INTO `auth_permission_rule` VALUES ('21', '16', 'admin/ad/index', '广告管理', '1', '', '999', '2018-07-06 17:19:00', '2018-07-06 17:19:00'); 150 | INSERT INTO `auth_permission_rule` VALUES ('22', '21', 'admin/ad/save', '广告添加', '1', '', '999', '2018-07-06 17:19:00', '2018-07-06 17:19:00'); 151 | INSERT INTO `auth_permission_rule` VALUES ('23', '21', 'admin/ad/edit', '广告编辑', '1', '', '999', '2018-07-06 17:19:00', '2018-07-06 17:19:00'); 152 | INSERT INTO `auth_permission_rule` VALUES ('24', '21', 'admin/ad/delete', '广告删除', '1', '', '999', '2018-07-06 17:19:00', '2018-07-06 17:19:00'); 153 | INSERT INTO `auth_permission_rule` VALUES ('25', '17', 'admin/ad_site/adlist', '广告位选择时的广告列表', '1', '', '999', '2018-07-06 17:19:00', '2018-07-06 17:19:00'); 154 | 155 | -- ---------------------------- 156 | -- Table structure for auth_role 157 | -- ---------------------------- 158 | DROP TABLE IF EXISTS `auth_role`; 159 | CREATE TABLE `auth_role` ( 160 | `id` int(11) unsigned NOT NULL AUTO_INCREMENT, 161 | `name` varchar(20) NOT NULL COMMENT '角色名称', 162 | `pid` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '父角色ID', 163 | `status` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '状态', 164 | `remark` varchar(255) NOT NULL DEFAULT '' COMMENT '备注', 165 | `create_time` datetime NOT NULL COMMENT '创建时间', 166 | `update_time` datetime NOT NULL COMMENT '更新时间', 167 | `listorder` int(3) NOT NULL DEFAULT '0' COMMENT '排序,优先级,越小优先级越高', 168 | PRIMARY KEY (`id`) 169 | ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='角色表'; 170 | 171 | -- ---------------------------- 172 | -- Records of auth_role 173 | -- ---------------------------- 174 | INSERT INTO `auth_role` VALUES ('1', '超级管理员', '0', '1', '拥有网站最高管理员权限!', '2018-07-06 17:19:00', '2018-07-06 17:19:00', '0'); 175 | 176 | -- ---------------------------- 177 | -- Table structure for auth_role_admin 178 | -- ---------------------------- 179 | DROP TABLE IF EXISTS `auth_role_admin`; 180 | CREATE TABLE `auth_role_admin` ( 181 | `role_id` int(11) unsigned DEFAULT '0' COMMENT '角色 id', 182 | `admin_id` int(11) DEFAULT '0' COMMENT '管理员id' 183 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户角色对应表'; 184 | 185 | -- ---------------------------- 186 | -- Records of auth_role_admin 187 | -- ---------------------------- 188 | 189 | -- ---------------------------- 190 | -- Table structure for file_resource 191 | -- ---------------------------- 192 | DROP TABLE IF EXISTS `file_resource`; 193 | CREATE TABLE `file_resource` ( 194 | `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '资源id', 195 | `tag_id` int(11) NOT NULL DEFAULT '0' COMMENT '资源分组id', 196 | `type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '资源的类型(0:图片)', 197 | `filename` varchar(255) NOT NULL DEFAULT '' COMMENT '资源的原名', 198 | `path` varchar(255) NOT NULL DEFAULT '' COMMENT '资源的路径(不加 域名的地址)', 199 | `size` int(11) NOT NULL DEFAULT '0' COMMENT '大小', 200 | `ext` varchar(10) NOT NULL DEFAULT '' COMMENT '资源的文件后缀', 201 | `create_time` datetime NOT NULL COMMENT '创建时间', 202 | PRIMARY KEY (`id`) 203 | ) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8 COMMENT='资源表'; 204 | 205 | -- ---------------------------- 206 | -- Records of file_resource 207 | -- ---------------------------- 208 | INSERT INTO `file_resource` VALUES ('1', '1', '0', 'Group 5.png', 'resources/image/20180530/854ae62758c585be5128cf344a511242.png', '7539', 'png', '2018-05-30 20:41:54'); 209 | INSERT INTO `file_resource` VALUES ('2', '0', '0', '643353_sdfaf123.png', 'resources/image/20180823/c356ca140f631a512f1c3a5e37a15dc1.png', '11507', 'png', '2018-08-23 13:38:42'); 210 | INSERT INTO `file_resource` VALUES ('3', '0', '0', '643353_sdfaf123.png', 'resources/image/20180823/4549c39e9c07c35681ee9fa94e0fc07e.png', '11507', 'png', '2018-08-23 14:05:18'); 211 | INSERT INTO `file_resource` VALUES ('4', '0', '0', '', '', '0', '', '2018-08-23 15:45:21'); 212 | INSERT INTO `file_resource` VALUES ('5', '0', '0', '', '', '2000000', '', '2018-08-23 15:45:21'); 213 | INSERT INTO `file_resource` VALUES ('6', '0', '0', '', '', '0', '', '2018-08-23 15:45:21'); 214 | INSERT INTO `file_resource` VALUES ('7', '0', '0', '', '', '0', '', '2018-08-23 15:45:21'); 215 | INSERT INTO `file_resource` VALUES ('8', '0', '0', '643353_sdfaf123.png', 'resources/image/20180823/0c424412b231eb8cb969377e15dbb812.png', '11507', 'png', '2018-08-23 15:53:32'); 216 | INSERT INTO `file_resource` VALUES ('9', '0', '0', '232826334630444283.png', 'FjBRVPOPF9gLeNBCAvK7jbif4yg8', '9668', 'png', '2018-08-23 16:08:13'); 217 | INSERT INTO `file_resource` VALUES ('10', '0', '0', '232826334630444283.png', 'FjBRVPOPF9gLeNBCAvK7jbif4yg8', '9668', 'png', '2018-08-23 16:09:07'); 218 | INSERT INTO `file_resource` VALUES ('11', '0', '0', '643353_sdfaf123.png', 'resources/image/20180823/52af5f8556a3af84cee696972b61baf4.png', '11507', 'png', '2018-08-23 17:06:05'); 219 | 220 | -- ---------------------------- 221 | -- Table structure for file_resource_tag 222 | -- ---------------------------- 223 | DROP TABLE IF EXISTS `file_resource_tag`; 224 | CREATE TABLE `file_resource_tag` ( 225 | `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '资源分组的id', 226 | `tag` varchar(255) NOT NULL DEFAULT '' COMMENT '资源分组的tag', 227 | `create_time` datetime NOT NULL COMMENT '更新时间', 228 | PRIMARY KEY (`id`) 229 | ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='资源的分组表'; 230 | 231 | -- ---------------------------- 232 | -- Records of file_resource_tag 233 | -- ---------------------------- 234 | INSERT INTO `file_resource_tag` VALUES ('1', '测试', '2018-05-30 20:41:48'); 235 | --------------------------------------------------------------------------------