users.service.dart 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. import 'dart:typed_data';
  2. import 'package:dio/dio.dart';
  3. import 'package:maxkey_flutter/utils.dart';
  4. class MaxKeyUser {
  5. final String displayName;
  6. final Uint8List? picture;
  7. MaxKeyUser(this.displayName, this.picture);
  8. factory MaxKeyUser.fromMap(Map map) {
  9. final String displayName = map["data"]["displayName"];
  10. final String? pictureBase64 = map["data"]["pictureBase64"];
  11. final picture = pictureBase64?.split(",")[1].base64ToBuf();
  12. return MaxKeyUser(displayName, picture);
  13. }
  14. }
  15. class MaxKeyUserInfo {
  16. MaxKeyUserInfo({
  17. /// 姓名
  18. required this.displayName,
  19. /// 登陆账号
  20. required this.username,
  21. /// 性别
  22. required this.gender,
  23. /// 员工编号
  24. required this.employeeNumber,
  25. /// 手机号码
  26. required this.mobile,
  27. /// 邮箱
  28. required this.email,
  29. /// 用户类型
  30. required this.userType,
  31. /// 用户状态
  32. required this.userState,
  33. /// 状态
  34. required this.status,
  35. /// 证件类型
  36. required this.idType,
  37. /// 证件号码
  38. required this.idCardNo,
  39. /// 婚姻状态
  40. required this.married,
  41. /// 出生日期
  42. required this.birthDate,
  43. /// 所属组织
  44. required this.organization,
  45. /// 分支机构
  46. required this.division,
  47. /// 部门编号
  48. required this.departmentId,
  49. /// 部门名称
  50. required this.department,
  51. /// 职位
  52. required this.jobTitle,
  53. /// 级别
  54. required this.jobLevel,
  55. /// 上级经理
  56. required this.manager,
  57. });
  58. static MaxKeyUserInfo? fromMap(Map map) {
  59. return MaxKeyUserInfo(
  60. displayName: map["displayName"].toString(),
  61. username: map["username"].toString(),
  62. gender: switch (map["gender"]) { 1 => "女", 2 => "男", _ => _unknwon },
  63. employeeNumber: map["employeeNumber"]?.toString() ?? _unknwon,
  64. mobile: map["mobile"]?.toString() ?? _unknwon,
  65. email: map["email"]?.toString() ?? _unknwon,
  66. userType: switch (map["userType"]) {
  67. "EMPLOYEE" => "内部员工",
  68. "CONTRACTOR" => "承包商",
  69. "CUSTOMER" => "客户",
  70. "SUPPLIER" => "供应商",
  71. "PARTNER" => "合作伙伴",
  72. "EXTERNAL" => "外部用户",
  73. "INTERN" => "实习生",
  74. "TEMP" => "临时用户",
  75. "DEALER" => "经销商",
  76. _ => _unknwon,
  77. },
  78. userState: switch (map["userState"]) {
  79. "RESIDENT" => "在职",
  80. "WITHDRAWN" => "离职",
  81. "INACTIVE" => "停薪留职",
  82. "RETIREE" => "退休",
  83. _ => _unknwon,
  84. },
  85. status: switch (map["status"]) {
  86. 1 => "活动",
  87. 2 => "不活动",
  88. 4 => "禁用",
  89. 5 => "锁定",
  90. 9 => "已删除",
  91. _ => _unknwon,
  92. },
  93. idType: switch (map["idType"]) {
  94. 0 => "未知",
  95. 1 => "身份证",
  96. 2 => "护照",
  97. 3 => "学生证",
  98. 4 => "军人证",
  99. _ => _unknwon,
  100. },
  101. idCardNo: map["idCardNo"]?.toString() ?? _unknwon,
  102. married: switch (map["married"]) {
  103. 0 => "未知",
  104. 1 => "单身",
  105. 2 => "已婚",
  106. 3 => "离异",
  107. 4 => "丧偶",
  108. _ => _unknwon,
  109. },
  110. birthDate: map["birthDate"]?.toString() ?? _unknwon,
  111. organization: map["organization"]?.toString() ?? _unknwon,
  112. division: map["division"]?.toString() ?? _unknwon,
  113. departmentId: map["departmentId"]?.toString() ?? _unknwon,
  114. department: map["deparment"]?.toString() ?? _unknwon,
  115. jobTitle: map["jobTitle"]?.toString() ?? _unknwon,
  116. jobLevel: map["jobLevel"]?.toString() ?? _unknwon,
  117. manager: map["manager"]?.toString() ?? _unknwon,
  118. );
  119. }
  120. /// 姓名
  121. final String displayName;
  122. /// 登陆账号
  123. final String username;
  124. /// 性别
  125. final String gender;
  126. /// 员工编号
  127. final String employeeNumber;
  128. /// 手机号码
  129. final String mobile;
  130. /// 邮箱
  131. final String email;
  132. /// 用户类型
  133. final String userType;
  134. /// 用户状态
  135. final String userState;
  136. /// 状态
  137. final String status;
  138. /// 证件类型
  139. final String idType;
  140. /// 证件号码
  141. final String idCardNo;
  142. /// 婚姻状态
  143. final String married;
  144. /// 出生日期
  145. final String birthDate;
  146. /// 所属组织
  147. final String organization;
  148. /// 分支机构
  149. final String division;
  150. /// 部门编号
  151. final String departmentId;
  152. /// 部门名称
  153. final String department;
  154. /// 职位
  155. final String jobTitle;
  156. /// 级别
  157. final String jobLevel;
  158. /// 上级经理
  159. final String manager;
  160. static const String _unknwon = "未知";
  161. }
  162. class UsersService {
  163. final Dio _dio;
  164. UsersService(this._dio);
  165. Future<MaxKeyUser?> getBasicUserInfo() async {
  166. try {
  167. LOGGER.i("UsersService.getBasicUserInfo(): ");
  168. LOGGER.i("GET: /users/profile/get");
  169. final res = await _dio.get("/users/profile/get");
  170. if (res.data["code"] != 0) {
  171. LOGGER.w(res.data["message"]);
  172. return null;
  173. }
  174. return MaxKeyUser.fromMap(res.data);
  175. } catch (err) {
  176. LOGGER.i("UsersService.getBasicUserInfo(): ");
  177. LOGGER.e(err);
  178. }
  179. return null;
  180. }
  181. Future<MaxKeyUserInfo?> getFullUserInfo() async {
  182. try {
  183. LOGGER.i("UsersService.getFullUserInfo(): ");
  184. LOGGER.i("GET: /users/profile/get");
  185. final res = await _dio.get("/users/profile/get");
  186. if (res.data["code"] != 0) {
  187. LOGGER.w(res.data["message"]);
  188. return null;
  189. }
  190. return MaxKeyUserInfo.fromMap(res.data["data"]);
  191. } catch (err) {
  192. LOGGER.e("UsersService.getFullUserInfo(): ");
  193. LOGGER.e(err);
  194. }
  195. return null;
  196. }
  197. }