import { Query, QueryTask, QueryType, Operator, } from "@airkoon/cellsys/cellsysUtil.js"; import ConditionReport from "./conditionReport"; import { artApi } from "./artApi"; import CellsysArt from "./cellsysArt"; import CellsysEventType from "@airkoon/cellsys/cellsysEventType"; import ArtCounty from "./artCounty"; import { EditTask } from "@airkoon/cellsys/cellsysUtil"; import ArtRepairFile from "./artRepairFile"; import ArtRepairPlan from "./artRepairPlan"; import * as http from "@airkoon/cellsys/utils/axios"; class ArtSystem { constructor(orgId) {} static orgId = window.CELLSYSORG ? window.CELLSYSORG.id : null; //查询艺术品材质字典 static queryMaterials(params = {}) { let query = new Query(); let { filter } = params; if (filter) { filter.forEach((item) => { query.addFilter(item["name"], item["operator"], item["value"]); }); } query.addFilter("dict_type", Operator.Equals, "material"); let queryTask = new QueryTask(QueryType.sysDictData, false); return new Promise((resolve, reject) => { queryTask .execute(query) .then((res) => { resolve(res); }) .catch((err) => { reject(err); }); }); } //查询艺术品一级分类 static queryArtCategoryOne() { let query = new Query(); query.addFilter("parent_id", Operator.Equals, 1); query.setOrder({ sort: "asc" }); let queryTask = new QueryTask(QueryType.sysCategoryData, false); return new Promise((resolve, reject) => { queryTask .execute(query) .then((res) => { resolve(res); }) .catch((err) => { reject(err); }); }); } static queryArtCategoryById(parentId) { let query = new Query(); query.addFilter("parent_id", Operator.Equals, parentId); let queryTask = new QueryTask(QueryType.sysCategoryData, false); return new Promise((resolve, reject) => { queryTask .execute(query) .then((res) => { resolve(res); }) .catch((err) => { reject(err); }); }); } //查询国家数据 static queryCountry(params = {}) { let query = new Query(); let { pageInfo, order, filter } = params; if (filter) { filter.forEach((item) => { query.addFilter(item["name"], item["operator"], item["value"]); }); } let queryTask = new QueryTask(artApi.country, !!pageInfo); return new Promise((resolve, reject) => { queryTask .execute(query) .then((res) => { if (pageInfo) { if (res.data) { res.data = res.data.map((item) => { return new ArtCounty(item); }); resolve(res); } } else { let resArr = res.map((item) => { return new ArtCounty(item); }); resolve(resArr); } }) .catch((err) => { reject(err); }); }); } //查询艺术片档案 static queryArtworks(params = {}) { let query = new Query(); let { pageInfo, order, filter } = params; if (pageInfo) { query.setCurrPage(pageInfo.currPage); query.setPageSize(pageInfo.pageSize); } if (filter) { filter.forEach((item) => { query.addFilter(item["name"], item["operator"], item["value"]); }); } if (order) { query.setOrder(order); } else { query.setOrder({ id: "desc" }); } let queryTask = new QueryTask( artApi.artworkRecord, pageInfo ? true : false ); return new Promise((resolve, reject) => { queryTask .execute(query) .then((res) => { if (pageInfo) { if (res.data) { res.data = res.data.map((item) => { return new CellsysArt(item); }); resolve(res); } } else { let resArr = res.map((item) => { return new CellsysArt(item); }); resolve(resArr); } }) .catch((err) => { reject(err); }); }); } //创建艺术品档案 static createArtwork(params = {}) { let editTask = new EditTask(artApi.artArtworkRecordInsert); editTask.addParam("_oldname", params.oldName); editTask.addParam("_countryId", params.country.id); editTask.addParam("_countryCode", params.country.code); editTask.addParam("_author", params.author); editTask.addParam("_create_period", params.createPeriod); editTask.addParam("_actual_number", params.actualNumber); 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); } if (params.categoryOne) { editTask.addParam("_category_one", params.categoryOne.id); editTask.addParam("_category_one_code", params.categoryOne.code); } if (params.categoryTwo) { editTask.addParam("_category_two", params.categoryTwo.id); editTask.addParam("_category_two_code", params.categoryTwo.code); } if (params.categoryThree) { editTask.addParam("_category_three", params.categoryThree.id); } 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); }); }); } //查询报告列表(应用列表) static queryConditionsReports(params) { if (!params) { params = {}; } let query = new Query(); let pageInfo = params.pageInfo; let order = params.order; if (pageInfo) { query.setCurrPage(pageInfo.currPage); query.setPageSize(pageInfo.pageSize); } if (order) { query.setOrder(order); } else { query.setOrder({ id: "desc" }); } // query.addFilter('model_id', Operator.Equals, 23); //病害报告模板 let filter = params.filter; if (filter) { filter.forEach((item) => { query.addFilter(item["name"], item["operator"], item["value"]); //病害报告模板 }); } let queryTask = new QueryTask( artApi.viewConditionCheck, pageInfo ? true : false ); 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 { let resArr = res.map((item) => { return new ConditionReport(item); }); resolve(resArr); } }) .catch((err) => { reject(err); }); }); } static queryArtworkByRepairId(params) { let query = new Query(); let artworkId = params.artworkId; let eventSetId = params.eventSetId; if (artworkId) { query.addFilter("artwork.id", Operator.Equals, artworkId); //病害报告模板 } if (eventSetId) { query.addFilter("event_set.id", Operator.Equals, eventSetId); //病害报告模板 } let queryTask = new QueryTask(artApi.artworkRepair, false); return new Promise((resolve, reject) => { queryTask .execute(query) .then((res) => { let resArr = res.map((item) => { return new CellsysArt(item.artwork); }); resolve(resArr); }) .catch((err) => { reject(err); }); }); } static queryArtworkEvent(params) { let query = new Query(); let artworkId = params.artworkId; if (artworkId) { query.addFilter("artwork.id", Operator.Equals, artworkId); //病害报告模板 } let queryTask = new QueryTask(artApi.artworkRepair, false); return new Promise((resolve, reject) => { queryTask .execute(query) .then((res) => { let resArr = res.map((item) => { return new CellsysEventType(item.event_set); }); resolve(resArr); }) .catch((err) => { reject(err); }); }); } //查询系统修复档案列表 static queryRepairFiles(params) { let query = new Query(); let { filter, pageInfo } = params; if (filter) { filter.forEach((item) => { query.addFilter(item["name"], item["operator"], item["value"]); }); } let queryTask = new QueryTask(artApi.viewRepairRecord, !!pageInfo); return new Promise((resolve, reject) => { queryTask .execute(query) .then((res) => { if (pageInfo) { if (res.data) { res.data = res.data.map((item) => { return new ArtRepairFile(item); }); resolve(res); } else { reject(new Error("修复档案数据格式异常")); } } else { let resArr = res.map((item) => { return new ArtRepairFile(item); }); resolve(resArr); } }) .catch((err) => { reject(err); }); }); } static queryRepairPlan(params) { let query = new Query(); let { filter, pageInfo } = params; if (filter) { filter.forEach((item) => { query.addFilter(item["name"], item["operator"], item["value"]); }); } let queryTask = new QueryTask(artApi.viewRepairPlan, !!pageInfo); return new Promise((resolve, reject) => { queryTask .execute(query) .then((res) => { if (pageInfo) { if (res.data) { res.data = res.data.map((item) => { return new ArtRepairPlan(item); }); resolve(res); } else { reject(new Error("修复方案数据格式异常")); } } else { let resArr = res.map((item) => { return new ArtRepairPlan(item); }); resolve(resArr); } }) .catch((err) => { reject(err); }); }); } //统一图片上传 static uploadImage(params = {}) { let { files, module } = params; let fd = new FormData(); fd.append("file", files); fd.append("module", module); return http.post(`/v2${artApi.artUploadPicture}`, fd, { headers: { "Content-Type": "multipart/form-data", }, }); } } export default ArtSystem;