manailin
2021-06-12 eefbb8708d62ce3ca9b0f00402d586c78716af77
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/listen/ComMngBuildingExcelListen.java
@@ -4,21 +4,20 @@
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.panzhihua.common.enums.*;
import com.panzhihua.common.exceptions.ServiceException;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.community.ComMngBuildingExcelVO;
import com.panzhihua.common.model.vos.community.ComMngPopulationImportErrorVO;
import com.panzhihua.common.model.vos.community.ComMngPopulationServeExcelVO;
import com.panzhihua.common.service.community.CommunityService;
import com.panzhihua.common.utlis.*;
import com.panzhihua.common.service.grid.GridService;
import com.panzhihua.common.utlis.ListUtils;
import com.panzhihua.common.utlis.Snowflake;
import lombok.extern.slf4j.Slf4j;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
@@ -27,7 +26,10 @@
 */
@Slf4j
public class ComMngBuildingExcelListen extends AnalysisEventListener<Map<Integer, String>> {
    private CommunityService communityService;
    private GridService gridService;
    private Long communityId;
@@ -54,7 +56,6 @@
    }
    /**
     *
     * @param headMap
     * @param context
     */
@@ -77,7 +78,7 @@
        try {
            ArrayList<ComMngBuildingExcelVO> voList = Lists.newArrayList();
            List<ComMngPopulationImportErrorVO> populationImportErrorVOList = new ArrayList<>();
            for(int i =1;i<list.size();i++){
            for (int i = 1; i < list.size(); i++) {
                Map<Integer, String> oneData = list.get(i);
                ComMngBuildingExcelVO vo = new ComMngBuildingExcelVO();
                vo.setId(Snowflake.getId());
@@ -87,33 +88,34 @@
                vo.setVillageName(oneData.get(4));
                vo.setDoorNo(oneData.get(5));
                vo.setName(oneData.get(6));
                try{
                    vo.setUnitTotal(oneData.get(7)==null?0:Integer.valueOf(oneData.get(7)));
                }catch (Exception e){
                vo.setGridName(oneData.get(15));
                vo.setGridId(oneData.get(15));
                try {
                    vo.setUnitTotal(oneData.get(7) == null ? 0 : Integer.valueOf(oneData.get(7)));
                } catch (Exception e) {
                    vo.setUnitTotal(0);
                }
                try{
                    vo.setBuildFloorSum(oneData.get(8)==null?0:Integer.valueOf(oneData.get(8)));
                }catch (Exception e){
                try {
                    vo.setBuildFloorSum(oneData.get(8) == null ? 0 : Integer.valueOf(oneData.get(8)));
                } catch (Exception e) {
                    vo.setBuildFloorSum(0);
                }
                try{
                    vo.setEveryFloorSum(oneData.get(9)==null?0:Integer.valueOf(oneData.get(9)));
                }catch (Exception e){
                try {
                    vo.setEveryFloorSum(oneData.get(9) == null ? 0 : Integer.valueOf(oneData.get(9)));
                } catch (Exception e) {
                    vo.setEveryFloorSum(0);
                }
                try{
                    vo.setBuildUserSum(oneData.get(10)==null?0:Integer.valueOf(oneData.get(10)));
                }catch (Exception e){
                try {
                    vo.setBuildUserSum(oneData.get(10) == null ? 0 : Integer.valueOf(oneData.get(10)));
                } catch (Exception e) {
                    vo.setBuildUserSum(0);
                }
                try{
                    vo.setElevatorTotal(oneData.get(11)==null?0:Integer.valueOf(oneData.get(11)));
                }catch (Exception e){
                try {
                    vo.setElevatorTotal(oneData.get(11) == null ? 0 : Integer.valueOf(oneData.get(11)));
                } catch (Exception e) {
                    vo.setElevatorTotal(0);
                }
@@ -121,26 +123,26 @@
                try {
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
                    vo.setBuildDate(sdf.parse(oneData.get(13)));
                }catch (Exception e){
                } catch (Exception e) {
                }
                vo.setRemark(oneData.get(14));
                vo.setGrid(oneData.get(15));
                vo.setGridId(oneData.get(15));
                voList.add(vo);
            }
            //根据list中的IdCard城市来去重
            List<ComMngBuildingExcelVO> newVoList = voList.stream().filter(ListUtils.distinctByKey(ComMngBuildingExcelVO::getName)).collect(Collectors.toList());
            R r = communityService.listSaveBuildingExcelVO(newVoList, communityId,123141L);
            R r = communityService.listSaveBuildingExcelVO(newVoList, communityId, 123141L);
            if (!R.isOk(r)) {
                String errMsg = r.getMsg();
                List<ComMngPopulationImportErrorVO> errorList = JSON.parseArray(errMsg,ComMngPopulationImportErrorVO.class);
                if(!errorList.isEmpty()){
                List<ComMngPopulationImportErrorVO> errorList = JSON.parseArray(errMsg, ComMngPopulationImportErrorVO.class);
                if (!errorList.isEmpty()) {
                    populationImportErrorVOList.addAll(errorList);
                }
                throw new ServiceException("500", JSON.toJSONString(populationImportErrorVOList));
            }else{
                if(!populationImportErrorVOList.isEmpty()){
            } else {
                if (!populationImportErrorVOList.isEmpty()) {
                    throw new ServiceException("500", JSON.toJSONString(populationImportErrorVOList));
                }
            }