def get_camera(self, id): """ 取得终端机信息 """ table_dict = TableDict() camera = table_dict.get("face_collection_camera", id) if camera is None: return {} camera["cno"] = str(camera["cno"]) return camera
def save_camera(self, id, cn, ip, sn, cno, tips): """ 新增或修改终端机 """ camera_cn = self.get_by_cn(cn) camera_ip = self.get_by_ip(ip) camera_sn = self.get_by_sn(sn) table_dict = TableDict() table = "face_collection_camera" id = id if id is not None else id_generator() camera = table_dict.get(table, id) if camera is None: # 确保名称、ip与序号的唯一 if camera_cn is not None: return "", "已经有名称为“{}”的终端机,不能重复!".format(cn) if camera_ip is not None: return "", "已经有ip地址为“{}”的终端机,不能重复!".format(ip) if camera_sn is not None: return "", "已经有序号为“{}”的终端机,不能重复!".format(sn) # 新增 camera = {"id": id, "cn": cn, "ip": ip, "sn": sn, "cno": cno, "tips": tips, "isdeleted": "0"} table_dict.save(table, camera) else: # 确保名称、ip与序号的唯一 if camera_cn is not None and camera_cn["id"] != id: return "", "已经有名称为“{}”的终端机,不能重复!".format(cn) if camera_ip is not None and camera_ip["id"] != id: return "", "已经有ip地址为“{}”的终端机,不能重复!".format(ip) if camera_sn is not None and camera_sn["id"] != id: return "", "已经有序号为“{}”的终端机,不能重复!".format(sn) # 修改 camera["cn"] = cn camera["ip"] = ip camera["sn"] = sn camera["cno"] = cno camera["tips"] = tips table_dict.update(table, camera) return id, ""