diff --git a/backend/src/main/java/com/xly/erp/module/usr/mapper/UserMapper.java b/backend/src/main/java/com/xly/erp/module/usr/mapper/UserMapper.java index e8aa0ba..f65f759 100644 --- a/backend/src/main/java/com/xly/erp/module/usr/mapper/UserMapper.java +++ b/backend/src/main/java/com/xly/erp/module/usr/mapper/UserMapper.java @@ -4,11 +4,24 @@ 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 { + @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 pageWithFilter(@Param("field") String field, @Param("matchOp") String matchOp, @Param("value") Object value, diff --git a/backend/src/test/java/com/xly/erp/module/usr/mapper/UserMapperIT.java b/backend/src/test/java/com/xly/erp/module/usr/mapper/UserMapperIT.java index 9e8cc40..4951c8a 100644 --- a/backend/src/test/java/com/xly/erp/module/usr/mapper/UserMapperIT.java +++ b/backend/src/test/java/com/xly/erp/module/usr/mapper/UserMapperIT.java @@ -94,6 +94,33 @@ class UserMapperIT { } @Test + void selectByUserName_returnsRowOrNull() { + User u = newUser("sp_test_byname", "命名用户"); + userMapper.insert(u); + + User loaded = userMapper.selectByUserName("命名用户"); + assertThat(loaded).isNotNull(); + assertThat(loaded.getSUserNo()).isEqualTo("sp_test_byname"); + + assertThat(userMapper.selectByUserName("不存在的用户名XYZ")).isNull(); + } + + @Test + void updateLastLoginDate_setsValue() { + User u = newUser("sp_test_lastlogin", "登录日期用户"); + userMapper.insert(u); + java.time.LocalDateTime ts = java.time.LocalDateTime.of(2026, 4, 30, 10, 0, 0); + + int rows = userMapper.updateLastLoginDate(u.getIIncrement(), ts); + assertThat(rows).isEqualTo(1); + + java.sql.Timestamp loaded = jdbcTemplate.queryForObject( + "SELECT tLastLoginDate FROM tUser WHERE iIncrement = ?", java.sql.Timestamp.class, u.getIIncrement()); + assertThat(loaded).isNotNull(); + assertThat(loaded.toLocalDateTime()).isEqualTo(ts); + } + + @Test void pageWithFilter_filtersAndJoins() { jdbcTemplate.update( "INSERT INTO tStaff (sBrandsId, sSubsidiaryId, tCreateDate, sStaffNo, sStaffName, sDepartment, "