-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #287 from mgz0227/cat_dev
订阅源分组改为数据库存储
- Loading branch information
Showing
6 changed files
with
195 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { ColumnInfo } from '../types/ColumnInfo'; | ||
import AppDatabaseUtil from '../AppDatabaseUtil' | ||
import { JSON } from '@kit.ArkTS'; | ||
import DbUtil from '../../common/utils/DbUtil'; | ||
import { RssSourceGroup } from '../entities/RssSourceGroup'; | ||
|
||
class RssSourceGroupDao { | ||
TABLE_NAME: string = 'rss_source_group' | ||
|
||
// rss_source_group | ||
async initBookSourceGroupTable() { | ||
try { | ||
const createSql = AppDatabaseUtil.getCreateSql(this.TABLE_NAME); | ||
if (!createSql) { | ||
return | ||
} | ||
await DbUtil.createTable(createSql); | ||
await AppDatabaseUtil.existsTable(this.TABLE_NAME) | ||
this.initGroupData() | ||
return | ||
} catch (err) { | ||
console.info('TagInfo', JSON.stringify(err)) | ||
} | ||
} | ||
|
||
|
||
async search(){ | ||
try { | ||
const column: ColumnInfo[] = AppDatabaseUtil.getColumn(this.TABLE_NAME); | ||
let sql = `SELECT * FROM ${this.TABLE_NAME}`; | ||
// sql += `ORDER BY isTop DESC, groupSort ASC`; | ||
const groupDbList = await DbUtil.querySqlForList<RssSourceGroup>(sql, column); | ||
console.log("TagInfo", '书籍:' + groupDbList.length) | ||
return groupDbList | ||
} catch (err) { | ||
console.log("TagInfo", JSON.stringify(err)) | ||
return [] | ||
} | ||
} | ||
|
||
|
||
//系统初始订阅源分组数据 | ||
async initGroupData() { | ||
let initGroup = ['小说','漫画','影视','资讯','收藏'] | ||
try { | ||
const groupList = await this.search() | ||
if (groupList.length > 0) { | ||
return | ||
} | ||
for (let index = 0; index < initGroup.length; index++) { | ||
let group = new RssSourceGroup() | ||
// group.rssGroupId = index | ||
group.rssGroupName = initGroup[index] | ||
group.groupSort = index | ||
group.isTop = false | ||
group.isDelete = false | ||
await this.insert(group) | ||
} | ||
}catch (e){ | ||
console.log('TagInfo, Error, ', JSON.stringify(e)) | ||
} | ||
} | ||
|
||
async insert(rssGroup: RssSourceGroup) { | ||
try { | ||
const column: ColumnInfo[] = AppDatabaseUtil.getColumn(this.TABLE_NAME); | ||
if (rssGroup.rssGroupId) { | ||
const predicates = DbUtil.getPredicates(this.TABLE_NAME); | ||
predicates.equalTo('rssGroupId', rssGroup.rssGroupId) | ||
const count = await DbUtil.queryForCount(predicates, column) | ||
if (count > 0) { | ||
this.update(rssGroup) | ||
return true | ||
} | ||
} | ||
await DbUtil.insert(this.TABLE_NAME, rssGroup, column) | ||
console.log('TagInfo', '创建成功') | ||
return true | ||
} catch (err) { | ||
console.log('TagInfo, Error, ', JSON.stringify(err)) | ||
return false | ||
} | ||
} | ||
|
||
async update(rssGroup: RssSourceGroup) { | ||
try { | ||
const column: ColumnInfo[] = AppDatabaseUtil.getColumn(this.TABLE_NAME); | ||
const predicates = DbUtil.getPredicates(this.TABLE_NAME); | ||
predicates.equalTo('rssGroupId', rssGroup.rssGroupId) | ||
const count = await DbUtil.queryForCount(predicates, column) | ||
if (count === 0 && rssGroup instanceof RssSourceGroup) { | ||
this.insert(rssGroup) | ||
return true | ||
} | ||
|
||
await DbUtil.update(predicates, rssGroup, column) | ||
return true | ||
} catch (err) { | ||
console.log('TagInfo, Error, ', JSON.stringify(err)) | ||
return false | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
} | ||
|
||
const rssSourceGroupDao = new RssSourceGroupDao() | ||
|
||
export default rssSourceGroupDao as RssSourceGroupDao |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* @author 2008 | ||
* @datetime 2024/12/6 23:31 | ||
* @className: rssSourceGroup | ||
* 订阅源分组 | ||
*/ | ||
@Observed | ||
export class RssSourceGroup{ | ||
rssGroupId?:number; | ||
//分组名称 | ||
rssGroupName:string = ""; | ||
//排序 | ||
groupSort:number = 0; | ||
//是否置顶 | ||
isTop:boolean = false; | ||
//是否允许删除 | ||
isDelete:boolean = true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters