InheritorContent.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. import { DataModel, transformArrayDataModel, transformDataModel } from '@imengyu/js-request-transform';
  2. import { AppServerRequestModule } from '../RequestModules';
  3. import dayjs from 'dayjs';
  4. import { transformSomeToArray } from '../Utils';
  5. export class CommonInfo<T extends DataModel> extends DataModel<T> {
  6. constructor(classCreator?: (new () => T) | undefined, name: string = '基础信息') {
  7. super(classCreator, name);
  8. this.setNameMapperCase('Camel', 'Snake');
  9. this._convertTable = {
  10. id: { clientSide: 'number', serverSide: 'number', clientSideRequired: true },
  11. flag: { clientSide: 'splitCommaArray', serverSide: 'commaArrayMerge' },
  12. type: { clientSide: 'number', serverSide: 'number' },
  13. keywords: { clientSide: 'splitCommaArray', serverSide: 'commaArrayMerge' },
  14. images: { clientSide: 'array', serverSide: 'string' },
  15. expandInfo: { serverSide: 'undefined' },
  16. region: { clientSide: 'number', serverSide: 'number' },
  17. };
  18. }
  19. contentId = null as number|null;
  20. collectId = null as number|null;
  21. title = '' as string;
  22. region = null as number|null;
  23. image = null as string|null;
  24. imageDesc = '' as string|null;
  25. images = [] as string[];
  26. audio = '' as string|null;
  27. video = '' as string|null;
  28. flag = [] as string[];
  29. keywords = [] as string[];
  30. tags = '' as string;
  31. associationId = 0 as number;
  32. pid = 0 as number;
  33. content = '' as string|null;
  34. }
  35. export class IchInfo extends CommonInfo<IchInfo> {
  36. constructor() {
  37. super(IchInfo, "非遗项目信息");
  38. this._convertTable = {
  39. ...this._convertTable,
  40. lonlat: { serverSide: 'undefined' },
  41. batch: { clientSide: 'number', serverSide: 'string' },
  42. typicalImages: [
  43. {
  44. clientSide: 'object',
  45. clientSideChildDataModel: {
  46. convertTable: {},
  47. },
  48. serverSide: 'string'
  49. },
  50. {
  51. clientSide: 'addDefaultValue',
  52. clientSideParam: {
  53. defaultValue: [],
  54. }
  55. },
  56. ],
  57. };
  58. this._convertKeyType = (key, direction) => {
  59. if (key.endsWith('Text') || key.endsWith('_text')) {
  60. return {
  61. clientSide: 'string',
  62. serverSide: 'undefined',
  63. };
  64. }
  65. };
  66. this._afterSolveServer = (self) => {
  67. self.lonlat = [ self.longitude, self.latitude ];
  68. };
  69. this._afterSolveClient = (data) => {
  70. data.longitude = this.lonlat[0];
  71. data.latitude = this.lonlat[1];
  72. };
  73. this._beforeSolveClient = (data) => {
  74. if (!this.expandInfo)
  75. this.expandInfo = new IchExpandInfo();
  76. this.expandInfo.batch = this.batch;
  77. this.expandInfo.region = this.region;
  78. this.expandInfo.image = this.image;
  79. this.expandInfo.level = this.level!;
  80. this.expandInfo.ichType = this.ichType!;
  81. this.expandInfo.contentId = this.contentId!;
  82. this.expandInfo.collectId = this.collectId!;
  83. };
  84. }
  85. lonlat = [] as (number|string)[];
  86. expandInfo : IchExpandInfo|null = new IchExpandInfo();
  87. id = 0 as number;
  88. modelId = 2;
  89. mainBodyColumnId = 0 as number;
  90. ztImage = '' as string|null;
  91. intro = '' as string;
  92. description = '' as string;
  93. heritage = null as number|null;
  94. level = null as number|null;
  95. ichType = null as number|null;
  96. batch = '' as string;
  97. longitude = '' as string;
  98. latitude = '' as string;
  99. mapX = '' as string|null;
  100. mapY = '' as string|null;
  101. unit = '' as string;
  102. address = '' as string|null;
  103. declarationRegion = '' as string;
  104. popularRegion = '' as string;
  105. approveTime = '' as string;
  106. typicalImages = [] as {
  107. form: string,
  108. mobile: string,
  109. desc: string,
  110. url: string,
  111. }[];
  112. thumbnail = '' as string;
  113. flagText = '' as string;
  114. typeText = '' as string;
  115. openStatusText = '' as string;
  116. statusText = '' as string;
  117. regionText = '' as string;
  118. levelText = '' as string;
  119. crTypeText = '' as string;
  120. ichTypeText = '' as string;
  121. claimStatusText = '' as string;
  122. isMultipleClaimsText = '' as string;
  123. batchText = '' as string;
  124. ichSiteTypeText = '' as string;
  125. }
  126. export class IchExpandInfo extends DataModel<IchExpandInfo> {
  127. constructor() {
  128. super(IchExpandInfo, "非遗项目信息");
  129. this.setNameMapperCase('Camel', 'Snake');
  130. this._convertTable = {
  131. protectLevel: { clientSide: 'number', serverSide: 'string' },
  132. id: { clientSide: 'number', serverSide: 'undefined' },
  133. };
  134. this._convertKeyType = (key, direction) => {
  135. if (key.endsWith('Text') || key.endsWith('_text')) {
  136. return {
  137. clientSide: 'string',
  138. serverSide: 'undefined',
  139. };
  140. }
  141. if (key.endsWith('At')) {
  142. return {
  143. clientSide: 'date',
  144. serverSide: 'undefined',
  145. };
  146. }
  147. };
  148. this._afterSolveServer = (self) => {
  149. };
  150. this._afterSolveClient = (data) => {
  151. };
  152. }
  153. id = 0 as number;
  154. modelId = 2;
  155. userId = 0 as number;
  156. reviewId = 0 as number;
  157. originId = '' as string|null;
  158. contentId = 0 as number;
  159. name = '' as string;
  160. level = 0 as number;
  161. ichType = 0 as number;
  162. protectLevel = null as number|null;
  163. image = '' as string|null;
  164. images = [] as string[];
  165. otherNames = '' as string|null;
  166. history = false;
  167. existence = false;
  168. folkCulture = '' as string|null;
  169. culturalRelic = '' as string|null;
  170. description = '' as string|null;
  171. desc = '' as string;
  172. mapX = '' as string|null;
  173. mapY = '' as string|null;
  174. declarationRegion = '' as string|null;
  175. popularRegion = '' as string|null;
  176. createdAt = '' as string;
  177. updatedAt = '' as string;
  178. deletedAt = '' as string|null;
  179. progress = 0 as number;
  180. comment = '' as string;
  181. levelText = '' as string;
  182. ichTypeText = '' as string;
  183. protectLevelText = '' as string;
  184. progressText = '' as string;
  185. }
  186. export class InheritorInfo extends CommonInfo<InheritorInfo> {
  187. constructor() {
  188. super(InheritorInfo, "传承人信息");
  189. this._convertTable = {
  190. ...this._convertTable,
  191. gender: { clientSide: 'number', serverSide: 'string' },
  192. level: { clientSide: 'number', serverSide: 'string' },
  193. batch: { clientSide: 'number', serverSide: 'string' },
  194. typicalImages: [
  195. {
  196. clientSide: 'object',
  197. clientSideChildDataModel: {
  198. convertTable: {},
  199. },
  200. serverSide: 'string'
  201. },
  202. {
  203. clientSide: 'addDefaultValue',
  204. clientSideParam: {
  205. defaultValue: [],
  206. }
  207. },
  208. ],
  209. works: {
  210. clientSide: 'array',
  211. clientSideChildDataModel: InheritorWorkInfo,
  212. serverSide: 'array'
  213. },
  214. };
  215. this._convertKeyType = (key, direction) => {
  216. if (key.endsWith('Text') || key.endsWith('_text')) {
  217. return {
  218. clientSide: 'string',
  219. serverSide: 'undefined',
  220. };
  221. }
  222. };
  223. }
  224. expandInfo : InheritorExpandInfo|null = new InheritorExpandInfo();
  225. id = 0 as number;
  226. modelId = 7;
  227. mainBodyColumnId = 0 as number;
  228. alsoName = '' as string|null;
  229. nation = '' as string;
  230. dateBirth = '' as string;
  231. deathBirth = '' as string|null;
  232. unit = '' as string;
  233. content = '' as string|null;
  234. intro = '' as string;
  235. prize = '' as string;
  236. level = null as number|null;
  237. gender = 0 as number;
  238. batch = '' as string|null;
  239. typicalImages = [] as string[];
  240. progress = 0 as number;
  241. contentId = 0 as number;
  242. thumbnail = '' as string;
  243. flagText = '' as string;
  244. typeText = '' as string;
  245. openStatusText = '' as string;
  246. statusText = '' as string;
  247. regionText = '' as string;
  248. levelText = '' as string;
  249. crTypeText = '' as string;
  250. ichTypeText = '' as string;
  251. claimStatusText = '' as string;
  252. isMultipleClaimsText = '' as string;
  253. batchText = '' as string;
  254. ichSiteTypeText = '' as string;
  255. progressText = '' as string;
  256. works = [] as InheritorWorkInfo[];
  257. }
  258. export class InheritorExpandInfo extends DataModel<InheritorExpandInfo> {
  259. constructor() {
  260. super(InheritorExpandInfo, "非遗项目信息");
  261. this.setNameMapperCase('Camel', 'Snake');
  262. this._convertTable = {
  263. gender: { clientSide: 'number', serverSide: 'string' },
  264. level: { clientSide: 'number', serverSide: 'string' },
  265. batch: { clientSide: 'number', serverSide: 'string' },
  266. photosJson: [
  267. {
  268. clientSide: 'object',
  269. clientSideChildDataModel: {
  270. convertTable: {},
  271. },
  272. serverSide: 'string'
  273. },
  274. {
  275. clientSide: 'addDefaultValue',
  276. clientSideParam: {
  277. defaultValue: [],
  278. }
  279. },
  280. ],
  281. };
  282. this._convertKeyType = (key, direction) => {
  283. if (key.endsWith('Text') || key.endsWith('_text')) {
  284. return {
  285. clientSide: 'string',
  286. serverSide: 'undefined',
  287. };
  288. }
  289. };
  290. this._afterSolveServer = (self) => {
  291. };
  292. this._afterSolveClient = (data) => {
  293. };
  294. }
  295. modelId = 7;
  296. }
  297. export class InheritorWorkInfo extends DataModel<InheritorWorkInfo> {
  298. constructor() {
  299. super(InheritorWorkInfo, "传承人作品");
  300. this.setNameMapperCase('Camel', 'Snake');
  301. this._convertTable = {
  302. collectionTime: { clientSide: 'dayjs', serverSide: 'string' },
  303. };
  304. this._convertKeyType = (key, direction) => {
  305. if (key.endsWith('Text') || key.endsWith('_text')) {
  306. return {
  307. clientSide: 'string',
  308. serverSide: 'undefined',
  309. };
  310. }
  311. };
  312. this._afterSolveServer = (self) => {
  313. };
  314. this._afterSolveClient = (data) => {
  315. };
  316. }
  317. id = 0;
  318. category = '';
  319. feature = '';
  320. otherName = '';
  321. creator = '';
  322. language = '';
  323. overview = '';
  324. ethnicGroup = '';
  325. creationEra = '';
  326. mainPerformer = '';
  327. otherPerformers = '';
  328. fullString = '';
  329. tune = '';
  330. development = '';
  331. spread = '';
  332. influence = '';
  333. collector = '';
  334. collectionTime = dayjs();
  335. collectionLocation = '';
  336. }
  337. export class SeminarInfo extends CommonInfo<SeminarInfo> {
  338. constructor() {
  339. super(SeminarInfo, "传习所信息");
  340. this.setNameMapperCase('Camel', 'Snake');
  341. this._convertTable = {
  342. ...this._convertTable,
  343. lonlat: { serverSide: 'undefined' },
  344. };
  345. this._convertKeyType = (key, direction) => {
  346. if (key.endsWith('Text') || key.endsWith('_text')) {
  347. return {
  348. clientSide: 'string',
  349. serverSide: 'undefined',
  350. };
  351. }
  352. };
  353. this._afterSolveServer = (self) => {
  354. self.lonlat = [ self.longitude, self.latitude ];
  355. };
  356. this._afterSolveClient = (data) => {
  357. data.longitude = this.lonlat[0];
  358. data.latitude = this.lonlat[1];
  359. };
  360. }
  361. lonlat = [] as (number|string)[];
  362. expandInfo : SeminarExpandInfo|null = new SeminarExpandInfo();
  363. id = 0 as number;
  364. modelId = 17;
  365. mainBodyColumnId = 0 as number;
  366. content = '' as string|null;
  367. mapX = '' as string|null;
  368. mapY = '' as string|null;
  369. longitude = '' as string|null;
  370. latitude = '' as string|null;
  371. address = '' as string;
  372. featuresType = null as number|null;
  373. contact = '' as string;
  374. ichSiteType = '' as string;
  375. flagText = '' as string;
  376. typeText = '' as string;
  377. openStatusText = '' as string;
  378. statusText = '' as string;
  379. regionText = '' as string;
  380. levelText = '' as string;
  381. crTypeText = '' as string;
  382. ichTypeText = '' as string;
  383. claimStatusText = '' as string;
  384. isMultipleClaimsText = '' as string;
  385. batchText = '' as string;
  386. ichSiteTypeText = '' as string;
  387. }
  388. export class SeminarExpandInfo extends DataModel<SeminarExpandInfo> {
  389. constructor() {
  390. super(SeminarExpandInfo, "非遗项目信息");
  391. this.setNameMapperCase('Camel', 'Snake');
  392. this._convertTable = {
  393. lonlat: { serverSide: 'undefined' },
  394. };
  395. this._convertKeyType = (key, direction) => {
  396. if (key.endsWith('Text') || key.endsWith('_text')) {
  397. return {
  398. clientSide: 'string',
  399. serverSide: 'undefined',
  400. };
  401. }
  402. };
  403. this._afterSolveServer = (self) => {
  404. self.lonlat = [ self.longitude, self.latitude ];
  405. };
  406. this._afterSolveClient = (data) => {
  407. data.longitude = this.lonlat[0];
  408. data.latitude = this.lonlat[1];
  409. };
  410. }
  411. modelId = 17;
  412. lonlat = [] as (number|string)[];
  413. }
  414. export class PlanInfo extends DataModel<PlanInfo> {
  415. constructor() {
  416. super(PlanInfo, "五年计划");
  417. this.setNameMapperCase('Camel', 'Snake');
  418. this._convertTable = {
  419. progress: { clientSide: 'number', serverSide: 'undefined' },
  420. };
  421. this._convertKeyType = (key, direction) => {
  422. if (key.endsWith('Text') || key.endsWith('_text')) {
  423. return {
  424. clientSide: 'string',
  425. serverSide: 'undefined',
  426. };
  427. }
  428. };
  429. this._afterSolveServer = (self) => {
  430. };
  431. this._afterSolveClient = (data) => {
  432. };
  433. }
  434. id = 0 as number;
  435. ichId = 0 as number;
  436. name = '' as string;
  437. investment = 0 as number;
  438. desc = '' as string;
  439. target = '' as string;
  440. unit = 0 as number;
  441. department = 0 as number;
  442. userId = 0 as number;
  443. progress = 0 as number;
  444. createdAt = '' as string;
  445. updatedAt = '' as string;
  446. ichName = '' as string;
  447. progressText = '' as string;
  448. }
  449. export class InheritorAccountInfo extends DataModel<InheritorAccountInfo> {
  450. constructor() {
  451. super(InheritorAccountInfo, "传承人账号信息");
  452. this.setNameMapperCase('Camel', 'Snake');
  453. this._convertTable = {
  454. username: { clientSide: 'string', clientSideRequired: true },
  455. password: { clientSide: 'string', clientSideRequired: true },
  456. };
  457. }
  458. id = 0 as number;
  459. username = '' as string;
  460. password = '' as string;
  461. nickname = '' as string;
  462. }
  463. export class InheritorContentApi extends AppServerRequestModule<DataModel> {
  464. constructor() {
  465. super();
  466. }
  467. async getBaseInfo<T extends DataModel>(id: number|undefined, newDataModel: new () => T) {
  468. return (await this.post('/ich/inheritor/baseInfo', {
  469. model_id: new newDataModel().modelId,
  470. id,
  471. }, '基础表信息', undefined, newDataModel)).data as T;
  472. }
  473. /**
  474. * 项目五年计划
  475. * @param ichId 项目ID:传承人只返回绑定项目的计划
  476. * @param progress 审核进度:-1=不通过,0=待审核,1=已通过
  477. * @returns
  478. */
  479. async getPlanList(ichId: number, progress?: number) {
  480. return transformArrayDataModel<PlanInfo>(
  481. PlanInfo,
  482. (await this.post('/ich/inheritor/plans', {
  483. ich_id: ichId,
  484. progress,
  485. }, '获取计划列表')).data2.data,
  486. "data2"
  487. );
  488. }
  489. async saveBaseInfo<T extends DataModel>(dataModel: T) {
  490. return (await this.post('/ich/inheritor/saveBase', dataModel.toServerSide(), '基础内容表采集(非遗,传承人,传习所)'));
  491. }
  492. async getExpandInfo<T extends DataModel>(id: number|undefined, newDataModel: new () => T) : Promise<T | null> {
  493. return this.post('/ich/inheritor/expandInfo', {
  494. model_id: new newDataModel().modelId,
  495. id,
  496. }, '扩展表信息', undefined).then((res) => {
  497. if (!res.data2)
  498. return null;
  499. return transformDataModel(newDataModel, res.data2) as T;
  500. })
  501. }
  502. async saveExpandInfo<T extends DataModel>(dataModel: T) {
  503. return (await this.post('/ich/inheritor/saveExpand', dataModel.toServerSide(), '扩展内容表采集(非遗,传承人,传习所)'));
  504. }
  505. async savePlanInfo(dataModel: PlanInfo) {
  506. return (await this.post('/ich/inheritor/savePlans', dataModel.toServerSide(), '保存项目五年计划'));
  507. }
  508. async getInheritorAccountInfo(contentId: number) {
  509. return this.post('/ich/inheritor/getAccount', {
  510. content_id: contentId,
  511. }, '获取传承人账号信息', undefined).then((res) => {
  512. const arr = transformSomeToArray(res.data2);
  513. if (arr.length === 0)
  514. return null;
  515. return transformDataModel(InheritorAccountInfo, arr[0]);
  516. })
  517. }
  518. async getIchInfo(id: number|undefined) {
  519. return await this.getBaseInfo(id, IchInfo);
  520. }
  521. async getInheritorInfo(id: number|undefined) {
  522. return await this.getBaseInfo(id, InheritorInfo);
  523. }
  524. async getSeminarInfo(id: number|undefined) {
  525. return await this.getBaseInfo(id, SeminarInfo);
  526. }
  527. async getIchExpandInfo(id: number|undefined) {
  528. return await this.getExpandInfo(id, IchExpandInfo);
  529. }
  530. async getInheritorExpandInfo(id: number|undefined) {
  531. return await this.getExpandInfo(id, InheritorExpandInfo);
  532. }
  533. async getSeminarExpandInfo(id: number|undefined) {
  534. return await this.getExpandInfo(id, SeminarExpandInfo);
  535. }
  536. }
  537. export default new InheritorContentApi();