def post(self): json_data = self.request.body.decode('utf8') try: data = tornado.escape.json_decode(json_data) except Exception as e: logger.error('data:{} is not a json'.format(json_data)) return self.fail(reason='data is not a json') buyer_id = data.get(CONST.BUYER_ID, '') seller_id = data.get(CONST.SELLER_ID, '') name = data.get(CONST.NAME, '') email = data.get(CONST.EMAIL, '') if not all([buyer_id, seller_id, name, email]): return self.fail(reason='params error') buyer = self.get_buyer(buyer_id, seller_id) if not buyer: new_buyer = { CONST.BUYER_ID: buyer_id, CONST.SELLER_ID: seller_id, CONST.NAME: name, CONST.EMAIL: email } mongo_op.insert_one(self.buyer_coll, new_buyer) self.success()
def post(self): param = self.request.body.decode('utf8') json_dict = tornado.escape.json_decode(param) seller_id = json_dict.get(CONST.SELLER_ID) seller = mongo_op.find_one(self.seller_coll, {CONST.SELLER_ID: seller_id}) if not seller: mongo_op.insert_one(self.seller_coll, json_dict) self.success()
def copy_flow_to_status(self, keyword='unittest'): filter_dict = { '{}.{}'.format(CONST.KEYWORD_LIST, CONST.KEYWORD): keyword } flow = mongo_op.find_one(self.auto_flow_coll, filter_dict) if flow: flow[CONST.BUYER_ID] = self.buyer_id flow[CONST.STATUS] = 'processing' flow[CONST.KEYWORD] = keyword flow['origin_flow_id'] = str(flow.pop(CONST.ID, '')) for action in flow.get(CONST.ACTION_LIST, []): if action.get('action_type') == 'flow_start': flow['current_action_id'] = action.get('action_id') old_action_list = flow['action_list'] flow['action_list'] = {i['action_id']: i for i in old_action_list} print(flow) mongo_op.insert_one(self.auto_flow_coll_status, flow) return flow
def msg_record_to_db(self, chat_msg): mongo_op.insert_one(self.chat_msg_record_coll, chat_msg)