weapp_subp_controller.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. 'use strict';
  2. /**
  3. * weapp控制器
  4. *
  5. * @author Lan
  6. * @date 2025/12/22
  7. * @version
  8. */
  9. module.exports = app => {
  10. class WeappSubpController extends app.BaseController {
  11. async subProjectList(ctx) {
  12. try {
  13. const list = await ctx.service.subProject.getSubProject(ctx.project.id, ctx.projectAccount.id, ctx.projectAccount.is_admin);
  14. ctx.body = {
  15. code: 0, msg: '', data: {
  16. list,
  17. },
  18. };
  19. } catch (error) {
  20. this.log(error);
  21. ctx.body = { code: -1, msg: '', data: null };
  22. }
  23. }
  24. async subProjectDetail(ctx) {
  25. try {
  26. const { id: subProjectId } = ctx.query;
  27. if (!subProjectId) {
  28. ctx.body = { code: -1, msg: '子项目ID不能为空', data: null };
  29. return;
  30. }
  31. const subProject = await ctx.service.subProject.getDataById(subProjectId);
  32. if (!subProject) {
  33. ctx.body = { code: -1, msg: '子项目不存在', data: null };
  34. return;
  35. }
  36. const pageShow = subProject.page_show ? JSON.parse(subProject.page_show) : {};
  37. const auditList = [];
  38. // 获取待审批的计量期列表
  39. const auditStages = await ctx.service.stageAudit.getAuditStageByWap(ctx.projectAccount.id, subProjectId);
  40. auditList.push(...(auditStages.map(item => ({ ...item, type: 'stage', subType: 'stage' }))));
  41. // 获取待审批的变更期
  42. const auditChanges = await ctx.service.changeAudit.getAuditChangeByWap(ctx.projectAccount.id, subProjectId);
  43. auditList.push(...(auditChanges.map(item => ({ ...item, type: 'change', subType: 'change' }))));
  44. // 获取待审批的变更立项
  45. if (pageShow.openChangeProject) {
  46. const changeProjects = await ctx.service.changeProjectAudit.getAuditChangeProjectByWap(ctx.projectAccount.id, subProjectId);
  47. auditList.push(...(changeProjects.map(item => ({ ...item, type: 'change', subType: 'changeProject' }))));
  48. }
  49. // 获取待审批的变更申请
  50. if (pageShow.openChangeApply) {
  51. const changeApplys = await ctx.service.changeApplyAudit.getAuditChangeApplyByWap(ctx.projectAccount.id, subProjectId);
  52. auditList.push(...(changeApplys.map(item => ({ ...item, type: 'change', subType: 'changeApply' }))));
  53. }
  54. // 获取待审批的变更方案
  55. if (pageShow.openChangePlan) {
  56. const changePlans = await ctx.service.changePlanAudit.getAuditChangePlanByWap(ctx.projectAccount.id, subProjectId);
  57. auditList.push(...(changePlans.map(item => ({ ...item, type: 'change', subType: 'changePlan' }))));
  58. }
  59. // 获取待审批的台账修订
  60. const ledgerRevises = await ctx.service.reviseAudit.getAuditReviseByWap(ctx.projectAccount.id, subProjectId);
  61. auditList.push(...(ledgerRevises.map(item => ({ ...item, type: 'revise', subType: 'revise' }))));
  62. // 获取待审批的预付款
  63. const auditAdvance = await ctx.service.advanceAudit.getAuditAdvanceByWap(ctx.projectAccount.id, subProjectId);
  64. auditList.push(...(auditAdvance.map(item => ({ ...item, type: 'advance', subType: 'advance' }))));
  65. // 获取待审批的材料调差
  66. if (pageShow.openMaterial) {
  67. const materialList = await ctx.service.materialAudit.getAuditMaterialByWap(ctx.projectAccount.id, subProjectId);
  68. auditList.push(...(materialList.map(item => ({ ...item, type: 'material', subType: 'material' }))));
  69. }
  70. // 获取待审批的质量巡检单
  71. if (pageShow.qualityInspection) {
  72. const qualityInspectionList = await ctx.service.qualityInspectionAudit.getAuditInspectionByWap(ctx.projectAccount.id, subProjectId);
  73. auditList.push(...(qualityInspectionList.map(item => ({ ...item, type: 'qualityInspection', subType: 'qualityInspection' }))));
  74. }
  75. // 获取待审批的安全巡检
  76. if (pageShow.safeInspection) {
  77. const safeInspectionList = await ctx.service.safeInspectionAudit.getAuditInspectionByWap(ctx.projectAccount.id, subProjectId);
  78. auditList.push(...(safeInspectionList.map(item => ({ ...item, type: 'safeInspection', subType: 'safeInspection' }))));
  79. }
  80. // 按照审批时间倒序排序
  81. auditList.sort((a, b) => new Date(b.begin_time).getTime() - new Date(a.begin_time).getTime());
  82. // 获取消息列表
  83. const msgList = await ctx.service.message.getMsgList(ctx.project.id, subProjectId, 1);
  84. ctx.body = {
  85. code: 0, msg: '', data: {
  86. auditList,
  87. msgList,
  88. },
  89. };
  90. } catch (error) {
  91. this.log(error);
  92. ctx.body = { code: -1, msg: '', data: null };
  93. }
  94. }
  95. }
  96. return WeappSubpController;
  97. };