|
@@ -1,9 +1,31 @@
|
|
|
+import json
|
|
|
import utils
|
|
|
from datetime import datetime
|
|
|
|
|
|
from utils.mysql_helper import MySQLHelper
|
|
|
|
|
|
|
|
|
+class InstrumentData:
|
|
|
+ def __init__(
|
|
|
+ self,
|
|
|
+ company: str,
|
|
|
+ name: str,
|
|
|
+ manufacturer: str,
|
|
|
+ model: str,
|
|
|
+ quantity: int,
|
|
|
+ unit_price: float,
|
|
|
+ ):
|
|
|
+ self.company = company # 中标单位名称,参与竞标并中标的公司名称
|
|
|
+ self.name = name # 仪器名称,例如:红外光谱仪
|
|
|
+ self.manufacturer = manufacturer # 仪器厂商,例如:赛默飞、Bruker
|
|
|
+ self.model = model # 仪器的型号 / 规格,例如:NIR25S
|
|
|
+ self.quantity = quantity # 中标仪器的数量,台数,例如:2
|
|
|
+ self.unit_price = unit_price # 仪器的单价,单位转
|
|
|
+
|
|
|
+ def to_str(self) -> str:
|
|
|
+ return f"[名称:{self.name},中标单位:{self.company},仪器厂商:{self.manufacturer},仪器规格:{self.model},数量:{self.quantity},单价:{self.unit_price}]"
|
|
|
+
|
|
|
+
|
|
|
class ProcessResultData:
|
|
|
|
|
|
def __init__(
|
|
@@ -12,9 +34,11 @@ class ProcessResultData:
|
|
|
title=None,
|
|
|
url=None,
|
|
|
keyword=None,
|
|
|
+ provice=None,
|
|
|
+ city=None,
|
|
|
date=None,
|
|
|
- price=None,
|
|
|
- bidder=None,
|
|
|
+ instruments=None,
|
|
|
+ instruments_o=None,
|
|
|
summary=None,
|
|
|
attach_path=None,
|
|
|
status=None,
|
|
@@ -31,8 +55,15 @@ class ProcessResultData:
|
|
|
self.url = url
|
|
|
self.keyword = keyword
|
|
|
self.date = date
|
|
|
- self.price = price
|
|
|
- self.bidder = bidder
|
|
|
+ self.instruments_str = ""
|
|
|
+ self.instruments = []
|
|
|
+ self.set_instruments(instruments, instruments_o)
|
|
|
+ self.provice = provice.replace("省", "").replace("市", "") if provice else ""
|
|
|
+ self.city = (
|
|
|
+ city.replace("市", "").replace("区", "").replace("县", "") if city else ""
|
|
|
+ )
|
|
|
+ if self.provice == self.city:
|
|
|
+ self.provice = ""
|
|
|
self.summary = summary
|
|
|
self.attach_path = attach_path
|
|
|
self.status = status
|
|
@@ -47,14 +78,34 @@ class ProcessResultData:
|
|
|
def __repr__(self):
|
|
|
return (
|
|
|
f"ProcessResultData(no={self.no}, title={self.title}, date={self.date}, "
|
|
|
- f"keyword={self.keyword}, price={self.price}, bidder={self.bidder}, summary={self.summary}, attach_path={self.attach_path}, "
|
|
|
+ f"keyword={self.keyword}, provice={self.provice},city={self.city},instruments={self.instruments_str} summary={self.summary}, attach_path={self.attach_path}, "
|
|
|
f"status={self.status}, create_time={self.create_time}, "
|
|
|
f"send_time={self.send_time}, remark={self.remark})"
|
|
|
)
|
|
|
|
|
|
+ def set_instruments(self, instruments_str: str, instruments):
|
|
|
+ if instruments is None:
|
|
|
+ instruments = []
|
|
|
+ if instruments_str:
|
|
|
+ self.instruments_str = instruments_str
|
|
|
+ self.instruments = [
|
|
|
+ InstrumentData(**instrument)
|
|
|
+ for instrument in json.loads(self.instruments_str)
|
|
|
+ ]
|
|
|
+ else:
|
|
|
+ self.instruments = instruments or []
|
|
|
+ self.instruments_str = (
|
|
|
+ json.dumps(
|
|
|
+ instruments,
|
|
|
+ ensure_ascii=False,
|
|
|
+ )
|
|
|
+ if len(instruments) > 0
|
|
|
+ else ""
|
|
|
+ )
|
|
|
+
|
|
|
_insert_query = """
|
|
|
- INSERT IGNORE INTO t_data_result (no, title, url, keyword, date, price, bidder, summary, attach_path, status, create_time, prompt_tokens, completion_tokens, total_tokens)
|
|
|
- VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);
|
|
|
+ INSERT IGNORE INTO t_data_result (no, title, url, keyword, date, provice, city, instruments, summary, attach_path, status, create_time, prompt_tokens, completion_tokens, total_tokens)
|
|
|
+ VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);
|
|
|
"""
|
|
|
# _update_query = """
|
|
|
# UPDATE t_collect_data SET status = 1 WHERE url = %s;
|
|
@@ -70,8 +121,9 @@ class ProcessResultData:
|
|
|
process_result_data.url,
|
|
|
process_result_data.keyword,
|
|
|
process_result_data.date,
|
|
|
- process_result_data.price,
|
|
|
- process_result_data.bidder,
|
|
|
+ process_result_data.provice,
|
|
|
+ process_result_data.city,
|
|
|
+ process_result_data.instruments_str,
|
|
|
process_result_data.summary,
|
|
|
process_result_data.attach_path,
|
|
|
0,
|
|
@@ -86,6 +138,7 @@ class ProcessResultData:
|
|
|
with MySQLHelper() as db_helper:
|
|
|
db_helper.execute_non_query(self._insert_query, insert_params)
|
|
|
# db_helper.execute_non_query(self._update_query, update_params)
|
|
|
+ utils.get_logger().info(f"共插入 1 条结果处理数据")
|
|
|
|
|
|
def insert_batch(self, process_result_data_list):
|
|
|
if not all(
|
|
@@ -103,8 +156,9 @@ class ProcessResultData:
|
|
|
process_result_data.url,
|
|
|
process_result_data.keyword,
|
|
|
process_result_data.date,
|
|
|
- process_result_data.price,
|
|
|
- process_result_data.bidder,
|
|
|
+ process_result_data.provice,
|
|
|
+ process_result_data.city,
|
|
|
+ process_result_data.instruments_str,
|
|
|
process_result_data.summary,
|
|
|
process_result_data.attach_path,
|
|
|
0,
|
|
@@ -122,7 +176,7 @@ class ProcessResultData:
|
|
|
with MySQLHelper() as db_helper:
|
|
|
db_helper.execute_non_query(self._insert_query, insert_params)
|
|
|
affected_rows = db_helper.connection.affected_rows()
|
|
|
- utils.get_logger().info(f"成功插入 {affected_rows} 条数据")
|
|
|
+ utils.get_logger().info(f"共插入 {affected_rows} 条结果处理数据")
|
|
|
# for param in update_params:
|
|
|
# db_helper.execute_non_query(self._update_query, param)
|
|
|
return affected_rows
|
|
@@ -137,10 +191,10 @@ class ProcessResultData:
|
|
|
if not result:
|
|
|
return None
|
|
|
data = ProcessResultData(
|
|
|
- url=result["url"],
|
|
|
no=result["no"],
|
|
|
- other_urls=result["other_urls"],
|
|
|
+ url=result["url"],
|
|
|
attach_path=result["attach_path"],
|
|
|
+ other_urls=result["other_urls"],
|
|
|
)
|
|
|
return data
|
|
|
|
|
@@ -154,14 +208,14 @@ class ProcessResultData:
|
|
|
if not result:
|
|
|
return None
|
|
|
data = ProcessResultData(
|
|
|
- url=result["url"],
|
|
|
no=result["no"],
|
|
|
- other_urls=result["other_urls"],
|
|
|
+ url=result["url"],
|
|
|
attach_path=result["attach_path"],
|
|
|
+ other_urls=result["other_urls"],
|
|
|
)
|
|
|
return data
|
|
|
|
|
|
- _not_send_query = "SELECT no, title, url, keyword, date, price, bidder, summary, attach_path, status, create_time, send_time FROM t_data_result WHERE status = 0"
|
|
|
+ _not_send_query = "SELECT no, title, url, keyword, date, provice, city, instruments, summary, attach_path, status, create_time, send_time FROM t_data_result WHERE status = 0"
|
|
|
|
|
|
def fetch_not_send(self):
|
|
|
with MySQLHelper() as db_helper:
|
|
@@ -185,7 +239,9 @@ class ProcessResultData:
|
|
|
params = (other_urls, url)
|
|
|
db_helper.execute_non_query(self._update_other_urls_query, params)
|
|
|
|
|
|
- _query_report = "select * from t_data_result where create_time between %s and %s"
|
|
|
+ _query_report = (
|
|
|
+ "select * from t_data_result where create_time between %s and %s ORDER BY date"
|
|
|
+ )
|
|
|
|
|
|
def fetch_to_report_by_date(self, start_date, end_date):
|
|
|
"""
|