修改多租户功能
parent
a408dec2ef
commit
1492f4ce31
|
@ -29,6 +29,26 @@ public class SysUserExt extends BaseEntity
|
|||
@Excel(name = "用户类型", readConverterExp = "0=0系统用户")
|
||||
private String userType;
|
||||
|
||||
private Long comId;
|
||||
|
||||
public Long getComId() {
|
||||
return comId;
|
||||
}
|
||||
|
||||
public void setComId(Long comId) {
|
||||
this.comId = comId;
|
||||
}
|
||||
|
||||
public Long getIsActive() {
|
||||
return isActive;
|
||||
}
|
||||
|
||||
public void setIsActive(Long isActive) {
|
||||
this.isActive = isActive;
|
||||
}
|
||||
|
||||
private Long isActive;
|
||||
|
||||
public void setUserId(Long userId)
|
||||
{
|
||||
this.userId = userId;
|
||||
|
|
|
@ -7,12 +7,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<resultMap type="SysUserExt" id="SysUserExtResult">
|
||||
<result property="userId" column="user_id" />
|
||||
<result property="projectId" column="project_id" />
|
||||
<result property="comId" column="com_id" />
|
||||
<result property="status" column="status" />
|
||||
<result property="userType" column="user_type" />
|
||||
<result property="isActive" column="is_active" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectSysUserExtVo">
|
||||
select user_id, project_id, status, user_type from sys_user_ext
|
||||
select user_id, project_id, status, user_type,com_id,is_active from sys_user_ext
|
||||
</sql>
|
||||
|
||||
<select id="selectSysUserExtList" parameterType="SysUserExt" resultMap="SysUserExtResult">
|
||||
|
@ -20,6 +22,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<where>
|
||||
<if test="status != null and status != ''"> and status = #{status}</if>
|
||||
<if test="userType != null and userType != ''"> and user_type = #{userType}</if>
|
||||
<if test="userId != null and userId != 0"> and user_id = #{userId}</if>
|
||||
<if test="projectId != null and projectId != 0"> and project_id = #{projectId}</if>
|
||||
<if test="comId != null and comId != 0"> and com_id = #{comId}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
@ -35,12 +40,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="projectId != null">project_id,</if>
|
||||
<if test="status != null">status,</if>
|
||||
<if test="userType != null">user_type,</if>
|
||||
<if test="comId != null">com_id,</if>
|
||||
<if test="isActive != null">is_active,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="userId != null">#{userId},</if>
|
||||
<if test="projectId != null">#{projectId},</if>
|
||||
<if test="status != null">#{status},</if>
|
||||
<if test="userType != null">#{userType},</if>
|
||||
<if test="comId != null">#{comId},</if>
|
||||
<if test="isActive != null">#{isActive},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
|
@ -50,6 +59,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="projectId != null">project_id = #{projectId},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="userType != null">user_type = #{userType},</if>
|
||||
<if test="comId != null">com_id = #{comId},</if>
|
||||
<if test="isActive != null">is_active = #{isActive},</if>
|
||||
</trim>
|
||||
where user_id = #{userId}
|
||||
</update>
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.yanzhu.system.controller;
|
|||
import com.yanzhu.common.core.constant.Constants;
|
||||
import com.yanzhu.common.core.domain.R;
|
||||
import com.yanzhu.common.core.enums.UserTypeEnums;
|
||||
import com.yanzhu.common.core.exception.ServiceException;
|
||||
import com.yanzhu.common.core.text.Convert;
|
||||
import com.yanzhu.common.core.utils.StringUtils;
|
||||
import com.yanzhu.common.core.utils.poi.ExcelUtil;
|
||||
|
@ -14,11 +15,13 @@ import com.yanzhu.common.log.enums.BusinessType;
|
|||
import com.yanzhu.common.redis.service.RedisService;
|
||||
import com.yanzhu.common.security.annotation.InnerAuth;
|
||||
import com.yanzhu.common.security.annotation.RequiresPermissions;
|
||||
import com.yanzhu.common.security.service.TokenService;
|
||||
import com.yanzhu.common.security.utils.SecurityUtils;
|
||||
import com.yanzhu.system.api.domain.SysDept;
|
||||
import com.yanzhu.system.api.domain.SysRole;
|
||||
import com.yanzhu.system.api.domain.SysUser;
|
||||
import com.yanzhu.system.api.model.LoginUser;
|
||||
import com.yanzhu.system.domain.SysUserCom;
|
||||
import com.yanzhu.system.domain.vo.TreeSelect;
|
||||
import com.yanzhu.system.service.*;
|
||||
import com.yanzhu.system.vo.AlertUserPassVo;
|
||||
|
@ -29,6 +32,7 @@ import org.springframework.validation.annotation.Validated;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
|
@ -65,6 +69,8 @@ public class SysUserController extends BaseController {
|
|||
|
||||
@Autowired
|
||||
private ISysConfigService configService;
|
||||
@Autowired
|
||||
private TokenService tokenService;
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
|
@ -109,12 +115,22 @@ public class SysUserController extends BaseController {
|
|||
@InnerAuth
|
||||
@GetMapping("/info/{username}")
|
||||
public R<LoginUser> info(@PathVariable("username") String username) {
|
||||
try {
|
||||
LoginUser sysUserVo = getLoginInfo(username);
|
||||
|
||||
return R.ok(sysUserVo);
|
||||
}catch (ServiceException ex){
|
||||
return R.fail(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private LoginUser getLoginInfo(String username){
|
||||
SysUser sysUser = userService.selectUserByUserName(username);
|
||||
if (StringUtils.isNull(sysUser)) {
|
||||
return R.fail("用户名或密码错误");
|
||||
throw new ServiceException("用户名或密码错误");
|
||||
}
|
||||
if (StringUtils.isEmpty(sysUser.getRoles())) {
|
||||
return R.fail("用户未查询到分配角色,请联系管理员!!!");
|
||||
throw new ServiceException("用户未查询到分配角色,请联系管理员!!!");
|
||||
}
|
||||
// 重写登录方法
|
||||
if (!sysUser.isAdmin() && sysUser.getRoles().size() > 1) {
|
||||
|
@ -125,6 +141,7 @@ public class SysUserController extends BaseController {
|
|||
sysUser.setActiveComId(sysUser.getComId());
|
||||
sysUser.setActiveComName(sysUser.getComName());
|
||||
} else {
|
||||
/*
|
||||
// 查询用户绑定项目列表
|
||||
List<Map<String, Object>> list = userService.selectProjectsByUserId(sysUser.getUserId());
|
||||
if (StringUtils.isEmpty(list)) {
|
||||
|
@ -136,6 +153,16 @@ public class SysUserController extends BaseController {
|
|||
sysUser.setActiveComName(Convert.toStr(list.get(0).get("com_name")));
|
||||
sysUser.setActiveProjectId(Convert.toLong(list.get(0).get("project_id")));
|
||||
sysUser.setActiveProjectName(Convert.toStr(list.get(0).get("project_name")));
|
||||
|
||||
*/
|
||||
sysUser.setActiveComId(sysUser.getComId());
|
||||
sysUser.setActiveComName(sysUser.getComName());
|
||||
sysUser.setActiveProjectId(sysUser.getDeptId());
|
||||
if(sysUser.getDept()!=null){
|
||||
sysUser.setActiveProjectName(sysUser.getDept().getDeptName());
|
||||
}else{
|
||||
sysUser.setActiveProjectName("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,8 +182,7 @@ public class SysUserController extends BaseController {
|
|||
roles.add("visitors");
|
||||
sysUserVo.setRoles(roles);
|
||||
}
|
||||
|
||||
return R.ok(sysUserVo);
|
||||
return sysUserVo;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -238,7 +264,7 @@ public class SysUserController extends BaseController {
|
|||
*
|
||||
* @return 用户信息
|
||||
*/
|
||||
@GetMapping("getInfo")
|
||||
@GetMapping("/getInfo")
|
||||
public AjaxResult getInfo() {
|
||||
SysUser user = SecurityUtils.getLoginUser().getSysUser();
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
|
@ -428,4 +454,21 @@ public class SysUserController extends BaseController {
|
|||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("/activeUserCom")
|
||||
public AjaxResult activeUserCom(@RequestBody SysUserCom userCom, HttpServletRequest request){
|
||||
SysUser user= userService.activeUserCom(userCom);
|
||||
|
||||
LoginUser sysUserVo = getLoginInfo(user.getUserName());
|
||||
LoginUser loginUser = tokenService.getLoginUser(request);
|
||||
loginUser.setSysUser(sysUserVo.getSysUser());
|
||||
loginUser.setProjectId(sysUserVo.getProjectId());
|
||||
loginUser.setProjectName(sysUserVo.getProjectName());
|
||||
loginUser.setProjectDeptId(sysUserVo.getProjectDeptId());
|
||||
loginUser.setProjectDeptName(sysUserVo.getProjectDeptName());
|
||||
loginUser.setRoles(sysUserVo.getRoles());
|
||||
loginUser.setPermissions(sysUserVo.getPermissions());
|
||||
tokenService.refreshToken(loginUser);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -264,5 +264,5 @@ public interface ISysUserService
|
|||
|
||||
public List<SysUserCom> getUserComs(Long userId);
|
||||
|
||||
public int activeUserCom(SysUserCom userCom);
|
||||
public SysUser activeUserCom(SysUserCom userCom);
|
||||
}
|
||||
|
|
|
@ -81,7 +81,10 @@ public class SysUserExtServiceImpl implements ISysUserExtService
|
|||
public void updateBySysUser(SysUser sysUser) {
|
||||
SysUserExt where=new SysUserExt();
|
||||
where.setUserId(sysUser.getUserId());
|
||||
where.setComId(sysUser.getComId());
|
||||
List<SysUserExt> userExts=sysUserExtMapper.selectSysUserExtList(where);
|
||||
where.setProjectId(sysUser.getDeptId());
|
||||
where.setIsActive(userExts.size()==0?1l:0l);
|
||||
SysUserExt old=selectSysUserExtById(where);
|
||||
if(Objects.nonNull(old)){
|
||||
old.setUserType(sysUser.getUserType());
|
||||
|
|
|
@ -10,10 +10,12 @@ import com.yanzhu.common.core.enums.ShiFouEnums;
|
|||
import com.yanzhu.common.core.enums.UserTypeEnums;
|
||||
import com.yanzhu.common.core.utils.DateUtils;
|
||||
import com.yanzhu.common.core.web.domain.AjaxResult;
|
||||
import com.yanzhu.common.security.service.TokenService;
|
||||
import com.yanzhu.system.api.RemoteProService;
|
||||
import com.yanzhu.system.api.RemoteUserService;
|
||||
import com.yanzhu.system.api.domain.SysDept;
|
||||
import com.yanzhu.system.api.domain.SysRoleDept;
|
||||
import com.yanzhu.system.api.model.LoginUser;
|
||||
import com.yanzhu.system.domain.*;
|
||||
import com.yanzhu.system.mapper.*;
|
||||
import com.yanzhu.system.service.ISysUserExtService;
|
||||
|
@ -83,6 +85,11 @@ public class SysUserServiceImpl implements ISysUserService
|
|||
private ISysUserExtService userExtService;
|
||||
@Autowired
|
||||
private SysUserComMapper userComMapper;
|
||||
|
||||
@Autowired
|
||||
private TokenService tokenService;
|
||||
|
||||
|
||||
/**
|
||||
* 根据条件分页查询用户列表
|
||||
*
|
||||
|
@ -319,7 +326,7 @@ public class SysUserServiceImpl implements ISysUserService
|
|||
public int insertUser(SysUser user)
|
||||
{
|
||||
// 新增用户信息
|
||||
user.setUserName(userNameAndCout(user.getNickName()));
|
||||
//user.setUserName(userNameAndCout(user.getNickName()));
|
||||
SysDept dept = deptMapper.selectDeptById(user.getDeptId());
|
||||
if(Objects.isNull(dept)){
|
||||
throw new ServiceException("所属单位选择异常,必须选择子公司及下属单位");
|
||||
|
@ -328,11 +335,11 @@ public class SysUserServiceImpl implements ISysUserService
|
|||
int rows=0;
|
||||
SysUser sysUser = userMapper.selectByPhone(user.getPhonenumber());
|
||||
if(Objects.nonNull(sysUser)){//此电话号码已注册
|
||||
SysUser where=new SysUser();
|
||||
SysUserExt where=new SysUserExt();
|
||||
where.setUserId(sysUser.getUserId());
|
||||
where.setComId(user.getComId());
|
||||
SysUser oldUserCom=userMapper.selectUserCom(where);
|
||||
if(Objects.nonNull(oldUserCom)){
|
||||
where.setProjectId(user.getDeptId());
|
||||
List<SysUserExt> userExts=userExtService.selectSysUserExtList(where);
|
||||
if(userExts.size()>0){
|
||||
throw new ServiceException("此用户己在此项目中!");
|
||||
}
|
||||
user.setUserId(sysUser.getUserId());
|
||||
|
@ -340,7 +347,9 @@ public class SysUserServiceImpl implements ISysUserService
|
|||
user.setStatus("0");
|
||||
userMapper.insertUserCom(user);
|
||||
sysUser.setUserName(user.getUserName());
|
||||
sysUser.setPhonenumber(user.getUserName());
|
||||
sysUser.setComId(user.getComId());
|
||||
sysUser.setDeptId(user.getDeptId());
|
||||
sysUser.setPhonenumber(user.getPhonenumber());
|
||||
sysUser.setNickName(user.getNickName());
|
||||
sysUser.setUpdateBy(user.getUpdateBy());
|
||||
sysUser.setUpdateTime(user.getUpdateTime());
|
||||
|
@ -915,14 +924,38 @@ public class SysUserServiceImpl implements ISysUserService
|
|||
}
|
||||
|
||||
@Override
|
||||
public int activeUserCom(SysUserCom userCom) {
|
||||
public SysUser activeUserCom(SysUserCom userCom) {
|
||||
userCom.setIsActive(1l);
|
||||
int cnt= userComMapper.updateActiveTo0(userCom);
|
||||
cnt+= userComMapper.updateActive(userCom);
|
||||
SysUserExt userExtWhere=new SysUserExt();
|
||||
userExtWhere.setUserId(userCom.getUserId());
|
||||
userExtWhere.setComId(userCom.getComId());
|
||||
List<SysUserExt> userExts=userExtService.selectSysUserExtList(userExtWhere);
|
||||
if(userExts.size()==0){
|
||||
throw new ServiceException("此租户下面没有项目");
|
||||
}
|
||||
SysUserExt sysUserExt=findActiveUserExt(userExts);
|
||||
SysUser user=selectUserById(userCom.getUserId());
|
||||
user.setComId(userCom.getComId());
|
||||
user.setDeptId(sysUserExt.getProjectId());
|
||||
cnt+= userMapper.updateUser(user);
|
||||
return cnt;
|
||||
return user;
|
||||
}
|
||||
|
||||
private SysUserExt findActiveUserExt(List<SysUserExt> userExts) {
|
||||
SysUserExt find=null;
|
||||
for(SysUserExt userExt:userExts){
|
||||
if(userExt.getIsActive()==1){
|
||||
find=userExt;
|
||||
}
|
||||
}
|
||||
if(find==null){
|
||||
find=userExts.get(0);
|
||||
find.setIsActive(1l);
|
||||
userExtService.updateSysUserExt(find);
|
||||
}
|
||||
return find;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -172,7 +172,7 @@ export function getUserComs(userId){
|
|||
|
||||
export function activeUserCom(userCom){
|
||||
return request({
|
||||
url:'/system/user/profile/activeUserCom',
|
||||
url:'/system/user/activeUserCom',
|
||||
method:'post',
|
||||
data:userCom
|
||||
})
|
||||
|
|
|
@ -56,8 +56,8 @@ const useUserStore = defineStore(
|
|||
this.nickName = user.nickName;
|
||||
this.compInfo=user.comp;
|
||||
this.avatar = avatar;
|
||||
this.currentComId = user.comp?.deptId||user.activeComId;
|
||||
this.currentComName =user.comp?.deptName|| user.activeComName;
|
||||
this.currentComId = user.activeComId;
|
||||
this.currentComName = user.activeComName;
|
||||
this.currentPrjId = user.activeProjectId;
|
||||
this.currentProName = user.activeProjectName;
|
||||
resolve(res)
|
||||
|
|
|
@ -27,7 +27,9 @@
|
|||
</li>
|
||||
<li class="list-group-item">
|
||||
<svg-icon icon-class="tree" />所属部门
|
||||
<div class="pull-right" v-if="state.user.dept">{{ state.user.dept.deptName }} / {{ state.postGroup }}</div>
|
||||
<div class="pull-right" v-if="state.user.dept">
|
||||
{{ state.user.dept.deptName }} / {{ state.postGroup }}
|
||||
</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<svg-icon icon-class="peoples" />所属角色
|
||||
|
@ -58,20 +60,31 @@
|
|||
</el-tabs>
|
||||
</el-card>
|
||||
|
||||
<el-card style="margin-top:10px;">
|
||||
<el-card style="margin-top: 10px">
|
||||
<template v-slot:header>
|
||||
<div class="clearfix">
|
||||
<span>租户信息</span>
|
||||
</div>
|
||||
</template>
|
||||
<div class="user-coms">
|
||||
<div v-for="(it,idx) in state.coms" :key="idx" class="user-com" :class="it.isActive==1?'is-active':''">
|
||||
<span style="display: inline-block;margin-right:10px;">
|
||||
<div
|
||||
v-for="(it, idx) in state.coms"
|
||||
:key="idx"
|
||||
class="user-com"
|
||||
:class="it.isActive == 1 ? 'is-active' : ''"
|
||||
>
|
||||
<span style="display: inline-block; margin-right: 10px">
|
||||
{{ it.comName }}
|
||||
</span>
|
||||
<el-tag type="success" class="is-active-tag" v-if="it.isActive==1">已激活</el-tag>
|
||||
<el-button v-else type="primary" @click="toggleCom(it)">切换</el-button>
|
||||
|
||||
<el-tag
|
||||
type="success"
|
||||
class="is-active-tag"
|
||||
v-if="it.isActive == 1"
|
||||
>已激活</el-tag
|
||||
>
|
||||
<el-button v-else type="primary" @click="toggleCom(it)"
|
||||
>切换</el-button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
|
@ -81,43 +94,44 @@
|
|||
</template>
|
||||
|
||||
<script setup name="Profile">
|
||||
import useUserStore from '@/store/modules/user'
|
||||
import useUserStore from "@/store/modules/user";
|
||||
import userAvatar from "./userAvatar";
|
||||
import userInfo from "./userInfo";
|
||||
import resetPwd from "./resetPwd";
|
||||
import { getUserProfile, getUserComs, activeUserCom } from "@/api/system/user";
|
||||
|
||||
import { switchProject } from "@/api/login";
|
||||
const { proxy } = getCurrentInstance();
|
||||
const userStore = useUserStore()
|
||||
const userStore = useUserStore();
|
||||
const activeTab = ref("userinfo");
|
||||
const state = reactive({
|
||||
user: {},
|
||||
roleGroup: {},
|
||||
postGroup: {},
|
||||
coms:[]
|
||||
coms: [],
|
||||
});
|
||||
|
||||
function getUser() {
|
||||
getUserProfile().then(response => {
|
||||
getUserProfile().then((response) => {
|
||||
state.user = response.data;
|
||||
state.roleGroup = response.roleGroup;
|
||||
state.postGroup = response.postGroup;
|
||||
});
|
||||
};
|
||||
}
|
||||
function loadUserComs() {
|
||||
let userId = userStore.uid;
|
||||
if (!userId) {
|
||||
return;
|
||||
}
|
||||
getUserComs(userId).then(d=>{
|
||||
getUserComs(userId).then((d) => {
|
||||
state.coms = d.data || [];
|
||||
});
|
||||
}
|
||||
|
||||
function toggleCom(com) {
|
||||
activeUserCom(com).then(d=>{
|
||||
activeUserCom(com).then((d) => {
|
||||
if (d.code == 200) {
|
||||
location.reload();
|
||||
proxy.$modal.loading("正在切换项目信息,请稍后...");
|
||||
setTimeout("window.location.reload()", 500);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -135,7 +149,6 @@ getUser();
|
|||
line-height: 40px;
|
||||
.is-active-tag {
|
||||
font-size: 12px;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue