def model_doc_tree(self, doc_list): ctrl_section = CtrlDSSection() model_doc_tree = [{ "label": "基本设计", "type": "design", "children": [] }, { "label": "详细设计", "type": "design", "children": [] }] for doc in doc_list: doc_dict = dict() doc_id = doc.get('doc_id') lable = doc.get('title') doc_dict['id'] = str(doc_id) doc_dict['type'] = 'doc' doc_dict['label'] = lable doc_section = ctrl_section.get_sections(doc_id) doc_sub = self.section_tree(doc_id, doc_section) doc_dict['children'] = doc_sub if doc.get('doc_type') == 'BASIC': model_doc_tree[0].get('children').append(doc_dict) elif doc.get('doc_type') == 'DETAIL': model_doc_tree[1].get('children').append(doc_dict) return model_doc_tree
def get_ds_doc(self, doc_id): doc_data = dict() q = (db.session.query(Ds_Doc.doc_id, Model.title, DSDocType.describe, Ds_Doc.creator, Ds_Doc.create_time, Ds_Doc.editor, Ds_Doc.update_time, Ds_Doc.ver, Ds_Doc.model_id) .outerjoin(Model, Ds_Doc.model_id == Model.model_id) .outerjoin(DSDocType, Ds_Doc.doc_type == DSDocType.doc_type) .filter(Ds_Doc.doc_id == doc_id)).all() if len(q): ds_doc = q[0] model_name = ds_doc[1] doc_type = ds_doc[2] doc_data['title'] = "%s_v%s(%s)" % (doc_type, ds_doc[7], model_name) doc_data['doc_type'] = doc_type doc_data['creator'] = ds_doc[3] doc_data['create_time'] = self.time_to_str(ds_doc[4]) doc_data['editor'] = ds_doc[5] doc_data['update_time'] = self.time_to_str(ds_doc[6]) doc_data['ver'] = ds_doc[7] doc_data['model_id'] = ds_doc[8] doc_data['Block'] = CtrlDSSection().get_section_by_type(doc_id, sec_type="BLOCK") doc_data['Class'] = CtrlDSSection().get_section_by_type(doc_id, sec_type="CLASS") doc_data['Usecase'] = CtrlDSSection().get_section_by_type(doc_id, sec_type="COMMON") doc_data['UsecaseTable'] = CtrlDSSection().get_uc_table2(doc_id) doc_data['Statemachine'] = CtrlDSSection().get_section_by_type(doc_id, sec_type="STD") return doc_data
def post(self): data_json = request.get_json() result = {"result": "NG", 'error': ''} sec_obj = CtrlDSSection() flag, error = sec_obj.section_commont(data_json) if flag: result["result"] = "OK" else: result["error"] = error return result
def get(self, doc_id): """ 取一个文档的所有usecase :param doc_id: :return: """ result = {"result": "NG", "content": []} obj = CtrlDSSection() data_list = obj.get_all_usecase_tille(doc_id) if data_list: result['result'] = "OK" result['content'] = data_list return result
def get(self, usecase_id): """ 取usecase的详细信息 :param usecase_id: :return: """ result = {"result": "NG", "content": ''} obj = CtrlDSSection() usecae_data = obj.get_usecase_detail(usecase_id) if usecae_data: result["result"] = "OK" result["content"] = usecae_data return result
def post(self): """ 编辑usecase下子usecase :return: """ data_json = request.get_json() result = {"result": "NG", 'error': ''} sec_obj = CtrlDSSection() flag, error = sec_obj.update_usecase_level2(data_json) if flag: result["result"] = "OK" else: result["error"] = error return result
def post(self): """ 保存和修改文档下usecase的说明 :return: """ result = {"result": "NG", 'error': ''} data_json = request.get_json() sec_obj = CtrlDSSection() flag, error = sec_obj.usecase_add(data_json) if flag: result["result"] = "OK" else: result["error"] = error return result
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, usecase_id): result = {"result": "NG", "content": ''} data_json = CtrlDSSection().get_level2_usecase(usecase_id) if data_json: result["result"] = "OK" result["content"] = data_json return result
def get(self, doc_id, sec_type): result = {"result": "NG", "contnet": ""} section_data = CtrlDSSection().get_section_detail(doc_id, sec_type) if section_data: result["result"] = "OK" result["content"] = section_data return result
def get_db_for_journal2(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 add(self, data_dict): doc_id = int(data_dict.get(CLI.doc_id.name)) if not doc_id: return False, '未指定文档ID!' sec_id = data_dict.get(CLI.sec_id.name) if not sec_id: sec_id = CtrlDSSection().add_usercase(doc_id) if not sec_id: return 0, 'UserCase生成失败!' else: self.delete(sec_id) checklist = data_dict.get("checklist") if checklist: for cl in checklist: check = dict() check[CLI.doc_id.name] = doc_id check[CLI.sec_id.name] = int(sec_id) check[CLI.item_id.name] = cl.get('item_id') check[CLI.content.name] = cl.get('content') # checks.append(CLI(**check)) db.session.add(CLI(**check)) try: db.session.commit() return sec_id, 'OK' except Exception as e: db.session.rollback() return 0, str(e)
def get(self, sec_id): result = {"result": "NG", "content": []} knowledge_doc = CtrlDSSection().get_knowledge_doc(sec_id) if knowledge_doc: result['result'] = "OK" result['content'] = knowledge_doc return result
def add(self, data_dict, commit_user): update_time = self.get_current_time() micro_ver = data_dict.get('micro_ver') doc_id = data_dict.get(DSRelScene.doc_id.name) if not doc_id: return False, '未指定文档ID!' from app.ctrl.ctrl_ds_doc import CtrlDsDoc doc_data, error = CtrlDsDoc().ds_doc_exist(doc_id) if error: return False, error sec_id = data_dict.get(DSRelScene.sec_id.name) if not sec_id: return False, '没有指定USECASE_ID!' old_data, error = CtrlDSSection().session_is_exist(sec_id) if error: return 0, error old_micro_ver = CtrlDSSection().get_sec_ver(sec_id) flag, error = self.diff_ver(micro_ver, old_micro_ver) if not flag: return False, error old_scenes_data = self.get_old_data(self.db_object, DSRelScene.sec_id, sec_id) scenes = data_dict.get("scenes") try: drbfm_log_list = self.delete_scene_drbfm(sec_id, scenes, old_scenes_data) new_scene_list = self.get_new_scene_list(scenes, doc_id, sec_id) scene_log_list = self.add_list(self.db_object, new_scene_list, old_scenes_data, self.key_col, self.col_list) db.session.flush() consider_log_list = CtrlDSConsider().create_considers(sec_id) commit_list = drbfm_log_list + scene_log_list + consider_log_list if commit_list: log_dict = CtrlDSSection().update_ver(sec_id) commit_list.append(log_dict) log_doc = CtrlDsDoc().update_ver(doc_id, commit_user) commit_list.append(log_doc) self.commit_log(commit_list, commit_user, update_time) db.session.commit() return sec_id, 'OK' except Exception as e: db.session.rollback() current_app.logger.error('%s' % e) return 0, "服务异常!请联系管理员!"
def delete_section(self, old_section_list): commit_list = [] for old_section in old_section_list: sec_id = old_section.get('sec_id') commit_list += CtrlDSSection()._delete(sec_id, None, delete='') # commit_list += CtrlDSSection().delete_sec_rel(sec_id) # commit_list += CtrlDSSection().delete_resource(sec_id) # commit_list += self.add_list(DSSection, [], old_section_list, DSSection.sec_id, []) return commit_list
def delete_section_by_name(self, sec_name, doc_id): commit_list = [] q = (db.session.query(DSSection).filter( DSSection.sec_title == sec_name).filter( DSSection.doc_id == doc_id).filter( DSSection.parent_sec_id == 0).first()) if q: sec_id = q.sec_id commit_list = CtrlDSSection()._delete(sec_id, "Admin", delete="") return commit_list
def get_template_sections(self, doc_id): q = db.session.query(DSSection.sec_id, DSSection.sec_type, DSSectionType.describe) q = q.filter(DSSection.sec_type == DSSectionType.sec_type) q = q.filter(DSSection.doc_id == doc_id) q = q.order_by(DSSection.order_id) sections = [] all_tags = CtrlDocTag().get_all_tag() ctrl_sec = CtrlDSSection() for sec in q: sec_id = sec[0] data = {DSSection.sec_id.name: sec_id, DSSection.sec_type.name: sec[1], DSSectionType.describe.name: sec[2]} tags = ctrl_sec.get_tags(sec_id, all_tags) data["tags"] = tags sections.append(data) return sections
def add(self, drbfm_data, commit_user): update_time = self.get_current_time() from app.ctrl.ctrl_ds_section import CtrlDSSection micro_ver = drbfm_data.get('micro_ver') doc_id = drbfm_data.get('doc_id') if not doc_id: return False, '未指定文档ID!' from app.ctrl.ctrl_ds_doc import CtrlDsDoc doc_data, error = CtrlDsDoc().ds_doc_exist(doc_id) if error: return False, error content = drbfm_data.get('content') if content: sec_id = drbfm_data.get('content')[0].get('sec_id') if not sec_id: return False, '没有指定USECASE_ID!' old_data, error = CtrlDSSection().session_is_exist(sec_id) if error: return 0, error old_micro_ver = CtrlDSSection().get_sec_ver(sec_id) flag, error = self.diff_ver(micro_ver, old_micro_ver) if not flag: return False, error try: new_data_list = self.get_new_drbfm(content) old_data_list = self.get_old_data(self.db_object, DSDrbfm.sec_id, sec_id) commit_list = self.add_list(self.db_object, new_data_list, old_data_list, self.key_col, self.col_list) if commit_list: log_dict = CtrlDSSection().update_ver(sec_id) commit_list.append(log_dict) log_doc = CtrlDsDoc().update_ver(doc_id, commit_user) commit_list.append(log_doc) self.commit_log(commit_list, commit_user, update_time) db.session.commit() return sec_id, 'ok' except Exception as e: current_app.logger.error('%s' % e) db.session.rollback() return False, "服务异常!请联系管理员!"
def get(self, doc_id): """ 获取文档下所有usecase的说明 :param doc_id: :return: """ result = {"result": "NG"} content = CtrlDSSection().get_usecase_by_doc_id(doc_id, 'USERCASE') if content: result = {"result": "OK", "content": content} return result
def post(self): data_json = request.get_json() commit_user = data_json.get('commit_user') result = {"result": "NG", 'error': ''} sec_type = data_json.get("sec_type") # if sec_type == "SPEC": # sec_obj = CtrlDSRelSpec() # elif sec_type == "SCENES": # sec_obj = CtrlDSScene() # elif sec_type in ("USERCASE", "SEQUENCE", "CLASS", # "BLOCK", "RESOURCE", "STD"): sec_obj = CtrlDSSection() # elif sec_type == "DRBFM": # sec_obj = CtrlDsDrbfm() flag, error = sec_obj.add(data_json, commit_user) if flag: result["result"] = "OK" else: result["error"] = error return result
def __init__(self): CtrlBase.__init__(self) self.key_col = Ds_Doc.doc_id self.db_object = Ds_Doc self.col_list = [Ds_Doc.title.name, Ds_Doc.summary.name] self.ds_col_list = [] for column in Ds_Doc.__table__.columns: self.ds_col_list.append(column.name) self.sec_type_list = [] for sec_type in CtrlDSSection().get_section_type(): self.sec_type_list.append(sec_type.get('sec_type'))
def add(self, data_dict): update_time = self.get_current_time() micro_ver = data_dict.get('micro_ver') doc_id = data_dict.get(DSRelSpec.doc_id.name) commit_user = data_dict.get('commit_user') content = data_dict.get('content') if not doc_id: return False, '未指定文档ID!' doc_data, error = CtrlDsDoc().ds_doc_exist(doc_id) if error: return False, error old_micro_ver = CtrlDsDoc().get_doc_ver(doc_id) flag, error = self.diff_ver(micro_ver, old_micro_ver) if not flag: return 0, error data_list = [] old_spec_list = self.get_old_data(self.db_object, DSRelSpec.doc_id, doc_id) old_data_list = [] for old_data in old_spec_list: if old_data.get('sec_id'): old_data_list.append(old_data) for data in content: sec_id = data.get(DSRelSpec.sec_id.name) if not sec_id: return 0, '没有指定USECASE_ID!' old_data, error = CtrlDSSection().session_is_exist(sec_id) if error: return 0, error specs = data.get('specs') if not specs: continue spec_info = dict() spec_info[DSRelSpec.gid.name] = specs.get('gid') spec_info[DSRelSpec.doc_id.name] = int(doc_id) spec_info[DSRelSpec.sec_id.name] = int(sec_id) spec_info[DSRelSpec.spec_id.name] = specs.get(DSRelSpec.spec_id.name) spec_info[DSRelSpec.func_id.name] = specs.get(DSRelSpec.func_id.name) data_list.append(spec_info) # if not spec_list: # return 0, '无式样书!' try: commit_list = self.add_list(self.db_object, data_list, old_data_list, self.key_col, self.col_list) if commit_list: log_doc = CtrlDsDoc().update_ver(doc_id, commit_user) commit_list.append(log_doc) self.commit_log(commit_list, commit_user, update_time) db.session.commit() return doc_id, 'OK' except Exception as e: db.session.rollback() current_app.logger.error('%s' % e) return 0, "服务异常!请联系管理员!"
def get_tag_tree(self, **agv): """ :param agv: mode_id, doc_type: "BASIC"/"DETAIL" :return: """ rate = agv.get("rate") if not rate or rate == TAG_RATE_ALL: statement = (db.session.query(DBDocTagCat) .filter() .order_by(DBDocTagCat.parent_tag_id, DBDocTagCat.tag_id) .statement) else: statement = (db.session.query(DBDocTagCat) .filter(DBDocTagCat.rate == rate) .order_by(DBDocTagCat.required.desc(), DBDocTagCat.parent_tag_id, DBDocTagCat.tag_id) .statement) tag_df = pd.read_sql(statement, db.session.bind) # ## 通过Model和文档类别过滤 model_id = agv.get("model_id") sec_id = agv.get("sec_id") if model_id: doc_type = agv.get("doc_type") filter_tags = self._get_tags_by_model(model_id, doc_type) filter_df = self.filter_tags(tag_df, filter_tags) if filter_df is None: return [] filter_df = filter_df.sort_values(["parent_tag_id", "tag_id"]) elif sec_id: filter_tags = [] from app.ctrl.ctrl_ds_section import CtrlDSSection sec_tags = CtrlDSSection().get_tags(sec_id) for tag in sec_tags: filter_tags.append(tag.get("tag_id")) filter_df = self.filter_tags(tag_df, filter_tags) if filter_df is None: return [] filter_df = filter_df.sort_values(["parent_tag_id", "tag_id"]) else: filter_df = tag_df # print(filter_df) # ## 第一级Tags root_df = filter_df[filter_df["parent_tag_id"] == 0] # print(root_df) # 求子孙TAG tag_list = root_df.to_dict(orient='records') self._get_sub_tags(tag_list, filter_df) return tag_list
def get(self, doc_id, sec_type, condition=None): """ :param sec_id: User Case ID :param sec_type: :return: """ result = {"result": "NG", "content": ''} # if sec_type == "SPEC": # sec_obj = CtrlDSRelSpec() # elif sec_type == "SCENES": # sec_obj = CtrlDSScene() # elif sec_type in ("USERCASE", "SEQUENCE", "CLASS", # "BLOCK", "RESOURCE", "STD"): sec_obj = CtrlDSSection() # elif sec_type == "DRBFM": # sec_obj = CtrlDsDrbfm() content, status = sec_obj.get(doc_id, sec_type, condition) if content or status: if status: result["status"] = status result["result"] = "OK" result["content"] = content return result
def get(self, usecase_id, sec_type): """ 取usecase下的sequence :return: """ result = {"result": "NG", "content": ''} sec_data = CtrlDSSection().get_sub_by_usecase(usecase_id, sec_type) if sec_data: result["result"] = "OK" result["content"] = { 'usecase_id': usecase_id, 'sec_type': sec_type, 'section_list': sec_data } return result
def get(self, doc_id, sec_type=None, condition=None): uc_list = CtrlDSSection().get_session_by_doc_id(doc_id, "USERCASE") uc_spec_list = [] i = 1 for uc in uc_list: spec_dict = dict() spec_dict['sec_id'] = uc.get('sec_id') content = json.loads(uc.get('content')) spec_dict['number'] = 'UC' + str(i) spec_dict['title'] = content[0].get('title') spec_dict['val'] = content[0].get('val') spec_type_dict, status = self._get(uc.get('sec_id')) if not spec_type_dict: continue spec_dict['specs'] = spec_type_dict uc_spec_list.append(spec_dict) i += 1 return uc_spec_list
def copy_usecase_rel(self, usecase_id, data_list, doc_id, commit_list, old_new_dict): from app.db.ds_section import DSSectionRel for data in data_list: sec_id = data.get('sec_id') sec_type = data.get('sec_type') if sec_id not in old_new_dict: basic_data = self.get_old_data(DSSection, DSSection.sec_id, sec_id) new_sec_id = self.copy_ds_session(basic_data[0], doc_id, commit_list) if sec_type == 'SEQUENCE': # basic_activity = self.get_old_data(DSSection, DSSection.parent_sec_id, basic_id) resource_list = CtrlDSSection()._get_resource(sec_id) for resource in resource_list: self.copy_ds_resource(resource, new_sec_id, commit_list) # for activity in basic_activity: # self.copy_ds_session(activity, doc_id, commit_list, basic_id) old_new_dict[sec_id] = new_sec_id seq_rel = {'sec_id': old_new_dict.get(sec_id), 'sec_rel_id': usecase_id} rel_log = self.common_add(DSSectionRel, seq_rel, None, [], DSSectionRel.gid) commit_list.append(rel_log)
def add_section_rel(self, usecase_rel_list, key_id_dict): commit_list = [] sec_rel_dict = dict() for usecase_rel in usecase_rel_list: ucNo = usecase_rel.get("ucNo") seqNo = usecase_rel.get("seqNo") uc_id = key_id_dict.get(ucNo) seq_id = key_id_dict.get(seqNo) if not uc_id or not seq_id: error = "%s或%s不存在!" % (ucNo, seqNo) return [], error else: if seq_id not in sec_rel_dict: sec_rel_dict[seq_id] = [uc_id] else: sec_rel_dict[seq_id].append(uc_id) for seq_id in sec_rel_dict: uc_id_list = sec_rel_dict.get(seq_id) commit_list += CtrlDSSection().update_sec_rel(seq_id, uc_id_list) return commit_list, None
def delete(self, _id, type, commit_user): """ :param id: :param del_type: doc/usercase :return: """ result = {"result": "OK"} try: if type == "doc": ctrl_obj = CtrlDsDoc() elif type == "usercase": ctrl_obj = CtrlDSSection() error = ctrl_obj.delete(_id, commit_user) if error: result["result"] = "NG" result["error"] = error except Exception as e: current_app.logger.error('%s' % e) result["result"] = "NG" result["error"] = "服务异常!请联系管理员!" return result
def get_doc(self, doc_id, detail=None): q = db.session.query(Ds_Doc).filter(Ds_Doc.doc_id == doc_id) q = q.order_by(Ds_Doc.doc_id).all() ds_doc = dict() if len(q): ds_doc = q[0].to_dict() ds_doc['create_time'] = self.time_to_str(ds_doc.get('create_time')) ds_doc['update_time'] = self.time_to_str(ds_doc.get('update_time')) ds_doc['copy_on'] = False parent_doc = self.get_parent_doc(doc_id) ds_doc['parent_doc'] = parent_doc if parent_doc: ds_doc['copy_on'] = True if not detail: return ds_doc else: if ds_doc.get(Ds_Doc.summary.name): ds_doc[Ds_Doc.summary.name] = ds_doc[Ds_Doc.summary.name].replace('\n', '<br>') ds_doc['sub'] = [] astah_dict = CtrlDSAstah().get_astah(doc_id) public_usecase_list = CtrlDSSection().get_session_by_doc_id(doc_id, 'COMMON') block_list = CtrlDSSection().get_session_by_doc_id(doc_id, "BLOCK") class_list = CtrlDSSection().get_session_by_doc_id(doc_id, "CLASS") seq_list = CtrlDSSection().get_sequence2(doc_id) std_list = CtrlDSSection().get_session_by_doc_id(doc_id, 'STD') if_list = CtrlDsIf().get_if_detail(doc_id) usercase_dict = CtrlDSSection().get_usecase_tree2(doc_id) drbfm_list = CtrlDsDrbfm().get_drbfm_new(doc_id) drbfm_dict = {'sec_type': 'DRBFM', 'drbfm_list': drbfm_list, 'sub': []} ds_doc['sub'].append(astah_dict) ds_doc['sub'] += if_list ds_doc['sub'] += public_usecase_list ds_doc['sub'] += block_list ds_doc['sub'] += class_list ds_doc['sub'].append(usercase_dict) ds_doc['sub'] += seq_list ds_doc['sub'] += std_list ds_doc['sub'].append(drbfm_dict) return ds_doc