cellsysArt/cellsysArt.js
zhangqg 185e53f256 1、增加查询艺术品关联的材料消息
2、修复档案获取封面图判断优化
3、移除无用的orgid属性
4、优化材料库字段
5、调整cellsysBase引用路径
2025-03-31 09:42:42 +08:00

310 lines
10 KiB
JavaScript

import ArtImage from './artImage';
import { artStatus } from './artEnum';
import { EditTask, Query, QueryTask } from './artUtil';
import { artApi } from './artApi';
import ArtRepairFile from './artRepairFile';
import ConditionReport from './conditionReport';
import ArtCategory from './artCategory';
import { formatterMillisecond } from './utils/date';
import ArtSystem from './artSystem';
import Material from './material';
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.textureId = params.texture_id; //材质id
this.textureName = params.texture_name; //材质名称
this.countryId = params.country_id;
this.countryName = params.country_name;
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.createTime = params.create_time;
this.updater = params.updater;
this.updateTime = params.update_time;
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 };
});
}
this.materialIds = params.material_ids; //材料Id数组
this.geometry = params.geometry; //当前位置
this.size = [];
if (params.size && params.size.length > 0) {
this.size = params.size.map((item) => {
return new ArtSize(item);
});
}
}
get oldNameFormat() {
//带书名号
return `${this.oldName}`;
}
//封面图
get coverImageUrl() {
if (this.artworkImages.length > 0) {
return this.artworkImages[0].compressionUrl;
}
}
get statusMsg() {
return artStatus[this.status];
}
get artworkImagesUrl() {
if (this.artworkImages.length > 0) {
return this.artworkImages.map((artImage) => {
return artImage.url;
});
}
}
get statusMsg() {
return artStatus[this.status];
}
get createTimeFormat() {
return formatterMillisecond(this.createTime);
}
get updateTimeFormat() {
return formatterMillisecond(this.updateTime);
}
//查看艺术品详情
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);
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);
if (params.texture) {
editTask.addParam('_texture', params.texture.dict_code);
}
editTask.addParam('_original_registration_number', params.originalRegistrationNumber);
editTask.addParam('_remark', params.remarks);
editTask.addParam('_images', params.images);
if (params.size && params.size.length > 0) {
editTask.addParam(
'_size',
params.size.map((item) => {
return item.toParams();
}),
);
}
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);
});
});
}
//创建修复档案
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);
return new Promise((resolve, reject) => {
editTask
.execute()
.then((res) => {
if (res.data) {
let artRepairFile = new ArtRepairFile(res.data);
resolve(artRepairFile);
}
})
.catch((err) => {
reject(err);
});
});
}
//查询艺术品所有修复档案
queryRepairFiles(params = {}) {
let { filter, pageInfo } = params;
if (!filter) {
filter = [];
}
filter.push({
name: 'artwork_record_id',
operator: '=',
value: this.id,
});
return ArtSystem.queryRepairFiles({
filter,
pageInfo,
});
}
//查询修复状况检查记录
queryConditionRecords(params = {}) {
let query = new Query();
query.addFilter('artwork_record_id', '=', 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);
}
})
.catch((err) => {
reject(err);
});
});
}
//获取艺术品所属类别的病害信息
queryCategoryDiseases() {
/* if (!this.categoryTwo) {
throw new Error('该艺术品没有二级类别,无法获取类别病害信息!');
}*/
let artCategory = new ArtCategory({
id: this.categoryTwo,
name: this.categoryTwoName,
});
return artCategory.queryDisease();
}
//获取艺术品关联的材料数据
queryArtMaterials(params = {}) {
let query = new Query();
let { filter } = params;
query.addFilter('artwork_record_id', '=', this.id); //病害报告模板
if (filter) {
filter.forEach((item) => {
query.addFilter(item['name'], item['operator'], item['value']);
});
}
let queryTask = new QueryTask(artApi.viewArtworkMaterial, false);
return new Promise((resolve, reject) => {
queryTask
.execute(query)
.then((res) => {
let resArr = res.map((item) => {
return new Material(item);
});
resolve(resArr);
})
.catch((err) => {
reject(err);
});
});
}
}
class ArtSize {
constructor(params = {}) {
let { name, width, length, height, leftTopRightBottom, leftBottomRightTop } = params;
this.name = name;
this.length = length;
this.width = width;
this.height = height;
this.leftTopRightBottom = leftTopRightBottom;
this.leftBottomRightTop = leftBottomRightTop;
}
//转化成接口保存所需要的格式
toParams() {
return {
name: this.name,
length: parseFloat(Number(this.length).toFixed(2)),
width: parseFloat(Number(this.width).toFixed(2)),
height: parseFloat(Number(this.height).toFixed(2)),
leftTopRightBottom: parseFloat(Number(this.leftTopRightBottom).toFixed(2)),
leftBottomRightTop: parseFloat(Number(this.leftBottomRightTop).toFixed(2)),
};
}
}
export { ArtSize };
export default CellsysArt;