def search(self, task_code): """ 查询有效模板数据 :param task_code: :return: """ try: template_code = self.search_template_code(task_code) """未查到模板编码""" if not template_code: return False """查询redis""" template_redis_key = "%s_%s" % (template_code, busi_config.TEMPLATE_EXT_REDIS_KEY) result = BusinessUtil.get_redis_by_key(template_redis_key) if result: return result _db = MySqlHelper() result = _db.fetch_all(template_sql.search, template_code) """如果未查到值""" if not result: return False """redis入库""" BusinessUtil.set_redis_by_key(template_redis_key, result, busi_config.REDIS_CACHE_TIME) return result except Exception as e: self.logger.error("【查询有效服务器】查询异常信息为:%s" % traceback.format_exc()) return False
def search_lock_domain_name(self): """ 查询域名状态 :return: """ try: """查询redis""" result = BusinessUtil.get_redis_by_key( busi_config.LOCK_ACCOUNT_REDIS_KEY) if result: return result """查询数据库""" _db = MySqlHelper() result = _db.fetch_one( send_email_account_sql.search_lock_domain_name) if not result: return False """获取域名""" domain_name = result.get("domainName", "") """如果不为空 则添加到redis""" if domain_name: BusinessUtil.set_redis_by_key( busi_config.LOCK_ACCOUNT_REDIS_KEY, domain_name, busi_config.REDIS_CACHE_TIME) return domain_name except Exception as e: self.logger.error("【查询发送邮箱账号】查询异常信息为:%s" % traceback.format_exc()) return False
def search_key(self, param): """ 查询业务配置 通过key值 :return: """ try: if not param: self.logger.info("【查询业务配置】请求参数为为空,流程结束") return False """查询redis""" result = BusinessUtil.get_redis_by_key( busi_config.BUSI_BASE_CONF_REDIS_KEY) if not result: """查询数据库""" _db = MySqlHelper() result = _db.fetch_all(busi_base_conf_sql.search, None) else: """转化数据""" result = json.loads(result) """存储到redis""" BusinessUtil.set_redis_by_key(busi_config.BUSI_BASE_CONF_REDIS_KEY, result, busi_config.REDIS_CACHE_TIME) """遍历结果""" busi_base_list = [] for item in result: if item.get("busiKey") != param: continue busi_base_list.append(item) break if not busi_base_list: return False return busi_base_list[0] except Exception as e: self.logger.error("【查询业务配置】查询异常信息为:%s" % traceback.format_exc()) return False
def insert_update_used(self, param): """ 添加或更新数据 :param param: :return: """ _db = None try: if not param: self.logger.info("【添加/更新账号使用量】请求参数为为空,流程结束") """查询数据""" _db = MySqlHelper() count = _db.count( used_of_count_sql.count, (param.get("usedOfContent"), param.get("usedType"), param.get("start"), param.get("end"))) if count > 0: result = _db.update( used_of_count_sql.update_used_count, (param.get("usedOfContent"), param.get("usedType"), param.get("start"), param.get("end"))) else: result = _db.insert_one( used_of_count_sql.insert_used, (param.get("usedOfContent"), param.get("usedType"))) _db.end() return result except Exception as e: if _db: _db.isEnd = 2 _db.end() self.logger.error("【添加/更新账号使用量】保存异常信息为:%s" % traceback.format_exc()) return False
def insert_update(self, param): """ 添加或更新数据 :param param: :return: """ _db = None try: if not param: self.logger.info("【添加/更新营销数据】请求参数为为空,流程结束") """查询数据""" _db = MySqlHelper() count = _db.count(marketing_data_sql.count, (param.get("batchCode"), param.get("mobile"), param.get("email"))) if count > 0: result = _db.update( marketing_data_sql.update_insert, (param.get("subBatchCode"), param.get("batchCode"), param.get("mobile"), param.get("email"))) else: result = _db.insert_one( marketing_data_sql.insert, (param.get("batchCode"), param.get("subBatchCode"), param.get("mobile"), param.get("email"))) _db.end() return result except Exception as e: if _db: _db.isEnd = 2 _db.end() self.logger.error("【添加/更新营销数据】保存异常信息为:%s" % traceback.format_exc()) return False
def update(self, param=None): """ 更新数据 :param param: :return: """ _db = None try: BusinessUtil.delete_redis_by_key( busi_config.SERVER_CONFIG_REDIS_KEY) if param is None: self.logger.info("【更新服务器】请求参数为空,流程结束") return False _db = MySqlHelper() _db.begin() count = _db.update(server_conf_sql.update, param) _db.end() return count except Exception as e: if _db: _db.isEnd = 2 _db.end() self.logger.error("【更新服务器】更新异常,事务回滚,异常信息为:%s" % traceback.format_exc()) return False
def search_smtp(self, param=None): """ 查询发送有效账号 SMTP :return: """ try: _db = MySqlHelper() result = _db.fetch_all(send_email_account_sql.search_smtp, param) return result except Exception as e: self.logger.error("【查询发送邮箱账号】查询异常信息为:%s" % traceback.format_exc()) return False
def search(self, param=None): """ 查询业务配置 通过状态 :return: """ try: _db = MySqlHelper() result = _db.fetch_all(busi_base_conf_sql.search, param) return result except Exception as e: self.logger.error("【查询业务配置】查询异常信息为:%s" % traceback.format_exc()) return False
def search(self, param=None): """ 查询返回码配置 :return: """ try: #self.logger.info("【查询返回码配置】请求参数为:%s" % param) _db = MySqlHelper() result = _db.fetch_all(return_code_conf_sql.search, param) #self.logger.info("【查询返回码配置】响应结果为:%s" % result) return result except Exception as e: self.logger.error("【查询返回码配置】查询异常信息为:%s" % traceback.format_exc()) return False
def search(self, param): """ 查询原始营销数据 :return: """ try: if not param: self.logger.info("【查询原始营销数据】请求参数为为空,流程结束") return False _db = MySqlHelper() result = _db.fetch_all(primary_data_sql.search, param) return result except Exception as e: self.logger.error("【查询原始营销数据】查询异常信息为:%s" % traceback.format_exc()) return False
def search(self, param): """ 查询账号使用量 :return: """ try: if not param: self.logger.info("【查询账号使用量】请求参数为为空,流程结束") return False _db = MySqlHelper() result = _db.fetch_all(used_of_count_sql.search, param) return result except Exception as e: self.logger.error("【查询账号使用量】查询异常信息为:%s" % traceback.format_exc()) return False
def search_pop_server_ip(self, server_ip): """ 通过服务ip查询账号 :param server_ip: :return: """ try: if not server_ip: return False _db = MySqlHelper() result = _db.fetch_all(send_email_account_sql.search_pop_server_ip, server_ip) return result except Exception as e: self.logger.error("【查询发送邮箱账号】查询异常信息为:%s" % traceback.format_exc()) return False
def resend_search(self, param): """ 提取二次营销数据 :param param: :return: """ try: if not param: self.logger.info("【查询二次营销数据】请求参数为为空,流程结束") return False _db = MySqlHelper() result = _db.fetch_all(marketing_data_sql.resend_search, param) return result except Exception as e: self.logger.error("【查询二次营销数据】查询异常信息为:%s" % traceback.format_exc()) return False
def search(self, param): """ 文件读取相关记录 :param param: :return: """ try: _db = MySqlHelper() result = _db.fetch_all(file_read_record_sql.search, param) if not result: self.logger.info("【文件读取记录】响应结果为空,结束流程") return False return result except Exception as e: self.logger.error("【文件读取记录】查询异常信息为:%s" % traceback.format_exc()) return False
def search(self, param): """ 查询通讯录 :return: """ try: if not param: self.logger.info("【查询通讯录】请求参数为为空,流程结束") return False self.logger.info("【查询通讯录】请求参数为:%s" % param) _db = MySqlHelper() result = _db.fetch_all(email_address_book_sql.search, param) self.logger.info("【查询通讯录】响应结果为:%s" % result) return result except Exception as e: self.logger.error("【查询通讯录】查询异常信息为:%s" % traceback.format_exc()) return False
def search_key(self, param): """ 查询黑白名单 通过content :return: """ try: if not param: self.logger.info("【查询黑白名单】请求参数为为空,流程结束") return False self.logger.info("【查询黑白名单】请求参数为:%s" % param) _db = MySqlHelper() result = _db.fetch_all(black_white_roll_call_sql.search_key, param) self.logger.info("【查询黑白名单】响应结果为:%s" % result) return result except Exception as e: self.logger.error("【查询黑白名单】查询异常信息为:%s" % traceback.format_exc()) return False
def search(self, param): """ 查询代理服务器 :return: """ try: if not param: self.logger.info("【查询代理服务器】请求参数为为空,流程结束") return False #self.logger.info("【查询代理服务器】请求参数为:%s" % param) _db = MySqlHelper() result = _db.fetch_all(proxy_server_conf_sql.search, param) #self.logger.info("【查询代理服务器】响应结果为:%s" % result) return result except Exception as e: self.logger.error("【查询代理服务器】查询异常信息为:%s" % traceback.format_exc()) return False
def search_task_code_by_server_ip(self, server_ip): """ 通过服务器IP查询任务编号 :param server_ip :return: """ try: _db = MySqlHelper() result = _db.fetch_one(task_sql.search_task_code_by_server_ip, server_ip) if not result: self.logger.info("【查询任务编号】响应结果为空,结束流程") return False return result except Exception as e: self.logger.error("【查询任务编号】查询异常信息为:%s" % traceback.format_exc()) return False
def search(self, param): """ 查询发送记录 :return: """ try: if not param: self.logger.info("【查询发送记录】请求参数为为空,流程结束") return False self.logger.info("【查询发送记录】请求参数为:%s" % str(param)) _db = MySqlHelper() result = _db.fetch_all(send_record_sql.search, param) self.logger.info("【查询发送记录】响应结果为:%s" % result) return result except Exception as e: self.logger.error("【查询发送记录】查询异常信息为:%s" % traceback.format_exc()) return False
def search_key(self, param): """ 查询黑名单 通过content :return: """ try: if not param: return False """从redis读取字段""" result = BusinessUtil.get_redis_by_key(param) if result: return result """从数据库内查询""" _db = MySqlHelper() result = _db.fetch_all(black_roll_call_sql.search_key) """未查到数据""" if not result: return False black_dict = {} """循环遍历数据""" for item in result: if not item: continue """生成分组""" item_key = BusinessUtil.get_verify_key(item.get("content")) if not item_key: continue if item_key in black_dict: black_dict[item_key].append(item.get("content")) else: black_dict.setdefault(item_key, []) black_dict[item_key].append(item.get("content")) """存入redis""" result_str = None for key in list(black_dict.keys()): item = black_dict[key] item_list = list(set(item)) item_str = ",".join(item_list) if key == param: result_str = item_str BusinessUtil.set_redis_reset_time_ex(key, item_str) return result_str except Exception as e: self.logger.error("【查询黑名单】查询异常信息为:%s" % traceback.format_exc()) return False
def search_key(self, param): """ 查询返回码配置 通过retCode :return: """ try: if not param: self.logger.info("【查询返回码配置】请求参数为为空,流程结束") return False #self.logger.info("【查询返回码配置】请求参数为:%s" % param) _db = MySqlHelper() result = _db.fetch_all(return_code_conf_sql.search_by_ret_code, param) #self.logger.info("【查询返回码配置】响应结果为:%s" % result) return result except Exception as e: self.logger.error("【查询返回码配置】查询异常信息为:%s" % traceback.format_exc()) return False
def update(self, param=None): """ 文件读取记录更新 :param param: :return: """ _db = None try: _db = MySqlHelper() _db.begin() count = _db.update(file_read_record_sql.update, param) _db.end() return count except Exception as e: if _db: _db.isEnd = 2 _db.end() self.logger.error("【文件读取记录】更新异常,事务回滚,异常信息为:%s" % traceback.format_exc()) return False
def search_not_lock_user_name(self, user_name): """ 查询账号状态 :param user_name: :return: """ try: if not user_name: return False """查询数据库""" _db = MySqlHelper() result = _db.count(send_email_account_sql.search_lock_user_name, user_name) """没有查到数据为空""" if not result: return True except Exception as e: self.logger.error("【查询发送邮箱账号】查询异常信息为:%s" % traceback.format_exc()) return False
def search_account_residue(self, user_name): """ 查询账号剩余量 :param user_name: :return: """ try: if not user_name: return False timeStr = str( time.strftime('%Y-%m-%d', time.localtime(time.time()))) _db = MySqlHelper() result = _db.fetch_one(used_of_count_sql.search_account_residue, (timeStr, user_name)) if not result: return False return result.get("residue", 0) except Exception as e: self.logger.error("【查询账号使用量】查询异常信息为:%s" % traceback.format_exc()) return False
def search_lock_account(self, account_reopen_time): """ 查询锁定的账号(未达到最大量数据) :param account_reopen_time: :return: """ _db = None try: _db = MySqlHelper() """设置当前日期""" timeStr = str( time.strftime('%Y-%m-%d', time.localtime(time.time()))) result = _db.fetch_all( send_email_account_sql.search_lock_account_for_user_name, (timeStr, account_reopen_time, timeStr)) return result except Exception as e: self.logger.error("【查询锁定的账号】查询锁定的账号异常,信息为:%s" % traceback.format_exc()) return False
def update_all_status_valid(self): """ 更新所有账号为有效 :return: """ _db = None try: _db = MySqlHelper() """更新当前账号 将所有数据转化为1""" _db.update(send_email_account_sql.update_all_status_valid) _db.end() return True except Exception as e: if _db: _db.isEnd = 2 _db.end() self.logger.error("【变更轮换账号】变更异常信息为:%s" % traceback.format_exc()) return False
def search(self, param=None): """ 查询有效服务器数据 优先查询redis内数据,未查得后查询数据库数据并更新到redis内 :param param: :return: result """ try: result = BusinessUtil.get_redis_by_key( busi_config.SERVER_CONFIG_REDIS_KEY) if result: return json.loads(result) _db = MySqlHelper() result = _db.fetch_all(server_conf_sql.search, param) if not result: self.logger.info("【查询有效服务器】响应结果为空,结束流程") return False BusinessUtil.set_redis_by_key(busi_config.SERVER_CONFIG_REDIS_KEY, result, busi_config.REDIS_CACHE_TIME) return result except Exception as e: self.logger.error("【查询有效服务器】查询异常信息为:%s" % traceback.format_exc()) return False
def search_has_valid_account(self, server_ip): """ 查询待转化的邮箱域名 :param server_ip: :return: """ _db = None try: _db = MySqlHelper() """设置当前日期""" timeStr = str( time.strftime('%Y-%m-%d', time.localtime(time.time()))) start = "%s 00:00:00" % timeStr end = "%s 23:59:59" % timeStr result = _db.fetch_all( send_email_account_sql.search_and_update_account, (server_ip, start, end)) return result except Exception as e: self.logger.error("【查询待转化的邮箱域名】查询待转化的邮箱域名信息为:%s" % traceback.format_exc()) return False
def search_valid_account(self, server_ip): """ 查询发送有效账号(含剩余数量) 缓存5分钟 可能存在账号多发情况 :param server_ip: :return: """ try: if not server_ip: self.logger.info("【查询发送邮箱账号】传入参数有误,请确认") return False """选取发送账号""" valid_account_key = "%s_%s" % (server_ip.replace( ".", "_"), busi_config.VALID_ACCOUNT_REDIS_KEY) """查询redis""" result = BusinessUtil.get_redis_by_key(valid_account_key) if not result: """查询数据库""" _db = MySqlHelper() """设置当前日期""" timeStr = str( time.strftime('%Y-%m-%d', time.localtime(time.time()))) start = "%s 00:00:00" % timeStr end = "%s 23:59:59" % timeStr result = _db.fetch_all( send_email_account_sql.search_valid_account, (server_ip, start, end)) else: """转化数据""" result = json.loads(result) """判断非空""" if not result: return False BusinessUtil.set_redis_by_key(valid_account_key, result, busi_config.REDIS_CACHE_TIME) return result except Exception as e: self.logger.error("【查询发送邮箱账号】查询异常信息为:%s" % traceback.format_exc()) return False
def search_and_update_account(self, server_ip, account_reopen_time): """ 变更轮换账号 :param server_ip: :param account_reopen_time: :return: """ _db = None try: _db = MySqlHelper() """设置当前日期""" timeStr = str( time.strftime('%Y-%m-%d', time.localtime(time.time()))) # start = "%s 00:00:00" % timeStr # end = "%s 23:59:59" % timeStr #result = _db.fetch_all(send_email_account_sql.search_and_update_account, (server_ip, start, end)) """更新当前账号 将所有数据转化为3""" #_db.update(send_email_account_sql.update_status, (3, 1, server_ip)) """查询锁定账号""" result = _db.fetch_all( send_email_account_sql.search_lock_account_for_user_name, (timeStr, account_reopen_time, timeStr)) # if not result: # """查询锁定账号""" # result = _db.fetch_all(send_email_account_sql.search_lock_account, (timeStr, account_reopen_time)) """存在数据 则更新""" if result: for item in result: _db.update(send_email_account_sql.update_user_name, (1, item.get("userName"))) _db.end() return True except Exception as e: if _db: _db.isEnd = 2 _db.end() self.logger.error("【变更轮换账号】变更异常信息为:%s" % traceback.format_exc()) return False