quality_controller.js 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081
  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. pageSizeCacheKey: 'inspection-pageSize:' + ctx.session.sessionUser.accountId + ':' + ctx.path.replace(/\/$/, ''),
  592. pageSize,
  593. total_num: total,
  594. total: Math.ceil(total / pageSize),
  595. queryData: JSON.stringify(ctx.urlInfo.query),
  596. };
  597. let codeRule = [];
  598. let c_connector = '1';
  599. let c_rule_first = 1;
  600. const rule_type = 'inspection';
  601. const tender = await this.service.tender.getDataById(ctx.tender.id);
  602. if (tender.c_code_rules) {
  603. const c_code_rules = JSON.parse(tender.c_code_rules);
  604. codeRule = c_code_rules[rule_type + '_rule'] !== undefined ? c_code_rules[rule_type + '_rule'] : [];
  605. c_connector = c_code_rules[rule_type + '_connector'] !== undefined ? c_code_rules[rule_type + '_connector'] : '1';
  606. c_rule_first = c_code_rules[rule_type + '_rule_first'] !== undefined ? c_code_rules[rule_type + '_rule_first'] : 1;
  607. }
  608. for (const rule of codeRule) {
  609. switch (rule.rule_type) {
  610. case codeRuleConst.measure.ruleType.dealCode:
  611. rule.preview = ctx.tender.info.deal_info.dealCode;
  612. break;
  613. case codeRuleConst.measure.ruleType.tenderName:
  614. rule.preview = tender.name;
  615. break;
  616. case codeRuleConst.measure.ruleType.inDate:
  617. rule.preview = moment().format('YYYY');
  618. break;
  619. case codeRuleConst.measure.ruleType.text:
  620. rule.preview = rule.text;
  621. break;
  622. case codeRuleConst.measure.ruleType.addNo:
  623. const s = '0000000000';
  624. rule.preview = s.substr(s.length - rule.format);
  625. break;
  626. default: break;
  627. }
  628. }
  629. const renderData = {
  630. moment,
  631. tender,
  632. permission: ctx.permission.inspection,
  633. rule_type,
  634. codeRule,
  635. dealCode: ctx.tender.info.deal_info.dealCode,
  636. c_connector,
  637. c_rule_first,
  638. ruleType: codeRuleConst.ruleType[rule_type],
  639. ruleConst: codeRuleConst.measure,
  640. filter,
  641. inspectionList,
  642. auditType,
  643. auditConst: qualityInspectionConst,
  644. status,
  645. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.quality.inspection),
  646. pageInfo,
  647. };
  648. await this.layout('quality/inspection.ejs', renderData, 'quality/inspection_modal.ejs');
  649. } catch (err) {
  650. ctx.log(err);
  651. ctx.postError(err, '无法查看质量巡检数据');
  652. ctx.redirect(`/sp/${ctx.subProject.id}/quality/inspection`);
  653. }
  654. }
  655. /**
  656. * 新增变更申请 (Post)
  657. *
  658. * @param {Object} ctx - egg全局变量
  659. * @return {void}
  660. */
  661. async inspectionSave(ctx) {
  662. try {
  663. const data = JSON.parse(ctx.request.body.data);
  664. const reponseData = {
  665. err: 0, msg: '', data: {},
  666. };
  667. switch (data.type) {
  668. case 'add':
  669. if (!data.code || data.code === '') {
  670. throw '编号不能为空';
  671. }
  672. if (!data.check_item || !data.check_date) {
  673. throw '请填写检查项和日期';
  674. }
  675. reponseData.data = await ctx.service.qualityInspection.add(ctx.tender.id, ctx.session.sessionUser.accountId, data.code, data.check_item, data.check_date);
  676. break;
  677. default:throw '参数有误';
  678. }
  679. ctx.body = reponseData;
  680. } catch (err) {
  681. this.log(err);
  682. ctx.body = { err: 1, msg: err.toString() };
  683. }
  684. }
  685. /**
  686. * 获取审批界面所需的 原报、审批人数据等
  687. * @param ctx
  688. * @return {Promise<void>}
  689. * @private
  690. */
  691. async _getInspectionAuditViewData(ctx) {
  692. await ctx.service.qualityInspection.loadAuditViewData(ctx.inspection);
  693. }
  694. async inspectionInformation(ctx) {
  695. try {
  696. const whiteList = this.ctx.app.config.multipart.whitelist;
  697. const tender = await ctx.service.tender.getDataById(ctx.tender.id);
  698. await this._getInspectionAuditViewData(ctx);
  699. // 获取附件列表
  700. const fileList = await ctx.service.qualityInspectionAtt.getAllAtt(ctx.tender.id, ctx.inspection.id);
  701. // 获取用户人验证手机号
  702. const renderData = {
  703. moment,
  704. tender,
  705. inspection: ctx.inspection,
  706. auditConst: qualityInspectionConst,
  707. inspectionMenuCounts: await this._getInspectionMenuCounts(ctx),
  708. fileList,
  709. whiteList,
  710. auditType,
  711. shenpiConst,
  712. deleteFilePermission: PermissionCheck.delFile(this.ctx.session.sessionUser.permission),
  713. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.quality.inspection_information),
  714. preUrl: `/sp/${ctx.subProject.id}/quality/tender/${ctx.tender.id}/inspection/${ctx.inspection.id}/information`,
  715. };
  716. // data.accountGroup = accountGroup;
  717. // 获取所有项目参与者
  718. const accountList = await ctx.service.projectAccount.getAllSubProjectAccount(ctx.subProject);
  719. renderData.accountList = accountList;
  720. const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: ctx.session.sessionProject.id } });
  721. renderData.accountGroup = unitList.map(item => {
  722. const groupList = accountList.filter(item1 => item1.company === item.name);
  723. return { groupName: item.name, groupList };
  724. }).filter(x => { return x.groupList.length > 0; });
  725. if (ctx.inspection.flow_version === 1) {
  726. const groupedIds = new Set(renderData.accountGroup.reduce((ids, group) => ids.concat(group.groupList.map(user => user.id)), []));
  727. const others = accountList.filter(user => !groupedIds.has(user.id));
  728. if (others.length) renderData.accountGroup.push({ groupName: '其他用户', groupList: others });
  729. }
  730. await this.layout('quality/inspection_information.ejs', renderData, 'quality/inspection_information_modal.ejs');
  731. } catch (err) {
  732. this.log(err);
  733. ctx.redirect(`/sp/${ctx.subProject.id}/quality/tender/${ctx.tender.id}/inspection`);
  734. }
  735. }
  736. async inspectionInformationSave(ctx) {
  737. try {
  738. const data = JSON.parse(ctx.request.body.data);
  739. const reponseData = {
  740. err: 0, msg: '', data: {},
  741. };
  742. if (ctx.inspection.flow_version === 1) {
  743. reponseData.data = await ctx.service.qualityInspectionAudit.processFlow(ctx.inspection, data);
  744. ctx.body = reponseData;
  745. return;
  746. }
  747. switch (data.type) {
  748. case 'update-field':
  749. if (!(!ctx.inspection.readOnly || ctx.inspection.rectificationPower)) {
  750. throw '当前状态不可修改';
  751. }
  752. if (data.update.check_item !== undefined && data.update.check_item === '') {
  753. throw '检查项不能为空';
  754. }
  755. if (data.update.check_date !== undefined && data.update.check_date === '') {
  756. throw '请填写检查日期';
  757. }
  758. if (data.update.rectification_item !== undefined && data.update.rectification_item === '') {
  759. throw '整改情况不能为空';
  760. }
  761. if (data.update.rectification_date !== undefined && data.update.rectification_date === '') {
  762. throw '请填写整改日期';
  763. }
  764. const fields = ['id', 'code', 'check_item', 'check_situation', 'action', 'check_date', 'inspector', 'rectification_item', 'rectification_date'];
  765. if (!this.checkFieldExists(data.update, fields)) {
  766. throw '参数有误';
  767. }
  768. reponseData.data = await ctx.service.qualityInspection.defaultUpdate(data.update);
  769. break;
  770. case 'add-audit':
  771. const id = this.app._.toInteger(data.auditorId);
  772. if (isNaN(id) || id <= 0) {
  773. throw '参数错误';
  774. }
  775. // 检查权限等
  776. if (ctx.inspection.uid !== ctx.session.sessionUser.accountId) {
  777. throw '您无权添加审核人';
  778. }
  779. if (ctx.inspection.status !== auditConst.inspection.status.uncheck && ctx.inspection.status !== auditConst.inspection.status.checkNo) {
  780. throw '当前不允许添加审核人';
  781. }
  782. ctx.inspection.auditorList = await ctx.service.qualityInspectionAudit.getAuditors(ctx.inspection.id, ctx.inspection.times);
  783. // 检查审核人是否已存在
  784. const exist = this.app._.find(ctx.inspection.auditorList, { aid: id });
  785. if (exist) {
  786. throw '该审核人已存在,请勿重复添加';
  787. }
  788. const shenpiInfo = await ctx.service.shenpiAudit.getDataByCondition({ tid: ctx.tender.id, sp_type: shenpiConst.sp_type.inspection, sp_status: shenpiConst.sp_status.gdzs });
  789. const is_gdzs = shenpiInfo && ctx.tender.info.shenpi.inspection === shenpiConst.sp_status.gdzs ? 1 : 0;
  790. const result = await ctx.service.qualityInspectionAudit.addAuditor(ctx.inspection.id, id, ctx.inspection.times, is_gdzs);
  791. if (!result) {
  792. throw '添加审核人失败';
  793. }
  794. reponseData.data = await ctx.service.qualityInspectionAudit.getUserGroup(ctx.inspection.id, ctx.inspection.times);
  795. break;
  796. case 'del-audit':
  797. const id2 = data.auditorId instanceof Number ? data.auditorId : this.app._.toNumber(data.auditorId);
  798. if (isNaN(id2) || id2 <= 0) {
  799. throw '参数错误';
  800. }
  801. const result2 = await ctx.service.qualityInspectionAudit.deleteAuditor(ctx.inspection.id, id2, ctx.inspection.times);
  802. if (!result2) {
  803. throw '移除审核人失败';
  804. }
  805. reponseData.data = await ctx.service.qualityInspectionAudit.getAuditors(ctx.inspection.id, ctx.inspection.times);
  806. break;
  807. case 'start-inspection':
  808. if (ctx.inspection.readOnly) {
  809. throw '当前状态不可提交';
  810. }
  811. await ctx.service.qualityInspectionAudit.start(ctx.inspection.id, ctx.inspection.times);
  812. break;
  813. case 'del-inspection':
  814. if (ctx.inspection.readOnly) {
  815. throw '当前状态不可删除';
  816. }
  817. await ctx.service.qualityInspection.delInspection(ctx.inspection.id);
  818. break;
  819. case 'check':
  820. if (!ctx.inspection || !(ctx.inspection.status === auditConst.inspection.status.checking || ctx.inspection.status === auditConst.inspection.status.checkNoPre)) {
  821. throw '当前质量巡检数据有误';
  822. }
  823. if (ctx.inspection.curAuditorIds.length === 0 || ctx.inspection.curAuditorIds.indexOf(ctx.session.sessionUser.accountId) === -1) {
  824. throw '您无权进行该操作';
  825. }
  826. await ctx.service.qualityInspectionAudit.check(ctx.inspection, data);
  827. break;
  828. case 'rectification':
  829. if (!ctx.inspection || ctx.inspection.status !== auditConst.inspection.status.rectification) {
  830. throw '当前质量巡检数据有误';
  831. }
  832. if (ctx.inspection.curAuditorIds.length === 0 || ctx.inspection.curAuditorIds.indexOf(ctx.session.sessionUser.accountId) === -1) {
  833. throw '您无权进行该操作';
  834. }
  835. await ctx.service.qualityInspectionAudit.rectification(ctx.inspection, data);
  836. break;
  837. default:throw '参数有误';
  838. }
  839. ctx.body = reponseData;
  840. } catch (err) {
  841. this.log(err);
  842. ctx.body = { err: 1, msg: err.toString() };
  843. }
  844. }
  845. checkFieldExists(update, fields) {
  846. for (const field of Object.keys(update)) {
  847. if (!fields.includes(field)) {
  848. return false;
  849. }
  850. }
  851. return true;
  852. }
  853. /**
  854. * 上传附件
  855. * @param {*} ctx 上下文
  856. */
  857. async uploadInspectionFile(ctx) {
  858. let stream;
  859. try {
  860. if (ctx.inspection.flow_version === 1 && !ctx.inspection.canUpload) throw '当前不可上传附件';
  861. const parts = this.ctx.multipart({
  862. autoFields: true,
  863. });
  864. const files = [];
  865. const create_time = Date.parse(new Date()) / 1000;
  866. let idx = 0;
  867. const extra_upload = ctx.inspection.status === auditConst.inspection.status.checked;
  868. while ((stream = await parts()) !== undefined) {
  869. if (!stream.filename) {
  870. // 如果没有传入直接返回
  871. return;
  872. }
  873. const fileInfo = path.parse(stream.filename);
  874. const filepath = `app/public/upload/${this.ctx.tender.id.toString()}/quality_inspection/fujian_${create_time + idx.toString() + fileInfo.ext}`;
  875. // await ctx.helper.saveStreamFile(stream, path.resolve(this.app.baseDir, 'app', filepath));
  876. await ctx.app.fujianOss.put(ctx.app.config.fujianOssFolder + filepath, stream);
  877. files.push({ filepath, name: stream.filename, ext: fileInfo.ext });
  878. ++idx;
  879. stream && (await sendToWormhole(stream));
  880. }
  881. const in_time = new Date();
  882. const payload = files.map(file => {
  883. let idx;
  884. if (Array.isArray(parts.field.name)) {
  885. idx = parts.field.name.findIndex(name => name === file.name);
  886. } else {
  887. idx = 'isString';
  888. }
  889. const newFile = {
  890. tid: ctx.tender.id,
  891. qiid: ctx.inspection.id,
  892. uid: ctx.session.sessionUser.accountId,
  893. filename: file.name,
  894. fileext: file.ext,
  895. filesize: ctx.helper.bytesToSize(idx === 'isString' ? parts.field.size : parts.field.size[idx]),
  896. filepath: file.filepath,
  897. upload_time: in_time,
  898. extra_upload,
  899. };
  900. return newFile;
  901. });
  902. // 执行文件信息写入数据库
  903. await ctx.service.qualityInspectionAtt.saveFileMsgToDb(payload);
  904. // 将最新的当前标段的所有文件信息返回
  905. const data = await ctx.service.qualityInspectionAtt.getAllAtt(ctx.tender.id, ctx.inspection.id);
  906. ctx.body = { err: 0, msg: '', data };
  907. } catch (err) {
  908. stream && (await sendToWormhole(stream));
  909. this.log(err);
  910. ctx.body = { err: 1, msg: err.toString(), data: null };
  911. }
  912. }
  913. /**
  914. * 删除附件
  915. * @param {Ojbect} ctx 上下文
  916. */
  917. async deleteInspectionFile(ctx) {
  918. try {
  919. const { id } = JSON.parse(ctx.request.body.data);
  920. const fileInfo = await ctx.service.qualityInspectionAtt.getDataById(id);
  921. if (ctx.inspection.flow_version === 1) {
  922. if (!fileInfo || fileInfo.qiid !== ctx.inspection.id || !ctx.inspection.canUpload || fileInfo.uid !== ctx.session.sessionUser.accountId) throw '您无权删除该附件';
  923. if (ctx.inspection.status === qualityInspectionConst.status.checked && !fileInfo.extra_upload && !PermissionCheck.delFile(ctx.session.sessionUser.permission)) throw '该附件不可删除';
  924. }
  925. if (fileInfo && Object.keys(fileInfo).length) {
  926. // 先删除文件
  927. // await fs.unlinkSync(path.resolve(this.app.baseDir, './app', fileInfo.filepath));
  928. await ctx.app.fujianOss.delete(ctx.app.config.fujianOssFolder + fileInfo.filepath);
  929. // 再删除数据库
  930. await ctx.service.qualityInspectionAtt.delete(id);
  931. } else {
  932. throw '不存在该文件';
  933. }
  934. const data = await ctx.service.qualityInspectionAtt.getAllAtt(ctx.tender.id, ctx.inspection.id);
  935. ctx.body = { err: 0, msg: '请求成功', data };
  936. } catch (err) {
  937. this.log(err);
  938. ctx.body = { err: 1, msg: err.toString(), data: null };
  939. }
  940. }
  941. /**
  942. * 下载附件
  943. * @param {Object} ctx - egg全局变量
  944. * @return {void}
  945. */
  946. async downloadInspectionFile(ctx) {
  947. const id = ctx.params.fid;
  948. if (id) {
  949. try {
  950. const fileInfo = await ctx.service.qualityInspectionAtt.getDataById(id);
  951. if (fileInfo !== undefined && fileInfo !== '') {
  952. // const fileName = path.join(__dirname, '../', fileInfo.filepath);
  953. // 解决中文无法下载问题
  954. const userAgent = (ctx.request.header['user-agent'] || '').toLowerCase();
  955. let disposition = '';
  956. if (userAgent.indexOf('msie') >= 0 || userAgent.indexOf('chrome') >= 0) {
  957. disposition = 'attachment; filename=' + encodeURIComponent(fileInfo.filename);
  958. } else if (userAgent.indexOf('firefox') >= 0) {
  959. disposition = 'attachment; filename*="utf8\'\'' + encodeURIComponent(fileInfo.filename) + '"';
  960. } else {
  961. /* safari等其他非主流浏览器只能自求多福了 */
  962. disposition = 'attachment; filename=' + new Buffer(fileInfo.filename).toString('binary');
  963. }
  964. ctx.response.set({
  965. 'Content-Type': 'application/octet-stream',
  966. 'Content-Disposition': disposition,
  967. 'Content-Length': fileInfo.filesize,
  968. });
  969. // ctx.body = await fs.createReadStream(fileName);
  970. ctx.body = await ctx.helper.ossFileGet(fileInfo.filepath);
  971. } else {
  972. throw '不存在该文件';
  973. }
  974. } catch (err) {
  975. this.log(err);
  976. this.setMessage(err.toString(), this.messageType.ERROR);
  977. }
  978. }
  979. }
  980. async inspectionOverview(ctx) {
  981. try {
  982. if (!ctx.subProject.page_show.qualityInspection) throw '该功能已关闭';
  983. const tender = await this.service.tender.getDataById(ctx.tender.id);
  984. const year = moment().year();
  985. const renderData = {
  986. moment,
  987. tender,
  988. permission: ctx.permission.inspection,
  989. overview: await ctx.service.qualityInspection.getOverviewData(ctx.tender.id, year),
  990. inspectionMenuCounts: await this._getInspectionMenuCounts(ctx),
  991. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.quality.inspection_overview),
  992. };
  993. await this.layout('quality/inspection_overview.ejs', renderData);
  994. } catch (err) {
  995. ctx.log(err);
  996. ctx.postError(err, '无法查看巡检概况数据');
  997. ctx.redirect(`/sp/${ctx.subProject.id}/quality/tender/${ctx.tender.id}/inspection`);
  998. }
  999. }
  1000. async inspectionRectification(ctx) {
  1001. try {
  1002. if (!ctx.subProject.page_show.qualityInspection) throw '该功能已关闭';
  1003. const status = qualityInspectionConst.filter.status.rectification; // 正在整改
  1004. await this._filterInspection(ctx, status);
  1005. } catch (err) {
  1006. ctx.log(err);
  1007. ctx.postError(err, '无法查看巡检整改数据');
  1008. ctx.redirect(`/sp/${ctx.subProject.id}/quality/tender/${ctx.tender.id}/inspection`);
  1009. }
  1010. }
  1011. async inspectionApproval(ctx) {
  1012. try {
  1013. if (!ctx.subProject.page_show.qualityInspection) throw '该功能已关闭';
  1014. const status = qualityInspectionConst.filter.status.reply; // 正在批复
  1015. await this._filterInspection(ctx, status);
  1016. } catch (err) {
  1017. ctx.log(err);
  1018. ctx.postError(err, '无法查看巡检批复数据');
  1019. ctx.redirect(`/sp/${ctx.subProject.id}/quality/tender/${ctx.tender.id}/inspection`);
  1020. }
  1021. }
  1022. async _getInspectionMenuCounts(ctx) {
  1023. const status = qualityInspectionConst.filter.status;
  1024. const [rectification, reply] = await Promise.all([
  1025. ctx.service.qualityInspection.getCountByStatus(ctx.tender.id, status.rectification),
  1026. ctx.service.qualityInspection.getCountByStatus(ctx.tender.id, status.reply),
  1027. ]);
  1028. return { rectification, reply };
  1029. }
  1030. }
  1031. return QualityController;
  1032. };