ProjectManager.cpp 4.2 KB

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