import { assert } from 'chai'; import { fileUtils } from '../../file/file-utils'; import { request } from '../../rpc/request'; import { printError, printSuccess } from '../../utils/print'; import { BaseDTO } from '../base/BaseDTO'; export class SpecialAuctionItemDetailDTO extends BaseDTO { url: string = ''; artCode: string = 'art5204960008'; show_title: string = '知竹山房 青花璎珞开窗婴戏提梁壶'; coverPic: string = 'https://auction1-img.artimg.net/Img/image?src=https://image.artron.net/d/auction/118/art/58537/0bb69aad87507f763d929f9cd0bbcc0e.jpg&w=350&h=350'; status: number = 5; isJoinTuLu: number = 0; isHD: number = 1; // 拍品名称 workName: string = '艺林藏珍 墨彩麒麟显瑞图圆融杯'; // 拍品分类 itemType: string = '陶瓷>现当代及其它瓷器'; // 尺寸 itemSize: string = '直径9.2cm'; // 估价 itemGuJIa: string = 'RMB 20,000-30,000'; // 成交价 itemDeal: string = 'RMB 32,200'; // 拍卖日期 auctionDate: string = '2022-11-12 下午14:00'; // 拍卖公司 auctionCompany: string = '北京保利'; //拍卖专场 百年薪火 槌响瓷博—近现代景德镇陶瓷专场 auctionSession: string = '百年薪火 槌响瓷博—近现代景德镇陶瓷专场'; //拍卖会 百年薪火 槌响瓷博——近现代景德镇陶瓷专场拍卖会 auctionSpecial: string = '百年薪火 槌响瓷博——近现代景德镇陶瓷专场拍卖会'; // 题识 底款:“艺林藏珍” tishi: string = '底款:“艺林藏珍”'; // 拍品描述 xxx description: string = 'xxx'; auctionAddress: string = ''; lot: string = ''; organCode: string = ''; sessionCode: string = ''; specialCode: string = ''; logoUrl: string = ''; bigPic: string = ''; middlePic: string = ''; bigPicArray: string[] = []; private get bigPicListStr(): string { return this.bigPicArray.join(',\r\n'); } private get content(): string { return ( `LOT:${this.lot}\r\n` + `url:${this.url}\r\n` + `拍品名称:${this.workName}\r\n` + `拍品分类:${this.itemType}\r\n` + `尺寸:${this.itemSize}\r\n` + `估价:${this.itemGuJIa}\r\n` + `成交价:${this.itemDeal}\r\n` + `拍卖日期:${this.auctionDate}\r\n` + `拍卖公司:${this.auctionCompany}\r\n` + `拍卖专场:${this.auctionSpecial}\r\n` + `拍卖会:${this.auctionSession}\r\n` + `题识:${this.tishi}\r\n` + `拍品描述:${this.description}\r\n` + `大图:${this.bigPicListStr}\r\n` ); } static createWithJson(json: any): SpecialAuctionItemDetailDTO { const dto = new SpecialAuctionItemDetailDTO(); assert.isObject(json, 'auction detail is not an object'); assert.isObject(json?.pageProDetail, 'auction pageProDetail is not an object'); assert.isObject(json?.pageProDetail?.data, 'auction pageProDetail data is not an object'); const data = json.pageProDetail.data; const detail = data.detail; dto.artCode = data.artCode; dto.show_title = data.show_title; dto.coverPic = data.coverPic; dto.status = data.status; dto.isJoinTuLu = data.isJoinTuLu; dto.isHD = data.isHD; dto.workName = detail.workName; const extraInfo = detail.extraInfo; extraInfo.forEach((item: any) => { if (item.label === '拍品分类') dto.itemType = item.text; if (item.label === '尺寸') dto.itemSize = item.text; if (item.label === '估价') dto.itemGuJIa = `${item.smallText} ${item.text}`; if (item.label === '成交价') dto.itemDeal = `${item.smallText} ${item.text}`; if (item.label === '题识') dto.tishi = item.text; if (item.label === '拍品描述') dto.description = item.fullText; }); dto.lot = detail.tlNumber; const attribute = detail.attribute; attribute.forEach((item: any) => { if (item.type === 'company') { dto.auctionCompany = item.text; dto.organCode = item.organCode; } if (item.type === 'session') { dto.auctionSession = item.text; dto.sessionCode = item.sessionCode; } if (item.type === 'special') { dto.auctionSpecial = item.text; dto.specialCode = item.specialCode; } if (item.label === '拍卖日期') dto.auctionDate = item.text; if (item.label === '拍卖地点') dto.auctionAddress = item.text; }); dto.logoUrl = detail.logoUrl; dto.bigPic = detail.bigPic; dto.middlePic = detail.middlePic; dto.bigPicArray = []; detail.bigPicArray.forEach((item: any) => { const url = item.split('src='); dto.bigPicArray.push(url.length > 1 ? url[1] : url[0]); }); return dto; } public async downloadImages(dir: string, fileName: string): Promise { return new Promise(async (resolve, reject) => { for (let i = 0; i < this.bigPicArray.length; i++) { const url = this.bigPicArray[i]; const file = `${dir}${fileName}_${i}.jpg`; if (fileUtils.isExist(file)) { continue; } try { console.log(url); let response = await request.doGet(url, { responseType: 'stream' }); fileUtils.writeFile(file); let stream = fileUtils.createWriteStream(file); response.data.pipe(stream); printSuccess(`下载成功:${this.lot}, ${this.workName}`); } catch (picErr) { // console.log(picErr); printError(`下载没成功:${this.lot}, ${this.workName}`); } } resolve(); }); } public async saveContent(fileName: string) { if (fileUtils.isExist(fileName)) { return; } fileUtils.writeFile(fileName, this.content); } }