def SellOrNotSellProduct(self,Command:SellOrNotSellProductCommand): UpdatedProduct = Product() Saga = SagaParticipant() Events, SnapshotData = ProductRepository().Find(Command.SagaId,Command.SagaType) Saga.Revise(SnapshotData,Events) Events, SnapshotData = ProductRepository().Find(Saga.Data['ProductId'],'Product') UpdatedProduct.Revise(SnapshotData,Events) Events = UpdatedProduct.proccess_SellOrNotSellProductCommand(Command) UpdatedProduct.apply_ProductSoldOrNotSoldEvent(Events[0]) ProductRepository().Update((UpdatedProduct,),Events,MessageId=Command.MessageId)
def ValidateOrderProduct(self,Command): try: SnapshotData = ProductRepository().ConnectProductToOrder(Command.ProductName) except NotAvailableProduct: SnapshotData = ProductRepository().ConnectProductToOrder(Command.ProductName) UpdatedProduct = Product() UpdatedProduct.Revise(SnapshotData,[]) Events = UpdatedProduct.proccessOrderProductValidationCommand(Command) UpdatedProduct.applyProductValidatedEvent(Events[0]) Saga = SagaParticipant() Saga.Create(Command.OrderId,Command.SagaType,Events[1].EventJsonData()) ProductRepository().Update((UpdatedProduct,Saga),Events,MessageId=Command.MessageId)
def Consumes(c): while True: msg = c.poll(1.0) #Consumes Messages from Kafka if msg is None: continue if msg.error(): print("Consumer error: {}".format(msg.error())) continue Msg = json.loads(msg.value().decode('utf-8')) if ProductRepository().CheckDuplicatedMessages( Msg['Message']['Head'] ['MessageId']): #If Message is not duplicated print( f'Message:Received, Service:Προϊόντα, EventType:{Msg["Message"]["Head"]["EventType"]}' ) CommandHandler(msg.value().decode( 'utf-8')).CommandHandler() #Activate the CommandHandler c.commit(msg) #Commits the offset of the message that it consumes c.close()
def post(self): # 依赖注入 Mapper.register(ModelProductService, ProductRepository()) Mapper.register(ProductService, ModelProductService()) product_service = ProductService() jd_buy_cookie = self.get_cookie('jd_buy_list') buy_str = escape.url_unescape(jd_buy_cookie) buy_list = json.loads(buy_str) data_list = [] for item in buy_list: print(item) temp = {} product_title = item['product_title'] product_img = item['product_img'] count = item['count'] price_id = item['price_id'] temp["count"] = count temp["price_id"] = price_id result = product_service.fetch_price_detail(int(price_id)) data_list.append(temp) print(data_list) print(result) self.write(json.dumps(data_list))
def AddProduct(self,Commands:list): for Command in Commands: NewProduct = Product() Events = NewProduct.processForProductCreationCommand(Command) NewProduct.applyForProductCreationEvent(Events[0]) ProductRepository().Create((NewProduct,),Events) return f'Products inserted successfully'
def get(self,*args,**kwargs): #获取一级分类 #循环一级分类,获取二级分类 #循环二级分类,获取三级分类 c=CategoryService(CategoryRepository()) category_list=c.fetch_all_category() p=ProductService(ProductRepository()) product_dict=p.fetch_index_product()
def delivery_report(self, err, msg, Details): msg = json.loads(msg) print( f'Message:Send, Service: Προΐόντα, EventType:{msg["Message"]["Head"]["EventType"]}' ) ProductRepository().UpdateEventThatItHasBeenPublished( Details[0], Details[1], Details[2]) #Update the event that was published successfully
def get(self, *args, **kwargs): # 数据库中获取数据,显示在页面 merchant_id = 14 product_id = self.get_argument('productid', None) service = ProductService(ProductRepository()) series = service.get_product_detail(merchant_id, product_id) self.render('Product/JdProductDetail.html', product_id=product_id)
def SendMessagesToMessageBroker(self): UnpublishedEvents = ProductRepository().GetUnpublishedEvents() #loads unpuplished events MC = MessageCreator() for Row in UnpublishedEvents: if Row.eventtype not in ['ProductLockedEvent','ProductNotSoldEvent']: #If the type of the eventis not one of these in the list Details = [Row.entityid,Row.entitytype,Row.eventtime,Row.eventtype] Message, Topic = MC.ProduceMessage(Row.entityid, Row.eventdata, Row.eventtype) #Creates the message that will be send to Kafka self.ProduceToBroker.Publish(Message, Topic, Details) #Send the event to Kafka
def get(self, *args, **kwargs): product_id = kwargs.get('product_id', None) price_id = kwargs.get('price_id', None) if not product_id or not price_id: self.redirect('/Index.html') return # 根据商品ID获取商品信息,商户信息,价格列表,图片 p = ProductService(ProductRepository()) product_dict = p.fetch_product_detail(product_id, price_id) self.render('Home/Detail.html', product_dict=product_dict)
def get(self, *args, **kwargs): summary = 'success' product_id = self.get_argument('productid', None) try: if not product_id: raise Exception('请输入商品ID') ip = self.request.remote_ip service = ProductService(ProductRepository()) service.create_puv(product_id, ip) except Exception as e: summary = str(e) self.write(summary)
def get(self, *args, **kwargs): # 获取一级分类 # 循环一级分类,获取二级分类 # 循环二级分类,获取三级分类 c = CategoryService(CategoryRepository()) category_list = c.get_all_category() p = ProductService(ProductRepository()) product_dict = p.fetch_index_product() self.render('Home/Index.html', category_list=category_list, product_dict=product_dict)
def GetWarehouseState(self,Command): Warehouse = { 'Samsung galaxy 9': 0, 'Samsung galaxy A70 Dual': 0, 'Apple iphone 11': 0 } for Events in ProductRepository().LoadEachProductEvents(Command.Date): product = Product() if Events: product.r(Events) if product.State not in ['Sold','Validated']: Warehouse[product.Name] = Warehouse[product.Name] + 1 return Warehouse
def get(self, *args, **kwargs): ret = {"status": False, "summary": "", "data": []} try: merchant_id = 6 product_id = self.get_argument("product_id", None) if not product_id: raise Exception("请输入商品ID") service = ProductService(ProductRepository()) series = service.get_upv(merchant_id, product_id) ret["data"] = series ret["status"] = True except Exception as e: ret["summary"] = str(e) self.write(json.dumps(ret))
def get(self, *args, **kwargs): ret = {'status': False, 'summary': '', 'data': []} try: merchant_id = 14 product_id = self.get_argument('product_id', None) if not product_id: raise Exception('请输入产品ID') service = ProductService(ProductRepository()) series = service.get_upv(merchant_id, product_id) ret['data'] = series ret['status'] = True except Exception as e: ret['summary'] = str(e) self.write(json.dumps(ret))
def get(self, *args, **kwargs): ret = {"status": False, "summary": "", "total": 0, "row": []} try: product_id = self.get_argument("product_id", None) if not product_id: raise Exception("商品id不能为空") merchant_id = 6 service = ProductService(ProductRepository()) total, result = service.get_price_by_product_id( merchant_id=merchant_id, product_id=product_id) ret["total"] = total ret['rows'] = result ret["status"] = True except Exception as e: ret["summary"] = str(e) self.write(json.dumps(ret, cls=JsonCustomEncoder))
def post(self, *args, **kwargs): ret = {"status": False, "summary": "", "detail": ""} form = JdProductForm() try: is_valid = form.valid(self) if is_valid: merchant_id = 6 print("data", form._value_dict) service = ProductService(ProductRepository()) service.create_product(merchant_id, form._value_dict) ret["status"] = True else: ret["detail"] = form._error_dict except Exception as e: ret["summary"] = str(e) self.write(json.dumps(ret))
def get(self, *args, **kwargs): product_id = kwargs.get('product_id', None) price_id = kwargs.get('price_id', None) if not product_id or not price_id: self.redirect('/Index.html') return # 依赖注入 Mapper.register(ModelProductService, ProductRepository()) Mapper.register(ProductService, ModelProductService()) product_service = ProductService() # 根据商品ID获取商品信息,商户信息,价格列表,图片 # p = ProductService(ProductRepository()) product_dict = product_service.fetch_product_detail( product_id, price_id) self.render('Home/Detail.html', product_dict=product_dict.rows)
def post(self, *args, **kwargs): ret = {'status': False, 'summary': '', 'detail': ""} form = JdProductForm() try: is_valid = form.valid(self) if is_valid: # print(is_valid, form._error_dict, form._value_dict) merchant_id = 14 service = ProductService(ProductRepository()) service.create_product(merchant_id, form._value_dict) ret['status'] = True else: ret['detail'] = form._error_dict except Exception as e: ret['summary'] = str(e) self.write(json.dumps(ret))
def delete(self, *args, **kwargs): ret = { "summary": "", "status": False, } nid = self.get_argument("nid", None) if nid: try: service = ProductService(ProductRepository()) result = service.delete_price(nid) if not result: raise Exception("删除失败") ret["status"] = True except Exception as e: ret["summary"] = str(e) else: ret['summary'] = "请选择要陕删除的行" self.write(json.dumps(ret))
def get(self): """ 根据参数,获取产品信息(type:自营(商户ID),type:所有商品) 后台管理用户登陆成功后,Session中保存自营ID 自营ID=1 """ # 手动获取京东自营ID为14 merchant_id = 14 page = int(self.get_argument('page', 1)) rows = int(self.get_argument('rows', 10)) start = (page - 1) * rows # 依赖注入 Mapper.register(modelProductService, ProductRepository()) Mapper.register(ProductService, modelProductService()) product_service = ProductService() response = product_service.get_page_by_merchant_id( merchant_id, start, rows)
def get(self, *args, **kwargs): ret = {"status": False, "summary": "", "data": {}} try: product_id = self.get_argument('product_id', None) if not product_id: raise Exception("请输入产品Id") else: merchant_id = 6 service = ProductService(ProductRepository()) data = service.get_product_by_id(merchant_id=merchant_id, product_id=product_id) if not data: raise Exception("未获取到商品信息") ret["status"] = True ret["data"] = data except Exception as e: ret["summary"] = str(e) self.render("Product/JdProductPriceManager.html", **ret)
def delete(self, *args, **kwargs): product_id = self.get_argument("nid") print(product_id) ret = {"summary": "", "status": False} if product_id: try: service = ProductService(ProductRepository()) db_result = service.delete_product(product_id) if db_result: ret["status"] = True else: raise Exception("删除失败") except Exception as e: print(e) ret["summary"] = str(e) else: ret["summary"] = "请选择要删除的行" self.write(json.dumps(ret))
def get(self, *args, **kwargs): ret = {'status': False, 'summary': '', 'total': 0, 'rows': []} try: product_id = self.get_argument('productid', None) if not product_id: raise Exception('商品ID不能为空') merchant_id = 14 service = ProductService(ProductRepository()) total, result = service.get_price_by_product_id( merchant_id=merchant_id, product_id=product_id) ret['total'] = total ret['rows'] = result ret['status'] = True except Exception as e: ret['summary'] = str(e) self.write(json.dumps(ret, cls=JsonCustomEncoder))
def get(self, *args, **kwargs): ret = {'status': False, 'summary': '', 'data': {}} try: product_id = self.get_argument('productid', None) if not product_id: raise Exception('请输入商品ID') merchant_id = 14 service = ProductService(ProductRepository()) result = service.get_product_by_id(merchant_id=merchant_id, product_id=product_id) if not result: raise Exception('未获取商品信息') ret['status'] = True ret['data'] = result except Exception as e: ret['summary'] = str(e) self.render('Product/JdProductPriceManager.html', **ret)
def get(self, *args, **kwargs): error_summary = "" product_id = self.get_argument("product_id", None) if not product_id: crumbs = "添加产品" method = "post" else: crumbs = "编辑产品" method = "put" #根据产品id获取产品信息 merchant_id = 6 service = ProductService(ProductRepository()) data = service.get_product_by_id(merchant_id, product_id) print(data) self.render("Product/JdProductEdit.html", crumbs=crumbs, method=method, data=data)
def get(self, *args, **kwargs): # 根据参数,获取产品信息(type:自营(商户ID),type:所有商品) # 后台管理用户登陆成功后,Session中保存自营ID # 自营ID=1 ret = {"status": False, "message": "", "total": 0, "rows": []} try: merchant_id = 6 page = int(self.get_argument("page", 1)) rows = int(self.get_argument("rows", 10)) start = (page - 1) * 10 service = ProductService(ProductRepository()) total, data = service.get_page_by_merchant_id( merchant_id, start, rows) ret["status"] = True ret["total"] = total ret["rows"] = data except Exception as e: ret["message"] = str(e) self.write(json.dumps(ret))
def put(self, *args, **kwargs): ret = {"status": False, "summary": "", "detail": {}} try: form = JdProductPriceForm() is_valid = form.valid(self) if is_valid: nid = form._value_dict.pop("nid") merchant_id = 6 service = ProductService(ProductRepository()) service.update_price(merchant_id, form._value_dict["product_id"], nid, form._value_dict) else: ret["detail"] = form._error_dict raise Exception("输入内容不合法") ret['status'] = True except Exception as e: print(e) ret["summary"] = str(e) self.write(json.dumps(ret))
def put(self, *args, **kwargs): ret = {'status': False, 'summary': '', 'detail': {}} try: form = JdProductPriceForm() is_valid = form.valid(self) if is_valid: nid = form._value_dict.pop('nid') merchant_id = 14 service = ProductService(ProductRepository()) service.update_price(merchant_id, form._value_dict['product_id'], nid, form._value_dict) else: ret['detail'] = form._error_dict raise Exception('输入内容不合法') ret['status'] = True except Exception as e: ret['summary'] = str(e) self.write(json.dumps(ret))
def get(self, *args, **kwargs): # 根据参数,获取产品信息(type:自营(商户ID),type:所有商品) # 后台管理用户登陆成功后,Session中保存自营ID # 自营ID=1 ret = {'status': False, 'message': '', 'total': 0, 'rows': []} try: # 手动获取京东自营ID为14 merchant_id = 14 page = int(self.get_argument('page', 1)) rows = int(self.get_argument('rows', 10)) start = (page - 1) * rows service = ProductService(ProductRepository()) total, result = service.get_page_by_merchant_id( merchant_id, start, rows) ret['status'] = True ret['total'] = total ret['rows'] = result except Exception as e: ret['message'] = str(e) self.write(json.dumps(ret))