package com.xly.erp.module.usr.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xly.erp.module.usr.entity.User;
import com.xly.erp.module.usr.vo.UserListVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

public interface UserMapper extends BaseMapper<User> {

    @Select("SELECT iIncrement, sId, sBrandsId, sSubsidiaryId, tCreateDate, sUserNo, sUserName, "
            + "iStaffId, sUserType, sLanguage, bCanModifyDocs, sPasswordHash, tLastLoginDate, "
            + "sCreatedBy, bDeleted, tDeletedDate, sDeletedBy "
            + "FROM tUser WHERE sUserName = #{name} LIMIT 1")
    User selectByUserName(@Param("name") String name);

    @Update("UPDATE tUser SET tLastLoginDate = #{ts} WHERE iIncrement = #{id}")
    int updateLastLoginDate(@Param("id") Integer id, @Param("ts") LocalDateTime ts);


    List<UserListVO> pageWithFilter(@Param("field") String field,
                                    @Param("matchOp") String matchOp,
                                    @Param("value") Object value,
                                    @Param("offset") int offset,
                                    @Param("size") int size);

    long countWithFilter(@Param("field") String field,
                         @Param("matchOp") String matchOp,
                         @Param("value") Object value);

    UserListVO selectDetailById(@Param("id") Integer id);
}
