def getAll(self): "获取所有有效案例" try: self.cursor_stg.execute("SELECT case_id,title,origin_id,provider_id,isEnglish FROM cases WHERE isEnglish='Y' AND display=1;") for row in self.cursor_stg.fetchall(): case=Case() case.id=row[0] case.title=row[1] case.originId=row[2] case.providerId=row[3] case.isEnglish=row[4] yield case except Exception,e: self.log.error(e)
def getByOrigin(self,originId,providerId,isEnglish): "根据origin_id,provider_id,isEnglish获取案例" if originId and providerId and isEnglish: try: self.cursor_stg.execute("SELECT cases.case_id,cases.title,case_content.content,cases.issue_date,cases.effect_date FROM cases LEFT JOIN case_content ON cases.case_id=case_content.case_id WHERE cases.origin_id=%s AND cases.provider_id=%s AND cases.isEnglish='%s'" % (originId,providerId,isEnglish)) row =self.cursor_stg.fetchone() if row: case=Case() case.id=row[0] case.title=row[1] case.content=row[2] article.proDate=row[3] article.effectDate=row[4] case.originId=originId case.providerId=providerId case.isEnglish=isEnglish return case else: raise Exception("No case with origin_id:%s,provider_id:%s,isEnglish:%s found!" %(originId,providerId,isEnglish)) except Exception,e: self.log.error(e)
def getById(self,id): "根据主键信息获取案例" if id: try: self.cursor_stg.execute("SELECT cases.case_id as id,cases.title,case_content.content,cases.origin_id,cases.provider_id,cases.isEnglish,cases.issue_date,cases.effect_date FROM cases LEFT JOIN case_content ON cases.case_id=case_content.case_id WHERE cases.case_id=%s;" % id) row=self.cursor_stg.fetchone() if row: article=Case() article.id=row[0] article.title=row[1] article.content=row[2] article.originId=row[3] article.providerId=row[4] article.isEnglish=row[5] article.proDate=row[6] article.effectDate=row[7] return article else: raise Exception("No case with id %s found!" %id) except Exception,e: self.log.error(e)