package com.xkrs.dao; import com.xkrs.model.entity.SysUserEntity; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Component; import java.util.List; @Component public interface SysUserDao extends JpaRepository, JpaSpecificationExecutor { @Modifying(clearAutomatically = true) @Query(value = "UPDATE sys_user SET receive_sms = ?2 WHERE id = ?1", nativeQuery = true) void updateReceiveSms(Long id, Integer receiveSms); /** * 检查系统用户名是否存在 */ @Query(value = "SELECT COUNT(*) FROM sys_user WHERE user_name = :userName", nativeQuery = true) int checkUserName(@Param("userName") String userName); /** * 查找用户实体根据用户名 */ @Query(value = "SELECT * FROM sys_user WHERE user_name = :userName", nativeQuery = true) SysUserEntity selectByUserName(@Param("userName") String userName); @Query(value = "SELECT * FROM sys_user ORDER BY id DESC LIMIT ?1 OFFSET ?2", nativeQuery = true) List selectUser(int limit, int offset); /** * 删除系统用户(危险操作!) */ @Modifying @Query(value = "DELETE FROM sys_user WHERE user_name = :userName ;", nativeQuery = true) int deleteSysUser(@Param("userName") String userName); /** * 启用 */ @Query(value = "update sys_user set active_flag = 0 where id = ?", nativeQuery = true) @Modifying(clearAutomatically = true) void updateEnable(Long userId); /** * 禁用 */ @Query(value = "update sys_user set active_flag = 1 where id = ?", nativeQuery = true) @Modifying(clearAutomatically = true) void updateDisable(Long userId); /** * 用户修改密码 */ @Query(value = "update sys_user set password = ?2 where id = ?1", nativeQuery = true) @Modifying(clearAutomatically = true) void updatePassword(Long userId, String newPassword); /** * 修改用户登录次数 */ @Query(value = "update sys_user set login_num = ?2 where id = ?1", nativeQuery = true) @Modifying(clearAutomatically = true) void updateLoginNum(Long userId, Integer loginNum); /** * 修改最后登录时间 */ @Query(value = "update sys_user set login_last_time = ?2 where id = ?1", nativeQuery = true) @Modifying(clearAutomatically = true) void updateLoginLastTime(Long userId, String loginLastTime); }