import { assert } from 'chai'; import * as cheerio from 'cheerio'; import { configs } from '../../auction/config'; import { request } from '../../rpc/request'; import { moneyThSplit } from '../../utils/money'; import { printError } from '../../utils/print'; import { BaseDTO } from '../base/BaseDTO'; import { SpecialAuctionItemDetailDTO } from './SpecialAuctionItemDetailDTO'; import { SpecialAuctionMetaDTO } from './SpecialAuctionMetaDTO'; /** * { Id: 10911320, OrganId: 5, SessionId: 15592, SpecialId: 58637, ArtCode: 'art0112902511', TlNumber: '2511', IsEvaluation: 1, EvaluationType: 0, OriginalEvaluation: 10000, LastEvaluation: 20000, CurrencyType: 'RMB', CurrencyPrice: 287500, AuctionStatus: 0, RMBPrice: 287500, HKDPrice: 321741, IsPermit: 0, Date: '2022-12-26', Status: 0, WorkName: '明崇祯 青花云龙纹大碗', Folder: 'https://image.artron.net/d/auction/5/art/58614/', FileName: 'https://auction1-img.artimg.net/Img/image?h=560&src=https%3A%2F%2Fimage.artron.net%2Fd%2Fauction%2F5%2Fart%2F58614%2F3217dd71319644ddff6227a223d16ad5.jpg&w=560', FolderSmall: '', Title: '青花云龙纹大碗', IsBigPic: 1, AuthorName: '', SpecialCode: 'PZ2057111', SessionCode: 'PMH214514' extInfo: { } }, */ export class SpecialAuctionListItemDTO extends BaseDTO { Id = ''; OrganId = 0; SessionId = 15592; SpecialId = 58637; ArtCode = 'art0112902511'; TlNumber = '2511'; IsEvaluation = 1; EvaluationType = 0; OriginalEvaluation = 10000; LastEvaluation = 20000; CurrencyType = 'RMB'; CurrencyPrice = 287500; AuctionStatus = 0; RMBPrice = 287500; HKDPrice = 321741; IsPermit = 0; Date = '2022-12-26'; Status = 0; WorkName = '明崇祯 青花云龙纹大碗'; Folder = 'https=//image.artron.net/d/auction/5/art/58614/'; FileName = 'https=//auction1-img.artimg.net/Img/image?h=560&src=https%3A%2F%2Fimage.artron.net%2Fd%2Fauction%2F5%2Fart%2F58614%2F3217dd71319644ddff6227a223d16ad5.jpg&w=560'; FolderSmall = ''; Title = '青花云龙纹大碗'; IsBigPic = 1; AuthorName = ''; SpecialCode = 'PZ2057111'; SessionCode = 'PMH214514'; private _auctionDetail: SpecialAuctionMetaDTO = null!; public set auctionDetail(value: SpecialAuctionMetaDTO) { this._auctionDetail = value; } public get lot(): string { return this.TlNumber; } public get auctionUrl(): string { return `https://auction.artron.net/paimai-${this.ArtCode}`; } private _size: string = null!; public get size(): string { return this._size ? this._size : '不知道'; } private formatName(str: string) { return str.replace(configs.separator, '&'); } public get fileNamePrefix(): string { let name = `LOT号:${this.lot}_${this.formatName(this.WorkName)}_估价:${ this.CurrencyType } ${moneyThSplit(this.OriginalEvaluation)}-${moneyThSplit(this.LastEvaluation)}_成交价:${ this.CurrencyType } ${moneyThSplit(this.CurrencyPrice)}_城市:${this.formatName( this._auctionDetail.city )}_日期:${this.formatName(this._auctionDetail.auction_date)}_${ this._auctionDetail.organ_name }_${this.formatName(this._auctionDetail.auction_place)}_尺寸:${this.size}`.replace( /:/g, ':' ); let nameArr = name.split('/'); name = nameArr.length > 1 ? nameArr.join('#') : name; nameArr = name.split(configs.separator); name = nameArr.length > 1 ? nameArr.join('#') : name; return name .replace(/\*/g, '') .replace(/\?/g, '') .replace(/\:/g, '') .replace(/\|/g, '') .replace(/\/g, ''); } public get txtFileName(): string { return `${this.fileNamePrefix}.txt`; } private async analysisInfo(): Promise { const web = await request.doGet(this.auctionUrl); const $ = cheerio.load(web.data); const scripts = $('script'); assert.isTrue( scripts.length > 0, `获取拍卖明细会页面数据失败:${this.ArtCode}, ${this.WorkName}` ); const html = $(scripts[0]).html(); const metaData = html?.split( ';(function(){var s;(s=document.currentScript||document.scripts[document.scripts.length-1]).parentNode.removeChild(s);}());' ); assert.isTrue( metaData && metaData.length > 0, `获取拍卖明细meta数据失败${this.ArtCode}, ${this.WorkName}` ); const info = metaData![0]; const auctionData = info.split('window.__INITIAL_STATE__=')[1]; try { const data = JSON.parse(auctionData); const item = SpecialAuctionItemDetailDTO.createWithJson(data); item.url = this.auctionUrl; return item; } catch (e) { console.error(auctionData); } return null; } public async analysis() { const dir = this._auctionDetail.dir; const detail = await this.analysisInfo(); if (!detail) { printError( `分析失败,请自行下载此图:${this.ArtCode}, ${this.WorkName}, ${this.auctionUrl}` ); return; } this._size = detail.itemSize; detail.saveContent(`${dir}${this.txtFileName}`); await detail.downloadImages(dir, this.fileNamePrefix); } }