ClassSet.cpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. #include "ClassSet.h"
  2. #include "DBServiceSet.h"
  3. #include "UserService.h"
  4. #include <QCryptographicHash>
  5. #include <QSettings>
  6. #include <QDebug>
  7. QList<NodeMatrixInfo *> ClassSet::datas;
  8. ClassSet::ClassSet()
  9. {
  10. datas.clear();
  11. NodeMatrixInfo *testData = new NodeMatrixInfo();
  12. testData->expertName = "luoyc";
  13. testData->expertId = "1";
  14. testData->engineerId = 1;
  15. testData->node = "1.1";
  16. testData->abscissa = "A";
  17. testData->ordinate = "A";
  18. datas.append(testData);
  19. NodeMatrixInfo *testData1 = new NodeMatrixInfo();
  20. testData1->expertName = "luoyc";
  21. testData1->expertId = "1";
  22. testData1->engineerId = 1;
  23. testData1->node = "1.1";
  24. testData1->abscissa = "A";
  25. testData1->ordinate = "B";
  26. datas.append(testData1);
  27. NodeMatrixInfo *testData2 = new NodeMatrixInfo();
  28. testData2->expertName = "luoyc";
  29. testData2->expertId = "1";
  30. testData2->engineerId = 1;
  31. testData2->node = "1.2";
  32. testData2->abscissa = "B";
  33. testData2->ordinate = "A";
  34. datas.append(testData2);
  35. NodeMatrixInfo *testData3 = new NodeMatrixInfo();
  36. testData3->expertName = "luoyc";
  37. testData3->expertId = "1";
  38. testData3->engineerId = 1;
  39. testData3->node = "1.2";
  40. testData3->abscissa = "B";
  41. testData3->ordinate = "B";
  42. datas.append(testData3);
  43. NodeMatrixInfo *testData4 = new NodeMatrixInfo();
  44. testData4->expertName = "luoyc";
  45. testData4->expertId = "1";
  46. testData4->engineerId = 1;
  47. testData4->node = "1.1.1";
  48. testData4->abscissa = "A1";
  49. testData4->ordinate = "A1";
  50. datas.append(testData4);
  51. NodeMatrixInfo *testData5 = new NodeMatrixInfo();
  52. testData5->expertName = "luoyc";
  53. testData5->expertId = "1";
  54. testData5->engineerId = 1;
  55. testData5->node = "1.1.1";
  56. testData5->abscissa = "A1";
  57. testData5->ordinate = "A2";
  58. datas.append(testData5);
  59. NodeMatrixInfo *testData6 = new NodeMatrixInfo();
  60. testData6->expertName = "luoyc";
  61. testData6->expertId = "1";
  62. testData6->engineerId = 1;
  63. testData6->node = "1.1.2";
  64. testData6->abscissa = "A2";
  65. testData6->ordinate = "A1";
  66. datas.append(testData6);
  67. NodeMatrixInfo *testData7 = new NodeMatrixInfo();
  68. testData7->expertName = "luoyc";
  69. testData7->expertId = "1";
  70. testData7->engineerId = 1;
  71. testData7->node = "1.1.2";
  72. testData7->abscissa = "A2";
  73. testData7->ordinate = "A2";
  74. datas.append(testData7);
  75. NodeMatrixInfo *testData8 = new NodeMatrixInfo();
  76. testData8->expertName = "luoyc";
  77. testData8->expertId = "1";
  78. testData8->engineerId = 1;
  79. testData8->node = "1.2.1";
  80. testData8->abscissa = "B1";
  81. testData8->ordinate = "B1";
  82. datas.append(testData8);
  83. NodeMatrixInfo *testData9 = new NodeMatrixInfo();
  84. testData9->expertName = "luoyc";
  85. testData9->expertId = "1";
  86. testData9->engineerId = 1;
  87. testData9->node = "1.2.1";
  88. testData9->abscissa = "B1";
  89. testData9->ordinate = "B2";
  90. datas.append(testData9);
  91. NodeMatrixInfo *testData10 = new NodeMatrixInfo();
  92. testData10->expertName = "luoyc";
  93. testData10->expertId = "1";
  94. testData10->engineerId = 1;
  95. testData10->node = "1.2.2";
  96. testData10->abscissa = "B2";
  97. testData10->ordinate = "B1";
  98. datas.append(testData10);
  99. NodeMatrixInfo *testData11 = new NodeMatrixInfo();
  100. testData11->expertName = "luoyc";
  101. testData11->expertId = "1";
  102. testData11->engineerId = 1;
  103. testData11->node = "1.2.2";
  104. testData11->abscissa = "B2";
  105. testData11->ordinate = "B2";
  106. datas.append(testData11);
  107. }
  108. static QFUser *m_currentUser = nullptr;
  109. QString QFUser::nameOfRole(QFUser::Role role)
  110. {
  111. switch (role) {
  112. case QFUser::SuperAdmin: {
  113. return "超级管理员";
  114. }
  115. case QFUser::GerneralAdmin: {
  116. return "普通管理员";
  117. }
  118. case QFUser::Expert: {
  119. return "专家";
  120. }
  121. default:
  122. return "未知";
  123. }
  124. }
  125. QFUser::QFUser() { }
  126. QFUser::QFUser(const QString userId, const QString password) : userNo(userId), m_rawPassword(password) { }
  127. const QString QFUser::rawPassword() const
  128. {
  129. return m_rawPassword;
  130. }
  131. QFUser *QFUser::currentUser()
  132. {
  133. return m_currentUser;
  134. }
  135. QString QFUser::roleName() const
  136. {
  137. return nameOfRole(role);
  138. }
  139. int QFUser::logout()
  140. {
  141. if (m_currentUser == nullptr) {
  142. return QF_CODE_NOT_LOGIN;
  143. }
  144. delete m_currentUser;
  145. m_currentUser = nullptr;
  146. return QF_CODE_SUCCEEDED;
  147. }
  148. int QFUser::resetAdmin(QString account, QString password, QString repeatPassword)
  149. {
  150. qDebug() << account << password << repeatPassword << (password == repeatPassword);
  151. if (account.isEmpty()) {
  152. return QF_CODE_EMPTY_ACCOUNT;
  153. } else if (password.isEmpty()) {
  154. return QF_CODE_EMPTY_PASSWORD;
  155. } else if (password != repeatPassword) {
  156. return QF_CODE_PASSWORD_NOT_SAME;
  157. } else if (password == m_rawPassword) {
  158. return QF_CODE_PASSWORD_UNCHANGED;
  159. }
  160. QString md5str;
  161. QByteArray md5bytes = QCryptographicHash::hash(password.toLatin1(), QCryptographicHash::Md5);
  162. md5str.prepend(md5bytes.toHex());
  163. bool ret = UserService().UpdateUserById(account, md5str, id);
  164. if (ret) {
  165. return QF_CODE_SUCCEEDED;
  166. } else {
  167. return QF_CODE_DATA_ERROR;
  168. }
  169. }
  170. int QFUser::login()
  171. {
  172. if (m_currentUser != nullptr) {
  173. return QF_CODE_ALREADY_LOGIN;
  174. }
  175. if (userNo.isEmpty()) {
  176. return QF_CODE_EMPTY_ACCOUNT;
  177. }
  178. if (m_rawPassword.isEmpty()) {
  179. return QF_CODE_EMPTY_PASSWORD;
  180. }
  181. if (!UserService().QueryUserByNo(this, userNo)) {
  182. return QF_CODE_USER_NOT_EXISTS;
  183. }
  184. QCryptographicHash ch(QCryptographicHash::Md5);
  185. qDebug() << "m_rawPassword=" << m_rawPassword;
  186. QString md5str;
  187. QByteArray md5bytes = QCryptographicHash::hash(m_rawPassword.toLatin1(), QCryptographicHash::Md5);
  188. md5str.prepend(md5bytes.toHex());
  189. qDebug() << "m_rawPassword=" << md5str;
  190. m_currentUser = new QFUser(userNo, m_rawPassword);
  191. if (!UserService().QueryUserByNoAndPassword(m_currentUser, userNo, md5str)) {
  192. delete m_currentUser;
  193. m_currentUser = nullptr;
  194. return QF_CODE_WRONG_PASSWORD;
  195. }
  196. return QF_CODE_SUCCEEDED;
  197. }
  198. QString EngineerInfo::nameOfEvalType(EngineerInfo::EvalType t)
  199. {
  200. switch (t) {
  201. case Importance:
  202. return "能力与技术重要度评估";
  203. case TechSchema:
  204. return "技术方案评估";
  205. case Requirements:
  206. return "需求分析评估";
  207. case SchemeOptimization:
  208. return "方案优选评估";
  209. case OverallEfficiency:
  210. return "综合效能评估";
  211. }
  212. }
  213. QString EngineerInfo::nameOFIndexType(EngineerInfo::IndexType t)
  214. {
  215. switch (t) {
  216. case Capability:
  217. return "能力重要度评估指标体系";
  218. case TechMessaures:
  219. return "技术措施重要度评估对象";
  220. case SchemaEval:
  221. return "方案评估指标体系";
  222. }
  223. }
  224. QList<EngineerInfo::IndexType> EngineerInfo::indexListOfEvalFlags(EvalTypes flags)
  225. {
  226. QList<IndexType> list;
  227. if ((flags & EngineerInfo::Importance) == EngineerInfo::Importance) {
  228. list.append(Capability);
  229. list.append(TechMessaures);
  230. }
  231. if ((flags & EngineerInfo::TechSchema) == EngineerInfo::TechSchema) {
  232. list.append(SchemaEval);
  233. }
  234. return list;
  235. }
  236. EngineerInfo::EvalTypes EngineerInfo::evalFlags() const
  237. {
  238. EvalTypes flags;
  239. if (remark.contains("能力与技术重要度评估")) {
  240. flags |= Importance;
  241. }
  242. if (remark.contains("技术方案评估")) {
  243. flags |= TechSchema;
  244. }
  245. return flags;
  246. }
  247. QList<EngineerInfo::IndexType> EngineerInfo::indexList() const
  248. {
  249. return indexListOfEvalFlags(evalFlags());
  250. }