Exemplo n.º 1
0
 def post(self, *args, **kwargs):
     """
     post请求,通过工厂id和需要更新的信息,完成生产线的插入
     :param args:
             name: 生产线名称
             workshop_id: 所属车间
     :param kwargs: /factory_id/
     :return: 成功返回201和生产线id,未能成功插入数据返回status_24
              参数错误返回status_22
     """
     # api日志记录
     SpiderApi.request(kwargs['c_user_id'], self.request.remote_ip, self.request.method,
                       self.request.uri)
     parameter = kwargs['parameter']
     parameter_list = parameter.split('/')
     request_data = kwargs['request_data']
     name = request_data.get('name')
     workshop_id = request_data.get('workshop_id')
     if len(parameter_list) == 2 and name and workshop_id:
         factory_id = parameter_list[0]
         product_line_obj = ProductLineDB(factory_id)
         result = product_line_obj.insert(name, workshop_id)
         product_line_obj.close()
         if result:
             SpiderApi.response(201)
             self.write_json(result, 201)
         else:
             SpiderApi.response(errors.status_24)
             raise HTTPError(**errors.status_24)
     else:
         SpiderApi.response(errors.status_22)
         raise HTTPError(**errors.status_22)
Exemplo n.º 2
0
 def put(self, *args, **kwargs):
     """
     put请求,通过工厂id,生产线id和更新的数据,完成生产线的更新
     :param args:
             name: 生产线名称
             workshop_id: 所属车间id
     :param kwargs: /factory_id/product_line_id
     :return: 成功返回200和生产线id,未找到设备返回status_24
              参数错误返回status_22
     """
     # api日志记录
     SpiderApi.request(kwargs['c_user_id'], self.request.remote_ip, self.request.method,
                       self.request.uri)
     parameter = kwargs['parameter']
     parameter_list = parameter.split('/')
     request_data = kwargs['request_data']
     name = request_data.get('name')
     workshop_id = request_data.get('workshop_id')
     if len(parameter_list) == 2 and name and workshop_id:
         factory_id = parameter_list[0]
         product_line_id = parameter_list[1]
         product_line_obj = ProductLineDB(factory_id)
         result = product_line_obj.update(product_line_id, name, factory_id, workshop_id)
         product_line_obj.close()
         if result:
             SpiderApi.response(200)
             self.write_json(result)
         else:
             SpiderApi.response(errors.status_24)
             raise HTTPError(**errors.status_24)
     else:
         SpiderApi.response(errors.status_22)
         raise HTTPError(**errors.status_22)
Exemplo n.º 3
0
 def post(self, *args, **kwargs):
     """
     post请求,通过工厂id,获取工厂下的所有的生产线
     :param args:
             page: 第几页
             per_page: 每页显几条数据
     :param kwargs: /factory_id
     :return: 成功返回201和该工厂的生产线列表,未找到数据返回status_24
              参数错误返回status_22
     """
     # api日志记录
     SpiderApi.request(kwargs['c_user_id'], self.request.remote_ip, self.request.method,
                       self.request.uri)
     factory_id = kwargs['factory_id']
     request_data = kwargs['request_data']
     page = request_data.get('page')
     per_page = request_data.get('per_page')
     if factory_id and page and per_page:
         product_line_obj = ProductLineDB(factory_id)
         limit = int(per_page)
         offset = (int(page) - 1) * limit
         result = product_line_obj.findall(offset, limit)
         product_line_obj.close()
         if result:
             SpiderApi.response(201)
             self.write_json(result, 201)
         else:
             SpiderApi.response(errors.status_24)
             raise HTTPError(**errors.status_24)
     else:
         SpiderApi.response(errors.status_22)
         raise HTTPError(**errors.status_22)
Exemplo n.º 4
0
 def get(self, *args, **kwargs):
     """
     get请求,通过工厂id和生产线id获取生产线的json信息
     :param args:
     :param kwargs: /factory_id/product_line_id
     :return: 成功返回200和设备json信息,未找到数据返回status_24
              参数错误返回status_22
     """
     # api日志记录
     SpiderApi.request(kwargs['c_user_id'], self.request.remote_ip, self.request.method,
                       self.request.uri)
     parameter = kwargs['parameter']
     parameter_list = parameter.split('/')
     if len(parameter_list) == 2:
         factory_id = parameter_list[0]
         product_line_id = parameter_list[1]
         product_line_obj = ProductLineDB(factory_id)
         result = product_line_obj.find(product_line_id)
         product_line_obj.close()
         if result:
             SpiderApi.response(200)
             self.write_json(result)
         else:
             SpiderApi.response(errors.status_24)
             raise HTTPError(**errors.status_24)
     else:
         SpiderApi.response(errors.status_22)
         raise HTTPError(**errors.status_22)
Exemplo n.º 5
0
 def delete(self, *args, **kwargs):
     """
     delete请求,通过工厂id和生产线id,删除生产线,删除之前判断该生产线下是否还有设备
     :param args:
     :param kwargs: /factory_id/product_line_id/
     :return: 成功返回204和None,未找到数据返回status_24
              参数错误返回status_22,该生产线下还有设备返回status_30
     """
     # api日志记录
     SpiderApi.request(kwargs['c_user_id'], self.request.remote_ip, self.request.method,
                       self.request.uri)
     parameter = kwargs['parameter']
     parameter_list = parameter.split('/')
     factory_id = parameter_list[0]
     product_line_id = parameter_list[1]
     equipment_obj = EquipmentDB(factory_id=factory_id)
     equipment_count = equipment_obj.get_counts_by_field('line_id', product_line_id)
     equipment_obj.close()
     if not equipment_count:
         if len(parameter_list) == 2:
             product_line_obj = ProductLineDB(factory_id)
             result = product_line_obj.remove(product_line_id)
             product_line_obj.close()
             if result:
                 SpiderApi.response(204)
                 self.write_json(None, 204)
             else:
                 SpiderApi.response(errors.status_24)
                 raise HTTPError(**errors.status_24)
         else:
             SpiderApi.response(errors.status_22)
             raise HTTPError(**errors.status_22)
     else:
         SpiderApi.response(errors.status_30)
         raise HTTPError(**errors.status_30)
Exemplo n.º 6
0
 def get(self, *args, **kwargs):
     """
     get请求,通过工厂id获取该工厂下的所有的工厂,生产线,设备,的层级关系树状图
     :param args:
     :param kwargs: /factory_id
     :return: 成功返回包含所有层级关系的列表,参数错误返回status_22
     """
     factory_id = kwargs['factory_id']
     if factory_id:
         workshop_obj = WorkShopDB(factory_id=factory_id)
         product_list_obj = ProductLineDB(factory_id=factory_id)
         equipment_obj = EquipmentDB(factory_id=factory_id)
         workshop_list = []  # 车间列表
         for workshop in workshop_obj.find(factory_id=factory_id):
             workshop_list.append(workshop)
             product_list = []  # 生产线列表
             for product_line in product_list_obj.find(
                     workshop_id=workshop['_id']):
                 equipment_list = []  # 设备列表
                 for equipment in equipment_obj.find(
                         line_id=product_line['_id']):
                     equipment_list.append(equipment)
                 product_line['equipment'] = equipment_list
                 product_list.append(product_line)
             workshop['product_line'] = product_list
             workshop_list.append(workshop)
         workshop_obj.close()
         product_list_obj.close()
         equipment_obj.close()
         self.write_json(workshop_list)
     else:
         raise HTTPError(**errors.status_22)
Exemplo n.º 7
0
 def get(self, *args, **kwargs):
     """
     post请求,通过工厂id,车间id,获取车间下的所有的生产线
     :param kwargs: /factory_id/group_id
     :return: 成功返回201和该工厂的生产线列表,未找到数据返回status_24
              参数错误返回status_22
     """
     # api日志记录
     SpiderApi.request(kwargs['c_user_id'], self.request.remote_ip,
                       self.request.method, self.request.uri)
     parameter = kwargs['parameter']
     parameter_list = parameter.split('/')
     if len(parameter_list) == 2:
         factory_id = parameter_list[0]
         workshop_id = parameter_list[1]
         product_line_obj = ProductLineDB(factory_id)
         result = product_line_obj.find(workshop_id=workshop_id)
         product_line_obj.close()
         if result:
             SpiderApi.response(200)
             self.write_json(list(result))
         else:
             SpiderApi.response(errors.status_24)
             raise HTTPError(**errors.status_24)
     else:
         SpiderApi.response(errors.status_22)
         raise HTTPError(**errors.status_22)
Exemplo n.º 8
0
 def delete(self, *args, **kwargs):
     """
     delete请求,通过工厂id和车间id,删除车间,删除之前要判断该车间下是否还有生产线
     :param args:
     :param kwargs: /factory_id/workshop_id
     :return: 成功返回204,未找到车间返回status_24
              参数错误返回status_22,如果该车间下还有生产线则返回status_30
     """
     # api日志记录
     SpiderApi.request(kwargs['c_user_id'], self.request.remote_ip,
                       self.request.method, self.request.uri)
     parameter = kwargs['parameter']
     parameter_list = parameter.split('/')
     factory_id = parameter_list[0]
     workshop_id = parameter_list[1]
     pro_line_obj = ProductLineDB(factory_id=factory_id)
     pro_line_count = pro_line_obj.get_counts_by_field(
         'workshop_id', workshop_id)
     pro_line_obj.close()
     if not pro_line_count:
         if len(parameter_list) == 2:
             workshop_obj = WorkShopDB(factory_id)
             result = workshop_obj.remove(workshop_id)
             workshop_obj.close()
             if result:
                 SpiderApi.response(204)
                 self.write_json(None, 204)
             else:
                 SpiderApi.response(errors.status_24)
                 raise HTTPError(**errors.status_24)
         else:
             SpiderApi.response(errors.status_22)
             raise HTTPError(**errors.status_22)
     else:
         SpiderApi.response(errors.status_30)
         raise HTTPError(**errors.status_30)
Exemplo n.º 9
0
 def findall(self, number=None, page=None):
     # 返回该工厂下的所有的车间
     try:
         result = []
         equipments = self.collection.find({}, {
             'create_time': 0
         }).skip(number).limit(page)
         for equipment in equipments:
             factory_name = FactoryDB().find(
                 equipment['factory_id'])['name']
             workshop_name = \
                 WorkShopDB(equipment['factory_id']).find(id=equipment['workshop_id'])['name']
             line_name = ProductLineDB(equipment['factory_id']).find(
                 id=equipment['line_id'])['name']
             equipment['factory_name'] = factory_name
             equipment['workshop_name'] = workshop_name
             equipment['line_name'] = line_name
             result.append(equipment)
         return result
     except:
         return None