83c49cee by 冯轩

Merge branch 'feature/CHINARPA-5131-5234'

2 parents c06bbf34 35dc3f45
......@@ -5,5 +5,7 @@ from . import views
urlpatterns = [
path(r'', views.DocView.as_view()),
path(r'query/employee', views.EmployeeView.as_view()),
path(r'query/greenBookHistoryFile', views.SearchGBHistoryFileView.as_view()),
path(r'download/greenBookHistoryFile', views.DownloadGBHistoryFileView.as_view()),
path(r'contract/v1', views.SEContractView.as_view()),
]
......
......@@ -1131,3 +1131,45 @@ class DealerMapping(models.Model):
class Meta:
managed = False
db_table = 'dealer_mapping'
class HILGreenBookHistoryFile(models.Model):
id = models.AutoField(primary_key=True, verbose_name="id") # 主键
object_id = models.CharField(max_length=64, verbose_name="文件唯一ID")
object_name = models.CharField(max_length=255, verbose_name="文件名称")
application_no = models.CharField(max_length=64, verbose_name="申请号")
object_type = models.CharField(max_length=64, verbose_name="文件类型")
customer_name = models.CharField(max_length=64, verbose_name="customer_name")
content_size = models.CharField(max_length=64, verbose_name="文件大小")
owner_name = models.CharField(max_length=64, verbose_name="owner_name")
input_date = models.DateTimeField(verbose_name="上传时间")
modify_date = models.DateTimeField(verbose_name="修改时间")
location = models.CharField(max_length=255, verbose_name="文件位置")
download_finish = models.SmallIntegerField(null=False, default=0, verbose_name="是否下载完成")
update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间')
create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
class Meta:
managed = False
db_table = 'hil_gb_history_file'
class AFCGreenBookHistoryFile(models.Model):
id = models.AutoField(primary_key=True, verbose_name="id") # 主键
object_id = models.CharField(max_length=64, verbose_name="文件唯一ID")
object_name = models.CharField(max_length=255, verbose_name="文件名称")
application_no = models.CharField(max_length=64, verbose_name="申请号")
object_type = models.CharField(max_length=64, verbose_name="文件类型")
customer_name = models.CharField(max_length=64, verbose_name="customer_name")
content_size = models.CharField(max_length=64, verbose_name="文件大小")
owner_name = models.CharField(max_length=64, verbose_name="owner_name")
input_date = models.DateTimeField(verbose_name="上传时间")
modify_date = models.DateTimeField(verbose_name="修改时间")
location = models.CharField(max_length=255, verbose_name="文件位置")
download_finish = models.BooleanField(default=True, verbose_name="是否下载完成")
update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间')
create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
class Meta:
managed = False
db_table = 'afc_gb_history_file'
situ_db_label = 'afc'
......
......@@ -163,3 +163,21 @@ class ECM(GenericView):
response.status_code, response.headers, response.text))
if 'ns12:createResponse' not in response.json().get('S:Envelope', {}).get('S:Body', {}):
raise ECMException('ECM upload failed: {0} , with headers: {1}'.format(response.json(), response.headers))
def search_doc_info_list(self, filePath, business_type):
args = {
#userName n大写,和其他接口不一样,是因为apigateway没有做统一
"userName": self.username,
"password": self.pwd,
"docbase": self.doc_base_map.get(business_type),
"documentType": "green_book",
"dql":"select r_object_id, object_name,b_application_no, r_object_type,b_customer_name,r_content_size, owner_name, b_input_date, r_modify_date, b_location from green_book where b_location = '{}'" .format(filePath),
}
header_info = self.get_headers()
self.running_log.info("{0} search header_info:{1}".format(self.log_base, header_info))
self.running_log.info("{0} search args_info:{1}".format(self.log_base, args))
response = requests.post(self.search_url, headers=header_info, json=args, verify=False)
if response.status_code != 200:
raise ECMException('ECM search failed with code: {0}'.format(response.status_code))
#self.running_log.info("{0} search response.json():{1}".format(self.log_base, response.json()))
return response.json()
\ No newline at end of file
......
......@@ -53,7 +53,9 @@ from .models import (
AFCOCRResult,
AFCSEOCRResult,
HILCmsStatusInfo,
AFCCmsStatusInfo
AFCCmsStatusInfo,
HILGreenBookHistoryFile,
AFCGreenBookHistoryFile
)
from .named_enum import ErrorType, AutoResult, WholeResult, RPAResult, SystemName, RequestTeam
from .mixins import DocHandler, MPOSHandler, PreSEHandler
......@@ -61,7 +63,7 @@ from . import consts
from apps.account.authentication import OAuth2AuthenticationWithUser
from celery_compare.tasks import compare, fsm_compare
from prese.compare import get_empty_result
from apps.doc.ocr.ecm import ECM
import time
......@@ -95,6 +97,18 @@ employee_args = {
'business_type': fields.Str(required=True, validate=validate.Length(max=64)),
}
q_gb_file_args = {
'file_path': fields.Str(required=True, validate=validate.Length(max=255)),
'business_type': fields.Str(required=True, validate=validate.Length(max=64)),
}
d_gb_file_args = {
'object_id': fields.Str(required=True, validate=validate.Length(max=64)),
'save_path': fields.Str(required=True, validate=validate.Length(max=255)),
'business_type': fields.Str(required=True, validate=validate.Length(max=64)),
}
go_args = {
'image': fields.Raw(required=True),
}
......@@ -1877,3 +1891,67 @@ class EmployeeView(GenericView):
if income_keywords is not None and len(income_keywords) > 0:
return response.ok(data=True)
return response.ok(data=False)
class SearchGBHistoryFileView(GenericView):
permission_classes = [IsAuthenticated]
authentication_classes = [OAuth2AuthenticationWithUser]
@use_args(q_gb_file_args, location='data')
def post(self, request, args):
file_path = args.get('file_path')
business_type = args.get('business_type')
gb_history_file_class = HILGreenBookHistoryFile if business_type in consts.HIL_SET else AFCGreenBookHistoryFile
ecm = ECM()
response_json = ecm.search_doc_info_list(file_path, business_type)
try:
data_objects = response_json['Envelope']['Body']['executeResponse']['return']['dataPackage']['DataObjects']
except Exception as e:
self.exception_log.exception('[SearchGBHistoryFileView] [response_json parse failed] [response_json={0}] [error={1}]'.format(response_json, traceback.format_exc()))
return response.ok(data=False)
self.running_log.info('[SearchGBHistoryFileView] [data_objects size={0}] '.format(len(data_objects)))
for data_object in data_objects:
object_id = data_object['Identity']['ObjectId']['@id']
properties_dict = {}
properties = data_object['Properties']['Properties']
for prop in properties:
name = prop['@name']
value = prop.get('Value', 'null') # 如果Value为空,则输出null
properties_dict[name] = value
self.running_log.info('[SearchGBHistoryFileView] [properties_dict={0}] '.format(properties_dict))
try:
gb_history_file_class.objects.create(
object_id=object_id,
object_name=properties_dict.get('object_name', ''),
application_no=properties_dict.get('b_application_no', ''),
object_type='green_book',
customer_name=properties_dict.get('b_customer_name', ''),
content_size=properties_dict.get('r_content_size', ''),
owner_name=properties_dict.get('owner_name', ''),
#input_date=properties_dict.get('b_input_date', ''),
#modify_date=properties_dict.get('r_modify_date', ''),
location=properties_dict.get('b_location', ''),
download_finish=False
)
except Exception as e:
self.exception_log.exception('[SearchGBHistoryFileView] [db save failed] [error={0}]'.format(traceback.format_exc()))
return response.ok(data=True)
class DownloadGBHistoryFileView(GenericView):
# permission_classes = [IsAuthenticated]
# authentication_classes = [OAuth2AuthenticationWithUser]
@use_args(d_gb_file_args, location='data')
def post(self, request, args):
try:
business_type = args.get('business_type')
object_id = args.get('object_id')
save_path = args.get('save_path')
ecm = ECM()
ecm.download(save_path, object_id, 'green_book', business_type)
self.running_log.info('[DownloadGBHistoryFileView] [args={0}] '.format(args))
return response.ok(data=True)
except Exception as e:
return response.ok(data=False)
\ No newline at end of file
......
import pyodbc
hil_sql = """
CREATE TABLE [dbo].[hil_gb_history_file] (
[id] int IDENTITY(1,1) NOT NULL,
[object_id] varchar(64) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[object_name] varchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[application_no] varchar(64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[object_type] varchar(64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[customer_name] varchar(64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[content_size] varchar(64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[owner_name] varchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[input_date] datetime NULL,
[modify_date] datetime NULL,
[location] varchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[download_finish] int NOT NULL,
[update_time] datetime NULL,
[create_time] datetime NULL
)
GO;
alter table hil_gb_history_file ADD CONSTRAINT unique_object_id unique(object_id)
"""
afc_sql = """
CREATE TABLE [dbo].[afc_gb_history_file] (
[id] int IDENTITY(1,1) NOT NULL,
[object_id] varchar(64) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[object_name] varchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[application_no] varchar(64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[object_type] varchar(64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[customer_name] varchar(64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[content_size] varchar(64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[owner_name] varchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[input_date] datetime NULL,
[modify_date] datetime NULL,
[location] varchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[download_finish] int NOT NULL,
[update_time] datetime NULL,
[create_time] datetime NULL
)
GO;
alter table afc_gb_history_file ADD CONSTRAINT unique_object_id unique(object_id)
"""
hil_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True)
hil_cursor = hil_cnxn.cursor()
hil_cursor.execute(hil_sql)
hil_cursor.close()
hil_cnxn.close()
afc_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True)
afc_cursor = afc_cnxn.cursor()
afc_cursor.execute(afc_sql)
afc_cursor.close()
afc_cnxn.close()
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!