导入修改

This commit is contained in:
zhangheng 2024-12-06 17:08:19 +08:00
parent 893b341775
commit 8d585324ba
5 changed files with 73 additions and 19 deletions

View File

@ -157,7 +157,7 @@ public interface DepartmentMapper {
/**
* 批量修改科室别名
*
* @param departmentList
* @param departmentList 科室别名
* @return int
*/
int updateDepartmentListByIds(List<Department> departmentList);

View File

@ -74,7 +74,7 @@ public interface ResidentInfoMapper {
/**
* 根据电话号码和居民姓名查询居民基本信息
*
* @param phone 手机号
* @param phone 手机号
* @param patientName 姓名
* @return 居民基本信息
*/
@ -82,6 +82,7 @@ public interface ResidentInfoMapper {
/**
* 更新用户openid
*
* @param residentInfo 用户信息
* @return 结果
*/
@ -94,4 +95,12 @@ public interface ResidentInfoMapper {
* @return 结果
*/
int insertResidentInfoList(List<PatientInfoImport> patientInfoImports);
/**
* 根据姓名手机号查询居民信息
*
* @param patientInfoImports 姓名手机号
* @return ResidentInfo
*/
List<ResidentInfo> selectResidentInfoByPhoneList(@Param("list") List<PatientInfoImport> patientInfoImports);
}

View File

@ -37,6 +37,7 @@ import com.xinelu.manage.vo.patientinfo.PatientInfoVo;
import com.xinelu.manage.vo.patientinfoimport.DeptAliasVO;
import com.xinelu.manage.vo.patientinfoimport.PatientInfoImportVO;
import com.xinelu.system.mapper.SysUserMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.ObjectUtils;
@ -59,6 +60,7 @@ import java.util.stream.Collectors;
* @author haown
* @date 2024-02-26
*/
@Slf4j
@Service
public class PatientInfoServiceImpl implements IPatientInfoService {
@ -336,20 +338,21 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
@Override
public AjaxResult patientUpload(List<PatientInfoImport> list, Integer records, String orgName) {
if (CollectionUtils.isEmpty(list) || list.size() == 0) {
return AjaxResult.error("导入用户数据不能为空!");
return AjaxResult.error("已完成数据导入导入成功0条记录失败" + list.size() + "条记录。失败原因:导入用户数据不能为空!");
}
List<PatientInfoImport> collect = list.stream().filter(Objects::nonNull).filter(item -> StringUtils.isEmpty(item.getPatientName()) || StringUtils.isEmpty(item.getPatientPhone()) || StringUtils.isEmpty(item.getDeptAlias()) || Objects.isNull(item.getVisitDate())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(collect)) {
return AjaxResult.error("请填写完整!");
return AjaxResult.error("已完成数据导入导入成功0条记录失败" + list.size() + "条记录。失败原因:请填写完整导入信息");
}
List<PatientInfoImport> regexPhoneList = list.stream().filter(item -> StringUtils.isNotBlank(item.getPatientPhone())).filter(item -> BooleanUtils.isFalse(regexUtil.regexPhone(item.getPatientPhone()))).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(regexPhoneList)) {
return AjaxResult.error(HttpStatus.ERROR_TWO, "手机号号码格式不正确,请重新录入!", regexPhoneList);
return AjaxResult.error(HttpStatus.ERROR_TWO, "已完成数据导入导入成功0条记录失败" + list.size() + "条记录。失败原因:手机号号码格式不正确,请重新录入!", regexPhoneList);
}
//导入重复过滤
List<PatientInfoImport> distinctCollect = list.stream().filter(Objects::nonNull).distinct().collect(Collectors.toList());
//与数据库重复
List<PatientInfo> patientInfos = new ArrayList<>();
List<ResidentInfo> residentInfos = residentInfoMapper.selectResidentInfoByPhoneList(list);
if (Objects.isNull(records) || records == 1) {
LocalDate nowDate = LocalDate.now();
patientInfos = patientInfoMapper.selectPatientInfoByPatientName(list, nowDate);
@ -360,7 +363,7 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
SysUser sysUser = sysUserMapper.selectUserById(SecurityUtils.getUserId());
Agency agency = agencyMapper.selectAgencyById(sysUser.getHospitalAgencyId());
if (Objects.isNull(agency) || StringUtils.isEmpty(agency.getNodeType())) {
return AjaxResult.error("该账号无所属医院信息,请先添加该账号所属的医院信息!");
return AjaxResult.error("已完成数据导入导入成功0条记录失败" + list.size() + "条记录。失败原因:该账号无所属医院信息,请先添加该账号所属的医院信息!");
}
Department department = new Department();
department.setHospitalAgencyId(sysUser.getHospitalAgencyId());
@ -371,6 +374,12 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
List<PatientInfoImport> patientInfoImportList = new ArrayList<>();
for (PatientInfoImport patientInfoImport : distinctCollect) {
//选择自动去除当日重复记录
if (CollectionUtils.isNotEmpty(residentInfos)) {
List<ResidentInfo> collect1 = residentInfos.stream().filter(Objects::nonNull).filter(item -> patientInfoImport.getPatientName().equals(item.getPatientName()) && patientInfoImport.getPatientPhone().equals(item.getPatientPhone())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(collect1)) {
continue;
}
}
if (CollectionUtils.isNotEmpty(patientInfos) && (Objects.isNull(records) || records == 1)) {
List<PatientInfo> collect1 = patientInfos.stream().filter(Objects::nonNull).filter(item -> patientInfoImport.getPatientName().equals(item.getPatientName()) && patientInfoImport.getPatientPhone().equals(item.getPatientPhone())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(collect1)) {
@ -415,10 +424,11 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
patientInfoImportList.add(patientInfoImport);
}
if (CollectionUtils.isEmpty(patientInfoImportList)) {
return AjaxResult.success();
return AjaxResult.success("已完成数据导入导入成功0条记录失败0条记录重复" + list.size() + "条记录(已自动去重)。");
}
//组装返回数据
patientInfoImportVO.setSn(sn);
patientInfoImportVO.setCount(list.size());
if (CollectionUtils.isNotEmpty(departmentList) && departmentList.size() > 0) {
patientInfoImportVO.setDepartments(departmentList);
}
@ -429,7 +439,8 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
//新增缓存表
int insertCount = patientInfoImportMapper.insertPatientInfoImportList(patientInfoImportList);
if (insertCount <= 0) {
return AjaxResult.error("导入失败,请联系管理员!");
log.info("缓存表新增失败!");
return AjaxResult.error("已完成数据导入导入成功0条记录失败" + patientInfoImportVO.getCount() + "条记录。");
}
//导入记录表
PatientInfoImportMain patientInfoImportMain = new PatientInfoImportMain();
@ -448,13 +459,15 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
patientInfoImportList.forEach(item -> item.setPatientInfoImportId(item.getId()));
int residentCount = residentInfoMapper.insertResidentInfoList(patientInfoImportList);
if (residentCount <= 0) {
return AjaxResult.error("导入失败,请联系管理员!");
log.info("居民表新增失败!");
return AjaxResult.error("已完成数据导入导入成功0条记录失败" + patientInfoImportVO.getCount() + "条记录。");
}
patientInfoImportList.forEach(item -> item.setResidentId(item.getId()));
//新增患者表
int i = patientInfoMapper.insertPatientInfoList(patientInfoImportList);
if (i <= 0) {
return AjaxResult.error("导入失败,请联系管理员!");
log.info("患者表新增失败!");
return AjaxResult.error("已完成数据导入导入成功0条记录失败" + patientInfoImportVO.getCount() + "条记录。");
}
patientInfoImportList.forEach(item -> item.setPatientInfoId(item.getId()));
//新增就诊记录表
@ -474,10 +487,16 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
}
int patientVisitRecordCount = patientVisitRecordMapper.insertPatientVisitRecordList(patientVisitRecords);
if (patientVisitRecordCount <= 0) {
return AjaxResult.error("导入失败,请联系管理员!");
log.info("就诊记录表新增失败!");
return AjaxResult.error("已完成数据导入导入成功0条记录失败" + patientInfoImportVO.getCount() + "条记录。");
}
}
return AjaxResult.success();
String msg = "已完成数据导入!导入成功" + patientInfoImportList.size() + "条记录失败0条记录";
if (list.size() != patientInfoImportList.size()) {
int i = list.size() - patientInfoImportList.size();
msg = msg + ",重复" + i + "条记录(已自动去重)。";
}
return AjaxResult.success(msg);
}
/**
@ -496,16 +515,19 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
SysUser sysUser = sysUserMapper.selectUserById(SecurityUtils.getUserId());
Agency agency = agencyMapper.selectAgencyById(sysUser.getHospitalAgencyId());
if (Objects.isNull(agency)) {
return AjaxResult.error("该账号无所属医院信息,请先添加该账号所属的医院信息");
return AjaxResult.error("已完成数据导入导入成功0条记录失败" + patientInfoImportVO.getCount() + "条记录。失败原因:该账号无所属医院信息,请先添加该账号所属的医院信息");
}
Department department = new Department();
department.setHospitalAgencyId(sysUser.getHospitalAgencyId());
List<Department> departmentList = departmentMapper.selectDepartmentNameCount(department);
if (CollectionUtils.isEmpty(departmentList)) {
return AjaxResult.error("该账号所属医院无下级科室,请先维护所属医院的下级科室信息");
return AjaxResult.error("已完成数据导入导入成功0条记录失败" + patientInfoImportVO.getCount() + "条记录。失败原因:该账号所属医院无下级科室,请先维护所属医院的下级科室信息");
}
//根据sn查询数据
List<PatientInfoImport> patientInfoImports = patientInfoImportMapper.selectPatientInfoImportBySn(patientInfoImportVO.getSn());
if (CollectionUtils.isEmpty(patientInfoImports)) {
return AjaxResult.error("已完成数据导入导入成功0条记录失败" + patientInfoImportVO.getCount() + "条记录。");
}
for (PatientInfoImport patientInfoImport : patientInfoImports) {
if (StringUtils.isEmpty(patientInfoImport.getDepartmentName()) || Objects.isNull(patientInfoImport.getDepartmentId())) {
DeptAliasVO deptAliasVO = patientInfoImportVO.getDeptAliasVOS().stream().filter(Objects::nonNull).filter(item -> StringUtils.isNotBlank(item.getDepartmentName()) && StringUtils.isNotEmpty(item.getDeptAlias()) && patientInfoImport.getDeptAlias().equals(item.getDeptAlias())).findFirst().orElse(new DeptAliasVO());
@ -537,20 +559,20 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
if (CollectionUtils.isNotEmpty(departments)) {
int i = departmentMapper.updateDepartmentListByIds(departments);
if (i <= 0) {
return AjaxResult.error("导入失败,请联系管理员!");
return AjaxResult.error("已完成数据导入导入成功0条记录失败" + patientInfoImportVO.getCount() + "条记录。");
}
}
//新增居民表
patientInfoImports.forEach(item -> item.setPatientInfoImportId(item.getId()));
int residentCount = residentInfoMapper.insertResidentInfoList(patientInfoImports);
if (residentCount <= 0) {
return AjaxResult.error("导入失败,请联系管理员!");
return AjaxResult.error("已完成数据导入导入成功0条记录失败" + patientInfoImportVO.getCount() + "条记录。");
}
patientInfoImports.forEach(item -> item.setResidentId(item.getId()));
//新增患者表
int i = patientInfoMapper.insertPatientInfoList(patientInfoImports);
if (i <= 0) {
return AjaxResult.error("导入失败,请联系管理员!");
return AjaxResult.error("已完成数据导入导入成功0条记录失败" + patientInfoImportVO.getCount() + "条记录。");
}
patientInfoImports.forEach(item -> item.setPatientInfoId(item.getId()));
List<PatientVisitRecord> patientVisitRecords = new ArrayList<>();
@ -568,8 +590,13 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
}
int patientVisitRecordCount = patientVisitRecordMapper.insertPatientVisitRecordList(patientVisitRecords);
if (patientVisitRecordCount <= 0) {
return AjaxResult.error("导入失败,请联系管理员!");
return AjaxResult.error("已完成数据导入导入成功0条记录失败" + patientInfoImportVO.getCount() + "条记录。");
}
return AjaxResult.success();
String msg = "已完成数据导入!导入成功" + patientInfoImports.size() + "条记录失败0条记录";
if (patientInfoImportVO.getCount() != patientInfoImports.size()) {
int minus = patientInfoImportVO.getCount() - patientInfoImports.size();
msg = msg + ",重复" + minus + "条记录(已自动去重)。";
}
return AjaxResult.success(msg);
}
}

View File

@ -23,6 +23,11 @@ public class PatientInfoImportVO extends BaseEntity {
*/
private String sn;
/**
* 导入总数
*/
private Integer count;
/**
* 科室别名集合
*/

View File

@ -235,4 +235,17 @@
)
</foreach>
</insert>
<select id="selectResidentInfoByPhoneList" resultType="com.xinelu.manage.domain.residentinfo.ResidentInfo">
select
patient_name,
patient_phone
from resident_info
<where>
(patient_name, patient_phone) IN
<foreach item="list" index="index" collection="list" open="(" separator="," close=")">
(#{list.patientName}, #{list.patientPhone})
</foreach>
</where>
</select>
</mapper>