上传文件至「/」
This commit is contained in:
@@ -0,0 +1,185 @@
|
||||
from house_service import *
|
||||
|
||||
def print_menu():
|
||||
print("\n===== 房屋出租系统 V3.0 =====")
|
||||
print("1. 新增房源")
|
||||
print("2. 删除房源")
|
||||
print("3. 修改房源")
|
||||
print("4. 查询房源")
|
||||
print("5. 查看/管理操作记录")
|
||||
print("6. 查看/管理浏览历史")
|
||||
# V3.0 新增菜单
|
||||
print("7. 地址字符串解析测试")
|
||||
print("8. 按区域关键词模糊查询")
|
||||
print("9. 初始化小区邻接矩阵")
|
||||
print("10. 更新小区间距离")
|
||||
print("11. 退出系统")
|
||||
print("============================")
|
||||
|
||||
def op_record_menu():
|
||||
while True:
|
||||
print("\n----- 操作记录管理 -----")
|
||||
print("1. 查看最近10条")
|
||||
print("2. 取出最新一条")
|
||||
print("3. 清空记录")
|
||||
print("4. 返回")
|
||||
c = input("请选择:")
|
||||
if c == "1":
|
||||
lst = get_recent_records("operation",10)
|
||||
print(lst if lst else "暂无记录")
|
||||
elif c == "2":
|
||||
print(pop_operation_stack() or "暂无记录")
|
||||
elif c == "3":
|
||||
clear_stack("operation")
|
||||
elif c == "4":
|
||||
break
|
||||
else:
|
||||
print("输入有误")
|
||||
|
||||
|
||||
def browse_history_menu():
|
||||
while True:
|
||||
print("\n----- 浏览历史管理 -----")
|
||||
print("1. 查看最近10条")
|
||||
print("2. 取出最新一条")
|
||||
print("3. 清空历史")
|
||||
print("4. 返回")
|
||||
c = input("请选择:")
|
||||
if c == "1":
|
||||
id_list = get_recent_records("browse",10)
|
||||
if not id_list:
|
||||
print("暂无浏览历史")
|
||||
continue
|
||||
for idx,hid in enumerate(id_list,1):
|
||||
info = query_house("id", hid)
|
||||
if info:
|
||||
h = info[0]
|
||||
print(f"{idx}. ID:{hid} 地址:{h['address']}")
|
||||
else:
|
||||
print(f"{idx}. ID:{hid} 房源已不存在")
|
||||
elif c == "2":
|
||||
hid = pop_browse_stack()
|
||||
if not hid:
|
||||
print("暂无浏览历史")
|
||||
continue
|
||||
info = query_house("id", hid)
|
||||
print(f"最近浏览ID:{hid}")
|
||||
elif c == "3":
|
||||
clear_stack("browse")
|
||||
elif c == "4":
|
||||
break
|
||||
else:
|
||||
print("输入有误")
|
||||
|
||||
|
||||
def main():
|
||||
while True:
|
||||
print_menu()
|
||||
choice = input("请输入功能编号:")
|
||||
|
||||
if choice == "1":
|
||||
addr = input("输入房源地址:")
|
||||
try:
|
||||
price = float(input("输入月租金:"))
|
||||
area = float(input("输入面积:"))
|
||||
except:
|
||||
print("租金面积必须是数字!")
|
||||
continue
|
||||
htype = input("输入户型:")
|
||||
if add_house(addr,price,area,htype):
|
||||
new_id = get_next_house_id() - 1
|
||||
push_operation_stack(f"新增房源ID:{new_id} 地址:{addr}")
|
||||
|
||||
elif choice == "2":
|
||||
try:
|
||||
hid = int(input("输入要删除房源ID:"))
|
||||
res = query_house("id",hid)
|
||||
addr = res[0]["address"] if res else "未知地址"
|
||||
if delete_house(hid):
|
||||
push_operation_stack(f"删除房源ID:{hid} 地址:{addr}")
|
||||
except:
|
||||
print("ID必须是整数")
|
||||
|
||||
elif choice == "3":
|
||||
try:
|
||||
hid = int(input("输入要修改房源ID:"))
|
||||
edit = {}
|
||||
a = input("新地址(回车不修改):")
|
||||
if a: edit["address"] = a
|
||||
p = input("新租金(回车不修改):")
|
||||
if p: edit["price"] = float(p)
|
||||
ar = input("新面积(回车不修改):")
|
||||
if ar: edit["area"] = float(ar)
|
||||
t = input("新户型(回车不修改):")
|
||||
if t: edit["house_type"] = t
|
||||
if edit:
|
||||
if update_house(hid, edit):
|
||||
push_operation_stack(f"修改房源ID:{hid} 变更:{edit}")
|
||||
else:
|
||||
print("未填写任何修改内容")
|
||||
except:
|
||||
print("输入格式错误")
|
||||
|
||||
elif choice == "4":
|
||||
print("1-ID 2-地址 3-租金 4-户型")
|
||||
sel = input("选择查询类型:")
|
||||
map_dic = {"1":"id","2":"address","3":"price","4":"house_type"}
|
||||
if sel not in map_dic:
|
||||
print("选择无效")
|
||||
continue
|
||||
val = input("输入查询值:")
|
||||
res_list = query_house(map_dic[sel], val)
|
||||
if not res_list:
|
||||
print("未找到房源")
|
||||
continue
|
||||
for h in res_list:
|
||||
print(f"ID:{h['id']} 地址:{h['address']} 租金:{h['price']}")
|
||||
if map_dic[sel] == "id":
|
||||
push_browse_stack(h["id"])
|
||||
|
||||
elif choice == "5":
|
||||
op_record_menu()
|
||||
elif choice == "6":
|
||||
browse_history_menu()
|
||||
|
||||
#3.0
|
||||
elif choice == "7":
|
||||
# 测试地址字符串解析
|
||||
full_addr = input("输入完整地址(如:四川省德阳市什邡市XX小区):")
|
||||
res = parse_address_string(full_addr)
|
||||
print("解析结果:", res)
|
||||
|
||||
elif choice == "8":
|
||||
# 按区域关键词模糊查询
|
||||
keyword = input("输入区域关键词(如:什邡、德阳):")
|
||||
res_list = fuzzy_query_by_district(keyword)
|
||||
if not res_list:
|
||||
print("未找到该区域房源")
|
||||
else:
|
||||
for h in res_list:
|
||||
print(f"ID:{h['id']} 地址:{h['address']}")
|
||||
|
||||
elif choice == "9":
|
||||
# 初始化小区邻接矩阵
|
||||
community_input = input("输入所有小区名称,用英文逗号分隔:")
|
||||
community_list = community_input.split(",")
|
||||
init_community_matrix(community_list)
|
||||
|
||||
elif choice == "10":
|
||||
# 更新两个小区距离
|
||||
c1 = input("输入小区A名称:")
|
||||
c2 = input("输入小区B名称:")
|
||||
try:
|
||||
dis = float(input("输入两小区距离:"))
|
||||
update_matrix_distance(c1, c2, dis)
|
||||
except:
|
||||
print("距离必须是数字")
|
||||
|
||||
elif choice == "11":
|
||||
print("系统退出成功!")
|
||||
break
|
||||
else:
|
||||
print("请输入有效编号")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user