linwei
2024-01-08 ad2ec97fe0c60eee4bb7c8cdacff7c876f280ea7
src/main/java/org/springblade/modules/place/service/impl/PlaceServiceImpl.java
@@ -26,7 +26,9 @@
import org.springblade.core.secure.utils.AuthUtil;
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.mapper.GridMapper;
import org.springblade.modules.grid.service.IGridRangeService;
import org.springblade.modules.grid.service.IGridService;
import org.springblade.modules.grid.service.IGridmanService;
@@ -85,6 +87,9 @@
   @Autowired
   private IDeptService deptService;
   @Autowired
   private GridMapper gridMapper;
   /**
    * 自定义列表查询
@@ -214,20 +219,74 @@
            gridRangeService.updateById(one);
         }
      }else {
         // 判断角色,如果是网格员则直接使用网格员的网格id,如果是民警则采用点落面的方式进行获取网格的id
         if (!Strings.isBlank(placeVO.getRoleName())) {
            // 网格员角色位置绑定
            gridmanPositionHandle(placeVO);
            // 民警角色位置绑定
            policePositionHandle(placeVO);
         }
      }
   }
   /**
    * 网格员角色位置绑定
    * @param placeVO
    */
   private void gridmanPositionHandle(PlaceVO placeVO) {
      if (placeVO.getRoleName().equals("网格员")) {
         // 判断网格员,查询对应网格人对应的网格id
         Integer gridId = gridmanService.getGridIdByUserId(AuthUtil.getUserId());
         if (null!=gridId){
         if (null != gridId) {
            // 判断关联关系表是否存在
            QueryWrapper<GridRangeEntity> wrapper = new QueryWrapper<>();
            wrapper.eq("grid_id",gridId).eq("house_code",placeVO.getHouseCode());
            wrapper.eq("grid_id", gridId).eq("house_code", placeVO.getHouseCode());
            GridRangeEntity one = gridRangeService.getOne(wrapper);
            if (null==one){
            if (null == one) {
               // 新增
               GridRangeEntity gridRangeEntity = new GridRangeEntity();
               gridRangeEntity.setHouseCode(placeVO.getHouseCode());
               gridRangeEntity.setGridId(gridId);
               // 插入
               gridRangeService.save(gridRangeEntity);
            }else {
               // 修改绑定
               one.setGridId(placeVO.getGridId());
               // 修改
               gridRangeService.updateById(one);
            }
         }
      }
   }
   /**
    * 民警角色位置绑定
    * @param placeVO
    */
   private void policePositionHandle(PlaceVO placeVO) {
      // 是民警且位置信息存在
      if (placeVO.getRoleName().equals("民警") && !Strings.isBlank(placeVO.getLng())) {
         //点坐标解析
         String point = "'POINT(" + placeVO.getLng() + " " + placeVO.getLat() +")'";
//         String point = "'POINT(" + villageInfoExcel.getLatitude() + " " + villageInfoExcel.getLongitude() +")'";
         GridEntity gridEntity = gridMapper.spatialAnalysis(point);
         if (null != gridEntity) {
            // 判断关联关系表是否存在
            QueryWrapper<GridRangeEntity> wrapper = new QueryWrapper<>();
            wrapper.eq("grid_id", gridEntity.getId()).eq("house_code", placeVO.getHouseCode());
            GridRangeEntity one = gridRangeService.getOne(wrapper);
            if (null == one) {
               // 新增
               GridRangeEntity gridRangeEntity = new GridRangeEntity();
               gridRangeEntity.setHouseCode(placeVO.getHouseCode());
               gridRangeEntity.setGridId(gridEntity.getId());
               // 插入
               gridRangeService.save(gridRangeEntity);
            }else {
               // 修改绑定
               one.setGridId(placeVO.getGridId());
               // 修改
               gridRangeService.updateById(one);
            }
         }
      }
@@ -298,8 +357,8 @@
         // 处理单个
         String labelCode = labelList.get(0);
         // 切割成三个,分别是大类,中类,小类
         String bigString = labelCode.substring(0,2);
         String midString = labelCode.substring(0,4);
         String bigString = labelCode.substring(0, 2);
         String midString = labelCode.substring(0, 4);
         // 大类
         PlacePoiLabel big = new PlacePoiLabel();
         big.setPlaceId(placeVO.getId());
@@ -313,7 +372,7 @@
         mid.setType(2);
         placePoiLabelService.save(mid);
         // 处理小类
         if (labelCode.length()>4) {
         if (labelCode.length() > 4) {
            // 小类
            PlacePoiLabel min = new PlacePoiLabel();
            min.setPlaceId(placeVO.getId());
@@ -337,7 +396,14 @@
         //根据手机号查询库里的数据
         User userParams = new User();
         userParams.setPhone(placeVO.getPrincipalPhone());
         userParams.setIsDeleted(0);
         User user = userService.getOne(Condition.getQueryWrapper(userParams));
         if (null==user){
            User userParams1 = new User();
            userParams1.setAccount(placeVO.getPrincipalPhone());
            userParams1.setIsDeleted(0);
            user = userService.getOne(Condition.getQueryWrapper(userParams1));
         }
         if (null!=user) {
            //如果用户存在,则该用户id绑定场所
@@ -388,9 +454,19 @@
      PlaceExtEntity one = placeExtService.getOne(wrapper);
      if (null == one) {
         placeExtEntity.setPlaceId(placeVO.getId());
         placeExtEntity.setLocaltion(placeVO.getLocation());
         //新增
         placeExtService.savePlaceExt(placeExtEntity);
         if (!Strings.isBlank(placeVO.getPrincipalPhone())) {
            // 待审核
            placeExtEntity.setConfirmFlag(1);
         }else {
            // 待完善
            placeExtEntity.setConfirmFlag(4);
         }
         placeExtEntity.setCreateTime(new Date());
         placeExtEntity.setUpdateTime(new Date());
         placeExtEntity.setCreateUser(AuthUtil.getUserId());
         placeExtEntity.setUpdateUser(AuthUtil.getUserId());
         // 新增场所详情
         placeExtService.save(placeExtEntity);
      }
   }
@@ -469,7 +545,7 @@
               List<DoorplateAddressEntity> list = doorplateAddressService.list(wrapper);
               if (list.size() > 0) {
                  placeVO.setDoorplateAddressEntity(list.get(0));
                  placeVO.setNeiCode(list.get(0).getNeiCode().replaceAll("0+$", ""));
                  placeVO.setNeiCode(list.get(0).getNeiCode());
               }
               // 查询网格数据
               GridVO gridVO = gridService.getGridDetailByHouseCode(place.getHouseCode());
@@ -562,6 +638,7 @@
    * @param isCovered
    */
   @Override
   @Transactional(rollbackFor = Exception.class)
   public void importAndRelPlace(List<PlaceAndRelExcel> data, Boolean isCovered) {
      for (PlaceAndRelExcel placeExcel : data) {
         // 判断是否存在,不存在则插入,否则不操作
@@ -580,6 +657,10 @@
            placeEntity.setCreateUser(AuthUtil.getUserId());
            placeEntity.setUpdateTime(new Date());
            placeEntity.setUpdateUser(AuthUtil.getUserId());
            // 并生成36位的houseCode
            placeEntity.setHouseCode(IdUtils.getIdBy36());
            // 商超数据
            placeEntity.setSource(3);
            //一个一个插入,防止同一个表中有相同的数据
            save(placeEntity);
            // 插入标签关系表
@@ -717,4 +798,58 @@
      }
      return null;
   }
   /**
    * 历史场所详情数据处理
    * @param place
    * @return
    */
   @Override
   public Object historyPlaceExtHandle(PlaceVO place) {
      // 查询所有的场所数据(除去详情表已有的)
      List<PlaceEntity> list = baseMapper.getPlaceListByNoExt();
      // 遍历更新
      for (PlaceEntity placeEntity : list) {
         QueryWrapper<PlaceExtEntity> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("place_id",placeEntity.getId()).eq("is_deleted",0);
         PlaceExtEntity one = placeExtService.getOne(queryWrapper);
         if (null==one){
            // 新增
            PlaceExtEntity placeExtEntity = new PlaceExtEntity();
            if (null!=placeEntity.getPrincipalUserId()){
               // 待审核
               placeExtEntity.setConfirmFlag(1);
            }else {
               // 待完善
               placeExtEntity.setConfirmFlag(4);
            }
            placeExtEntity.setPlaceId(placeEntity.getId());
            // 插入
            placeExtService.save(placeExtEntity);
         }
      }
      return null;
   }
   /**
    * 商超数据处理
    * @return
    */
   @Override
   public Object placeAndRelHandle() {
      // 查询未处理的商超数据
      List<PlaceEntity> placeEntityList = baseMapper.placeAndRelHandle();
      // 处理
      for (PlaceEntity placeEntity : placeEntityList) {
         if (Strings.isBlank(placeEntity.getHouseCode())){
            // 并生成36位的houseCode
            placeEntity.setHouseCode(IdUtils.getIdBy36());
            // 商超数据
            placeEntity.setSource(3);
            // 更新
            updateById(placeEntity);
         }
      }
      return null;
   }
}