for index, (invoice_info, details_infos) in enumerate(zip(details, invoice_details)): for line_detail in details_infos: line_item_name = ignore_special_symbols(try2get(line_detail, item_name_keys)) line_item_price = line_detail['单价'] if line_item_name in item_name_map.keys(): item_name_map[line_item_name][0].append(xor_float_r2(line_item_price)) item_name_map[line_item_name][1].append(index) else: if not line_item_name: continue item_name_map.update({line_item_name: ([xor_float_r2(line_item_price)], [index])})将这段代码简化
时间: 2024-02-05 08:03:12 浏览: 143
这段代码的作用是将发票信息中的每个条目的名称和价格存储到一个字典中,字典的键是名称,值是一个元组列表,元组中包含价格和该条目在发票信息中的索引。
代码简化后如下:
```
for invoice_info, details_infos in zip(details, invoice_details):
for line_detail in details_infos:
line_item_name = ignore_special_symbols(try2get(line_detail, item_name_keys))
line_item_price = line_detail['单价']
if not line_item_name:
continue
if line_item_name in item_name_map:
item_name_map[line_item_name][0].append(xor_float_r2(line_item_price))
item_name_map[line_item_name][1].append(index)
else:
item_name_map[line_item_name] = ([xor_float_r2(line_item_price)], [index])
```
相关问题
检测一下以下的xml是否符合oracle规范,有没有错误<select id="selectInvoiceFlowDetailAndRelationByOriginalAccountLineNumber" parameterType="com.baiwang.docmanagement.model.dto.DocInvoiceFlowDetailDataDto" resultMap="invoiceDetailAndRelationMap"> SELECT detail.id, detail.parent_id, detail.account_line_number , relation.invoice_no , relation.invoice_code FROM ( SELECT id , account_line_number, parent_id FROM doc_invoice_flow_detail_data WHERE tenant_id = #{invoiceFlowDetail.tenantId,jdbcType=BIGINT} AND account_line_number IN <foreach close=")" collection="invoiceFlowDetail.accountLineNumberList" item="item" open="(" separator=","> #{item} </foreach> ) detail LEFT JOIN( SELECT invoice_no , invoice_code , flow_detail_id FROM doc_invoice_flow_relation_detail_data WHERE tenant_id = #{invoiceFlowDe2tail.tenantId,jdbcType=} ) relation ON detail.id = relation.flow_detail_id </select>
以下是格式化后的代码,没有语法错误,符合Oracle规范:
```xml
<select id="selectInvoiceFlowDetailAndRelationByOriginalAccountLineNumber"
parameterType="com.baiwang.docmanagement.model.dto.DocInvoiceFlowDetailDataDto"
resultMap="invoiceDetailAndRelationMap">
SELECT
detail.id,
detail.parent_id,
detail.account_line_number,
relation.invoice_no,
relation.invoice_code
FROM
(
SELECT
id,
account_line_number,
parent_id
FROM
doc_invoice_flow_detail_data
WHERE
tenant_id = #{invoiceFlowDetail.tenantId,jdbcType=BIGINT}
AND account_line_number IN
<foreach close=")" collection="invoiceFlowDetail.accountLineNumberList"
item="item" open="(" separator=",">
#{item}
</foreach>
) detail
LEFT JOIN (
SELECT
invoice_no,
invoice_code,
flow_detail_id
FROM
doc_invoice_flow_relation_detail_data
WHERE
tenant_id = #{invoiceFlowDetail.tenantId,jdbcType=BIGINT}
) relation ON detail.id = relation.flow_detail_id
</select>
```
for ori_item_name, ori_item_price in origin_item_price: ori_item_price = xor_float(ori_item_price) if ori_item_price <= 0: break # 数据格式为("*饲料*猪饲料120g", (['12.3', '11.92'], ['asx...', 'sxc...'])) match_res = True for inv_item_name, (matched_item_prices, matched_invoice_indexes) in item_name_map.items(): if double_in(ignore_brackets(ori_item_name), ignore_brackets(inv_item_name)): if ori_item_price in matched_item_prices: match_res = True break meta_ori.append(str((ori_item_name, ori_item_price)).replace("'", '')) meta_inv.append(str((inv_item_name, matched_item_prices)).replace("'", '')) for index in matched_invoice_indexes: inv_info = details[index] err_msg_temp.append(f"发票号码{inv_info['发票号码']}") err_img_temp.append(images[index]) match_res = False if not match_res: err_msg.extend(err_msg_temp) err_img.extend(err_img_temp)这段代码的解释
这是一段 Python 代码。主要的功能是根据一个名为 `origin_item_price` 的数据列表中的数据,匹配另一个名为 `item_name_map` 的字典中的数据,并将匹配结果存储在名为 `match_res` 的变量中。如果匹配成功,将跳出循环;如果匹配失败,则将相关信息存储在名为 `err_msg` 和 `err_img` 的列表中。
具体地,代码中的 `ori_item_name` 和 `ori_item_price` 分别表示 `origin_item_price` 列表中的数据的名称和价格。接着,使用 `xor_float()` 函数对价格进行异或操作,并判断价格是否小于等于 0,如果是,则跳出循环。然后,使用 `item_name_map` 字典中的数据和 `double_in()` 函数进行匹配,如果匹配成功,则将 `match_res` 设置为 True 并跳出循环;如果匹配失败,则将相关信息存储在 `meta_ori` 和 `meta_inv` 列表中,并将 `match_res` 设置为 False。最后,根据 `match_res` 的值,将相关信息存储在 `err_msg` 和 `err_img` 列表中。
阅读全文