Ejemplo n.º 1
0
 def query_products(self):
     """查询产品信息"""
     pid_list = EX.load_product_data(self.path_prd, "自动导出产品信息")
     # pid_list = EX.load_product_data(self.path_prd, "Sheet2")
     lists = []
     if len(pid_list):
         for i in range(len(pid_list)):
             try:
                 url = self.host + self.port + '/v2/product/' + pid_list[i][
                     1]
                 print(url)
                 r = requests.get(url=url, headers=self.headers)
                 if (r.status_code == 200):
                     res = eval(r.text)
                     print("查询成功")
                     print(res)
                     lists.append(res['name'])
                 else:
                     print("查询失败,错误码:", r.status_code)
             except Exception:
                 print('traceback.format_exc():\n%s' %
                       traceback.format_exc())
                 raise
         return lists
     else:
         print("产品列表为空")
Ejemplo n.º 2
0
 def create_task(self):
     """创建产巡检任务,每个任务分开表格存放数据"""
     # product_id = ''
     # device_id = ''
     # point_indexs = []
     url = self.host + self.port + '/v2/service/maintenance/task'
     task_lists = EX.get_sheets(self.path_maintenance)
     product_lists = EX.load_product_data(self.path_maintenance, task_lists[0])
     for projcet in product_lists:
         project_id = self.get_project_id(projcet[0])
         self.projectid = project_id
         for task in range(1, len(task_lists)):
             base_task_body = {
                 "name": "",
                 "status": 2,
                 "project_id": "",
                 "check_items": []
             }
             check_lists = EX.load_product_data(self.path_maintenance, task_lists[task])
             for item in check_lists:
                 if item[2] != '':
                     product_id = self.get_product_id(item[2])
                     device_id = self.get_device_id(product_id, project_id,item[4])
                     points = self.get_points_lists(item[3])
                     point_indexs = self.get_data_points_indexs(product_id, points)
                 else:
                     product_id = ''
                     device_id = ''
                     point_indexs = []
                 check_items_body = self.get_check_items_json(item[0], item[1], product_id, device_id, point_indexs)
                 self.get_base_task_json(base_task_body, task_lists[task], project_id, check_items_body)
             try:
                 r = requests.post(url=url, json=base_task_body, headers=self.headers)
                 if r.status_code == 200:
                     print('[项目]' + projcet[0] + '--' + '[巡检任务]' + task_lists[task] + '巡检任务创建成功')
                     print(r.text)
             except Exception:
                 print(projcet[0] + task_lists[task] + '巡检任务创建失败!!')
                 print(traceback.format_exc())
Ejemplo n.º 3
0
 def delete_product(self):
     """删除产品"""
     pid_list = EX.load_product_data(self.path_prd, "自动导出产品信息")
     # pid_list = EX.load_product_data(self.path_prd, "Sheet2")
     type_tem = false
     for i in range(len(pid_list)):
         try:
             url = self.host + self.port + '/v2/product/' + pid_list[i][1]
             print(url)
             r = requests.delete(url=url, headers=self.headers)
             if (r.status_code == 200):
                 type_tem = true
                 print("删除成功")
             else:
                 print("删除失败,错误码:", r.status_code)
         except Exception:
             print('traceback.format_exc():\n%s' % traceback.format_exc())
             raise
     if type_tem:
         EX.clear_product_data(self.path_prd, "自动导出产品信息")
     else:
         print("删除失败,未清除数据")
Ejemplo n.º 4
0
 def creat_schedule(self):
     task_lists = EX.get_sheets(self.path_maintenance)
     product_lists = EX.load_product_data(self.path_maintenance, task_lists[0])
     for projcet in product_lists:
         print(projcet[0])
         project_id = self.get_project_id(projcet[0])
         # list_task = self.get_list_task(project_id)
         # day_daily_plan_id = self.creat_daily_plan(project_id,list_task,'08:30','17:30','早班')
         # night_daily_plan_id = self.creat_daily_plan(project_id,list_task,'17:30','08:30','晚班')
         day_daily_plan_id = '5d06fe89d8af2f766eda3ebb'
         night_daily_plan_id = '5d06fe8a6fb0bd7570814d6e'
         deps = self.get_project_departments(project_id)
         pos_list = self.get_project_positions(deps)
         member_list = self.get_project_members(pos_list)
         self.batch_schedule_artificial(member_list[0:3],project_id,[2019,7])
         schedule_ids = self.get_member_schedule_id(project_id, [2019, 7])
         # schedule_plans = [[1, 0, 1, 1], [1, 1, 0, 1], [2, 1, 1, 0], [0, 2, 2, 2]]
         schedule_plans = [[1, 0, 2], [2, 1, 0], [0, 2, 1]]
         for i in range(len(schedule_plans)):
             print(member_list[0:3][i])
             print(schedule_plans[i])
             self.add_member_schedule(schedule_ids, [2019, 7], day_daily_plan_id, night_daily_plan_id,
                                      schedule_plans[i], member_list[0:3][i])
         break
Ejemplo n.º 5
0
    def create_products(self):
        """创建产品"""
        link_type = 1
        p_type = 0
        visible = 0
        prd_lists = []
        url = self.host + self.port + '/v2/product'
        lists = EX.load_product_data(self.path_prd, "手动导入产品信息")
        # lists = EX.load_product_data(self.path_prd, "Sheet1")  #测试
        for i in range(len(lists)):
            # 判断设备连接类型
            if lists[i][2] == "wifi设备":
                link_type = 1
            elif lists[i][2] == "Zigbee设备":
                link_type = 2
            elif lists[i][2] == "蓝牙设备":
                link_type = 3
            elif lists[i][2] == "蓝牙Mesh设备":
                link_type = 4
            elif lists[i][2] == "PC设备":
                link_type = 5

            # 判断产品类型
            if lists[i][3] == "其他":
                p_type = 0
            elif lists[i][3] == "消费电子":
                p_type = 1
            elif lists[i][3] == "智能家居":
                p_type = 2
            elif lists[i][3] == "智能安防":
                p_type = 3
            elif lists[i][3] == "商用/工控设备":
                p_type = 4
            elif lists[i][3] == "照明/电工":
                p_type = 5
            elif lists[i][3] == "生活电器":
                p_type = 6
            elif lists[i][3] == "暖通空气":
                p_type = 7

            # 判断可见权限
            if lists[i][5] == "企业可见":
                visible = 0
            elif lists[i][5] == "企业用户均可见":
                visible = 1

            body = {
                "name": lists[i][0],
                "description": lists[i][1],
                "link_type": link_type,
                "type": p_type,
                "os_type": lists[i][4],
                "visibility": visible
            }
            lists_temp = {"pname": "", "pid": "", "pkey": ""}
            try:
                r = requests.post(url=url, json=body, headers=self.headers)
                if (r.status_code == 200):
                    res = eval(r.text)
                    print(res)
                    print("创建成功")
                    lists_temp["pname"] = res["name"]
                    lists_temp["pid"] = res["id"]
                    lists_temp["pkey"] = res["key"]
                    prd_lists.append(lists_temp)
                else:
                    print("创建失败,错误码:", r.status_code)
            except Exception:
                print('traceback.format_exc():\n%s' % traceback.format_exc())
                raise
        if len(prd_lists) != 0:
            EX.write_product_data(self.path_prd, "自动导出产品信息",
                                  prd_lists)  #将产品名称,pid,pkey写入excel
            # EX.write_product_data(self.path_prd, "Sheet2", prd_lists)  # 将产品名称,pid,pkey写入excel
            #将产品名称,pid,pkey写入ini文件
            j = 1
            for i in range(len(prd_lists)):
                section = 'DEVICE' + str(j)
                INI.write_to_ini(section, "PRODUCTNAME", prd_lists[i]["pname"])
                INI.write_to_ini(section, "PRODUCTID", prd_lists[i]["pid"])
                INI.write_to_ini(section, "PRODUCTKEY", prd_lists[i]["pkey"])
                INI.write_to_ini(section, "DEVICELIMIT", "10")
                j += 1