import ArtImage from './artImage'; import { formatterMillisecond } from './utils/date'; import { artApi } from './artApi'; import { EditTask, Query, QueryTask } from './artUtil'; import ConditionReport from './conditionReport'; import ArtRepairPlan from './artRepairPlan'; import { repairFileStatus } from './artEnum'; import ArtRepairLog from './artRepairLog'; import { EditType } from '@airkoon/cellsys/cellsysUtil'; import { PublishStatus, PublishTarget } from '@airkoon/cellsys/cellsysEnum'; import ArtSystem from './artSystem'; import RepairFileAudit from "./repairFileAudit"; class ArtRepairFile { constructor(params = {}) { this.cellsysType = 'ArtRepairFile'; this.id = params.id; this.name = params.name; this.description = params.description; this.conditionCheckId = params.condition_check_id; //关联的状况检查记录id this.creator = params.creator; this.updater = params.updater; this.createTime = params.create_time; this.updateTime = params.update_time; this.status = params.status; this.artworkRecord = { artworkRecordId: params.artwork_record_id, //关联的艺术品id }; if (params.artwork_record) { let { record_number, old_name, images } = params.artwork_record; this.artworkRecord['recordNumber'] = record_number; this.artworkRecord['oldName'] = old_name; this.artworkRecord['artworkImages'] = images.map((url) => { return new ArtImage(url); }); } this.tags = []; if (params.tag_name) { this.tags = params.tag_name.map((name) => { return { name: name }; }); } this.orgName = params.org_name; //发布状态有关逻辑 this.isPublish = params.is_publish; this.isUnlock = params.is_unlock; this.publishRange=params.publish_range this.publishGroup = params.publish_group ? params.publish_group : []; //发布的群组 } //艺术品封面图 get coverImageUrl() { if (this.artworkRecord && this.artworkRecord['artworkImages'].length > 0) { return this.artworkRecord['artworkImages'][0].compressionUrl; } } //艺术品封面图 get oldNameFormat() { return `《${this.artworkRecord['oldName']}》`; } get createTimeFormat() { return formatterMillisecond(this.createTime); } get updateTimeFormat() { return formatterMillisecond(this.updateTime); } //修复档案归档状态 get statusMsg() { return repairFileStatus[this.status]; } //修复档案发布状态 get statusPublishMsg() { return PublishStatus[this.isPublish]; } //查询状况检查记录信息 queryConditionReport() { /*if (!this.conditionCheckId) { throw new Error("没有状况检查记录信息!"); }*/ let query = new Query(); query.addFilter('id', '=', this.conditionCheckId); //病害报告模板 let queryTask = new QueryTask(artApi.viewConditionCheck, false); return new Promise((resolve, reject) => { queryTask .execute(query) .then((res) => { let resArr = res.map((item) => { return new ConditionReport(item); }); resolve(resArr); }) .catch((err) => { reject(err); }); }); } //更新修复档案信息 updateRepairFile(params = {}) { let { name, description, conditionCheckId } = params; let editTask = new EditTask(artApi.repairRecordUpdate); editTask.addParam('_id', this.id); editTask.addParam('_description', description); editTask.addParam('_name', name); editTask.addParam('_condition_check_id', conditionCheckId); return new Promise((resolve, reject) => { editTask .execute() .then((res) => { if (res.data) { let artRepairFile = new ArtRepairFile(res.data); resolve(artRepairFile); } }) .catch((err) => { reject(err); }); }); } //创建修复方案 createRepairPlan(params) { let editTask = new EditTask(artApi.repairPlanInsert); editTask.addParam('_repair_record_id', this.id); editTask.addParam('_name', params.name); editTask.addParam('_repair_nodes', params.repairNodes); return new Promise((resolve, reject) => { editTask .execute() .then((res) => { if (res.data) { let artRepairFile = new ArtRepairPlan(res.data); resolve(artRepairFile); } }) .catch((err) => { reject(err); }); }); } //修复档案归档 repairFileArchive(params = {}) { let { signatureImage } = params; let editTask = new EditTask(artApi.repairRecordArchiveReviewInsert); editTask.addParam('_repair_record_id', this.id); editTask.addParam('_applicant_signature_image', signatureImage); return editTask.execute(); } //取消归档状态 cancelArchive(params = {}) { let { password } = params; let editTask = new EditTask(artApi.repairRecordCancelArchive); editTask.addParam('_id', this.id); editTask.addParam('_password', password); return editTask.execute(); } //创建修复记录 createRepairLog(params = {}) { let editTask = new EditTask(artApi.repairLogInsert); editTask.addParam('_repair_record_id', this.id); editTask.addParam('_description', params.description); editTask.addParam('_repair_node', params.repairNode); editTask.addParam('_images', params.images); editTask.addParam('_material_ids', params.materialIds); editTask.addParam('_restorers', params.restorers); editTask.addParam('_datetime', params.datetime); editTask.addParam('_links', params.links); editTask.addParam('_geometry', params.geometry); editTask.addParam('_geometry_name', params.geometryName); return new Promise((resolve, reject) => { editTask .execute() .then((res) => { if (res.data) { let artRepairFile = new ArtRepairLog(res.data); resolve(artRepairFile); } }) .catch((err) => { reject(err); }); }); } //更新标签关联 //@params 参数tags为标签对象数组 [{name:"标签名称"}] updateTageRel(tags) { let editTask = new EditTask(EditType.TagsGroupModeleUpdate); if (Array.isArray(tags)) { let tagNames = tags.map((tag) => { return tag.name; }); editTask.addParam('_tag_names', tagNames); } editTask.addParam('_model_code', 'repairRecord'); editTask.addParam('_model_object_id', this.id); return editTask.execute(); } //查询修复方案列表 queryRepairPlan(params = {}) { let { filter, pageInfo } = params; if (!filter) { filter = []; } filter.push({ name: 'repair_record_id', operator: '=', value: this.id, }); return ArtSystem.queryRepairPlan({ filter, pageInfo, }); } //发布共享 setPublish(publishStatus, range, ids, isEditable, remark) { let editTask = new EditTask(artApi.repairRecordPublish); editTask.addParam('_id', this.id); editTask.addParam('_repair_record_name', this.name); editTask.addParam('_is_publish', PublishTarget[publishStatus]); editTask.addParam('_remark', remark); if (publishStatus !== 'noPublish') { if (range === 1) { //发布到组织 editTask.addParam('_publish_org', ids); } else { editTask.addParam('_publish_group', ids); } editTask.addParam('_publish_range', range); } if (isEditable) { editTask.addParam('_is_update', 1); } else { editTask.addParam('_is_update', 0); } return editTask.execute(); } //查询修复记录 queryRepairLogs(params = {}) { let { filter, pageInfo } = params; if (!filter) { filter = []; } filter.push({ name: 'repair_record_id', operator: '=', value: this.id, }); return ArtSystem.queryRepairLogs({ filter, pageInfo, }); } //查询修复档案归档申请列表 queryRepairFileArchive(params = {}) { let { pageInfo, order, filters } = params; let query = new Query(); if (pageInfo) { query.setCurrPage(pageInfo.currPage); query.setPageSize(pageInfo.pageSize); } query.addFilter('repair_record_id', '=', this.id); //查询审核中的记录 if (filters && filters.length > 0) { filters.forEach((item) => { query.addFilter(item['name'], item['operator'], item['value']); }); } let queryTask = new QueryTask(artApi.viewRepairRecordArchiveReview, !!pageInfo); return new Promise((resolve, reject) => { queryTask .execute(query) .then((res) => { if (pageInfo) { if (res.data) { res.data = res.data.map((item) => { return new RepairFileAudit(item); }); resolve(res); } } else { let resArr = res.map((item) => { return new RepairFileAudit(item); }); resolve(resArr); } }) .catch((err) => { reject(err); }); }); } } export default ArtRepairFile;