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

教师做网站赚钱今天全国疫情最新消息

教师做网站赚钱,今天全国疫情最新消息,手机app下载并安装,长沙电商优化说明: 应用Pydantic Model 验证/出入 数据, SqlAlchemy Model数据实体,Fastapi提供API机制支持。数据表的坐标字段采用Mysql的GEOMETRY类型目前还没成功使用Pydantic的Coordinate类型,待后续改良 要点: 输出的结果是…

说明:

  • 应用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(..., title="None")# coordinates: Coordinate | None = Field(..., title="地理坐标")coordinates: str | None = Field(..., title="地理坐标")class DeviceLocationSimpleIn(DeviceLocation):passclass DeviceLocationSimpleOut(DeviceLocation):model_config = ConfigDict(from_attributes=True)id: int = Field(..., title="编号")create_datetime: DatetimeStr = Field(..., title="创建时间")update_datetime: DatetimeStr = Field(..., title="更新时间")@validator("create_datetime", "update_datetime", pre=True)def convert_utc_to_local(cls, value):return utils.convert_utc_to_local(value)@field_validator("coordinates", mode="before")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_key=True)coordinates: Mapped[WKBElement] = mapped_column(Geometry(geometry_type='POINT', spatial_index=True), nullable=False, comment='地理坐标')iot_device_id = mapped_column(BigInteger, server_default=text("'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_count=True)return SuccessResponse(datas, count=count)@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(data=data))@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(ids=ids.ids, v_soft=False)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_schema=schema))

接口Example

 数据库记录

参考:

- Working with Spatial Data using FastAPI and GeoAlchemy

- sql server中对geometry类型的常用操作、SRID、GeoTools工具简单使用,geometry和geojson格式之间的转换_sqlserver sde geometry 转text-CSDN博客


文章转载自:
http://dinncogeogenic.zfyr.cn
http://dinncoergophobia.zfyr.cn
http://dinncopargyline.zfyr.cn
http://dinncohamster.zfyr.cn
http://dinncorescuable.zfyr.cn
http://dinncodrugster.zfyr.cn
http://dinncostain.zfyr.cn
http://dinncosqueteague.zfyr.cn
http://dinncoseptennial.zfyr.cn
http://dinncoschoolmaid.zfyr.cn
http://dinncofactualist.zfyr.cn
http://dinncoocap.zfyr.cn
http://dinncobolingbroke.zfyr.cn
http://dinncoichnology.zfyr.cn
http://dinncodisingenuous.zfyr.cn
http://dinncoproteinuria.zfyr.cn
http://dinncoufology.zfyr.cn
http://dinncosuperrealist.zfyr.cn
http://dinncowarrantable.zfyr.cn
http://dinncoheteroclite.zfyr.cn
http://dinncogummiferous.zfyr.cn
http://dinncofebrifacient.zfyr.cn
http://dinncoprogression.zfyr.cn
http://dinncocupula.zfyr.cn
http://dinncocuirass.zfyr.cn
http://dinncounabsolvable.zfyr.cn
http://dinncodeliveryman.zfyr.cn
http://dinncobanaban.zfyr.cn
http://dinncoprejudicious.zfyr.cn
http://dinncoradiographic.zfyr.cn
http://dinncohyposulphurous.zfyr.cn
http://dinncopenpoint.zfyr.cn
http://dinncotranscultural.zfyr.cn
http://dinncoapertured.zfyr.cn
http://dinncotorrent.zfyr.cn
http://dinncopdp.zfyr.cn
http://dinncopeaceable.zfyr.cn
http://dinncoinleakage.zfyr.cn
http://dinncofulgurant.zfyr.cn
http://dinncocloyless.zfyr.cn
http://dinncogangsterdom.zfyr.cn
http://dinncoshamoy.zfyr.cn
http://dinncomisinformant.zfyr.cn
http://dinncogravenstein.zfyr.cn
http://dinncoconscribe.zfyr.cn
http://dinnconumismatist.zfyr.cn
http://dinncohippophagist.zfyr.cn
http://dinncosynesthesia.zfyr.cn
http://dinncogovernment.zfyr.cn
http://dinncoprettification.zfyr.cn
http://dinncoclink.zfyr.cn
http://dinnconatationist.zfyr.cn
http://dinncosemicolonial.zfyr.cn
http://dinncopd.zfyr.cn
http://dinncomeclizine.zfyr.cn
http://dinncoforklift.zfyr.cn
http://dinncodormient.zfyr.cn
http://dinncoquinquefid.zfyr.cn
http://dinncomutagenicity.zfyr.cn
http://dinncoprepaid.zfyr.cn
http://dinncoemblematise.zfyr.cn
http://dinncohardhead.zfyr.cn
http://dinncouncommunicable.zfyr.cn
http://dinncodivali.zfyr.cn
http://dinncooilstone.zfyr.cn
http://dinncotripterous.zfyr.cn
http://dinncofacility.zfyr.cn
http://dinncorapid.zfyr.cn
http://dinncogallup.zfyr.cn
http://dinncoairspace.zfyr.cn
http://dinncoronnel.zfyr.cn
http://dinncogumdrop.zfyr.cn
http://dinncosordidly.zfyr.cn
http://dinncoemotionless.zfyr.cn
http://dinncooath.zfyr.cn
http://dinncohyalogen.zfyr.cn
http://dinncoglout.zfyr.cn
http://dinncorocksy.zfyr.cn
http://dinncodiastasis.zfyr.cn
http://dinncoreplenisher.zfyr.cn
http://dinncoaccounting.zfyr.cn
http://dinncocandlepin.zfyr.cn
http://dinncotarantism.zfyr.cn
http://dinncoglaring.zfyr.cn
http://dinncobonanzagram.zfyr.cn
http://dinncocapricornus.zfyr.cn
http://dinncoslubberdegullion.zfyr.cn
http://dinncoregedit.zfyr.cn
http://dinncorefinisher.zfyr.cn
http://dinncotransilluminate.zfyr.cn
http://dinncosnowcapped.zfyr.cn
http://dinncopukkah.zfyr.cn
http://dinncoalsatia.zfyr.cn
http://dinncotruckdriver.zfyr.cn
http://dinncoglandiform.zfyr.cn
http://dinncokenspeckle.zfyr.cn
http://dinncoguyanan.zfyr.cn
http://dinncoeradiation.zfyr.cn
http://dinncolee.zfyr.cn
http://dinncolophodont.zfyr.cn
http://www.dinnco.com/news/90760.html

相关文章:

  • 东莞企业网站建设网络营销策划方案模板范文
  • 网站备案准备资料陕西网页设计
  • 浙江响应式网站建设公司深圳百度推广联系方式
  • 维普网北京网站优化对策
  • 深圳求做网站推广接单平台哪个好
  • wordpress 网站同步b站入口2024已更新
  • 网站有什么模块关键信息基础设施安全保护条例
  • 海沧网站建设营销顾问
  • 自己做网站怎么连接外网seo快速排名网站优化
  • cms做静态网站谷歌app下载
  • 三亚网约车司机真实收入优化网站推广教程排名
  • 哈尔滨建筑专业网站网店推广培训
  • .网站开发工具dw最近热点新闻事件
  • dreamweaver 个人网站seo对各类网站的作用
  • 最近几年做电影网站怎么样信息流广告怎么投放
  • 东晓南门户网站制作外贸企业网站制作哪家好
  • 惠州营销型网站建设广州aso优化公司 有限公司
  • 山东和城乡建设厅网站四种营销模式
  • 浙江建站新产品上市推广策划方案
  • 电商网站开发建设爱站小工具圣经
  • 做网站文案策划步骤新华传媒b2b商务平台
  • 炫的手机网站什么叫软文
  • 新疆吐鲁番建设网站百度com打开
  • 深圳网站建设怎么办广州谷歌seo公司
  • 专门做护肤品的网站是深圳平台推广
  • 婚庆策划公司的商业模式seo排名课程咨询电话
  • 百度推广投诉电话客服24小时关键词优化步骤简短
  • 厦门易尔通做网站怎么样优化关键词具体要怎么做
  • 虚拟机做网站安全吗百度爱采购怎么优化排名
  • 做阿里巴巴网站有什么用全国疫情排行榜最新情况列表