ImportDataUtil.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 "SchemePlanManager.h"
  9. #include "dbService/SchemeProcessService.h"
  10. #include "CNode.h"
  11. ImportDataUtil::ImportDataUtil() { }
  12. bool ImportDataUtil::importSystemData()
  13. {
  14. bool ret = false;
  15. try {
  16. // TODO 解析exportData数据
  17. QSettings exportData("exportData.ini", QSettings::IniFormat);
  18. exportData.setIniCodec("UTF-8");
  19. QString projectInfo = exportData.value("EXPORTDATA/projectInfo", "").toString();
  20. QString nodeDate = exportData.value("EXPORTDATA/nodeDate", "").toString();
  21. QString userInfo = exportData.value("EXPORTDATA/userInfo", "").toString();
  22. QString schemeProcess = exportData.value("EXPORTDATA/schemeProcess", "").toString();
  23. //清除表相关数据
  24. ProjectService().DeleteAll();
  25. CNodeDataService().DeleteAllNodeData();
  26. UserService().DeleteAllUser();
  27. SchemeProcessService().DeleteAll();
  28. //插入工程
  29. QStringList proList = projectInfo.split(",");
  30. ProjectInfo proj;
  31. proj.id = proList[0].toInt();
  32. proj.projectName = proList[1];
  33. proj.remark = proList[2];
  34. proj.taskName = proList[3];
  35. proj.estimateTime = proList[4];
  36. proj.estimateObjective = proList[5];
  37. proj.estimateDept = proList[6];
  38. proj.estimatePerson = proList[7];
  39. proj.estimateType = proList[8];
  40. proj.positionalTitles = proList[9];
  41. proj.createTime = proList[10];
  42. bool ret = ProjectService().SaveProjectInfo(proj);
  43. //保存节点信息系
  44. QStringList nodeList = nodeDate.split(";");
  45. for (int i = 0; i < nodeList.size(); i++) {
  46. CNodeData nodeData;
  47. QStringList nodeDataList = nodeList[i].split(",");
  48. if (nodeDataList.size() > 1) {
  49. nodeData.id = nodeDataList[0].toInt();
  50. nodeData.projectId = nodeDataList[1].toInt();
  51. nodeData.indexType = nodeDataList[2].toInt();
  52. nodeData.number = nodeDataList[3].toInt();
  53. nodeData.pNumber = nodeDataList[4].toInt();
  54. nodeData.name = nodeDataList[5];
  55. nodeData.remark = nodeDataList[6];
  56. nodeData.dimension = nodeDataList[7];
  57. nodeData.type = nodeDataList[8].toInt();
  58. nodeData.isEffective = nodeDataList[9].toInt();
  59. CNodeDataService().SaveCNodeData(nodeData);
  60. }
  61. }
  62. //保存用户信息
  63. QStringList userList = userInfo.split(";");
  64. for (int i = 0; i < userList.size(); i++) {
  65. QFUser user;
  66. QStringList userInfoList = userList[i].split(",");
  67. if (userInfoList.size() > 1) {
  68. user.id = userInfoList[0].toInt();
  69. user.userName = userInfoList[1];
  70. user.userNo = userInfoList[2];
  71. user.password = userInfoList[3];
  72. user.role = static_cast<QFUser::Role>(userInfoList[4].toInt());
  73. user.post = userInfoList[5];
  74. user.major = userInfoList[6];
  75. user.workPosition = userInfoList[7];
  76. user.educationDegree = userInfoList[8];
  77. user.phone = userInfoList[9];
  78. user.remark = userInfoList[10];
  79. user.projectId = userInfoList[11];
  80. user.writeTime = userInfoList[12];
  81. user.projectId = userInfoList[13];
  82. int retuser = UserService().AddUserInfo(user);
  83. // qDebug() << "-------------retUser=" << retuser;
  84. }
  85. }
  86. //保存流程信息
  87. QStringList schemeProcessList = schemeProcess.split(";");
  88. for (int i = 0; i < schemeProcessList.size(); i++) {
  89. QStringList schemeList = schemeProcessList[i].split(",");
  90. if (schemeList.size() > 1) {
  91. SchemePlanManager::SchemeProcessInfo info;
  92. info.id = schemeList[0].toInt();
  93. info.projectId = schemeList[1].toInt();
  94. info.indexType = schemeList[2].toInt();
  95. info.step = schemeList[3].toInt();
  96. info.type = static_cast<SchemePlanManager::SchemeProcessType>(schemeList[4].toInt());
  97. info.dSource = static_cast<SchemePlanManager::SchemeDataSource>(schemeList[5].toInt());
  98. info.algorithm = static_cast<SchemePlanManager::Algorithm>(schemeList[6].toInt());
  99. info.efficiencyGrades = schemeList[7].toInt();
  100. QVariant tempValue = schemeList[8];
  101. info.isChecked = tempValue.toBool();
  102. int retscheme = SchemeProcessService().SaveSchemeProcess(info);
  103. // qDebug() << "-------------retscheme=" << retscheme;
  104. }
  105. }
  106. ret = true;
  107. } catch (const std::exception &e) {
  108. // 捕获到std::exception类型的异常
  109. qDebug() << "Caught exception: " << e.what();
  110. }
  111. return ret;
  112. }