| | |
| | | package org.springblade.modules.grid.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springblade.common.cache.SysCache; |
| | | import org.springblade.common.param.CommonParamSet; |
| | | import org.springblade.common.utils.NodeTreeUtil; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.utils.BeanUtil; |
| | | import org.springblade.modules.doorplateAddress.entity.DoorplateAddressEntity; |
| | | import org.springblade.modules.doorplateAddress.service.IDoorplateAddressService; |
| | | import org.springblade.modules.grid.entity.GridEntity; |
| | | import org.springblade.modules.grid.entity.GridRangeEntity; |
| | | import org.springblade.modules.grid.entity.GridmanEntity; |
| | | import org.springblade.modules.grid.excel.GridExcel; |
| | | import org.springblade.modules.grid.service.IGridRangeService; |
| | | import org.springblade.modules.grid.vo.GridVO; |
| | | import org.springblade.modules.grid.mapper.GridMapper; |
| | | import org.springblade.modules.grid.service.IGridRangeService; |
| | | import org.springblade.modules.grid.service.IGridService; |
| | | import org.springblade.core.mp.base.BaseServiceImpl; |
| | | import org.springblade.modules.grid.vo.GridVO; |
| | | import org.springblade.modules.place.vo.PlaceVO; |
| | | import org.springblade.modules.system.entity.User; |
| | | import org.springblade.modules.system.entity.Dept; |
| | | import org.springblade.modules.system.entity.Region; |
| | | import org.springblade.modules.system.service.IDeptService; |
| | | import org.springblade.modules.system.service.IRegionService; |
| | | import org.springblade.modules.task.vo.TaskVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 网格表 服务实现类 |
| | |
| | | public class GridServiceImpl extends ServiceImpl<GridMapper, GridEntity> implements IGridService { |
| | | |
| | | @Autowired |
| | | private IRegionService regionService; |
| | | |
| | | @Autowired |
| | | private IDoorplateAddressService doorplateAddressService; |
| | | |
| | | @Autowired |
| | | private IGridRangeService gridRangeService; |
| | | |
| | | @Autowired |
| | | private IDeptService deptService; |
| | | |
| | | @Override |
| | | public IPage<GridVO> selectGridPage(IPage<GridVO> page, GridVO grid) { |
| | | return page.setRecords(baseMapper.selectGridPage(page, grid)); |
| | | // List<String> regionChildCodesList = SysCache.getRegionChildCodesByDeptId(AuthUtil.getDeptId()); |
| | | // Integer isAdministrator = AuthUtil.isAdministrator()==true?1:2; |
| | | CommonParamSet commonParamSet = new CommonParamSet().invoke(GridVO.class, grid); |
| | | return page.setRecords(baseMapper.selectGridPage(page, grid,commonParamSet.getRegionChildCodesList(),commonParamSet.getIsAdministrator())); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param isCovered |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void importGrid(List<GridExcel> data, Boolean isCovered) { |
| | | List<GridEntity> list = new ArrayList<>(); |
| | | // 遍历 |
| | | for (GridExcel gridExcel : data) { |
| | | // 取出名称分隔 |
| | | String[] split = gridExcel.getGridName().split("居民委员会"); |
| | | String[] split = gridExcel.getGridName().split("第"); |
| | | GridEntity gridEntity = new GridEntity(); |
| | | gridEntity.setCommunityName(split[0] + "居民委员会"); |
| | | gridEntity.setGridName(split[1]); |
| | | gridEntity.setGeom(gridExcel.getGeom()); |
| | | gridEntity.setCreateUser(AuthUtil.getUserId()); |
| | | gridEntity.setCreateTime(new Date()); |
| | | gridEntity.setUpdateUser(AuthUtil.getUserId()); |
| | | gridEntity.setUpdateTime(new Date()); |
| | | list.add(gridEntity); |
| | | // 通过社区名称查询对应的社区编号 |
| | | QueryWrapper<Region> wrapper = new QueryWrapper<>(); |
| | | wrapper.like("name",split[0]); |
| | | System.out.println("社区名称 = " + split[0]); |
| | | Region region = regionService.getOne(wrapper); |
| | | if (null!=region){ |
| | | gridEntity.setCommunityCode(region.getCode()); |
| | | } |
| | | // 比对网格是否存在,如果已存在则更新,否则则新增 |
| | | QueryWrapper<GridEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("is_deleted",0) |
| | | .eq("grid_name","第" + split[1]) |
| | | .eq("community_code",region.getCode()); |
| | | GridEntity one = getOne(queryWrapper); |
| | | if (null!=one){ |
| | | one.setGridCode(gridExcel.getGridCode()); |
| | | one.setGridName("第" + split[1]); |
| | | one.setGeom(gridExcel.getGeom()); |
| | | one.setUpdateUser(AuthUtil.getUserId()); |
| | | one.setUpdateTime(new Date()); |
| | | // 更新 |
| | | updateById(one); |
| | | }else { |
| | | // 设置网格数据 |
| | | gridEntity.setGridCode(gridExcel.getGridCode()); |
| | | gridEntity.setGridName("第" + split[1]); |
| | | gridEntity.setGeom(gridExcel.getGeom()); |
| | | gridEntity.setCreateUser(AuthUtil.getUserId()); |
| | | gridEntity.setCreateTime(new Date()); |
| | | gridEntity.setUpdateUser(AuthUtil.getUserId()); |
| | | gridEntity.setUpdateTime(new Date()); |
| | | list.add(gridEntity); |
| | | } |
| | | } |
| | | // 批量导入 |
| | | saveBatch(list); |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public GridVO getGridDetailByHouseCode(String houseCode) { |
| | | return baseMapper.getGridDetailByHouseCode(houseCode); |
| | | public GridVO getPlaceGridDetailByHouseCode(String houseCode) { |
| | | return baseMapper.getPlaceGridDetailByHouseCode(houseCode); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<String> getAddressCodeListByUserId(Long userId) { |
| | | return baseMapper.getAddressCodeListByUserId(userId); |
| | | public List<String> getAddressCodeListByUserId(Long userId,String addressCode) { |
| | | return baseMapper.getAddressCodeListByUserId(userId,addressCode); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Object spatialAnalysis() { |
| | | public Object spatialAnalysis(DoorplateAddressEntity addressEntity) { |
| | | // 按社区 |
| | | // String name = "万达社区居民委员会"; |
| | | String name = "茶山路社区居民委员会"; |
| | | String name = null; |
| | | // String name = "茶山路社区居民委员会"; |
| | | //查询社区信息 |
| | | List<DoorplateAddressEntity> doorplateAddressEntities = doorplateAddressService.getAllDoorplateAddress(name); |
| | | List<DoorplateAddressEntity> doorplateAddressEntities = doorplateAddressService.getAllDoorplateAddress(addressEntity); |
| | | //遍历 |
| | | for (DoorplateAddressEntity doorplateAddressEntity : doorplateAddressEntities) { |
| | | //点坐标解析 |
| | | String point = "'POINT(" + doorplateAddressEntity.getX84() + " " + doorplateAddressEntity.getY84() +")'"; |
| | | String point = "'POINT(" + doorplateAddressEntity.getX() + " " + doorplateAddressEntity.getY() +")'"; |
| | | // String point = "'POINT(" + villageInfoExcel.getLatitude() + " " + villageInfoExcel.getLongitude() +")'"; |
| | | GridEntity gridEntity = baseMapper.spatialAnalysis(point); |
| | | if (null!=gridEntity){ |
| | | List<GridEntity> gridEntityList = baseMapper.spatialAnalysis(point); |
| | | if (gridEntityList.size()>0) { |
| | | GridEntity gridEntity = gridEntityList.get(0); |
| | | QueryWrapper<GridRangeEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("grid_id",gridEntity.getId()).eq("house_code",doorplateAddressEntity.getAddressCode()); |
| | | GridRangeEntity one = gridRangeService.getOne(queryWrapper); |
| | |
| | | gridRangeEntity.setDistrictName(doorplateAddressEntity.getAoiName()); |
| | | // 保存 |
| | | gridRangeService.save(gridRangeEntity); |
| | | }else { |
| | | one.setGridId(gridEntity.getId()); |
| | | // 更新 |
| | | gridRangeService.updateById(one); |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 空间分析 |
| | | */ |
| | | @Override |
| | | public List<GridEntity> spatialAnalysis(String point) { |
| | | return baseMapper.spatialAnalysis(point); |
| | | } |
| | | |
| | | /** |
| | |
| | | public GridVO getGridDetailByParam(PlaceVO place) { |
| | | return baseMapper.getGridDetailByParam(place); |
| | | } |
| | | |
| | | /** |
| | | * 网格表 自定义详情 |
| | | * @param grid |
| | | * @return |
| | | */ |
| | | @Override |
| | | public GridVO getGridDetail(GridVO grid) { |
| | | return baseMapper.getGridDetail(grid); |
| | | } |
| | | |
| | | /** |
| | | * 网格表 自定义新增或修改 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean saveOrUpdateGrid(GridEntity grid) { |
| | | boolean flag = false; |
| | | if (null!=grid.getId()) { |
| | | // 更新 |
| | | flag = updateById(grid); |
| | | }else { |
| | | // 先查询当前网格社区对应的机构id |
| | | QueryWrapper<Region> regionWrapper = new QueryWrapper<>(); |
| | | regionWrapper.eq("code", grid.getCommunityCode()); |
| | | Region region = regionService.getOne(regionWrapper); |
| | | // 查询父机构(社区机构) |
| | | System.out.println("社区名称 = " + region.getName()); |
| | | QueryWrapper<Dept> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("dept_name", region.getName()) |
| | | .eq("dept_nature", 2) |
| | | .eq("is_deleted", 0); |
| | | Dept dept = deptService.getOne(wrapper); |
| | | // 查询当前网格在机构中是否存在,存在不做操作,否则则新增 |
| | | QueryWrapper<Dept> wrapperChild = new QueryWrapper<>(); |
| | | wrapperChild.eq("dept_name", grid.getGridName()) |
| | | .eq("is_deleted", 0) |
| | | .eq("dept_nature", 2) |
| | | .eq("parent_id", dept.getId()); |
| | | List<Dept> deptChild = deptService.list(wrapperChild); |
| | | if (deptChild.size() == 0) { |
| | | Dept deptInfo = new Dept(); |
| | | deptInfo.setParentId(dept.getId()); |
| | | deptInfo.setFullName(grid.getGridName()); |
| | | deptInfo.setDeptName(grid.getGridName()); |
| | | deptInfo.setDeptCategory(1); |
| | | // 综治 |
| | | deptInfo.setDeptNature(2); |
| | | deptInfo.setTenantId("000000"); |
| | | deptInfo.setRegionCode(grid.getGridCode()); |
| | | deptInfo.setAncestors(dept.getAncestors() + "," + dept.getId()); |
| | | // 新增 |
| | | deptService.save(deptInfo); |
| | | // 查询网格是否已存在(社区编号-网格名称),已存在更新,不存在插入新的 |
| | | QueryWrapper<GridEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("grid_code", grid.getGridCode()) |
| | | .eq("is_deleted", 0); |
| | | System.out.println("网格编号 = " + grid.getGridCode()); |
| | | GridEntity one = getOne(queryWrapper); |
| | | if (null != one) { |
| | | grid.setId(one.getId()); |
| | | grid.setDeptId(deptInfo.getId()); |
| | | if (null != grid.getGeom() && grid.getGeom().equals("")) { |
| | | grid.setGeom(null); |
| | | } |
| | | // 更新 |
| | | flag = updateById(grid); |
| | | } else { |
| | | grid.setDeptId(deptInfo.getId()); |
| | | grid.setGeom(null); |
| | | // 插入 |
| | | flag = save(grid); |
| | | } |
| | | } |
| | | } |
| | | return flag; |
| | | } |
| | | |
| | | /** |
| | | * 网格数据同步处理 |
| | | */ |
| | | @Override |
| | | public Object asyncGridDept() { |
| | | List<GridEntity> list = baseMapper.selectGridAll(); |
| | | for (GridEntity gridEntity : list) { |
| | | saveOrUpdateGrid(gridEntity); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 网格树 |
| | | * |
| | | * @param grid |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Object getGridTree(GridVO grid) { |
| | | return NodeTreeUtil.getStringNodeTree(baseMapper.getGridTree()); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Object gridInfoByHouseCode(String houseCode) { |
| | | Map<String, Object> objectObjectHashMap = new HashMap<>(); |
| | | List<GridmanEntity> gridmanEntities = baseMapper.gridInfo(houseCode); |
| | | if (gridmanEntities.size()>0) { |
| | | Integer id = gridmanEntities.get(0).getId(); |
| | | objectObjectHashMap.put("grid", gridmanEntities); |
| | | List<DoorplateAddressEntity> result = baseMapper.gridAoiName(id); |
| | | objectObjectHashMap.put("doorplateAddress", result); |
| | | } |
| | | return objectObjectHashMap; |
| | | } |
| | | |
| | | /** |
| | | * 网格集合查询 |
| | | * @param grid |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Object getGridList(GridVO grid) { |
| | | return baseMapper.getGridList(grid); |
| | | } |
| | | |
| | | /** |
| | | * 查询小区网格绑定 |
| | | * @param aoiCode 小区aoiCode |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<GridVO> getGridListByAoiCode(String aoiCode) { |
| | | return baseMapper.getGridListByAoiCode(aoiCode); |
| | | } |
| | | |
| | | /** |
| | | * 查询对应网格人对应的网格 |
| | | * @param userId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public GridEntity getGridByUserId(Long userId) { |
| | | return baseMapper.getGridByUserId(userId); |
| | | } |
| | | |
| | | /** |
| | | * 根据网格名称,社区名称查询对应的网格 |
| | | * @param gridName |
| | | * @param communityName |
| | | * @return |
| | | */ |
| | | @Override |
| | | public GridEntity getGridByNames(String gridName, String communityName) { |
| | | return baseMapper.getGridByNames(gridName,communityName); |
| | | } |
| | | |
| | | /** |
| | | * 查询用户对应的网格 |
| | | * @param userId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<String> getGridListByUserId(Long userId) { |
| | | return baseMapper.getGridListByUserId(userId.toString()); |
| | | } |
| | | |
| | | /** |
| | | * 查询对应的房屋地址code(更加网格编号集合) |
| | | * @param gridCodeList |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<String> getAddressCodeListByGridCodeList(String communityCode, List<String> gridCodeList) { |
| | | return baseMapper.getAddressCodeListByGridCodeList(communityCode,gridCodeList); |
| | | } |
| | | |
| | | /** |
| | | * 根据社区编号及网格编号集合查询对应的网格信息 |
| | | * @param communityCode |
| | | * @param gridCodeList |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<GridVO> getGridListByComAndList(String communityCode, List<String> gridCodeList) { |
| | | return baseMapper.getGridListByComAndList(communityCode,gridCodeList); |
| | | } |
| | | |
| | | /** |
| | | * 根据社区名称和网格名称查询对应的网格信息 |
| | | * @param communityName |
| | | * @param gridName |
| | | * @return |
| | | */ |
| | | @Override |
| | | public GridEntity getGridInfoByParam(String communityName, String gridName) { |
| | | return baseMapper.getGridInfoByParam(communityName,gridName); |
| | | } |
| | | } |