def put(self, request, pk): logger.info(f"batch任务 >>>>>> 修改设定,入参:设定ID:{pk}") logger.info(f"batch任务 >>>>>> 修改设定,入参:{request.data}") try: format_request_data = { 'batch_desc': request.data.get('batch_desc', None), "batch_group_name": request.data.get('batch_group_name', None), "batch_param": request.data.get('batch_param', None), 'batch_job_name': request.data.get('batch_job_name', None), 'clean_table': json.dumps(request.data['batch_data']['clean']['table']), 'ready_table': json.dumps(request.data['batch_data']['ready']['table']), 'assert_table': json.dumps(request.data['batch_data']['assert']['table']), } except Exception as e: logger.error(repr(e)) return Response(BaseResponse(code=400, message=repr(e)).context()) else: serializer = ScheduleConfigSerializer( ScheduleConfig.objects.get(id=pk), data=format_request_data) if serializer.is_valid(): serializer.save() return Response(BaseResponse(message="修改成功").context()) return Response( BaseResponse(code=500, message=serializer.errors).context())
def get(self, request): id_number = request.query_params['idNumber'] if len(id_number) != 15 and len(id_number) != 18: return Response(BaseResponse(code=400, message='身份证号码位数至少15位或18位!').context()) serializer = IdNumberSerializer(IdNumberEnity(id=id_number)) return Response(BaseResponse(data=serializer.data).context())
def get(self, request): """获取指定日期的验证数据""" date = request.GET.get('date', None) if date is None: return Response(BaseResponse(code=400, message="日期必填!").context()) return Response( BaseResponse( data=smh().filter_schedule_result_by_date(date)).context())
def get(self, request): """获取指定日期的验证数据""" dispatch_no = request.GET.get('dispatch_no', None) if dispatch_no is None or dispatch_no == '': return Response( BaseResponse(code=400, message="任务号必填!!!").context()) return Response( BaseResponse(data=smh().filter_report_by_dispatch_no( dispatch_no)).context())
def post(self, request): case_id = request.POST.get('case_id', None) sfh = ScheduleFlowHandler(case_id) # 执行任务流 flag, message = sfh.flow_control() if flag is False: return Response(BaseResponse(message=message).context()) return Response(BaseResponse(message="任务调度成功").context())
def get(self, request): """两个日期相差时间天数计算接口""" begin_date = request.query_params['begin_date'] end_date = request.query_params['end_date'] if begin_date is None or begin_date == 'Invalid Date': return Response(BaseResponse(code=400, message='开始时间不能为空!').context()) if end_date is None or end_date == 'Invalid Date': return Response(BaseResponse(code=400, message='结束时间不能为空!').context()) data = CommonUtil().get_date_interval(begin_date, end_date) return Response(BaseResponse(data=data).context())
def get(self, request): """date推算接口""" date = request.query_params['date'] days = request.query_params['days'] if date is None or date == 'Invalid Date': return Response(BaseResponse(code=400, message='基础日期不能为空!').context()) if days is None or days == 'NaN': return Response(BaseResponse(code=400, message='天数不能为空!').context()) data = CommonUtil().get_date_extrapolation(date, int(days)) return Response(BaseResponse(data=data).context())
def get(self, request): id_number = request.query_params['idNumber'] if len(id_number) != 15 and len(id_number) != 18: return Response(BaseResponse(code=400, message='身份证号码位数至少15位或18位!').context()) serializer = IdNumberSerializer(IdNumberEnity(id=id_number)) id_info = serializer.data print(serializer.data) if id_info['facticity'] == '无效': return Response(BaseResponse(code=400, message='身份证无效,请检查!').context()) birth = id_info['birthday'].split('-') age = id_info['age'] # 有效期判断 # if 16 <= age <= 25: # effect_age = 10 # elif 26 <= age <= 45: # effect_age = 20 # else: # effect_age = 100 image_path = IdCardUtil().generator( name='张三', sex=id_info['sex'], nation='汉', year=birth[0], mon=birth[1], day=birth[2], addr=id_info['area_name'] + '大世界街287号', idn=id_number, org=id_info['area_name'], life=birth[0] + '.' + birth[1] + '.' + birth[2] + '-' + str(int(birth[0]) + 40) + '.' + birth[1] + '.' + birth[2], ) if image_path[0]: return Response(BaseResponse(data=f'http://XX.XX.XX.XX:4396/image/{image_path[1]}').context()) else: return Response(BaseResponse(code=400, message='身份证图片生成失败').context())
def post(self, request): age = request.data.get('age', 18) sex = request.data.get('sex', 0) area_id = request.data.get('area_id', None) age = int(age) sex = int(sex) if age == '' or sex == '': return Response(BaseResponse(code=400, message='年龄或性别不能为空!').context()) if age > 500: return Response(BaseResponse(code=400, message='最大500岁哦').context()) return Response(BaseResponse(data=IdNumber.generate_id(sex=sex, age=age, area_id=area_id)).context())
def get(self, request): """获取全部域""" result = ProjectDetail.objects.all() serializer = ProjectDetailSerializer(result, many=True) return Response(BaseResponse(data=serializer.data).context())
def get(self, request): """获取所有设定""" result = ScheduleConfig.objects.all() serializer = ScheduleConfigSerializer(result, many=True) return Response(BaseResponse(data=serializer.data).context())
def get(self, request): logger.info(">>>获取用户信息接口") username = request.successful_authenticator.get_user( request.successful_authenticator.get_validated_token( request.successful_authenticator.get_raw_token(request.successful_authenticator.get_header(request)))) return Response(BaseResponse(data=str(username)).context())
def put(self, request, pk): """修改对应的项目详情""" logger.info(f"项目模块 >>>>>> 修改对应项目,入参:项目ID:{pk}") logger.info(f"项目模块 >>>>>> 修改对应项目,入参:{request.data}") result = ModelUtil(ProjectDetail).check_data_exist(id=pk) if result[0] is False: return Response( BaseResponse(code=500, message="无对应项目详情id,请检查").context()) serializer = ProjectDetailSerializer(result[1], data=request.data) if serializer.is_valid(): serializer.save() return Response(BaseResponse().context()) return Response( BaseResponse(code=500, message=serializer.errors).context())
def get(self, request): """获取项目进度看板数据""" start_date, end_date = request.GET.get("start_date", None), request.GET.get( "end_date", None) # 使用date查询需要多+1天,否则会漏掉最后一天的数据 end_date = (datetime.datetime.strptime(end_date, "%Y-%m-%d") + datetime.timedelta(days=1)).strftime("%Y-%m-%d") bi_data = [] # 三维数组 # 先获取项目域 project_areas = ProjectArea.objects.all() for project_area in project_areas: project_area_name = project_area.name project_area_id = project_area.id projects_result = [] # 获取时间段内的项目详情 project_details = ProjectDetail.objects.filter( project_area_id=project_area_id, gmt_modified__range=(start_date, end_date)) for project_detail in project_details: project_detail_name = project_detail.name project_detail_id = project_detail.id project_process_result = [] project_process_s = ProjectProgress.objects.filter( project_detail_id=project_detail_id, gmt_modified__range=(start_date, end_date)) for project_process in project_process_s: project_process_result.append( model_to_dict(project_process)) if project_process_result: project_dict = { 'name': project_detail_name, 'monitors': project_process_result } projects_result.append(project_dict) if projects_result: ares_result = { 'name': project_area_name, 'projects': projects_result } bi_data.append(ares_result) return Response(BaseResponse(data=bi_data).context())
def post(self, request): """ 新增项目 """ logger.info(f"项目模块 >>>>>> 新增项目,入参:{request.data}") if ModelUtil(ProjectArea).check_data_exist( id=request.data['project_area_id'])[0] is False: return Response( BaseResponse(code=500, message="无对应项目域id,请检查").context()) serializer = ProjectDetailSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(BaseResponse().context()) return Response( BaseResponse(code=500, message=serializer.errors).context())
def put(self, request, pk): """修改对应项目进度""" logger.info(f"项目进度模块 >>>>>> 修改对应项目进度,入参:项目ID:{pk}") logger.info(f"项目进度模块 >>>>>> 修改对应项目进度,入参:{request.data}") result = ModelUtil(ProjectProgress).check_data_exist(id=pk) if result[0] is False: return Response( BaseResponse(code=500, message="无对应项目进度id,请检查").context()) serializer = ProjectProgressSerializer(result[1], data=request.data) if serializer.is_valid(): serializer.save() ProjectModelUtil().check_process_stage_and_change_project_status( request.data['project_detail_id']) return Response(BaseResponse().context()) return Response( BaseResponse(code=500, message=serializer.errors).context())
def delete(self, request, pk, format=None): """删除对应项目""" query_data = ModelUtil(ProjectProgress).check_data_exist(id=pk) # 对应项目是否存在检查 if query_data[0] is False: return Response( BaseResponse(code=500, message="对应项目进度不存在或已删除,请检查").context()) else: project_detail_id = ProjectProgressSerializer( query_data[1], many=False).data['project_detail_id'] query_data[1].delete() logger.info( f"项目进度模块 >>>>>> 删除对应项目进度成功,项目详情:{ProjectProgressSerializer(query_data[1]).data}" ) ProjectModelUtil().check_process_stage_and_change_project_status( project_detail_id) return Response(BaseResponse().context())
def post(self, request): """ 新增项目 """ logger.info(f"项目进度模块 >>>>>> 新增项目进度,入参:{request.data}") if ModelUtil(ProjectDetail).check_data_exist( id=request.data['project_detail_id'])[0] is False: return Response( BaseResponse(code=500, message="无对应项目详情id,请检查").context()) serializer = ProjectProgressSerializer(data=request.data) if serializer.is_valid(): serializer.save() ProjectModelUtil().check_process_stage_and_change_project_status( request.data['project_detail_id']) return Response(BaseResponse().context()) return Response( BaseResponse(code=500, message=serializer.errors).context())
def get(self, request): data = { "case_priority": case_priority, "case_status": case_status, "area_info": const.AREA_INFO, } conf = CamusConfig.objects.all() # searlizer = CamusConfigSerializer(conf, many=True) for sql_result in conf: for key, value in sql_result.to_json().items(): data[key] = value return Response(BaseResponse(data=data).context())
def delete(self, request, pk, format=None): """删除对应项目""" query_data = ModelUtil(ProjectDetail).check_data_exist(id=pk) # 对应项目是否存在检查 if query_data[0] is False: return Response( BaseResponse(code=500, message="对应项目不存在或已删除,请检查").context()) # query_data[1].delete() request.data['status'] = -1 serializer = ProjectDetailSerializer(query_data[1], data=request.data) if serializer.is_valid(): serializer.save() logger.info( f"项目模块 >>>>>> 删除对应项目成功,项目详情:{ProjectDetailSerializer(query_data[1]).data}" ) return Response(BaseResponse().context()) return Response( BaseResponse(code=500, message=serializer.errors).context())
def get(self, request, pk): """获取对应项目域下的所有项目""" result = ProjectDetail.objects.filter(project_area_id=pk) current_week = CommonUtil().get_current_week() query_final_result = [] for query in result: # 放行状态为 0进行中 和 本周内状态为 -1异常 或 1已完成 的项目 if (query.status == -1 or query.status == 1) and (current_week[0] <= query.gmt_modified.date() <= current_week[1]): query_final_result.append(query) elif query.status == 0: query_final_result.append(query) else: pass serializer = ProjectDetailSerializer(query_final_result, many=True) return Response(BaseResponse(data=serializer.data).context())
def get(self, request, pk): """获取对应项目详情下的所有项目进度""" result = ProjectProgress.objects.filter(project_detail_id=pk) serializer = ProjectProgressSerializer(result, many=True) return Response(BaseResponse(data=serializer.data).context())
def get(self, request): query_data = UserModel.objects.all() serializer = UserSerializer(query_data, many=True) return Response(BaseResponse(data=serializer.data).context())
def post(self, request): """ 新增设定 """ logger.info(f"增加case >>>>>> 新增设定,入参:{request.data}") format_request_data = { 'batch_group_name': request.data.get('batch_group_name', None), "batch_group_desc": request.data.get('batch_group_desc', None), 'job': request.data.get('job', None), } model_handler = smh() old_seq_no = model_handler.get_seq_no() config_data = [] try: for jobs_info in format_request_data['job']: data = { "case_id": str(old_seq_no + 1).zfill(7), "batch_group_name": format_request_data['batch_group_name'], "batch_group_desc": format_request_data['batch_group_desc'], "pacakge_name": jobs_info['pacakge_name'], "batch_job_name": jobs_info['batch_job_name'], "batch_job_desc": jobs_info['batch_job_desc'], "batch_job_param": jobs_info['batch_job_param'], "priority": jobs_info['priority'], "clean_table": json.dumps(jobs_info['batch_data']['clean']['table']), "ready_table": json.dumps(jobs_info['batch_data']['ready']['table']), "assert_table": json.dumps(jobs_info['batch_data']['assert']['table']), } schedule_config_serializer = ScheduleConfigSerializer( data=data) if schedule_config_serializer.is_valid(): config_data.append( ScheduleConfig(**schedule_config_serializer.data)) else: logger.error( f"增加case >>>>>> 序列化失败 {schedule_config_serializer.errors}" ) return Response( BaseResponse( code=400, message= f"增加case >>>>>> 序列化失败 {schedule_config_serializer.errors}" ).context()) except Exception as e: logger.error(repr(e)) return Response(BaseResponse(code=400, message=repr(e)).context()) try: # 批量写入表中 ScheduleConfig.objects.bulk_create(config_data) except Exception as e: logger.error(repr(e)) return Response( BaseResponse( code=400, message=f"增加case >>>>>> 批量写入表失败 {repr(e)}").context()) else: if model_handler.set_seq_no(old_seq_no): return Response( BaseResponse(message="增加case >>>>>> 新增设定成功").context())
def post(self, request): """对已clean和已ready的任务进行验证数据""" batch_job_name = request.POST.get('batch_job_name', None) logger.info(f"batch任务 >>>>>> 数据验证接口,入参:{batch_job_name}") model_handler = smh() # 验证全部任务 if batch_job_name == '' or batch_job_name is None: logger.info(f"batch任务 >>>>>> 验证批量任务") # 任务调度增加一条主任务 no_asserted_dispatch = model_handler.get_all_no_asserted_dispatch({ "is_assert": False, "is_clean": True, "is_ready": True }) else: logger.info(f"batch任务 >>>>>> 验证单个任务") # 任务调度增加一条主任务 config_data = model_handler.get_schedule_config( {"batch_job_name": batch_job_name}) no_asserted_dispatch = smh().get_all_no_asserted_dispatch({ "is_assert": False, "schedule_config_id": config_data.id, "is_clean": True, "is_ready": True }) logger.info( f"batch任务 >>>>>> 数据验证, 总共需要验证 {len(no_asserted_dispatch)} 个任务") if len(no_asserted_dispatch) == 0: return Response( BaseResponse(code=400, message="无对应未完成的验证任务").context()) db2_handler = Db2Handler() try: # 先取任务明细 for dispatch_detail in no_asserted_dispatch: schedule_config_data = model_handler.get_all_schedule_config_by_pk( dispatch_detail.schedule_config_id) # 根据设定ID取对应的配置项 for need_assert_data in json.loads( schedule_config_data.assert_table): result = db2_handler.get_assert_result( assert_table_name=need_assert_data['name'], assert_tag=need_assert_data['tag'], order=need_assert_data['order'], eliminate=need_assert_data['eliminate']) logger.info( f"验证设定 {schedule_config_data.batch_job_name} 完成") serializer = ScheduleResultSerializer( data={ "dispatch_no": dispatch_detail.dispatch_no, "schedule_config_id": dispatch_detail.schedule_config_id, "result_info": result }) if serializer.is_valid(): serializer.save() # 回写任务明细表验证状态 model_handler.set_dispath_detail_flag( dispatch_detail.dispatch_no, dispatch_detail.schedule_config_id, "is_assert") except Exception as e: db2_handler.close_conn() logger.error(repr(e)) return Response(BaseResponse(code=400, message=repr(e)).context()) else: db2_handler.close_conn() no_asserted_dispatch = smh().get_all_no_asserted_dispatch({ "is_assert": False, "is_clean": True, "is_ready": True }) if len(no_asserted_dispatch) == 0: model_handler.set_dispath_list_flag() return Response(BaseResponse(message="数据验证成功").context())
def post(self, request): """任务调度""" batch_job_name = request.POST.get('batch_job_name', None) logger.info(f"batch任务 >>>>>> 任务调度接口,入参:{batch_job_name}") model_handler = smh() if ModelUtil(sdl_model).check_data_exist(is_done=False)[0]: return Response( BaseResponse(code=400, message="有任务运行中,请稍后重试").context()) is_all_schedule_flag = False # 跑全部任务 if batch_job_name == '' or batch_job_name is None: logger.info(f"batch任务 >>>>>> 调度批量任务") # 任务调度增加一条主任务 dispatch_no = CommonUtil().generate_dispatch_no() is_all_schedule_flag = True else: logger.info(f"batch任务 >>>>>> 调度单个任务") # 任务调度增加一条主任务 dispatch_no = CommonUtil().generate_dispatch_no(batch_job_name) sdls_serializer = ScheduleDispatchListSerializer( data={"dispatch_no": dispatch_no}) if sdls_serializer.is_valid(): sdls_serializer.save() else: return Response( BaseResponse(code=400, message=sdls_serializer.errors).context()) # 任务明细增加对应明细任务 # 查询对应的设定 if is_all_schedule_flag: config_data = model_handler.get_all_schedule_config() else: config_data = model_handler.filter_schedule_config( {"batch_job_name": batch_job_name}) dispatch_detail = [] for data in config_data: pks = {"dispatch_no": dispatch_no, "schedule_config_id": data.id} dispatch_detail.append(ScheduleDispatchDetail(**pks)) try: # 批量写入任务明细表中 ScheduleDispatchDetail.objects.bulk_create(dispatch_detail) except Exception as e: logger.error(repr(e)) return Response(BaseResponse(code=400, message=repr(e)).context()) # 开始进行数据清理 # 创建db2链接 db2_handler = Db2Handler() for get_config in config_data: # 循环清理表数据 for table_name in json.loads(get_config.clean_table): db2_handler.clean_data(table_name) # 写表记录完成状态 model_handler.set_dispath_detail_flag(dispatch_no, get_config.id, "is_clean") # 循环准备表数据 for config_dict in json.loads(get_config.ready_table): db2_handler.ready_data(config_dict['name'], config_dict['tag']) model_handler.set_dispath_detail_flag(dispatch_no, get_config.id, "is_ready") db2_handler.close_conn() logger.info("batch任务 >>>>>> 任务调度成功") return Response(BaseResponse(message="任务调度成功").context())