first commit
This commit is contained in:
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