2024年2月4日18:20:26
parent
caa64d2bda
commit
01d4ae4bf3
7
pom.xml
7
pom.xml
|
|
@ -193,15 +193,10 @@
|
|||
<version>1.2.8</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.zhangmeng</groupId>
|
||||
<artifactId>db-tk-spring-boot-starter</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zhangmeng</groupId>
|
||||
<artifactId>jwt-security-spring-boot-starter</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<version>0.0.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,91 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.common.utils;
|
||||
|
||||
|
||||
import com.zhangmeng.fiction.server.dto.LoginUser;
|
||||
import com.zhangmeng.jwt.config.TokenConfig;
|
||||
import io.jsonwebtoken.ExpiredJwtException;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
import java.io.Serializable;
|
||||
import java.security.Key;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zhengmeng
|
||||
* @version 1.0
|
||||
* @date 2021年1月7日23:38:55
|
||||
*/
|
||||
@Component
|
||||
public class TokenUtil implements Serializable {
|
||||
|
||||
private Key KEY = null;
|
||||
|
||||
private final String LOGIN_USER_KEY = "LOGIN_USER_KEY";
|
||||
|
||||
@Autowired
|
||||
private TokenConfig tokenConfig;
|
||||
|
||||
/**
|
||||
* create token
|
||||
*
|
||||
* @param loginUser 登陆用户
|
||||
* @return token string
|
||||
*/
|
||||
public String createToken(LoginUser loginUser) {
|
||||
Map<String, Object> claims = new HashMap<>();
|
||||
// 放入一个随机字符串,通过该串可找到登陆用户
|
||||
claims.put(LOGIN_USER_KEY, loginUser.getToken());
|
||||
return Jwts.builder().setClaims(claims).signWith(SignatureAlgorithm.HS256, getKeyInstance()).compact();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get uuid from token
|
||||
*
|
||||
* @param jwtToken
|
||||
* @return
|
||||
*/
|
||||
public String getUid(String jwtToken) {
|
||||
if ("null".equals(jwtToken) || StringUtils.isBlank(jwtToken)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Map<String, Object> jwtClaims = Jwts.parser().setSigningKey(getKeyInstance()).parseClaimsJws(jwtToken).getBody();
|
||||
return MapUtils.getString(jwtClaims, LOGIN_USER_KEY);
|
||||
} catch (ExpiredJwtException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* tokens:uuid
|
||||
*
|
||||
* @param uuid 标识字符串
|
||||
* @return String
|
||||
*/
|
||||
public static String getTokenKey(String uuid) {
|
||||
return "tokens:" + uuid;
|
||||
}
|
||||
|
||||
public Key getKeyInstance() {
|
||||
if (KEY == null) {
|
||||
synchronized (TokenUtil.class) {
|
||||
// 双重锁
|
||||
if (KEY == null) {
|
||||
byte[] apiKeySecretBytes = DatatypeConverter.parseBase64Binary(tokenConfig.getJwtSecret());
|
||||
KEY = new SecretKeySpec(apiKeySecretBytes, SignatureAlgorithm.HS256.getJcaName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return KEY;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,221 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.controller;
|
||||
|
||||
|
||||
import com.zhangmeng.fiction.server.common.controller.BaseController;
|
||||
import com.zhangmeng.fiction.server.common.res.ResultTree;
|
||||
import com.zhangmeng.fiction.server.common.utils.CommonUtil;
|
||||
import com.zhangmeng.fiction.server.entity.Permission;
|
||||
import com.zhangmeng.fiction.server.res.Result;
|
||||
import com.zhangmeng.fiction.server.res.StatusCode;
|
||||
import com.zhangmeng.fiction.server.service.PermissionService;
|
||||
import com.zhangmeng.fiction.server.service.RolePermissionService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
import tk.mybatis.mapper.entity.Condition;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Api(tags = "权限管理")
|
||||
@RestController
|
||||
@RequestMapping("/permission")
|
||||
public class PermissionController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private PermissionService permissionService;
|
||||
|
||||
@Autowired
|
||||
private RolePermissionService rolePermissionService;
|
||||
|
||||
@ApiIgnore
|
||||
@GetMapping("/index")
|
||||
public ModelAndView index() {
|
||||
return this.jumpPage("admin/permission/list");
|
||||
}
|
||||
|
||||
@ApiIgnore
|
||||
@GetMapping("/add")
|
||||
public ModelAndView add(Model model) {
|
||||
model.addAttribute("permissionTypeList", Permission.Type.valueListMap());
|
||||
return this.jumpPage("admin/permission/add");
|
||||
}
|
||||
|
||||
@ApiIgnore
|
||||
@GetMapping("/edit")
|
||||
public ModelAndView edit(Model model, String permissionId) {
|
||||
if (CommonUtil.isNotNull(permissionId)) {
|
||||
Permission permission = this.permissionService.findById(Long.parseLong(permissionId));
|
||||
model.addAttribute("permission", permission);
|
||||
model.addAttribute("permissionTypeList",Permission.Type.valueListMap());
|
||||
}
|
||||
return this.jumpPage("admin/permission/edit");
|
||||
}
|
||||
|
||||
@ApiOperation("权限列表")
|
||||
@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 + "%");
|
||||
}
|
||||
// criteria.andEqualTo("status",Permission.Status.show);
|
||||
// PageHelper.startPage(pageNum,pageSize,"addTime desc");
|
||||
List<Permission> permissionList = this.permissionService.findByCondition(condition);
|
||||
// PageInfo<Permission> pageInfo = new PageInfo<>(permissionList);
|
||||
return new Result(true, 0, "查询成功", permissionList.size(),permissionList);
|
||||
}
|
||||
|
||||
@ApiOperation("查询上级")
|
||||
@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);
|
||||
}
|
||||
|
||||
@ApiOperation("保存权限")
|
||||
@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);
|
||||
}
|
||||
|
||||
@ApiOperation("删除权限")
|
||||
@PostMapping("/delete")
|
||||
public Result delete(String permissionId) {
|
||||
if (CommonUtil.isNotNull(permissionId)) {
|
||||
this.permissionService.deleteById(Long.parseLong(permissionId));
|
||||
}
|
||||
return new Result(true, StatusCode.OK, "删除成功");
|
||||
}
|
||||
|
||||
@ApiOperation("批量删除权限")
|
||||
@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, "删除成功");
|
||||
}
|
||||
|
||||
@ApiOperation("菜单的显示与隐藏")
|
||||
@PostMapping("/upStatus")
|
||||
public Result upStatus(@RequestParam @RequestBody Map<String,Object> params){
|
||||
String status = CommonUtil.map_get_value(params, "status");
|
||||
String id = CommonUtil.map_get_value(params, "id");
|
||||
|
||||
if (status == null || status.equals("")){
|
||||
return Result.failure("stats不能为空");
|
||||
}
|
||||
|
||||
if (id == null || id.equals("")){
|
||||
return Result.failure("id不能为空");
|
||||
}
|
||||
|
||||
if (status.equals("true")){
|
||||
status = "show";
|
||||
}else {
|
||||
status = "hidden";
|
||||
}
|
||||
|
||||
|
||||
Permission.Status st = CommonUtil.getEnum(status,Permission.Status.class);
|
||||
Permission permission = this.permissionService.findById(Long.parseLong(id));
|
||||
|
||||
if (permission != null){
|
||||
permission.setStatus(st);
|
||||
this.permissionService.update(permission);
|
||||
}
|
||||
|
||||
return Result.success("操作成功");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,161 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.controller;
|
||||
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.zhangmeng.db.tk.mybatis.QueryParams;
|
||||
import com.zhangmeng.fiction.server.common.controller.BaseController;
|
||||
import com.zhangmeng.fiction.server.common.res.ResultTree;
|
||||
import com.zhangmeng.fiction.server.common.utils.CommonUtil;
|
||||
import com.zhangmeng.fiction.server.entity.Role;
|
||||
import com.zhangmeng.fiction.server.res.Result;
|
||||
import com.zhangmeng.fiction.server.res.StatusCode;
|
||||
import com.zhangmeng.fiction.server.service.RoleService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
import tk.mybatis.mapper.entity.Condition;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
@Api(tags = "角色管理")
|
||||
@RestController
|
||||
@RequestMapping("/role")
|
||||
public class RoleController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
|
||||
@ApiIgnore
|
||||
@GetMapping("/index")
|
||||
public ModelAndView index() {
|
||||
return this.jumpPage("admin/role/list");
|
||||
}
|
||||
|
||||
@ApiIgnore
|
||||
@GetMapping("/add")
|
||||
public ModelAndView add(Model model) {
|
||||
model.addAttribute("roleStatusList", Role.Status.enumListMap());
|
||||
return this.jumpPage("admin/role/add");
|
||||
}
|
||||
|
||||
@ApiIgnore
|
||||
@GetMapping("/edit")
|
||||
public ModelAndView edit(Model model, String roleId) {
|
||||
if (roleId != null && !roleId.equals("")) {
|
||||
Role role = this.roleService.findById(Long.parseLong(roleId));
|
||||
model.addAttribute("roleTypeList", Role.Type.enumListMap());
|
||||
model.addAttribute("role", role);
|
||||
}
|
||||
return this.jumpPage("admin/role/edit");
|
||||
}
|
||||
|
||||
/**
|
||||
* 授权
|
||||
*
|
||||
* @param model
|
||||
* @param roleId
|
||||
* @return
|
||||
*/
|
||||
@ApiIgnore
|
||||
@GetMapping("/authorize")
|
||||
public ModelAndView authorize(Model model, String roleId) {
|
||||
if (roleId != null && !roleId.equals("")) {
|
||||
Role role = this.roleService.findById(Long.parseLong(roleId));
|
||||
model.addAttribute("roleTypeList", Role.Type.enumListMap());
|
||||
model.addAttribute("role", role);
|
||||
}
|
||||
return this.jumpPage("admin/role/authorize");
|
||||
}
|
||||
|
||||
@ApiOperation("角色保存")
|
||||
@PostMapping("/save")
|
||||
public Result save(@RequestParam @RequestBody Map<String, Object> map) {
|
||||
String roleId = CommonUtil.map_get_value(map, "roleId");
|
||||
boolean flag = false;
|
||||
Role role = null;
|
||||
if (roleId == null || roleId.equals("")) {
|
||||
flag = true;
|
||||
role = new Role();
|
||||
role.setAddTime(new Date());
|
||||
role.setUpdateTime(new Date());
|
||||
role.setDeleteStatus(false);
|
||||
} else {
|
||||
role = this.roleService.findById(Long.parseLong(roleId));
|
||||
}
|
||||
|
||||
String type = CommonUtil.map_get_value(map, "type");
|
||||
if (CommonUtil.isNotNull(type)) {
|
||||
role.setType(CommonUtil.getEnum(type, Role.Type.class));
|
||||
}
|
||||
String roleName = CommonUtil.map_get_value(map, "roleName");
|
||||
if (CommonUtil.isNotNull(roleName)) {
|
||||
role.setRoleName(roleName);
|
||||
}
|
||||
String status = CommonUtil.map_get_value(map, "status");
|
||||
if (CommonUtil.isNotNull(status)) {
|
||||
role.setStatus(CommonUtil.getEnum(status, Role.Status.class));
|
||||
}
|
||||
|
||||
String description = CommonUtil.map_get_value(map, "description");
|
||||
if (CommonUtil.isNotNull(description)) {
|
||||
role.setDescription(description);
|
||||
}
|
||||
if (flag) {
|
||||
this.roleService.save(role);
|
||||
} else {
|
||||
this.roleService.update(role);
|
||||
}
|
||||
return Result.success("添加成功");
|
||||
}
|
||||
|
||||
@ApiOperation("角色列表")
|
||||
@GetMapping("/list")
|
||||
public Result list(Integer pageNum, Integer pageSize,String roleName,String roleCode) {
|
||||
Condition condition = new Condition(Role.class);
|
||||
Example.Criteria criteria = condition.createCriteria();
|
||||
if (CommonUtil.isNotNull(roleName)){
|
||||
criteria.andEqualTo("roleName",roleName);
|
||||
}
|
||||
|
||||
if (CommonUtil.isNotNull(roleCode)){
|
||||
criteria.andEqualTo("roleCode",roleCode);
|
||||
}
|
||||
PageInfo<Role> pageInfo = this.roleService.findByCondition(new QueryParams(pageNum, pageSize, condition),true);
|
||||
return new Result(true, StatusCode.OK, "重新成功", pageInfo.getTotal(),pageInfo.getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Describe: 获取角色权限
|
||||
* Param RoleId
|
||||
* Return ResuTree
|
||||
*/
|
||||
@GetMapping("/getRolePower")
|
||||
@ApiOperation(value = "获取角色权限数据")
|
||||
public ResultTree getRolePower(String roleId) {
|
||||
return dataTree(this.roleService.getRolePermission(roleId));
|
||||
}
|
||||
|
||||
@ApiOperation("角色删除")
|
||||
@PostMapping("/delete")
|
||||
public Result delete(String roleId) {
|
||||
if (CommonUtil.isNotNull(roleId) && CommonUtil.isNumeric_ASCII(roleId)) {
|
||||
this.roleService.deleteById(Long.parseLong(roleId));
|
||||
}
|
||||
return Result.success("删除成功");
|
||||
}
|
||||
|
||||
@ApiOperation("批量删除")
|
||||
@PostMapping("/batchRemove")
|
||||
public Result batchRemove(String ids){
|
||||
if (CommonUtil.isNotNull(ids)){
|
||||
this.roleService.deleteByIds(CommonUtil.firstLastComma(ids));
|
||||
}
|
||||
return Result.success("批量删除成功");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,269 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.controller;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
|
||||
import com.zhangmeng.db.tk.mybatis.QueryParams;
|
||||
import com.zhangmeng.fiction.server.common.controller.BaseController;
|
||||
import com.zhangmeng.fiction.server.common.utils.CommonUtil;
|
||||
import com.zhangmeng.fiction.server.common.utils.UserUtil;
|
||||
import com.zhangmeng.fiction.server.dto.LoginUser;
|
||||
import com.zhangmeng.fiction.server.dto.Token;
|
||||
import com.zhangmeng.fiction.server.entity.Permission;
|
||||
import com.zhangmeng.fiction.server.entity.Role;
|
||||
import com.zhangmeng.fiction.server.entity.User;
|
||||
import com.zhangmeng.fiction.server.entity.VerificationCode;
|
||||
import com.zhangmeng.fiction.server.res.Result;
|
||||
import com.zhangmeng.fiction.server.res.StatusCode;
|
||||
import com.zhangmeng.fiction.server.service.PermissionService;
|
||||
import com.zhangmeng.fiction.server.service.TokenService;
|
||||
import com.zhangmeng.fiction.server.service.UserService;
|
||||
import com.zhangmeng.fiction.server.service.VerificationCodeService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
import tk.mybatis.mapper.entity.Condition;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zhangmeng
|
||||
* @version 1.0
|
||||
* @date 2021年7月10日09:15:06
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "用户管理")
|
||||
@RestController
|
||||
@RequestMapping("/user")
|
||||
public class UserController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private VerificationCodeService verificationCodeService;
|
||||
|
||||
@Autowired
|
||||
private PermissionService permissionService;
|
||||
|
||||
@Autowired
|
||||
private TokenService tokenService;
|
||||
|
||||
@ApiIgnore
|
||||
@GetMapping("/index")
|
||||
public ModelAndView index() {
|
||||
return this.jumpPage("admin/user/list");
|
||||
}
|
||||
|
||||
@ApiIgnore
|
||||
@GetMapping("/add")
|
||||
public ModelAndView add() {
|
||||
return this.jumpPage("admin/user/add");
|
||||
}
|
||||
|
||||
@ApiIgnore
|
||||
@GetMapping("/edit")
|
||||
public ModelAndView edit(Model model, String userId) {
|
||||
if (userId != null && !userId.equals("")) {
|
||||
User user = this.userService.findById(Long.parseLong(userId));
|
||||
model.addAttribute("user", user);
|
||||
}
|
||||
return this.jumpPage("admin/user/edit");
|
||||
}
|
||||
|
||||
@ApiIgnore
|
||||
@GetMapping("/person")
|
||||
public ModelAndView person(Model model) {
|
||||
User user = this.userService.findById(UserUtil.getLoginUser().getId());
|
||||
model.addAttribute("loginUser", user);
|
||||
//性别
|
||||
model.addAttribute("gender_list", User.Gender.enumListMap());
|
||||
//状态
|
||||
model.addAttribute("status_list", User.Status.enumListMap());
|
||||
//角色类型
|
||||
model.addAttribute("type_list", Role.Type.enumListMap());
|
||||
return this.jumpPage("admin/user/person");
|
||||
}
|
||||
|
||||
@ApiOperation("用户保存")
|
||||
@PostMapping("/save")
|
||||
public Result save(@RequestParam @RequestBody Map<String, Object> parms) {
|
||||
return this.userService.save_user(parms);
|
||||
}
|
||||
|
||||
@ApiOperation("用户删除")
|
||||
@PostMapping("/delete")
|
||||
public Result delete(String userId) {
|
||||
if (userId != null && !userId.equals("")) {
|
||||
this.userService.deleteById(Long.parseLong(userId));
|
||||
}
|
||||
return new Result(true, StatusCode.OK, "删除成功");
|
||||
}
|
||||
|
||||
@ApiOperation("用户列表")
|
||||
@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());
|
||||
}
|
||||
|
||||
@ApiOperation("用户批量删除")
|
||||
@PostMapping("/batchRemove")
|
||||
public Result batchRemove(String ids) {
|
||||
if (CommonUtil.isNotNull(ids)) {
|
||||
this.userService.deleteByIds(CommonUtil.firstLastComma(ids));
|
||||
}
|
||||
return Result.success("批量删除成功");
|
||||
}
|
||||
|
||||
@ApiIgnore
|
||||
@GetMapping("/reg")
|
||||
public ModelAndView reg() {
|
||||
return this.jumpPage("admin/user/reg");
|
||||
}
|
||||
|
||||
@ApiOperation("注册保存")
|
||||
@PostMapping("/reg_save")
|
||||
public Result reg_save(@RequestParam @RequestBody Map<String, Object> parms) {
|
||||
return this.userService.reg_save(parms);
|
||||
}
|
||||
|
||||
@ApiOperation("获取当前用户")
|
||||
@GetMapping("/current")
|
||||
public Result current() {
|
||||
return new Result(true, StatusCode.OK, "查询成功", UserUtil.getLoginUser());
|
||||
}
|
||||
|
||||
@ApiOperation("个人资料修改")
|
||||
@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);
|
||||
}
|
||||
|
||||
String now_pos = CommonUtil.map_get_value(map, "now_pos");
|
||||
if (CommonUtil.isNotNull(now_pos)) {
|
||||
user.setNow_pos(now_pos);
|
||||
}
|
||||
|
||||
if (flag) {
|
||||
this.userService.update(user);
|
||||
} else {
|
||||
this.userService.save(user);
|
||||
}
|
||||
return Result.success("修改成功");
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/loginVerification")
|
||||
public ResponseEntity<Object> loginVerification(@RequestBody Map<String, Object> params) {
|
||||
//判断验证码是否正确
|
||||
String telephone = CommonUtil.map_get_value(params, "phone");
|
||||
String code = CommonUtil.map_get_value(params, "verificationCode");
|
||||
boolean flag = false;
|
||||
if (CommonUtil.isNotNull(code) && CommonUtil.isNotNull(telephone)) {
|
||||
Condition condition = new Condition(VerificationCode.class);
|
||||
Example.Criteria criteria = condition.createCriteria();
|
||||
criteria.andEqualTo("telephone", telephone);
|
||||
criteria.andEqualTo("code", code);
|
||||
List<VerificationCode> codeList = this.verificationCodeService.findByCondition(condition);
|
||||
if (codeList.size() > 0) {
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
Token token = null;
|
||||
boolean istrue = false;
|
||||
if (flag) {
|
||||
//根据手机号查询登录对象
|
||||
Condition condition = new Condition(User.class);
|
||||
Example.Criteria criteria = condition.createCriteria();
|
||||
criteria.andEqualTo("telephone", telephone);
|
||||
List<User> users = this.userService.findByCondition(condition);
|
||||
if (users.size() > 0) {
|
||||
User user = users.get(0);
|
||||
List<Permission> permissions = this.permissionService.findByUserId(user.getId());
|
||||
LoginUser loginUser = new LoginUser();
|
||||
BeanUtils.copyProperties(user, loginUser);
|
||||
loginUser.setPermissions(permissions);
|
||||
token = this.tokenService.saveToken(loginUser);
|
||||
istrue = true;
|
||||
}
|
||||
}
|
||||
if (istrue){
|
||||
Map<String,Object> result = new HashMap<>();
|
||||
result.put("isNew", false); result.put("token", token.getToken());
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.dao;
|
||||
|
||||
import com.zhangmeng.db.tk.base.AbstractBaseMapper;
|
||||
import com.zhangmeng.fiction.server.entity.FictionCategory;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface FictionCategoryDao extends AbstractBaseMapper<FictionCategory> {
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.dao;
|
||||
|
||||
|
||||
import com.zhangmeng.db.tk.base.AbstractBaseMapper;
|
||||
import com.zhangmeng.fiction.server.entity.FictionChapter;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface FictionChapterDao extends AbstractBaseMapper<FictionChapter> {
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.dao;
|
||||
|
||||
|
||||
import com.zhangmeng.db.tk.base.AbstractBaseMapper;
|
||||
import com.zhangmeng.fiction.server.entity.FictionCollection;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface FictionCollectionDao extends AbstractBaseMapper<FictionCollection> {
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.dao;
|
||||
|
||||
import com.zhangmeng.db.tk.base.AbstractBaseMapper;
|
||||
import com.zhangmeng.fiction.server.entity.Fiction;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
@Mapper
|
||||
public interface FictionDao extends AbstractBaseMapper<Fiction> {
|
||||
|
||||
|
||||
@Select("select * from fiction obj where obj.bookName = #{bookName}")
|
||||
Fiction finbByBookName(String bookName);
|
||||
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.dao;
|
||||
|
||||
|
||||
import com.zhangmeng.db.tk.base.AbstractBaseMapper;
|
||||
import com.zhangmeng.fiction.server.entity.FictionDetails;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface FictionDetailsDao extends AbstractBaseMapper<FictionDetails> {
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.dao;
|
||||
|
||||
|
||||
|
||||
import com.zhangmeng.db.tk.base.AbstractBaseMapper;
|
||||
import com.zhangmeng.fiction.server.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);
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.dao;
|
||||
|
||||
import com.zhangmeng.db.tk.base.AbstractBaseMapper;
|
||||
import com.zhangmeng.fiction.server.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> {
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.dao;
|
||||
|
||||
|
||||
import com.zhangmeng.db.tk.base.AbstractBaseMapper;
|
||||
import com.zhangmeng.fiction.server.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> {
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.dao;
|
||||
|
||||
|
||||
import com.zhangmeng.db.tk.base.AbstractBaseMapper;
|
||||
import com.zhangmeng.fiction.server.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> {
|
||||
}
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.zhangmeng.fiction.server.entity.Permission;
|
||||
import com.zhangmeng.fiction.server.entity.User;
|
||||
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 org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author zhangmeng
|
||||
* @version 1.0
|
||||
* @date 2020年11月13日15:37:45
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class LoginUser extends User implements UserDetails {
|
||||
|
||||
private List<Permission> permissions;
|
||||
|
||||
private String token;
|
||||
|
||||
/**
|
||||
* 登陆时间戳(毫秒)
|
||||
*/
|
||||
private Long loginTime;
|
||||
/**
|
||||
* 过期时间戳
|
||||
*/
|
||||
private Long expireTime;
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
return permissions.parallelStream().filter(permission -> !StringUtils.isEmpty(permission.getTitle()))
|
||||
.map(permission -> new SimpleGrantedAuthority(permission.getTitle())).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
/**
|
||||
* 账户是否未过期
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public boolean isAccountNonExpired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 账户是否未锁定
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public boolean isAccountNonLocked() {
|
||||
return getStatus() != Status.LOCKED;
|
||||
}
|
||||
|
||||
/**
|
||||
* 密码是否未过期
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public boolean isCredentialsNonExpired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 账户是否激活
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.dto;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统常量
|
||||
*
|
||||
* @author zhangmeng
|
||||
* @date 2021年7月8日09:15:26
|
||||
* @version 1.0
|
||||
*/
|
||||
public class SystemConstant {
|
||||
|
||||
/**
|
||||
* Windows 系统常量标识
|
||||
* */
|
||||
public static String WINDOWS = "windows";
|
||||
|
||||
/**
|
||||
* Linux 系统常量标识
|
||||
* */
|
||||
private static String Linux = "linux";
|
||||
|
||||
/**
|
||||
* UTF-8 编码格式
|
||||
* */
|
||||
public static String UTF8 ="UTF-8";
|
||||
|
||||
/**
|
||||
* GBK 编码格式
|
||||
* */
|
||||
public static String GBK = "GBK";
|
||||
|
||||
/**
|
||||
* 空串
|
||||
* */
|
||||
public static String EMPTY = "";
|
||||
|
||||
/**
|
||||
* 验证码集合
|
||||
*/
|
||||
public static List<String> VerificationCodeList = new ArrayList<>();
|
||||
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class Token implements Serializable {
|
||||
|
||||
/**
|
||||
* token
|
||||
*/
|
||||
private String token;
|
||||
|
||||
/**
|
||||
* 登录时间
|
||||
*/
|
||||
private Long loginTime;
|
||||
|
||||
public Token(String token, Long loginTime) {
|
||||
this.token = token;
|
||||
this.loginTime = loginTime;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,100 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.entity;
|
||||
|
||||
import com.zhangmeng.fiction.server.entity.baseEntity.BaseEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author zhengmeng
|
||||
* @version 1.0
|
||||
* @date 2021年1月7日11:38:42
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Table(name = "permission")
|
||||
public class Permission extends BaseEntity<Long> {
|
||||
|
||||
public enum Status{
|
||||
show("显示"),
|
||||
hidden("隐藏");
|
||||
private String description;//描述
|
||||
|
||||
Status(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public enum Type{
|
||||
CATALOG("目录"),
|
||||
MENU("菜单"),
|
||||
BUTTON("按钮");
|
||||
private String description;//描述
|
||||
|
||||
Type(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public static List<Map<String,Object>> valueListMap(){
|
||||
Type[] values = Type.values();
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (Type value : values) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
String description = value.getDescription();
|
||||
map.put("description",description);
|
||||
map.put("value",value);
|
||||
list.add(map);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
private Status status;
|
||||
|
||||
private String title;
|
||||
|
||||
private Type type;
|
||||
|
||||
private String href;
|
||||
|
||||
private String openType;
|
||||
|
||||
private Long parent_id;
|
||||
|
||||
private String icon;
|
||||
|
||||
private String code;
|
||||
|
||||
private String checkArr = "0";
|
||||
|
||||
private Integer sort;
|
||||
}
|
||||
|
|
@ -1,108 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.entity;
|
||||
|
||||
import com.zhangmeng.fiction.server.entity.baseEntity.BaseEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zhengmeng
|
||||
* @version 1.0
|
||||
* @date 2021年1月7日17:44:40
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Table(name = "role")
|
||||
public class Role extends BaseEntity<Long> {
|
||||
|
||||
public enum Type {
|
||||
|
||||
Super_Administrator("超级管理员") ,//超级管理员
|
||||
Administrator("管理员"),//管理员
|
||||
User("用户");//用户
|
||||
|
||||
private String description;//描述
|
||||
|
||||
Type(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public static List<Map<String,Object>> enumListMap(){
|
||||
Type[] values = Type.values();
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (Type value : values) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
String description = value.getDescription();
|
||||
map.put("description",description);
|
||||
map.put("value",value);
|
||||
list.add(map);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
public enum Status {
|
||||
|
||||
Enable("开启") ,
|
||||
DisEnable("关闭");
|
||||
|
||||
private String description;//描述
|
||||
|
||||
Status(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public static List<Map<String,Object>> enumListMap(){
|
||||
Status[] values = Status.values();
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (Status value : values) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
String description = value.getDescription();
|
||||
map.put("description",description);
|
||||
map.put("value",value);
|
||||
list.add(map);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
private String roleName;
|
||||
|
||||
private String roleCode;
|
||||
|
||||
private Status status;
|
||||
|
||||
private String description;
|
||||
|
||||
private Type type;
|
||||
|
||||
private Long createUserId;
|
||||
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.entity;
|
||||
|
||||
import com.zhangmeng.fiction.server.entity.baseEntity.BaseEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* @author zhengmeng
|
||||
* @version 1.0
|
||||
* @date 2021年1月7日11:38:42
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Table(name = "role_permission")
|
||||
public class RolePermission extends BaseEntity<Long> {
|
||||
private Long role_id;
|
||||
private Long permission_id;
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.entity;
|
||||
|
||||
import com.zhangmeng.fiction.server.entity.baseEntity.BaseEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* @author zhengmeng
|
||||
* @date 2021年1月7日17:44:40
|
||||
* @version 1.0
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Table(name = "sys_config")
|
||||
public class SysConfig extends BaseEntity<Long> {
|
||||
|
||||
public enum MailType{
|
||||
|
||||
mail_163("smtp.163.com"),
|
||||
mail_qq("smtp.qq.com");
|
||||
|
||||
private String description;//描述
|
||||
|
||||
MailType(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
|
||||
private String siteName;//站点名称
|
||||
|
||||
private String domain;//域名设置
|
||||
|
||||
private String siteIntroduction; //站点简介
|
||||
|
||||
private MailType mailType;//邮箱类型
|
||||
|
||||
private String blogTitle;//博客标题
|
||||
|
||||
private String author;
|
||||
}
|
||||
|
|
@ -1,142 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.entity;
|
||||
|
||||
import com.zhangmeng.fiction.server.entity.baseEntity.BaseEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* @author zhengmeng
|
||||
* @version 1.0
|
||||
* @date 2021年1月7日11:38:42
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Table(name = "sys_log")
|
||||
public class SysLog extends BaseEntity<Long> {
|
||||
|
||||
/**
|
||||
* 业务类型
|
||||
* @author zhangmeng
|
||||
* @date 2021年7月8日11:36:07
|
||||
* @version 1.0
|
||||
*/
|
||||
public enum BusinessType {
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
ADD("新增"),
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
EDIT("修改"),
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
REMOVE("删除"),
|
||||
|
||||
/**
|
||||
* 查询
|
||||
*/
|
||||
QUERY("查询"),
|
||||
|
||||
/**
|
||||
* 导出
|
||||
*/
|
||||
EXPORT("导出"),
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
LOGIN("登录"),
|
||||
|
||||
/**
|
||||
* 其他
|
||||
*/
|
||||
OTHER("其他");
|
||||
|
||||
private String desc;
|
||||
|
||||
BusinessType(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public void setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
}
|
||||
|
||||
public enum LoggingType{
|
||||
LOGIN("登录"),
|
||||
LOGIN_OUT("退出");
|
||||
|
||||
LoggingType(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
private String description;//描述
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
private String serial_number;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 业务类型
|
||||
*/
|
||||
private BusinessType businessType;
|
||||
|
||||
/**
|
||||
* 日 志 类 型
|
||||
*/
|
||||
private LoggingType loggingType;
|
||||
|
||||
/**
|
||||
* 异 常 信 息
|
||||
*/
|
||||
private String errorMsg;
|
||||
|
||||
/**
|
||||
* 操 作 人 员
|
||||
*/
|
||||
private Long user_id;
|
||||
|
||||
/**
|
||||
* 扩 展 信 息
|
||||
*/
|
||||
|
||||
private String expandInfoJSON;
|
||||
}
|
||||
|
|
@ -1,128 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.entity;
|
||||
|
||||
|
||||
import com.zhangmeng.fiction.server.entity.baseEntity.BaseEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author zhengmeng
|
||||
* @version 1.0
|
||||
* @date 2021年1月7日11:38:42
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Table(name = "user")
|
||||
public class User extends BaseEntity<Long> {
|
||||
|
||||
public enum Status {
|
||||
DISABLED("已停用"),
|
||||
VALID("正常"),
|
||||
LOCKED("锁定");
|
||||
|
||||
Status(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
private String description;//描述
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public static List<Map<String,Object>> enumListMap(){
|
||||
Status[] values = Status.values();
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (Status value : values) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
String description = value.getDescription();
|
||||
map.put("description",description);
|
||||
map.put("value",value);
|
||||
list.add(map);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public enum Gender {
|
||||
male("男"),
|
||||
female("女");
|
||||
|
||||
Gender(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
private String description;//描述
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public static List<Map<String,Object>> enumListMap(){
|
||||
Gender[] values = Gender.values();
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (Gender value : values) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
String description = value.getDescription();
|
||||
map.put("description",description);
|
||||
map.put("value",value);
|
||||
list.add(map);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
private String username;
|
||||
|
||||
private String password;
|
||||
|
||||
private Status status;
|
||||
|
||||
@Column(columnDefinition = "longtext")
|
||||
private String sign;
|
||||
|
||||
private String avatar;
|
||||
|
||||
private String email;
|
||||
|
||||
private String name;//姓名
|
||||
|
||||
private String nickname;//昵称
|
||||
|
||||
private String profession;//职业
|
||||
|
||||
private String qq;
|
||||
|
||||
private String telephone;
|
||||
|
||||
private Date birthday;
|
||||
|
||||
private Gender gender;//性别
|
||||
|
||||
private String remarks;//备注
|
||||
|
||||
private Role.Type roleType;//角色类型
|
||||
|
||||
private Long photo_id;
|
||||
|
||||
private String now_pos;//现居住城市
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.entity;
|
||||
|
||||
import com.zhangmeng.fiction.server.entity.baseEntity.BaseEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* @author zhengmeng
|
||||
* @version 1.0
|
||||
* @date 2021年1月7日11:38:42
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Table(name = "user_role")
|
||||
public class UserRole extends BaseEntity<Long> {
|
||||
|
||||
private Long user_id;
|
||||
private Long role_id;
|
||||
}
|
||||
|
|
@ -1,93 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.entity;
|
||||
|
||||
import com.zhangmeng.fiction.server.entity.baseEntity.BaseEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* 验证码
|
||||
*
|
||||
* @author zhangmeng
|
||||
* @version 1.0
|
||||
* @date 2021/4/1 21:29
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Table(name = "verification_code")
|
||||
public class VerificationCode extends BaseEntity<Long> {
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
public enum Type{
|
||||
/**
|
||||
* 手机
|
||||
*/
|
||||
mobile("手机"),
|
||||
|
||||
/**
|
||||
* 网页
|
||||
*/
|
||||
pc("web");
|
||||
|
||||
Type(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
//描述
|
||||
private String description;
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
public enum Status{
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
login("登录"),
|
||||
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
register("注册");
|
||||
|
||||
Status(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
private String description;
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
|
||||
private Type type;
|
||||
|
||||
private Status status;
|
||||
|
||||
private String code;
|
||||
|
||||
private String telephone;
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.service;
|
||||
|
||||
|
||||
import com.zhangmeng.fiction.server.common.sys.Menu;
|
||||
import com.zhangmeng.fiction.server.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);
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.service;
|
||||
|
||||
|
||||
|
||||
import com.zhangmeng.fiction.server.entity.RolePermission;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface RolePermissionService extends BaseService<RolePermission> {
|
||||
|
||||
List<RolePermission> findByRoleId(Long roleId);
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.service;
|
||||
|
||||
import com.zhangmeng.fiction.server.entity.Permission;
|
||||
import com.zhangmeng.fiction.server.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);
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.service;
|
||||
|
||||
|
||||
import com.zhangmeng.fiction.server.dto.LoginUser;
|
||||
import com.zhangmeng.fiction.server.dto.Token;
|
||||
|
||||
public interface TokenService {
|
||||
|
||||
/**
|
||||
* 根据token 获取用户
|
||||
*
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
LoginUser getLoginUser(String token);
|
||||
|
||||
/**
|
||||
* 检查登录是否过期
|
||||
*
|
||||
* @param loginUser 登录用户
|
||||
* @return
|
||||
*/
|
||||
LoginUser checkLoginTime(LoginUser loginUser);
|
||||
|
||||
/**
|
||||
* 保存token
|
||||
*
|
||||
* @param loginUser
|
||||
* @return
|
||||
*/
|
||||
Token saveToken(LoginUser loginUser);
|
||||
|
||||
/**
|
||||
* 刷新缓存
|
||||
*
|
||||
* @param loginUser
|
||||
*/
|
||||
public void refresh(LoginUser loginUser);
|
||||
|
||||
/**
|
||||
* 生成token
|
||||
*
|
||||
* @param token token
|
||||
*/
|
||||
void deleteToken(String token);
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.service;
|
||||
|
||||
|
||||
|
||||
import com.zhangmeng.fiction.server.entity.User;
|
||||
import com.zhangmeng.fiction.server.res.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);
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.service;
|
||||
|
||||
import com.wf.captcha.SpecCaptcha;
|
||||
import com.zhangmeng.fiction.server.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);
|
||||
|
||||
public void ram_save(SpecCaptcha specCaptcha);
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.service.impl;
|
||||
|
||||
|
||||
import com.zhangmeng.fiction.server.entity.FictionChapter;
|
||||
|
||||
import com.zhangmeng.fiction.server.service.FictionChapterService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import tk.mybatis.mapper.entity.Condition;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class FictionChapterServiceImpl extends AbstractBaseServiceImpl<FictionChapter> implements FictionChapterService {
|
||||
@Override
|
||||
public FictionChapter findByChapterName(String title,Long fiction_id) {
|
||||
|
||||
Condition condition = new Condition(FictionChapter.class);
|
||||
Example.Criteria criteria = condition.createCriteria();
|
||||
criteria.andEqualTo("title",title);
|
||||
criteria.andEqualTo("fiction_id",fiction_id);
|
||||
List<FictionChapter> fictionChapters = this.findByCondition(condition);
|
||||
if (fictionChapters.size() > 0){
|
||||
return fictionChapters.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FictionChapter> getByFictionId() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,119 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.service.impl;
|
||||
|
||||
|
||||
import com.zhangmeng.fiction.server.common.sys.Menu;
|
||||
import com.zhangmeng.fiction.server.dao.RolePermissionDao;
|
||||
import com.zhangmeng.fiction.server.dao.UserRoleDao;
|
||||
import com.zhangmeng.fiction.server.entity.Permission;
|
||||
import com.zhangmeng.fiction.server.entity.RolePermission;
|
||||
import com.zhangmeng.fiction.server.entity.UserRole;
|
||||
import com.zhangmeng.fiction.server.service.PermissionService;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import tk.mybatis.mapper.entity.Condition;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
|
||||
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 UserRoleDao userRoleDao;
|
||||
|
||||
@Autowired
|
||||
private RolePermissionDao rolePermissionDao;
|
||||
|
||||
private List<RolePermission> rolePermissions(Condition condition){
|
||||
return this.rolePermissionDao.selectByCondition(condition);
|
||||
}
|
||||
|
||||
private List<UserRole> userRoleList(Condition condition){
|
||||
return this.userRoleDao.selectByCondition(condition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Permission> findByUserId(Long userId) {
|
||||
Condition condition = new Condition(UserRole.class);
|
||||
Example.Criteria criteria = condition.createCriteria();
|
||||
criteria.andEqualTo("user_id", userId);
|
||||
//List<UserRole> userRoleList = this.securityUserRoleService.findByCondition(condition);
|
||||
List<UserRole> userRoleList = this.userRoleList(condition);
|
||||
List<Permission> permissionList = new ArrayList<>();
|
||||
if (userRoleList.size() > 0) {
|
||||
for (UserRole userRole : userRoleList) {
|
||||
Condition r_p = new Condition(RolePermission.class);
|
||||
r_p.createCriteria().andEqualTo("role_id", userRole.getRole_id());
|
||||
//List<RolePermission> rolePermissions = this.securityRolePermissionService.findByCondition(r_p);
|
||||
List<RolePermission> rolePermissions = this.rolePermissions(r_p);
|
||||
if (rolePermissions.size() > 0) {
|
||||
for (RolePermission rolePermission : rolePermissions) {
|
||||
Permission permission = this.findById(rolePermission.getPermission_id());
|
||||
permissionList.add(permission);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return permissionList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归获取菜单tree
|
||||
*
|
||||
* @param permissions 权限列表
|
||||
* @return list
|
||||
*/
|
||||
@Override
|
||||
public List<Menu> toUserMenus(List<Permission> permissions, Long parentId) {
|
||||
List<Menu> menuList = menuList(permissions);
|
||||
return toUserMenu(menuList, parentId);
|
||||
}
|
||||
|
||||
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) {
|
||||
if (permission.getStatus().equals(Permission.Status.show)) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.service.impl;
|
||||
|
||||
|
||||
import com.zhangmeng.fiction.server.entity.RolePermission;
|
||||
import com.zhangmeng.fiction.server.service.RolePermissionService;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.service.impl;
|
||||
|
||||
|
||||
import com.zhangmeng.fiction.server.common.utils.CommonUtil;
|
||||
import com.zhangmeng.fiction.server.entity.Permission;
|
||||
import com.zhangmeng.fiction.server.entity.Role;
|
||||
import com.zhangmeng.fiction.server.entity.RolePermission;
|
||||
import com.zhangmeng.fiction.server.service.PermissionService;
|
||||
import com.zhangmeng.fiction.server.service.RolePermissionService;
|
||||
import com.zhangmeng.fiction.server.service.RoleService;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,105 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.service.impl;
|
||||
|
||||
|
||||
import com.zhangmeng.fiction.server.common.utils.TokenUtil;
|
||||
import com.zhangmeng.fiction.server.config.TokenConfig;
|
||||
import com.zhangmeng.fiction.server.dto.LoginUser;
|
||||
import com.zhangmeng.fiction.server.dto.Token;
|
||||
import com.zhangmeng.fiction.server.service.TokenService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Service
|
||||
public class TokenServiceImpl implements TokenService {
|
||||
|
||||
@Autowired
|
||||
private TokenConfig tokenConfig;
|
||||
|
||||
private static final Long MINUTES_10 = 10 * 60 * 1000L;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("userDetailsServiceImpl")
|
||||
private UserDetailsService userDetailsService;
|
||||
|
||||
@Autowired
|
||||
private TokenUtil tokenUtil;
|
||||
|
||||
@Override
|
||||
public LoginUser getLoginUser(String token) {
|
||||
//解析token ,获取uuid
|
||||
String uuid = this.tokenUtil.getUid(token);
|
||||
if (uuid != null) {
|
||||
return (LoginUser) redisTemplate.boundValueOps(TokenUtil.getTokenKey(uuid)).get();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public LoginUser checkLoginTime(LoginUser loginUser) {
|
||||
long expireTime = loginUser.getExpireTime();
|
||||
long currentTime = System.currentTimeMillis();
|
||||
if (expireTime - currentTime <= MINUTES_10) {
|
||||
loginUser = (LoginUser) userDetailsService.loadUserByUsername(loginUser.getUsername());
|
||||
refresh(loginUser);
|
||||
}
|
||||
return loginUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新缓存
|
||||
*
|
||||
* @param loginUser
|
||||
*/
|
||||
@Override
|
||||
public void refresh(LoginUser loginUser) {
|
||||
cacheLoginUser(loginUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录成功 ,保存token
|
||||
*
|
||||
* @param loginUser
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Token saveToken(LoginUser loginUser) {
|
||||
loginUser.setToken(UUID.randomUUID().toString());
|
||||
cacheLoginUser(loginUser);
|
||||
//生成token
|
||||
String token = this.tokenUtil.createToken(loginUser);
|
||||
return new Token(token, loginUser.getLoginTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* experTime 过期秒数
|
||||
*
|
||||
* @param loginUser
|
||||
*/
|
||||
private void cacheLoginUser(LoginUser loginUser) {
|
||||
loginUser.setLoginTime(System.currentTimeMillis());
|
||||
loginUser.setExpireTime(loginUser.getLoginTime() + tokenConfig.getExperTime() * 1000);
|
||||
// 根据uuid将loginUser缓存
|
||||
redisTemplate.boundValueOps(TokenUtil.getTokenKey(loginUser.getToken())).set(loginUser, tokenConfig.getExperTime(), TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteToken(String token) {
|
||||
try {
|
||||
String uid = this.tokenUtil.getUid(token);
|
||||
String key = TokenUtil.getTokenKey(uid);
|
||||
redisTemplate.delete(key);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.service.impl;
|
||||
|
||||
import com.zhangmeng.fiction.server.dto.LoginUser;
|
||||
import com.zhangmeng.fiction.server.entity.Permission;
|
||||
import com.zhangmeng.fiction.server.entity.User;
|
||||
import com.zhangmeng.fiction.server.exception.CustomizeException;
|
||||
import com.zhangmeng.fiction.server.service.PermissionService;
|
||||
import com.zhangmeng.fiction.server.service.UserService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.authentication.DisabledException;
|
||||
import org.springframework.security.authentication.LockedException;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class UserDetailsServiceImpl implements UserDetailsService {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private PermissionService permissionService;
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
User user = this.userService.loadUserByUsername(username);
|
||||
if (user == null){
|
||||
throw new UsernameNotFoundException("用户未找到");
|
||||
}
|
||||
|
||||
//判断用户状态是否正常
|
||||
if (!user.getDeleteStatus()){
|
||||
if (user.getStatus().equals(User.Status.LOCKED)) {
|
||||
throw new LockedException("用户被锁定,请联系管理员");
|
||||
}
|
||||
if (user.getStatus().equals(User.Status.DISABLED)) {
|
||||
throw new DisabledException("用户已作废");
|
||||
}
|
||||
}else {
|
||||
throw new CustomizeException("该用户已被删除");
|
||||
}
|
||||
//根据用户查询权限列表
|
||||
List<Permission> permissions = this.permissionService.findByUserId(user.getId());
|
||||
LoginUser loginUser = new LoginUser();
|
||||
BeanUtils.copyProperties(user,loginUser);
|
||||
loginUser.setPermissions(permissions);
|
||||
return loginUser;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,168 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.service.impl;
|
||||
|
||||
|
||||
import com.zhangmeng.db.tk.mybatis.QuerySingleParams;
|
||||
import com.zhangmeng.fiction.server.common.utils.CommonUtil;
|
||||
import com.zhangmeng.fiction.server.dao.UserRoleDao;
|
||||
import com.zhangmeng.fiction.server.entity.Role;
|
||||
import com.zhangmeng.fiction.server.entity.User;
|
||||
import com.zhangmeng.fiction.server.entity.UserRole;
|
||||
import com.zhangmeng.fiction.server.res.Result;
|
||||
import com.zhangmeng.fiction.server.res.StatusCode;
|
||||
import com.zhangmeng.fiction.server.service.RoleService;
|
||||
import com.zhangmeng.fiction.server.service.UserService;
|
||||
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 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;
|
||||
|
||||
@Autowired
|
||||
private BCryptPasswordEncoder bCryptPasswordEncoder;
|
||||
|
||||
@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)) {
|
||||
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 Result.success(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);
|
||||
user.setPassword(bCryptPasswordEncoder.encode(password));
|
||||
return Result.success("注册成功");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,134 +0,0 @@
|
|||
package com.zhangmeng.fiction.server.service.impl;
|
||||
|
||||
|
||||
import com.wf.captcha.SpecCaptcha;
|
||||
import com.zhangmeng.fiction.server.common.utils.CommonUtil;
|
||||
import com.zhangmeng.fiction.server.config.RedisTemplateUtil;
|
||||
import com.zhangmeng.fiction.server.config.VerificationCodeConfig;
|
||||
import com.zhangmeng.fiction.server.dto.SystemConstant;
|
||||
import com.zhangmeng.fiction.server.entity.VerificationCode;
|
||||
import com.zhangmeng.fiction.server.service.VerificationCodeService;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ram_save(SpecCaptcha specCaptcha) {
|
||||
cacheVerificationCode2Ram(specCaptcha.text());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 缓存
|
||||
*
|
||||
* @param generatorVerificationCode 验证码
|
||||
*/
|
||||
public void cacheVerificationCode(String generatorVerificationCode) {
|
||||
//转小写
|
||||
generatorVerificationCode = generatorVerificationCode.toLowerCase();
|
||||
VerificationCodeConfig.Type type = this.verificationCodeConfig.getType();
|
||||
if (type.equals(VerificationCodeConfig.Type.RAM)) {
|
||||
cacheVerificationCode2Ram(generatorVerificationCode);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 内存 静态变量 常量
|
||||
*/
|
||||
private void cacheVerificationCode2Ram(String generatorVerificationCode) {
|
||||
boolean contains = SystemConstant.VerificationCodeList.contains(generatorVerificationCode);
|
||||
if (!contains) {
|
||||
SystemConstant.VerificationCodeList.add(generatorVerificationCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue