导入修改

This commit is contained in:
zhangheng 2024-05-15 11:16:47 +08:00
parent cb706e689e
commit 07ce2cbe3f
9 changed files with 137 additions and 17 deletions

View File

@ -8,6 +8,7 @@ import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.agency.Agency;
import com.xinelu.manage.dto.agency.AgencyDTO;
import com.xinelu.manage.dto.agency.HospitalDTO;
import com.xinelu.manage.service.agency.IAgencyService;
import org.apache.commons.lang3.StringUtils;
@ -141,8 +142,8 @@ public class AgencyController extends BaseController {
if (!orgName.endsWith(Constants.XLSX) && !orgName.endsWith(Constants.XLS)) {
return AjaxResult.error("导入文件格式不正确请导入xlsx或xls格式的文件");
}
ExcelUtil<Agency> util = new ExcelUtil<>(Agency.class);
List<Agency> list = util.importExcel(file.getInputStream());
ExcelUtil<AgencyDTO> util = new ExcelUtil<>(AgencyDTO.class);
List<AgencyDTO> list = util.importExcel(file.getInputStream());
return agencyService.insertAgencyImportList(list);
}

View File

@ -41,7 +41,6 @@ public class Agency extends BaseEntity {
* 所属机构类别id
*/
@ApiModelProperty(value = "所属机构类别id")
@Excel(name = "所属机构类别")
private Long agencyCategoryId;
/**
@ -97,7 +96,7 @@ public class Agency extends BaseEntity {
* 节点类型节点类型卫健委HEALTH_COMMISSION医保局MEDICAL_INSURANCE_BUREAU医院HOSPITAL院区CAMPUS药店PHARMACY科室DEPARTMENT病区WARD中国CHINA省份PROVINCE
*/
@ApiModelProperty(value = "节点类型节点类型卫健委HEALTH_COMMISSION医保局MEDICAL_INSURANCE_BUREAU医院HOSPITAL院区CAMPUS药店PHARMACY科室DEPARTMENT病区WARD中国CHINA省份PROVINCE")
@Excel(name = "节点类型")
@Excel(name = "节点类型医院HOSPITAL院区CAMPUS")
private String nodeType;
/**

View File

@ -0,0 +1,48 @@
package com.xinelu.manage.dto.agency;
import com.xinelu.common.annotation.Excel;
import com.xinelu.manage.domain.agency.Agency;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Objects;
@Data
public class AgencyDTO extends Agency {
@Excel(name = "上级机构代码")
private String parentAgencyCode;
/**
* 机构名称
*/
@ApiModelProperty(value = "机构名称")
@Excel(name = "机构名称(必填)")
private String agencyName;
/**
* 类别编码
*/
@ApiModelProperty(value = "类别编码")
@Excel(name = "所属机构类别编码")
private String categoryCode;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AgencyDTO that = (AgencyDTO) o;
return Objects.equals(agencyName, that.agencyName);
}
@Override
public int hashCode() {
return Objects.hash(agencyName);
}
}

View File

@ -1,6 +1,8 @@
package com.xinelu.manage.mapper.agency;
import com.xinelu.manage.domain.agency.Agency;
import com.xinelu.manage.domain.agencycategory.AgencyCategory;
import com.xinelu.manage.dto.agency.AgencyDTO;
import com.xinelu.manage.vo.agency.AgencyVO;
import org.apache.ibatis.annotations.Param;
@ -100,7 +102,7 @@ public interface AgencyMapper {
* @param agencyNames 机构信息集合
* @return 列表集合信息
*/
List<Agency> getAllAgencyInfo(@Param("agencyNames") List<String> agencyNames);
List<AgencyDTO> getAllAgencyInfo(@Param("agencyNames") List<String> agencyNames);
/**
* 机构信息导入
@ -112,4 +114,14 @@ public interface AgencyMapper {
int selectAgencyNameByAgencyNameInt(String agencyName);
/**
* 通过机构编号查询机构id
*
* @param parentAgencyCodeList 机构编号
* @return AgencyDTO
*/
List<AgencyDTO> selectAgencyId(@Param("parentAgencyCodeList") List<String> parentAgencyCodeList);
List<AgencyCategory> selectAgencyCategoryId(@Param("categoryCode") List<String> categoryCode);
}

View File

@ -2,6 +2,7 @@ package com.xinelu.manage.service.agency;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.manage.domain.agency.Agency;
import com.xinelu.manage.dto.agency.AgencyDTO;
import com.xinelu.manage.dto.agency.HospitalDTO;
import com.xinelu.manage.vo.agency.AgencyTreeVO;
import com.xinelu.manage.vo.agency.AgencyVO;
@ -87,7 +88,7 @@ public interface IAgencyService {
* @param agencyList 机构信息
* @return int
**/
AjaxResult insertAgencyImportList(List<Agency> agencyList);
AjaxResult insertAgencyImportList(List<AgencyDTO> agencyList);
/**
* 医院园区科室病区联动查询

View File

@ -9,7 +9,9 @@ import com.xinelu.common.utils.bean.BeanUtils;
import com.xinelu.common.utils.codes.GenerateSystemCodeUtil;
import com.xinelu.common.utils.regex.RegexUtil;
import com.xinelu.manage.domain.agency.Agency;
import com.xinelu.manage.domain.agencycategory.AgencyCategory;
import com.xinelu.manage.domain.department.Department;
import com.xinelu.manage.dto.agency.AgencyDTO;
import com.xinelu.manage.dto.agency.HospitalDTO;
import com.xinelu.manage.mapper.agency.AgencyMapper;
import com.xinelu.manage.mapper.department.DepartmentMapper;
@ -27,7 +29,10 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@ -191,32 +196,56 @@ public class AgencyServiceImpl implements IAgencyService {
**/
@Transactional(rollbackFor = Exception.class)
@Override
public AjaxResult insertAgencyImportList(List<Agency> agencyList) {
public AjaxResult insertAgencyImportList(List<AgencyDTO> agencyList) {
//判断添加的数据是否为空
if (CollectionUtils.isEmpty(agencyList)) {
return AjaxResult.error("请添加机构导入信息!");
}
//根据护理站名称做去除处理
List<Agency> importDataList = agencyList.stream().filter(item -> StringUtils.isNotBlank(item.getAgencyName())).distinct().collect(Collectors.toList());
List<AgencyDTO> importDataList = agencyList.stream().filter(item -> StringUtils.isNotBlank(item.getAgencyName())).distinct().collect(Collectors.toList());
//校验联系电话格式是否正确
Agency agency = importDataList.stream().filter(item -> StringUtils.isNotBlank(item.getAgencyPhone())).filter(item -> BooleanUtils.isFalse(regexUtil.regexPhone(item.getAgencyPhone()))).findFirst().orElse(new Agency());
AgencyDTO agency = importDataList.stream().filter(item -> StringUtils.isNotBlank(item.getAgencyPhone())).filter(item -> BooleanUtils.isFalse(regexUtil.regexPhone(item.getAgencyPhone()))).findFirst().orElse(new AgencyDTO());
if (StringUtils.isNotBlank(agency.getAgencyPhone())) {
return AjaxResult.error("当前机构联系电话:" + agency.getAgencyPhone() + " 格式不正确,请重新录入!");
}
List<String> agencyNames = importDataList.stream().filter(item -> StringUtils.isNotBlank(item.getAgencyName())).map(Agency::getAgencyName).distinct().collect(Collectors.toList());
//根据名称查询护理站基本信息
List<Agency> allAgencyInfo = agencyMapper.getAllAgencyInfo(agencyNames);
//做差集去除数据库中已经存在的护理站信息
List<Agency> subtractList = new ArrayList<>(CollectionUtils.subtract(importDataList, allAgencyInfo));
List<String> agencyNames = importDataList.stream().filter(item -> StringUtils.isNotBlank(item.getAgencyName())).map(AgencyDTO::getAgencyName).distinct().collect(Collectors.toList());
//根据名称查询机构基本信息
List<AgencyDTO> allAgencyInfo = agencyMapper.getAllAgencyInfo(agencyNames);
//做差集去除数据库中已经存在的机构信息
List<AgencyDTO> subtractList = new ArrayList<>(CollectionUtils.subtract(importDataList, allAgencyInfo));
if (CollectionUtils.isEmpty(subtractList)) {
return AjaxResult.success();
}
//上级机构查询
List<AgencyDTO> agencyIds = new ArrayList<>();
List<String> parentAgencyCodeList = agencyList.stream().filter(Objects::nonNull).map(AgencyDTO::getParentAgencyCode).filter(Objects::nonNull).distinct().collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(parentAgencyCodeList)) {
agencyIds = agencyMapper.selectAgencyId(parentAgencyCodeList);
}
//机构类别查询
List<AgencyCategory> agencyCategories = new ArrayList<>();
List<String> categoryCode = agencyList.stream().filter(Objects::nonNull).map(AgencyDTO::getCategoryCode).filter(Objects::nonNull).distinct().collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(categoryCode)) {
agencyCategories = agencyMapper.selectAgencyCategoryId(categoryCode);
}
List<Agency> saveAgencyList = new ArrayList<>();
for (Agency item : subtractList) {
for (AgencyDTO item : subtractList) {
if (StringUtils.isBlank(item.getAgencyName())) {
return AjaxResult.error("机构名称不能为空!");
}
item.setCreateBy(SecurityUtils.getUsername());
item.setCreateTime(LocalDateTime.now());
Agency newAgency = new Agency();
BeanUtils.copyProperties(item, newAgency);
if (CollectionUtils.isNotEmpty(agencyIds)) {
AgencyDTO agencyDTO = agencyIds.stream().filter(Objects::nonNull).filter(items -> StringUtils.isNotBlank(items.getAgencyCode()) && Objects.nonNull(items.getId()) && items.getAgencyCode().equals(item.getParentAgencyCode())).findFirst().orElse(new AgencyDTO());
newAgency.setParentId(agencyDTO.getId());
}
if (CollectionUtils.isNotEmpty(agencyCategories)) {
AgencyCategory agencyCategory = agencyCategories.stream().filter(Objects::nonNull).filter(items -> StringUtils.isNotBlank(items.getCategoryCode()) && Objects.nonNull(items.getId()) && items.getCategoryCode().equals(item.getCategoryCode())).findFirst().orElse(new AgencyCategory());
newAgency.setAgencyCategoryId(agencyCategory.getId());
}
newAgency.setAgencyCode(Constants.AGENCY_CODE + generateSystemCodeUtil.generateSystemCode(Constants.AGENCY_CODE));
saveAgencyList.add(newAgency);
}
int insertCount = agencyMapper.insertAgencyImportList(saveAgencyList);

View File

@ -360,7 +360,7 @@
</foreach>
</delete>
<select id="getAllAgencyInfo" resultType="com.xinelu.manage.domain.agency.Agency">
<select id="getAllAgencyInfo" resultType="com.xinelu.manage.dto.agency.AgencyDTO">
select id,
parent_id,
agency_category_id,
@ -446,4 +446,34 @@
from agency
where agency_name = #{agencyName}
</select>
<select id="selectAgencyId" resultType="com.xinelu.manage.dto.agency.AgencyDTO">
select
id,
agency_code
from agency
<where>
<if test="parentAgencyCodeList != null and parentAgencyCodeList.size() > 0">
and agency_code in
<foreach item="parentAgencyCodeList" collection="parentAgencyCodeList" open="(" separator="," close=")">
#{parentAgencyCodeList}
</foreach>
</if>
</where>
</select>
<select id="selectAgencyCategoryId" resultType="com.xinelu.manage.domain.agencycategory.AgencyCategory">
select
id,
category_code
from agency_category
<where>
<if test="categoryCode != null and categoryCode.size() > 0">
and category_code in
<foreach item="categoryCode" collection="categoryCode" open="(" separator="," close=")">
#{categoryCode}
</foreach>
</if>
</where>
</select>
</mapper>