def _add_all_service_item(self, combo_box=None): if not isinstance(combo_box, QComboBox): combo_box = self.sender() obj_name_seg = combo_box.objectName().split('_') level = obj_name_seg[0] number = obj_name_seg[2] item_count = combo_box.count() if not item_count: combo_box.insertItem(0, '请选择') if level == 'first': services = service_handler.get_all_first_level_service() else: father_id = getattr(self, 'first_service_' + number).currentData() if father_id: services = service_handler.get_second_service_by_father(int(father_id)) else: services = () for service in services: if combo_box.findData(service['id'], flags=Qt.MatchExactly) == -1: combo_box.addItem(service['name'], service['id']) need_delete = [] for index in range(1, combo_box.count()): cnt = 0 for service in services: if service['id'] == int(combo_box.itemData(index)): cnt += 1 break if not cnt: need_delete.append(index) for index, data in enumerate(need_delete): combo_box.removeItem(data - index)
def _init_service(self): first_srv = service_handler.get_all_first_level_service() if first_srv: self.first_service_combo_box.clear() for father_srv in first_srv: self.first_service_combo_box.addItem(father_srv[1], father_srv[0]) self._update_second_service(first_srv[0][0])
def _init_first_srv(self): first_srv_combo = self.first_srv_combo first_srv_combo.addItem('请选择') first_srvs = service_handler.get_all_first_level_service() for first_srv in first_srvs: first_srv_combo.addItem(first_srv[1], first_srv[0]) if first_srvs: first_srv_id = first_srvs[0][0] self._refresh_second_srv(first_srv_id)
def import_service(file_name): bk = xlrd.open_workbook(file_name) sh = bk.sheet_by_name("菜单列表") rows = sh.nrows # 将表格中的一级和二级放入到字典[数组]的数据结构中 first_service_from_file_dict = defaultdict(list) for i in range(1, rows): row_data = sh.row_values(i) first_service = row_data[0] second_service = row_data[1] if first_service not in first_service_from_file_dict: first_service_from_file_dict[first_service] = [second_service] else: first_service_from_file_dict[first_service].append(second_service) # 将数据库中一级服务项目汇总,并将一级服务项目的名称和ID建立字典 first_service_in_db = get_all_first_level_service() all_first_service = list() first_service_in_db_dict = dict() for data in first_service_in_db: all_first_service.append(data[1]) first_service_in_db_dict[data[1]] = data[0] # 循环增加一级服务项目和二级服务项目 first_service_add_id = None for first_service_name_from_file in first_service_from_file_dict: if first_service_name_from_file not in all_first_service: # 一级服务类型不在全部列表中,则新增 first_service_add_id = add_first_level_service( first_service_name_from_file) else: if first_service_in_db_dict.get(first_service_name_from_file): first_service_add_id = first_service_in_db_dict.get( first_service_name_from_file) if not first_service_add_id: continue # 循环增加二级服务项目 for second_service_name in first_service_from_file_dict[ first_service_name_from_file]: second_service_id = add_second_level_service( second_service_name, first_service_add_id) add_all_required_attribute(second_service_id)
def ApiService(self, keyWord, getData): try: if self.request.method == "GET": if keyWord == "one": second_services = service_handler.get_all_first_level_service( ) send_data = list() for data in second_services: send_data.append({ "oneMenuId": data[0], "name": data[1] }) return set_return_dicts(send_data) elif keyWord == "two": first_service_id = getData.get("oneMenuId") second_services = service_handler.get_second_service_by_father( first_service_id) send_data = list() for data in second_services: second_service_id = data[2] second_service_name = data[3] attribute_dict = {} for attr in service_handler.get_attribute_by_service( second_service_id): attribute_dict[attr[1]] = '1' send_data.append({ "twoMenuId": second_service_id, "name": second_service_name, "attribute": attribute_dict, }) return set_return_dicts(send_data) else: raise ApiException(ErrorCode.ErrorRequest) except ApiException as e: return set_return_dicts(forWorker=e.error_result['forWorker'], code=e.error_result['errorCode'], forUser=e.error_result['forUser'])
def _refresh_first_service(self): set_table_content(self.first_service_table, service_handler.get_all_first_level_service(), self.first_service_title) self.first_service_table.setColumnHidden(0, True)
def ApiService(self, keyword, para_data): try: if self.request.method == "GET": if keyword == "one": second_services = service_handler.get_all_first_level_service() send_data = list() for data in second_services: send_data.append({ "oneMenuId": data[0], "name": data[1] }) return set_return_dicts(send_data) elif keyword == "two": first_service_id = para_data.get("oneMenuId") second_services = service_handler.get_second_service_by_father(first_service_id) send_data = list() for data in second_services: second_service_id = data[2] second_service_name = data[3] attribute_dict = {} for attr in service_handler.get_attribute_by_service(second_service_id): attribute_dict[attr[1]] = '1' send_data.append({ "twoMenuId": second_service_id, "name": second_service_name, "attribute": attribute_dict, }) return set_return_dicts(send_data) elif keyword == 'brand': second_service_id = para_data.get['second_service_id'] brands = [] for brand in stock_handler.get_brand_by_second_service(second_service_id): brands.append({'name': brand['brand_name'], 'id': brand['brand_id']}) send_data = { 'second_service_id': second_service_id, 'brands': brands } return set_return_dicts(send_data) elif keyword == 'model': second_service_id = para_data.get['second_service_id'] brand_id = para_data.get['brand_id'] models = [] for model in stock_handler.get_model_by_second_service_and_brand(second_service_id, brand_id): models.append(({'name': model['model_name'], 'id': model['model_id']})) send_data = { 'second_service_id': second_service_id, 'models': models } return set_return_dicts(send_data) elif keyword == 'balance': model_id = para_data.get['model_id'] stock = stock_handler.get_stock_by_model(model_id) if stock: balance = stock['balance'] else: balance = 0 send_data = { 'model_id': model_id, 'balance': balance } return set_return_dicts(send_data) else: raise ApiException(ErrorCode.ErrorRequest) except ApiException as e: return set_return_dicts(forWorker=e.error_result['forWorker'], code=e.error_result['errorCode'], forUser=e.error_result['forUser'])