<version>4.12</version> | <version>4.12</version> | ||||
<scope>test</scope> | <scope>test</scope> | ||||
</dependency> | </dependency> | ||||
<dependency> | |||||
<groupId>commons-codec</groupId> | |||||
<artifactId>commons-codec</artifactId> | |||||
<version>1.11</version> | |||||
</dependency> | |||||
<!-- 分页支持pageHelper --> | <!-- 分页支持pageHelper --> | ||||
<dependency> | |||||
<groupId>cn.hutool</groupId> | |||||
<artifactId>hutool-all</artifactId> | |||||
<version>4.6.10</version> | |||||
</dependency> | |||||
</dependencies> | </dependencies> | ||||
package com.xdf.creative.base.params.creative; | |||||
import io.swagger.annotations.ApiModel; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.Data; | |||||
import lombok.experimental.Accessors; | |||||
import javax.validation.constraints.NotBlank; | |||||
import javax.validation.constraints.NotEmpty; | |||||
import javax.validation.constraints.Size; | |||||
import java.util.List; | |||||
/** | |||||
* 添加角色 | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-10-25 | |||||
**/ | |||||
@Data | |||||
@Accessors(chain = true) | |||||
@ApiModel(value = "添加角色", description = "添加系统角色参数对象") | |||||
public class AddSysRoleParam { | |||||
@ApiModelProperty(value = "角色名称") | |||||
@NotBlank(message = "角色名称不能为空") | |||||
private String name; | |||||
@ApiModelProperty(value = "角色唯一编码") | |||||
private String code; | |||||
@ApiModelProperty(value = "角色类型") | |||||
private Integer type; | |||||
@ApiModelProperty(value = "角色状态,0:禁用,1:启用") | |||||
private Integer state; | |||||
@ApiModelProperty(value = "备注") | |||||
private String remark; | |||||
@ApiModelProperty(value = "权限id列表") | |||||
@NotEmpty(message = "权限集合不能为空") | |||||
@Size(max = 1000, message = "权限集合超过上限") | |||||
private List<String> permissionIds; | |||||
} |
package com.xdf.creative.base.params.creative; | |||||
import lombok.Data; | |||||
@Data | |||||
public class IsEnableSysOrganizeParam { | |||||
//用户Id | |||||
private Long userId; | |||||
//组织Id | |||||
private Long orgId; | |||||
public IsEnableSysOrganizeParam() { | |||||
} | |||||
public IsEnableSysOrganizeParam(Long userId, Long orgId) { | |||||
this.userId = userId; | |||||
this.orgId = orgId; | |||||
} | |||||
} |
package com.xdf.creative.base.params.creative; | |||||
import com.baomidou.mybatisplus.annotation.IdType; | |||||
import com.baomidou.mybatisplus.annotation.TableId; | |||||
import com.xdf.creative.base.params.QueryParam; | |||||
import io.swagger.annotations.ApiModel; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.Data; | |||||
import lombok.EqualsAndHashCode; | |||||
import lombok.experimental.Accessors; | |||||
import javax.validation.constraints.NotNull; | |||||
import java.util.Date; | |||||
/** | |||||
* <p> | |||||
* 组织信息 查询参数对象 | |||||
* </p> | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-11-05 | |||||
*/ | |||||
@Data | |||||
@Accessors(chain = true) | |||||
@EqualsAndHashCode(callSuper = true) | |||||
@ApiModel(value = "SysOrganizeQueryParam对象", description = "组织信息查询参数") | |||||
public class SysOrganizeQueryParam extends QueryParam { | |||||
private static final long serialVersionUID = 1L; | |||||
@TableId(value = "id", type = IdType.AUTO) | |||||
@NotNull(message = "不能为空") | |||||
private Long id; | |||||
@ApiModelProperty(value = "组织名称") | |||||
private String organizeName; | |||||
@ApiModelProperty(value = "管辖区域") | |||||
private Long popedom_id; | |||||
@ApiModelProperty(value = "类型: 0 普通用户 1、园区用户 2 区文创办 3市文创办 8后台管理 ") | |||||
private Integer organizeType; | |||||
@ApiModelProperty(value = "是否为系统组织: 0 否 1是") | |||||
private Integer systemCreate; | |||||
@ApiModelProperty(value = "系统状态 0停用 1启用") | |||||
private Integer state; | |||||
@ApiModelProperty(value = "修该时间") | |||||
private Date updateTime; | |||||
@ApiModelProperty(value = "创建时间") | |||||
private Date createTime; | |||||
@ApiModelProperty(value = "父id") | |||||
private Long parentId; | |||||
} |
package com.xdf.creative.base.params.creative; | |||||
import com.baomidou.mybatisplus.annotation.IdType; | |||||
import com.baomidou.mybatisplus.annotation.TableId; | |||||
import com.xdf.creative.base.params.QueryParam; | |||||
import io.swagger.annotations.ApiModel; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.Data; | |||||
import lombok.EqualsAndHashCode; | |||||
import lombok.experimental.Accessors; | |||||
import java.util.Date; | |||||
/** | |||||
* <p> | |||||
* 系统权限 查询参数对象 | |||||
* </p> | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-11-07 | |||||
*/ | |||||
@Data | |||||
@Accessors(chain = true) | |||||
@EqualsAndHashCode(callSuper = true) | |||||
@ApiModel(value = "SysPermissionQueryParam对象", description = "系统权限查询参数") | |||||
public class SysPermissionQueryParam extends QueryParam { | |||||
private static final long serialVersionUID = 1L; | |||||
@ApiModelProperty(value = "主键") | |||||
@TableId(value = "id", type = IdType.ID_WORKER) | |||||
private Long id; | |||||
@ApiModelProperty(value = "权限名称") | |||||
private String name; | |||||
private String resourceId; | |||||
@ApiModelProperty(value = "父id") | |||||
private String parentResourceId; | |||||
@ApiModelProperty(value = "路径") | |||||
private String url; | |||||
@ApiModelProperty(value = "唯一编码") | |||||
private String code; | |||||
@ApiModelProperty(value = "图标") | |||||
private String icon; | |||||
@ApiModelProperty(value = "类型,0 目录 1:菜单,2:按钮 3 url") | |||||
private Integer type; | |||||
@ApiModelProperty(value = "层级,1:第一级,2:第二级,N:第N级") | |||||
private Integer level; | |||||
@ApiModelProperty(value = "状态,0:禁用,1:启用") | |||||
private Integer state; | |||||
@ApiModelProperty(value = "排序") | |||||
private Integer sort; | |||||
@ApiModelProperty(value = "备注") | |||||
private String remark; | |||||
@ApiModelProperty(value = "逻辑删除,0:未删除,1:已删除") | |||||
private Integer deleted; | |||||
@ApiModelProperty(value = "版本") | |||||
private Integer version; | |||||
@ApiModelProperty(value = "创建时间") | |||||
private Date createTime; | |||||
@ApiModelProperty(value = "修改时间") | |||||
private Date updateTime; | |||||
} |
package com.xdf.creative.base.params.creative; | |||||
import com.xdf.creative.base.params.QueryParam; | |||||
import io.swagger.annotations.ApiModel; | |||||
import lombok.Data; | |||||
import lombok.EqualsAndHashCode; | |||||
import lombok.experimental.Accessors; | |||||
/** | |||||
* <pre> | |||||
* 角色权限关系 查询参数对象 | |||||
* </pre> | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-10-24 | |||||
*/ | |||||
@Data | |||||
@Accessors(chain = true) | |||||
@EqualsAndHashCode(callSuper = true) | |||||
@ApiModel(value = "SysRolePermissionQueryParam对象", description = "角色权限关系查询参数") | |||||
public class SysRolePermissionQueryParam extends QueryParam { | |||||
private static final long serialVersionUID = 1L; | |||||
} |
package com.xdf.creative.base.params.creative; | |||||
import com.xdf.creative.base.params.QueryParam; | |||||
import io.swagger.annotations.ApiModel; | |||||
import lombok.Data; | |||||
import lombok.EqualsAndHashCode; | |||||
import lombok.experimental.Accessors; | |||||
/** | |||||
* <pre> | |||||
* 系统角色 查询参数对象 | |||||
* </pre> | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-10-24 | |||||
*/ | |||||
@Data | |||||
@Accessors(chain = true) | |||||
@EqualsAndHashCode(callSuper = true) | |||||
@ApiModel(value = "SysRoleQueryParam对象", description = "系统角色查询参数") | |||||
public class SysRoleQueryParam extends QueryParam { | |||||
private static final long serialVersionUID = 1L; | |||||
} |
package com.xdf.creative.base.params.creative; | |||||
import com.xdf.creative.base.params.QueryParam; | |||||
import io.swagger.annotations.ApiModel; | |||||
import lombok.Data; | |||||
import lombok.EqualsAndHashCode; | |||||
import lombok.experimental.Accessors; | |||||
/** | |||||
* <pre> | |||||
* 系统用户 查询参数对象 | |||||
* </pre> | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-10-24 | |||||
*/ | |||||
@Data | |||||
@Accessors(chain = true) | |||||
@EqualsAndHashCode(callSuper = true) | |||||
@ApiModel(value = "SysUserQueryParam对象", description = "系统用户查询参数") | |||||
public class SysUserQueryParam extends QueryParam { | |||||
private static final long serialVersionUID = 1L; | |||||
} |
package com.xdf.creative.base.params.creative; | |||||
import com.baomidou.mybatisplus.annotation.IdType; | |||||
import com.baomidou.mybatisplus.annotation.TableId; | |||||
import com.xdf.creative.base.params.QueryParam; | |||||
import io.swagger.annotations.ApiModel; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.Data; | |||||
import lombok.EqualsAndHashCode; | |||||
import lombok.experimental.Accessors; | |||||
import javax.validation.constraints.NotNull; | |||||
import java.util.Date; | |||||
/** | |||||
* <p> | |||||
* 系统用户角色表 查询参数对象 | |||||
* </p> | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-10-30 | |||||
*/ | |||||
@Data | |||||
@Accessors(chain = true) | |||||
@EqualsAndHashCode(callSuper = true) | |||||
@ApiModel(value = "SysUserRoleQueryParam对象", description = "系统用户角色表查询参数") | |||||
public class SysUserRoleQueryParam extends QueryParam { | |||||
private static final long serialVersionUID = 1L; | |||||
@TableId(value = "id", type = IdType.AUTO) | |||||
@NotNull(message = "不能为空") | |||||
private Long id; | |||||
@ApiModelProperty(value = "用户ID") | |||||
private Long userId; | |||||
@ApiModelProperty(value = "角色ID") | |||||
private Long roleId; | |||||
@ApiModelProperty(value = "创建时间") | |||||
private Date createTime; | |||||
} |
package com.xdf.creative.base.params.creative; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.Data; | |||||
import lombok.experimental.Accessors; | |||||
import javax.validation.constraints.NotEmpty; | |||||
import javax.validation.constraints.NotNull; | |||||
/** | |||||
* 修改密码参数 | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-10-27 | |||||
**/ | |||||
@Data | |||||
@Accessors(chain = true) | |||||
public class UpdatePasswordParam { | |||||
@ApiModelProperty("用户id") | |||||
@NotNull(message = "用户id不能为空") | |||||
private Long userId; | |||||
@ApiModelProperty("原密码") | |||||
@NotEmpty(message = "原密码不能为空") | |||||
private String oldPassword; | |||||
@ApiModelProperty("新密码") | |||||
@NotEmpty(message = "新密码不能为空") | |||||
private String newPassword; | |||||
@ApiModelProperty("新密码") | |||||
@NotEmpty(message = "确认密码不能为空") | |||||
private String confirmPassword; | |||||
} |
package com.xdf.creative.base.params.creative; | |||||
import io.swagger.annotations.ApiModel; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.Data; | |||||
import lombok.experimental.Accessors; | |||||
import javax.validation.constraints.NotBlank; | |||||
import javax.validation.constraints.NotEmpty; | |||||
import javax.validation.constraints.NotNull; | |||||
import javax.validation.constraints.Size; | |||||
import java.util.List; | |||||
/** | |||||
* 添加角色 | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-10-25 | |||||
**/ | |||||
@Data | |||||
@Accessors(chain = true) | |||||
@ApiModel(value = "添加角色", description = "添加系统角色参数对象") | |||||
public class UpdateSysRoleParam { | |||||
@ApiModelProperty(value = "主键") | |||||
@NotNull(message = "主键不能为空") | |||||
private Long id; | |||||
@ApiModelProperty(value = "角色名称") | |||||
@NotBlank(message = "角色名称不能为空") | |||||
private String name; | |||||
@ApiModelProperty(value = "角色类型") | |||||
private Integer type; | |||||
@ApiModelProperty(value = "角色状态,0:禁用,1:启用") | |||||
private Integer state; | |||||
@ApiModelProperty(value = "备注") | |||||
private String remark; | |||||
@ApiModelProperty(value = "权限id列表") | |||||
@NotEmpty(message = "权限集合不能为空") | |||||
@Size(max = 1000, message = "权限集合超过上限") | |||||
private List<String> permissionIds; | |||||
} |
package com.xdf.creative.base.params.creative; | |||||
import com.baomidou.mybatisplus.annotation.IdType; | |||||
import com.baomidou.mybatisplus.annotation.TableId; | |||||
import io.swagger.annotations.ApiModel; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.Data; | |||||
import lombok.experimental.Accessors; | |||||
import javax.validation.constraints.NotNull; | |||||
import java.util.Set; | |||||
@Data | |||||
@Accessors(chain = true) | |||||
@ApiModel(value = "SaveSysUserParam对象", description = "添加系统用户对象") | |||||
public class UpdateUserParam { | |||||
@ApiModelProperty(value = "主键") | |||||
@TableId(value = "id", type = IdType.ID_WORKER) | |||||
@NotNull(message = "用户id不能为空") | |||||
private Long id; | |||||
@ApiModelProperty(value = "昵称") | |||||
private String nickname; | |||||
@ApiModelProperty(value = "密码") | |||||
private String password; | |||||
@ApiModelProperty(value = "手机号码") | |||||
private String phone; | |||||
@ApiModelProperty(value = "邮箱") | |||||
private String email; | |||||
@ApiModelProperty(value = "状态,0:禁用,1:启用,2:锁定") | |||||
private Integer state; | |||||
@ApiModelProperty(value = "角色id") | |||||
private Set<Long> roleId; | |||||
@ApiModelProperty(value = "性别,0:女,1:男,默认1") | |||||
private Integer gender; | |||||
@ApiModelProperty(value = "头像") | |||||
private String head; | |||||
@ApiModelProperty(value = "逻辑删除,0:未删除,1:已删除") | |||||
private Integer deleted; | |||||
@ApiModelProperty(value = "备注") | |||||
private String remark; | |||||
@ApiModelProperty(value = "组织id") | |||||
private Long organizeId; | |||||
} |
package com.xdf.creative.base.vo.creative; | |||||
import com.alibaba.fastjson.annotation.JSONField; | |||||
import com.fasterxml.jackson.annotation.JsonFormat; | |||||
import io.swagger.annotations.ApiModel; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.Data; | |||||
import lombok.experimental.Accessors; | |||||
import java.io.Serializable; | |||||
import java.util.Date; | |||||
/** | |||||
* <p> | |||||
* 组织信息 查询结果对象 | |||||
* </p> | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-11-05 | |||||
*/ | |||||
@Data | |||||
@Accessors(chain = true) | |||||
@ApiModel(value = "SysOrganizeQueryVo对象", description = "组织信息查询参数") | |||||
public class SysOrganizeQueryVo implements Serializable { | |||||
private static final long serialVersionUID = 1L; | |||||
private Long id; | |||||
@ApiModelProperty(value = "组织名称") | |||||
private String organizeName; | |||||
@ApiModelProperty(value = "管辖区域") | |||||
private Long popedomId; | |||||
@ApiModelProperty(value = "类型: 0 普通用户 1、园区用户 2 区文创办 3市文创办 8后台管理 ") | |||||
private Integer organizeType; | |||||
@ApiModelProperty(value = "是否为系统组织: 0 否 1是") | |||||
private Integer systemCreate; | |||||
@ApiModelProperty(value = "系统状态 0停用 1启用") | |||||
private Integer state; | |||||
@ApiModelProperty(value = "修该时间") | |||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss") | |||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||||
private Date updateTime; | |||||
@ApiModelProperty(value = "创建时间") | |||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss") | |||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||||
private Date createTime; | |||||
@ApiModelProperty(value = "父id") | |||||
private Long parentId; | |||||
} |
package com.xdf.creative.base.vo.creative; | |||||
import io.swagger.annotations.ApiModel; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.Data; | |||||
import lombok.experimental.Accessors; | |||||
import java.io.Serializable; | |||||
import java.util.Date; | |||||
/** | |||||
* <p> | |||||
* 系统权限 查询结果对象 | |||||
* </p> | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-11-07 | |||||
*/ | |||||
@Data | |||||
@Accessors(chain = true) | |||||
@ApiModel(value = "SysPermissionQueryVo对象", description = "系统权限查询参数") | |||||
public class SysPermissionQueryVo implements Serializable { | |||||
private static final long serialVersionUID = 1L; | |||||
@ApiModelProperty(value = "主键") | |||||
private Long id; | |||||
@ApiModelProperty(value = "权限名称") | |||||
private String name; | |||||
private String resourceId; | |||||
@ApiModelProperty(value = "父id") | |||||
private String parentResourceId; | |||||
@ApiModelProperty(value = "路径") | |||||
private String url; | |||||
@ApiModelProperty(value = "唯一编码") | |||||
private String code; | |||||
@ApiModelProperty(value = "图标") | |||||
private String icon; | |||||
@ApiModelProperty(value = "类型,0 目录 1:菜单,2:按钮 3 url") | |||||
private Integer type; | |||||
@ApiModelProperty(value = "层级,1:第一级,2:第二级,N:第N级") | |||||
private Integer level; | |||||
@ApiModelProperty(value = "状态,0:禁用,1:启用") | |||||
private Integer state; | |||||
@ApiModelProperty(value = "排序") | |||||
private Integer sort; | |||||
@ApiModelProperty(value = "备注") | |||||
private String remark; | |||||
@ApiModelProperty(value = "逻辑删除,0:未删除,1:已删除") | |||||
private Integer deleted; | |||||
@ApiModelProperty(value = "版本") | |||||
private Integer version; | |||||
@ApiModelProperty(value = "创建时间") | |||||
private Date createTime; | |||||
@ApiModelProperty(value = "修改时间") | |||||
private Date updateTime; | |||||
} |
/* | |||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea) | |||||
* | |||||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||||
* you may not use this file except in compliance with the License. | |||||
* You may obtain a copy of the License at | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | |||||
* distributed under the License is distributed on an "AS IS" BASIS, | |||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
* See the License for the specific language governing permissions and | |||||
* limitations under the License. | |||||
*/ | |||||
package com.xdf.creative.base.vo.creative; | |||||
import io.swagger.annotations.ApiModel; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.Data; | |||||
import lombok.experimental.Accessors; | |||||
import java.io.Serializable; | |||||
import java.util.ArrayList; | |||||
import java.util.Date; | |||||
import java.util.List; | |||||
/** | |||||
* 系统权限树形列表VO | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-10-26 | |||||
**/ | |||||
@Data | |||||
@Accessors(chain = true) | |||||
@ApiModel(value = "SysPermissionTreeVo对象", description = "系统权限树形列表") | |||||
public class SysPermissionTreeVo implements Serializable { | |||||
private static final long serialVersionUID = 2738804574228359190L; | |||||
@ApiModelProperty(value = "主键") | |||||
private Long id; | |||||
@ApiModelProperty(value = "权限名称") | |||||
private String name; | |||||
private String resourceId; | |||||
@ApiModelProperty(value = "父id") | |||||
private String parentResourceId; | |||||
@ApiModelProperty(value = "路径") | |||||
private String url; | |||||
@ApiModelProperty(value = "唯一编码") | |||||
private String code; | |||||
@ApiModelProperty(value = "图标") | |||||
private String icon; | |||||
@ApiModelProperty(value = "类型,1:菜单,2:按钮") | |||||
private Integer type; | |||||
@ApiModelProperty(value = "层级,1:第一级,2:第二级,N:第N级") | |||||
private Integer level; | |||||
@ApiModelProperty(value = "状态,0:禁用,1:启用") | |||||
private Integer state; | |||||
@ApiModelProperty(value = "排序") | |||||
private Integer sort; | |||||
@ApiModelProperty(value = "备注") | |||||
private String remark; | |||||
@ApiModelProperty(value = "版本") | |||||
private Integer version; | |||||
@ApiModelProperty(value = "创建时间") | |||||
private Date createTime; | |||||
@ApiModelProperty(value = "修改时间") | |||||
private Date updateTime; | |||||
@ApiModelProperty(value = "子节点集合") | |||||
private List<SysPermissionTreeVo> children = new ArrayList<>(); | |||||
} |
/* | |||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea) | |||||
* | |||||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||||
* you may not use this file except in compliance with the License. | |||||
* You may obtain a copy of the License at | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | |||||
* distributed under the License is distributed on an "AS IS" BASIS, | |||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
* See the License for the specific language governing permissions and | |||||
* limitations under the License. | |||||
*/ | |||||
package com.xdf.creative.base.vo.creative; | |||||
import io.swagger.annotations.ApiModel; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.Data; | |||||
import lombok.experimental.Accessors; | |||||
import java.io.Serializable; | |||||
import java.util.Date; | |||||
/** | |||||
* <pre> | |||||
* 角色权限关系 查询结果对象 | |||||
* </pre> | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-10-24 | |||||
*/ | |||||
@Data | |||||
@Accessors(chain = true) | |||||
@ApiModel(value = "SysRolePermissionQueryVo对象", description = "角色权限关系查询参数") | |||||
public class SysRolePermissionQueryVo implements Serializable { | |||||
private static final long serialVersionUID = 1L; | |||||
@ApiModelProperty(value = "主键") | |||||
private Long id; | |||||
@ApiModelProperty(value = "角色id") | |||||
private Long roleId; | |||||
@ApiModelProperty(value = "权限id") | |||||
private Long permissionId; | |||||
@ApiModelProperty(value = "状态,0:禁用,1:启用") | |||||
private Integer state; | |||||
@ApiModelProperty(value = "备注") | |||||
private String remark; | |||||
@ApiModelProperty(value = "版本") | |||||
private Integer version; | |||||
@ApiModelProperty(value = "创建时间") | |||||
private Date createTime; | |||||
@ApiModelProperty(value = "修改时间") | |||||
private Date updateTime; | |||||
} |
/* | |||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea) | |||||
* | |||||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||||
* you may not use this file except in compliance with the License. | |||||
* You may obtain a copy of the License at | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | |||||
* distributed under the License is distributed on an "AS IS" BASIS, | |||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
* See the License for the specific language governing permissions and | |||||
* limitations under the License. | |||||
*/ | |||||
package com.xdf.creative.base.vo.creative; | |||||
import io.swagger.annotations.ApiModel; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.Data; | |||||
import lombok.experimental.Accessors; | |||||
import java.io.Serializable; | |||||
import java.util.Date; | |||||
/** | |||||
* <pre> | |||||
* 系统角色 查询结果对象 | |||||
* </pre> | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-10-24 | |||||
*/ | |||||
@Data | |||||
@Accessors(chain = true) | |||||
@ApiModel(value = "SysRoleQueryVo对象", description = "系统角色查询参数") | |||||
public class SysRoleQueryVo implements Serializable { | |||||
private static final long serialVersionUID = 1L; | |||||
@ApiModelProperty(value = "主键") | |||||
private Long id; | |||||
@ApiModelProperty(value = "角色名称") | |||||
private String name; | |||||
@ApiModelProperty(value = "角色唯一编码") | |||||
private String code; | |||||
@ApiModelProperty(value = "角色类型") | |||||
private Integer type; | |||||
@ApiModelProperty(value = "角色状态,0:禁用,1:启用") | |||||
private Integer state; | |||||
@ApiModelProperty(value = "备注") | |||||
private String remark; | |||||
@ApiModelProperty(value = "版本") | |||||
private Integer version; | |||||
@ApiModelProperty(value = "创建时间") | |||||
private Date createTime; | |||||
@ApiModelProperty(value = "修改时间") | |||||
private Date updateTime; | |||||
} |
/* | |||||
* Copyright 2019-2029 geekidea(https://github.com/geekidea) | |||||
* | |||||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||||
* you may not use this file except in compliance with the License. | |||||
* You may obtain a copy of the License at | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | |||||
* distributed under the License is distributed on an "AS IS" BASIS, | |||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
* See the License for the specific language governing permissions and | |||||
* limitations under the License. | |||||
*/ | |||||
package com.xdf.creative.base.vo.creative; | |||||
import com.baomidou.mybatisplus.annotation.TableField; | |||||
import io.swagger.annotations.ApiModel; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.Data; | |||||
import lombok.experimental.Accessors; | |||||
import java.io.Serializable; | |||||
import java.util.Date; | |||||
import java.util.Set; | |||||
/** | |||||
* <pre> | |||||
* 系统用户 查询结果对象 | |||||
* </pre> | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-10-24 | |||||
*/ | |||||
@Data | |||||
@Accessors(chain = true) | |||||
@ApiModel(value = "SysUserQueryVo对象", description = "系统用户查询参数") | |||||
public class SysUserQueryVo implements Serializable { | |||||
private static final long serialVersionUID = 1L; | |||||
@ApiModelProperty(value = "主键") | |||||
private Long id; | |||||
@ApiModelProperty(value = "用户名") | |||||
private String username; | |||||
@ApiModelProperty(value = "昵称") | |||||
private String nickname; | |||||
@ApiModelProperty(value = "密码") | |||||
private String password; | |||||
@ApiModelProperty(value = "盐值") | |||||
private String salt; | |||||
@ApiModelProperty(value = "手机号码") | |||||
private String phone; | |||||
@ApiModelProperty(value = "邮箱") | |||||
private String email; | |||||
@ApiModelProperty(value = "状态,0:禁用,1:启用,2:锁定") | |||||
private Integer state; | |||||
@ApiModelProperty(value = "角色id") | |||||
@TableField(exist = false) | |||||
private Set<Long> roleId; | |||||
@ApiModelProperty(value = "性别,0:女,1:男,默认1") | |||||
private Integer gender; | |||||
@ApiModelProperty(value = "头像") | |||||
private String head; | |||||
@ApiModelProperty(value = "0 普通用户 1、园区 2 区文创办 3 市文创办 8后台管理") | |||||
private Integer userType; | |||||
@ApiModelProperty(value = "组织id") | |||||
private Long organizeId; | |||||
@ApiModelProperty(value = "创建者id") | |||||
private Long createUserId; | |||||
@ApiModelProperty(value = "逻辑删除,0:未删除,1:已删除") | |||||
private Integer deleted; | |||||
@ApiModelProperty(value = "版本") | |||||
private Integer version; | |||||
@ApiModelProperty(value = "remark") | |||||
private String remark; | |||||
@ApiModelProperty(value = "创建时间") | |||||
private Date createTime; | |||||
@ApiModelProperty(value = "修改时间") | |||||
private Date updateTime; | |||||
} |
package com.xdf.creative.base.vo.creative; | |||||
import io.swagger.annotations.ApiModel; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.Data; | |||||
import lombok.experimental.Accessors; | |||||
import java.io.Serializable; | |||||
import java.util.Date; | |||||
/** | |||||
* <p> | |||||
* 系统用户角色表 查询结果对象 | |||||
* </p> | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-10-30 | |||||
*/ | |||||
@Data | |||||
@Accessors(chain = true) | |||||
@ApiModel(value = "SysUserRoleQueryVo对象", description = "系统用户角色表查询参数") | |||||
public class SysUserRoleQueryVo implements Serializable { | |||||
private static final long serialVersionUID = 1L; | |||||
private Long id; | |||||
@ApiModelProperty(value = "用户ID") | |||||
private Long userId; | |||||
@ApiModelProperty(value = "角色ID") | |||||
private Long roleId; | |||||
@ApiModelProperty(value = "创建时间") | |||||
private Date createTime; | |||||
} |
package com.xdf.creative.enums; | |||||
/** | |||||
* @author DeanYe | |||||
* @date 2018-11-08 | |||||
*/ | |||||
public interface BaseTypeStateEnum { | |||||
Integer getKey(); | |||||
String getValue(); | |||||
} |
package com.xdf.creative.enums; | |||||
/** | |||||
* @author DeanYe | |||||
* @date 2019-10-24 | |||||
**/ | |||||
public enum LevelEnum implements BaseTypeStateEnum { | |||||
ONE(1, "一级菜单"), | |||||
TWO(2, "二级菜单"), | |||||
THREE(3, "功能菜单"); | |||||
private Integer key; | |||||
private String value; | |||||
LevelEnum(Integer key, String value) { | |||||
this.key = key; | |||||
this.value = value; | |||||
} | |||||
@Override | |||||
public Integer getKey() { | |||||
return this.key; | |||||
} | |||||
@Override | |||||
public String getValue() { | |||||
return this.value; | |||||
} | |||||
} |
package com.xdf.creative.enums; | |||||
/** | |||||
* @author DeanYe | |||||
* @date 2019-10-24 | |||||
**/ | |||||
public enum StateEnum implements BaseTypeStateEnum { | |||||
DISABLE, ENABLE; | |||||
@Override | |||||
public Integer getKey() { | |||||
return this.ordinal(); | |||||
} | |||||
@Override | |||||
public String getValue() { | |||||
return this.name(); | |||||
} | |||||
} |
package com.xdf.creative.module.controller; | |||||
import com.xdf.creative.base.controller.BaseController; | |||||
import com.xdf.creative.base.params.IdParam; | |||||
import com.xdf.creative.base.params.creative.SysOrganizeQueryParam; | |||||
import com.xdf.creative.base.vo.creative.SysOrganizeQueryVo; | |||||
import com.xdf.creative.module.entity.SysOrganize; | |||||
import com.xdf.creative.module.service.SysOrganizeService; | |||||
import com.xdf.creative.util.page.ApiResult; | |||||
import com.xdf.creative.util.page.PageTool; | |||||
import io.swagger.annotations.Api; | |||||
import io.swagger.annotations.ApiOperation; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.web.bind.annotation.PostMapping; | |||||
import org.springframework.web.bind.annotation.RequestBody; | |||||
import org.springframework.web.bind.annotation.RequestMapping; | |||||
import org.springframework.web.bind.annotation.RestController; | |||||
import javax.validation.Valid; | |||||
/** | |||||
* <p> | |||||
* 组织信息 前端控制器 | |||||
* </p> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-11-05 | |||||
*/ | |||||
@Slf4j | |||||
@RestController | |||||
@RequestMapping("/sysOrganize") | |||||
@Api("组织信息 API") | |||||
public class SysOrganizeController extends BaseController { | |||||
@Autowired | |||||
private SysOrganizeService sysOrganizeService; | |||||
/** | |||||
* 添加组织信息 | |||||
*/ | |||||
@PostMapping("/add") | |||||
@ApiOperation(value = "添加SysOrganize对象", notes = "添加组织信息", response = ApiResult.class) | |||||
public ApiResult<Boolean> addSysOrganize(@Valid @RequestBody SysOrganize sysOrganize) throws Exception { | |||||
boolean flag = sysOrganizeService.save(sysOrganize); | |||||
return ApiResult.result(flag); | |||||
} | |||||
/** | |||||
* 修改组织信息 | |||||
*/ | |||||
@PostMapping("/update") | |||||
@ApiOperation(value = "修改SysOrganize对象", notes = "修改组织信息", response = ApiResult.class) | |||||
public ApiResult<Boolean> updateSysOrganize(@Valid @RequestBody SysOrganize sysOrganize) throws Exception { | |||||
boolean flag = sysOrganizeService.updateById(sysOrganize); | |||||
return ApiResult.result(flag); | |||||
} | |||||
/** | |||||
* 删除组织信息 | |||||
*/ | |||||
@PostMapping("/delete") | |||||
@ApiOperation(value = "删除SysOrganize对象", notes = "删除组织信息", response = ApiResult.class) | |||||
public ApiResult<Boolean> deleteSysOrganize(@Valid @RequestBody IdParam idParam) throws Exception { | |||||
boolean flag = sysOrganizeService.removeById(idParam.getId()); | |||||
return ApiResult.result(flag); | |||||
} | |||||
/** | |||||
* 获取组织信息 | |||||
*/ | |||||
@PostMapping("/getSysOrganize") | |||||
@ApiOperation(value = "获取SysOrganize对象详情", notes = "查看组织信息", response = SysOrganizeQueryVo.class) | |||||
public ApiResult<SysOrganizeQueryVo> getSysOrganize(@Valid @RequestBody IdParam idParam) throws Exception { | |||||
SysOrganizeQueryVo sysOrganizeQueryVo = sysOrganizeService.getSysOrganizeById(idParam.getId()); | |||||
return ApiResult.ok(sysOrganizeQueryVo); | |||||
} | |||||
/** | |||||
* 组织信息分页列表 | |||||
*/ | |||||
@PostMapping("/getPageList") | |||||
@ApiOperation(value = "获取SysOrganize分页列表", notes = "组织信息分页列表", response = SysOrganizeQueryVo.class) | |||||
public ApiResult<PageTool<SysOrganizeQueryVo>> getSysOrganizePageList(@Valid @RequestBody SysOrganizeQueryParam sysOrganizeQueryParam) throws Exception { | |||||
PageTool<SysOrganizeQueryVo> pageList = sysOrganizeService.getSysOrganizePageList(sysOrganizeQueryParam); | |||||
return ApiResult.ok(pageList); | |||||
} | |||||
} | |||||
package com.xdf.creative.module.controller; | |||||
import com.xdf.creative.base.controller.BaseController; | |||||
import com.xdf.creative.base.params.creative.SysPermissionQueryParam; | |||||
import com.xdf.creative.base.vo.creative.SysPermissionQueryVo; | |||||
import com.xdf.creative.module.entity.SysPermission; | |||||
import com.xdf.creative.module.service.SysPermissionService; | |||||
import com.xdf.creative.util.page.ApiResult; | |||||
import com.xdf.creative.util.page.PageTool; | |||||
import com.xdf.creative.util.tree.TreeConfig; | |||||
import com.xdf.creative.util.tree.Utils; | |||||
import io.swagger.annotations.Api; | |||||
import io.swagger.annotations.ApiOperation; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.web.bind.annotation.*; | |||||
import javax.validation.Valid; | |||||
import java.util.List; | |||||
import java.util.Set; | |||||
/** | |||||
* <pre> | |||||
* 系统权限 前端控制器 | |||||
* </pre> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-10-24 | |||||
*/ | |||||
@Slf4j | |||||
@RestController | |||||
@RequestMapping("/sysPermission") | |||||
@Api("系统权限 API") | |||||
public class SysPermissionController extends BaseController { | |||||
@Autowired | |||||
private SysPermissionService sysPermissionService; | |||||
/** | |||||
* 添加系统权限 | |||||
*/ | |||||
@PostMapping("/add") | |||||
@ApiOperation(value = "添加SysPermission对象", notes = "添加系统权限", response = ApiResult.class) | |||||
public ApiResult<Boolean> addSysPermission(@Valid @RequestBody SysPermission sysPermission) throws Exception { | |||||
boolean flag = sysPermissionService.saveSysPermission(sysPermission); | |||||
return ApiResult.result(flag); | |||||
} | |||||
/** | |||||
* 修改系统权限 | |||||
*/ | |||||
@PostMapping("/update") | |||||
@ApiOperation(value = "修改SysPermission对象", notes = "修改系统权限", response = ApiResult.class) | |||||
public ApiResult<Boolean> updateSysPermission(@Valid @RequestBody SysPermission sysPermission) throws Exception { | |||||
boolean flag = sysPermissionService.updateSysPermission(sysPermission); | |||||
return ApiResult.result(flag); | |||||
} | |||||
/** | |||||
* 删除系统权限 | |||||
*/ | |||||
@PostMapping("/deleteSysPermissionById") | |||||
@ApiOperation(value = "删除SysPermission对象", notes = "删除系统权限", response = ApiResult.class) | |||||
public ApiResult<Boolean> deleteSysPermission(String resourceId) throws Exception { | |||||
boolean flag = sysPermissionService.deleteSysPermission(resourceId); | |||||
return ApiResult.result(flag); | |||||
} | |||||
/** | |||||
* 获取系统权限 | |||||
*/ | |||||
@GetMapping("/getSysPermissionById") | |||||
@ApiOperation(value = "获取SysPermission对象详情", notes = "查看系统权限", response = SysPermissionQueryVo.class) | |||||
public ApiResult<SysPermissionQueryVo> getSysPermission(Long id) throws Exception { | |||||
SysPermissionQueryVo sysPermissionQueryVo = sysPermissionService.getSysPermissionById(id); | |||||
return ApiResult.ok(sysPermissionQueryVo); | |||||
} | |||||
/** | |||||
* 系统权限分页列表 | |||||
*/ | |||||
@PostMapping("/getPageList") | |||||
@ApiOperation(value = "获取SysPermission分页列表", notes = "系统权限分页列表", response = SysPermissionQueryVo.class) | |||||
public ApiResult<PageTool<SysPermissionQueryVo>> getSysPermissionPageList(@Valid @RequestBody SysPermissionQueryParam sysPermissionQueryParam) throws Exception { | |||||
PageTool<SysPermissionQueryVo> paging = sysPermissionService.getSysPermissionPageList(sysPermissionQueryParam); | |||||
return ApiResult.ok(paging); | |||||
} | |||||
/** | |||||
* 获取所有菜单列表 | |||||
*/ | |||||
@PostMapping("/getAllMenuList") | |||||
@ApiOperation(value = "获取所有菜单列表", notes = "获取所有菜单列表", response = SysPermission.class) | |||||
public ApiResult<SysPermission> getAllMenuList() throws Exception { | |||||
List<SysPermission> list = sysPermissionService.getAllMenuList(); | |||||
return ApiResult.ok(list); | |||||
} | |||||
/** | |||||
* 根据用户id获取菜单列表 | |||||
*/ | |||||
@GetMapping("/getMenuListByUserId") | |||||
@ApiOperation(value = "根据用户id获取菜单列表", notes = "根据用户id获取菜单列表", response = SysPermission.class) | |||||
public ApiResult<SysPermission> getMenuListByUserId(Long userId) throws Exception { | |||||
List<SysPermission> list = sysPermissionService.getMenuListByUserId(userId); | |||||
return ApiResult.ok(list); | |||||
} | |||||
/** | |||||
* 根据请userId获取该用户权限路径集合 | |||||
*/ | |||||
@RequestMapping(value = "/getPermissionUrlByUserId", method = {RequestMethod.POST, RequestMethod.GET}) | |||||
@ApiOperation(value = "根据请求路径获取该用户权限编码", notes = "根据请求路径获取该用户权限编码", response = ApiResult.class) | |||||
public ApiResult<Set<String>> getPermissionUrlByUserId(Long userId) throws Exception { | |||||
Set<String> permissionUrls = sysPermissionService.getPermissionUrlByUserId(userId); | |||||
return ApiResult.ok(permissionUrls); | |||||
} | |||||
/** | |||||
* 角色授权资源树 | |||||
*/ | |||||
@PostMapping("/impowerResourceTreeList") | |||||
@ApiOperation(value = "获取所有菜单列表", notes = "获取所有菜单列表", response = SysPermission.class) | |||||
public ApiResult<SysPermission> impowerResourceTreeList(Long userId) throws Exception { | |||||
List<Object> list = sysPermissionService.impowerResourceTreeList(userId); | |||||
TreeConfig config = new TreeConfig("resourceId", "parentResourceId", "parentResourceId", "1", ""); | |||||
return ApiResult.ok(Utils.tree(list, config)); | |||||
} | |||||
@RequestMapping(value = "/setPermissionToRoleByUserId", method = {RequestMethod.GET}) | |||||
@ApiOperation(value = "给用户角色授权", notes = "给用户角色授权", response = SysPermission.class) | |||||
public ApiResult<Boolean> setPermissionToRoleByUserId(Long userId, Long roleId) throws Exception { | |||||
boolean isSucceed = sysPermissionService.setPermissionToRoleByUserId(userId, roleId); | |||||
return ApiResult.result(isSucceed); | |||||
} | |||||
@RequestMapping(value = "/getTreeMenusByUserId", method = {RequestMethod.GET}) | |||||
@ApiOperation(value = "根据用户ID获取树形菜单", notes = "根据用户ID获取树形菜单", response = SysPermission.class) | |||||
public ApiResult<List<Object>> getTreeMenusByUserId(Long userId) throws Exception { | |||||
List<Object> treeMenusByUserId = sysPermissionService.getTreeMenusByUserId(userId); | |||||
return ApiResult.ok(treeMenusByUserId); | |||||
} | |||||
@RequestMapping(value = "/getSkipAuthUrls", method = {RequestMethod.GET}) | |||||
@ApiOperation(value = "获取无需鉴权URL", notes = "获取无需鉴权URL", response = SysPermission.class) | |||||
public ApiResult<List<String>> getSkipAuthUrls() throws Exception { | |||||
List<String> skipAuthUrls = sysPermissionService.getSkipAuthUrls(); | |||||
return ApiResult.ok(skipAuthUrls); | |||||
} | |||||
@RequestMapping(value = "/refreshSkipAuthUrls", method = {RequestMethod.POST}) | |||||
@ApiOperation(value = "刷新SkipAuthUrls", notes = "刷新SkipAuthUrls", response = SysPermission.class) | |||||
public ApiResult refreshSkipAuthUrls() throws Exception { | |||||
List<String> skipAuthUrls = sysPermissionService.getSkipAuthUrls(); | |||||
// redisTemplate.convertAndSend("skipAuthUrls", skipAuthUrls);//发送对列消息 | |||||
return ApiResult.ok(); | |||||
} | |||||
} | |||||
package com.xdf.creative.module.controller; | |||||
import com.xdf.creative.base.controller.BaseController; | |||||
import com.xdf.creative.base.params.creative.AddSysRoleParam; | |||||
import com.xdf.creative.base.params.creative.SysRoleQueryParam; | |||||
import com.xdf.creative.base.params.creative.UpdateSysRoleParam; | |||||
import com.xdf.creative.base.vo.creative.SysRoleQueryVo; | |||||
import com.xdf.creative.module.service.SysRoleService; | |||||
import com.xdf.creative.util.page.ApiResult; | |||||
import com.xdf.creative.util.page.PageTool; | |||||
import io.swagger.annotations.Api; | |||||
import io.swagger.annotations.ApiOperation; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.web.bind.annotation.*; | |||||
import javax.validation.Valid; | |||||
import java.util.List; | |||||
/** | |||||
* <pre> | |||||
* 系统角色 前端控制器 | |||||
* </pre> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-10-24 | |||||
*/ | |||||
@Slf4j | |||||
@RestController | |||||
@RequestMapping("/sysRole") | |||||
@Api("系统角色 API") | |||||
public class SysRoleController extends BaseController { | |||||
@Autowired | |||||
private SysRoleService sysRoleService; | |||||
/** | |||||
* 添加系统角色 | |||||
*/ | |||||
@PostMapping("/add") | |||||
@ApiOperation(value = "添加SysRole对象", notes = "添加系统角色", response = ApiResult.class) | |||||
public ApiResult<Boolean> addSysRole(@Valid @RequestBody AddSysRoleParam addSysRoleParam) throws Exception { | |||||
boolean flag = sysRoleService.saveSysRole(addSysRoleParam); | |||||
return ApiResult.result(flag); | |||||
} | |||||
/** | |||||
* 修改系统角色 | |||||
*/ | |||||
@PostMapping("/update") | |||||
@ApiOperation(value = "修改SysRole对象", notes = "修改系统角色", response = ApiResult.class) | |||||
public ApiResult<Boolean> updateSysRole(@Valid @RequestBody UpdateSysRoleParam updateSysRoleParam) throws Exception { | |||||
boolean flag = sysRoleService.updateSysRole(updateSysRoleParam); | |||||
return ApiResult.result(flag); | |||||
} | |||||
/** | |||||
* 删除系统角色 | |||||
*/ | |||||
@PostMapping("/delete/{id}") | |||||
@ApiOperation(value = "删除SysRole对象", notes = "删除系统角色", response = ApiResult.class) | |||||
public ApiResult<Boolean> deleteSysRole(@PathVariable("id") Long id) throws Exception { | |||||
boolean flag = sysRoleService.deleteSysRole(id); | |||||
return ApiResult.result(flag); | |||||
} | |||||
/** | |||||
* 获取系统角色 | |||||
*/ | |||||
@GetMapping("/getSysRoleInfo") | |||||
@ApiOperation(value = "获取SysRole对象详情", notes = "查看系统角色", response = SysRoleQueryVo.class) | |||||
public ApiResult<SysRoleQueryVo> getSysRole(Long id) throws Exception { | |||||
SysRoleQueryVo sysRoleQueryVo = sysRoleService.getSysRoleById(id); | |||||
return ApiResult.ok(sysRoleQueryVo); | |||||
} | |||||
/** | |||||
* 系统角色分页列表 | |||||
*/ | |||||
@PostMapping("/getPageList") | |||||
@ApiOperation(value = "获取SysRole分页列表", notes = "系统角色分页列表", response = SysRoleQueryVo.class) | |||||
public ApiResult<PageTool<SysRoleQueryVo>> getSysRolePageList(@Valid @RequestBody SysRoleQueryParam sysRoleQueryParam) throws Exception { | |||||
PageTool<SysRoleQueryVo> pageList = sysRoleService.getSysRolePageList(sysRoleQueryParam); | |||||
return ApiResult.ok(pageList); | |||||
} | |||||
/** | |||||
* 根据UserId系统角色列表 | |||||
*/ | |||||
@RequestMapping(value = "/getUserRoleByUserId", method = {RequestMethod.GET, RequestMethod.POST}) | |||||
@ApiOperation(value = "获取SysRole列表", notes = "系统角色列表", response = SysRoleQueryVo.class) | |||||
public ApiResult<List<SysRoleQueryVo>> getUserRoleByUserId(@RequestParam Long userId) { | |||||
List<SysRoleQueryVo> vos = sysRoleService.getUserRoleByUserId(userId); | |||||
return ApiResult.ok(vos); | |||||
} | |||||
} | |||||
package com.xdf.creative.module.controller; | |||||
import com.xdf.creative.base.controller.BaseController; | |||||
import com.xdf.creative.base.params.creative.SysUserQueryParam; | |||||
import com.xdf.creative.base.params.creative.UpdatePasswordParam; | |||||
import com.xdf.creative.base.params.creative.UpdateUserParam; | |||||
import com.xdf.creative.base.vo.creative.SysUserQueryVo; | |||||
import com.xdf.creative.module.entity.SysUser; | |||||
import com.xdf.creative.module.service.SysUserService; | |||||
import com.xdf.creative.support.auth.LoginParam; | |||||
import com.xdf.creative.support.auth.LoginSysUserTokenVo; | |||||
import com.xdf.creative.util.page.ApiResult; | |||||
import com.xdf.creative.util.page.PageTool; | |||||
import io.swagger.annotations.Api; | |||||
import io.swagger.annotations.ApiOperation; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.web.bind.annotation.*; | |||||
import javax.servlet.http.HttpServletResponse; | |||||
import javax.validation.Valid; | |||||
/** | |||||
* <pre> | |||||
* 系统用户 前端控制器 | |||||
* </pre> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-10-24 | |||||
*/ | |||||
@Slf4j | |||||
@RestController | |||||
@RequestMapping("/sysUser") | |||||
@Api("系统用户 API") | |||||
public class SysUserController extends BaseController { | |||||
@Autowired | |||||
private SysUserService sysUserService; | |||||
@PostMapping("/login") | |||||
@ApiOperation(value = "登陆", notes = "系统用户登陆", response = ApiResult.class) | |||||
public ApiResult login(@Valid @RequestBody LoginParam loginParam, HttpServletResponse response) throws Exception { | |||||
LoginSysUserTokenVo loginSysUserTokenVo = sysUserService.login(loginParam); | |||||
// 设置token响应头 | |||||
// response.setHeader(JwtTokenUtil.getTokenName(), loginSysUserTokenVo.getToken()); | |||||
return ApiResult.ok(loginSysUserTokenVo, "登陆成功"); | |||||
} | |||||
/** | |||||
* 添加系统用户 | |||||
*/ | |||||
@PostMapping("/add") | |||||
@ApiOperation(value = "添加SysUser对象", notes = "添加系统用户", response = ApiResult.class) | |||||
public ApiResult<Boolean> addSysUser(@Valid @RequestBody SysUser sysUser) throws Exception { | |||||
boolean flag = sysUserService.saveSysUser(sysUser); | |||||
return ApiResult.result(flag); | |||||
} | |||||
/** | |||||
* 修改系统用户 | |||||
*/ | |||||
@PostMapping("/update") | |||||
@ApiOperation(value = "修改SysUser对象", notes = "修改系统用户", response = ApiResult.class) | |||||
public ApiResult<Boolean> updateSysUser(@Valid @RequestBody UpdateUserParam updateUserParam) throws Exception { | |||||
boolean flag = sysUserService.updateSysUser(updateUserParam); | |||||
return ApiResult.result(flag); | |||||
} | |||||
/** | |||||
* 删除系统用户 | |||||
*/ | |||||
@RequestMapping(value = "/delete", method = {RequestMethod.GET, RequestMethod.POST}) | |||||
@ApiOperation(value = "删除SysUser对象", notes = "删除系统用户", response = ApiResult.class) | |||||
public ApiResult<Boolean> deleteSysUser(Long id) throws Exception { | |||||
boolean flag = sysUserService.deleteSysUser(id); | |||||
return ApiResult.result(flag); | |||||
} | |||||
/** | |||||
* 获取系统用户 | |||||
*/ | |||||
@GetMapping("/getSysUserById") | |||||
@ApiOperation(value = "获取SysUser对象详情", notes = "查看系统用户", response = SysUserQueryVo.class) | |||||
public ApiResult<SysUserQueryVo> getSysUser(Long id) throws Exception { | |||||
SysUserQueryVo sysUserQueryVo = sysUserService.getSysUserById(id); | |||||
return ApiResult.ok(sysUserQueryVo); | |||||
} | |||||
/** | |||||
* 获取系统用户 | |||||
*/ | |||||
@GetMapping("/getSysUserByUserName") | |||||
@ApiOperation(value = "获取SysUser对象详情", notes = "查看系统用户", response = SysUserQueryVo.class) | |||||
public ApiResult<SysUser> getSysUserByUserName(@RequestParam String username) throws Exception { | |||||
SysUser sysUser = sysUserService.getSysUserByUserName(username); | |||||
return ApiResult.ok(sysUser); | |||||
} | |||||
/** | |||||
* 系统用户分页列表 | |||||
*/ | |||||
@PostMapping("/getPageList") | |||||
@ApiOperation(value = "获取SysUser分页列表", notes = "系统用户分页列表", response = SysUserQueryVo.class) | |||||
public ApiResult<PageTool<SysUserQueryVo>> getSysUserPageList(@Valid @RequestBody SysUserQueryParam sysUserQueryParam) throws Exception { | |||||
PageTool<SysUserQueryVo> pageList = sysUserService.getSysUserPageList(sysUserQueryParam); | |||||
return ApiResult.ok(pageList); | |||||
} | |||||
/** | |||||
* 修改密码 | |||||
*/ | |||||
@PostMapping("/updatePassword") | |||||
@ApiOperation(value = "修改密码", notes = "修改密码", response = ApiResult.class) | |||||
public ApiResult<Boolean> updatePassword(@Valid @RequestBody UpdatePasswordParam updatePasswordParam) throws Exception { | |||||
boolean flag = sysUserService.updatePassword(updatePasswordParam); | |||||
return ApiResult.result(flag); | |||||
} | |||||
} | |||||
package com.xdf.creative.module.entity; | |||||
import com.baomidou.mybatisplus.annotation.IdType; | |||||
import com.baomidou.mybatisplus.annotation.TableId; | |||||
import com.xdf.creative.base.entity.BaseEntity; | |||||
import io.swagger.annotations.ApiModel; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.Data; | |||||
import lombok.EqualsAndHashCode; | |||||
import lombok.experimental.Accessors; | |||||
import java.util.Date; | |||||
/** | |||||
* <p> | |||||
* 组织信息 | |||||
* </p> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-11-05 | |||||
*/ | |||||
@Data | |||||
@Accessors(chain = true) | |||||
@EqualsAndHashCode(callSuper = true) | |||||
@ApiModel(value = "SysOrganize对象", description = "组织信息") | |||||
public class SysOrganize extends BaseEntity { | |||||
private static final long serialVersionUID = 1L; | |||||
@TableId(value = "id", type = IdType.AUTO) | |||||
private Long id; | |||||
@ApiModelProperty(value = "组织名称") | |||||
private String organizeName; | |||||
@ApiModelProperty(value = "管辖区域") | |||||
private Long popedom_id; | |||||
@ApiModelProperty(value = "类型: 0 普通用户 1、园区用户 2 区文创办 3市文创办 8后台管理 ") | |||||
private Integer organizeType; | |||||
@ApiModelProperty(value = "是否为系统组织: 0 否 1是") | |||||
private Integer systemCreate; | |||||
@ApiModelProperty(value = "系统状态 0停用 1启用") | |||||
private Integer state; | |||||
@ApiModelProperty(value = "修该时间") | |||||
private Date updateTime; | |||||
@ApiModelProperty(value = "创建时间") | |||||
private Date createTime; | |||||
@ApiModelProperty(value = "父id") | |||||
private Long parentId; | |||||
} |
package com.xdf.creative.module.entity; | |||||
import com.baomidou.mybatisplus.annotation.IdType; | |||||
import com.baomidou.mybatisplus.annotation.TableField; | |||||
import com.baomidou.mybatisplus.annotation.TableId; | |||||
import com.xdf.creative.base.entity.BaseEntity; | |||||
import io.swagger.annotations.ApiModel; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.Data; | |||||
import lombok.EqualsAndHashCode; | |||||
import lombok.experimental.Accessors; | |||||
import java.util.ArrayList; | |||||
import java.util.Date; | |||||
import java.util.List; | |||||
/** | |||||
* <p> | |||||
* 系统权限 | |||||
* </p> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-11-07 | |||||
*/ | |||||
@Data | |||||
@Accessors(chain = true) | |||||
@EqualsAndHashCode(callSuper = true) | |||||
@ApiModel(value = "SysPermission对象", description = "系统权限") | |||||
public class SysPermission extends BaseEntity { | |||||
private static final long serialVersionUID = 1L; | |||||
@ApiModelProperty(value = "主键") | |||||
@TableId(value = "id", type = IdType.ID_WORKER) | |||||
private Long id; | |||||
@ApiModelProperty(value = "权限名称") | |||||
private String name; | |||||
@ApiModelProperty(value = "资源id") | |||||
private String resourceId; | |||||
@ApiModelProperty(value = "父id") | |||||
private String parentResourceId; | |||||
@ApiModelProperty(value = "路径") | |||||
private String url; | |||||
@ApiModelProperty(value = "唯一编码") | |||||
private String code; | |||||
@ApiModelProperty(value = "图标") | |||||
private String icon; | |||||
@ApiModelProperty(value = "类型,0 目录 1:菜单,2:按钮 3 url") | |||||
private Integer type; | |||||
@ApiModelProperty(value = "层级,1:第一级,2:第二级,N:第N级") | |||||
private Integer level; | |||||
@ApiModelProperty(value = "状态,0:禁用,1:启用") | |||||
private Integer state; | |||||
@ApiModelProperty(value = "排序") | |||||
private Integer sort; | |||||
@ApiModelProperty(value = "备注") | |||||
private String remark; | |||||
@ApiModelProperty(value = "逻辑删除,0:未删除,1:已删除") | |||||
private Integer deleted; | |||||
@ApiModelProperty(value = "版本") | |||||
private Integer version; | |||||
@ApiModelProperty(value = "创建时间") | |||||
private Date createTime; | |||||
@ApiModelProperty(value = "修改时间") | |||||
private Date updateTime; | |||||
/** | |||||
* 用于构造树 | |||||
*/ | |||||
@TableField(exist = false) | |||||
protected List<SysPermission> children = new ArrayList<SysPermission>(); | |||||
@TableField(exist = false) | |||||
protected Boolean leaf; | |||||
@TableField(exist = false) | |||||
protected Boolean checked; | |||||
} |
package com.xdf.creative.module.entity; | |||||
import com.baomidou.mybatisplus.annotation.IdType; | |||||
import com.baomidou.mybatisplus.annotation.TableId; | |||||
import com.baomidou.mybatisplus.annotation.Version; | |||||
import com.xdf.creative.base.entity.BaseEntity; | |||||
import io.swagger.annotations.ApiModel; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.Data; | |||||
import lombok.EqualsAndHashCode; | |||||
import lombok.experimental.Accessors; | |||||
import javax.validation.constraints.NotBlank; | |||||
import javax.validation.constraints.Null; | |||||
import java.util.Date; | |||||
/** | |||||
* <pre> | |||||
* 系统角色 | |||||
* </pre> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-10-24 | |||||
*/ | |||||
@Data | |||||
@Accessors(chain = true) | |||||
@EqualsAndHashCode(callSuper = true) | |||||
@ApiModel(value = "SysRole对象", description = "系统角色") | |||||
public class SysRole extends BaseEntity { | |||||
private static final long serialVersionUID = 1L; | |||||
@ApiModelProperty(value = "主键") | |||||
@TableId(value = "id", type = IdType.ID_WORKER) | |||||
private Long id; | |||||
@ApiModelProperty(value = "角色名称") | |||||
@NotBlank(message = "角色名称不能为空") | |||||
private String name; | |||||
@ApiModelProperty(value = "角色唯一编码") | |||||
private String code; | |||||
@ApiModelProperty(value = "角色类型") | |||||
private Integer type; | |||||
@ApiModelProperty(value = "角色状态,0:禁用,1:启用") | |||||
private Integer state; | |||||
@ApiModelProperty(value = "备注") | |||||
private String remark; | |||||
@ApiModelProperty(value = "版本") | |||||
@Null(message = "版本不用传") | |||||
@Version | |||||
private Integer version; | |||||
@ApiModelProperty(value = "创建时间") | |||||
@Null(message = "创建时间不用传") | |||||
private Date createTime; | |||||
@ApiModelProperty(value = "修改时间") | |||||
@Null(message = "修改时间不用传") | |||||
private Date updateTime; | |||||
} |
package com.xdf.creative.module.entity; | |||||
import com.baomidou.mybatisplus.annotation.IdType; | |||||
import com.baomidou.mybatisplus.annotation.TableId; | |||||
import com.baomidou.mybatisplus.annotation.Version; | |||||
import com.xdf.creative.base.entity.BaseEntity; | |||||
import io.swagger.annotations.ApiModel; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.Data; | |||||
import lombok.EqualsAndHashCode; | |||||
import lombok.experimental.Accessors; | |||||
import javax.validation.constraints.NotNull; | |||||
import javax.validation.constraints.Null; | |||||
import java.util.Date; | |||||
/** | |||||
* <pre> | |||||
* 角色权限关系 | |||||
* </pre> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-10-24 | |||||
*/ | |||||
@Data | |||||
@Accessors(chain = true) | |||||
@EqualsAndHashCode(callSuper = true) | |||||
@ApiModel(value = "SysRolePermission对象", description = "角色权限关系") | |||||
public class SysRolePermission extends BaseEntity { | |||||
private static final long serialVersionUID = 1L; | |||||
@ApiModelProperty(value = "主键") | |||||
@TableId(value = "id", type = IdType.AUTO) | |||||
private Long id; | |||||
@ApiModelProperty(value = "角色id") | |||||
@NotNull(message = "角色id不能为空") | |||||
private Long roleId; | |||||
@ApiModelProperty(value = "权限id") | |||||
@NotNull(message = "权限id不能为空") | |||||
private String permissionId; | |||||
@ApiModelProperty(value = "状态,0:禁用,1:启用") | |||||
private Integer state; | |||||
@ApiModelProperty(value = "备注") | |||||
private String remark; | |||||
@ApiModelProperty(value = "版本") | |||||
@Null(message = "版本不用传") | |||||
@Version | |||||
private Integer version; | |||||
@ApiModelProperty(value = "创建时间") | |||||
@Null(message = "创建时间不用传") | |||||
private Date createTime; | |||||
@ApiModelProperty(value = "修改时间") | |||||
@Null(message = "修改时间不用传") | |||||
private Date updateTime; | |||||
} |
package com.xdf.creative.module.entity; | |||||
import com.baomidou.mybatisplus.annotation.IdType; | |||||
import com.baomidou.mybatisplus.annotation.TableField; | |||||
import com.baomidou.mybatisplus.annotation.TableId; | |||||
import com.xdf.creative.base.entity.BaseEntity; | |||||
import io.swagger.annotations.ApiModel; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.Data; | |||||
import lombok.EqualsAndHashCode; | |||||
import lombok.experimental.Accessors; | |||||
import javax.validation.constraints.NotBlank; | |||||
import javax.validation.constraints.NotNull; | |||||
import java.util.Date; | |||||
import java.util.Set; | |||||
/** | |||||
* <pre> | |||||
* 系统用户 | |||||
* </pre> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-10-24 | |||||
*/ | |||||
@Data | |||||
@Accessors(chain = true) | |||||
@EqualsAndHashCode(callSuper = true) | |||||
@ApiModel(value = "SysUser对象", description = "系统用户") | |||||
public class SysUser extends BaseEntity { | |||||
private static final long serialVersionUID = 1L; | |||||
@ApiModelProperty(value = "主键") | |||||
@TableId(value = "id", type = IdType.ID_WORKER) | |||||
private Long id; | |||||
@ApiModelProperty(value = "用户名") | |||||
@NotBlank(message = "用户名不能为空") | |||||
private String username; | |||||
@ApiModelProperty(value = "昵称") | |||||
private String nickname; | |||||
@ApiModelProperty(value = "密码") | |||||
@NotBlank(message = "密码不能为空") | |||||
private String password; | |||||
@ApiModelProperty(value = "盐值") | |||||
private String salt; | |||||
@ApiModelProperty(value = "手机号码") | |||||
@NotBlank(message = "手机号码不能为空") | |||||
private String phone; | |||||
@ApiModelProperty(value = "邮箱") | |||||
private String email; | |||||
@ApiModelProperty(value = "状态,0:禁用,1:启用,2:锁定") | |||||
private Integer state; | |||||
@ApiModelProperty(value = "角色id") | |||||
@TableField(exist = false) | |||||
private Set<Long> roleId; | |||||
@ApiModelProperty(value = "性别,0:女,1:男,默认1") | |||||
private Integer gender; | |||||
@ApiModelProperty(value = "头像") | |||||
private String head; | |||||
@ApiModelProperty(value = "0 普通用户 1、园区 2 区文创办 3 市文创办 8后台管理") | |||||
private Integer userType; | |||||
@ApiModelProperty(value = "组织id") | |||||
@NotNull(message = "组织不能为空") | |||||
private Long organizeId; | |||||
@ApiModelProperty(value = "创建者id") | |||||
private Long createUserId; | |||||
@ApiModelProperty(value = "逻辑删除,0:未删除,1:已删除") | |||||
private Integer deleted; | |||||
@ApiModelProperty(value = "版本") | |||||
private Integer version; | |||||
@ApiModelProperty(value = "remark") | |||||
private String remark; | |||||
@ApiModelProperty(value = "创建时间") | |||||
private Date createTime; | |||||
@ApiModelProperty(value = "修改时间") | |||||
private Date updateTime; | |||||
} |
package com.xdf.creative.module.entity; | |||||
import com.baomidou.mybatisplus.annotation.IdType; | |||||
import com.baomidou.mybatisplus.annotation.TableId; | |||||
import com.xdf.creative.base.entity.BaseEntity; | |||||
import io.swagger.annotations.ApiModel; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.Data; | |||||
import lombok.EqualsAndHashCode; | |||||
import lombok.experimental.Accessors; | |||||
import javax.validation.constraints.NotNull; | |||||
import java.util.Date; | |||||
/** | |||||
* <p> | |||||
* 系统用户角色表 | |||||
* </p> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-10-30 | |||||
*/ | |||||
@Data | |||||
@Accessors(chain = true) | |||||
@EqualsAndHashCode(callSuper = true) | |||||
@ApiModel(value = "SysUserRole对象", description = "系统用户角色表") | |||||
public class SysUserRole extends BaseEntity { | |||||
private static final long serialVersionUID = 1L; | |||||
@TableId(value = "id", type = IdType.AUTO) | |||||
@NotNull(message = "不能为空") | |||||
private Long id; | |||||
@ApiModelProperty(value = "用户ID") | |||||
private Long userId; | |||||
@ApiModelProperty(value = "角色ID") | |||||
private Long roleId; | |||||
@ApiModelProperty(value = "创建时间") | |||||
private Date createTime; | |||||
} |
package com.xdf.creative.module.mapper; | |||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||||
import com.xdf.creative.base.params.creative.IsEnableSysOrganizeParam; | |||||
import com.xdf.creative.base.params.creative.SysOrganizeQueryParam; | |||||
import com.xdf.creative.base.vo.creative.SysOrganizeQueryVo; | |||||
import com.xdf.creative.module.entity.SysOrganize; | |||||
import org.apache.ibatis.annotations.Param; | |||||
import org.springframework.stereotype.Repository; | |||||
import java.io.Serializable; | |||||
/** | |||||
* 组织信息 Mapper 接口 | |||||
*/ | |||||
@Repository | |||||
public interface SysOrganizeMapper extends BaseMapper<SysOrganize> { | |||||
/** | |||||
* 根据用户id | |||||
* | |||||
* @param userId | |||||
* @return | |||||
*/ | |||||
SysOrganizeQueryVo getSysOrganizeByUserId(Long userId); | |||||
/** | |||||
* 根据ID获取查询对象 | |||||
* | |||||
* @param id | |||||
* @return | |||||
*/ | |||||
SysOrganizeQueryVo getSysOrganizeById(Serializable id); | |||||
/** | |||||
* 获取分页对象 | |||||
* | |||||
* @param page | |||||
* @param sysOrganizeQueryParam | |||||
* @return | |||||
*/ | |||||
IPage<SysOrganizeQueryVo> getSysOrganizePageList(@Param("page") Page page, @Param("param") SysOrganizeQueryParam sysOrganizeQueryParam); | |||||
/** | |||||
* 检查当前用户组织是否可用 | |||||
* | |||||
* @param isEnableSysOrganizeParam | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
Integer isEnableSysOrganize(IsEnableSysOrganizeParam isEnableSysOrganizeParam) throws Exception; | |||||
} |
package com.xdf.creative.module.mapper; | |||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||||
import com.xdf.creative.base.params.creative.SysPermissionQueryParam; | |||||
import com.xdf.creative.base.vo.creative.SysPermissionQueryVo; | |||||
import com.xdf.creative.module.entity.SysPermission; | |||||
import org.apache.ibatis.annotations.Param; | |||||
import org.springframework.stereotype.Repository; | |||||
import java.io.Serializable; | |||||
import java.util.List; | |||||
/** | |||||
* <pre> | |||||
* 系统权限 Mapper 接口 | |||||
* </pre> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-10-24 | |||||
*/ | |||||
@Repository | |||||
public interface SysPermissionMapper extends BaseMapper<SysPermission> { | |||||
/** | |||||
* 根据ID获取查询对象 | |||||
* | |||||
* @param id | |||||
* @return | |||||
*/ | |||||
SysPermissionQueryVo getSysPermissionById(Serializable id); | |||||
/** | |||||
* 获取分页对象 | |||||
* | |||||
* @param page | |||||
* @param sysPermissionQueryParam | |||||
* @return | |||||
*/ | |||||
IPage<SysPermissionQueryVo> getSysPermissionPageList(@Param("page") Page page, @Param("param") SysPermissionQueryParam sysPermissionQueryParam); | |||||
/** | |||||
* 根据用户id获取该用户所有Url | |||||
* 一个用户可以映射多个角色 | |||||
* | |||||
* @param userId | |||||
* @return | |||||
*/ | |||||
List<String> getPermissionUrlByUserId(@Param("userId") Long userId); | |||||
/** | |||||
* 根据用户id获取菜单列表 | |||||
* | |||||
* @param userId | |||||
* @return | |||||
*/ | |||||
List<SysPermission> getMenuListByUserId(@Param("userId") Long userId); | |||||
/** | |||||
* 根据用户ID获取菜单 | |||||
* | |||||
* @param userId | |||||
* @return | |||||
*/ | |||||
List<Object> getMenusByUserId(@Param("userId") Long userId); | |||||
/** | |||||
* 获取用户角色授权资源 树 | |||||
*/ | |||||
List<Object> impowerResourceTreeList(@Param("userId") Long userId); | |||||
/** | |||||
* 获取不需要鉴权urls | |||||
* | |||||
* @return | |||||
*/ | |||||
List<String> getSkipAuthUrls(); | |||||
} |
package com.xdf.creative.module.mapper; | |||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||||
import com.xdf.creative.base.params.creative.SysRoleQueryParam; | |||||
import com.xdf.creative.base.vo.creative.SysRoleQueryVo; | |||||
import com.xdf.creative.module.entity.SysRole; | |||||
import org.apache.ibatis.annotations.Param; | |||||
import org.springframework.stereotype.Repository; | |||||
import java.io.Serializable; | |||||
import java.util.List; | |||||
/** | |||||
* <pre> | |||||
* 系统角色 Mapper 接口 | |||||
* </pre> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-10-24 | |||||
*/ | |||||
@Repository | |||||
public interface SysRoleMapper extends BaseMapper<SysRole> { | |||||
/** | |||||
* 根据ID获取查询对象 | |||||
* | |||||
* @param id | |||||
* @return | |||||
*/ | |||||
SysRoleQueryVo getSysRoleById(Serializable id); | |||||
/** | |||||
* 获取分页对象 | |||||
* | |||||
* @param page | |||||
* @param sysRoleQueryParam | |||||
* @return | |||||
*/ | |||||
IPage<SysRoleQueryVo> getSysRolePageList(@Param("page") Page page, @Param("param") SysRoleQueryParam sysRoleQueryParam); | |||||
List<SysRoleQueryVo> getUserRoleByUserId(Long userId); | |||||
} |
package com.xdf.creative.module.mapper; | |||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||||
import com.xdf.creative.base.params.creative.SysRolePermissionQueryParam; | |||||
import com.xdf.creative.base.vo.creative.SysRolePermissionQueryVo; | |||||
import com.xdf.creative.module.entity.SysRolePermission; | |||||
import org.apache.ibatis.annotations.Param; | |||||
import org.springframework.stereotype.Repository; | |||||
import java.io.Serializable; | |||||
import java.util.Set; | |||||
/** | |||||
* <pre> | |||||
* 角色权限关系 Mapper 接口 | |||||
* </pre> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-10-24 | |||||
*/ | |||||
@Repository | |||||
public interface SysRolePermissionMapper extends BaseMapper<SysRolePermission> { | |||||
/** | |||||
* 根据ID获取查询对象 | |||||
* | |||||
* @param id | |||||
* @return | |||||
*/ | |||||
SysRolePermissionQueryVo getSysRolePermissionById(Serializable id); | |||||
/** | |||||
* 获取分页对象 | |||||
* | |||||
* @param page | |||||
* @param sysRolePermissionQueryParam | |||||
* @return | |||||
*/ | |||||
IPage<SysRolePermissionQueryVo> getSysRolePermissionPageList(@Param("page") Page page, @Param("param") SysRolePermissionQueryParam sysRolePermissionQueryParam); | |||||
/** | |||||
* 根据角色id获取可用的权限编码 | |||||
* | |||||
* @param roleId | |||||
* @return | |||||
*/ | |||||
Set<String> getPermissionCodesByRoleId(@Param("roleId") Long roleId); | |||||
} |
package com.xdf.creative.module.mapper; | |||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||||
import com.xdf.creative.base.params.creative.SysUserQueryParam; | |||||
import com.xdf.creative.base.vo.creative.SysUserQueryVo; | |||||
import com.xdf.creative.module.entity.SysUser; | |||||
import org.apache.ibatis.annotations.Param; | |||||
import org.springframework.stereotype.Repository; | |||||
import java.io.Serializable; | |||||
/** | |||||
* <pre> | |||||
* 系统用户 Mapper 接口 | |||||
* </pre> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-10-24 | |||||
*/ | |||||
@Repository | |||||
public interface SysUserMapper extends BaseMapper<SysUser> { | |||||
/** | |||||
* 根据ID获取查询对象 | |||||
* | |||||
* @param id | |||||
* @return | |||||
*/ | |||||
SysUserQueryVo getSysUserById(Serializable id); | |||||
/** | |||||
* 获取分页对象 | |||||
* | |||||
* @param page | |||||
* @param sysUserQueryParam | |||||
* @return | |||||
*/ | |||||
IPage<SysUserQueryVo> getSysUserPageList(@Param("page") Page page, @Param("param") SysUserQueryParam sysUserQueryParam); | |||||
SysUser getSysUserByUserName(@Param("username") String username); | |||||
} |
package com.xdf.creative.module.mapper; | |||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||||
import com.baomidou.mybatisplus.core.toolkit.Constants; | |||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||||
import com.xdf.creative.base.params.creative.SysUserRoleQueryParam; | |||||
import com.xdf.creative.base.vo.creative.SysUserRoleQueryVo; | |||||
import com.xdf.creative.module.entity.SysUserRole; | |||||
import org.apache.ibatis.annotations.Param; | |||||
import org.springframework.stereotype.Repository; | |||||
import java.io.Serializable; | |||||
/** | |||||
* <p> | |||||
* 系统用户角色表 Mapper 接口 | |||||
* </p> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-10-30 | |||||
*/ | |||||
@Repository | |||||
public interface SysUserRoleMapper extends BaseMapper<SysUserRole> { | |||||
/** | |||||
* 根据ID获取查询对象 | |||||
* | |||||
* @param id | |||||
* @return | |||||
*/ | |||||
SysUserRoleQueryVo getSysUserRoleById(Serializable id); | |||||
/** | |||||
* 获取分页对象 | |||||
* | |||||
* @param page | |||||
* @param sysUserRoleQueryParam | |||||
* @return | |||||
*/ | |||||
IPage<SysUserRoleQueryVo> getSysUserRolePageList(@Param("page") Page page, @Param(Constants.WRAPPER) SysUserRoleQueryParam sysUserRoleQueryParam); | |||||
} |
package com.xdf.creative.module.service; | |||||
import com.xdf.creative.base.params.creative.IsEnableSysOrganizeParam; | |||||
import com.xdf.creative.base.params.creative.SysOrganizeQueryParam; | |||||
import com.xdf.creative.base.service.BaseService; | |||||
import com.xdf.creative.base.vo.creative.SysOrganizeQueryVo; | |||||
import com.xdf.creative.module.entity.SysOrganize; | |||||
import com.xdf.creative.util.page.ApiResult; | |||||
import com.xdf.creative.util.page.PageTool; | |||||
import java.io.Serializable; | |||||
/** | |||||
* <p> | |||||
* 组织信息 服务类 | |||||
* </p> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-11-05 | |||||
*/ | |||||
public interface SysOrganizeService extends BaseService<SysOrganize> { | |||||
/** | |||||
* 根据ID获取查询对象 | |||||
* | |||||
* @param id | |||||
* @return | |||||
*/ | |||||
SysOrganizeQueryVo getSysOrganizeById(Serializable id) throws Exception; | |||||
/** | |||||
* 获取分页对象 | |||||
* | |||||
* @param sysOrganizeQueryParam | |||||
* @return | |||||
*/ | |||||
PageTool<SysOrganizeQueryVo> getSysOrganizePageList(SysOrganizeQueryParam sysOrganizeQueryParam) throws Exception; | |||||
/** | |||||
* 检查组织是否可用 | |||||
* | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
boolean isEnableSysOrganize(IsEnableSysOrganizeParam isEnableSysOrganizeParam) throws Exception; | |||||
} |
package com.xdf.creative.module.service; | |||||
import com.xdf.creative.base.params.creative.SysPermissionQueryParam; | |||||
import com.xdf.creative.base.service.BaseService; | |||||
import com.xdf.creative.base.vo.creative.SysPermissionQueryVo; | |||||
import com.xdf.creative.module.entity.SysPermission; | |||||
import com.xdf.creative.util.page.PageTool; | |||||
import java.io.Serializable; | |||||
import java.util.List; | |||||
import java.util.Set; | |||||
/** | |||||
* <pre> | |||||
* 系统权限 服务类 | |||||
* </pre> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-10-24 | |||||
*/ | |||||
public interface SysPermissionService extends BaseService<SysPermission> { | |||||
/** | |||||
* 保存 | |||||
* | |||||
* @param sysPermission | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
boolean saveSysPermission(SysPermission sysPermission) throws Exception; | |||||
/** | |||||
* 修改 | |||||
* | |||||
* @param sysPermission | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
boolean updateSysPermission(SysPermission sysPermission) throws Exception; | |||||
/** | |||||
* 删除 | |||||
* | |||||
* @param resourceId | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
boolean deleteSysPermission(String resourceId) throws Exception; | |||||
/** | |||||
* 根据ID获取查询对象 | |||||
* | |||||
* @param resourceId | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
SysPermissionQueryVo getSysPermissionById(Serializable resourceId) throws Exception; | |||||
/** | |||||
* 获取分页对象 | |||||
* | |||||
* @param sysPermissionQueryParam | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
PageTool<SysPermissionQueryVo> getSysPermissionPageList(SysPermissionQueryParam sysPermissionQueryParam) throws Exception; | |||||
/** | |||||
* 判断权限id是否存在 | |||||
* | |||||
* @param permissionIds | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
boolean isExistsByPermissionIds(List<String> permissionIds) throws Exception; | |||||
/** | |||||
* 获取所有菜单列表 | |||||
* | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
List<SysPermission> getAllMenuList() throws Exception; | |||||
/** | |||||
* 获取角色授权资源树 | |||||
* | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
List<Object> impowerResourceTreeList(Long userId) throws Exception; | |||||
/** | |||||
* 根据用户id获取菜单列表 | |||||
* | |||||
* @param userId | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
List<SysPermission> getMenuListByUserId(Long userId) throws Exception; | |||||
/** | |||||
* @param userId | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
List<Object> getTreeMenusByUserId(Long userId) throws Exception; | |||||
/** | |||||
* 根据请用户id取权限路径集合 | |||||
* | |||||
* @param userId | |||||
* @return | |||||
*/ | |||||
Set<String> getPermissionUrlByUserId(Long userId) throws Exception; | |||||
/** | |||||
* 给超级管理角色员赋予所有权限 | |||||
* | |||||
* @param userId | |||||
* @param roleId | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
Boolean setPermissionToRoleByUserId(Long userId, Long roleId) throws Exception; | |||||
/** | |||||
* 获取不需要鉴权url | |||||
* | |||||
* @return | |||||
*/ | |||||
List<String> getSkipAuthUrls() throws Exception; | |||||
} |
package com.xdf.creative.module.service; | |||||
import com.xdf.creative.base.service.BaseService; | |||||
import com.xdf.creative.module.entity.SysRolePermission; | |||||
import org.apache.commons.collections4.SetUtils; | |||||
import java.util.List; | |||||
import java.util.Set; | |||||
/** | |||||
* <pre> | |||||
* 角色权限关系 服务类 | |||||
* </pre> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-10-24 | |||||
*/ | |||||
public interface SysRolePermissionService extends BaseService<SysRolePermission> { | |||||
/** | |||||
* 保存 | |||||
* | |||||
* @param roleId | |||||
* @param permissionIds | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
boolean saveSysRolePermission(Long roleId, List<String> permissionIds) throws Exception; | |||||
/** | |||||
* 根据角色id获取权限id列表 | |||||
* | |||||
* @param roleId | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
List<String> getPermissionIdsByRoleId(Long roleId) throws Exception; | |||||
/** | |||||
* 批量保存角色权限关系 | |||||
* | |||||
* @param roleId | |||||
* @param addSet | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
boolean saveSysRolePermissionBatch(Long roleId, SetUtils.SetView addSet) throws Exception; | |||||
/** | |||||
* 根据角色id删除关联的权限关系 | |||||
* | |||||
* @param roleId | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
boolean deleteSysRolePermissionByRoleId(Long roleId) throws Exception; | |||||
/** | |||||
* 根据角色id获取可用的权限编码 | |||||
* | |||||
* @param roleId | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
Set<String> getPermissionCodesByRoleId(Long roleId) throws Exception; | |||||
/** | |||||
* 通过角色id判断在角色权限表中是否有数据存在 | |||||
* | |||||
* @param permissionId | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
boolean isExistsByPermissionId(String permissionId) throws Exception; | |||||
} |
package com.xdf.creative.module.service; | |||||
import com.xdf.creative.base.params.creative.AddSysRoleParam; | |||||
import com.xdf.creative.base.params.creative.SysRoleQueryParam; | |||||
import com.xdf.creative.base.params.creative.UpdateSysRoleParam; | |||||
import com.xdf.creative.base.service.BaseService; | |||||
import com.xdf.creative.base.vo.creative.SysRoleQueryVo; | |||||
import com.xdf.creative.module.entity.SysRole; | |||||
import com.xdf.creative.util.page.PageTool; | |||||
import java.io.Serializable; | |||||
import java.util.List; | |||||
import java.util.Set; | |||||
/** | |||||
* <pre> | |||||
* 系统角色 服务类 | |||||
* </pre> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-10-24 | |||||
*/ | |||||
public interface SysRoleService extends BaseService<SysRole> { | |||||
/** | |||||
* 保存 | |||||
* | |||||
* @param addSysRoleParam | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
boolean saveSysRole(AddSysRoleParam addSysRoleParam) throws Exception; | |||||
/** | |||||
* 修改 | |||||
* | |||||
* @param updateSysRoleParam | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
boolean updateSysRole(UpdateSysRoleParam updateSysRoleParam) throws Exception; | |||||
/** | |||||
* 删除 | |||||
* | |||||
* @param id | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
boolean deleteSysRole(Long id) throws Exception; | |||||
/** | |||||
* 根据ID获取查询对象 | |||||
* | |||||
* @param id | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
SysRoleQueryVo getSysRoleById(Serializable id) throws Exception; | |||||
/** | |||||
* 获取分页对象 | |||||
* | |||||
* @param sysRoleQueryParam | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
PageTool<SysRoleQueryVo> getSysRolePageList(SysRoleQueryParam sysRoleQueryParam) throws Exception; | |||||
/** | |||||
* 根据id校验角色是否存在并且已启用 | |||||
* | |||||
* @param id | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
boolean isEnableSysRole(Long id) throws Exception; | |||||
boolean isEnableSysRole(Set<Long> id) throws Exception; | |||||
/** | |||||
* 判断角色编码是否存在 | |||||
* | |||||
* @param code | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
boolean isExistsByCode(String code) throws Exception; | |||||
List<SysRoleQueryVo> getUserRoleByUserId(Long userId); | |||||
} |
package com.xdf.creative.module.service; | |||||
import com.xdf.creative.base.params.creative.SysUserRoleQueryParam; | |||||
import com.xdf.creative.base.service.BaseService; | |||||
import com.xdf.creative.base.vo.creative.SysUserRoleQueryVo; | |||||
import com.xdf.creative.module.entity.SysUserRole; | |||||
import com.xdf.creative.util.page.PageTool; | |||||
import java.io.Serializable; | |||||
/** | |||||
* <p> | |||||
* 系统用户角色表 服务类 | |||||
* </p> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-10-30 | |||||
*/ | |||||
public interface SysUserRoleService extends BaseService<SysUserRole> { | |||||
/** | |||||
* 根据ID获取查询对象 | |||||
* | |||||
* @param id | |||||
* @return | |||||
*/ | |||||
SysUserRoleQueryVo getSysUserRoleById(Serializable id) throws Exception; | |||||
/** | |||||
* 获取分页对象 | |||||
* | |||||
* @param sysUserRoleQueryParam | |||||
* @return | |||||
*/ | |||||
PageTool<SysUserRoleQueryVo> getSysUserRolePageList(SysUserRoleQueryParam sysUserRoleQueryParam) throws Exception; | |||||
} |
package com.xdf.creative.module.service; | |||||
import com.xdf.creative.base.params.creative.SysUserQueryParam; | |||||
import com.xdf.creative.base.params.creative.UpdatePasswordParam; | |||||
import com.xdf.creative.base.params.creative.UpdateUserParam; | |||||
import com.xdf.creative.base.service.BaseService; | |||||
import com.xdf.creative.base.vo.creative.SysUserQueryVo; | |||||
import com.xdf.creative.module.entity.SysUser; | |||||
import com.xdf.creative.support.auth.LoginParam; | |||||
import com.xdf.creative.support.auth.LoginSysUserTokenVo; | |||||
import com.xdf.creative.util.page.PageTool; | |||||
import java.io.Serializable; | |||||
import java.util.Set; | |||||
/** | |||||
* <pre> | |||||
* 系统用户 服务类 | |||||
* </pre> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-10-24 | |||||
*/ | |||||
public interface SysUserService extends BaseService<SysUser> { | |||||
/** | |||||
* 用户登录 | |||||
* | |||||
* @param loginParam | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
LoginSysUserTokenVo login(LoginParam loginParam) throws Exception; | |||||
/** | |||||
* 保存 | |||||
* | |||||
* @param sysUser | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
boolean saveSysUser(SysUser sysUser) throws Exception; | |||||
/** | |||||
* 修改系统用户信息 | |||||
* | |||||
* @param updateUserParam | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
boolean updateSysUser(UpdateUserParam updateUserParam) throws Exception; | |||||
/** | |||||
* 删除 | |||||
* | |||||
* @param id | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
boolean deleteSysUser(Long id) throws Exception; | |||||
/** | |||||
* 根据ID获取查询对象 | |||||
* | |||||
* @param id | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
SysUserQueryVo getSysUserById(Serializable id) throws Exception; | |||||
/** | |||||
* 获取分页对象 | |||||
* | |||||
* @param sysUserQueryParam | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
PageTool<SysUserQueryVo> getSysUserPageList(SysUserQueryParam sysUserQueryParam) throws Exception; | |||||
/** | |||||
* 判断用户名是否存在 | |||||
* | |||||
* @param username | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
boolean isExistsByUsername(String username) throws Exception; | |||||
/** | |||||
* 检验部门和角色是否存在并且已启用 | |||||
* | |||||
* @param departmentId | |||||
* @param roleId | |||||
* @throws Exception | |||||
*/ | |||||
void checkOrganizeAndRole(Long departmentId, Set<Long> roleId) throws Exception; | |||||
/** | |||||
* 通过角色id判断是否存在可用用户id | |||||
* | |||||
* @param roleId | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
boolean isExistsSysUserByRoleId(Long roleId) throws Exception; | |||||
/** | |||||
* 修改密码 | |||||
* | |||||
* @param updatePasswordParam | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
boolean updatePassword(UpdatePasswordParam updatePasswordParam) throws Exception; | |||||
/** | |||||
* 修改系统用户头像 | |||||
* | |||||
* @param id | |||||
* @param headPath | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
boolean updateSysUserHead(Long id, String headPath) throws Exception; | |||||
SysUser getSysUserByUserName(String username) throws Exception; | |||||
} |
package com.xdf.creative.module.service.impl; | |||||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||||
import com.xdf.creative.base.params.creative.IsEnableSysOrganizeParam; | |||||
import com.xdf.creative.base.params.creative.SysOrganizeQueryParam; | |||||
import com.xdf.creative.base.service.impl.BaseServiceImpl; | |||||
import com.xdf.creative.base.vo.creative.SysOrganizeQueryVo; | |||||
import com.xdf.creative.module.entity.SysOrganize; | |||||
import com.xdf.creative.module.mapper.SysOrganizeMapper; | |||||
import com.xdf.creative.module.mapper.SysRegionMapper; | |||||
import com.xdf.creative.module.service.SysOrganizeService; | |||||
import com.xdf.creative.util.page.PageTool; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.stereotype.Service; | |||||
import org.springframework.transaction.annotation.Transactional; | |||||
import java.io.Serializable; | |||||
/** | |||||
* <p> | |||||
* 组织信息 服务实现类 | |||||
* </p> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-11-05 | |||||
*/ | |||||
@Slf4j | |||||
@Service | |||||
@Transactional(rollbackFor = Exception.class) | |||||
public class SysOrganizeServiceImpl extends BaseServiceImpl<SysOrganizeMapper, SysOrganize> implements SysOrganizeService { | |||||
@Autowired | |||||
private SysOrganizeMapper sysOrganizeMapper; | |||||
@Autowired | |||||
private SysRegionMapper sysRegionMapper; | |||||
@Override | |||||
public SysOrganizeQueryVo getSysOrganizeById(Serializable id) throws Exception { | |||||
return sysOrganizeMapper.getSysOrganizeById(id); | |||||
} | |||||
@Override | |||||
public PageTool<SysOrganizeQueryVo> getSysOrganizePageList(SysOrganizeQueryParam sysOrganizeQueryParam) throws Exception { | |||||
Page page = setPageParam(sysOrganizeQueryParam); | |||||
IPage<SysOrganizeQueryVo> iPage = sysOrganizeMapper.getSysOrganizePageList(page, sysOrganizeQueryParam); | |||||
return new PageTool(iPage); | |||||
} | |||||
@Override | |||||
public boolean isEnableSysOrganize(IsEnableSysOrganizeParam isEnableSysOrganizeParam) throws Exception { | |||||
Integer count = sysOrganizeMapper.isEnableSysOrganize(isEnableSysOrganizeParam); | |||||
return count > 0; | |||||
} | |||||
} |
package com.xdf.creative.module.service.impl; | |||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||||
import com.xdf.creative.base.params.creative.SysPermissionQueryParam; | |||||
import com.xdf.creative.base.service.impl.BaseServiceImpl; | |||||
import com.xdf.creative.base.vo.creative.SysPermissionQueryVo; | |||||
import com.xdf.creative.enums.StateEnum; | |||||
import com.xdf.creative.module.entity.SysPermission; | |||||
import com.xdf.creative.module.entity.SysRolePermission; | |||||
import com.xdf.creative.module.mapper.SysPermissionMapper; | |||||
import com.xdf.creative.module.service.SysPermissionService; | |||||
import com.xdf.creative.module.service.SysRolePermissionService; | |||||
import com.xdf.creative.support.exception.BusinessException; | |||||
import com.xdf.creative.util.StringUtil; | |||||
import com.xdf.creative.util.page.PageTool; | |||||
import com.xdf.creative.util.tree.TreeConfig; | |||||
import com.xdf.creative.util.tree.Utils; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.stereotype.Service; | |||||
import org.springframework.transaction.annotation.Transactional; | |||||
import javax.annotation.Resource; | |||||
import java.io.Serializable; | |||||
import java.util.*; | |||||
/** | |||||
* <pre> | |||||
* 系统权限 服务实现类 | |||||
* </pre> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-10-25 | |||||
*/ | |||||
@Slf4j | |||||
@Service | |||||
public class SysPermissionServiceImpl extends BaseServiceImpl<SysPermissionMapper, SysPermission> implements SysPermissionService { | |||||
@Autowired | |||||
private SysPermissionMapper sysPermissionMapper; | |||||
@Resource | |||||
private SysRolePermissionService sysRolePermissionService; | |||||
@Transactional(rollbackFor = Exception.class) | |||||
@Override | |||||
public boolean saveSysPermission(SysPermission sysPermission) throws Exception { | |||||
sysPermission.setId(null); | |||||
return super.save(sysPermission); | |||||
} | |||||
@Transactional(rollbackFor = Exception.class) | |||||
@Override | |||||
public boolean updateSysPermission(SysPermission sysPermission) throws Exception { | |||||
// 获取权限 | |||||
SysPermission updateSysPermission = getById(sysPermission.getResourceId()); | |||||
if (updateSysPermission == null) { | |||||
throw new BusinessException("权限不存在"); | |||||
} | |||||
// 指定需改的字段 | |||||
updateSysPermission.setParentResourceId(sysPermission.getParentResourceId()) | |||||
.setLevel(sysPermission.getLevel()) | |||||
.setName(sysPermission.getName()) | |||||
.setState(sysPermission.getState()) | |||||
.setCode(sysPermission.getCode()) | |||||
.setIcon(sysPermission.getIcon()) | |||||
.setRemark(sysPermission.getRemark()) | |||||
.setSort(sysPermission.getSort()) | |||||
.setType(sysPermission.getType()) | |||||
.setUrl(sysPermission.getUrl()) | |||||
.setUpdateTime(new Date()); | |||||
return super.updateById(updateSysPermission); | |||||
} | |||||
@Transactional(rollbackFor = Exception.class) | |||||
@Override | |||||
public boolean deleteSysPermission(String resourceId) throws Exception { | |||||
boolean isExists = sysRolePermissionService.isExistsByPermissionId(resourceId); | |||||
if (isExists) { | |||||
throw new BusinessException("该权限存在角色关联关系,不能删除"); | |||||
} | |||||
return super.removeById(resourceId); | |||||
} | |||||
@Override | |||||
public SysPermissionQueryVo getSysPermissionById(Serializable id) throws Exception { | |||||
return sysPermissionMapper.getSysPermissionById(id); | |||||
} | |||||
@Override | |||||
public PageTool<SysPermissionQueryVo> getSysPermissionPageList(SysPermissionQueryParam sysPermissionQueryParam) throws Exception { | |||||
Page page = setPageParam(sysPermissionQueryParam); | |||||
IPage<SysPermissionQueryVo> iPage = sysPermissionMapper.getSysPermissionPageList(page, sysPermissionQueryParam); | |||||
return new PageTool(iPage); | |||||
} | |||||
@Override | |||||
public boolean isExistsByPermissionIds(List<String> permissionIds) { | |||||
QueryWrapper queryWrapper = new QueryWrapper(); | |||||
queryWrapper.in("resourceId", permissionIds); | |||||
return sysPermissionMapper.selectCount(queryWrapper).intValue() == permissionIds.size(); | |||||
} | |||||
@Override | |||||
public List<SysPermission> getAllMenuList() throws Exception { | |||||
SysPermission sysPermission = new SysPermission().setState(StateEnum.ENABLE.ordinal()); | |||||
// 获取所有已启用的权限列表 | |||||
return sysPermissionMapper.selectList(new QueryWrapper(sysPermission)); | |||||
} | |||||
/** | |||||
* 获取角色授权资源树 | |||||
* | |||||
* @param userId | |||||
* @return | |||||
* @throws Exception | |||||
*/ | |||||
@Override | |||||
public List<Object> impowerResourceTreeList(Long userId) throws Exception { | |||||
return sysPermissionMapper.impowerResourceTreeList(userId); | |||||
} | |||||
@Override | |||||
public List<SysPermission> getMenuListByUserId(Long userId) throws Exception { | |||||
return sysPermissionMapper.getMenuListByUserId(userId); | |||||
} | |||||
@Override | |||||
public List<Object> getTreeMenusByUserId(Long userId) throws Exception { | |||||
// 获取所有已启用的权限列表 | |||||
List<Object> list = sysPermissionMapper.getMenusByUserId(userId); | |||||
TreeConfig config = new TreeConfig("resourceId", "parentResourceId", "parentResourceId", "01", ""); | |||||
List<Object> objectList = Utils.tree(list, config); | |||||
return objectList; | |||||
} | |||||
@Override | |||||
public Set<String> getPermissionUrlByUserId(Long userId) throws Exception { | |||||
List<String> permissionUrls = sysPermissionMapper.getPermissionUrlByUserId(userId); | |||||
HashSet<String> stringHashSet = new HashSet<>(); | |||||
permissionUrls.stream().forEach(s -> { | |||||
if (StringUtil.isNotEmpty(s)) { | |||||
if (s.contains(";")) { | |||||
String[] url = s.split(s); | |||||
for (String s1 : url) { | |||||
stringHashSet.add(s1); | |||||
} | |||||
} else { | |||||
stringHashSet.add(s); | |||||
} | |||||
} | |||||
}); | |||||
return stringHashSet; | |||||
} | |||||
@Override | |||||
public Boolean setPermissionToRoleByUserId(Long userId, Long roleId) throws Exception { | |||||
QueryWrapper queryWrapper = new QueryWrapper(); | |||||
List<SysPermission> list = sysPermissionMapper.selectList(queryWrapper); | |||||
List<SysRolePermission> sysRolePermissions = new ArrayList<>(); | |||||
list.stream().forEach(sysPermission -> { | |||||
SysRolePermission sysRolePermission = new SysRolePermission(); | |||||
String resourceId = sysPermission.getResourceId(); | |||||
sysRolePermission.setPermissionId(resourceId); | |||||
sysRolePermission.setRoleId(roleId); | |||||
sysRolePermission.setRemark(sysPermission.getName()); | |||||
sysRolePermissions.add(sysRolePermission); | |||||
}); | |||||
boolean isSucceed = sysRolePermissionService.saveBatch(sysRolePermissions, 20); | |||||
return isSucceed; | |||||
} | |||||
@Override | |||||
public List<String> getSkipAuthUrls() throws Exception { | |||||
List<String> skipAuthUrls = sysPermissionMapper.getSkipAuthUrls(); | |||||
return skipAuthUrls; | |||||
} | |||||
} |
package com.xdf.creative.module.service.impl; | |||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||||
import com.xdf.creative.base.service.impl.BaseServiceImpl; | |||||
import com.xdf.creative.enums.StateEnum; | |||||
import com.xdf.creative.module.entity.SysRolePermission; | |||||
import com.xdf.creative.module.mapper.SysRolePermissionMapper; | |||||
import com.xdf.creative.module.service.SysRolePermissionService; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.apache.commons.collections4.SetUtils; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.stereotype.Service; | |||||
import org.springframework.transaction.annotation.Transactional; | |||||
import java.util.ArrayList; | |||||
import java.util.List; | |||||
import java.util.Set; | |||||
/** | |||||
* <pre> | |||||
* 角色权限关系 服务实现类 | |||||
* </pre> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-10-25 | |||||
*/ | |||||
@Slf4j | |||||
@Service | |||||
public class SysRolePermissionServiceImpl extends BaseServiceImpl<SysRolePermissionMapper, SysRolePermission> implements SysRolePermissionService { | |||||
@Autowired | |||||
private SysRolePermissionMapper sysRolePermissionMapper; | |||||
@Transactional(rollbackFor = Exception.class) | |||||
@Override | |||||
public boolean saveSysRolePermission(Long roleId, List<String> permissionIds) throws Exception { | |||||
List<SysRolePermission> list = new ArrayList<>(); | |||||
permissionIds.forEach(permissionId -> { | |||||
SysRolePermission sysRolePermission = new SysRolePermission() | |||||
.setRoleId(roleId) | |||||
.setPermissionId(permissionId) | |||||
.setState(StateEnum.ENABLE.ordinal()); | |||||
list.add(sysRolePermission); | |||||
}); | |||||
// 批量保存角色权限中间表 | |||||
return saveBatch(list, 20); | |||||
} | |||||
@Override | |||||
public List<String> getPermissionIdsByRoleId(Long roleId) throws Exception { | |||||
SysRolePermission sysRolePermission = new SysRolePermission() | |||||
.setRoleId(roleId) | |||||
.setState(StateEnum.ENABLE.ordinal()); | |||||
QueryWrapper queryWrapper = new QueryWrapper(sysRolePermission, "permission_id"); | |||||
return sysRolePermissionMapper.selectObjs(queryWrapper); | |||||
} | |||||
@Override | |||||
public boolean saveSysRolePermissionBatch(Long roleId, SetUtils.SetView addSet) { | |||||
List<SysRolePermission> list = new ArrayList<>(); | |||||
addSet.forEach(id -> { | |||||
SysRolePermission sysRolePermission = new SysRolePermission(); | |||||
String permissionId = (String) id; | |||||
sysRolePermission | |||||
.setRoleId(roleId) | |||||
.setPermissionId(permissionId) | |||||
.setState(StateEnum.ENABLE.ordinal()); | |||||
list.add(sysRolePermission); | |||||
}); | |||||
return saveBatch(list, 20); | |||||
} | |||||
@Override | |||||
public boolean deleteSysRolePermissionByRoleId(Long roleId) throws Exception { | |||||
SysRolePermission sysRolePermission = new SysRolePermission() | |||||
.setRoleId(roleId); | |||||
return remove(new QueryWrapper<>(sysRolePermission)); | |||||
} | |||||
@Override | |||||
public Set<String> getPermissionCodesByRoleId(Long roleId) throws Exception { | |||||
return sysRolePermissionMapper.getPermissionCodesByRoleId(roleId); | |||||
} | |||||
@Override | |||||
public boolean isExistsByPermissionId(String permissionId) throws Exception { | |||||
// 判断角色权限表是否有关联存在,如果存在,则不能删除 | |||||
SysRolePermission sysRolePermission = new SysRolePermission() | |||||
.setPermissionId(permissionId); | |||||
return count(new QueryWrapper(sysRolePermission)) > 0; | |||||
} | |||||
} |
package com.xdf.creative.module.service.impl; | |||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | |||||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||||
import com.xdf.creative.base.params.creative.AddSysRoleParam; | |||||
import com.xdf.creative.base.params.creative.SysRoleQueryParam; | |||||
import com.xdf.creative.base.params.creative.UpdateSysRoleParam; | |||||
import com.xdf.creative.base.service.impl.BaseServiceImpl; | |||||
import com.xdf.creative.base.vo.creative.SysRoleQueryVo; | |||||
import com.xdf.creative.enums.StateEnum; | |||||
import com.xdf.creative.module.entity.SysRole; | |||||
import com.xdf.creative.module.mapper.SysRoleMapper; | |||||
import com.xdf.creative.module.service.SysPermissionService; | |||||
import com.xdf.creative.module.service.SysRolePermissionService; | |||||
import com.xdf.creative.module.service.SysRoleService; | |||||
import com.xdf.creative.module.service.SysUserService; | |||||
import com.xdf.creative.support.exception.BusinessException; | |||||
import com.xdf.creative.support.exception.DaoException; | |||||
import com.xdf.creative.util.convert.SysRoleConvert; | |||||
import com.xdf.creative.util.page.PageTool; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.apache.commons.collections4.SetUtils; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.stereotype.Service; | |||||
import org.springframework.transaction.annotation.Transactional; | |||||
import javax.annotation.Resource; | |||||
import java.io.Serializable; | |||||
import java.util.Date; | |||||
import java.util.HashSet; | |||||
import java.util.List; | |||||
import java.util.Set; | |||||
/** | |||||
* <pre> | |||||
* 系统角色 服务实现类 | |||||
* </pre> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-10-24 | |||||
*/ | |||||
@Slf4j | |||||
@Service | |||||
public class SysRoleServiceImpl extends BaseServiceImpl<SysRoleMapper, SysRole> implements SysRoleService { | |||||
@Autowired | |||||
private SysRoleMapper sysRoleMapper; | |||||
@Resource | |||||
private SysPermissionService sysPermissionService; | |||||
@Resource | |||||
private SysRolePermissionService sysRolePermissionService; | |||||
@Resource | |||||
private SysUserService sysUserService; | |||||
@Transactional(rollbackFor = Exception.class) | |||||
@Override | |||||
public boolean saveSysRole(AddSysRoleParam addSysRoleParam) throws Exception { | |||||
String code = addSysRoleParam.getCode(); | |||||
List<String> permissionIds = addSysRoleParam.getPermissionIds(); | |||||
// 校验角色标识code唯一性 | |||||
if (isExistsByCode(code)) { | |||||
throw new BusinessException("角色编码已存在"); | |||||
} | |||||
// 校验权限列表是否存在 | |||||
if (!sysPermissionService.isExistsByPermissionIds(permissionIds)) { | |||||
throw new BusinessException("权限id不存在"); | |||||
} | |||||
// 保存角色 | |||||
SysRole sysRole = SysRoleConvert.INSTANCE.addSysRoleParamToSysRole(addSysRoleParam); | |||||
boolean saveRoleResult = super.save(sysRole); | |||||
if (!saveRoleResult) { | |||||
throw new DaoException("保存角色失败"); | |||||
} | |||||
// 保存角色权限 | |||||
Long roleId = sysRole.getId(); | |||||
boolean saveRolePermissionResult = sysRolePermissionService.saveSysRolePermission(roleId, permissionIds); | |||||
if (!saveRolePermissionResult) { | |||||
throw new DaoException("保存角色权限失败"); | |||||
} | |||||
return true; | |||||
} | |||||
@Transactional(rollbackFor = Exception.class) | |||||
@Override | |||||
public boolean updateSysRole(UpdateSysRoleParam updateSysRoleParam) throws Exception { | |||||
Long roleId = updateSysRoleParam.getId(); | |||||
List<String> permissionIds = updateSysRoleParam.getPermissionIds(); | |||||
// 校验角色是否存在 | |||||
SysRole sysRole = getById(roleId); | |||||
if (sysRole == null) { | |||||
throw new BusinessException("该角色不存在"); | |||||
} | |||||
// 校验权限列表是否存在 | |||||
if (!sysPermissionService.isExistsByPermissionIds(permissionIds)) { | |||||
throw new BusinessException("权限列表id匹配失败"); | |||||
} | |||||
// 修改角色 | |||||
sysRole.setName(updateSysRoleParam.getName()) | |||||
.setType(updateSysRoleParam.getType()) | |||||
.setRemark(updateSysRoleParam.getRemark()) | |||||
.setState(updateSysRoleParam.getState()) | |||||
.setUpdateTime(new Date()); | |||||
boolean updateResult = updateById(sysRole); | |||||
if (!updateResult) { | |||||
throw new DaoException("修改系统角色失败"); | |||||
} | |||||
// 获取之前的权限id集合 | |||||
List<String> beforeList = sysRolePermissionService.getPermissionIdsByRoleId(roleId); | |||||
// 差集计算 | |||||
// before:1,2,3,4,5,6 | |||||
// after: 1,2,3,4,7,8 | |||||
// 删除5,6 新增7,8 | |||||
// 此处真实删除,去掉deleted字段的@TableLogic注解 | |||||
Set<String> beforeSet = new HashSet<>(beforeList); | |||||
Set<String> afterSet = new HashSet<>(permissionIds); | |||||
SetUtils.SetView deleteSet = SetUtils.difference(beforeSet, afterSet); | |||||
SetUtils.SetView addSet = SetUtils.difference(afterSet, beforeSet); | |||||
log.debug("deleteSet = " + deleteSet); | |||||
log.debug("addSet = " + addSet); | |||||
// 删除权限关联 | |||||
UpdateWrapper updateWrapper = new UpdateWrapper(); | |||||
updateWrapper.eq("role_id", roleId); | |||||
updateWrapper.in("permission_id", deleteSet); | |||||
boolean deleteResult = sysRolePermissionService.remove(updateWrapper); | |||||
if (!deleteResult) { | |||||
throw new DaoException("删除角色权限关系失败"); | |||||
} | |||||
// 新增权限关联 | |||||
boolean addResult = sysRolePermissionService.saveSysRolePermissionBatch(roleId, addSet); | |||||
if (!addResult) { | |||||
throw new DaoException("新增角色权限关系失败"); | |||||
} | |||||
return true; | |||||
} | |||||
@Transactional(rollbackFor = Exception.class) | |||||
@Override | |||||
public boolean deleteSysRole(Long id) throws Exception { | |||||
// 判断该角色下是否有可用用户,如果有,则不能删除 | |||||
boolean isExistsUser = sysUserService.isExistsSysUserByRoleId(id); | |||||
if (isExistsUser) { | |||||
throw new DaoException("该角色下还存在可用用户,不能删除"); | |||||
} | |||||
// 角色逻辑删除 | |||||
boolean deleteRoleResult = removeById(id); | |||||
if (!deleteRoleResult) { | |||||
throw new DaoException("删除角色失败"); | |||||
} | |||||
// 角色权限关系真实删除 | |||||
boolean deletePermissionResult = sysRolePermissionService.deleteSysRolePermissionByRoleId(id); | |||||
if (!deletePermissionResult) { | |||||
throw new DaoException("删除角色权限关系失败"); | |||||
} | |||||
return true; | |||||
} | |||||
@Override | |||||
public SysRoleQueryVo getSysRoleById(Serializable id) throws Exception { | |||||
return sysRoleMapper.getSysRoleById(id); | |||||
} | |||||
@Override | |||||
public PageTool<SysRoleQueryVo> getSysRolePageList(SysRoleQueryParam sysRoleQueryParam) throws Exception { | |||||
Page page = setPageParam(sysRoleQueryParam); | |||||
IPage<SysRoleQueryVo> iPage = sysRoleMapper.getSysRolePageList(page, sysRoleQueryParam); | |||||
return new PageTool(iPage); | |||||
} | |||||
@Override | |||||
public boolean isEnableSysRole(Long id) throws Exception { | |||||
SysRole sysRole = new SysRole() | |||||
.setId(id) | |||||
.setState(StateEnum.ENABLE.ordinal()); | |||||
int count = sysRoleMapper.selectCount(new QueryWrapper<>(sysRole)); | |||||
return count > 0; | |||||
} | |||||
@Override | |||||
public boolean isEnableSysRole(Set<Long> ids) throws Exception { | |||||
for (Long id : ids) { | |||||
SysRole sysRole = new SysRole() | |||||
.setId(id) | |||||
.setState(StateEnum.ENABLE.ordinal()); | |||||
int count = sysRoleMapper.selectCount(new QueryWrapper<>(sysRole)); | |||||
if (count == 0) { | |||||
return false; | |||||
} | |||||
} | |||||
return true; | |||||
} | |||||
@Override | |||||
public boolean isExistsByCode(String code) throws Exception { | |||||
SysRole sysRole = new SysRole().setCode(code); | |||||
return sysRoleMapper.selectCount(new QueryWrapper<>(sysRole)) > 0; | |||||
} | |||||
@Override | |||||
public List<SysRoleQueryVo> getUserRoleByUserId(Long userId) { | |||||
return sysRoleMapper.getUserRoleByUserId(userId); | |||||
} | |||||
} |
package com.xdf.creative.module.service.impl; | |||||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||||
import com.xdf.creative.base.params.creative.SysUserRoleQueryParam; | |||||
import com.xdf.creative.base.service.impl.BaseServiceImpl; | |||||
import com.xdf.creative.base.vo.creative.SysUserRoleQueryVo; | |||||
import com.xdf.creative.module.entity.SysUserRole; | |||||
import com.xdf.creative.module.mapper.SysUserRoleMapper; | |||||
import com.xdf.creative.module.service.SysUserRoleService; | |||||
import com.xdf.creative.util.page.PageTool; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.stereotype.Service; | |||||
import org.springframework.transaction.annotation.Transactional; | |||||
import java.io.Serializable; | |||||
/** | |||||
* <p> | |||||
* 系统用户角色表 服务实现类 | |||||
* </p> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-10-30 | |||||
*/ | |||||
@Slf4j | |||||
@Service | |||||
@Transactional(rollbackFor = Exception.class) | |||||
public class SysUserRoleServiceImpl extends BaseServiceImpl<SysUserRoleMapper, SysUserRole> implements SysUserRoleService { | |||||
@Autowired | |||||
private SysUserRoleMapper sysUserRoleMapper; | |||||
@Override | |||||
public SysUserRoleQueryVo getSysUserRoleById(Serializable id) throws Exception { | |||||
return sysUserRoleMapper.getSysUserRoleById(id); | |||||
} | |||||
@Override | |||||
public PageTool<SysUserRoleQueryVo> getSysUserRolePageList(SysUserRoleQueryParam sysUserRoleQueryParam) throws Exception { | |||||
Page page = setPageParam(sysUserRoleQueryParam); | |||||
IPage<SysUserRoleQueryVo> iPage = sysUserRoleMapper.getSysUserRolePageList(page, sysUserRoleQueryParam); | |||||
return new PageTool(iPage); | |||||
} | |||||
} |
package com.xdf.creative.module.service.impl; | |||||
import com.alibaba.fastjson.JSON; | |||||
import com.alibaba.fastjson.JSONObject; | |||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||||
import com.xdf.creative.base.params.creative.IsEnableSysOrganizeParam; | |||||
import com.xdf.creative.base.params.creative.SysUserQueryParam; | |||||
import com.xdf.creative.base.params.creative.UpdatePasswordParam; | |||||
import com.xdf.creative.base.params.creative.UpdateUserParam; | |||||
import com.xdf.creative.base.service.impl.BaseServiceImpl; | |||||
import com.xdf.creative.base.vo.creative.SysOrganizeQueryVo; | |||||
import com.xdf.creative.base.vo.creative.SysRoleQueryVo; | |||||
import com.xdf.creative.base.vo.creative.SysUserQueryVo; | |||||
import com.xdf.creative.enums.ApiCode; | |||||
import com.xdf.creative.enums.StateEnum; | |||||
import com.xdf.creative.module.entity.SysUser; | |||||
import com.xdf.creative.module.entity.SysUserRole; | |||||
import com.xdf.creative.module.mapper.SysUserMapper; | |||||
import com.xdf.creative.module.service.SysOrganizeService; | |||||
import com.xdf.creative.module.service.SysRoleService; | |||||
import com.xdf.creative.module.service.SysUserRoleService; | |||||
import com.xdf.creative.module.service.SysUserService; | |||||
import com.xdf.creative.shiro.jwt.JwtProperties; | |||||
import com.xdf.creative.shiro.jwt.JwtToken; | |||||
import com.xdf.creative.shiro.jwt.JwtUtil; | |||||
import com.xdf.creative.shiro.jwt.SaltUtil; | |||||
import com.xdf.creative.support.auth.LoginParam; | |||||
import com.xdf.creative.support.auth.LoginSysUserTokenVo; | |||||
import com.xdf.creative.support.auth.LoginSysUserVo; | |||||
import com.xdf.creative.support.exception.BusinessException; | |||||
import com.xdf.creative.support.exception.SysLoginException; | |||||
import com.xdf.creative.util.PasswordUtil; | |||||
import com.xdf.creative.util.StringUtil; | |||||
import com.xdf.creative.util.UUIDUtil; | |||||
import com.xdf.creative.util.convert.SysUserConvert; | |||||
import com.xdf.creative.util.page.PageTool; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import cn.hutool.core.collection.CollectionUtil; | |||||
import org.apache.shiro.SecurityUtils; | |||||
import org.apache.shiro.authc.UsernamePasswordToken; | |||||
import org.apache.shiro.subject.Subject; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.context.annotation.Lazy; | |||||
import org.springframework.stereotype.Service; | |||||
import org.springframework.transaction.annotation.Transactional; | |||||
import java.io.Serializable; | |||||
import java.time.Duration; | |||||
import java.util.*; | |||||
/** | |||||
* <pre> | |||||
* 系统用户 服务实现类 | |||||
* </pre> | |||||
* | |||||
* @author DeanYe | |||||
* @since 2019-10-24 | |||||
*/ | |||||
@Slf4j | |||||
@Service | |||||
public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser> implements SysUserService { | |||||
@Autowired | |||||
private SysUserMapper sysUserMapper; | |||||
@Lazy | |||||
@Autowired | |||||
private SysRoleService sysRoleService; | |||||
@Lazy | |||||
@Autowired | |||||
private SysOrganizeService sysOrganizeService; | |||||
@Lazy | |||||
@Autowired | |||||
private SysUserRoleService sysUserRoleService; | |||||
@Autowired | |||||
private JwtProperties jwtProperties; | |||||
@Override | |||||
public LoginSysUserTokenVo login(LoginParam loginParam) throws Exception { | |||||
// 校验验证码 | |||||
String userName = loginParam.getUsername(); | |||||
SysUser sysUser = getSysUserByUserName(userName); | |||||
if (sysUser == null) { | |||||
log.error("登陆失败,用户名不正确,loginParam:{}", loginParam); | |||||
throw new SysLoginException(ApiCode.USERNAME_ERROR); | |||||
} | |||||
if (StateEnum.DISABLE.getKey().equals(sysUser.getState())) { | |||||
log.debug("登陆失败,用户不可用,loginParam:{}", loginParam); | |||||
throw new SysLoginException(ApiCode.USER_DISABLE); | |||||
} | |||||
String encryptPassword = PasswordUtil.encrypt(loginParam.getPassword(), sysUser.getSalt()); | |||||
if (!encryptPassword.equals(sysUser.getPassword())) { | |||||
throw new SysLoginException(ApiCode.PASSWORD_ERROR); | |||||
} | |||||
SysOrganizeQueryVo sysOrganizeQueryVo = sysOrganizeService.getSysOrganizeById(sysUser.getOrganizeId()); | |||||
if (sysOrganizeQueryVo == null) { | |||||
throw new BusinessException("组织不存在"); | |||||
} | |||||
if (!StateEnum.ENABLE.getKey().equals(sysOrganizeQueryVo.getState())) { | |||||
throw new BusinessException("组织已禁用"); | |||||
} | |||||
// 将系统用户对象转换成登陆用户对象 | |||||
LoginSysUserVo loginSysUserVo = SysUserConvert.INSTANCE.sysUserToLoginSysUserVo(sysUser); | |||||
loginSysUserVo.setOrganizeId(sysOrganizeQueryVo.getId()); | |||||
//获取角色id、名称、code | |||||
HashSet<Long> roleIdSet = new HashSet<>(); | |||||
HashSet<String> roleNameSet = new HashSet<>(); | |||||
HashSet<String> roleCodeSet = new HashSet<>(); | |||||
List<SysRoleQueryVo> sysRoleQueryVoList = sysRoleService.getUserRoleByUserId(sysUser.getId()); | |||||
if (CollectionUtil.isEmpty(sysRoleQueryVoList)) { | |||||
throw new BusinessException("角色不存在"); | |||||
} | |||||
sysRoleQueryVoList.stream().forEach(sysRoleQueryVo -> { | |||||
roleIdSet.add(sysRoleQueryVo.getId()); | |||||
roleNameSet.add(sysRoleQueryVo.getName()); | |||||
roleCodeSet.add(sysRoleQueryVo.getCode()); | |||||
}); | |||||
loginSysUserVo.setRoleId(roleIdSet) | |||||
.setRoleName(roleNameSet) | |||||
.setRoleCode(roleCodeSet); | |||||
//获取角色url | |||||
// 获取数据库中保存的盐值 | |||||
String newSalt = SaltUtil.getSalt(sysUser.getSalt(), jwtProperties); | |||||
// 生成token字符串并返回 | |||||
Long expireSecond = jwtProperties.getExpireSecond(); | |||||
String token = JwtUtil.generateToken(sysUser.getId(), userName, sysUser.getOrganizeId(),sysUser.getUserType(), newSalt, Duration.ofSeconds(expireSecond)); | |||||
log.debug("token:{}", token); | |||||
// 创建AuthenticationToken | |||||
JwtToken jwtToken = JwtToken.build(token, sysUser.getId(), userName, sysUser.getOrganizeId(),sysUser.getUserType(), newSalt, expireSecond); | |||||
Subject subject = SecurityUtils.getSubject(); | |||||
UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken( | |||||
loginParam.getUsername(), | |||||
loginParam.getPassword()); | |||||
//进行验证,这里可以捕获异常,然后返回对应信息 | |||||
subject.login(usernamePasswordToken); | |||||
// 返回token和登陆用户信息对象 | |||||
LoginSysUserTokenVo loginSysUserTokenVo = new LoginSysUserTokenVo(); | |||||
loginSysUserTokenVo.setToken("12wer234f345g34g45"); | |||||
loginSysUserTokenVo.setLoginSysUserVo(loginSysUserVo); | |||||
return loginSysUserTokenVo; | |||||
} | |||||
@Transactional(rollbackFor = Exception.class) | |||||
@Override | |||||
public boolean saveSysUser(SysUser sysUser) throws Exception { | |||||
// 校验用户名是否存在 | |||||
boolean isExists = isExistsByUsername(sysUser.getUsername()); | |||||
if (isExists) { | |||||
throw new BusinessException("用户名已存在"); | |||||
} | |||||
// 校验组织和角色 | |||||
checkOrganizeAndRole(sysUser.getOrganizeId(), sysUser.getRoleId()); | |||||
// Long userId = getUserId();//获取当前用户id | |||||
// 生成盐值 | |||||
String salt = UUIDUtil.getUUID(); | |||||
sysUser.setSalt(salt); | |||||
sysUser.setId(null); | |||||
//sysUser.setCreateUserId(userId); | |||||
// 密码加密 | |||||
String newPassword = PasswordUtil.encrypt(sysUser.getPassword(), salt); | |||||
sysUser.setPassword(newPassword); | |||||
// 保存系统用户 | |||||
return super.save(sysUser); | |||||
} | |||||
@Transactional(rollbackFor = Exception.class) | |||||
@Override | |||||
public boolean updateSysUser(UpdateUserParam updateUserParam) throws Exception { | |||||
// 获取系统用户 | |||||
SysUser updateSysUser = getById(updateUserParam.getId()); | |||||
if (updateSysUser == null) { | |||||
throw new BusinessException("修改的用户不存在"); | |||||
} | |||||
// 校验组织和角色 | |||||
checkOrganizeAndRole(updateUserParam.getOrganizeId(), updateUserParam.getRoleId()); | |||||
//String jsonStr = (String) redisTemplate.opsForValue().get(String.format(CommonRedisKey.LOGIN_USER, updateSysUser.getUsername())); | |||||
//LoginSysUserRedisVo loginSysUserRedisVo = JSONObject.parseObject(jsonStr, LoginSysUserRedisVo.class); | |||||
//权限修改 | |||||
Set<Long> roleIds = updateUserParam.getRoleId(); | |||||
if (1==1){//CollectionUtil.isNotEmpty(roleIds)) { | |||||
QueryWrapper<SysUserRole> queryWrapper = new QueryWrapper(); | |||||
queryWrapper.eq("user_id", updateUserParam.getId()); | |||||
sysUserRoleService.remove(queryWrapper); | |||||
List<SysUserRole> sysUserRoles = new ArrayList<>(); | |||||
for (Long roleId : roleIds) { | |||||
SysUserRole sysUserRole = new SysUserRole(); | |||||
sysUserRole.setRoleId(roleId); | |||||
sysUserRole.setUserId(updateUserParam.getId()); | |||||
sysUserRoles.add(sysUserRole); | |||||
} | |||||
//sysUserRoleService.saveBatch(sysUserRoles); | |||||
Set<Long> roleSet = new HashSet<>(); | |||||
Set<String> roleNameSet = new HashSet<>(); | |||||
List<SysRoleQueryVo> sysRoleQueryVos = sysRoleService.getUserRoleByUserId(null);//getUserId()); | |||||
sysRoleQueryVos.stream().forEach(sysRoleQueryVo -> { | |||||
roleSet.add(sysRoleQueryVo.getId()); | |||||
roleNameSet.add(sysRoleQueryVo.getName()); | |||||
}); | |||||
// loginSysUserRedisVo.setRoleId(roleSet); | |||||
// loginSysUserRedisVo.setRoleName(roleNameSet); | |||||
} | |||||
// 修改系统用户 | |||||
updateSysUser.setNickname(updateUserParam.getNickname()) | |||||
.setPhone(updateUserParam.getPhone()) | |||||
.setGender(updateUserParam.getGender()) | |||||
.setRemark(updateUserParam.getRemark()) | |||||
.setState(updateUserParam.getState()) | |||||
.setOrganizeId(updateUserParam.getOrganizeId()) | |||||
.setUpdateTime(new Date()); | |||||
super.updateById(updateSysUser); | |||||
// if (StringUtil.isNotEmpty(updateUserParam.getNickname())) { | |||||
// loginSysUserRedisVo.setNickname(updateUserParam.getNickname()); | |||||
// } | |||||
// if (StringUtil.isNotEmpty(updateUserParam.getPhone())) { | |||||
// loginSysUserRedisVo.setPhone(updateUserParam.getPhone()); | |||||
// } | |||||
// if (updateUserParam.getGender() != null) { | |||||
// loginSysUserRedisVo.setGender(updateUserParam.getGender()); | |||||
// } | |||||
// if (updateUserParam.getState() != null) { | |||||
// loginSysUserRedisVo.setState(updateUserParam.getState()); | |||||
// } | |||||
// if (StringUtil.longIsNotEmpty(updateUserParam.getOrganizeId())) { | |||||
// loginSysUserRedisVo.setOrgId(updateUserParam.getOrganizeId()); | |||||
// } | |||||
// | |||||
// | |||||
// Long expireDuration = redisTemplate.getExpire(String.format(CommonRedisKey.LOGIN_USER, updateSysUser.getUsername())); | |||||
// redisTemplate.delete(String.format(CommonRedisKey.LOGIN_USER, updateSysUser.getUsername())); | |||||
// String key = String.format(CommonRedisKey.LOGIN_USER, updateSysUser.getUsername()); | |||||
// String val = JSON.toJSONString(loginSysUserRedisVo); | |||||
// redisUtil.set(key, val, expireDuration); | |||||
return true; | |||||
} | |||||
@Transactional(rollbackFor = Exception.class) | |||||
@Override | |||||
public boolean deleteSysUser(Long id) throws Exception { | |||||
return super.removeById(id); | |||||
} | |||||
@Override | |||||
public SysUserQueryVo getSysUserById(Serializable id) throws Exception { | |||||
return sysUserMapper.getSysUserById(id); | |||||
} | |||||
@Override | |||||
public PageTool<SysUserQueryVo> getSysUserPageList(SysUserQueryParam sysUserQueryParam) throws Exception { | |||||
Page page = setPageParam(sysUserQueryParam); | |||||
IPage<SysUserQueryVo> iPage = sysUserMapper.getSysUserPageList(page, sysUserQueryParam); | |||||
return new PageTool(iPage); | |||||
} | |||||
@Override | |||||
public boolean isExistsByUsername(String username) throws Exception { | |||||
SysUser selectSysUser = new SysUser().setUsername(username); | |||||
return sysUserMapper.selectCount(new QueryWrapper<>(selectSysUser)) > 0; | |||||
} | |||||
@Override | |||||
public void checkOrganizeAndRole(Long organizeId, Set<Long> roleId) throws Exception { | |||||
// 校验组织是否存在并且可用 | |||||
if (StringUtil.longIsNotEmpty(organizeId)) { | |||||
boolean isEnableSysOrganize = sysOrganizeService.isEnableSysOrganize(new IsEnableSysOrganizeParam(null, organizeId));//getUserId(), organizeId)); | |||||
if (!isEnableSysOrganize) { | |||||
throw new BusinessException("该组织不存在或已禁用"); | |||||
} | |||||
} | |||||
// 校验角色是否存在并且可用 | |||||
if (1==1){//CollectionUtil.isNotEmpty(roleId)) { | |||||
boolean isEnable = sysRoleService.isEnableSysRole(roleId); | |||||
if (!isEnable) { | |||||
throw new BusinessException("该角色不存在或已禁用"); | |||||
} | |||||
} | |||||
} | |||||
@Override | |||||
public boolean isExistsSysUserByRoleId(Long roleId) throws Exception { | |||||
SysUser sysUser = new SysUser() | |||||
.setState(StateEnum.ENABLE.ordinal()); | |||||
return sysUserMapper.selectCount(new QueryWrapper(sysUser)) > 0; | |||||
} | |||||
@Override | |||||
public boolean updatePassword(UpdatePasswordParam updatePasswordParam) throws Exception { | |||||
String oldPassword = updatePasswordParam.getOldPassword(); | |||||
String newPassword = updatePasswordParam.getNewPassword(); | |||||
String confirmPassword = updatePasswordParam.getConfirmPassword(); | |||||
if (!newPassword.equals(confirmPassword)) { | |||||
throw new BusinessException("两次输入的密码不一致"); | |||||
} | |||||
if (newPassword.equals(oldPassword)) { | |||||
throw new BusinessException("新密码和旧密码不能一致"); | |||||
} | |||||
// 判断原密码是否正确 | |||||
SysUser sysUser = null;//getById(updatePasswordParam.getUserId()); | |||||
if (sysUser == null) { | |||||
throw new BusinessException("用户不存在"); | |||||
} | |||||
if (StateEnum.DISABLE.getKey().equals(sysUser.getState())) { | |||||
throw new BusinessException("用户已禁用"); | |||||
} | |||||
// 密码加密处理 | |||||
String salt = sysUser.getSalt(); | |||||
String encryptOldPassword = PasswordUtil.encrypt(oldPassword, salt); | |||||
if (!sysUser.getPassword().equals(encryptOldPassword)) { | |||||
throw new BusinessException("原密码错误"); | |||||
} | |||||
// 新密码加密 | |||||
String encryptNewPassword = PasswordUtil.encrypt(newPassword, salt); | |||||
// 修改密码 | |||||
sysUser.setPassword(encryptNewPassword) | |||||
.setUpdateTime(new Date()); | |||||
return updateById(sysUser); | |||||
} | |||||
@Override | |||||
public boolean updateSysUserHead(Long id, String headPath) throws Exception { | |||||
SysUser sysUser = new SysUser() | |||||
.setId(id) | |||||
.setHead(headPath); | |||||
return updateById(sysUser); | |||||
} | |||||
@Override | |||||
public SysUser getSysUserByUserName(String username) throws Exception { | |||||
return sysUserMapper.getSysUserByUserName(username); | |||||
} | |||||
} |
package com.xdf.creative.shiro; | |||||
import cn.hutool.core.collection.CollectionUtil; | |||||
import com.xdf.creative.base.vo.creative.SysRoleQueryVo; | |||||
import com.xdf.creative.module.entity.SysUser; | |||||
import com.xdf.creative.module.service.SysRoleService; | |||||
import com.xdf.creative.module.service.SysUserService; | |||||
import com.xdf.creative.support.exception.BusinessException; | |||||
import org.apache.shiro.authc.*; | |||||
import org.apache.shiro.authz.AuthorizationInfo; | |||||
import org.apache.shiro.authz.SimpleAuthorizationInfo; | |||||
import org.apache.shiro.realm.AuthorizingRealm; | |||||
import org.apache.shiro.subject.PrincipalCollection; | |||||
import org.slf4j.Logger; | |||||
import org.slf4j.LoggerFactory; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import java.util.HashSet; | |||||
import java.util.List; | |||||
public class CustomRealm extends AuthorizingRealm { | |||||
private final static Logger log = LoggerFactory.getLogger(AuthorizingRealm.class); | |||||
@Autowired | |||||
private SysUserService sysUserService; | |||||
@Autowired | |||||
private SysRoleService sysRoleService; | |||||
@Override | |||||
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) { | |||||
//获取登录用户名 | |||||
String name = (String) principalCollection.getPrimaryPrincipal(); | |||||
//根据用户名去数据库查询用户信息 | |||||
SysUser user = null; | |||||
try { | |||||
user = sysUserService.getSysUserByUserName(name); | |||||
if(null==user){ | |||||
return null; | |||||
} | |||||
} catch (Exception e) { | |||||
throw new BusinessException("用户不存在"); | |||||
} | |||||
//添加角色和权限 | |||||
SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo(); | |||||
HashSet<Long> roleIdSet = new HashSet<>(); | |||||
HashSet<String> roleNameSet = new HashSet<>(); | |||||
HashSet<String> roleCodeSet = new HashSet<>(); | |||||
List<SysRoleQueryVo> sysRoleQueryVoList = sysRoleService.getUserRoleByUserId(user.getId()); | |||||
if (CollectionUtil.isEmpty(sysRoleQueryVoList)) { | |||||
throw new BusinessException("角色不存在"); | |||||
} | |||||
sysRoleQueryVoList.stream().forEach(sysRoleQueryVo -> { | |||||
roleIdSet.add(sysRoleQueryVo.getId()); | |||||
roleNameSet.add(sysRoleQueryVo.getName()); | |||||
roleCodeSet.add(sysRoleQueryVo.getCode()); | |||||
}); | |||||
simpleAuthorizationInfo.setRoles(roleCodeSet); | |||||
// simpleAuthorizationInfo.addStringPermission(permissions.getPermissionsName()); | |||||
return simpleAuthorizationInfo; | |||||
} | |||||
@Override | |||||
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException { | |||||
//加这一步的目的是在Post请求的时候会先进认证,然后在到请求 | |||||
if (authenticationToken.getPrincipal() == null) { | |||||
return null; | |||||
} | |||||
UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken) authenticationToken; | |||||
//根据用户名去数据库查询用户信息 | |||||
SysUser user = null; | |||||
//获取用户信息 | |||||
String name =usernamePasswordToken.getUsername(); | |||||
try { | |||||
user = sysUserService.getSysUserByUserName(name); | |||||
} catch (Exception e) { | |||||
log.error("用户 { "+name+" } 不存在 "); | |||||
throw new AccountException("账户不存在"); | |||||
} | |||||
if (user == null) { | |||||
//这里返回后会报出对应异常 | |||||
throw new BusinessException("用户不存在"); | |||||
} else { | |||||
//这里验证authenticationToken和simpleAuthenticationInfo的信息 | |||||
SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo(user, usernamePasswordToken.getPassword().toString(), getName()); | |||||
return simpleAuthenticationInfo; | |||||
} | |||||
} | |||||
} | |||||
package com.xdf.creative.shiro; | |||||
import com.xdf.creative.enums.ApiCode; | |||||
import com.xdf.creative.util.page.ApiResult; | |||||
import org.apache.shiro.authz.UnauthorizedException; | |||||
import org.springframework.web.bind.annotation.ControllerAdvice; | |||||
import org.springframework.web.bind.annotation.ExceptionHandler; | |||||
import javax.servlet.http.HttpServletRequest; | |||||
/** | |||||
* @author : lgw | |||||
* @date : 16:51 2020/3/3 | |||||
*/ | |||||
@ControllerAdvice | |||||
public class GlobalExceptionHandler { | |||||
@ExceptionHandler(value = UnauthorizedException.class) | |||||
public ApiResult jsonExceptionHandler(HttpServletRequest req, Exception e) { | |||||
return ApiResult.fail(ApiCode.FAIL, "权限不足!"); | |||||
} | |||||
// @ExceptionHandler(value = UnauthorizedException.class) | |||||
// public ModelAndView businessExceptionHandler(){ | |||||
// ModelAndView mav = new ModelAndView(); | |||||
// mav.setStatus(HttpStatus.UNAUTHORIZED); | |||||
// mav.addObject("message", e.getMessage()); | |||||
// mav.setViewName("403"); | |||||
// return mav; | |||||
// } | |||||
} | |||||
package com.xdf.creative.shiro; | |||||
/** | |||||
* @author : lgw | |||||
* @date : 15:58 2020/3/3 | |||||
*/ | |||||
import org.apache.shiro.SecurityUtils; | |||||
import org.apache.shiro.mgt.DefaultSessionStorageEvaluator; | |||||
import org.apache.shiro.mgt.DefaultSubjectDAO; | |||||
import org.apache.shiro.mgt.SecurityManager; | |||||
import org.apache.shiro.spring.LifecycleBeanPostProcessor; | |||||
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor; | |||||
import org.apache.shiro.spring.web.ShiroFilterFactoryBean; | |||||
import org.apache.shiro.web.mgt.DefaultWebSecurityManager; | |||||
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator; | |||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | |||||
import org.springframework.context.annotation.Bean; | |||||
import org.springframework.context.annotation.Configuration; | |||||
import org.springframework.context.annotation.DependsOn; | |||||
import java.util.HashMap; | |||||
import java.util.Map; | |||||
@Configuration | |||||
public class ShiroConfig { | |||||
//不加这个注解不生效,具体不详 | |||||
@Bean | |||||
@ConditionalOnMissingBean | |||||
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() { | |||||
DefaultAdvisorAutoProxyCreator defaultAAP = new DefaultAdvisorAutoProxyCreator(); | |||||
defaultAAP.setProxyTargetClass(true); | |||||
return defaultAAP; | |||||
} | |||||
//将自己的验证方式加入容器 | |||||
@Bean | |||||
public CustomRealm myShiroRealm() { | |||||
CustomRealm customRealm = new CustomRealm(); | |||||
return customRealm; | |||||
} | |||||
//权限管理,配置主要是Realm的管理认证 | |||||
@Bean | |||||
public SecurityManager securityManager() { | |||||
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager(); | |||||
securityManager.setRealm(myShiroRealm()); | |||||
// 无状态subjectFactory设置 | |||||
DefaultSessionStorageEvaluator evaluator = (DefaultSessionStorageEvaluator)((DefaultSubjectDAO) securityManager.getSubjectDAO()).getSessionStorageEvaluator(); | |||||
evaluator.setSessionStorageEnabled(Boolean.FALSE); | |||||
StatelessWebSubjectFactory subjectFactory = new StatelessWebSubjectFactory(); | |||||
securityManager.setSubjectFactory(subjectFactory); | |||||
SecurityUtils.setSecurityManager(securityManager); | |||||
return securityManager; | |||||
} | |||||
//Filter工厂,设置对应的过滤条件和跳转条件 | |||||
@Bean | |||||
public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager) { | |||||
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); | |||||
shiroFilterFactoryBean.setSecurityManager(securityManager); | |||||
Map<String, String> map = new HashMap<>(); | |||||
//登出 | |||||
map.put("/logout", "logout"); | |||||
//对所有用户认证 | |||||
map.put("/**", "authc"); | |||||
//登录 | |||||
shiroFilterFactoryBean.setLoginUrl("/sysUser/login"); | |||||
//首页 | |||||
shiroFilterFactoryBean.setSuccessUrl("/index"); | |||||
//错误页面,认证不通过跳转 | |||||
shiroFilterFactoryBean.setUnauthorizedUrl("/error"); | |||||
shiroFilterFactoryBean.setFilterChainDefinitionMap(map); | |||||
return shiroFilterFactoryBean; | |||||
} | |||||
/** | |||||
* 开启Shiro的注解(如@RequiresRoles,@RequiresPermissions),需借助SpringAOP扫描使用Shiro注解的类,并在必要时进行安全逻辑验证 | |||||
* 配置以下两个bean(DefaultAdvisorAutoProxyCreator(可选)和AuthorizationAttributeSourceAdvisor)即可实现此功能 | |||||
* | |||||
* @return | |||||
*/ | |||||
@Bean | |||||
@DependsOn({"lifecycleBeanPostProcessor"}) | |||||
public DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator() { | |||||
DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator(); | |||||
advisorAutoProxyCreator.setProxyTargetClass(true); | |||||
return advisorAutoProxyCreator; | |||||
} | |||||
@Bean(name="lifecycleBeanPostProcessor") | |||||
public static LifecycleBeanPostProcessor getLifecycleBeanPostProcessor() { | |||||
return new LifecycleBeanPostProcessor(); | |||||
} | |||||
//加入注解的使用,不加入这个注解不生效 | |||||
@Bean | |||||
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) { | |||||
AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor(); | |||||
authorizationAttributeSourceAdvisor.setSecurityManager(securityManager); | |||||
return authorizationAttributeSourceAdvisor; | |||||
} | |||||
} |
package com.xdf.creative.shiro; | |||||
import org.apache.shiro.subject.Subject; | |||||
import org.apache.shiro.subject.SubjectContext; | |||||
import org.apache.shiro.web.mgt.DefaultWebSubjectFactory; | |||||
/** | |||||
* 对于无状态的TOKEN不创建session 这里都不使用session | |||||
* @author tomsun28 | |||||
* @date 21:52 2018/3/3 | |||||
*/ | |||||
public class StatelessWebSubjectFactory extends DefaultWebSubjectFactory { | |||||
@Override | |||||
public Subject createSubject(SubjectContext context) { | |||||
// 这里都不创建session | |||||
context.setSessionCreationEnabled(Boolean.FALSE); | |||||
return super.createSubject(context); | |||||
} | |||||
public StatelessWebSubjectFactory() {} | |||||
} |
/* | |||||
package com.xdf.creative.shiro.filter; | |||||
import com.usthe.bootshiro.service.AccountService; | |||||
import com.usthe.bootshiro.shiro.config.RestPathMatchingFilterChainResolver; | |||||
import com.usthe.bootshiro.shiro.provider.ShiroFilterRulesProvider; | |||||
import com.usthe.bootshiro.shiro.rule.RolePermRule; | |||||
import com.usthe.bootshiro.support.SpringContextHolder; | |||||
import org.apache.shiro.spring.web.ShiroFilterFactoryBean; | |||||
import org.apache.shiro.web.filter.mgt.DefaultFilterChainManager; | |||||
import org.apache.shiro.web.servlet.AbstractShiroFilter; | |||||
import org.slf4j.Logger; | |||||
import org.slf4j.LoggerFactory; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.beans.factory.annotation.Value; | |||||
import org.springframework.data.redis.core.StringRedisTemplate; | |||||
import org.springframework.stereotype.Component; | |||||
import javax.servlet.Filter; | |||||
import java.util.Arrays; | |||||
import java.util.LinkedHashMap; | |||||
import java.util.List; | |||||
import java.util.Map; | |||||
*/ | |||||
/** | |||||
* Filter 管理器 | |||||
* @author tomsun28 | |||||
* @date 11:16 2018/2/28 | |||||
*//* | |||||
@Component | |||||
public class ShiroFilterChainManager { | |||||
private static final Logger LOGGER = LoggerFactory.getLogger(ShiroFilterChainManager.class); | |||||
private final ShiroFilterRulesProvider shiroFilterRulesProvider; | |||||
private final StringRedisTemplate redisTemplate; | |||||
private final AccountService accountService; | |||||
@Value("${bootshiro.enableEncryptPassword}") | |||||
private boolean isEncryptPassword; | |||||
@Autowired | |||||
public ShiroFilterChainManager(ShiroFilterRulesProvider shiroFilterRulesProvider, StringRedisTemplate redisTemplate, AccountService accountService){ | |||||
this.shiroFilterRulesProvider = shiroFilterRulesProvider; | |||||
this.redisTemplate = redisTemplate; | |||||
this.accountService = accountService; | |||||
} | |||||
*/ | |||||
/** | |||||
* description 初始化获取过滤链 | |||||
* | |||||
* @return java.util.Map<java.lang.String,javax.servlet.Filter> | |||||
*//* | |||||
public Map<String,Filter> initGetFilters() { | |||||
Map<String,Filter> filters = new LinkedHashMap<>(); | |||||
PasswordFilter passwordFilter = new PasswordFilter(); | |||||
passwordFilter.setRedisTemplate(redisTemplate); | |||||
passwordFilter.setEncryptPassword(isEncryptPassword); | |||||
filters.put("auth",passwordFilter); | |||||
BonJwtFilter jwtFilter = new BonJwtFilter(); | |||||
jwtFilter.setRedisTemplate(redisTemplate); | |||||
jwtFilter.setAccountService(accountService); | |||||
filters.put("jwt",jwtFilter); | |||||
return filters; | |||||
} | |||||
*/ | |||||
/** | |||||
* description 初始化获取过滤链规则 | |||||
* | |||||
* @return java.util.Map<java.lang.String,java.lang.String> | |||||
*//* | |||||
public Map<String,String> initGetFilterChain() { | |||||
Map<String,String> filterChain = new LinkedHashMap<>(); | |||||
// -------------anon 默认过滤器忽略的URL | |||||
List<String> defalutAnon = Arrays.asList("/css/**","/js/**"); | |||||
defalutAnon.forEach(ignored -> filterChain.put(ignored,"anon")); | |||||
// -------------auth 默认需要认证过滤器的URL 走auth--PasswordFilter | |||||
List<String> defalutAuth = Arrays.asList("/account/**"); | |||||
defalutAuth.forEach(auth -> filterChain.put(auth,"auth")); | |||||
// -------------dynamic 动态URL | |||||
if (shiroFilterRulesProvider != null) { | |||||
List<RolePermRule> rolePermRules = this.shiroFilterRulesProvider.loadRolePermRules(); | |||||
if (null != rolePermRules) { | |||||
rolePermRules.forEach(rule -> { | |||||
StringBuilder chain = rule.toFilterChain(); | |||||
if (null != chain) { | |||||
filterChain.putIfAbsent(rule.getUrl(),chain.toString()); | |||||
} | |||||
}); | |||||
} | |||||
} | |||||
return filterChain; | |||||
} | |||||
*/ | |||||
/** | |||||
* description 动态重新加载过滤链规则 | |||||
*//* | |||||
public void reloadFilterChain() { | |||||
ShiroFilterFactoryBean shiroFilterFactoryBean = SpringContextHolder.getBean(ShiroFilterFactoryBean.class); | |||||
AbstractShiroFilter abstractShiroFilter = null; | |||||
try { | |||||
abstractShiroFilter = (AbstractShiroFilter)shiroFilterFactoryBean.getObject(); | |||||
RestPathMatchingFilterChainResolver filterChainResolver = (RestPathMatchingFilterChainResolver)abstractShiroFilter.getFilterChainResolver(); | |||||
DefaultFilterChainManager filterChainManager = (DefaultFilterChainManager)filterChainResolver.getFilterChainManager(); | |||||
filterChainManager.getFilterChains().clear(); | |||||
shiroFilterFactoryBean.getFilterChainDefinitionMap().clear(); | |||||
shiroFilterFactoryBean.setFilterChainDefinitionMap(this.initGetFilterChain()); | |||||
shiroFilterFactoryBean.getFilterChainDefinitionMap().forEach((k,v) -> filterChainManager.createChain(k,v)); | |||||
} catch (Exception e) { | |||||
LOGGER.error(e.getMessage(),e); | |||||
} | |||||
} | |||||
} | |||||
*/ |
package com.xdf.creative.shiro.jwt; | |||||
import lombok.Data; | |||||
import org.springframework.boot.context.properties.ConfigurationProperties; | |||||
import org.springframework.core.annotation.Order; | |||||
import org.springframework.stereotype.Component; | |||||
/** | |||||
* JWT属性配置 | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-05-22 | |||||
**/ | |||||
@Data | |||||
@Component | |||||
@Order(-1) | |||||
@ConfigurationProperties(prefix = "spring-boot-plus.jwt") | |||||
public class JwtProperties { | |||||
/** | |||||
* token名称,默认名称为:token,可自定义 | |||||
*/ | |||||
private String tokenName; | |||||
/** | |||||
* 密码 | |||||
*/ | |||||
private String secret; | |||||
/** | |||||
* 签发人 | |||||
*/ | |||||
private String issuer; | |||||
/** | |||||
* 主题 | |||||
*/ | |||||
private String subject; | |||||
/** | |||||
* 签发的目标 | |||||
*/ | |||||
private String audience; | |||||
/** | |||||
* token失效时间,默认1小时,60*60=3600 | |||||
*/ | |||||
private Long expireSecond; | |||||
/** | |||||
* 是否刷新token,默认为true | |||||
*/ | |||||
private boolean refreshToken = true; | |||||
/** | |||||
* 刷新token倒计时,默认10分钟,10*60=600 | |||||
*/ | |||||
private Integer refreshTokenCountdown; | |||||
/** | |||||
* redis校验jwt token是否存在 | |||||
*/ | |||||
private boolean redisCheck; | |||||
/** | |||||
* 单用户登陆,一个用户只能又一个有效的token | |||||
*/ | |||||
private boolean singleLogin; | |||||
/** | |||||
* 是否进行盐值校验 | |||||
*/ | |||||
private boolean saltCheck; | |||||
/** | |||||
* 刷新tokenName | |||||
*/ | |||||
private String refreshTokenName; | |||||
} |
package com.xdf.creative.shiro.jwt; | |||||
import com.auth0.jwt.interfaces.DecodedJWT; | |||||
import com.xdf.creative.util.IpUtil; | |||||
import lombok.Data; | |||||
import lombok.experimental.Accessors; | |||||
import java.util.Date; | |||||
/** | |||||
* Shiro JwtToken对象 | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-09-27 | |||||
* @since 1.3.0.RELEASE | |||||
**/ | |||||
@Data | |||||
@Accessors(chain = true) | |||||
public class JwtToken { | |||||
private Long userId; | |||||
/** | |||||
* 登陆ip | |||||
*/ | |||||
private String host; | |||||
/** | |||||
* 登陆用户名称 | |||||
*/ | |||||
private String username; | |||||
/*** | |||||
* 组织id | |||||
*/ | |||||
private Long organizeId; | |||||
/*** | |||||
* 组织类型 0 普通用户 1、园区用户 2 区文创办 3市文创办 8后台管理 | |||||
*/ | |||||
private Integer organizeType; | |||||
/** | |||||
* 辖区id | |||||
*/ | |||||
private String regionId; | |||||
/** | |||||
* 登陆盐值 | |||||
*/ | |||||
private String salt; | |||||
/** | |||||
* 登陆token | |||||
*/ | |||||
private String token; | |||||
/** | |||||
* 创建时间 | |||||
*/ | |||||
private Date createDate; | |||||
/** | |||||
* 多长时间过期,默认一小时 | |||||
*/ | |||||
private long expireSecond; | |||||
/** | |||||
* 过期日期 | |||||
*/ | |||||
private Date expireDate; | |||||
private String principal; | |||||
private String credentials; | |||||
public static JwtToken build(String token, Long userId, String username, Long organizeId, Integer organizeType, String salt, long expireSecond) { | |||||
DecodedJWT decodedJWT = JwtUtil.getJwtInfo(token); | |||||
Date createDate = decodedJWT.getIssuedAt(); | |||||
Date expireDate = decodedJWT.getExpiresAt(); | |||||
return new JwtToken() | |||||
.setUsername(username) | |||||
.setUserId(userId) | |||||
.setToken(token) | |||||
.setOrganizeType(organizeType) | |||||
.setOrganizeId(organizeId) | |||||
.setHost(IpUtil.getRequestIp()) | |||||
.setSalt(salt) | |||||
.setCreateDate(createDate) | |||||
.setExpireSecond(expireSecond) | |||||
.setExpireDate(expireDate); | |||||
} | |||||
} |
package com.xdf.creative.shiro.jwt; | |||||
import com.xdf.creative.util.HttpServletRequestUtil; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.apache.commons.lang3.StringUtils; | |||||
import org.springframework.stereotype.Component; | |||||
import javax.servlet.http.HttpServletRequest; | |||||
/** | |||||
* JwtToken工具类 | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-10-03 | |||||
* @since 1.3.0.RELEASE | |||||
**/ | |||||
@Slf4j | |||||
@Component | |||||
public class JwtTokenUtil { | |||||
private static String tokenName; | |||||
private static String refreshTokenName; | |||||
public JwtTokenUtil(JwtProperties jwtProperties) { | |||||
tokenName = jwtProperties.getTokenName(); | |||||
refreshTokenName = jwtProperties.getRefreshTokenName(); | |||||
log.debug("tokenName:{}", tokenName); | |||||
} | |||||
/** | |||||
* 获取token名称 | |||||
* | |||||
* @return | |||||
*/ | |||||
public static String getTokenName() { | |||||
return tokenName; | |||||
} | |||||
/** | |||||
* 获取refreshTokenName名称 | |||||
* | |||||
* @return | |||||
*/ | |||||
public static String getRefreshTokenName() { | |||||
return refreshTokenName; | |||||
} | |||||
/** | |||||
* 从请求头或者请求参数中 | |||||
* | |||||
* @return | |||||
*/ | |||||
public static String getToken() { | |||||
return getToken(HttpServletRequestUtil.getRequest()); | |||||
} | |||||
/** | |||||
* 从请求头或者请求参数中 | |||||
* | |||||
* @param request | |||||
* @return | |||||
*/ | |||||
public static String getToken(HttpServletRequest request) { | |||||
if (request == null) { | |||||
throw new IllegalArgumentException("request不能为空"); | |||||
} | |||||
// 从请求头中获取token | |||||
String token = request.getHeader(tokenName); | |||||
if (StringUtils.isBlank(token)) { | |||||
// 从请求参数中获取token | |||||
token = request.getParameter(tokenName); | |||||
} | |||||
return token; | |||||
} | |||||
} |
package com.xdf.creative.shiro.jwt; | |||||
import com.alibaba.fastjson.JSON; | |||||
import com.auth0.jwt.JWT; | |||||
import com.auth0.jwt.JWTVerifier; | |||||
import com.auth0.jwt.algorithms.Algorithm; | |||||
import com.auth0.jwt.interfaces.DecodedJWT; | |||||
import com.xdf.creative.constant.CommonConstant; | |||||
import com.xdf.creative.util.UUIDUtil; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.apache.commons.lang3.StringUtils; | |||||
import org.apache.commons.lang3.time.DateUtils; | |||||
import org.springframework.stereotype.Component; | |||||
import java.time.Duration; | |||||
import java.util.Date; | |||||
/** | |||||
* JWT工具类 | |||||
* https://github.com/auth0/java-jwt | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-09-30 | |||||
* @since 1.3.0.RELEASE | |||||
**/ | |||||
@Slf4j | |||||
@Component | |||||
public class JwtUtil { | |||||
private static JwtProperties jwtProperties; | |||||
public JwtUtil(JwtProperties jwtProperties) { | |||||
JwtUtil.jwtProperties = jwtProperties; | |||||
log.info(JSON.toJSONString(JwtUtil.jwtProperties)); | |||||
} | |||||
/** | |||||
* 生成JWT Token | |||||
* | |||||
* @param username 用户名 | |||||
* @param salt 盐值 | |||||
* @param expireDuration 过期时间和单位 | |||||
* @return token | |||||
*/ | |||||
public static String generateToken(long userId, String username, long organizeId, Integer organizeType, String salt, Duration expireDuration) { | |||||
try { | |||||
if (StringUtils.isBlank(username)) { | |||||
log.error("username不能为空"); | |||||
return null; | |||||
} | |||||
log.debug("username:{}", username); | |||||
// 如果盐值为空,则使用默认值:666666 | |||||
if (StringUtils.isBlank(salt)) { | |||||
salt = jwtProperties.getSecret(); | |||||
} | |||||
log.debug("salt:{}", salt); | |||||
// 过期时间,单位:秒 | |||||
Long expireSecond; | |||||
// 默认过期时间为1小时 | |||||
if (expireDuration == null) { | |||||
expireSecond = jwtProperties.getExpireSecond(); | |||||
} else { | |||||
expireSecond = expireDuration.getSeconds(); | |||||
} | |||||
log.debug("expireSecond:{}", expireSecond); | |||||
Date expireDate = DateUtils.addSeconds(new Date(), expireSecond.intValue()); | |||||
log.debug("expireDate:{}", expireDate); | |||||
// 生成token | |||||
Algorithm algorithm = Algorithm.HMAC256(salt); | |||||
String token = JWT.create() | |||||
.withClaim(CommonConstant.JWT_USERNAME, username) | |||||
.withClaim(CommonConstant.JWT_USERID, userId) | |||||
.withClaim(CommonConstant.JWT_ORGANIZE, organizeId) | |||||
.withClaim(CommonConstant.JWT_ORGANIZETYPE, organizeType) | |||||
.withJWTId(UUIDUtil.getUUID()) // jwt唯一id | |||||
.withIssuer(jwtProperties.getIssuer()) // 签发人 | |||||
.withSubject(jwtProperties.getSubject()) // 主题 | |||||
.withAudience(jwtProperties.getAudience()) // 签发的目标 | |||||
.withIssuedAt(new Date()) // 签名时间 | |||||
.withExpiresAt(expireDate) // token过期时间 | |||||
.sign(algorithm); // 签名 | |||||
return token; | |||||
} catch (Exception e) { | |||||
log.error("generateToken exception", e); | |||||
} | |||||
return null; | |||||
} | |||||
public static boolean verifyToken(String token, String salt) { | |||||
try { | |||||
Algorithm algorithm = Algorithm.HMAC256(salt); | |||||
JWTVerifier verifier = JWT.require(algorithm) | |||||
.withIssuer(jwtProperties.getIssuer()) // 签发人 | |||||
.withSubject(jwtProperties.getSubject()) // 主题 | |||||
.withAudience(jwtProperties.getAudience()) // 签发的目标 | |||||
.build(); | |||||
DecodedJWT jwt = verifier.verify(token); | |||||
if (jwt != null) { | |||||
return true; | |||||
} | |||||
} catch (Exception e) { | |||||
log.error("Verify Token Exception", e); | |||||
} | |||||
return false; | |||||
} | |||||
/** | |||||
* 解析token,获取token数据 | |||||
* | |||||
* @param token | |||||
* @return | |||||
*/ | |||||
public static DecodedJWT getJwtInfo(String token) { | |||||
DecodedJWT decodedJWT = JWT.decode(token); | |||||
return decodedJWT; | |||||
} | |||||
/** | |||||
* 获取用户名 | |||||
* | |||||
* @param token | |||||
* @return | |||||
*/ | |||||
public static String getUsername(String token) { | |||||
if (StringUtils.isBlank(token)) { | |||||
return null; | |||||
} | |||||
DecodedJWT decodedJWT = getJwtInfo(token); | |||||
if (decodedJWT == null) { | |||||
return null; | |||||
} | |||||
String username = decodedJWT.getClaim(CommonConstant.JWT_USERNAME).asString(); | |||||
return username; | |||||
} | |||||
/** | |||||
* 获取组织id | |||||
* | |||||
* @param token | |||||
* @return | |||||
*/ | |||||
public static Long getOrganizeId(String token) { | |||||
if (StringUtils.isBlank(token)) { | |||||
return null; | |||||
} | |||||
DecodedJWT decodedJWT = getJwtInfo(token); | |||||
if (decodedJWT == null) { | |||||
return null; | |||||
} | |||||
Long organizeId = decodedJWT.getClaim(CommonConstant.JWT_ORGANIZE).asLong(); | |||||
return organizeId; | |||||
} | |||||
/** | |||||
* 获取辖区id | |||||
* | |||||
* @param token | |||||
* @return | |||||
*/ | |||||
public static String getRegionId(String token) { | |||||
if (StringUtils.isBlank(token)) { | |||||
return null; | |||||
} | |||||
DecodedJWT decodedJWT = getJwtInfo(token); | |||||
if (decodedJWT == null) { | |||||
return null; | |||||
} | |||||
String regionId = decodedJWT.getClaim(CommonConstant.JWT_REGIONID).asString(); | |||||
return regionId; | |||||
} | |||||
/** | |||||
* 获取组织类型 | |||||
* | |||||
* @param token | |||||
* @return | |||||
*/ | |||||
public static Integer getOrganizeType(String token) { | |||||
if (StringUtils.isBlank(token)) { | |||||
return null; | |||||
} | |||||
DecodedJWT decodedJWT = getJwtInfo(token); | |||||
if (decodedJWT == null) { | |||||
return null; | |||||
} | |||||
Integer organizeType = decodedJWT.getClaim(CommonConstant.JWT_ORGANIZETYPE).asInt(); | |||||
return organizeType; | |||||
} | |||||
/** | |||||
* 获取用户ID | |||||
* | |||||
* @param token | |||||
* @return | |||||
*/ | |||||
public static Long getUserId(String token) { | |||||
if (StringUtils.isBlank(token)) { | |||||
return null; | |||||
} | |||||
DecodedJWT decodedJWT = getJwtInfo(token); | |||||
if (decodedJWT == null) { | |||||
return null; | |||||
} | |||||
Long userId = decodedJWT.getClaim(CommonConstant.JWT_USERID).asLong(); | |||||
return userId; | |||||
} | |||||
/** | |||||
* 获取创建时间 | |||||
* | |||||
* @param token | |||||
* @return | |||||
*/ | |||||
public static Date getIssuedAt(String token) { | |||||
DecodedJWT decodedJWT = getJwtInfo(token); | |||||
if (decodedJWT == null) { | |||||
return null; | |||||
} | |||||
return decodedJWT.getIssuedAt(); | |||||
} | |||||
/** | |||||
* 获取过期时间 | |||||
* | |||||
* @param token | |||||
* @return | |||||
*/ | |||||
public static Date getExpireDate(String token) { | |||||
DecodedJWT decodedJWT = getJwtInfo(token); | |||||
if (decodedJWT == null) { | |||||
return null; | |||||
} | |||||
return decodedJWT.getExpiresAt(); | |||||
} | |||||
/** | |||||
* 判断token是否已过期 | |||||
* | |||||
* @param token | |||||
* @return | |||||
*/ | |||||
public static boolean isExpired(String token) { | |||||
Date expireDate = getExpireDate(token); | |||||
if (expireDate == null) { | |||||
return true; | |||||
} | |||||
return expireDate.before(new Date()); | |||||
} | |||||
} |
package com.xdf.creative.shiro.jwt; | |||||
import org.apache.commons.codec.digest.DigestUtils; | |||||
import org.apache.commons.lang3.StringUtils; | |||||
/** | |||||
* 盐值包装工具类 | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-09-30 | |||||
* @since 1.3.0.RELEASE | |||||
**/ | |||||
public class SaltUtil { | |||||
/** | |||||
* 盐值包装 | |||||
* | |||||
* @param secret 配置文件中配置的附加盐值 | |||||
* @param salt 数据库中保存的盐值 | |||||
* @return | |||||
*/ | |||||
public static String getSalt(String secret, String salt) { | |||||
if (StringUtils.isBlank(secret) && StringUtils.isBlank(salt)) { | |||||
return null; | |||||
} | |||||
// 加密方法 | |||||
String newSalt = DigestUtils.sha256Hex(secret + salt); | |||||
return newSalt; | |||||
} | |||||
/** | |||||
* 加工盐值 | |||||
* | |||||
* @param salt | |||||
* @param jwtProperties | |||||
* @return | |||||
*/ | |||||
public static String getSalt(String salt, JwtProperties jwtProperties) { | |||||
String newSalt; | |||||
if (jwtProperties.isSaltCheck()) { | |||||
// 包装盐值 | |||||
newSalt = SaltUtil.getSalt(jwtProperties.getSecret(), salt); | |||||
} else { | |||||
newSalt = jwtProperties.getSecret(); | |||||
} | |||||
return newSalt; | |||||
} | |||||
} | |||||
package com.xdf.creative.shiro.match; | |||||
import org.apache.shiro.authc.AuthenticationInfo; | |||||
import org.apache.shiro.authc.AuthenticationToken; | |||||
import org.apache.shiro.authc.credential.CredentialsMatcher; | |||||
import org.springframework.stereotype.Component; | |||||
/** | |||||
* @author tomsun28 | |||||
* @date 18:00 2018/3/3 | |||||
*/ | |||||
@Component | |||||
public class PasswordMatcher implements CredentialsMatcher { | |||||
@Override | |||||
public boolean doCredentialsMatch(AuthenticationToken authenticationToken, AuthenticationInfo authenticationInfo) { | |||||
return authenticationToken.getPrincipal().toString().equals(authenticationInfo.getPrincipals().getPrimaryPrincipal().toString()) | |||||
&& authenticationToken.getCredentials().toString().equals(authenticationInfo.getCredentials().toString()); | |||||
} | |||||
} |
package com.xdf.creative.support.auth; | |||||
import io.swagger.annotations.ApiModel; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.Data; | |||||
import javax.validation.constraints.NotBlank; | |||||
import javax.validation.constraints.NotNull; | |||||
/** | |||||
* 登录参数 | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-05-15 | |||||
**/ | |||||
@Data | |||||
@ApiModel("登录参数") | |||||
public class LoginParam { | |||||
@NotBlank(message = "请输入账号") | |||||
@ApiModelProperty("账号") | |||||
private String username; | |||||
@NotBlank(message = "请输入密码") | |||||
@ApiModelProperty("密码") | |||||
private String password; | |||||
@ApiModelProperty("验证码Token") | |||||
private String verifyToken; | |||||
@ApiModelProperty("验证码") | |||||
private String code; | |||||
} |
package com.xdf.creative.support.auth; | |||||
import io.swagger.annotations.ApiModel; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.Data; | |||||
import lombok.experimental.Accessors; | |||||
import java.io.Serializable; | |||||
/** | |||||
* @author DeanYe | |||||
* @date 2019-10-26 | |||||
**/ | |||||
@Data | |||||
@Accessors(chain = true) | |||||
@ApiModel("登陆用户信息TokenVO") | |||||
public class LoginSysUserTokenVo implements Serializable { | |||||
private static final long serialVersionUID = -4650803752566647697L; | |||||
@ApiModelProperty("token") | |||||
private String token; | |||||
/** | |||||
* 登陆用户对象 | |||||
*/ | |||||
private LoginSysUserVo loginSysUserVo; | |||||
} |
package com.xdf.creative.support.auth; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.Data; | |||||
import lombok.experimental.Accessors; | |||||
import java.io.Serializable; | |||||
import java.util.Set; | |||||
/** | |||||
* <p> | |||||
* 登录用户对象,响应给前端 | |||||
* </p> | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-05-15 | |||||
**/ | |||||
@Data | |||||
@Accessors(chain = true) | |||||
public class LoginSysUserVo implements Serializable { | |||||
private static final long serialVersionUID = -1758338570596088158L; | |||||
@ApiModelProperty(value = "主键") | |||||
private Long id; | |||||
@ApiModelProperty(value = "用户名") | |||||
private String username; | |||||
@ApiModelProperty(value = "昵称") | |||||
private String nickname; | |||||
@ApiModelProperty(value = "手机号") | |||||
private String phone; | |||||
@ApiModelProperty(value = "头像") | |||||
private String head; | |||||
@ApiModelProperty(value = "性别,0:女,1:男,默认1") | |||||
private Integer gender; | |||||
@ApiModelProperty(value = "状态,0:禁用,1:启用,2:锁定") | |||||
private Integer state; | |||||
@ApiModelProperty("组织id") | |||||
private Long organizeId; | |||||
@ApiModelProperty("角色id") | |||||
private Set<Long> roleId; | |||||
@ApiModelProperty("角色名称") | |||||
private Set<String> roleName; | |||||
@ApiModelProperty("角色编码") | |||||
private Set<String> roleCode; | |||||
@ApiModelProperty("权限编码列表") | |||||
private Set<String> permissionUrls; | |||||
} |
package com.xdf.creative.support.exception; | |||||
/** | |||||
* 业务异常 | |||||
* | |||||
* @author DeanYe | |||||
* @date 2018-11-08 | |||||
*/ | |||||
public class BusinessException extends SpringBootPlusException { | |||||
public BusinessException(String message) { | |||||
super(message); | |||||
} | |||||
public BusinessException(Integer errorCode, String message) { | |||||
super(errorCode, message); | |||||
} | |||||
} |
package com.xdf.creative.support.exception; | |||||
/** | |||||
* DAO异常 | |||||
* | |||||
* @author DeanYe | |||||
* @date 2018-11-08 | |||||
*/ | |||||
public class DaoException extends SpringBootPlusException { | |||||
public DaoException(String message) { | |||||
super(message); | |||||
} | |||||
public DaoException(Integer errorCode, String message) { | |||||
super(errorCode, message); | |||||
} | |||||
} |
package com.xdf.creative.support.exception; | |||||
import lombok.Data; | |||||
import lombok.EqualsAndHashCode; | |||||
/** | |||||
* 自定义异常 | |||||
* | |||||
* @author DeanYe | |||||
* @date 2018-11-08 | |||||
*/ | |||||
@Data | |||||
@EqualsAndHashCode(callSuper = false) | |||||
public class SpringBootPlusException extends RuntimeException { | |||||
private Integer errorCode; | |||||
private String message; | |||||
public SpringBootPlusException(String message) { | |||||
super(message); | |||||
this.message = message; | |||||
} | |||||
public SpringBootPlusException(Integer errorCode, String message) { | |||||
super(message); | |||||
this.errorCode = errorCode; | |||||
this.message = message; | |||||
} | |||||
} |
package com.xdf.creative.support.exception; | |||||
import com.xdf.creative.enums.ApiCode; | |||||
/** | |||||
* 系统登录异常 | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-08-04 | |||||
*/ | |||||
public class SysLoginException extends SpringBootPlusException { | |||||
public SysLoginException(String message) { | |||||
super(message); | |||||
} | |||||
public SysLoginException(Integer errorCode, String message) { | |||||
super(errorCode, message); | |||||
} | |||||
public SysLoginException(ApiCode apiCode) { | |||||
super(apiCode.getCode(), apiCode.getMsg()); | |||||
} | |||||
} |
package com.xdf.creative.util; | |||||
import org.springframework.web.context.request.RequestContextHolder; | |||||
import org.springframework.web.context.request.ServletRequestAttributes; | |||||
import javax.servlet.http.HttpServletRequest; | |||||
/** | |||||
* 获取当前请求的HttpServletRequest对象 | |||||
* | |||||
* @author DeanYe | |||||
* @date 2018-11-08 | |||||
*/ | |||||
public class HttpServletRequestUtil { | |||||
public static HttpServletRequest getRequest() { | |||||
HttpServletRequest httpServletRequest = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | |||||
return httpServletRequest; | |||||
} | |||||
} |
package com.xdf.creative.util; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.apache.commons.codec.digest.DigestUtils; | |||||
import org.apache.commons.lang3.StringUtils; | |||||
/** | |||||
* 密码加密工具类 | |||||
* | |||||
* @author DeanYe | |||||
* @date 2018-11-08 | |||||
*/ | |||||
@Slf4j | |||||
public class PasswordUtil { | |||||
private static final String KEY = "f80b2eed0110a7ea5a94c35cbea1fe003d9bb450803473428b74862cceb697f8"; | |||||
public static String encrypt(String pwd, String salt) { | |||||
if (StringUtils.isBlank(pwd)) { | |||||
return null; | |||||
} | |||||
return DigestUtils.sha256Hex(pwd + salt); | |||||
} | |||||
public static void main(String[] args) { | |||||
String pss = encrypt("123456", "99952b31c18156169a26bec80fd211f6"); | |||||
System.out.println("----------:" + pss); | |||||
} | |||||
} |
package com.xdf.creative.util; | |||||
import java.util.UUID; | |||||
/** | |||||
* @author DeanYe | |||||
* @date 2018-11-08 | |||||
*/ | |||||
public class UUIDUtil { | |||||
public static String getUUID() { | |||||
String uuid = UUID.randomUUID().toString().replaceAll("-", ""); | |||||
return uuid; | |||||
} | |||||
} |
package com.xdf.creative.util.convert; | |||||
import com.xdf.creative.base.vo.creative.SysPermissionTreeVo; | |||||
import com.xdf.creative.module.entity.SysPermission; | |||||
import org.mapstruct.Mapper; | |||||
import org.mapstruct.factory.Mappers; | |||||
/** | |||||
* SysPermission类相关转换 | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-10-26 | |||||
**/ | |||||
@Mapper | |||||
public interface SysPermissionConvert { | |||||
SysPermissionConvert INSTANCE = Mappers.getMapper(SysPermissionConvert.class); | |||||
/** | |||||
* SysPermission对象转换成SysPermissionTreeVo对象 | |||||
* | |||||
* @param sysPermission | |||||
* @return | |||||
*/ | |||||
SysPermissionTreeVo permissionToTreeVo(SysPermission sysPermission); | |||||
} |
package com.xdf.creative.util.convert; | |||||
import com.xdf.creative.base.params.creative.AddSysRoleParam; | |||||
import com.xdf.creative.module.entity.SysRole; | |||||
import org.mapstruct.Mapper; | |||||
import org.mapstruct.factory.Mappers; | |||||
/** | |||||
* 系统角色转换器 | |||||
* | |||||
* @author DeanYe | |||||
* @date 2019-10-05 | |||||
**/ | |||||
@Mapper | |||||
public interface SysRoleConvert { | |||||
SysRoleConvert INSTANCE = Mappers.getMapper(SysRoleConvert.class); | |||||
/** | |||||
* AddSysRoleParam转SysRole | |||||
* | |||||
* @param addSysRoleParam | |||||
* @return | |||||
*/ | |||||
SysRole addSysRoleParamToSysRole(AddSysRoleParam addSysRoleParam); | |||||
} |
package com.xdf.creative.util.convert; | |||||
import com.xdf.creative.base.params.creative.SysUserQueryParam; | |||||
import com.xdf.creative.base.vo.creative.SysUserQueryVo; | |||||
import com.xdf.creative.module.entity.SysUser; | |||||
import com.xdf.creative.support.auth.LoginSysUserVo; | |||||
import org.mapstruct.Mapper; | |||||
import org.mapstruct.factory.Mappers; | |||||
/** | |||||
* @author DeanYe | |||||
* @date 2019-10-05 | |||||
**/ | |||||
@Mapper | |||||
public interface SysUserConvert { | |||||
SysUserConvert INSTANCE = Mappers.getMapper(SysUserConvert.class); | |||||
/** | |||||
* 系统用户实体对象转换成登陆用户VO对象 | |||||
* | |||||
* @param sysUser | |||||
* @return | |||||
*/ | |||||
LoginSysUserVo sysUserToLoginSysUserVo(SysUser sysUser); | |||||
SysUserQueryVo sysUserToSysUserQueryVo(SysUser sysUser); | |||||
SysUser sysUserQueryParamToSysUser(SysUserQueryParam sysUserQueryParam); | |||||
} |
package com.xdf.creative.util.tree; | |||||
import org.apache.commons.lang.StringUtils; | |||||
/** | |||||
* 构建树时,需要对树的构成进行配置 | |||||
* | |||||
* @author chen | |||||
* @Date 2011-4-21 | |||||
*/ | |||||
public class TreeConfig { | |||||
/** | |||||
* 主键字段 | |||||
*/ | |||||
String idField; | |||||
/** | |||||
* 父节点字段 | |||||
*/ | |||||
String parentField; | |||||
/** | |||||
* 根节点字段 | |||||
*/ | |||||
String rootField; | |||||
/** | |||||
* 根节点值 | |||||
*/ | |||||
String rootValue; | |||||
/** | |||||
* 叶节点字段,如果为空,对节点是否为叶子节点将由每个节点是否有子节点来判定 | |||||
*/ | |||||
String leafField; | |||||
public TreeConfig() { | |||||
} | |||||
public TreeConfig(String idField, String parentField, String rootField, String rootValue, String leafField) { | |||||
this.idField = idField; | |||||
this.parentField = parentField; | |||||
this.rootField = rootField; | |||||
this.rootValue = rootValue; | |||||
this.leafField = leafField; | |||||
} | |||||
/** | |||||
* 如果配置参数不完全,将返回false | |||||
* | |||||
* @return | |||||
* @author chen | |||||
* @Date 2011-4-21 | |||||
*/ | |||||
public boolean isNull() { | |||||
//当leafField为空时,将要把是否有子节点来判定是否是叶子节点 | |||||
if (/*StringUtils.isBlank(this.displayField) || */StringUtils.isBlank(this.parentField) | |||||
|| StringUtils.isBlank(this.rootField) || StringUtils.isBlank(this.rootValue) | |||||
|| StringUtils.isBlank(this.idField)) | |||||
return true; | |||||
/*//如果设置显示叶子节点,但并没有设置节点字段,将返回为空 | |||||
else if(this.getShowLeaf() && StringUtils.isBlank(this.getLeafField())) | |||||
return true;*/ | |||||
return false; | |||||
} | |||||
public String getIdField() { | |||||
return idField; | |||||
} | |||||
public void setIdField(String idField) { | |||||
this.idField = idField; | |||||
} | |||||
public String getRootField() { | |||||
return rootField; | |||||
} | |||||
public void setRootField(String rootField) { | |||||
this.rootField = rootField; | |||||
} | |||||
public String getParentField() { | |||||
return parentField; | |||||
} | |||||
public void setParentField(String parentField) { | |||||
this.parentField = parentField; | |||||
} | |||||
public String getRootValue() { | |||||
return rootValue; | |||||
} | |||||
public void setRootValue(String returnValue) { | |||||
this.rootValue = returnValue; | |||||
} | |||||
public String getLeafField() { | |||||
return leafField; | |||||
} | |||||
public void setLeafField(String leafField) { | |||||
this.leafField = leafField; | |||||
} | |||||
} |
package com.xdf.creative.util.tree; | |||||
import org.apache.commons.lang.StringUtils; | |||||
import java.lang.reflect.InvocationTargetException; | |||||
import java.lang.reflect.Method; | |||||
import java.util.ArrayList; | |||||
import java.util.Collection; | |||||
import java.util.List; | |||||
import java.util.Map; | |||||
/** | |||||
* 系统工具类 | |||||
* | |||||
* @author chen | |||||
* @Date 2011-1-26 | |||||
*/ | |||||
@SuppressWarnings("unchecked") | |||||
public class Utils { | |||||
/** | |||||
* 将list集合转换为TreePanel所使用的数据,并返回 | |||||
* | |||||
* @param list list集合 | |||||
* @param config TreeNode的配置信息 | |||||
* @return | |||||
*/ | |||||
public static List tree(List<Object> list, TreeConfig config) { | |||||
List results = new ArrayList(); | |||||
if (Utils.isNotEmpty(list) && !config.isNull()) { | |||||
for (int i = 0; i < list.size(); i++) { | |||||
Object obj = list.get(i); | |||||
if (null != obj | |||||
&& getFieldValue(obj, config.getRootField()).equals( | |||||
config.getRootValue())) { | |||||
obj = parse(list, obj, config); | |||||
if (null != obj) | |||||
results.add(obj); | |||||
} | |||||
if (i == list.size() - 1) | |||||
return results; | |||||
} | |||||
} | |||||
return results; | |||||
} | |||||
/** | |||||
* 供 @see #tree(List, TreeConfig)方法递归出TreeNode | |||||
* | |||||
* @param list list集合 | |||||
* @param current 当前节点 | |||||
* @param config TreeNode配置信息 | |||||
* @return | |||||
*/ | |||||
@SuppressWarnings("rawtypes") | |||||
public static Object parse(List<Object> list, Object current, | |||||
TreeConfig config) { | |||||
for (Object obj : list) { | |||||
if (null != obj | |||||
&& getFieldValue(obj, config.getParentField()).equals( | |||||
getFieldValue(current, config.getIdField()))) { | |||||
if (null != obj) { | |||||
List children = (List) getFieldValue(current, "children"); | |||||
Object child = parse(list, obj, config); | |||||
children.add(child); | |||||
} | |||||
} | |||||
} | |||||
if (Utils.isNotEmpty(((List) getFieldValue(current, "children")))) { | |||||
setFieldValue(current, "leaf", false); | |||||
} else { | |||||
setFieldValue(current, "leaf", true); | |||||
} | |||||
return current; | |||||
} | |||||
/** | |||||
* 验证集合是否为空,包括是否为null或者集合长度为0 | |||||
* | |||||
* @param obj | |||||
* @return | |||||
* @author chen | |||||
* @Date 2011-4-19 | |||||
*/ | |||||
public static boolean isNotEmpty(Object obj) { | |||||
if (null == obj) | |||||
return false; | |||||
else { | |||||
if (obj instanceof Collection) { | |||||
if (((Collection) obj).size() < 1) | |||||
return false; | |||||
} else if (obj instanceof Map) { | |||||
if (((Map) obj).size() < 1) | |||||
return false; | |||||
} else { | |||||
String className = obj.getClass().getName(); | |||||
if (className.indexOf(".") != -1) | |||||
if (((Object[]) obj).length < 1) | |||||
return false; | |||||
if (className.length() == 2 && className.startsWith("[")) { | |||||
String type = className.substring(1); | |||||
if (type.equals("I")) { | |||||
if (((int[]) obj).length < 1) | |||||
return false; | |||||
} else if (type.equals("D")) { | |||||
if (((double[]) obj).length < 1) | |||||
return false; | |||||
} else if (type.equals("F")) { | |||||
if (((float[]) obj).length < 1) | |||||
return false; | |||||
} else if (type.equals("B")) { | |||||
if (((byte[]) obj).length < 1) | |||||
return false; | |||||
} else if (type.equals("C")) { | |||||
if (((char[]) obj).length < 1) | |||||
return false; | |||||
} else if (type.equals("S")) { | |||||
if (((short[]) obj).length < 1) | |||||
return false; | |||||
} else if (type.equals("L")) { | |||||
if (((long[]) obj).length < 1) | |||||
return false; | |||||
} else if (type.equals("Z")) { | |||||
if (((boolean[]) obj).length < 1) | |||||
return false; | |||||
} | |||||
} | |||||
} | |||||
return true; | |||||
} | |||||
} | |||||
/** | |||||
* 得到对象的指定字段值 | |||||
* | |||||
* @param obj | |||||
* @param fieldName 字段名 | |||||
* @return | |||||
* @author chen | |||||
* @Date 2011-1-26 | |||||
*/ | |||||
public static Object getFieldValue(Object obj, String fieldName) { | |||||
if (null == obj || !StringUtils.isNotEmpty(fieldName)) | |||||
return null; | |||||
// 得到对象的所有定义的方法 | |||||
Method[] methods = obj.getClass().getDeclaredMethods(); | |||||
for (Method method : methods) { | |||||
// 得到对象的getter方法 | |||||
if (method.getName().toLowerCase() | |||||
.equals(("get" + fieldName).toLowerCase())) | |||||
try { | |||||
// 调用getter方法获得字段值 | |||||
return method.invoke(obj, null); | |||||
} catch (IllegalArgumentException e) { | |||||
// TODO Auto-generated catch block | |||||
e.printStackTrace(); | |||||
return null; | |||||
} catch (IllegalAccessException e) { | |||||
// TODO Auto-generated catch block | |||||
e.printStackTrace(); | |||||
return null; | |||||
} catch (InvocationTargetException e) { | |||||
// TODO Auto-generated catch block | |||||
e.printStackTrace(); | |||||
return null; | |||||
} catch (Exception e) { | |||||
// TODO: handle exception | |||||
e.printStackTrace(); | |||||
return null; | |||||
} | |||||
} | |||||
return null; | |||||
} | |||||
/** | |||||
* 设置对象指定的字段值 | |||||
* | |||||
* @param obj 需要设置值的对象 | |||||
* @param fieldName 字段名 | |||||
* @param fieldValue 字段值 | |||||
* @author chen | |||||
* @Date 2011-3-10 | |||||
*/ | |||||
public static void setFieldValue(Object obj, String fieldName, | |||||
Object fieldValue) { | |||||
if (null == obj || !StringUtils.isNotEmpty(fieldName)) | |||||
return; | |||||
// 得到对象的所有定义的方法 | |||||
Method[] methods = obj.getClass().getMethods(); | |||||
for (Method method : methods) { | |||||
// 得到对象的getter方法 | |||||
if (method.getName().toLowerCase() | |||||
.equals(("set" + fieldName).toLowerCase())) | |||||
try { | |||||
// 调用setter方法设置字段值 | |||||
method.invoke(obj, fieldValue); | |||||
} catch (IllegalArgumentException e) { | |||||
// TODO Auto-generated catch block | |||||
e.printStackTrace(); | |||||
} catch (IllegalAccessException e) { | |||||
// TODO Auto-generated catch block | |||||
e.printStackTrace(); | |||||
} catch (InvocationTargetException e) { | |||||
// TODO Auto-generated catch block | |||||
e.printStackTrace(); | |||||
} catch (Exception e) { | |||||
// TODO: handle exception | |||||
e.printStackTrace(); | |||||
} | |||||
} | |||||
} | |||||
} |
validation-query-timeout: 60000 | validation-query-timeout: 60000 | ||||
############################ JWT start ############################# | |||||
jwt: | |||||
# token请求头名称 | |||||
token-name: token | |||||
# jwt密钥线上需要修改secret | |||||
secret: f80b2eed0110a7ea5a94c35cbea1fe003d9bb450803473428b74862cceb697f8 | |||||
# 发行人 | |||||
issuer: xdf | |||||
# 观众 | |||||
audience: web | |||||
# 默认过期时间1小时,单位:秒 | |||||
expire-second: 3600 | |||||
# 是否刷新token | |||||
refresh-token: true | |||||
# 刷新token的时间间隔,默认10分钟,单位:秒 | |||||
refresh-token-countdown: 600 | |||||
# redis校验jwt token是否存在,可选 | |||||
redis-check: true | |||||
# true: 同一个账号只能是最后一次登陆token有效,false:同一个账号可多次登陆 | |||||
single-login: true | |||||
# 盐值校验,如果不加自定义盐值,则使用secret校验 | |||||
salt-check: true | |||||
############################ JWT end ############################### | |||||
############################### mybatis-plus start ################################# | ############################### mybatis-plus start ################################# | ||||
mybatis-plus: | mybatis-plus: |
<?xml version="1.0" encoding="UTF-8"?> | |||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||||
<mapper namespace="com.xdf.creative.module.mapper.SysOrganizeMapper"> | |||||
<!-- 通用查询结果列 --> | |||||
<sql id="Base_Column_List"> | |||||
id, organize_name,popedom_id,organize_type,system_create,state, | |||||
update_time, create_time, parent_id | |||||
</sql> | |||||
<sql id="Base_Bus_Column_List"> | |||||
${alias}.id, ${alias}.organize_name, | |||||
${alias}.popedom_id,, ${alias}.organize_type, ${alias}.system_create, ${alias}.state, | |||||
${alias}.update_time, ${alias}.create_time, ${alias}.parent_id | |||||
</sql> | |||||
<sql id="Base_If_Condition"> | |||||
<where> | |||||
<if test="param.id !=null and param.id!=''"> | |||||
and id=#{param.id} | |||||
</if> | |||||
<if test="param.organizeName !=null and param.organizeName!=''"> | |||||
and organize_name=#{param.organizeName} | |||||
</if> | |||||
<if test="param.popedomId !=null and param.popedomId!=''"> | |||||
and popedom_id=#{param.popedomId} | |||||
</if> | |||||
<if test="param.organizeType !=null and param.organizeType!=''"> | |||||
and organize_type=#{param.organizeType} | |||||
</if> | |||||
<if test="param.systemCeate !=null and param.systemCeate!=''"> | |||||
and system_create=#{param.systemCeate} | |||||
</if> | |||||
<if test="param.state !=null and param.state!=''"> | |||||
and state=#{param.state} | |||||
</if> | |||||
<if test="param.updateTime !=null and param.updateTime!=''"> | |||||
and update_time=#{param.updateTime} | |||||
</if> | |||||
<if test="param.createTime !=null and param.createTime!=''"> | |||||
and create_time=#{param.createTime} | |||||
</if> | |||||
<if test="param.parentId !=null and param.parentId!=''"> | |||||
and parent_id=#{param.parentId} | |||||
</if> | |||||
</where> | |||||
</sql> | |||||
<!--根据ID查询--> | |||||
<select id="getSysOrganizeById" resultType="com.xdf.creative.base.vo.creative.SysOrganizeQueryVo"> | |||||
select | |||||
<include refid="Base_Column_List"/> | |||||
from sys_organize where id = #{id} | |||||
</select> | |||||
<!--根据用户ID查询--> | |||||
<select id="getSysOrganizeByUserId" resultType="com.xdf.creative.base.vo.creative.SysOrganizeQueryVo"> | |||||
select | |||||
<include refid="Base_Bus_Column_List"> | |||||
<property name="alias" value="a"/> | |||||
</include> | |||||
from sys_organize a left join web_user b on a.id = b.organize_id where b.id = #{id} | |||||
</select> | |||||
<!--分页查询--> | |||||
<select id="getSysOrganizePageList" | |||||
resultType="com.xdf.creative.base.vo.creative.SysOrganizeQueryVo" | |||||
parameterType="com.xdf.creative.base.params.creative.SysOrganizeQueryParam"> | |||||
select | |||||
<include refid="Base_Column_List"/> | |||||
from sys_organize | |||||
<include refid="Base_If_Condition"/> | |||||
</select> | |||||
<select id="isEnableSysOrganize" parameterType="com.xdf.creative.base.params.creative.IsEnableSysOrganizeParam" | |||||
resultType="java.lang.Integer"> | |||||
select count(1) | |||||
from sys_organize so | |||||
inner join sys_user su | |||||
on so.parent_id = su.organize_id | |||||
where su.id=#{userId} | |||||
and so.id=#{orgId} | |||||
and so.state = 1 | |||||
</select> | |||||
</mapper> |
<?xml version="1.0" encoding="UTF-8"?> | |||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||||
<mapper namespace="com.xdf.creative.module.mapper.SysPermissionMapper"> | |||||
<!-- 通用查询结果列 --> | |||||
<!-- 通用查询结果列 --> | |||||
<sql id="Base_Column_List"> | |||||
id, name, resource_id, parent_resource_id, url, code, icon, type, level, state, sort, remark, deleted, version, | |||||
create_time, update_time | |||||
</sql> | |||||
<select id="getSysPermissionById" resultType="com.xdf.creative.base.vo.creative.SysPermissionQueryVo"> | |||||
select | |||||
<include refid="Base_Column_List"/> | |||||
from sys_permission where resource_id = #{resourceId} | |||||
</select> | |||||
<select id="getSysPermissionPageList" resultType="com.xdf.creative.base.vo.creative.SysPermissionQueryVo"> | |||||
select | |||||
<include refid="Base_Column_List"/> | |||||
from sys_permission | |||||
</select> | |||||
<select id="getMenuListByUserId" resultType="com.xdf.creative.module.entity.SysPermission"> | |||||
select sp.* | |||||
from sys_user u | |||||
inner join sys_user_role sur | |||||
on u.id = sur.user_id | |||||
inner join sys_role sr | |||||
on sur.role_id = sr.id | |||||
inner join sys_role_permission srp | |||||
on sr.id=srp.role_id | |||||
inner join sys_permission sp | |||||
on srp.permission_id = sp.resource_id | |||||
where u.state = 1 | |||||
and u.deleted = 0 | |||||
and sr.state = 1 | |||||
and sp.state = 1 | |||||
and u.id = #{userId} | |||||
</select> | |||||
<select id="getPermissionUrlByUserId" resultType="java.lang.String" parameterType="java.lang.Long"> | |||||
select url from sys_permission where parent_resource_id in ( | |||||
select sp.resource_id | |||||
from sys_user u | |||||
inner join sys_user_role sur | |||||
on u.id = sur.user_id | |||||
inner join sys_role sr | |||||
on sur.role_id = sr.id | |||||
inner join sys_role_permission srp | |||||
on sr.id = srp.role_id | |||||
inner join sys_permission sp | |||||
on srp.permission_id = sp.resource_id | |||||
where u.id = #{userId} | |||||
and u.state = 1 | |||||
and u.deleted = 0 | |||||
and sr.state = 1 | |||||
and sr.deleted = 0 | |||||
and sp.state = 1 | |||||
and sp.deleted = 0 | |||||
) and state = 1 | |||||
and deleted = 0 | |||||
and type = 2 | |||||
</select> | |||||
<select id="getMenusByUserId" resultType="com.xdf.creative.module.entity.SysPermission" parameterType="java.lang.Long"> | |||||
select | |||||
sp.id, sp.name, sp.resource_id, sp.parent_resource_id, sp.url, sp.code, sp.icon, sp.type, sp.level, sp.state, | |||||
sp.sort, sp.remark, sp.deleted, sp.version, sp.create_time, sp.update_time | |||||
from sys_user_role sur | |||||
inner join sys_role sr | |||||
on sur.role_id = sr.id | |||||
inner join sys_role_permission srp | |||||
on sr.id = srp.role_id | |||||
inner join sys_permission sp | |||||
on srp.permission_id = sp.resource_id | |||||
where sur.id = #{userId} | |||||
and sr.state = 1 | |||||
and sr.deleted = 0 | |||||
and sp.state = 1 | |||||
and sp.deleted = 0 | |||||
and sp.type =1 | |||||
</select> | |||||
<!--角色授权资源列表查询--> | |||||
<select id="impowerResourceTreeList" parameterType="java.lang.Long" | |||||
resultType="com.xdf.creative.module.entity.SysPermission"> | |||||
select a.*,case when b.state =1 then 'true' else 'false' end as checked from sys_permission a | |||||
left join (select distinct permission_id,state from sys_role_permission where role_id in (select role_id from | |||||
sys_user_role where user_id = #{userId}))b | |||||
on a.resource_id =b.permission_id where a.state = 1 and a.deleted = 0 and a.code <![CDATA[ <> ]]> "0" | |||||
</select> | |||||
<!--用户登录加载左侧资源树 屏蔽按钮--> | |||||
<select id="currentUserResourceTreeList" parameterType="java.lang.Long" | |||||
resultType="com.xdf.creative.module.entity.SysPermission"> | |||||
select a.* from sys_permission a right join (select * from sys_role_permission where role_id in (select role_id | |||||
from sys_user_role | |||||
where user_id = 1))b on a.resource_id =b.permission_id where a.state = 1 and a.deleted = 0 and a.type =1 | |||||
</select> | |||||
<!-- 获取不需要鉴权的url --> | |||||
<select id="getSkipAuthUrls" resultType="java.lang.String"> | |||||
select url from sys_permission where type = 2 and (code = 0 or code = 3); | |||||
</select> | |||||
</mapper> |
<?xml version="1.0" encoding="UTF-8"?> | |||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||||
<mapper namespace="com.xdf.creative.module.mapper.SysRoleMapper"> | |||||
<!-- 通用查询结果列 --> | |||||
<sql id="Base_Column_List"> | |||||
id, name, code, type, state, remark, version, create_time, update_time | |||||
</sql> | |||||
<select id="getSysRoleById" resultType="com.xdf.creative.base.vo.creative.SysRoleQueryVo"> | |||||
select | |||||
<include refid="Base_Column_List"/> | |||||
from sys_role where id = #{id} | |||||
</select> | |||||
<select id="getSysRolePageList" resultType="com.xdf.creative.base.vo.creative.SysRoleQueryVo"> | |||||
select | |||||
<include refid="Base_Column_List"/> | |||||
from sys_role | |||||
</select> | |||||
<select id="getUserRoleByUserId" resultType="com.xdf.creative.base.vo.creative.SysRoleQueryVo" parameterType="java.lang.Long"> | |||||
select | |||||
sr.* | |||||
from sys_role sr | |||||
inner join sys_user_role sur | |||||
on sr.id = sur.role_id | |||||
where sur.user_id=#{userId} | |||||
</select> | |||||
</mapper> |
<?xml version="1.0" encoding="UTF-8"?> | |||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||||
<mapper namespace="com.xdf.creative.module.mapper.SysRolePermissionMapper"> | |||||
<!-- 通用查询结果列 --> | |||||
<sql id="Base_Column_List"> | |||||
id, role_id, permission_id, state, remark, version, create_time, update_time | |||||
</sql> | |||||
<select id="getSysRolePermissionById" resultType="com.xdf.creative.base.vo.creative.SysRolePermissionQueryVo"> | |||||
select | |||||
<include refid="Base_Column_List"/> | |||||
from sys_role_permission where id = #{id} | |||||
</select> | |||||
<select id="getSysRolePermissionPageList" | |||||
resultType="com.xdf.creative.base.vo.creative.SysRolePermissionQueryVo"> | |||||
select | |||||
<include refid="Base_Column_List"/> | |||||
from sys_role_permission | |||||
</select> | |||||
<select id="getPermissionCodesByRoleId" resultType="java.lang.String"> | |||||
select p.code | |||||
from sys_role r | |||||
inner join sys_role_permission rp | |||||
on r.id = rp.role_id | |||||
inner join sys_permission p | |||||
on rp.permission_id = p.id | |||||
where r.state = 1 | |||||
and rp.state = 1 | |||||
and p.state = 1 | |||||
and r.id = #{roleId}; | |||||
</select> | |||||
</mapper> |
<?xml version="1.0" encoding="UTF-8"?> | |||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||||
<mapper namespace="com.xdf.creative.module.mapper.SysUserMapper"> | |||||
<!-- 通用查询结果列 --> | |||||
<sql id="Base_Column_List"> | |||||
id, username, nickname, password, salt, phone, email, state, | |||||
gender, head, user_type, organize_id, deleted, version, remark, create_time, update_time | |||||
</sql> | |||||
<select id="getSysUserById" resultType="com.xdf.creative.base.vo.creative.SysUserQueryVo"> | |||||
select | |||||
<include refid="Base_Column_List"/> | |||||
from sys_user | |||||
where deleted = 0 and id = #{id} | |||||
</select> | |||||
<select id="getSysUserPageList" resultType="com.xdf.creative.base.vo.creative.SysUserQueryVo"> | |||||
select | |||||
<include refid="Base_Column_List"/> | |||||
from sys_user | |||||
where deleted = 0 | |||||
</select> | |||||
<select id="getSysUserByUserName" resultType="com.xdf.creative.module.entity.SysUser" parameterType="java.lang.String"> | |||||
SELECT | |||||
<include refid="Base_Column_List"/> | |||||
FROM sys_user | |||||
WHERE username=#{username} | |||||
</select> | |||||
</mapper> |
<?xml version="1.0" encoding="UTF-8"?> | |||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||||
<mapper namespace="com.xdf.creative.module.mapper.SysUserRoleMapper"> | |||||
<!-- 通用查询结果列 --> | |||||
<sql id="Base_Column_List"> | |||||
id, user_id, role_id, create_time | |||||
</sql> | |||||
<sql id="Base_If_Condition"> | |||||
<where> | |||||
<if test="ew.id !=null and ew.id!=''"> | |||||
and id=id | |||||
</if> | |||||
<if test="ew.userId !=null and ew.userId!=''"> | |||||
and user_id=userId | |||||
</if> | |||||
<if test="ew.roleId !=null and ew.roleId!=''"> | |||||
and role_id=roleId | |||||
</if> | |||||
<if test="ew.createTime !=null and ew.createTime!=''"> | |||||
and create_time=createTime | |||||
</if> | |||||
</where> | |||||
</sql> | |||||
<!--根据ID查询--> | |||||
<select id="getSysUserRoleById" resultType="com.xdf.creative.base.vo.creative.SysUserRoleQueryVo"> | |||||
select | |||||
<include refid="Base_Column_List"/> | |||||
from sys_user_role where id = #{id} | |||||
</select> | |||||
<!--分页查询--> | |||||
<select id="getSysUserRolePageList" | |||||
resultType="com.xdf.creative.base.vo.creative.SysUserRoleQueryVo" | |||||
parameterType="com.xdf.creative.base.params.creative.SysUserRoleQueryParam"> | |||||
select | |||||
<include refid="Base_Column_List"/> | |||||
from sys_user_role | |||||
<include refid="Base_If_Condition"/> | |||||
</select> | |||||
</mapper> |