|
|
@ -1,11 +1,15 @@ |
|
|
|
package com.ccsens.carbasics.service; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.lang.Snowflake; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.ccsens.carbasics.bean.dto.OrganizationDto; |
|
|
|
import com.ccsens.carbasics.bean.po.Organization; |
|
|
|
import com.ccsens.carbasics.bean.po.*; |
|
|
|
import com.ccsens.carbasics.bean.vo.OrganizationVo; |
|
|
|
import com.ccsens.carbasics.persist.dao.OrganizationDao; |
|
|
|
import com.ccsens.carbasics.persist.mapper.OrganizationParentMapper; |
|
|
|
import com.ccsens.carbasics.util.Constant; |
|
|
|
import com.ccsens.util.WebConstant; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
@ -13,7 +17,9 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
/** |
|
|
|
* @description: |
|
|
@ -27,6 +33,10 @@ public class OrganizationService implements IOrganizationService { |
|
|
|
|
|
|
|
@Resource |
|
|
|
private OrganizationDao organizationDao; |
|
|
|
@Resource |
|
|
|
private OrganizationParentMapper organizationParentMapper; |
|
|
|
@Resource |
|
|
|
private Snowflake snowflake; |
|
|
|
|
|
|
|
@Override |
|
|
|
public OrganizationVo.Rank rank(OrganizationDto.Rank param, Long userId) { |
|
|
@ -46,9 +56,14 @@ public class OrganizationService implements IOrganizationService { |
|
|
|
break; |
|
|
|
default:break; |
|
|
|
} |
|
|
|
for (int i = 0; i<items.size(); i++) { |
|
|
|
OrganizationVo.RankItem item = items.get(i); |
|
|
|
item.setRank(i+1); |
|
|
|
} |
|
|
|
OrganizationVo.RankItem self = null; |
|
|
|
if (organization != null && organization.getOrganizationType() == Constant.Organization.HOSPITAL && CollectionUtil.isNotEmpty(items)) { |
|
|
|
for (OrganizationVo.RankItem item: items) { |
|
|
|
for (int i = 0; i<items.size(); i++) { |
|
|
|
OrganizationVo.RankItem item = items.get(i); |
|
|
|
if (item.getId().longValue() == organization.getId().longValue()) { |
|
|
|
self = item; |
|
|
|
break; |
|
|
@ -60,4 +75,75 @@ public class OrganizationService implements IOrganizationService { |
|
|
|
rank.setList(items); |
|
|
|
return rank; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String importCode(List<Object[]> rowList, Long userId) throws Exception { |
|
|
|
if (CollectionUtil.isEmpty(rowList)) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
List<Organization> organizations = new ArrayList<>(); |
|
|
|
List<OrganizationParent> parents = new ArrayList<>(); |
|
|
|
Map<String, Long> nameMap = new HashMap<>(); |
|
|
|
int nameIndex = 0; |
|
|
|
StringBuilder builder = new StringBuilder(); |
|
|
|
rowList.forEach(row -> { |
|
|
|
if (row == null || row.length <= nameIndex || StrUtil.isBlank((String)row[nameIndex])) { |
|
|
|
return; |
|
|
|
} |
|
|
|
Organization newOrganization = new Organization(); |
|
|
|
String name = (String)row[nameIndex]; |
|
|
|
name = name.trim(); |
|
|
|
Organization oldOrganization = organizationDao.getOrganizationByName(name); |
|
|
|
newOrganization.setId(oldOrganization == null ? snowflake.nextId() : oldOrganization.getId()); |
|
|
|
newOrganization.setName(name); |
|
|
|
newOrganization.setOperator(userId); |
|
|
|
for (String key: Constant.Organization.typeMap.keySet()) { |
|
|
|
if (name.endsWith(key)) { |
|
|
|
newOrganization.setOrganizationType(Constant.Organization.typeMap.get(key)); |
|
|
|
} |
|
|
|
} |
|
|
|
if (newOrganization.getOrganizationType() == null) { |
|
|
|
builder.append(name).append("无法判断类型,设置默认类型为医院。"); |
|
|
|
newOrganization.setOrganizationType(Constant.Organization.HOSPITAL); |
|
|
|
} |
|
|
|
newOrganization.setCode(row.length > 1 && row[1] != null ? (String)row[1] : ""); |
|
|
|
newOrganization.setShortName(row.length > 2 && row[2] != null ? (String)row[2] : ""); |
|
|
|
newOrganization.setIntroduce(row.length > 3 && row[3] != null ? (String)row[3] : ""); |
|
|
|
newOrganization.setLevel(row.length > 4 && row[4] != null ? Byte.parseByte((String)row[4]) : 0); |
|
|
|
organizations.add(newOrganization); |
|
|
|
nameMap.put(name, newOrganization.getId()); |
|
|
|
int parentIndex = 5; |
|
|
|
if (row.length <= parentIndex || row[parentIndex] == null || StrUtil.isBlank((String)row[parentIndex])) { |
|
|
|
return; |
|
|
|
} |
|
|
|
String parentName = (String) row[parentIndex]; |
|
|
|
parentName = parentName.trim(); |
|
|
|
if (!nameMap.containsKey(parentName)) { |
|
|
|
builder.append(name).append("的上级").append(parentName) |
|
|
|
.append("未找到,请检查机构排序是否存在或排序是否正确。"); |
|
|
|
} else { |
|
|
|
OrganizationParent parent = new OrganizationParent(); |
|
|
|
if (oldOrganization != null) { |
|
|
|
// 删除原有的上下级关系
|
|
|
|
OrganizationParentExample parentExample = new OrganizationParentExample(); |
|
|
|
parentExample.createCriteria().andOrganizationIdEqualTo(oldOrganization.getId()); |
|
|
|
OrganizationParent update = new OrganizationParent(); |
|
|
|
update.setRecStatus(WebConstant.REC_STATUS.Deleted.value); |
|
|
|
organizationParentMapper.updateByExampleSelective(update, parentExample); |
|
|
|
} |
|
|
|
parent.setId(snowflake.nextId()); |
|
|
|
parent.setOrganizationId(newOrganization.getId()); |
|
|
|
parent.setParentId(nameMap.get(parentName)); |
|
|
|
parent.setOperator(userId); |
|
|
|
parents.add(parent); |
|
|
|
} |
|
|
|
}); |
|
|
|
if (CollectionUtil.isNotEmpty(organizations)) { |
|
|
|
organizationDao.batchInsert(organizations); |
|
|
|
} |
|
|
|
if (CollectionUtil.isNotEmpty(parents)) { |
|
|
|
organizationDao.batchInsertParent(parents); |
|
|
|
} |
|
|
|
return builder.toString(); |
|
|
|
} |
|
|
|
} |
|
|
|