'.'
This commit is contained in:
@@ -791,13 +791,135 @@ class Database:
|
||||
sql = "UPDATE domains SET expire_date = %s WHERE id = %s"
|
||||
return self.execute(sql, (expire_date, domain_id))
|
||||
|
||||
def get_domains_to_detect(self, limit=1000):
|
||||
def update_domain_detect_time(self, domain_id, detect_time):
|
||||
"""
|
||||
更新域名检测时间
|
||||
|
||||
:param domain_id: 域名ID
|
||||
:param detect_time: 检测时间
|
||||
:return: bool - 是否更新成功
|
||||
"""
|
||||
sql = "UPDATE domains SET detect_time = %s WHERE id = %s"
|
||||
return self.execute(sql, (detect_time, domain_id))
|
||||
|
||||
def update_detection_status(self, domain_id, status_type, status):
|
||||
"""
|
||||
更新检测状态
|
||||
|
||||
:param domain_id: 域名ID
|
||||
:param status_type: 状态类型 (whois, beian, intercept, juziseo_history, juziseo_outlink)
|
||||
:param status: 状态值 (0: 待检测, 1: 已检测)
|
||||
:return: bool - 是否更新成功
|
||||
"""
|
||||
status_field_map = {
|
||||
'whois': 'whois_status',
|
||||
'beian': 'beian_status',
|
||||
'intercept': 'intercept_status',
|
||||
'juziseo_history': 'juziseo_history_status',
|
||||
'juziseo_outlink': 'juziseo_outlink_status'
|
||||
}
|
||||
|
||||
if status_type not in status_field_map:
|
||||
return False
|
||||
|
||||
# 先检查domain_detections表中是否存在对应记录
|
||||
check_sql = "SELECT id FROM domain_detections WHERE domain_id = %s"
|
||||
existing_record = self.fetch_one(check_sql, (domain_id,))
|
||||
|
||||
if not existing_record:
|
||||
# 如果不存在,先创建一条记录
|
||||
insert_sql = "INSERT INTO domain_detections (domain_id, create_time, update_time) VALUES (%s, NOW(), NOW())"
|
||||
if not self.execute(insert_sql, (domain_id,)):
|
||||
return False
|
||||
|
||||
# 更新状态
|
||||
field_name = status_field_map[status_type]
|
||||
sql = f"UPDATE domain_detections SET {field_name} = %s, update_time = NOW() WHERE domain_id = %s"
|
||||
return self.execute(sql, (status, domain_id))
|
||||
|
||||
def get_detection_statuses(self, domain_id):
|
||||
"""
|
||||
获取域名的检测状态
|
||||
|
||||
:param domain_id: 域名ID
|
||||
:return: dict - 检测状态字典
|
||||
"""
|
||||
try:
|
||||
sql = "SELECT whois_status, beian_status, intercept_status, juziseo_history_status, juziseo_outlink_status FROM domain_detections WHERE domain_id = %s"
|
||||
result = self.fetch_one(sql, (domain_id,))
|
||||
|
||||
if result:
|
||||
return {
|
||||
'whois_status': result.get('whois_status', 0) if result.get('whois_status') is not None else 0,
|
||||
'beian_status': result.get('beian_status', 0) if result.get('beian_status') is not None else 0,
|
||||
'intercept_status': result.get('intercept_status', 0) if result.get('intercept_status') is not None else 0,
|
||||
'juziseo_history_status': result.get('juziseo_history_status', 0) if result.get('juziseo_history_status') is not None else 0,
|
||||
'juziseo_outlink_status': result.get('juziseo_outlink_status', 0) if result.get('juziseo_outlink_status') is not None else 0
|
||||
}
|
||||
else:
|
||||
return {
|
||||
'whois_status': 0,
|
||||
'beian_status': 0,
|
||||
'intercept_status': 0,
|
||||
'juziseo_history_status': 0,
|
||||
'juziseo_outlink_status': 0
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"获取检测状态失败: {e}")
|
||||
return {
|
||||
'whois_status': 0,
|
||||
'beian_status': 0,
|
||||
'intercept_status': 0,
|
||||
'juziseo_history_status': 0,
|
||||
'juziseo_outlink_status': 0
|
||||
}
|
||||
|
||||
def get_domains_to_detect(self, limit=1000, detect_options=None):
|
||||
"""
|
||||
获取需要检测的域名
|
||||
|
||||
:param limit: 限制数量
|
||||
:param detect_options: 检测选项字典,如 {'detect_whois': True, 'detect_beian': True, ...}
|
||||
:return: list - 域名列表
|
||||
"""
|
||||
if detect_options:
|
||||
# 构建检测状态条件
|
||||
status_conditions = []
|
||||
params = []
|
||||
|
||||
# 检查每个检测选项
|
||||
if detect_options.get('detect_whois', False):
|
||||
status_conditions.append("(dd.whois_status = 0 OR dd.whois_status IS NULL)")
|
||||
if detect_options.get('detect_beian', False):
|
||||
status_conditions.append("(dd.beian_status = 0 OR dd.beian_status IS NULL)")
|
||||
if detect_options.get('detect_intercept', False):
|
||||
status_conditions.append("(dd.intercept_status = 0 OR dd.intercept_status IS NULL)")
|
||||
if detect_options.get('detect_juziseo', False):
|
||||
status_conditions.append("(dd.juziseo_history_status = 0 OR dd.juziseo_history_status IS NULL)")
|
||||
if detect_options.get('detect_juziseo_outlink', False):
|
||||
status_conditions.append("(dd.juziseo_outlink_status = 0 OR dd.juziseo_outlink_status IS NULL)")
|
||||
|
||||
# 构建SQL查询
|
||||
if status_conditions:
|
||||
status_condition = " OR ".join(status_conditions)
|
||||
sql = f"""
|
||||
SELECT DISTINCT d.id, d.domain, d.source_type FROM domains d
|
||||
LEFT JOIN domain_detections dd ON d.id = dd.domain_id
|
||||
WHERE d.detect_status != 3 AND (d.detect_status = 0 OR ({status_condition}))
|
||||
ORDER BY d.id ASC
|
||||
LIMIT %s
|
||||
"""
|
||||
else:
|
||||
# 如果没有检测选项,只获取detect_status=0的记录
|
||||
sql = """
|
||||
SELECT id, domain, source_type FROM domains
|
||||
WHERE detect_status = 0
|
||||
ORDER BY id ASC
|
||||
LIMIT %s
|
||||
"""
|
||||
return self.fetch_all(sql, (limit,))
|
||||
|
||||
# 默认查询逻辑
|
||||
sql = """
|
||||
SELECT id, domain, source_type FROM domains
|
||||
WHERE detect_status IN (0, 3) OR (use_status = 0 AND detect_status = 1 AND register_status = 3 AND expire_date < CURRENT_DATE)
|
||||
@@ -1147,6 +1269,10 @@ class Database:
|
||||
sql += " AND d.review_status = %s"
|
||||
params.append(conditions['review_status'])
|
||||
|
||||
if 'has_beian' in conditions and conditions['has_beian'] is not None:
|
||||
sql += " AND d.has_beian = %s"
|
||||
params.append(conditions['has_beian'])
|
||||
|
||||
# 其他条件保持不变
|
||||
if conditions.get('beian_year'):
|
||||
sql += " AND d.beian_year = %s"
|
||||
@@ -1212,6 +1338,10 @@ class Database:
|
||||
sql += " AND d.review_status = %s"
|
||||
params.append(conditions['review_status'])
|
||||
|
||||
if 'has_beian' in conditions and conditions['has_beian'] is not None:
|
||||
sql += " AND d.has_beian = %s"
|
||||
params.append(conditions['has_beian'])
|
||||
|
||||
# 其他条件保持不变
|
||||
if conditions.get('beian_year'):
|
||||
sql += " AND d.beian_year = %s"
|
||||
|
||||
Reference in New Issue
Block a user