瀏覽代碼

241207-1代码。

baoyubo 5 月之前
父節點
當前提交
e4879ffb87
共有 4 個文件被更改,包括 389 次插入0 次删除
  1. 42 0
      models/pattern_base.py
  2. 4 0
      routers/api/pattern/__init__.py
  3. 191 0
      routers/api/pattern/classification.py
  4. 152 0
      routers/api/pattern/template.py

+ 42 - 0
models/pattern_base.py

@@ -66,5 +66,47 @@ class TpPatternWSGroupList(Base):
     create_dept = Column(BigInteger, default=None, comment='创建部门')
     create_by = Column(BigInteger, default=None, comment='创建者')
     update_by = Column(BigInteger, default=None, comment='更新者')
+    class Config:
+        orm_mode = True
+
+
+class TpPatternTemplate(Base):
+    __tablename__ = 'tp_pattern_template'
+
+    template_id = Column(String(255), primary_key=True, comment='模板ID')
+    name = Column(String(255), nullable=False, comment='模板名称')
+    value = Column(String(255), nullable=False, comment='值')
+    order_num = Column(Integer, nullable=True, comment='显示顺序')
+    visible = Column(String(10), default='1', comment='是否显示')
+    del_flag = Column(String(1), default='0', comment='删除标志(0代表存在 2代表删除)')
+    create_time = Column(DateTime, default=datetime.now, comment='数据创建时间')
+    update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='数据更新时间')
+    create_dept = Column(BigInteger, default=None, comment='创建部门')
+    create_by = Column(BigInteger, default=None, comment='创建者')
+    update_by = Column(BigInteger, default=None, comment='更新者')
+    remark = Column(String(500), default='', comment='备注')
+    class Config:
+        orm_mode = True
+
+
+class TpPatternClassification(Base):
+    __tablename__ = 'tp_pattern_classification'
+
+    classification_id = Column(String(255), primary_key=True, comment='ID')
+    template_id = Column(String(255), nullable=False, comment='模板ID')
+    name = Column(String(255), nullable=False, comment='分类名称')
+    value = Column(String(255), nullable=False, comment='值')
+    order_num = Column(Integer, nullable=True, comment='显示顺序')
+    visible = Column(String(255), default='1', comment='是否显示')
+    image = Column(String(255), nullable=False, comment='图像文件名')
+    icon = Column(String(255), nullable=False, comment='图标名称')
+    size = Column(JSON, nullable=False, comment='大小,存储为JSON格式')
+    del_flag = Column(String(1), default='0', comment='删除标志(0代表存在 2代表删除)')
+    create_time = Column(DateTime, default=datetime.now, comment='数据创建时间')
+    update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='数据更新时间')
+    create_dept = Column(BigInteger, default=None, comment='创建部门')
+    create_by = Column(BigInteger, default=None, comment='创建者')
+    update_by = Column(BigInteger, default=None, comment='更新者')
+    remark = Column(String(500), default='', comment='备注')
     class Config:
         orm_mode = True

+ 4 - 0
routers/api/pattern/__init__.py

@@ -19,8 +19,12 @@ from utils.ry_system_util import *
 from common.websocketManager import *
 import json
 import traceback
+from . import template
+from . import classification
 
 router = APIRouter()
+router.include_router(template.router, prefix="/template", tags=["模板"])
+router.include_router(classification.router, prefix="/classification", tags=["分类"])
 
 @router.post("/create")
 async def create_pattern(

+ 191 - 0
routers/api/pattern/classification.py

@@ -0,0 +1,191 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from fastapi import APIRouter, Request, Depends, Query, HTTPException, status,WebSocket,WebSocketDisconnect
+from common.security import valid_access_token,valid_websocket_token
+from fastapi.responses import JSONResponse
+from sqlalchemy.orm import Session
+from sqlalchemy.sql import func
+from common.auth_user import *
+from sqlalchemy import  text
+from pydantic import BaseModel
+from common.BigDataCenterAPI import *
+from database import get_db
+from typing import List
+from models import *
+from utils import *
+from utils.spatial import *
+from utils.ry_system_util import *
+from common.websocketManager import *
+import json
+import traceback
+
+router = APIRouter()
+
+def classification_id_get_classification_info(db,id):
+    query = db.query(TpPatternClassification)
+    query = query.filter_by(classification_id = id,del_flag = '0')
+    return query.first()
+
+
+
+@router.post("/create")
+async def create_pattern(
+    user_id=Depends(valid_access_token),
+    body = Depends(remove_xss_json),
+    db: Session = Depends(get_db)
+):
+    try:
+        new_classification = TpPatternClassification(
+            classification_id=new_guid(),
+            template_id=body['template_id'],
+            name=body['name'],
+            value=body['value'],
+            order_num = body['order_num'],
+            visible=body['visible'],
+            image=body['image'],
+            icon=body['icon'],
+            size=body['size'],
+            create_by = user_id
+        )
+        db.add(new_classification)
+        db.commit()
+        return {"code": 200, "msg": "创建成功", "data": None}
+    except Exception as e:
+        traceback.print_exc()
+        raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
+
+
+
+@router.put("/update/{id}")
+async def update_classification(
+    id :str ,
+    user_id=Depends(valid_access_token),
+    body=Depends(remove_xss_json),
+    db: Session = Depends(get_db)
+):
+    try:
+        update_classification = classification_id_get_classification_info(db,id)
+        if not update_classification:
+            return JSONResponse(status_code=404,content={"code":404,"msg":"classification not found"})
+
+        update_classification.template_id = body['template_id']
+        update_classification.name = body['name']
+        update_classification.value=body['value']
+        update_classification.order_num=body['order_num']
+        update_classification.visible=body['visible']
+        update_classification.image=body['image']
+        update_classification.icon=body['icon']
+        update_classification.size=body['size']
+        update_classification.update_by = user_id
+        db.commit()
+        return {"code": 200, "msg": "更新成功"}
+    except Exception as e:
+        traceback.print_exc()
+        raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
+
+@router.get("/info/{id}")
+async def get_pattern_info(
+    id: str,
+    db: Session = Depends(get_db)
+):
+    try:
+
+        info = classification_id_get_classification_info(db,id)
+        if not info:
+            return JSONResponse(status_code=404,content={"code":404,"msg":"classification not found"})
+        data = {"classification_id": info.classification_id,
+                "template_id": info.template_id,
+                "name": info.name,
+                "value": info.value,
+                "order_num": info.order_num,
+                "visible": info.visible,
+                "image": info.image,
+                "icon": info.icon,
+                "size": info.size,
+                "create_time": info.create_time}
+        return {"code": 200, "msg": "获取成功", "data": data}
+    except Exception as e:
+        traceback.print_exc()
+        raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
+
+@router.get("/list")
+async def get_pattern_list(
+    name: str = Query(None, description='名称'),
+    page: int = Query(1, gt=0, description='页码'),
+    pageSize: int = Query(None, gt=0, description='每页条目数量'),
+    db: Session = Depends(get_db)
+):
+    try:
+        query = db.query(TpPatternClassification)
+        query = query.filter_by(del_flag='0')
+        if name:
+            query = query.filter(TpPatternClassification.name.like(f'%{name}%'))
+        total_items = query.count()
+        # 排序
+        if pageSize is None:
+            pageSize=total_items
+        query = query.order_by(TpPatternClassification.order_num.asc())
+        # 执行分页查询
+        lists = query.offset((page - 1) * pageSize).limit(pageSize).all()
+        data = [{"classification_id": info.classification_id,
+                "template_id": info.template_id,
+                "name": info.name,
+                "value": info.value,
+                "order_num": info.order_num,
+                "visible": info.visible,
+                "image": info.image,
+                "icon": info.icon,
+                "size": info.size,
+                "create_time": info.create_time} for info in lists]
+        return {"code": 200, "msg": "查询成功", "data": data,
+                "total": total_items,
+                "page": page,
+                "pageSize": pageSize,
+                "totalPages": (total_items + pageSize - 1) // pageSize
+                }
+    except Exception as e:
+        traceback.print_exc()
+        raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
+
+@router.delete("/delete/{id}")
+async def delete_pattern(
+    id: str,
+    db: Session = Depends(get_db)
+):
+    try:
+        # 检查图案是否存在
+        info = classification_id_get_classification_info(db, id)
+        if not info:
+            return JSONResponse(status_code=404, content={"code": 404, "msg": "classification not found"})
+        info.del_flag='2'
+        db.commit()
+        return {"code": 200, "msg": "删除成功"}
+    except Exception as e:
+        traceback.print_exc()
+        raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
+
+
+@router.put('/changeVisible')
+async def change_classification_visible(
+        db: Session = Depends(get_db),
+        body=Depends(remove_xss_json),
+        user_id=Depends(valid_access_token)
+):
+    try:
+        classification_id = body['classification_id']
+        visible = body['visible']
+        info = classification_id_get_classification_info(db, classification_id)
+        if not info:
+            return JSONResponse(status_code=404, content={"code": 404, "msg": "classification not found"})
+        info.visible= visible
+        info.update_by=user_id
+        db.commit()
+        return {
+            "code": 200,
+            "msg": "操作成功"
+        }
+    except Exception as e:
+        # 处理异常
+        traceback.print_exc()
+        raise HTTPException(status_code=500, detail=str(e))

+ 152 - 0
routers/api/pattern/template.py

@@ -0,0 +1,152 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from fastapi import APIRouter, Request, Depends, Query, HTTPException, status,WebSocket,WebSocketDisconnect
+from common.security import valid_access_token,valid_websocket_token
+from fastapi.responses import JSONResponse
+from sqlalchemy.orm import Session
+from sqlalchemy.sql import func
+from common.auth_user import *
+from sqlalchemy import  text
+from pydantic import BaseModel
+from common.BigDataCenterAPI import *
+from database import get_db
+from typing import List
+from models import *
+from utils import *
+from utils.spatial import *
+from utils.ry_system_util import *
+from common.websocketManager import *
+import json
+import traceback
+
+router = APIRouter()
+
+def template_id_get_template_info(db,id):
+    query = db.query(TpPatternTemplate)
+    query = query.filter_by(template_id = id,del_flag = '0')
+    return query.first()
+
+
+
+@router.post("/create")
+async def create_template(
+    user_id=Depends(valid_access_token),
+    body = Depends(remove_xss_json),
+    db: Session = Depends(get_db)
+):
+    try:
+        new_template = TpPatternTemplate(
+            template_id=new_guid(),
+            name=body['name'],
+            value=body['value'],
+            order_num=body['order_num'],
+            visible=body['visible'],
+            create_by = user_id
+        )
+        db.add(new_template)
+        db.commit()
+        return {"code": 200, "msg": "创建成功", "data": None}
+    except Exception as e:
+        traceback.print_exc()
+        raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
+
+
+
+@router.put("/update/{id}")
+async def update_pattern(
+    id :str ,
+    user_id=Depends(valid_access_token),
+    body=Depends(remove_xss_json),
+    db: Session = Depends(get_db)
+):
+    try:
+        update_template = template_id_get_template_info(db,id)
+        if not update_template:
+            return JSONResponse(status_code=404,content={"code":404,"msg":"template not found"})
+
+        update_template.name = body['name']
+        update_template.value = body['value']
+        update_template.order_num=body['order_num']
+        update_template.visible=body['visible']
+        update_template.update_by = user_id
+        db.commit()
+        return {"code": 200, "msg": "更新成功"}
+    except Exception as e:
+        traceback.print_exc()
+        raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
+
+@router.get("/info/{id}")
+async def get_pattern_info(
+    id: str,
+    db: Session = Depends(get_db)
+):
+    try:
+
+        info = template_id_get_template_info(db,id)
+        if not info:
+            return JSONResponse(status_code=404,content={"code":404,"msg":"template not found"})
+        data = {"template_id": info.template_id,
+                "name": info.name,
+                "value": info.value,
+                "order_num": info.order_num,
+                "visible": info.visible,
+                "create_time": info.create_time,
+                "create_by": info.create_by}
+        return {"code": 200, "msg": "获取成功", "data": data}
+    except Exception as e:
+        traceback.print_exc()
+        raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
+
+@router.get("/list")
+async def get_pattern_list(
+    name: str = Query(None, description='名称'),
+    page: int = Query(1, gt=0, description='页码'),
+    pageSize: int = Query(None, gt=0, description='每页条目数量'),
+    db: Session = Depends(get_db)
+):
+    try:
+        query = db.query(TpPatternTemplate)
+        query = query.filter_by(del_flag='0')
+        if name:
+            query = query.filter(TpPatternTemplate.name.like(f'%{name}%'))
+        total_items = query.count()
+        # 排序
+        if pageSize is None:
+            pageSize=total_items
+        query = query.order_by(TpPatternTemplate.order_num.asc())
+        # 执行分页查询
+        lists = query.offset((page - 1) * pageSize).limit(pageSize).all()
+        data = [{"template_id": info.template_id,
+                "name": info.name,
+                "value": info.value,
+                "order_num": info.order_num,
+                "visible": info.visible,
+                "create_time": info.create_time,
+                "create_by": info.create_by} for info in lists]
+        return {"code": 200, "msg": "查询成功", "data": data,
+                "total": total_items,
+                "page": page,
+                "pageSize": pageSize,
+                "totalPages": (total_items + pageSize - 1) // pageSize
+                }
+    except Exception as e:
+        traceback.print_exc()
+        raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
+
+@router.delete("/delete/{id}")
+async def delete_pattern(
+    id: str,
+    db: Session = Depends(get_db)
+):
+    try:
+        # 检查图案是否存在
+        info = template_id_get_template_info(db, id)
+        if not info:
+            return JSONResponse(status_code=404, content={"code": 404, "msg": "template not found"})
+        info.del_flag='2'
+        db.commit()
+        return {"code": 200, "msg": "删除成功"}
+    except Exception as e:
+        traceback.print_exc()
+        raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")