xyh
2021-06-14 d6e86197a5a857c697465fb97a488c7327c9cb3b
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/listen/ComMngBuildingExcelListen.java
@@ -11,6 +11,7 @@
import com.panzhihua.common.service.community.CommunityService;
import com.panzhihua.common.service.grid.GridService;
import com.panzhihua.common.utlis.Snowflake;
import com.panzhihua.common.utlis.StringUtils;
import lombok.extern.slf4j.Slf4j;
import java.text.SimpleDateFormat;
@@ -73,6 +74,7 @@
     */
    private void saveData() {
        try {
            int index = 2;
            ArrayList<ComMngBuildingExcelVO> voList = Lists.newArrayList();
            List<ComMngPopulationImportErrorVO> populationImportErrorVOList = new ArrayList<>();
            for (int i = 1; i < list.size(); i++) {
@@ -81,71 +83,97 @@
                vo.setId(Snowflake.getId());
                vo.setUseType(oneData.get(1));
                vo.setBuildType(oneData.get(2));
                vo.setAlley(oneData.get(3));
                if (StringUtils.isEmpty(oneData.get(oneData.get(3)))) {
                    ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO();
                    importErrorVO.setErrorMsg("街路巷不能为空");
                    importErrorVO.setErrorPosition("第" + index + "行");
                    populationImportErrorVOList.add(importErrorVO);
                    vo.setAlley(oneData.get(3));
                }
                vo.setVillageName(oneData.get(4));
                vo.setDoorNo(oneData.get(5));
                vo.setName(oneData.get(6));
                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) {
                    vo.setBuildFloorSum(0);
                }
                    if (StringUtils.isEmpty(oneData.get(oneData.get(5)))) {
                        ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO();
                        importErrorVO.setErrorMsg("门牌号不能为空");
                        importErrorVO.setErrorPosition("第" + index + "行");
                        populationImportErrorVOList.add(importErrorVO);
                        vo.setDoorNo(oneData.get(5));
                    }
                    if (StringUtils.isEmpty(oneData.get(oneData.get(5)))) {
                        ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO();
                        importErrorVO.setErrorMsg("楼栋号不能为空");
                        importErrorVO.setErrorPosition("第" + index + "行");
                        populationImportErrorVOList.add(importErrorVO);
                        vo.setName(oneData.get(6));
                    }
                    try {
                        vo.setUnitTotal(oneData.get(7) == null ? 0 : Integer.valueOf(oneData.get(7)));
                    } catch (Exception e1) {
                        vo.setUnitTotal(0);
                    }
                    try {
                        vo.setBuildFloorSum(oneData.get(8) == null ? 0 : Integer.valueOf(oneData.get(8)));
                    } catch (Exception e1) {
                        vo.setBuildFloorSum(0);
                    }
                try {
                    vo.setEveryFloorSum(oneData.get(9) == null ? 0 : Integer.valueOf(oneData.get(9)));
                } catch (Exception e) {
                    vo.setEveryFloorSum(0);
                    try {
                        vo.setEveryFloorSum(oneData.get(9) == null ? 0 : Integer.valueOf(oneData.get(9)));
                    } catch (Exception e1) {
                        vo.setEveryFloorSum(0);
                    }
                    try {
                        vo.setBuildUserSum(oneData.get(10) == null ? 0 : Integer.valueOf(oneData.get(10)));
                    } catch (Exception e1) {
                        vo.setBuildUserSum(0);
                    }
                    try {
                        vo.setElevatorTotal(oneData.get(11) == null ? 0 : Integer.valueOf(oneData.get(11)));
                    } catch (Exception e1) {
                        vo.setElevatorTotal(0);
                    }
                    vo.setPropertyCompanyName(oneData.get(12));
                    try {
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
                        vo.setBuildDate(sdf.parse(oneData.get(13)));
                    } catch (Exception e1) {
                    }
                    vo.setRemark(oneData.get(14));
                    vo.setGridId(oneData.get(15));
                    vo.setGridName(oneData.get(15));
                    voList.add(vo);
                    index++;
                }
                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) {
                    vo.setElevatorTotal(0);
                }
                vo.setPropertyCompanyName(oneData.get(12));
                try {
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
                    vo.setBuildDate(sdf.parse(oneData.get(13)));
                } catch (Exception e) {
                }
                vo.setRemark(oneData.get(14));
                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(voList, communityId);
            if (!R.isOk(r)) {
                String errMsg = r.getMsg();
                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()) {
                R r = communityService.listSaveBuildingExcelVO(voList, communityId);
                if (!R.isOk(r)) {
                    String errMsg = r.getMsg();
                    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()) {
                        throw new ServiceException("500", JSON.toJSONString(populationImportErrorVOList));
                    }
                }
            }
        } catch (NumberFormatException e) {
            }
        }catch (NumberFormatException e){
            e.printStackTrace();
        }
    }
}