浏览代码

用户模块

zhangyang 2 年之前
父节点
当前提交
4f9e293a7c

+ 99 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/PoUserController.java

@@ -0,0 +1,99 @@
+package com.ruoyi.web.controller.system;
+
+import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.page.TableDataInfo;
+import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.system.domain.PoUser;
+import com.ruoyi.system.service.IPoUserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
+/**
+ * 被分配用户Controller
+ *
+ * @author ruoyi
+ * @date 2023-01-17
+ */
+@RestController
+@RequestMapping("/po/user")
+public class PoUserController extends BaseController
+{
+    @Autowired
+    private IPoUserService poUserService;
+
+    /**
+     * 查询用户列表
+     */
+    @PreAuthorize("@ss.hasPermi('post:user:list')")
+    @GetMapping("/list")
+    public TableDataInfo list(PoUser poUser)
+    {
+        startPage();
+        List<PoUser> list = poUserService.selectPoUserList(poUser);
+        return getDataTable(list);
+    }
+
+    /**
+     * 导出用户列表
+     */
+    @PreAuthorize("@ss.hasPermi('post:user:export')")
+    @Log(title = "被分配权限的用户", businessType = BusinessType.EXPORT)
+    @PostMapping("/export")
+    public void export(HttpServletResponse response, PoUser poUser)
+    {
+        List<PoUser> list = poUserService.selectPoUserList(poUser);
+        ExcelUtil<PoUser> util = new ExcelUtil<PoUser>(PoUser.class);
+        util.exportExcel(response, list, "用户数据");
+    }
+
+    /**
+     * 获取用户有权限查到的详细信息
+     */
+    @PreAuthorize("@ss.hasPermi('post:user:query')")
+    @GetMapping(value = "/{userId}")
+    public AjaxResult getInfo(@PathVariable("userId") String userId)
+    {
+        return success(poUserService.selectPoUserByUserId(userId));
+    }
+
+    /**
+     * 新增分配权限用户
+     */
+    @PreAuthorize("@ss.hasPermi('post:user:add')")
+    @Log(title = "获得权限用户", businessType = BusinessType.INSERT)
+    @PostMapping("/add")
+    public AjaxResult add(@RequestBody PoUser poUser)
+    {
+        return toAjax(poUserService.insertPoUser(poUser));
+    }
+
+    /**
+     * 修改用户
+     */
+    @PreAuthorize("@ss.hasPermi('post:user:edit')")
+    @Log(title = "修改权限用户", businessType = BusinessType.UPDATE)
+    @PutMapping("/edit")
+    public AjaxResult edit(@RequestBody PoUser poUser)
+    {
+        return toAjax(poUserService.updatePoUser(poUser));
+    }
+
+    /**
+     * 删除用户
+     */
+    @PreAuthorize("@ss.hasPermi('po:user:remove')")
+    @Log(title = "删除权限用户", businessType = BusinessType.DELETE)
+    @DeleteMapping("/{userIds}")
+    public AjaxResult remove(@PathVariable String[] userIds)
+    {
+        return toAjax(poUserService.deletePoUserByUserIds(userIds));
+    }
+}
+

+ 228 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/PoUser.java

@@ -0,0 +1,228 @@
+package com.ruoyi.system.domain;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.ruoyi.common.annotation.Excel;
+import com.ruoyi.common.core.domain.BaseEntity;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+
+import java.util.Date;
+
+/**
+ * 被分配用户对象 po_user
+ *
+ * @author ruoyi
+ * @date 2023-01-17
+ */
+public class PoUser extends BaseEntity
+{
+    private static final long serialVersionUID = 1L;
+
+    /** 用户Id */
+    private String userId;
+
+    /** 部门id */
+    @Excel(name = "部门id")
+    private String deptId;
+
+    /** 用户账号 */
+    @Excel(name = "用户账号")
+    private String userName;
+
+    /** 用户昵称 */
+    @Excel(name = "用户昵称")
+    private String nickName;
+
+    /** 用户类型(00系统用户) */
+    @Excel(name = "用户类型", readConverterExp = "0=0系统用户")
+    private String userType;
+
+    /** 用户邮箱 */
+    @Excel(name = "用户邮箱")
+    private String email;
+
+    /** 电话号码 */
+    @Excel(name = "电话号码")
+    private String phonenumber;
+
+    /** 性别(0男 1女 2未知) */
+    @Excel(name = "性别", readConverterExp = "0=男,1=女,2=未知")
+    private String sex;
+
+    /** 头像地址 */
+    @Excel(name = "头像地址")
+    private String avatar;
+
+    /** 用户密码 */
+    @Excel(name = "用户密码")
+    private String password;
+
+    /** 用户状态 */
+    @Excel(name = "用户状态")
+    private String status;
+
+    /** 逻辑删除(0未删除 2删除) */
+    private String delFlag;
+
+    /** 最后登陆ip */
+    @Excel(name = "最后登陆ip")
+    private String loginIp;
+
+    /** 最后登陆时间 */
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    @Excel(name = "最后登陆时间", width = 30, dateFormat = "yyyy-MM-dd")
+    private Date loginDate;
+
+    public void setUserId(String userId)
+    {
+        this.userId = userId;
+    }
+
+    public String getUserId()
+    {
+        return userId;
+    }
+    public void setDeptId(String deptId)
+    {
+        this.deptId = deptId;
+    }
+
+    public String getDeptId()
+    {
+        return deptId;
+    }
+    public void setUserName(String userName)
+    {
+        this.userName = userName;
+    }
+
+    public String getUserName()
+    {
+        return userName;
+    }
+    public void setNickName(String nickName)
+    {
+        this.nickName = nickName;
+    }
+
+    public String getNickName()
+    {
+        return nickName;
+    }
+    public void setUserType(String userType)
+    {
+        this.userType = userType;
+    }
+
+    public String getUserType()
+    {
+        return userType;
+    }
+    public void setEmail(String email)
+    {
+        this.email = email;
+    }
+
+    public String getEmail()
+    {
+        return email;
+    }
+    public void setPhonenumber(String phonenumber)
+    {
+        this.phonenumber = phonenumber;
+    }
+
+    public String getPhonenumber()
+    {
+        return phonenumber;
+    }
+    public void setSex(String sex)
+    {
+        this.sex = sex;
+    }
+
+    public String getSex()
+    {
+        return sex;
+    }
+    public void setAvatar(String avatar)
+    {
+        this.avatar = avatar;
+    }
+
+    public String getAvatar()
+    {
+        return avatar;
+    }
+    public void setPassword(String password)
+    {
+        this.password = password;
+    }
+
+    public String getPassword()
+    {
+        return password;
+    }
+    public void setStatus(String status)
+    {
+        this.status = status;
+    }
+
+    public String getStatus()
+    {
+        return status;
+    }
+    public void setDelFlag(String delFlag)
+    {
+        this.delFlag = delFlag;
+    }
+
+    public String getDelFlag()
+    {
+        return delFlag;
+    }
+    public void setLoginIp(String loginIp)
+    {
+        this.loginIp = loginIp;
+    }
+
+    public String getLoginIp()
+    {
+        return loginIp;
+    }
+    public void setLoginDate(Date loginDate)
+    {
+        this.loginDate = loginDate;
+    }
+
+    public Date getLoginDate()
+    {
+        return loginDate;
+    }
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
+                .append("userId", getUserId())
+                .append("deptId", getDeptId())
+                .append("userName", getUserName())
+                .append("nickName", getNickName())
+                .append("userType", getUserType())
+                .append("email", getEmail())
+                .append("phonenumber", getPhonenumber())
+                .append("sex", getSex())
+                .append("avatar", getAvatar())
+                .append("password", getPassword())
+                .append("status", getStatus())
+                .append("delFlag", getDelFlag())
+                .append("loginIp", getLoginIp())
+                .append("loginDate", getLoginDate())
+                .append("createBy", getCreateBy())
+                .append("createTime", getCreateTime())
+                .append("updateBy", getUpdateBy())
+                .append("updateTime", getUpdateTime())
+                .append("remark", getRemark())
+                .toString();
+    }
+}
+

+ 62 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/PoUserMapper.java

@@ -0,0 +1,62 @@
+package com.ruoyi.system.mapper;
+
+import com.ruoyi.system.domain.PoUser;
+
+import java.util.List;
+
+/**
+ * 用户Mapper接口
+ *
+ * @author ruoyi
+ * @date 2023-01-17
+ */
+public interface PoUserMapper
+{
+    /**
+     * 查询用户
+     *
+     * @param userId 用户主键
+     * @return 用户
+     */
+    public PoUser selectPoUserByUserId(String userId);
+
+    /**
+     * 查询用户列表
+     *
+     * @param poUser 用户
+     * @return 用户集合
+     */
+    public List<PoUser> selectPoUserList(PoUser poUser);
+
+    /**
+     * 新增用户
+     *
+     * @param poUser 用户
+     * @return 结果
+     */
+    public int insertPoUser(PoUser poUser);
+
+    /**
+     * 修改用户
+     *
+     * @param poUser 用户
+     * @return 结果
+     */
+    public int updatePoUser(PoUser poUser);
+
+    /**
+     * 删除用户
+     *
+     * @param userId 用户主键
+     * @return 结果
+     */
+    public int deletePoUserByUserId(String userId);
+
+    /**
+     * 批量删除用户
+     *
+     * @param userIds 需要删除的数据主键集合
+     * @return 结果
+     */
+    public int deletePoUserByUserIds(String[] userIds);
+}

+ 62 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/IPoUserService.java

@@ -0,0 +1,62 @@
+package com.ruoyi.system.service;
+
+import com.ruoyi.system.domain.PoUser;
+
+import java.util.List;
+
+/**
+ * 用户Service接口
+ *
+ * @author ruoyi
+ * @date 2023-01-17
+ */
+public interface IPoUserService
+{
+    /**
+     * 查询用户
+     *
+     * @param userId 用户主键
+     * @return 用户
+     */
+    public PoUser selectPoUserByUserId(String userId);
+
+    /**
+     * 查询用户列表
+     *
+     * @param poUser 用户
+     * @return 用户集合
+     */
+    public List<PoUser> selectPoUserList(PoUser poUser);
+
+    /**
+     * 新增用户
+     *
+     * @param poUser 用户
+     * @return 结果
+     */
+    public int insertPoUser(PoUser poUser);
+
+    /**
+     * 修改用户
+     *
+     * @param poUser 用户
+     * @return 结果
+     */
+    public int updatePoUser(PoUser poUser);
+
+    /**
+     * 批量删除用户
+     *
+     * @param userIds 需要删除的用户主键集合
+     * @return 结果
+     */
+    public int deletePoUserByUserIds(String[] userIds);
+
+    /**
+     * 删除用户信息
+     *
+     * @param userId 用户主键
+     * @return 结果
+     */
+    public int deletePoUserByUserId(String userId);
+}

+ 97 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PoUserServiceImpl.java

@@ -0,0 +1,97 @@
+package com.ruoyi.system.service.impl;
+
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.system.domain.PoUser;
+import com.ruoyi.system.mapper.PoUserMapper;
+import com.ruoyi.system.service.IPoUserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * 用户Service业务层处理
+ *
+ * @author ruoyi
+ * @date 2023-01-17
+ */
+@Service
+public class PoUserServiceImpl implements IPoUserService
+{
+    @Autowired
+    private PoUserMapper poUserMapper;
+
+    /**
+     * 查询用户
+     *
+     * @param userId 用户主键
+     * @return 用户
+     */
+    @Override
+    public PoUser selectPoUserByUserId(String userId)
+    {
+        return poUserMapper.selectPoUserByUserId(userId);
+    }
+
+    /**
+     * 查询用户列表
+     *
+     * @param poUser 用户
+     * @return 用户
+     */
+    @Override
+    public List<PoUser> selectPoUserList(PoUser poUser)
+    {
+        return poUserMapper.selectPoUserList(poUser);
+    }
+
+    /**
+     * 新增用户
+     *
+     * @param poUser 用户
+     * @return 结果
+     */
+    @Override
+    public int insertPoUser(PoUser poUser)
+    {
+        poUser.setCreateTime(DateUtils.getNowDate());
+        return poUserMapper.insertPoUser(poUser);
+    }
+
+    /**
+     * 修改用户
+     *
+     * @param poUser 用户
+     * @return 结果
+     */
+    @Override
+    public int updatePoUser(PoUser poUser)
+    {
+        poUser.setUpdateTime(DateUtils.getNowDate());
+        return poUserMapper.updatePoUser(poUser);
+    }
+
+    /**
+     * 批量删除用户
+     *
+     * @param userIds 需要删除的用户主键
+     * @return 结果
+     */
+    @Override
+    public int deletePoUserByUserIds(String[] userIds)
+    {
+        return poUserMapper.deletePoUserByUserIds(userIds);
+    }
+
+    /**
+     * 删除用户信息
+     *
+     * @param userId 用户主键
+     * @return 结果
+     */
+    @Override
+    public int deletePoUserByUserId(String userId)
+    {
+        return poUserMapper.deletePoUserByUserId(userId);
+    }
+}

+ 138 - 0
ruoyi-system/src/main/resources/mapper/system/PoUserMapper.xml

@@ -0,0 +1,138 @@
+<?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.ruoyi.system.mapper.PoUserMapper">
+
+    <resultMap type="PoUser" id="PoUserResult">
+        <result property="userId"    column="user_id"    />
+        <result property="deptId"    column="dept_id"    />
+        <result property="userName"    column="user_name"    />
+        <result property="nickName"    column="nick_name"    />
+        <result property="userType"    column="user_type"    />
+        <result property="email"    column="email"    />
+        <result property="phonenumber"    column="phonenumber"    />
+        <result property="sex"    column="sex"    />
+        <result property="avatar"    column="avatar"    />
+        <result property="password"    column="password"    />
+        <result property="status"    column="status"    />
+        <result property="delFlag"    column="del_flag"    />
+        <result property="loginIp"    column="login_ip"    />
+        <result property="loginDate"    column="login_date"    />
+        <result property="createBy"    column="create_by"    />
+        <result property="createTime"    column="create_time"    />
+        <result property="updateBy"    column="update_by"    />
+        <result property="updateTime"    column="update_time"    />
+        <result property="remark"    column="remark"    />
+    </resultMap>
+
+    <sql id="selectPoUserVo">
+        select user_id, dept_id, user_name, nick_name, user_type, email, phonenumber, sex, avatar, password, status, del_flag, login_ip, login_date, create_by, create_time, update_by, update_time, remark from po_user
+    </sql>
+
+    <select id="selectPoUserList" parameterType="PoUser" resultMap="PoUserResult">
+        <include refid="selectPoUserVo"/>
+        <where>
+            <if test="deptId != null "> and dept_id = #{deptId}</if>
+            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
+            <if test="nickName != null  and nickName != ''"> and nick_name like concat('%', #{nickName}, '%')</if>
+            <if test="userType != null  and userType != ''"> and user_type = #{userType}</if>
+            <if test="email != null  and email != ''"> and email = #{email}</if>
+            <if test="phonenumber != null  and phonenumber != ''"> and phonenumber = #{phonenumber}</if>
+            <if test="sex != null  and sex != ''"> and sex = #{sex}</if>
+            <if test="avatar != null  and avatar != ''"> and avatar = #{avatar}</if>
+            <if test="password != null  and password != ''"> and password = #{password}</if>
+            <if test="status != null  and status != ''"> and status = #{status}</if>
+            <if test="loginIp != null  and loginIp != ''"> and login_ip = #{loginIp}</if>
+            <if test="loginDate != null "> and login_date = #{loginDate}</if>
+        </where>
+    </select>
+
+    <select id="selectPoUserByUserId" parameterType="String" resultMap="PoUserResult">
+        <include refid="selectPoUserVo"/>
+        where user_id = #{userId}
+    </select>
+
+    <insert id="insertPoUser" parameterType="PoUser">
+        insert into po_user
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="userId != null">user_id,</if>
+            <if test="deptId != null">dept_id,</if>
+            <if test="userName != null and userName != ''">user_name,</if>
+            <if test="nickName != null and nickName != ''">nick_name,</if>
+            <if test="userType != null">user_type,</if>
+            <if test="email != null">email,</if>
+            <if test="phonenumber != null">phonenumber,</if>
+            <if test="sex != null">sex,</if>
+            <if test="avatar != null">avatar,</if>
+            <if test="password != null">password,</if>
+            <if test="status != null">status,</if>
+            <if test="delFlag != null">del_flag,</if>
+            <if test="loginIp != null">login_ip,</if>
+            <if test="loginDate != null">login_date,</if>
+            <if test="createBy != null">create_by,</if>
+            <if test="createTime != null">create_time,</if>
+            <if test="updateBy != null">update_by,</if>
+            <if test="updateTime != null">update_time,</if>
+            <if test="remark != null">remark,</if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="userId != null">#{userId},</if>
+            <if test="deptId != null">#{deptId},</if>
+            <if test="userName != null and userName != ''">#{userName},</if>
+            <if test="nickName != null and nickName != ''">#{nickName},</if>
+            <if test="userType != null">#{userType},</if>
+            <if test="email != null">#{email},</if>
+            <if test="phonenumber != null">#{phonenumber},</if>
+            <if test="sex != null">#{sex},</if>
+            <if test="avatar != null">#{avatar},</if>
+            <if test="password != null">#{password},</if>
+            <if test="status != null">#{status},</if>
+            <if test="delFlag != null">#{delFlag},</if>
+            <if test="loginIp != null">#{loginIp},</if>
+            <if test="loginDate != null">#{loginDate},</if>
+            <if test="createBy != null">#{createBy},</if>
+            <if test="createTime != null">#{createTime},</if>
+            <if test="updateBy != null">#{updateBy},</if>
+            <if test="updateTime != null">#{updateTime},</if>
+            <if test="remark != null">#{remark},</if>
+        </trim>
+    </insert>
+
+    <update id="updatePoUser" parameterType="PoUser">
+        update po_user
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="deptId != null">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">user_type = #{userType},</if>
+            <if test="email != null">email = #{email},</if>
+            <if test="phonenumber != null">phonenumber = #{phonenumber},</if>
+            <if test="sex != null">sex = #{sex},</if>
+            <if test="avatar != null">avatar = #{avatar},</if>
+            <if test="password != null">password = #{password},</if>
+            <if test="status != null">status = #{status},</if>
+            <if test="delFlag != null">del_flag = #{delFlag},</if>
+            <if test="loginIp != null">login_ip = #{loginIp},</if>
+            <if test="loginDate != null">login_date = #{loginDate},</if>
+            <if test="createBy != null">create_by = #{createBy},</if>
+            <if test="createTime != null">create_time = #{createTime},</if>
+            <if test="updateBy != null">update_by = #{updateBy},</if>
+            <if test="updateTime != null">update_time = #{updateTime},</if>
+            <if test="remark != null">remark = #{remark},</if>
+        </trim>
+        where user_id = #{userId}
+    </update>
+
+    <delete id="deletePoUserByUserId" parameterType="String">
+        delete from po_user where user_id = #{userId}
+    </delete>
+
+    <delete id="deletePoUserByUserIds" parameterType="String">
+        delete from po_user where user_id in
+        <foreach item="userId" collection="array" open="(" separator="," close=")">
+            #{userId}
+        </foreach>
+    </delete>
+</mapper>
+