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

137 lines
4.8 KiB
Java

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> {
@Modifying(clearAutomatically = true)
@Query(value = "UPDATE sys_user SET vip_level = ?2 WHERE id = ?1", nativeQuery = true)
void updateVipLevel(Integer id, Integer vipLevel);
@Modifying(clearAutomatically = true)
@Query(value = "UPDATE sys_user SET receive_sms = ?2 WHERE id = ?1", nativeQuery = true)
void updateReceiveSms(Integer id, Integer receiveSms);
@Modifying(clearAutomatically = true)
@Query(value = "UPDATE sys_user SET remark = ?2 WHERE id = ?1", nativeQuery = true)
void updateRemark(Integer id, String remark);
/**
* 检查系统用户名是否存在
*/
@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);
/**
* 根据用户名查询用户信息
*/
SysUserEntity findByUserName(String userName);
/**
* 更新用户登录信息
*/
@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);
/**
* 软删除系统用户根据id
*/
@Modifying
@Query(value = "UPDATE sys_user SET delete_flag = 1 " + "WHERE id = :id ;", nativeQuery = true)
int softDeleteGeneralUserById(@Param("id") Integer id);
/**
* 删除系统用户(危险操作!)
*/
@Modifying
@Query(value = "DELETE FROM sys_user WHERE user_name = :userName ;", nativeQuery = true)
int deleteSysUser(@Param("userName") String userName);
/**
* 查询用户信息
*/
@Query(value = "select new com.xkrs.model.vo.SysUserVo (id,reallyName,telephone,countyCode,activeFlag,addTime,overTime,dayNum,accountType,countyName,lastEntryIp,loginNum,loginLastTime,vipLevel,receiveSms,remark,agentOrgId) from SysUserEntity")
List<SysUserVo> selectAll();
/**
* 根据用户名查询实体信息
*/
@Query(value = "select new com.xkrs.model.vo.SysUserVo (id,reallyName,telephone,countyCode,activeFlag,addTime,overTime,dayNum,accountType,countyName,lastEntryIp,loginNum,loginLastTime,vipLevel,receiveSms,remark,agentOrgId) from SysUserEntity where userName = :userName")
SysUserVo selectUserByUserName(String userName);
/**
* 启用
*/
@Query(value = "update sys_user set active_flag = 0 where id = ?", nativeQuery = true)
@Modifying(clearAutomatically = true)
void updateEnable(Integer userId);
/**
* 禁用
*/
@Query(value = "update sys_user set active_flag = 1 where id = ?", nativeQuery = true)
@Modifying(clearAutomatically = true)
void updateDisable(Integer userId);
/**
* 用户修改密码
*/
@Query(value = "update sys_user set password = ?2 where id = ?1", nativeQuery = true)
@Modifying(clearAutomatically = true)
void updatePassword(Integer userId, String newPassword);
/**
* 根据id查询用户的信息
*/
@Query(value = "select * from sys_user where id = ?", nativeQuery = true)
SysUserEntity selectByUserId(Integer userId);
/**
* 根据id修改账户的到期时间
*/
@Query(value = "update sys_user set over_time = ?2 where id = ?1", nativeQuery = true)
@Modifying(clearAutomatically = true)
void updateOverTime(Integer userId, String overTime);
/**
* 将账户的期限修改为永久有效
*/
@Query(value = "update sys_user set over_time = '永久' and day_num = 1 where id = ?", nativeQuery = true)
@Modifying(clearAutomatically = true)
void updateDayNum(Integer userId);
/**
* 记录用户登录次数
*/
@Query(value = "update sys_user set login_num = ?2 where id = ?1", nativeQuery = true)
@Modifying(clearAutomatically = true)
void updateLoginNum(Integer userId, Integer loginNum);
/**
* 修改登陆时间
*/
@Query(value = "update sys_user set login_last_time = ?2 where id = ?1", nativeQuery = true)
@Modifying(clearAutomatically = true)
void updateLoginLastTime(Integer userId, String loginLastTime);
}