def check_valid(**kwargs): response = BaseResponse() try: result = models.AdminInfo.objects.get(**kwargs) response.status = True response.data = result except Exception, e: response.message = str(e)
def get_shutdown_lists_count(idc_id): ''' 获取关闭的工单个数 ''' response = BaseResponse() try: result = work_handle.get_shutdown_work_lists_count(idc_id) # j将搜索条件Q 传入其中 取出搜索到的数据的条数 response.data = result response.status = True except Exception, e: response.message = str(e)
def get_work_detail(nid): ''' 获取指定工单的详细信息 ''' response = BaseResponse() try: work_obj = work_handle.get_work_by_id(nid) # 根据id获取一条资产对象 result = {'work_msg': work_obj} response.status = True response.data = result except Exception, e: response.message = str(e)
def get_report(month_num): ''' 获取某个月份的运维报告数据 ''' response = BaseResponse() try: ret = pengboshi_handle.get_report_by_month(month_num) response.status = True response.data = list(ret) return response except Exception, e: response.message = str(e) return response
def get_over_lists_count(idc_id): ''' 获取已完成工单的个数 ''' # conditions = {'event_state__id': ['3']} response = BaseResponse() try: result = work_handle.get_over_work_count(idc_id) response.data = result response.status = True except Exception, e: response.message = str(e)
def get_over_work_lists(page_start, page_stop, idc_id): ''' 获取已完成工单的简要信息 ''' response = BaseResponse() try: values = ['id', 'work_id', 'work_title', 'operation_type__operation', 'specific__name', 'priority_level__priority', 'event_state__event_type', 'user__name', 'idc__name', 'add_time', 'over_time', 'event_state__event_mark', 'mail_re'] # 在这里定义好查询表时 需要筛选的字段 result = work_handle.get_over_work_list(page_start, page_stop, values, idc_id) # 搜索工单信息 result = list(result) response.data = result # 封装到对象中 response.status = True except Exception, e: response.message = str(e)
def change_work_state(state_str, work_id): response = BaseResponse() try: if state_str == 'running': work_handle.change_state_by_obj(state_str, work_id) elif state_str == 'finish': work_handle.change_state_by_obj(state_str, work_id) elif state_str == 'shutdown': work_handle.change_state_by_obj(state_str, work_id) response.status = 1 response.data = "OK" except Exception, e: response.message = str(e)
def get_asset_lists_count(conditions): ''' 获取搜索到资产的个数 ''' # conditions = {'event_state__id': ['3']} response = BaseResponse() try: con = Q() for k, v in conditions.items(): temp = Q() temp.connector = 'OR' for item in v: temp.children.append((k, item)) con.add(temp, 'AND') result = work_handle.get_work_lists_q_count(con) # j将搜索条件Q 传入其中 取出搜索到的数据的条数 response.data = result response.status = True except Exception, e: response.message = str(e)
def create_work(post_data): ''' 创建工单 中间处理层 将数据字典写入库 然后将结果返回 ''' response = BaseResponse() try: with transaction.atomic(): t = settings.now_time() post_data['add_time'] = t post_data['start_time'] = time.time() idc_id = post_data['idc_id'] # 获取idc的id 来获取邮箱地址 idc_email = work_handle.get_idc_email(idc_id) idc_email = dict(idc_email).get('email') work_obj = work_handle.create_new_work(post_data) # 将工单字典传入写库方法 response.status = True if response.status: order_dict = make_order_dict(post_data['work_id']) email_msg = "" for key, value in order_dict.items(): msg_ = key + ":" + str(value) + "\n" email_msg += msg_ title = order_dict.pop('work_title') task_obj = send_mail.apply_async(args=[title, email_msg, idc_email]) # 调用celery 执行任务 task_key = "celery-task-meta-%s" % task_obj.id work_handle.save_redis_key(work_obj.id, task_key) # 将数据库的id和 redis中任务的key存入表中 print "task_obj.id", task_obj.id, task_key re = get_task_re.apply_async(args=[str(task_key)], countdown=5) print "idddddddddddddddddddddddddddddddddd", re except Exception, e: print "mail_send mail error ::::::::", e response.message = str(e)
def get_work_lists(conditions, page_start, page_stop): ''' 获取工单的简要信息 ''' response = BaseResponse() try: values = ['id', 'work_id', 'work_title', 'operation_type__operation', 'specific__name', 'priority_level__priority', 'event_state__event_type', 'user__name', 'idc__name', 'add_time', 'over_time', 'event_state__event_mark', 'mail_re'] # 在这里定义好查询表时 需要筛选的字段 con = Q() for k, v in conditions.items(): # 循环搜索字典中的数据 temp = Q() # 创建一个综合搜索的对象 temp.connector = 'OR' # 设置关系为OR for item in v: # 遍历搜索字典中的value列表 temp.children.append((k, item)) con.add(temp, 'AND') # 将字典中的每种搜索条件关系设置为AND result = work_handle.get_work_list(page_start, page_stop, con, values) # 搜索工单信息 result = list(result) response.data = result # 封装到对象中 response.status = True except Exception, e: response.message = str(e)
def get_work_massage(work_id): ''' 获取工单的对话 根绝工单ID ''' response = BaseResponse() values = ['id', 'user_from__name', 'message', 'submit_time'] try: work_state = list(work_handle.get_work_state_by_id(work_id))[0] msg_obj = list(comment_handle.get_comment(work_id, values)) response.status = True response.data = msg_obj response.work_state = work_state except Exception, e: print "get_work_msg_______error", e response.message = str(e)
def add_work_massage(work_id, user_id, work_msg): ''' 获取工单的对话 根绝工单ID ''' response = BaseResponse() if len(work_msg.strip()) == 0: response.status = True response.data = 1 return response try: with transaction.atomic(): work_msg.replace('\r\n', '<br />') data_dict = {} t = settings.now_time() data_dict['user_from_id'] = user_id data_dict['work_from_id'] = work_id data_dict['message'] = work_msg data_dict['submit_time'] = t comment_handle.add_comment(data_dict) response.status = True response.data = 1 except Exception, e: print "create_______error", e response.message = str(e)