Example #1
0
 def paginate(cls, page=1, page_size=10, userId=None):
     start = page_size * (page - 1)
     end = page * page_size
     if userId:
         return dbSession.query(cls).filter(
             CheckInRecordModel.userId == userId).order_by(
                 -cls.createTime).slice(start, end).all()
     else:
         return dbSession.query(cls).order_by(-cls.createTime).slice(
             start, end).all()
Example #2
0
 def paginate(cls, page=1, page_size=10, location=None):
     start = page_size * (page - 1)
     end = page * page_size
     if location:
         return dbSession.query(cls).filter(
             SariNews.provinceName.like(
                 '%{}%'.format(location))).order_by(-cls.pubDate).slice(
                     start, end).all()
     else:
         return dbSession.query(cls).order_by(-cls.pubDate).slice(
             start, end).all()
Example #3
0
 def update(self, **kwargs):
     """根据实例更新数据"""
     kwargs['updateTime'] = datetime.now()
     row = dbSession.query(Orders).filter_by(uuid=self.uuid).first()
     for k, v in kwargs.items():
         setattr(row, k, v)
     dbSession.commit()
     return row
Example #4
0
 def verify_code(cls, phone, code):
     row = dbSession.query(cls).filter(cls.phone == phone).first()
     if row:
         if row.is_expired():
             dbSession.delete(row)
             dbSession.commit()
             return False, "您的验证码过期"
         else:
             if row.code == code:
                 dbSession.delete(row)
                 dbSession.commit()
                 return True, "验证成功"
             else:
                 dbSession.delete(row)
                 dbSession.commit()
                 return False, "您的验证码无效, 请重新申请"
     else:
         return False, "您的验证码无效"
Example #5
0
 def update_and_insert(cls, **kwargs):
     name = kwargs.get('companyName')
     row = dbSession.query(cls) \
         .filter(Company.companyName == name) \
         .first()
     if row:
         logger.debug(f"{name} 已经存在 更新数据")
         try:
             for k, v in kwargs.items():
                 setattr(row, k, v)
             dbSession.commit()
         except Exception as e:
             logger.error("Update Error " + str(e))
     else:
         logger.debug(f"{name} 不存在 新增数据")
         try:
             new_row = Company(**kwargs)
             dbSession.add(new_row)
             dbSession.commit()
         except Exception as e:
             logger.error("Insert Error " + str(e))
Example #6
0
 def update_and_insert(cls, **kwargs):
     province = kwargs.get('provinceName')
     city = kwargs.get('cityName')
     row = dbSession.query(cls) \
         .filter(and_(SariRecord.provinceName.like('%{}%'.format(province)),
                 SariRecord.cityName == city)) \
         .first()
     if row:
         logger.debug("已经存在 更新数据")
         try:
             for k, v in kwargs.items():
                 setattr(row, k, v)
             dbSession.commit()
         except Exception as e:
             logger.error("Update Error " + str(e))
     else:
         logger.debug("不存在 新增数据")
         try:
             new_row = SariRecord(**kwargs)
             dbSession.add(new_row)
             dbSession.commit()
         except Exception as e:
             logger.error("Insert Error " + str(e))
Example #7
0
 def update_and_insert(cls, **kwargs):
     infectSource = kwargs.get('infectSource')
     updateTime = int(str(kwargs.get('updateTime'))[:-3]) if kwargs.get(
         'updateTime') else None
     row = dbSession.query(cls) \
         .filter(and_(SariOverall.infectSource == infectSource,
                 SariRecord.updateTime == updateTime)) \
         .first()
     if row:
         logger.debug("头条 已经存在 更新数据")
         try:
             for k, v in kwargs.items():
                 setattr(row, k, v)
             dbSession.commit()
         except Exception as e:
             logger.error("Update Error " + str(e))
     else:
         logger.debug("头条 不存在 新增数据")
         try:
             new_row = SariOverall(**kwargs)
             dbSession.add(new_row)
             dbSession.commit()
         except Exception as e:
             logger.error("Insert Error " + str(e))
Example #8
0
 def update_and_insert(cls, **kwargs):
     title = kwargs.get('title')
     pubDate = int(str(
         kwargs.get('pubDate'))[:-3]) if kwargs.get('pubDate') else None
     row = dbSession.query(cls) \
         .filter(and_(SariNews.title == title,
                 SariNews.pubDate == pubDate)) \
         .first()
     if row:
         logger.debug("新闻 已经存在 更新数据")
         try:
             for k, v in kwargs.items():
                 setattr(row, k, v)
             dbSession.commit()
         except Exception as e:
             logger.error("Update Error " + str(e))
     else:
         logger.debug("新闻 不存在 新增数据")
         try:
             new_row = SariNews(**kwargs)
             dbSession.add(new_row)
             dbSession.commit()
         except Exception as e:
             logger.error("Insert Error " + str(e))
Example #9
0
 def by_user_id(cls, kid, page=1, page_size=10):
     start = page_size * (page - 1)
     end = page * page_size
     return dbSession.query(cls).filter_by(
         userId=kid).order_by(-cls.createTime).slice(start, end).all()
Example #10
0
 def by_country(cls):
     return dbSession.query(cls).filter(SariRecord.country != '中国').all()
Example #11
0
 def by_name(cls, name):
     return dbSession.query(cls)\
         .filter(User.userName.like('%{}%'.format(name))).all()
Example #12
0
 def by_name(cls, name):
     return dbSession.query(cls)\
         .filter(Company.companyName.like('%{}%'.format(name))).all()
Example #13
0
 def inQueue(self):
     return len(dbSession.query(Orders).filter(and_(Orders.id < self.id, Orders.Status == Orders.COMMIT)).all())
Example #14
0
 def by_address(cls, address, limit=10):
     return dbSession.query(cls).filter(cls.Address.like('%{}%'.format(address))).limit(limit)
Example #15
0
 def all(cls):
     return dbSession.query(cls).order_by(-cls.createTime).all()
Example #16
0
 def by_id(cls, _id):
     return dbSession.query(cls).filter(cls.id == _id).first()
Example #17
0
 def by_id(cls, kid):
     return dbSession.query(cls).filter_by(id=kid).first()
Example #18
0
 def by_limit(cls, num):
     return dbSession.query(cls).order_by(-cls.updateTime).limit(num)
Example #19
0
 def by_lasted(cls):
     return dbSession.query(cls).order_by(-cls.updateTime).first()
Example #20
0
 def by_phone(cls, userPhone):
     return dbSession.query(cls).filter_by(userPhone=userPhone).first()
Example #21
0
 def by_id_card(cls, id_card):
     return dbSession.query(cls).filter_by(userIdCard=id_card).first()
Example #22
0
 def order_over(cls, uuid):
     order = dbSession.query(cls).filter(cls.uuid == uuid).first()
     if order:
         order.Status = Orders.SUCCESS
         order.updatedTime = datetime.now()
         dbSession.commit()
Example #23
0
 def get_one(cls, key, eType, msgType):
     return dbSession.query(cls) \
         .filter(and_(AuthReplyModel.EventKey == key,
                      AuthReplyModel.EventType == eType,
                      AuthReplyModel.MsgType == msgType)) \
         .first()
Example #24
0
 def by_user_id(cls, user_id):
     return dbSession.query(cls).order_by(-cls.createdTime).filter(cls.userId == user_id).all()
Example #25
0
 def paginate(cls, page=1, page_size=10):
     start = page_size * (page - 1)
     end = page * page_size
     return dbSession.query(cls).order_by(-cls.createTime).slice(
         start, end).all()
Example #26
0
 def hot_product(cls):
     return dbSession.query(cls).filter_by(isHot=True).order_by(-cls.createdTime).all()
Example #27
0
 def all(cls):
     return dbSession.query(cls).all()
Example #28
0
 def by_lasted(cls):
     return dbSession.query(cls).order_by(-cls.pubDate).first()
Example #29
0
 def by_province(cls, province):
     return dbSession.query(cls)\
         .filter(SariRecord.provinceName.like('%{}%'.format(province))).all()
Example #30
0
 def by_uuid(cls, uuid):
     return dbSession.query(cls).filter(cls.uuid == uuid).first()