mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-31 06:29:46 +08:00
♻️ 重构用户祈愿数据库相关处理
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
/**
|
||||
* @file plugins Sqlite sql updateData.ts
|
||||
* @file plugins/Sqlite/sql/updateData.ts
|
||||
* @description 更新数据
|
||||
* @author BTMuli <bt-muli@outlook.com>
|
||||
* @since Alpha v0.2.0
|
||||
* @since Beta v0.4.7
|
||||
*/
|
||||
|
||||
// utils
|
||||
import minifySql from "../../../utils/minifySql";
|
||||
|
||||
/**
|
||||
@@ -26,15 +24,21 @@ export function importUIAFData(data: TGApp.Plugins.UIAF.Achievement[]): string[]
|
||||
.replace("T", " ")
|
||||
.slice(0, 19);
|
||||
sql = `
|
||||
UPDATE Achievements
|
||||
SET isCompleted = 1, completedTime = '${completedTime}', progress = ${achievement.current}, updated = datetime('now', 'localtime')
|
||||
WHERE id = ${achievement.id} AND (isCompleted = 0 OR completedTime != '${completedTime}' OR progress != ${achievement.current});
|
||||
UPDATE Achievements
|
||||
SET isCompleted = 1,
|
||||
completedTime = '${completedTime}',
|
||||
progress = ${achievement.current},
|
||||
updated = datetime('now', 'localtime')
|
||||
WHERE id = ${achievement.id}
|
||||
AND (isCompleted = 0 OR completedTime != '${completedTime}' OR progress != ${achievement.current});
|
||||
`;
|
||||
} else {
|
||||
sql = `
|
||||
UPDATE Achievements
|
||||
SET progress = ${achievement.current}, updated = datetime('now', 'localtime')
|
||||
WHERE id = ${achievement.id} AND progress != ${achievement.current};
|
||||
UPDATE Achievements
|
||||
SET progress = ${achievement.current},
|
||||
updated = datetime('now', 'localtime')
|
||||
WHERE id = ${achievement.id}
|
||||
AND progress != ${achievement.current};
|
||||
`;
|
||||
}
|
||||
return sqlRes.push(minifySql(sql));
|
||||
@@ -43,37 +47,30 @@ export function importUIAFData(data: TGApp.Plugins.UIAF.Achievement[]): string[]
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 导入UIGF数据
|
||||
* @since Alpha v0.2.3
|
||||
* @description 导入UIGF数据-单项
|
||||
* @since Beta v0.4.7
|
||||
* @param {string} uid - UID
|
||||
* @param {TGApp.Plugins.UIGF.GachaItem[]} data - UIGF数据
|
||||
* @returns {string[]} sql
|
||||
* @param {TGApp.Plugins.UIGF.GachaItem} gacha - UIGF数据
|
||||
* @returns {string} sql
|
||||
*/
|
||||
export function importUIGFData(uid: string, data: TGApp.Plugins.UIGF.GachaItem[]): string[] {
|
||||
const sqlRes: string[] = [];
|
||||
data.forEach((gacha) => {
|
||||
const sql = `
|
||||
export function importUIGFData(uid: string, gacha: TGApp.Plugins.UIGF.GachaItem): string {
|
||||
const sql = `
|
||||
INSERT INTO GachaRecords (uid, gachaType, itemId, count, time, name, type, rank, id, uigfType, updated)
|
||||
VALUES ('${uid}', '${gacha.gacha_type}', '${gacha.item_id ?? null}', '${
|
||||
gacha.count ?? null
|
||||
}', '${gacha.time}',
|
||||
'${gacha.name}', '${gacha.item_type ?? null}', '${gacha.rank_type ?? null}', '${
|
||||
gacha.id
|
||||
}',
|
||||
VALUES ('${uid}', '${gacha.gacha_type}', '${gacha.item_id ?? null}', '${gacha.count ?? null}', '${gacha.time}',
|
||||
'${gacha.name}', '${gacha.item_type ?? null}', '${gacha.rank_type ?? null}', '${gacha.id}',
|
||||
'${gacha.uigf_gacha_type}', datetime('now', 'localtime'))
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
uid = '${uid}',
|
||||
gachaType = '${gacha.gacha_type}',
|
||||
uigfType = '${gacha.uigf_gacha_type}',
|
||||
time = '${gacha.time}',
|
||||
itemId = '${gacha.item_id ?? null}',
|
||||
count = '${gacha.count ?? null}',
|
||||
name = '${gacha.name}',
|
||||
type = '${gacha.item_type ?? null}',
|
||||
rank = '${gacha.rank_type ?? null}',
|
||||
updated = datetime('now', 'localtime');
|
||||
`;
|
||||
sqlRes.push(minifySql(sql));
|
||||
});
|
||||
return sqlRes;
|
||||
ON CONFLICT (id)
|
||||
DO UPDATE
|
||||
SET uid = '${uid}',
|
||||
gachaType = '${gacha.gacha_type}',
|
||||
uigfType = '${gacha.uigf_gacha_type}',
|
||||
time = '${gacha.time}',
|
||||
itemId = '${gacha.item_id ?? null}',
|
||||
count = '${gacha.count ?? null}',
|
||||
name = '${gacha.name}',
|
||||
type = '${gacha.item_type ?? null}',
|
||||
rank = '${gacha.rank_type ?? null}',
|
||||
updated = datetime('now', 'localtime');
|
||||
`;
|
||||
return minifySql(sql);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user