Skip to content

Commit

Permalink
Merge pull request #287 from mgz0227/cat_dev
Browse files Browse the repository at this point in the history
订阅源分组改为数据库存储
  • Loading branch information
MaoXiaoone authored Dec 8, 2024
2 parents 31464e0 + bf1db35 commit 1f6561a
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 7 deletions.
50 changes: 49 additions & 1 deletion entry/src/main/ets/database/AppDatabase/index.ets
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export default {
{
"fieldPath": "isTop",
"columnName": "isTop",
"affinity": "isTop",
"affinity": "INTEGER",
"boolean": true,
"notNull": true,
"defaultValue": "1"
Expand Down Expand Up @@ -2369,6 +2369,54 @@ export default {
},
"indices": [],
"foreignKeys": []
},
{
"tableName":"rss_source_group",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`rssGroupId` INTEGER NOT NULL, `rssGroupName` TEXT NOT NULL , `isTop` INTEGER NOT NULL DEFAULT 0 , `groupSort` INTEGER , `isDelete` INTEGER NOT NULL DEFAULT 1 , PRIMARY KEY(`rssGroupId`))",
"fields": [
{
"fieldPath": "rssGroupId",
"columnName": "rssGroupId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "rssGroupName",
"columnName": "rssGroupName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "groupSort",
"columnName": "groupSort",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "isTop",
"columnName": "isTop",
"affinity": "INTEGER",
"boolean": true,
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "isDelete",
"columnName": "isDelete",
"affinity": "INTEGER",
"boolean": true,
"notNull": false,
"defaultValue": "1"
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"rssGroupId"
]
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
Expand Down
111 changes: 111 additions & 0 deletions entry/src/main/ets/database/dao/rssSourceGroupDao.ets
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
18 changes: 18 additions & 0 deletions entry/src/main/ets/database/entities/RssSourceGroup.ets
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;
}
2 changes: 2 additions & 0 deletions entry/src/main/ets/database/index.ets
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import BookGroupsDao from './dao/BookGroupsDao'
import bookHistoryDao from './dao/BookHistoryDao'
import BooksDao from './dao/BooksDao'
import BookSourceDao from './dao/BookSourceDao'
import rssSourceGroupDao from './dao/rssSourceGroupDao'
import rssSourcesHistoryDao from './dao/RssSourcesHistoryDao'
import SubscriptionDao from './dao/SubscriptionDao'
import worksListsDao from './dao/WorksListsDao'
Expand All @@ -15,6 +16,7 @@ class DataBase {
await BookGroupsDao.initGroupTable()
await worksListsDao.initWorksListsTable()
await bookHistoryDao.initBookHistoryTable()
await rssSourceGroupDao.initBookSourceGroupTable()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import dialogTitleFuction from '../../../../componets/common/dialogTitleFuction'
import { showMessage } from '../../../../componets/common/promptShow'
import Help from '../../../../componets/dialog/help'
import FormItem from '../../../../componets/Form/FormItem'
import rssSourceGroupDao from '../../../../database/dao/rssSourceGroupDao'
import SubscriptionDao from '../../../../database/dao/SubscriptionDao'
import { rssSources, SUBSCRIPTION_GROUP_TYPE } from '../../../../database/entities/rssSources'
import { rssListRule } from '../../../../database/entities/rule/rssListRule'
Expand Down Expand Up @@ -221,15 +222,23 @@ export default struct newSources{
rssWebViewRule: new rssWebViewRule(),
}

// @State sourceGroupList:SelectOption[] = []
@State sourceGroupList:SelectOption[] = []
getRssSourceList() {
let list = programDataPreferences.getRssSourcesListData()
//将list存放到sourceGroupList
list.forEach((item) => {

async getRssSourceList() {
let group = await rssSourceGroupDao.search();
group.forEach(item=>{
this.sourceGroupList.push({
value: item
value: item.rssGroupName
})
})
// let list = programDataPreferences.getRssSourcesListData()
// //将list存放到sourceGroupList
// list.forEach((item) => {
// this.sourceGroupList.push({
// value: item
// })
// })
}
aboutToAppear(): void {
this.getRssSourceList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default struct SubscriptionContent{
build() {
Column(){
Column({
space:20
space:16
}){
Flex({
justifyContent:FlexAlign.SpaceBetween,
Expand Down

0 comments on commit 1f6561a

Please sign in to comment.