在数字化家政服务需求激增的今天,搭建一套覆盖APP与小程序双端、打通用户端与商家端的全链路家政服务平台,已成为行业转型升级的关键路径。本文以Spring Boot+微信小程序+Node.js技术栈为核心,结合实际源码示例,拆解从0到1快速落地家政平台的完整方案。
步骤1:环境搭建
步骤2:核心功能实现
wx.getLocation获取用户经纬度,调用后端/api/staff/nearby接口筛选5公里内服务人员。后端使用Redis GEO存储服务人员位置,通过GEOSEARCH命令实现高效范围查询:// Spring Boot后端定位查询
@GetMapping("/nearby")
public List<Staff> findNearby(@RequestParam double lat, @RequestParam double lng, @RequestParam int radius) {
return redisTemplate.opsForGeo()
.search("staff:locations",
new Circle(new Point(lng, lat), new Distance(radius, Metrics.KILOMETERS)))
.stream().map(GeoResult::getContent).collect(Collectors.toList());
}socketTask连接并监听位置更新:// 微信小程序WebSocket连接
const socket = wx.connectSocket({ url: 'wss://api.example.com/track' });
socket.onMessage(res => {
const data = JSON.parse(res.data);
this.setData({ staffLocation: data.location });
});步骤3:测试与部署
以下为家政源码中智能排班算法与数据驾驶舱功能的核心源代码实现,采用Spring Boot+Python技术栈,可直接集成到项目中:
// 服务人员匹配度计算核心算法
public class StaffMatchingEngine {
// 权重配置:距离占30%,技能匹配占40%,评分占30%
private static final double DISTANCE_WEIGHT = 0.3;
private static final double SKILL_WEIGHT = 0.4;
private static final double RATING_WEIGHT = 0.3;
// 计算服务人员匹配得分
public double calculateMatchScore(Staff staff, Order order) {
double distanceScore = calculateDistanceScore(staff.getLocation(), order.getLocation());
double skillScore = calculateSkillScore(staff.getSkills(), order.getServiceType());
double ratingScore = staff.getAverageRating() / 5.0; // 归一化到0-1区间
return DISTANCE_WEIGHT * distanceScore
+ SKILL_WEIGHT * skillScore
+ RATING_WEIGHT * ratingScore;
}
// 距离得分计算(基于高德地图API返回的直线距离)
private double calculateDistanceScore(Location staffLoc, Location orderLoc) {
double distance = calculateHaversineDistance(staffLoc, orderLoc);
// 距离越近得分越高,5公里内满分,超过10公里得0分
return Math.max(0, (5000 - distance) / 5000);
}
// 技能匹配度计算(完全匹配得1分,部分匹配得0.5分)
private double calculateSkillScore(List<String> staffSkills, String orderServiceType) {
return staffSkills.contains(orderServiceType) ? 1.0 : 0.5;
}
// 哈弗赛因距离计算(单位:米)
private double calculateHaversineDistance(Location loc1, Location loc2) {
// 实际项目中应调用高德/腾讯地图API获取真实道路距离
return Math.sqrt(Math.pow(loc1.getLng()-loc2.getLng(),2)
+ Math.pow(loc1.getLat()-loc2.getLat(),2)) * 111321;
}
}# 订单热力图生成(使用folium+geopandas)
import folium
import geopandas as gpd
from folium.plugins import HeatMap
def generate_order_heatmap(orders):
# 创建北京五环内底图
m = folium.Map(location=[39.9042, 116.4074],
zoom_start=12,
tiles='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
attr='OpenStreetMap')
# 提取订单坐标并转换为GeoDataFrame
geometry = [Point(xy) for xy in zip(orders.lng, orders.lat)]
gdf = gpd.GeoDataFrame(orders, geometry=geometry, crs="EPSG:4326")
# 生成热力图数据(权重由订单金额决定)
heat_data = [[row.geometry.y, row.geometry.x, row.amount]
for _, row in gdf.iterrows()]
# 添加热力图层
HeatMap(heat_data,
radius=15,
blur=15,
max_zoom=1).add_to(m)
# 保存为HTML文件
m.save('./heatmap.html')
return m
# 服务评分趋势图(使用matplotlib)
import matplotlib.pyplot as plt
import pandas as pd
def plot_rating_trend(ratings):
# 数据准备
df = pd.DataFrame({
'date': pd.to_datetime(ratings.date),
'rating': ratings.score
})
# 按周聚合数据
weekly = df.groupby(pd.Grouper(key='date', freq='W')).mean()
# 绘制趋势图
plt.figure(figsize=(12,6))
plt.plot(weekly.index, weekly.rating, marker='o', linestyle='-', color='#4C72B0')
plt.title('服务评分周趋势', fontsize=14)
plt.xlabel('日期', fontsize=12)
plt.ylabel('平均评分(5分制)', fontsize=12)
plt.grid(True, linestyle='--', alpha=0.7)
plt.savefig('./rating_trend.png', dpi=300, bbox_inches='tight')智能排班调用示例
// 订单创建时自动分配服务人员
public Order assignStaff(Order newOrder) {
List<Staff> availableStaff = staffRepository.findAvailableInArea(newOrder.getLocation(), 5000);
// 计算每个服务人员的匹配得分
Map<Staff, Double> staffScores = availableStaff.stream()
.collect(Collectors.toMap(
Function.identity(),
staff -> matchingEngine.calculateMatchScore(staff, newOrder)
));
// 选择得分最高的服务人员
Staff bestStaff = Collections.max(staffScores.entrySet(),
Map.Entry.comparingByValue())
.getKey();
newOrder.setStaff(bestStaff);
return orderRepository.save(newOrder);
}数据驾驶舱数据获取API
// Spring Boot数据接口
@RestController
@RequestMapping("/api/dashboard")
public class DashboardController {
@Autowired
private OrderRepository orderRepo;
@GetMapping("/heatmap")
public List<Order> getHeatmapData() {
// 返回最近7天的订单数据用于热力图
return orderRepo.findByDateAfter(LocalDateTime.now().minusDays(7));
}
@GetMapping("/ratings")
public List<Rating> getRatingTrend() {
// 返回最近30天的评分数据
return ratingRepo.findByDateAfter(LocalDateTime.now().minusDays(30));
}
}
通过家政源码双端搭建,你可以在2-4周内快速落地一套全链路家政服务平台。技术层面,微服务架构保障系统可扩展性,LBS定位与智能派单提升服务效率;业务层面,透明化评价体系与数据驾驶舱实现精细化运营。未来,随着AI客服、区块链存证等技术的融入,家政服务将向“生态型平台”升级,最终实现用户、服务人员、商家、平台的多方共赢。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。