💖💖作者:计算机编程小咖 💙💙个人简介:曾长期从事计算机专业培训教学,本人也热爱上课教学,语言擅长Java、微信小程序、Python、Golang、安卓Android等,开发项目包括大数据、深度学习、网站、小程序、安卓、算法。平常会做一些项目定制化开发、代码讲解、答辩教学、文档编写、也懂一些降重方面的技巧。平常喜欢分享一些自己开发中遇到的问题的解决办法,也喜欢交流技术,大家有技术代码这一块的问题可以问我! 💛💛想说的话:感谢大家的关注与支持! 💜💜 网站实战项目 安卓/小程序实战项目 大数据实战项目 深度学习实战项目
@TOC
基于Vue的垃圾分类回收网站介绍
基于Vue的垃圾分类回收网站是一个采用现代化技术栈开发的环保主题毕业设计项目,该系统采用B/S架构,前端使用Vue框架结合ElementUI组件库构建用户界面,后端支持Java+SpringBoot和Python+Django两种技术方案,数据存储采用MySQL数据库,开发工具可选择IDEA或PyCharm。系统功能涵盖完整的垃圾分类回收业务流程,包括用户中心模块实现用户注册登录和个人信息管理,用户管理和回收人员管理模块负责不同角色的权限控制,文章类型和社区资讯模块提供垃圾分类知识科普和环保资讯发布平台,预约回收功能允许用户在线预约上门回收服务,订单信息和回收分配模块实现回收订单的全流程管理和智能分配,回收记录模块详细记录每次回收活动的具体信息,垃圾分类模块提供标准的垃圾分类指导和查询功能,积分商品和积分兑换模块通过积分激励机制促进用户参与垃圾回收,系统管理模块确保后台数据的安全管理,系统首页则整合展示所有核心功能入口。整个系统设计合理,功能完善,技术栈主流且易于实现,非常适合作为计算机专业学生的毕业设计项目,既能体现技术水平又具有实际的社会价值和应用前景。
基于Vue的垃圾分类回收网站演示视频
基于Vue的垃圾分类回收网站演示图片
基于Vue的垃圾分类回收网站代码展示
from pyspark.sql import SparkSession
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from django.utils.decorators import method_decorator
from django.views import View
from .models import RecycleAppointment, GarbageCategory, UserPoints, PointsProduct
import json
import datetime
import uuid
spark = SparkSession.builder.appName("GarbageClassificationSystem").config("spark.sql.adaptive.enabled", "true").getOrCreate()
@method_decorator(csrf_exempt, name='dispatch')
class RecycleAppointmentView(View):
def post(self, request):
try:
data = json.loads(request.body)
user_id = data.get('user_id')
address = data.get('address')
contact_phone = data.get('contact_phone')
appointment_time = data.get('appointment_time')
garbage_type = data.get('garbage_type')
estimated_weight = data.get('estimated_weight', 0)
special_note = data.get('special_note', '')
appointment_id = str(uuid.uuid4())
current_time = datetime.datetime.now()
appointment_obj = RecycleAppointment()
appointment_obj.appointment_id = appointment_id
appointment_obj.user_id = user_id
appointment_obj.address = address
appointment_obj.contact_phone = contact_phone
appointment_obj.appointment_time = datetime.datetime.strptime(appointment_time, '%Y-%m-%d %H:%M:%S')
appointment_obj.garbage_type = garbage_type
appointment_obj.estimated_weight = float(estimated_weight)
appointment_obj.special_note = special_note
appointment_obj.status = 'pending'
appointment_obj.create_time = current_time
appointment_obj.save()
available_recyclers = self.find_available_recyclers(address, appointment_time)
if available_recyclers:
selected_recycler = self.assign_recycler_by_algorithm(available_recyclers, garbage_type, estimated_weight)
appointment_obj.assigned_recycler_id = selected_recycler['id']
appointment_obj.status = 'assigned'
appointment_obj.save()
self.send_notification_to_recycler(selected_recycler['id'], appointment_id)
predicted_points = self.calculate_predicted_points(garbage_type, estimated_weight)
return JsonResponse({
'status': 'success',
'appointment_id': appointment_id,
'assigned_recycler': selected_recycler['name'] if available_recyclers else None,
'predicted_points': predicted_points,
'message': '预约提交成功,回收人员将在30分钟内联系您'
})
except Exception as e:
return JsonResponse({'status': 'error', 'message': str(e)})
def find_available_recyclers(self, address, appointment_time):
district = self.extract_district_from_address(address)
appointment_hour = datetime.datetime.strptime(appointment_time, '%Y-%m-%d %H:%M:%S').hour
spark_df = spark.sql(f"SELECT recycler_id, name, district, work_hours FROM recyclers WHERE district = '{district}' AND status = 'active'")
available_recyclers = []
for row in spark_df.collect():
work_hours = row.work_hours.split('-')
start_hour = int(work_hours[0])
end_hour = int(work_hours[1])
if start_hour <= appointment_hour <= end_hour:
available_recyclers.append({'id': row.recycler_id, 'name': row.name, 'district': row.district})
return available_recyclers
def assign_recycler_by_algorithm(self, available_recyclers, garbage_type, estimated_weight):
recycler_scores = []
for recycler in available_recyclers:
score = self.calculate_recycler_score(recycler['id'], garbage_type, estimated_weight)
recycler_scores.append({'recycler': recycler, 'score': score})
recycler_scores.sort(key=lambda x: x['score'], reverse=True)
return recycler_scores[0]['recycler']
def calculate_recycler_score(self, recycler_id, garbage_type, estimated_weight):
base_score = 100
specialty_bonus = 20 if self.recycler_specializes_in(recycler_id, garbage_type) else 0
capacity_score = min(50, estimated_weight * 2)
recent_performance = self.get_recycler_recent_performance(recycler_id)
return base_score + specialty_bonus + capacity_score + recent_performance
def calculate_predicted_points(self, garbage_type, estimated_weight):
point_rates = {'可回收垃圾': 10, '有害垃圾': 15, '厨余垃圾': 5, '其他垃圾': 3}
base_points = point_rates.get(garbage_type, 5) * estimated_weight
return int(base_points)
@method_decorator(csrf_exempt, name='dispatch')
class GarbageClassificationView(View):
def post(self, request):
try:
data = json.loads(request.body)
garbage_name = data.get('garbage_name', '').strip()
image_base64 = data.get('image_base64', '')
classification_method = data.get('method', 'name')
if classification_method == 'name' and garbage_name:
classification_result = self.classify_by_name(garbage_name)
elif classification_method == 'image' and image_base64:
classification_result = self.classify_by_image(image_base64)
else:
return JsonResponse({'status': 'error', 'message': '请提供垃圾名称或图片'})
garbage_category = classification_result['category']
confidence_score = classification_result['confidence']
disposal_guide = self.get_disposal_guide(garbage_category)
environmental_impact = self.get_environmental_impact(garbage_category)
similar_items = self.get_similar_garbage_items(garbage_name, garbage_category)
classification_record = {
'user_query': garbage_name or 'image_upload',
'classification_result': garbage_category,
'confidence_score': confidence_score,
'query_time': datetime.datetime.now().isoformat()
}
self.save_classification_record(classification_record)
return JsonResponse({
'status': 'success',
'garbage_name': garbage_name,
'category': garbage_category,
'confidence': confidence_score,
'disposal_guide': disposal_guide,
'environmental_impact': environmental_impact,
'similar_items': similar_items,
'tips': self.get_classification_tips(garbage_category)
})
except Exception as e:
return JsonResponse({'status': 'error', 'message': str(e)})
def classify_by_name(self, garbage_name):
spark_df = spark.sql(f"SELECT category, confidence FROM garbage_database WHERE name LIKE '%{garbage_name}%' ORDER BY confidence DESC LIMIT 1")
result = spark_df.collect()
if result:
return {'category': result[0].category, 'confidence': result[0].confidence}
keyword_mapping = self.get_keyword_classification_mapping()
for keyword, category in keyword_mapping.items():
if keyword in garbage_name:
return {'category': category, 'confidence': 0.8}
return {'category': '其他垃圾', 'confidence': 0.3}
def classify_by_image(self, image_base64):
image_features = self.extract_image_features(image_base64)
spark_df = spark.sql("SELECT category, feature_vector FROM image_classification_model")
model_data = spark_df.collect()
best_match = {'category': '其他垃圾', 'confidence': 0.0}
for row in model_data:
similarity = self.calculate_feature_similarity(image_features, row.feature_vector)
if similarity > best_match['confidence']:
best_match = {'category': row.category, 'confidence': similarity}
return best_match
def get_disposal_guide(self, category):
disposal_guides = {
'可回收垃圾': '请清洗干净后投放至蓝色可回收垃圾桶,可获得积分奖励',
'有害垃圾': '请投放至红色有害垃圾桶,注意不要破损包装',
'厨余垃圾': '请沥干水分后投放至绿色厨余垃圾桶',
'其他垃圾': '请投放至灰色其他垃圾桶'
}
return disposal_guides.get(category, '请咨询当地垃圾分类管理部门')
def get_similar_garbage_items(self, garbage_name, category):
spark_df = spark.sql(f"SELECT name FROM garbage_database WHERE category = '{category}' AND name != '{garbage_name}' LIMIT 5")
similar_items = [row.name for row in spark_df.collect()]
return similar_items
@method_decorator(csrf_exempt, name='dispatch')
class PointsExchangeView(View):
def post(self, request):
try:
data = json.loads(request.body)
user_id = data.get('user_id')
product_id = data.get('product_id')
exchange_quantity = int(data.get('quantity', 1))
user_points = UserPoints.objects.get(user_id=user_id)
current_points = user_points.total_points
product = PointsProduct.objects.get(product_id=product_id)
required_points = product.required_points * exchange_quantity
if current_points < required_points:
return JsonResponse({
'status': 'error',
'message': f'积分不足,当前积分: {current_points},需要积分: {required_points}'
})
if product.stock_quantity < exchange_quantity:
return JsonResponse({
'status': 'error',
'message': f'库存不足,当前库存: {product.stock_quantity}'
})
exchange_id = str(uuid.uuid4())
exchange_time = datetime.datetime.now()
user_points.total_points -= required_points
user_points.used_points += required_points
user_points.save()
product.stock_quantity -= exchange_quantity
product.exchange_count += exchange_quantity
product.save()
exchange_record = {
'exchange_id': exchange_id,
'user_id': user_id,
'product_id': product_id,
'product_name': product.product_name,
'exchange_quantity': exchange_quantity,
'points_cost': required_points,
'exchange_time': exchange_time,
'status': 'completed'
}
self.save_exchange_record(exchange_record)
delivery_info = self.arrange_product_delivery(user_id, product, exchange_quantity)
remaining_points = user_points.total_points
user_level = self.calculate_user_level(user_points.accumulated_points)
return JsonResponse({
'status': 'success',
'exchange_id': exchange_id,
'remaining_points': remaining_points,
'delivery_info': delivery_info,
'user_level': user_level,
'message': f'成功兑换{product.product_name} × {exchange_quantity}'
})
except UserPoints.DoesNotExist:
return JsonResponse({'status': 'error', 'message': '用户积分信息不存在'})
except PointsProduct.DoesNotExist:
return JsonResponse({'status': 'error', 'message': '商品信息不存在'})
except Exception as e:
return JsonResponse({'status': 'error', 'message': str(e)})
def arrange_product_delivery(self, user_id, product, quantity):
if product.delivery_type == 'virtual':
virtual_code = self.generate_virtual_product_code(product.product_id, quantity)
return {'type': 'virtual', 'code': virtual_code, 'validity_days': 30}
else:
delivery_address = self.get_user_default_address(user_id)
estimated_delivery_time = datetime.datetime.now() + datetime.timedelta(days=3)
return {
'type': 'physical',
'address': delivery_address,
'estimated_delivery': estimated_delivery_time.strftime('%Y-%m-%d'),
'tracking_number': f'GC{datetime.datetime.now().strftime("%Y%m%d")}{user_id[-6:]}'
}
def calculate_user_level(self, accumulated_points):
level_thresholds = [0, 100, 500, 1000, 2000, 5000]
level_names = ['新手', '环保达人', '分类专家', '回收大师', '绿色先锋', '环保之星']
for i, threshold in enumerate(level_thresholds):
if accumulated_points >= threshold:
current_level = i
return {'level': current_level, 'name': level_names[current_level], 'next_threshold': level_thresholds[min(current_level + 1, len(level_thresholds) - 1)]}
基于Vue的垃圾分类回收网站文档展示
💖💖作者:计算机编程小咖 💙💙个人简介:曾长期从事计算机专业培训教学,本人也热爱上课教学,语言擅长Java、微信小程序、Python、Golang、安卓Android等,开发项目包括大数据、深度学习、网站、小程序、安卓、算法。平常会做一些项目定制化开发、代码讲解、答辩教学、文档编写、也懂一些降重方面的技巧。平常喜欢分享一些自己开发中遇到的问题的解决办法,也喜欢交流技术,大家有技术代码这一块的问题可以问我! 💛💛想说的话:感谢大家的关注与支持! 💜💜 网站实战项目 安卓/小程序实战项目 大数据实战项目 深度学习实战项目