manailin
2021-08-20 51508c8c63bb072739a0e3ae45cb11e7599c8f66
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngPopulationServiceImpl.java
@@ -81,6 +81,10 @@
    @Resource
    private ComMngPopulationHouseUserDAO comMngPopulationHouseUserDAO;
    @Resource
    private ComMngPopulationCommunityTagsDAO comMngPopulationCommunityTagsDAO;
    @Resource
    private ComMngPopulationCommunityTagsService comMngPopulationCommunityTagsService;
    @Resource
    private ComMngPopulationDAO comMngPopulationDAO;
    @Resource
    private ComMngPopulationHouseUserService comMngPopulationHouseUserService;
@@ -213,6 +217,12 @@
        //设置年龄
        if (StringUtils.isNotEmpty(comMngPopulationVO.getBirthday())) {
            comMngPopulationVO.setAge(AgeUtils.getAgeFromBirthTimes(comMngPopulationVO.getBirthday()));
        }
        //设置特殊群体标签
        ComMngPopulationCommunityTagsDO comMngPopulationCommunityTagsDO = comMngPopulationCommunityTagsDAO.selectOne(new QueryWrapper<ComMngPopulationCommunityTagsDO>().
                lambda().eq(ComMngPopulationCommunityTagsDO::getPopulationId, populationId));
        if (null != comMngPopulationCommunityTagsDO) {
            comMngPopulationVO.setLabel(comMngPopulationCommunityTagsDO.getLabel());
        }
        //查询当前用户电子档信息
@@ -496,7 +506,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R listSavePopulation(List<ComMngPopulationServeExcelVO> list, Long communityId){
    public R listSavePopulation(List<ComMngPopulationServeExcelVO> list, Long communityId, Long userId){
        //需要新增的房屋集合
        List<ComMngPopulationHouseDO> houseList = new ArrayList<>();
        //需要新增的人口集合
@@ -505,6 +515,10 @@
        List<ComMngPopulationDO> updateList = new ArrayList<>();
        //需要新增的人口与房屋关系集合
        List<ComMngPopulationHouseUserDO> houseUserList = new ArrayList<>();
        //需要新增的人口与社区关系集合
        List<ComMngPopulationCommunityTagsDO> savePopulationCommunityList = new ArrayList<>();
        //需要新增的人口与社区关系集合
        List<ComMngPopulationCommunityTagsDO> updatePopulationCommunityList = new ArrayList<>();
        log.info("开始处理导入数据");
        List<ComMngPopulationMistakeExcelVO> mistakes = new ArrayList<>();
@@ -516,7 +530,7 @@
                log.error("未查询到社区信息");
                return R.fail("未查询到社区信息");
            }
            log.info("开始查询社区信息数据完成");
            log.info("查询社区信息数据完成");
            //查询当前社区标签列表
            List<String> labelList = new ArrayList<>();
@@ -559,6 +573,12 @@
                houseUserMap.put(key,houseUser);
            });
            List<ComMngPopulationCommunityTagsDO> populationCommunityLists = comMngPopulationCommunityTagsDAO.selectList(null);
            HashMap<String,Object> populationCommunityMap = new HashMap<>();
            populationCommunityLists.forEach(populationCommunity -> {
                String key = populationCommunity.getPopulationId() + populationCommunity.getCommunityId() + "";
                populationCommunityMap.put(key,populationCommunity);
            });
            for (ComMngPopulationServeExcelVO vo : list) {
                if (vo.getDoorNo().contains("号")) {
@@ -607,7 +627,7 @@
                    address.append(vo.getHouseNo()).append("号");
                }
                vo.setAddress(address.toString());
                log.info("开始查询小区街路巷是否存在完成");
                log.info("查询小区街路巷是否存在完成");
                log.info("开始查询房屋是否存在");
                //先判断房屋是否存在
@@ -633,7 +653,7 @@
                    populationHouseDO = (ComMngPopulationHouseDO)houseMap.get(houseKey);
                }
                vo.setHouseId(populationHouseDO.getId());
                log.info("开始查询房屋是否存在完成");
                log.info("查询房屋是否存在完成");
                if (StringUtils.isEmpty(vo.getName()) && StringUtils.isEmpty(vo.getCardNo())) {
                    //空户处理完房屋信息,直接返回
@@ -647,20 +667,14 @@
                if(!isOnly(populationKey,populationMap)){
                    //存在实有人口信息,则更新
                    populationDO = (ComMngPopulationDO)populationMap.get(populationKey);
                    ComMngPopulationDO updatePopulationDO = updatePopulationDO(vo,populationDO,labelList);
                    ComMngPopulationDO updatePopulationDO = updatePopulationDO(vo,populationDO,userId);
                    updateList.add(updatePopulationDO);
                    ComMngPopulationMistakeExcelVO mistake = new ComMngPopulationMistakeExcelVO();
                    BeanUtils.copyProperties(vo,mistake);
                    setMistake(mistake, vo);
                    mistake.setMistake("该实有人口已存在,执行更新,社区id::"+ populationDO.getActId());
                    mistakes.add(mistake);
                }else{
                    //不存在实有人口,则新增
                    populationDO = savePopulationDO(vo, populationActVO, comMngVillageDO,labelList);
                    populationDO = savePopulationDO(vo, populationActVO, comMngVillageDO, userId);
                    saveList.add(populationDO);
                }
                log.info("开始查询实有人口是否已存在完成");
                log.info("查询实有人口是否已存在完成");
                log.info("开始查询实有人口房屋居住信息");
                //处理实有人口房屋居住信息
@@ -678,7 +692,53 @@
                        houseUserList.add(populationHouseUserDO);
                    }
                }
                log.info("开始查询实有人口房屋居住信息完成");
                log.info("查询实有人口房屋居住信息完成");
                log.info("开始查询实有人口存在社区信息");
                //处理实有人口与社区关系以及对应特殊群体标签
                String populationCommunityKey = populationDO.getId() + populationActVO.getCommunityId() + "";
                if (populationDO != null) {
                    ComMngPopulationCommunityTagsDO cpopulationCommunityTagsDO = null;
                    if(isOnly(populationCommunityKey,populationCommunityMap)){
                        //实有人口不存在于当前社区
                        cpopulationCommunityTagsDO = new ComMngPopulationCommunityTagsDO();
                        cpopulationCommunityTagsDO.setId(Snowflake.getId());
                        cpopulationCommunityTagsDO.setPopulationId(populationDO.getId());
                        cpopulationCommunityTagsDO.setCommunityId(communityId);
                        List<String> userTag = vo.getUserTagStr().stream().map(userTagStr -> userTagStr.split("\\(")[0]).collect(Collectors.toList());
                        //如果导入数据标签中有当前社区标签列表中不包含的标签,则删除
                        Iterator<String> iterator = userTag.iterator();
                        while (iterator.hasNext()) {
                            String s = iterator.next();
                            if (!labelList.contains(s))
                                iterator.remove();
                        }
                        populationDO.setLabel(Joiner.on(",").join(userTag));
                        populationDO.setCreateBy(userId);
                        savePopulationCommunityList.add(cpopulationCommunityTagsDO);
                    }
                }else {
                    //实有人口存在于当前社区,则更新
                    ComMngPopulationCommunityTagsDO comMngPopulationCommunityTagsDO = (ComMngPopulationCommunityTagsDO)populationCommunityMap.get(populationCommunityKey);
                    List<String> userTag = vo.getUserTagStr().stream().map(userTagStr -> userTagStr.split("\\(")[0]).collect(Collectors.toList());
                    //如果导入数据标签中有当前社区标签列表中不包含的标签,则删除
                    Iterator<String> iterator = userTag.iterator();
                    while (iterator.hasNext()) {
                        String s = iterator.next();
                        if (!labelList.contains(s))
                            iterator.remove();
                    }
                    comMngPopulationCommunityTagsDO.setLabel(Joiner.on(",").join(userTag));
                    comMngPopulationCommunityTagsDO.setUpdateBy(userId);
                    updatePopulationCommunityList.add(comMngPopulationCommunityTagsDO);
                    ComMngPopulationMistakeExcelVO mistake = new ComMngPopulationMistakeExcelVO();
                    BeanUtils.copyProperties(vo,mistake);
                    setMistake(mistake, vo);
                    mistake.setMistake("该实有人口已存在于该社区,执行更新");
                    mistakes.add(mistake);
                }
                log.info("查询实有人口存在社区信息完成");
            }
        }catch (Exception e){
            log.info("出现错误,错误原因:" + e.getMessage());
@@ -689,23 +749,33 @@
        if(!houseList.isEmpty()){
            log.info("执行数据库导入房屋");
            comMngPopulationHouseDAO.insertAll(houseList);
            log.info("执行数据库导入房屋完成");
            log.info("数据库导入房屋完成");
        }
        if(!saveList.isEmpty()){
            log.info("执行数据库导入人口");
            this.baseMapper.insertAll(saveList);
            log.info("执行数据库导入人口完成");
            log.info("数据库导入人口完成");
        }
        if(!updateList.isEmpty()){
            log.info("执行数据库更新人口");
            this.baseMapper.updateAll(updateList);
//            this.updateBatchById(updateList);
            log.info("执行数据库更新人口完成");
            log.info("数据库更新人口完成");
        }
        if(!houseUserList.isEmpty()){
            log.info("执行数据库导入人口房屋关系");
            comMngPopulationHouseUserService.saveBatch(houseUserList);
            log.info("执行数据库导入人口房屋关系完成");
            log.info("数据库导入人口房屋关系完成");
        }
        if(!savePopulationCommunityList.isEmpty()){
            log.info("执行数据库导入人口社区关系");
            comMngPopulationCommunityTagsService.saveBatch(savePopulationCommunityList);
            log.info("数据库导入人口社区关系完成");
        }
        if(!updatePopulationCommunityList.isEmpty()){
            log.info("执行数据库更新人口社区关系");
            comMngPopulationCommunityTagsService.updateBatchById(updatePopulationCommunityList);
            log.info("数据库更新人口社区关系完成");
        }
        log.info("执行数据库导入完成");
@@ -718,7 +788,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R listSaveDrugPopulation(List<ComMngPopulationDrugExcelVO> list, Long communityId) {
    public R listSaveDrugPopulation(List<ComMngPopulationDrugExcelVO> list, Long communityId, Long userId) {
        //需要新增的房屋集合
        List<ComMngPopulationHouseDO> houseList = new ArrayList<>();
        //需要新增的人口集合
@@ -934,7 +1004,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R listSaveCorrectPopulation(List<ComMngPopulationCorrectExcelVO> list, Long communityId) {
    public R listSaveCorrectPopulation(List<ComMngPopulationCorrectExcelVO> list, Long communityId, Long userId) {
        //需要新增的房屋集合
        List<ComMngPopulationHouseDO> houseList = new ArrayList<>();
        //需要新增的人口集合
@@ -1150,7 +1220,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R listSaveMajorPopulation(List<ComMngPopulationMajorExcelVO> list, Long communityId) {
    public R listSaveMajorPopulation(List<ComMngPopulationMajorExcelVO> list, Long communityId, Long userId) {
        //需要新增的房屋集合
        List<ComMngPopulationHouseDO> houseList = new ArrayList<>();
        //需要新增的人口集合
@@ -1366,7 +1436,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R listSaveCultPopulation(List<ComMngPopulationCultExcelVO> list, Long communityId) {
    public R listSaveCultPopulation(List<ComMngPopulationCultExcelVO> list, Long communityId, Long userId) {
        //需要新增的房屋集合
        List<ComMngPopulationHouseDO> houseList = new ArrayList<>();
        //需要新增的人口集合
@@ -1582,7 +1652,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R listSaveRehabilitationPopulation(List<ComMngPopulationRehabilitationExcelVO> list, Long communityId) {
    public R listSaveRehabilitationPopulation(List<ComMngPopulationRehabilitationExcelVO> list, Long communityId, Long userId) {
        //需要新增的房屋集合
        List<ComMngPopulationHouseDO> houseList = new ArrayList<>();
        //需要新增的人口集合
@@ -1798,7 +1868,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R listSaveKeyPopulation(List<ComMngPopulationKeyExcelVO> list, Long communityId) {
    public R listSaveKeyPopulation(List<ComMngPopulationKeyExcelVO> list, Long communityId, Long userId) {
        //需要新增的房屋集合
        List<ComMngPopulationHouseDO> houseList = new ArrayList<>();
        //需要新增的人口集合
@@ -2014,7 +2084,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R listSaveSentencePopulation(List<ComMngPopulationSentenceExcelVO> list, Long communityId) {
    public R listSaveSentencePopulation(List<ComMngPopulationSentenceExcelVO> list, Long communityId, Long userId) {
        //需要新增的房屋集合
        List<ComMngPopulationHouseDO> houseList = new ArrayList<>();
        //需要新增的人口集合
@@ -2230,7 +2300,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R listSaveVeteransPopulation(List<ComMngPopulationVeteransExcelVO> list, Long communityId) {
    public R listSaveVeteransPopulation(List<ComMngPopulationVeteransExcelVO> list, Long communityId, Long userId) {
        //需要新增的房屋集合
        List<ComMngPopulationHouseDO> houseList = new ArrayList<>();
        //需要新增的人口集合
@@ -2446,7 +2516,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R listSaveDisabilityPopulation(List<ComMngPopulationDisabilityExcelVO> list, Long communityId) {
    public R listSaveDisabilityPopulation(List<ComMngPopulationDisabilityExcelVO> list, Long communityId, Long userId) {
        //需要新增的房屋集合
        List<ComMngPopulationHouseDO> houseList = new ArrayList<>();
        //需要新增的人口集合
@@ -2662,7 +2732,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R listSaveLowSecurityPopulation(List<ComMngPopulationLowSecurityExcelVO> list, Long communityId) {
    public R listSaveLowSecurityPopulation(List<ComMngPopulationLowSecurityExcelVO> list, Long communityId, Long userId) {
        //需要新增的房屋集合
        List<ComMngPopulationHouseDO> houseList = new ArrayList<>();
        //需要新增的人口集合
@@ -2881,24 +2951,25 @@
    }
    private ComMngPopulationDO updatePopulationDO(ComMngPopulationServeExcelVO vo, ComMngPopulationDO populationDO,List<String> labelList){
    private ComMngPopulationDO updatePopulationDO(ComMngPopulationServeExcelVO vo, ComMngPopulationDO populationDO, Long userId){
        BeanUtils.copyProperties(vo, populationDO);
        List<String> userTag = vo.getUserTagStr().stream().map(userTagStr -> userTagStr.split("\\(")[0]).collect(Collectors.toList());
        //如果导入数据标签中有当前社区标签列表中不包含的标签,则删除
        Iterator<String> iterator = userTag.iterator();
        while (iterator.hasNext()) {
            String s = iterator.next();
            if (!labelList.contains(s))
                iterator.remove();
        }
//        List<String> userTag = vo.getUserTagStr().stream().map(userTagStr -> userTagStr.split("\\(")[0]).collect(Collectors.toList());
//        //如果导入数据标签中有当前社区标签列表中不包含的标签,则删除
//        Iterator<String> iterator = userTag.iterator();
//        while (iterator.hasNext()) {
//            String s = iterator.next();
//            if (!labelList.contains(s))
//                iterator.remove();
//        }
        String cardNoAES = populationDO.getCardNo();
        try {
            cardNoAES = AESUtil.encrypt128(vo.getCardNo(), aesKey);
        }catch (Exception e){
            log.error("身份证加密失败");
        }
        populationDO.setLabel(Joiner.on(",").join(userTag));
//        populationDO.setLabel(Joiner.on(",").join(userTag));
        populationDO.setCardNo(cardNoAES);
        populationDO.setUpdateBy(userId);
        return populationDO;
    }
@@ -3263,23 +3334,23 @@
        return populationDO;
    }
    private ComMngPopulationDO savePopulationDO(ComMngPopulationServeExcelVO vo, ComPopulationActVO comActDO, ComMngVillageDO comMngVillageDO,List<String> labelList) {
    private ComMngPopulationDO savePopulationDO(ComMngPopulationServeExcelVO vo, ComPopulationActVO comActDO, ComMngVillageDO comMngVillageDO, Long userId) {
        ComMngPopulationDO populationDO = new ComMngPopulationDO();
        BeanUtils.copyProperties(vo, populationDO);
        populationDO.setId(Snowflake.getId());
        List<String> userTag = vo.getUserTagStr().stream().map(userTagStr -> userTagStr.split("\\(")[0]).collect(Collectors.toList());
        //如果导入数据标签中有当前社区标签列表中不包含的标签,则删除
        Iterator<String> iterator = userTag.iterator();
        while (iterator.hasNext()) {
            String s = iterator.next();
            if (!labelList.contains(s))
                iterator.remove();
        }
//        List<String> userTag = vo.getUserTagStr().stream().map(userTagStr -> userTagStr.split("\\(")[0]).collect(Collectors.toList());
//
//        //如果导入数据标签中有当前社区标签列表中不包含的标签,则删除
//        Iterator<String> iterator = userTag.iterator();
//        while (iterator.hasNext()) {
//            String s = iterator.next();
//            if (!labelList.contains(s))
//                iterator.remove();
//        }
        populationDO.setVillageId(comMngVillageDO.getVillageId());
        populationDO.setActId(comActDO.getCommunityId());
        populationDO.setStreetId(comActDO.getStreetId());
        populationDO.setLabel(Joiner.on(",").join(userTag));
//        populationDO.setLabel(Joiner.on(",").join(userTag));
        populationDO.setVillageName(comMngVillageDO.getGroupAt());
        populationDO.setCardNoStr(vo.getCardNo());
        populationDO.setUpdateAt(new Date());
@@ -3291,6 +3362,7 @@
            log.error("身份证加密失败");
        }
        populationDO.setCardNo(cardNoAES);
        populationDO.setCreateBy(userId);
        //新增的时候默认绑定房屋id
//        if ((vo.getIsRent() != null && vo.getIsRent().equals(PopulHouseUseEnum.SELF.getCode())) ||
//                (vo.getIsResidence() != null && vo.getIsResidence().intValue() == 1)) {