123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- from flask import Blueprint, request
- from core.dtos import ProjectQuotaDto
- from core.user_session import Permission
- from core.api import ResponseBase, TableResponse
- from services import ProjectQuotaService
- project_quota_api = Blueprint("project_quota_api", __name__)
- quota_service = ProjectQuotaService()
- @project_quota_api.route(
- "/list/<int:budget_id>/<project_id>/<item_code>", methods=["POST"]
- )
- @Permission.authorize
- def get_page_list(budget_id: int, project_id: str, item_code: str):
- try:
- data = request.get_json()
- page = int(data.get("pageNum", 1))
- per_page = int(data.get("pageSize", 10))
- keyword = data.get("keyword")
- send_status = int(data.get("send_status")) if data.get("send_status") else None
- data, count = quota_service.get_quotas_paginated(
- budget_id, project_id, item_code, page, per_page, keyword, send_status
- )
- return TableResponse.success(data, count)
- except Exception as e:
- return ResponseBase.error(f"获取定额条目列表失败:{str(e)}")
- @project_quota_api.route(
- "/list/task/<int:task_id>/<int:budget_id>/<project_id>/<item_code>",
- methods=["POST"],
- )
- @Permission.authorize
- def get_quotas_by_task_paginated(
- task_id: int, budget_id: int, project_id: str, item_code: str
- ):
- try:
- data = request.get_json()
- page = int(data.get("pageNum", 1))
- per_page = int(data.get("pageSize", 10))
- keyword = data.get("keyword")
- send_status = int(data.get("send_status")) if data.get("send_status") else None
- data, count = quota_service.get_quotas_by_task_paginated(
- task_id,
- budget_id,
- project_id,
- item_code,
- page,
- per_page,
- keyword,
- send_status,
- )
- return TableResponse.success(data, count)
- except Exception as e:
- return ResponseBase.error(f"获取任务定额条目列表失败:{str(e)}")
- @project_quota_api.route("/get/<int:quota_id>", methods=["POST"])
- @Permission.authorize
- def get_quota(quota_id: int):
- try:
- data = quota_service.get_quota_dto(quota_id)
- return ResponseBase.success(data.to_dict())
- except Exception as e:
- return ResponseBase.error(f"获取定额条目失败:{str(e)}")
- @project_quota_api.route("/save", methods=["POST"])
- @Permission.authorize
- def save_quota():
- try:
- data = request.get_json()
- quota_dto = ProjectQuotaDto(**data)
- quota_dto = quota_service.save_quota(quota_dto)
- run_now = data.get("run_now", "false") == "true"
- if run_now:
- is_cover = data.get("is_cover", "false") == "true"
- quota_service.start_send(quota_dto.id, is_cover)
- return ResponseBase.success(quota_dto.to_dict())
- except Exception as e:
- return ResponseBase.error(f"保存定额条目失败:{str(e)}")
- @project_quota_api.route("/edit", methods=["POST"])
- @Permission.authorize
- def edit_by_key():
- try:
- data = request.get_json()
- id = data.get("id")
- if not id:
- return ResponseBase.error(f"未能获取到定额条目ID")
- key = data.get("key")
- value = data.get("val")
- msg = quota_service.edit_by_key(id, key, value)
- if msg:
- return ResponseBase.error(msg)
- return ResponseBase.success()
- except Exception as e:
- return ResponseBase.error(f"编辑定额条目失败:{str(e)}")
- @project_quota_api.route("/edit_quota_code_batch", methods=["POST"])
- @Permission.authorize
- def edit_quota_code_batch():
- try:
- data = request.get_json()
- ids = data.get("ids", "")
- quota_code = data.get("quota_code", "")
- msg = quota_service.edit_quota_code_batch(ids, quota_code)
- if msg:
- return ResponseBase.error(msg)
- return ResponseBase.success()
- except Exception as e:
- return ResponseBase.error(f"批量修改定额编号失败:{str(e)}")
- @project_quota_api.route("/delete/<int:quota_id>", methods=["POST"])
- @Permission.authorize
- def delete_quota(quota_id: int):
- try:
- quota_service.delete_quota(quota_id)
- return ResponseBase.success()
- except Exception as e:
- return ResponseBase.error(f"删除定额条目失败:{str(e)}")
- @project_quota_api.route("/start_send", methods=["POST"])
- @Permission.authorize
- def start_send():
- try:
- data = request.get_json()
- ids = data.get("ids", "")
- is_cover = data.get("is_cover", "false") == "true"
- msg = quota_service.start_send_by_ids(ids, is_cover)
- if msg:
- return ResponseBase.error(msg)
- return ResponseBase.success()
- except Exception as e:
- return ResponseBase.error(f"启动定额条目失败:{str(e)}")
- @project_quota_api.route("/save_change_chapter/<project_id>", methods=["POST"])
- @Permission.authorize
- def save_change_chapter(project_id: str):
- try:
- data = request.get_json()
- ids = data.get("ids", "")
- new_id = data.get("new_id", "")
- msg = quota_service.save_change_chapter(project_id, ids, new_id)
- if msg:
- return ResponseBase.error(msg)
- return ResponseBase.success()
- except Exception as e:
- return ResponseBase.error(f"变更章节失败:{str(e)}")
|