Hibok
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

110 行
2.8 KiB

  1. import 'package:chat/models/UserInfo.dart';
  2. import 'package:chat/utils/sql_model.dart';
  3. import 'package:sqflite/sqflite.dart';
  4. class UserInfoTable {
  5. final String table = 'user_info';
  6. Sql sql;
  7. UserInfoTable() {
  8. sql = Sql.setTable(table);
  9. }
  10. createTable() async {
  11. print('创建表$table');
  12. await sql.createTable(table, '''userId INTEGER PRIMARY KEY,
  13. headimgurl TEXT,
  14. nickName TEXT,
  15. meetPlace TEXT,
  16. birthday TEXT,
  17. occupation TEXT,
  18. program TEXT,
  19. hopeObject TEXT,
  20. height INTEGER,
  21. weight INTEGER,
  22. ownMsg TEXT,
  23. isAttestation INTEGER,
  24. isVipAttestation INTEGER,
  25. invisibleStatus INTEGER,
  26. distanceStatus INTEGER,
  27. accountStatus INTEGER,
  28. chatStatus INTEGER,
  29. photoAut INTEGER,
  30. infoAut INTEGER,
  31. loginDate TEXT,
  32. onlineStatus INTEGER,
  33. sex INTEGER,
  34. applyStatus INTEGER,
  35. payStatus INTEGER,
  36. city TEXT,
  37. country TEXT,
  38. constellation INTEGER,
  39. price INTEGER,
  40. burnNum INTEGER,
  41. accessNum INTEGER,
  42. distince INTEGER,
  43. wechat TEXT,
  44. facebook TEXT,
  45. isMember INTEGER,
  46. isAuthority INTEGER,
  47. freeNum INTEGER,
  48. usedNum INTEGER,
  49. publishNum INTEGER,
  50. usedPublishNum INTEGER,
  51. isBlackList INTEGER,
  52. isLike INTEGER,
  53. followNum INTEGER,
  54. fans INTEGER,
  55. dynamicNum INTEGER,
  56. isCanStrangerNews INTEGER,
  57. isBlackened INTEGER,
  58. isAddFriends INTEGER''');
  59. }
  60. Future clear() {
  61. return sql.clearTable(table);
  62. }
  63. //插入新用户
  64. Future insertUser(UserInfo userInfo) async {
  65. var res = await sql.db.rawQuery(
  66. 'select count(*) as count from $table where userId=${userInfo.userId}');
  67. var count = Sqflite.firstIntValue(res);
  68. print('用户是否存在$count');
  69. if (count == null || count == 0) {
  70. var res = await sql.insert(userInfo.toDbJson());
  71. print('插入用户结果$res');
  72. return res;
  73. } else {
  74. return updateUser(userInfo);
  75. }
  76. }
  77. //删除用户信息
  78. deleteUser(int userId) async {
  79. var res =
  80. await sql.db.delete(table, where: 'userId=?', whereArgs: [userId]);
  81. print('删除用户结果$res');
  82. return res;
  83. }
  84. //更新用户信息
  85. updateUser(UserInfo userInfo) async {
  86. var res = await sql.db.update(table, userInfo.toDbJson(),
  87. where: 'userId=?', whereArgs: [userInfo.userId]);
  88. print('更新用户信息$res');
  89. return res;
  90. }
  91. //从本地获取用户信息,仅限聊天
  92. Future<UserInfo> getUserInfoFromLocal(int userId) async {
  93. List list = await sql.query(table, where: 'userId=?', whereArgs: [userId]);
  94. if (list != null && list.length > 0) {
  95. return UserInfo.fromLocalDB(list.first);
  96. }
  97. return null;
  98. }
  99. }