示例#1
0
 def put(self, *args, **kwargs):
     """
     put请求,通过工厂id和车间id,和修改的车间信息,更新车间
     :param args:
             name: 车间名称
     :param kwargs: /factory_id/workshop_id
     :return: 成功返回车间的id和200,未找到车间返回status_24
              参数错误返回status_22
     """
     # api日志记录
     SpiderApi.request(kwargs['c_user_id'], self.request.remote_ip,
                       self.request.method, self.request.uri)
     parameter = kwargs['parameter']
     request_data = kwargs['request_data']
     name = request_data.get('name')
     parameter_list = parameter.split('/')
     if len(parameter_list) == 2 and name:
         factory_id = parameter_list[0]
         workshop_id = parameter_list[1]
         workshop_obj = WorkShopDB(factory_id)
         result = workshop_obj.update(workshop_id, name)
         workshop_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)
示例#2
0
 def get(self, *args, **kwargs):
     """
     get请求,通过工厂id和车间id获取该车间的详细信息
     :param args:
     :param kwargs:  /factory_id/workshop_id
     :return: 成功返回车间的信息,未找到数据返回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]
         workshop_obj = WorkShopDB(factory_id)
         result = workshop_obj.find(id=workshop_id)
         workshop_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)
示例#3
0
 def post(self, *args, **kwargs):
     """
     post请求,通过工厂id和车间信息,写入车间信息
     :param args:
     :param kwargs: /factory_id/
     :return: 成功返回车间id和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('/')
     request_data = kwargs['request_data']
     name = request_data.get('name')
     if len(parameter_list) == 2 and name:
         factory_id = parameter_list[0]
         workshop_obj = WorkShopDB(factory_id)
         result = workshop_obj.insert(name)
         workshop_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)
示例#4
0
 def post(self, *args, **kwargs):
     """
     post请求,通过工厂id获取该工厂下的所有的车间列表
     :param args:
             page: 第几页
             per_page: 每页显示几条记录
     :param kwargs:  /factory_id
     :return: 成功返回该工厂的车间列表,未找到返回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:
         workshop_obj = WorkShopDB(factory_id)
         limit = int(per_page)
         offset = (int(page) - 1) * limit
         result = workshop_obj.findall(offset, limit)
         workshop_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)
示例#5
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)
示例#6
0
    def delete(self, *args, **kwargs):
        """
        delete请求,通过工厂ID删除工厂,删除前需要做判断该工厂的车间数量是否为空
        :param args:
        :param kwargs: /factory_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)
        factory_id = kwargs['parameter']
        workshop_obj = WorkShopDB(factory_id=factory_id)
        workshop_count = workshop_obj.get_counts_by_field(
            'factory_id', factory_id)
        workshop_obj.close()
        if not workshop_count:
            if id:
                factory_obj = FactoryDB()
                result = factory_obj.remove(factory_id)
                # 同步缓存写入

                factory_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)
示例#7
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)
示例#8
0
 def findall(self, number=None, page=None):
     # 返回该工厂下的所有生产线
     try:
         result = []
         lines = self.collection.find({}, {
             "create_time": 0
         }).skip(number).limit(page)
         for line in lines:
             factory_name = FactoryDB().find(line['factory_id'])['name']
             workshop_name = WorkShopDB(
                 line['factory_id']).find(id=line['workshop_id'])['name']
             line['factory_name'] = factory_name
             line['workshop_name'] = workshop_name
             result.append(line)
         return result
     except:
         return None
示例#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