ProjectManager.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #include "ProjectManager.h"
  2. #include <dbService/DBServiceSet.h>
  3. #include <dbService/UserConfigService.h>
  4. #include <dbService/ProjectService.h>
  5. #include <QMetaEnum>
  6. #include <QDebug>
  7. int kDemoProjId1 = 113;
  8. int kDemoProjId2 = 999;
  9. QString ProjectManager::nameOfIndexType(ProjectManager::IndexType t)
  10. {
  11. switch (t) {
  12. case AbilityIndex:
  13. return "能力重要度评估";
  14. case TechIndex:
  15. return "技术措施重要度评估";
  16. case OptimalIndex:
  17. return "方案优选评估";
  18. case EfficiencyIndex:
  19. return "综合效能评估";
  20. }
  21. }
  22. QString ProjectManager::nameOfEvalType(ProjectManager::EvalType t)
  23. {
  24. switch (t) {
  25. case None:
  26. return "无";
  27. case DemandEval:
  28. return "需求分析评估";
  29. case OptimalEval:
  30. return "方案优选评估";
  31. case EfficiencyEval:
  32. return "综合效能评估";
  33. }
  34. }
  35. QList<ProjectManager::IndexType> ProjectManager::indexListOfEvalTypes(EvalTypes types)
  36. {
  37. QList<IndexType> list;
  38. QMetaEnum metaEnum = QMetaEnum::fromType<IndexType>();
  39. for (int i = 0; i < metaEnum.keyCount(); i++) {
  40. IndexType t = IndexType(metaEnum.value(i));
  41. if ((types & t) == t) {
  42. list.append(t);
  43. }
  44. }
  45. return list;
  46. }
  47. ProjectManager::EvalTypes ProjectManager::evalTypes(ProjectInfo proj)
  48. {
  49. int t = proj.estimateType.toInt();
  50. EvalTypes types = EvalTypes(t);
  51. return types;
  52. }
  53. QList<ProjectManager::EvalType> ProjectManager::evalTypeList(EvalTypes types)
  54. {
  55. QList<ProjectManager::EvalType> list;
  56. QMetaEnum metaEnum = QMetaEnum::fromType<EvalType>();
  57. for (int i = 0; i < metaEnum.keyCount(); i++) {
  58. EvalType t = EvalType(metaEnum.value(i));
  59. if (t != None && (types & t) == t) {
  60. list.append(t);
  61. }
  62. }
  63. return list;
  64. }
  65. QList<ProjectManager::EvalType> ProjectManager::evalTypeList(ProjectInfo proj)
  66. {
  67. EvalTypes types = evalTypes(proj);
  68. QList<ProjectManager::EvalType> list = evalTypeList(types);
  69. return list;
  70. }
  71. QList<ProjectManager::IndexType> ProjectManager::indexList(ProjectInfo proj)
  72. {
  73. return indexListOfEvalTypes(evalTypes(proj));
  74. }
  75. int ProjectManager::queryProjects(QList<ProjectInfo *> *projList)
  76. {
  77. bool ret = ProjectService().QueryAll(projList);
  78. return ret ? QF_CODE_SUCCEEDED : QF_CODE_DATA_ERROR;
  79. }
  80. int ProjectManager::queryProjects(QList<ProjectInfo *> *list, int &total, int page, int pageSize, QString name)
  81. {
  82. qDebug() << __FUNCTION__ << __LINE__ << "page:" << page << "pagesize:" << pageSize << "name:" << name << endl;
  83. bool ret = ProjectService().SelectAllByPage(list, total, page, pageSize, name);
  84. return ret ? QF_CODE_SUCCEEDED : QF_CODE_DATA_ERROR;
  85. }
  86. int ProjectManager::verifyProjectInfo(ProjectInfo proj)
  87. {
  88. if (proj.taskName.isEmpty() || proj.estimateObjective.isEmpty() || proj.estimateDept.isEmpty()
  89. || proj.estimatePerson.isEmpty() || proj.positionalTitles.isEmpty() || proj.remark.isEmpty()) {
  90. return QF_CODE_NEED_PROJ_SUMMARY;
  91. }
  92. if (proj.projectName.isEmpty()) {
  93. return QF_CODE_NEED_PROJ_NAME;
  94. }
  95. if (proj.estimateType.isEmpty()) {
  96. return QF_CODE_NEED_PROJ_TYPE;
  97. }
  98. return QF_CODE_SUCCEEDED;
  99. }
  100. int ProjectManager::insertProject(ProjectInfo &proj)
  101. {
  102. int code = verifyProjectInfo(proj);
  103. if (code == QF_CODE_SUCCEEDED) {
  104. int id = ProjectService().AddProjectInfo(proj);
  105. qDebug() << __FUNCTION__ << __LINE__ << "id:" << id;
  106. if (id == -1) {
  107. code = QF_CODE_PROJ_CREATE_FALIED;
  108. }
  109. }
  110. return code;
  111. }
  112. int ProjectManager::updateProject(ProjectInfo &proj)
  113. {
  114. if (proj.estimateType.isEmpty()) {
  115. return QF_CODE_PROJ_NOT_EDITABLE;
  116. }
  117. int code = verifyProjectInfo(proj);
  118. if (code == QF_CODE_SUCCEEDED) {
  119. bool ret = ProjectService().UpdateProjectInfo(proj);
  120. qDebug() << __FUNCTION__ << __LINE__ << "ret:" << ret;
  121. if (ret == false) {
  122. code = QF_CODE_PROJ_UPDATE_FALIED;
  123. }
  124. }
  125. return code;
  126. }
  127. int ProjectManager::deleteProject(int id)
  128. {
  129. bool ret = ProjectService().DeleteById(id);
  130. qDebug() << __FUNCTION__ << __LINE__ << "id:" << id << "ret:" << ret;
  131. return ret ? QF_CODE_SUCCEEDED : QF_CODE_PROJ_DELETE_FALIED;
  132. }