feat: 操作日志系统 + 日期修复 + 协同去重 + 主题持久化 + 计划自动完成
本次累积提交包含以下功能: 1. 修复:el-date-picker 缺失 value-format 导致日期保存偏移(8处) 2. 新增:协同拜访 visit_group_id 去重机制(完整副本 + 周报合并 + 亮灯去重) 3. 新增:计划自动完成(创建计划检测已有拜访 / 编辑拜访触发) 4. 新增:拜访表单选择客户后自动预填过期计划内容 5. 新增:移动端主题切换按钮 + 后端持久化 6. 新增:操作日志系统 (audit_logs),全覆盖 8 个模块 CRUD 7. 新增:PC端「我的数据」支局长/领导视角客户经理列 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,7 @@ from app.models.mini_business import MiniBusiness
|
||||
from app.models.key_visit import KeyVisit
|
||||
from app.models.daily_note import DailyNote
|
||||
from app.models.user import User
|
||||
from app.utils.audit import log_audit
|
||||
from app.schemas.customer import (
|
||||
CustomerCreate, CustomerUpdate, CustomerOut, CustomerListOut, CustomerListResponse,
|
||||
ContactCreate, ContactOut, AssignmentCreate, AssignmentOut, BatchAssignRequest,
|
||||
@@ -399,6 +400,10 @@ async def create_customer(
|
||||
))
|
||||
await db.commit()
|
||||
|
||||
# Audit log
|
||||
await log_audit(db, "customer", customer.id, customer.name, "create", current_user["user_id"], current_user["name"])
|
||||
await db.commit()
|
||||
|
||||
result = await db.execute(
|
||||
select(Customer).where(Customer.id == customer.id).options(selectinload(Customer.contacts))
|
||||
)
|
||||
@@ -470,6 +475,10 @@ async def update_customer(
|
||||
|
||||
await db.commit()
|
||||
|
||||
# Audit log
|
||||
await log_audit(db, "customer", uuid_mod.UUID(customer_id), customer.name, "update", current_user["user_id"], current_user["name"])
|
||||
await db.commit()
|
||||
|
||||
result = await db.execute(
|
||||
select(Customer).where(Customer.id == customer.id).options(selectinload(Customer.contacts))
|
||||
)
|
||||
@@ -486,8 +495,12 @@ async def delete_customer(
|
||||
customer = result.scalar_one_or_none()
|
||||
if not customer:
|
||||
raise HTTPException(status_code=404, detail="Customer not found")
|
||||
cust_name = customer.name
|
||||
await db.delete(customer)
|
||||
await db.commit()
|
||||
# Audit log
|
||||
await log_audit(db, "customer", uuid_mod.UUID(customer_id), cust_name, "delete", current_user["user_id"], current_user["name"])
|
||||
await db.commit()
|
||||
return {"detail": "deleted"}
|
||||
|
||||
|
||||
@@ -715,3 +728,33 @@ async def assign_manager(
|
||||
await db.commit()
|
||||
await db.refresh(assignment)
|
||||
return assignment
|
||||
|
||||
|
||||
@router.get("/{customer_id}/overdue-plans")
|
||||
async def get_overdue_plans(
|
||||
customer_id: str,
|
||||
current_user: dict = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
"""Return the latest overdue (plan_date < today) and still '计划中' plan for a customer.
|
||||
Used by the frontend to pre-fill visit forms with pending plan content."""
|
||||
from app.utils.timezone import today_cst
|
||||
today = today_cst()
|
||||
result = await db.execute(
|
||||
select(WorkPlan).where(
|
||||
WorkPlan.customer_id == uuid_mod.UUID(customer_id),
|
||||
WorkPlan.status == "计划中",
|
||||
WorkPlan.plan_date < today,
|
||||
).order_by(WorkPlan.plan_date.desc()).limit(1)
|
||||
)
|
||||
plan = result.scalar_one_or_none()
|
||||
if not plan:
|
||||
return {"plan": None}
|
||||
return {
|
||||
"plan": {
|
||||
"id": str(plan.id),
|
||||
"plan_content": plan.plan_content,
|
||||
"plan_date": str(plan.plan_date),
|
||||
"manager_id": str(plan.manager_id),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user