parent
979074fc11
commit
a78b4f3fc1
|
@ -11,6 +11,12 @@ public class SecurityConstants {
|
||||||
*/
|
*/
|
||||||
public static final String DETAILS_USER_ID = "user_id";
|
public static final String DETAILS_USER_ID = "user_id";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户ID字段
|
||||||
|
*/
|
||||||
|
public static final String COMPANY_SIGN = "company_sign";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户名字段
|
* 用户名字段
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -61,6 +61,14 @@ public class SecurityContextHolder {
|
||||||
set(SecurityConstants.DETAILS_USERNAME, username);
|
set(SecurityConstants.DETAILS_USERNAME, username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getCompanySign () {
|
||||||
|
return get(SecurityConstants.COMPANY_SIGN);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setCompanySign (String companySign) {
|
||||||
|
set(SecurityConstants.COMPANY_SIGN, companySign);
|
||||||
|
}
|
||||||
|
|
||||||
public static String getUserKey () {
|
public static String getUserKey () {
|
||||||
return get(SecurityConstants.USER_KEY);
|
return get(SecurityConstants.USER_KEY);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ public class HeaderInterceptor implements AsyncHandlerInterceptor {
|
||||||
SecurityContextHolder.setUserId(ServletUtils.getHeader(request, SecurityConstants.DETAILS_USER_ID));
|
SecurityContextHolder.setUserId(ServletUtils.getHeader(request, SecurityConstants.DETAILS_USER_ID));
|
||||||
SecurityContextHolder.setUserName(ServletUtils.getHeader(request, SecurityConstants.DETAILS_USERNAME));
|
SecurityContextHolder.setUserName(ServletUtils.getHeader(request, SecurityConstants.DETAILS_USERNAME));
|
||||||
SecurityContextHolder.setUserKey(ServletUtils.getHeader(request, SecurityConstants.USER_KEY));
|
SecurityContextHolder.setUserKey(ServletUtils.getHeader(request, SecurityConstants.USER_KEY));
|
||||||
|
SecurityContextHolder.setCompanySign(ServletUtils.getHeader(request, SecurityConstants.COMPANY_SIGN));
|
||||||
|
|
||||||
String token = SecurityUtils.getToken();
|
String token = SecurityUtils.getToken();
|
||||||
if (StringUtils.isNotEmpty(token)) {
|
if (StringUtils.isNotEmpty(token)) {
|
||||||
|
|
|
@ -44,9 +44,11 @@ public class TokenService {
|
||||||
String token = IdUtils.fastUUID();
|
String token = IdUtils.fastUUID();
|
||||||
Long userId = loginUser.getSysUser().getUserId();
|
Long userId = loginUser.getSysUser().getUserId();
|
||||||
String userName = loginUser.getSysUser().getUserName();
|
String userName = loginUser.getSysUser().getUserName();
|
||||||
|
String companySign = loginUser.getSysUser().getDept().getCompanySign();
|
||||||
loginUser.setToken(token);
|
loginUser.setToken(token);
|
||||||
loginUser.setUserid(userId);
|
loginUser.setUserid(userId);
|
||||||
loginUser.setUsername(userName);
|
loginUser.setUsername(userName);
|
||||||
|
loginUser.setCompanySign(companySign);
|
||||||
loginUser.setIpaddr(IpUtils.getIpAddr());
|
loginUser.setIpaddr(IpUtils.getIpAddr());
|
||||||
refreshToken(loginUser);
|
refreshToken(loginUser);
|
||||||
|
|
||||||
|
@ -55,6 +57,7 @@ public class TokenService {
|
||||||
claimsMap.put(SecurityConstants.USER_KEY, token);
|
claimsMap.put(SecurityConstants.USER_KEY, token);
|
||||||
claimsMap.put(SecurityConstants.DETAILS_USER_ID, userId);
|
claimsMap.put(SecurityConstants.DETAILS_USER_ID, userId);
|
||||||
claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName);
|
claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName);
|
||||||
|
claimsMap.put(SecurityConstants.COMPANY_SIGN,companySign);
|
||||||
|
|
||||||
// 接口返回信息
|
// 接口返回信息
|
||||||
Map<String, Object> rspMap = new HashMap<String, Object>();
|
Map<String, Object> rspMap = new HashMap<String, Object>();
|
||||||
|
|
|
@ -3,9 +3,12 @@ package com.zhilian.common.security.utils;
|
||||||
import com.zhilian.common.core.constant.SecurityConstants;
|
import com.zhilian.common.core.constant.SecurityConstants;
|
||||||
import com.zhilian.common.core.constant.TokenConstants;
|
import com.zhilian.common.core.constant.TokenConstants;
|
||||||
import com.zhilian.common.core.context.SecurityContextHolder;
|
import com.zhilian.common.core.context.SecurityContextHolder;
|
||||||
|
import com.zhilian.common.core.utils.JwtUtils;
|
||||||
import com.zhilian.common.core.utils.ServletUtils;
|
import com.zhilian.common.core.utils.ServletUtils;
|
||||||
import com.zhilian.common.core.utils.StringUtils;
|
import com.zhilian.common.core.utils.StringUtils;
|
||||||
import com.zhilian.common.system.domain.LoginUser;
|
import com.zhilian.common.system.domain.LoginUser;
|
||||||
|
import io.jsonwebtoken.Claims;
|
||||||
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -30,6 +33,17 @@ public class SecurityUtils {
|
||||||
return SecurityContextHolder.getUserName();
|
return SecurityContextHolder.getUserName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取公司标识
|
||||||
|
*/
|
||||||
|
public static String formatToken (String token) {
|
||||||
|
// 如果前端设置了令牌前缀,则裁剪掉前缀
|
||||||
|
if (StringUtils.isNotEmpty(token) && token.startsWith(TokenConstants.PREFIX)) {
|
||||||
|
token = token.replaceFirst(TokenConstants.PREFIX, StringUtils.EMPTY);
|
||||||
|
}
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户key
|
* 获取用户key
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -27,6 +27,11 @@ public class LoginUser implements Serializable {
|
||||||
*/
|
*/
|
||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 企业标识
|
||||||
|
*/
|
||||||
|
private String companySign;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录时间
|
* 登录时间
|
||||||
*/
|
*/
|
||||||
|
@ -128,4 +133,12 @@ public class LoginUser implements Serializable {
|
||||||
public void setSysUser (SysUser sysUser) {
|
public void setSysUser (SysUser sysUser) {
|
||||||
this.sysUser = sysUser;
|
this.sysUser = sysUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCompanySign() {
|
||||||
|
return companySign;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCompanySign(String companySign) {
|
||||||
|
this.companySign = companySign;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,12 @@ public class SysDept extends BaseEntity {
|
||||||
*/
|
*/
|
||||||
private String ancestors;
|
private String ancestors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 企业标识
|
||||||
|
*/
|
||||||
|
|
||||||
|
private String companySign;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 部门名称
|
* 部门名称
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -45,6 +45,11 @@ public class SysUser extends BaseEntity {
|
||||||
@Excel(name = "部门编号", type = Type.IMPORT)
|
@Excel(name = "部门编号", type = Type.IMPORT)
|
||||||
private Long deptId;
|
private Long deptId;
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 企业标识
|
||||||
|
// */
|
||||||
|
// private String companySign;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户账号
|
* 用户账号
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -78,6 +78,8 @@
|
||||||
<artifactId>zhilian-common-swagger</artifactId>
|
<artifactId>zhilian-common-swagger</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -78,6 +78,12 @@
|
||||||
<artifactId>zhilian-common-swagger</artifactId>
|
<artifactId>zhilian-common-swagger</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zhilian</groupId>
|
||||||
|
<artifactId>zhilian-common-redis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -1,20 +1,28 @@
|
||||||
package com.zhilian.system.controller;
|
package com.zhilian.system.controller;
|
||||||
|
|
||||||
|
import com.zhilian.common.core.constant.CacheConstants;
|
||||||
|
import com.zhilian.common.core.constant.TokenConstants;
|
||||||
import com.zhilian.common.core.constant.UserConstants;
|
import com.zhilian.common.core.constant.UserConstants;
|
||||||
|
import com.zhilian.common.core.utils.JwtUtils;
|
||||||
import com.zhilian.common.core.utils.StringUtils;
|
import com.zhilian.common.core.utils.StringUtils;
|
||||||
import com.zhilian.common.core.web.controller.BaseController;
|
import com.zhilian.common.core.web.controller.BaseController;
|
||||||
import com.zhilian.common.core.domain.Result;
|
import com.zhilian.common.core.domain.Result;
|
||||||
import com.zhilian.common.log.annotation.Log;
|
import com.zhilian.common.log.annotation.Log;
|
||||||
import com.zhilian.common.log.enums.BusinessType;
|
import com.zhilian.common.log.enums.BusinessType;
|
||||||
|
import com.zhilian.common.redis.service.RedisService;
|
||||||
import com.zhilian.common.security.annotation.RequiresPermissions;
|
import com.zhilian.common.security.annotation.RequiresPermissions;
|
||||||
import com.zhilian.common.security.utils.SecurityUtils;
|
import com.zhilian.common.security.utils.SecurityUtils;
|
||||||
import com.zhilian.common.system.domain.SysDept;
|
import com.zhilian.common.system.domain.SysDept;
|
||||||
import com.zhilian.system.service.SysDeptService;
|
import com.zhilian.system.service.SysDeptService;
|
||||||
|
import io.jsonwebtoken.Claims;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.Cookie;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,13 +36,17 @@ public class SysDeptController extends BaseController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysDeptService deptService;
|
private SysDeptService deptService;
|
||||||
|
@Autowired
|
||||||
|
private RedisService redisService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取部门列表
|
* 获取部门列表
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("system:dept:list")
|
@RequiresPermissions("system:dept:list")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public Result list (SysDept dept) {
|
public Result list (SysDept dept, HttpServletRequest request) {
|
||||||
|
String companySign = getCompanySign(request);
|
||||||
|
dept.setCompanySign(companySign);
|
||||||
List<SysDept> depts = deptService.selectDeptList(dept);
|
List<SysDept> depts = deptService.selectDeptList(dept);
|
||||||
return success(depts);
|
return success(depts);
|
||||||
}
|
}
|
||||||
|
@ -110,4 +122,17 @@ public class SysDeptController extends BaseController {
|
||||||
deptService.checkDeptDataScope(deptId);
|
deptService.checkDeptDataScope(deptId);
|
||||||
return toAjax(deptService.deleteDeptById(deptId));
|
return toAjax(deptService.deleteDeptById(deptId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getCompanySign(HttpServletRequest request){
|
||||||
|
Cookie[] cookies = request.getCookies();
|
||||||
|
for (Cookie cookie : cookies) {
|
||||||
|
if ("companySign".equals(cookie.getName())){
|
||||||
|
return cookie.getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new RuntimeException("公司标识无法获取");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,12 +205,16 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int insertDept (SysDept dept) {
|
public int insertDept (SysDept dept) {
|
||||||
SysDept info = deptMapper.selectDeptById(dept.getParentId());
|
dept.setAncestors("0");
|
||||||
// 如果父节点不为正常状态,则不允许新增子节点
|
if (0 != dept.getParentId()){
|
||||||
if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) {
|
//不是父节点则需要检查其父节点是否正常
|
||||||
throw new ServiceException("部门停用,不允许新增");
|
SysDept info = deptMapper.selectDeptById(dept.getParentId());
|
||||||
|
// 如果父节点不为正常状态,则不允许新增子节点
|
||||||
|
if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) {
|
||||||
|
throw new ServiceException("部门停用,不允许新增");
|
||||||
|
}
|
||||||
|
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
|
||||||
}
|
}
|
||||||
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
|
|
||||||
return deptMapper.insertDept(dept);
|
return deptMapper.insertDept(dept);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
<id property="deptId" column="dept_id"/>
|
<id property="deptId" column="dept_id"/>
|
||||||
<result property="parentId" column="parent_id"/>
|
<result property="parentId" column="parent_id"/>
|
||||||
<result property="ancestors" column="ancestors"/>
|
<result property="ancestors" column="ancestors"/>
|
||||||
|
<result property="companySign" column="company_sign"/>
|
||||||
<result property="deptName" column="dept_name"/>
|
<result property="deptName" column="dept_name"/>
|
||||||
<result property="orderNum" column="order_num"/>
|
<result property="orderNum" column="order_num"/>
|
||||||
<result property="leader" column="leader"/>
|
<result property="leader" column="leader"/>
|
||||||
|
@ -26,6 +27,7 @@
|
||||||
select d.dept_id,
|
select d.dept_id,
|
||||||
d.parent_id,
|
d.parent_id,
|
||||||
d.ancestors,
|
d.ancestors,
|
||||||
|
d.company_sign,
|
||||||
d.dept_name,
|
d.dept_name,
|
||||||
d.order_num,
|
d.order_num,
|
||||||
d.leader,
|
d.leader,
|
||||||
|
@ -41,6 +43,13 @@
|
||||||
<select id="selectDeptList" parameterType="com.zhilian.common.system.domain.SysDept" resultMap="SysDeptResult">
|
<select id="selectDeptList" parameterType="com.zhilian.common.system.domain.SysDept" resultMap="SysDeptResult">
|
||||||
<include refid="selectDeptVo"/>
|
<include refid="selectDeptVo"/>
|
||||||
where d.del_flag = '0'
|
where d.del_flag = '0'
|
||||||
|
<choose>
|
||||||
|
<when test="'ZL' == companySign">
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
and d.company_sign = #{companySign,jdbcType=VARCHAR}
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
<if test="deptId != null and deptId != 0">
|
<if test="deptId != null and deptId != 0">
|
||||||
AND dept_id = #{deptId}
|
AND dept_id = #{deptId}
|
||||||
</if>
|
</if>
|
||||||
|
@ -114,6 +123,7 @@
|
||||||
<if test="deptId != null and deptId != 0">dept_id,</if>
|
<if test="deptId != null and deptId != 0">dept_id,</if>
|
||||||
<if test="parentId != null and parentId != 0">parent_id,</if>
|
<if test="parentId != null and parentId != 0">parent_id,</if>
|
||||||
<if test="deptName != null and deptName != ''">dept_name,</if>
|
<if test="deptName != null and deptName != ''">dept_name,</if>
|
||||||
|
<if test="companySign != null and companySign != ''">company_sign,</if>
|
||||||
<if test="ancestors != null and ancestors != ''">ancestors,</if>
|
<if test="ancestors != null and ancestors != ''">ancestors,</if>
|
||||||
<if test="orderNum != null">order_num,</if>
|
<if test="orderNum != null">order_num,</if>
|
||||||
<if test="leader != null and leader != ''">leader,</if>
|
<if test="leader != null and leader != ''">leader,</if>
|
||||||
|
@ -126,6 +136,7 @@
|
||||||
<if test="deptId != null and deptId != 0">#{deptId},</if>
|
<if test="deptId != null and deptId != 0">#{deptId},</if>
|
||||||
<if test="parentId != null and parentId != 0">#{parentId},</if>
|
<if test="parentId != null and parentId != 0">#{parentId},</if>
|
||||||
<if test="deptName != null and deptName != ''">#{deptName},</if>
|
<if test="deptName != null and deptName != ''">#{deptName},</if>
|
||||||
|
<if test="companySign != null and companySign != ''">#{companySign},</if>
|
||||||
<if test="ancestors != null and ancestors != ''">#{ancestors},</if>
|
<if test="ancestors != null and ancestors != ''">#{ancestors},</if>
|
||||||
<if test="orderNum != null">#{orderNum},</if>
|
<if test="orderNum != null">#{orderNum},</if>
|
||||||
<if test="leader != null and leader != ''">#{leader},</if>
|
<if test="leader != null and leader != ''">#{leader},</if>
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
<resultMap id="deptResult" type="com.zhilian.common.system.domain.SysDept">
|
<resultMap id="deptResult" type="com.zhilian.common.system.domain.SysDept">
|
||||||
<id property="deptId" column="dept_id"/>
|
<id property="deptId" column="dept_id"/>
|
||||||
<result property="parentId" column="parent_id"/>
|
<result property="parentId" column="parent_id"/>
|
||||||
|
<result property="companySign" column="company_sign"/>
|
||||||
<result property="deptName" column="dept_name"/>
|
<result property="deptName" column="dept_name"/>
|
||||||
<result property="ancestors" column="ancestors"/>
|
<result property="ancestors" column="ancestors"/>
|
||||||
<result property="orderNum" column="order_num"/>
|
<result property="orderNum" column="order_num"/>
|
||||||
|
@ -65,6 +66,7 @@
|
||||||
u.remark,
|
u.remark,
|
||||||
d.dept_id,
|
d.dept_id,
|
||||||
d.parent_id,
|
d.parent_id,
|
||||||
|
d.company_sign,
|
||||||
d.ancestors,
|
d.ancestors,
|
||||||
d.dept_name,
|
d.dept_name,
|
||||||
d.order_num,
|
d.order_num,
|
||||||
|
@ -84,7 +86,7 @@
|
||||||
|
|
||||||
<select id="selectUserList" parameterType="com.zhilian.common.system.domain.SysUser" resultMap="SysUserResult">
|
<select id="selectUserList" parameterType="com.zhilian.common.system.domain.SysUser" resultMap="SysUserResult">
|
||||||
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status,
|
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status,
|
||||||
u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from sys_user
|
u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.company_sign ,d.dept_name, d.leader from sys_user
|
||||||
u
|
u
|
||||||
left join sys_dept d on u.dept_id = d.dept_id
|
left join sys_dept d on u.dept_id = d.dept_id
|
||||||
where u.del_flag = '0'
|
where u.del_flag = '0'
|
||||||
|
|
Loading…
Reference in New Issue