需求:
查询本地数据库,实现本周,本月,本日,本季度,本年的查询,并实现分页效果
,代码是用的自己的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()
}
}