155 lines
4.8 KiB
Markdown
155 lines
4.8 KiB
Markdown
# 用户档案导入问题修复说明
|
||
|
||
## 问题描述
|
||
|
||
用户在导入用户档案数据时,明明某些用户已被删除(在系统中看不到),但系统仍提示"用户已存在",导致无法正常导入。
|
||
|
||
## 问题原因
|
||
|
||
在 `PsyUserProfileMapper.xml` 中,多个档案查询方法缺少对已删除用户的过滤条件:
|
||
|
||
1. **`selectProfilesByInfoNumbers`** - 批量查询档案(导入时使用)
|
||
2. **`selectProfileByInfoNumber`** - 根据信息编号查询(唯一性验证时使用)
|
||
3. **`selectProfileById`** - 根据档案ID查询
|
||
4. **`selectProfileByUserId`** - 根据用户ID查询
|
||
|
||
这些查询没有添加 `u.del_flag = '0'` 过滤条件,导致:
|
||
- 当用户被删除(`del_flag = '2'`)后,在列表中看不到(列表查询有过滤)
|
||
- 但导入时仍能查到这些已删除用户的档案(导入查询无过滤)
|
||
- 系统误判为"用户已存在",拒绝导入
|
||
|
||
## 修复内容
|
||
|
||
### 1. 修复 `selectProfilesByInfoNumbers`(批量查询)
|
||
|
||
**位置**: `PsyUserProfileMapper.xml` 第279-288行
|
||
|
||
```xml
|
||
<!-- 修复前 -->
|
||
<select id="selectProfilesByInfoNumbers" resultMap="PsyUserProfileResult">
|
||
<include refid="selectProfileVo"/>
|
||
from psy_user_profile p
|
||
left join sys_user u on p.user_id = u.user_id
|
||
where p.info_number in
|
||
<foreach item="infoNumber" collection="list" open="(" separator="," close=")">
|
||
#{infoNumber}
|
||
</foreach>
|
||
</select>
|
||
|
||
<!-- 修复后 -->
|
||
<select id="selectProfilesByInfoNumbers" resultMap="PsyUserProfileResult">
|
||
<include refid="selectProfileVo"/>
|
||
from psy_user_profile p
|
||
left join sys_user u on p.user_id = u.user_id
|
||
where u.del_flag = '0'
|
||
and p.info_number in
|
||
<foreach item="infoNumber" collection="list" open="(" separator="," close=")">
|
||
#{infoNumber}
|
||
</foreach>
|
||
</select>
|
||
```
|
||
|
||
### 2. 修复 `selectProfileByInfoNumber`(单个查询)
|
||
|
||
**位置**: `PsyUserProfileMapper.xml` 第62-68行
|
||
|
||
```xml
|
||
<!-- 修复前 -->
|
||
<select id="selectProfileByInfoNumber" parameterType="String" resultMap="PsyUserProfileResult">
|
||
<include refid="selectProfileVo"/>
|
||
from psy_user_profile p
|
||
left join sys_user u on p.user_id = u.user_id
|
||
where p.info_number = #{infoNumber}
|
||
</select>
|
||
|
||
<!-- 修复后 -->
|
||
<select id="selectProfileByInfoNumber" parameterType="String" resultMap="PsyUserProfileResult">
|
||
<include refid="selectProfileVo"/>
|
||
from psy_user_profile p
|
||
left join sys_user u on p.user_id = u.user_id
|
||
where p.info_number = #{infoNumber}
|
||
and u.del_flag = '0'
|
||
</select>
|
||
```
|
||
|
||
### 3. 修复 `selectProfileById`
|
||
|
||
**位置**: `PsyUserProfileMapper.xml` 第46-52行
|
||
|
||
```xml
|
||
<!-- 修复后 -->
|
||
<select id="selectProfileById" parameterType="Long" resultMap="PsyUserProfileResult">
|
||
<include refid="selectProfileVo"/>
|
||
from psy_user_profile p
|
||
left join sys_user u on p.user_id = u.user_id
|
||
where p.profile_id = #{profileId}
|
||
and u.del_flag = '0'
|
||
</select>
|
||
```
|
||
|
||
### 4. 修复 `selectProfileByUserId`
|
||
|
||
**位置**: `PsyUserProfileMapper.xml` 第54-60行
|
||
|
||
```xml
|
||
<!-- 修复后 -->
|
||
<select id="selectProfileByUserId" parameterType="Long" resultMap="PsyUserProfileResult">
|
||
<include refid="selectProfileVo"/>
|
||
from psy_user_profile p
|
||
left join sys_user u on p.user_id = u.user_id
|
||
where p.user_id = #{userId}
|
||
and u.del_flag = '0'
|
||
</select>
|
||
```
|
||
|
||
## 修复效果
|
||
|
||
修复后,系统在以下场景中的行为将更加合理:
|
||
|
||
1. **导入档案时**: 不会再将已删除用户的档案识别为"已存在",可以正常导入
|
||
2. **信息编号唯一性验证**: 不会因已删除用户的旧信息编号而拒绝新用户使用
|
||
3. **查询档案**: 所有档案查询统一过滤已删除用户,保持数据一致性
|
||
|
||
## 测试建议
|
||
|
||
### 测试场景1:导入已删除用户的档案
|
||
1. 删除一个有档案的用户(设置 `del_flag = '2'`)
|
||
2. 准备Excel文件,包含该用户的信息编号
|
||
3. 导入档案数据
|
||
4. **预期结果**: 成功导入,系统自动创建新用户
|
||
|
||
### 测试场景2:信息编号唯一性
|
||
1. 删除用户A(信息编号:001)
|
||
2. 创建新档案,使用信息编号:001
|
||
3. **预期结果**: 成功创建,不提示"信息编号已存在"
|
||
|
||
### 测试场景3:正常导入(未删除用户)
|
||
1. 准备包含现有用户信息编号的Excel
|
||
2. 不勾选"更新已存在数据"
|
||
3. 导入档案
|
||
4. **预期结果**: 提示"信息编号已存在"(行为不变)
|
||
|
||
## 影响范围
|
||
|
||
**修改文件**:
|
||
- `ry-xinli-system/src/main/resources/mapper/system/psychology/PsyUserProfileMapper.xml`
|
||
|
||
**影响模块**:
|
||
- 用户档案导入功能
|
||
- 用户档案查询功能
|
||
- 信息编号唯一性验证
|
||
|
||
**兼容性**: 完全向后兼容,只是增加了已删除用户的过滤条件
|
||
|
||
## 部署说明
|
||
|
||
1. 更新代码后重新编译项目
|
||
2. 重启应用服务器
|
||
3. 无需数据库变更
|
||
4. 建议清理旧的已删除用户档案数据(可选)
|
||
|
||
---
|
||
|
||
**修复日期**: 2024年12月2日
|
||
**修复人**: Cascade AI Assistant
|