Merge branch 'feature/CHINARPA-5131-5234'
Showing
5 changed files
with
207 additions
and
4 deletions
... | @@ -5,5 +5,7 @@ from . import views | ... | @@ -5,5 +5,7 @@ from . import views |
5 | urlpatterns = [ | 5 | urlpatterns = [ |
6 | path(r'', views.DocView.as_view()), | 6 | path(r'', views.DocView.as_view()), |
7 | path(r'query/employee', views.EmployeeView.as_view()), | 7 | path(r'query/employee', views.EmployeeView.as_view()), |
8 | path(r'query/greenBookHistoryFile', views.SearchGBHistoryFileView.as_view()), | ||
9 | path(r'download/greenBookHistoryFile', views.DownloadGBHistoryFileView.as_view()), | ||
8 | path(r'contract/v1', views.SEContractView.as_view()), | 10 | path(r'contract/v1', views.SEContractView.as_view()), |
9 | ] | 11 | ] | ... | ... |
... | @@ -1130,4 +1130,46 @@ class DealerMapping(models.Model): | ... | @@ -1130,4 +1130,46 @@ class DealerMapping(models.Model): |
1130 | 1130 | ||
1131 | class Meta: | 1131 | class Meta: |
1132 | managed = False | 1132 | managed = False |
1133 | db_table = 'dealer_mapping' | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1133 | db_table = 'dealer_mapping' | ||
1134 | |||
1135 | class HILGreenBookHistoryFile(models.Model): | ||
1136 | id = models.AutoField(primary_key=True, verbose_name="id") # 主键 | ||
1137 | object_id = models.CharField(max_length=64, verbose_name="文件唯一ID") | ||
1138 | object_name = models.CharField(max_length=255, verbose_name="文件名称") | ||
1139 | application_no = models.CharField(max_length=64, verbose_name="申请号") | ||
1140 | object_type = models.CharField(max_length=64, verbose_name="文件类型") | ||
1141 | customer_name = models.CharField(max_length=64, verbose_name="customer_name") | ||
1142 | content_size = models.CharField(max_length=64, verbose_name="文件大小") | ||
1143 | owner_name = models.CharField(max_length=64, verbose_name="owner_name") | ||
1144 | input_date = models.DateTimeField(verbose_name="上传时间") | ||
1145 | modify_date = models.DateTimeField(verbose_name="修改时间") | ||
1146 | location = models.CharField(max_length=255, verbose_name="文件位置") | ||
1147 | download_finish = models.SmallIntegerField(null=False, default=0, verbose_name="是否下载完成") | ||
1148 | update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间') | ||
1149 | create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间') | ||
1150 | |||
1151 | class Meta: | ||
1152 | managed = False | ||
1153 | db_table = 'hil_gb_history_file' | ||
1154 | |||
1155 | |||
1156 | class AFCGreenBookHistoryFile(models.Model): | ||
1157 | id = models.AutoField(primary_key=True, verbose_name="id") # 主键 | ||
1158 | object_id = models.CharField(max_length=64, verbose_name="文件唯一ID") | ||
1159 | object_name = models.CharField(max_length=255, verbose_name="文件名称") | ||
1160 | application_no = models.CharField(max_length=64, verbose_name="申请号") | ||
1161 | object_type = models.CharField(max_length=64, verbose_name="文件类型") | ||
1162 | customer_name = models.CharField(max_length=64, verbose_name="customer_name") | ||
1163 | content_size = models.CharField(max_length=64, verbose_name="文件大小") | ||
1164 | owner_name = models.CharField(max_length=64, verbose_name="owner_name") | ||
1165 | input_date = models.DateTimeField(verbose_name="上传时间") | ||
1166 | modify_date = models.DateTimeField(verbose_name="修改时间") | ||
1167 | location = models.CharField(max_length=255, verbose_name="文件位置") | ||
1168 | download_finish = models.BooleanField(default=True, verbose_name="是否下载完成") | ||
1169 | update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间') | ||
1170 | create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间') | ||
1171 | |||
1172 | class Meta: | ||
1173 | managed = False | ||
1174 | db_table = 'afc_gb_history_file' | ||
1175 | situ_db_label = 'afc' | ... | ... |
... | @@ -163,3 +163,21 @@ class ECM(GenericView): | ... | @@ -163,3 +163,21 @@ class ECM(GenericView): |
163 | response.status_code, response.headers, response.text)) | 163 | response.status_code, response.headers, response.text)) |
164 | if 'ns12:createResponse' not in response.json().get('S:Envelope', {}).get('S:Body', {}): | 164 | if 'ns12:createResponse' not in response.json().get('S:Envelope', {}).get('S:Body', {}): |
165 | raise ECMException('ECM upload failed: {0} , with headers: {1}'.format(response.json(), response.headers)) | 165 | raise ECMException('ECM upload failed: {0} , with headers: {1}'.format(response.json(), response.headers)) |
166 | |||
167 | def search_doc_info_list(self, filePath, business_type): | ||
168 | args = { | ||
169 | #userName n大写,和其他接口不一样,是因为apigateway没有做统一 | ||
170 | "userName": self.username, | ||
171 | "password": self.pwd, | ||
172 | "docbase": self.doc_base_map.get(business_type), | ||
173 | "documentType": "green_book", | ||
174 | "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), | ||
175 | } | ||
176 | header_info = self.get_headers() | ||
177 | self.running_log.info("{0} search header_info:{1}".format(self.log_base, header_info)) | ||
178 | self.running_log.info("{0} search args_info:{1}".format(self.log_base, args)) | ||
179 | response = requests.post(self.search_url, headers=header_info, json=args, verify=False) | ||
180 | if response.status_code != 200: | ||
181 | raise ECMException('ECM search failed with code: {0}'.format(response.status_code)) | ||
182 | #self.running_log.info("{0} search response.json():{1}".format(self.log_base, response.json())) | ||
183 | return response.json() | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -53,7 +53,9 @@ from .models import ( | ... | @@ -53,7 +53,9 @@ from .models import ( |
53 | AFCOCRResult, | 53 | AFCOCRResult, |
54 | AFCSEOCRResult, | 54 | AFCSEOCRResult, |
55 | HILCmsStatusInfo, | 55 | HILCmsStatusInfo, |
56 | AFCCmsStatusInfo | 56 | AFCCmsStatusInfo, |
57 | HILGreenBookHistoryFile, | ||
58 | AFCGreenBookHistoryFile | ||
57 | ) | 59 | ) |
58 | from .named_enum import ErrorType, AutoResult, WholeResult, RPAResult, SystemName, RequestTeam | 60 | from .named_enum import ErrorType, AutoResult, WholeResult, RPAResult, SystemName, RequestTeam |
59 | from .mixins import DocHandler, MPOSHandler, PreSEHandler | 61 | from .mixins import DocHandler, MPOSHandler, PreSEHandler |
... | @@ -61,7 +63,7 @@ from . import consts | ... | @@ -61,7 +63,7 @@ from . import consts |
61 | from apps.account.authentication import OAuth2AuthenticationWithUser | 63 | from apps.account.authentication import OAuth2AuthenticationWithUser |
62 | from celery_compare.tasks import compare, fsm_compare | 64 | from celery_compare.tasks import compare, fsm_compare |
63 | from prese.compare import get_empty_result | 65 | from prese.compare import get_empty_result |
64 | 66 | from apps.doc.ocr.ecm import ECM | |
65 | import time | 67 | import time |
66 | 68 | ||
67 | 69 | ||
... | @@ -95,6 +97,18 @@ employee_args = { | ... | @@ -95,6 +97,18 @@ employee_args = { |
95 | 'business_type': fields.Str(required=True, validate=validate.Length(max=64)), | 97 | 'business_type': fields.Str(required=True, validate=validate.Length(max=64)), |
96 | } | 98 | } |
97 | 99 | ||
100 | q_gb_file_args = { | ||
101 | 'file_path': fields.Str(required=True, validate=validate.Length(max=255)), | ||
102 | 'business_type': fields.Str(required=True, validate=validate.Length(max=64)), | ||
103 | } | ||
104 | |||
105 | d_gb_file_args = { | ||
106 | 'object_id': fields.Str(required=True, validate=validate.Length(max=64)), | ||
107 | 'save_path': fields.Str(required=True, validate=validate.Length(max=255)), | ||
108 | 'business_type': fields.Str(required=True, validate=validate.Length(max=64)), | ||
109 | } | ||
110 | |||
111 | |||
98 | go_args = { | 112 | go_args = { |
99 | 'image': fields.Raw(required=True), | 113 | 'image': fields.Raw(required=True), |
100 | } | 114 | } |
... | @@ -1876,4 +1890,68 @@ class EmployeeView(GenericView): | ... | @@ -1876,4 +1890,68 @@ class EmployeeView(GenericView): |
1876 | self.running_log.info('[query Employee] [application_id={0}] [income_keywords={1}]'.format(application_id, income_keywords)) | 1890 | self.running_log.info('[query Employee] [application_id={0}] [income_keywords={1}]'.format(application_id, income_keywords)) |
1877 | if income_keywords is not None and len(income_keywords) > 0: | 1891 | if income_keywords is not None and len(income_keywords) > 0: |
1878 | return response.ok(data=True) | 1892 | return response.ok(data=True) |
1879 | return response.ok(data=False) | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1893 | return response.ok(data=False) | ||
1894 | |||
1895 | class SearchGBHistoryFileView(GenericView): | ||
1896 | permission_classes = [IsAuthenticated] | ||
1897 | authentication_classes = [OAuth2AuthenticationWithUser] | ||
1898 | |||
1899 | @use_args(q_gb_file_args, location='data') | ||
1900 | def post(self, request, args): | ||
1901 | |||
1902 | file_path = args.get('file_path') | ||
1903 | business_type = args.get('business_type') | ||
1904 | |||
1905 | gb_history_file_class = HILGreenBookHistoryFile if business_type in consts.HIL_SET else AFCGreenBookHistoryFile | ||
1906 | ecm = ECM() | ||
1907 | response_json = ecm.search_doc_info_list(file_path, business_type) | ||
1908 | try: | ||
1909 | data_objects = response_json['Envelope']['Body']['executeResponse']['return']['dataPackage']['DataObjects'] | ||
1910 | except Exception as e: | ||
1911 | self.exception_log.exception('[SearchGBHistoryFileView] [response_json parse failed] [response_json={0}] [error={1}]'.format(response_json, traceback.format_exc())) | ||
1912 | return response.ok(data=False) | ||
1913 | self.running_log.info('[SearchGBHistoryFileView] [data_objects size={0}] '.format(len(data_objects))) | ||
1914 | for data_object in data_objects: | ||
1915 | object_id = data_object['Identity']['ObjectId']['@id'] | ||
1916 | properties_dict = {} | ||
1917 | properties = data_object['Properties']['Properties'] | ||
1918 | for prop in properties: | ||
1919 | name = prop['@name'] | ||
1920 | value = prop.get('Value', 'null') # 如果Value为空,则输出null | ||
1921 | properties_dict[name] = value | ||
1922 | self.running_log.info('[SearchGBHistoryFileView] [properties_dict={0}] '.format(properties_dict)) | ||
1923 | |||
1924 | try: | ||
1925 | gb_history_file_class.objects.create( | ||
1926 | object_id=object_id, | ||
1927 | object_name=properties_dict.get('object_name', ''), | ||
1928 | application_no=properties_dict.get('b_application_no', ''), | ||
1929 | object_type='green_book', | ||
1930 | customer_name=properties_dict.get('b_customer_name', ''), | ||
1931 | content_size=properties_dict.get('r_content_size', ''), | ||
1932 | owner_name=properties_dict.get('owner_name', ''), | ||
1933 | #input_date=properties_dict.get('b_input_date', ''), | ||
1934 | #modify_date=properties_dict.get('r_modify_date', ''), | ||
1935 | location=properties_dict.get('b_location', ''), | ||
1936 | download_finish=False | ||
1937 | ) | ||
1938 | except Exception as e: | ||
1939 | self.exception_log.exception('[SearchGBHistoryFileView] [db save failed] [error={0}]'.format(traceback.format_exc())) | ||
1940 | return response.ok(data=True) | ||
1941 | |||
1942 | class DownloadGBHistoryFileView(GenericView): | ||
1943 | # permission_classes = [IsAuthenticated] | ||
1944 | # authentication_classes = [OAuth2AuthenticationWithUser] | ||
1945 | |||
1946 | @use_args(d_gb_file_args, location='data') | ||
1947 | def post(self, request, args): | ||
1948 | try: | ||
1949 | business_type = args.get('business_type') | ||
1950 | object_id = args.get('object_id') | ||
1951 | save_path = args.get('save_path') | ||
1952 | ecm = ECM() | ||
1953 | ecm.download(save_path, object_id, 'green_book', business_type) | ||
1954 | self.running_log.info('[DownloadGBHistoryFileView] [args={0}] '.format(args)) | ||
1955 | return response.ok(data=True) | ||
1956 | except Exception as e: | ||
1957 | return response.ok(data=False) | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
src/common/tools/mssql_script30.py
0 → 100644
1 | import pyodbc | ||
2 | |||
3 | hil_sql = """ | ||
4 | CREATE TABLE [dbo].[hil_gb_history_file] ( | ||
5 | [id] int IDENTITY(1,1) NOT NULL, | ||
6 | [object_id] varchar(64) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, | ||
7 | [object_name] varchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, | ||
8 | [application_no] varchar(64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, | ||
9 | [object_type] varchar(64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, | ||
10 | [customer_name] varchar(64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, | ||
11 | [content_size] varchar(64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, | ||
12 | [owner_name] varchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, | ||
13 | [input_date] datetime NULL, | ||
14 | [modify_date] datetime NULL, | ||
15 | [location] varchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, | ||
16 | [download_finish] int NOT NULL, | ||
17 | [update_time] datetime NULL, | ||
18 | [create_time] datetime NULL | ||
19 | ) | ||
20 | GO; | ||
21 | |||
22 | alter table hil_gb_history_file ADD CONSTRAINT unique_object_id unique(object_id) | ||
23 | |||
24 | """ | ||
25 | |||
26 | afc_sql = """ | ||
27 | CREATE TABLE [dbo].[afc_gb_history_file] ( | ||
28 | [id] int IDENTITY(1,1) NOT NULL, | ||
29 | [object_id] varchar(64) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, | ||
30 | [object_name] varchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, | ||
31 | [application_no] varchar(64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, | ||
32 | [object_type] varchar(64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, | ||
33 | [customer_name] varchar(64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, | ||
34 | [content_size] varchar(64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, | ||
35 | [owner_name] varchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, | ||
36 | [input_date] datetime NULL, | ||
37 | [modify_date] datetime NULL, | ||
38 | [location] varchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, | ||
39 | [download_finish] int NOT NULL, | ||
40 | [update_time] datetime NULL, | ||
41 | [create_time] datetime NULL | ||
42 | ) | ||
43 | GO; | ||
44 | |||
45 | alter table afc_gb_history_file ADD CONSTRAINT unique_object_id unique(object_id) | ||
46 | |||
47 | """ | ||
48 | |||
49 | hil_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True) | ||
50 | |||
51 | hil_cursor = hil_cnxn.cursor() | ||
52 | hil_cursor.execute(hil_sql) | ||
53 | |||
54 | hil_cursor.close() | ||
55 | hil_cnxn.close() | ||
56 | |||
57 | afc_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True) | ||
58 | |||
59 | afc_cursor = afc_cnxn.cursor() | ||
60 | afc_cursor.execute(afc_sql) | ||
61 | |||
62 | afc_cursor.close() | ||
63 | afc_cnxn.close() |
-
Please register or sign in to post a comment