From e43b12e8972853af179f4953719a568f0faaafe6 Mon Sep 17 00:00:00 2001 From: macro Date: Tue, 9 Nov 2021 20:43:09 +0800 Subject: [PATCH] add mall-tiny-torna --- mall-tiny-torna/.gitignore | 29 + mall-tiny-torna/pom.xml | 115 +++ .../macro/mall/tiny/MallTinyApplication.java | 13 + .../mall/tiny/common/api/CommonPage.java | 71 ++ .../mall/tiny/common/api/CommonResult.java | 115 +++ .../mall/tiny/common/api/IErrorCode.java | 11 + .../mall/tiny/common/api/ResultCode.java | 28 + .../mall/tiny/common/utils/JwtTokenUtil.java | 137 +++ .../JwtAuthenticationTokenFilter.java | 57 ++ .../RestAuthenticationEntryPoint.java | 27 + .../component/RestfulAccessDeniedHandler.java | 29 + .../macro/mall/tiny/config/MyBatisConfig.java | 13 + .../mall/tiny/config/SecurityConfig.java | 111 +++ .../mall/tiny/config/Swagger2Config.java | 73 ++ .../tiny/controller/PmsBrandController.java | 109 +++ .../tiny/controller/UmsAdminController.java | 47 + .../mall/tiny/domain/AdminUserDetails.java | 58 ++ .../macro/mall/tiny/mbg/CommentGenerator.java | 73 ++ .../com/macro/mall/tiny/mbg/Generator.java | 38 + .../mall/tiny/mbg/mapper/PmsBrandMapper.java | 36 + .../macro/mall/tiny/mbg/model/PmsBrand.java | 147 +++ .../mall/tiny/mbg/model/PmsBrandExample.java | 840 ++++++++++++++++++ .../mall/tiny/service/PmsBrandService.java | 24 + .../mall/tiny/service/UmsAdminService.java | 19 + .../service/impl/PmsBrandServiceImpl.java | 53 ++ .../service/impl/UmsAdminServiceImpl.java | 78 ++ .../src/main/resources/application.yml | 24 + .../mall/tiny/mbg/mapper/PmsBrandMapper.xml | 358 ++++++++ .../src/main/resources/generator.properties | 4 + .../src/main/resources/generatorConfig.xml | 43 + mall-tiny-torna/src/main/resources/torna.json | 22 + .../mall/tiny/MallTinyApplicationTests.java | 23 + 32 files changed, 2825 insertions(+) create mode 100644 mall-tiny-torna/.gitignore create mode 100644 mall-tiny-torna/pom.xml create mode 100644 mall-tiny-torna/src/main/java/com/macro/mall/tiny/MallTinyApplication.java create mode 100644 mall-tiny-torna/src/main/java/com/macro/mall/tiny/common/api/CommonPage.java create mode 100644 mall-tiny-torna/src/main/java/com/macro/mall/tiny/common/api/CommonResult.java create mode 100644 mall-tiny-torna/src/main/java/com/macro/mall/tiny/common/api/IErrorCode.java create mode 100644 mall-tiny-torna/src/main/java/com/macro/mall/tiny/common/api/ResultCode.java create mode 100644 mall-tiny-torna/src/main/java/com/macro/mall/tiny/common/utils/JwtTokenUtil.java create mode 100644 mall-tiny-torna/src/main/java/com/macro/mall/tiny/component/JwtAuthenticationTokenFilter.java create mode 100644 mall-tiny-torna/src/main/java/com/macro/mall/tiny/component/RestAuthenticationEntryPoint.java create mode 100644 mall-tiny-torna/src/main/java/com/macro/mall/tiny/component/RestfulAccessDeniedHandler.java create mode 100644 mall-tiny-torna/src/main/java/com/macro/mall/tiny/config/MyBatisConfig.java create mode 100644 mall-tiny-torna/src/main/java/com/macro/mall/tiny/config/SecurityConfig.java create mode 100644 mall-tiny-torna/src/main/java/com/macro/mall/tiny/config/Swagger2Config.java create mode 100644 mall-tiny-torna/src/main/java/com/macro/mall/tiny/controller/PmsBrandController.java create mode 100644 mall-tiny-torna/src/main/java/com/macro/mall/tiny/controller/UmsAdminController.java create mode 100644 mall-tiny-torna/src/main/java/com/macro/mall/tiny/domain/AdminUserDetails.java create mode 100644 mall-tiny-torna/src/main/java/com/macro/mall/tiny/mbg/CommentGenerator.java create mode 100644 mall-tiny-torna/src/main/java/com/macro/mall/tiny/mbg/Generator.java create mode 100644 mall-tiny-torna/src/main/java/com/macro/mall/tiny/mbg/mapper/PmsBrandMapper.java create mode 100644 mall-tiny-torna/src/main/java/com/macro/mall/tiny/mbg/model/PmsBrand.java create mode 100644 mall-tiny-torna/src/main/java/com/macro/mall/tiny/mbg/model/PmsBrandExample.java create mode 100644 mall-tiny-torna/src/main/java/com/macro/mall/tiny/service/PmsBrandService.java create mode 100644 mall-tiny-torna/src/main/java/com/macro/mall/tiny/service/UmsAdminService.java create mode 100644 mall-tiny-torna/src/main/java/com/macro/mall/tiny/service/impl/PmsBrandServiceImpl.java create mode 100644 mall-tiny-torna/src/main/java/com/macro/mall/tiny/service/impl/UmsAdminServiceImpl.java create mode 100644 mall-tiny-torna/src/main/resources/application.yml create mode 100644 mall-tiny-torna/src/main/resources/com/macro/mall/tiny/mbg/mapper/PmsBrandMapper.xml create mode 100644 mall-tiny-torna/src/main/resources/generator.properties create mode 100644 mall-tiny-torna/src/main/resources/generatorConfig.xml create mode 100644 mall-tiny-torna/src/main/resources/torna.json create mode 100644 mall-tiny-torna/src/test/java/com/macro/mall/tiny/MallTinyApplicationTests.java diff --git a/mall-tiny-torna/.gitignore b/mall-tiny-torna/.gitignore new file mode 100644 index 00000000..153c9335 --- /dev/null +++ b/mall-tiny-torna/.gitignore @@ -0,0 +1,29 @@ +HELP.md +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +/build/ + +### VS Code ### +.vscode/ diff --git a/mall-tiny-torna/pom.xml b/mall-tiny-torna/pom.xml new file mode 100644 index 00000000..13b815f3 --- /dev/null +++ b/mall-tiny-torna/pom.xml @@ -0,0 +1,115 @@ + + + 4.0.0 + com.macro.mall + mall-tiny-torna + 1.0-SNAPSHOT + mall-tiny-torna + Demo project for Spring Boot + + + UTF-8 + UTF-8 + 1.8 + true + + + + org.springframework.boot + spring-boot-starter-parent + 2.2.0.RELEASE + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-aop + + + org.springframework.boot + spring-boot-starter-test + test + + + + com.github.pagehelper + pagehelper-spring-boot-starter + 1.2.10 + + + + com.alibaba + druid-spring-boot-starter + 1.1.10 + + + + org.mybatis.generator + mybatis-generator-core + 1.3.3 + + + + mysql + mysql-connector-java + 8.0.15 + + + + org.projectlombok + lombok + true + + + + org.springframework.boot + spring-boot-starter-security + + + + cn.hutool + hutool-all + 4.5.7 + + + + io.jsonwebtoken + jjwt + 0.9.0 + + + + io.springfox + springfox-boot-starter + 3.0.0 + + + + cn.torna + swagger-plugin + 1.2.6 + test + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/mall-tiny-torna/src/main/java/com/macro/mall/tiny/MallTinyApplication.java b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/MallTinyApplication.java new file mode 100644 index 00000000..80f20db5 --- /dev/null +++ b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/MallTinyApplication.java @@ -0,0 +1,13 @@ +package com.macro.mall.tiny; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class MallTinyApplication { + + public static void main(String[] args) { + SpringApplication.run(MallTinyApplication.class, args); + } + +} diff --git a/mall-tiny-torna/src/main/java/com/macro/mall/tiny/common/api/CommonPage.java b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/common/api/CommonPage.java new file mode 100644 index 00000000..eb6c7bd9 --- /dev/null +++ b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/common/api/CommonPage.java @@ -0,0 +1,71 @@ +package com.macro.mall.tiny.common.api; + +import com.github.pagehelper.PageInfo; + +import java.util.List; + +/** + * 分页数据封装类 + * Created by macro on 2019/4/19. + */ +public class CommonPage { + private Integer pageNum; + private Integer pageSize; + private Integer totalPage; + private Long total; + private List list; + + /** + * 将PageHelper分页后的list转为分页信息 + */ + public static CommonPage restPage(List list) { + CommonPage result = new CommonPage(); + PageInfo pageInfo = new PageInfo(list); + result.setTotalPage(pageInfo.getPages()); + result.setPageNum(pageInfo.getPageNum()); + result.setPageSize(pageInfo.getPageSize()); + result.setTotal(pageInfo.getTotal()); + result.setList(pageInfo.getList()); + return result; + } + + public Integer getPageNum() { + return pageNum; + } + + public void setPageNum(Integer pageNum) { + this.pageNum = pageNum; + } + + public Integer getPageSize() { + return pageSize; + } + + public void setPageSize(Integer pageSize) { + this.pageSize = pageSize; + } + + public Integer getTotalPage() { + return totalPage; + } + + public void setTotalPage(Integer totalPage) { + this.totalPage = totalPage; + } + + public List getList() { + return list; + } + + public void setList(List list) { + this.list = list; + } + + public Long getTotal() { + return total; + } + + public void setTotal(Long total) { + this.total = total; + } +} diff --git a/mall-tiny-torna/src/main/java/com/macro/mall/tiny/common/api/CommonResult.java b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/common/api/CommonResult.java new file mode 100644 index 00000000..f1d580d5 --- /dev/null +++ b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/common/api/CommonResult.java @@ -0,0 +1,115 @@ +package com.macro.mall.tiny.common.api; + +/** + * 通用返回对象 + * Created by macro on 2019/4/19. + */ +public class CommonResult { + private long code; + private String message; + private T data; + + protected CommonResult() { + } + + protected CommonResult(long code, String message, T data) { + this.code = code; + this.message = message; + this.data = data; + } + + /** + * 成功返回结果 + * + * @param data 获取的数据 + */ + public static CommonResult success(T data) { + return new CommonResult(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data); + } + + /** + * 成功返回结果 + * + * @param data 获取的数据 + * @param message 提示信息 + */ + public static CommonResult success(T data, String message) { + return new CommonResult(ResultCode.SUCCESS.getCode(), message, data); + } + + /** + * 失败返回结果 + * @param errorCode 错误码 + */ + public static CommonResult failed(IErrorCode errorCode) { + return new CommonResult(errorCode.getCode(), errorCode.getMessage(), null); + } + + /** + * 失败返回结果 + * @param message 提示信息 + */ + public static CommonResult failed(String message) { + return new CommonResult(ResultCode.FAILED.getCode(), message, null); + } + + /** + * 失败返回结果 + */ + public static CommonResult failed() { + return failed(ResultCode.FAILED); + } + + /** + * 参数验证失败返回结果 + */ + public static CommonResult validateFailed() { + return failed(ResultCode.VALIDATE_FAILED); + } + + /** + * 参数验证失败返回结果 + * @param message 提示信息 + */ + public static CommonResult validateFailed(String message) { + return new CommonResult(ResultCode.VALIDATE_FAILED.getCode(), message, null); + } + + /** + * 未登录返回结果 + */ + public static CommonResult unauthorized(T data) { + return new CommonResult(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getMessage(), data); + } + + /** + * 未授权返回结果 + */ + public static CommonResult forbidden(T data) { + return new CommonResult(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getMessage(), data); + } + + public long getCode() { + return code; + } + + public void setCode(long code) { + this.code = code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/mall-tiny-torna/src/main/java/com/macro/mall/tiny/common/api/IErrorCode.java b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/common/api/IErrorCode.java new file mode 100644 index 00000000..cfdf47ed --- /dev/null +++ b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/common/api/IErrorCode.java @@ -0,0 +1,11 @@ +package com.macro.mall.tiny.common.api; + +/** + * 封装API的错误码 + * Created by macro on 2019/4/19. + */ +public interface IErrorCode { + long getCode(); + + String getMessage(); +} diff --git a/mall-tiny-torna/src/main/java/com/macro/mall/tiny/common/api/ResultCode.java b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/common/api/ResultCode.java new file mode 100644 index 00000000..2e9368dd --- /dev/null +++ b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/common/api/ResultCode.java @@ -0,0 +1,28 @@ +package com.macro.mall.tiny.common.api; + +/** + * 枚举了一些常用API操作码 + * Created by macro on 2019/4/19. + */ +public enum ResultCode implements IErrorCode { + SUCCESS(200, "操作成功"), + FAILED(500, "操作失败"), + VALIDATE_FAILED(404, "参数检验失败"), + UNAUTHORIZED(401, "暂未登录或token已经过期"), + FORBIDDEN(403, "没有相关权限"); + private long code; + private String message; + + private ResultCode(long code, String message) { + this.code = code; + this.message = message; + } + + public long getCode() { + return code; + } + + public String getMessage() { + return message; + } +} diff --git a/mall-tiny-torna/src/main/java/com/macro/mall/tiny/common/utils/JwtTokenUtil.java b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/common/utils/JwtTokenUtil.java new file mode 100644 index 00000000..5ec26f6c --- /dev/null +++ b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/common/utils/JwtTokenUtil.java @@ -0,0 +1,137 @@ +package com.macro.mall.tiny.common.utils; + +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.stereotype.Component; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * JwtToken生成的工具类 + * JWT token的格式:header.payload.signature + * header的格式(算法、token的类型): + * {"alg": "HS512","typ": "JWT"} + * payload的格式(用户名、创建时间、生成时间): + * {"sub":"wang","created":1489079981393,"exp":1489684781} + * signature的生成算法: + * HMACSHA512(base64UrlEncode(header) + "." +base64UrlEncode(payload),secret) + * Created by macro on 2018/4/26. + */ +@Component +public class JwtTokenUtil { + private static final Logger LOGGER = LoggerFactory.getLogger(JwtTokenUtil.class); + private static final String CLAIM_KEY_USERNAME = "sub"; + private static final String CLAIM_KEY_CREATED = "created"; + @Value("${jwt.secret}") + private String secret; + @Value("${jwt.expiration}") + private Long expiration; + + /** + * 根据负责生成JWT的token + */ + private String generateToken(Map claims) { + return Jwts.builder() + .setClaims(claims) + .setExpiration(generateExpirationDate()) + .signWith(SignatureAlgorithm.HS512, secret) + .compact(); + } + + /** + * 从token中获取JWT中的负载 + */ + private Claims getClaimsFromToken(String token) { + Claims claims = null; + try { + claims = Jwts.parser() + .setSigningKey(secret) + .parseClaimsJws(token) + .getBody(); + } catch (Exception e) { + LOGGER.info("JWT格式验证失败:{}",token); + } + return claims; + } + + /** + * 生成token的过期时间 + */ + private Date generateExpirationDate() { + return new Date(System.currentTimeMillis() + expiration * 1000); + } + + /** + * 从token中获取登录用户名 + */ + public String getUserNameFromToken(String token) { + String username; + try { + Claims claims = getClaimsFromToken(token); + username = claims.getSubject(); + } catch (Exception e) { + username = null; + } + return username; + } + + /** + * 验证token是否还有效 + * + * @param token 客户端传入的token + * @param userDetails 从数据库中查询出来的用户信息 + */ + public boolean validateToken(String token, UserDetails userDetails) { + String username = getUserNameFromToken(token); + return username.equals(userDetails.getUsername()) && !isTokenExpired(token); + } + + /** + * 判断token是否已经失效 + */ + private boolean isTokenExpired(String token) { + Date expiredDate = getExpiredDateFromToken(token); + return expiredDate.before(new Date()); + } + + /** + * 从token中获取过期时间 + */ + private Date getExpiredDateFromToken(String token) { + Claims claims = getClaimsFromToken(token); + return claims.getExpiration(); + } + + /** + * 根据用户信息生成token + */ + public String generateToken(UserDetails userDetails) { + Map claims = new HashMap<>(); + claims.put(CLAIM_KEY_USERNAME, userDetails.getUsername()); + claims.put(CLAIM_KEY_CREATED, new Date()); + return generateToken(claims); + } + + /** + * 判断token是否可以被刷新 + */ + public boolean canRefresh(String token) { + return !isTokenExpired(token); + } + + /** + * 刷新token + */ + public String refreshToken(String token) { + Claims claims = getClaimsFromToken(token); + claims.put(CLAIM_KEY_CREATED, new Date()); + return generateToken(claims); + } +} diff --git a/mall-tiny-torna/src/main/java/com/macro/mall/tiny/component/JwtAuthenticationTokenFilter.java b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/component/JwtAuthenticationTokenFilter.java new file mode 100644 index 00000000..abdb7b71 --- /dev/null +++ b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/component/JwtAuthenticationTokenFilter.java @@ -0,0 +1,57 @@ +package com.macro.mall.tiny.component; + +import com.macro.mall.tiny.common.utils.JwtTokenUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.web.authentication.WebAuthenticationDetailsSource; +import org.springframework.web.filter.OncePerRequestFilter; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * JWT登录授权过滤器 + * Created by macro on 2018/4/26. + */ +public class JwtAuthenticationTokenFilter extends OncePerRequestFilter { + private static final Logger LOGGER = LoggerFactory.getLogger(JwtAuthenticationTokenFilter.class); + @Autowired + private UserDetailsService userDetailsService; + @Autowired + private JwtTokenUtil jwtTokenUtil; + @Value("${jwt.tokenHeader}") + private String tokenHeader; + @Value("${jwt.tokenHead}") + private String tokenHead; + + @Override + protected void doFilterInternal(HttpServletRequest request, + HttpServletResponse response, + FilterChain chain) throws ServletException, IOException { + String authHeader = request.getHeader(this.tokenHeader); + if (authHeader != null && authHeader.startsWith(this.tokenHead)) { + String authToken = authHeader.substring(this.tokenHead.length());// The part after "Bearer " + String username = jwtTokenUtil.getUserNameFromToken(authToken); + LOGGER.info("checking username:{}", username); + if (username != null && SecurityContextHolder.getContext().getAuthentication() == null) { + UserDetails userDetails = this.userDetailsService.loadUserByUsername(username); + if (jwtTokenUtil.validateToken(authToken, userDetails)) { + UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities()); + authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); + LOGGER.info("authenticated user:{}", username); + SecurityContextHolder.getContext().setAuthentication(authentication); + } + } + } + chain.doFilter(request, response); + } +} diff --git a/mall-tiny-torna/src/main/java/com/macro/mall/tiny/component/RestAuthenticationEntryPoint.java b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/component/RestAuthenticationEntryPoint.java new file mode 100644 index 00000000..757df36c --- /dev/null +++ b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/component/RestAuthenticationEntryPoint.java @@ -0,0 +1,27 @@ +package com.macro.mall.tiny.component; + +import cn.hutool.json.JSONUtil; +import com.macro.mall.tiny.common.api.CommonResult; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.web.AuthenticationEntryPoint; +import org.springframework.stereotype.Component; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * 当未登录或者token失效访问接口时,自定义的返回结果 + * Created by macro on 2018/5/14. + */ +@Component +public class RestAuthenticationEntryPoint implements AuthenticationEntryPoint { + @Override + public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application/json"); + response.getWriter().println(JSONUtil.parse(CommonResult.unauthorized(authException.getMessage()))); + response.getWriter().flush(); + } +} diff --git a/mall-tiny-torna/src/main/java/com/macro/mall/tiny/component/RestfulAccessDeniedHandler.java b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/component/RestfulAccessDeniedHandler.java new file mode 100644 index 00000000..bc201cce --- /dev/null +++ b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/component/RestfulAccessDeniedHandler.java @@ -0,0 +1,29 @@ +package com.macro.mall.tiny.component; + +import cn.hutool.json.JSONUtil; +import com.macro.mall.tiny.common.api.CommonResult; +import org.springframework.security.access.AccessDeniedException; +import org.springframework.security.web.access.AccessDeniedHandler; +import org.springframework.stereotype.Component; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * 当访问接口没有权限时,自定义的返回结果 + * Created by macro on 2018/4/26. + */ +@Component +public class RestfulAccessDeniedHandler implements AccessDeniedHandler{ + @Override + public void handle(HttpServletRequest request, + HttpServletResponse response, + AccessDeniedException e) throws IOException, ServletException { + response.setCharacterEncoding("UTF-8"); + response.setContentType("application/json"); + response.getWriter().println(JSONUtil.parse(CommonResult.forbidden(e.getMessage()))); + response.getWriter().flush(); + } +} diff --git a/mall-tiny-torna/src/main/java/com/macro/mall/tiny/config/MyBatisConfig.java b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/config/MyBatisConfig.java new file mode 100644 index 00000000..e680ce8a --- /dev/null +++ b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/config/MyBatisConfig.java @@ -0,0 +1,13 @@ +package com.macro.mall.tiny.config; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.context.annotation.Configuration; + +/** + * MyBatis配置类 + * Created by macro on 2019/4/8. + */ +@Configuration +@MapperScan("com.macro.mall.tiny.mbg.mapper") +public class MyBatisConfig { +} diff --git a/mall-tiny-torna/src/main/java/com/macro/mall/tiny/config/SecurityConfig.java b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/config/SecurityConfig.java new file mode 100644 index 00000000..ddb793de --- /dev/null +++ b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/config/SecurityConfig.java @@ -0,0 +1,111 @@ +package com.macro.mall.tiny.config; + +import com.macro.mall.tiny.component.JwtAuthenticationTokenFilter; +import com.macro.mall.tiny.component.RestAuthenticationEntryPoint; +import com.macro.mall.tiny.component.RestfulAccessDeniedHandler; +import com.macro.mall.tiny.domain.AdminUserDetails; +import com.macro.mall.tiny.service.UmsAdminService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpMethod; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; + + +/** + * SpringSecurity的配置 + * Created by macro on 2018/4/26. + */ +@Configuration +@EnableWebSecurity +@EnableGlobalMethodSecurity(prePostEnabled = true) +public class SecurityConfig extends WebSecurityConfigurerAdapter { + @Autowired + private UmsAdminService adminService; + @Autowired + private RestfulAccessDeniedHandler restfulAccessDeniedHandler; + @Autowired + private RestAuthenticationEntryPoint restAuthenticationEntryPoint; + + @Override + protected void configure(HttpSecurity httpSecurity) throws Exception { + httpSecurity.csrf()// 由于使用的是JWT,我们这里不需要csrf + .disable() + .sessionManagement()// 基于token,所以不需要session + .sessionCreationPolicy(SessionCreationPolicy.STATELESS) + .and() + .authorizeRequests() + .antMatchers(HttpMethod.GET, // 允许对于网站静态资源的无授权访问 + "/", + "/swagger-ui/", + "/*.html", + "/favicon.ico", + "/**/*.html", + "/**/*.css", + "/**/*.js", + "/swagger-resources/**", + "/v2/api-docs/**" + ) + .permitAll() + .antMatchers("/admin/login")// 对登录注册要允许匿名访问 + .permitAll() + .antMatchers(HttpMethod.OPTIONS)//跨域请求会先进行一次options请求 + .permitAll() + .anyRequest()// 除上面外的所有请求全部需要鉴权认证 + .authenticated(); + // 禁用缓存 + httpSecurity.headers().cacheControl(); + // 添加JWT filter + httpSecurity.addFilterBefore(jwtAuthenticationTokenFilter(), UsernamePasswordAuthenticationFilter.class); + //添加自定义未授权和未登录结果返回 + httpSecurity.exceptionHandling() + .accessDeniedHandler(restfulAccessDeniedHandler) + .authenticationEntryPoint(restAuthenticationEntryPoint); + } + + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + auth.userDetailsService(userDetailsService()) + .passwordEncoder(passwordEncoder()); + } + + @Bean + public PasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } + + @Bean + public UserDetailsService userDetailsService() { + //获取登录用户信息 + return username -> { + AdminUserDetails admin = adminService.getAdminByUsername(username); + if (admin != null) { + return admin; + } + throw new UsernameNotFoundException("用户名或密码错误"); + }; + } + + @Bean + public JwtAuthenticationTokenFilter jwtAuthenticationTokenFilter() { + return new JwtAuthenticationTokenFilter(); + } + + @Bean + @Override + public AuthenticationManager authenticationManagerBean() throws Exception { + return super.authenticationManagerBean(); + } + +} diff --git a/mall-tiny-torna/src/main/java/com/macro/mall/tiny/config/Swagger2Config.java b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/config/Swagger2Config.java new file mode 100644 index 00000000..0115ca4f --- /dev/null +++ b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/config/Swagger2Config.java @@ -0,0 +1,73 @@ +package com.macro.mall.tiny.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.*; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spi.service.contexts.SecurityContext; +import springfox.documentation.spring.web.plugins.Docket; + +import java.util.ArrayList; +import java.util.List; + +/** + * Swagger2API文档的配置 + */ +@Configuration +public class Swagger2Config { + @Bean + public Docket createRestApi() { + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo()) + .select() + .apis(RequestHandlerSelectors.basePackage("com.macro.mall.tiny.controller")) + .paths(PathSelectors.any()) + .build() + //添加登录认证 + .securitySchemes(securitySchemes()) + .securityContexts(securityContexts()); + } + + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("SwaggerUI演示") + .description("mall-tiny") + .contact(new Contact("macro", null, null)) + .version("1.0") + .build(); + } + + private List securitySchemes() { + //设置请求头信息 + List result = new ArrayList<>(); + ApiKey apiKey = new ApiKey("Authorization", "Authorization", "header"); + result.add(apiKey); + return result; + } + + private List securityContexts() { + //设置需要登录认证的路径 + List result = new ArrayList<>(); + result.add(getContextByPath("/brand/.*")); + return result; + } + + private SecurityContext getContextByPath(String pathRegex) { + return SecurityContext.builder() + .securityReferences(defaultAuth()) + .forPaths(PathSelectors.regex(pathRegex)) + .build(); + } + + private List defaultAuth() { + List result = new ArrayList<>(); + AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything"); + AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; + authorizationScopes[0] = authorizationScope; + result.add(new SecurityReference("Authorization", authorizationScopes)); + return result; + } +} diff --git a/mall-tiny-torna/src/main/java/com/macro/mall/tiny/controller/PmsBrandController.java b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/controller/PmsBrandController.java new file mode 100644 index 00000000..66508034 --- /dev/null +++ b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/controller/PmsBrandController.java @@ -0,0 +1,109 @@ +package com.macro.mall.tiny.controller; + +import com.macro.mall.tiny.common.api.CommonPage; +import com.macro.mall.tiny.common.api.CommonResult; +import com.macro.mall.tiny.mbg.model.PmsBrand; +import com.macro.mall.tiny.service.PmsBrandService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Controller; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + + +/** + * 品牌管理Controller + * Created by macro on 2019/4/19. + */ +@Api(tags = "PmsBrandController", description = "商品品牌管理") +@Controller +@RequestMapping("/brand") +public class PmsBrandController { + @Autowired + private PmsBrandService brandService; + + private static final Logger LOGGER = LoggerFactory.getLogger(PmsBrandController.class); + + @ApiOperation("获取所有品牌列表") + @RequestMapping(value = "listAll", method = RequestMethod.GET) + @ResponseBody + public CommonResult> getBrandList() { + return CommonResult.success(brandService.listAllBrand()); + } + + @ApiOperation("添加品牌") + @RequestMapping(value = "/create", method = RequestMethod.POST) + @ResponseBody + @PreAuthorize("hasRole('ADMIN')") + public CommonResult createBrand(@RequestBody PmsBrand pmsBrand) { + CommonResult commonResult; + int count = brandService.createBrand(pmsBrand); + if (count == 1) { + commonResult = CommonResult.success(pmsBrand); + LOGGER.debug("createBrand success:{}", pmsBrand); + } else { + commonResult = CommonResult.failed("操作失败"); + LOGGER.debug("createBrand failed:{}", pmsBrand); + } + return commonResult; + } + + @ApiOperation("更新指定id品牌信息") + @RequestMapping(value = "/update/{id}", method = RequestMethod.POST) + @ResponseBody + @PreAuthorize("hasRole('ADMIN')") + public CommonResult updateBrand(@PathVariable("id") Long id, @RequestBody PmsBrand pmsBrandDto, BindingResult result) { + CommonResult commonResult; + int count = brandService.updateBrand(id, pmsBrandDto); + if (count == 1) { + commonResult = CommonResult.success(pmsBrandDto); + LOGGER.debug("updateBrand success:{}", pmsBrandDto); + } else { + commonResult = CommonResult.failed("操作失败"); + LOGGER.debug("updateBrand failed:{}", pmsBrandDto); + } + return commonResult; + } + + @ApiOperation("删除指定id的品牌") + @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET) + @ResponseBody + @PreAuthorize("hasRole('ADMIN')") + public CommonResult deleteBrand(@PathVariable("id") Long id) { + int count = brandService.deleteBrand(id); + if (count == 1) { + LOGGER.debug("deleteBrand success :id={}", id); + return CommonResult.success(null); + } else { + LOGGER.debug("deleteBrand failed :id={}", id); + return CommonResult.failed("操作失败"); + } + } + + @ApiOperation("分页查询品牌列表") + @RequestMapping(value = "/list", method = RequestMethod.GET) + @ResponseBody + @PreAuthorize("hasRole('ADMIN')") + public CommonResult> listBrand(@RequestParam(value = "pageNum", defaultValue = "1") + @ApiParam("页码") Integer pageNum, + @RequestParam(value = "pageSize", defaultValue = "3") + @ApiParam("每页数量") Integer pageSize) { + List brandList = brandService.listBrand(pageNum, pageSize); + return CommonResult.success(CommonPage.restPage(brandList)); + } + + @ApiOperation("获取指定id的品牌详情") + @RequestMapping(value = "/{id}", method = RequestMethod.GET) + @ResponseBody + @PreAuthorize("hasRole('ADMIN')") + public CommonResult brand(@PathVariable("id") Long id) { + return CommonResult.success(brandService.getBrand(id)); + } +} diff --git a/mall-tiny-torna/src/main/java/com/macro/mall/tiny/controller/UmsAdminController.java b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/controller/UmsAdminController.java new file mode 100644 index 00000000..27e9d37d --- /dev/null +++ b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/controller/UmsAdminController.java @@ -0,0 +1,47 @@ +package com.macro.mall.tiny.controller; + +import com.macro.mall.tiny.common.api.CommonResult; +import com.macro.mall.tiny.service.UmsAdminService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import java.util.HashMap; +import java.util.Map; + +/** + * 后台用户管理 + * Created by macro on 2018/4/26. + */ +@Controller +@Api(tags = "UmsAdminController", description = "后台用户管理") +@RequestMapping("/admin") +public class UmsAdminController { + @Autowired + private UmsAdminService adminService; + @Value("${jwt.tokenHeader}") + private String tokenHeader; + @Value("${jwt.tokenHead}") + private String tokenHead; + + + @ApiOperation(value = "登录以后返回token") + @RequestMapping(value = "/login", method = RequestMethod.POST) + @ResponseBody + public CommonResult login(@RequestParam String username, @RequestParam String password) { + String token = adminService.login(username, password); + if (token == null) { + return CommonResult.validateFailed("用户名或密码错误"); + } + Map tokenMap = new HashMap<>(); + tokenMap.put("token", token); + tokenMap.put("tokenHead", tokenHead); + return CommonResult.success(tokenMap); + } +} diff --git a/mall-tiny-torna/src/main/java/com/macro/mall/tiny/domain/AdminUserDetails.java b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/domain/AdminUserDetails.java new file mode 100644 index 00000000..3152ef66 --- /dev/null +++ b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/domain/AdminUserDetails.java @@ -0,0 +1,58 @@ +package com.macro.mall.tiny.domain; + +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; + +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Created by macro on 2020/10/15. + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Builder +public class AdminUserDetails implements UserDetails { + private String username; + private String password; + private List authorityList; + @Override + public Collection getAuthorities() { + return this.authorityList.stream().map(SimpleGrantedAuthority::new).collect(Collectors.toList()); + } + + @Override + public String getPassword() { + return this.password; + } + + @Override + public String getUsername() { + return this.username; + } + + @Override + public boolean isAccountNonExpired() { + return true; + } + + @Override + public boolean isAccountNonLocked() { + return true; + } + + @Override + public boolean isCredentialsNonExpired() { + return true; + } + + @Override + public boolean isEnabled() { + return true; + } +} diff --git a/mall-tiny-torna/src/main/java/com/macro/mall/tiny/mbg/CommentGenerator.java b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/mbg/CommentGenerator.java new file mode 100644 index 00000000..162458af --- /dev/null +++ b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/mbg/CommentGenerator.java @@ -0,0 +1,73 @@ +package com.macro.mall.tiny.mbg; + +import org.mybatis.generator.api.IntrospectedColumn; +import org.mybatis.generator.api.IntrospectedTable; +import org.mybatis.generator.api.dom.java.CompilationUnit; +import org.mybatis.generator.api.dom.java.Field; +import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; +import org.mybatis.generator.internal.DefaultCommentGenerator; +import org.mybatis.generator.internal.util.StringUtility; + +import java.util.Properties; + +/** + * 自定义注释生成器 + * Created by macro on 2018/4/26. + */ +public class CommentGenerator extends DefaultCommentGenerator { + private boolean addRemarkComments = false; + private static final String EXAMPLE_SUFFIX="Example"; + private static final String API_MODEL_PROPERTY_FULL_CLASS_NAME="io.swagger.annotations.ApiModelProperty"; + + /** + * 设置用户配置的参数 + */ + @Override + public void addConfigurationProperties(Properties properties) { + super.addConfigurationProperties(properties); + this.addRemarkComments = StringUtility.isTrue(properties.getProperty("addRemarkComments")); + } + + /** + * 给字段添加注释 + */ + @Override + public void addFieldComment(Field field, IntrospectedTable introspectedTable, + IntrospectedColumn introspectedColumn) { + String remarks = introspectedColumn.getRemarks(); + //根据参数和备注信息判断是否添加备注信息 + if(addRemarkComments&&StringUtility.stringHasValue(remarks)){ +// addFieldJavaDoc(field, remarks); + //数据库中特殊字符需要转义 + if(remarks.contains("\"")){ + remarks = remarks.replace("\"","'"); + } + //给model的字段添加swagger注解 + field.addJavaDocLine("@ApiModelProperty(value = \""+remarks+"\")"); + } + } + + /** + * 给model的字段添加注释 + */ + private void addFieldJavaDoc(Field field, String remarks) { + //文档注释开始 + field.addJavaDocLine("/**"); + //获取数据库字段的备注信息 + String[] remarkLines = remarks.split(System.getProperty("line.separator")); + for(String remarkLine:remarkLines){ + field.addJavaDocLine(" * "+remarkLine); + } + addJavadocTag(field, false); + field.addJavaDocLine(" */"); + } + + @Override + public void addJavaFileComment(CompilationUnit compilationUnit) { + super.addJavaFileComment(compilationUnit); + //只在model中添加swagger注解类的导入 + if(!compilationUnit.isJavaInterface()&&!compilationUnit.getType().getFullyQualifiedName().contains(EXAMPLE_SUFFIX)){ + compilationUnit.addImportedType(new FullyQualifiedJavaType(API_MODEL_PROPERTY_FULL_CLASS_NAME)); + } + } +} diff --git a/mall-tiny-torna/src/main/java/com/macro/mall/tiny/mbg/Generator.java b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/mbg/Generator.java new file mode 100644 index 00000000..f7851362 --- /dev/null +++ b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/mbg/Generator.java @@ -0,0 +1,38 @@ +package com.macro.mall.tiny.mbg; + +import org.mybatis.generator.api.MyBatisGenerator; +import org.mybatis.generator.config.Configuration; +import org.mybatis.generator.config.xml.ConfigurationParser; +import org.mybatis.generator.internal.DefaultShellCallback; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +/** + * 用于生产MBG的代码 + * Created by macro on 2018/4/26. + */ +public class Generator { + public static void main(String[] args) throws Exception { + //MBG 执行过程中的警告信息 + List warnings = new ArrayList(); + //当生成的代码重复时,覆盖原代码 + boolean overwrite = true; + //读取我们的 MBG 配置文件 + InputStream is = Generator.class.getResourceAsStream("/generatorConfig.xml"); + ConfigurationParser cp = new ConfigurationParser(warnings); + Configuration config = cp.parseConfiguration(is); + is.close(); + + DefaultShellCallback callback = new DefaultShellCallback(overwrite); + //创建 MBG + MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings); + //执行生成代码 + myBatisGenerator.generate(null); + //输出警告信息 + for (String warning : warnings) { + System.out.println(warning); + } + } +} diff --git a/mall-tiny-torna/src/main/java/com/macro/mall/tiny/mbg/mapper/PmsBrandMapper.java b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/mbg/mapper/PmsBrandMapper.java new file mode 100644 index 00000000..617584fb --- /dev/null +++ b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/mbg/mapper/PmsBrandMapper.java @@ -0,0 +1,36 @@ +package com.macro.mall.tiny.mbg.mapper; + +import com.macro.mall.tiny.mbg.model.PmsBrand; +import com.macro.mall.tiny.mbg.model.PmsBrandExample; +import java.util.List; +import org.apache.ibatis.annotations.Param; + +public interface PmsBrandMapper { + int countByExample(PmsBrandExample example); + + int deleteByExample(PmsBrandExample example); + + int deleteByPrimaryKey(Long id); + + int insert(PmsBrand record); + + int insertSelective(PmsBrand record); + + List selectByExampleWithBLOBs(PmsBrandExample example); + + List selectByExample(PmsBrandExample example); + + PmsBrand selectByPrimaryKey(Long id); + + int updateByExampleSelective(@Param("record") PmsBrand record, @Param("example") PmsBrandExample example); + + int updateByExampleWithBLOBs(@Param("record") PmsBrand record, @Param("example") PmsBrandExample example); + + int updateByExample(@Param("record") PmsBrand record, @Param("example") PmsBrandExample example); + + int updateByPrimaryKeySelective(PmsBrand record); + + int updateByPrimaryKeyWithBLOBs(PmsBrand record); + + int updateByPrimaryKey(PmsBrand record); +} \ No newline at end of file diff --git a/mall-tiny-torna/src/main/java/com/macro/mall/tiny/mbg/model/PmsBrand.java b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/mbg/model/PmsBrand.java new file mode 100644 index 00000000..0d5dde95 --- /dev/null +++ b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/mbg/model/PmsBrand.java @@ -0,0 +1,147 @@ +package com.macro.mall.tiny.mbg.model; + +import io.swagger.annotations.ApiModelProperty; +import java.io.Serializable; + +public class PmsBrand implements Serializable { + private Long id; + + private String name; + + @ApiModelProperty(value = "首字母") + private String firstLetter; + + private Integer sort; + + @ApiModelProperty(value = "是否为品牌制造商:0->不是;1->是") + private Integer factoryStatus; + + private Integer showStatus; + + @ApiModelProperty(value = "产品数量") + private Integer productCount; + + @ApiModelProperty(value = "产品评论数量") + private Integer productCommentCount; + + @ApiModelProperty(value = "品牌logo") + private String logo; + + @ApiModelProperty(value = "专区大图") + private String bigPic; + + @ApiModelProperty(value = "品牌故事") + private String brandStory; + + private static final long serialVersionUID = 1L; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getFirstLetter() { + return firstLetter; + } + + public void setFirstLetter(String firstLetter) { + this.firstLetter = firstLetter; + } + + public Integer getSort() { + return sort; + } + + public void setSort(Integer sort) { + this.sort = sort; + } + + public Integer getFactoryStatus() { + return factoryStatus; + } + + public void setFactoryStatus(Integer factoryStatus) { + this.factoryStatus = factoryStatus; + } + + public Integer getShowStatus() { + return showStatus; + } + + public void setShowStatus(Integer showStatus) { + this.showStatus = showStatus; + } + + public Integer getProductCount() { + return productCount; + } + + public void setProductCount(Integer productCount) { + this.productCount = productCount; + } + + public Integer getProductCommentCount() { + return productCommentCount; + } + + public void setProductCommentCount(Integer productCommentCount) { + this.productCommentCount = productCommentCount; + } + + public String getLogo() { + return logo; + } + + public void setLogo(String logo) { + this.logo = logo; + } + + public String getBigPic() { + return bigPic; + } + + public void setBigPic(String bigPic) { + this.bigPic = bigPic; + } + + public String getBrandStory() { + return brandStory; + } + + public void setBrandStory(String brandStory) { + this.brandStory = brandStory; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", id=").append(id); + sb.append(", name=").append(name); + sb.append(", firstLetter=").append(firstLetter); + sb.append(", sort=").append(sort); + sb.append(", factoryStatus=").append(factoryStatus); + sb.append(", showStatus=").append(showStatus); + sb.append(", productCount=").append(productCount); + sb.append(", productCommentCount=").append(productCommentCount); + sb.append(", logo=").append(logo); + sb.append(", bigPic=").append(bigPic); + sb.append(", brandStory=").append(brandStory); + sb.append(", serialVersionUID=").append(serialVersionUID); + sb.append("]"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/mall-tiny-torna/src/main/java/com/macro/mall/tiny/mbg/model/PmsBrandExample.java b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/mbg/model/PmsBrandExample.java new file mode 100644 index 00000000..4e4a1108 --- /dev/null +++ b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/mbg/model/PmsBrandExample.java @@ -0,0 +1,840 @@ +package com.macro.mall.tiny.mbg.model; + +import java.util.ArrayList; +import java.util.List; + +public class PmsBrandExample { + protected String orderByClause; + + protected boolean distinct; + + protected List oredCriteria; + + public PmsBrandExample() { + oredCriteria = new ArrayList(); + } + + public void setOrderByClause(String orderByClause) { + this.orderByClause = orderByClause; + } + + public String getOrderByClause() { + return orderByClause; + } + + public void setDistinct(boolean distinct) { + this.distinct = distinct; + } + + public boolean isDistinct() { + return distinct; + } + + public List getOredCriteria() { + return oredCriteria; + } + + public void or(Criteria criteria) { + oredCriteria.add(criteria); + } + + public Criteria or() { + Criteria criteria = createCriteriaInternal(); + oredCriteria.add(criteria); + return criteria; + } + + public Criteria createCriteria() { + Criteria criteria = createCriteriaInternal(); + if (oredCriteria.size() == 0) { + oredCriteria.add(criteria); + } + return criteria; + } + + protected Criteria createCriteriaInternal() { + Criteria criteria = new Criteria(); + return criteria; + } + + public void clear() { + oredCriteria.clear(); + orderByClause = null; + distinct = false; + } + + protected abstract static class GeneratedCriteria { + protected List criteria; + + protected GeneratedCriteria() { + super(); + criteria = new ArrayList(); + } + + public boolean isValid() { + return criteria.size() > 0; + } + + public List getAllCriteria() { + return criteria; + } + + public List getCriteria() { + return criteria; + } + + protected void addCriterion(String condition) { + if (condition == null) { + throw new RuntimeException("Value for condition cannot be null"); + } + criteria.add(new Criterion(condition)); + } + + protected void addCriterion(String condition, Object value, String property) { + if (value == null) { + throw new RuntimeException("Value for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value)); + } + + protected void addCriterion(String condition, Object value1, Object value2, String property) { + if (value1 == null || value2 == null) { + throw new RuntimeException("Between values for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value1, value2)); + } + + public Criteria andIdIsNull() { + addCriterion("id is null"); + return (Criteria) this; + } + + public Criteria andIdIsNotNull() { + addCriterion("id is not null"); + return (Criteria) this; + } + + public Criteria andIdEqualTo(Long value) { + addCriterion("id =", value, "id"); + return (Criteria) this; + } + + public Criteria andIdNotEqualTo(Long value) { + addCriterion("id <>", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThan(Long value) { + addCriterion("id >", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThanOrEqualTo(Long value) { + addCriterion("id >=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThan(Long value) { + addCriterion("id <", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThanOrEqualTo(Long value) { + addCriterion("id <=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdIn(List values) { + addCriterion("id in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdNotIn(List values) { + addCriterion("id not in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdBetween(Long value1, Long value2) { + addCriterion("id between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andIdNotBetween(Long value1, Long value2) { + addCriterion("id not between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andNameIsNull() { + addCriterion("name is null"); + return (Criteria) this; + } + + public Criteria andNameIsNotNull() { + addCriterion("name is not null"); + return (Criteria) this; + } + + public Criteria andNameEqualTo(String value) { + addCriterion("name =", value, "name"); + return (Criteria) this; + } + + public Criteria andNameNotEqualTo(String value) { + addCriterion("name <>", value, "name"); + return (Criteria) this; + } + + public Criteria andNameGreaterThan(String value) { + addCriterion("name >", value, "name"); + return (Criteria) this; + } + + public Criteria andNameGreaterThanOrEqualTo(String value) { + addCriterion("name >=", value, "name"); + return (Criteria) this; + } + + public Criteria andNameLessThan(String value) { + addCriterion("name <", value, "name"); + return (Criteria) this; + } + + public Criteria andNameLessThanOrEqualTo(String value) { + addCriterion("name <=", value, "name"); + return (Criteria) this; + } + + public Criteria andNameLike(String value) { + addCriterion("name like", value, "name"); + return (Criteria) this; + } + + public Criteria andNameNotLike(String value) { + addCriterion("name not like", value, "name"); + return (Criteria) this; + } + + public Criteria andNameIn(List values) { + addCriterion("name in", values, "name"); + return (Criteria) this; + } + + public Criteria andNameNotIn(List values) { + addCriterion("name not in", values, "name"); + return (Criteria) this; + } + + public Criteria andNameBetween(String value1, String value2) { + addCriterion("name between", value1, value2, "name"); + return (Criteria) this; + } + + public Criteria andNameNotBetween(String value1, String value2) { + addCriterion("name not between", value1, value2, "name"); + return (Criteria) this; + } + + public Criteria andFirstLetterIsNull() { + addCriterion("first_letter is null"); + return (Criteria) this; + } + + public Criteria andFirstLetterIsNotNull() { + addCriterion("first_letter is not null"); + return (Criteria) this; + } + + public Criteria andFirstLetterEqualTo(String value) { + addCriterion("first_letter =", value, "firstLetter"); + return (Criteria) this; + } + + public Criteria andFirstLetterNotEqualTo(String value) { + addCriterion("first_letter <>", value, "firstLetter"); + return (Criteria) this; + } + + public Criteria andFirstLetterGreaterThan(String value) { + addCriterion("first_letter >", value, "firstLetter"); + return (Criteria) this; + } + + public Criteria andFirstLetterGreaterThanOrEqualTo(String value) { + addCriterion("first_letter >=", value, "firstLetter"); + return (Criteria) this; + } + + public Criteria andFirstLetterLessThan(String value) { + addCriterion("first_letter <", value, "firstLetter"); + return (Criteria) this; + } + + public Criteria andFirstLetterLessThanOrEqualTo(String value) { + addCriterion("first_letter <=", value, "firstLetter"); + return (Criteria) this; + } + + public Criteria andFirstLetterLike(String value) { + addCriterion("first_letter like", value, "firstLetter"); + return (Criteria) this; + } + + public Criteria andFirstLetterNotLike(String value) { + addCriterion("first_letter not like", value, "firstLetter"); + return (Criteria) this; + } + + public Criteria andFirstLetterIn(List values) { + addCriterion("first_letter in", values, "firstLetter"); + return (Criteria) this; + } + + public Criteria andFirstLetterNotIn(List values) { + addCriterion("first_letter not in", values, "firstLetter"); + return (Criteria) this; + } + + public Criteria andFirstLetterBetween(String value1, String value2) { + addCriterion("first_letter between", value1, value2, "firstLetter"); + return (Criteria) this; + } + + public Criteria andFirstLetterNotBetween(String value1, String value2) { + addCriterion("first_letter not between", value1, value2, "firstLetter"); + return (Criteria) this; + } + + public Criteria andSortIsNull() { + addCriterion("sort is null"); + return (Criteria) this; + } + + public Criteria andSortIsNotNull() { + addCriterion("sort is not null"); + return (Criteria) this; + } + + public Criteria andSortEqualTo(Integer value) { + addCriterion("sort =", value, "sort"); + return (Criteria) this; + } + + public Criteria andSortNotEqualTo(Integer value) { + addCriterion("sort <>", value, "sort"); + return (Criteria) this; + } + + public Criteria andSortGreaterThan(Integer value) { + addCriterion("sort >", value, "sort"); + return (Criteria) this; + } + + public Criteria andSortGreaterThanOrEqualTo(Integer value) { + addCriterion("sort >=", value, "sort"); + return (Criteria) this; + } + + public Criteria andSortLessThan(Integer value) { + addCriterion("sort <", value, "sort"); + return (Criteria) this; + } + + public Criteria andSortLessThanOrEqualTo(Integer value) { + addCriterion("sort <=", value, "sort"); + return (Criteria) this; + } + + public Criteria andSortIn(List values) { + addCriterion("sort in", values, "sort"); + return (Criteria) this; + } + + public Criteria andSortNotIn(List values) { + addCriterion("sort not in", values, "sort"); + return (Criteria) this; + } + + public Criteria andSortBetween(Integer value1, Integer value2) { + addCriterion("sort between", value1, value2, "sort"); + return (Criteria) this; + } + + public Criteria andSortNotBetween(Integer value1, Integer value2) { + addCriterion("sort not between", value1, value2, "sort"); + return (Criteria) this; + } + + public Criteria andFactoryStatusIsNull() { + addCriterion("factory_status is null"); + return (Criteria) this; + } + + public Criteria andFactoryStatusIsNotNull() { + addCriterion("factory_status is not null"); + return (Criteria) this; + } + + public Criteria andFactoryStatusEqualTo(Integer value) { + addCriterion("factory_status =", value, "factoryStatus"); + return (Criteria) this; + } + + public Criteria andFactoryStatusNotEqualTo(Integer value) { + addCriterion("factory_status <>", value, "factoryStatus"); + return (Criteria) this; + } + + public Criteria andFactoryStatusGreaterThan(Integer value) { + addCriterion("factory_status >", value, "factoryStatus"); + return (Criteria) this; + } + + public Criteria andFactoryStatusGreaterThanOrEqualTo(Integer value) { + addCriterion("factory_status >=", value, "factoryStatus"); + return (Criteria) this; + } + + public Criteria andFactoryStatusLessThan(Integer value) { + addCriterion("factory_status <", value, "factoryStatus"); + return (Criteria) this; + } + + public Criteria andFactoryStatusLessThanOrEqualTo(Integer value) { + addCriterion("factory_status <=", value, "factoryStatus"); + return (Criteria) this; + } + + public Criteria andFactoryStatusIn(List values) { + addCriterion("factory_status in", values, "factoryStatus"); + return (Criteria) this; + } + + public Criteria andFactoryStatusNotIn(List values) { + addCriterion("factory_status not in", values, "factoryStatus"); + return (Criteria) this; + } + + public Criteria andFactoryStatusBetween(Integer value1, Integer value2) { + addCriterion("factory_status between", value1, value2, "factoryStatus"); + return (Criteria) this; + } + + public Criteria andFactoryStatusNotBetween(Integer value1, Integer value2) { + addCriterion("factory_status not between", value1, value2, "factoryStatus"); + return (Criteria) this; + } + + public Criteria andShowStatusIsNull() { + addCriterion("show_status is null"); + return (Criteria) this; + } + + public Criteria andShowStatusIsNotNull() { + addCriterion("show_status is not null"); + return (Criteria) this; + } + + public Criteria andShowStatusEqualTo(Integer value) { + addCriterion("show_status =", value, "showStatus"); + return (Criteria) this; + } + + public Criteria andShowStatusNotEqualTo(Integer value) { + addCriterion("show_status <>", value, "showStatus"); + return (Criteria) this; + } + + public Criteria andShowStatusGreaterThan(Integer value) { + addCriterion("show_status >", value, "showStatus"); + return (Criteria) this; + } + + public Criteria andShowStatusGreaterThanOrEqualTo(Integer value) { + addCriterion("show_status >=", value, "showStatus"); + return (Criteria) this; + } + + public Criteria andShowStatusLessThan(Integer value) { + addCriterion("show_status <", value, "showStatus"); + return (Criteria) this; + } + + public Criteria andShowStatusLessThanOrEqualTo(Integer value) { + addCriterion("show_status <=", value, "showStatus"); + return (Criteria) this; + } + + public Criteria andShowStatusIn(List values) { + addCriterion("show_status in", values, "showStatus"); + return (Criteria) this; + } + + public Criteria andShowStatusNotIn(List values) { + addCriterion("show_status not in", values, "showStatus"); + return (Criteria) this; + } + + public Criteria andShowStatusBetween(Integer value1, Integer value2) { + addCriterion("show_status between", value1, value2, "showStatus"); + return (Criteria) this; + } + + public Criteria andShowStatusNotBetween(Integer value1, Integer value2) { + addCriterion("show_status not between", value1, value2, "showStatus"); + return (Criteria) this; + } + + public Criteria andProductCountIsNull() { + addCriterion("product_count is null"); + return (Criteria) this; + } + + public Criteria andProductCountIsNotNull() { + addCriterion("product_count is not null"); + return (Criteria) this; + } + + public Criteria andProductCountEqualTo(Integer value) { + addCriterion("product_count =", value, "productCount"); + return (Criteria) this; + } + + public Criteria andProductCountNotEqualTo(Integer value) { + addCriterion("product_count <>", value, "productCount"); + return (Criteria) this; + } + + public Criteria andProductCountGreaterThan(Integer value) { + addCriterion("product_count >", value, "productCount"); + return (Criteria) this; + } + + public Criteria andProductCountGreaterThanOrEqualTo(Integer value) { + addCriterion("product_count >=", value, "productCount"); + return (Criteria) this; + } + + public Criteria andProductCountLessThan(Integer value) { + addCriterion("product_count <", value, "productCount"); + return (Criteria) this; + } + + public Criteria andProductCountLessThanOrEqualTo(Integer value) { + addCriterion("product_count <=", value, "productCount"); + return (Criteria) this; + } + + public Criteria andProductCountIn(List values) { + addCriterion("product_count in", values, "productCount"); + return (Criteria) this; + } + + public Criteria andProductCountNotIn(List values) { + addCriterion("product_count not in", values, "productCount"); + return (Criteria) this; + } + + public Criteria andProductCountBetween(Integer value1, Integer value2) { + addCriterion("product_count between", value1, value2, "productCount"); + return (Criteria) this; + } + + public Criteria andProductCountNotBetween(Integer value1, Integer value2) { + addCriterion("product_count not between", value1, value2, "productCount"); + return (Criteria) this; + } + + public Criteria andProductCommentCountIsNull() { + addCriterion("product_comment_count is null"); + return (Criteria) this; + } + + public Criteria andProductCommentCountIsNotNull() { + addCriterion("product_comment_count is not null"); + return (Criteria) this; + } + + public Criteria andProductCommentCountEqualTo(Integer value) { + addCriterion("product_comment_count =", value, "productCommentCount"); + return (Criteria) this; + } + + public Criteria andProductCommentCountNotEqualTo(Integer value) { + addCriterion("product_comment_count <>", value, "productCommentCount"); + return (Criteria) this; + } + + public Criteria andProductCommentCountGreaterThan(Integer value) { + addCriterion("product_comment_count >", value, "productCommentCount"); + return (Criteria) this; + } + + public Criteria andProductCommentCountGreaterThanOrEqualTo(Integer value) { + addCriterion("product_comment_count >=", value, "productCommentCount"); + return (Criteria) this; + } + + public Criteria andProductCommentCountLessThan(Integer value) { + addCriterion("product_comment_count <", value, "productCommentCount"); + return (Criteria) this; + } + + public Criteria andProductCommentCountLessThanOrEqualTo(Integer value) { + addCriterion("product_comment_count <=", value, "productCommentCount"); + return (Criteria) this; + } + + public Criteria andProductCommentCountIn(List values) { + addCriterion("product_comment_count in", values, "productCommentCount"); + return (Criteria) this; + } + + public Criteria andProductCommentCountNotIn(List values) { + addCriterion("product_comment_count not in", values, "productCommentCount"); + return (Criteria) this; + } + + public Criteria andProductCommentCountBetween(Integer value1, Integer value2) { + addCriterion("product_comment_count between", value1, value2, "productCommentCount"); + return (Criteria) this; + } + + public Criteria andProductCommentCountNotBetween(Integer value1, Integer value2) { + addCriterion("product_comment_count not between", value1, value2, "productCommentCount"); + return (Criteria) this; + } + + public Criteria andLogoIsNull() { + addCriterion("logo is null"); + return (Criteria) this; + } + + public Criteria andLogoIsNotNull() { + addCriterion("logo is not null"); + return (Criteria) this; + } + + public Criteria andLogoEqualTo(String value) { + addCriterion("logo =", value, "logo"); + return (Criteria) this; + } + + public Criteria andLogoNotEqualTo(String value) { + addCriterion("logo <>", value, "logo"); + return (Criteria) this; + } + + public Criteria andLogoGreaterThan(String value) { + addCriterion("logo >", value, "logo"); + return (Criteria) this; + } + + public Criteria andLogoGreaterThanOrEqualTo(String value) { + addCriterion("logo >=", value, "logo"); + return (Criteria) this; + } + + public Criteria andLogoLessThan(String value) { + addCriterion("logo <", value, "logo"); + return (Criteria) this; + } + + public Criteria andLogoLessThanOrEqualTo(String value) { + addCriterion("logo <=", value, "logo"); + return (Criteria) this; + } + + public Criteria andLogoLike(String value) { + addCriterion("logo like", value, "logo"); + return (Criteria) this; + } + + public Criteria andLogoNotLike(String value) { + addCriterion("logo not like", value, "logo"); + return (Criteria) this; + } + + public Criteria andLogoIn(List values) { + addCriterion("logo in", values, "logo"); + return (Criteria) this; + } + + public Criteria andLogoNotIn(List values) { + addCriterion("logo not in", values, "logo"); + return (Criteria) this; + } + + public Criteria andLogoBetween(String value1, String value2) { + addCriterion("logo between", value1, value2, "logo"); + return (Criteria) this; + } + + public Criteria andLogoNotBetween(String value1, String value2) { + addCriterion("logo not between", value1, value2, "logo"); + return (Criteria) this; + } + + public Criteria andBigPicIsNull() { + addCriterion("big_pic is null"); + return (Criteria) this; + } + + public Criteria andBigPicIsNotNull() { + addCriterion("big_pic is not null"); + return (Criteria) this; + } + + public Criteria andBigPicEqualTo(String value) { + addCriterion("big_pic =", value, "bigPic"); + return (Criteria) this; + } + + public Criteria andBigPicNotEqualTo(String value) { + addCriterion("big_pic <>", value, "bigPic"); + return (Criteria) this; + } + + public Criteria andBigPicGreaterThan(String value) { + addCriterion("big_pic >", value, "bigPic"); + return (Criteria) this; + } + + public Criteria andBigPicGreaterThanOrEqualTo(String value) { + addCriterion("big_pic >=", value, "bigPic"); + return (Criteria) this; + } + + public Criteria andBigPicLessThan(String value) { + addCriterion("big_pic <", value, "bigPic"); + return (Criteria) this; + } + + public Criteria andBigPicLessThanOrEqualTo(String value) { + addCriterion("big_pic <=", value, "bigPic"); + return (Criteria) this; + } + + public Criteria andBigPicLike(String value) { + addCriterion("big_pic like", value, "bigPic"); + return (Criteria) this; + } + + public Criteria andBigPicNotLike(String value) { + addCriterion("big_pic not like", value, "bigPic"); + return (Criteria) this; + } + + public Criteria andBigPicIn(List values) { + addCriterion("big_pic in", values, "bigPic"); + return (Criteria) this; + } + + public Criteria andBigPicNotIn(List values) { + addCriterion("big_pic not in", values, "bigPic"); + return (Criteria) this; + } + + public Criteria andBigPicBetween(String value1, String value2) { + addCriterion("big_pic between", value1, value2, "bigPic"); + return (Criteria) this; + } + + public Criteria andBigPicNotBetween(String value1, String value2) { + addCriterion("big_pic not between", value1, value2, "bigPic"); + return (Criteria) this; + } + } + + public static class Criteria extends GeneratedCriteria { + + protected Criteria() { + super(); + } + } + + public static class Criterion { + private String condition; + + private Object value; + + private Object secondValue; + + private boolean noValue; + + private boolean singleValue; + + private boolean betweenValue; + + private boolean listValue; + + private String typeHandler; + + public String getCondition() { + return condition; + } + + public Object getValue() { + return value; + } + + public Object getSecondValue() { + return secondValue; + } + + public boolean isNoValue() { + return noValue; + } + + public boolean isSingleValue() { + return singleValue; + } + + public boolean isBetweenValue() { + return betweenValue; + } + + public boolean isListValue() { + return listValue; + } + + public String getTypeHandler() { + return typeHandler; + } + + protected Criterion(String condition) { + super(); + this.condition = condition; + this.typeHandler = null; + this.noValue = true; + } + + protected Criterion(String condition, Object value, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.typeHandler = typeHandler; + if (value instanceof List) { + this.listValue = true; + } else { + this.singleValue = true; + } + } + + protected Criterion(String condition, Object value) { + this(condition, value, null); + } + + protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.secondValue = secondValue; + this.typeHandler = typeHandler; + this.betweenValue = true; + } + + protected Criterion(String condition, Object value, Object secondValue) { + this(condition, value, secondValue, null); + } + } +} \ No newline at end of file diff --git a/mall-tiny-torna/src/main/java/com/macro/mall/tiny/service/PmsBrandService.java b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/service/PmsBrandService.java new file mode 100644 index 00000000..7171412b --- /dev/null +++ b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/service/PmsBrandService.java @@ -0,0 +1,24 @@ +package com.macro.mall.tiny.service; + + +import com.macro.mall.tiny.mbg.model.PmsBrand; + +import java.util.List; + +/** + * PmsBrandService + * Created by macro on 2019/4/19. + */ +public interface PmsBrandService { + List listAllBrand(); + + int createBrand(PmsBrand brand); + + int updateBrand(Long id, PmsBrand brand); + + int deleteBrand(Long id); + + List listBrand(int pageNum, int pageSize); + + PmsBrand getBrand(Long id); +} diff --git a/mall-tiny-torna/src/main/java/com/macro/mall/tiny/service/UmsAdminService.java b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/service/UmsAdminService.java new file mode 100644 index 00000000..6528582e --- /dev/null +++ b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/service/UmsAdminService.java @@ -0,0 +1,19 @@ +package com.macro.mall.tiny.service; + +import com.macro.mall.tiny.domain.AdminUserDetails; + +/** + * 后台用于管理Service + * Created by macro on 2020/10/15. + */ +public interface UmsAdminService { + /** + * 根据用户名获取用户信息 + */ + AdminUserDetails getAdminByUsername(String username); + + /** + * 用户名密码登录 + */ + String login(String username, String password); +} diff --git a/mall-tiny-torna/src/main/java/com/macro/mall/tiny/service/impl/PmsBrandServiceImpl.java b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/service/impl/PmsBrandServiceImpl.java new file mode 100644 index 00000000..2a2b102e --- /dev/null +++ b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/service/impl/PmsBrandServiceImpl.java @@ -0,0 +1,53 @@ +package com.macro.mall.tiny.service.impl; + +import com.github.pagehelper.PageHelper; +import com.macro.mall.tiny.mbg.mapper.PmsBrandMapper; +import com.macro.mall.tiny.mbg.model.PmsBrand; +import com.macro.mall.tiny.mbg.model.PmsBrandExample; +import com.macro.mall.tiny.service.PmsBrandService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * PmsBrandService实现类 + * Created by macro on 2019/4/19. + */ +@Service +public class PmsBrandServiceImpl implements PmsBrandService { + @Autowired + private PmsBrandMapper brandMapper; + + @Override + public List listAllBrand() { + return brandMapper.selectByExample(new PmsBrandExample()); + } + + @Override + public int createBrand(PmsBrand brand) { + return brandMapper.insertSelective(brand); + } + + @Override + public int updateBrand(Long id, PmsBrand brand) { + brand.setId(id); + return brandMapper.updateByPrimaryKeySelective(brand); + } + + @Override + public int deleteBrand(Long id) { + return brandMapper.deleteByPrimaryKey(id); + } + + @Override + public List listBrand(int pageNum, int pageSize) { + PageHelper.startPage(pageNum, pageSize); + return brandMapper.selectByExample(new PmsBrandExample()); + } + + @Override + public PmsBrand getBrand(Long id) { + return brandMapper.selectByPrimaryKey(id); + } +} diff --git a/mall-tiny-torna/src/main/java/com/macro/mall/tiny/service/impl/UmsAdminServiceImpl.java b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/service/impl/UmsAdminServiceImpl.java new file mode 100644 index 00000000..45347be4 --- /dev/null +++ b/mall-tiny-torna/src/main/java/com/macro/mall/tiny/service/impl/UmsAdminServiceImpl.java @@ -0,0 +1,78 @@ +package com.macro.mall.tiny.service.impl; + +import cn.hutool.core.collection.CollUtil; +import com.macro.mall.tiny.common.utils.JwtTokenUtil; +import com.macro.mall.tiny.domain.AdminUserDetails; +import com.macro.mall.tiny.service.UmsAdminService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.authentication.BadCredentialsException; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Created by macro on 2020/10/15. + */ +@Slf4j +@Service +public class UmsAdminServiceImpl implements UmsAdminService { + /** + * 存放默认用户信息 + */ + private List adminUserDetailsList = new ArrayList<>(); + @Autowired + private JwtTokenUtil jwtTokenUtil; + @Autowired + private PasswordEncoder passwordEncoder; + + @PostConstruct + private void init(){ + adminUserDetailsList.add(AdminUserDetails.builder() + .username("admin") + .password(passwordEncoder.encode("123456")) + .authorityList(CollUtil.toList("ROLE_ADMIN")) + .build()); + adminUserDetailsList.add(AdminUserDetails.builder() + .username("macro") + .password(passwordEncoder.encode("123456")) + .authorityList(CollUtil.toList("ROLE_USER")) + .build()); + } + @Override + public AdminUserDetails getAdminByUsername(String username) { + List findList = adminUserDetailsList.stream().filter(item -> item.getUsername().equals(username)).collect(Collectors.toList()); + if(CollUtil.isNotEmpty(findList)){ + return findList.get(0); + } + return null; + } + + @Override + public String login(String username, String password) { + String token = null; + try { + UserDetails userDetails = getAdminByUsername(username); + if(userDetails==null){ + return token; + } + if (!passwordEncoder.matches(password, userDetails.getPassword())) { + throw new BadCredentialsException("密码不正确"); + } + UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities()); + SecurityContextHolder.getContext().setAuthentication(authentication); + token = jwtTokenUtil.generateToken(userDetails); + } catch (AuthenticationException e) { + log.warn("登录异常:{}", e.getMessage()); + } + return token; + } +} diff --git a/mall-tiny-torna/src/main/resources/application.yml b/mall-tiny-torna/src/main/resources/application.yml new file mode 100644 index 00000000..5a618a77 --- /dev/null +++ b/mall-tiny-torna/src/main/resources/application.yml @@ -0,0 +1,24 @@ +server: + port: 8088 + +spring: + datasource: + url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai + username: root + password: root + +mybatis: + mapper-locations: + - classpath:mapper/*.xml + - classpath*:com/**/mapper/*.xml + +# 自定义jwt key +jwt: + tokenHeader: Authorization #JWT存储的请求头 + secret: mySecret #JWT加解密使用的密钥 + expiration: 604800 #JWT的超期限时间(60*60*24) + tokenHead: Bearer #JWT负载中拿到开头 + +springfox: + documentation: + enabled: true \ No newline at end of file diff --git a/mall-tiny-torna/src/main/resources/com/macro/mall/tiny/mbg/mapper/PmsBrandMapper.xml b/mall-tiny-torna/src/main/resources/com/macro/mall/tiny/mbg/mapper/PmsBrandMapper.xml new file mode 100644 index 00000000..1842e269 --- /dev/null +++ b/mall-tiny-torna/src/main/resources/com/macro/mall/tiny/mbg/mapper/PmsBrandMapper.xml @@ -0,0 +1,358 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + id, name, first_letter, sort, factory_status, show_status, product_count, product_comment_count, + logo, big_pic + + + brand_story + + + + + + delete from pms_brand + where id = #{id,jdbcType=BIGINT} + + + delete from pms_brand + + + + + + + SELECT LAST_INSERT_ID() + + insert into pms_brand (name, first_letter, sort, + factory_status, show_status, product_count, + product_comment_count, logo, big_pic, + brand_story) + values (#{name,jdbcType=VARCHAR}, #{firstLetter,jdbcType=VARCHAR}, #{sort,jdbcType=INTEGER}, + #{factoryStatus,jdbcType=INTEGER}, #{showStatus,jdbcType=INTEGER}, #{productCount,jdbcType=INTEGER}, + #{productCommentCount,jdbcType=INTEGER}, #{logo,jdbcType=VARCHAR}, #{bigPic,jdbcType=VARCHAR}, + #{brandStory,jdbcType=LONGVARCHAR}) + + + + SELECT LAST_INSERT_ID() + + insert into pms_brand + + + name, + + + first_letter, + + + sort, + + + factory_status, + + + show_status, + + + product_count, + + + product_comment_count, + + + logo, + + + big_pic, + + + brand_story, + + + + + #{name,jdbcType=VARCHAR}, + + + #{firstLetter,jdbcType=VARCHAR}, + + + #{sort,jdbcType=INTEGER}, + + + #{factoryStatus,jdbcType=INTEGER}, + + + #{showStatus,jdbcType=INTEGER}, + + + #{productCount,jdbcType=INTEGER}, + + + #{productCommentCount,jdbcType=INTEGER}, + + + #{logo,jdbcType=VARCHAR}, + + + #{bigPic,jdbcType=VARCHAR}, + + + #{brandStory,jdbcType=LONGVARCHAR}, + + + + + + update pms_brand + + + id = #{record.id,jdbcType=BIGINT}, + + + name = #{record.name,jdbcType=VARCHAR}, + + + first_letter = #{record.firstLetter,jdbcType=VARCHAR}, + + + sort = #{record.sort,jdbcType=INTEGER}, + + + factory_status = #{record.factoryStatus,jdbcType=INTEGER}, + + + show_status = #{record.showStatus,jdbcType=INTEGER}, + + + product_count = #{record.productCount,jdbcType=INTEGER}, + + + product_comment_count = #{record.productCommentCount,jdbcType=INTEGER}, + + + logo = #{record.logo,jdbcType=VARCHAR}, + + + big_pic = #{record.bigPic,jdbcType=VARCHAR}, + + + brand_story = #{record.brandStory,jdbcType=LONGVARCHAR}, + + + + + + + + update pms_brand + set id = #{record.id,jdbcType=BIGINT}, + name = #{record.name,jdbcType=VARCHAR}, + first_letter = #{record.firstLetter,jdbcType=VARCHAR}, + sort = #{record.sort,jdbcType=INTEGER}, + factory_status = #{record.factoryStatus,jdbcType=INTEGER}, + show_status = #{record.showStatus,jdbcType=INTEGER}, + product_count = #{record.productCount,jdbcType=INTEGER}, + product_comment_count = #{record.productCommentCount,jdbcType=INTEGER}, + logo = #{record.logo,jdbcType=VARCHAR}, + big_pic = #{record.bigPic,jdbcType=VARCHAR}, + brand_story = #{record.brandStory,jdbcType=LONGVARCHAR} + + + + + + update pms_brand + set id = #{record.id,jdbcType=BIGINT}, + name = #{record.name,jdbcType=VARCHAR}, + first_letter = #{record.firstLetter,jdbcType=VARCHAR}, + sort = #{record.sort,jdbcType=INTEGER}, + factory_status = #{record.factoryStatus,jdbcType=INTEGER}, + show_status = #{record.showStatus,jdbcType=INTEGER}, + product_count = #{record.productCount,jdbcType=INTEGER}, + product_comment_count = #{record.productCommentCount,jdbcType=INTEGER}, + logo = #{record.logo,jdbcType=VARCHAR}, + big_pic = #{record.bigPic,jdbcType=VARCHAR} + + + + + + update pms_brand + + + name = #{name,jdbcType=VARCHAR}, + + + first_letter = #{firstLetter,jdbcType=VARCHAR}, + + + sort = #{sort,jdbcType=INTEGER}, + + + factory_status = #{factoryStatus,jdbcType=INTEGER}, + + + show_status = #{showStatus,jdbcType=INTEGER}, + + + product_count = #{productCount,jdbcType=INTEGER}, + + + product_comment_count = #{productCommentCount,jdbcType=INTEGER}, + + + logo = #{logo,jdbcType=VARCHAR}, + + + big_pic = #{bigPic,jdbcType=VARCHAR}, + + + brand_story = #{brandStory,jdbcType=LONGVARCHAR}, + + + where id = #{id,jdbcType=BIGINT} + + + update pms_brand + set name = #{name,jdbcType=VARCHAR}, + first_letter = #{firstLetter,jdbcType=VARCHAR}, + sort = #{sort,jdbcType=INTEGER}, + factory_status = #{factoryStatus,jdbcType=INTEGER}, + show_status = #{showStatus,jdbcType=INTEGER}, + product_count = #{productCount,jdbcType=INTEGER}, + product_comment_count = #{productCommentCount,jdbcType=INTEGER}, + logo = #{logo,jdbcType=VARCHAR}, + big_pic = #{bigPic,jdbcType=VARCHAR}, + brand_story = #{brandStory,jdbcType=LONGVARCHAR} + where id = #{id,jdbcType=BIGINT} + + + update pms_brand + set name = #{name,jdbcType=VARCHAR}, + first_letter = #{firstLetter,jdbcType=VARCHAR}, + sort = #{sort,jdbcType=INTEGER}, + factory_status = #{factoryStatus,jdbcType=INTEGER}, + show_status = #{showStatus,jdbcType=INTEGER}, + product_count = #{productCount,jdbcType=INTEGER}, + product_comment_count = #{productCommentCount,jdbcType=INTEGER}, + logo = #{logo,jdbcType=VARCHAR}, + big_pic = #{bigPic,jdbcType=VARCHAR} + where id = #{id,jdbcType=BIGINT} + + \ No newline at end of file diff --git a/mall-tiny-torna/src/main/resources/generator.properties b/mall-tiny-torna/src/main/resources/generator.properties new file mode 100644 index 00000000..173547bb --- /dev/null +++ b/mall-tiny-torna/src/main/resources/generator.properties @@ -0,0 +1,4 @@ +jdbc.driverClass=com.mysql.cj.jdbc.Driver +jdbc.connectionURL=jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai +jdbc.userId=root +jdbc.password=root \ No newline at end of file diff --git a/mall-tiny-torna/src/main/resources/generatorConfig.xml b/mall-tiny-torna/src/main/resources/generatorConfig.xml new file mode 100644 index 00000000..e0852226 --- /dev/null +++ b/mall-tiny-torna/src/main/resources/generatorConfig.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
\ No newline at end of file diff --git a/mall-tiny-torna/src/main/resources/torna.json b/mall-tiny-torna/src/main/resources/torna.json new file mode 100644 index 00000000..d98bdb51 --- /dev/null +++ b/mall-tiny-torna/src/main/resources/torna.json @@ -0,0 +1,22 @@ +{ + // 开启推送 + "enable": true, + // 扫描package,多个用;隔开 + "basePackage": "com.macro.mall.tiny.controller", + // 推送URL,IP端口对应Torna服务器 + "url": "http://localhost:7700/api", + // appKey + "appKey": "20211103905498418195988480", + // secret + "secret": "~#ZS~!*2B3I01vbW0f9iKH,rzj-%Xv^Q", + // 模块token + "token": "74365d40038d4f648ae65a077d956836", + // 调试环境,格式:环境名称,调试路径,多个用"|"隔开 + "debugEnv": "test,http://localhost:8088", + // 推送人 + "author": "macro", + // 打开调试:true/false + "debug": true, + // 是否替换文档,true:替换,false:不替换(追加)。默认:true + "isReplace": true +} \ No newline at end of file diff --git a/mall-tiny-torna/src/test/java/com/macro/mall/tiny/MallTinyApplicationTests.java b/mall-tiny-torna/src/test/java/com/macro/mall/tiny/MallTinyApplicationTests.java new file mode 100644 index 00000000..a705e524 --- /dev/null +++ b/mall-tiny-torna/src/test/java/com/macro/mall/tiny/MallTinyApplicationTests.java @@ -0,0 +1,23 @@ +package com.macro.mall.tiny; + +import cn.torna.swaggerplugin.SwaggerPlugin; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class MallTinyApplicationTests { + + @Test + public void contextLoads() { + } + + @Test + public void pushDoc(){ + // 将文档推送到Torna服务中去,默认查找resources下的torna.json + SwaggerPlugin.pushDoc(); + } + +}