Commit b85484cd authored by pengxiong's avatar pengxiong

报告列表视图

parent dc7dcac2
...@@ -142,26 +142,7 @@ class HoldDiagnoseReport(Base, BaseModel): ...@@ -142,26 +142,7 @@ class HoldDiagnoseReport(Base, BaseModel):
if self.file: if self.file:
file = pdf_folder + self.file file = pdf_folder + self.file
data = {c: int(getattr(self, c).timestamp()) if isinstance(getattr(self, c), datetime.datetime) else getattr(self, c) for c in allow_field} data = {c: int(getattr(self, c).timestamp()) if isinstance(getattr(self, c), datetime.datetime) else getattr(self, c) for c in allow_field}
with TAMP_SQL(tamp_user_engine) as tamp_user, TAMP_SQL(tamp_diagnose_app_engine) as tamp_diagnose_app:
tamp_user_session = tamp_user.session
tamp_diagnose_app_session = tamp_diagnose_app.session
sql = "select ui_username_mp from user_info where id = '{}'".format(self.ifa_id)
res = tamp_user_session.execute(sql)
sql2 = "select customer_name from tamp_diagnose_app.customer_view where id = '{}'".format(self.customer_id)
res2 = tamp_diagnose_app_session.execute(sql2)
res = res.fetchone()
res2 = res2.fetchone()
if data:
data['file'] = file data['file'] = file
if res:
data['author_name'] = res[0]
else:
data['author_name'] = ''
if res2:
data['customer_name'] = res2[0]
else:
data['customer_name'] = ''
data['type'] = 2
return data return data
...@@ -188,26 +169,7 @@ class HoldReport(Base, BaseModel): ...@@ -188,26 +169,7 @@ class HoldReport(Base, BaseModel):
if self.file: if self.file:
file = pdf_folder + self.file file = pdf_folder + self.file
data = {c: int(getattr(self, c).timestamp()) if isinstance(getattr(self, c), datetime.datetime) else getattr(self, c) for c in allow_field} data = {c: int(getattr(self, c).timestamp()) if isinstance(getattr(self, c), datetime.datetime) else getattr(self, c) for c in allow_field}
with TAMP_SQL(tamp_user_engine) as tamp_user, TAMP_SQL(tamp_diagnose_app_engine) as tamp_diagnose_app:
tamp_user_session = tamp_user.session
tamp_diagnose_app_session = tamp_diagnose_app.session
sql = "select ui_username_mp from user_info where id = '{}'".format(self.ifa_id)
res = tamp_user_session.execute(sql)
sql2 = "select customer_name from tamp_diagnose_app.customer_view where id = '{}'".format(self.customer_id)
res2 = tamp_diagnose_app_session.execute(sql2)
res = res.fetchone()
res2 = res2.fetchone()
if data:
data['file'] = file data['file'] = file
if res:
data['author_name'] = res[0]
else:
data['author_name'] = ''
if res2:
data['customer_name'] = res2[0]
else:
data['customer_name'] = ''
data['type'] = 1
return data return data
...@@ -234,29 +196,41 @@ class PeriodicReport(Base, BaseModel): ...@@ -234,29 +196,41 @@ class PeriodicReport(Base, BaseModel):
if self.file: if self.file:
file = pdf_folder + self.file file = pdf_folder + self.file
data = {c: int(getattr(self, c).timestamp()) if isinstance(getattr(self, c), datetime.datetime) else getattr(self, c) for c in allow_field} data = {c: int(getattr(self, c).timestamp()) if isinstance(getattr(self, c), datetime.datetime) else getattr(self, c) for c in allow_field}
with TAMP_SQL(tamp_user_engine) as tamp_user, TAMP_SQL(tamp_diagnose_app_engine) as tamp_diagnose_app:
tamp_user_session = tamp_user.session
tamp_diagnose_app_session = tamp_diagnose_app.session
sql = "select ui_username_mp from user_info where id = '{}'".format(self.ifa_id)
res = tamp_user_session.execute(sql)
sql2 = "select customer_name from tamp_diagnose_app.customer_view where id = '{}'".format(self.customer_id)
res2 = tamp_diagnose_app_session.execute(sql2)
res = res.fetchone()
res2 = res2.fetchone()
if data:
data['file'] = file data['file'] = file
if res: return data
data['author_name'] = res[0]
else:
data['author_name'] = '' class ReportView(Base, BaseModel):
if res2: __tablename__ = 'report_view'
data['customer_name'] = res2[0]
id = Column(INTEGER(11), primary_key=True)
customer_id = Column(String(64))
ifa_id = Column(String(64))
update_time = Column(DateTime)
update_status = Column(INTEGER(11))
file = Column(String(128))
be_viewed = Column(INTEGER(2), comment='0未查看1已查看')
report_data = Column(Text)
name = Column(String(100))
customer_name = Column(String(100))
author_name = Column(String(100))
type = Column(INTEGER(2))
def to_dict(self, allow_field=None):
all_field = [r.name for r in self.__table__.columns]
if allow_field:
allow_field = set(allow_field) & set(allow_field)
else: else:
data['customer_name'] = '' allow_field = all_field
data['type'] = 3 file = ''
if self.file:
file = pdf_folder + self.file
data = {c: int(getattr(self, c).timestamp()) if isinstance(getattr(self, c), datetime.datetime) else getattr(self, c) for c in allow_field}
data['file'] = file
return data return data
class IfaCustomer(Base, BaseModel): class IfaCustomer(Base, BaseModel):
__tablename__ = 'ifa_customer' __tablename__ = 'ifa_customer'
......
...@@ -11,11 +11,11 @@ import json ...@@ -11,11 +11,11 @@ import json
import os import os
import uuid import uuid
from sqlalchemy import and_ from sqlalchemy import and_, or_
# from sqlalchemy import union_all # from sqlalchemy import union_all
from app.api.engine import TAMP_SQL, tamp_diagnose_app_engine, template_folder, temp_img_save_folder from app.api.engine import TAMP_SQL, tamp_diagnose_app_engine, template_folder, temp_img_save_folder
from app.model.tamp_diagnose_app import HoldReport, HoldDiagnoseReport, PeriodicReport from app.model.tamp_diagnose_app import HoldReport, HoldDiagnoseReport, PeriodicReport, Customer, ReportView
from app.utils.jinjia2html_v2 import DataIntegrate from app.utils.jinjia2html_v2 import DataIntegrate
...@@ -23,61 +23,56 @@ def get_report_list(args): ...@@ -23,61 +23,56 @@ def get_report_list(args):
""".""" """."""
type = args.get('type') type = args.get('type')
ifa_id = args.get('ifa_id') ifa_id = args.get('ifa_id')
name = args.get('name')
pageNumber = args['pageNumber'] pageNumber = args['pageNumber']
pageSize = args['pageSize'] pageSize = args['pageSize']
start_time = args.get('start_time') start_time = args.get('start_time')
end_time = args.get('end_time') end_time = args.get('end_time')
offset = (pageNumber - 1) * pageSize offset = (pageNumber - 1) * pageSize
res = [] res = []
allow_field = ['id', 'customer_id', 'ifa_id', 'update_time', 'update_status', 'file', 'be_viewed', 'name'] conditions = ()
with TAMP_SQL(tamp_diagnose_app_engine) as tamp_diagnose_app: if type == 0:
tamp_diagnose_session = tamp_diagnose_app.session conditions = [
hold_report = tamp_diagnose_session.query(HoldReport).filter(and_( and_(
HoldReport.ifa_id == ifa_id, ReportView.ifa_id == ifa_id,
HoldReport.update_time >= start_time, ReportView.name.like('%' + name + '%'),
ReportView.update_time >= start_time,
HoldReport.update_time <= end_time HoldReport.update_time <= end_time
)) ),
hold_diagnose_report = tamp_diagnose_session.query(HoldDiagnoseReport).filter(and_( and_(
HoldDiagnoseReport.ifa_id == ifa_id, ReportView.ifa_id == ifa_id,
HoldDiagnoseReport.update_time >= start_time, ReportView.customer_name.like('%' + name + '%'),
HoldDiagnoseReport.update_time <= end_time ReportView.update_time >= start_time,
)) HoldReport.update_time <= end_time
periodic_report = tamp_diagnose_session.query(PeriodicReport).filter(and_( )
PeriodicReport.ifa_id == ifa_id, ]
PeriodicReport.update_time >= start_time,
PeriodicReport.update_time <= end_time
))
if hold_report.all():
hold_report = [r.to_dict(allow_field=allow_field) for r in hold_report]
else:
hold_report = []
if hold_diagnose_report.all():
hold_diagnose_report = [r.to_dict(allow_field=allow_field) for r in hold_diagnose_report]
else:
hold_diagnose_report = []
if periodic_report.all():
periodic_report = [r.to_dict(allow_field=allow_field) for r in periodic_report]
else: else:
periodic_report = [] conditions = [
if type == 0: and_(
# res = hold_report.union_all(hold_diagnose_report).union_all(periodic_report) ReportView.ifa_id == ifa_id,
res.extend(hold_report) ReportView.type == type,
res.extend(hold_diagnose_report) ReportView.name.like('%' + name + '%'),
res.extend(periodic_report) ReportView.update_time >= start_time,
elif type == 1: HoldReport.update_time <= end_time
res = hold_report ),
elif type == 2: and_(
res = hold_diagnose_report ReportView.ifa_id == ifa_id,
elif type == 3: ReportView.type == type,
res = periodic_report ReportView.customer_name.like('%' + name + '%'),
# totalSize = res.count() ReportView.update_time >= start_time,
# data = res.offset(offset).limit(pageSize) HoldReport.update_time <= end_time
# if data: )
# data = [r.to_dict(allow_field=allow_field) for r in data] ]
totalSize = len(res) allow_field = ['id', 'customer_id', 'ifa_id', 'update_time', 'update_status', 'file', 'be_viewed', 'name', 'customer_name', 'author_name', 'type']
data = res[offset:offset+pageSize] with TAMP_SQL(tamp_diagnose_app_engine) as tamp_diagnose_app:
tamp_diagnose_session = tamp_diagnose_app.session
report_res = tamp_diagnose_session.query(ReportView).filter(or_(
*conditions
)).offset(offset).limit(pageSize)
res = [r.to_dict(allow_field=allow_field) for r in report_res]
totalSize = res.count()
return { return {
'content': data, 'content': res,
'pageNum': pageNumber, 'pageNum': pageNumber,
'pageSize': pageSize, 'pageSize': pageSize,
'totalSize': totalSize 'totalSize': totalSize
...@@ -116,26 +111,11 @@ def get_one_report(args): ...@@ -116,26 +111,11 @@ def get_one_report(args):
res = [] res = []
with TAMP_SQL(tamp_diagnose_app_engine) as tamp_diagnose_app: with TAMP_SQL(tamp_diagnose_app_engine) as tamp_diagnose_app:
tamp_diagnose_session = tamp_diagnose_app.session tamp_diagnose_session = tamp_diagnose_app.session
hold_report = tamp_diagnose_session.query(HoldReport).filter(and_( res = tamp_diagnose_session.query(ReportView).filter(and_(
HoldReport.id == id, ReportView.id == id,
ReportView.type == type,
HoldReport.ifa_id == ifa_id, HoldReport.ifa_id == ifa_id,
)) ))
hold_diagnose_report = tamp_diagnose_session.query(HoldDiagnoseReport).filter(and_(
HoldDiagnoseReport.id == id,
HoldDiagnoseReport.ifa_id == ifa_id,
))
periodic_report = tamp_diagnose_session.query(PeriodicReport).filter(and_(
PeriodicReport.id == id,
PeriodicReport.ifa_id == ifa_id,
))
if type == 0:
res = hold_report.union_all(hold_diagnose_report).union_all(periodic_report)
elif type == 1:
res = hold_report
elif type == 2:
res = hold_diagnose_report
elif type == 3:
res = periodic_report
data = [r.to_dict() for r in res] data = [r.to_dict() for r in res]
if data: if data:
return data[0] return data[0]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment