def post(self, *args, **kwargs): """ post请求,通过工厂名字插入工厂数据, 单机版只能允许新建一个工厂 :param args: name: 工厂名称 :param kwargs: :return: 成功返回工厂id和201,未成功插入返回status_24 参数错误返回status_22,已经有一个工厂返回status_31 """ # api日志记录 SpiderApi.request(kwargs['c_user_id'], self.request.remote_ip, self.request.method, self.request.uri) factory_obj = FactoryDB() count = factory_obj.get_counts() request_data = kwargs['request_data'] name = request_data.get('name') if not count: if name: result = factory_obj.insert(name=name) # 同步缓存写入 factory_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) else: SpiderApi.response(errors.status_31) raise HTTPError(**errors.status_31)
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)
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)
def post(self, *args, **kwargs): """ post请求,通过用户名和密码获取token,rf_token以及用户的角色 token的有效期为两小时,rf_token的有效期为30小时 :param args: username: 用户名 password: 密码 :param kwargs: :return: 成功返回token,rf_token,role的json以及201,密码验证错误返回status_23 没有该用户返回status_26,缺少参数返回status_22 """ # 请求数据检查 content_type = self.request.headers.get('Content-Type') if content_type != 'application/json': raise HTTPError(**errors.status_34) try: request_data = json.loads(self.request.body) except: raise HTTPError(**errors.status_35) username = request_data.get("username") password = request_data.get("password") # api日志记录 SpiderApi.request(username, self.request.remote_ip, self.request.method, self.request.uri) if username and password: user = UserDB().find(username=username) if user: encrypt_password = Encryption.generate_password( password, parser.auth_salt) if encrypt_password == user["password"]: token = genTokenSeq(user["_id"], user["user_role"], 7200) rf_token = genRfTokenSeq(user["_id"], user["user_role"], 108000) SpiderApi.response(201) # 获取工厂名称 factory_obj = FactoryDB() factory_name = factory_obj.find( id=user["factory_id"])['name'] self.write_json( { 'token': token, 'rf_token': rf_token, 'role': user["user_role"], 'factory_id': user["factory_id"], "factory_name": factory_name, "username": user['username'], "user_id": user["_id"] }, 201) else: SpiderApi.response(errors.status_23) raise HTTPError(**errors.status_23) else: SpiderApi.response(errors.status_26) raise HTTPError(**errors.status_26) else: SpiderApi.response(errors.status_22) raise HTTPError(**errors.status_22)
def put(self, *args, **kwargs): """ put请求,用户通过该接口直接修改基本信息 通过解析传递过来的token中的用户id和修改的用户id做对比,相同才能够然他修改 该接口只能修改用户名和密码 :param args: name: 用户名 password: 密码 :param kwargs: /user_id :return: 成功返回用户id和200,未找到对象返回status_24 参数错误返回status_22, 不是修改自己的信息返回status_29 """ # api日志记录 SpiderApi.request(kwargs['c_user_id'], self.request.remote_ip, self.request.method, self.request.uri) user_id = kwargs['user_id'] if kwargs['c_user_id'] == user_id: request_data = kwargs['request_data'] name = request_data.get('name') password = request_data.get('password') if user_id and name and password: user_obj = UserDB() old_user_name = user_obj.find(id=user_id)['username'] if old_user_name != name: # 用户名唯一性检测 uniqueness = user_obj.find(username=name) if uniqueness: SpiderApi.response(errors.status_33) raise HTTPError(**errors.status_33) result = user_obj.update(user_id, username=name, password=password) user_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) else: SpiderApi.response(errors.status_29) raise HTTPError(**errors.status_29)
def put(self, *args, **kwargs): """ put请求,通过工厂和设备id以及需要修改的字段,更新设备信息 :param args: name: 设备名 workshop_id: 工厂id line_id: 生产线id factory_number: 出厂编号 factory_time: 出厂时间 product_number: 产品型号 :param kwargs: /factory_id/equipment_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'] parameter_list = parameter.split('/') request_data = kwargs['request_data'] name = request_data.get('name') workshop_id = request_data.get('workshop_id') line_id = request_data.get('line_id') factory_number = request_data.get('factory_number') factory_time = request_data.get('factory_time') product_number = request_data.get('product_number') factory_id = parameter_list[0] equipment_id = parameter_list[1] equipment_obj = EquipmentDB(factory_id) if factory_number: # 先判断是否更新factory_number if factory_number != equipment_obj.find( id=equipment_id)['factory_number']: # 出厂编号唯一性验证 count = equipment_obj.get_counts_by_field( 'factory_number', factory_number) if count: SpiderApi.response(errors.status_36) raise HTTPError(**errors.status_36) if len(parameter_list) == 2 and name and workshop_id and line_id and factory_number \ and factory_time and product_number: result = equipment_obj.update(equipment_id, name, factory_id, workshop_id, line_id, factory_number, factory_time, product_number) equipment_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)
def post(self, *args, **kwargs): # TODO 插入之前要判断出厂编号的唯一性 """ post请求,通过工厂ID和插入的设备详细插入设备: 插入之前要判断出厂编号的唯一性 :param args: name: 设备名 workshop_id: 工厂id line_id: 生产线id factory_number: 出厂编号 factory_time: 出厂时间 product_number: 产品型号 :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') workshop_id = request_data.get('workshop_id') line_id = request_data.get('line_id') factory_number = request_data.get('factory_number') factory_time = request_data.get('factory_time') product_number = request_data.get('product_number') factory_id = parameter_list[0] equipment_obj = EquipmentDB(factory_id) # 出厂编号唯一性验证 count = equipment_obj.get_counts_by_field('factory_number', factory_number) if not count: if parameter_list and name and workshop_id and line_id and factory_number and factory_time and product_number: result = equipment_obj.insert(name, workshop_id, line_id, factory_number, factory_time, product_number) equipment_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) else: SpiderApi.response(errors.status_36) raise HTTPError(**errors.status_36)
def post(self, *args, **kwargs): """ post请求,通过该接口能够查询设备在指定月份的报表信息 :param args: date: 年月字符串 search_field: 查找字段 :param kwargs: /factory_id/equipment_id :return: 成功返回报表信息 """ # 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'] date = request_data.get('date') search_field = request_data.get('search_field') # 对查询的参数进行判断 if search_field not in ALLOWED_PARA: SpiderApi.response(errors.status_37) raise HTTPError(**errors.status_37) if len(parameter_list) == 2 and date and search_field: factory_id = parameter_list[0] equipment_id = parameter_list[1] # 对传递过来的date时间字符串进行处理 date_list = map(int, date.split("-")) year = date_list[0] month = date_list[1] start_datetime = datetime.datetime.combine( datetime.date(year, month, 1), datetime.time.min) # 获取查询月的最后一天日期 _, last_day_num = calendar.monthrange(year, month) end_datetime = datetime.datetime.combine( datetime.date(year, month, last_day_num), datetime.time.min) # 从每日报表中获取查询的数据 daily_report_obj = DailyReportDB(factory_id=factory_id, equipment_id=equipment_id) result = daily_report_obj.get_daily_rep_dict( start_time=start_datetime, end_time=end_datetime, field=search_field) daily_report_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)
def delete(self, *args, **kwargs): """ delete请求,通过设备id和工厂id删除指定设备 删除设备的时候不需要检测该分类下是否还有子类,但是需要在班组的设备列表中删除该设备 :param args: :param kwargs:/factory_id/equipment_id :return:成功返回204,未能成功删除返回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] equipment_id = parameter_list[1] equipment_obj = EquipmentDB(factory_id) workgroup_obj = WorkGroupDB(factory_id=factory_id) result = equipment_obj.remove(equipment_id) result1 = workgroup_obj.del_equipment_in_list( equipment_id) # 在班组的设备列表中删除该设备 equipment_obj.close() workgroup_obj.close() if result and result1: SpiderApi.response(204) self.write_json(None, status_code=204) else: SpiderApi.response(errors.status_24) raise HTTPError(**errors.status_24) else: SpiderApi.response(errors.status_22) raise HTTPError(**errors.status_22)
def put(self, *args, **kwargs): """ put请求,通过工厂id和班组id,和需要修改的信息,更新班组 :param args: 利用(application/json)传递 name: 班组名称 :param kwargs: /factory_id/group_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') equipment_list = request_data.get('equipment_list') if len(parameter_list) == 2: factory_id = parameter_list[0] group_id = parameter_list[1] group_obj = WorkGroupDB(factory_id=factory_id) result = group_obj.update(id=group_id, name=name, equipment_list=equipment_list) group_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)
def post(self, *args, **kwargs): """ post请求,通过工厂id和班组名称,添加班组 :param args: 利用(application/json)传递 name: 班组名称 equipment_list: 设备列表 :param kwargs: /factory_id/ :return: 成功返回201和班组的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('/') request_data = kwargs['request_data'] name = request_data.get('name') equipment_list = request_data.get('equipment_list') if len(parameter_list) == 2 and name and isinstance( equipment_list, list): factory_id = parameter_list[0] group_obj = WorkGroupDB(factory_id=factory_id) result = group_obj.insert(name=name, equipment_list=equipment_list) group_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_24) raise HTTPError(**errors.status_22)
def post(self, *args, **kwargs): """ post请求,获取所有工厂的列表 :param args: page: 第几页 per_page: 每页显示几条数据 :param kwargs: :return: 成功返回工厂列表和201,未找到工厂返回status_24 参数错误返回status_22 """ # api日志记录 SpiderApi.request(kwargs['c_user_id'], self.request.remote_ip, self.request.method, self.request.uri) request_data = kwargs['request_data'] page = request_data.get('page') per_page = request_data.get('per_page') if page and per_page: limit = int(per_page) offset = (int(page) - 1) * limit factory_obj = FactoryDB() result = factory_obj.findall(offset, limit) factory_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)
def post(self, *args, **kwargs): """ post请求,通过rf_token获取最新的token值 :param args: rf_token: 有效期为30小时的rf_token,用来获取最新的token :param kwargs: :return: 成功返回201和token的json,rf_token错误返回status_28 参数错误返回status_27 """ # 请求数据检查 content_type = self.request.headers.get('Content-Type') if content_type != 'application/json': raise HTTPError(**errors.status_34) try: request_data = json.loads(self.request.body) except: raise HTTPError(**errors.status_35) rf_token = request_data.get("rf_token") # api日志记录 SpiderApi.request(None, self.request.remote_ip, self.request.method, self.request.uri) if rf_token: result = RftokenAuth(rf_token) if result[0] and result[1]: SpiderApi.response(201) self.write_json({'token': result[2]}, 201) else: SpiderApi.response(errors.status_28) raise HTTPError(**errors.status_28) else: SpiderApi.response(errors.status_27) raise HTTPError(**errors.status_27)
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)
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)
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)
def put(self, *args, **kwargs): """ put请求,通过工厂id和需要更新的数据 :param args: name: 需要更新的工厂名称 :param kwargs: /factory_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) factory_id = kwargs['parameter'] request_data = kwargs['request_data'] name = request_data.get('name') if factory_id and name: factory_obj = FactoryDB() result = factory_obj.update(factory_id, name) # 同步缓存写入 factory_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)
def delete(self, *args, **kwargs): """ delete请求,通过用户id,直接删除用户 :param args: :param kwargs: /user_id :return: 成功返回204,未找到返回status_24 参数错误返回status_22 """ # api日志记录 SpiderApi.request(kwargs['c_user_id'], self.request.remote_ip, self.request.method, self.request.uri) user_id = kwargs['user_id'] if user_id: user_obj = UserDB() result = user_obj.remove(id=user_id) user_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)
def get(self, *args, **kwargs): """ get请求,通过工厂id获取工厂的信息json :param args: :param kwargs: /factory_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) factory_id = kwargs['parameter'] if factory_id: factory_obj = FactoryDB() result = factory_obj.find(factory_id) factory_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)
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: equipment_obj = EquipmentDB(factory_id) limit = int(per_page) offset = (int(page) - 1) * limit result = equipment_obj.findall(offset, limit) equipment_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)
def get(self, *args, **kwargs): """ get请求,通过设备id和工厂id获取该设备详细信息接口 :param args: :param kwargs: /factory_id/equipment_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] equipment_id = parameter_list[1] equipment_obj = EquipmentDB(factory_id) result = equipment_obj.find(id=equipment_id) equipment_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)
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)
def delete(self, *args, **kwargs): """ delete请求:通过factory_id和schedule_id,删除班次 :param args: :param kwargs: /factory_id/schedule_id :return: 成功返回204,未找到数据返回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] schedule_id = parameter_list[1] schedule_obj = WorkScheduleDB(factory_id=factory_id) result = schedule_obj.remove(id=schedule_id) schedule_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)
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)
def delete(self, *args, **kwargs): """ delete请求,通过工厂id和班组id,删除班组信息, 删除班组信息的时候要删除班次中包含班组的记录设置为None :param args: :param kwargs: /factory_id/group_id :return: 成功返回204,未找到班组返回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] group_id = parameter_list[1] group_obj = WorkGroupDB(factory_id=factory_id) result = group_obj.remove(id=group_id) schedule_obj = WorkScheduleDB(factory_id=factory_id) result1 = schedule_obj.set_none_for_groupid(group_id=group_id) group_obj.close() schedule_obj.close() if result and result1: 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)
def get(self, *args, **kwargs): """ get请求,通过用户id获取该用户的详细信息的json :param args: :param kwargs: /user_id :return: 成功返回用户详细信息的json,未找到该用户返回status_24 参数错误返回status_22 """ # api日志记录 SpiderApi.request(kwargs['c_user_id'], self.request.remote_ip, self.request.method, self.request.uri) user_id = kwargs['user_id'] if user_id: user_obj = UserDB() result = user_obj.find(user_id) user_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)
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)
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: limit = int(per_page) offset = (int(page) - 1) * limit group_obj = WorkGroupDB(factory_id=factory_id) result = group_obj.findall(factory_id, offset, limit) group_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)
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)
def get(self, *args, **kwargs): """ get请求,通过工厂id和设备id,获取拥有该设备的所有班组信息 :param args: :param kwargs: /factory_id/equipment_id :return: 成功返回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'] parameter_list = parameter.split('/') if len(parameter_list) == 2: factory_id = parameter_list[0] equipment_id = parameter_list[1] group_obj = WorkGroupDB(factory_id=factory_id) result = group_obj.get_group_for_equipment( equipment_id=equipment_id) group_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)