authentication.m.dart 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. import 'aIDiagnosis.m.dart';
  2. import 'package:fis_jsonrpc/utils.dart';
  3. import 'package:fis_common/json_convert.dart';
  4. class AuthenticationRequest extends TokenRequest{
  5. String? fileName;
  6. AuthenticationRequest({
  7. this.fileName,
  8. String? token,
  9. }) : super(
  10. token: token,
  11. );
  12. factory AuthenticationRequest.fromJson(Map<String, dynamic> map) {
  13. return AuthenticationRequest(
  14. fileName: map['FileName'],
  15. token: map['Token'],
  16. );
  17. }
  18. Map<String, dynamic> toJson() {
  19. final map = super.toJson();
  20. if(fileName != null)
  21. map['FileName'] = fileName;
  22. return map;
  23. }
  24. }
  25. enum AccountType {
  26. Admin,
  27. User,
  28. US,
  29. USBox,
  30. ThirdParty,
  31. }
  32. enum Platform {
  33. Windows,
  34. Android,
  35. Ios,
  36. }
  37. enum LoginSource {
  38. PC,
  39. Mobile,
  40. Pad,
  41. Web,
  42. }
  43. class TokenDTO {
  44. int version;
  45. String? code;
  46. AccountType accountType;
  47. String? accountName;
  48. Platform platform;
  49. LoginSource loginSource;
  50. String? clientId;
  51. String? loginServer;
  52. DateTime? createTime;
  53. DateTime? expiration;
  54. int ipValue;
  55. bool isOnline;
  56. TokenDTO({
  57. this.version = 0,
  58. this.code,
  59. this.accountType = AccountType.Admin,
  60. this.accountName,
  61. this.platform = Platform.Windows,
  62. this.loginSource = LoginSource.PC,
  63. this.clientId,
  64. this.loginServer,
  65. this.createTime,
  66. this.expiration,
  67. this.ipValue = 0,
  68. this.isOnline = false,
  69. });
  70. factory TokenDTO.fromJson(Map<String, dynamic> map) {
  71. return TokenDTO(
  72. version: map['Version'],
  73. code: map['Code'],
  74. accountType: AccountType.values.firstWhere((e) => e.index == map['AccountType']),
  75. accountName: map['AccountName'],
  76. platform: Platform.values.firstWhere((e) => e.index == map['Platform']),
  77. loginSource: LoginSource.values.firstWhere((e) => e.index == map['LoginSource']),
  78. clientId: map['ClientId'],
  79. loginServer: map['LoginServer'],
  80. createTime: map['CreateTime'] != null ? DateTime.parse(map['CreateTime']) : null,
  81. expiration: map['Expiration'] != null ? DateTime.parse(map['Expiration']) : null,
  82. ipValue: map['IpValue'],
  83. isOnline: map['IsOnline'],
  84. );
  85. }
  86. Map<String, dynamic> toJson() {
  87. final map = Map<String, dynamic>();
  88. map['Version'] = version;
  89. if(code != null)
  90. map['Code'] = code;
  91. map['AccountType'] = accountType.index;
  92. if(accountName != null)
  93. map['AccountName'] = accountName;
  94. map['Platform'] = platform.index;
  95. map['LoginSource'] = loginSource.index;
  96. if(clientId != null)
  97. map['ClientId'] = clientId;
  98. if(loginServer != null)
  99. map['LoginServer'] = loginServer;
  100. if(createTime != null)
  101. map['CreateTime'] = JsonRpcUtils.dateFormat(createTime!);
  102. if(expiration != null)
  103. map['Expiration'] = JsonRpcUtils.dateFormat(expiration!);
  104. map['IpValue'] = ipValue;
  105. map['IsOnline'] = isOnline;
  106. return map;
  107. }
  108. }
  109. class ApplyTokenRequest {
  110. AccountType accountType;
  111. Platform platform;
  112. LoginSource loginSource;
  113. String? clientId;
  114. String? loginServer;
  115. int ipValue;
  116. ApplyTokenRequest({
  117. this.accountType = AccountType.Admin,
  118. this.platform = Platform.Windows,
  119. this.loginSource = LoginSource.PC,
  120. this.clientId,
  121. this.loginServer,
  122. this.ipValue = 0,
  123. });
  124. factory ApplyTokenRequest.fromJson(Map<String, dynamic> map) {
  125. return ApplyTokenRequest(
  126. accountType: AccountType.values.firstWhere((e) => e.index == map['AccountType']),
  127. platform: Platform.values.firstWhere((e) => e.index == map['Platform']),
  128. loginSource: LoginSource.values.firstWhere((e) => e.index == map['LoginSource']),
  129. clientId: map['ClientId'],
  130. loginServer: map['LoginServer'],
  131. ipValue: map['IpValue'],
  132. );
  133. }
  134. Map<String, dynamic> toJson() {
  135. final map = Map<String, dynamic>();
  136. map['AccountType'] = accountType.index;
  137. map['Platform'] = platform.index;
  138. map['LoginSource'] = loginSource.index;
  139. if(clientId != null)
  140. map['ClientId'] = clientId;
  141. if(loginServer != null)
  142. map['LoginServer'] = loginServer;
  143. map['IpValue'] = ipValue;
  144. return map;
  145. }
  146. }
  147. enum CustomerRpcCode {
  148. Ok,
  149. TokenNotExist,
  150. TokenExpired,
  151. InvalidTokenVersion,
  152. IPInBlacklist,
  153. }
  154. class ValidateTokenResult {
  155. CustomerRpcCode code;
  156. TokenDTO? token;
  157. ValidateTokenResult({
  158. this.code = CustomerRpcCode.Ok,
  159. this.token,
  160. });
  161. factory ValidateTokenResult.fromJson(Map<String, dynamic> map) {
  162. return ValidateTokenResult(
  163. code: CustomerRpcCode.values.firstWhere((e) => e.index == map['Code']),
  164. token: map['Token'] != null ? TokenDTO.fromJson(map['Token']) : null,
  165. );
  166. }
  167. Map<String, dynamic> toJson() {
  168. final map = Map<String, dynamic>();
  169. map['Code'] = code.index;
  170. if(token != null)
  171. map['Token'] = token;
  172. return map;
  173. }
  174. }
  175. class ValidateTokenRequest {
  176. String? token;
  177. ValidateTokenRequest({
  178. this.token,
  179. });
  180. factory ValidateTokenRequest.fromJson(Map<String, dynamic> map) {
  181. return ValidateTokenRequest(
  182. token: map['Token'],
  183. );
  184. }
  185. Map<String, dynamic> toJson() {
  186. final map = Map<String, dynamic>();
  187. if(token != null)
  188. map['Token'] = token;
  189. return map;
  190. }
  191. }
  192. class IList<T> {
  193. TokenDTO? item;
  194. IList({
  195. this.item,
  196. });
  197. factory IList.fromJson(Map<String, dynamic> map) {
  198. return IList(
  199. item: map['Item'] != null ? TokenDTO.fromJson(map['Item']) : null,
  200. );
  201. }
  202. Map<String, dynamic> toJson() {
  203. final map = Map<String, dynamic>();
  204. if(item != null)
  205. map['Item'] = item;
  206. return map;
  207. }
  208. }
  209. class GetTokensWithClientIdRequest extends BaseRequest{
  210. String? clientId;
  211. AccountType accountType;
  212. GetTokensWithClientIdRequest({
  213. this.clientId,
  214. this.accountType = AccountType.Admin,
  215. }) : super(
  216. );
  217. factory GetTokensWithClientIdRequest.fromJson(Map<String, dynamic> map) {
  218. return GetTokensWithClientIdRequest(
  219. clientId: map['ClientId'],
  220. accountType: AccountType.values.firstWhere((e) => e.index == map['AccountType']),
  221. );
  222. }
  223. Map<String, dynamic> toJson() {
  224. final map = super.toJson();
  225. if(clientId != null)
  226. map['ClientId'] = clientId;
  227. map['AccountType'] = accountType.index;
  228. return map;
  229. }
  230. }
  231. class GetTokenWithClientIdsRequest extends BaseRequest{
  232. List<String>? clientIds;
  233. GetTokenWithClientIdsRequest({
  234. this.clientIds,
  235. }) : super(
  236. );
  237. factory GetTokenWithClientIdsRequest.fromJson(Map<String, dynamic> map) {
  238. return GetTokenWithClientIdsRequest(
  239. clientIds: map['ClientIds'] != null ? map['ClientIds'].cast<String>().toList() : null,
  240. );
  241. }
  242. Map<String, dynamic> toJson() {
  243. final map = super.toJson();
  244. if(clientIds != null)
  245. map['ClientIds'] = clientIds;
  246. return map;
  247. }
  248. }
  249. class GetTokenWithValuesRequest extends BaseRequest{
  250. List<String>? tokenValues;
  251. GetTokenWithValuesRequest({
  252. this.tokenValues,
  253. }) : super(
  254. );
  255. factory GetTokenWithValuesRequest.fromJson(Map<String, dynamic> map) {
  256. return GetTokenWithValuesRequest(
  257. tokenValues: map['TokenValues'] != null ? map['TokenValues'].cast<String>().toList() : null,
  258. );
  259. }
  260. Map<String, dynamic> toJson() {
  261. final map = super.toJson();
  262. if(tokenValues != null)
  263. map['TokenValues'] = tokenValues;
  264. return map;
  265. }
  266. }
  267. class SetOnlineStateRequest extends TokenRequest{
  268. bool isOnline;
  269. SetOnlineStateRequest({
  270. this.isOnline = false,
  271. String? token,
  272. }) : super(
  273. token: token,
  274. );
  275. factory SetOnlineStateRequest.fromJson(Map<String, dynamic> map) {
  276. return SetOnlineStateRequest(
  277. isOnline: map['IsOnline'],
  278. token: map['Token'],
  279. );
  280. }
  281. Map<String, dynamic> toJson() {
  282. final map = super.toJson();
  283. map['IsOnline'] = isOnline;
  284. return map;
  285. }
  286. }
  287. class PageResult<T> {
  288. int pageIndex;
  289. int pageSize;
  290. int totalCount;
  291. List<T>? pageData;
  292. PageResult({
  293. this.pageIndex = 0,
  294. this.pageSize = 0,
  295. this.totalCount = 0,
  296. this.pageData,
  297. });
  298. factory PageResult.fromJson(Map<String, dynamic> map) {
  299. List<T> pageDataList = [];
  300. if (map['PageData'] != null) {
  301. pageDataList.addAll(
  302. (map['PageData'] as List).map((e) => FJsonConvert.fromJson<T>(e)!));
  303. }
  304. return PageResult(
  305. pageIndex: map['PageIndex'],
  306. pageSize: map['PageSize'],
  307. totalCount: map['TotalCount'],
  308. pageData: pageDataList,
  309. );
  310. }
  311. Map<String, dynamic> toJson() {
  312. final map = Map<String, dynamic>();
  313. map['PageIndex'] = pageIndex;
  314. map['PageSize'] = pageSize;
  315. map['TotalCount'] = totalCount;
  316. if(pageData != null)
  317. map['PageData'] = pageData;
  318. return map;
  319. }
  320. }
  321. class PageRequest extends TokenRequest{
  322. int pageIndex;
  323. int pageSize;
  324. PageRequest({
  325. this.pageIndex = 0,
  326. this.pageSize = 0,
  327. String? token,
  328. }) : super(
  329. token: token,
  330. );
  331. factory PageRequest.fromJson(Map<String, dynamic> map) {
  332. return PageRequest(
  333. pageIndex: map['PageIndex'],
  334. pageSize: map['PageSize'],
  335. token: map['Token'],
  336. );
  337. }
  338. Map<String, dynamic> toJson() {
  339. final map = super.toJson();
  340. map['PageIndex'] = pageIndex;
  341. map['PageSize'] = pageSize;
  342. return map;
  343. }
  344. }
  345. class GetPagedTokensRequest extends PageRequest{
  346. String? keyword;
  347. GetPagedTokensRequest({
  348. this.keyword,
  349. int pageIndex = 0,
  350. int pageSize = 0,
  351. String? token,
  352. }) : super(
  353. pageIndex: pageIndex,
  354. pageSize: pageSize,
  355. token: token,
  356. );
  357. factory GetPagedTokensRequest.fromJson(Map<String, dynamic> map) {
  358. return GetPagedTokensRequest(
  359. keyword: map['Keyword'],
  360. pageIndex: map['PageIndex'],
  361. pageSize: map['PageSize'],
  362. token: map['Token'],
  363. );
  364. }
  365. Map<String, dynamic> toJson() {
  366. final map = super.toJson();
  367. if(keyword != null)
  368. map['Keyword'] = keyword;
  369. return map;
  370. }
  371. }