123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915 |
- //
- // statisticsVC.m
- // LN_School
- //
- // Created by apple on 2017/4/5.
- // Copyright © 2017年 Danson. All rights reserved.
- //
- #import "statisticsVC.h"
- #import "SelectCheckDateViewController.h"
- #import "AFView.h"
- @interface statisticsVC ()
- {
- UILabel *calendarLabel;
- UIButton *calendarbtn;
- UIView *calendarView;
- UIButton *lastDatebtn;
- UILabel *numberLabel;
- UILabel *compareNumLabel;
- UIView *afView;
-
-
- NSString *todayString;
- NSString *yesterdayString;
- NSString *weekNow;
- NSString *weekLast;
- NSString *monthNow;
- NSString *monthLast;
-
- NSString *startDateString;
- NSString *endDateString;
-
- // 1代表报名统计 2代表退学
- NSInteger styleType;
- // 1代表是日 2代表周 3代表月 4代表年
- NSInteger dateType;
- }
- @end
- @implementation statisticsVC
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.navigationItem.title = @"智能统计";//某某驾校
- self.view.backgroundColor = KBackGroundColor;
-
- [self myInit];
- }
- - (void)myInit {
-
- //顶部日历条
- CGFloat x, y, w, h, bd;
- bd = 10;
- x = 0;
- y = kNavOffSet;
- w = kSize.width;
- h = 50;
-
- UIView *view = [[UIView alloc] KSetxywh];
- view.backgroundColor = RQMianColor;
- [self.view addSubview:view];
-
- x = y = bd;
- w = h = 30;
- UIImageView *imgView = [[UIImageView alloc] KSetxywh];
- [imgView setModeAspectFill];
- imgView.image = [UIImage imageNamed:@"arrow_left"];
- [view addSubview:imgView];
-
- x = kSize.width - w - bd;
- imgView = [[UIImageView alloc] KSetxywh];
- [imgView setModeAspectFill];
- imgView.image = [UIImage imageNamed:@"arrow_right"];
- [view addSubview:imgView];
-
- x = y = 0;
- w = 70;
- h = 50;
- UIButton *btn = [[UIButton alloc] KSetxywh];
- [btn target:self Tag:1];
- [view addSubview:btn];
-
- x = kSize.width - w;
- btn = [[UIButton alloc] KSetxywh];
- [btn target:self Tag:2];
- [view addSubview:btn];
-
- x = w;
- w = kSize.width - 2*x;
- btn = [[UIButton alloc] KSetxywh];
- [btn target:self Tag:3];
- [view addSubview:btn];
- calendarbtn = btn;
-
- x = 0;
- w = kSize.width;
- UILabel *label = [[UILabel alloc] KSetxywh];
- [label setText:@"请选择日期 ▽" Font:Font16 TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentCenter];
- [view addSubview:label];
- calendarLabel = label;
-
-
- //报名/退学
- x = 0;
- y = kNavOffSet + 50;
- w = kSize.width/2.0;
- h = 60;
- btn = [[UIButton alloc] KSetxywh];
- [btn setTitle:@"报名统计" textColor:KTitleColor font:Font21 fotState:UIControlStateNormal];
- [btn setTitleColor:RQMianColor forState:UIControlStateSelected];
- [btn target:self Tag:4];
- [self.view addSubview:btn];
- btn.selected = YES;
- [btn addViewWithRect:CGRectMake(w - 1, y + 5, 1, h - 10)];
-
- x += w;
- btn = [[UIButton alloc] KSetxywh];
- [btn setTitle:@"退学统计" textColor:KTitleColor font:Font21 fotState:UIControlStateNormal];
- [btn setTitleColor:RQMianColor forState:UIControlStateSelected];
- [btn target:self Tag:5];
- [self.view addSubview:btn];
- [btn addViewWithRect:CGRectMake(bd, y + h - 1, 2*w - 2*bd, 1)];
-
-
- x = bd;
- y += h;
- w = kSize.width - 2*bd;
- label = [[UILabel alloc] KSetxywh];
- [label setText:@"受理人数" Font:Font18 TextColor:KTitleColor Alignment:NSTextAlignmentLeft];
- [self.view addSubview:label];
-
- label = [[UILabel alloc] KSetxywh];
- [label setText:@"暂无数据" Font:Font18 TextColor:KContentTextColor Alignment:NSTextAlignmentCenter];
- [self.view addSubview:label];
- numberLabel = label;
-
- label = [[UILabel alloc] KSetxywh];
- [label setText:@"比前一日\n--" Font:Font14 TextColor:KContentTextColor Alignment:NSTextAlignmentRight];
- label.numberOfLines = 2;
- [self.view addSubview:label];
- [label addViewWithRect:CGRectMake(10, y + h - 1, w, 1)];
- compareNumLabel = label;
-
- //折线图
-
- y += h + 4*bd;
- x = 0;
- w = kSize.width;
- h = w/2.0 + 3*bd;
- afView = [[UIView alloc] KSetxywh];
- afView.backgroundColor = RQMianColor;
- [self.view addSubview:afView];
-
- // AFView *afv = [[AFView alloc] initWithFrame:CGRectMake(0, 20, afView.width, afView.height - 30)];
- // NSArray* xTitles = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7"];
- // [afv setX_labels:xTitles];
- // [afv setMin_X:1];
- // [afv setMax_X:xTitles.count];
- // [afv setMin_Y:0];
- // [afv setMax_Y:100];
- // [afv setY_labels:@[@"0",@"20",@"40",@"60",@"80",@"100"]];
- // [afView addSubview:afv];
-
-
-
-
-
-
- //隐藏的日期选择
- x = 0;
- y = kNavOffSet + 50;
- w = kSize.width;
- h = kSize.height - y;
- view = [[UIView alloc] KSetxywh];
- view.backgroundColor = [UIColor colorWithWhite:.7 alpha:1.0];
- [self.view addSubview:view];
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap)];
- [view addGestureRecognizer:tap];
- calendarView = view;
-
- y = 0;
- h = 170;
- view = [[UIView alloc] KSetxywh];
- view.backgroundColor = KBackGroundColor;
- [calendarView addSubview:view];
-
- x = bd;
- w -= 2*x;
- h = 40;
- label = [[UILabel alloc] KSetxywh];
- [label setText:@"日期" Font:Font17 TextColor:KTitleColor];
- [view addSubview:label];
-
- y += h;
- w = (kSize.width - 40)/3.0;
- h = 30;
- NSArray *titleArray = @[@"今日",@"昨日",@"本周",@"上周",@"本月",@"上月"];
- for (int i = 0; i < titleArray.count; i ++) {
-
- int row = i/3;
- int column = i%3;
- btn = [[UIButton alloc] initWithFrame:CGRectMake(x + column*(w + bd), y + row*(h + bd), w, h)];
- [btn target:self Tag:i-6];
- [btn setTitle:titleArray[i] textColor:KSubTitleColor font:Font16 fotState:UIControlStateNormal];
- [btn setBackgroundColor:kLineColor];
- [btn setTitleColor:RQMianColor forState:UIControlStateSelected];
- [btn borderCornorRadios:3];
- [view addSubview:btn];
-
- if (i == 0) {
- btn.selected = YES;
- btn.backgroundColor = [UIColor whiteColor];
- [btn boardWid:1 Color:RQMianColor];
- lastDatebtn = btn;
- }
- }
-
- y += 2*h + 2*bd;
- w = kSize.width - 2*x;
- btn = [[UIButton alloc] KSetxywh];
- [btn target:self Tag:-7];
- [btn setTitle:@"自定义日期范围" textColor:KSubTitleColor font:Font16 fotState:UIControlStateNormal];
- [btn setBackgroundColor:kLineColor];
- [btn borderCornorRadios:3];
- [view addSubview:btn];
-
- calendarView.hidden = YES;
- dateType = 1;
- [self initDefaultDate]; //设置默认日期
- [self getPeopleNum];
- }
- - (void)btnClick:(UIButton *)sender
- {
- // NSLog(@"%d",(int)sender.tag);
-
- if (sender.tag == -7) {
- //自定义日期
- calendarView.hidden = YES;
- SelectCheckDateViewController *vc = [[SelectCheckDateViewController alloc]init];
- // __weak typeof(self) weakSelf = self;
- [vc setSelectCheckDateBlock:^(NSString *startDateStr, NSString *endDateStr, NSString *daysStr) {
-
- if ([daysStr integerValue] > 92) {
- ShowMsg(@"系统仅查询时间跨度三个月以内的数据");
- return;
- }
-
- startDateString = [startDateStr stringByReplacingOccurrencesOfString:@"-" withString:@"."];
- endDateString = [endDateStr stringByReplacingOccurrencesOfString:@"-" withString:@"."];
-
- //更改按钮状态 调接口
- UIButton *selectBtn;
-
- if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:todayString]) {
- //相当于选择当天
- dateType = 1;
- selectBtn = (UIButton *)[calendarView viewWithTag:-6];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:yesterdayString]) {
- //相当于选择昨天
- dateType = 1;
- selectBtn = (UIButton *)[calendarView viewWithTag:-5];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:weekNow]) {
- //相当于选择本周
- dateType = 2;
- selectBtn = (UIButton *)[calendarView viewWithTag:-4];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:weekLast]) {
- //相当于选择上周
- dateType = 2;
- selectBtn = (UIButton *)[calendarView viewWithTag:-3];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:monthNow]) {
- //相当于选择本月
- dateType = 3;
- selectBtn = (UIButton *)[calendarView viewWithTag:-2];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:monthLast]) {
- //相当于选择上月
- dateType = 3;
- selectBtn = (UIButton *)[calendarView viewWithTag:-1];
- }else {
- //其他日期
- selectBtn = sender;
- dateType = 1;
- }
-
- lastDatebtn.selected = NO;
- [lastDatebtn boardWid:.1 Color:kLineColor];
- lastDatebtn.backgroundColor = kLineColor;
-
- selectBtn.selected = YES;
- selectBtn.backgroundColor = [UIColor whiteColor];
- [selectBtn boardWid:1 Color:RQMianColor];
- lastDatebtn = selectBtn;
-
- calendarView.hidden = YES;
-
- [self getPeopleNum];
- }];
- [self.navigationController pushViewController:vc animated:YES];
-
- return;
- }
-
- if (sender.tag < 0 && sender.tag > -7) {
-
- if (lastDatebtn.tag != sender.tag) {
-
- if (sender.tag < -4) {
- dateType = 1;
- }else if (sender.tag < -2) {
- dateType = 2;
- }else {
- dateType = 3;
- }
-
- lastDatebtn.selected = NO;
- [lastDatebtn boardWid:.1 Color:kLineColor];
- lastDatebtn.backgroundColor = kLineColor;
-
- sender.selected = !sender.selected;
- sender.backgroundColor = [UIColor whiteColor];
- [sender boardWid:1 Color:RQMianColor];
-
- lastDatebtn = sender;
- calendarView.hidden = YES;
-
- //逻辑处理 要确定日期 然后调接口
- NSArray *dateArray = @[todayString,yesterdayString,weekNow,weekLast,monthNow,monthLast];
- NSArray *beginAndEndDate = [dateArray[lastDatebtn.tag + 6] componentsSeparatedByString:@"-"];
- startDateString = [beginAndEndDate firstObject];
- endDateString = [beginAndEndDate lastObject];
-
- [self getPeopleNum];
- }else{
- calendarView.hidden = YES;
- }
- return;
- }
-
- if (sender.tag == 1 || sender.tag == 2) {
- //更新日期
- [self getDateWithtype:sender.tag == 1 ? -1 : 1];
-
- //更改按钮状态 调接口
- UIButton *selectBtn;
- if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:todayString]) {
- //相当于选择当天
- selectBtn = (UIButton *)[calendarView viewWithTag:-6];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:yesterdayString]) {
- //相当于选择昨天
- selectBtn = (UIButton *)[calendarView viewWithTag:-5];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:weekNow]) {
- //相当于选择本周
- selectBtn = (UIButton *)[calendarView viewWithTag:-4];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:weekLast]) {
- //相当于选择上周
- selectBtn = (UIButton *)[calendarView viewWithTag:-3];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:monthNow]) {
- //相当于选择本月
- selectBtn = (UIButton *)[calendarView viewWithTag:-2];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:monthLast]) {
- //相当于选择上月
- selectBtn = (UIButton *)[calendarView viewWithTag:-1];
- }else {
- //其他日期
- selectBtn = (UIButton *)[calendarView viewWithTag:-7];
- }
-
- lastDatebtn.selected = NO;
- [lastDatebtn boardWid:.1 Color:kLineColor];
- lastDatebtn.backgroundColor = kLineColor;
-
- selectBtn.selected = YES;
- selectBtn.backgroundColor = [UIColor whiteColor];
- [selectBtn boardWid:1 Color:RQMianColor];
-
- lastDatebtn = selectBtn;
-
-
- if (!calendarView.hidden) {
- calendarView.hidden = YES;
- }
-
- [self getPeopleNum];
- return;
- }
-
- if (sender.tag == 3) {
- //显示或收起
- calendarView.hidden = !calendarView.hidden;
- return;
- }
-
- if (sender.tag == 4) {//签到统计
- if (styleType != 1) {
- styleType = 1;
- UIButton *btn = (UIButton *)[self.view viewWithTag:5];
- btn.selected = NO;
- sender.selected = YES;
-
- [self getPeopleNum];
- }
- return;
- }
-
- if (sender.tag == 5) {//签到统计
- if (styleType != 2) {
- styleType = 2;
- UIButton *btn = (UIButton *)[self.view viewWithTag:4];
- btn.selected = NO;
- sender.selected = YES;
-
- [self getPeopleNum];
- }
- return;
- }
-
- }
- - (void)handleTap
- {
- calendarView.hidden = YES;
- }
- - (void)initDefaultDate {
-
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"yyyy.MM.dd"];
-
- //今天
- NSString *dateStr = [dateFormatter stringFromDate:[NSDate date]];
- todayString = [NSString stringWithFormat:@"%@-%@",dateStr,dateStr];
- //设置默认值
- startDateString = endDateString = dateStr;
- calendarLabel.text = [NSString stringWithFormat:@"今日(%@) ▽",dateStr];
-
- //昨天
- dateStr = [self getDateWithdifferentDay:-1];
- yesterdayString =[NSString stringWithFormat:@"%@-%@",dateStr,dateStr];
-
- //本周
- [dateFormatter setDateFormat:@"e"];//1-7 这里把周日当作一周的开始
- int weekDay = [[dateFormatter stringFromDate:[NSDate date]] intValue] - 1;
- if (weekDay == 0) {
- weekDay = 7;
- }
- NSString *beginDate = [self getDateWithdifferentDay: 1-weekDay];
- NSString *endDate = [self getDateWithdifferentDay: 7-weekDay];
- weekNow = [NSString stringWithFormat:@"%@-%@",beginDate,endDate];
-
- //上周
- beginDate = [self getDateWithdifferentDay: -6-weekDay];
- endDate = [self getDateWithdifferentDay: -weekDay];
- weekLast = [NSString stringWithFormat:@"%@-%@",beginDate,endDate];
-
- //本月
- [dateFormatter setDateFormat:@"yyyy.MM"];
- dateStr = [dateFormatter stringFromDate:[NSDate date]];
-
- int moneyInt = [[dateStr substringFromIndex:5] intValue];
- int yearInt = [[dateStr substringToIndex:4] intValue];
- int moneyDay = 31;
- if (moneyInt == 2) {
- if (yearInt%4 == 0) {
- moneyDay = 28;
- }else{
- moneyDay = 29;
- }
- }else{
- if (moneyInt == 4 || moneyInt == 6 || moneyInt == 9 || moneyInt == 11) {
- moneyDay = 30;
- }
- }
- monthNow = [NSString stringWithFormat:@"%@.01-%@.%d",dateStr,dateStr,moneyDay];
-
- //上月
- if (moneyInt == 1) {
- yearInt -= 1;
- moneyInt = 12;
- }else{
- moneyInt -= 1;
- }
-
- moneyDay = 31;
- if (moneyInt == 2) {
- if (yearInt%4 == 0) {
- moneyDay = 28;
- }else{
- moneyDay = 29;
- }
- }else{
- if (moneyInt == 4 || moneyInt == 6 || moneyInt == 9 || moneyInt == 11) {
- moneyDay = 30;
- }
- }
- monthLast = [NSString stringWithFormat:@"%d.%02d.01-%d.%02d.%d",yearInt,moneyInt,yearInt,moneyInt,moneyDay];
-
- // NSLog(@"%@\n%@\n%@\n%@\n%@\n%@",todayString,yesterdayString,weekNow,weekLast,monthNow,monthLast);
- }
- - (NSString *)getDateWithdifferentDay:(NSInteger)day
- {
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"yyyy.MM.dd"];
- return [self getDateWithDay:[dateFormatter stringFromDate:[NSDate date]] DifferentDay:day];
- }
- /**获取指定日期相差某天的日期 格式 yyyy.MM.dd
- @param now 指定日期
- @param day 相差日期 向后为正 向前为负
- @return 返回计算后的日期
- */
- - (NSString *)getDateWithDay:(NSString *)now DifferentDay:(NSInteger)day
- {
- #if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_8_0
- NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
- NSDateComponents *comps = nil;
- comps = [calendar components:NSCalendarUnitDay fromDate:[NSDate date]];
- NSDateComponents *adcomps = [[NSDateComponents alloc] init];
-
- [adcomps setDay:day];
-
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"yyyy.MM.dd"];
-
- NSDate *newdate = [calendar dateByAddingComponents:adcomps toDate:[dateFormatter dateFromString:now] options:0];
- return [dateFormatter stringFromDate:newdate];
- #else
- NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
- NSDateComponents *comps = nil;
- comps = [calendar components:NSDayCalendarUnit fromDate:[NSDate date]];
- NSDateComponents *adcomps = [[NSDateComponents alloc] init];
-
- [adcomps setDay:day];
-
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"yyyy.MM.dd"];
-
- NSDate *newdate = [calendar dateByAddingComponents:adcomps toDate:[dateFormatter dateFromString:now] options:0];
- return [dateFormatter stringFromDate:newdate];
- #endif
- }
- /**给定一串 日期与受理人数的数组 补全开始到结束中的所有天 没有的补0
- */
- - (NSArray *)getCompleteDataWithArray:(NSArray *)array
- {
- // if ([startDateString isEqualToString:endDateString]) {
- // NSMutableArray *aArray = [NSMutableArray array];
- // if (array.count > 0) {
- // [aArray addObject:[array firstObject]];
- // }else {
- // [aArray addObject:[NSDictionary dictionaryWithObject:@"0" forKey:startDateString]];
- // }
- //
- // return aArray;
- // }
-
- NSMutableDictionary *preDic = [NSMutableDictionary dictionaryWithCapacity:array.count];
- for (NSDictionary *dic in array) {
- [preDic setObject:[dic.allValues firstObject] forKey:[[dic.allKeys firstObject] stringByReplacingOccurrencesOfString:@"-" withString:@"."]];
- }
- NSMutableArray *aArray = [NSMutableArray array];
- NSString *dateString = startDateString;
-
- for (int i = 0; ![dateString isEqualToString:[self getDateWithDay:endDateString DifferentDay:1]]; i ++) {
- if ([preDic.allKeys containsObject:dateString]) {
- [aArray addObject:[NSDictionary dictionaryWithObject:preDic[dateString] forKey:dateString]];
- }else {
- [aArray addObject:[NSDictionary dictionaryWithObject:@"0" forKey:dateString]];
- }
-
- dateString = [self getDateWithDay:dateString DifferentDay:1];
- }
- return aArray;
- }
- /**获取给定时间前或后的日期
- @param type 1、向前 2、向后
- */
- - (void)getDateWithtype:(NSInteger)type
- {
- if (dateType == 2) {
-
- startDateString = [self getDateWithDay:startDateString DifferentDay:type*7];
- endDateString = [self getDateWithDay:endDateString DifferentDay:type*7];
- return;
- }
-
- #if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_8_0
- NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
- NSDateComponents *comps = nil;
- comps = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|kCFCalendarUnitWeekday fromDate:[NSDate date]];
- NSDateComponents *adcomps = [[NSDateComponents alloc] init];
-
- switch (dateType) {
- case 1:
- [adcomps setDay:type];
- break;
- case 2:
- // [adcomps setWeekday:type];
- break;
- case 3:
- [adcomps setMonth:type];
- break;
- case 4:
- [adcomps setYear:type];
- break;
- default:
- break;
- }
-
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"yyyy.MM.dd"];
-
- NSDate *newdate = [calendar dateByAddingComponents:adcomps toDate:[dateFormatter dateFromString:startDateString] options:0];
- startDateString = [dateFormatter stringFromDate:newdate];
-
- newdate = [calendar dateByAddingComponents:adcomps toDate:[dateFormatter dateFromString:endDateString] options:0];
- endDateString = [dateFormatter stringFromDate:newdate];
-
- if (dateType == 3) {
- int month = [[endDateString componentsSeparatedByString:@"."][1] intValue];
- if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
- if ([endDateString containsString:@".30"]) {
- endDateString = [endDateString stringByReplacingOccurrencesOfString:@".30" withString:@".31"];
- }
- if ([endDateString containsString:@".29"]) {
- endDateString = [endDateString stringByReplacingOccurrencesOfString:@".29" withString:@".31"];
- }
- if ([endDateString containsString:@".28"]) {
- endDateString = [endDateString stringByReplacingOccurrencesOfString:@".28" withString:@".31"];
- }
- }
- if (month == 4 || month == 6 || month == 9 || month == 11) {
- if ([endDateString containsString:@".31"]) {
- endDateString = [endDateString stringByReplacingOccurrencesOfString:@".31" withString:@".30"];
- }
- if ([endDateString containsString:@".29"]) {
- endDateString = [endDateString stringByReplacingOccurrencesOfString:@".29" withString:@".30"];
- }
- if ([endDateString containsString:@".28"]) {
- endDateString = [endDateString stringByReplacingOccurrencesOfString:@".28" withString:@".30"];
- }
- }
- }
-
- #else
- NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
- NSDateComponents *comps = nil;
- comps = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit|NSCalendarUnitWeekday fromDate:[NSDate date]];
- NSDateComponents *adcomps = [[NSDateComponents alloc] init];
-
- switch (dateType) {
- case 1:
- [adcomps setDay:type];
- break;
- case 2:
- // [adcomps setWeekday:type];
- break;
- case 3:
- [adcomps setMonth:type];
- break;
- case 4:
- [adcomps setYear:type];
- break;
- default:
- break;
- }
-
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"yyyy.MM.dd"];
-
- NSDate *newdate = [calendar dateByAddingComponents:adcomps toDate:[dateFormatter dateFromString:startDateString] options:0];
- startDateString = [dateFormatter stringFromDate:newdate];
-
- newdate = [calendar dateByAddingComponents:adcomps toDate:[dateFormatter dateFromString:endDateString] options:0];
- endDateString = [dateFormatter stringFromDate:newdate];
-
- if (dateType == 3) {
- int month = [[endDateString componentsSeparatedByString:@"."][1] intValue];
- if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
- if ([endDateString containsString:@".30"]) {
- endDateString = [endDateString stringByReplacingOccurrencesOfString:@".30" withString:@".31"];
- }
- if ([endDateString containsString:@".29"]) {
- endDateString = [endDateString stringByReplacingOccurrencesOfString:@".29" withString:@".31"];
- }
- if ([endDateString containsString:@".28"]) {
- endDateString = [endDateString stringByReplacingOccurrencesOfString:@".28" withString:@".31"];
- }
- }
- if (month == 4 || month == 6 || month == 9 || month == 11) {
- if ([endDateString containsString:@".31"]) {
- endDateString = [endDateString stringByReplacingOccurrencesOfString:@".31" withString:@".30"];
- }
- if ([endDateString containsString:@".29"]) {
- endDateString = [endDateString stringByReplacingOccurrencesOfString:@".29" withString:@".30"];
- }
- if ([endDateString containsString:@".28"]) {
- endDateString = [endDateString stringByReplacingOccurrencesOfString:@".28" withString:@".30"];
- }
- }
- }
- #endif
- }
- #pragma mark 数据请求
- - (void)getPeopleNum {
-
- if (![NetManager connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSString *typeString = [NSString stringWithFormat:@"%d",(int)dateType];
- if (lastDatebtn.tag == -7 && ![startDateString isEqualToString:endDateString]) {
- typeString = @"4";
- }
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
- [dic setObject:defUser.userDict[@"school"] forKey:@"schoolId"];
- [dic setObject:typeString forKey:@"type"];
- [dic setObject:[startDateString stringByReplacingOccurrencesOfString:@"." withString:@"-"] forKey:@"startTime"];
- [dic setObject:[endDateString stringByReplacingOccurrencesOfString:@"." withString:@"-"] forKey:@"endTime"];
-
- NSString *method = @"getStudentSignStatistics";
- if (styleType == 2) {
- method = @"getStudentDropStatistics";
- }
-
- [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
-
- if (!root) {
- ShowErrorMsg(@"请求失败!");
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
- ShowErrorMsg(root[@"msg"]);
- return;
- }
-
- //请求成功
- //根据传过来的时间 改变calendarLabel
- NSString *calendarString = calendarString = [NSString stringWithFormat:@"%@-%@ ▽",startDateString,endDateString];
-
- if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:todayString]) {
- //相当于选择当天
- calendarString = [NSString stringWithFormat:@"今日(%@) ▽",startDateString];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:yesterdayString]) {
- //相当于选择昨天
- calendarString = [NSString stringWithFormat:@"昨日(%@) ▽",startDateString];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:weekNow]) {
- //相当于选择本周
- calendarString = [NSString stringWithFormat:@"本周(%@-%@) ▽",startDateString,endDateString];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:weekLast]) {
- //相当于选择上周
- calendarString = [NSString stringWithFormat:@"上周(%@-%@) ▽",startDateString,endDateString];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:monthNow]) {
- //相当于选择本月
- calendarString = [NSString stringWithFormat:@"本月(%@-%@) ▽",startDateString,endDateString];
- }else if ([[NSString stringWithFormat:@"%@-%@",startDateString,endDateString] isEqualToString:monthLast]) {
- //相当于选择上月
- calendarString = [NSString stringWithFormat:@"上月(%@-%@) ▽",startDateString,endDateString];
- }else {
- //其他日期
- if (lastDatebtn.tag == -7) {
- if ([startDateString isEqualToString:endDateString]) {
- calendarString = [NSString stringWithFormat:@"%@ ▽",startDateString];
- }
- }
- }
- //根据type不同 分为报名和退学
- calendarLabel.text = calendarString;
-
-
-
- //根据返回值 设置人数和折线图
- NSDictionary *dict = root[@"body"];
- NSArray *realArray = dict[@"nums"];
- if (![startDateString isEqualToString:endDateString]) {
- if ([dict[@"nums"] count] > 0) {
- realArray = [self getCompleteDataWithArray:dict[@"nums"]];
- }
- }
- // NSLog(@"realArray----><>%@",realArray);
-
- NSString *numString = @"0";
- if ([dict.allKeys containsObject:@"CURRENTNUM"]) {
- numString = [NSString stringWithFormat:@"%@",dict[@"CURRENTNUM"]];
- }
- numberLabel.text = [NSString stringWithFormat:@"%@人",numString];
-
- int differentNumber = [dict[@"CURRENTNUM"] intValue] - [dict[@"LASTNUM"] intValue];
- NSString *differentString = @"--";
- if (differentNumber < 0) {
- differentString = [NSString stringWithFormat:@"- %d人",-differentNumber];
- }else {
- differentString = [NSString stringWithFormat:@"+ %d人",differentNumber];
- }
-
- //请求结束后
- NSInteger pointNum = 0;
- NSArray *xTitles = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10"];
- compareNumLabel.hidden = NO;
- switch (dateType) {
- case 1:
- if ([startDateString isEqualToString:endDateString]) {
- pointNum = 1;
- xTitles = @[startDateString];
- compareNumLabel.text = [NSString stringWithFormat:@"比前一日\n%@",differentString];
- }else{
-
- pointNum = realArray.count > 10 ? 10 : realArray.count;//这个返回多少天 就=多少个吧
- NSMutableArray *aray = [NSMutableArray array];
- for (int i = 0; i < pointNum; i ++) {
- [aray addObject:[NSString stringWithFormat:@"%d",i + 1]];
- }
- xTitles = [NSArray arrayWithArray:aray];
- compareNumLabel.hidden = YES;
- }
- break;
- case 2:
- pointNum = 7;
- xTitles = @[@"周一",@"周二",@"周三",@"周四",@"周五",@"周六",@"周日"];
- compareNumLabel.text = [NSString stringWithFormat:@"比前一周\n%@",differentString];
- break;
- case 3:
- pointNum = 4;
- xTitles = @[@"第1周",@"第2周",@"第3周",@"第4周"];
- compareNumLabel.text = [NSString stringWithFormat:@"比前一月\n%@",differentString];
- break;
- case 4:
- pointNum = 12;
- xTitles = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12"];
- compareNumLabel.text = [NSString stringWithFormat:@"比前一年\n%@",differentString];
- break;
- default:
- break;
- }
-
-
- for (AFView *subV in afView.subviews) {
- [subV removeFromSuperview];
- }
-
- AFView *afv = [[AFView alloc] initWithFrame:CGRectMake(0, 20, afView.width, afView.height - 30)];
- //设置X轴
- [afv setX_labels:xTitles];
- [afv setMin_X:1];
- [afv setMax_X:xTitles.count];
- //设置Y轴
- [afv setMin_Y:0];
- [afv setMax_Y:100];
- [afv setY_labels:@[@"0",@"20",@"40",@"60",@"80",@"100"]];
- [afView addSubview:afv];
-
- NSMutableArray *points = [NSMutableArray arrayWithCapacity:pointNum];
- NSArray *counterfeitDate = @[@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0"];
-
- if ([dict[@"nums"] count] != 0) {
-
- if (dateType == 1 || dateType == 2) {
- NSMutableArray *aray = [NSMutableArray array];
- for (int i = 0; i < pointNum; i ++) {
- [aray addObject:[[realArray[i] allValues] firstObject]];
- }
- counterfeitDate = [NSArray arrayWithArray:aray];
- }else if (dateType == 3) {
-
- NSMutableArray *aray = [NSMutableArray array];
- int num = 0;
- for (int i = 0; i < realArray.count; i ++) {
-
- num += [[[realArray[i] allValues] firstObject] intValue];
- if (i%7 == 6) {
- if (aray.count < 4) {
- num = 0;
- [aray addObject:[NSString stringWithFormat:@"%d",num]];
- }else{
- if (i == realArray.count - 1) {
- [aray addObject:[NSString stringWithFormat:@"%d",num]];
- }
- }
- }
- }
- counterfeitDate = [NSArray arrayWithArray:aray];
- }else if (dateType == 4) {
- //年就不作处理了先
- }
- }
-
- for (int i = 0; i < pointNum; i++) {
- [points addObject:[NSValue valueWithCGPoint:CGPointMake(i + 1, [counterfeitDate[i] integerValue])]];
- }
- [afv setData:points];//折线图的数据。
- }];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
|