def _get_scenes(self, df, df2, lf, sec_id): """ :param df: :param sec_id: :return: 场景 """ rel_scene_list = [] table_name = 'ds_rel_scene' cols = ['sec_id'] vals = [str(sec_id)] rel_scene_df_list = self._get_sub_df_list(df, table_name, cols, vals) if rel_scene_df_list: from app.ctrl.ctrl_ds_scene import CtrlDSScene scene_dict = CtrlDSScene().get_scene2() for rel_spec_df in rel_scene_df_list: rel_spec_dict = self.df_to_dict(rel_spec_df, df2, lf) scene_id = rel_spec_dict.get("scene_id") if scene_id: scene_id = int(scene_id) scene_info = scene_dict.get(scene_id) if scene_info: rel_spec_dict.update(scene_info) else: current_app.logger.error('Unknown scene ID [%s].' % scene_id) rel_scene_list.append(rel_spec_dict) return rel_scene_list
def post(self): result = {"result": "NG", "doc_id": 0, 'error': ''} data_json = request.get_json() type = data_json.get('type') if type == "SCENE": doc_id, error = CtrlDSScene().add_scene(data_json) elif type == "CHANGE": doc_id, error = CtrlDSScene().add2(data_json) if doc_id: # micro_ver = CtrlDsDoc().get_doc_ver(doc_id) result['result'] = "OK" result['doc_id'] = doc_id # result["micro_ver"] = micro_ver else: result['error'] = error return result
def get_db_for_journal(self, doc_id): """设计方档整体备份使用 :param doc_id: :return: """ from app.ctrl.ctrl_ds_rel_spec import CtrlDSRelSpec from app.ctrl.ctrl_ds_scene import CtrlDSScene db_objs = [] q = db.session.query(Ds_Doc).filter(Ds_Doc.doc_id == doc_id).first() ds_doc = q astahs = CtrlDSAstah().get_db_for_journal(doc_id) if astahs: db_objs += astahs ifs = CtrlDsIf().get_db_for_journal(doc_id) if ifs: db_objs += ifs specs = CtrlDSRelSpec().get_db_for_journal(doc_id) if specs: db_objs += specs drbfms = CtrlDSScene().get_db_for_journal(doc_id) if drbfms: db_objs += drbfms sections = CtrlDSSection().get_db_for_journal(doc_id) if sections: db_objs += sections if ds_doc: db_objs.append(ds_doc) return db_objs
def delete(self, doc_id, commit_user, commit=True): """ #删除整个文档 :param doc_id: :return: """ update_time = self.get_current_time() commit_list = [] from app.ctrl.ctrl_ds_rel_spec import CtrlDSRelSpec from app.ctrl.ctrl_ds_scene import CtrlDSScene commit_list += CtrlDSAstah().delete_by_doc_id(doc_id) commit_list += CtrlDSRelSpec().delete_by_doc_id(doc_id) commit_list += CtrlDsIf().delete_by_doc_id(doc_id) commit_list += CtrlDSSection().delete_section(doc_id, commit_user) commit_list += CtrlDSScene().del_rel_tag(doc_id) doc_log_list, error = self.delete_ds_doc(doc_id) if error: return error commit_list += doc_log_list if not commit: return commit_list self.commit_log(commit_list, commit_user, update_time) db.session.commit() from app.db import cache cache.delete('get_model_tree') # 删除缓存 return None
def get(self, doc_id=0, type='change'): result = {"result": "NG"} if not doc_id: # 取所有场景(TAG) # scenes = CtrlDSScene().get_scene() scenes = CtrlDSScene().get_scene3() else: # scenes = CtrlDSScene().get_scene_by_sec(doc_id) if type == 'change': # 修改点、影响点 scenes = CtrlDSScene().get_scene_by_doc2(doc_id) else: # 已选择 scenes = CtrlDSScene().get_scene_by_doc(doc_id) micro_ver = CtrlDsDoc().get_doc_ver(doc_id) result["micro_ver"] = micro_ver if scenes: result['result'] = "OK" result['content'] = scenes return result
def get2(self, usecase_id, sec_type=None, condition=None): drbfm_list = [] from app.ctrl.ctrl_ds_scene import CtrlDSScene drbfm_df = self.get_drbfm_df(usecase_id) if drbfm_df.empty: return drbfm_list, 'NO_SCENE' columns = {DSDrbfm.drbfm_content.name: "content"} drbfm_df.rename(columns=columns, inplace=True) drbfm_df.fillna('', inplace=True) if condition == 'YES': # 过滤列 drbfm_df2 = drbfm_df[~drbfm_df["content"].isin(['', '-'])] if drbfm_df2.empty: return drbfm_list, 'NO_CONTENT' scene_id_list = list(drbfm_df2["scene_id"].unique()) drbfm_df = drbfm_df[drbfm_df["scene_id"].isin(scene_id_list)] if drbfm_df.empty: return drbfm_list, 'NO_CONTENT' failure_df = CtrlDSFailure().get_failure_df() scene_df = CtrlDSScene().get_scene_df() merge_df = pd.merge(failure_df, drbfm_df, how="left", on=[DSFailure.item_id.name]) print(merge_df) merge_df = pd.merge(merge_df, scene_df, how="left", on=[DSScene.scene_id.name]) merge_df["showFlag"] = [False] * len(merge_df) category_list = list(merge_df["category"].unique()) for category in category_list: cat_dict = {"name": category, "sub": []} df1 = merge_df[merge_df["category"] == category] major_items = list(df1["major_item"].unique()) for major_item in major_items: major_dict = {"name": major_item, "sub": []} df2 = df1[df1["major_item"] == major_item] failure_list = list(df2["failure"].unique()) for failure in failure_list: failure_dict = {"name": failure, "sub": []} df3 = df2[df2["failure"] == failure] if condition == 'YES': # 过滤行 df4 = df3[~df3["content"].isin(['', '-'])] if df4.empty: continue failure_dict["item_id"] = int(df3.iloc[0].item_id) df3 = df3[[ "gid", "scene_id", "content", "scene", "explain", "showFlag" ]] failure_dict["scenes"] = df3.to_dict(orient="record") major_dict["sub"].append(failure_dict) if major_dict["sub"]: cat_dict["sub"].append(major_dict) if cat_dict["sub"]: drbfm_list.append(cat_dict) return drbfm_list, 'normal'
def get(self, doc_id=0): """获取设计文档关系的场景(场景的考虑点使用)""" result = {"result": "NG", 'content': []} if doc_id: # 取所有场景(TAG) # scenes = CtrlDSScene().get_scene() tags = CtrlDSScene().get_tags_by_doc_id(doc_id) if tags: result['result'] = "OK" result['content'] = tags micro_ver = CtrlDsDoc().get_doc_ver(doc_id) result["micro_ver"] = micro_ver return result
def post(self): """ 保存場景的模快下的考慮點 :return: """ result = {"result": "NG", "doc_id": 0, 'error': ''} data_json = request.get_json() doc_id, error = CtrlDSScene().add_tag_considers(data_json) if doc_id: result['result'] = "OK" result['doc_id'] = doc_id else: result['error'] = error return result
def _get_scene_df(self): if self.scene_df is None: from app.ctrl.ctrl_ds_scene import CtrlDSScene # 获取着眼点 self.scene_df = CtrlDSScene().get_scene_df() return self.scene_df