当前位置: 首页 > news >正文

华硕固件做网站6建筑工程网上培训平台

华硕固件做网站6,建筑工程网上培训平台,西安百度推广代理商,高端室内设计工作室说明#xff1a; 应用Pydantic Model 验证/出入 数据#xff0c; SqlAlchemy Model数据实体#xff0c;Fastapi提供API机制支持。数据表的坐标字段采用Mysql的GEOMETRY类型目前还没成功使用Pydantic的Coordinate类型#xff0c;待后续改良 要点#xff1a; 输出的结果是…说明 应用Pydantic Model 验证/出入 数据 SqlAlchemy Model数据实体Fastapi提供API机制支持。数据表的坐标字段采用Mysql的GEOMETRY类型目前还没成功使用Pydantic的Coordinate类型待后续改良 要点 输出的结果是DeviceLocationSimpleOut模型里面的验证/转换方法需通过否则不能录入成功 设计 建表sql /**/ /* Table: ia_iot_device_location */ /**/ create table ia_iot_device_location (id bigint not null auto_increment comment ,iot_device_id bigint default 0 comment ,label varchar(255) comment ,coordinates GEOMETRY not null comment 地理坐标,create_datetime datetime not null default CURRENT_TIMESTAMP comment 创建时间,update_datetime datetime not null default CURRENT_TIMESTAMP comment 更新时间,delete_datetime datetime comment ,is_delete tinyint not null default 0 comment ,primary key (id) );/**/ /* Index: Index_1 */ /**/ create index Index_1 on ia_iot_device_location (iot_device_id );/**/ /* Index: Index_2 */ /**/ create SPATIAL index Index_2 on ia_iot_device_location (coordinates );Pydantic Model (apps\vadmin\iot\schemas\DeviceLocation.py) #!/usr/bin/python # -*- coding: utf-8 -*- # version : 1.0 # Create Time : 2024/05/22 20:45 # File : Device.py # IDE : PyCharm # desc : pydantic 模型用于数据库序列化操作from pydantic import BaseModel, Field, ConfigDict, ValidationError, validator, field_validator, constr from core.data_types import DatetimeStr from datetime import datetime, timezone, timedelta from apps.vadmin.iot.models.data_types import * from apps.vadmin.iot.utils import utils from application import settings from pydantic_extra_types.coordinate import Coordinate from geoalchemy2.shape import to_shapeclass DeviceLocation(BaseModel):label: str | None Field(None, title标签)iot_device_id: int | None Field(..., titleNone)# coordinates: Coordinate | None Field(..., title地理坐标)coordinates: str | None Field(..., title地理坐标)class DeviceLocationSimpleIn(DeviceLocation):passclass DeviceLocationSimpleOut(DeviceLocation):model_config ConfigDict(from_attributesTrue)id: int Field(..., title编号)create_datetime: DatetimeStr Field(..., title创建时间)update_datetime: DatetimeStr Field(..., title更新时间)validator(create_datetime, update_datetime, preTrue)def convert_utc_to_local(cls, value):return utils.convert_utc_to_local(value)field_validator(coordinates, modebefore)def turn_coordinates_into_wkt(cls, value):return to_shape(value).wkt SqlAlchemy Model (apps\vadmin\iot\models\models.py) from typing import List, Optional from datetime import datetime from sqlalchemy import BigInteger, Column, DateTime, ForeignKey, ForeignKeyConstraint, Index, Integer, String, Table, Text, text from sqlalchemy.dialects.mysql import TINYINT from sqlalchemy.orm import Mapped, declarative_base, mapped_column, relationship from sqlalchemy.orm.base import Mapped from geoalchemy2 import Geometry, WKBElement from sqlalchemy.orm import relationship, Mapped, mapped_column from db.db_base import BaseModel from .data_types import DeviceType import uuid import secretsmetadata BaseModel.metadataclass DeviceLocation(BaseModel):__tablename__ ia_iot_device_location__table_args__ (Index(Index_1, iot_device_id),Index(Index_2, coordinates))id mapped_column(BigInteger, primary_keyTrue)coordinates: Mapped[WKBElement] mapped_column(Geometry(geometry_typePOINT, spatial_indexTrue), nullableFalse, comment地理坐标)iot_device_id mapped_column(BigInteger, server_defaulttext(0))label mapped_column(String(255, utf8mb4_general_ci)) FastApi 入口 (apps\vadmin\iot\views.py) ########################################################### # 设备地理位置 ########################################################### app.get(/device-location, summary获取设备地理位置列表, tags[设备地理位置]) async def get_deviceLocation_list(p: params.DeviceLocation Depends(), auth: Auth Depends(AllUserAuth())):datas, count await crud.DeviceLocationDal(auth.db).get_datas(**p.dict(), v_return_countTrue)return SuccessResponse(datas, countcount)app.post(/device-location, summary创建设备地理位置, tags[设备地理位置]) async def create_deviceLocation(data: schemas.DeviceLocation, auth: Auth Depends(AllUserAuth())):return SuccessResponse(await crud.DeviceLocationDal(auth.db).create_data(datadata))app.delete(/device-location, summary删除设备地理位置, description硬删除, tags[设备地理位置]) async def delete_deviceLocation_list(ids: IdList Depends(), auth: Auth Depends(AllUserAuth())):await crud.DeviceLocationDal(auth.db).delete_datas(idsids.ids, v_softFalse)return SuccessResponse(删除成功)app.put(/device-location/{data_id}, summary更新设备地理位置, tags[设备地理位置]) async def put_deviceLocation(data_id: int, data: schemas.DeviceLocation, auth: Auth Depends(AllUserAuth())):return SuccessResponse(await crud.DeviceLocationDal(auth.db).put_data(data_id, data))app.get(/device-location/{data_id}, summary获取设备地理位置信息, tags[设备地理位置]) async def get_deviceLocation(data_id: int, db: AsyncSession Depends(db_getter)):schema schemas.deviceLocationSimpleOutreturn SuccessResponse(await crud.DeviceLocationDal(db).get_data(data_id, v_schemaschema)) 接口Example 数据库记录 参考 - Working with Spatial Data using FastAPI and GeoAlchemy - sql server中对geometry类型的常用操作、SRID、GeoTools工具简单使用geometry和geojson格式之间的转换_sqlserver sde geometry 转text-CSDN博客
http://www.hkea.cn/news/14546646/

相关文章:

  • 有那些方法推广网站兴安盟网站建设
  • 郑州网络营销网站购物网站建设项目策划书
  • 指定图片做logo网站wordpress本地迁移到服务器
  • 做钢结构网站有哪些搜索引擎优化的简称
  • 搭建网站的过程超短网址生成
  • 阿里云网站建设与发布题库江北区网站建设
  • 如何做网站的营销邵阳建设银行网站是多少钱
  • 奇信建设集团官方网站wordpress顶部栏如何修改
  • 诚信经营网站的建设wordpress安全
  • 什么软件做网站比较好广州建站商城
  • 做自己的网站需要会编程吗wordpress同学录
  • 静态网站公用头部 调用标题百度广告联盟app下载官网
  • 网站标题优化可以含几个关键词摄影基地设计
  • 搭建个网站需要多少钱各大门户网站
  • 越秀区建设水务局网站东莞市做网站公司
  • win7 做网站服务器asp.net 网站开发项目
  • 甘肃两学一做网站手机版商城网站案例
  • 网站建设素材包用h5开发的网站模板下载
  • 合肥做网站工作室个人网站建立多少钱
  • 品牌网站建设小8蝌蚪如何在手机上开自己的网站
  • 郑州七彩网站建设公司怎么样虚拟主机有几种类型
  • 天天seo站长工具域名提交收录
  • 网站访问量查询工具广州做网站建设哪家专业
  • 优秀个人网站模板下载网站建设策划方
  • 微信网站建站平台做电商一般月入多少钱
  • 网站大全app下载推广公司业务发朋友圈
  • 那块做微信平台网站小程序商店有哪些
  • 网站建设安全吗台州市临海建设局网站
  • 网站推广营销方法专业提供网站建设服务是什么
  • 网站备案 座机百度销售岗位怎么样