package com.panzhihua.service_community.service.impl;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
|
import com.panzhihua.service_community.dao.*;
|
import com.panzhihua.service_community.model.dos.*;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.stereotype.Service;
|
|
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.google.common.collect.Lists;
|
import com.panzhihua.common.model.dtos.community.PageComMngVillageDTO;
|
import com.panzhihua.common.model.dtos.grid.ComMngVillageListAppDTO;
|
import com.panzhihua.common.model.dtos.grid.admin.ComMngVillageListExportAdminDTO;
|
import com.panzhihua.common.model.vos.R;
|
import com.panzhihua.common.model.vos.community.ComMngVillageServeExcelVO;
|
import com.panzhihua.common.model.vos.community.ComMngVillageVO;
|
import com.panzhihua.common.model.vos.grid.ComMngVillageBuildingVO;
|
import com.panzhihua.common.utlis.Snowflake;
|
import com.panzhihua.common.utlis.StringUtils;
|
import com.panzhihua.service_community.service.ComMngVillageService;
|
import org.springframework.util.CollectionUtils;
|
|
/**
|
* @author: llming
|
* @description: 实有房屋
|
**/
|
@Service
|
public class ComMngVillageServiceImpl extends ServiceImpl<ComActVillageDAO, ComMngVillageDO>
|
implements ComMngVillageService {
|
@Resource
|
ComActVillageDAO comActVillageDAO;
|
@Resource
|
ComActDAO comActDAO;
|
@Resource
|
ComMngPopulationDAO populationDAO;
|
@Resource
|
private ComMngPopulationHouseDAO comMngPopulationHouseDAO;
|
@Resource
|
private ComMngBuildingDAO comMngBuildingDAO;
|
|
@Override
|
public R addComActVillage(ComMngVillageVO comMngVillageVO) {
|
ComMngVillageDO comMngVillageDO = new ComMngVillageDO();
|
LambdaQueryWrapper<ComMngVillageDO> param = new QueryWrapper<ComMngVillageDO>().lambda();
|
param.eq(ComMngVillageDO::getCommunityId, comMngVillageVO.getCommunityId());
|
param.eq(ComMngVillageDO::getAlley, comMngVillageVO.getAlley());
|
param.eq(ComMngVillageDO::getHouseNum, comMngVillageVO.getHouseNum());
|
Integer resultCount = comActVillageDAO.selectCount(param);
|
if (resultCount > 0) {
|
return R.fail("实有房屋已经存在");
|
}
|
BeanUtils.copyProperties(comMngVillageVO, comMngVillageDO);
|
ComActDO comActDO = comActDAO.selectById(comMngVillageDO.getCommunityId());
|
if (comActDO == null || comActDO.getStreetId() == null) {
|
return R.fail("社区没有绑定街道,请绑定后操作!");
|
}
|
comMngVillageDO.setVillageId(Snowflake.getId());
|
comMngVillageDO.setStreetId(comActDO.getStreetId());
|
comMngVillageDO.setUpdateAt(new Date());
|
int insert = comActVillageDAO.insert(comMngVillageDO);
|
if (insert > 0) {
|
// param.eq(ComMngVillageDO::getAlley, comMngVillageVO.getAlley());
|
// param.eq(ComMngVillageDO::getHouseNum, comMngVillageVO.getHouseNum());
|
// ComMngVillageDO comMngVillageDO1 = comActVillageDAO.selectOne(param);
|
BeanUtils.copyProperties(comMngVillageDO, comMngVillageVO);
|
return R.ok(comMngVillageVO);
|
}
|
return R.fail();
|
}
|
|
@Override
|
public R listComActVillage(ComMngVillageVO comMngVillageVO) {
|
List<ComMngVillageDO> vos = Lists.newArrayList();
|
if(comMngVillageVO.getCommunityId()!=null){
|
LambdaQueryWrapper<ComMngVillageDO> param = new QueryWrapper<ComMngVillageDO>().lambda();
|
if(StringUtils.isNotEmpty(comMngVillageVO.getName())){
|
param.like(ComMngVillageDO::getName, comMngVillageVO.getName());
|
}
|
if(comMngVillageVO.getCommunityId()!=0){
|
param.eq(ComMngVillageDO::getCommunityId, comMngVillageVO.getCommunityId());
|
}
|
List<ComMngVillageDO> comMngVillageDOS = comActVillageDAO.selectList(param);
|
BeanUtils.copyProperties(comMngVillageDOS, vos);
|
if(CollectionUtils.isEmpty(comMngVillageDOS)){
|
//默认添加小区
|
ComMngVillageDO comMngVillageDO=new ComMngVillageDO();
|
comMngVillageDO.setVillageId(1540264792718184449L);
|
comMngVillageDO.setType(1);
|
comMngVillageDO.setName("该社区/村暂未添加小区(院落),请先选择本项");
|
comMngVillageDOS.add(comMngVillageDO);
|
}
|
return R.ok(comMngVillageDOS);
|
}
|
if(CollectionUtils.isEmpty(vos)){
|
//默认添加小区
|
ComMngVillageDO comMngVillageDO=new ComMngVillageDO();
|
comMngVillageDO.setVillageId(1540264792718184449L);
|
comMngVillageDO.setType(1);
|
comMngVillageDO.setName("该社区/村暂未添加小区(院落),请先选择本项");
|
vos.add(comMngVillageDO);
|
}
|
return R.ok(vos);
|
}
|
|
@Override
|
public ComMngVillageDO getVillageById(Long villageId) {
|
ComMngVillageDO comMngVillageDO = new ComMngVillageDO();
|
comMngVillageDO = comActVillageDAO.selectById(villageId);
|
return comMngVillageDO;
|
}
|
|
@Override
|
public R pageComActVillage(PageComMngVillageDTO pageComMngVillageDTO) {
|
LambdaQueryWrapper<ComMngVillageDO> userLambdaQueryWrapper = Wrappers.lambdaQuery();
|
if (pageComMngVillageDTO.getCommunityId() != null) {
|
userLambdaQueryWrapper.eq(ComMngVillageDO::getCommunityId, pageComMngVillageDTO.getCommunityId());
|
}
|
if (pageComMngVillageDTO.getAlley() != null) {
|
userLambdaQueryWrapper.like(ComMngVillageDO::getAlley, pageComMngVillageDTO.getAlley());
|
}
|
if (StringUtils.isNotEmpty(pageComMngVillageDTO.getHouseNum())) {
|
userLambdaQueryWrapper.eq(ComMngVillageDO::getHouseNum, pageComMngVillageDTO.getHouseNum());
|
}
|
if (StringUtils.isNotEmpty(pageComMngVillageDTO.getGroupAt())) {
|
userLambdaQueryWrapper.eq(ComMngVillageDO::getGroupAt, pageComMngVillageDTO.getGroupAt());
|
}
|
if (pageComMngVillageDTO.getType() != null) {
|
userLambdaQueryWrapper.eq(ComMngVillageDO::getType, pageComMngVillageDTO.getType());
|
}
|
Page userPage = new Page(pageComMngVillageDTO.getPageNum(), pageComMngVillageDTO.getPageSize());
|
IPage<ComMngVillageDO> doPager =
|
comActVillageDAO.selectPage(userPage, userLambdaQueryWrapper.orderByDesc(ComMngVillageDO::getName));
|
|
IPage<ComMngVillageVO> villageVOIPage = new Page<>();
|
villageVOIPage.setCurrent(doPager.getCurrent());
|
villageVOIPage.setPages(doPager.getPages());
|
villageVOIPage.setSize(doPager.getSize());
|
villageVOIPage.setTotal(doPager.getTotal());
|
if (!doPager.getRecords().isEmpty()) {
|
List<ComMngVillageVO> villageVOList = new ArrayList<>();
|
// 统计小区下的数据
|
doPager.getRecords().forEach(village -> {
|
ComMngVillageVO villageVO = new ComMngVillageVO();
|
BeanUtils.copyProperties(village, villageVO);
|
// 查询小区统计数据
|
ComMngVillageVO villageTotal = comActVillageDAO.getStatisticsCount(village.getVillageId());
|
if (villageTotal != null) {
|
villageVO.setFloorTotal(villageTotal.getFloorTotal());
|
villageVO.setCarTotal(villageTotal.getCarTotal());
|
villageVO.setHouseTotal(villageTotal.getHouseTotal());
|
villageVO.setPopulationTotal(villageTotal.getPopulationTotal());
|
}
|
villageVOList.add(villageVO);
|
});
|
villageVOIPage.setRecords(villageVOList);
|
}
|
return R.ok(villageVOIPage);
|
}
|
|
@Override
|
public R delecComActVillage(List<Long> Ids) {
|
LambdaQueryWrapper<ComMngPopulationHouseDO> paramHouseWrapper = Wrappers.lambdaQuery();
|
paramHouseWrapper.in(ComMngPopulationHouseDO::getVillageId, Ids);
|
List<ComMngPopulationHouseDO> populationHouseDOList = comMngPopulationHouseDAO.selectList(paramHouseWrapper);
|
if (!populationHouseDOList.isEmpty()) {
|
return R.fail("无法删除,已绑定实有房屋!");
|
}
|
|
LambdaQueryWrapper<ComMngPopulationDO> paramWrapper = Wrappers.lambdaQuery();
|
paramWrapper.in(ComMngPopulationDO::getVillageId, Ids);
|
List<ComMngPopulationDO> mngPopulationDOList = populationDAO.selectList(paramWrapper);
|
if (!mngPopulationDOList.isEmpty()) {
|
return R.fail("无法删除,已绑定实有人口!");
|
}
|
int delete = comActVillageDAO.deleteBatchIds(Ids);
|
if (delete > 0) {
|
return R.ok();
|
}
|
return R.fail();
|
}
|
|
@Override
|
public R listSaveVillage(List<ComMngVillageServeExcelVO> list, Long communityId) {
|
// 思路:获取社区下所有的实有房屋(小区),打印已经存在的重复数据
|
if (list.size() == 0) {
|
return R.fail("数据为空!");
|
}
|
List<ComMngVillageDO> comMngVillageDOs = comActVillageDAO
|
.selectList(new QueryWrapper<ComMngVillageDO>().lambda().eq(ComMngVillageDO::getCommunityId, communityId));
|
int index = 2;
|
for (ComMngVillageServeExcelVO vo : list) {
|
if (vo.getHouseNum() == null) {
|
return R.fail("门牌号第" + index + "行为空!");
|
}
|
if (vo.getAlley() == null) {
|
return R.fail("街路巷第" + index + "行为空!");
|
}
|
// 判断DB和exel数据重复判断
|
boolean result = comMngVillageDOs.stream().anyMatch(
|
village -> village.getAlley().equals(vo.getAlley()) && village.getHouseNum().equals(vo.getHouseNum()));
|
if (result) {
|
return R.fail("导入街路巷重复(" + vo.getAlley() + ")");
|
}
|
ComMngVillageDO comMngVillageDO=new ComMngVillageDO();
|
BeanUtils.copyProperties(vo,comMngVillageDO);
|
comMngVillageDOs.add(comMngVillageDO);
|
index++;
|
}
|
ComActDO comActDO = comActDAO.selectById(communityId);
|
if (comActDO.getStreetId() == null || comActDO.getStreetId().toString().equals("")) {
|
return R.fail("请绑定街道,再操作!");
|
}
|
ArrayList<ComMngVillageDO> comMngVillageDOS = Lists.newArrayList();
|
list.forEach(vo -> {
|
ComMngVillageDO comMngVillageDO = new ComMngVillageDO();
|
BeanUtils.copyProperties(vo, comMngVillageDO);
|
if(StringUtils.isNotEmpty(vo.getType())){
|
if("城镇".equals(vo.getType())){
|
comMngVillageDO.setType(1);
|
}
|
else {
|
comMngVillageDO.setType(2);
|
}
|
}
|
comMngVillageDO.setCommunityId(comActDO.getCommunityId());
|
comMngVillageDO.setStreetId(comActDO.getStreetId());
|
StringBuilder path = new StringBuilder();
|
path.append(vo.getAlley()).append(">").append(vo.getHouseNum()).append(">").append(vo.getGroupAt());
|
comMngVillageDO.setPath(path.toString());
|
comMngVillageDO.setUpdateAt(new Date());
|
comMngVillageDO.setName(comMngVillageDO.getGroupAt());
|
comMngVillageDOS.add(comMngVillageDO);
|
});
|
this.saveBatch(comMngVillageDOS);
|
return R.ok("共计导入实有小区数量:" + comMngVillageDOS.size());
|
}
|
|
@Override
|
public R editVillage(Long villageId, ComMngVillageVO comMngVillageVO) {
|
ComMngVillageDO comMngVillageDO = this.baseMapper.selectById(villageId);
|
if (comMngVillageDO == null) {
|
return R.fail("id有误!");
|
}
|
if(!comMngVillageVO.getAlley().equals(comMngVillageDO.getAlley())&&!comMngVillageVO.getHouseNum().equals(comMngVillageDO.getHouseNum())){
|
Integer count= this.baseMapper.selectCount(new QueryWrapper<ComMngVillageDO>().lambda().eq(ComMngVillageDO::getAlley,comMngVillageVO.getAlley()).eq(ComMngVillageDO::getHouseNum,comMngVillageVO.getHouseNum()));
|
if(count>0){
|
return R.fail("街路巷已存在");
|
}
|
//历史人口数据处理
|
List<ComMngPopulationDO> populationDOS=this.populationDAO.selectList(new QueryWrapper<ComMngPopulationDO>().lambda().eq(ComMngPopulationDO::getVillageId,villageId));
|
if(!populationDOS.isEmpty()){
|
populationDOS.forEach(comMngPopulationDO -> {
|
comMngPopulationDO.setRoad(comMngVillageVO.getAlley());
|
comMngPopulationDO.setDoorNo(comMngVillageVO.getHouseNum());
|
comMngPopulationDO.setAddress(comMngPopulationDO.getAddress().replace(comMngVillageDO.getAlley()+comMngVillageDO.getHouseNum(),comMngVillageVO.getAlley()+comMngVillageVO.getHouseNum()));
|
this.populationDAO.updateById(comMngPopulationDO);
|
});
|
}
|
//历史房屋数据处理
|
List<ComMngPopulationHouseDO> comMngPopulationHouseDOS=this.comMngPopulationHouseDAO.selectList(new QueryWrapper<ComMngPopulationHouseDO>().lambda().eq(ComMngPopulationHouseDO::getVillageId,comMngVillageVO.getVillageId()));
|
if(!comMngPopulationHouseDOS.isEmpty()){
|
comMngPopulationHouseDOS.forEach(comMngPopulationHouseDO -> {
|
comMngPopulationHouseDO.setAlley(comMngVillageVO.getAlley());
|
comMngPopulationHouseDO.setHouseNum(comMngVillageVO.getHouseNum());
|
comMngPopulationHouseDO.setAddress(comMngPopulationHouseDO.getAddress().replace(comMngVillageDO.getAlley()+comMngVillageDO.getHouseNum(),comMngVillageVO.getAlley()+comMngVillageVO.getHouseNum()));
|
this.comMngPopulationHouseDAO.updateById(comMngPopulationHouseDO);
|
});
|
}
|
}
|
ComActDO comActDO = comActDAO.selectById(comMngVillageDO.getCommunityId());
|
if (comActDO == null || comActDO.getStreetId() == null) {
|
return R.fail("社区没有绑定街道,请绑定后操作!");
|
}
|
BeanUtils.copyProperties(comMngVillageVO, comMngVillageDO);
|
comMngVillageDO.setName(comMngVillageVO.getGroupAt());
|
comMngVillageDO.setStreetId(comActDO.getStreetId());
|
int update = this.baseMapper.update(comMngVillageDO,
|
new LambdaQueryWrapper<ComMngVillageDO>().eq(ComMngVillageDO::getVillageId, villageId));
|
if (update > 0) {
|
return R.ok(comMngVillageVO);
|
}
|
return R.fail();
|
}
|
|
/**
|
* 统计社区内小区数量
|
*
|
* @param communityId
|
* 社区id
|
* @return 统计小区数量
|
*/
|
@Override
|
public R villageStatistics(Long communityId) {
|
return R.ok(this.baseMapper.getVillageStatisticsCount(communityId));
|
}
|
|
/**
|
* 小区详情
|
*
|
* @param villageId
|
* 小区id
|
* @return 小区详情
|
*/
|
@Override
|
public R getVillage(Long villageId) {
|
return R.ok(this.baseMapper.getVillageById(villageId));
|
}
|
|
/**
|
* 综治app-小区列表
|
*
|
* @param villageListAppDTO
|
* 请求参数
|
* @return 小区列表
|
*/
|
@Override
|
public R getGridVillageList(ComMngVillageListAppDTO villageListAppDTO) {
|
return R.ok(this.baseMapper.getGridVillageList(
|
new Page(villageListAppDTO.getPageNum(), villageListAppDTO.getPageSize()), villageListAppDTO));
|
}
|
|
@Override
|
public R getGridVillageListApp(ComMngVillageListAppDTO villageListAppDTO) {
|
return R.ok(this.baseMapper.getGridVillageList(
|
new Page(villageListAppDTO.getPageNum(), villageListAppDTO.getPageSize()), villageListAppDTO));
|
}
|
|
/**
|
* 综治app-根据小区id查询小区下楼栋列表
|
*
|
* @param villageId
|
* 小区id
|
* @return 楼栋列表
|
*/
|
@Override
|
public R getGridVillageBuildingList(Long villageId) {
|
|
List<ComMngVillageBuildingVO> villageBuildingList = this.baseMapper.getGridVillageBuildingList(villageId);
|
if (!villageBuildingList.isEmpty()) {
|
villageBuildingList.forEach(villageBuilding -> {
|
if (!villageBuilding.getFloor().contains("栋")) {
|
villageBuilding.setFloorString(villageBuilding.getFloor() + "栋");
|
} else {
|
villageBuilding.setFloorString(villageBuilding.getFloor());
|
}
|
if (!villageBuilding.getUnitNo().contains("单元")) {
|
villageBuilding.setUnitNoString(villageBuilding.getUnitNo() + "单元");
|
} else {
|
villageBuilding.setUnitNoString(villageBuilding.getUnitNo());
|
}
|
});
|
}
|
return R.ok(villageBuildingList);
|
}
|
|
@Override
|
public R delGridVillage(List<Long> villageIds) {
|
|
if (villageIds.isEmpty()) {
|
return R.fail("请选择需要删除的小区");
|
}
|
// 查询需要删除的小区下面是否绑定的有房屋
|
Integer count = this.baseMapper.getVillageHouseCount(villageIds);
|
if (count > 0) {
|
return R.fail("您选择的小区已被引用,无法删除");
|
}
|
if (this.baseMapper.deleteBatchIds(villageIds) > 0) {
|
return R.ok();
|
}
|
return R.fail("删除失败");
|
}
|
|
@Override
|
public R getGridVillageStatistics() {
|
return R.ok(this.baseMapper.getGridVillageStatistics());
|
}
|
|
@Override
|
public R getGridVillageListExport(ComMngVillageListExportAdminDTO villageListAppDTO) {
|
return R.ok(this.baseMapper.getGridVillageLists(villageListAppDTO));
|
}
|
|
}
|