|
@ -11,6 +11,7 @@ from exceptions.exception import ServiceException, ServiceWarning |
|
|
from datetime import datetime |
|
|
from datetime import datetime |
|
|
from utils.common_util import CamelCaseUtil |
|
|
from utils.common_util import CamelCaseUtil |
|
|
from module_admin.dao.approval_dao import ApprovalDao |
|
|
from module_admin.dao.approval_dao import ApprovalDao |
|
|
|
|
|
from module_admin.dao.user_dao import UserDao |
|
|
from module_admin.dao.meta_dao import MetaDao |
|
|
from module_admin.dao.meta_dao import MetaDao |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -20,7 +21,7 @@ class ApprovalService: |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
@classmethod |
|
|
@classmethod |
|
|
async def apply_services(cls, result_db: AsyncSession, apply: ApplyModel): |
|
|
async def apply_services(cls, result_db: AsyncSession, apply: ApplyModel, module: str): |
|
|
flow_approval = FlowApproval() |
|
|
flow_approval = FlowApproval() |
|
|
flow_approval.id = uuid.uuid4() |
|
|
flow_approval.id = uuid.uuid4() |
|
|
flow_approval.businessType = apply.businessType |
|
|
flow_approval.businessType = apply.businessType |
|
@ -28,9 +29,10 @@ class ApprovalService: |
|
|
flow_approval.applicant = apply.applicant |
|
|
flow_approval.applicant = apply.applicant |
|
|
flow_approval.applyTime = datetime.now().strftime("%Y-%m-%d %H:%M:%S") |
|
|
flow_approval.applyTime = datetime.now().strftime("%Y-%m-%d %H:%M:%S") |
|
|
flow_approval.status = 'waiting' |
|
|
flow_approval.status = 'waiting' |
|
|
# todo 后期进行流程配置,角色 or 人员 下一步审批人 |
|
|
listConf = await ApprovalDao.get_first_node_conf(module, result_db) |
|
|
flow_approval.approver = 'admin' |
|
|
flow_approval.nextStep = json.dumps([item.id for item in listConf]) |
|
|
flow_approval.nextStep = '1' |
|
|
flow_approval.nextStepRole = json.dumps([item.code for item in listConf if item.type == 'Role']) |
|
|
|
|
|
flow_approval.nextStepUser = json.dumps([item.code for item in listConf if item.type == 'User']) |
|
|
await ApprovalDao.add_flow_approval(result_db, flow_approval) |
|
|
await ApprovalDao.add_flow_approval(result_db, flow_approval) |
|
|
await result_db.commit() |
|
|
await result_db.commit() |
|
|
return CrudResponseModel(is_success=True, message='申请成功') |
|
|
return CrudResponseModel(is_success=True, message='申请成功') |
|
@ -44,28 +46,49 @@ class ApprovalService: |
|
|
raise ServiceException(message='所操作的流程已结束') |
|
|
raise ServiceException(message='所操作的流程已结束') |
|
|
if flow_approval.status == 'canceled': |
|
|
if flow_approval.status == 'canceled': |
|
|
raise ServiceException(message='所操作的流程已撤回') |
|
|
raise ServiceException(message='所操作的流程已撤回') |
|
|
|
|
|
edit = EditObjectModel() |
|
|
|
|
|
edit.id = flow_approval.id |
|
|
|
|
|
flowConfList = await ApprovalDao.get_conf_list(result_db, flow_approval.businessType) |
|
|
|
|
|
nextSteps = json.loads(flow_approval.nextStep) |
|
|
|
|
|
nextStepFlowList = [item for item in flowConfList if item.id in nextSteps] |
|
|
|
|
|
nextFlowList = [item for item in nextStepFlowList if item.code in current_user.roles] |
|
|
|
|
|
confNodeId = nextFlowList[0].id |
|
|
array = [] |
|
|
array = [] |
|
|
if flow_approval.approvalFlow is not None: |
|
|
if flow_approval.approvalFlow is not None: |
|
|
array = json.loads(flow_approval.approvalFlow) |
|
|
array = json.loads(flow_approval.approvalFlow) |
|
|
|
|
|
if operate.operateType == 'success': |
|
|
|
|
|
nextFlow = [] |
|
|
|
|
|
for flowConf in flowConfList: |
|
|
|
|
|
parent = json.loads(flowConf.parent) |
|
|
|
|
|
if confNodeId in parent: |
|
|
|
|
|
nextFlow.append(flowConf) |
|
|
|
|
|
if len(nextFlow) > 0: |
|
|
|
|
|
edit.status = 'pending' # 有下一步执行人,则设置为 pending |
|
|
|
|
|
edit.nextStep = json.dumps([item.id for item in nextFlow]) |
|
|
|
|
|
edit.nextStepRole = json.dumps([item.code for item in nextFlow if item.type == 'Role']) |
|
|
|
|
|
edit.nextStepUser = json.dumps([item.code for item in nextFlow if item.type == 'User']) |
|
|
|
|
|
edit.currentNodeId = confNodeId |
|
|
|
|
|
else: |
|
|
|
|
|
edit.status = 'succeed' |
|
|
|
|
|
edit.currentNodeId = confNodeId |
|
|
|
|
|
edit.nextStep = '[]' |
|
|
|
|
|
edit.nextStepRole = '[]' |
|
|
|
|
|
edit.nextStepUser = '[]' |
|
|
|
|
|
if operate.operateType == 'reject': |
|
|
|
|
|
edit.status = 'rejected' |
|
|
|
|
|
edit.currentNodeId = confNodeId |
|
|
|
|
|
edit.nextStep = '[]' |
|
|
|
|
|
edit.nextStepRole = '[]' |
|
|
|
|
|
edit.nextStepUser = '[]' |
|
|
array.append({'operator': current_user.user.user_name, |
|
|
array.append({'operator': current_user.user.user_name, |
|
|
|
|
|
'confFlowId': confNodeId, |
|
|
'operateTime': datetime.now().strftime("%Y-%m-%d %H:%M:%S"), |
|
|
'operateTime': datetime.now().strftime("%Y-%m-%d %H:%M:%S"), |
|
|
'operate': operate.operateType, |
|
|
'operate': operate.operateType, |
|
|
'operateComment': operate.operateComment, |
|
|
'operateComment': operate.operateComment, |
|
|
}) |
|
|
}) |
|
|
edit = EditObjectModel() |
|
|
|
|
|
edit.id = flow_approval.id |
|
|
|
|
|
edit.approvalFlow = json.dumps(array) |
|
|
edit.approvalFlow = json.dumps(array) |
|
|
if operate.operateType == 'success': |
|
|
if flow_approval.businessType == 'metaDataInfo': |
|
|
# todo 增加流程配置,并查询出下一步操作人以及步骤 |
|
|
await cls.syncSuppInfo(result_db, flow_approval.businessId, edit.status) |
|
|
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 ApprovalDao.edit_flow_approval(result_db, edit.model_dump(exclude_unset=True)) |
|
|
await result_db.commit() |
|
|
await result_db.commit() |
|
|
return CrudResponseModel(is_success=True, message='操作成功') |
|
|
return CrudResponseModel(is_success=True, message='操作成功') |
|
@ -98,13 +121,37 @@ class ApprovalService: |
|
|
@classmethod |
|
|
@classmethod |
|
|
async def get_flow_list_services(cls, query_db: AsyncSession, query_param: ApprovalQueryObject, |
|
|
async def get_flow_list_services(cls, query_db: AsyncSession, query_param: ApprovalQueryObject, |
|
|
current_user: CurrentUserModel): |
|
|
current_user: CurrentUserModel): |
|
|
|
|
|
if query_param.status == 'waiting': |
|
|
result = await ApprovalDao.get_flow_list(query_db, query_param, current_user) |
|
|
result = await ApprovalDao.get_flow_list(query_db, query_param, current_user) |
|
|
return result |
|
|
return result |
|
|
|
|
|
if query_param.status == 'over': |
|
|
|
|
|
result = await ApprovalDao.get_owner_flow_list(query_db, query_param, current_user) |
|
|
|
|
|
return result |
|
|
|
|
|
return None |
|
|
|
|
|
|
|
|
@classmethod |
|
|
@classmethod |
|
|
async def get_waiting_total_services(cls, query_db: AsyncSession, current_user: CurrentUserModel): |
|
|
async def get_waiting_total_services(cls, query_db: AsyncSession, current_user: CurrentUserModel): |
|
|
result = await ApprovalDao.get_waiting_total(query_db, current_user) |
|
|
approval_list = await ApprovalDao.get_all_waitingOrPendingFlows(query_db) |
|
|
return result |
|
|
count = 0 |
|
|
|
|
|
for item in approval_list: |
|
|
|
|
|
nextRoles = json.loads(item.nextStepRole) |
|
|
|
|
|
nextUsers = json.loads(item.nextStepUser) |
|
|
|
|
|
if len(nextRoles)>0 and len(nextUsers) > 0: |
|
|
|
|
|
if current_user.user.user_name in nextUsers: |
|
|
|
|
|
count = count+1 |
|
|
|
|
|
break |
|
|
|
|
|
if any(element in set(current_user.roles) for element in nextRoles): |
|
|
|
|
|
count = count+1 |
|
|
|
|
|
break |
|
|
|
|
|
if len(nextRoles) > 0 and len(nextUsers) == 0: |
|
|
|
|
|
if any(element in set(current_user.roles) for element in nextRoles): |
|
|
|
|
|
count = count+1 |
|
|
|
|
|
break |
|
|
|
|
|
if len(nextRoles) == 0 and len(nextUsers) > 0: |
|
|
|
|
|
if current_user.user.user_name in nextUsers: |
|
|
|
|
|
count = count+1 |
|
|
|
|
|
break |
|
|
|
|
|
return count |
|
|
|
|
|
|
|
|
@classmethod |
|
|
@classmethod |
|
|
async def cancel_apply_services(cls, query_db: AsyncSession, flow_id: str, |
|
|
async def cancel_apply_services(cls, query_db: AsyncSession, flow_id: str, |
|
|