xkrs_work/src/main/java/com/xkrs/dao/SysUserDao.java

147 lines
4.3 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.xkrs.dao;
import com.xkrs.model.entity.SysUserEntity;
import com.xkrs.model.vo.SysUserVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
/**
* SysUserDao
* @author tajochen
*/
public interface SysUserDao extends JpaRepository<SysUserEntity,Integer> {
/**
* 检查系统用户名是否存在
* @param userName
* @return
*/
@Query(value = "SELECT COUNT(*) FROM sys_user WHERE user_name = :userName", nativeQuery = true)
int checkUserName(@Param("userName") String userName);
/**
* 查找用户实体根据用户名
* @param userName
* @return
*/
@Query(value = "SELECT * FROM sys_user WHERE user_name = :userName", nativeQuery = true)
SysUserEntity selectByUserName(@Param("userName") String userName);
/**
* 根据用户名查询用户信息
* @param userName
* @return
*/
SysUserEntity findByUserName(String userName);
/**
* 更新用户登录信息
* @param userName
* @param ipAddress
* @return
*/
@Modifying
@Query(value = "UPDATE sys_user SET last_entry_time = now(), last_entry_ip = :ipAddress " +
"WHERE user_name = :userName ;", nativeQuery = true)
int updateSysUserLogin(@Param("userName") String userName, @Param("ipAddress") String ipAddress);
/**
* 软删除系统用户根据用户名
* @param userName
* @return
*/
@Modifying
@Query(value = "UPDATE sys_user SET delete_flag = 1 " +
"WHERE user_name = :userName ;", nativeQuery = true)
int softDeleteSysUserByUserName(@Param("userName") String userName);
/**
* 软删除系统用户根据id
* @param id
* @return
*/
@Modifying
@Query(value = "UPDATE sys_user SET delete_flag = 1 " +
"WHERE id = :id ;", nativeQuery = true)
int softDeleteGeneralUserById(@Param("id") Integer id);
/**
* 删除系统用户(危险操作!)
* @param userName
* @return
*/
@Modifying
@Query(value = "DELETE FROM sys_user WHERE user_name = :userName ;", nativeQuery = true)
int deleteSysUser(@Param("userName") String userName);
/**
* 查询用户信息
* @return
*/
@Query(value = "select new com.xkrs.model.vo.SysUserVo (id,reallyName,telephone,userDepartment,activeFlag,addTime) " +
"from SysUserEntity")
List<SysUserVo> selectAll();
/**
* 根据用户名查询实体信息
* @param userName
* @return
*/
@Query(value = "select new com.xkrs.model.vo.SysUserVo (id,reallyName,telephone,userDepartment,activeFlag,addTime) " +
"from SysUserEntity where userName = :userName")
SysUserVo selectUserByUserName(String userName);
/**
* 启用
* @param userId
*/
@Query(value = "update sys_user set active_flag = 0 where id = ?",nativeQuery = true)
@Modifying(clearAutomatically=true)
void updateEnable(Integer userId);
/**
* 禁用
* @param userId
*/
@Query(value = "update sys_user set active_flag = 1 where id = ?",nativeQuery = true)
@Modifying(clearAutomatically=true)
void updateDisable(Integer userId);
/**
* 用户修改密码
* @param userId
* @param newPassword
*/
@Query(value = "update sys_user set password = ?2 where id = ?1",nativeQuery = true)
@Modifying(clearAutomatically=true)
void updatePassword(Integer userId,String newPassword);
/**
* 根据id查询用户的信息
* @param userId
* @return
*/
@Query(value = "select * from sys_user where id = ?",nativeQuery = true)
SysUserEntity selectByUserId(Integer userId);
/**
* 根据openId查询用户的信息
* @param openId
* @return
*/
SysUserEntity findByOpenId(String openId);
/**
* 根据用户名手机号修改openid
* @param userName
* @param openId
*/
@Query(value = "update sys_user set open_id = ?2 where user_name = ?1",nativeQuery = true)
@Modifying(clearAutomatically=true)
void updateOpenIdByPhone(String userName,String openId);
}