ImportDataUtil.cpp 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include "importDataUtil.h"
  2. #include <QDebug>
  3. #include <QSettings>
  4. #include "dbService/ClassSet.h"
  5. #include "dbService/ProjectService.h"
  6. #include "dbService/CNodeDataService.h"
  7. #include "dbService/UserService.h"
  8. #include "CNode.h"
  9. ImportDataUtil::ImportDataUtil() { }
  10. bool ImportDataUtil::importSystemData()
  11. {
  12. bool ret = false;
  13. try {
  14. // TODO 解析exportData数据
  15. QSettings exportData("exportData.ini", QSettings::IniFormat);
  16. exportData.setIniCodec("UTF-8");
  17. QString projectInfo = exportData.value("EXPORTDATA/projectInfo", "").toString();
  18. QString nodeDate = exportData.value("EXPORTDATA/nodeDate", "").toString();
  19. QString userInfo = exportData.value("EXPORTDATA/userInfo", "").toString();
  20. //清除表相关数据
  21. ProjectService().DeleteAll();
  22. CNodeDataService().DeleteAllNodeData();
  23. UserService().DeleteAllUser();
  24. //插入工程
  25. QStringList proList = projectInfo.split(",");
  26. ProjectInfo proj;
  27. proj.id = proList[0].toInt();
  28. proj.projectName = proList[1];
  29. proj.remark = proList[2];
  30. proj.taskName = proList[3];
  31. proj.estimateTime = proList[4];
  32. proj.estimateObjective = proList[5];
  33. proj.estimateDept = proList[6];
  34. proj.estimatePerson = proList[7];
  35. proj.estimateType = proList[8];
  36. proj.positionalTitles = proList[9];
  37. proj.createTime = proList[10];
  38. bool ret = ProjectService().SaveProjectInfo(proj);
  39. //保存节点信息系
  40. QStringList nodeList = nodeDate.split(";");
  41. for (int i = 0; i < nodeList.size(); i++) {
  42. CNodeData nodeData;
  43. QStringList nodeDataList = nodeList[i].split(",");
  44. if (nodeDataList.size() > 1) {
  45. nodeData.id = nodeDataList[0].toInt();
  46. nodeData.projectId = nodeDataList[1].toInt();
  47. nodeData.indexType = nodeDataList[2].toInt();
  48. nodeData.number = nodeDataList[3].toInt();
  49. nodeData.pNumber = nodeDataList[4].toInt();
  50. nodeData.name = nodeDataList[5];
  51. nodeData.remark = nodeDataList[6];
  52. nodeData.dimension = nodeDataList[7];
  53. CNodeDataService().SaveCNodeData(nodeData);
  54. }
  55. }
  56. //保存用户信息
  57. QStringList userList = userInfo.split(";");
  58. for (int i = 0; i < userList.size(); i++) {
  59. QFUser user;
  60. QStringList userInfoList = userList[i].split(",");
  61. if (userInfoList.size() > 1) {
  62. user.id = userInfoList[0].toInt();
  63. user.userName = userInfoList[1];
  64. user.userNo = userInfoList[2];
  65. user.password = userInfoList[3];
  66. user.role = static_cast<QFUser::Role>(userInfoList[4].toInt());
  67. user.post = userInfoList[5];
  68. user.major = userInfoList[6];
  69. user.workPosition = userInfoList[7];
  70. user.educationDegree = userInfoList[8];
  71. user.phone = userInfoList[9];
  72. user.remark = userInfoList[10];
  73. user.projectId = userInfoList[11];
  74. user.writeTime = userInfoList[12];
  75. int retuser = UserService().AddUserInfo(user);
  76. qDebug() << "-------------retUser=" << retuser;
  77. }
  78. }
  79. ret = true;
  80. } catch (const std::exception &e) {
  81. // 捕获到std::exception类型的异常
  82. qDebug() << "Caught exception: " << e.what();
  83. }
  84. return ret;
  85. }