class PageDefService: def __init__(self): # Log self.__logger = OrcLog("view.driver.web.service.page_def") self.__resource_page_def = OrcHttpNewResource("PageDef") def usr_add(self, p_data): """ 新增 :param p_data: :return: """ page_data = self.__resource_page_def.post(p_data) return dict(id=page_data["id"]) def usr_delete(self, p_list): """ 删除 :param p_list: :return: """ return self.__resource_page_def.delete(p_list) def usr_update(self, p_data): """ 修改 :param p_data: :return: """ self.__resource_case_def.set_path(p_data["id"]) return self.__resource_page_def.put(p_data) def usr_search(self, p_cond): """ 查询 :param p_cond: :return: """ return self.__resource_page_def.get(p_cond)
class ItemService(object): def __init__(self): object.__init__(self) self.__resource_case_def = OrcHttpNewResource("CaseDef") self.__resource_step_det = OrcHttpNewResource("StepDet") self.__resource_item = OrcHttpNewResource("Item") def usr_add(self, p_data): """ 增加 :param p_data: :return: """ step_type = p_data["type"] step_id = p_data["step_id"] step_data = p_data["data"] if "ITEM" == step_type: # 增加 item item = self.__resource_item.post(step_data) # 增加 step det step_id = step_id item_id = item["id"] step_det_data = dict(step_id=step_id, item_id=item_id) self.__resource_step_det.post(step_det_data) elif "FUNC" == step_type: # 增加 step det step_id = step_id func_id = step_data step_det_data = dict(step_id=step_id, item_id=func_id) self.__resource_step_det.post(step_det_data) return dict(step_id=step_id) def usr_delete(self, p_list): """ 删除 :param p_list: :return: """ return self.__resource_step_det.delete(p_list) def usr_update(self, p_data): """ 更新 :param p_data: :return: """ # 获取 item id self.__resource_step_det.set_path(p_data["id"]) item_id = self.__resource_step_det.get()["item_id"] # 更新数据 data = p_data.copy() data["id"] = item_id self.__resource_item.set_path(item_id) return self.__resource_item.put(p_data) def usr_search(self, p_cond): """ 删除 :param p_cond: :return: """ # 查询 step det 列表 step_det_list = self.__resource_step_det.get(p_cond) # 查询 item id 列表 item_id_list = [step_det["item_id"] for step_det in step_det_list] # 查询 item 列表 item_list = self.__resource_item.get(dict(id=item_id_list)) # 查询 func case_list = self.__resource_case_def.get(dict(id=item_id_list)) # func 转成 item 结构 func_list = [ dict(id=case["id"], item_no=case["case_no"], item_mode="", item_type="", item_operate=case["case_path"], item_desc=case["case_desc"], comment=case["comment"], create_time=case["create_time"], modify_time=case["modify_time"]) for case in case_list ] # 连接 list print func_list item_list.extend(func_list) print item_list # 连接数据 return connect_list(step_det_list, item_list, "item_id")
class Runtime(object): """ """ def __init__(self, p_mod): object.__init__(self) self.__mod = p_mod self.__resource = OrcHttpNewResource("RunTime") def add_value(self, p_data): """ 新增 :param p_data: :return: """ data = dict(module=self.__mod) data.update(p_data) return self.__resource.post(data) def get_value(self, p_flag): """ 获取数据 :param p_flag: :return: """ cond = dict(module=self.__mod, data_flag=p_flag) result = self.__resource.get(cond) return None if not result else result[0]["data_value"] def get_values(self, p_flag): """ 获取多条数据 :param p_flag: :return: """ cond = dict(module=self.__mod, data_flag=p_flag) result = self.__resource.get(cond) return None if not result else [item["data_value"] for item in result] def set_value(self, p_flag, p_value, p_index=None): """ 设置数据,如果不存在就新增一个,数据有多个时只入第一个 :param p_index: :param p_flag: :param p_value: :return: """ # 生成查询条件 cond = dict(module=self.__mod, data_flag=p_flag) if p_index is not None: cond["data_index"] = p_index # 判断数据存在,如果存在找到 id data_item = self.__resource.get(cond) data_id = None if data_item is None else data_item[0]["id"] # 设置值 if data_id is not None: self.__resource.set_path(data_id) result = self.__resource.put(dict(data_value=p_value)) else: cond["data_value"] = p_value result = self.__resource.post(cond) return result def del_value(self, p_flag, p_index=None): """ 删除数据 :param p_index: :type p_index: int :param p_flag: :return: """ # 查找数据 cond = dict(module=self.__mod, data_flag=p_flag) data_list = self.__resource.get(cond) # 获取 id list data_id_list = None if data_list is None else [ item["id"] for item in data_list ] # 不存在合适的对象 if data_id_list is None: return False # 只删除一条的情况 if p_index is not None: # index 超出范围 if p_index < len(data_id_list): data_id = data_id_list[p_index] self.__resource.set_path(data_id) return self.__resource.delete() else: return False # 删除符合条件全部数据 else: return self.__resource.delete(data_id_list)
class WindowDefService: """ Window service """ def __init__(self): # Log self.__logger = OrcLog("view.driver.web.service.window_def") self.__resource_widget_def = OrcHttpNewResource("WidgetDef") self.__resource_widow_def = OrcHttpNewResource("WindowDef") def usr_add(self, p_data): """ 把存在于 widget 表但在 window 表中不存在的 window 增加到 window 表 :param p_data: :return: """ windows_all = [ item["id"] for item in self.__resource_widget_def.get( dict(widget_type="WINDOW")) ] windows_exist = [ item["id"] for item in self.__resource_widow_def.get() ] if not windows_all: return for _id in windows_all: if (not windows_exist) or (_id not in windows_exist): self.__resource_widow_def.post(dict(id=_id)) return dict() def usr_delete(self, p_list): """ :param p_list: :return: """ return self.__resource_widow_def.delete(p_list) def usr_update(self, p_data): """ :param p_data: :return: """ self.__resource_widow_def.set_path(p_data["id"]) return self.__resource_widow_def.put(p_data) def usr_search(self, p_cond): """ :param p_cond: :return: """ _cond = p_cond # 有 window_flag 条件先查 widget if "window_flag" in _cond: _ids = [ item["id"] for item in self.__resource_widget_def.get( dict(widget_flag=_cond["window_flag"])) ] _cond["id"] = _ids # 查询 _data = self.__resource_widow_def.get(_cond) _window_list = self.__resource_widget_def.get( dict(widget_type="WINDOW")) def _get_widget(p_id): for _item in _window_list: if _item["id"] == p_id: return _item return None if _data is None: return [] else: for _window in _data: _widget = _get_widget(_window["id"]) if _widget is not None: _window["window_flag"] = _widget["widget_flag"] return _data
class CaseDetService(object): def __init__(self): object.__init__(self) self.__resource_case_det = OrcHttpNewResource("CaseDet") self.__resource_step = OrcHttpNewResource("StepDef") def usr_add(self, p_data): """ 新增 :param p_data: :return: """ # 增加步骤 step_info = p_data["step"] step_det = self.__resource_step.post(step_info) # 增加 case case_info = p_data["case_det"] case_info["step_id"] = step_det["id"] case_det = self.__resource_case_det.post(case_info) return dict(case_id=case_det["case_id"]) def usr_delete(self, p_list): """ 删除 :param p_list: :return: """ return self.__resource_case_det.delete(p_list) def usr_update(self, p_data): """ 更新 :param p_data: :return: """ # 获取 step id self.__resource_case_det.set_path(p_data["id"]) step_id = self.__resource_case_det.get()["step_id"] # 更新数据 data = p_data.copy() data["id"] = step_id self.__resource_step.set_path(step_id) return self.__resource_step.put(data) def usr_search(self, p_cond): """ 查询 :param p_cond: :return: """ # 查询 case_det 列表 case_det_list = self.__resource_case_det.get(p_cond) # 查询 step id 列表 step_id_list = [item["step_id"] for item in case_det_list] # 查询 step_def 列表 step_def_list = self.__resource_step.get(dict(id=step_id_list)) # 连接数据 return connect_list(case_det_list, step_def_list, "step_id")
class StepService(object): def __init__(self): object.__init__(self) self.__resource_step_det = OrcHttpNewResource("StepDet") self.__resource_item = OrcHttpNewResource("Item") def usr_add(self, p_data): """ 增加 :param p_data: :return: """ # 增加 item item = self.__resource_item.post(p_data) # 增加 step det step_id = p_data["step_id"] item_id = item["id"] step_data = dict(step_id=step_id, item_id=item_id) self.__resource_step_det.post(step_data) return dict(step_id=step_id) def usr_delete(self, p_list): """ 删除 :param p_list: :return: """ return self.__resource_step_det.delete(p_list) def usr_update(self, p_data): """ 更新 :param p_data: :return: """ # 获取 item id self.__resource_step_det.set_path(p_data["id"]) item_id = self.__resource_step_det.get()["item_id"] # 更新数据 data = p_data.copy() data["id"] = item_id self.__resource_item.set_path(item_id) return self.__resource_item.put(p_data) def usr_search(self, p_cond): """ 删除 :param p_cond: :return: """ # 查询 step det 列表 step_det_list = self.__resource_step_det.get(p_cond) # 查询 item id 列表 item_id_list = [step_det["item_id"] for step_det in step_det_list] # 查询 item 列表 item_list = self.__resource_item.get(dict(id=item_id_list)) # 连接数据 return connect_list(step_det_list, item_list, "item_id")