-(void)handleDataArray
{
NSMutableArray *timeArray = [NSMutableArray array];
NSMutableArray *nameArray = [NSMutableArray array];
NSMutableArray *orderItemArray = [NSMutableArray array];
for (int i = 0; i<self.dataArray.count; i++) {
SaleAcountInfo *info = [self.dataArray objectAtIndex:i];
NSString *timeStr = info.payedYearMonthDay;
NSString *name = info.name;
if (![timeArray containsObject:timeStr]) {
[timeArray addObject:timeStr];
}
if (![nameArray containsObject:name]) {
[nameArray addObject:name];
}
}
//分类出OrderItem对象
for (NSString *gName in nameArray) {
OrderItem *item = [[OrderItem alloc]init];
int quantity = 0;
for (int i = 0; i<self.dataArray.count; i++) {
SaleAcountInfo *info = [self.dataArray objectAtIndex:i];
NSString *name = info.name;
if ([name isEqualToString:gName]) {
quantity = quantity + info.quantity;
item.timeStr = info.payedYearMonthDay;//时间会有遗漏么 时间是按照天来的么,是整天的么,
}
}
item.quantity = quantity;
item.goodName = gName;
[orderItemArray addObject:item];
}
NSMutableArray *destDataArray = [NSMutableArray array];
for (int n = 0; n<timeArray.count; n++) {
NSString *nTimestr = [timeArray objectAtIndex:n];
NSMutableArray *kOrderItemArray = [NSMutableArray array];
OrderSummaryInfo *summaryInfo = [[OrderSummaryInfo alloc]init];
int quantity = 0;
for (int t = 0; t<orderItemArray.count; t++) {
OrderItem *item = [orderItemArray objectAtIndex:t];
NSString *iName = item.goodName;
for (int m = 0; m<self.dataArray.count; m++) {
SaleAcountInfo *info = [self.dataArray objectAtIndex:m];
NSString *timeStr = info.payedYearMonthDay;
NSString *name = info.name;
if ([timeStr isEqualToString:nTimestr] && [name isEqualToString:iName]) {
if (![kOrderItemArray containsObject:item]) {
[kOrderItemArray addObject:item];
quantity = quantity + item.quantity;
}
}
}
}
summaryInfo.timeStr = nTimestr;
summaryInfo.orderItemArray = kOrderItemArray;
summaryInfo.totalQuantity = quantity;
[destDataArray addObject:summaryInfo];
}
for (NSString *mTime in timeArray) {
NSMutableArray *temp = [NSMutableArray array];
OrderSummaryInfo *info = [[OrderSummaryInfo alloc]init];
int quantity = 0;
for (int i = 0; i<orderItemArray.count; i++) {
OrderItem *item = [orderItemArray objectAtIndex:i];
NSString *time = item.timeStr;
if ([time isEqualToString:mTime]) {
quantity = quantity + item.quantity;
[temp addObject:item];
info.timeStr = time;
}
}
info.totalQuantity = quantity;
info.orderItemArray = temp;
[destDataArray addObject:info];
}
}