first commit
This commit is contained in:
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 数据源本地存储已忽略文件
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
||||
4
.idea/misc.xml
generated
Normal file
4
.idea/misc.xml
generated
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/撤案程序.iml" filepath="$PROJECT_DIR$/.idea/撤案程序.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
8
.idea/撤案程序.iml
generated
Normal file
8
.idea/撤案程序.iml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
BIN
__pycache__/config.cpython-37.pyc
Normal file
BIN
__pycache__/config.cpython-37.pyc
Normal file
Binary file not shown.
BIN
__pycache__/utils.cpython-37.pyc
Normal file
BIN
__pycache__/utils.cpython-37.pyc
Normal file
Binary file not shown.
20
config.py
Normal file
20
config.py
Normal file
@ -0,0 +1,20 @@
|
||||
# 调用域名
|
||||
base_path = 'https://www.jiyuankeshang.com'
|
||||
# 密钥
|
||||
SECRET = '8jSj7EF1J6P1zzDeqzMxc-1c4EV3tTGyB5yljB2RWtk'
|
||||
# apikey
|
||||
apikey = '82bl1lhsgjzhd9ahBYvaMNVAncYYRkbE'
|
||||
# APIv3密钥
|
||||
v3_SECRET = '20230626yinjian13370189887jiyuan'
|
||||
# 服务器IP
|
||||
ip = '101.43.208.145'
|
||||
# 应用ID
|
||||
app_id = "6790ca1682b769eeefb022f2"
|
||||
# 车损任务表单ID
|
||||
vehicle_damage_id = "67d39b39baccd58c66507dfd"
|
||||
# 物损表单ID
|
||||
item_damage_id = "67dbe8bbbaccd58c66c606eb"
|
||||
# 人伤表单ID
|
||||
human_injury_id = "67dbbc83baccd58c66c1575a"
|
||||
# 车损任务表单ID
|
||||
lossseqcategory_id = "67eb42cfde8bbe9eed2733f3"
|
||||
131
logs/withdrawcase.log
Normal file
131
logs/withdrawcase.log
Normal file
File diff suppressed because one or more lines are too long
201
utils.py
Normal file
201
utils.py
Normal file
@ -0,0 +1,201 @@
|
||||
import time
|
||||
import requests
|
||||
import os
|
||||
import json
|
||||
from config import *
|
||||
import base64
|
||||
import urllib.parse
|
||||
from urllib.parse import urlparse, parse_qs
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def req_tool_jdy(url, data):
|
||||
#调用简道云接口
|
||||
headers = {"Authorization": f"Bearer {apikey}"}
|
||||
while 1:
|
||||
try:
|
||||
res = requests.post(url, headers=headers, json=data, timeout=15, verify=False).json()
|
||||
if "code" in res.keys():
|
||||
logger.info(f"req_tool_jdy请求错误 - url: {url}, "
|
||||
f"请求参数: {data}, 返回结果: {res}")
|
||||
time.sleep(2)
|
||||
continue
|
||||
return res
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
|
||||
def query_data(query_data_info):
|
||||
#调用批量查询数据接口
|
||||
query_data_url = f'{base_path}/api/v5/app/entry/data/list'
|
||||
try:
|
||||
query_data_res = req_tool_jdy(query_data_url, query_data_info)
|
||||
return query_data_res
|
||||
except Exception as e:
|
||||
logger.error(f"query_data请求异常 - url: {query_data_url}, "
|
||||
f"请求参数: {query_data_info}, 异常信息: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def update_data(instance_id, workflow_entry_id, withdrawal_reason):
|
||||
# 调用更新数据接口
|
||||
update_data_url = f'{base_path}/api/v5/app/entry/data/update'
|
||||
update_data_info = {
|
||||
"app_id": app_id,
|
||||
"entry_id": workflow_entry_id,
|
||||
"data_id": instance_id,
|
||||
"is_start_trigger": True,
|
||||
"data": {
|
||||
"withdrawal_opinion": {"value": "是"},
|
||||
"withdrawal_reason": {"value": withdrawal_reason}
|
||||
}
|
||||
}
|
||||
try:
|
||||
logger.info(f"update_data请求 - url: {update_data_url}, update_data_info: {update_data_info} ")
|
||||
update_data_res = req_tool_jdy(update_data_url, update_data_info)
|
||||
logger.info(f"更新数据完成\nupdate_data_res: {update_data_res}")
|
||||
return update_data_res
|
||||
except Exception as e:
|
||||
logger.error(f"update_data请求异常 - url: {update_data_url}, "
|
||||
f"请求参数: {update_data_info}, 异常信息: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def get_workflow(lossseqno, lossseqcategory):
|
||||
# 调用查询流程信息接口
|
||||
get_workflow_url = f'{base_path}/api/v6/workflow/instance/get'
|
||||
if lossseqcategory == "车损":
|
||||
workflow_entry_id = vehicle_damage_id
|
||||
elif lossseqcategory == "物损":
|
||||
workflow_entry_id = item_damage_id
|
||||
elif lossseqcategory == "人伤":
|
||||
workflow_entry_id = human_injury_id
|
||||
else:
|
||||
logger.error(f"未知的损失类别: {lossseqcategory}")
|
||||
return None
|
||||
query_data_info = {
|
||||
"app_id": app_id,
|
||||
"entry_id": workflow_entry_id,
|
||||
"limit": 100,
|
||||
"fields": ["_id", "appId", "entryId", "reportno", "lossseqno", "lossseqname", "lossseqtype"],
|
||||
"filter": {
|
||||
"rel": "and",
|
||||
"cond": [
|
||||
{
|
||||
"field": "lossseqno",
|
||||
"method": "eq",
|
||||
"value": [lossseqno]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
try:
|
||||
query_result = query_data(query_data_info)
|
||||
instance_id = query_result['data'][0]['_id']
|
||||
get_workflow_info = {
|
||||
"instance_id": instance_id,
|
||||
"tasks_type":1
|
||||
}
|
||||
get_workflow_res = req_tool_jdy(get_workflow_url, get_workflow_info)
|
||||
logger.info(f"完成流程查询\nstatus:{get_workflow_res['status']}, instance_id:{instance_id}, workflow_entry_id:{workflow_entry_id}")
|
||||
return {"status":get_workflow_res['status'], "instance_id":instance_id, "workflow_entry_id":workflow_entry_id}
|
||||
except Exception as e:
|
||||
logger.error(f"get_workflow请求异常 - url: {get_workflow_url}, "
|
||||
f"请求参数: {query_data_info}, 异常信息: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def close_workflow(close_workflow_info):
|
||||
# 调用结束流程接口
|
||||
close_workflow_url = f'{base_path}/api/v1/workflow/instance/close'
|
||||
try:
|
||||
query_data_res = req_tool_jdy(close_workflow_url, close_workflow_info)
|
||||
return query_data_res
|
||||
except Exception as e:
|
||||
logger.error(f"query_data请求异常 - url: {close_workflow_url}, "
|
||||
f"请求参数: {close_workflow_info}, 异常信息: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def get_lossseqcategory_info(lossseqtype):
|
||||
# 调用查询损失类别信息接口
|
||||
get_lossseqcategory_info_url = f'{base_path}/api/v5/app/entry/data/list'
|
||||
get_lossseqcategory_info_data = {
|
||||
"app_id": app_id,
|
||||
"entry_id": lossseqcategory_id,
|
||||
"limit": 100,
|
||||
"fields": ["_id", "appId", "entryId", "lossseqtype", "lossseqcategory"],
|
||||
"filter": {
|
||||
"rel": "and",
|
||||
"cond": [
|
||||
{
|
||||
"field": "lossseqtype",
|
||||
"method": "eq",
|
||||
"value": [lossseqtype]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
query_data_res = req_tool_jdy(get_lossseqcategory_info_url, get_lossseqcategory_info_data)
|
||||
if not query_data_res.get('data'):
|
||||
logger.error("查询结果为空")
|
||||
return None
|
||||
lossseqcategory = query_data_res['data'][0]['lossseqcategory']
|
||||
return lossseqcategory
|
||||
|
||||
|
||||
def withdraw_a_case(reportno, withdrawal_reason):
|
||||
query_data_info = {
|
||||
"app_id": app_id,
|
||||
"entry_id": "67ab117682b769eeef2549df",
|
||||
"limit": 100,
|
||||
"fields": ["_id", "appId", "entryId", "reportno", "lossseq_info"],
|
||||
"filter": {
|
||||
"rel": "and",
|
||||
"cond": [
|
||||
{
|
||||
"field": "reportno",
|
||||
"method": "eq",
|
||||
"value": [reportno]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
querydata = query_data(query_data_info)
|
||||
# 提取所有 lossseqno 和 lossseqtype
|
||||
query_result = []
|
||||
for item in querydata['data']:
|
||||
if not item.get('lossseq_info'):
|
||||
logger.info(f"没有任务信息: {item}")
|
||||
return 1
|
||||
for lossseq in item['lossseq_info']:
|
||||
lossseqcategory = get_lossseqcategory_info(lossseq['lossseqtype'])
|
||||
query_result.append({
|
||||
'lossseqno': lossseq['lossseqno'],
|
||||
'lossseqtype': lossseq['lossseqtype'],
|
||||
'lossseqcategory': lossseqcategory
|
||||
})
|
||||
|
||||
for task in query_result:
|
||||
workflow_res = get_workflow(task['lossseqno'], task['lossseqcategory'])
|
||||
if workflow_res['status'] == 0:
|
||||
instance_id = workflow_res['instance_id']
|
||||
workflow_entry_id = workflow_res['workflow_entry_id']
|
||||
close_workflow_info = {
|
||||
"instance_id": instance_id
|
||||
}
|
||||
close_workflow_res = close_workflow(close_workflow_info)
|
||||
if close_workflow_res['status'] == "success":
|
||||
update_data_res = update_data(instance_id, workflow_entry_id , withdrawal_reason)
|
||||
if update_data_res['data'] :
|
||||
logger.info(f"撤回成功,回写成功 - 报案号: {reportno}, 流程实例ID: {instance_id}")
|
||||
return 1
|
||||
else:
|
||||
logger.error(f"撤回成功,回写失败 - 报案号: {reportno}, 流程实例ID: {instance_id}")
|
||||
return 1
|
||||
else:
|
||||
logger.error(f"撤回失败 - 报案号: {reportno}, 流程实例ID: {instance_id}")
|
||||
return 0
|
||||
|
||||
|
||||
97
withdrawcase.py
Normal file
97
withdrawcase.py
Normal file
@ -0,0 +1,97 @@
|
||||
from flask import Flask, request, redirect, abort, session, jsonify, json
|
||||
from utils import *
|
||||
import os, _thread, urllib, re
|
||||
from flask_cors import CORS
|
||||
import logging
|
||||
from logging.handlers import TimedRotatingFileHandler
|
||||
import datetime
|
||||
|
||||
# 初始化Flask应用
|
||||
app = Flask(__name__)
|
||||
app.config['SECRET_KEY'] = os.urandom(24)
|
||||
CORS(app, supports_credentials=True)
|
||||
|
||||
def setup_logging():
|
||||
"""配置日志系统,按天分割日志文件"""
|
||||
# 创建日志目录
|
||||
log_dir = "logs"
|
||||
os.makedirs(log_dir, exist_ok=True)
|
||||
|
||||
# 设置日志格式
|
||||
log_format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
||||
formatter = logging.Formatter(log_format)
|
||||
|
||||
# 创建按天轮转的文件处理器
|
||||
file_handler = TimedRotatingFileHandler(
|
||||
filename=os.path.join(log_dir, 'withdrawcase.log'),
|
||||
when='midnight', # 每天午夜轮转
|
||||
interval=1, # 每天一个文件
|
||||
backupCount=30, # 保留30天的日志
|
||||
encoding='utf-8'
|
||||
)
|
||||
file_handler.setFormatter(formatter)
|
||||
file_handler.setLevel(logging.INFO)
|
||||
|
||||
# 创建控制台处理器
|
||||
console_handler = logging.StreamHandler()
|
||||
console_handler.setFormatter(formatter)
|
||||
console_handler.setLevel(logging.DEBUG)
|
||||
|
||||
# 获取根logger并配置
|
||||
logger = logging.getLogger()
|
||||
logger.setLevel(logging.DEBUG)
|
||||
logger.addHandler(file_handler)
|
||||
logger.addHandler(console_handler)
|
||||
|
||||
|
||||
# 初始化日志配置
|
||||
setup_logging()
|
||||
|
||||
# 获取当前模块的 logger
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.info("App started") # 会输出到文件和控制台
|
||||
|
||||
@app.route('/withdrawACase', methods=['POST'])
|
||||
def withdrawCase():
|
||||
try:
|
||||
# 直接解析二进制数据为 JSON(不需要手动 decode + loads)
|
||||
data = request.get_json() # Flask 提供的便捷方法
|
||||
if data is None:
|
||||
raise ValueError("Request data is not valid JSON")
|
||||
|
||||
# 安全获取 'data' 字段
|
||||
result = data.get('data')
|
||||
if result is None:
|
||||
raise ValueError("Missing 'data' field in JSON")
|
||||
withdrawal_opinion =result['withdrawal_opinion']
|
||||
withdrawal_type = result['withdrawal_type']
|
||||
withdrawal_reason = result['withdrawal_reason']
|
||||
leader_opinion = result['leader_opinion']
|
||||
reportno = result['reportno']
|
||||
|
||||
logger.info(f"收到请求 - withdrawal_opinion: {withdrawal_opinion}, "
|
||||
f"withdrawal_type: {withdrawal_type},withdrawal_reason: {withdrawal_reason},reportno: {reportno}")
|
||||
|
||||
if withdrawal_opinion == "同意" and withdrawal_type:
|
||||
# 调用函数
|
||||
if withdrawal_type == "超出统筹服务范围" and leader_opinion in ("内保理赔", "机构审批统筹处理"):
|
||||
# 处理超出统筹服务范围的撤案
|
||||
logger.info(f"案件 {reportno}超出统筹服务范围,{leader_opinion}")
|
||||
return jsonify({"status": "success", "message": "Case withdrawn successfully."})
|
||||
else:
|
||||
logger.info(f"案件 {reportno}开始撤案")
|
||||
if withdraw_a_case(reportno, withdrawal_reason) ==1:
|
||||
return jsonify({"status": "success", "message": "Case withdrawn successfully."})
|
||||
else:
|
||||
return jsonify({"status": "fail", "message": "Case mismatch."})
|
||||
|
||||
else:
|
||||
logger.warning("案件不匹配 - withdrawal conditions not met")
|
||||
return jsonify({"status": "success", "message": "Case mismatch."})
|
||||
except Exception as e:
|
||||
logger.error(f"Error in withdrawCase: {str(e)}", exc_info=True)
|
||||
return jsonify({"status": "error", "message": str(e)})
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host="0.0.0.0", port=3012, processes=True)
|
||||
Reference in New Issue
Block a user