系统用户改造

dev_xd
lj7788@126.com 2025-01-09 22:20:40 +08:00
parent 9490d7aa7c
commit e892f77673
13 changed files with 463 additions and 24 deletions

View File

@ -0,0 +1,78 @@
package com.yanzhu.system.domain;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import Excel;
import BaseEntity;
/**
* sys_user_ext
*
* @author yanzhu
* @date 2025-01-09
*/
public class SysUserExt extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 用户ID */
private Long userId;
/** 项目ID */
private Long projectId;
/** 状态 */
@Excel(name = "状态")
private String status;
/** 用户类型00系统用户 */
@Excel(name = "用户类型", readConverterExp = "0=0系统用户")
private String userType;
public void setUserId(Long userId)
{
this.userId = userId;
}
public Long getUserId()
{
return userId;
}
public void setProjectId(Long projectId)
{
this.projectId = projectId;
}
public Long getProjectId()
{
return projectId;
}
public void setStatus(String status)
{
this.status = status;
}
public String getStatus()
{
return status;
}
public void setUserType(String userType)
{
this.userType = userType;
}
public String getUserType()
{
return userType;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("userId", getUserId())
.append("projectId", getProjectId())
.append("status", getStatus())
.append("userType", getUserType())
.toString();
}
}

View File

@ -16,6 +16,16 @@ public class SysUserPost
/** 岗位ID */
private Long postId;
private Long projectId;
public Long getProjectId() {
return projectId;
}
public void setProjectId(Long projectId) {
this.projectId = projectId;
}
public Long getUserId()
{
return userId;

View File

@ -0,0 +1,61 @@
package com.yanzhu.system.mapper;
import java.util.List;
import com.yanzhu.system.domain.SysUserExt;
/**
* Mapper
*
* @author yanzhu
* @date 2025-01-09
*/
public interface SysUserExtMapper
{
/**
*
*
* @param userId
* @return
*/
public SysUserExt selectSysUserExtByUserId(Long userId);
/**
*
*
* @param sysUserExt
* @return
*/
public List<SysUserExt> selectSysUserExtList(SysUserExt sysUserExt);
/**
*
*
* @param sysUserExt
* @return
*/
public int insertSysUserExt(SysUserExt sysUserExt);
/**
*
*
* @param sysUserExt
* @return
*/
public int updateSysUserExt(SysUserExt sysUserExt);
/**
*
*
* @param userId
* @return
*/
public int deleteSysUserExtByUserId(Long userId);
/**
*
*
* @param userIds
* @return
*/
public int deleteSysUserExtByUserIds(Long[] userIds);
}

View File

@ -45,6 +45,7 @@ public interface SysUserMapper
*/
public SysUser selectUserByUserName(String userName);
public SysUser selectByPhone(String phone);
/**
*
*

View File

@ -0,0 +1,67 @@
<?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.yanzhu.system.mapper.SysUserExtMapper">
<resultMap type="SysUserExt" id="SysUserExtResult">
<result property="userId" column="user_id" />
<result property="projectId" column="project_id" />
<result property="status" column="status" />
<result property="userType" column="user_type" />
</resultMap>
<sql id="selectSysUserExtVo">
select user_id, project_id, status, user_type from sys_user_ext
</sql>
<select id="selectSysUserExtList" parameterType="SysUserExt" resultMap="SysUserExtResult">
<include refid="selectSysUserExtVo"/>
<where>
<if test="status != null and status != ''"> and status = #{status}</if>
<if test="userType != null and userType != ''"> and user_type = #{userType}</if>
</where>
</select>
<select id="selectSysUserExtByUserId" parameterType="Long" resultMap="SysUserExtResult">
<include refid="selectSysUserExtVo"/>
where user_id = #{userId}
</select>
<insert id="insertSysUserExt" parameterType="SysUserExt">
insert into sys_user_ext
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="userId != null">user_id,</if>
<if test="projectId != null">project_id,</if>
<if test="status != null">status,</if>
<if test="userType != null">user_type,</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>
</trim>
</insert>
<update id="updateSysUserExt" parameterType="SysUserExt">
update sys_user_ext
<trim prefix="SET" suffixOverrides=",">
<if test="projectId != null">project_id = #{projectId},</if>
<if test="status != null">status = #{status},</if>
<if test="userType != null">user_type = #{userType},</if>
</trim>
where user_id = #{userId}
</update>
<delete id="deleteSysUserExtByUserId" parameterType="Long">
delete from sys_user_ext where user_id = #{userId}
</delete>
<delete id="deleteSysUserExtByUserIds" parameterType="String">
delete from sys_user_ext where user_id in
<foreach item="userId" collection="array" open="(" separator="," close=")">
#{userId}
</foreach>
</delete>
</mapper>

View File

@ -61,12 +61,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectUserVo">
select u.user_id, uc.com_id, com.dept_name as com_name, u.dept_id, u.user_name, u.nick_name, u.user_type, u.card_code, u.email
, u.avatar, u.phonenumber, u.password, u.sex, uc.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
select u.user_id, u.com_id, com.dept_name as com_name, u.dept_id, u.user_name, u.nick_name, u.user_type, u.card_code, u.email
, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.dept_short_name, d.dept_code, d.dept_type, d.order_num, d.leader, d.status as dept_status,
r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status,com.dept_name com_dept_name,uc.is_active is_active
r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status,com.dept_name com_dept_name
from sys_user u
left join sys_user_com uc on u.user_id=uc.user_id
left join sys_dept d on u.dept_id = d.dept_id
left join sys_dept com on u.com_id = com.dept_id
left join sys_user_role ur on u.user_id = ur.user_id
@ -74,11 +73,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</sql>
<select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult">
select u.user_id, uc.com_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, uc.status,
u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader,
uc.is_active is_active
select u.user_id, u.com_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
left join sys_user_com uc on u.user_id=uc.user_id
left join sys_dept d on u.dept_id = d.dept_id
where u.del_flag = '0'
<if test="userId != null and userId != 0">
@ -113,9 +110,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult">
select distinct u.user_id, uc.com_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, uc.status, u.create_time,uc.is_active is_active
select distinct u.user_id, u.com_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time
from sys_user u
left join sys_user_com uc on u.user_id=uc.user_id
left join sys_dept d on u.dept_id = d.dept_id
left join sys_user_role ur on u.user_id = ur.user_id
left join sys_role r on r.role_id = ur.role_id
@ -131,9 +127,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectUnallocatedList" parameterType="SysUser" resultMap="SysUserResult">
select distinct u.user_id, uc.com_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, uc.status, u.create_time,uc.is_active is_active
select distinct u.user_id, u.com_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time
from sys_user u
left join sys_user_com uc on u.user_id=uc.user_id
left join sys_dept d on u.dept_id = d.dept_id
left join sys_user_role ur on u.user_id = ur.user_id
left join sys_role r on r.role_id = ur.role_id
@ -182,6 +177,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="checkPhoneUnique" parameterType="String" resultMap="SysUserResult">
select user_id, phonenumber from sys_user where phonenumber = #{phonenumber} and del_flag = '0' limit 1
</select>
<select id="selectByPhone" parameterType="String" resultMap="SysUserResult">
select * from sys_user where phonenumber = #{phonenumber} and del_flag = '0' limit 1
</select>
<select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult">
select user_id, email from sys_user where email = #{email} and del_flag = '0' limit 1
@ -230,8 +228,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="deptId != null and deptId != 0">dept_id = #{deptId},</if>
<if test="userName != null and userName != ''">user_name = #{userName},</if>
<if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
<if test="userType != null ">userType = #{userType},</if>
<if test="cardCode != null ">cardCode = #{cardCode},</if>
<if test="userType != null ">user_Type = #{userType},</if>
<if test="cardCode != null ">card_Code = #{cardCode},</if>
<if test="email != null ">email = #{email},</if>
<if test="phonenumber != null ">phonenumber = #{phonenumber},</if>
<if test="sex != null and sex != ''">sex = #{sex},</if>
@ -282,17 +280,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<insert id="insertUserCom" parameterType="SysUser" >
insert into sys_user(
insert into sys_user_com(
<if test="userId != null and userId != 0">user_id,</if>
<if test="comId != null and comId != 0">com_id,</if>
<if test="status != null and status != 0">status,</if>
<if test="isActive != null and isActive != 0">is_active,</if>
<if test="status != null and status!=''">status,</if>
is_active
)values(
<if test="userId != null and userId != 0">#{userId},</if>
<if test="comId != null and comId != 0">#{comId},</if>
<if test="status != null and status != 0">#{status},</if>
<if test="isActive != null and isActive != ''">#{isActive},</if>
<if test="status != null and status!=''">#{status},</if>
#{isActive}
)
</insert>
<delete id="deleteUserCom" parameterType="SysUser">

View File

@ -159,6 +159,17 @@ public class SysUserController extends BaseController {
return R.ok(sysUserVo);
}
/**
*
* @param phone
* @return
*/
@RequiresPermissions("system:user:list")
@GetMapping("/selectByPhone/{phone}")
public R<SysUser> selectByPhone(@PathVariable("phone") String phone) {
SysUser sysUser = userService.selectByPhone(phone);
return R.ok(sysUser);
}
/**
*
*/
@ -286,13 +297,14 @@ public class SysUserController extends BaseController {
@Log(title = "用户管理", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@Validated @RequestBody SysUser user) {
/*
if (StringUtils.isNotEmpty(user.getUserName()) && !userService.checkUserNameUnique(user)) {
return error("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
} else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
return error("新增用户'" + user.getUserName() + "'失败,手机号码已存在");
} else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
return error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
}
}*/
user.setCreateBy(SecurityUtils.getUsername());
user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
return toAjax(userService.insertUser(user));

View File

@ -0,0 +1,61 @@
package com.yanzhu.system.service;
import java.util.List;
import com.yanzhu.system.domain.SysUserExt;
/**
* Service
*
* @author yanzhu
* @date 2025-01-09
*/
public interface ISysUserExtService
{
/**
*
*
* @param userId
* @return
*/
public SysUserExt selectSysUserExtByUserId(Long userId);
/**
*
*
* @param sysUserExt
* @return
*/
public List<SysUserExt> selectSysUserExtList(SysUserExt sysUserExt);
/**
*
*
* @param sysUserExt
* @return
*/
public int insertSysUserExt(SysUserExt sysUserExt);
/**
*
*
* @param sysUserExt
* @return
*/
public int updateSysUserExt(SysUserExt sysUserExt);
/**
*
*
* @param userIds
* @return
*/
public int deleteSysUserExtByUserIds(Long[] userIds);
/**
*
*
* @param userId
* @return
*/
public int deleteSysUserExtByUserId(Long userId);
}

View File

@ -45,6 +45,12 @@ public interface ISysUserService
*/
public SysUser selectUserByUserName(String userName);
/**
*
* @param phone
* @return
*/
public SysUser selectByPhone(String phone);
/**
*
*

View File

@ -0,0 +1,93 @@
package com.yanzhu.system.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yanzhu.system.mapper.SysUserExtMapper;
import com.yanzhu.system.domain.SysUserExt;
import com.yanzhu.system.service.ISysUserExtService;
/**
* Service
*
* @author yanzhu
* @date 2025-01-09
*/
@Service
public class SysUserExtServiceImpl implements ISysUserExtService
{
@Autowired
private SysUserExtMapper sysUserExtMapper;
/**
*
*
* @param userId
* @return
*/
@Override
public SysUserExt selectSysUserExtByUserId(Long userId)
{
return sysUserExtMapper.selectSysUserExtByUserId(userId);
}
/**
*
*
* @param sysUserExt
* @return
*/
@Override
public List<SysUserExt> selectSysUserExtList(SysUserExt sysUserExt)
{
return sysUserExtMapper.selectSysUserExtList(sysUserExt);
}
/**
*
*
* @param sysUserExt
* @return
*/
@Override
public int insertSysUserExt(SysUserExt sysUserExt)
{
return sysUserExtMapper.insertSysUserExt(sysUserExt);
}
/**
*
*
* @param sysUserExt
* @return
*/
@Override
public int updateSysUserExt(SysUserExt sysUserExt)
{
return sysUserExtMapper.updateSysUserExt(sysUserExt);
}
/**
*
*
* @param userIds
* @return
*/
@Override
public int deleteSysUserExtByUserIds(Long[] userIds)
{
return sysUserExtMapper.deleteSysUserExtByUserIds(userIds);
}
/**
*
*
* @param userId
* @return
*/
@Override
public int deleteSysUserExtByUserId(Long userId)
{
return sysUserExtMapper.deleteSysUserExtByUserId(userId);
}
}

View File

@ -131,6 +131,11 @@ public class SysUserServiceImpl implements ISysUserService
return userMapper.selectUserByUserName(userName);
}
@Override
public SysUser selectByPhone(String phone) {
return userMapper.selectByPhone(phone);
}
/**
*
*
@ -317,7 +322,36 @@ public class SysUserServiceImpl implements ISysUserService
throw new ServiceException("所属单位选择异常,必须选择子公司及下属单位");
}
user.setComId(dept.getComId());
int rows = userMapper.insertUser(user);
int rows=0;
SysUser sysUser = userMapper.selectByPhone(user.getPhonenumber());
if(Objects.nonNull(sysUser)){//此电话号码已注册
SysUser where=new SysUser();
where.setUserId(sysUser.getUserId());
where.setComId(user.getComId());
SysUser oldUserCom=userMapper.selectUserCom(where);
if(Objects.nonNull(oldUserCom)){
throw new ServiceException("此用户己在此项目中!");
}
user.setUserId(sysUser.getUserId());
user.setIsActive(0l);
user.setStatus("0");
userMapper.insertUserCom(user);
sysUser.setUserName(user.getUserName());
sysUser.setPhonenumber(user.getUserName());
sysUser.setNickName(user.getNickName());
sysUser.setUpdateBy(user.getUpdateBy());
sysUser.setUpdateTime(user.getUpdateTime());
sysUser.setPassword(user.getPassword());
rows=userMapper.updateUser(sysUser);
}else{//此电话号码未注册
user.setCreateBy(user.getUpdateBy());
user.setCreateTime(user.getUpdateTime());
user.setUserType("99");
rows=userMapper.insertUser(user);
user.setIsActive(1l);
userMapper.insertUserCom(user);
}
//int rows = userMapper.insertUser(user);
// 新增用户岗位关联
insertUserPost(user);
// 新增用户与角色管理
@ -370,7 +404,7 @@ public class SysUserServiceImpl implements ISysUserService
@Override
public Long registerUser(SysUser user) throws ServiceException
{
SysUser sysUser = userMapper.checkUserNameUnique(user.getUserName());
SysUser sysUser = userMapper.selectByPhone(user.getPhonenumber());
if(Objects.nonNull(sysUser)){
if(user.getComId().equals(sysUser.getOldComId())){
SysUser where=new SysUser();
@ -701,6 +735,7 @@ public class SysUserServiceImpl implements ISysUserService
SysUserPost up = new SysUserPost();
up.setUserId(user.getUserId());
up.setPostId(postId);
list.add(up);
}
userPostMapper.batchUserPost(list);

View File

@ -18,6 +18,15 @@ export function getUser(userId) {
})
}
// 按手机号码查询用户
export function selectByPhone(phone) {
return request({
url: '/system/user/selectByPhone/' + phone,
method: 'get'
})
}
// 新增用户
export function addUser(data) {
return request({

View File

@ -144,7 +144,8 @@
<el-col :span="12">
<el-form-item label="手机号码" prop="phonenumber">
<el-input v-model="form.phonenumber" :disabled="form.userId" placeholder="请输入手机号码"
maxlength="11" />
maxlength="11" style="width: 150px;"/>
<el-button type="primary" style="margin-left: 10px;" @click="doQueryUser"></el-button>
</el-form-item>
</el-col>
<el-col :span="12">
@ -236,7 +237,7 @@
<script setup name="User">
import { getToken } from "@/utils/auth";
import { getDeptRole } from "@/api/system/role";
import { changeUserStatus, listUser, resetUserPwd, delUser, getUser, updateUser, addUser, deptTreeSelect } from "@/api/system/user";
import { changeUserStatus, listUser, resetUserPwd, delUser, getUser, updateUser, addUser,selectByPhone, deptTreeSelect } from "@/api/system/user";
const router = useRouter();
const { proxy } = getCurrentInstance();
@ -331,6 +332,12 @@ function getDeptTree() {
defaultEK.value.push(response.data[0].id);
});
};
//
function doQueryUser(){
selectByPhone(form.value.phonenumber).then(d=>{{
debugger
}});
}
function doRoleChange(){
if(form.value.userType==99){
data.rules={
@ -509,6 +516,7 @@ function handleAdd() {
password: [{ required: true, message: "用户密码不能为空", trigger: "blur" }, { min: 5, max: 20, message: "用户密码长度必须介于 5 和 20 之间", trigger: "blur" }],
phonenumber: [{ required: true, message: "手机号码不能为空", trigger: "blur" }, { pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, message: "请输入正确的手机号码", trigger: "blur" }]
}
roleOptions.value=[];
postOptions.value = response.posts;
open.value = true;
title.value = "添加用户";