ProjectManager.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. QString ProjectManager::reportNameOfEvalType(ProjectManager::EvalType t)
  34. {
  35. switch (t) {
  36. case None:
  37. return "无";
  38. case DemandEval:
  39. return "需求分析评估报告";
  40. case OptimalEval:
  41. return "方案优选评估报告";
  42. case EfficiencyEval:
  43. return "效能分析评估报告";
  44. }
  45. }
  46. QList<ProjectManager::IndexType> ProjectManager::indexListOfEvalTypes(EvalTypes types)
  47. {
  48. QList<IndexType> list;
  49. QMetaEnum metaEnum = QMetaEnum::fromType<IndexType>();
  50. for (int i = 0; i < metaEnum.keyCount(); i++) {
  51. IndexType t = IndexType(metaEnum.value(i));
  52. if ((types & t) == t) {
  53. list.append(t);
  54. }
  55. }
  56. return list;
  57. }
  58. ProjectManager::EvalTypes ProjectManager::evalTypes(ProjectInfo proj)
  59. {
  60. int t = proj.estimateType.toInt();
  61. EvalTypes types = EvalTypes(t);
  62. return types;
  63. }
  64. QList<ProjectManager::EvalType> ProjectManager::evalTypeList(EvalTypes types)
  65. {
  66. QList<ProjectManager::EvalType> list;
  67. QMetaEnum metaEnum = QMetaEnum::fromType<EvalType>();
  68. for (int i = 0; i < metaEnum.keyCount(); i++) {
  69. EvalType t = EvalType(metaEnum.value(i));
  70. if (t != None && (types & t) == t) {
  71. list.append(t);
  72. }
  73. }
  74. return list;
  75. }
  76. QList<ProjectManager::EvalType> ProjectManager::evalTypeList(ProjectInfo proj)
  77. {
  78. EvalTypes types = evalTypes(proj);
  79. QList<ProjectManager::EvalType> list = evalTypeList(types);
  80. return list;
  81. }
  82. QList<ProjectManager::IndexType> ProjectManager::indexList(ProjectInfo proj)
  83. {
  84. return indexListOfEvalTypes(evalTypes(proj));
  85. }
  86. int ProjectManager::evalTypeOfIndexType(int type)
  87. {
  88. EvalType e = None;
  89. QMetaEnum metaEnum = QMetaEnum::fromType<EvalType>();
  90. for (int i = 0; i < metaEnum.keyCount(); i++) {
  91. EvalType t = EvalType(metaEnum.value(i));
  92. if ((type & t) == type) {
  93. e = t;
  94. }
  95. }
  96. return e;
  97. }
  98. int ProjectManager::queryProjects(QList<ProjectInfo *> *projList)
  99. {
  100. bool ret = ProjectService().QueryAll(projList);
  101. return ret ? QF_CODE_SUCCEEDED : QF_CODE_DATA_ERROR;
  102. }
  103. int ProjectManager::queryProjects(QList<ProjectInfo *> *list, int &total, int page, int pageSize, QString name)
  104. {
  105. qDebug() << __FUNCTION__ << __LINE__ << "page:" << page << "pagesize:" << pageSize << "name:" << name << endl;
  106. bool ret = ProjectService().SelectAllByPage(list, total, page, pageSize, name);
  107. return ret ? QF_CODE_SUCCEEDED : QF_CODE_DATA_ERROR;
  108. }
  109. int ProjectManager::verifyProjectInfo(ProjectInfo proj)
  110. {
  111. if (proj.taskName.isEmpty() || proj.estimateObjective.isEmpty() || proj.estimateDept.isEmpty()
  112. || proj.estimatePerson.isEmpty() || proj.positionalTitles.isEmpty() || proj.remark.isEmpty()) {
  113. return QF_CODE_NEED_PROJ_SUMMARY;
  114. }
  115. if (proj.projectName.isEmpty()) {
  116. return QF_CODE_NEED_PROJ_NAME;
  117. }
  118. if (proj.estimateType.isEmpty()) {
  119. return QF_CODE_NEED_PROJ_TYPE;
  120. }
  121. return QF_CODE_SUCCEEDED;
  122. }
  123. int ProjectManager::insertProject(ProjectInfo &proj)
  124. {
  125. int code = verifyProjectInfo(proj);
  126. if (code == QF_CODE_SUCCEEDED) {
  127. int id = ProjectService().AddProjectInfo(proj);
  128. qDebug() << __FUNCTION__ << __LINE__ << "id:" << id;
  129. if (id == -1) {
  130. code = QF_CODE_PROJ_CREATE_FALIED;
  131. }
  132. }
  133. return code;
  134. }
  135. int ProjectManager::updateProject(ProjectInfo &proj)
  136. {
  137. if (proj.estimateType.isEmpty()) {
  138. return QF_CODE_PROJ_NOT_EDITABLE;
  139. }
  140. int code = verifyProjectInfo(proj);
  141. if (code == QF_CODE_SUCCEEDED) {
  142. bool ret = ProjectService().UpdateProjectInfo(proj);
  143. qDebug() << __FUNCTION__ << __LINE__ << "ret:" << ret;
  144. if (ret == false) {
  145. code = QF_CODE_PROJ_UPDATE_FALIED;
  146. }
  147. }
  148. return code;
  149. }
  150. int ProjectManager::deleteProject(int id)
  151. {
  152. bool ret = ProjectService().DeleteById(id);
  153. qDebug() << __FUNCTION__ << __LINE__ << "id:" << id << "ret:" << ret;
  154. return ret ? QF_CODE_SUCCEEDED : QF_CODE_PROJ_DELETE_FALIED;
  155. }