将这段代码改为按照收缩压和舒张压的分级范围查询,分别取数据中的收缩压和舒张压和分级规则中的收缩压取值范围和舒张压取值范围比较,要有是否需要同时满足舒张压和收缩压范围的选项,不再按照value值查询。- (NSMutableArray *)getBloodPresureDataField:(NSString *)field value:(NSInteger)value startTime:(NSTimeInterval)startTime endTime:(NSTimeInterval)endTime { __block NSMutableArray *array = [NSMutableArray array]; [[HWFitnessMgr sharedInstance] excuteInTransaction:^(FMDatabase *db ,BOOL * rollBack) { NSMutableString *rs = [NSMutableString string]; [rs appendString:@" where"]; //此处逻辑:若搜索字段不为COLUMN_SYNC_CLOUD_STATUS去掉本地已删除未上云的数据 if ([field isEqualToString:COLUMN_SYNC_CLOUD_STATUS]) { [rs appendFormat:@" %@ >= %.0lf and %@ <= %.0lf and %@ = %ld", Column_TimeStamp, startTime, Column_TimeStamp, endTime, field, (long)value]; } else { [rs appendFormat:@" %@ >= %.0lf and %@ <= %.0lf and %@ = %ld and %@ != %ld", Column_TimeStamp, startTime, Column_TimeStamp, endTime, field, (long)value, COLUMN_SYNC_CLOUD_STATUS, (long)HWHealthDataSyncCloudStatusDeleteNotSync]; } [rs appendFormat:@" order by %@ desc", Column_TimeStamp]; NSString *strSql = [@"select * from '%@'" stringByAppendingString:rs]; NSString *bloodPressureTable = [self getTableName:FitnessSamplePointBloodPressureTable]; FMResultSet * detailRs = [[HWFitnessMgr sharedInstance] selectBy:strSql andTable:bloodPressureTable inDatabase:db]; if (detailRs) { while ([detailRs next]) { [array addObject:[self fetchBloodPressureDataWithDetailRs:detailRs]]; } [detailRs close]; } }]; return array; }
时间: 2023-06-20 14:06:22 浏览: 107
以下是修改后的代码,按照收缩压和舒张压的分级范围查询:
- (NSMutableArray *)getBloodPresureDataWithSystolicRange:(NSRange)systolicRange diastolicRange:(NSRange)diastolicRange requireBoth:(BOOL)requireBoth startTime:(NSTimeInterval)startTime endTime:(NSTimeInterval)endTime {
__block NSMutableArray *array = [NSMutableArray array];
[[HWFitnessMgr sharedInstance] excuteInTransaction:^(FMDatabase *db, BOOL *rollBack) {
NSMutableString *rs = [NSMutableString string];
[rs appendString:@" where"];
//此处逻辑:若搜索字段不为COLUMN_SYNC_CLOUD_STATUS去掉本地已删除未上云的数据
[rs appendFormat:@" %@ >= %.0lf and %@ <= %.0lf and %@ != %ld", Column_TimeStamp, startTime, Column_TimeStamp, endTime, COLUMN_SYNC_CLOUD_STATUS, (long)HWHealthDataSyncCloudStatusDeleteNotSync];
if (requireBoth) {
[rs appendFormat:@" and %@ >= %ld and %@ <= %ld and %@ >= %ld and %@ <= %ld", COLUMN_SYSTOLIC_PRESSURE, (long)systolicRange.location, COLUMN_SYSTOLIC_PRESSURE, (long)(systolicRange.location + systolicRange.length - 1), COLUMN_DIASTOLIC_PRESSURE, (long)diastolicRange.location, COLUMN_DIASTOLIC_PRESSURE, (long)(diastolicRange.location + diastolicRange.length - 1)];
} else {
// 如果不同时满足收缩压和舒张压的范围,则只要满足其中一个即可
[rs appendFormat:@" and ((%@ >= %ld and %@ <= %ld) or (%@ >= %ld and %@ <= %ld))", COLUMN_SYSTOLIC_PRESSURE, (long)systolicRange.location, COLUMN_SYSTOLIC_PRESSURE, (long)(systolicRange.location + systolicRange.length - 1), COLUMN_DIASTOLIC_PRESSURE, (long)diastolicRange.location, COLUMN_DIASTOLIC_PRESSURE, (long)(diastolicRange.location + diastolicRange.length - 1)];
}
[rs appendFormat:@" order by %@ desc", Column_TimeStamp];
NSString *strSql = [NSString stringWithFormat:@"select * from '%@'%@", [self getTableName:FitnessSamplePointBloodPressureTable], rs];
FMResultSet *detailRs = [[HWFitnessMgr sharedInstance] selectBy:strSql andTable:[self getTableName:FitnessSamplePointBloodPressureTable] inDatabase:db];
if (detailRs) {
while ([detailRs next]) {
[array addObject:[self fetchBloodPressureDataWithDetailRs:detailRs]];
}
[detailRs close];
}
}];
return array;
}
阅读全文