quality_controller.js 54 KB

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