quality_controller.js 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  1. 'use strict';
  2. /**
  3. * 标段管理控制器
  4. *
  5. * @author Mai
  6. * @date 2025/7/17
  7. * @version
  8. */
  9. const auditConst = require('../const/audit');
  10. const qualityInspectionConst = require('../const/quality_inspection');
  11. const auditType = require('../const/audit').auditType;
  12. const shenpiConst = require('../const/shenpi');
  13. const codeRuleConst = require('../const/code_rule');
  14. const contractConst = require('../const/contract');
  15. const moment = require('moment');
  16. const sendToWormhole = require('stream-wormhole');
  17. const fs = require('fs');
  18. const path = require('path');
  19. const PermissionCheck = require('../const/account_permission').PermissionCheck;
  20. module.exports = app => {
  21. class QualityController extends app.BaseController {
  22. constructor(ctx) {
  23. super(ctx);
  24. ctx.showProject = true;
  25. // ctx.showTitle = true;
  26. }
  27. loadMenu(ctx) {
  28. super.loadMenu(ctx);
  29. // 虚拟menu,以保证标题显示正确
  30. ctx.menu = {
  31. name: '质量管理',
  32. display: false,
  33. caption: '质量管理',
  34. controller: 'quality',
  35. };
  36. }
  37. async tender(ctx) {
  38. try {
  39. if (!ctx.subProject.page_show.quality) throw '该功能已关闭';
  40. const renderData = {
  41. is_inspection: ctx.url.includes('inspection') ? 1 : 0,
  42. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.quality.tender),
  43. };
  44. const accountList = await ctx.service.projectAccount.getAllSubProjectAccount(ctx.subProject);
  45. renderData.accountList = accountList;
  46. const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: ctx.session.sessionProject.id } });
  47. const accountGroupList = unitList.map(item => {
  48. const groupList = accountList.filter(item1 => item1.company === item.name);
  49. return { groupName: item.name, groupList };
  50. }).filter(x => { return x.groupList.length > 0; });
  51. // const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: ctx.session.sessionProject.id } });
  52. // renderData.accountGroup = unitList.map(item => {
  53. // const groupList = accountList.filter(item1 => item1.company === item.name);
  54. // return { groupName: item.name, groupList };
  55. // });
  56. renderData.accountGroup = accountGroupList;
  57. renderData.accountInfo = await ctx.service.projectAccount.getDataById(ctx.session.sessionUser.accountId);
  58. renderData.tenderList = await ctx.service.tender.getSpecList(ctx.service.tenderPermission, 'quality', ctx.session.sessionUser.is_admin ? 'all' : '');
  59. renderData.categoryData = await this.ctx.service.category.getAllCategory(this.ctx.subProject);
  60. renderData.selfCategoryLevel = this.ctx.subProject.permission.self_category_level;
  61. renderData.permissionConst = ctx.service.tenderPermission.partPermissionConst('quality');
  62. renderData.permissionBlock = ctx.service.tenderPermission.partPermissionBlock('quality');
  63. await this.layout('quality/tender.ejs', renderData, 'quality/tender_modal.ejs');
  64. } catch (err) {
  65. ctx.log(err);
  66. ctx.postError(err, '无法查看质量管理数据');
  67. ctx.redirect(`/sp/${ctx.subProject.id}/dashboard`);
  68. }
  69. }
  70. async inspectionTender(ctx) {
  71. try {
  72. if (!ctx.subProject.page_show.qualityInspection) throw '该功能已关闭';
  73. const renderData = {
  74. is_inspection: ctx.url.includes('inspection') ? 1 : 0,
  75. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.quality.tender),
  76. };
  77. const accountList = await ctx.service.projectAccount.getAllSubProjectAccount(ctx.subProject);
  78. renderData.accountList = accountList;
  79. const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: ctx.session.sessionProject.id } });
  80. const accountGroupList = unitList.map(item => {
  81. const groupList = accountList.filter(item1 => item1.company === item.name);
  82. return { groupName: item.name, groupList };
  83. }).filter(x => { return x.groupList.length > 0; });
  84. // const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: ctx.session.sessionProject.id } });
  85. // renderData.accountGroup = unitList.map(item => {
  86. // const groupList = accountList.filter(item1 => item1.company === item.name);
  87. // return { groupName: item.name, groupList };
  88. // });
  89. renderData.accountGroup = accountGroupList;
  90. renderData.accountInfo = await ctx.service.projectAccount.getDataById(ctx.session.sessionUser.accountId);
  91. renderData.tenderList = await ctx.service.tender.getSpecList(ctx.service.tenderPermission, 'inspection', ctx.session.sessionUser.is_admin ? 'all' : '');
  92. renderData.categoryData = await this.ctx.service.category.getAllCategory(this.ctx.subProject);
  93. renderData.selfCategoryLevel = this.ctx.subProject.permission.self_category_level;
  94. renderData.permissionConst = ctx.service.tenderPermission.partPermissionConst('inspection');
  95. renderData.permissionBlock = ctx.service.tenderPermission.partPermissionBlock('inspection');
  96. await this.layout('quality/tender.ejs', renderData, 'quality/tender_modal.ejs');
  97. } catch (err) {
  98. ctx.log(err);
  99. ctx.postError(err, '无法查看质量巡检数据');
  100. ctx.redirect(`/sp/${ctx.subProject.id}/dashboard`);
  101. }
  102. }
  103. async member(ctx) {
  104. try {
  105. const data = JSON.parse(ctx.request.body.data);
  106. const result = await ctx.service.tenderPermission.getPartsPermission(data.tid, data.parts);
  107. ctx.body = { err: 0, msg: '', data: result };
  108. } catch (err) {
  109. ctx.log(err);
  110. ctx.ajaxErrorBody(err, '查询标段权限错误');
  111. }
  112. }
  113. async memberSave(ctx) {
  114. try {
  115. const data = JSON.parse(ctx.request.body.data);
  116. await ctx.service.tenderPermission.savePermission(data.tid, data.member, data.permissionBlock);
  117. ctx.body = { err: 0, msg: '', data: '' };
  118. } catch (err) {
  119. ctx.log(err);
  120. ctx.ajaxErrorBody(err, '保存标段权限错误');
  121. }
  122. }
  123. async auditSave(ctx) {
  124. try {
  125. if (ctx.session.sessionUser.is_admin === 0) throw '没有设置权限';
  126. const tid = parseInt(ctx.params.tid);
  127. const responseData = {
  128. err: 0, msg: '', data: null,
  129. };
  130. const tenderInfo = await ctx.service.tender.getDataById(tid);
  131. if (!tenderInfo) throw '标段不存在';
  132. const data = JSON.parse(ctx.request.body.data);
  133. if (!data.type) {
  134. throw '提交数据错误';
  135. }
  136. let uids;
  137. let auditList = [];
  138. const tenderPermissionKeys = ['quality', 'inspection', 'safe_inspection', 'safe_payment', 'schedule'];
  139. const tPsKeys = {
  140. quality: ['quality', 'inspection'],
  141. safe: ['safe_inspection', 'safe_payment'],
  142. };
  143. switch (data.type) {
  144. case 'add-audit':
  145. if (!data.key || (!tenderPermissionKeys.includes(data.key) && !Object.keys(tPsKeys).includes(data.key))) throw '参数有误';
  146. // // 判断用户是单个还是数组
  147. uids = data.id instanceof Array ? data.id : [data.id];
  148. // // 判断该用户的组是否已加入到表中,已加入则提示无需添加
  149. const insertKeys = data.together ? tPsKeys[data.key] : [data.key];
  150. auditList = await ctx.service.tenderPermission.getPartsPermission(tenderInfo.id, insertKeys);
  151. const addAidList = ctx.helper._.difference(uids, ctx.helper._.map(auditList, 'uid'));
  152. if (addAidList.length === 0) {
  153. throw '用户已存在成员管理中,无需重复添加';
  154. }
  155. const accountList = await ctx.service.projectAccount.getAllDataByCondition({ where: { id: addAidList } });
  156. const insert_members = [];
  157. for (const account of accountList) {
  158. const insert_member = { uid: account.id };
  159. for (const key of insertKeys) {
  160. insert_member[key] = ['1'];
  161. }
  162. insert_members.push(insert_member);
  163. }
  164. await ctx.service.tenderPermission.saveOnePermission(tenderInfo.id, ctx.helper._.map(accountList, 'id'), insert_members, insertKeys);
  165. responseData.data = await ctx.service.tenderPermission.getPartsPermission(tenderInfo.id, insertKeys);
  166. break;
  167. case 'del-audit':
  168. if (!data.key || (!tenderPermissionKeys.includes(data.key) && !Object.keys(tPsKeys).includes(data.key))) throw '参数有误';
  169. uids = data.id instanceof Array ? data.id : [data.id];
  170. if (uids.length === 0) throw '没有选择要移除的用户';
  171. const deleteKeys = data.together ? tPsKeys[data.key] : [data.key];
  172. auditList = await ctx.service.tenderPermission.getPartsPermission(tenderInfo.id, deleteKeys);
  173. // 判断uids和auditList中是否有相同的uid
  174. const commonUids = ctx.helper._.intersection(uids, ctx.helper._.map(auditList, 'uid'));
  175. if (commonUids.length === 0) {
  176. throw '该用户已不在成员管理中,移除失败';
  177. }
  178. const del_members = [];
  179. for (const uid of uids) {
  180. const del_member = { uid };
  181. for (const key of deleteKeys) {
  182. del_member[key] = [];
  183. }
  184. del_members.push(del_member);
  185. }
  186. await ctx.service.tenderPermission.saveOnePermission(tenderInfo.id, uids, del_members, deleteKeys);
  187. responseData.data = await ctx.service.tenderPermission.getPartsPermission(tenderInfo.id, deleteKeys);
  188. break;
  189. case 'save-permission':
  190. if (!data.key || !tenderPermissionKeys.includes(data.key)) throw '参数有误';
  191. uids = data.uid instanceof Array ? data.uid : [data.uid];
  192. await ctx.service.tenderPermission.saveOnePermission(tenderInfo.id, uids, data.members, [data.key]);
  193. break;
  194. case 'list':
  195. if (!data.key || !tenderPermissionKeys.includes(data.key)) throw '参数有误';
  196. responseData.data = await ctx.service.tenderPermission.getPartsPermission(tenderInfo.id, [data.key]);
  197. break;
  198. default: throw '参数有误';
  199. }
  200. ctx.body = responseData;
  201. } catch (err) {
  202. this.log(err);
  203. ctx.body = { err: 1, msg: err.toString(), data: null };
  204. }
  205. }
  206. async info(ctx) {
  207. try {
  208. if (!ctx.subProject.page_show.quality) throw '该功能已关闭';
  209. const renderData = {
  210. thirdParty: {
  211. gxby: ctx.session.sessionProject.gxby_status,
  212. dagl: ctx.session.sessionProject.dagl_status,
  213. },
  214. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.quality.info),
  215. };
  216. await this.layout('quality/info.ejs', renderData, 'quality/info_modal.ejs');
  217. } catch (err) {
  218. ctx.log(err);
  219. ctx.postError(err, '无法查看质量管理数据');
  220. ctx.redirect(`/sp/${ctx.subProject.id}/quality`);
  221. }
  222. }
  223. async flaw(ctx) {
  224. try {
  225. if (!ctx.subProject.page_show.quality) throw '该功能已关闭';
  226. const renderData = {
  227. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.quality.flaw),
  228. };
  229. await this.layout('quality/flaw.ejs', renderData, 'quality/flaw_modal.ejs');
  230. } catch (err) {
  231. ctx.log(err);
  232. ctx.postError(err, '无法查看质量管理数据');
  233. ctx.redirect(`/sp/${ctx.subProject.id}/quality`);
  234. }
  235. }
  236. async lab(ctx) {
  237. try {
  238. if (!ctx.subProject.page_show.quality) throw '该功能已关闭';
  239. const renderData = {
  240. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.quality.lab),
  241. };
  242. await this.layout('quality/lab.ejs', renderData, 'quality/lab_modal.ejs');
  243. } catch (err) {
  244. ctx.log(err);
  245. ctx.postError(err, '无法查看质量管理数据');
  246. ctx.redirect(`/sp/${ctx.subProject.id}/quality`);
  247. }
  248. }
  249. async _loadXmjData(spec) {
  250. const xmj = await this.ctx.service.ledger.getAllDataByCondition({
  251. where: { tender_id: this.ctx.tender.id },
  252. columns: ['id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf', 'code', 'b_code', 'name'],
  253. });
  254. // const quality = spec && spec.loadStatus ? await this.ctx.service.quality.getAllDataByCondition({
  255. // where: { tid: this.ctx.tender.id, rela_type: 'xmj' },
  256. // columns: ['rela_id', 'gxby_status', 'gxby_date', 'dagl_status'],
  257. // }) : [];
  258. // this.ctx.helper.assignRelaData(xmj, [
  259. // { data: quality, fields: ['gxby_status', 'gxby_date', 'dagl_status'], prefix: '', relaId: 'rela_id' },
  260. // ]);
  261. return xmj; // .filter(x => { return !x.b_code; });
  262. }
  263. async _loadPosData(condition, spec) {
  264. const pos = await this.ctx.service.pos.getAllDataByCondition({
  265. where: condition,
  266. columns: ['id', 'tid', 'lid', 'name'],
  267. orders: [['porder', 'ASC']],
  268. });
  269. // const quality = spec && spec.loadStatus ? await this.ctx.service.quality.getAllDataByCondition({
  270. // where: { tid: this.ctx.tender.id, rela_type: 'pos' },
  271. // columns: ['rela_id', 'gxby_status', 'gxby_date', 'dagl_status'],
  272. // }) : [];
  273. // this.ctx.helper.assignRelaData(pos, [
  274. // { data: quality, fields: ['gxby_status', 'gxby_date', 'dagl_status'], prefix: '', relaId: 'rela_id' },
  275. // ]);
  276. return pos;
  277. }
  278. async _loadDetailData(rela_type, rela_id, rela_name) {
  279. const result = await this.ctx.service.quality.getDataByCondition({ tid: this.ctx.tender.id, rela_type, rela_id, rela_name });
  280. if (!result) return result;
  281. await this.ctx.service.quality.loadQualityDetail(result);
  282. await this.ctx.service.quality.checkQualityStatusAndSave(result);
  283. return result;
  284. }
  285. async _loadData(type, data, result) {
  286. if (result[type]) return result[type];
  287. switch (type) {
  288. case 'xmj':
  289. return this._loadXmjData(data.spec);
  290. case 'pos':
  291. return this._loadPosData({ tid: this.ctx.tender.id }, data.spec);
  292. case 'detail':
  293. if (!data.rela_id && !data.rela_type) throw '缺少参数';
  294. return this._loadDetailData(data.rela_type, data.rela_id, data.rela_name);
  295. case 'quality':
  296. return await this.ctx.service.quality.getAllDataByCondition({ where: { tid: this.ctx.tender.id } });
  297. case 'lab':
  298. return await this.ctx.service.qualityLab.getAllDataByCondition({ where: { tid: this.ctx.tender.id } });
  299. default: throw '未知数据类型';
  300. }
  301. }
  302. async _load(data) {
  303. if (!data.filter) throw '参数错误';
  304. const filter = data.filter.split(';');
  305. const result = {};
  306. for (const f of filter) {
  307. result[f] = await this._loadData(f, data, result);
  308. }
  309. return result;
  310. }
  311. async load(ctx) {
  312. try {
  313. const data = JSON.parse(ctx.request.body.data);
  314. const result = await this._load(data);
  315. ctx.body = { err: 0, msg: '', data: result };
  316. } catch (err) {
  317. ctx.log(err);
  318. ctx.ajaxErrorBody(err, '获取数据错误');
  319. }
  320. }
  321. async _saveKaigong(ctx, data) {
  322. if (data.add) {
  323. if (!ctx.permission.quality.add) throw '您无权新增开工';
  324. await ctx.service.quality.kaigong(data, data.add.name, data.add.date);
  325. } else if (data.update) {
  326. await ctx.service.quality.kaigong(data, data.update.name, data.update.date);
  327. } else if (data.del) {
  328. await ctx.service.quality.delKaigong(data);
  329. }
  330. }
  331. async _saveGongxu(ctx, data) {
  332. if (data.add) {
  333. if (!ctx.permission.quality.add) throw '您无权新增工序';
  334. await ctx.service.qualityGongxu.add(data, data.add.name);
  335. } else if (data.update) {
  336. await ctx.service.qualityGongxu.update(data.update.id, data.update.name);
  337. } else if (data.del) {
  338. await ctx.service.qualityGongxu.del(data.del);
  339. }
  340. }
  341. async _saveYinbi(ctx, data) {
  342. if (data.add) {
  343. if (!ctx.permission.quality.add) throw '您无权新增隐蔽工程';
  344. await ctx.service.qualityYinbi.add(data, data.add);
  345. } else if (data.update) {
  346. await ctx.service.qualityYinbi.update(data.update.id, data.update);
  347. } else if (data.del) {
  348. await ctx.service.qualityYinbi.del(data.del);
  349. }
  350. }
  351. async save(ctx) {
  352. try {
  353. const data = JSON.parse(ctx.request.body.data);
  354. if (!data.quality_id && (!data.rela_type && !data.rela_id)) throw '参数错误';
  355. switch (ctx.params.type) {
  356. case 'kaigong':
  357. await this._saveKaigong(ctx, data);
  358. break;
  359. case 'gongxu':
  360. await this._saveGongxu(ctx, data);
  361. break;
  362. case 'yinbi':
  363. await this._saveYinbi(ctx, data);
  364. break;
  365. default: throw '请求错误';
  366. }
  367. const quality = await this._loadDetailData(data.rela_type, data.rela_id, data.rela_name);
  368. ctx.body = { err: 0, msg: '', data: quality };
  369. } catch (err) {
  370. ctx.log(err);
  371. ctx.ajaxErrorBody(err, '保存数据错误');
  372. }
  373. }
  374. async checkCanUpload(ctx) {
  375. if (!ctx.permission.quality.upload) {
  376. throw '您无权上传、删除文件';
  377. }
  378. }
  379. async uploadFile(ctx) {
  380. let stream;
  381. try {
  382. await this.checkCanUpload(ctx);
  383. const parts = ctx.multipart({ autoFields: true });
  384. let index = 0;
  385. const create_time = Date.parse(new Date()) / 1000;
  386. let stream = await parts();
  387. const user = await ctx.service.projectAccount.getDataById(ctx.session.sessionUser.accountId);
  388. const quality = await ctx.service.quality.getDataById(parts.field.quality_id);
  389. if (!quality) throw '工程未开工';
  390. const blockType = parts.field.block_type;
  391. const blockId = parts.field.block_id || '';
  392. const specType = parts.field.spec_type || '';
  393. if (!blockType) throw '参数错误';
  394. const uploadfiles = [];
  395. while (stream !== undefined) {
  396. if (!stream.filename) throw '未发现上传文件!';
  397. const fileInfo = path.parse(stream.filename);
  398. const filepath = `${ctx.session.sessionProject.id}/${ctx.tender.id}/quality/${blockType}/${ctx.moment().format('YYYYMMDD')}/${create_time + '_' + index + fileInfo.ext}`;
  399. // 保存文件
  400. await ctx.fujianOss.put(ctx.fujianOssPath + filepath, stream);
  401. await sendToWormhole(stream);
  402. // 插入到stage_pay对应的附件列表中
  403. uploadfiles.push({
  404. filename: fileInfo.name,
  405. fileext: fileInfo.ext,
  406. filesize: Array.isArray(parts.field.size) ? parts.field.size[index] : parts.field.size,
  407. filepath,
  408. });
  409. ++index;
  410. if (Array.isArray(parts.field.size) && index < parts.field.size.length) {
  411. stream = await parts();
  412. } else {
  413. stream = undefined;
  414. }
  415. }
  416. const result = await ctx.service.qualityFile.addFiles(user, quality, uploadfiles, blockType, blockId, specType);
  417. ctx.body = { err: 0, msg: '', data: result };
  418. } catch (error) {
  419. ctx.log(error);
  420. // 失败需要消耗掉stream 以防卡死
  421. if (stream) await sendToWormhole(stream);
  422. ctx.body = this.ajaxErrorBody(error, '上传附件失败,请重试');
  423. }
  424. }
  425. async delFile(ctx) {
  426. try {
  427. const data = JSON.parse(ctx.request.body.data);
  428. if (!data.del) throw '缺少参数';
  429. const result = await ctx.service.qualityFile.delFiles(data.del);
  430. ctx.body = { err: 0, msg: '', data: result };
  431. } catch (error) {
  432. this.log(error);
  433. ctx.ajaxErrorBody(error, '删除附件失败');
  434. }
  435. }
  436. async saveFile(ctx) {
  437. try {
  438. const data = JSON.parse(ctx.request.body.data);
  439. if (!data.id) throw '缺少参数';
  440. const result = await ctx.service.file.qualityFile(data.id, data.filename);
  441. ctx.body = { err: 0, msg: '', data: result };
  442. } catch (error) {
  443. this.log(error);
  444. ctx.ajaxErrorBody(error, '编辑附件失败');
  445. }
  446. }
  447. async rule(ctx) {
  448. try {
  449. if (!ctx.subProject.page_show.quality) throw '该功能已关闭';
  450. const ruleGroups = await ctx.service.qualityRule.getRuleGroups(ctx.subProject.id);
  451. const tenderList = await ctx.service.tender.getAllDataByCondition({ where: { spid: ctx.subProject.id } });
  452. const renderData = {
  453. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.quality.rule),
  454. ruleGroups,
  455. thirdParty: {
  456. gxby: ctx.session.sessionProject.gxby_status,
  457. dagl: ctx.session.sessionProject.dagl_status,
  458. },
  459. tenderList,
  460. };
  461. await this.layout('quality/rule.ejs', renderData, 'quality/rule_modal.ejs');
  462. } catch (err) {
  463. ctx.log(err);
  464. ctx.postError(err, '无法查看质量管理数据');
  465. ctx.redirect(`/sp/${ctx.subProject.id}/quality`);
  466. }
  467. }
  468. async ruleSave(ctx) {
  469. try {
  470. if (!ctx.subProject.page_show.quality) throw '该功能已关闭';
  471. const data = JSON.parse(ctx.request.body.data);
  472. if (!data.group && !data.rule && !data.quality) throw '参数错误';
  473. if (data.group) {
  474. const result = await ctx.service.qualityRule.saveGroup(data.group);
  475. ctx.body = { err: 0, msg: '', data: result };
  476. } else if (data.rule) {
  477. const result = await ctx.service.qualityRule.saveRule(data.rule);
  478. ctx.body = { err: 0, msg: '', data: result };
  479. } else if (data.quality) {
  480. const result = await ctx.service.quality.saveQualityManage(this.ctx.tender.id, data.quality);
  481. ctx.body = { err: 0, msg: '', data: result };
  482. }
  483. } catch (err) {
  484. ctx.log(err);
  485. ctx.ajaxErrorBody(err, '保存状态推送规则错误');
  486. }
  487. }
  488. async _pushIncStatus(select) {
  489. // todo 向其他系统推送
  490. return await this.ctx.service.quality.pushIncStatus(select);
  491. }
  492. async _pushAllStatus(select) {
  493. // todo 向其他系统推送
  494. return await this.ctx.service.quality.pushAllStatus(select);
  495. }
  496. async pushStatus(ctx) {
  497. try {
  498. if (!ctx.subProject.page_show.quality) throw '该功能已关闭';
  499. const data = JSON.parse(ctx.request.body.data);
  500. if (!data.push_type) throw '参数错误';
  501. let count;
  502. switch (data.push_type) {
  503. case 'inc':
  504. count = await this._pushIncStatus(data.select);
  505. break;
  506. case 'all':
  507. count = await this._pushAllStatus();
  508. break;
  509. default: throw '参数错误';
  510. }
  511. ctx.body = { err: 0, msg: '', data: count };
  512. } catch (err) {
  513. ctx.log(err);
  514. ctx.ajaxErrorBody(err, '推送失败');
  515. }
  516. }
  517. async _forceRefreshStatus() {
  518. const qualities = await this.ctx.service.quality.getAllDataByCondition({ where: { tid: this.ctx.tender.id } });
  519. for (const q of qualities) {
  520. await this.ctx.service.quality.loadQualityDetail(q);
  521. await this.ctx.service.quality.checkQualityStatusAndSave(q);
  522. }
  523. }
  524. async force(ctx) {
  525. try {
  526. if (!ctx.subProject.page_show.quality) throw '该功能已关闭';
  527. const data = JSON.parse(ctx.request.body.data);
  528. if (!data.type) throw '参数错误';
  529. switch (data.type) {
  530. case 'all':
  531. await this._forceRefreshStatus();
  532. break;
  533. default: throw '参数错误';
  534. }
  535. const result = data.load ? this._load(data.load) : {};
  536. ctx.body = { err: 0, msg: '', data: result };
  537. } catch (err) {
  538. console.log(err);
  539. ctx.log(err);
  540. ctx.ajaxErrorBody(err, '操作失败');
  541. }
  542. }
  543. /**
  544. * 变更管理 页面 (Get)
  545. *
  546. * @param {Object} ctx - egg全局变量
  547. * @return {void}
  548. */
  549. async inspection(ctx) {
  550. try {
  551. if (!ctx.subProject.page_show.qualityInspection) throw '该功能已关闭';
  552. const status = parseInt(ctx.query.status) || 0;
  553. await this._filterInspection(ctx, status);
  554. } catch (err) {
  555. ctx.log(err);
  556. ctx.postError(err, '无法查看质量管理数据');
  557. ctx.redirect(`/sp/${ctx.subProject.id}/quality/tender`);
  558. }
  559. }
  560. // 质量巡检单功能
  561. async _filterInspection(ctx, status = 0) {
  562. try {
  563. ctx.session.sessionUser.tenderId = ctx.tender.id;
  564. const sorts = ctx.query.sort ? ctx.query.sort : 0;
  565. const orders = ctx.query.order ? ctx.query.order : 0;
  566. const filter = JSON.parse(JSON.stringify(qualityInspectionConst.filter));
  567. filter.count = [];
  568. filter.count[filter.status.pending] = await ctx.service.qualityInspection.getCountByStatus(ctx.tender.id, filter.status.pending);
  569. filter.count[filter.status.uncheck] = await ctx.service.qualityInspection.getCountByStatus(ctx.tender.id, filter.status.uncheck);
  570. filter.count[filter.status.checking] = await ctx.service.qualityInspection.getCountByStatus(ctx.tender.id, filter.status.checking);
  571. filter.count[filter.status.reply] = await ctx.service.qualityInspection.getCountByStatus(ctx.tender.id, filter.status.reply);
  572. filter.count[filter.status.rectification] = await ctx.service.qualityInspection.getCountByStatus(ctx.tender.id, filter.status.rectification);
  573. filter.count[filter.status.checked] = await ctx.service.qualityInspection.getCountByStatus(ctx.tender.id, filter.status.checked);
  574. filter.count[filter.status.checkStop] = await ctx.service.qualityInspection.getCountByStatus(ctx.tender.id, filter.status.checkStop);// await ctx.service.change.pendingDatas(tender.id, ctx.session.sessionUser.accountId);
  575. const inspectionList = await ctx.service.qualityInspection.getListByStatus(ctx.tender.id, status, 1, sorts, orders);
  576. const total = await ctx.service.qualityInspection.getCountByStatus(ctx.tender.id, status);
  577. const allAttList = inspectionList.length > 0 ? await ctx.service.qualityInspectionAtt.getAllAtt(ctx.tender.id, ctx.helper._.map(inspectionList, 'id')) : [];
  578. for (const c of inspectionList) {
  579. c.attList = ctx.helper._.filter(allAttList, { qiid: c.id });
  580. c.curAuditors = await ctx.service.qualityInspectionAudit.getAuditorsByStatus(c.id, c.status, c.times);
  581. if (c.status === auditConst.inspection.status.checkNoPre) {
  582. c.curAuditors2 = await ctx.service.qualityInspectionAudit.getAuditorsByStatus(c.id, auditConst.inspection.status.checking, c.times);
  583. }
  584. }
  585. // 分页相关
  586. const page = ctx.page;
  587. const pageSize = ctx.pageSize;
  588. const pageInfo = {
  589. page,
  590. pageSizeSelect: 1,
  591. pageSize,
  592. total_num: total,
  593. total: Math.ceil(total / pageSize),
  594. queryData: JSON.stringify(ctx.urlInfo.query),
  595. };
  596. let codeRule = [];
  597. let c_connector = '1';
  598. let c_rule_first = 1;
  599. const rule_type = 'inspection';
  600. const tender = await this.service.tender.getDataById(ctx.tender.id);
  601. if (tender.c_code_rules) {
  602. const c_code_rules = JSON.parse(tender.c_code_rules);
  603. codeRule = c_code_rules[rule_type + '_rule'] !== undefined ? c_code_rules[rule_type + '_rule'] : [];
  604. c_connector = c_code_rules[rule_type + '_connector'] !== undefined ? c_code_rules[rule_type + '_connector'] : '1';
  605. c_rule_first = c_code_rules[rule_type + '_rule_first'] !== undefined ? c_code_rules[rule_type + '_rule_first'] : 1;
  606. }
  607. for (const rule of codeRule) {
  608. switch (rule.rule_type) {
  609. case codeRuleConst.measure.ruleType.dealCode:
  610. rule.preview = ctx.tender.info.deal_info.dealCode;
  611. break;
  612. case codeRuleConst.measure.ruleType.tenderName:
  613. rule.preview = tender.name;
  614. break;
  615. case codeRuleConst.measure.ruleType.inDate:
  616. rule.preview = moment().format('YYYY');
  617. break;
  618. case codeRuleConst.measure.ruleType.text:
  619. rule.preview = rule.text;
  620. break;
  621. case codeRuleConst.measure.ruleType.addNo:
  622. const s = '0000000000';
  623. rule.preview = s.substr(s.length - rule.format);
  624. break;
  625. default: break;
  626. }
  627. }
  628. const renderData = {
  629. moment,
  630. tender,
  631. permission: ctx.permission.inspection,
  632. rule_type,
  633. codeRule,
  634. dealCode: ctx.tender.info.deal_info.dealCode,
  635. c_connector,
  636. c_rule_first,
  637. ruleType: codeRuleConst.ruleType[rule_type],
  638. ruleConst: codeRuleConst.measure,
  639. filter,
  640. inspectionList,
  641. auditType,
  642. auditConst: qualityInspectionConst,
  643. status,
  644. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.quality.inspection),
  645. pageInfo,
  646. };
  647. await this.layout('quality/inspection.ejs', renderData, 'quality/inspection_modal.ejs');
  648. } catch (err) {
  649. ctx.log(err);
  650. ctx.postError(err, '无法查看质量巡检数据');
  651. ctx.redirect(`/sp/${ctx.subProject.id}/quality/inspection`);
  652. }
  653. }
  654. /**
  655. * 新增变更申请 (Post)
  656. *
  657. * @param {Object} ctx - egg全局变量
  658. * @return {void}
  659. */
  660. async inspectionSave(ctx) {
  661. try {
  662. const data = JSON.parse(ctx.request.body.data);
  663. const reponseData = {
  664. err: 0, msg: '', data: {},
  665. };
  666. switch (data.type) {
  667. case 'add':
  668. if (!data.code || data.code === '') {
  669. throw '编号不能为空';
  670. }
  671. if (!data.check_item || !data.check_date) {
  672. throw '请填写检查项和日期';
  673. }
  674. reponseData.data = await ctx.service.qualityInspection.add(ctx.tender.id, ctx.session.sessionUser.accountId, data.code, data.check_item, data.check_date);
  675. break;
  676. default:throw '参数有误';
  677. }
  678. ctx.body = reponseData;
  679. } catch (err) {
  680. this.log(err);
  681. ctx.body = { err: 1, msg: err.toString() };
  682. }
  683. }
  684. /**
  685. * 获取审批界面所需的 原报、审批人数据等
  686. * @param ctx
  687. * @return {Promise<void>}
  688. * @private
  689. */
  690. async _getInspectionAuditViewData(ctx) {
  691. await ctx.service.qualityInspection.loadAuditViewData(ctx.inspection);
  692. }
  693. async inspectionInformation(ctx) {
  694. try {
  695. const whiteList = this.ctx.app.config.multipart.whitelist;
  696. const tender = await ctx.service.tender.getDataById(ctx.tender.id);
  697. await this._getInspectionAuditViewData(ctx);
  698. // 获取附件列表
  699. const fileList = await ctx.service.qualityInspectionAtt.getAllAtt(ctx.tender.id, ctx.inspection.id);
  700. // 获取用户人验证手机号
  701. const renderData = {
  702. moment,
  703. tender,
  704. inspection: ctx.inspection,
  705. auditConst: qualityInspectionConst,
  706. fileList,
  707. whiteList,
  708. auditType,
  709. shenpiConst,
  710. deleteFilePermission: PermissionCheck.delFile(this.ctx.session.sessionUser.permission),
  711. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.quality.inspection_information),
  712. preUrl: `/sp/${ctx.subProject.id}/quality/tender/${ctx.tender.id}/inspection/${ctx.inspection.id}/information`,
  713. };
  714. // data.accountGroup = accountGroup;
  715. // 获取所有项目参与者
  716. const accountList = await ctx.service.projectAccount.getAllSubProjectAccount(ctx.subProject);
  717. renderData.accountList = accountList;
  718. const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: ctx.session.sessionProject.id } });
  719. renderData.accountGroup = unitList.map(item => {
  720. const groupList = accountList.filter(item1 => item1.company === item.name);
  721. return { groupName: item.name, groupList };
  722. }).filter(x => { return x.groupList.length > 0; });
  723. if (ctx.inspection.flow_version === 1) {
  724. const groupedIds = new Set(renderData.accountGroup.reduce((ids, group) => ids.concat(group.groupList.map(user => user.id)), []));
  725. const others = accountList.filter(user => !groupedIds.has(user.id));
  726. if (others.length) renderData.accountGroup.push({ groupName: '其他用户', groupList: others });
  727. }
  728. await this.layout('quality/inspection_information.ejs', renderData, 'quality/inspection_information_modal.ejs');
  729. } catch (err) {
  730. this.log(err);
  731. ctx.redirect(`/sp/${ctx.subProject.id}/quality/tender/${ctx.tender.id}/inspection`);
  732. }
  733. }
  734. async inspectionInformationSave(ctx) {
  735. try {
  736. const data = JSON.parse(ctx.request.body.data);
  737. const reponseData = {
  738. err: 0, msg: '', data: {},
  739. };
  740. if (ctx.inspection.flow_version === 1) {
  741. reponseData.data = await ctx.service.qualityInspectionAudit.processFlow(ctx.inspection, data);
  742. ctx.body = reponseData;
  743. return;
  744. }
  745. switch (data.type) {
  746. case 'update-field':
  747. if (!(!ctx.inspection.readOnly || ctx.inspection.rectificationPower)) {
  748. throw '当前状态不可修改';
  749. }
  750. if (data.update.check_item !== undefined && data.update.check_item === '') {
  751. throw '检查项不能为空';
  752. }
  753. if (data.update.check_date !== undefined && data.update.check_date === '') {
  754. throw '请填写检查日期';
  755. }
  756. if (data.update.rectification_item !== undefined && data.update.rectification_item === '') {
  757. throw '整改情况不能为空';
  758. }
  759. if (data.update.rectification_date !== undefined && data.update.rectification_date === '') {
  760. throw '请填写整改日期';
  761. }
  762. const fields = ['id', 'code', 'check_item', 'check_situation', 'action', 'check_date', 'inspector', 'rectification_item', 'rectification_date'];
  763. if (!this.checkFieldExists(data.update, fields)) {
  764. throw '参数有误';
  765. }
  766. reponseData.data = await ctx.service.qualityInspection.defaultUpdate(data.update);
  767. break;
  768. case 'add-audit':
  769. const id = this.app._.toInteger(data.auditorId);
  770. if (isNaN(id) || id <= 0) {
  771. throw '参数错误';
  772. }
  773. // 检查权限等
  774. if (ctx.inspection.uid !== ctx.session.sessionUser.accountId) {
  775. throw '您无权添加审核人';
  776. }
  777. if (ctx.inspection.status !== auditConst.inspection.status.uncheck && ctx.inspection.status !== auditConst.inspection.status.checkNo) {
  778. throw '当前不允许添加审核人';
  779. }
  780. ctx.inspection.auditorList = await ctx.service.qualityInspectionAudit.getAuditors(ctx.inspection.id, ctx.inspection.times);
  781. // 检查审核人是否已存在
  782. const exist = this.app._.find(ctx.inspection.auditorList, { aid: id });
  783. if (exist) {
  784. throw '该审核人已存在,请勿重复添加';
  785. }
  786. const shenpiInfo = await ctx.service.shenpiAudit.getDataByCondition({ tid: ctx.tender.id, sp_type: shenpiConst.sp_type.inspection, sp_status: shenpiConst.sp_status.gdzs });
  787. const is_gdzs = shenpiInfo && ctx.tender.info.shenpi.inspection === shenpiConst.sp_status.gdzs ? 1 : 0;
  788. const result = await ctx.service.qualityInspectionAudit.addAuditor(ctx.inspection.id, id, ctx.inspection.times, is_gdzs);
  789. if (!result) {
  790. throw '添加审核人失败';
  791. }
  792. reponseData.data = await ctx.service.qualityInspectionAudit.getUserGroup(ctx.inspection.id, ctx.inspection.times);
  793. break;
  794. case 'del-audit':
  795. const id2 = data.auditorId instanceof Number ? data.auditorId : this.app._.toNumber(data.auditorId);
  796. if (isNaN(id2) || id2 <= 0) {
  797. throw '参数错误';
  798. }
  799. const result2 = await ctx.service.qualityInspectionAudit.deleteAuditor(ctx.inspection.id, id2, ctx.inspection.times);
  800. if (!result2) {
  801. throw '移除审核人失败';
  802. }
  803. reponseData.data = await ctx.service.qualityInspectionAudit.getAuditors(ctx.inspection.id, ctx.inspection.times);
  804. break;
  805. case 'start-inspection':
  806. if (ctx.inspection.readOnly) {
  807. throw '当前状态不可提交';
  808. }
  809. await ctx.service.qualityInspectionAudit.start(ctx.inspection.id, ctx.inspection.times);
  810. break;
  811. case 'del-inspection':
  812. if (ctx.inspection.readOnly) {
  813. throw '当前状态不可删除';
  814. }
  815. await ctx.service.qualityInspection.delInspection(ctx.inspection.id);
  816. break;
  817. case 'check':
  818. if (!ctx.inspection || !(ctx.inspection.status === auditConst.inspection.status.checking || ctx.inspection.status === auditConst.inspection.status.checkNoPre)) {
  819. throw '当前质量巡检数据有误';
  820. }
  821. if (ctx.inspection.curAuditorIds.length === 0 || ctx.inspection.curAuditorIds.indexOf(ctx.session.sessionUser.accountId) === -1) {
  822. throw '您无权进行该操作';
  823. }
  824. await ctx.service.qualityInspectionAudit.check(ctx.inspection, data);
  825. break;
  826. case 'rectification':
  827. if (!ctx.inspection || ctx.inspection.status !== auditConst.inspection.status.rectification) {
  828. throw '当前质量巡检数据有误';
  829. }
  830. if (ctx.inspection.curAuditorIds.length === 0 || ctx.inspection.curAuditorIds.indexOf(ctx.session.sessionUser.accountId) === -1) {
  831. throw '您无权进行该操作';
  832. }
  833. await ctx.service.qualityInspectionAudit.rectification(ctx.inspection, data);
  834. break;
  835. default:throw '参数有误';
  836. }
  837. ctx.body = reponseData;
  838. } catch (err) {
  839. this.log(err);
  840. ctx.body = { err: 1, msg: err.toString() };
  841. }
  842. }
  843. checkFieldExists(update, fields) {
  844. for (const field of Object.keys(update)) {
  845. if (!fields.includes(field)) {
  846. return false;
  847. }
  848. }
  849. return true;
  850. }
  851. /**
  852. * 上传附件
  853. * @param {*} ctx 上下文
  854. */
  855. async uploadInspectionFile(ctx) {
  856. let stream;
  857. try {
  858. if (ctx.inspection.flow_version === 1 && !ctx.inspection.canUpload) throw '当前不可上传附件';
  859. const parts = this.ctx.multipart({
  860. autoFields: true,
  861. });
  862. const files = [];
  863. const create_time = Date.parse(new Date()) / 1000;
  864. let idx = 0;
  865. const extra_upload = ctx.inspection.status === auditConst.inspection.status.checked;
  866. while ((stream = await parts()) !== undefined) {
  867. if (!stream.filename) {
  868. // 如果没有传入直接返回
  869. return;
  870. }
  871. const fileInfo = path.parse(stream.filename);
  872. const filepath = `app/public/upload/${this.ctx.tender.id.toString()}/quality_inspection/fujian_${create_time + idx.toString() + fileInfo.ext}`;
  873. // await ctx.helper.saveStreamFile(stream, path.resolve(this.app.baseDir, 'app', filepath));
  874. await ctx.app.fujianOss.put(ctx.app.config.fujianOssFolder + filepath, stream);
  875. files.push({ filepath, name: stream.filename, ext: fileInfo.ext });
  876. ++idx;
  877. stream && (await sendToWormhole(stream));
  878. }
  879. const in_time = new Date();
  880. const payload = files.map(file => {
  881. let idx;
  882. if (Array.isArray(parts.field.name)) {
  883. idx = parts.field.name.findIndex(name => name === file.name);
  884. } else {
  885. idx = 'isString';
  886. }
  887. const newFile = {
  888. tid: ctx.tender.id,
  889. qiid: ctx.inspection.id,
  890. uid: ctx.session.sessionUser.accountId,
  891. filename: file.name,
  892. fileext: file.ext,
  893. filesize: ctx.helper.bytesToSize(idx === 'isString' ? parts.field.size : parts.field.size[idx]),
  894. filepath: file.filepath,
  895. upload_time: in_time,
  896. extra_upload,
  897. };
  898. return newFile;
  899. });
  900. // 执行文件信息写入数据库
  901. await ctx.service.qualityInspectionAtt.saveFileMsgToDb(payload);
  902. // 将最新的当前标段的所有文件信息返回
  903. const data = await ctx.service.qualityInspectionAtt.getAllAtt(ctx.tender.id, ctx.inspection.id);
  904. ctx.body = { err: 0, msg: '', data };
  905. } catch (err) {
  906. stream && (await sendToWormhole(stream));
  907. this.log(err);
  908. ctx.body = { err: 1, msg: err.toString(), data: null };
  909. }
  910. }
  911. /**
  912. * 删除附件
  913. * @param {Ojbect} ctx 上下文
  914. */
  915. async deleteInspectionFile(ctx) {
  916. try {
  917. const { id } = JSON.parse(ctx.request.body.data);
  918. const fileInfo = await ctx.service.qualityInspectionAtt.getDataById(id);
  919. if (ctx.inspection.flow_version === 1) {
  920. if (!fileInfo || fileInfo.qiid !== ctx.inspection.id || !ctx.inspection.canUpload || fileInfo.uid !== ctx.session.sessionUser.accountId) throw '您无权删除该附件';
  921. if (ctx.inspection.status === qualityInspectionConst.status.checked && !fileInfo.extra_upload && !PermissionCheck.delFile(ctx.session.sessionUser.permission)) throw '该附件不可删除';
  922. }
  923. if (fileInfo && Object.keys(fileInfo).length) {
  924. // 先删除文件
  925. // await fs.unlinkSync(path.resolve(this.app.baseDir, './app', fileInfo.filepath));
  926. await ctx.app.fujianOss.delete(ctx.app.config.fujianOssFolder + fileInfo.filepath);
  927. // 再删除数据库
  928. await ctx.service.qualityInspectionAtt.delete(id);
  929. } else {
  930. throw '不存在该文件';
  931. }
  932. const data = await ctx.service.qualityInspectionAtt.getAllAtt(ctx.tender.id, ctx.inspection.id);
  933. ctx.body = { err: 0, msg: '请求成功', data };
  934. } catch (err) {
  935. this.log(err);
  936. ctx.body = { err: 1, msg: err.toString(), data: null };
  937. }
  938. }
  939. /**
  940. * 下载附件
  941. * @param {Object} ctx - egg全局变量
  942. * @return {void}
  943. */
  944. async downloadInspectionFile(ctx) {
  945. const id = ctx.params.fid;
  946. if (id) {
  947. try {
  948. const fileInfo = await ctx.service.qualityInspectionAtt.getDataById(id);
  949. if (fileInfo !== undefined && fileInfo !== '') {
  950. // const fileName = path.join(__dirname, '../', fileInfo.filepath);
  951. // 解决中文无法下载问题
  952. const userAgent = (ctx.request.header['user-agent'] || '').toLowerCase();
  953. let disposition = '';
  954. if (userAgent.indexOf('msie') >= 0 || userAgent.indexOf('chrome') >= 0) {
  955. disposition = 'attachment; filename=' + encodeURIComponent(fileInfo.filename);
  956. } else if (userAgent.indexOf('firefox') >= 0) {
  957. disposition = 'attachment; filename*="utf8\'\'' + encodeURIComponent(fileInfo.filename) + '"';
  958. } else {
  959. /* safari等其他非主流浏览器只能自求多福了 */
  960. disposition = 'attachment; filename=' + new Buffer(fileInfo.filename).toString('binary');
  961. }
  962. ctx.response.set({
  963. 'Content-Type': 'application/octet-stream',
  964. 'Content-Disposition': disposition,
  965. 'Content-Length': fileInfo.filesize,
  966. });
  967. // ctx.body = await fs.createReadStream(fileName);
  968. ctx.body = await ctx.helper.ossFileGet(fileInfo.filepath);
  969. } else {
  970. throw '不存在该文件';
  971. }
  972. } catch (err) {
  973. this.log(err);
  974. this.setMessage(err.toString(), this.messageType.ERROR);
  975. }
  976. }
  977. }
  978. async inspectionOverview(ctx) {
  979. try {
  980. if (!ctx.subProject.page_show.qualityInspection) throw '该功能已关闭';
  981. const tender = await this.service.tender.getDataById(ctx.tender.id);
  982. const year = moment().year();
  983. const renderData = {
  984. moment,
  985. tender,
  986. permission: ctx.permission.inspection,
  987. overview: await ctx.service.qualityInspection.getOverviewData(ctx.tender.id, year),
  988. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.quality.inspection_overview),
  989. };
  990. await this.layout('quality/inspection_overview.ejs', renderData);
  991. } catch (err) {
  992. ctx.log(err);
  993. ctx.postError(err, '无法查看巡检概况数据');
  994. ctx.redirect(`/sp/${ctx.subProject.id}/quality/tender/${ctx.tender.id}/inspection`);
  995. }
  996. }
  997. async inspectionRectification(ctx) {
  998. try {
  999. if (!ctx.subProject.page_show.qualityInspection) throw '该功能已关闭';
  1000. const status = qualityInspectionConst.filter.status.rectification; // 正在整改
  1001. await this._filterInspection(ctx, status);
  1002. } catch (err) {
  1003. ctx.log(err);
  1004. ctx.postError(err, '无法查看巡检整改数据');
  1005. ctx.redirect(`/sp/${ctx.subProject.id}/quality/tender/${ctx.tender.id}/inspection`);
  1006. }
  1007. }
  1008. async inspectionApproval(ctx) {
  1009. try {
  1010. if (!ctx.subProject.page_show.qualityInspection) throw '该功能已关闭';
  1011. const status = qualityInspectionConst.filter.status.reply; // 正在批复
  1012. await this._filterInspection(ctx, status);
  1013. } catch (err) {
  1014. ctx.log(err);
  1015. ctx.postError(err, '无法查看巡检批复数据');
  1016. ctx.redirect(`/sp/${ctx.subProject.id}/quality/tender/${ctx.tender.id}/inspection`);
  1017. }
  1018. }
  1019. }
  1020. return QualityController;
  1021. };