1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
| class DBHelper:
def __init__(self): try: self.conn = pymysql.connect(host=DBConfig.HOST, user=DBConfig.USER, password=DBConfig.PASS, database=DBConfig.NAME, charset=DBConfig.CHARSET) except Exception as ex: self.conn = None
logger.exception(ex)
def close(self): try: self.conn.close() if self.conn is not None else '' except Exception as ex: logger.exception(ex)
def query_for_download(self): query_result = list() try: cursor = self.conn.cursor() query = "SELECT d.data_query_id,d.data_time_stamp,d.interval_cycle,u.user_name FROM business_rule_sumary s," \ "business_rule_detail d,sys_user u WHERE s.id=d.rule_sumary_id AND s.rule_state >= 7 AND " \ "s.create_user=u.user_id GROUP BY d.data_query_id;" cursor.execute(query)
query_result = [DownloadModel(item) for item in cursor.fetchall()] except Exception as ex: logger.exception(ex) finally: self.close() return query_result
def update_download_info(self, id_query, data_time, download_state): try: cursor = self.conn.cursor() storage_time = TimeUtil().get_current_time() cursor.execute("INSERT INTO stat_download_info(id_query,data_time,download_state,storage_time) " "VALUES('%s','%s',%d,'%s')" % (id_query, data_time, int(download_state), storage_time)) self.conn.commit() except Exception as ex: logger.exception(ex)
def update_business_time(self, id_query, next_time_repr, next_time_str): try: cursor = self.conn.cursor() update_time = TimeUtil().get_current_time() cursor.execute("SELECT id, rule_sumary_id FROM business_rule_detail WHERE data_query_id='%s'" % id_query) for rule_info in cursor.fetchall(): command = "UPDATE business_rule_detail d, business_rule_sumary s SET d.data_time_stamp='%s'," \ "d.update_time='%s', s.data_time='%s',s.update_time='%s' WHERE d.id=%d AND s.id=%d" % \ (next_time_str, update_time, next_time_repr, update_time, rule_info[0], rule_info[1]) cursor.execute(command) self.conn.commit() except Exception as ex: logger.exception(ex)
def query_for_operation(self, rule_id, batch_id, query_id): executor_model = None try: cursor = self.conn.cursor() query_operations_cmd = "SELECT b.rule_sumary_id, b.create_user,s.user_name,k.operation_name,o.operation_id, " \ "o.operation_attach FROM business_rule_detail b, knowledge_rule_operation k, " \ "business_rule_operation o, sys_user s WHERE b.data_rule_id = '%s' AND b.rule_sumary_id" \ "=o.rule_sumary_id AND b.create_user=s.user_id AND o.operation_id=k.id;" % rule_id cursor.execute(query_operations_cmd) query_result = cursor.fetchall() if len(query_result) > 0: executor_model = ExecutorModel(query_result[0][0], rule_id, query_id, batch_id, query_result[0][1], query_result[0][2]) for query_item in query_result: executor_model.operations[query_item[3]] = (query_item[4], query_item[5]) except Exception as ex: logger.exception(ex) finally: self.close() return executor_model
def update_for_operation(self, rule_id, operation_id, user_id, **kwargs): try: storage_time = TimeUtil().get_current_time() cursor = self.conn.cursor() update = "UPDATE business_rule_operation SET update_time='%s',update_user=%d" % (storage_time, int(user_id)) if kwargs.get('data_store_detail') is not None: update += ", data_store_detail='%s'" % kwargs.get('data_store_detail') update += " WHERE rule_sumary_id=%d AND operation_id=%d;" % (int(rule_id), int(operation_id)) cursor.execute(update) self.conn.commit() except Exception as ex: logger.exception(ex) finally: self.close()
def update_state_for_rule(self, rule_summary_id, rule_state): try: storage_time = TimeUtil().get_current_time() cursor = self.conn.cursor() update = "UPDATE business_rule_sumary SET rule_state=%d, update_time='%s' WHERE id=%d;" % \ (int(rule_state), storage_time, int(rule_summary_id)) cursor.execute(update) self.conn.commit() except Exception as ex: logger.exception(ex) finally: self.close()
def update_business_analysis(self, id_query, id_batch): try: storage_time = TimeUtil().get_current_time() cursor = self.conn.cursor() update = "INSERT INTO stat_business_analysis(query_id, batch_id, create_time, update_time) " \ "VALUES('%s','%s','%s','%s')" % (id_query, id_batch, storage_time, storage_time) cursor.execute(update) self.conn.commit() except Exception as ex: logging.exception(ex) finally: self.close()
|