Ejemplo n.º 1
0
 def post(self, request):
     """
     发送微信消息
     """
     if request.data.get('key') == 'cb8e30682b927f35':
         MessageObject.send(title=request.data.get('title'), user_list=request.data.get('user_list').split(","),
                            msg=request.data.get('message'), send_mode=['users'])
         return Response({"status": True, "message": "成功", "data": {}})
     else:
         return Response({"status": False, "message": "key错误", "data": {}})
Ejemplo n.º 2
0
 def notice_bigdata(db_change_order_ids, step):
     big_data_need = [
         "数据库IP更换",
         "数据表字段类型变更",
         "数据表字段删除",
         "数据表字段用途变更(比如存放值的逻辑变动)",
     ]
     user_list = ['卢春洋', '程鹏', '吴绍杰']
     for db_change_order_id in db_change_order_ids:
         dbchangeorder = DBChangeOrder.objects.get(id=db_change_order_id)
         user_list = ['程俊杰', '程鹏', '丁金梁', '申俊伯', '王红卫', '吴绍杰']
         MessageObject.send(
             title='TMS 数据库变更通知',
             user_list=user_list,
             msg=f"【{step}】{dbchangeorder.title}",
             forward=f"/database/audit/detail/{db_change_order_id}",
             send_mode=['users'])
Ejemplo n.º 3
0
    def get(self, request):
        """
        上线完成后,针对昨天之前没有验收的单子进行提醒
        """

        orders = OnlineOrder.objects.filter(
            delete=1,
            status='上线完成',
            real_online_time__lt=datetime.datetime.now().strftime("%Y-%m-%d"))
        for order in orders:
            MessageObject.send(
                title='TMS 验收提醒',
                user_list=json.loads(order.product_users),
                msg=f"【{order.status}-等待确认】【{order.system}】{order.title}",
                forward=f"/flow/online/detail/{order.id}",
                send_mode=['users'])
        return Response({
            "status": True,
            "message": "成功",
            "data": orders.count()
        })
Ejemplo n.º 4
0
    def put(self, request, id):
        """
        修改一个上线单的内容
        """
        myonlineorder = self.get_object(id=id, delete=1)
        myonlineorder_old = self.get_object(id=id, delete=1)

        send_message_flag = False

        # 1. 修改保存的上线流程
        request = OnlineOrderFlowObject().put(request, myonlineorder.id)

        # 2. 修改关联的提测单状态为  “已上线”
        if request.data[
                'status'] and myonlineorder.status != request.data['status']:
            print(request.data['status'])
            # 暂存data
            request_data = request.data.copy()
            # 进入这里,修改提测单状态
            if request.data['status'] == '上线完成':
                for testtask_id in json.loads(myonlineorder.testtask):
                    request.data.clear()
                    request.data['status'] = '已上线'
                    TestTaskDetail().put(request, testtask_id)
            # 还原data
            for (k, v) in request_data.items():
                request.data[k] = v

            # 发消息通知状态
            send_message_flag = True
        else:
            del request.data['status']

        # 3. 保存上线单
        serializer = OnlineOrderSerializer(myonlineorder, data=request.data)
        if not serializer.is_valid():
            return Response({
                "status": False,
                "message": "数据格式不正确",
                "data": serializer.errors
            })
        serializer.save()

        # 4. 保存操作记录
        change_data = request.data.copy()
        del change_data['onlineorderflow']
        del change_data['dev_users']
        del change_data['test_users']
        del change_data['product_users']
        keys = list(change_data.keys())
        print(keys)
        if 'onlineorderflow' in keys: keys.remove('onlineorderflow')
        old_content = [
            myonlineorder_old.__getattribute__(filed) for filed in keys
        ]
        if len(keys) > 0:
            OnlineOrderOperation.objects.create(
                onlineorder_id=myonlineorder.id,
                username=request.session['user'].get('username'),
                realname=request.session['user'].get('realname'),
                change_fields=list(change_data.keys()),
                old_content=old_content,
                new_content=list(change_data.values()),
                change_action=self.actions(list(change_data.keys()),
                                           list(change_data.values())))

        # 5.发现企业消息
        if send_message_flag:
            if serializer.data.get('status') == '上线完成':
                print('发给相关人员+流程负责人+部门领导+cto')
                user_list = json.loads(serializer.data.get("users"))
                user_list += json.loads(serializer.data.get("dev_users"))
                user_list += json.loads(serializer.data.get("test_users"))
                user_list += json.loads(serializer.data.get("product_users"))
                send_mode = ['users', 'leaders', 'CTO']

            elif serializer.data.get('status') == '验收完成':
                print('发给相关人员+流程负责人+部门领导')
                user_list = json.loads(serializer.data.get("users"))
                user_list += json.loads(serializer.data.get("dev_users"))
                user_list += json.loads(serializer.data.get("test_users"))
                user_list += json.loads(serializer.data.get("product_users"))
                send_mode = ['users', 'leaders']
            else:
                print('只发给上线流程中的负责人')
                user_list = json.loads(serializer.data.get("dev_users"))
                user_list += json.loads(serializer.data.get("test_users"))
                user_list += json.loads(serializer.data.get("product_users"))
                send_mode = ['users']

            MessageObject.send(
                title='TMS 上线提醒',
                user_list=user_list,
                msg=
                f"【{serializer.data.get('status')}】【{serializer.data.get('system')}】{serializer.data.get('title')}",
                forward=f"/flow/online/detail/{serializer.data.get('id')}",
                send_mode=send_mode)

        return Response({
            "status": True,
            "message": "成功",
            "data": serializer.data
        })
Ejemplo n.º 5
0
    def post(self, request):
        """
        上线单新增
        """

        print(request.data)

        # 1. 检查传入的参数,并保存
        request.data['status'] = '发起上线'
        serializer = OnlineOrderSerializer(data=request.data)
        if not serializer.is_valid():
            return Response({
                "status": False,
                "message": "数据格式不正确",
                "data": serializer.errors
            })
        serializer.save()

        # 2. 记录操作记录
        OnlineOrderOperation.objects.create(
            onlineorder_id=serializer.data.get('id'),
            username=request.session['user'].get('username'),
            realname=request.session['user'].get('realname'),
            change_action='发起上线流程')

        # 3. 记录上线流程
        request = OnlineOrderFlowObject().post(request,
                                               serializer.data.get('id'))

        # 4.更新负责人
        myOnlineOrder = OnlineOrder.objects.get(id=serializer.data.get('id'))
        serializer = OnlineOrderSerializer(myOnlineOrder, data=request.data)
        if not serializer.is_valid():
            return Response({
                "status": False,
                "message": "数据格式不正确",
                "data": serializer.errors
            })
        serializer.save()

        # 5.发现企业消息 ,发给相关人员+部门领导
        print('发给相关人员+流程负责人+部门领导')
        user_list = json.loads(serializer.data.get("users"))
        user_list += json.loads(serializer.data.get("dev_users"))
        user_list += json.loads(serializer.data.get("test_users"))
        user_list += json.loads(serializer.data.get("product_users"))
        MessageObject.send(
            title='TMS 上线提醒',
            user_list=user_list,
            msg=
            f"【{serializer.data.get('status')}】【{serializer.data.get('system')}】{serializer.data.get('title')}",
            forward=f"/flow/online/detail/{serializer.data.get('id')}",
            send_mode=['users', 'leaders'])

        # 异步数据库变更通知大数据
        for testtask_id in json.loads(myOnlineOrder.testtask):
            myTestTask = TestTask.objects.get(id=testtask_id)
            if int(myTestTask.version) <= 1:
                continue
            # db_change_order_ids = json.loads(myTestTask.sql_files)
            # threading.Thread(target=views_dbchange.DBChangeOrderAuditRecordObject().notice_bigdata,
            #                  args=(db_change_order_ids, '上线阶段',)).start()

            for version_id in json.loads(myTestTask.version_id):
                request.data.clear()
                request.data['id'] = version_id
                request.data['stage'] = '6'
                request.data['status'] = '进行中'
                UpdateVersionStage().put(request, version_id)

        return Response({
            "status": True,
            "message": "成功",
            "data": serializer.data
        })
Ejemplo n.º 6
0
    def post(self, request):
        """
        提测单新增
        """
        # 1. 检查传入的参数,并保存
        print(request.data)
        request.data['status'] = '已提测'
        serializer = TestTaskSerializer(data=request.data)
        if not serializer.is_valid():
            return Response({
                "status": False,
                "message": "数据格式不正确",
                "data": serializer.errors
            })
        serializer.save()

        # 2. 保留一份历史版本
        serializer_history = TestTaskHistorySerializer(data=request.data)
        serializer_history.is_valid() and serializer_history.save()

        # 3. 记录操作记录
        TestTaskOperation.objects.create(
            testtask_id=serializer.data.get('id'),
            username=request.session['user'].get('username'),
            realname=request.session['user'].get('realname'),
            current_version=serializer_history.data.get('id'),
            change_action='创建提测单并提测')

        # 4.发现企业消息
        user_list = json.loads(serializer.data.get("test_users"))
        user_list += json.loads(serializer.data.get("product_users"))
        user_list += json.loads(serializer.data.get("dev_users"))
        MessageObject.send(
            title='TMS 提交测试',
            user_list=user_list,
            msg=
            f"【{serializer.data.get('status')}】{serializer.data.get('title')}",
            forward=f"/flow/testtask/detail_v4/{serializer.data.get('id')}",
            send_mode=['users', 'leaders'])

        # 异步数据库变更通知大数据
        db_change_order_ids = json.loads(serializer.data.get("sql_files"))
        threading.Thread(target=views_dbchange.DBChangeOrderAuditRecordObject(
        ).notice_bigdata,
                         args=(
                             db_change_order_ids,
                             '提测阶段',
                         )).start()

        # 关联的版本更新为测试中
        for version_id in json.loads(serializer.data.get("version_id")):
            request.data.clear()
            request.data['id'] = version_id
            request.data['stage'] = '5'
            request.data['status'] = '进行中'
            UpdateVersionStage().put(request, version_id)

        return Response({
            "status": True,
            "message": "成功",
            "data": serializer.data
        })
Ejemplo n.º 7
0
    def put(self, request, id):
        """
        修改一个变更单的所有审核记录
        """
        serializer_record = DBChangeAuditRecordSerializer(
            data={
                'dbchangeorder_id': id,
                'content': request.data.get('content'),
                'status': request.data.get('status'),
                'username': request.session['user'].get('username'),
                'realname': request.session['user'].get('realname'),
                'new_dbchangehistory_id': '[]',
                'old_dbchangehistory_id': '[]'
            })
        if not serializer_record.is_valid():
            return Response({
                "status": False,
                "message": "数据格式不正确",
                "data": serializer_record.errors
            })
        serializer_record.save()

        if request.data.get('status') == '审核通过':
            status = '已通过'
        elif request.data.get('status') == '审核不通过':
            status = '不通过'
        elif request.data.get('status') == '已上线':
            status = '已上线'
        else:
            status = '未知'

        order = DBChangeOrder.objects.get(id=id)
        order.status = status
        order.save()

        if status == '已通过':
            # 异步处理分析sql
            threading.Thread(target=self.update_notice,
                             args=(
                                 order.dbchange_ids,
                                 id,
                             )).start()

        if status == '已上线':
            order.online_time = datetime.datetime.now()
            order.save()

        # 3.发送企业消息
        if order.status == '已通过':
            user_list = [order.submit_user]
            MessageObject.send(title='TMS 数据库审核',
                               user_list=user_list,
                               msg=f"【{order.status}】{order.title}",
                               forward=f"/database/audit/detail/{order.id}",
                               send_mode=['users', 'leaders'])
            user_list = json.loads(order.cc_users)
            MessageObject.send(title='TMS 数据库审核',
                               user_list=user_list,
                               msg=f"【{order.status}】{order.title}",
                               forward=f"/database/audit/detail/{order.id}",
                               send_mode=['users'])

        if order.status == '不通过':
            user_list = [order.submit_user]
            MessageObject.send(title='TMS 数据库审核',
                               user_list=user_list,
                               msg=f"【{order.status}】{order.title}",
                               forward=f"/database/audit/detail/{order.id}",
                               send_mode=['users', 'leaders'])

        return Response({
            "status": True,
            "message": "成功",
            "data": serializer_record.data
        })
Ejemplo n.º 8
0
    def put(self, request, id):
        """
        修改一个变更单的内容
        """
        dbchange_ids_raw = json.loads(request.data.get('dbchange_ids'))
        dbchange_ids = [int(x) for x in dbchange_ids_raw if int(x) > 0]
        dbchange_ids_add = [
            abs(int(x)) for x in dbchange_ids_raw if str(x).startswith('+')
        ]
        dbchange_ids_delete = [
            abs(int(x)) for x in dbchange_ids_raw if str(x).startswith('-')
        ]
        dbchange_ids_modify = [
            abs(int(x)) for x in dbchange_ids_raw if str(x).startswith('0')
        ]

        new_dbchangehistory_id = []
        old_dbchangehistory_id = []
        for dbchange_id in dbchange_ids_raw:
            if str(dbchange_id).startswith('+'):
                old_dbchangehistory_id.append(0)
                new_dbchangehistory_id.append(
                    DBChangeHistory.objects.filter(
                        dbchange_id=abs(int(dbchange_id)),
                        delete=1).order_by('-id')[0].id)
            elif str(dbchange_id).startswith('-'):
                old_dbchangehistory_id.append(
                    DBChangeHistory.objects.filter(
                        dbchange_id=abs(int(dbchange_id)),
                        delete=1).order_by('-id')[0].id)
                new_dbchangehistory_id.append(0)
            elif str(dbchange_id).startswith('0'):
                old_dbchangehistory_id.append(
                    DBChangeHistory.objects.filter(
                        dbchange_id=abs(int(dbchange_id)),
                        delete=1).order_by('-id')[1].id)
                new_dbchangehistory_id.append(
                    DBChangeHistory.objects.filter(
                        dbchange_id=abs(int(dbchange_id)),
                        delete=1).order_by('-id')[0].id)

        dbchange_delete = []
        dbchange_add = []
        dbchange_modify = []

        for iid in dbchange_ids_delete:
            dbchange_delete.append(DBChange.objects.get(id=iid).database)
        for iid in dbchange_ids_add:
            dbchange_add.append(DBChange.objects.get(id=iid).database)
        for iid in dbchange_ids_modify:
            dbchange_modify.append(DBChange.objects.get(id=iid).database)

        content = []
        if len(dbchange_delete) > 0:
            content.append(f"删除--->{','.join(dbchange_delete)}")
        if len(dbchange_add) > 0:
            content.append(f"新增--->{','.join(dbchange_add)}")
        if len(dbchange_modify) > 0:
            content.append(f"修改--->{','.join(dbchange_modify)}")
        content = '\n'.join(content)

        # 1. 检查传入的参数,并保存
        mydbchangeorder = DBChangeOrder.objects.get(id=id, delete=1)
        request.data['dbchange_ids'] = json.dumps(dbchange_ids)
        request.data['status'] = '待审核'
        serializer = DBChangeOrderSerializerModifyParam(mydbchangeorder,
                                                        data=request.data)
        if not serializer.is_valid():
            return Response({
                "status": False,
                "message": "数据格式不正确",
                "data": serializer.errors
            })
        serializer.save()

        # 2. 操作记录
        serializer_record = DBChangeAuditRecordSerializer(
            data={
                'dbchangeorder_id': serializer.data.get('id'),
                'content': content,
                'status': '修改变更单并重新提交',
                'username': request.session['user'].get('username'),
                'realname': request.session['user'].get('realname'),
                'new_dbchangehistory_id': json.dumps(new_dbchangehistory_id),
                'old_dbchangehistory_id': json.dumps(old_dbchangehistory_id)
            })
        if not serializer_record.is_valid():
            return Response({
                "status": False,
                "message": "数据格式不正确",
                "data": serializer_record.errors
            })
        serializer_record.save()

        # 3.发送企业消息
        user_list = [mydbchangeorder.submit_user]
        MessageObject.send(
            title='TMS 数据库审核',
            user_list=user_list,
            msg=f"【修改并重新提交】{mydbchangeorder.title}",
            forward=f"/database/audit/detail/{mydbchangeorder.id}",
            send_mode=['users', 'leaders'])

        user_list = json.loads(mydbchangeorder.check_users)
        MessageObject.send(
            title='TMS 数据库审核',
            user_list=user_list,
            msg=f"【修改并重新提交】{mydbchangeorder.title}",
            forward=f"/database/audit/detail/{mydbchangeorder.id}",
            send_mode=['users'])

        return Response({
            "status": True,
            "message": "成功",
            "data": serializer.data
        })
Ejemplo n.º 9
0
    def post(self, request):
        """
        新增一个数据库变更单
        """
        # 1. 检查传入的参数,并保存
        request.data['status'] = '待审核'
        request.data['submit_user'] = request.session['user'].get('realname')
        request.data['dbchange_ids'] = json.dumps([
            abs(int(x)) for x in json.loads(request.data.get('dbchange_ids'))
        ])
        serializer = DBChangeOrderSerializer(data=request.data)
        if not serializer.is_valid():
            return Response({
                "status": False,
                "message": "数据格式不正确",
                "data": serializer.errors
            })
        serializer.save()

        # 2. 操作记录

        serializer_record = DBChangeAuditRecordSerializer(
            data={
                'dbchangeorder_id': serializer.data.get('id'),
                'content': '',
                'status': '提交变更单',
                'username': request.session['user'].get('username'),
                'realname': request.session['user'].get('realname')
            })
        if not serializer_record.is_valid():
            return Response({
                "status": False,
                "message": "数据格式不正确",
                "data": serializer_record.errors
            })
        serializer_record.save()

        # 3.发送企业消息
        user_list = [serializer.data.get("submit_user")]
        MessageObject.send(
            title='TMS 数据库审核',
            user_list=user_list,
            msg=
            f"【{serializer.data.get('status')}】{serializer.data.get('title')}",
            forward=f"/database/audit/detail/{serializer.data.get('id')}",
            send_mode=['users', 'leaders'])
        print(serializer.data)
        user_list = json.loads(serializer.data.get("check_users"))
        MessageObject.send(
            title='TMS 数据库审核',
            user_list=user_list,
            msg=
            f"【{serializer.data.get('status')}】{serializer.data.get('title')}",
            forward=f"/database/audit/detail/{serializer.data.get('id')}",
            send_mode=['users'])

        return Response({
            "status": True,
            "message": "成功",
            "data": serializer.data
        })