| | |
| | | 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; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Slf4j |
| | | public class ComMngBuildingExcelListen extends AnalysisEventListener<Map<Integer, String>> { |
| | | |
| | | private CommunityService communityService; |
| | | |
| | | private GridService gridService; |
| | | |
| | | private Long communityId; |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param headMap |
| | | * @param context |
| | | */ |
| | |
| | | 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()); |
| | |
| | | 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); |
| | | } |
| | | |
| | |
| | | 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)); |
| | | } |
| | | } |