pars = new ArrayList<>();
35 | tokenPar.name("Authorization").description("权限验证令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
36 | pars.add(tokenPar.build());
37 | return new Docket(DocumentationType.SWAGGER_2)
38 | .produces(Sets.newHashSet("application/json","application/x-www-form-urlencoded","*/*"))
39 | .consumes(Sets.newHashSet("application/json","application/x-www-form-urlencoded","*/*"))
40 | .protocols(Sets.newHashSet("http"))
41 | .forCodeGeneration(true)
42 | .select()
43 | .paths(PathSelectors.any())
44 | .apis(RequestHandlerSelectors.basePackage("com.example.demo"))
45 | .build()
46 | .globalOperationParameters(pars)
47 | .apiInfo(apiInfo());
48 | }
49 | private ApiInfo apiInfo(){
50 | return new ApiInfoBuilder()
51 | .title("接口调用文档")
52 | .description("前后端调试对接文档")
53 | .contact(new Contact("liuxinghong","","349695133@qq.com"))
54 | .version("2.0")
55 | .build();
56 | }
57 | private SwaggerResource swaggerResource(String name, String location) {
58 | SwaggerResource swaggerResource = new SwaggerResource();
59 | swaggerResource.setName(name);
60 | swaggerResource.setLocation(location);
61 | swaggerResource.setSwaggerVersion("2.0");
62 | return swaggerResource;
63 | }
64 |
65 | }
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/controller/SysLogController.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.controller;
2 |
3 |
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 |
6 | import org.springframework.stereotype.Controller;
7 |
8 | /**
9 | *
10 | * 日志信息表 前端控制器
11 | *
12 | *
13 | * @author LXH
14 | * @since 2019-05-06
15 | */
16 | @Controller
17 | @RequestMapping("/sysLog")
18 | public class SysLogController {
19 |
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/controller/SysResController.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.controller;
2 |
3 |
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 |
6 | import org.springframework.stereotype.Controller;
7 |
8 | /**
9 | *
10 | * 资源表 前端控制器
11 | *
12 | *
13 | * @author LXH
14 | * @since 2019-05-06
15 | */
16 | @Controller
17 | @RequestMapping("/entity/sysRes")
18 | public class SysResController {
19 |
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/controller/SysRoleController.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.controller;
2 |
3 |
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 |
6 | import org.springframework.stereotype.Controller;
7 |
8 | /**
9 | *
10 | * 角色表 前端控制器
11 | *
12 | *
13 | * @author LXH
14 | * @since 2019-05-06
15 | */
16 | @Controller
17 | @RequestMapping("/entity/sysRole")
18 | public class SysRoleController {
19 |
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/controller/SysRoleResController.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.controller;
2 |
3 |
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 |
6 | import org.springframework.stereotype.Controller;
7 |
8 | /**
9 | *
10 | * 角色资源表 前端控制器
11 | *
12 | *
13 | * @author LXH
14 | * @since 2019-05-06
15 | */
16 | @Controller
17 | @RequestMapping("/entity/sysRoleRes")
18 | public class SysRoleResController {
19 |
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/controller/SysUserController.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.controller;
2 |
3 |
4 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
5 | import com.baomidou.mybatisplus.core.toolkit.IdWorker;
6 | import com.example.demo.VO.USerAddVO;
7 | import com.example.demo.base_controller.BaseController;
8 | import com.example.demo.entity.SysUser;
9 | import com.example.demo.service.SysUserService;
10 | import io.swagger.annotations.Api;
11 | import io.swagger.annotations.ApiImplicitParam;
12 | import io.swagger.annotations.ApiImplicitParams;
13 | import io.swagger.annotations.ApiOperation;
14 | import org.mindrot.jbcrypt.BCrypt;
15 | import org.springframework.beans.BeanUtils;
16 | import org.springframework.beans.factory.annotation.Autowired;
17 | import org.springframework.validation.annotation.Validated;
18 | import org.springframework.web.bind.annotation.*;
19 |
20 | import org.springframework.stereotype.Controller;
21 |
22 | /**
23 | *
24 | * 用户表 前端控制器
25 | *
26 | *
27 | * @author LXH
28 | * @since 2019-05-06
29 | */
30 | @Controller
31 | @RequestMapping("/sysUser")
32 | @Api("用户管理")
33 | public class SysUserController extends BaseController {
34 | @Autowired
35 | private SysUserService userService;
36 |
37 | @PostMapping("/add")
38 | @ApiOperation(value="添加用户", notes="添加用户")
39 | public Object add(@RequestBody @Validated USerAddVO vo){
40 | SysUser user = new SysUser();
41 | user.setId(IdWorker.getIdStr());
42 | user.setPwd(BCrypt.hashpw(vo.getPwd(), BCrypt.gensalt()));
43 | BeanUtils.copyProperties(vo,user);
44 | QueryWrapper wrapper = new QueryWrapper<>();
45 | wrapper.setEntity(new SysUser());
46 | return success(userService.save(user));
47 | }
48 |
49 | @GetMapping("/list")
50 | @ApiOperation(value="用户列表", notes="")
51 | @ApiImplicitParams({
52 | @ApiImplicitParam(name = "pageNO", value = "页数", dataType = "Integer"),
53 | @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "Integer")
54 | })
55 | public Object list(@RequestParam("pageNO") Integer pageNO, @RequestParam("pageSize") Integer pageSize){
56 | return success(userService.pageList(pageNO,pageSize));
57 | }
58 |
59 | }
60 |
61 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/controller/SysUserRoleController.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.controller;
2 |
3 |
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 |
6 | import org.springframework.stereotype.Controller;
7 |
8 | /**
9 | *
10 | * 用户角色表 前端控制器
11 | *
12 | *
13 | * @author LXH
14 | * @since 2019-05-06
15 | */
16 | @Controller
17 | @RequestMapping("/entity/sysUserRole")
18 | public class SysUserRoleController {
19 |
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/entity/SysLog.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.entity;
2 |
3 | import java.util.Date;
4 |
5 | import com.baomidou.mybatisplus.annotation.TableField;
6 | import com.baomidou.mybatisplus.annotation.TableName;
7 | import lombok.Data;
8 | import scala.util.parsing.combinator.testing.Str;
9 |
10 | import java.io.Serializable;
11 |
12 | /**
13 | *
14 | * 日志信息表
15 | *
16 | *
17 | * @author LXH
18 | * @since 2019-05-06
19 | */
20 | @TableName("sys_log")
21 | @Data
22 | public class SysLog implements Serializable {
23 |
24 | private static final long serialVersionUID = 1L;
25 |
26 | /**
27 | * 日志信息表主键
28 | */
29 | private String id;
30 | /**
31 | * 日志类型(1:增,2:删,3:改,4:查)
32 | */
33 | private Integer type;
34 | /**
35 | * 日志说明(日志数据)
36 | */
37 | private String desc;
38 | /**
39 | * 操作详情
40 | */
41 | private String remark;
42 | /**
43 | * 操作人IP地址
44 | */
45 | private String adr;
46 | /**
47 | * 删除标识(1:未删除,2:已删除)
48 | */
49 | private Integer status;
50 | /**
51 | * 创建时间
52 | */
53 | @TableField("create_time")
54 | private Date createTime;
55 | /**
56 | * 创建用户
57 | */
58 | @TableField("create_user")
59 | private String createUser;
60 |
61 |
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/entity/SysRes.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.entity;
2 |
3 | import com.baomidou.mybatisplus.annotation.TableField;
4 | import com.baomidou.mybatisplus.annotation.TableName;
5 | import lombok.Data;
6 |
7 | import java.util.Date;
8 | import java.io.Serializable;
9 | import java.util.List;
10 |
11 | /**
12 | *
13 | * 资源表
14 | *
15 | *
16 | * @author LXH
17 | * @since 2019-05-06
18 | */
19 | @TableName("sys_res")
20 | @Data
21 | public class SysRes implements Serializable {
22 |
23 | private static final long serialVersionUID = 1L;
24 |
25 | private String id;
26 | private String pid;
27 | /**
28 | * 在vue中name表示路由名称,非vue是资源名称
29 | */
30 | private String name;
31 | private String permission;
32 | /**
33 | * vue中表示路由的path
34 | */
35 | private String url;
36 | /**
37 | * 排序
38 | */
39 | @TableField("sort_num")
40 | private Integer sortNum;
41 | /**
42 | * PC菜单图片
43 | */
44 | private String icon1;
45 | /**
46 | * APP菜单图片
47 | */
48 | private String icon2;
49 | /**
50 | * TreeTable排序
51 | */
52 | private String pids;
53 | /**
54 | * 1 菜单 2 按钮
55 | */
56 | private Integer type;
57 | private String des;
58 | /**
59 | * 1 可用 0 不可用 -1: 删除
60 | */
61 | private Integer status;
62 | /**
63 | * 创建时间
64 | */
65 | @TableField("create_time")
66 | private Date createTime;
67 | /**
68 | * 修改时间
69 | */
70 | @TableField("update_time")
71 | private Date updateTime;
72 |
73 | @TableField(exist = false)
74 | private List ChildRes;
75 |
76 |
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/entity/SysRole.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.entity;
2 |
3 | import com.baomidou.mybatisplus.annotation.TableField;
4 | import com.baomidou.mybatisplus.annotation.TableName;
5 | import lombok.Data;
6 |
7 | import java.util.Date;
8 | import java.io.Serializable;
9 |
10 | /**
11 | *
12 | * 角色表
13 | *
14 | *
15 | * @author LXH
16 | * @since 2019-05-06
17 | */
18 | @TableName("sys_role")
19 | @Data
20 | public class SysRole implements Serializable {
21 |
22 | private static final long serialVersionUID = 1L;
23 |
24 | private String id;
25 | private String name;
26 | private String code;
27 | @TableField("sort_num")
28 | private Integer sortNum;
29 | private String des;
30 | /**
31 | * 角色类型 0,超管 1.普通用户
32 | */
33 | private Integer type;
34 | /**
35 | * 1 可用 0 不可用 -1: 删除
36 | */
37 | private Integer status;
38 | /**
39 | * 创建时间
40 | */
41 | @TableField("create_time")
42 | private Date createTime;
43 | /**
44 | * 修改时间
45 | */
46 | @TableField("update_time")
47 | private Date updateTime;
48 |
49 |
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/entity/SysRoleRes.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.entity;
2 |
3 | import com.baomidou.mybatisplus.annotation.TableField;
4 | import com.baomidou.mybatisplus.annotation.TableName;
5 | import lombok.Builder;
6 | import lombok.Data;
7 |
8 | import java.io.Serializable;
9 |
10 | /**
11 | *
12 | * 角色资源表
13 | *
14 | *
15 | * @author LXH
16 | * @since 2019-05-06
17 | */
18 | @TableName("sys_role_res")
19 | @Data
20 | @Builder
21 | public class SysRoleRes implements Serializable {
22 |
23 | private static final long serialVersionUID = 1L;
24 |
25 | private String id;
26 | @TableField("res_id")
27 | private String resId;
28 | @TableField("role_id")
29 | private String roleId;
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/entity/SysUser.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.entity;
2 |
3 | import java.util.Date;
4 |
5 | import com.baomidou.mybatisplus.annotation.TableField;
6 | import com.baomidou.mybatisplus.annotation.TableName;
7 | import lombok.*;
8 |
9 | import java.io.Serializable;
10 |
11 | /**
12 | *
13 | * 用户表
14 | *
15 | *
16 | * @author LXH
17 | * @since 2019-05-06
18 | */
19 | @TableName("sys_user")
20 | @Data
21 | @Builder
22 | @ToString
23 | @AllArgsConstructor
24 | @NoArgsConstructor
25 | public class SysUser implements Serializable {
26 |
27 | private static final long serialVersionUID = 1L;
28 |
29 | private String id;
30 | @TableField("login_name")
31 | private String loginName;
32 | @TableField("user_no")
33 | private String userNo;
34 | private String pwd;
35 | private String salt;
36 | private String name;
37 | private String email;
38 | /**
39 | * 1:男,0:女
40 | */
41 | private Integer sex;
42 | /**
43 | * 手机号
44 | */
45 | @TableField("mobile_no")
46 | private String mobileNo;
47 | /**
48 | * 微信号
49 | */
50 | @TableField("weixin_id")
51 | private String weixinId;
52 | /**
53 | * 注册时间
54 | */
55 | @TableField("reg_time")
56 | private Date regTime;
57 | /**
58 | * 头像
59 | */
60 | private String avatar;
61 | /**
62 | * 1 可用 0 不可用 -1: 删除
63 | */
64 | private Integer status;
65 | /**
66 | * 创建时间
67 | */
68 | @TableField("create_time")
69 | private Date createTime;
70 | /**
71 | * 修改时间
72 | */
73 | @TableField("update_time")
74 | private Date updateTime;
75 | /**
76 | * 客户id
77 | */
78 | @TableField("client_id")
79 | private String clientId;
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/entity/SysUserRole.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.entity;
2 |
3 | import com.baomidou.mybatisplus.annotation.TableField;
4 | import com.baomidou.mybatisplus.annotation.TableName;
5 | import lombok.Data;
6 |
7 | import java.io.Serializable;
8 |
9 | /**
10 | *
11 | * 用户角色表
12 | *
13 | *
14 | * @author LXH
15 | * @since 2019-05-06
16 | */
17 | @TableName("sys_user_role")
18 | @Data
19 | public class SysUserRole implements Serializable {
20 |
21 | private static final long serialVersionUID = 1L;
22 |
23 | private String id;
24 | @TableField("user_id")
25 | private String userId;
26 | @TableField("role_id")
27 | private String roleId;
28 |
29 |
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/mapper/SysLogMapper.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.mapper;
2 |
3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4 | import com.example.demo.entity.SysLog;
5 | import org.apache.ibatis.annotations.Mapper;
6 |
7 | /**
8 | *
9 | * 日志信息表 Mapper 接口
10 | *
11 | *
12 | * @author LXH
13 | * @since 2019-05-06
14 | */
15 | @Mapper
16 | public interface SysLogMapper extends BaseMapper {
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/mapper/SysResMapper.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.mapper;
2 |
3 |
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 | import com.example.demo.entity.SysRes;
6 | import org.apache.ibatis.annotations.Mapper;
7 | import org.apache.ibatis.annotations.Param;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | *
13 | * 资源表 Mapper 接口
14 | *
15 | *
16 | * @author LXH
17 | * @since 2019-05-06
18 | */
19 | @Mapper
20 | public interface SysResMapper extends BaseMapper {
21 |
22 | List findMenuByRoleCode(@Param("roleCode") List roleCode);
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/mapper/SysRoleMapper.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.mapper;
2 |
3 |
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 | import com.example.demo.entity.SysRole;
6 | import org.apache.ibatis.annotations.Mapper;
7 |
8 | /**
9 | *
10 | * 角色表 Mapper 接口
11 | *
12 | *
13 | * @author LXH
14 | * @since 2019-05-06
15 | */
16 | @Mapper
17 | public interface SysRoleMapper extends BaseMapper {
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/mapper/SysRoleResMapper.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.mapper;
2 |
3 |
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 | import com.example.demo.entity.SysRoleRes;
6 | import org.apache.ibatis.annotations.Mapper;
7 |
8 | /**
9 | *
10 | * 角色资源表 Mapper 接口
11 | *
12 | *
13 | * @author LXH
14 | * @since 2019-05-06
15 | */
16 | @Mapper
17 | public interface SysRoleResMapper extends BaseMapper {
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/mapper/SysUserMapper.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.mapper;
2 |
3 |
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 | import com.example.demo.entity.SysUser;
7 | import org.apache.ibatis.annotations.Mapper;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | *
13 | * 用户表 Mapper 接口
14 | *
15 | *
16 | * @author LXH
17 | * @since 2019-05-06
18 | */
19 | @Mapper
20 | public interface SysUserMapper extends BaseMapper {
21 | List selectByParam(Page pageInfo);
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/mapper/SysUserRoleMapper.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.mapper;
2 |
3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4 | import com.example.demo.entity.SysUserRole;
5 | import org.apache.ibatis.annotations.Mapper;
6 |
7 | /**
8 | *
9 | * 用户角色表 Mapper 接口
10 | *
11 | *
12 | * @author LXH
13 | * @since 2019-05-06
14 | */
15 | @Mapper
16 | public interface SysUserRoleMapper extends BaseMapper {
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/service/SysLogService.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.service;
2 |
3 | import com.baomidou.mybatisplus.extension.service.IService;
4 | import com.example.demo.entity.SysLog;
5 |
6 | /**
7 | *
8 | * 日志信息表 服务类
9 | *
10 | *
11 | * @author LXH
12 | * @since 2019-05-06
13 | */
14 | public interface SysLogService extends IService {
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/service/SysResService.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.service;
2 |
3 |
4 | import com.baomidou.mybatisplus.extension.service.IService;
5 | import com.example.demo.entity.SysRes;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | *
11 | * 资源表 服务类
12 | *
13 | *
14 | * @author LXH
15 | * @since 2019-05-06
16 | */
17 | public interface SysResService extends IService {
18 |
19 |
20 | /**
21 | * 根据 Ids 查询
22 | * @param permissionIds ids
23 | * @return 权限List
24 | */
25 | List selectByIds(List permissionIds);
26 |
27 | /**
28 | * 根据角色查询菜单
29 | * @param roleIds 角色主键S
30 | * @return
31 | */
32 | List findMenuByRoleCode(List roleIds);
33 |
34 | /**
35 | * 获取菜单树形结构
36 | * @param pId
37 | * @param list
38 | * @return
39 | */
40 | List treeMenuList(String pId, List list);
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/service/SysRoleResService.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.service;
2 |
3 |
4 | import com.baomidou.mybatisplus.extension.service.IService;
5 | import com.example.demo.entity.SysRoleRes;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | *
11 | * 角色资源表 服务类
12 | *
13 | *
14 | * @author LXH
15 | * @since 2019-05-06
16 | */
17 | public interface SysRoleResService extends IService {
18 | /**
19 | * 根据角色ID查询
20 | * @param roleId 角色ID
21 | * @return 结果集
22 | */
23 | List selectByRoleCode(String roleId);
24 |
25 | /**
26 | * 根据角色、权限集合录入数据
27 | * @param roleCode 角色ID
28 | * @param menuCodes 权限集合
29 | * @return 结果 true/false
30 | */
31 | boolean saveAll(String roleCode, List menuCodes);
32 |
33 | boolean deleteAllByRoleCode(String roleCode);
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/service/SysRoleService.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.service;
2 |
3 |
4 | import com.baomidou.mybatisplus.extension.service.IService;
5 | import com.example.demo.base_security.VO.RoleAddVO;
6 | import com.example.demo.base_security.VO.RoleUpdateVO;
7 | import com.example.demo.entity.SysRole;
8 |
9 | import java.util.Map;
10 |
11 | /**
12 | *
13 | * 角色表 服务类
14 | *
15 | *
16 | * @author LXH
17 | * @since 2019-05-06
18 | */
19 | public interface SysRoleService extends IService {
20 |
21 | /**
22 | * 新增角色以及角色权限信息
23 | * @param roleModel 角色以及角色权限信息
24 | * @return 新增结果 true/false
25 | */
26 | boolean addRoleAndPermission(RoleAddVO roleModel)throws Exception;
27 |
28 | /**
29 | * 更新色以及角色权限信息
30 | * @param roleModel
31 | * @return
32 | * @throws Exception
33 | */
34 | boolean updateRoleInfo(RoleUpdateVO roleModel)throws Exception;
35 |
36 | /**
37 | * 通过角色ID获取菜单列表
38 | * @param roleId
39 | * @return
40 | */
41 | Map getMenuByRoleCode(String roleId);
42 |
43 | /**
44 | * 判断当前是否是超级管理员,如果是,不能修改信息 抛出异常
45 | * @param userNo
46 | * @throws Exception
47 | */
48 | void getRoleIsAdminByUserNo(String userNo) throws Exception;
49 |
50 | Map selectByRoleCode(String roleCode)throws Exception;
51 |
52 | void deleteByRoleCode(String roleCode)throws Exception;
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/service/SysUserRoleService.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.service;
2 |
3 | import com.baomidou.mybatisplus.extension.service.IService;
4 | import com.example.demo.entity.SysUserRole;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | *
10 | * 用户角色表 服务类
11 | *
12 | *
13 | * @author LXH
14 | * @since 2019-05-06
15 | */
16 | public interface SysUserRoleService extends IService {
17 |
18 | /**
19 | * 根据用户ID查询人员角色
20 | * @param id 用户ID
21 | * @return 结果
22 | */
23 | List selectByUserNo(String id);
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/service/SysUserService.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.service;
2 |
3 |
4 | import com.alibaba.fastjson.JSONObject;
5 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 | import com.baomidou.mybatisplus.extension.service.IService;
7 | import com.example.demo.base_security.VO.registerVO;
8 | import com.example.demo.entity.SysUser;
9 |
10 | import javax.servlet.http.HttpServletRequest;
11 | import java.util.Map;
12 |
13 | /**
14 | *
15 | * 用户表 服务类
16 | *
17 | *
18 | * @author LXH
19 | * @since 2019-05-06
20 | */
21 | public interface SysUserService extends IService {
22 |
23 |
24 | Page pageList(Integer pageNO, Integer pageSize);
25 | /**
26 | * 根据用户名查询用户
27 | * @param username 用户名
28 | * @return 用户
29 | */
30 | SysUser getUserByUserName(String username);
31 |
32 | SysUser getUserByMobile(String mobile);
33 |
34 | /**
35 | * 注册用户
36 | * @param user
37 | * @return
38 | */
39 | SysUser register(SysUser user);
40 |
41 | Map getLoginUserAndMenuInfo(SysUser user);
42 |
43 | void deleteByUserNo(String userId)throws Exception;
44 |
45 | Page selectPageByConditionUser(Page userPage, String info, Integer[] status, String startTime, String endTime);
46 |
47 | Map checkMobileAndPasswd(JSONObject requestJson)throws Exception;
48 |
49 | Map checkMobileAndCatcha(JSONObject requestJson)throws Exception;
50 |
51 | SysUser checkAndRegisterUser(registerVO vo)throws Exception;
52 |
53 | SysUser updateForgetPasswd(JSONObject requestJson)throws Exception;
54 |
55 | void resetMobile(SysUser currentUser, JSONObject requestJson)throws Exception;
56 |
57 | void resetPassWord(SysUser currentUser, JSONObject requestJson)throws Exception;
58 |
59 | boolean loginOut(String userId);
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/service/impl/SysLogServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.service.impl;
2 |
3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
4 | import com.example.demo.entity.SysLog;
5 | import com.example.demo.mapper.SysLogMapper;
6 | import com.example.demo.service.SysLogService;
7 | import org.springframework.stereotype.Service;
8 |
9 | /**
10 | *
11 | * 日志信息表 服务实现类
12 | *
13 | *
14 | * @author LXH
15 | * @since 2019-05-06
16 | */
17 | @Service
18 | public class SysLogServiceImpl extends ServiceImpl implements SysLogService {
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/service/impl/SysResServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.service.impl;
2 |
3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
5 | import com.example.demo.commons.Constant;
6 | import com.example.demo.entity.SysRes;
7 | import com.example.demo.mapper.SysResMapper;
8 | import com.example.demo.service.SysResService;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.cache.annotation.Cacheable;
11 | import org.springframework.stereotype.Service;
12 | import org.springframework.transaction.annotation.Transactional;
13 |
14 | import javax.management.Query;
15 | import java.util.ArrayList;
16 | import java.util.List;
17 |
18 | /**
19 | *
20 | * 资源表 服务实现类
21 | *
22 | *
23 | * @author LXH
24 | * @since 2019-05-06
25 | */
26 | @Service
27 | @Transactional
28 | public class SysResServiceImpl extends ServiceImpl implements SysResService {
29 |
30 | @Autowired
31 | private SysResMapper menuMapper;
32 |
33 | @Override
34 | //redis方法级别的缓存,需要做缓存打开改注解即可
35 | //@Cacheable(value = "UserToRole",keyGenerator="wiselyKeyGenerator")
36 | public List selectByIds(List permissionIds) {
37 | QueryWrapper ew = new QueryWrapper<>();
38 | ew.in("id", permissionIds);
39 | return this.list(ew);
40 | }
41 |
42 | @Override
43 | // @Cacheable(value = "UserToRole",keyGenerator="wiselyKeyGenerator")
44 | public List findMenuByRoleCode(List roleIds) {
45 | return menuMapper.findMenuByRoleCode(roleIds);
46 | }
47 |
48 | @Override
49 | public List treeMenuList(String pId, List list) {
50 | List IteratorMenuList = new ArrayList<>();
51 | for (SysRes m : list) {
52 | if (String.valueOf(m.getPid()).equals(pId)) {
53 | List childMenuList = treeMenuList(String.valueOf(m.getId()), list);
54 | m.setChildRes(childMenuList);
55 | if(m.getType() == Constant.TYPE_MENU){
56 | IteratorMenuList.add(m);
57 | }
58 | }
59 | }
60 | return IteratorMenuList;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/service/impl/SysRoleResServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.service.impl;
2 |
3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 | import com.baomidou.mybatisplus.core.toolkit.IdWorker;
5 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
6 | import com.example.demo.entity.SysRoleRes;
7 | import com.example.demo.mapper.SysRoleResMapper;
8 | import com.example.demo.base_security.util.ComUtil;
9 | import com.example.demo.service.SysRoleResService;
10 | import org.springframework.stereotype.Service;
11 |
12 | import java.util.ArrayList;
13 | import java.util.List;
14 |
15 | /**
16 | *
17 | * 角色资源表 服务实现类
18 | *
19 | *
20 | * @author LXH
21 | * @since 2019-05-06
22 | */
23 | @Service
24 | public class SysRoleResServiceImpl extends ServiceImpl implements SysRoleResService {
25 |
26 | @Override
27 | //redis生成key注解,以类名方法名和参数组成key
28 | // @Cacheable(value = "UserToRole",keyGenerator="wiselyKeyGenerator")
29 | public List selectByRoleCode(String roleCode) {
30 | QueryWrapper ew = new QueryWrapper<>();
31 | ew.eq("role_id", roleCode);
32 | return this.list(ew);
33 | }
34 |
35 | @Override
36 | public boolean saveAll(String roleCode, List menuCodes) {
37 | boolean result = true;
38 | if (!ComUtil.isEmpty(menuCodes)) {
39 | List modelList = new ArrayList<>();
40 | for (String menuCode : menuCodes) {
41 | modelList.add(SysRoleRes.builder().id(IdWorker.getIdStr()).roleId(roleCode).resId(menuCode).build());
42 | }
43 | result = this.saveBatch(modelList);
44 | }
45 | return result;
46 | }
47 |
48 | @Override
49 | public boolean deleteAllByRoleCode(String roleCode) {
50 | QueryWrapper ew = new QueryWrapper<>();
51 | ew.eq("role_id", roleCode);
52 | return this.remove(ew);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/service/impl/SysRoleServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.service.impl;
2 |
3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
5 | import com.example.demo.base_security.VO.RoleAddVO;
6 | import com.example.demo.base_security.VO.RoleUpdateVO;
7 | import com.example.demo.base_security.commons.Constant;
8 | import com.example.demo.entity.SysRes;
9 | import com.example.demo.entity.SysRole;
10 | import com.example.demo.entity.SysRoleRes;
11 | import com.example.demo.entity.SysUserRole;
12 | import com.example.demo.mapper.SysRoleMapper;
13 | import com.example.demo.base_security.commons.PublicResultConstant;
14 | import com.example.demo.base_security.util.ComUtil;
15 | import com.example.demo.service.SysResService;
16 | import com.example.demo.service.SysRoleResService;
17 | import com.example.demo.service.SysRoleService;
18 | import com.example.demo.service.SysUserRoleService;
19 | import com.google.common.collect.Lists;
20 | import org.apache.commons.collections4.CollectionUtils;
21 | import org.joda.time.DateTime;
22 | import org.springframework.beans.BeanUtils;
23 | import org.springframework.beans.factory.annotation.Autowired;
24 | import org.springframework.stereotype.Service;
25 |
26 | import java.util.*;
27 | import java.util.stream.Collectors;
28 |
29 | /**
30 | *
31 | * 角色表 服务实现类
32 | *
33 | *
34 | * @author LXH
35 | * @since 2019-05-06
36 | */
37 | @Service
38 | public class SysRoleServiceImpl extends ServiceImpl implements SysRoleService {
39 |
40 | @Autowired
41 | private SysRoleResService roleToMenuService;
42 |
43 | @Autowired
44 | private SysUserRoleService userToRoleService;
45 |
46 | @Autowired
47 | private SysResService menuService;
48 |
49 | @Override
50 | public boolean addRoleAndPermission(RoleAddVO roleModel) throws Exception{
51 | SysRole role = new SysRole();
52 | BeanUtils.copyProperties(roleModel,role);
53 | boolean result = this.save(role);
54 | if (! result) {
55 | throw new RuntimeException(PublicResultConstant.UPDATE_ROLEINFO_ERROR);
56 | }
57 | result = roleToMenuService.saveAll(role.getId(), roleModel.getMenuIds());
58 | return result;
59 | }
60 |
61 | @Override
62 | public boolean updateRoleInfo(RoleUpdateVO roleModel) throws Exception{
63 | SysRole role1 = this.getById(roleModel.getId());
64 | if (Constant.ROLE_TYPE_ADMIN.equals(role1.getType())){
65 | throw new RuntimeException(PublicResultConstant.UPDATE_SYSADMIN_INFO_ERROR);
66 | }
67 | if (ComUtil.isEmpty(role1)) {
68 | return false;
69 | }
70 | BeanUtils.copyProperties(roleModel,role1);
71 | role1.setUpdateTime(DateTime.now().toDate());
72 | boolean result = this.updateById(role1);
73 | if (! result) {
74 | throw new RuntimeException(PublicResultConstant.UPDATE_ROLEINFO_ERROR);
75 | }
76 | result = roleToMenuService.remove(new QueryWrapper().eq("role_id",roleModel.getId()));
77 | if (! result) {
78 | throw new RuntimeException("删除权限信息失败");
79 | }
80 | result = roleToMenuService.saveAll(role1.getId(), roleModel.getMenuIds());
81 | if (! result) {
82 | throw new RuntimeException("更新权限信息失败");
83 | }
84 | return result;
85 |
86 | }
87 |
88 | @Override
89 | public void getRoleIsAdminByUserNo(String userNo) throws Exception {
90 | List userToRole = userToRoleService.selectByUserNo(userNo);
91 | if (CollectionUtils.isNotEmpty(userToRole)){
92 | List ids = userToRole.stream().map(item -> item.getRoleId()).collect(Collectors.toList());
93 | List role = this.listByIds(ids).stream().collect(Collectors.toList());
94 | role.forEach(item->{
95 | if(item.getType().equals(Constant.ROLE_TYPE_ADMIN)){
96 | throw new RuntimeException(PublicResultConstant.UPDATE_SYSADMIN_INFO_ERROR);
97 | }
98 |
99 | });
100 |
101 | }
102 | }
103 |
104 | @Override
105 | public Map selectByRoleCode(String roleCode) throws Exception {
106 | SysRole role = this.getById(roleCode);
107 | if(ComUtil.isEmpty(role)){
108 | throw new RuntimeException(PublicResultConstant.INVALID_ROLE);
109 | }
110 | Map result = new HashMap<>();
111 | result.put("role", role);
112 | //权限信息
113 | result.put("nodes", this.getMenuByRoleCode(role.getId()));
114 | return result;
115 | }
116 |
117 | @Override
118 | public void deleteByRoleCode(String roleCode) throws Exception {
119 | if (ComUtil.isEmpty(this.getById(roleCode))) {
120 | throw new RuntimeException("角色不存在");
121 | }
122 | if(!ComUtil.isEmpty(userToRoleService.list(new QueryWrapper().eq("role_id",roleCode)))){
123 | throw new RuntimeException("角色存在相关用户,请先删除相关角色的用户");
124 | }
125 | this.remove(new QueryWrapper().eq("role_code",roleCode));
126 | }
127 |
128 |
129 | @Override
130 | public Map getMenuByRoleCode(String roleCode) {
131 | Map retMap =new HashMap<>();
132 | LinkedList ids = Lists.newLinkedList();
133 | ids.add(roleCode);
134 | List menuList = menuService.findMenuByRoleCode(ids);
135 | List buttonList = new ArrayList();
136 | List retMenuList = menuService.treeMenuList(Constant.ROOT_MENU, menuList);
137 | for (SysRes buttonMenu : menuList) {
138 | if(buttonMenu.getType() == Constant.TYPE_BUTTON){
139 | buttonList.add(buttonMenu);
140 | }
141 | }
142 | retMap.put("menuList",retMenuList);
143 | retMap.put("buttonList",buttonList);
144 | return retMap;
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/service/impl/SysUserRoleServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.service.impl;
2 |
3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
5 | import com.example.demo.entity.SysUserRole;
6 | import com.example.demo.mapper.SysUserRoleMapper;
7 | import com.example.demo.base_security.util.ComUtil;
8 | import com.example.demo.service.SysUserRoleService;
9 | import org.springframework.stereotype.Service;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | *
15 | * 用户角色表 服务实现类
16 | *
17 | *
18 | * @author LXH
19 | * @since 2019-05-06
20 | */
21 | @Service
22 | public class SysUserRoleServiceImpl extends ServiceImpl implements SysUserRoleService {
23 |
24 | @Override
25 | // @Cacheable(value = "UserToRole",keyGenerator="wiselyKeyGenerator")
26 | public List selectByUserNo(String userId) {
27 | QueryWrapper ew = new QueryWrapper<>();
28 | ew.eq("user_id", userId);
29 | List userToRoleList = this.list(ew);
30 | return ComUtil.isEmpty(userToRoleList)? null: userToRoleList;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/service/impl/SysUserServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.service.impl;
2 |
3 | import com.alibaba.fastjson.JSONObject;
4 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
5 | import com.baomidou.mybatisplus.core.toolkit.IdWorker;
6 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
7 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
8 | import com.example.demo.base_security.VO.registerVO;
9 | import com.example.demo.base_security.commons.Constant;
10 | import com.example.demo.entity.SysRes;
11 | import com.example.demo.entity.SysUser;
12 | import com.example.demo.entity.SysUserRole;
13 | import com.example.demo.mapper.SysUserMapper;
14 | import com.example.demo.base_security.commons.PublicResultConstant;
15 | import com.example.demo.base_security.util.ComUtil;
16 | import com.example.demo.base_security.util.JWTUtil;
17 | import com.example.demo.base_security.util.StringUtil;
18 | import com.example.demo.service.SysResService;
19 | import com.example.demo.service.SysRoleService;
20 | import com.example.demo.service.SysUserRoleService;
21 | import com.example.demo.service.SysUserService;
22 | import com.example.demo.utils.CurrentUserUtils;
23 | import com.google.common.collect.Sets;
24 | import org.apache.commons.collections4.CollectionUtils;
25 | import org.joda.time.DateTime;
26 | import org.mindrot.jbcrypt.BCrypt;
27 | import lombok.extern.slf4j.Slf4j;
28 | import org.apache.commons.lang3.StringUtils;
29 | import org.springframework.beans.BeanUtils;
30 | import org.springframework.beans.factory.annotation.Autowired;
31 | import org.springframework.beans.factory.annotation.Value;
32 | import org.springframework.data.redis.core.StringRedisTemplate;
33 | import org.springframework.stereotype.Service;
34 | import org.springframework.transaction.annotation.Transactional;
35 |
36 | import javax.servlet.http.HttpServletRequest;
37 | import java.util.*;
38 | import java.util.stream.Collectors;
39 |
40 | /**
41 | *
42 | * 用户表 服务实现类
43 | *
44 | *
45 | * @author LXH
46 | * @since 2019-05-06
47 | */
48 | @Service
49 | @Slf4j
50 | @Transactional
51 | public class SysUserServiceImpl extends ServiceImpl implements SysUserService {
52 |
53 | @Value("${defaultPwd}")
54 | private String defaultPwd;
55 | @Autowired
56 | private SysUserMapper userMapper;
57 |
58 | @Autowired
59 | private StringRedisTemplate stringRedisTemplate;
60 |
61 | @Autowired
62 | private SysUserRoleService userToRoleService;
63 | @Autowired
64 | private SysResService menuService;
65 | @Autowired
66 | private SysUserRoleService sysUserRoleService;
67 |
68 | @Autowired
69 | private SysRoleService roleService;
70 |
71 | @Override
72 | public Page pageList(Integer pageNO, Integer pageSize) {
73 | Page pageInfo = new Page<>(pageNO, pageSize);//创建分页
74 | List list = userMapper.selectByParam(pageInfo);
75 | pageInfo.setRecords(list);
76 | SysUser user = CurrentUserUtils.getUser();
77 |
78 | return pageInfo;
79 |
80 | }
81 |
82 | @Override
83 | public SysUser getUserByUserName(String username) {
84 | return null;
85 | }
86 |
87 | @Override
88 | public SysUser getUserByMobile(String mobile) {
89 | QueryWrapper ew = new QueryWrapper<>();
90 | ew.eq("mobile", mobile);
91 | ew.eq("status", Constant.ENABLE);
92 | return this.getOne(ew);
93 | }
94 |
95 | @Override
96 | public SysUser register(SysUser user) {
97 | user.setId(IdWorker.getIdStr());
98 | user.setUserNo(user.getId());
99 | user.setCreateTime(DateTime.now().toDate());
100 | user.setStatus(Constant.ENABLE);
101 | user.setCreateTime(DateTime.now().toDate());
102 | user.setUpdateTime(DateTime.now().toDate());
103 | boolean result = this.save(user);
104 | // if (result) {
105 | // UserToRole userToRole = UserToRole.builder().userNo(user.getUserNo()).roleCode(roleCode).build();
106 | // userToRoleService.insert(userToRole);
107 | // }
108 | return user;
109 | }
110 |
111 | @Override
112 | public Map getLoginUserAndMenuInfo(SysUser user) {
113 | Map result = new HashMap<>();
114 | List userToRoleList = sysUserRoleService.selectByUserNo(user.getId());
115 | String token = JWTUtil.sign(user.getId(),user.getLoginName(), user.getPwd());
116 | result.put("token", token);
117 | result.put("user", user);
118 | List buttonList = new ArrayList<>();
119 | //根据角色主键查询启用的菜单权限
120 | if (CollectionUtils.isNotEmpty(userToRoleList)) {
121 | List roleIds = userToRoleList.stream().map(item -> item.getRoleId()).collect(Collectors.toList());
122 | List menuList = menuService.findMenuByRoleCode(roleIds);
123 | //去重
124 | if (CollectionUtils.isNotEmpty(menuList)) {
125 | HashSet ids = Sets.newHashSet();
126 | menuList.forEach(item -> {
127 | ids.add(item.getId());
128 | });
129 | List sysRes = menuService.listByIds(ids).stream().collect(Collectors.toList());
130 | List retMenuList = menuService.treeMenuList(Constant.ROOT_MENU, sysRes);
131 | for (SysRes buttonMenu : menuList) {
132 | if (buttonMenu.getType() == Constant.TYPE_BUTTON) {
133 | buttonList.add(buttonMenu);
134 | }
135 | }
136 | result.put("menuList", retMenuList);
137 | result.put("buttonList", buttonList);
138 | }
139 | }
140 | return result;
141 | }
142 |
143 | @Override
144 | public void deleteByUserNo(String userId) throws Exception {
145 | SysUser user = this.getById(userId);
146 | if (ComUtil.isEmpty(user)) {
147 | throw new RuntimeException(PublicResultConstant.INVALID_USER);
148 | }
149 | //todo: 暂未实现
150 | }
151 |
152 | @Override
153 | public Page selectPageByConditionUser(Page userPage, String info, Integer[] status, String startTime, String endTime) {
154 | return null;
155 | }
156 |
157 | @Override
158 | public Map checkMobileAndPasswd(JSONObject requestJson) throws Exception {
159 | String mobileNo = String.valueOf(requestJson.get("mobileNo"));
160 | String pwd = String.valueOf(requestJson.get("pwd"));
161 | if (StringUtils.isBlank(mobileNo) || StringUtils.isBlank(pwd)) {
162 | throw new RuntimeException("入参不能为空!");
163 | }
164 | if (!StringUtil.checkMobileNumber(mobileNo)) {
165 | throw new RuntimeException(PublicResultConstant.MOBILE_ERROR);
166 | }
167 | SysUser user = this.getOne(new QueryWrapper().eq("mobile_no", mobileNo).eq("status", 1));
168 | if (ComUtil.isEmpty(user) || !BCrypt.checkpw(requestJson.getString("pwd"), user.getPwd())) {
169 | throw new RuntimeException(PublicResultConstant.INVALID_USERNAME_PASSWORD);
170 | }
171 | return this.getLoginUserAndMenuInfo(user);
172 | }
173 |
174 | @Override
175 | public Map checkMobileAndCatcha(JSONObject requestJson) throws Exception {
176 | String mobile = requestJson.getString("mobile");
177 | if (!StringUtil.checkMobileNumber(mobile)) {
178 | throw new RuntimeException(PublicResultConstant.MOBILE_ERROR);
179 | }
180 | SysUser user = this.getUserByMobile(mobile);
181 | //如果不是启用的状态
182 | if (!ComUtil.isEmpty(user) && user.getStatus() != Constant.ENABLE) {
183 | throw new RuntimeException("该用户状态不是启用的!");
184 | }
185 | //todo:验证码校验 暂未处理
186 | // List smsVerifies = smsVerifyService.getByMobileAndCaptchaAndType(mobile,
187 | // requestJson.getString("captcha"), SmsSendUtil.SMSType.getType(SmsSendUtil.SMSType.AUTH.name()));
188 | // if(ComUtil.isEmpty(smsVerifies)){
189 | // throw new RuntimeException(PublicResultConstant.VERIFY_PARAM_ERROR);
190 | // }
191 | // if(SmsSendUtil.isCaptchaPassTime(smsVerifies.get(0).getCreateTime())){
192 | // throw new RuntimeException(PublicResultConstant.VERIFY_PARAM_PASS);
193 | // }
194 | if (ComUtil.isEmpty(user)) {
195 | //设置默认密码
196 | SysUser userRegister = SysUser.builder().pwd(BCrypt.hashpw(defaultPwd, BCrypt.gensalt()))
197 | .mobileNo(mobile).loginName(mobile).build();
198 | user = this.register(userRegister);
199 | }
200 | return this.getLoginUserAndMenuInfo(user);
201 | }
202 |
203 | @Override
204 | public SysUser checkAndRegisterUser(registerVO vo) throws Exception {
205 | //可直接转为java对象,简化操作,不用再set一个个属性
206 | SysUser userRegister = new SysUser();
207 | BeanUtils.copyProperties(vo, userRegister);
208 | //todo:验证码相关逻辑暂未处理
209 |
210 | // List smsVerifies = smsVerifyService.getByMobileAndCaptchaAndType(userRegister.getMobile(),
211 | // requestJson.getString("captcha"), SmsSendUtil.SMSType.getType(SmsSendUtil.SMSType.REG.name()));
212 | // if(ComUtil.isEmpty(smsVerifies)){
213 | // throw new BusinessException(PublicResultConstant.VERIFY_PARAM_ERROR);
214 | // }
215 | //验证码是否过期
216 | // if(SmsSendUtil.isCaptchaPassTime(smsVerifies.get(0).getCreateTime())){
217 | // throw new BusinessException(PublicResultConstant.VERIFY_PARAM_PASS);
218 | // }
219 | userRegister.setPwd(BCrypt.hashpw(vo.getPwd(), BCrypt.gensalt()));
220 | //默认注册普通用户
221 | return this.register(userRegister);
222 | }
223 |
224 | @Override
225 | public SysUser updateForgetPasswd(JSONObject requestJson) throws Exception {
226 | String mobile = requestJson.getString("mobile");
227 | if (!StringUtil.checkMobileNumber(mobile)) {
228 | throw new RuntimeException(PublicResultConstant.MOBILE_ERROR);
229 | }
230 | if (!requestJson.getString("password").equals(requestJson.getString("rePassword"))) {
231 | throw new RuntimeException(PublicResultConstant.INVALID_RE_PASSWORD);
232 | }
233 | SysUser user = this.getUserByMobile(mobile);
234 | roleService.getRoleIsAdminByUserNo(user.getUserNo());
235 | if (ComUtil.isEmpty(user)) {
236 | throw new RuntimeException(PublicResultConstant.INVALID_USER);
237 | }
238 | //todo:短信验证码校验暂未设置
239 | // List smsVerifies = smsVerifyService.getByMobileAndCaptchaAndType(mobile,
240 | // requestJson.getString("captcha"), SmsSendUtil.SMSType.getType(SmsSendUtil.SMSType.FINDPASSWORD.name()));
241 | // if(ComUtil.isEmpty(smsVerifies)){
242 | // throw new BusinessException(PublicResultConstant.VERIFY_PARAM_ERROR);
243 | // }
244 | // if(SmsSendUtil.isCaptchaPassTime(smsVerifies.get(0).getCreateTime())){
245 | // throw new BusinessException(PublicResultConstant.VERIFY_PARAM_PASS);
246 | // }
247 | user.setPwd(BCrypt.hashpw(requestJson.getString("password"), BCrypt.gensalt()));
248 | this.updateById(user);
249 | return user;
250 | }
251 |
252 | @Override
253 | public void resetMobile(SysUser currentUser, JSONObject requestJson) throws Exception {
254 | String newMobile = requestJson.getString("newMobile");
255 | if (!StringUtil.checkMobileNumber(newMobile)) {
256 | throw new RuntimeException(PublicResultConstant.MOBILE_ERROR);
257 | }
258 | /**todo: 短信验证码 暂未处置
259 | List smsVerifies = smsVerifyService.getByMobileAndCaptchaAndType(newMobile,
260 | requestJson.getString("captcha"), SmsSendUtil.SMSType.getType(SmsSendUtil.SMSType.MODIFYINFO.name()));
261 | if(ComUtil.isEmpty(smsVerifies)){
262 | throw new RuntimeException(PublicResultConstant.VERIFY_PARAM_ERROR);
263 | }
264 | if(SmsSendUtil.isCaptchaPassTime(smsVerifies.get(0).getCreateTime())){
265 | throw new RuntimeException(PublicResultConstant.VERIFY_PARAM_PASS);
266 | }
267 | **/
268 | currentUser.setMobileNo(newMobile);
269 | this.updateById(currentUser);
270 | }
271 |
272 | @Override
273 | public void resetPassWord(SysUser currentUser, JSONObject requestJson) throws Exception {
274 | if (!requestJson.getString("password").equals(requestJson.getString("rePassword"))) {
275 | throw new RuntimeException(PublicResultConstant.INVALID_RE_PASSWORD);
276 | }
277 | if (!BCrypt.checkpw(requestJson.getString("oldPassword"), currentUser.getPwd())) {
278 | throw new RuntimeException(PublicResultConstant.INVALID_USERNAME_PASSWORD);
279 | }
280 | currentUser.setPwd(BCrypt.hashpw(requestJson.getString("password"), BCrypt.gensalt()));
281 | this.updateById(currentUser);
282 | }
283 |
284 | @Override
285 | public boolean loginOut(String userId) {
286 | stringRedisTemplate.opsForHash().delete("token", userId);
287 | return true;
288 | }
289 | }
290 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/utils/CurrentUserUtils.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.utils;
2 |
3 | import com.baomidou.mybatisplus.extension.api.R;
4 | import com.example.demo.entity.SysUser;
5 | import org.apache.shiro.SecurityUtils;
6 | import org.springframework.web.context.request.RequestContextHolder;
7 | import org.springframework.web.context.request.ServletRequestAttributes;
8 | import springfox.documentation.RequestHandler;
9 |
10 | import javax.servlet.http.HttpServletRequest;
11 |
12 | /**
13 | * @author liuxinghong
14 | * @Description: 获取当前用用信息
15 | * @date 2019/5/16 001617:40
16 | */
17 | public class CurrentUserUtils {
18 |
19 | public static SysUser getUser(){
20 | ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
21 |
22 | HttpServletRequest request = servletRequestAttributes.getRequest();
23 | SysUser user = (SysUser)request.getAttribute("currentUser");
24 | if (null != user){
25 | return user;
26 | }
27 | return null;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/example/demo/utils/DateUtils.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.utils;
2 |
3 |
4 | import com.baomidou.mybatisplus.core.toolkit.StringUtils;
5 |
6 | import java.text.ParseException;
7 | import java.text.SimpleDateFormat;
8 | import java.util.Date;
9 |
10 | /**
11 | * Created with IntelliJ IDEA.
12 | * Description:
13 | *
14 | * @author : lxh
15 | * Date: 2018-01-29
16 | * Time: 17:30
17 | */
18 | public class DateUtils {
19 | public static SimpleDateFormat matter1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
20 | /**
21 | * 将字符串转date
22 | * @param str
23 | * @param pattern "yyyy-MM-dd HH:mm:ss" "yyyy-MM-dd" "yyyy-MM-dd HH:mm"
24 | * @return
25 | */
26 | public static Date stringToDate(String str , String pattern){
27 | SimpleDateFormat sdf = new SimpleDateFormat(pattern);
28 | try {
29 | if(StringUtils.isNotEmpty(str)&&StringUtils.isNotEmpty(pattern)){
30 | return sdf.parse(str);
31 | }else{
32 | return null;
33 | }
34 | } catch (ParseException e) {
35 | e.printStackTrace();
36 | return null;
37 | }
38 | }
39 |
40 | public static String dateToString(Date date,String format){
41 | if(date!=null){
42 | SimpleDateFormat sdf = new SimpleDateFormat(format);
43 | return sdf.format(date);
44 | }else{
45 | return "";
46 | }
47 | }
48 | /**
49 | * long类型转为String
50 | * @return 格式yyyy-MM-dd ,精确到日
51 | */
52 | public static Date longToDate(long l) {
53 | try {
54 | Date dt = new Date(l);
55 | return dt;
56 | } catch (Exception e) {
57 | return null;
58 | }
59 | }
60 |
61 | // public static void main(String[] args){
62 | // System.out.println(stringToDate("2017-01-01","yyyy-MM-dd"));
63 | // }
64 |
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/resources/application-dev.yml:
--------------------------------------------------------------------------------
1 |
2 | spring:
3 | datasource:
4 | name: test
5 | url: jdbc:mysql://18.136.204.238:3306/springboot_demo?useUnicode=true&characterEncoding=UTF-8&useSSL=false
6 | username:
7 | password:
8 | type: com.alibaba.druid.pool.DruidDataSource
9 | driver-class-name: com.mysql.jdbc.Driver
10 |
11 | redis:
12 | database: 2
13 | host: 18.136.204.238
14 | port: 6379
15 | password:
16 | cache:
17 | type: redis
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/main/resources/application-local.yml:
--------------------------------------------------------------------------------
1 |
2 | spring:
3 | datasource:
4 | name: test
5 | url: jdbc:mysql://192.168.60.182:3306/springboot_demo?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
6 | username: root
7 | password: root
8 | type: com.alibaba.druid.pool.DruidDataSource
9 | driver-class-name: com.mysql.jdbc.Driver
10 |
11 | redis:
12 | database: 3
13 | host: 192.168.60.182
14 | port: 6379
15 | password: root
16 | cache:
17 | type: redis
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8090
3 | # servlet:
4 | # context-path: /sb
5 |
6 | spring:
7 | profiles:
8 | active: local
9 | application:
10 | name: spring-demo
11 |
12 | logging:
13 | level:
14 | org.springframework: info
15 |
16 |
17 |
18 | liquibase:
19 | path: classpath:migrates/master.xml
20 | #配置文件上传支持文件大小
21 | servlet:
22 | multipart:
23 | max-file-size: 200MB
24 | max-request-size: 200MB
25 |
26 | #文件上传支持文件类型
27 | file:
28 | upload:
29 | acceptTypes: txt,jpg,jpeg,png,gif,svg,ico,doc,docx,xls,xlsx,ppt,pptx,pdf,flv,mp4,avi,rmvb
30 |
31 | mybatis-plus:
32 | mapper-locations: classpath*:mapper/*.xml
33 | #实体扫描,多个package用逗号或者分号分隔
34 | typeAliasesPackage: com.example.demo.entity
35 | #typeEnumsPackage: com.baomidou.springboot.entity.enums
36 | global-config:
37 | #主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
38 | id-type: 1
39 | #字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
40 | field-strategy: 2
41 | #驼峰下划线转换
42 | db-column-underline: true
43 | #刷新mapper 调试神器
44 | refresh-mapper: true
45 | #数据库大写下划线转换
46 | #capital-mode: true
47 | #序列接口实现类配置
48 | #key-generator: com.baomidou.springboot.xxx
49 | #逻辑删除配置
50 | logic-delete-value: 0
51 | logic-not-delete-value: 1
52 | #自定义填充策略接口实现
53 | #meta-object-handler: com.baomidou.springboot.xxx
54 | #自定义SQL注入器
55 | #sql-injector: com.baomidou.springboot.xxx
56 | configuration:
57 | map-underscore-to-camel-case: true
58 | cache-enabled: false
59 |
60 | #用户默认登录密码
61 | defaultPwd: 123456
62 | #token过期时间:单位毫秒
63 | expireTime: 15000
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/src/main/resources/mapper/SysLogMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | id, type, desc, remark, adr, status, create_time AS createTime, create_user AS createUser
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/main/resources/mapper/SysResMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | id, pid, name, permission, url, sort_num AS sortNum, icon1, icon2, pids, type, des, status, create_time AS createTime, update_time AS updateTime
26 |
27 |
28 |
29 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/src/main/resources/mapper/SysRoleMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | id, name, code, sort_num AS sortNum, des, status, create_time AS createTime, update_time AS updateTime
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/main/resources/mapper/SysRoleResMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | id, res_id AS resId, role_id AS roleId
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/main/resources/mapper/SysUserMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | id, login_name AS loginName, pwd, salt, name, email, sex, telephone, avatar, status, create_time AS createTime, update_time AS updateTime
28 |
29 |
30 |
31 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/src/main/resources/mapper/SysUserRoleMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | id, user_id AS userId, role_id AS roleId
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/main/resources/migrates/init/db.changelog.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
103 |
104 |
105 |
106 |
--------------------------------------------------------------------------------
/src/main/resources/migrates/init/db.data.initlog.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 | 超级管理员
11 |
12 |
13 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/main/resources/migrates/master.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/test/java/com/example/demo/DemoApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.example.demo;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class DemoApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------