Commit 9c6dcd52ff6746b12ccb417010db6d3b752f1e1f

Authored by zichun
1 parent d06c610a

feat(usr): mapper selectByUserName + updateLastLoginDate REQ-USR-004

backend/src/main/java/com/xly/erp/module/usr/mapper/UserMapper.java
@@ -4,11 +4,24 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; @@ -4,11 +4,24 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4 import com.xly.erp.module.usr.entity.User; 4 import com.xly.erp.module.usr.entity.User;
5 import com.xly.erp.module.usr.vo.UserListVO; 5 import com.xly.erp.module.usr.vo.UserListVO;
6 import org.apache.ibatis.annotations.Param; 6 import org.apache.ibatis.annotations.Param;
  7 +import org.apache.ibatis.annotations.Select;
  8 +import org.apache.ibatis.annotations.Update;
7 9
  10 +import java.time.LocalDateTime;
8 import java.util.List; 11 import java.util.List;
9 12
10 public interface UserMapper extends BaseMapper<User> { 13 public interface UserMapper extends BaseMapper<User> {
11 14
  15 + @Select("SELECT iIncrement, sId, sBrandsId, sSubsidiaryId, tCreateDate, sUserNo, sUserName, "
  16 + + "iStaffId, sUserType, sLanguage, bCanModifyDocs, sPasswordHash, tLastLoginDate, "
  17 + + "sCreatedBy, bDeleted, tDeletedDate, sDeletedBy "
  18 + + "FROM tUser WHERE sUserName = #{name} LIMIT 1")
  19 + User selectByUserName(@Param("name") String name);
  20 +
  21 + @Update("UPDATE tUser SET tLastLoginDate = #{ts} WHERE iIncrement = #{id}")
  22 + int updateLastLoginDate(@Param("id") Integer id, @Param("ts") LocalDateTime ts);
  23 +
  24 +
12 List<UserListVO> pageWithFilter(@Param("field") String field, 25 List<UserListVO> pageWithFilter(@Param("field") String field,
13 @Param("matchOp") String matchOp, 26 @Param("matchOp") String matchOp,
14 @Param("value") Object value, 27 @Param("value") Object value,
backend/src/test/java/com/xly/erp/module/usr/mapper/UserMapperIT.java
@@ -94,6 +94,33 @@ class UserMapperIT { @@ -94,6 +94,33 @@ class UserMapperIT {
94 } 94 }
95 95
96 @Test 96 @Test
  97 + void selectByUserName_returnsRowOrNull() {
  98 + User u = newUser("sp_test_byname", "命名用户");
  99 + userMapper.insert(u);
  100 +
  101 + User loaded = userMapper.selectByUserName("命名用户");
  102 + assertThat(loaded).isNotNull();
  103 + assertThat(loaded.getSUserNo()).isEqualTo("sp_test_byname");
  104 +
  105 + assertThat(userMapper.selectByUserName("不存在的用户名XYZ")).isNull();
  106 + }
  107 +
  108 + @Test
  109 + void updateLastLoginDate_setsValue() {
  110 + User u = newUser("sp_test_lastlogin", "登录日期用户");
  111 + userMapper.insert(u);
  112 + java.time.LocalDateTime ts = java.time.LocalDateTime.of(2026, 4, 30, 10, 0, 0);
  113 +
  114 + int rows = userMapper.updateLastLoginDate(u.getIIncrement(), ts);
  115 + assertThat(rows).isEqualTo(1);
  116 +
  117 + java.sql.Timestamp loaded = jdbcTemplate.queryForObject(
  118 + "SELECT tLastLoginDate FROM tUser WHERE iIncrement = ?", java.sql.Timestamp.class, u.getIIncrement());
  119 + assertThat(loaded).isNotNull();
  120 + assertThat(loaded.toLocalDateTime()).isEqualTo(ts);
  121 + }
  122 +
  123 + @Test
97 void pageWithFilter_filtersAndJoins() { 124 void pageWithFilter_filtersAndJoins() {
98 jdbcTemplate.update( 125 jdbcTemplate.update(
99 "INSERT INTO tStaff (sBrandsId, sSubsidiaryId, tCreateDate, sStaffNo, sStaffName, sDepartment, " 126 "INSERT INTO tStaff (sBrandsId, sSubsidiaryId, tCreateDate, sStaffNo, sStaffName, sDepartment, "