You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
6.1 KiB
122 lines
6.1 KiB
2 months ago
|
import json
|
||
|
import uuid
|
||
|
|
||
|
from typing import Optional
|
||
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||
|
from module_admin.entity.vo.common_vo import CrudResponseModel
|
||
|
from module_admin.entity.vo.approval_vo import ApplyModel, OperateModel, ApprovalQueryObject, EditObjectModel
|
||
|
from module_admin.entity.vo.user_vo import CurrentUserModel
|
||
|
from module_admin.entity.do.approval_do import FlowApproval
|
||
|
from exceptions.exception import ServiceException, ServiceWarning
|
||
|
from datetime import datetime
|
||
|
from utils.common_util import CamelCaseUtil
|
||
|
from module_admin.dao.approval_dao import ApprovalDao
|
||
|
from module_admin.dao.meta_dao import MetaDao
|
||
|
|
||
|
|
||
|
class ApprovalService:
|
||
|
"""
|
||
|
智能问答服务层
|
||
|
"""
|
||
|
|
||
|
@classmethod
|
||
|
async def apply_services(cls, result_db: AsyncSession, apply: ApplyModel):
|
||
|
flow_approval = FlowApproval()
|
||
|
flow_approval.id = uuid.uuid4()
|
||
|
flow_approval.businessType = apply.businessType
|
||
|
flow_approval.businessId = apply.businessId
|
||
|
flow_approval.applicant = apply.applicant
|
||
|
flow_approval.applyTime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||
|
flow_approval.status = 'waiting'
|
||
|
# todo 后期进行流程配置,角色 or 人员 下一步审批人
|
||
|
flow_approval.approver = 'admin'
|
||
|
flow_approval.nextStep = '1'
|
||
|
await ApprovalDao.add_flow_approval(result_db, flow_approval)
|
||
|
await result_db.commit()
|
||
|
return CrudResponseModel(is_success=True, message='申请成功')
|
||
|
|
||
|
@classmethod
|
||
|
async def operate_services(cls, result_db: AsyncSession, operate: OperateModel, current_user: CurrentUserModel):
|
||
|
flow_approval = await ApprovalDao.get_flow_by_id(result_db, operate.flowId)
|
||
|
if flow_approval is None:
|
||
|
raise ServiceException(message=f'所操作的流程不存在')
|
||
|
if flow_approval.status == 'succeed' or flow_approval.status == 'rejected':
|
||
|
raise ServiceException(message='所操作的流程已结束')
|
||
|
if flow_approval.status == 'canceled':
|
||
|
raise ServiceException(message='所操作的流程已撤回')
|
||
|
array = []
|
||
|
if flow_approval.approvalFlow is not None:
|
||
|
array = json.loads(flow_approval.approvalFlow)
|
||
|
array.append({'operator': current_user.user.user_name,
|
||
|
'operateTime': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
||
|
'operate': operate.operateType,
|
||
|
'operateComment': operate.operateComment,
|
||
|
})
|
||
|
edit = EditObjectModel()
|
||
|
edit.id = flow_approval.id
|
||
|
edit.approvalFlow = json.dumps(array)
|
||
|
if operate.operateType == 'success':
|
||
|
# todo 增加流程配置,并查询出下一步操作人以及步骤
|
||
|
edit.status = 'succeed' # 有下一步执行人,则设置为 pending
|
||
|
edit.approver = None
|
||
|
edit.nextStep = -1
|
||
|
if operate.operateType == 'reject':
|
||
|
edit.status = 'rejected'
|
||
|
edit.approver = None
|
||
|
edit.nextStep = -1
|
||
|
if flow_approval.businessType == 't_metadata_supp_info':
|
||
|
await cls.syncSuppInfo(result_db, flow_approval.businessId, operate.operateType)
|
||
|
await ApprovalDao.edit_flow_approval(result_db, edit.model_dump(exclude_unset=True))
|
||
|
await result_db.commit()
|
||
|
return CrudResponseModel(is_success=True, message='操作成功')
|
||
|
|
||
|
@classmethod
|
||
|
async def syncSuppInfo(cls, result_db: AsyncSession, suppId: str, operateType: str):
|
||
|
table = await MetaDao.get_supp_table_vett_by_id(suppId, result_db)
|
||
|
if table is None:
|
||
|
raise ServiceException(message='所查询的业务数据不存在')
|
||
|
if table.apply_status == 'succeed' or table.apply_status == 'rejected':
|
||
|
raise ServiceException(message='所改业务已审核完毕')
|
||
|
column_list = await MetaDao.get_meta_col_supp_vett(table, result_db)
|
||
|
if column_list is not None and len(column_list) > 0:
|
||
|
for column in column_list:
|
||
|
column.apply_status = operateType
|
||
|
suppColumn = await MetaDao.get_supp_column_by_vett(column, result_db)
|
||
|
await MetaDao.updateMetadataFldSuppInfoVett(column.onum, operateType, result_db)
|
||
|
if suppColumn is None:
|
||
|
await MetaDao.insertMetadataFldSuppInfo(column, result_db)
|
||
|
else:
|
||
|
await MetaDao.updateMetadataFldSuppInfo(suppColumn.onum, column, result_db)
|
||
|
suppTable = await MetaDao.get_supp_table_by_vett(table.ssys_cd, table.mdl_name, table.tab_eng_name, result_db)
|
||
|
await MetaDao.updateMetadataSuppInfoVett(table.onum, operateType, result_db)
|
||
|
if suppTable is None:
|
||
|
await MetaDao.insertMetadataSuppInfo(table, result_db)
|
||
|
else:
|
||
|
await MetaDao.updateMetadataSuppInfo(suppTable.onum, table, result_db)
|
||
|
return CrudResponseModel(is_success=True, message='操作成功')
|
||
|
|
||
|
@classmethod
|
||
|
async def get_flow_list_services(cls, query_db: AsyncSession, query_param: ApprovalQueryObject,
|
||
|
current_user: CurrentUserModel):
|
||
|
result = await ApprovalDao.get_flow_list(query_db, query_param, current_user)
|
||
|
return result
|
||
|
|
||
|
@classmethod
|
||
|
async def get_waiting_total_services(cls, query_db: AsyncSession, current_user: CurrentUserModel):
|
||
|
result = await ApprovalDao.get_waiting_total(query_db, current_user)
|
||
|
return result
|
||
|
|
||
|
@classmethod
|
||
|
async def cancel_apply_services(cls, query_db: AsyncSession, flow_id: str,
|
||
|
current_user: CurrentUserModel):
|
||
|
flow = await ApprovalDao.get_flow_by_idAndUser(flow_id, current_user.user.user_name)
|
||
|
if flow is None:
|
||
|
raise ServiceException(message=f'所操作的流程不存在')
|
||
|
if flow.status == 'succeed' or flow.status == 'rejected':
|
||
|
raise ServiceException(message='所操作的流程已结束,无需撤回')
|
||
|
if flow.status == 'canceled':
|
||
|
raise ServiceException(message='所操作的流程已撤回,无需重复操作')
|
||
|
flow.status = 'canceled'
|
||
|
await ApprovalDao.edit_flow_approval(query_db, flow)
|
||
|
return CrudResponseModel(is_success=True, message='操作成功')
|