refactor(ota): 移除 OTA 相关冗余字段及清理代码
- 从 OTA 结构体中删除 pawVerCode、pawVerName、pawUrl、pawMd5 字段 - 更新数据库查询,去除对上述字段的扫描 - 调整 SQL 迁移脚本,删除对应的数据库列 - 简化相关存储库方法的查询逻辑,提升代码维护性
This commit is contained in:
@@ -19,7 +19,7 @@ func NewOTARepository(db *sql.DB) *OTARepository {
|
||||
// GetLatestOTA 按 model+hw+beta+status=1 查询最新一条 OTA 记录(verCode 降序)
|
||||
func (r *OTARepository) GetLatestOTA(ctx context.Context, modelVal string, hw, beta int) (*model.OTA, error) {
|
||||
const query = `SELECT id, verCode, verName, url, md5, ` + "`force`" + `, ` + "`desc`" + `, model, hw, target, beta,
|
||||
pawVerCode, pawVerName, pawUrl, pawMd5, startTime, endTime, status
|
||||
startTime, endTime, status
|
||||
FROM ota WHERE model = ? AND hw = ? AND beta = ? AND status = 1
|
||||
ORDER BY verCode DESC LIMIT 1`
|
||||
|
||||
@@ -30,7 +30,7 @@ func (r *OTARepository) GetLatestOTA(ctx context.Context, modelVal string, hw, b
|
||||
err := r.db.QueryRowContext(ctx, query, modelVal, hw, beta).Scan(
|
||||
&o.ID, &o.VerCode, &o.VerName, &o.URL, &o.MD5, &o.Force, &desc, &mdl,
|
||||
&o.HW, &o.Target, &o.Beta,
|
||||
&o.PawVerCode, &o.PawVerName, &o.PawURL, &o.PawMD5, &startTime, &endTime, &o.Status,
|
||||
&startTime, &endTime, &o.Status,
|
||||
)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
@@ -57,7 +57,7 @@ func (r *OTARepository) GetLatestOTA(ctx context.Context, modelVal string, hw, b
|
||||
// GetLatestOTANotInBlackList 查询最新一条不在黑名单中的 OTA 记录
|
||||
func (r *OTARepository) GetLatestOTANotInBlackList(ctx context.Context, modelVal string, hw, beta int, mac string) (*model.OTA, error) {
|
||||
const query = `SELECT id, verCode, verName, url, md5, ` + "`force`" + `, ` + "`desc`" + `, model, hw, target, beta,
|
||||
pawVerCode, pawVerName, pawUrl, pawMd5, startTime, endTime, status
|
||||
startTime, endTime, status
|
||||
FROM ota WHERE status = 1 AND model = ? AND hw = ? AND beta = ?
|
||||
AND id NOT IN (SELECT ota_id FROM black_list WHERE mac = ?)
|
||||
ORDER BY verCode DESC LIMIT 1`
|
||||
@@ -69,7 +69,7 @@ func (r *OTARepository) GetLatestOTANotInBlackList(ctx context.Context, modelVal
|
||||
err := r.db.QueryRowContext(ctx, query, modelVal, hw, beta, mac).Scan(
|
||||
&o.ID, &o.VerCode, &o.VerName, &o.URL, &o.MD5, &o.Force, &desc, &mdl,
|
||||
&o.HW, &o.Target, &o.Beta,
|
||||
&o.PawVerCode, &o.PawVerName, &o.PawURL, &o.PawMD5, &startTime, &endTime, &o.Status,
|
||||
&startTime, &endTime, &o.Status,
|
||||
)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
@@ -96,7 +96,7 @@ func (r *OTARepository) GetLatestOTANotInBlackList(ctx context.Context, modelVal
|
||||
// GetLatestOTANotTarget 查询最新一条非定向的 OTA 记录
|
||||
func (r *OTARepository) GetLatestOTANotTarget(ctx context.Context, modelVal string, hw, beta int) (*model.OTA, error) {
|
||||
const query = `SELECT id, verCode, verName, url, md5, ` + "`force`" + `, ` + "`desc`" + `, model, hw, target, beta,
|
||||
pawVerCode, pawVerName, pawUrl, pawMd5, startTime, endTime, status
|
||||
startTime, endTime, status
|
||||
FROM ota WHERE status = 1 AND model = ? AND hw = ? AND beta = ? AND target = 0
|
||||
ORDER BY verCode DESC LIMIT 1`
|
||||
|
||||
@@ -107,7 +107,7 @@ func (r *OTARepository) GetLatestOTANotTarget(ctx context.Context, modelVal stri
|
||||
err := r.db.QueryRowContext(ctx, query, modelVal, hw, beta).Scan(
|
||||
&o.ID, &o.VerCode, &o.VerName, &o.URL, &o.MD5, &o.Force, &desc, &mdl,
|
||||
&o.HW, &o.Target, &o.Beta,
|
||||
&o.PawVerCode, &o.PawVerName, &o.PawURL, &o.PawMD5, &startTime, &endTime, &o.Status,
|
||||
&startTime, &endTime, &o.Status,
|
||||
)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
|
||||
Reference in New Issue
Block a user