| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import liquibase.repackaged.org.apache.commons.lang3.StringUtils; |
| | | import org.apache.logging.log4j.util.Strings; |
| | | import org.springblade.common.cache.SysCache; |
| | | import org.springblade.common.node.TreeStringNode; |
| | | import org.springblade.common.utils.IdUtils; |
| | | import org.springblade.core.mp.support.Condition; |
| | |
| | | import org.springblade.modules.grid.service.IGridService; |
| | | import org.springblade.modules.grid.service.IGridmanService; |
| | | import org.springblade.modules.grid.vo.GridVO; |
| | | import org.springblade.modules.house.entity.HouseholdEntity; |
| | | import org.springblade.modules.house.entity.UserHouseLabelEntity; |
| | | import org.springblade.modules.house.service.IHouseholdService; |
| | | import org.springblade.modules.place.entity.*; |
| | | import org.springblade.modules.place.excel.PlaceAndRelExcel; |
| | | import org.springblade.modules.place.excel.PlaceExcel; |
| | | import org.springblade.modules.place.service.IPlaceExtService; |
| | | import org.springblade.modules.place.service.IPlacePoiLabelService; |
| | | import org.springblade.modules.place.service.IPlaceRelService; |
| | | import org.springblade.modules.place.vo.PlacePoiLabelVO; |
| | | import org.springblade.modules.place.vo.PlaceVO; |
| | | import org.springblade.modules.place.mapper.PlaceMapper; |
| | | import org.springblade.modules.place.service.IPlaceService; |
| | |
| | | private IGridmanService gridmanService; |
| | | |
| | | @Autowired |
| | | private IDeptService deptService; |
| | | private GridMapper gridMapper; |
| | | |
| | | @Autowired |
| | | private GridMapper gridMapper; |
| | | private IHouseholdService householdService; |
| | | |
| | | /** |
| | | * 自定义列表查询 |
| | |
| | | */ |
| | | @Override |
| | | public IPage<PlaceVO> selectPlacePage(IPage<PlaceVO> page, PlaceVO place) { |
| | | Dept dept = deptService.getById(AuthUtil.getDeptId()); |
| | | if (null!=dept){ |
| | | place.setRegionCode(dept.getRegionCode()); |
| | | } |
| | | List<String> regionChildCodesList = SysCache.getRegionChildCodesByDeptId(AuthUtil.getDeptId()); |
| | | Integer isAdministrator = AuthUtil.isAdministrator()==true?1:2; |
| | | List<String> list = new ArrayList<>(); |
| | | if (null!=place.getRoleName() && !place.getRoleName().equals("")){ |
| | | if (place.getRoleName().equals("网格员")){ |
| | |
| | | list = gridService.getAddressCodeListByUserId(AuthUtil.getUserId()); |
| | | } |
| | | } |
| | | List<PlaceVO> placeVOS = baseMapper.selectPlacePage(page, place, list); |
| | | List<PlaceVO> placeVOS = baseMapper.selectPlacePage(page, place, list,regionChildCodesList,isAdministrator); |
| | | // 遍历 |
| | | for (PlaceVO placeVO : placeVOS) { |
| | | // 设置对应的网格名称 |
| | |
| | | if (null!=one) { |
| | | placeVO.setId(one.getId()); |
| | | } |
| | | // 设置来源( 1:地址总表 2:国控采集),扫码采集 |
| | | placeVO.setSource(1); |
| | | // 绑定用户信息 |
| | | bindUserHandle(placeVO); |
| | | // 设置完善状态 |
| | | setPlaceStatus(placeVO); |
| | | // 更新场所信息 |
| | | flag = updateById(placeVO); |
| | | // 保存场所详情及任务信息 |
| | |
| | | placeVO.setHouseCode(IdUtils.getIdBy36()); |
| | | // 绑定用户信息 |
| | | bindUserHandle(placeVO); |
| | | // 设置完善状态 |
| | | setPlaceStatus(placeVO); |
| | | // 新增场所信息 |
| | | flag = save(placeVO); |
| | | // 保存场所详情及任务信息 |
| | |
| | | // 位置绑定,通过定位去匹配所在网格 |
| | | // 返回结果 |
| | | return flag; |
| | | } |
| | | |
| | | /** |
| | | * 设置场所完善状态 |
| | | * @param placeVO |
| | | */ |
| | | private void setPlaceStatus(PlaceVO placeVO) { |
| | | if (!Strings.isBlank(placeVO.getPrincipal()) |
| | | && !Strings.isBlank(placeVO.getPrincipalPhone()) |
| | | && !Strings.isBlank(placeVO.getLocation()) |
| | | && !Strings.isBlank(placeVO.getPlaceName()) |
| | | && !Strings.isBlank(placeVO.getImageUrls()) |
| | | ){ |
| | | // 已完善 |
| | | placeVO.setStatus(2); |
| | | }else { |
| | | // 未完善 |
| | | placeVO.setStatus(1); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | big.setPlaceId(placeVO.getId()); |
| | | big.setPoiCode(Integer.parseInt(bigString)); |
| | | big.setType(1); |
| | | if (!Strings.isBlank(placeVO.getColor())){ |
| | | big.setColor(placeVO.getColor()); |
| | | } |
| | | placePoiLabelService.save(big); |
| | | // 中类 |
| | | PlacePoiLabel mid = new PlacePoiLabel(); |
| | | mid.setPlaceId(placeVO.getId()); |
| | | mid.setPoiCode(Integer.parseInt(midString)); |
| | | mid.setType(2); |
| | | if (!Strings.isBlank(placeVO.getColor())){ |
| | | mid.setColor(placeVO.getColor()); |
| | | } |
| | | placePoiLabelService.save(mid); |
| | | // 小类 |
| | | PlacePoiLabel min = new PlacePoiLabel(); |
| | | min.setPlaceId(placeVO.getId()); |
| | | min.setPoiCode(Integer.parseInt(labelId)); |
| | | min.setType(3); |
| | | if (!Strings.isBlank(placeVO.getColor())){ |
| | | min.setColor(placeVO.getColor()); |
| | | } |
| | | placePoiLabelService.save(min); |
| | | } |
| | | }); |
| | |
| | | big.setPlaceId(placeVO.getId()); |
| | | big.setPoiCode(Integer.parseInt(bigString)); |
| | | big.setType(1); |
| | | if (!Strings.isBlank(placeVO.getColor())){ |
| | | big.setColor(placeVO.getColor()); |
| | | } |
| | | placePoiLabelService.save(big); |
| | | // 中类 |
| | | PlacePoiLabel mid = new PlacePoiLabel(); |
| | | mid.setPlaceId(placeVO.getId()); |
| | | mid.setPoiCode(Integer.parseInt(midString)); |
| | | mid.setType(2); |
| | | if (!Strings.isBlank(placeVO.getColor())){ |
| | | mid.setColor(placeVO.getColor()); |
| | | } |
| | | placePoiLabelService.save(mid); |
| | | // 处理小类 |
| | | if (labelCode.length() > 4) { |
| | |
| | | min.setPlaceId(placeVO.getId()); |
| | | min.setPoiCode(Integer.parseInt(labelCode)); |
| | | min.setType(3); |
| | | if (!Strings.isBlank(placeVO.getColor())){ |
| | | min.setColor(placeVO.getColor()); |
| | | } |
| | | placePoiLabelService.save(min); |
| | | } |
| | | } |
| | |
| | | if (null != placeVO.getHouseCode() && !placeVO.getHouseCode().equals("")) { |
| | | place.setHouseCode(placeVO.getHouseCode()); |
| | | } |
| | | if (placeVO.getPlacePoiLabelVOList().size()>0){ |
| | | PlacePoiLabelVO placePoiLabelVO = placeVO.getPlacePoiLabelVOList().get(0); |
| | | if (!Strings.isBlank(placePoiLabelVO.getColor())){ |
| | | placeVO.setColor(placePoiLabelVO.getColor()); |
| | | } |
| | | } |
| | | // 查询门牌地址信息 |
| | | if (null != place.getHouseCode() && !place.getHouseCode().equals("")) { |
| | | QueryWrapper<DoorplateAddressEntity> wrapper = new QueryWrapper<>(); |
| | |
| | | placeVO.setGrid(gridVO); |
| | | place.setGridId(gridVO.getId()); |
| | | } |
| | | // 设置详情信息 |
| | | QueryWrapper<PlaceExtEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("is_deleted",0).eq("place_id",placeVO.getId()); |
| | | placeVO.setPlaceExtEntity(placeExtService.getOne(queryWrapper)); |
| | | } else { |
| | | // 通过定位点落面分析网格位置,反向推出社区派出所相关数据 |
| | | |
| | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 根据编号集合查询对应的场所(按颜色区分近多少天没有发过任务的场所) |
| | | * @param stringList |
| | | * @param tableName |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<PlaceVO> getPlaceListByParam(List<String> stringList,String tableName) { |
| | | return baseMapper.getPlaceListByParam(stringList,tableName); |
| | | } |
| | | |
| | | /** |
| | | * 删除 |
| | | * @param longs |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean removePlace(List<Long> longs) { |
| | | // 删除场所负责人对应的用户 |
| | | removeUser(longs); |
| | | // 删除 |
| | | boolean removeByIds = removeByIds(longs); |
| | | // 删除对应的详情 |
| | | removePlaceExt(longs); |
| | | // 删除对应的标签绑定信息 |
| | | removePlaceLabel(longs); |
| | | // 返回 |
| | | return removeByIds; |
| | | } |
| | | |
| | | /** |
| | | * 删除场所负责人对应的用户 |
| | | * @param longs |
| | | */ |
| | | public void removeUser(List<Long> longs) { |
| | | // 遍历 |
| | | for (Long id : longs) { |
| | | PlaceEntity placeEntity = getById(id); |
| | | if (null!=placeEntity.getPrincipalUserId()){ |
| | | User user = userService.getById(placeEntity.getPrincipalUserId()); |
| | | // 查询场所判断是否还绑定有其他的场所 |
| | | QueryWrapper<PlaceEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("is_deleted",0).eq("principal_user_id",user.getId()); |
| | | List<PlaceEntity> placeEntityList = list(queryWrapper); |
| | | // 如果没有(1个 当前的还没有删除) |
| | | if (placeEntityList.size()==1){ |
| | | // 判断角色 |
| | | if (!Strings.isBlank(user.getRoleId())){ |
| | | // 判断是否还绑定其他的房屋,如果有,则不操作用户 |
| | | QueryWrapper<HouseholdEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("is_deleted",0).eq("associated_user_id",user.getId()); |
| | | List<HouseholdEntity> householdEntityList = householdService.list(wrapper); |
| | | // 即没有房屋和场所了就删除对应的居民角色 |
| | | if (householdEntityList.size()==0) { |
| | | List<String> stringList = Arrays.asList(user.getRoleId().split(",")); |
| | | // 查看当前用户的角色是否只有一个 |
| | | if (stringList.size() > 1) { |
| | | // 查询是否对应有场所负责人,如果有则不删除,如果没有则删除对应的角色 |
| | | List<String> arrayList = new ArrayList<>(); |
| | | for (String roleId : stringList) { |
| | | if (!roleId.equals("1717429059648606209")) { |
| | | arrayList.add(roleId); |
| | | } |
| | | } |
| | | user.setRoleId(StringUtils.join(arrayList, ",")); |
| | | // 更新用户 |
| | | userService.updateById(user); |
| | | } else { |
| | | // 删除当前用户 |
| | | userService.removeById(user.getId()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除场所对应的详情 |
| | | * @param longs |
| | | */ |
| | | public void removePlaceExt(List<Long> longs) { |
| | | for (Long id : longs) { |
| | | QueryWrapper<PlaceExtEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("place_id",id); |
| | | placeExtService.remove(wrapper); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除对应的标签绑定信息 |
| | | * @param longs |
| | | */ |
| | | public void removePlaceLabel(List<Long> longs) { |
| | | for (Long id : longs) { |
| | | QueryWrapper<PlacePoiLabel> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("place_id",id); |
| | | placePoiLabelService.remove(wrapper); |
| | | } |
| | | } |
| | | } |