HandleSpeech.py
14.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# @Time : 2022/10/20 11:56
# @Author : 付孟奇
from util.HandleLog import logger
from util.HandleData import handle_data
from util.HandleDB import db_load
from config.VendorPath import *
import copy
import json
class SpeechLoad:
def __init__(self):
# 获取Excel信息源
self.data_excel = handle_data.load_excel(excel_path, '纸质入件')
self.dic_excel = handle_data.load_excel(excel_path, '字典映射')
self.result_desc = None # 话术变量拼接的extra
self.list_order = []
self.list_insurance = []
self.list_insures = []
self.list_agent = []
self.list_applicant = []
self.dic_key = []
self.case_num = None
self.del_excel()
# 处理纸质入件信息参数
def del_data_excel(self):
num_base = 0
for i in self.data_excel:
# 数据分类
if i['group_id'] == 0:
num_base += 1
elif i['group_id'] == 4:
self.list_order.append(i)
elif i['group_id'] == 5 and i['is_insured'] == 0:
self.list_insurance.append(i)
elif i['group_id'] == 5 and i['is_insured'] == 1:
self.list_insures.append(i)
elif i['group_id'] == 6:
self.list_agent.append(i)
elif i['group_id'] == 7:
self.list_applicant.append(i)
# 处理数据字典参数与话术变量参数一致
def del_excel(self):
for index in range(len(self.dic_excel)):
str_tag = str(self.dic_excel[index]['函数TAG']).split('Enums')[0]
new_tag = str_tag[0].lower() + str_tag[1:]
self.dic_key.append(new_tag)
self.dic_excel[index]['函数TAG'] = new_tag
self.dic_key = list(set(self.dic_key))
# 合成入参字符串
def getJsonString(self, arg_list):
result = '{'
for i in arg_list: # 处理每一行信息
i_v = i.get(self.case_num)
if i_v == '' or i_v is None:
i_v = 'test_' + i.get('name')
# elif i.get('name') in self.dic_key:
else:
i_v = self.getArgs(i.get('name'), i_v)
result += '''"{}":"{}",'''.format(i.get('name'), i_v)
result += '}'
return result.replace(',}', '}')
# 合成数据结构
def getJsonDesc(self, arg_list):
result = '{'
for i in arg_list: # 处理每一行信息
i_v = i.get(self.case_num)
if i_v == '' or i_v is None:
i_v = 'test_' + i.get('name')
else:
i_v = self.getArgs(i.get('name'), i_v)
result += '''"{}":"{}",'''.format(i.get('desc'), i_v)
result += '}'
return result.replace(',}', '}')
# 字典映射
def getArgs(self, arg_k, arg_v):
# 数据字典替换
result = ''
for i in self.dic_excel:
if i['函数TAG'] == 'applicantSex' and arg_k == 'gender' and int(i['dict_value']) == int(arg_v):
result = i['dict_label']
elif i['函数TAG'] == 'insuredRelation' and arg_k == 'relation' and i['dict_value'] == arg_v:
result = i['dict_label']
elif i['函数TAG'] == 'orderType' and arg_k == 'policyType' and i['dict_value'] == arg_v:
result = i['dict_label']
elif i['函数TAG'] == arg_k and i['dict_value'] == arg_v:
result = i['dict_label']
else: # 未找到替换数据
continue
if result == '':
return arg_v
else:
return result
# 组装订单请求信息
def getRestult(self, case_num):
self.case_num = case_num # 执行的case内容
self.del_data_excel() # 处理纸质入件数据源
insurance_json = ''
insurance_desc_json = ''
order_json = '''"order":''' + self.getJsonString(self.list_order) # 订单基本信息
order_desc_json = '''"订单基本信息":''' + self.getJsonDesc(self.list_order)
agent_json = '''"agent":''' + self.getJsonString(self.list_agent) # 销售人员信息
agent__desc_json = '''"销售人员信息":''' + self.getJsonDesc(self.list_agent)
applicant_json = '''"applicant":''' + self.getJsonString(self.list_applicant) # 投保人信息
applicant_desc_json = '''"投保人信息":''' + self.getJsonDesc(self.list_applicant)
# 处理被保人信息
list_people_1 = copy.deepcopy(self.list_insures)
list_people_2 = copy.deepcopy(self.list_insures)
for i in range(len(self.list_insures)):
i_list = self.list_insures[i][case_num].split(';')
if len(i_list) is 2:
list_people_1[i][case_num] = i_list[0]
list_people_2[i][case_num] = i_list[1]
elif len(i_list) is 1:
list_people_1[i][case_num] = i_list[0]
list_people_2[i][case_num] = ''
else:
list_people_1[i][case_num] = ''
list_people_2[i][case_num] = ''
# 处理投保基本信息
if self.case_num == 'test_case1': # 处理一主一附
logger.info('订单类型是一主一附')
list_product_1 = copy.deepcopy(self.list_insurance)
list_product_2 = copy.deepcopy(self.list_insurance)
for i in range(len(self.list_insurance)): # 拆分组装主险信息、附加险信息
i_list = self.list_insurance[i][case_num].split(';')
if len(i_list) is 2:
list_product_1[i][case_num] = i_list[0]
list_product_2[i][case_num] = i_list[1]
elif len(i_list) is 1:
list_product_1[i][case_num] = i_list[0]
list_product_2[i][case_num] = ''
else:
list_product_1[i][case_num] = ''
list_product_2[i][case_num] = ''
main_insurance_json = '''"mainInsurance":''' + self.getJsonString(list_product_1).replace('}', ',') + '''"insureds":[''' + self.getJsonString(list_people_1) + "]}"
main_insurance_desc_json = '''"投保基本信息1":''' + (self.getJsonDesc(list_product_1) + self.getJsonDesc(list_people_1)).replace('}{', ',')
additional_insurance_json = '''"additionalInsurances":[''' + self.getJsonString(list_product_2).replace('}', ',') + '''"insureds":[''' + self.getJsonString(list_people_2) + "]}]"
additional_insurance_desc_json = '''"投保基本信息2":''' + (self.getJsonDesc(list_product_2) + self.getJsonDesc(list_people_2)).replace('}{', ',')
insurance_json = '''"insurance":[{''' + main_insurance_json + "," + additional_insurance_json + "}]"
insurance_desc_json = main_insurance_desc_json + "," + additional_insurance_desc_json
elif self.case_num == 'test_case2': # 处理一主多附
logger.info('订单类型是一主多附')
list_product_1 = copy.deepcopy(self.list_insurance)
list_product_2 = copy.deepcopy(self.list_insurance)
list_product_3 = copy.deepcopy(self.list_insurance)
for i in range(len(self.list_insurance)): # 拆分组装主险信息、附加险信息
i_list = self.list_insurance[i][case_num].split(';')
if len(i_list) is 3:
list_product_1[i][case_num] = i_list[0]
list_product_2[i][case_num] = i_list[1]
list_product_3[i][case_num] = i_list[2]
elif len(i_list) is 2:
list_product_1[i][case_num] = i_list[0]
list_product_2[i][case_num] = i_list[1]
elif len(i_list) is 1:
list_product_1[i][case_num] = i_list[0]
list_product_2[i][case_num] = ''
else:
list_product_1[i][case_num] = ''
list_product_2[i][case_num] = ''
main_insurance_json = '''"mainInsurance":''' + self.getJsonString(list_product_1).replace('}', ',') + '''"insureds":[''' + self.getJsonString(list_people_1) + "]}"
add_1_json = self.getJsonString(list_product_2).replace('}', ',') + '''"insureds":[''' + self.getJsonString(list_people_2) + "]}"
add_2_json = self.getJsonString(list_product_3).replace('}', ',') + '''"insureds":[''' + self.getJsonString(list_people_2) + "]}"
additional_insurance_json = '''"additionalInsurances":[''' + add_1_json + ',' + add_2_json + "]"
insurance_json = '''"insurance":[{''' + main_insurance_json + "," + additional_insurance_json + "}]"
main_insurance_desc_json = '''"投保基本信息1":''' + (self.getJsonDesc(list_product_1) + self.getJsonDesc(list_people_1)).replace('}{', ',')
add_1_desc_json = '''"投保基本信息2":''' + (self.getJsonDesc(list_product_2) + self.getJsonDesc(list_people_2)).replace('}{', ',')
add_2_desc_json = '''"投保基本信息3":''' + (self.getJsonDesc(list_product_3) + self.getJsonDesc(list_people_2)).replace('}{', ',')
insurance_desc_json = main_insurance_desc_json + "," + add_1_desc_json + ',' + add_2_desc_json
elif self.case_num == 'test_case3': # 处理多主多附
logger.info('订单类型是多主多附')
list_product_1 = copy.deepcopy(self.list_insurance)
list_product_2 = copy.deepcopy(self.list_insurance)
list_product_3 = copy.deepcopy(self.list_insurance)
list_product_4 = copy.deepcopy(self.list_insurance)
for i in range(len(self.list_insurance)): # 拆分组装主险信息、附加险信息
i_list = self.list_insurance[i][case_num].split(';')
if len(i_list) is 4:
list_product_1[i][case_num] = i_list[0]
list_product_2[i][case_num] = i_list[1]
list_product_3[i][case_num] = i_list[2]
list_product_4[i][case_num] = i_list[3]
elif len(i_list) is 3:
list_product_1[i][case_num] = i_list[0]
list_product_2[i][case_num] = i_list[1]
list_product_3[i][case_num] = i_list[2]
elif len(i_list) is 2:
list_product_1[i][case_num] = i_list[0]
list_product_2[i][case_num] = i_list[1]
elif len(i_list) is 1:
list_product_1[i][case_num] = i_list[0]
list_product_2[i][case_num] = ''
else:
list_product_1[i][case_num] = ''
list_product_2[i][case_num] = ''
main_1_insurance_json = '''"mainInsurance":''' + self.getJsonString(list_product_1).replace('}', ',') + '''"insureds":[''' + self.getJsonString(list_people_1) + "]}"
main_2_insurance_json = '''"mainInsurance":''' + self.getJsonString(list_product_2).replace('}', ',') + '''"insureds":[''' + self.getJsonString(list_people_1) + "]}"
add_1_json = self.getJsonString(list_product_3).replace('}', ',') + '''"insureds":[''' + self.getJsonString(list_people_2) + "]}"
add_2_json = self.getJsonString(list_product_4).replace('}', ',') + '''"insureds":[''' + self.getJsonString(list_people_2) + "]}"
additional_insurance_json = '''"additionalInsurances":[''' + add_1_json + ',' + add_2_json + "]"
insurance_json = '''"insurance":[{''' + main_1_insurance_json + ',' + additional_insurance_json + '},{' + main_2_insurance_json + ',' + additional_insurance_json + '}]'
main_1_insurance_desc_json = '''"投保基本信息1":''' + (self.getJsonDesc(list_product_1) + self.getJsonDesc(list_people_1)).replace('}{', ',')
main_2_insurance_desc_json = '''"投保基本信息2":''' + (self.getJsonDesc(list_product_2) + self.getJsonDesc(list_people_1)).replace('}{', ',')
add_1_desc_json = '''"投保基本信息3":''' + (self.getJsonDesc(list_product_3) + self.getJsonDesc(list_people_2)).replace('}{', ',')
add_2_desc_json = '''"投保基本信息4":''' + (self.getJsonDesc(list_product_4) + self.getJsonDesc(list_people_2)).replace('}{', ',')
insurance_desc_json = main_1_insurance_desc_json + ',' + main_2_insurance_desc_json + ',' + add_1_desc_json + ',' + add_2_desc_json
result = "{" + order_json + "," + agent_json + "," + applicant_json + "," + insurance_json + "}"
self.result_desc = "{" + order_desc_json + "," + agent__desc_json + "," + applicant_desc_json + "," + insurance_desc_json + "}"
logger.info("话术变量参数自动生成成功!")
logger.info("订单数据结构为" + str(self.result_desc))
return result
def getAssert(self, orderRecordId):
# 研发代码生成的extra_info信息
res_extra = db_load.select_db(('''SELECT extra_info FROM order_base_info WHERE id={};''').format(orderRecordId))
auto_dic = {}
extra_dic = {}
for k, v in json.loads(self.result_desc).items():
for k_, v_ in v.items():
auto_dic[(k + '/' + k_)] = v_
for m, n in json.loads(res_extra[0]['extra_info']).items():
for m_, n_ in n.items():
extra_dic[m + '/' + m_] = n_
error_list = []
lack_list = []
res_msg = None
for i in extra_dic:
if i in auto_dic:
if extra_dic[i] == auto_dic[i]:
res_msg = {'code': 0, 'msg': '数据处理成功'}
else:
error_list.append(i)
else:
lack_list.append(i)
if len(lack_list) != 0 and len(error_list) != 0:
res_msg = {'code': 1, 'msg': [{'数据生成异常,下列数据不存在,请核对话术变量表': str(lack_list)}, {'数据生成错误,下列数据值与原始值不符合': str(error_list)}]}
elif len(lack_list) != 0:
res_msg = {'code': 1, 'msg': '数据生成异常,下列数据不存在,请核对话术变量表:' + str(lack_list)}
elif len(error_list) != 0:
res_msg = {'code': 1, 'msg': '数据生成错误,下列数据值与原始值不符合:' + str(error_list)}
return res_msg
handle_speech = SpeechLoad()
if __name__ == '__main__':
handle_speech.getRestult(case_num='test_case1')
# handle_speech.getArgs()