后端更新
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
from config.minIO import get_temp_url_dict
|
||||
from config.pgDb import pg_pool
|
||||
from models.SentinelRecordRequest import SentinelRecordRequest
|
||||
from utils.MyUtils import format_datetime
|
||||
|
||||
|
||||
@@ -90,6 +89,7 @@ def get_sentinel_record_list_db_page(
|
||||
r.vehicle_image,
|
||||
r.livestock_type,
|
||||
r.livestock_source,
|
||||
r.license_plate_color,
|
||||
r.is_inspected,
|
||||
r.dept_id,
|
||||
sd.name AS dept_name,
|
||||
@@ -116,6 +116,7 @@ def get_sentinel_record_list_db_page(
|
||||
vehicle_image,
|
||||
livestock_type,
|
||||
livestock_source,
|
||||
license_plate_color,
|
||||
is_inspected,
|
||||
dept_id,
|
||||
dept_name,
|
||||
@@ -130,13 +131,14 @@ def get_sentinel_record_list_db_page(
|
||||
"license_plate": license_plate,
|
||||
"vehicle_type": vehicle_type,
|
||||
"license_plate_image": get_temp_url_dict(
|
||||
"sentinel", "license_plate", license_plate_image
|
||||
"sentinel", "vehicle_image_front", license_plate_image
|
||||
),
|
||||
"vehicle_image": get_temp_url_dict(
|
||||
"sentinel", "vehicle_image", vehicle_image
|
||||
"sentinel", "vehicle_image_side", vehicle_image
|
||||
),
|
||||
"livestock_type": livestock_type,
|
||||
"livestock_source": livestock_source,
|
||||
"license_plate_color": license_plate_color,
|
||||
"is_inspected": 1 if is_inspected else 0,
|
||||
"dept_id": dept_id,
|
||||
"dept_name": dept_name,
|
||||
@@ -161,6 +163,7 @@ def get_sentinel_record_by_id(record_id):
|
||||
r.license_plate_image,
|
||||
r.vehicle_image,
|
||||
r.livestock_type,
|
||||
r.license_plate_color,
|
||||
r.livestock_source,
|
||||
r.is_inspected,
|
||||
r.dept_id,
|
||||
@@ -188,6 +191,7 @@ def get_sentinel_record_by_id(record_id):
|
||||
license_plate_image,
|
||||
vehicle_image,
|
||||
livestock_type,
|
||||
license_plate_color,
|
||||
livestock_source,
|
||||
is_inspected,
|
||||
dept_id,
|
||||
@@ -202,12 +206,13 @@ def get_sentinel_record_by_id(record_id):
|
||||
"license_plate": license_plate,
|
||||
"vehicle_type": vehicle_type,
|
||||
"license_plate_image": get_temp_url_dict(
|
||||
"sentinel", "license_plate", license_plate_image
|
||||
"sentinel", "vehicle_image_front", license_plate_image
|
||||
),
|
||||
"vehicle_image": get_temp_url_dict(
|
||||
"sentinel", "vehicle_image", vehicle_image
|
||||
"sentinel", "vehicle_image_side", vehicle_image
|
||||
),
|
||||
"livestock_type": livestock_type,
|
||||
"license_plate_color": license_plate_color,
|
||||
"livestock_source": livestock_source,
|
||||
"is_inspected": 1 if is_inspected else 0,
|
||||
"dept_id": str(dept_id),
|
||||
@@ -333,15 +338,30 @@ def delete_sentinel_record_db(id: str) -> int:
|
||||
return cursor.rowcount
|
||||
|
||||
|
||||
def saveSentinelRecord(data: SentinelRecordRequest) -> str:
|
||||
def saveSentinelRecord(
|
||||
id: str,
|
||||
vehicle_type: str,
|
||||
vehicle_image: str,
|
||||
livestock_type: str,
|
||||
remark: str,
|
||||
dept_id: str,
|
||||
license_plate: str,
|
||||
license_plate_image: str,
|
||||
license_plate_color: int = 0,
|
||||
) -> str:
|
||||
sql = """
|
||||
INSERT INTO sentinel_records (
|
||||
id,
|
||||
vehicle_type,
|
||||
vehicle_image,
|
||||
livestock_type,
|
||||
remark,
|
||||
dept_id,
|
||||
license_plate,
|
||||
license_plate_image,
|
||||
vehicle_type,
|
||||
vehicle_image
|
||||
license_plate_color
|
||||
)
|
||||
VALUES (%s, %s, %s, %s)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
RETURNING id;
|
||||
"""
|
||||
|
||||
@@ -350,36 +370,17 @@ def saveSentinelRecord(data: SentinelRecordRequest) -> str:
|
||||
cursor.execute(
|
||||
sql,
|
||||
(
|
||||
data.LicensePlate,
|
||||
data.LicensePlateImage,
|
||||
data.VehicleType,
|
||||
data.VehicleImage,
|
||||
id,
|
||||
vehicle_type,
|
||||
vehicle_image,
|
||||
livestock_type,
|
||||
remark,
|
||||
dept_id,
|
||||
license_plate,
|
||||
license_plate_image,
|
||||
license_plate_color,
|
||||
),
|
||||
)
|
||||
new_id = cursor.fetchone()[0]
|
||||
conn.commit()
|
||||
return str(new_id)
|
||||
|
||||
|
||||
def update_sentinel_record(
|
||||
id: str, livestock_type: str, remark: str, dept_id: str
|
||||
) -> bool:
|
||||
"""
|
||||
根据 id 更新 sentinel_records 表中的 livestock_type 和 dept_id
|
||||
"""
|
||||
sql = """
|
||||
UPDATE sentinel_records
|
||||
SET livestock_type = %s,
|
||||
remark = %s,
|
||||
dept_id = %s,
|
||||
updated_at = now()
|
||||
WHERE id = %s
|
||||
RETURNING id;
|
||||
"""
|
||||
|
||||
with pg_pool.getConn() as conn:
|
||||
with conn.cursor() as cursor:
|
||||
cursor.execute(sql, (livestock_type, remark, dept_id, id))
|
||||
record = cursor.fetchone()
|
||||
conn.commit()
|
||||
return record is not None
|
||||
|
||||
Reference in New Issue
Block a user