美文网首页
利用liyfmdb框架,实现本周,本月,本日,本季度,本年的sq

利用liyfmdb框架,实现本周,本月,本日,本季度,本年的sq

作者: 锦鲤跃龙 | 来源:发表于2017-03-11 12:27 被阅读0次

    需求

    查询本地数据库,实现本周,本月,本日,本季度,本年的查询,并实现分页效果,代码是用的自己的lyjfmdb进行的数据库查询
    

    代码

    //MARK:获取巡检离线数据
        
        func getoffSpaceExam() {
            
            
            let examModelList  = ExamModel()
            
            let fmdboffset = (currentNum - 1) * mypageCount
            
            var betweensql = ""
            
            
            
            
            let season = Date().getseason()
            
            
            
            
            
            
            print("==beginSeasonStr====\(season.0)==endSeasonStr===\(season.1)====")
            
    
            
            switch timeParame {
            case "5":
                //本年
                betweensql = " and  ((date(startTime)  BETWEEN  date('now','start of year') and  date('now','start of year','+1 year','-1 day') ) OR (date(endTime)  BETWEEN  date('now','start of year') and  date('now','start of year','+1 year','-1 day') ))"
            case "4":
                //本季
                betweensql = " AND ( (strftime('%Y%m',startTime) BETWEEN '\(season.0)' AND '\(season.1)' ) OR (strftime('%Y%m',endTime) BETWEEN '\(season.0)' AND '\(season.1)' ))"
            case "3":
                //本月
                betweensql = " and  ((date(startTime)  BETWEEN  date('now','start of month') and  date('now','start of month','+1 month','-1 second')) OR (date(endTime)  BETWEEN  date('now','start of month') and  date('now','start of month','+1 month','-1 second')))"
            case "2":
                //本周
                betweensql = " and  ((date(startTime)  BETWEEN  date(datetime('now',strftime('-%w day','now')),'+1 day')  and  date(datetime('now',(6 - strftime('%w day','now'))||' day','1 day')) ) OR (date(endTime)  BETWEEN  date(datetime('now',strftime('-%w day','now')),'+1 day')  and  date(datetime('now',(6 - strftime('%w day','now'))||' day','1 day')) ))"
            case "1":
                //本日
                betweensql = " and date('now') between  date(startTime)  and date(endTime) "
            default:
                break
            }
          
            var whereStr = " managerId = '\(spacemangerid)' "
            
            whereStr.append(betweensql)
            
             let reslutList = examModelList.queryWithWhereStr(whereStr: whereStr, orderBy: nil ,otherquery:" LIMIT \(mypageCount)  OFFSET \(fmdboffset) ")
            
            if let reslutList = reslutList,  reslutList.count > 0{
                
              let  examlist = reslutList as! [ExamModel]
               
                if self.currentNum == 1{
                    
                    self.dataSource.removeAll()
                }
                
                
                self.dataSource = self.dataSource + examlist
                
                self.tableView.reloadData()
              
                self.tableView.mj_footer.endRefreshing()
    
            }else{
                self.tableView.mj_footer.endRefreshingWithNoMoreData()
                
            }
            
            
        }
    

    相关文章

      网友评论

          本文标题:利用liyfmdb框架,实现本周,本月,本日,本季度,本年的sq

          本文链接:https://www.haomeiwen.com/subject/akpagttx.html