cellsysArt/cellsysArt.js

214 lines
6.0 KiB
JavaScript
Raw Normal View History

2024-12-26 10:28:43 +08:00
import ArtImage from "./artImage";
import { artStatus } from "./artEnum";
import {
EditTask,
EditType,
2025-01-03 09:52:13 +08:00
Operator,
2024-12-26 10:28:43 +08:00
Query,
QueryTask,
} from "@airkoon/cellsys/cellsysUtil";
import { artApi } from "./artApi";
2025-01-03 09:52:13 +08:00
import ArtRepairFile from "./artRepairFile";
import ConditionReport from "./conditionReport";
2024-12-26 10:28:43 +08:00
class CellsysArt {
constructor(params = {}) {
this.id = params.id;
this.oldName = params.old_name; //不带书名号
this.recordNumber = params.record_number;
this.artworkName = params.artwork_name;
this.author = params.author;
this.createPeriod = params.create_period;
this.actualNumber = params.actual_number || 1;
this.materialId = params.material_id;
this.materialName = params.material_name;
this.countryId = params.country_id;
this.countryName = params.country_name;
this.length = params.length;
this.width = params.width;
this.height = params.height;
this.categoryOne = params.category_one;
this.categoryOneName = params.category_one_name;
this.categoryTwo = params.category_two;
this.categoryTwoName = params.category_two_name;
this.categoryThree = params.category_three;
this.categoryThreeName = params.category_three_name;
this.originalRegistrationNumber = params.original_registration_number;
this.remark = params.remark;
this.creator = params.creator;
this.updater = params.updater;
this.status = params.status;
this.artworkImages = [];
if (params.images) {
this.artworkImages = params.images.map((url) => {
return new ArtImage(url);
});
}
this.tags = [];
if (params.tag_name) {
this.tags = params.tag_name.map((name) => {
return { name: name };
});
}
}
get oldNameFormat() {
//带书名号
return `${this.oldName}`;
}
//封面图
get coverImageUrl() {
if (this.artworkImages.length > 0) {
return this.artworkImages[0].compressionUrl;
}
}
2025-01-03 09:52:13 +08:00
get statusMsg() {
return artStatus[this.status];
}
2024-12-26 10:28:43 +08:00
get artworkImagesUrl() {
if (this.artworkImages.length > 0) {
return this.artworkImages.map((artImage) => {
return artImage.url;
});
}
}
get statusMsg() {
return artStatus[this.status];
}
//查看艺术品详情
getDetails() {
let editTask = new EditTask(artApi.artworkDetails);
editTask.addParam("_id", this.id);
return new Promise((resolve, reject) => {
editTask
.execute()
.then((res) => {
if (res.data) {
let cellsysArt = new CellsysArt(res.data);
//todo 详情字段填充
resolve(cellsysArt);
}
})
.catch((err) => {
reject(err);
});
});
}
//编辑艺术品档案
updateArtwork(params = {}) {
let editTask = new EditTask(artApi.artArtworkRecordUpdate);
editTask.addParam("_id", params.id);
editTask.addParam("_oldname", params.oldName);
editTask.addParam("_author", params.author);
editTask.addParam("_create_period", params.createPeriod);
editTask.addParam("_length", params.length);
editTask.addParam("_width", params.width);
editTask.addParam("_height", params.height);
if (params.material) {
editTask.addParam("_material", params.material.dict_code);
}
editTask.addParam(
"_original_registration_number",
params.originalRegistrationNumber
);
editTask.addParam("_remark", params.remarks);
editTask.addParam("_images", params.images);
return new Promise((resolve, reject) => {
editTask
.execute()
.then((res) => {
if (res.data) {
let cellsysArt = new CellsysArt(res.data);
resolve(cellsysArt);
}
})
.catch((err) => {
reject(err);
});
});
}
//删除艺术品档案
removeArtwork(params = {}) {
let editTask = new EditTask(artApi.artArtworkRecordDelete);
editTask.addParam("_id", this.id);
editTask.addParam("_password", params.password);
return new Promise((resolve, reject) => {
editTask
.execute()
.then((res) => {
resolve(res);
})
.catch((err) => {
reject(err);
});
});
}
2025-01-03 09:52:13 +08:00
//创建修复档案
createRepairFile(params = {}) {
let { name, description, conditionCheckId } = params;
let editTask = new EditTask(artApi.repairRecordInsert);
editTask.addParam("_artwork_record_id", this.id);
editTask.addParam("_description", description);
editTask.addParam("_name", name);
editTask.addParam("_condition_check_id", conditionCheckId);
2024-12-26 10:28:43 +08:00
return new Promise((resolve, reject) => {
2025-01-03 09:52:13 +08:00
editTask
.execute()
2024-12-26 10:28:43 +08:00
.then((res) => {
2025-01-03 09:52:13 +08:00
if (res.data) {
let artRepairFile = new ArtRepairFile(res.data);
resolve(artRepairFile);
}
})
.catch((err) => {
reject(err);
});
});
}
//查询修复状况检查记录
queryConditionRecords(params = {}) {
let query = new Query();
query.addFilter("artwork_record_id", Operator.Equals, this.id); //病害报告模板
let { filter, pageInfo } = params;
if (filter) {
filter.forEach((item) => {
query.addFilter(item["name"], item["operator"], item["value"]);
});
}
let queryTask = new QueryTask(artApi.viewConditionCheck, !!pageInfo);
return new Promise((resolve, reject) => {
queryTask
.execute(query)
.then((res) => {
if (pageInfo) {
if (res.data) {
res.data = res.data.map((item) => {
return new ConditionReport(item);
});
resolve(res);
} else {
reject(new Error("状况检查记录数据格式异常!"));
}
} else {
let resArr = res.map((item) => {
return new ConditionReport(item);
});
resolve(resArr);
}
2024-12-26 10:28:43 +08:00
})
.catch((err) => {
reject(err);
});
});
}
}
export default CellsysArt;