|
|
@@ -14,6 +14,8 @@ const tenderConst = require('../const/tender');
|
|
|
const changeConst = require('../const/change');
|
|
|
const advanceConst = require('../const/advance');
|
|
|
const materialConst = require('../const/material');
|
|
|
+const shenpiConst = require('../const/shenpi');
|
|
|
+const codeRuleConst = require('../const/code_rule');
|
|
|
const fs = require('fs');
|
|
|
const path = require('path');
|
|
|
const sendToWormhole = require('stream-wormhole');
|
|
|
@@ -23,6 +25,7 @@ const AiInspect = require('../lib/ai_inspect');
|
|
|
const uuid = require('node-uuid');
|
|
|
const nlsToken = require('../lib/nls_token');
|
|
|
const streamToArray = require('stream-to-array');
|
|
|
+const PermissionCheck = require('../const/account_permission').PermissionCheck;
|
|
|
|
|
|
module.exports = app => {
|
|
|
|
|
|
@@ -247,6 +250,45 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ // 获取待审批的质量巡检单
|
|
|
+ const auditQualityInspections = [];
|
|
|
+ const qualityInspectionList = await ctx.service.qualityInspectionAudit.getAuditInspectionByWap(ctx.session.sessionUser.accountId);
|
|
|
+ for (const audit of qualityInspectionList) {
|
|
|
+ let sp = null;
|
|
|
+ if (audit.spid) {
|
|
|
+ if (ctx.helper._.findIndex(subProjects, { id: audit.spid }) !== -1) {
|
|
|
+ sp = ctx.helper._.find(subProjects, { id: audit.spid });
|
|
|
+ } else {
|
|
|
+ sp = await ctx.service.subProject.getDataById(audit.spid);
|
|
|
+ subProjects.push(sp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (sp) {
|
|
|
+ const pageShow = JSON.parse(sp.page_show);
|
|
|
+ if (pageShow.qualityInspection) {
|
|
|
+ auditQualityInspections.push(audit);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const auditSafeInspections = [];
|
|
|
+ const safeInspectionList = await ctx.service.safeInspectionAudit.getAuditInspectionByWap(ctx.session.sessionUser.accountId);
|
|
|
+ for (const audit of safeInspectionList) {
|
|
|
+ let sp = null;
|
|
|
+ if (audit.spid) {
|
|
|
+ if (ctx.helper._.findIndex(subProjects, { id: audit.spid }) !== -1) {
|
|
|
+ sp = ctx.helper._.find(subProjects, { id: audit.spid });
|
|
|
+ } else {
|
|
|
+ sp = await ctx.service.subProject.getDataById(audit.spid);
|
|
|
+ subProjects.push(sp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (sp) {
|
|
|
+ const pageShow = JSON.parse(sp.page_show);
|
|
|
+ if (pageShow.safeInspection) {
|
|
|
+ auditSafeInspections.push(audit);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
const renderData = {
|
|
|
auditStages,
|
|
|
auditChanges,
|
|
|
@@ -256,6 +298,8 @@ module.exports = app => {
|
|
|
auditMaterials,
|
|
|
auditRevise,
|
|
|
auditAdvance,
|
|
|
+ auditQualityInspections,
|
|
|
+ auditSafeInspections,
|
|
|
changeConst,
|
|
|
advanceConst,
|
|
|
tpUnit: 2,
|
|
|
@@ -287,10 +331,19 @@ module.exports = app => {
|
|
|
async list(ctx) {
|
|
|
try {
|
|
|
// 获取用户新建标段权利
|
|
|
+ const type = ctx.params.type || '';
|
|
|
+ let tenderList = '';
|
|
|
const accountInfo = await this.ctx.service.projectAccount.getDataById(ctx.session.sessionUser.accountId);
|
|
|
const userPermission = accountInfo !== undefined && accountInfo.permission !== '' ? JSON.parse(accountInfo.permission) : null;
|
|
|
-
|
|
|
- const tenderList = await this.ctx.service.tender.getBuildList('', userPermission);
|
|
|
+ if (type) {
|
|
|
+ if (type === 'safe' && !ctx.subProject.page_show.safeInspection) throw '该功能已关闭';
|
|
|
+ if (type === 'quality' && !ctx.subProject.page_show.qualityInspection) throw '该功能已关闭';
|
|
|
+ const permission = type === 'quality' ? 'inspection' : type === 'safe' ? 'safe_inspection' : '';
|
|
|
+ if (!permission) throw '参数错误';
|
|
|
+ tenderList = await ctx.service.tender.getSpecList(ctx.service.tenderPermission, permission, ctx.session.sessionUser.is_admin ? 'all' : '');
|
|
|
+ } else {
|
|
|
+ tenderList = await this.ctx.service.tender.getBuildList('', userPermission);
|
|
|
+ }
|
|
|
for (const t of tenderList) {
|
|
|
await this.ctx.service.tenderCache.loadTenderCache(t, this.ctx.session.sessionUser.accountId);
|
|
|
}
|
|
|
@@ -304,6 +357,7 @@ module.exports = app => {
|
|
|
valuations,
|
|
|
uid: this.ctx.session.sessionUser.accountId,
|
|
|
pid: this.ctx.session.sessionProject.id,
|
|
|
+ type,
|
|
|
};
|
|
|
await ctx.render('wap/list.ejs', renderData);
|
|
|
} catch (err) {
|
|
|
@@ -1181,12 +1235,196 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 巡检列表页
|
|
|
+ *
|
|
|
+ * @param {Object} ctx - egg全局变量
|
|
|
+ * @return {void}
|
|
|
+ */
|
|
|
async inspection(ctx) {
|
|
|
+ try {
|
|
|
+ const type = ctx.params.type || '';
|
|
|
+ if (type !== 'safe' && type !== 'quality') {
|
|
|
+ throw '参数有误';
|
|
|
+ }
|
|
|
+ const tableName = type + 'Inspection';
|
|
|
+ // 变更令列表
|
|
|
+ const inspections = await ctx.service[tableName].getListByStatus(ctx.tender.id, 0, 0);
|
|
|
+
|
|
|
+ for (const c of inspections) {
|
|
|
+ c.showApprovalBtn = false;
|
|
|
+ c.curAuditors = await ctx.service[tableName + 'Audit'].getAuditorsByStatus(c.id, c.status, c.times);
|
|
|
+ if ((c.status === auditConst.inspection.status.uncheck || c.status === auditConst.inspection.status.checkNo) && c.uid === ctx.session.sessionUser.accountId) {
|
|
|
+ c.showApprovalBtn = true;
|
|
|
+ } else if (c.status === auditConst.inspection.status.checkNoPre) {
|
|
|
+ c.curAuditors2 = await ctx.service[tableName + 'Audit'].getAuditorsByStatus(c.id, auditConst.inspection.status.checking, c.times);
|
|
|
+ const curAudit = c.curAuditors2.find(function(x) {
|
|
|
+ return x.aid === ctx.session.sessionUser.accountId;
|
|
|
+ });
|
|
|
+ if (curAudit && (curAudit.status === auditConst.inspection.status.checking || curAudit.status === auditConst.inspection.status.rectification)) {
|
|
|
+ c.showApprovalBtn = true;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ const curAudit = c.curAuditors.find(function(x) {
|
|
|
+ return x.aid === ctx.session.sessionUser.accountId;
|
|
|
+ });
|
|
|
+ if (curAudit && (curAudit.status === auditConst.inspection.status.checking || curAudit.status === auditConst.inspection.status.rectification)) {
|
|
|
+ c.showApprovalBtn = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const renderData = {
|
|
|
+ tender: ctx.tender.data,
|
|
|
+ inspections,
|
|
|
+ auditInspectionConst: auditConst.inspection,
|
|
|
+ auditType: auditConst.auditType,
|
|
|
+ type,
|
|
|
+ moment,
|
|
|
+ permission: type === 'quality' ? ctx.permission.inspection : ctx.permission.safe_inspection,
|
|
|
+ };
|
|
|
+ await ctx.render('wap/shenpi_inspection_index.ejs', renderData);
|
|
|
+ } catch (err) {
|
|
|
+ console.log(err);
|
|
|
+ this.log(err);
|
|
|
+ ctx.redirect('/wap/sp/' + ctx.subProject.id + '/' + ctx.params.type + '/inspection');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 巡检审批详细页
|
|
|
+ *
|
|
|
+ * @param {Object} ctx - egg全局变量
|
|
|
+ * @return {void}
|
|
|
+ */
|
|
|
+ async qualityInspectionInformation(ctx) {
|
|
|
+ const type = 'quality';
|
|
|
+ await this._inspectionInformation(ctx, type);
|
|
|
+ }
|
|
|
+
|
|
|
+ async safeInspectionInformation(ctx) {
|
|
|
+ const type = 'safe';
|
|
|
+ await this._inspectionInformation(ctx, type);
|
|
|
+ }
|
|
|
+
|
|
|
+ async _inspectionInformation(ctx, type) {
|
|
|
+ try {
|
|
|
+ const whiteList = this.ctx.app.config.multipart.whitelist;
|
|
|
+ const tender = ctx.tender.data;
|
|
|
+ const inspection = ctx.inspection;
|
|
|
+ await ctx.service[type + 'Inspection'].loadAuditViewData(ctx.inspection);
|
|
|
+ // 获取附件列表
|
|
|
+ const fileList = await ctx.service[type + 'InspectionAtt'].getAllAtt(ctx.tender.id, ctx.inspection.id);
|
|
|
+ const renderData = {
|
|
|
+ moment,
|
|
|
+ tender,
|
|
|
+ inspection,
|
|
|
+ fileList,
|
|
|
+ whiteList,
|
|
|
+ deleteFilePermission: PermissionCheck.delFile(this.ctx.session.sessionUser.permission),
|
|
|
+ auditConst: auditConst.inspection,
|
|
|
+ shenpiConst,
|
|
|
+ tpUnit: ctx.tender.info.decimal.tp,
|
|
|
+ auditType,
|
|
|
+ type,
|
|
|
+ preUrl: `/sp/${ctx.subProject.id}/${type}/tender/${ctx.tender.id}/inspection/${ctx.inspection.id}/information`,
|
|
|
+ };
|
|
|
+ const accountList = await ctx.service.projectAccount.getAllSubProjectAccount(ctx.subProject);
|
|
|
+ renderData.accountList = accountList;
|
|
|
+ const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: ctx.session.sessionProject.id } });
|
|
|
+ renderData.accountGroup = unitList.map(item => {
|
|
|
+ const groupList = accountList.filter(item1 => item1.company === item.name);
|
|
|
+ return { groupName: item.name, groupList };
|
|
|
+ }).filter(x => { return x.groupList.length > 0; });
|
|
|
+ await ctx.render('wap/shenpi_inspection.ejs', renderData);
|
|
|
+ } catch (err) {
|
|
|
+ this.log(err);
|
|
|
+ ctx.redirect('/wap/sp/' + ctx.subProject.id + '/' + type + '/inspection');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async inspectionAdd(ctx) {
|
|
|
+ const type = ctx.params.type || '';
|
|
|
+ if (type !== 'safe' && type !== 'quality') {
|
|
|
+ throw '参数有误';
|
|
|
+ }
|
|
|
+ const tenderData = await ctx.service.tender.getDataById(ctx.tender.id);
|
|
|
+ const codeType = type === 'quality' ? codeRuleConst.ruleString[codeRuleConst.ruleType.inspection] : codeRuleConst.ruleString[codeRuleConst.ruleType.safe_inspection];
|
|
|
+ const c_code_rules = tenderData.c_code_rules !== null ? JSON.parse(tenderData.c_code_rules) : null;
|
|
|
+ const cCodeRule = c_code_rules && c_code_rules[codeType + '_rule'] ? c_code_rules[codeType + '_rule'] : [
|
|
|
+ { rule_type: 2, text: (type === 'quality' ? '质量' : '安全') + '巡检' + moment().format('YYYYMMDD') },
|
|
|
+ { rule_type: 4, format: 3, start: 1 },
|
|
|
+ ];
|
|
|
+ const cConnector = c_code_rules && c_code_rules[codeType + '_connector'] ? c_code_rules[codeType + '_connector'] : 3;
|
|
|
+ const changeCount = await ctx.service[type + 'Inspection'].count({ tid: ctx.tender.id });
|
|
|
+ const code = [];
|
|
|
+ for (const rule of cCodeRule) {
|
|
|
+ switch (rule.rule_type) {
|
|
|
+ case codeRuleConst.measure.ruleType.dealCode:
|
|
|
+ code.push(ctx.tender.info.deal_info.dealCode);
|
|
|
+ break;
|
|
|
+ case codeRuleConst.measure.ruleType.tenderName:
|
|
|
+ code.push(tenderData.name);
|
|
|
+ break;
|
|
|
+ case codeRuleConst.measure.ruleType.text:
|
|
|
+ code.push(rule.text);
|
|
|
+ break;
|
|
|
+ case codeRuleConst.measure.ruleType.inDate:
|
|
|
+ code.push(moment().format('YYYY'));
|
|
|
+ break;
|
|
|
+ case codeRuleConst.measure.ruleType.addNo:
|
|
|
+ let s = '0000000000';
|
|
|
+ const count = rule.start + changeCount;
|
|
|
+ s = s + count;
|
|
|
+ code.push(s.substr(s.length - rule.format));
|
|
|
+ break;
|
|
|
+ default: break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const newCode = code.join(cConnector !== null && parseInt(cConnector) !== 3 ? codeRuleConst.measure.connectorString[cConnector] : '');
|
|
|
const renderData = {
|
|
|
+ newCode,
|
|
|
+ tender: ctx.tender.data,
|
|
|
+ type,
|
|
|
};
|
|
|
await ctx.render('wap/inspection.ejs', renderData);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 新增变更申请 (Post)
|
|
|
+ *
|
|
|
+ * @param {Object} ctx - egg全局变量
|
|
|
+ * @return {void}
|
|
|
+ */
|
|
|
+ async inspectionSave(ctx) {
|
|
|
+ try {
|
|
|
+ const type = ctx.params.type || '';
|
|
|
+ if (type !== 'safe' && type !== 'quality') {
|
|
|
+ throw '参数有误';
|
|
|
+ }
|
|
|
+ const data = JSON.parse(ctx.request.body.data);
|
|
|
+ const reponseData = {
|
|
|
+ err: 0, msg: '', data: {},
|
|
|
+ };
|
|
|
+ switch (data.type) {
|
|
|
+ case 'addByWap':
|
|
|
+ if (!data.insert || !data.insert.code || data.insert.code === '') {
|
|
|
+ throw '巡检编号不能为空';
|
|
|
+ }
|
|
|
+ if (!data.insert.check_item) {
|
|
|
+ throw '检查项不能为空';
|
|
|
+ }
|
|
|
+ reponseData.data = await ctx.service[type + 'Inspection'].addByWap(ctx.tender.id, data.insert);
|
|
|
+ break;
|
|
|
+ default:throw '参数有误';
|
|
|
+ }
|
|
|
+ ctx.body = reponseData;
|
|
|
+ } catch (err) {
|
|
|
+ this.log(err);
|
|
|
+ ctx.body = { err: 1, msg: err.toString() };
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
async inspectionAiAsk(ctx) {
|
|
|
const responseData = {
|
|
|
err: 0,
|