|
@@ -2,42 +2,113 @@ package com.slibra.web.controller.listener;
|
|
|
|
|
|
import com.alibaba.excel.context.AnalysisContext;
|
|
|
import com.alibaba.excel.event.AnalysisEventListener;
|
|
|
-import com.slibra.business.domain.TUserInfo;
|
|
|
+import com.slibra.business.domain.*;
|
|
|
import com.slibra.business.mapper.*;
|
|
|
+import com.slibra.business.res.BZXQLHInfo;
|
|
|
+import com.slibra.business.res.MoreExcelInfo;
|
|
|
import com.slibra.business.res.UserExcelInfo;
|
|
|
+import com.slibra.common.utils.StringUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.ibatis.session.SqlSession;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Component
|
|
|
-public class MoreDataListener extends AnalysisEventListener<UserExcelInfo> {
|
|
|
+@Slf4j
|
|
|
+public class MoreDataListener extends AnalysisEventListener<MoreExcelInfo> {
|
|
|
|
|
|
|
|
|
SqlSession sqlSession;
|
|
|
|
|
|
- private TPumpingStationMapper tPumpingStationMapper;
|
|
|
+ TPumpingStationMapper tPumpingStationMapper;
|
|
|
+
|
|
|
+ TNeighborhoodBuildingMapper tNeighborhoodBuildingMapper;
|
|
|
|
|
|
- private TNeighborhoodBuildingMapper tNeighborhoodBuildingMapper;
|
|
|
+ TPumpingStationNeighbourhoodNumberMapper tPumpingStationNeighbourhoodNumberMapper;
|
|
|
|
|
|
- private TPumpingStationNeighbourhoodNumberMapper tPumpingStationNeighbourhoodNumberMapper;
|
|
|
+ TNeighborhoodMapper tNeighborhoodMapper;
|
|
|
|
|
|
- private TNeighborhoodMapper tNeighborhoodMapper;
|
|
|
+ List<MoreExcelInfo> list = new ArrayList<>();
|
|
|
|
|
|
@Override
|
|
|
- public void invoke(UserExcelInfo userExcelInfo, AnalysisContext context) {
|
|
|
+ public void invoke(MoreExcelInfo userExcelInfo, AnalysisContext context) {
|
|
|
System.out.println("开始执行插入操作:");
|
|
|
-
|
|
|
-
|
|
|
+ userExcelInfo.setPumpingStationName(userExcelInfo.getPumpingStationName().trim());
|
|
|
+ userExcelInfo.setNeighbourName(userExcelInfo.getNeighbourName().trim());
|
|
|
+ userExcelInfo.setBuildingName(userExcelInfo.getBuildingName().trim());
|
|
|
+ list.add(userExcelInfo);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void doAfterAllAnalysed(AnalysisContext context) {
|
|
|
// 所有数据读取完毕后的处理逻辑
|
|
|
System.out.println("所有数据读取完毕");
|
|
|
+ //拿到集合以后,处理数据
|
|
|
+ this.handleData(list);
|
|
|
sqlSession.commit();
|
|
|
sqlSession.close();
|
|
|
}
|
|
|
|
|
|
+ private void handleData(List<MoreExcelInfo> list) {
|
|
|
+ int size = 0;
|
|
|
+ if(!CollectionUtils.isEmpty(list)){
|
|
|
+ size = list.size();
|
|
|
+ //处理业务数据
|
|
|
+ Map<String, List<MoreExcelInfo>> map = list.stream().collect(Collectors.groupingBy(MoreExcelInfo::getNeighbourName));
|
|
|
+ map.forEach((k, v) -> {
|
|
|
+// System.out.println("小区名称:" + k + ",对应的楼号信息:" + JSON.toJSONString(v));
|
|
|
+ //插入小区
|
|
|
+ TNeighborhood tNeighborhood = TNeighborhood.builder().name(k).build();
|
|
|
+ this.tNeighborhoodMapper.insertTNeighborhood(tNeighborhood);
|
|
|
+ //插入楼号
|
|
|
+ for (MoreExcelInfo bzxqlhInfo : v) {
|
|
|
+ TNeighborhoodBuilding tNeighborhoodBuilding = TNeighborhoodBuilding.builder().neighborhoodId(tNeighborhood.getId()).name(bzxqlhInfo.getBuildingName()).build();
|
|
|
+ this.tNeighborhoodBuildingMapper.insertTNeighborhoodBuilding(tNeighborhoodBuilding);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //添加泵站(添加之前先去校验,通过名称查询泵站是否已经添加过了
|
|
|
+ // 如果添加过了,就用该泵站ID,然后再通过小区和楼号查询对应的数据,绑定关系
|
|
|
+ // 如果没有添加过,新增泵站,然后再通过小区和楼号查询对应的数据,绑定关系)
|
|
|
+ for (MoreExcelInfo bzxqlhInfo : list) {
|
|
|
+ String pumpingStationName = bzxqlhInfo.getPumpingStationName();
|
|
|
+ List<TPumpingStation> pumpingStations = this.tPumpingStationMapper.selectTPumpingStationList(TPumpingStation.builder().name(pumpingStationName).build());
|
|
|
+ Long pumpingStationId = null;
|
|
|
+ if(CollectionUtils.isEmpty(pumpingStations)){
|
|
|
+ log.info("A第一次添加泵站信息,泵站名称是{}", pumpingStationName);
|
|
|
+ //新增泵站,然后再通过小区和楼号查询对应的数据,绑定关系
|
|
|
+ TPumpingStation tPumpingStation = TPumpingStation.builder().name(pumpingStationName).build();
|
|
|
+ this.tPumpingStationMapper.insertTPumpingStation(tPumpingStation);
|
|
|
+ pumpingStationId = tPumpingStation.getId();
|
|
|
+ }else{
|
|
|
+ log.info("Z已经添加过泵站信息,泵站名称是{}", pumpingStationName);
|
|
|
+ pumpingStationId = pumpingStations.get(0).getId();
|
|
|
+ }
|
|
|
+ //有了泵站信息,处理其他逻辑
|
|
|
+ //再通过小区和楼号查询对应的数据,绑定关系
|
|
|
+ //2024年12月31日18:28:22 这里不能直接通过楼号去查询,因为楼号很多都是重复的 通过小区查询、,因为小区名字是唯一的。
|
|
|
+ List<TNeighborhood> tNeighborhoods = this.tNeighborhoodMapper.selectTNeighborhoodList(TNeighborhood.builder().name(bzxqlhInfo.getNeighbourName()).build());
|
|
|
+ if(!CollectionUtils.isEmpty(tNeighborhoods)){
|
|
|
+ TNeighborhood tNeighborhood = tNeighborhoods.get(0);
|
|
|
+ //通过小区ID和楼号名称【2者组合是唯一的】
|
|
|
+ List<TNeighborhoodBuilding> tNeighborhoodBuildings = this.tNeighborhoodBuildingMapper.selectTNeighborhoodBuildingList(TNeighborhoodBuilding.builder().neighborhoodId(tNeighborhood.getId()).name(bzxqlhInfo.getBuildingName()).build());
|
|
|
+ if(!CollectionUtils.isEmpty(tNeighborhoodBuildings)){
|
|
|
+ TNeighborhoodBuilding tNeighborhoodBuilding = tNeighborhoodBuildings.get(0);
|
|
|
+ //泵关联小区楼号对象
|
|
|
+ TPumpingStationNeighbourhoodNumber tPumpingStationNeighbourhoodNumber = TPumpingStationNeighbourhoodNumber.builder().pumpingStationId(pumpingStationId).neighborhoodId(tNeighborhoodBuilding.getNeighborhoodId()).neighborhoodBuildingId(tNeighborhoodBuilding.getId()).build();
|
|
|
+ this.tPumpingStationNeighbourhoodNumberMapper.insertTPumpingStationNeighbourhoodNumber(tPumpingStationNeighbourhoodNumber);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println("一共处理了:" + size + "条数据");
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public MoreDataListener(SqlSession sqlSession, TPumpingStationMapper tPumpingStationMapper, TNeighborhoodBuildingMapper tNeighborhoodBuildingMapper, TPumpingStationNeighbourhoodNumberMapper tPumpingStationNeighbourhoodNumberMapper, TNeighborhoodMapper tNeighborhoodMapper) {
|
|
|
this.sqlSession = sqlSession;
|