Commit d3a8dc00 by lzy

空间导入

parent 3e229647
...@@ -157,6 +157,7 @@ ...@@ -157,6 +157,7 @@
<orderEntry type="library" name="Maven: org.springframework.integration:spring-integration-core:5.5.5" level="project" /> <orderEntry type="library" name="Maven: org.springframework.integration:spring-integration-core:5.5.5" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-messaging:5.3.12" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-messaging:5.3.12" level="project" />
<orderEntry type="library" name="Maven: org.springframework.retry:spring-retry:1.3.1" level="project" /> <orderEntry type="library" name="Maven: org.springframework.retry:spring-retry:1.3.1" level="project" />
<orderEntry type="library" name="Maven: javax.annotation:javax.annotation-api:1.3.2" level="project" />
<orderEntry type="library" name="Maven: org.springframework.integration:spring-integration-mqtt:5.5.5" level="project" /> <orderEntry type="library" name="Maven: org.springframework.integration:spring-integration-mqtt:5.5.5" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5" level="project" /> <orderEntry type="library" name="Maven: org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5" level="project" />
<orderEntry type="library" name="Maven: com.aliyun:dysmsapi20170525:2.0.9" level="project" /> <orderEntry type="library" name="Maven: com.aliyun:dysmsapi20170525:2.0.9" level="project" />
...@@ -183,7 +184,6 @@ ...@@ -183,7 +184,6 @@
<orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml:5.2.2" level="project" /> <orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml:5.2.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml-lite:5.2.2" level="project" /> <orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml-lite:5.2.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.xmlbeans:xmlbeans:5.0.3" level="project" /> <orderEntry type="library" name="Maven: org.apache.xmlbeans:xmlbeans:5.0.3" level="project" />
<orderEntry type="library" name="Maven: xml-apis:xml-apis:1.4.01" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-compress:1.21" level="project" /> <orderEntry type="library" name="Maven: org.apache.commons:commons-compress:1.21" level="project" />
<orderEntry type="library" name="Maven: com.github.virtuald:curvesapi:1.07" level="project" /> <orderEntry type="library" name="Maven: com.github.virtuald:curvesapi:1.07" level="project" />
<orderEntry type="library" name="Maven: cn.hutool:hutool-all:5.3.5" level="project" /> <orderEntry type="library" name="Maven: cn.hutool:hutool-all:5.3.5" level="project" />
...@@ -205,6 +205,7 @@ ...@@ -205,6 +205,7 @@
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-bridge:1.14" level="project" /> <orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-bridge:1.14" level="project" />
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-script:1.14" level="project" /> <orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-script:1.14" level="project" />
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-dom:1.14" level="project" /> <orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-dom:1.14" level="project" />
<orderEntry type="library" name="Maven: xml-apis:xml-apis:1.4.01" level="project" />
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-gvt:1.14" level="project" /> <orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-gvt:1.14" level="project" />
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-shared-resources:1.14" level="project" /> <orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-shared-resources:1.14" level="project" />
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-svggen:1.14" level="project" /> <orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-svggen:1.14" level="project" />
......
...@@ -22,6 +22,9 @@ public class PlatSpaceVO extends BaseIdDTO { ...@@ -22,6 +22,9 @@ public class PlatSpaceVO extends BaseIdDTO {
@ApiModelProperty("父级Id") @ApiModelProperty("父级Id")
private String parentId; private String parentId;
@ApiModelProperty("父级名称")
private String parentName;
@ApiModelProperty("子集") @ApiModelProperty("子集")
private List<PlatSpaceVO> children; private List<PlatSpaceVO> children;
} }
...@@ -6,15 +6,13 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; ...@@ -6,15 +6,13 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.makeit.common.dto.BaseIdDTO; import com.makeit.common.dto.BaseIdDTO;
import com.makeit.common.vo.ExcelErrorVo; import com.makeit.common.vo.ExcelErrorVo;
import com.makeit.common.vo.ExcelImportVo; import com.makeit.common.vo.ExcelImportVo;
import com.makeit.dto.platform.space.PlatSpaceAddDTO; import com.makeit.dto.platform.space.*;
import com.makeit.dto.platform.space.PlatSpaceImportDTO;
import com.makeit.dto.platform.space.PlatSpaceQueryDTO;
import com.makeit.dto.platform.space.PlatSpaceVO;
import com.makeit.entity.platform.auth.PlatOrg; import com.makeit.entity.platform.auth.PlatOrg;
import com.makeit.entity.platform.space.PlatBed; import com.makeit.entity.platform.space.PlatBed;
import com.makeit.entity.platform.space.PlatRoom; import com.makeit.entity.platform.space.PlatRoom;
import com.makeit.entity.platform.space.PlatSpace; import com.makeit.entity.platform.space.PlatSpace;
import com.makeit.enums.CodeMessageEnum; import com.makeit.enums.CodeMessageEnum;
import com.makeit.enums.platform.space.PlatSpaceEnum;
import com.makeit.exception.BusinessException; import com.makeit.exception.BusinessException;
import com.makeit.mapper.platform.space.PlatSpaceMapper; import com.makeit.mapper.platform.space.PlatSpaceMapper;
import com.makeit.service.platform.auth.PlatOrgService; import com.makeit.service.platform.auth.PlatOrgService;
...@@ -23,6 +21,7 @@ import com.makeit.service.platform.space.PlatRoomService; ...@@ -23,6 +21,7 @@ import com.makeit.service.platform.space.PlatRoomService;
import com.makeit.service.platform.space.PlatSpaceService; import com.makeit.service.platform.space.PlatSpaceService;
import com.makeit.utils.data.convert.BeanDtoVoUtils; import com.makeit.utils.data.convert.BeanDtoVoUtils;
import com.makeit.utils.data.excel.ExcelUtil; import com.makeit.utils.data.excel.ExcelUtil;
import com.makeit.utils.user.TokenUtil;
import com.makeit.utils.user.plat.PlatUserUtil; import com.makeit.utils.user.plat.PlatUserUtil;
import com.makeit.utils.user.plat.PlatUserVO; import com.makeit.utils.user.plat.PlatUserVO;
import com.makeit.vo.platform.space.PlatSpaceAndRoomVO; import com.makeit.vo.platform.space.PlatSpaceAndRoomVO;
...@@ -274,12 +273,22 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace ...@@ -274,12 +273,22 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
} }
@Override @Override
@Transactional
public ExcelImportVo importSpaceExcel(MultipartFile excelFile) { public ExcelImportVo importSpaceExcel(MultipartFile excelFile) {
ExcelImportVo excelImportVo = new ExcelImportVo(); ExcelImportVo excelImportVo = new ExcelImportVo();
try { try {
List<PlatSpace> listPlatSpace = list(new LambdaQueryWrapper<>());
List<PlatSpace> firstSpace = listPlatSpace.stream().filter(item->item.getParentId() == null).collect(Collectors.toList());
Map<String,String> firstSpaceNameMap = firstSpace.stream().collect(Collectors.toMap(PlatSpace::getName,PlatSpace::getId,(k1,k2)->k1));
List<PlatSpace> listChildren = listPlatSpace.stream().filter(item->item.getParentId() != null).collect(Collectors.toList());
Map<String,List<PlatSpace>> childrenMap = listChildren.stream().collect(Collectors.groupingBy(PlatSpace::getParentId));
Map<String,String> childrenIdMap = listChildren.stream().collect(Collectors.toMap(item->item.getParentId()+item.getName(),item->item.getId(),(k1,k2)->k1));
List<PlatSpaceImportDTO> list = ExcelUtil.importExcel(null,3,excelFile,PlatSpaceImportDTO.class); List<PlatSpaceImportDTO> list = ExcelUtil.importExcel(null,3,excelFile,PlatSpaceImportDTO.class);
List<ExcelErrorVo> errorVoList = new ArrayList<>(10); List<ExcelErrorVo> errorVoList = new ArrayList<>(10);
...@@ -287,19 +296,158 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace ...@@ -287,19 +296,158 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
int startRow = 3; int startRow = 3;
List<PlatSpace> listFirst = new ArrayList<>(10); // List<PlatSpaceVO> listFirst = new ArrayList<>(10);
// List<PlatSpaceVO> listSecond = new ArrayList<>(10);
// List<PlatSpaceVO> listThree = new ArrayList<>(10);
// List<PlatSpaceVO> listFour = new ArrayList<>(10);
List<PlatRoomDTO> listRoom = new ArrayList<>(10);
List<String> listKey = new ArrayList<>();
Integer errorCount = 0; Integer errorCount = 0;
Integer successCount = 0; Integer successCount = 0;
boolean errorFlag = false;
for(int i=0;i<list.size();i++){ for(int i=0;i<list.size();i++){
PlatSpaceImportDTO item = list.get(i); PlatSpaceImportDTO item = list.get(i);
if(StringUtil.isEmpty(item.getCommunity())){ if(StringUtil.isEmpty(item.getCommunity())){
errorVoList.add(new ExcelErrorVo(i+3,excelField.get(0),"第一层级必填")); errorVoList.add(new ExcelErrorVo(i+3,excelField.get(0),"第一层级必填"));
errorFlag = true;
}
if(StringUtil.isEmpty(item.getFloor())){
errorVoList.add(new ExcelErrorVo(i+3,excelField.get(4),"房间名必填"));
errorFlag = true;
}
String key = item.getCommunity();
//第二层级
if(StringUtil.isNotEmpty(item.getBuilding())){
key = key + "-" + item.getBuilding();
} }
}
//第三层级
if(StringUtil.isNotEmpty(item.getUnit())){
key = key + "-" + item.getUnit();
}
//第四层级
if(StringUtil.isNotEmpty(item.getFloor())){
key = key + "-" + item.getFloor();
}
if(listKey.contains(key)){
errorVoList.add(new ExcelErrorVo(i+3,excelField.get(0),"该空间下,房间名已存在"));
errorFlag = true;
}
if(errorFlag){
errorCount++;
}else{
successCount++;
}
}
String orgId = TokenUtil.getTntUserDetail().getOrgId();
if(errorVoList.isEmpty()){
for(int i=0;i<list.size();i++){
PlatSpaceImportDTO item = list.get(i);
//第一层级
String firstId = null;
if(!firstSpaceNameMap.containsKey(item.getCommunity())){
PlatSpace platSpace = new PlatSpace();
platSpace.setName(item.getCommunity());
platSpace.setType(PlatSpaceEnum.TypeEnum.COMMUNITY.getValue());
platSpace.setOrgId(orgId);
save(platSpace);
firstSpaceNameMap.put(platSpace.getName(),platSpace.getId());
firstId = platSpace.getId();
}else{
firstId = firstSpaceNameMap.get(item.getCommunity());
}
//第二层级
String secondId = null;
if(StringUtil.isNotEmpty(item.getBuilding())){
String secondKey = firstId + "-" + item.getBuilding();
if(!childrenIdMap.containsKey(secondKey)){
PlatSpace platSpace = new PlatSpace();
platSpace.setName(item.getBuilding());
platSpace.setType(PlatSpaceEnum.TypeEnum.BUILDING.getValue());
platSpace.setOrgId(orgId);
platSpace.setParentId(firstId);
platSpace.setParentPath(firstId);
save(platSpace);
childrenIdMap.put(secondKey,platSpace.getId());
secondId = platSpace.getId();
}else{
secondId = childrenIdMap.get(secondKey);
}
}
//第三级
String threeId = null;
if(StringUtil.isNotEmpty(item.getUnit())){
String threeKey = secondId + "-" + item.getUnit();
if(!childrenIdMap.containsKey(threeKey)){
PlatSpace platSpace = new PlatSpace();
platSpace.setName(item.getBuilding());
platSpace.setType(PlatSpaceEnum.TypeEnum.UNIT.getValue());
platSpace.setOrgId(orgId);
platSpace.setParentId(secondId);
platSpace.setParentPath(firstId+","+secondId);
save(platSpace);
childrenIdMap.put(threeKey,platSpace.getId());
threeId = platSpace.getId();
}else{
threeId = childrenIdMap.get(threeKey);
}
}
//第四级
String fourId = null;
if(StringUtil.isNotEmpty(item.getFloor())){
String fourKey = threeId + "-" + item.getFloor();
if(!childrenIdMap.containsKey(fourKey)){
PlatSpace platSpace = new PlatSpace();
platSpace.setName(item.getBuilding());
platSpace.setType(PlatSpaceEnum.TypeEnum.FLOOR.getValue());
platSpace.setOrgId(orgId);
platSpace.setParentId(threeId);
platSpace.setParentPath(firstId+","+secondId + "," + threeId);
save(platSpace);
childrenIdMap.put(fourKey,platSpace.getId());
fourId = platSpace.getId();
}else{
fourId = childrenIdMap.get(fourKey);
}
}
//房间
PlatRoomDTO platRoomDTO = new PlatRoomDTO();
platRoomDTO.setName(item.getRoomName());
platRoomDTO.setBedNumber(item.getBedNumber());
String spaceId = null;
if(firstId != null){
spaceId = firstId;
}else if(secondId != null){
spaceId = secondId;
}else if(threeId != null){
spaceId = threeId;
}else if(fourId != null){
spaceId = fourId;
}
platRoomDTO.setSpaceId(spaceId);
platRoomService.add(platRoomDTO);
}
}
excelImportVo.setTotalCount(list.size()); excelImportVo.setTotalCount(list.size());
excelImportVo.setErrorCount(errorCount); excelImportVo.setErrorCount(errorCount);
excelImportVo.setSuccessCount(successCount); excelImportVo.setSuccessCount(successCount);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment