潍坊科技学院 本科生毕业设计任务书
核心算法代码分享如下:
# -*- codeing = utf-8 -*-
# Author: Tesla Tech
# XXXX
# @Time :2022/2/10 12:57
# @Author: Administrator
# @File :community.py
import datetime
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine, Column, Integer, String, DECIMAL
from sqlalchemy.orm import sessionmaker
from sqlalchemy.dialects.mysql import DOUBLE
from sqlalchemy.sql import func
from sqlalchemy import DATETIME
DB_URI ='mysql+pymysql://root:123456@localhost:3306/2407_house'
engine = create_engine(DB_URI)
Base = declarative_base() # SQLORM基类
session = sessionmaker(engine)() # 构建session对象
# 小区的表
class Community(Base):
__tablename__ = 'tb_community' # 表名
id = Column(Integer, primary_key=True, autoincrement=True)
cid = Column(String(255))
name = Column(String(255))
address = Column(String(255))
lng = Column(DOUBLE)
lat = Column(DOUBLE)
imgs = Column(String(3000))
price = Column(DOUBLE)
unit = Column(String(255))
cankao = Column(String(255))
jznd = Column(Integer)
jzlx = Column(String(255))
wyfy = Column(String(255))
wygs = Column(String(255))
kfs = Column(String(255))
ldzs = Column(String(255))
fwzs = Column(String(255))
create_time = Column(DATETIME, default=datetime.datetime.now) #时间的处理
def __init__(self, cid, name, address, lng, lat, imgs, price, unit, cankao, jznd, jzlx, wyfy, wygs, kfs, ldzs, fwzs):
self.cid = cid
self.name = name
self.address = address
self.lng = lng
self.lat = lat
self.imgs = imgs
self.price = price
self.unit = unit
self.cankao = cankao
self.jznd = jznd
self.jzlx = jzlx
self.wyfy = wyfy
self.wygs = wygs
self.kfs = kfs
self.ldzs = ldzs
self.fwzs = fwzs
def save(community):
try:
session.add(community) # 添加到session
session.commit() # 提交到数据库
except:
session.rollback()
# 查看一下是否存在这个小区的信息啦?
def checkExist(cid):
try:
cnt = session.query(Community).filter(Community.cid == cid).count()
except Exception as ex:
print('数据操作错误:', ex)
return cnt