third 2021年11月1日14:44:40
parent
26cdee56a5
commit
5e1a9141ff
|
|
@ -0,0 +1,70 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>mystyle-cloud-parent</artifactId>
|
||||
<groupId>com.zhangmeng</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>mystyle-cloud-admin-manager</artifactId>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.zhangmeng</groupId>
|
||||
<artifactId>mystyle-cloud-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.zhangmeng</groupId>
|
||||
<artifactId>mystyle-cloud-model</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-sleuth</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.oschina.zcx7878</groupId>
|
||||
<artifactId>fastdfs-client-java</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.zhangmeng.admin.manager;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
@EnableFeignClients
|
||||
@ComponentScan(basePackages = {"com.zhangmeng.model","com.zhangmeng.admin.manager","com.zhangmeng.api"})
|
||||
public class AdminManagerApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AdminManagerApplication.class,args);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
package com.zhangmeng.admin.manager.config.verificationCode;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author zhangmeng
|
||||
* @version 1.0
|
||||
* @date 2020年11月16日16:34:08
|
||||
*/
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "verification-code")
|
||||
public class VerificationCodeConfig {
|
||||
|
||||
private String redisKey;
|
||||
|
||||
private Long expirationTime;
|
||||
|
||||
private Type type;
|
||||
|
||||
public enum Type {
|
||||
|
||||
RAM("内存"),
|
||||
MYSQL("mysql"),
|
||||
REDIS("redis");
|
||||
|
||||
private String description;
|
||||
|
||||
Type(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Long getExpirationTime() {
|
||||
return expirationTime;
|
||||
}
|
||||
|
||||
public void setExpirationTime(Long expirationTime) {
|
||||
this.expirationTime = expirationTime;
|
||||
}
|
||||
|
||||
public String getRedisKey() {
|
||||
return redisKey;
|
||||
}
|
||||
|
||||
public void setRedisKey(String redisKey) {
|
||||
this.redisKey = redisKey;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,160 @@
|
|||
package com.zhangmeng.admin.manager.controller;
|
||||
|
||||
import com.zhangmeng.admin.manager.service.PermissionService;
|
||||
import com.zhangmeng.api.service.admin_manager.PermissionControllerApi;
|
||||
import com.zhangmeng.model.base.baseController.BaseController;
|
||||
import com.zhangmeng.model.base.baseUtil.CommonUtil;
|
||||
import com.zhangmeng.model.entity.Permission;
|
||||
import com.zhangmeng.model.vo.Result;
|
||||
import com.zhangmeng.model.vo.ResultTree;
|
||||
import com.zhangmeng.model.vo.StatusCode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import tk.mybatis.mapper.entity.Condition;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/permission")
|
||||
public class PermissionController extends BaseController implements PermissionControllerApi {
|
||||
|
||||
@Autowired
|
||||
private PermissionService permissionService;
|
||||
|
||||
@Override
|
||||
@GetMapping("/list")
|
||||
public Result list(Integer pageNum, Integer pageSize, String title) {
|
||||
Condition condition = new Condition(Permission.class);
|
||||
Example.Criteria criteria = condition.createCriteria();
|
||||
if (CommonUtil.isNotNull(title)){
|
||||
criteria.andLike("title","%" + title + "%");
|
||||
}
|
||||
List<Permission> permissionList = this.permissionService.findByCondition(condition);
|
||||
return new Result(true, 0, "查询成功", permissionList);
|
||||
}
|
||||
|
||||
@Override
|
||||
@GetMapping("/selectParent")
|
||||
public ResultTree selectParent(String parentId) {
|
||||
Condition condition = new Condition(Permission.class);
|
||||
Example.Criteria criteria = condition.createCriteria();
|
||||
if (parentId != null && !parentId.equals("")) {
|
||||
criteria.andEqualTo("parent_id", Long.parseLong(parentId));
|
||||
}
|
||||
List<Permission> list = this.permissionService.findByCondition(condition);
|
||||
Permission basePower = new Permission();
|
||||
basePower.setTitle("顶级权限");
|
||||
basePower.setId(0L);
|
||||
basePower.setParent_id(-1L);
|
||||
list.add(basePower);
|
||||
return dataTree(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
@PostMapping("/save")
|
||||
public Result save(@RequestParam @RequestBody Map<String, Object> map) {
|
||||
Permission permission = null;
|
||||
boolean flag = false;
|
||||
String message = null;
|
||||
String id = CommonUtil.map_get_value(map, "id");
|
||||
if (id == null || id.equals("")) {
|
||||
permission = new Permission();
|
||||
flag = true;
|
||||
} else {
|
||||
permission = this.permissionService.findById(Long.parseLong(id));
|
||||
}
|
||||
String parentId = CommonUtil.map_get_value(map, "parentId");
|
||||
if (CommonUtil.isNotNull(parentId)) {
|
||||
permission.setParent_id(Long.parseLong(parentId));
|
||||
}
|
||||
|
||||
String title = CommonUtil.map_get_value(map, "title");
|
||||
if (CommonUtil.isNotNull(title)) {
|
||||
permission.setTitle(title);
|
||||
}
|
||||
|
||||
String code = CommonUtil.map_get_value(map, "code");
|
||||
|
||||
if (CommonUtil.isNotNull(code)) {
|
||||
permission.setCode(code);
|
||||
}
|
||||
|
||||
String type = CommonUtil.map_get_value(map, "type");
|
||||
|
||||
if (CommonUtil.isNotNull(type)) {
|
||||
Permission.Type permission_type = null;
|
||||
if (type.equals("CATALOG")) {
|
||||
permission_type = Permission.Type.CATALOG;
|
||||
}
|
||||
if (type.equals("MENU")) {
|
||||
permission_type = Permission.Type.MENU;
|
||||
}
|
||||
if (type.equals("BUTTON")) {
|
||||
permission_type = Permission.Type.BUTTON;
|
||||
}
|
||||
permission.setType(permission_type);
|
||||
}
|
||||
|
||||
String href = CommonUtil.map_get_value(map, "href");
|
||||
if (CommonUtil.isNotNull(href)) {
|
||||
permission.setHref(href);
|
||||
}
|
||||
|
||||
String openType = CommonUtil.map_get_value(map, "openType");
|
||||
if (CommonUtil.isNotNull(openType)) {
|
||||
permission.setOpenType(openType);
|
||||
}
|
||||
String icon = CommonUtil.map_get_value(map, "icon");
|
||||
if (CommonUtil.isNotNull(icon)) {
|
||||
permission.setIcon(icon);
|
||||
}
|
||||
|
||||
String sort = CommonUtil.map_get_value(map, "sort");
|
||||
if (CommonUtil.isNotNull(sort)) {
|
||||
//判断是否为数字
|
||||
if (CommonUtil.isNumeric_ASCII(sort)) {
|
||||
permission.setSort(Integer.parseInt(sort));
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
message = "保存成功";
|
||||
this.permissionService.save(permission);
|
||||
} else {
|
||||
message = "修改成功";
|
||||
this.permissionService.update(permission);
|
||||
}
|
||||
return new Result(true, StatusCode.OK, message);
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
@Override
|
||||
@PostMapping("/delete")
|
||||
public Result delete(String permissionId) {
|
||||
if (CommonUtil.isNotNull(permissionId)) {
|
||||
this.permissionService.deleteById(Long.parseLong(permissionId));
|
||||
}
|
||||
return new Result(true, StatusCode.OK, "删除成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
@PostMapping("/batchRemove")
|
||||
public Result batchRemove(String ids) {
|
||||
String id_s = CommonUtil.firstLastComma(ids);
|
||||
String[] strings = id_s.split(",");
|
||||
if (strings.length > 0) {
|
||||
for (String id : strings) {
|
||||
this.permissionService.deleteById(Long.parseLong(id));
|
||||
}
|
||||
}
|
||||
return new Result(true, 0, "删除成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
@GetMapping("/findByUserId")
|
||||
public List<Permission> findByUserId(Long id) {
|
||||
return this.permissionService.findByUserId(id);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,154 @@
|
|||
package com.zhangmeng.admin.manager.controller;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.zhangmeng.api.service.admin_manager.UserControllerApi;
|
||||
import com.zhangmeng.model.base.baseController.BaseController;
|
||||
import com.zhangmeng.model.base.baseUtil.CommonUtil;
|
||||
import com.zhangmeng.model.dto.QueryParams;
|
||||
import com.zhangmeng.model.entity.Role;
|
||||
import com.zhangmeng.model.entity.User;
|
||||
import com.zhangmeng.model.vo.Result;
|
||||
import com.zhangmeng.model.vo.StatusCode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import tk.mybatis.mapper.entity.Condition;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
import com.zhangmeng.admin.manager.service.UserService;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zhangmeng
|
||||
* @version 1.0
|
||||
* @date 2021年7月10日09:15:06
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/user")
|
||||
public class UserController extends BaseController implements UserControllerApi {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Override
|
||||
@PostMapping("/save")
|
||||
public Result save(@RequestParam @RequestBody Map<String, Object> parms) {
|
||||
return this.userService.save_user(parms);
|
||||
}
|
||||
|
||||
@Override
|
||||
@PostMapping("/delete")
|
||||
public Result delete(String userId) {
|
||||
if (userId != null && !userId.equals("")) {
|
||||
this.userService.deleteById(Long.parseLong(userId));
|
||||
}
|
||||
return new Result(true, StatusCode.OK, "删除成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
@GetMapping("/list")
|
||||
public Result list(Integer pageNum, Integer pageSize, String username, String telephone) {
|
||||
Condition condition = new Condition(User.class);
|
||||
Example.Criteria criteria = condition.createCriteria();
|
||||
if (username != null && !username.equals("")) {
|
||||
criteria.andLike("username", "%" + username + "%");
|
||||
}
|
||||
if (telephone != null && !telephone.equals("")) {
|
||||
criteria.andLike("telephone", "%" + telephone + "%");
|
||||
}
|
||||
PageInfo<User> pageInfo = this.userService.findByCondition(new QueryParams(pageNum, pageSize, condition,"addTime desc"),true);
|
||||
return new Result(true, StatusCode.OK, "查询成功",pageInfo.getTotal(), pageInfo.getList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@PostMapping("/batchRemove")
|
||||
public Result batchRemove(String ids){
|
||||
if (CommonUtil.isNotNull(ids)){
|
||||
this.userService.deleteByIds(CommonUtil.firstLastComma(ids));
|
||||
}
|
||||
return new Result(true,StatusCode.OK,"批量删除成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
@PostMapping("/reg_save")
|
||||
public Result reg_save(@RequestParam @RequestBody Map<String, Object> parms) {
|
||||
return this.userService.reg_save(parms);
|
||||
}
|
||||
|
||||
@Override
|
||||
@GetMapping("/current")
|
||||
public Result current(){
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@PostMapping("/personUpdate")
|
||||
public Result personUpdate(@RequestParam @RequestBody Map<String,Object> map){
|
||||
User user = null;
|
||||
boolean flag = false;
|
||||
String userId = CommonUtil.map_get_value(map, "userId");
|
||||
if (userId != null && !userId.equals("")){
|
||||
user = this.userService.findById(Long.parseLong(userId));
|
||||
flag = true;
|
||||
}else {
|
||||
user = new User();
|
||||
}
|
||||
String username = CommonUtil.map_get_value(map, "username");
|
||||
if (CommonUtil.isNotNull(username)){
|
||||
user.setUsername(username);
|
||||
}
|
||||
|
||||
String sex = CommonUtil.map_get_value(map, "sex");
|
||||
if (CommonUtil.isNotNull(sex)){
|
||||
user.setGender(CommonUtil.getEnum(sex,User.Gender.class));
|
||||
}
|
||||
String status = CommonUtil.map_get_value(map, "status");
|
||||
if (CommonUtil.isNotNull(status)){
|
||||
user.setStatus(CommonUtil.getEnum(status,User.Status.class));
|
||||
}
|
||||
|
||||
String role_type = CommonUtil.map_get_value(map, "role_name");
|
||||
if (CommonUtil.isNotNull(role_type)){
|
||||
user.setRoleType(CommonUtil.getEnum(role_type, Role.Type.class));
|
||||
}
|
||||
|
||||
String email = CommonUtil.map_get_value(map, "email");
|
||||
if (CommonUtil.isNotNull(email)){
|
||||
user.setEmail(email);
|
||||
}
|
||||
String telephone = CommonUtil.map_get_value(map, "telephone");
|
||||
if (CommonUtil.isNotNull(telephone)){
|
||||
user.setTelephone(telephone);
|
||||
}
|
||||
|
||||
String profession = CommonUtil.map_get_value(map, "profession");
|
||||
if (CommonUtil.isNotNull(profession)){
|
||||
user.setProfession(profession);
|
||||
}
|
||||
|
||||
String sign = CommonUtil.map_get_value(map, "sign");
|
||||
if (CommonUtil.isNotNull(sign)){
|
||||
user.setSign(sign);
|
||||
}
|
||||
|
||||
String file_id = CommonUtil.map_get_value(map, "file_id");
|
||||
if (CommonUtil.isNotNull(file_id)){
|
||||
user.setPhoto_id(Long.parseLong(file_id));
|
||||
}
|
||||
String upload_image = CommonUtil.map_get_value(map, "upload_image");
|
||||
if (CommonUtil.isNotNull(upload_image)){
|
||||
user.setAvatar(upload_image);
|
||||
}
|
||||
if (flag){
|
||||
this.userService.update(user);
|
||||
}else {
|
||||
this.userService.save(user);
|
||||
}
|
||||
return new Result(true,StatusCode.OK,"修改成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
@GetMapping("/findByUserName")
|
||||
public User findByUserName(String username) {
|
||||
return this.userService.loadUserByUsername(username);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,153 @@
|
|||
package com.zhangmeng.admin.manager.controller;
|
||||
|
||||
import cn.hutool.captcha.CaptchaUtil;
|
||||
import cn.hutool.captcha.ShearCaptcha;
|
||||
import com.wf.captcha.SpecCaptcha;
|
||||
import com.zhangmeng.admin.manager.config.verificationCode.VerificationCodeConfig;
|
||||
import com.zhangmeng.admin.manager.service.VerificationCodeService;
|
||||
import com.zhangmeng.admin.manager.utils.VerificationCodeUtil;
|
||||
import com.zhangmeng.api.service.admin_manager.VerificationCodeControllerApi;
|
||||
import com.zhangmeng.model.base.baseController.BaseController;
|
||||
import com.zhangmeng.model.base.baseUtil.CommonUtil;
|
||||
import com.zhangmeng.model.entity.VerificationCode;
|
||||
import com.zhangmeng.model.vo.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author zhangmeng
|
||||
* @version 1.0
|
||||
* @date 2021/1/21 21:41
|
||||
* <p>
|
||||
* 验证码控制器
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/verificationCode")
|
||||
public class VerificationCodeController extends BaseController implements VerificationCodeControllerApi {
|
||||
|
||||
/**
|
||||
* 验证码 参数
|
||||
*/
|
||||
private static final String SESSION_KEY = "captcha";
|
||||
|
||||
private static final int DEFAULT_LEN = 4; // 默认长度
|
||||
|
||||
private static final int DEFAULT_WIDTH = 130; // 默认宽度
|
||||
|
||||
private static final int DEFAULT_HEIGHT = 48; // 默认高度
|
||||
|
||||
@Autowired
|
||||
private VerificationCodeConfig verificationCodeConfig;
|
||||
|
||||
@Autowired
|
||||
private VerificationCodeService verificationCodeService;
|
||||
|
||||
|
||||
/**
|
||||
* 验证码生成
|
||||
*
|
||||
* @param request 请求报文 校验
|
||||
* @param response 响应报文
|
||||
*/
|
||||
@Override
|
||||
@RequestMapping("/generate")
|
||||
public String generate(HttpServletRequest request, HttpServletResponse response) {
|
||||
SpecCaptcha specCaptcha = new SpecCaptcha(DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_LEN);
|
||||
VerificationCodeConfig.Type type = this.verificationCodeConfig.getType();
|
||||
switch (type) {
|
||||
case MYSQL:
|
||||
this.verificationCodeService.mysql_save(specCaptcha);
|
||||
break;
|
||||
case REDIS:
|
||||
this.verificationCodeService.redis_save(specCaptcha);
|
||||
break;
|
||||
}
|
||||
//输出验证码到页面
|
||||
//specCaptcha.out(response.getOutputStream());
|
||||
return specCaptcha.text();
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步验证
|
||||
*
|
||||
* @param request 请求报文
|
||||
* @param captcha 验证码
|
||||
* @return 验证结果
|
||||
*/
|
||||
@Override
|
||||
@RequestMapping("/verify")
|
||||
public Result verify(HttpServletRequest request, String captcha) {
|
||||
if (com.wf.captcha.utils.CaptchaUtil.ver(captcha, request)) {
|
||||
return success("验证成功");
|
||||
}
|
||||
return failure("验证失败");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成验证码
|
||||
*
|
||||
* @param httpServletRequest imageIo
|
||||
* @param httpServletResponse imageIo
|
||||
*/
|
||||
@Override
|
||||
@GetMapping("/generateVerificationCode/v1")
|
||||
public void generateVerificationCodeV1(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
|
||||
@RequestParam(name = "vl", defaultValue = "4") Integer vcodeLength,//vcodeLength,验证码长度
|
||||
@RequestParam(name = "fs", defaultValue = "21") Integer fontSize,//fontSize,验证码字体大小
|
||||
@RequestParam(name = "w", defaultValue = "98") Integer width,//width,图片宽度
|
||||
@RequestParam(name = "h", defaultValue = "33") Integer height//height,图片高度
|
||||
) {
|
||||
VerificationCodeUtil verificationCodeUtil = new VerificationCodeUtil(vcodeLength, fontSize, width, height);
|
||||
String generatorVerificationCode = verificationCodeUtil.generatorVCode();
|
||||
this.verificationCodeService.cacheVerificationCode(generatorVerificationCode);
|
||||
try {
|
||||
ImageIO.write(verificationCodeUtil.generatorVCodeImage(generatorVerificationCode, true), "gif", httpServletResponse.getOutputStream());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成验证码
|
||||
*/
|
||||
@Override
|
||||
@GetMapping("/generateVerificationCode/v2")
|
||||
public String generateVerificationCodeV2() {
|
||||
ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(111, 36, 6, 6);
|
||||
// 验证码对应的字符串
|
||||
String code = captcha.getCode();
|
||||
this.verificationCodeService.cacheVerificationCode(code);
|
||||
return captcha.getImageBase64();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 模拟手机验证码
|
||||
*/
|
||||
@Override
|
||||
@GetMapping("/generateVerificationCode/v3")
|
||||
public Result generateVerificationCodeV3(String telephone) {
|
||||
String verifierCode = CommonUtil.mobileVerifierCode(6);
|
||||
//保存至数据库
|
||||
VerificationCode verificationCode = new VerificationCode();
|
||||
verificationCode.setAddTime(new Date());
|
||||
verificationCode.setDeleteStatus(false);
|
||||
verificationCode.setType(VerificationCode.Type.pc);
|
||||
verificationCode.setStatus(VerificationCode.Status.register);
|
||||
verificationCode.setTelephone(telephone);
|
||||
verificationCode.setCode(verifierCode);
|
||||
this.verificationCodeService.save(verificationCode);
|
||||
return new Result(true, 0, "发送成功", verifierCode);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package com.zhangmeng.admin.manager.dao;
|
||||
|
||||
|
||||
import com.zhangmeng.model.base.baseDao.AbstractBaseMapper;
|
||||
import com.zhangmeng.model.entity.Permission;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhengmeng
|
||||
* @version 1.0
|
||||
* @date 2021年1月7日17:44:40
|
||||
*/
|
||||
@Mapper
|
||||
public interface PermissionDao extends AbstractBaseMapper<Permission> {
|
||||
|
||||
@Results(value = {
|
||||
@Result(id = true,column = "id",property = "id"),
|
||||
@Result(column = "addTime",property = "addTime"),
|
||||
@Result(column = "updateTime",property = "updateTime"),
|
||||
@Result(column = "name",property = "name"),
|
||||
@Result(column = "type",property = "type"),
|
||||
@Result(column = "permissionCode",property = "permissionCode"),
|
||||
@Result(column = "url",property = "url"),
|
||||
@Result(column = "openType",property = "openType"),
|
||||
@Result(column = "parent_id",property = "parent_id"),
|
||||
@Result(column = "long_text_id",property = "long_text_id"),
|
||||
@Result(column = "parent_long_text_id",property = "parent_long_text_id"),
|
||||
@Result(column = "icon",property = "icon"),
|
||||
@Result(column = "sort",property = "sort"),
|
||||
})
|
||||
@Select("select DISTINCT p.* from permission p left join role_permission rp on p.id = rp.permission_id left join user_role ur on ur.role_id = rp.role_id where ur.user_id = #{userId}")
|
||||
List<Permission> findByUserId(@Param("userId") Long userId);
|
||||
|
||||
@Select("select * from permission p where p.parentId is null")
|
||||
List<Permission> findByParentIdIsNull();
|
||||
|
||||
@Select("select * from permission p where p.parentId = #{parentId}")
|
||||
List<Permission> findByParentId(Long parentId);
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.zhangmeng.admin.manager.dao;
|
||||
|
||||
import com.zhangmeng.model.base.baseDao.AbstractBaseMapper;
|
||||
import com.zhangmeng.model.entity.Role;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @author zhengmeng
|
||||
* @version 1.0
|
||||
* @date 2021年1月7日17:44:40
|
||||
*/
|
||||
@Mapper
|
||||
public interface RoleDao extends AbstractBaseMapper<Role> {
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.zhangmeng.admin.manager.dao;
|
||||
|
||||
|
||||
import com.zhangmeng.model.base.baseDao.AbstractBaseMapper;
|
||||
import com.zhangmeng.model.entity.RolePermission;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @author zhengmeng
|
||||
* @version 1.0
|
||||
* @date 2021年1月7日17:44:40
|
||||
*/
|
||||
@Mapper
|
||||
public interface RolePermissionDao extends AbstractBaseMapper<RolePermission> {
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.zhangmeng.admin.manager.dao;
|
||||
|
||||
import com.zhangmeng.model.base.baseDao.AbstractBaseMapper;
|
||||
import com.zhangmeng.model.entity.User;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @author zhengmeng
|
||||
* @version 1.0
|
||||
* @date 2021年1月7日17:44:40
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserDao extends AbstractBaseMapper<User> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.zhangmeng.admin.manager.dao;
|
||||
|
||||
|
||||
import com.zhangmeng.model.base.baseDao.AbstractBaseMapper;
|
||||
import com.zhangmeng.model.entity.UserRole;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @author zhengmeng
|
||||
* @version 1.0
|
||||
* @date 2021年1月7日17:44:40
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserRoleDao extends AbstractBaseMapper<UserRole> {
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.zhangmeng.admin.manager.dao;
|
||||
|
||||
import com.zhangmeng.model.base.baseDao.AbstractBaseMapper;
|
||||
import com.zhangmeng.model.entity.VerificationCode;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @author zhangmeng
|
||||
* @version 1.0
|
||||
* @date 2021/4/1 21:34
|
||||
*/
|
||||
@Mapper
|
||||
public interface VerificationCodeDao extends AbstractBaseMapper<VerificationCode> {
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.zhangmeng.admin.manager.service;
|
||||
|
||||
import com.zhangmeng.model.base.baseService.BaseService;
|
||||
import com.zhangmeng.model.dto.Menu;
|
||||
import com.zhangmeng.model.entity.Permission;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhangmeng
|
||||
* @version 1.0
|
||||
* @date 2021年1月7日22:32:54
|
||||
*/
|
||||
public interface PermissionService extends BaseService<Permission> {
|
||||
|
||||
List<Permission> findByUserId(Long userId);
|
||||
|
||||
List<Menu> toUserMenus(List<Permission> permissions, Long parentId);
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package com.zhangmeng.admin.manager.service;
|
||||
|
||||
import com.zhangmeng.model.base.baseService.BaseService;
|
||||
import com.zhangmeng.model.entity.RolePermission;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface RolePermissionService extends BaseService<RolePermission> {
|
||||
|
||||
List<RolePermission> findByRoleId(Long roleId);
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.zhangmeng.admin.manager.service;
|
||||
|
||||
|
||||
|
||||
import com.zhangmeng.model.base.baseService.BaseService;
|
||||
import com.zhangmeng.model.entity.Permission;
|
||||
import com.zhangmeng.model.entity.Role;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhangmeng
|
||||
* @version 1.0
|
||||
* @date 2021年1月7日22:32:54
|
||||
*/
|
||||
public interface RoleService extends BaseService<Role> {
|
||||
|
||||
List<Permission> getRolePermission(String roleId);
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.zhangmeng.admin.manager.service;
|
||||
|
||||
import com.zhangmeng.model.base.baseService.BaseService;
|
||||
import com.zhangmeng.model.entity.User;
|
||||
import com.zhangmeng.model.vo.Result;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zhangmeng
|
||||
* @version 1.0
|
||||
* @date 2021年1月7日22:32:54
|
||||
*/
|
||||
public interface UserService extends BaseService<User> {
|
||||
|
||||
User loadUserByUsername(String username);
|
||||
|
||||
Result save_user(Map<String, Object> parms);
|
||||
|
||||
Result reg_save(Map<String, Object> parms);
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package com.zhangmeng.admin.manager.service;
|
||||
|
||||
import com.wf.captcha.SpecCaptcha;
|
||||
import com.zhangmeng.model.base.baseService.BaseService;
|
||||
import com.zhangmeng.model.entity.VerificationCode;
|
||||
|
||||
|
||||
/**
|
||||
* @author zhangmeng
|
||||
* @version 1.0
|
||||
* @date 2021/4/1 21:32
|
||||
*/
|
||||
public interface VerificationCodeService extends BaseService<VerificationCode> {
|
||||
|
||||
public void mysql_save(SpecCaptcha specCaptcha);
|
||||
|
||||
public boolean mysql_verify(String code);
|
||||
|
||||
public void redis_save(SpecCaptcha specCaptcha);
|
||||
|
||||
public void cacheVerificationCode(String generatorVerificationCode);
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
package com.zhangmeng.admin.manager.service.impl;
|
||||
|
||||
import com.zhangmeng.admin.manager.dao.PermissionDao;
|
||||
import com.zhangmeng.admin.manager.service.PermissionService;
|
||||
import com.zhangmeng.model.base.baseService.impl.AbstractBaseServiceImpl;
|
||||
import com.zhangmeng.model.dto.Menu;
|
||||
import com.zhangmeng.model.entity.Permission;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhangmeng
|
||||
* @version 1.0
|
||||
* @date 2021年1月7日22:32:54
|
||||
*/
|
||||
@Service
|
||||
public class PermissionServiceImpl extends AbstractBaseServiceImpl<Permission> implements PermissionService {
|
||||
|
||||
@Autowired
|
||||
private PermissionDao permissionDao;
|
||||
|
||||
@Override
|
||||
public List<Permission> findByUserId(Long userId) {
|
||||
return this.permissionDao.findByUserId(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归获取菜单tree
|
||||
*
|
||||
* @param permissions 权限列表
|
||||
* @return list
|
||||
*/
|
||||
@Override
|
||||
public List<Menu> toUserMenus(List<Permission> permissions, Long parentId) {
|
||||
List<Menu> menuList = menuList(permissions);
|
||||
return toUserMenu(menuList, 0L);
|
||||
}
|
||||
|
||||
private List<Menu> toUserMenu(List<Menu> menuList, Long parentId) {
|
||||
List<Menu> list = new ArrayList<>();
|
||||
if (menuList.size() > 0) {
|
||||
for (Menu menu : menuList) {
|
||||
if (parentId.equals(menu.getParent_id())) {
|
||||
menu.setChildren(toUserMenu(menuList, menu.getId()));
|
||||
list.add(menu);
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<Menu> menuList(List<Permission> permissions) {
|
||||
List<Menu> menus = new ArrayList<>();
|
||||
if (permissions.size() > 0) {
|
||||
for (Permission permission : permissions) {
|
||||
Menu menu = new Menu();
|
||||
switch (permission.getType()){
|
||||
case CATALOG:
|
||||
menu.setType(0);
|
||||
break;
|
||||
case MENU:
|
||||
menu.setType(1);
|
||||
break;
|
||||
case BUTTON:
|
||||
menu.setType(2);
|
||||
break;
|
||||
}
|
||||
BeanUtils.copyProperties(permission, menu);
|
||||
menus.add(menu);
|
||||
}
|
||||
}
|
||||
return menus;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package com.zhangmeng.admin.manager.service.impl;
|
||||
|
||||
import com.zhangmeng.admin.manager.service.RolePermissionService;
|
||||
import com.zhangmeng.model.base.baseService.impl.AbstractBaseServiceImpl;
|
||||
import com.zhangmeng.model.entity.RolePermission;
|
||||
import org.springframework.stereotype.Service;
|
||||
import tk.mybatis.mapper.entity.Condition;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Service
|
||||
public class RolePermissionServiceImpl extends AbstractBaseServiceImpl<RolePermission> implements RolePermissionService {
|
||||
|
||||
@Override
|
||||
public List<RolePermission> findByRoleId(Long roleId) {
|
||||
Condition condition = new Condition(RolePermission.class);
|
||||
Example.Criteria criteria = condition.createCriteria();
|
||||
criteria.andEqualTo("role_id",roleId);
|
||||
return this.findByCondition(condition);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
package com.zhangmeng.admin.manager.service.impl;
|
||||
|
||||
import com.zhangmeng.admin.service.PermissionService;
|
||||
import com.zhangmeng.admin.service.RolePermissionService;
|
||||
import com.zhangmeng.admin.service.RoleService;
|
||||
import com.zhangmeng.common.base.baseService.impl.AbstractBaseServiceImpl;
|
||||
import com.zhangmeng.common.utils.CommonUtil;
|
||||
import com.zhangmeng.domain.admin.Permission;
|
||||
import com.zhangmeng.domain.admin.Role;
|
||||
import com.zhangmeng.domain.admin.RolePermission;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhangmeng
|
||||
* @version 1.0
|
||||
* @date 2021年1月7日22:32:54
|
||||
*/
|
||||
@Service
|
||||
public class RoleServiceImpl extends AbstractBaseServiceImpl<Role> implements RoleService {
|
||||
|
||||
@Autowired
|
||||
private RolePermissionService rolePermissionService;
|
||||
|
||||
@Autowired
|
||||
private PermissionService permissionService;
|
||||
|
||||
@Override
|
||||
public List<Permission> getRolePermission(String roleId) {
|
||||
if (CommonUtil.isNotNull(roleId)) {
|
||||
List<RolePermission> rolePermissionList = this.rolePermissionService.findByRoleId(Long.parseLong(roleId));
|
||||
List<Long> pIds = p_ids(rolePermissionList);
|
||||
List<Permission> permissionList = this.permissionService.findAll();
|
||||
if (permissionList.size() > 0){
|
||||
for (Permission permission : permissionList) {
|
||||
if (pIds.contains(permission.getId())){
|
||||
permission.setCheckArr("1");
|
||||
}
|
||||
}
|
||||
}
|
||||
return permissionList;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<Long> p_ids(List<RolePermission> rolePermissionList){
|
||||
List<Long> list = new ArrayList<>();
|
||||
if (rolePermissionList.size() > 0){
|
||||
for (RolePermission rolePermission : rolePermissionList) {
|
||||
list.add(rolePermission.getPermission_id());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,167 @@
|
|||
package com.zhangmeng.admin.manager.service.impl;
|
||||
|
||||
import com.zhangmeng.admin.manager.service.RoleService;
|
||||
import com.zhangmeng.admin.manager.service.UserService;
|
||||
import com.zhangmeng.model.base.baseService.impl.AbstractBaseServiceImpl;
|
||||
import com.zhangmeng.model.base.baseUtil.CommonUtil;
|
||||
import com.zhangmeng.model.dto.QuerySingleParams;
|
||||
import com.zhangmeng.model.entity.Role;
|
||||
import com.zhangmeng.model.entity.User;
|
||||
import com.zhangmeng.model.entity.UserRole;
|
||||
import com.zhangmeng.model.vo.Result;
|
||||
import com.zhangmeng.model.vo.StatusCode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import tk.mybatis.mapper.entity.Condition;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
import com.zhangmeng.admin.manager.dao.UserRoleDao;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zhangmeng
|
||||
* @version 1.0
|
||||
* @date 2021年1月7日22:32:54
|
||||
*/
|
||||
@Service
|
||||
public class UserServiceImpl extends AbstractBaseServiceImpl<User> implements UserService {
|
||||
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
|
||||
@Autowired
|
||||
private UserRoleDao userRoleDao;
|
||||
|
||||
@Override
|
||||
public User loadUserByUsername(String username) {
|
||||
Condition condition = new Condition(User.class);
|
||||
Example.Criteria criteria = condition.createCriteria();
|
||||
criteria.andEqualTo("username",username);
|
||||
User user = null;
|
||||
List<User> userList = this.findByCondition(condition);
|
||||
if (userList.size() > 0){
|
||||
user = userList.get(0);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result save_user(Map<String, Object> parms) {
|
||||
boolean flag = false;
|
||||
User user = null;
|
||||
String userId = CommonUtil.map_get_value(parms, "userId");
|
||||
if (userId == null || userId.equals("")) {
|
||||
user = new User();
|
||||
user.setAddTime(new Date());
|
||||
user.setUpdateTime(new Date());
|
||||
user.setDeleteStatus(false);
|
||||
flag = true;
|
||||
} else {
|
||||
user = this.findById(Long.parseLong(userId));
|
||||
}
|
||||
|
||||
String username = CommonUtil.map_get_value(parms, "username");
|
||||
if (CommonUtil.isNotNull(username)) {
|
||||
user.setUsername(username);
|
||||
}
|
||||
String name = CommonUtil.map_get_value(parms, "name");
|
||||
if (CommonUtil.isNotNull(name)) {
|
||||
user.setName(name);
|
||||
}
|
||||
String email = CommonUtil.map_get_value(parms, "email");
|
||||
if (CommonUtil.isNotNull(email)) {
|
||||
user.setEmail(email);
|
||||
}
|
||||
|
||||
String password = CommonUtil.map_get_value(parms, "password");
|
||||
if (CommonUtil.isNotNull(password)) {
|
||||
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
|
||||
user.setPassword(bCryptPasswordEncoder.encode(password));
|
||||
}
|
||||
|
||||
String phone = CommonUtil.map_get_value(parms, "phone");
|
||||
if (CommonUtil.isNotNull(phone)) {
|
||||
user.setTelephone(phone);
|
||||
}
|
||||
|
||||
String sex = CommonUtil.map_get_value(parms, "sex");
|
||||
User.Gender gender = null;
|
||||
if (CommonUtil.isNotNull(sex)) {
|
||||
if (sex.equals("0")) {
|
||||
gender = User.Gender.male;
|
||||
}
|
||||
if (sex.equals("1")) {
|
||||
gender = User.Gender.female;
|
||||
}
|
||||
}
|
||||
user.setGender(gender);
|
||||
String status = CommonUtil.map_get_value(parms, "status");
|
||||
User.Status status1 = null;
|
||||
if (CommonUtil.isNotNull(status)) {
|
||||
switch (status) {
|
||||
case "0":
|
||||
status1 = User.Status.DISABLED;
|
||||
break;
|
||||
case "1":
|
||||
status1 = User.Status.VALID;
|
||||
break;
|
||||
case "2":
|
||||
status1 = User.Status.LOCKED;
|
||||
break;
|
||||
}
|
||||
}
|
||||
String message = null;
|
||||
if (flag){
|
||||
this.save(user);
|
||||
String role_name = CommonUtil.map_get_value(parms, "role_name");
|
||||
if (CommonUtil.isNotNull(role_name)) {
|
||||
Role.Type type = CommonUtil.getEnum(role_name, Role.Type.class);
|
||||
Role role = this.roleService.findBySingleParams(new QuerySingleParams("type",type, QuerySingleParams.Type.equal)).get(0);
|
||||
UserRole userRole = new UserRole();
|
||||
userRole.setAddTime(new Date());
|
||||
userRole.setUpdateTime(new Date());
|
||||
userRole.setDeleteStatus(false);
|
||||
userRole.setRole_id(role.getId());
|
||||
userRole.setUser_id(user.getId());
|
||||
this.userRoleDao.insert(userRole);
|
||||
}
|
||||
user.setStatus(status1);
|
||||
this.update(user);
|
||||
message = "添加成功";
|
||||
}else {
|
||||
message = "修改成功";
|
||||
this.update(user);
|
||||
}
|
||||
return new Result(true, StatusCode.OK,message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result reg_save(Map<String, Object> parms) {
|
||||
String username = CommonUtil.map_get_value(parms, "username");
|
||||
String telephone = CommonUtil.map_get_value(parms, "telephone");
|
||||
String password = CommonUtil.map_get_value(parms, "password");
|
||||
Condition condition = new Condition(User.class);
|
||||
Example.Criteria criteria = condition.createCriteria();
|
||||
criteria.andLike("username", "%" + username + "%");
|
||||
criteria.andEqualTo("telephone", telephone);
|
||||
List<User> users = this.findByCondition(condition);
|
||||
|
||||
if (users.size() > 0) {
|
||||
return new Result(false, StatusCode.ERROR, "该手机号已经注册");
|
||||
} else {
|
||||
User user = new User();
|
||||
user.setAddTime(new Date());
|
||||
user.setUpdateTime(new Date());
|
||||
user.setDeleteStatus(false);
|
||||
user.setStatus(User.Status.VALID);
|
||||
user.setUsername(username);
|
||||
user.setTelephone(telephone);
|
||||
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
|
||||
user.setPassword(bCryptPasswordEncoder.encode(password));
|
||||
return new Result(true,StatusCode.OK,"注册成功");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
package com.zhangmeng.admin.manager.service.impl;
|
||||
|
||||
|
||||
import com.wf.captcha.SpecCaptcha;
|
||||
import com.zhangmeng.admin.manager.config.verificationCode.VerificationCodeConfig;
|
||||
import com.zhangmeng.admin.manager.service.VerificationCodeService;
|
||||
import com.zhangmeng.admin.manager.utils.RedisTemplateUtil;
|
||||
import com.zhangmeng.model.base.baseService.impl.AbstractBaseServiceImpl;
|
||||
import com.zhangmeng.model.base.baseUtil.CommonUtil;
|
||||
import com.zhangmeng.model.entity.VerificationCode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import tk.mybatis.mapper.entity.Condition;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author zhangmeng
|
||||
* @version 1.0
|
||||
* @date 2021/4/1 21:33
|
||||
*/
|
||||
@Service
|
||||
public class VerificationCodeServiceImpl extends AbstractBaseServiceImpl<VerificationCode> implements VerificationCodeService {
|
||||
|
||||
private final static String VERIFICATION_CODE_KEY = "VerificationCodeKey";
|
||||
|
||||
@Autowired
|
||||
private VerificationCodeConfig verificationCodeConfig;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, List<String>> redisTemplate;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplateUtil redisTemplateUtil;
|
||||
|
||||
@Override
|
||||
public void mysql_save(SpecCaptcha specCaptcha) {
|
||||
String text = specCaptcha.text();
|
||||
VerificationCode verificationCode = new VerificationCode();
|
||||
verificationCode.setDeleteStatus(false);
|
||||
verificationCode.setAddTime(new Date());
|
||||
verificationCode.setUpdateTime(new Date());
|
||||
verificationCode.setCode(text.toLowerCase());
|
||||
verificationCode.setStatus(VerificationCode.Status.login);
|
||||
verificationCode.setType(VerificationCode.Type.pc);
|
||||
this.save(verificationCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* mysql 验证码校验
|
||||
*
|
||||
* @param code 验证码
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean mysql_verify(String code) {
|
||||
boolean flag = false;
|
||||
long expirationTime = new Date().getTime() + this.verificationCodeConfig.getExpirationTime() * 1000; //毫秒
|
||||
Date date = new Date(expirationTime);
|
||||
Condition condition = new Condition(VerificationCode.class);
|
||||
Example.Criteria criteria = condition.createCriteria();
|
||||
criteria.andEqualTo("code", code);
|
||||
criteria.andLessThan("addTime", CommonUtil.data_format(date, CommonUtil.Format.YYYY_MM_DD_HH_MM_SS));
|
||||
List<VerificationCode> verificationCodes = this.findByCondition(condition);
|
||||
if (verificationCodes.size() > 0) {
|
||||
flag = true;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void redis_save(SpecCaptcha specCaptcha) {
|
||||
String code = specCaptcha.text();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put(String.valueOf(new Date().getTime()), code);
|
||||
this.redisTemplateUtil.set_verification_code_map(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存
|
||||
*
|
||||
* @param generatorVerificationCode 验证码
|
||||
*/
|
||||
public void cacheVerificationCode(String generatorVerificationCode) {
|
||||
//转小写
|
||||
generatorVerificationCode = generatorVerificationCode.toLowerCase();
|
||||
VerificationCodeConfig.Type type = this.verificationCodeConfig.getType();
|
||||
cacheVerificationCode2Redis(generatorVerificationCode);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 缓存验证码
|
||||
*
|
||||
* @param generatorVerificationCode 验证码
|
||||
*/
|
||||
private void cacheVerificationCode2Redis(String generatorVerificationCode) {
|
||||
//判断Redis 里面是否存在
|
||||
List<String> verificationCodeList = this.redisTemplate.opsForValue().get("VERIFICATION_CODE_KEY");
|
||||
if (verificationCodeList != null && verificationCodeList.size() > 0) {
|
||||
if (!verificationCodeList.contains(generatorVerificationCode)) {
|
||||
verificationCodeList.add(generatorVerificationCode);
|
||||
}
|
||||
} else {
|
||||
verificationCodeList = new ArrayList<>();
|
||||
verificationCodeList.add(generatorVerificationCode);
|
||||
}
|
||||
this.redisTemplate.boundValueOps(VERIFICATION_CODE_KEY).set(verificationCodeList, verificationCodeConfig.getExpirationTime(), TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package com.zhangmeng.admin.manager.utils;
|
||||
|
||||
import com.zhangmeng.admin.manager.config.verificationCode.VerificationCodeConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.HashOperations;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class RedisTemplateUtil {
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
@Autowired
|
||||
private VerificationCodeConfig verificationCodeConfig;
|
||||
|
||||
/**
|
||||
* 存储验证码集合
|
||||
* @param map 验证码集合
|
||||
*/
|
||||
public void set_verification_code_map(Map<String, Object> map) {
|
||||
this.redisTemplate.opsForHash().putAll(this.verificationCodeConfig.getRedisKey(), map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取验证码集合
|
||||
* @return map
|
||||
*/
|
||||
public Map<String, Object> get_verification_code_map() {
|
||||
HashOperations<String, String, Object> hashOperations = this.redisTemplate.opsForHash();
|
||||
return hashOperations.entries(this.verificationCodeConfig.getRedisKey());
|
||||
}
|
||||
|
||||
public boolean verification_code_isTrue(String code){
|
||||
boolean flag = false;
|
||||
Map<String, Object> verification_code_map = get_verification_code_map();
|
||||
for (Map.Entry<String, Object> entry : verification_code_map.entrySet()) {
|
||||
String value = String.valueOf(entry.getValue());
|
||||
if (value.equalsIgnoreCase(code)){
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,307 @@
|
|||
package com.zhangmeng.admin.manager.utils;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author zhangmeng
|
||||
* @version 1.0
|
||||
* @date 2021/1/21 21:31
|
||||
* 验证码生成器
|
||||
*/
|
||||
public class VerificationCodeUtil {
|
||||
|
||||
/**
|
||||
* 验证码来源
|
||||
*/
|
||||
final private char[] code = {
|
||||
'2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
|
||||
'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v',
|
||||
'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F',
|
||||
'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R',
|
||||
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
|
||||
};
|
||||
/**
|
||||
* 字体
|
||||
*/
|
||||
final private String[] fontNames = new String[]{
|
||||
"黑体", "宋体", "Courier", "Arial",
|
||||
"Verdana", "Times", "Tahoma", "Georgia"};
|
||||
/**
|
||||
* 字体样式
|
||||
*/
|
||||
final private int[] fontStyles = new int[]{
|
||||
Font.BOLD, Font.ITALIC | Font.BOLD
|
||||
};
|
||||
|
||||
/**
|
||||
* 验证码长度
|
||||
* 默认4个字符
|
||||
*/
|
||||
private int vcodeLen = 4;
|
||||
/**
|
||||
* 验证码图片字体大小
|
||||
* 默认17
|
||||
*/
|
||||
private int fontsize = 21;
|
||||
/**
|
||||
* 验证码图片宽度
|
||||
*/
|
||||
private int width = (fontsize + 1) * vcodeLen + 10;
|
||||
/**
|
||||
* 验证码图片高度
|
||||
*/
|
||||
private int height = fontsize + 12;
|
||||
/**
|
||||
* 干扰线条数
|
||||
* 默认3条
|
||||
*/
|
||||
private int disturbline = 3;
|
||||
|
||||
|
||||
public VerificationCodeUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定验证码长度
|
||||
*
|
||||
* @param vcodeLen 验证码长度
|
||||
*/
|
||||
public VerificationCodeUtil(int vcodeLen) {
|
||||
this.vcodeLen = vcodeLen;
|
||||
this.width = (fontsize + 1) * vcodeLen + 10;
|
||||
}
|
||||
|
||||
public VerificationCodeUtil(int vcodeLen, int fontSize) {
|
||||
this.vcodeLen = vcodeLen;
|
||||
this.fontsize = fontSize;
|
||||
this.width = (fontsize + 1) * vcodeLen + 10;
|
||||
height = fontsize + 12;
|
||||
}
|
||||
|
||||
public VerificationCodeUtil(Integer vcodeLen, Integer fontSize, Integer width, Integer height) {
|
||||
this.vcodeLen = vcodeLen;
|
||||
this.fontsize = fontSize;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成验证码图片
|
||||
*
|
||||
* @param vcode 要画的验证码
|
||||
* @param drawline 是否画干扰线
|
||||
* @return
|
||||
*/
|
||||
public BufferedImage generatorVCodeImage(String vcode, boolean drawline) {
|
||||
//创建验证码图片
|
||||
BufferedImage vcodeImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics g = vcodeImage.getGraphics();
|
||||
//填充背景色
|
||||
g.setColor(new Color(246, 240, 250));
|
||||
g.fillRect(0, 0, width, height);
|
||||
if (drawline) {
|
||||
drawDisturbLine(g);
|
||||
}
|
||||
//用于生成伪随机数
|
||||
Random ran = new Random();
|
||||
//在图片上画验证码
|
||||
for (int i = 0; i < vcode.length(); i++) {
|
||||
//设置字体
|
||||
g.setFont(new Font(fontNames[ran.nextInt(fontNames.length)], fontStyles[ran.nextInt(fontStyles.length)], fontsize));
|
||||
//随机生成颜色
|
||||
g.setColor(getRandomColor());
|
||||
//画验证码
|
||||
g.drawString(vcode.charAt(i) + "", i * fontsize + 10, fontsize + 5);
|
||||
}
|
||||
//释放此图形的上下文以及它使用的所有系统资源
|
||||
g.dispose();
|
||||
|
||||
return vcodeImage;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得旋转字体的验证码图片
|
||||
*
|
||||
* @param vcode String
|
||||
* @param drawline 是否画干扰线
|
||||
* @return BufferedImage
|
||||
*/
|
||||
public BufferedImage generatorRotateVCodeImage(String vcode, boolean drawline) {
|
||||
//创建验证码图片
|
||||
BufferedImage rotateVcodeImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D g2d = rotateVcodeImage.createGraphics();
|
||||
//填充背景色
|
||||
g2d.setColor(new Color(246, 240, 250));
|
||||
g2d.fillRect(0, 0, width, height);
|
||||
if (drawline) {
|
||||
drawDisturbLine(g2d);
|
||||
}
|
||||
//在图片上画验证码
|
||||
for (int i = 0; i < vcode.length(); i++) {
|
||||
BufferedImage rotateImage = getRotateImage(vcode.charAt(i));
|
||||
g2d.drawImage(rotateImage, null, (int) (this.height * 0.7) * i, 0);
|
||||
}
|
||||
g2d.dispose();
|
||||
return rotateVcodeImage;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成验证码
|
||||
*
|
||||
* @return 验证码
|
||||
*/
|
||||
public String generatorVCode() {
|
||||
int len = code.length;
|
||||
Random ran = new Random();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < vcodeLen; i++) {
|
||||
int index = ran.nextInt(len);
|
||||
sb.append(code[index]);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 为验证码图片画一些干扰线
|
||||
*
|
||||
* @param g Graphics
|
||||
*/
|
||||
private void drawDisturbLine(Graphics g) {
|
||||
Random ran = new Random();
|
||||
for (int i = 0; i < disturbline; i++) {
|
||||
int x1 = ran.nextInt(width);
|
||||
int y1 = ran.nextInt(height);
|
||||
int x2 = ran.nextInt(width);
|
||||
int y2 = ran.nextInt(height);
|
||||
g.setColor(getRandomColor());
|
||||
//画干扰线
|
||||
g.drawLine(x1, y1, x2, y2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一张旋转的图片
|
||||
*
|
||||
* @param c 要画的字符
|
||||
* @return BufferedImage
|
||||
*/
|
||||
private BufferedImage getRotateImage(char c) {
|
||||
BufferedImage rotateImage = new BufferedImage(height, height, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g2d = rotateImage.createGraphics();
|
||||
//设置透明度为0
|
||||
g2d.setColor(new Color(255, 255, 255, 0));
|
||||
g2d.fillRect(0, 0, height, height);
|
||||
Random ran = new Random();
|
||||
g2d.setFont(new Font(fontNames[ran.nextInt(fontNames.length)], fontStyles[ran.nextInt(fontStyles.length)], fontsize));
|
||||
g2d.setColor(getRandomColor());
|
||||
double theta = getTheta();
|
||||
//旋转图片
|
||||
g2d.rotate(theta, height / 2, height / 2);
|
||||
g2d.drawString(Character.toString(c), (height - fontsize) / 2, fontsize + 5);
|
||||
g2d.dispose();
|
||||
|
||||
return rotateImage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 返回一个随机颜色
|
||||
*/
|
||||
private Color getRandomColor() {
|
||||
Random ran = new Random();
|
||||
return new Color(ran.nextInt(220), ran.nextInt(220), ran.nextInt(220));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 角度
|
||||
*/
|
||||
private double getTheta() {
|
||||
return ((int) (Math.random() * 1000) % 2 == 0 ? -1 : 1) * Math.random();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 验证码字符个数
|
||||
*/
|
||||
public int getVcodeLen() {
|
||||
return vcodeLen;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置验证码字符个数
|
||||
*
|
||||
* @param vcodeLen 验证码字符个数
|
||||
*/
|
||||
public void setVcodeLen(int vcodeLen) {
|
||||
this.width = (fontsize + 3) * vcodeLen + 10;
|
||||
this.vcodeLen = vcodeLen;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 字体大小
|
||||
*/
|
||||
public int getFontsize() {
|
||||
return fontsize;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置字体大小
|
||||
*
|
||||
* @param fontsize 字体大小
|
||||
*/
|
||||
public void setFontsize(int fontsize) {
|
||||
this.width = (fontsize + 3) * vcodeLen + 10;
|
||||
this.height = fontsize + 15;
|
||||
this.fontsize = fontsize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 图片宽度
|
||||
*/
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置图片宽度
|
||||
*
|
||||
* @param width 宽度
|
||||
*/
|
||||
public void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 图片高度
|
||||
*/
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置图片高度
|
||||
*
|
||||
* @param height 图片高度
|
||||
*/
|
||||
public void setHeight(int height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 干扰线条数
|
||||
*/
|
||||
public int getDisturbline() {
|
||||
return disturbline;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置干扰线条数
|
||||
*
|
||||
* @param disturbline 干扰线条数
|
||||
*/
|
||||
public void setDisturbline(Integer disturbline) {
|
||||
this.disturbline = disturbline;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
server:
|
||||
port: 8763
|
||||
spring:
|
||||
application:
|
||||
name: mystyle-cloud-admin-manager
|
||||
datasource:
|
||||
username: root
|
||||
password: root
|
||||
url: jdbc:mysql://127.0.0.1:3306/mystyle-blog?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
jpa:
|
||||
database: mysql
|
||||
hibernate:
|
||||
ddl-auto: update
|
||||
naming:
|
||||
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
|
||||
show-sql: true
|
||||
properties:
|
||||
hibernate:
|
||||
dialect: org.hibernate.dialect.MySQL5Dialect
|
||||
zipkin:
|
||||
sender:
|
||||
type: web
|
||||
base-url: http://localhost:9411/
|
||||
service:
|
||||
name: mystyle-cloud-file
|
||||
sleuth:
|
||||
sampler:
|
||||
probability: 1
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 127.0.0.1:8848
|
||||
mybatis:
|
||||
type-aliases-package: com.zhangmeng.model.entity
|
||||
configuration:
|
||||
mapUnderscoreToCamelCase: true
|
||||
default-enum-type-handler: org.apache.ibatis.type.EnumOrdinalTypeHandler
|
||||
mapper:
|
||||
style: normal
|
||||
enum-as-simple-type: true
|
||||
identity: MYSQL
|
||||
check-example-entity-class: true
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>mystyle-cloud-parent</artifactId>
|
||||
<groupId>com.zhangmeng</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>mystyle-cloud-api</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.zhangmeng</groupId>
|
||||
<artifactId>mystyle-cloud-model</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-bean-validators</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
package com.zhangmeng.api.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 springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhangmeng
|
||||
* @version 1.0
|
||||
* @date 2021年7月8日09:12:01
|
||||
*/
|
||||
@EnableSwagger2
|
||||
@Configuration
|
||||
public class SwaggerConfig {
|
||||
|
||||
@Bean
|
||||
public Docket docket() {
|
||||
return new Docket(DocumentationType.SWAGGER_2).groupName("swagger接口文档")
|
||||
.apiInfo(new ApiInfoBuilder().title("swagger接口文档")
|
||||
.contact(new Contact("转身的背影在心底里沉沦", "", "1334717033.com")).version("1.0").build())
|
||||
.securitySchemes(securitySchemes())
|
||||
.securityContexts(securityContexts())
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("com.zhangmeng"))
|
||||
.paths(PathSelectors.any()).build();
|
||||
}
|
||||
|
||||
private List<ApiKey> securitySchemes() {
|
||||
List<ApiKey> apiKeyList= new ArrayList<>();
|
||||
apiKeyList.add(new ApiKey("token", "token", "header"));
|
||||
return apiKeyList;
|
||||
}
|
||||
|
||||
private List<SecurityContext> securityContexts() {
|
||||
List<SecurityContext> securityContexts=new ArrayList<>();
|
||||
securityContexts.add(
|
||||
SecurityContext.builder()
|
||||
.securityReferences(defaultAuth())
|
||||
.forPaths(PathSelectors.regex("^(?!auth).*$"))
|
||||
.build());
|
||||
return securityContexts;
|
||||
}
|
||||
|
||||
private List<SecurityReference> defaultAuth() {
|
||||
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
|
||||
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
|
||||
authorizationScopes[0] = authorizationScope;
|
||||
List<SecurityReference> securityReferences=new ArrayList<>();
|
||||
securityReferences.add(new SecurityReference("token", authorizationScopes));
|
||||
return securityReferences;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package com.zhangmeng.api.service.admin_manager;
|
||||
|
||||
|
||||
import com.zhangmeng.model.entity.Permission;
|
||||
import com.zhangmeng.model.vo.Result;
|
||||
import com.zhangmeng.model.vo.ResultTree;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Api(tags = "权限列表")
|
||||
public interface PermissionControllerApi {
|
||||
|
||||
@ApiOperation("权限列表")
|
||||
public Result list(Integer pageNum, Integer pageSize, String title);
|
||||
|
||||
@ApiOperation("查询上级")
|
||||
public ResultTree selectParent(String parentId);
|
||||
|
||||
@ApiOperation("保存权限")
|
||||
public Result save(@RequestParam @RequestBody Map<String, Object> map);
|
||||
|
||||
@ApiOperation("删除权限")
|
||||
public Result delete(String permissionId);
|
||||
|
||||
@ApiOperation("批量删除权限")
|
||||
public Result batchRemove(String ids);
|
||||
|
||||
@ApiOperation("根据userId查询权限")
|
||||
List<Permission> findByUserId(Long id);
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package com.zhangmeng.api.service.admin_manager;
|
||||
|
||||
import com.zhangmeng.model.entity.User;
|
||||
import com.zhangmeng.model.vo.Result;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Api(tags = "用户管理")
|
||||
public interface UserControllerApi {
|
||||
|
||||
@ApiOperation("用户保存")
|
||||
public Result save(@RequestParam @RequestBody Map<String, Object> parms);
|
||||
|
||||
@ApiOperation("用户删除")
|
||||
public Result delete(String userId);
|
||||
|
||||
@ApiOperation("用户列表")
|
||||
public Result list(Integer pageNum, Integer pageSize, String username, String telephone);
|
||||
|
||||
@ApiOperation("用户批量删除")
|
||||
public Result batchRemove(String ids);
|
||||
|
||||
@ApiOperation("注册保存")
|
||||
public Result reg_save(@RequestParam @RequestBody Map<String, Object> parms);
|
||||
|
||||
@ApiOperation("获取当前用户")
|
||||
public Result current();
|
||||
|
||||
@ApiOperation("个人资料修改")
|
||||
public Result personUpdate(@RequestParam @RequestBody Map<String, Object> map);
|
||||
|
||||
@ApiOperation("根据用户名称查询用户")
|
||||
public User findByUserName(String username);
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
package com.zhangmeng.api.service.admin_manager;
|
||||
|
||||
|
||||
import com.zhangmeng.model.vo.Result;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@Api(tags = "验证码管理")
|
||||
public interface VerificationCodeControllerApi {
|
||||
|
||||
/**
|
||||
* 验证码生成
|
||||
*
|
||||
* @param request 请求报文 校验
|
||||
* @param response 响应报文
|
||||
*/
|
||||
@ApiOperation("验证码生成")
|
||||
public String generate(HttpServletRequest request, HttpServletResponse response);
|
||||
|
||||
/**
|
||||
* 异步验证
|
||||
*
|
||||
* @param request 请求报文
|
||||
* @param captcha 验证码
|
||||
* @return 验证结果
|
||||
*/
|
||||
@ApiOperation("异步验证")
|
||||
public Result verify(HttpServletRequest request, String captcha);
|
||||
|
||||
|
||||
/**
|
||||
* 生成验证码
|
||||
*
|
||||
* @param httpServletRequest imageIo
|
||||
* @param httpServletResponse imageIo
|
||||
*/
|
||||
@ApiOperation("生成验证码V1")
|
||||
public void generateVerificationCodeV1(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
|
||||
@RequestParam(name = "vl", defaultValue = "4") Integer vcodeLength,//vcodeLength,验证码长度
|
||||
@RequestParam(name = "fs", defaultValue = "21") Integer fontSize,//fontSize,验证码字体大小
|
||||
@RequestParam(name = "w", defaultValue = "98") Integer width,//width,图片宽度
|
||||
@RequestParam(name = "h", defaultValue = "33") Integer height//height,图片高度
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* 生成验证码
|
||||
*/
|
||||
@ApiOperation("生成验证码V2")
|
||||
public String generateVerificationCodeV2();
|
||||
|
||||
|
||||
/**
|
||||
* 模拟手机验证码
|
||||
*/
|
||||
@ApiOperation("生成验证码V2")
|
||||
public Result generateVerificationCodeV3(String telephone);
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@ spring:
|
|||
discovery:
|
||||
server-addr: 127.0.0.1:8848
|
||||
mybatis:
|
||||
type-aliases-package: com.zhangmeng.domain.blog
|
||||
type-aliases-package: com.zhangmeng.model.entity
|
||||
configuration:
|
||||
mapUnderscoreToCamelCase: true
|
||||
default-enum-type-handler: org.apache.ibatis.type.EnumOrdinalTypeHandler
|
||||
|
|
|
|||
|
|
@ -68,5 +68,16 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--验证码-->
|
||||
<dependency>
|
||||
<groupId>com.github.whvcse</groupId>
|
||||
<artifactId>easy-captcha</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,193 @@
|
|||
package com.zhangmeng.model.base.baseUtil;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
public class CommonUtil {
|
||||
|
||||
public static boolean isNotNull(Object object) {
|
||||
return object != null && !"".equals(object);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T, K, V> T map_get_value(Map<K, V> map, T t) {
|
||||
return (T) map.get(t);
|
||||
}
|
||||
|
||||
public static boolean isNumeric_JDK(String str) {
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
if (!Character.isDigit(str.charAt(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isNumeric_ASCII(String str) {
|
||||
for (int i = str.length(); --i >= 0; ) {
|
||||
int chr = str.charAt(i);
|
||||
if (chr < 48 || chr > 57)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isNumeric_exception(String str) {
|
||||
try {
|
||||
Integer.parseInt(str);
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Long parseLong(String number) {
|
||||
if (isNumeric_ASCII(number)) {
|
||||
return Long.parseLong(number);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 去掉收尾逗号
|
||||
*/
|
||||
public static String firstLastComma(String string) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
String[] split = string.trim().split(",");
|
||||
if (split.length > 0) {
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
if (i == split.length - 1) {
|
||||
stringBuilder.append(split[i]);
|
||||
} else {
|
||||
if (!split[i].equals("")) {
|
||||
stringBuilder.append(split[i]).append(",");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
private static final String TOKEN_KEY = "token";
|
||||
|
||||
private static String YYYY = "yyyy";
|
||||
|
||||
private static String YYYY_MM = "yyyy-MM";
|
||||
|
||||
private static String YYYY_MM_DD = "yyyy-MM-dd";
|
||||
|
||||
private static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
private static Integer pageNum = 1;
|
||||
|
||||
private static Integer pageSize = 10;
|
||||
|
||||
private static String[] parsePatterns = {
|
||||
"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
|
||||
"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
|
||||
"yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};
|
||||
|
||||
public enum Format {
|
||||
|
||||
YYYY("yyyy"),
|
||||
YYYY_MM("yyyy-MM"),
|
||||
YYYY_MM_DD("yyyy-MM-dd"),
|
||||
YYYY_MM_DD_HH_MM_SS("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
Format(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
private String desc;
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public void setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 日期格式
|
||||
*
|
||||
* @param date 日期
|
||||
* @return String
|
||||
*/
|
||||
public static String data_format(Date date, Format format) {
|
||||
String format_string = null;
|
||||
switch (format) {
|
||||
case YYYY:
|
||||
format_string = YYYY;
|
||||
break;
|
||||
case YYYY_MM:
|
||||
format_string = YYYY_MM;
|
||||
break;
|
||||
case YYYY_MM_DD:
|
||||
format_string = YYYY_MM_DD;
|
||||
break;
|
||||
case YYYY_MM_DD_HH_MM_SS:
|
||||
format_string = YYYY_MM_DD_HH_MM_SS;
|
||||
break;
|
||||
}
|
||||
return new SimpleDateFormat(format_string).format(date);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 日期格式
|
||||
*
|
||||
* @param date 日期
|
||||
* @return String
|
||||
*/
|
||||
public static Date data_format(String date, Format format) {
|
||||
String format_string = null;
|
||||
switch (format) {
|
||||
case YYYY:
|
||||
format_string = YYYY;
|
||||
break;
|
||||
case YYYY_MM:
|
||||
format_string = YYYY_MM;
|
||||
break;
|
||||
case YYYY_MM_DD:
|
||||
format_string = YYYY_MM_DD;
|
||||
break;
|
||||
case YYYY_MM_DD_HH_MM_SS:
|
||||
format_string = YYYY_MM_DD_HH_MM_SS;
|
||||
break;
|
||||
}
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(format_string);
|
||||
try {
|
||||
return sdf.parse(date);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <T extends Enum<T>> T getEnum(String str, Class<T> enumClass) {
|
||||
if (isNotNull(str)) {
|
||||
return Enum.valueOf(enumClass, str);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 模拟手机验证码
|
||||
*
|
||||
* @param size 验证码的个数
|
||||
* @return String
|
||||
*/
|
||||
public static String mobileVerifierCode(int size) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (int i = 1; i <= size; i++) {
|
||||
//产生0~9的随机数
|
||||
int d = (int) (Math.random() * 9 + 1);
|
||||
stringBuilder.append(d);
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package com.zhangmeng.model.bean;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.GenericToStringSerializer;
|
||||
|
||||
/**
|
||||
* @author zhangmeng
|
||||
* @version 1.0
|
||||
* @date 2020年11月16日14:33:38
|
||||
*/
|
||||
@Configuration
|
||||
public class RedisConfig {
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Bean("redisTemplate")
|
||||
public RedisTemplate redisTemplate(@Lazy RedisConnectionFactory connectionFactory) {
|
||||
RedisTemplate redis = new RedisTemplate();
|
||||
GenericToStringSerializer<String> keySerializer = new GenericToStringSerializer<String>(String.class);
|
||||
redis.setKeySerializer(keySerializer);
|
||||
redis.setHashKeySerializer(keySerializer);
|
||||
GenericJackson2JsonRedisSerializer valueSerializer = new GenericJackson2JsonRedisSerializer();
|
||||
redis.setValueSerializer(valueSerializer);
|
||||
redis.setHashValueSerializer(valueSerializer);
|
||||
redis.setConnectionFactory(connectionFactory);
|
||||
return redis;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.zhangmeng.model.dto;
|
||||
|
||||
import com.zhangmeng.model.base.baseEntity.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 菜单封装类
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class Menu extends BaseEntity<Long> implements Serializable {
|
||||
|
||||
private String title;
|
||||
|
||||
private Integer type;
|
||||
|
||||
private String href;
|
||||
|
||||
private String openType;
|
||||
|
||||
private Long parent_id;
|
||||
|
||||
private String icon;
|
||||
|
||||
private List<Menu> children = new ArrayList<>();
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
package com.zhangmeng.model.dto;
|
||||
|
||||
import com.wf.captcha.SpecCaptcha;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class MySpecCaptcha extends SpecCaptcha {
|
||||
|
||||
private String code;
|
||||
|
||||
public MySpecCaptcha(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean out(OutputStream out) {
|
||||
return graphicsImage(code.toCharArray(), out);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成验证码图形
|
||||
*
|
||||
* @param strs 验证码
|
||||
* @param out 输出流
|
||||
* @return boolean
|
||||
*/
|
||||
private boolean graphicsImage(char[] strs, OutputStream out) {
|
||||
try {
|
||||
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D g2d = (Graphics2D) bi.getGraphics();
|
||||
// 填充背景
|
||||
g2d.setColor(Color.WHITE);
|
||||
g2d.fillRect(0, 0, width, height);
|
||||
// 抗锯齿
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
// 画干扰圆
|
||||
drawOval(2, g2d);
|
||||
// 画干扰线
|
||||
g2d.setStroke(new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
|
||||
drawBesselLine(1, g2d);
|
||||
// 画字符串
|
||||
g2d.setFont(getFont());
|
||||
FontMetrics fontMetrics = g2d.getFontMetrics();
|
||||
int fW = width / strs.length; // 每一个字符所占的宽度
|
||||
int fSp = (fW - (int) fontMetrics.getStringBounds("W", g2d).getWidth()) / 2; // 字符的左右边距
|
||||
for (int i = 0; i < strs.length; i++) {
|
||||
g2d.setColor(color());
|
||||
int fY = height - ((height - (int) fontMetrics.getStringBounds(String.valueOf(strs[i]), g2d).getHeight()) >> 1); // 文字的纵坐标
|
||||
g2d.drawString(String.valueOf(strs[i]), i * fW + fSp + 3, fY - 3);
|
||||
}
|
||||
g2d.dispose();
|
||||
ImageIO.write(bi, "png", out);
|
||||
out.flush();
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
34
pom.xml
34
pom.xml
|
|
@ -25,6 +25,9 @@
|
|||
<module>mystyle-cloud-file</module>
|
||||
<module>mystyle-cloud-gateway</module>
|
||||
<module>mystyle-cloud-model</module>
|
||||
<module>mystyle-cloud-admin-manager</module>
|
||||
<module>mystyle-cloud-api</module>
|
||||
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
|
|
@ -36,6 +39,9 @@
|
|||
<pagehelper.version>1.3.0</pagehelper.version>
|
||||
<fastdfs-client-java.version>1.27.0.0</fastdfs-client-java.version>
|
||||
<jackson.version>2.9.7</jackson.version>
|
||||
<hutool.version>5.5.7</hutool.version>
|
||||
<captcha.version>1.6.2</captcha.version>
|
||||
<swagger.version>2.8.0</swagger.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
|
@ -87,6 +93,34 @@
|
|||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
<!--验证码-->
|
||||
<dependency>
|
||||
<groupId>com.github.whvcse</groupId>
|
||||
<artifactId>easy-captcha</artifactId>
|
||||
<version>${captcha.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${swagger.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-bean-validators</artifactId>
|
||||
<version>${swagger.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${swagger.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
Loading…
Reference in New Issue