'use strict'; const { CrudService } = require('naf-framework-mongoose/lib/service'); const { BusinessError, ErrorCode } = require('naf-core').Error; const Path = require('path'); const _ = require('lodash'); const moment = require('moment'); const assert = require('assert'); const { ObjectId } = require('mongoose').Types; const Excel = require('exceljs'); const { sep } = require('path'); const fs = require('fs'); // 价值评估表 class PatentassessService extends CrudService { constructor(ctx) { super(ctx, 'patentassess'); this.model = this.ctx.model.Patent.Patentassess; this.notice = this.ctx.model.Patent.Patentexamine; } /** * 查新检索审核 * @param {body} body 参数 * @property id 数据id * @property status 交底书要改变成的状态 * @property info 其他数据,当做多个备注,记录使用 */ async check({ id, status, remark, report, is_money }) { const data = { status, report, is_money }; if (status === '4') data['meta.state'] = 1; await this.model.updateOne({ _id: ObjectId(id) }, data); // 换成对应的状态码,record在下面 return await this.record({ id, method: status, remark }); } async record({ id, method, remark }) { let word = ''; switch (`${method}`) { case 'create': word = '已申请'; break; case 'update': word = '修改'; break; case '1': word = '审核通过'; break; case '-1': word = '审核拒绝'; break; default: word = '未知状态'; break; } const data = await this.model.findById(id); if (!data) { throw new BusinessError( ErrorCode.DATA_NOT_EXIST, '添加记录----未找到数据' ); } const obj = { time: moment().format('YYYY-MM-DD HH:mm:ss'), word, remark, }; data.record.push(obj); const res = await data.save(); this.toNotice(id, method); return res; } async toNotice(id, code) { const data = await this.model.findById(id); if (!data) return; const { user_id, admin_id, status, patent_name } = data; const arr = []; let content = ''; let to = ''; switch (code) { case 'create': content = `${patent_name}提交了价值评估的申报,请及时前往申请管理进行处理`; if (status === '0') { to = admin_id; } break; case 'update': content = `${patent_name}重新提交了价值评估的申报,请及时前往申请管理进行处理`; if (status === '0') { to = admin_id; } break; case '-1': content = `您提交的价值评估【${patent_name}】未通过管理员的审核,请您及时修改,重新申请`; to = user_id; break; case '1': content = `您提交的价值评估【${patent_name}】通过了管理员的审核,系统管理员会在3-5个工作日发出价值评估报告,以供用户下载`; to = user_id; break; case '2': content = `您提交的价值评估【${patent_name}】系统管理员已发放报告文件,请及时查看并下载`; to = user_id; break; default: break; } if (arr.length > 0) { await this.notice.insertMany(arr); } else { const obj = { to, content }; await this.notice.create(obj); } } } module.exports = PatentassessService;