Beispiel #1
0
 def add_workflow(cls, name: str, description: str, notices: str, view_permission_check: int, limit_expression: str,
                  display_form_str: str, creator: str, workflow_admin: str, title_template: str,
                  content_template: str)->tuple:
     """
     新增工作流
     add workflow
     :param name:
     :param description:
     :param notices:
     :param view_permission_check:
     :param limit_expression:
     :param display_form_str:
     :param creator:
     :param workflow_admin:
     :param title_template:
     :param content_template:
     :return:
     """
     workflow_obj = Workflow(name=name, description=description, notices=notices,
                             view_permission_check=view_permission_check, limit_expression=limit_expression,
                             display_form_str=display_form_str, creator=creator, title_template=title_template,
                             content_template=content_template)
     workflow_obj.save()
     workflow_admin_insert_list = []
     if workflow_admin:
         for username in workflow_admin.split(','):
             workflow_admin_insert_list.append(WorkflowAdmin(
                 workflow_id=workflow_obj.id, username=username, creator=creator))
         WorkflowAdmin.objects.bulk_create(workflow_admin_insert_list)
     return True, dict(workflow_id=workflow_obj.id)
    def edit_workflow(cls, workflow_id: int, name: str, description: str,
                      notices: str, view_permission_check: int,
                      limit_expression: str, display_form_str: str,
                      workflow_admin: str) -> tuple:
        """
        更新工作流
        update workfow
        :param workflow_id:
        :param name:
        :param description:
        :param notices:
        :param view_permission_check:
        :param limit_expression:
        :param display_form_str:
        :param workflow_admin:
        :return:
        """
        workflow_obj = Workflow.objects.filter(id=workflow_id, is_deleted=0)
        if workflow_obj:
            workflow_obj.update(name=name,
                                description=description,
                                notices=notices,
                                view_permission_check=view_permission_check,
                                limit_expression=limit_expression,
                                display_form_str=display_form_str)
        # 更新工作流管理员
        if workflow_admin:
            workflow_admin_list = workflow_admin.split(',')
            # 查询已经存在的记录
            workflow_admin_existed_queryset = WorkflowAdmin.objects.filter(
                workflow_id=workflow_id,
                username__in=workflow_admin_list,
                is_deleted=0).all()
            workflow_admin_existed_list = [
                workflow_admin_existed.username
                for workflow_admin_existed in workflow_admin_existed_queryset
            ]
            # 删除移除掉的
            WorkflowAdmin.objects.filter(workflow_id=workflow_id, is_deleted=0)\
                .exclude(username__in=workflow_admin_list).update(is_deleted=1)

            # 新增新添加的
            workflow_admin_need_add_list = list(
                set(workflow_admin_list) - set(workflow_admin_existed_list))
            workflow_admin_need_add_insert_list = []
            for workflow_admin_need_add in workflow_admin_need_add_list:
                workflow_admin_need_add_insert_list.append(
                    WorkflowAdmin(workflow_id=workflow_id,
                                  username=workflow_admin_need_add))
            WorkflowAdmin.objects.bulk_create(
                workflow_admin_need_add_insert_list)

        else:
            # 删除所有记录
            WorkflowAdmin.objects.filter(workflow_id=workflow_id,
                                         is_deleted=0).update(is_deleted=1)

        return True, ''