From 2e64c232ab6b51b2cecf1ee96e1e9b709234f326 Mon Sep 17 00:00:00 2001 From: huanghongfa <huanghongfa123456> Date: 星期六, 21 八月 2021 16:35:14 +0800 Subject: [PATCH] 随手拍改版接口开发 --- springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngPopulationHouseServiceImpl.java | 206 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 202 insertions(+), 4 deletions(-) diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngPopulationHouseServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngPopulationHouseServiceImpl.java index 9235fa4..b23b247 100644 --- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngPopulationHouseServiceImpl.java +++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngPopulationHouseServiceImpl.java @@ -1,23 +1,35 @@ package com.panzhihua.service_community.service.impl; +import cn.hutool.core.util.IdcardUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.panzhihua.common.model.dtos.community.CascadeHouseDTO; import com.panzhihua.common.model.dtos.community.ComMngPopulationHouseAdminDTO; import com.panzhihua.common.model.dtos.community.ComMngPopulationHouseEditAdminDTO; +import com.panzhihua.common.model.dtos.grid.PageComMngVillageBuildHouseAppDTO; +import com.panzhihua.common.model.dtos.grid.admin.ComMngPopulationRelationHouseDTO; +import com.panzhihua.common.model.dtos.grid.admin.ComMngPopulationSubordinateDTO; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.vos.community.ComMngCascadeHouseVO; import com.panzhihua.common.model.vos.community.ComMngPopulationHouseDetailAdminVO; import com.panzhihua.common.model.vos.community.ComMngPopulationHouseTotalVO; import com.panzhihua.common.model.vos.community.ComMngPopulationHouseUserAdminVO; +import com.panzhihua.common.model.vos.grid.ComMngVillageBuildingHouseDetailVO; +import com.panzhihua.common.model.vos.grid.ComMngVillageBuildingHouseVO; +import com.panzhihua.common.model.vos.grid.PopulationListVO; +import com.panzhihua.common.model.vos.grid.admin.ComMngSubordinateVO; +import com.panzhihua.common.utlis.Snowflake; import com.panzhihua.service_community.dao.ComActVillageDAO; import com.panzhihua.service_community.dao.ComMngPopulationDAO; import com.panzhihua.service_community.dao.ComMngPopulationHouseDAO; import com.panzhihua.service_community.dao.ComMngPopulationHouseUserDAO; import com.panzhihua.service_community.model.dos.ComMngPopulationDO; import com.panzhihua.service_community.model.dos.ComMngPopulationHouseDO; +import com.panzhihua.service_community.model.dos.ComMngPopulationHouseUserDO; import com.panzhihua.service_community.model.dos.ComMngVillageDO; import com.panzhihua.service_community.service.ComMngPopulationHouseService; import com.panzhihua.service_community.service.ComMngVillageService; @@ -26,6 +38,10 @@ import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collectors; import javax.annotation.Resource; import java.util.*; @@ -46,6 +62,8 @@ private ComMngPopulationDAO comMngPopulationDAO; @Resource private ComActVillageDAO comActVillageDAO; + @Resource + private ComMngPopulationHouseDAO comMngPopulationHouseDAO; /** * 查询房屋级联菜单 @@ -67,7 +85,7 @@ cascadeHouseVOList = cascadeHouseVOList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getAlley()))), ArrayList::new)); cascadeHouseVOList.forEach(cascade -> { cascade.setName(cascade.getAlley()); - }); + }); break; case 2: if(houseDO != null){ @@ -207,9 +225,9 @@ @Override @Transactional(rollbackFor = Exception.class) public R deleteHouses(List<Long> Ids){ - LambdaQueryWrapper<ComMngPopulationDO> paramWrapper = Wrappers.lambdaQuery(); - paramWrapper.in(ComMngPopulationDO::getVillageId, Ids); - List<ComMngPopulationDO> mngPopulationDOList = comMngPopulationDAO.selectList(paramWrapper); + LambdaQueryWrapper<ComMngPopulationHouseUserDO> paramWrapper = Wrappers.lambdaQuery(); + paramWrapper.in(ComMngPopulationHouseUserDO::getHouseId, Ids); + List<ComMngPopulationHouseUserDO> mngPopulationDOList = comMngPopulationHouseUserDAO.selectList(paramWrapper); if (!mngPopulationDOList.isEmpty()) { return R.fail("无法删除,已绑定实有人口!"); } @@ -245,4 +263,184 @@ return R.ok(this.baseMapper.getRegion(communityId)); } + /** + * 小区楼栋下房屋列表 + * @param buildHouseAppDTO 请求参数 + * @return 房屋列表 + */ + @Override + public R getGridVillageBuildingHouseList(PageComMngVillageBuildHouseAppDTO buildHouseAppDTO){ + + IPage<ComMngVillageBuildingHouseVO> buildingHouseVOIPage = this.baseMapper.getGridVillageBuildingHouseList(new Page(buildHouseAppDTO.getPageNum(),buildHouseAppDTO.getPageSize()),buildHouseAppDTO); + if(!buildingHouseVOIPage.getRecords().isEmpty()){ + buildingHouseVOIPage.getRecords().forEach(house ->{ + boolean result=house.getHouseNo().matches("[0-9]+"); + if(result){//该字段为纯数字 + if(house.getHouseNo().length() == 4){ + house.setBuildingNum(house.getHouseNo().substring(0,2).replaceAll("^(0+)", "")); + }else if(house.getHouseNo().length() == 3){ + house.setBuildingNum(house.getHouseNo().substring(0,1).replaceAll("^(0+)", "")); + } + }else{ + house.setBuildingNum("-"); + } + }); + } + return R.ok(buildingHouseVOIPage); + } + + /** + * 小区楼栋下房屋信息 + * @param houseId 房屋id + * @return 房屋信息 + */ + @Override + public R getGridVillageBuildingHouseDetail(Long houseId){ + + ComMngVillageBuildingHouseDetailVO buildingHouseDetailVO = this.baseMapper.getGridVillageBuildingHouseDetail(houseId); + if(buildingHouseDetailVO != null){ + + //转换楼层数 + String houseNo = buildingHouseDetailVO.getHouseNo(); + boolean result = houseNo.matches("[0-9]+"); + if(result){//该字段为纯数字 + if(houseNo.length() == 4){ + buildingHouseDetailVO.setBuildingNum(houseNo.substring(0,2).replaceAll("^(0+)", "")); + }else if(houseNo.length() == 3){ + buildingHouseDetailVO.setBuildingNum(houseNo.substring(0,1).replaceAll("^(0+)", "")); + } + }else{ + buildingHouseDetailVO.setBuildingNum("-"); + } + + //查询该房屋的户主信息 + List<PopulationListVO> householderList = this.baseMapper.getGridVillageBuildingPopulationList(buildingHouseDetailVO.getId(),1,null); + if(!householderList.isEmpty()){ + householderList.forEach(householder -> { + try { + Integer age = IdcardUtil.getAgeByIdCard(householder.getCardNo()); + householder.setAge(age); + }catch (Exception e){ + log.error("身份证号码转换年龄失败,人员id:" + householder.getId()); + } + }); + buildingHouseDetailVO.setHouseholderList(householderList); + } + //查询该房屋的住户信息 + List<PopulationListVO> populationList = this.baseMapper.getGridVillageBuildingPopulationList(buildingHouseDetailVO.getId(),null,1); + if(!populationList.isEmpty()){ + populationList.forEach(population -> { + try { + Integer age = IdcardUtil.getAgeByIdCard(population.getCardNo()); + population.setAge(age); + }catch (Exception e){ + log.error("身份证号码转换年龄失败,人员id:" + population.getId()); + } + }); + buildingHouseDetailVO.setPopulationList(populationList); + } + } + return R.ok(buildingHouseDetailVO); + } + + private static <T> Predicate<T> distinctByKey(Function<? super T, Object> keyExtractor) { + Map<Object, Boolean> seen = new ConcurrentHashMap<>(); + return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null; + } + + @Override + public R subordinate(ComMngPopulationSubordinateDTO subordinateDTO){ + + List<ComMngSubordinateVO> subordinateList = new ArrayList<>(); + + ComMngPopulationHouseDO houseDO = null; + if(subordinateDTO.getHouseId() != null){ + houseDO = this.baseMapper.selectById(subordinateDTO.getHouseId()); + } + + switch (subordinateDTO.getType()){ + case 1: + subordinateList = this.baseMapper.getHouseLevelByFloors(subordinateDTO.getVillageId()); +// subordinateList = subordinateList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getFloor()))), ArrayList::new)); + subordinateList = subordinateList.stream().filter(distinctByKey(ComMngSubordinateVO::getFloor)).collect(Collectors.toList()); + subordinateList.forEach(cascade -> { + if(cascade.getFloor().contains("栋")){ + cascade.setName(cascade.getFloor()); + }else{ + cascade.setName(cascade.getFloor() + "栋"); + } + }); + break; + case 2: + if(houseDO != null){ + subordinateList = this.baseMapper.getHouseLevelByUnitNos(houseDO.getVillageId(),houseDO.getFloor()); + subordinateList = subordinateList.stream().filter(distinctByKey(ComMngSubordinateVO::getUnitNo)).collect(Collectors.toList()); +// subordinateList = subordinateList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getUnitNo()))), ArrayList::new)); + subordinateList.forEach(cascade -> { + if(cascade.getUnitNo().contains("单元")){ + cascade.setName(cascade.getUnitNo()); + }else{ + cascade.setName(cascade.getUnitNo() + "单元"); + } + }); + } + break; + case 3: + if(houseDO != null) { + subordinateList = this.baseMapper.getHouseLevelByHouseNos(houseDO.getVillageId(), houseDO.getFloor(), houseDO.getUnitNo()); + subordinateList = subordinateList.stream().filter(distinctByKey(ComMngSubordinateVO::getHouseNo)).collect(Collectors.toList()); +// subordinateList = subordinateList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getHouseNo()))), ArrayList::new)); + subordinateList.forEach(cascade -> { + cascade.setName(cascade.getHouseNo()); + }); + } + break; + default: + break; + } + return R.ok(subordinateList); + } + + public R populationRelationHouse(ComMngPopulationRelationHouseDTO relationHouseDTO){ + + if(relationHouseDTO.getPopulationId().isEmpty()){ + return R.fail("请选择居民"); + } + + //查询房屋信息 + ComMngPopulationHouseDO houseDO = comMngPopulationHouseDAO.selectById(relationHouseDTO.getHouseId()); + if(houseDO == null){ + return R.fail("未查到房屋信息"); + } + + relationHouseDTO.getPopulationId().forEach(population -> { + //修改人口信息 + ComMngPopulationDO populationDO = new ComMngPopulationDO(); + populationDO.setId(population); + populationDO.setHouseId(houseDO.getId()); + populationDO.setRoad(houseDO.getAlley()); + populationDO.setDoorNo(houseDO.getHouseNum()); + populationDO.setFloor(houseDO.getFloor()); + populationDO.setUnitNo(houseDO.getUnitNo()); + populationDO.setHouseNo(houseDO.getHouseNo()); + comMngPopulationDAO.updateById(populationDO); + + //添加房屋关系 + ComMngPopulationHouseUserDO houseUserDO = comMngPopulationHouseUserDAO.selectOne(new QueryWrapper<ComMngPopulationHouseUserDO>() + .lambda().eq(ComMngPopulationHouseUserDO::getPopulId,population).eq(ComMngPopulationHouseUserDO::getHouseId,relationHouseDTO.getHouseId())); + if(houseUserDO == null){ + houseUserDO = new ComMngPopulationHouseUserDO(); + houseUserDO.setId(Snowflake.getId()); + houseUserDO.setHouseId(relationHouseDTO.getHouseId()); + houseUserDO.setPopulId(population); + houseUserDO.setRelationId(ComMngPopulationHouseUserDO.relationId.zizhu); + comMngPopulationHouseUserDAO.insert(houseUserDO); + }else{ + houseUserDO.setRelationId(ComMngPopulationHouseUserDO.relationId.zizhu); + comMngPopulationHouseUserDAO.updateById(houseUserDO); + } + }); + return R.ok(); + } + } -- Gitblit v1.7.1