Commit 715aa40e7d229aeaf0c9a7f401c397bf792953cd

Authored by “张旭”
1 parent e59136b8

认证下滑页getpage增加数据库 , 每次启动时重置会更新getpage时更新数据库

@@ -71,6 +71,9 @@ target 'metaCode' do @@ -71,6 +71,9 @@ target 'metaCode' do
71 #网页交互 71 #网页交互
72 pod 'WebViewJavascriptBridge' 72 pod 'WebViewJavascriptBridge'
73 73
  74 + #数据库
  75 + pod 'FMDB'
  76 +
74 #依赖三方私有库,如果里面有.a的时候加上这个 77 #依赖三方私有库,如果里面有.a的时候加上这个
75 pre_install do |installer| Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {} 78 pre_install do |installer| Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
76 end 79 end
metaCode.xcodeproj/project.pbxproj
@@ -105,6 +105,8 @@ @@ -105,6 +105,8 @@
105 1965FA3E2AFB176E00F0F435 /* CNLiveShopAddGoodsSingleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1965FA3D2AFB176E00F0F435 /* CNLiveShopAddGoodsSingleView.swift */; }; 105 1965FA3E2AFB176E00F0F435 /* CNLiveShopAddGoodsSingleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1965FA3D2AFB176E00F0F435 /* CNLiveShopAddGoodsSingleView.swift */; };
106 1965FA402AFB38AA00F0F435 /* CNLiveAddGoodsSelectUploadImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1965FA3F2AFB38AA00F0F435 /* CNLiveAddGoodsSelectUploadImageView.swift */; }; 106 1965FA402AFB38AA00F0F435 /* CNLiveAddGoodsSelectUploadImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1965FA3F2AFB38AA00F0F435 /* CNLiveAddGoodsSelectUploadImageView.swift */; };
107 1965FA422AFB79EA00F0F435 /* CNLiveGoodsCategoryController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1965FA412AFB79EA00F0F435 /* CNLiveGoodsCategoryController.swift */; }; 107 1965FA422AFB79EA00F0F435 /* CNLiveGoodsCategoryController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1965FA412AFB79EA00F0F435 /* CNLiveGoodsCategoryController.swift */; };
  108 + 197325D22BB11C18002E41A3 /* DatabaseManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 197325D12BB11C18002E41A3 /* DatabaseManager.swift */; };
  109 + 19AB90642BB412C700B6A79B /* CNLiveDownslideOperationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19AB90632BB412C700B6A79B /* CNLiveDownslideOperationManager.swift */; };
108 19AD65AA2BA041210045A444 /* CNLiveGoodsDetailsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19AD65A92BA041210045A444 /* CNLiveGoodsDetailsTableViewCell.swift */; }; 110 19AD65AA2BA041210045A444 /* CNLiveGoodsDetailsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19AD65A92BA041210045A444 /* CNLiveGoodsDetailsTableViewCell.swift */; };
109 19AD65AC2BA16CF20045A444 /* CNLiveShopCommentRequestShareModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19AD65AB2BA16CF20045A444 /* CNLiveShopCommentRequestShareModel.swift */; }; 111 19AD65AC2BA16CF20045A444 /* CNLiveShopCommentRequestShareModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19AD65AB2BA16CF20045A444 /* CNLiveShopCommentRequestShareModel.swift */; };
110 19AD65AE2BA177C20045A444 /* CNLiveShopGoodsDetailsTableHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19AD65AD2BA177C20045A444 /* CNLiveShopGoodsDetailsTableHeaderView.swift */; }; 112 19AD65AE2BA177C20045A444 /* CNLiveShopGoodsDetailsTableHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19AD65AD2BA177C20045A444 /* CNLiveShopGoodsDetailsTableHeaderView.swift */; };
@@ -372,6 +374,8 @@ @@ -372,6 +374,8 @@
372 1965FA3D2AFB176E00F0F435 /* CNLiveShopAddGoodsSingleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveShopAddGoodsSingleView.swift; sourceTree = "<group>"; }; 374 1965FA3D2AFB176E00F0F435 /* CNLiveShopAddGoodsSingleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveShopAddGoodsSingleView.swift; sourceTree = "<group>"; };
373 1965FA3F2AFB38AA00F0F435 /* CNLiveAddGoodsSelectUploadImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveAddGoodsSelectUploadImageView.swift; sourceTree = "<group>"; }; 375 1965FA3F2AFB38AA00F0F435 /* CNLiveAddGoodsSelectUploadImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveAddGoodsSelectUploadImageView.swift; sourceTree = "<group>"; };
374 1965FA412AFB79EA00F0F435 /* CNLiveGoodsCategoryController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveGoodsCategoryController.swift; sourceTree = "<group>"; }; 376 1965FA412AFB79EA00F0F435 /* CNLiveGoodsCategoryController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveGoodsCategoryController.swift; sourceTree = "<group>"; };
  377 + 197325D12BB11C18002E41A3 /* DatabaseManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseManager.swift; sourceTree = "<group>"; };
  378 + 19AB90632BB412C700B6A79B /* CNLiveDownslideOperationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveDownslideOperationManager.swift; sourceTree = "<group>"; };
375 19AD65A92BA041210045A444 /* CNLiveGoodsDetailsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveGoodsDetailsTableViewCell.swift; sourceTree = "<group>"; }; 379 19AD65A92BA041210045A444 /* CNLiveGoodsDetailsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveGoodsDetailsTableViewCell.swift; sourceTree = "<group>"; };
376 19AD65AB2BA16CF20045A444 /* CNLiveShopCommentRequestShareModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveShopCommentRequestShareModel.swift; sourceTree = "<group>"; }; 380 19AD65AB2BA16CF20045A444 /* CNLiveShopCommentRequestShareModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveShopCommentRequestShareModel.swift; sourceTree = "<group>"; };
377 19AD65AD2BA177C20045A444 /* CNLiveShopGoodsDetailsTableHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveShopGoodsDetailsTableHeaderView.swift; sourceTree = "<group>"; }; 381 19AD65AD2BA177C20045A444 /* CNLiveShopGoodsDetailsTableHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveShopGoodsDetailsTableHeaderView.swift; sourceTree = "<group>"; };
@@ -809,6 +813,7 @@ @@ -809,6 +813,7 @@
809 1938BD482B512C5800390A34 /* DownSlide */ = { 813 1938BD482B512C5800390A34 /* DownSlide */ = {
810 isa = PBXGroup; 814 isa = PBXGroup;
811 children = ( 815 children = (
  816 + 197325D32BB3B40F002E41A3 /* CNLiveDownslideOperationManager */,
812 7CD6753B2A2740B0008354C1 /* CNDownSlideView.swift */, 817 7CD6753B2A2740B0008354C1 /* CNDownSlideView.swift */,
813 7CD6753A2A2740B0008354C1 /* CNDownSlideViewRemindView.swift */, 818 7CD6753A2A2740B0008354C1 /* CNDownSlideViewRemindView.swift */,
814 19FA20162AE22D3C001F7186 /* CNLiveDownSlideRecommendCell.swift */, 819 19FA20162AE22D3C001F7186 /* CNLiveDownSlideRecommendCell.swift */,
@@ -940,6 +945,22 @@ @@ -940,6 +945,22 @@
940 path = GoodsManager; 945 path = GoodsManager;
941 sourceTree = "<group>"; 946 sourceTree = "<group>";
942 }; 947 };
  948 + 197325D02BB11BFD002E41A3 /* DatabaseManager */ = {
  949 + isa = PBXGroup;
  950 + children = (
  951 + 197325D12BB11C18002E41A3 /* DatabaseManager.swift */,
  952 + );
  953 + path = DatabaseManager;
  954 + sourceTree = "<group>";
  955 + };
  956 + 197325D32BB3B40F002E41A3 /* CNLiveDownslideOperationManager */ = {
  957 + isa = PBXGroup;
  958 + children = (
  959 + 19AB90632BB412C700B6A79B /* CNLiveDownslideOperationManager.swift */,
  960 + );
  961 + path = CNLiveDownslideOperationManager;
  962 + sourceTree = "<group>";
  963 + };
943 19BB1FE42AEB93850094D962 /* Model */ = { 964 19BB1FE42AEB93850094D962 /* Model */ = {
944 isa = PBXGroup; 965 isa = PBXGroup;
945 children = ( 966 children = (
@@ -1156,6 +1177,7 @@ @@ -1156,6 +1177,7 @@
1156 798A44F32A3077ED00815935 /* CustomView */, 1177 798A44F32A3077ED00815935 /* CustomView */,
1157 790D01832A2D89E100C5978D /* Extensions */, 1178 790D01832A2D89E100C5978D /* Extensions */,
1158 796398912A260C0100D045EB /* Common */, 1179 796398912A260C0100D045EB /* Common */,
  1180 + 197325D02BB11BFD002E41A3 /* DatabaseManager */,
1159 796398922A260C0100D045EB /* Config */, 1181 796398922A260C0100D045EB /* Config */,
1160 796398902A260C0100D045EB /* Main */, 1182 796398902A260C0100D045EB /* Main */,
1161 7963988B2A260C0100D045EB /* Other */, 1183 7963988B2A260C0100D045EB /* Other */,
@@ -1906,8 +1928,10 @@ @@ -1906,8 +1928,10 @@
1906 790D019A2A2DCAE400C5978D /* CNLiveViewController.swift in Sources */, 1928 790D019A2A2DCAE400C5978D /* CNLiveViewController.swift in Sources */,
1907 191733192B10A05D007BCC04 /* CNLivePlayerProgressView.swift in Sources */, 1929 191733192B10A05D007BCC04 /* CNLivePlayerProgressView.swift in Sources */,
1908 79803E272AD68D3100F05F68 /* CNLiveMineShopViewController.swift in Sources */, 1930 79803E272AD68D3100F05F68 /* CNLiveMineShopViewController.swift in Sources */,
  1931 + 197325D22BB11C18002E41A3 /* DatabaseManager.swift in Sources */,
1909 79803E292AD6991200F05F68 /* CNLiveMineInputMessageView.swift in Sources */, 1932 79803E292AD6991200F05F68 /* CNLiveMineInputMessageView.swift in Sources */,
1910 79282A462A2F457D00B5F8CF /* CNLiveMineViewController.swift in Sources */, 1933 79282A462A2F457D00B5F8CF /* CNLiveMineViewController.swift in Sources */,
  1934 + 19AB90642BB412C700B6A79B /* CNLiveDownslideOperationManager.swift in Sources */,
1911 7991723A2AF091E100DC01A8 /* CNLiveShopOrderListViewController.swift in Sources */, 1935 7991723A2AF091E100DC01A8 /* CNLiveShopOrderListViewController.swift in Sources */,
1912 798A44F02A305BC200815935 /* UIButton+CNLiveExtensions.swift in Sources */, 1936 798A44F02A305BC200815935 /* UIButton+CNLiveExtensions.swift in Sources */,
1913 1938BD342B4B968300390A34 /* CNLiveHomePageDuanJuCell.swift in Sources */, 1937 1938BD342B4B968300390A34 /* CNLiveHomePageDuanJuCell.swift in Sources */,
metaCode/Classes/DatabaseManager/DatabaseManager.swift 0 → 100644
  1 +//
  2 +// DatabaseManager.swift
  3 +// metaCode
  4 +//
  5 +// Created by zx on 2024/3/25.
  6 +//
  7 +
  8 +import FMDB
  9 +import HandyJSON
  10 +
  11 +class DatabaseManager {
  12 + private let dbQueue: FMDatabaseQueue
  13 +
  14 + init(filePath: String) {
  15 + let databasePath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
  16 + let filePathStr = "\(databasePath)/CNLiveDownSlideModelDataBase.db"
  17 +// print("2222222:\n\(filePathStr)")
  18 + self.dbQueue = FMDatabaseQueue(path: filePathStr) ?? FMDatabaseQueue()
  19 + // 在这里调用创建表的
  20 + self.createTable()
  21 + }
  22 +
  23 + func hasDataInTable() -> Bool {
  24 + // 查询一行来确定是否有数据
  25 + var isHaveData = false
  26 + dbQueue.inDatabase { db in
  27 + let sql = "SELECT * FROM CNLiveDownSlideModelDataBase LIMIT 1" // 查询一行来确定是否有数据
  28 + let results: FMResultSet? = db.executeQuery(sql, withArgumentsIn: [])
  29 + isHaveData = results != nil && results!.next() // 如果 results 不为空且至少有一行数据,则返回 true
  30 + }
  31 + return isHaveData // 如果 results 不为空且至少有一行数据,则返回 true
  32 + }
  33 +
  34 + // 创建表(如果表不存在)
  35 + func createTable() {
  36 + dbQueue.inDatabase { db in
  37 + if !db.executeUpdate("CREATE TABLE IF NOT EXISTS CNLiveDownSlideModelDataBase (blockId INTEGER PRIMARY KEY AUTOINCREMENT,id INTEGER,timeStamp INTEGER, isGetPage INTEGER,json_data TEXT)", withArgumentsIn: []) {
  38 + print("Error creating table: \(db.lastErrorMessage())")
  39 + }
  40 + }
  41 + }
  42 +
  43 + // 保存模型(增)
  44 + func saveModel(_ models: [CNLiveDownSlideModel]) {
  45 + self.dbQueue.inTransaction { db, rollback in
  46 +
  47 + do {
  48 + for slide in models {
  49 + let jsonData = try slide.toJSONString()
  50 + let insertSQL = "INSERT INTO CNLiveDownSlideModelDataBase (blockId,id,timeStamp,isGetPage, json_data) VALUES (?,?,?,?,?)"
  51 + if db.executeUpdate(insertSQL, withArgumentsIn: [slide.blockId ,slide.id,slide.timeStamp,0, jsonData ?? ["":""]]) == true{
  52 +// print("2222222save succ")
  53 + }else{
  54 +// print("2222222save fail")
  55 + }
  56 + }
  57 + } catch {
  58 + rollback
  59 + }
  60 + }
  61 + }
  62 +
  63 + // 更新模型(改)
  64 + func updateModel(_ models: [CNLiveDownSlideModel]) {
  65 + self.dbQueue.inTransaction { db, rollback in
  66 + do {
  67 + for slide in models {
  68 + let jsonData = try slide.toJSONString()
  69 + let updateSQL = "UPDATE CNLiveDownSlideModelDataBase SET json_data = ? ,id = ? , isGetPage = ? ,timeStamp = ? WHERE blockId = ?"
  70 + if db.executeUpdate(updateSQL, withArgumentsIn: [jsonData ?? ["":""],slide.id,0,slide.timeStamp ,slide.blockId]) == true{
  71 +// print("2222222Succ updating model,blockId\(slide.blockId)")
  72 + }else{
  73 +// print("2222222Error updating model")
  74 + }
  75 + }
  76 + } catch {
  77 + rollback
  78 + }
  79 + }
  80 + }
  81 +
  82 + // 更新表中所有记录的 isGetPage属性
  83 + func updateIsGetPage(isGetPage: Int){
  84 + let updateSQL = "UPDATE CNLiveDownSlideModelDataBase SET isGetPage = ?"
  85 + self.dbQueue.inTransaction { db, rollback in
  86 + if db.executeUpdate(updateSQL, withArgumentsIn: [isGetPage]) == true{
  87 +// print("2222222Succ updating model")
  88 + }else{
  89 +// print("2222222Error updating model")
  90 + }
  91 + }
  92 + }
  93 +
  94 + // 删除模型(删)
  95 + func deleteModel(withID id: Int64) {
  96 + self.dbQueue.inTransaction { db, rollback in
  97 + let statement = "DELETE FROM CNLiveDownSlideModelDataBase WHERE id = ?"
  98 + if db.executeUpdate(statement, withArgumentsIn: [id]){
  99 + print("Success deleting model")
  100 + }else{
  101 + print("2222222Error deleting model")
  102 + }
  103 + }
  104 + }
  105 +
  106 + // 查询所有模型(查)
  107 +// func fetchAllModels() -> [CNLiveDownSlideModel] {
  108 +// var models: [CNLiveDownSlideModel] = []
  109 +// self.dbQueue.inDatabase { db in
  110 +// if let results = try? db.executeQuery("SELECT * FROM CNLiveDownSlideModelDataBase", withArgumentsIn: []){
  111 +// while results.next() {
  112 +// let model = CNLiveDownSlideModel()
  113 +// model.pageId = Int(results.int(forColumn: "id"))
  114 +// let slideModelJSONStr = results.string(forColumn: "downSlideJSONStr")
  115 +// models.append(model)
  116 +// }
  117 +//
  118 +// }
  119 +//
  120 +// }
  121 +// return models
  122 +// }
  123 +
  124 + // 根据ID查询模型(查)
  125 + func fetchModel(withID id: Int64) -> [CNLiveDownSlideModel]? {
  126 + var models: [CNLiveDownSlideModel]?
  127 + self.dbQueue.inDatabase { db in
  128 + let results = try? db.executeQuery("SELECT * FROM CNLiveDownSlideModelDataBase WHERE id = ? ORDER BY timeStamp ASC", withArgumentsIn: [id])
  129 + var tempModels = [CNLiveDownSlideModel]()
  130 + while results?.next() == true {
  131 + if let jsonData = results!.data(forColumn: "json_data"){
  132 + if let jsonResult = try? JSONSerialization.jsonObject(with: jsonData, options: []) as? [String: Any] {
  133 +// print("转换成功,jsonResult: \(jsonResult)")
  134 + // 在这里,jsonResult就是转换后的Dictionary<String, Any>
  135 + let res = jsonResult
  136 + let slide = newDictionaryToModel(res, CNLiveDownSlideModel.self) as! CNLiveDownSlideModel
  137 + if let isGetPage = results?.int(forColumn: "isGetPage"){
  138 + slide.isGetPage = Int(isGetPage)
  139 + }else{
  140 +
  141 + }
  142 + tempModels.append(slide)
  143 + } else {
  144 + print("2222222转换失败,无法转换为字典")
  145 + }
  146 +
  147 + }else{
  148 + print("2222222jsonData fail")
  149 + }
  150 +
  151 + }
  152 + if tempModels.count > 0{
  153 + models = Array(tempModels)
  154 + }
  155 + }
  156 + return models
  157 + }
  158 +
  159 + // 其他数据库操作方法可以在这里继续添加...
  160 +}
  161 +
metaCode/Classes/Main/HomePage/Controller/DownSlideController/CNUpSlideViewController.swift
@@ -59,10 +59,58 @@ class CNUpSlideViewController: CNLiveBaseViewController,UITableViewDelegate,UITa @@ -59,10 +59,58 @@ class CNUpSlideViewController: CNLiveBaseViewController,UITableViewDelegate,UITa
59 } 59 }
60 set{ 60 set{
61 _downPath = newValue! 61 _downPath = newValue!
62 - self.getPageApi() 62 +
  63 + let databaseManager = DatabaseManager(filePath: "")
  64 + // 检索数据
  65 + var newDataArr = databaseManager.fetchModel(withID: Int64(newValue!) ?? 0)
  66 + if (newDataArr != nil){
  67 +
  68 + //查询isGetPage是否为1 true
  69 + if newDataArr?.first?.isGetPage == 1{
  70 + //请求getpage后更新本地数据库
  71 + let operation = BlockOperation { [weak self] in
  72 + //网络请求
  73 + self!.getPageApi(isUpdateDB: true)
  74 + }
  75 + CNLiveDownslideOperationManager.shared.addDownslideOperation(operation: operation)
  76 + }else{
  77 + //不更新本地数据库
  78 +
  79 + }
  80 +
  81 + self.dataArray.removeAllObjects()
  82 + self.dataArray.addObjects(from: newDataArr!)
  83 + if self.idModel?.id == 6{
  84 + //幼教中国,请求我的课程接口
  85 + self.getYjzgMyCurriculumApi()
  86 + let firMdl = self.dataArray.firstObject as! CNLiveDownSlideModel
  87 + if firMdl.type == SlideModelTypeTodayRecommend74{
  88 + self.isFirstMyCurriculum = false
  89 + }else{
  90 + self.isFirstMyCurriculum = true
  91 + }
  92 + }else{
  93 + self.tableView.reloadData()
  94 + }
  95 + }else{
  96 + let operation = BlockOperation { [weak self] in
  97 + //网络请求
  98 + self!.getPageApi(isUpdateDB: false)
  99 + }
  100 + CNLiveDownslideOperationManager.shared.addDownslideOperation(operation: operation)
  101 + }
  102 +
  103 +// self.getPageApi()
63 } 104 }
64 } 105 }
65 106
  107 + /// 获取十位时间戳
  108 + func getTimeStamp()->Int{
  109 + let timeInterval: TimeInterval = NSDate().timeIntervalSince1970
  110 + let timeStamp = Int(timeInterval)
  111 + return timeStamp
  112 + }
  113 +
66 // MARK: - 懒加载 114 // MARK: - 懒加载
67 ///数据源 115 ///数据源
68 lazy var dataArray: NSMutableArray = { 116 lazy var dataArray: NSMutableArray = {
@@ -265,24 +313,38 @@ class CNUpSlideViewController: CNLiveBaseViewController,UITableViewDelegate,UITa @@ -265,24 +313,38 @@ class CNUpSlideViewController: CNLiveBaseViewController,UITableViewDelegate,UITa
265 return 0 313 return 0
266 } 314 }
267 //MARK: - 网络请求获取详情页 315 //MARK: - 网络请求获取详情页
268 - func getPageApi() 316 + func getPageApi(isUpdateDB:Bool)
269 { 317 {
270 // showLoading(message: "") 318 // showLoading(message: "")
271 CNLiveDownSlideViewModel.requestGetPage(pageId: _downPath! as NSString) { result, status in 319 CNLiveDownSlideViewModel.requestGetPage(pageId: _downPath! as NSString) { result, status in
272 hiddenLoading() 320 hiddenLoading()
273 321
274 if status == .success{ 322 if status == .success{
  323 + // 假设你有一个 CNLiveDownSlideModel 实例要保存
  324 + let databaseManager = DatabaseManager(filePath: "")
275 325
276 self.dataArray.removeAllObjects() 326 self.dataArray.removeAllObjects()
277 let array = result as! [Any] 327 let array = result as! [Any]
278 let newDataArray = NSMutableArray() 328 let newDataArray = NSMutableArray()
  329 + var index = 1
279 for slideModel in array { 330 for slideModel in array {
280 if let model = slideModel as? CNLiveDownSlideModel{ 331 if let model = slideModel as? CNLiveDownSlideModel{
281 -  
282 let layout = CNLiveDownSlideModelLayout.init(model: model) 332 let layout = CNLiveDownSlideModelLayout.init(model: model)
283 - newDataArray.addObjects(from: [layout.getCellHModel()]) 333 + let newSlideModel = layout.getCellHModel()
  334 + newSlideModel.id = Int(self.downPath!) ?? 0
  335 +
  336 + let timestampIdx = index
  337 + newSlideModel.timeStamp = timestampIdx
  338 + print("timeStamp:\(timestampIdx)")
  339 + index = index + 1
  340 + newDataArray.add(newSlideModel)
284 } 341 }
285 } 342 }
  343 + let newDataArr = newDataArray as! [CNLiveDownSlideModel]
  344 +
  345 + databaseManager.saveModel(newDataArr)
  346 + databaseManager.updateModel(newDataArr)
  347 +
286 self.dataArray.addObjects(from: newDataArray as! [Any]) 348 self.dataArray.addObjects(from: newDataArray as! [Any])
287 if self.idModel?.id == 6{ 349 if self.idModel?.id == 6{
288 //幼教中国,请求我的课程接口 350 //幼教中国,请求我的课程接口
@@ -298,10 +360,13 @@ class CNUpSlideViewController: CNLiveBaseViewController,UITableViewDelegate,UITa @@ -298,10 +360,13 @@ class CNUpSlideViewController: CNLiveBaseViewController,UITableViewDelegate,UITa
298 } 360 }
299 361
300 }else if (status == .failed){ 362 }else if (status == .failed){
  363 +// print("222222222getPageFail:\(self.downPath!)")
301 // self.NetApiStatus = .apiError 364 // self.NetApiStatus = .apiError
302 }else if (status == .noNetwork){ 365 }else if (status == .noNetwork){
303 - 366 +// print("222222222getPageFail:\(self.downPath!)")
304 // self.NetApiStatus = .notNetwork 367 // self.NetApiStatus = .notNetwork
  368 + }else{
  369 +// print("222222222getPageFail:\(self.downPath!)")
305 } 370 }
306 } 371 }
307 // 372 //
metaCode/Classes/Main/HomePage/View/VerticalViews/DownSlide/CNDownSlideSingleCourseCell.swift
@@ -105,7 +105,7 @@ class CNDownSlideSingleCourseCell: UITableViewCell { @@ -105,7 +105,7 @@ class CNDownSlideSingleCourseCell: UITableViewCell {
105 //全部课程列表 105 //全部课程列表
106 contentView.addSubview(bgBackView) 106 contentView.addSubview(bgBackView)
107 107
108 - bgBackView.frame = CGRect(x: DownSlideRecommendLeftGap, y: 0,width:DownSlideSingleCourseW , height:model.cellH-DownSlideRecommendLeftGap) 108 + bgBackView.frame = CGRect(x: DownSlideRecommendLeftGap, y: 0,width:DownSlideSingleCourseW , height:CGFloat(model.cellH)-DownSlideRecommendLeftGap)
109 // 设置阴影效果 109 // 设置阴影效果
110 bgBackView.layer.masksToBounds = false 110 bgBackView.layer.masksToBounds = false
111 //定义view的阴影颜色 111 //定义view的阴影颜色
@@ -120,7 +120,7 @@ class CNDownSlideSingleCourseCell: UITableViewCell { @@ -120,7 +120,7 @@ class CNDownSlideSingleCourseCell: UITableViewCell {
120 bgBackView.backgroundColor = .white 120 bgBackView.backgroundColor = .white
121 121
122 var titleTop:CGFloat = DownSlideRecommendLeftGap 122 var titleTop:CGFloat = DownSlideRecommendLeftGap
123 - if model.blockSubTitle?.count ?? 0 > 0{ 123 + if model.blockSubTitle.count ?? 0 > 0{
124 let subtitleLbl = UILabel(frame: CGRect(x: DownSlideRecommendLeftGap, y: DownSlideRecommendLeftGap, width: DownSlideSingleCourseW-DownSlideRecommendLeftGap*2, height: 17)) 124 let subtitleLbl = UILabel(frame: CGRect(x: DownSlideRecommendLeftGap, y: DownSlideRecommendLeftGap, width: DownSlideSingleCourseW-DownSlideRecommendLeftGap*2, height: 17))
125 subtitleLbl.text = model.blockSubTitle 125 subtitleLbl.text = model.blockSubTitle
126 subtitleLbl.font = Font_12 126 subtitleLbl.font = Font_12
@@ -202,8 +202,8 @@ class CNDownSlideSingleCourseCell: UITableViewCell { @@ -202,8 +202,8 @@ class CNDownSlideSingleCourseCell: UITableViewCell {
202 bgImageView.layer.cornerRadius = GlobalConstants.toDayCardCornerRadius 202 bgImageView.layer.cornerRadius = GlobalConstants.toDayCardCornerRadius
203 bgImageView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner] 203 bgImageView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
204 bgImageView.layer.masksToBounds = true 204 bgImageView.layer.masksToBounds = true
205 - if let bgImgStr = model.background{  
206 - bgImageView.kf.setImage(with: URL(string: bgImgStr)) 205 + if model.background.count > 0{
  206 + bgImageView.kf.setImage(with: URL(string: model.background))
207 }else{ 207 }else{
208 bgImageView.kf.setImage(with: URL(string: model.contents[0].poster ?? "")) 208 bgImageView.kf.setImage(with: URL(string: model.contents[0].poster ?? ""))
209 } 209 }
metaCode/Classes/Main/HomePage/View/VerticalViews/DownSlide/CNLiveDownSlideRecommendCell.swift
@@ -57,7 +57,7 @@ class CNLiveDownSlideRecommendCell: UITableViewCell { @@ -57,7 +57,7 @@ class CNLiveDownSlideRecommendCell: UITableViewCell {
57 //显示左边的块 57 //显示左边的块
58 let contentMdl = model.contents[(hangIndex-1)*2+(lieIndex)] 58 let contentMdl = model.contents[(hangIndex-1)*2+(lieIndex)]
59 let imageView = UIImageView(frame: CGRectMake(DownSlideRecommendLeftGap, CGFloat(hangIndex-1)*DownSlideRecommendWH+DownSlideRecommendLeftGap*CGFloat(hangIndex-1), CGFloat(DownSlideRecommendWH), CGFloat(DownSlideRecommendWH))) 59 let imageView = UIImageView(frame: CGRectMake(DownSlideRecommendLeftGap, CGFloat(hangIndex-1)*DownSlideRecommendWH+DownSlideRecommendLeftGap*CGFloat(hangIndex-1), CGFloat(DownSlideRecommendWH), CGFloat(DownSlideRecommendWH)))
60 - imageView.kf.setImage(with: URL(string:contentMdl.poster!)) 60 + imageView.kf.setImage(with: URL(string:contentMdl.poster))
61 imageView.tag = i 61 imageView.tag = i
62 imageView.layer.cornerRadius = 14 62 imageView.layer.cornerRadius = 14
63 imageView.clipsToBounds = true 63 imageView.clipsToBounds = true
@@ -69,7 +69,7 @@ class CNLiveDownSlideRecommendCell: UITableViewCell { @@ -69,7 +69,7 @@ class CNLiveDownSlideRecommendCell: UITableViewCell {
69 //lieIndex==1显示右边的块 69 //lieIndex==1显示右边的块
70 let contentMdl = model.contents[(hangIndex-1)*2+(lieIndex)] 70 let contentMdl = model.contents[(hangIndex-1)*2+(lieIndex)]
71 let imageView = UIImageView(frame: CGRectMake(CGFloat(DownSlideRecommendLeftGap*2)+CGFloat(DownSlideRecommendWH), CGFloat(hangIndex-1)*DownSlideRecommendWH+DownSlideRecommendLeftGap*CGFloat(hangIndex-1), CGFloat(DownSlideRecommendWH), CGFloat(DownSlideRecommendWH))) 71 let imageView = UIImageView(frame: CGRectMake(CGFloat(DownSlideRecommendLeftGap*2)+CGFloat(DownSlideRecommendWH), CGFloat(hangIndex-1)*DownSlideRecommendWH+DownSlideRecommendLeftGap*CGFloat(hangIndex-1), CGFloat(DownSlideRecommendWH), CGFloat(DownSlideRecommendWH)))
72 - imageView.kf.setImage(with: URL(string:contentMdl.poster!)) 72 + imageView.kf.setImage(with: URL(string:contentMdl.poster))
73 imageView.tag = i 73 imageView.tag = i
74 imageView.layer.cornerRadius = 14 74 imageView.layer.cornerRadius = 14
75 imageView.clipsToBounds = true 75 imageView.clipsToBounds = true
metaCode/Classes/Main/HomePage/View/VerticalViews/DownSlide/CNLiveDownslideOperationManager/CNLiveDownslideOperationManager.swift 0 → 100644
  1 +//
  2 +// CNLiveDownslideOperationManager.swift
  3 +// metaCode
  4 +//
  5 +// Created by zx on 2024/3/27.
  6 +// 下滑页原生页getpage网络请求 队列管理类
  7 +
  8 +import Foundation
  9 +
  10 +class CNLiveDownslideOperationManager : NSObject{
  11 +
  12 + //单例类
  13 + static let shared = CNLiveDownslideOperationManager()
  14 +
  15 + let operationQueue = OperationQueue()
  16 +
  17 + override init() {
  18 + super.init()
  19 + self.operationQueue.maxConcurrentOperationCount = 1
  20 + }
  21 +
  22 + func addDownslideOperation(operation:Operation){
  23 + if self.operationQueue.operationCount == 0{
  24 + self.operationQueue.addOperation(operation)
  25 + }else{
  26 + // 添加Operation到OperationQueue,并设置依赖关系
  27 + self.operationQueue.addOperation(operation)
  28 + if let lastOperation = operationQueue.operations.last {
  29 + operation.addDependency(lastOperation)
  30 + }
  31 + }
  32 + }
  33 +}
metaCode/Classes/Main/Model/CNLiveDownSlideModel.swift
@@ -9,22 +9,32 @@ import Foundation @@ -9,22 +9,32 @@ import Foundation
9 9
10 // !!!: /contentApi/getPage 接口数据 10 // !!!: /contentApi/getPage 接口数据
11 class CNLiveDownSlideModel: BaseModel { 11 class CNLiveDownSlideModel: BaseModel {
  12 + ///page id自定义数据方便数据库
  13 + var id: Int = 0
  14 + ///存入数据库时间戳10位
  15 + var timeStamp:Int = 0
  16 + ///是否可以请求GetPage接口,1可以 0不可以
  17 + var isGetPage:Int = 0
  18 +
  19 + ///////接口数据
12 ///大块标题id 20 ///大块标题id
13 - var blockId: String? 21 + var blockId: String = ""
14 ///大块标题 22 ///大块标题
15 - var blockName: String? 23 + var blockName: String = ""
16 ///大块副标题 24 ///大块副标题
17 - var blockSubTitle: String? 25 + var blockSubTitle: String = ""
18 ///类型 type=4一排两个 74今日推荐 12列表全部课程 75单课程大图 26 ///类型 type=4一排两个 74今日推荐 12列表全部课程 75单课程大图
19 - var type: String? 27 + var type: String = ""
20 ///区块封面图 28 ///区块封面图
21 - var background: String? 29 + var background: String = ""
22 ///显示几行 30 ///显示几行
23 var rowNum: Int = 0 31 var rowNum: Int = 0
24 ///具体内容 title subTitle poster thirdUrl或者shareUrl 32 ///具体内容 title subTitle poster thirdUrl或者shareUrl
25 var contents = [CNLiveDownSlideContentsModel]() 33 var contents = [CNLiveDownSlideContentsModel]()
26 ///cell高度 34 ///cell高度
27 - var cellH: CGFloat = 0 35 + var cellH: Float = 0
  36 +
  37 +
28 } 38 }
29 39
30 //下滑tableview背景颜色 40 //下滑tableview背景颜色
@@ -40,29 +50,29 @@ let kCNDownSlideContentsModelModelServing: String = &quot;serving&quot;//微信小程序 @@ -40,29 +50,29 @@ let kCNDownSlideContentsModelModelServing: String = &quot;serving&quot;//微信小程序
40 50
41 class CNLiveDownSlideContentsModel: BaseModel { 51 class CNLiveDownSlideContentsModel: BaseModel {
42 ///内容id 52 ///内容id
43 - var contentId: String? 53 + var contentId: String = ""
44 ///主标题 54 ///主标题
45 - var title: String? 55 + var title: String = ""
46 ///副标题 56 ///副标题
47 - var subTitle: String? 57 + var subTitle: String = ""
48 ///头像/ 58 ///头像/
49 - var poster: String? 59 + var poster: String = ""
50 ///videoId 60 ///videoId
51 - var pid: String? 61 + var pid: String = ""
52 ///model 62 ///model
53 ///1,2时跳转:sharelUrl后面拼接 ?contentId=contentId&videoId=pid 63 ///1,2时跳转:sharelUrl后面拼接 ?contentId=contentId&videoId=pid
54 ///3,4时跳转:thirdUrl 64 ///3,4时跳转:thirdUrl
55 ///“album”,“album_video”,“album_ugc” -> http://wjjh5.cnlive.com/cnYmAlbumVideoList.html?aid=contentId&title=titlle 65 ///“album”,“album_video”,“album_ugc” -> http://wjjh5.cnlive.com/cnYmAlbumVideoList.html?aid=contentId&title=titlle
56 /// aid:专辑id,title:专辑名称(需要encode) 66 /// aid:专辑id,title:专辑名称(需要encode)
57 - var model: String? 67 + var model: String = ""
58 ///model为1,2时 68 ///model为1,2时
59 - var shareUrl: String? 69 + var shareUrl: String = ""
60 ///model为3,4时跳转url 70 ///model为3,4时跳转url
61 - var thirdUrl: String? 71 + var thirdUrl: String = ""
62 ///小程序地址和小程序id {"path":"page/login_hint/login_hint","id":"gh_234d4ed615a3"} 72 ///小程序地址和小程序id {"path":"page/login_hint/login_hint","id":"gh_234d4ed615a3"}
63 - var s_to: String? 73 + var s_to: String = ""
64 ///103时为微信小程序 74 ///103时为微信小程序
65 - var s_type: String? 75 + var s_type: String = ""
66 ///"weixin://dl/business/?t=NnvptiuER3k" 76 ///"weixin://dl/business/?t=NnvptiuER3k"
67 - var s_showType: String? 77 + var s_showType: String = ""
68 } 78 }
metaCode/Classes/Main/Model/CNLiveDownSlideModelLayout.swift
@@ -38,14 +38,14 @@ class CNLiveDownSlideModelLayout:NSObject{ @@ -38,14 +38,14 @@ class CNLiveDownSlideModelLayout:NSObject{
38 if row == 0{//row为0 , contents全部显示 38 if row == 0{//row为0 , contents全部显示
39 totalNum = contentsNum 39 totalNum = contentsNum
40 } 40 }
41 - _slideModel?.cellH = ceil(CGFloat(totalNum)*0.5)*(DownSlideRecommendWH + DownSlideRecommendLeftGap) 41 + _slideModel?.cellH = Float(ceil(CGFloat(totalNum)*0.5)*(DownSlideRecommendWH + DownSlideRecommendLeftGap))
42 }else if(_slideModel?.type == SlideModelTypeTodayRecommend74){//今日推荐 42 }else if(_slideModel?.type == SlideModelTypeTodayRecommend74){//今日推荐
43 //总显示块数/循环数 43 //总显示块数/循环数
44 var totalNum = (contentsNum >= row) ? row : contentsNum 44 var totalNum = (contentsNum >= row) ? row : contentsNum
45 if row == 0{//row为0 , contents全部显示 45 if row == 0{//row为0 , contents全部显示
46 totalNum = contentsNum 46 totalNum = contentsNum
47 } 47 }
48 - _slideModel?.cellH = CGFloat(totalNum)*(DownSlideTodayRecommendH + DownSlideRecommendLeftGap) 48 + _slideModel?.cellH = Float(CGFloat(totalNum)*(DownSlideTodayRecommendH + DownSlideRecommendLeftGap))
49 }else if(_slideModel?.type == SlideModelTypeAllCourse12){//全部课程 49 }else if(_slideModel?.type == SlideModelTypeAllCourse12){//全部课程
50 //总显示块数/循环数 50 //总显示块数/循环数
51 var totalNum = (contentsNum >= row) ? row : contentsNum 51 var totalNum = (contentsNum >= row) ? row : contentsNum
@@ -53,11 +53,11 @@ class CNLiveDownSlideModelLayout:NSObject{ @@ -53,11 +53,11 @@ class CNLiveDownSlideModelLayout:NSObject{
53 totalNum = contentsNum 53 totalNum = contentsNum
54 } 54 }
55 55
56 - _slideModel?.cellH = DownSlideAllCourseTitleH + DownSlideAllCourseRowH * CGFloat(totalNum)+DownSlideRecommendLeftGap 56 + _slideModel?.cellH = Float(DownSlideAllCourseTitleH + DownSlideAllCourseRowH * CGFloat(totalNum)+DownSlideRecommendLeftGap)
57 57
58 }else if(_slideModel?.type == SlideModelTypeOneCourse75){//单节课程 58 }else if(_slideModel?.type == SlideModelTypeOneCourse75){//单节课程
59 59
60 - _slideModel?.cellH = DownSlideSingleCourseImgH + DownSlideSingleCourseMoreH+DownSlideRecommendLeftGap 60 + _slideModel?.cellH = Float(DownSlideSingleCourseImgH + DownSlideSingleCourseMoreH+DownSlideRecommendLeftGap)
61 }else{ 61 }else{
62 _slideModel?.cellH = 0 62 _slideModel?.cellH = 0
63 } 63 }
metaCode/Classes/Main/Util/CNLiveDownSlideTool.swift
@@ -142,7 +142,7 @@ class CNLiveDownSlideTool:NSObject{ @@ -142,7 +142,7 @@ class CNLiveDownSlideTool:NSObject{
142 142
143 let queryItem = URLQueryItem(name: "contentId", value: contentMdl.contentId) 143 let queryItem = URLQueryItem(name: "contentId", value: contentMdl.contentId)
144 let queryItem1 = URLQueryItem(name: "videoId", value: contentMdl.pid) 144 let queryItem1 = URLQueryItem(name: "videoId", value: contentMdl.pid)
145 - let urlComponents = NSURLComponents(string: (contentMdl.shareUrl)!)! 145 + let urlComponents = NSURLComponents(string: (contentMdl.shareUrl))!
146 urlComponents.queryItems = [queryItem, queryItem1] 146 urlComponents.queryItems = [queryItem, queryItem1]
147 let regURL = urlComponents.url 147 let regURL = urlComponents.url
148 let webVC = CNWebViewController() 148 let webVC = CNWebViewController()
@@ -151,7 +151,7 @@ class CNLiveDownSlideTool:NSObject{ @@ -151,7 +151,7 @@ class CNLiveDownSlideTool:NSObject{
151 151
152 }else if (contentMdl.model == kCNDownSlideContentsModelModel3) || (contentMdl.model == kCNDownSlideContentsModelModel4){ 152 }else if (contentMdl.model == kCNDownSlideContentsModelModel3) || (contentMdl.model == kCNDownSlideContentsModelModel4){
153 let webVC = CNWebViewController() 153 let webVC = CNWebViewController()
154 - webVC.url = URL(string: (contentMdl.thirdUrl)!) 154 + webVC.url = URL(string: (contentMdl.thirdUrl))
155 viewController.navigationController?.pushViewController(webVC, animated: true) 155 viewController.navigationController?.pushViewController(webVC, animated: true)
156 }else if (contentMdl.model == kCNDownSlideContentsModelModelAlbum){ 156 }else if (contentMdl.model == kCNDownSlideContentsModelModelAlbum){
157 157
@@ -179,7 +179,7 @@ class CNLiveDownSlideTool:NSObject{ @@ -179,7 +179,7 @@ class CNLiveDownSlideTool:NSObject{
179 viewController.navigationController?.pushViewController(webVC, animated: true) 179 viewController.navigationController?.pushViewController(webVC, animated: true)
180 }else if (contentMdl.model == kCNDownSlideContentsModelModelAlbum_ugc){ 180 }else if (contentMdl.model == kCNDownSlideContentsModelModelAlbum_ugc){
181 //短剧-跳转短剧播放页 181 //短剧-跳转短剧播放页
182 - navigationViewController().visibleViewController?.navigationController?.pushViewController(CNLiveShortVideoViewController(aid: contentMdl.contentId!), animated: pushAnimated) 182 + navigationViewController().visibleViewController?.navigationController?.pushViewController(CNLiveShortVideoViewController(aid: contentMdl.contentId), animated: pushAnimated)
183 }else if contentMdl.model == kCNDownSlideContentsModelModelServing{ 183 }else if contentMdl.model == kCNDownSlideContentsModelModelServing{
184 //跳转微信小程序 184 //跳转微信小程序
185 if let data = (contentMdl.s_to ?? "").data(using: .utf8) { 185 if let data = (contentMdl.s_to ?? "").data(using: .utf8) {
metaCode/Classes/Other/AppDelegate.swift
@@ -46,10 +46,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate { @@ -46,10 +46,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
46 window?.rootViewController = is_login ? CNLiveBaseTabBarViewController.init() : CNLiveLoginViewController.init() 46 window?.rootViewController = is_login ? CNLiveBaseTabBarViewController.init() : CNLiveLoginViewController.init()
47 window?.makeKeyAndVisible() 47 window?.makeKeyAndVisible()
48 48
49 -  
50 AppDelegate_configRequestManager() 49 AppDelegate_configRequestManager()
51 AppDelegate_configIQKeyboardManager() 50 AppDelegate_configIQKeyboardManager()
52 51
  52 + let databasePath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
  53 + let filePath = "\(databasePath)/CNLiveDownSlideModelDataBase.db"
  54 + let databaseManager = DatabaseManager(filePath: filePath)
  55 + databaseManager.createTable()
  56 +
  57 + if databaseManager.hasDataInTable(){
  58 + databaseManager.updateIsGetPage(isGetPage: 1)
  59 + }else{
  60 + print("noData")
  61 + }
53 return true 62 return true
54 } 63 }
55 64