Skip to content

Commit

Permalink
🏷️ Add isPostgraduate isContinuingEducation and update isCY def…
Browse files Browse the repository at this point in the history
…ine.
  • Loading branch information
AlexV525 committed Feb 11, 2020
1 parent 1e375f7 commit 0ed01df
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
40 changes: 36 additions & 4 deletions lib/model/user_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class UserInfo {
String sid;
String ticket;
bool isTeacher;
bool isCY;

/// Common Object
int uid;
Expand All @@ -33,7 +32,6 @@ class UserInfo {
this.signature,
this.ticket,
this.isTeacher,
this.isCY,
this.unitId,
this.workId,
this.classId,
Expand All @@ -57,12 +55,14 @@ class UserInfo {
'signature': signature,
'ticket': ticket,
'isTeacher': isTeacher,
'isCY': isCY,
'unitId': unitId,
'workId': workId,
// 'classId': classId,
'gender': gender,
'isFollowing': isFollowing,
'isPostgraduate': isPostgraduate,
'isContinuingEducation': isContinuingEducation,
'isCY': isCY,
};
}

Expand All @@ -71,6 +71,39 @@ class UserInfo {
return 'UserInfo ${JsonEncoder.withIndent(' ').convert(toJson())}';
}

/// 是否为研究生
bool get isPostgraduate {
if (workId.length != 12) {
return false;
} else {
final int code = int.tryParse(workId.substring(4, 6));
if (code == null) return false;
return code >= 10 && code <= 19;
}
}

/// 是否为继续教育学生
bool get isContinuingEducation {
if (workId.length != 12) {
return false;
} else {
final int code = int.tryParse(workId.substring(4, 6));
if (code == null) return false;
return code >= 30 && code <= 39;
}
}

/// 是否为诚毅学院学生
bool get isCY {
if (workId.length != 12) {
return false;
} else {
final int code = int.tryParse(workId.substring(4, 6));
if (code == null) return false;
return code >= 41 && code <= 45;
}
}

factory UserInfo.fromJson(Map<String, dynamic> json) {
json.forEach((k, v) {
if (json[k] == '') json[k] = null;
Expand All @@ -82,7 +115,6 @@ class UserInfo {
signature: json['signature'],
ticket: json['ticket'],
isTeacher: json['isTeacher'] ?? int.parse(json['type'].toString()) == 1,
isCY: json['isCY'],
unitId: json['unitId'] ?? json['unitid'],
workId: (json['workId'] ?? json['workid'] ?? json['uid']).toString(),
classId: null,
Expand Down
15 changes: 0 additions & 15 deletions lib/utils/data_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class DataUtils {
'signature': user['signature'],
'ticket': loginData['ticket'],
'isTeacher': int.parse(user['type'].toString()) == 1,
'isCY': checkCY(user['workid']),
'unitId': loginData['unitid'],
'workId': user['workid'],
// 'classId': user['class_id'],
Expand Down Expand Up @@ -73,19 +72,6 @@ class DataUtils {
}
}

static bool checkCY(String workId) {
if (workId.length != 12) {
return false;
} else {
final int code = int.tryParse(workId.substring(4, 6));
if (code >= 41 && code <= 45) {
return true;
} else {
return false;
}
}
}

static String recoverWorkId() => settingsBox.get(spUserWorkId);

static Future recoverLoginInfo() async {
Expand Down Expand Up @@ -124,7 +110,6 @@ class DataUtils {
'signature': data['signature'],
'ticket': settingsBox.get(spTicket),
'isTeacher': int.parse(data['type'].toString()) == 1,
'isCY': checkCY(data['workid']),
'unitId': data['unitid'],
'workId': data['workid'],
// 'classId': user['class_id'],
Expand Down

0 comments on commit 0ed01df

Please sign in to comment.