优化案件模块
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 6.0.1 on 2026-01-14 07:40
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('business', '0003_remove_bid_user_remove_case_user_remove_caselog_user_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='projectregistration',
|
||||
name='responsiblefor',
|
||||
field=models.TextField(),
|
||||
),
|
||||
]
|
||||
@@ -19,7 +19,7 @@ class ProjectRegistration(models.Model):
|
||||
client_info = models.TextField(null=True, blank=True) # 委托人身份信息(临时允许为空,用于数据迁移)
|
||||
party_info = models.TextField(null=True, blank=True) # 相对方身份信息(临时允许为空,用于数据迁移)
|
||||
description = models.TextField(null=True, blank=True) # 项目简述(临时允许为空,用于数据迁移)
|
||||
responsiblefor = models.CharField(max_length=100) # 负责人
|
||||
responsiblefor = models.TextField() # 负责人信息(JSON格式字典:{"负责人":"","主办律师":"","助理律师":"","收益分配":""},负责人必填,其余选填)
|
||||
charge = models.CharField(max_length=100) # 收费情况
|
||||
contract = models.TextField() # 上传合同
|
||||
state = models.CharField(max_length=100) # 状态
|
||||
|
||||
@@ -195,7 +195,7 @@ class Project(APIView):
|
||||
client_info = request.data.get('client_info') # 委托人身份信息
|
||||
party_info = request.data.get('party_info') # 相对方身份信息
|
||||
description = request.data.get('description') # 项目简述
|
||||
responsiblefor = request.data.get('responsiblefor')
|
||||
responsiblefor = request.data.get('responsiblefor') # 负责人信息(字典格式)
|
||||
charge = request.data.get('charge')
|
||||
contract = request.FILES.getlist('contract')
|
||||
approvers = request.data.get('approvers') # 审核人列表(可选,多人团队时需要,推荐:用户ID数组如[1,2,3],兼容:用户名数组)
|
||||
@@ -205,11 +205,32 @@ class Project(APIView):
|
||||
approvers = [personincharge] if personincharge else None
|
||||
|
||||
import datetime
|
||||
import json
|
||||
|
||||
# 验证必填字段
|
||||
if not all([type, ContractNo, times, client_info, party_info, description, responsiblefor, charge]):
|
||||
if not all([type, ContractNo, times, client_info, party_info, description, charge]):
|
||||
return Response({'status': 'error', 'message': '缺少必填参数', 'code': 1}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# 验证负责人信息(字典格式)
|
||||
if not responsiblefor:
|
||||
return Response({'status': 'error', 'message': '负责人信息不能为空', 'code': 1}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# 解析负责人信息(支持字符串JSON或字典)
|
||||
try:
|
||||
if isinstance(responsiblefor, str):
|
||||
responsiblefor_dict = json.loads(responsiblefor)
|
||||
else:
|
||||
responsiblefor_dict = responsiblefor
|
||||
|
||||
# 验证负责人字段必填
|
||||
if not responsiblefor_dict.get('负责人'):
|
||||
return Response({'status': 'error', 'message': '负责人字段不能为空', 'code': 1}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# 将字典转换为JSON字符串存储
|
||||
responsiblefor_str = json.dumps(responsiblefor_dict, ensure_ascii=False)
|
||||
except (json.JSONDecodeError, TypeError, AttributeError):
|
||||
return Response({'status': 'error', 'message': '负责人信息格式错误,应为字典格式', 'code': 1}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
if contract:
|
||||
contract = flies(contract)
|
||||
else:
|
||||
@@ -236,7 +257,7 @@ class Project(APIView):
|
||||
client_info=client_info,
|
||||
party_info=party_info,
|
||||
description=description,
|
||||
responsiblefor=responsiblefor,
|
||||
responsiblefor=responsiblefor_str,
|
||||
charge=charge,
|
||||
contract=contract_str,
|
||||
state="审核中",
|
||||
@@ -245,23 +266,32 @@ class Project(APIView):
|
||||
today = datetime.datetime.now()
|
||||
formatted_date = today.strftime("%Y-%m-%d")
|
||||
|
||||
# 获取负责人的团队信息
|
||||
# 获取负责人的团队信息(从字典中获取负责人字段)
|
||||
team_name = None
|
||||
try:
|
||||
responsible_user = User.objects.get(username=responsiblefor, is_deleted=False)
|
||||
team_name = responsible_user.team
|
||||
responsible_person = responsiblefor_dict.get('负责人')
|
||||
if responsible_person:
|
||||
responsible_user = User.objects.get(username=responsible_person, is_deleted=False)
|
||||
team_name = responsible_user.team
|
||||
except User.DoesNotExist:
|
||||
pass
|
||||
|
||||
# 使用统一的审核流程函数
|
||||
from User.utils import create_approval_with_team_logic
|
||||
|
||||
content = f"{responsiblefor}在{times}办理立项登记,项目类型:{type},合同编号:{ContractNo},负责人:{responsiblefor},收费情况:{charge}"
|
||||
# 构建负责人信息描述
|
||||
responsible_desc = responsiblefor_dict.get('负责人', '')
|
||||
if responsiblefor_dict.get('主办律师'):
|
||||
responsible_desc += f",主办律师:{responsiblefor_dict.get('主办律师')}"
|
||||
if responsiblefor_dict.get('助理律师'):
|
||||
responsible_desc += f",助理律师:{responsiblefor_dict.get('助理律师')}"
|
||||
|
||||
content = f"{responsiblefor_dict.get('负责人')}在{times}办理立项登记,项目类型:{type},合同编号:{ContractNo},{responsible_desc},收费情况:{charge}"
|
||||
|
||||
approval, approvers_order_json, needs_approval = create_approval_with_team_logic(
|
||||
team_name=team_name,
|
||||
approvers=approvers,
|
||||
title=responsiblefor + "立项登记",
|
||||
title=responsiblefor_dict.get('负责人', '') + "立项登记",
|
||||
content=content,
|
||||
approval_type="立项登记",
|
||||
user_id=pro.id,
|
||||
@@ -282,7 +312,7 @@ class Project(APIView):
|
||||
'id': pro.id,
|
||||
'contract_no': pro.ContractNo,
|
||||
'type': pro.type,
|
||||
'responsiblefor': pro.responsiblefor,
|
||||
'responsiblefor': responsiblefor_dict,
|
||||
'times': pro.times
|
||||
}
|
||||
log_operation(
|
||||
@@ -294,7 +324,7 @@ class Project(APIView):
|
||||
target_id=pro.id,
|
||||
target_name=pro.ContractNo,
|
||||
new_data=new_data,
|
||||
remark=f'新增立项登记:合同编号 {pro.ContractNo},负责人 {pro.responsiblefor}'
|
||||
remark=f'新增立项登记:合同编号 {pro.ContractNo},负责人 {responsiblefor_dict.get("负责人", "")}'
|
||||
)
|
||||
|
||||
return Response({'message': '登记成功', 'code': 0}, status=status.HTTP_200_OK)
|
||||
@@ -367,7 +397,14 @@ class ProjectDetail(APIView):
|
||||
except EmptyPage:
|
||||
user_agents_page = paginator.page(paginator.num_pages)
|
||||
data = []
|
||||
import json
|
||||
for info in user_agents_page.object_list:
|
||||
# 解析负责人信息(JSON字符串转字典)
|
||||
try:
|
||||
responsiblefor_dict = json.loads(info.responsiblefor) if info.responsiblefor else {}
|
||||
except:
|
||||
responsiblefor_dict = info.responsiblefor if info.responsiblefor else {}
|
||||
|
||||
data.append({
|
||||
"id": info.id,
|
||||
'times': info.times,
|
||||
@@ -376,7 +413,7 @@ class ProjectDetail(APIView):
|
||||
"client_info": info.client_info,
|
||||
"party_info": info.party_info,
|
||||
"description": info.description,
|
||||
"responsiblefor": info.responsiblefor,
|
||||
"responsiblefor": responsiblefor_dict, # 返回字典格式
|
||||
"charge": info.charge,
|
||||
"contract": info.contract,
|
||||
"state": info.state,
|
||||
@@ -420,9 +457,11 @@ class EditProject(APIView):
|
||||
client_info = request.data.get('client_info')
|
||||
party_info = request.data.get('party_info')
|
||||
description = request.data.get('description')
|
||||
responsiblefor = request.data.get('responsiblefor')
|
||||
responsiblefor = request.data.get('responsiblefor') # 负责人信息(字典格式)
|
||||
charge = request.data.get('charge')
|
||||
contract = request.FILES.getlist('contract')
|
||||
|
||||
import json
|
||||
|
||||
try:
|
||||
pro = ProjectRegistration.objects.get(id=id, is_deleted=False)
|
||||
@@ -435,7 +474,10 @@ class EditProject(APIView):
|
||||
# 保存原始值用于日志记录
|
||||
original_type = pro.type
|
||||
original_ContractNo = pro.ContractNo
|
||||
original_responsiblefor = pro.responsiblefor
|
||||
try:
|
||||
original_responsiblefor = json.loads(pro.responsiblefor) if pro.responsiblefor else {}
|
||||
except:
|
||||
original_responsiblefor = {}
|
||||
original_times = pro.times
|
||||
original_charge = pro.charge
|
||||
|
||||
@@ -456,8 +498,23 @@ class EditProject(APIView):
|
||||
update_fields_list.append('times')
|
||||
|
||||
if responsiblefor:
|
||||
pro.responsiblefor = responsiblefor
|
||||
update_fields_list.append('responsiblefor')
|
||||
# 解析负责人信息(支持字符串JSON或字典)
|
||||
try:
|
||||
if isinstance(responsiblefor, str):
|
||||
responsiblefor_dict = json.loads(responsiblefor)
|
||||
else:
|
||||
responsiblefor_dict = responsiblefor
|
||||
|
||||
# 验证负责人字段必填
|
||||
if not responsiblefor_dict.get('负责人'):
|
||||
return Response({'status': 'error', 'message': '负责人字段不能为空', 'code': 1}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# 将字典转换为JSON字符串存储
|
||||
responsiblefor_str = json.dumps(responsiblefor_dict, ensure_ascii=False)
|
||||
pro.responsiblefor = responsiblefor_str
|
||||
update_fields_list.append('responsiblefor')
|
||||
except (json.JSONDecodeError, TypeError, AttributeError):
|
||||
return Response({'status': 'error', 'message': '负责人信息格式错误,应为字典格式', 'code': 1}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
if charge:
|
||||
pro.charge = charge
|
||||
@@ -478,12 +535,12 @@ class EditProject(APIView):
|
||||
pro.state = "审核中"
|
||||
update_fields_list.append('state')
|
||||
|
||||
# 记录操作前的数据
|
||||
# 记录操作前的数据(original_responsiblefor已经是字典格式)
|
||||
old_data = {
|
||||
'id': pro.id,
|
||||
'contract_no': original_ContractNo,
|
||||
'type': original_type,
|
||||
'responsiblefor': original_responsiblefor,
|
||||
'responsiblefor': original_responsiblefor if isinstance(original_responsiblefor, dict) else {},
|
||||
'times': original_times,
|
||||
'charge': original_charge
|
||||
}
|
||||
@@ -492,22 +549,40 @@ class EditProject(APIView):
|
||||
pro.save(update_fields=update_fields_list)
|
||||
|
||||
# 记录操作后的数据
|
||||
try:
|
||||
current_responsiblefor = json.loads(pro.responsiblefor) if pro.responsiblefor else {}
|
||||
except:
|
||||
current_responsiblefor = pro.responsiblefor if pro.responsiblefor else {}
|
||||
|
||||
new_data = {
|
||||
'id': pro.id,
|
||||
'contract_no': pro.ContractNo,
|
||||
'type': pro.type,
|
||||
'responsiblefor': pro.responsiblefor,
|
||||
'responsiblefor': current_responsiblefor,
|
||||
'times': pro.times,
|
||||
'charge': pro.charge
|
||||
}
|
||||
|
||||
today = datetime.datetime.now()
|
||||
formatted_date = today.strftime("%Y-%m-%d")
|
||||
|
||||
# 获取负责人名称用于审批记录
|
||||
if responsiblefor:
|
||||
current_responsiblefor = responsiblefor_dict.get('负责人', '')
|
||||
# 构建负责人信息描述
|
||||
responsible_desc = current_responsiblefor
|
||||
if responsiblefor_dict.get('主办律师'):
|
||||
responsible_desc += f",主办律师:{responsiblefor_dict.get('主办律师')}"
|
||||
if responsiblefor_dict.get('助理律师'):
|
||||
responsible_desc += f",助理律师:{responsiblefor_dict.get('助理律师')}"
|
||||
else:
|
||||
current_responsiblefor = original_responsiblefor.get('负责人', '') if isinstance(original_responsiblefor, dict) else ''
|
||||
responsible_desc = current_responsiblefor
|
||||
|
||||
Approval.objects.create(
|
||||
title=(responsiblefor or original_responsiblefor) + "立项登记重新编辑",
|
||||
content=(responsiblefor or original_responsiblefor) + "在" + (
|
||||
times or original_times) + "办理立项登记,项目类型:" + original_type + ",合同编号:" + original_ContractNo + "描述:" + ",负责人:" + (
|
||||
responsiblefor or original_responsiblefor) + ",收费情况:" + (charge or original_charge),
|
||||
title=current_responsiblefor + "立项登记重新编辑",
|
||||
content=current_responsiblefor + "在" + (
|
||||
times or original_times) + "办理立项登记,项目类型:" + original_type + ",合同编号:" + original_ContractNo + "描述:" + ",负责人:" + responsible_desc + ",收费情况:" + (charge or original_charge),
|
||||
times=formatted_date,
|
||||
personincharge="", # personincharge不再从请求中获取
|
||||
state='审核中',
|
||||
@@ -961,12 +1036,19 @@ class caseManagementDetail(APIView):
|
||||
except EmptyPage:
|
||||
user_agents_page = paginator.page(paginator.num_pages)
|
||||
data = []
|
||||
import json
|
||||
for info in user_agents_page.object_list:
|
||||
try:
|
||||
pro = ProjectRegistration.objects.get(id=info.project_id, is_deleted=False)
|
||||
except ProjectRegistration.DoesNotExist:
|
||||
continue # 跳过已删除的关联数据
|
||||
|
||||
# 解析负责人信息(JSON字符串转字典)
|
||||
try:
|
||||
responsiblefor_dict = json.loads(pro.responsiblefor) if pro.responsiblefor else {}
|
||||
except:
|
||||
responsiblefor_dict = pro.responsiblefor if pro.responsiblefor else {}
|
||||
|
||||
data.append({
|
||||
"id": info.id,
|
||||
"ContractNo": pro.ContractNo, # 合同编号
|
||||
@@ -974,7 +1056,7 @@ class caseManagementDetail(APIView):
|
||||
"client_name": pro.client_info, # 客户名称(委托人身份信息)
|
||||
"party_name": pro.party_info, # 相对方名称
|
||||
"description": pro.description, # 项目简述
|
||||
"responsiblefor": pro.responsiblefor, # 负责人
|
||||
"responsiblefor": responsiblefor_dict, # 负责人信息(字典格式)
|
||||
"charge": pro.charge, # 收费情况
|
||||
'times': info.times, # 立案时间
|
||||
"AgencyContract": info.AgencyContract, # 代理合同
|
||||
|
||||
1328
案件管理模块接口文档.md
Normal file
1328
案件管理模块接口文档.md
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user