Browse Source

出版社导出脚本

warrior 4 months ago
parent
commit
f13c2cf224
2 changed files with 257 additions and 95 deletions
  1. 16 21
      projects/textbook/src/services/importDept.ts
  2. 241 74
      projects/textbook/src/services/shell.ts

+ 16 - 21
projects/textbook/src/services/importDept.ts

@@ -2522,27 +2522,22 @@ export const updateDept = {
     { code: '202409268853b', title: ' 动物营养学(第四版)' },
   ],
   list6: [
-    { code: '202409130644', isbn: '暂无', type: '纸质教材附带数字资源' },
-    { code: '202409181349', isbn: '暂无', type: '纸质教材附带数字资源' },
-    { code: '202409225565', isbn: '暂无', type: '纸质教材附带数字资源' },
-    { code: '202409028193', isbn: '暂无', type: '纸质教材附带数字资源' },
-    { code: '202409124123', isbn: '暂无', type: '纸质教材' },
-    { code: '202409093173', isbn: '暂无', type: '纸质教材附带数字资源' },
-    { code: '202409178376', isbn: '暂无', type: '纸质教材附带数字资源' },
-    { code: '202409156693', isbn: '暂无', type: '纸质教材附带数字资源' },
-    { code: '202409193746', isbn: '暂无', type: '纸质教材附带数字资源' },
-    { code: '202409069059', isbn: '暂无', type: '纸质教材附带数字资源' },
-    { code: '202409125214', isbn: '暂无', type: '纸质教材附带数字资源' },
-    { code: '202409203478', isbn: '暂无', type: '纸质教材附带数字资源' },
-    { code: '202409082588', isbn: '暂无', type: '纸质教材附带数字资源' },
+    { code: '202409148424', isbn: '9787040632668', type: '暂无' },
+    { code: '202409185617', isbn: '暂无', type: '纸质教材附带数字资源' },
+    { code: '202409215513', isbn: '9787040584394', type: '暂无' },
+    { code: '202409272118210086', isbn: '暂无', type: '纸质教材附带数字资源' },
+    { code: '202409133902', isbn: '暂无', type: '纸质教材附带数字资源' },
+    { code: '202409260758', isbn: '暂无', type: '纸质教材附带数字资源' },
+    { code: '202408156604', isbn: '暂无', type: '纸质教材附带数字资源' },
+    { code: '202408269716', isbn: '暂无', type: '纸质教材附带数字资源' },
+    { code: '202409262582', isbn: '暂无', type: '纸质教材附带数字资源' },
+    { code: '202409206173', isbn: '9787895309586', type: '暂无' },
+    { code: '202409155656', isbn: '暂无', type: '纸质教材附带数字资源' },
+    { code: '202409191999', isbn: '暂无', type: '纸质教材' },
+    { code: '202409250546', isbn: '暂无', type: '纸质教材附带数字资源' },
+    { code: '202409148424', isbn: '9787040632668', type: '暂无' },
+    { code: '202409185617', isbn: '暂无', type: '纸质教材附带数字资源' },
+    { code: '202409215513', isbn: '9787040584394', type: '暂无' },
     { code: '202409140405', isbn: '暂无', type: '纸质教材附带数字资源' },
-    {
-      code: '202409148424',
-      isbn: '9787040632668',
-      type: '纸质教材附带数字资源',
-    },
-    { code: '202409145156', isbn: '暂无', type: '纸质教材附带数字资源' },
-    { code: '202408290958', isbn: '暂无', type: '纸质教材附带数字资源' },
-    { code: '202409085021', isbn: '暂无', type: '纸质教材附带数字资源' },
   ],
 };

+ 241 - 74
projects/textbook/src/services/shell.ts

@@ -14,29 +14,65 @@ export class shellServer {
     | { upload: any; signatureUrl: any; download: any }
     | undefined;
 
+  departments: {} | any = {};
   constructor(private http: HttpClient, private tbookSer: textbookServer) {
     this.ossProvider = new ProvierOssAli();
   }
+
   //格式化链
   async formatNode(id: string): Promise<Array<any>> {
     if (!id) return [];
-    let query = new Parse.Query('Department');
-    query.select('name', 'parent.name', 'branch');
-    let r = await query.get(id);
-    let arr = [
-      {
-        title: r.get('name'),
-        key: r.id,
-        // hasChildren: r.get('hasChildren'), //是否是最下级
-        // type: r.get('type'),
-        branch: r?.get('branch'),
-        parent: r?.get('parent')?.id, //上级
-      },
-    ];
-    if (r?.get('parent')) {
-      arr.unshift(...(await this.formatNode(r?.get('parent').id)));
+    if (Object.keys(this.departments).length == 0) {
+      let query = new Parse.Query('Department');
+      query.select('name', 'parent.objectId');
+      query.containedIn('branch', [
+        '有关部门(单位)教育司(局)',
+        '省级教育行政部门',
+      ]);
+      query.ascending('createdAt');
+      query.limit(4000);
+      let r = await query.find();
+      this.departments = {
+        '66865e1c5d561921fb4d6764':{name:'省级教育行政部门'},
+        '66865deea3ac903090a7b30b':{name:'有关部门(单位)教育司(局)'}
+      }
+      r?.forEach((item) => {
+        this.departments[item.id] = item.toJSON();
+      });
+      // console.log(this.departments);
+    }
+    try {
+      let arr = [
+        {
+          title: this.departments[id].name,
+        },
+      ];
+      if (this.departments[id]?.parent?.objectId) {
+        arr.unshift(
+          ...(await this.formatNode(this.departments[id].parent.objectId))
+        );
+      }
+
+      // let query = new Parse.Query('Department');
+      // query.select('name', 'parent.name', 'branch');
+      // let r = await query.get(id);
+      // let arr = [
+      //   {
+      //     title: r.get('name'),
+      //     key: r.id,
+      //     branch: r?.get('branch'),
+      //     parent: r?.get('parent')?.id, //上级
+      //   },
+      // ];
+      // if (r?.get('parent')) {
+      //   arr.unshift(...(await this.formatNode(r?.get('parent').id)));
+      // }
+      return arr;
+    } catch (err) {
+      console.warn(err);
+      console.log(id);
+      return [];
     }
-    return arr;
   }
   /* 获取已有联系人出版单位、未注册联系人出版单位 */
   async getUnitList() {
@@ -299,7 +335,11 @@ export class shellServer {
   }
 
   /* 格式化拓展表字段 */
-  fromatFiled(list: Array<Parse.Object>, filed: string): string {
+  fromatFiled(
+    list: Array<Parse.Object>,
+    filed: string,
+    numFiled?: string
+  ): string {
     let arr: Array<string | null> = [];
     let isDate = false;
     // 监测空值
@@ -308,25 +348,33 @@ export class shellServer {
         isDate ||
         Object.prototype.toString.call(item.get(filed)).indexOf('Date') != -1
       ) {
-        arr.push(
-          this.tbookSer.formatTime('YYYY-mm-dd', item.get(filed)) +
-            '/' +
-            item.get('printNumber')
-        );
+        if (numFiled) {
+          arr.push(
+            this.tbookSer.formatTime('YYYY-mm', item.get(filed)) +
+              '(' +
+              item.get(numFiled) +
+              ')'
+          );
+        } else {
+          arr.push(this.tbookSer.formatTime('YYYY-mm', item.get(filed)));
+        }
         isDate = true;
       } else {
         arr.push(item.get(filed));
+        // if(filed == 'importantProject'){
+        //   console.log(item.get(filed));
+        // }
       }
     });
     let j = Array.from(arr).join(',');
-    if (!isDate) {
+    if (!isDate || filed != 'printSum') {
       j = Array.from(new Set(arr)).join(' ');
     }
     return j || '-';
   }
   //导出表格
   async exportEduTextbook() {
-    let unitName = '未提交';
+    let unitName = '全部教材';
     try {
       let queryParams: any = {
         where: {
@@ -336,7 +384,8 @@ export class shellServer {
                 $inQuery: {
                   where: {
                     // editionUnit: unitName,
-                    collectStatus:{$ne: '200'}
+                    collectStatus: {$ne: '200'},
+                    // collectStatus: '200',
                   },
                   className: 'EduTextbookVolume',
                 },
@@ -354,18 +403,30 @@ export class shellServer {
         'title',
         'childrens.ISBN',
         'childrens.author',
+        'childrens.unit',
         'childrens.printDate',
         'childrens.printNumber',
         'childrens.editionUnit',
         'childrens.carrierShape',
-        'inviteUnit',
+        'childrens.lang',
+        'childrens.editionFirst',
+        'childrens.editionDate',
+        'childrens.editionNumber',
+        'childrens.printSum',
+        'childrens.importantProject',
         'user.department',
         'department.branch',
-        'code'
-        // 'eduProcess.profileSubmitted',
-        // 'eduProcess.profileSubmitted.email',
-        // 'eduProcess.profileSubmitted.user.name',
-        // 'eduProcess.profileSubmitted.user.phone'
+        'code',
+        'discipline',
+        'majorPoniter',
+        'approval',
+        'inviteUnit',
+        'eduProcess.profileSubmitted',
+        'eduProcess.profileSubmitted.email',
+        'eduProcess.profileSubmitted.user.name',
+        'eduProcess.profileSubmitted.user.phone',
+        'type',
+        'major'
       );
       // query.containedIn('status', ['102', '103', '200', '201', '400']);
       query.containedIn('status', ['400']);
@@ -373,7 +434,7 @@ export class shellServer {
       query.ascending('createdAt');
       let count = await query.count();
       console.log(count);
-      query.limit(2000);
+      query.limit(100);
       query.skip(0);
       let data = await query.find();
       let table = `<table border="1px" cellspacing="0" cellpadding="0">
@@ -381,12 +442,28 @@ export class shellServer {
           <tr>
             <th>申报编号</th>
             <th>申报教材名称</th>
-            <th>第一主编/作者</th>
-            <th>ISBN</th>
+            <th>教材所属学科专业类</th>
+            <th>教材应用对象及所属学科专业类</th>
+            <th>是否为重点立项教材</th>
+            <th>申报部门</th>
+            <th>申报部门工作联系人</th>
+            <th>申报部门工作联系人手机号</th>
+            <th>申报部门工作联系人邮箱</th>
+            <th>申报类型</th>
+            <th>第一主编(作者)</th>
+            <th>第一主编(作者)单位</th>
+            <th>教材主要语种类型</th>
+            <th>国际标准书号(ISBN)</th>
             <th>出版单位</th>
-            <th>所属院校</th>
-            <th>最新印次和时间</th>
+            <th>初版时间</th>
             <th>载体形式</th>
+            <th>本版出版时间及版次</th>
+            <th>最新印次时间及印次</th>
+            <th>初版以来合计印数</th>
+            <th>初版以来是否曾列为重点项目</th>
+            <th>适用专业代码(六位)及名称</th>
+            <th>申报状态</th>
+            <th>源文件状态</th>
           </tr>
         </thead>
         <tbody>
@@ -406,7 +483,7 @@ export class shellServer {
       // `;
       let _body = '';
       for (var row = 0; row < data.length; row++) {
-        // console.log(data[row].get('user')?.get('department'));
+        // console.log(data[row]?.get('user')?.get('department'));
         let inviteUnit = data[row]?.get('inviteUnit');
         if (
           data[row]?.get('department')?.get('branch') == '省级教育行政部门' ||
@@ -414,39 +491,91 @@ export class shellServer {
             '有关部门(单位)教育司(局)'
         ) {
           let parentMap = await this.formatNode(
-            data[row].get('user')?.get('department')?.id
+            data[row]?.get('user')?.get('department')?.id
           );
           inviteUnit = parentMap[2]?.title;
         }
         _body += '<tr>';
         _body += '<td>';
-        _body += `&nbsp;${data[row].get('code') || ''}`;
+        _body += `&nbsp;${data[row]?.get('code') || ''}`;
         _body += '</td>';
 
         _body += '<td>';
-        _body += ` &nbsp;${data[row].get('title') || '-'}`;
+        _body += `&nbsp;${data[row]?.get('title') || '-'}`;
         _body += '</td>';
 
-        // _body += '<td>';
-        // _body += `&nbsp;${data[row].get('inviteUnit') || ''}`;
-        // _body += '</td>';
+        _body += '<td>';
+        _body += `&nbsp;${
+          data[row]?.get('discipline')?.code +
+          '-' +
+          data[row]?.get('discipline')?.name
+        }`;
+        _body += '</td>';
+
+        _body += '<td>';
+        _body += `&nbsp;${
+          data[row]?.get('majorPoniter')?.code +
+          '-' +
+          data[row]?.get('majorPoniter')?.name
+        }`;
+        _body += '</td>';
+
+        _body += '<td>';
+        _body += `&nbsp;${data[row]?.get('approval') || '否'}`;
+        _body += '</td>';
+
+        _body += '<td>';
+        // _body += `&nbsp;${data[row]?.get('inviteUnit') || ''}`;
+        _body += `&nbsp;${inviteUnit || ''}`;
+        _body += '</td>';
 
-        // _body += '<td>';
-        // _body += `&nbsp;${data[row]?.get('eduProcess')?.get('profileSubmitted')?.get('user')?.get('name') || ''}`;
-        // _body += '</td>';
+        _body += '<td>';
+        _body += `&nbsp;${
+          data[row]
+            ?.get('eduProcess')
+            ?.get('profileSubmitted')
+            ?.get('user')
+            ?.get('name') || ''
+        }`;
+        _body += '</td>';
 
-        // _body += '<td>';
-        // _body += `&nbsp;${data[row]?.get('eduProcess')?.get('profileSubmitted')?.get('user')?.get('phone') || ''}`;
-        // _body += '</td>';
+        _body += '<td>';
+        _body += `&nbsp;${
+          data[row]
+            ?.get('eduProcess')
+            ?.get('profileSubmitted')
+            ?.get('user')
+            ?.get('phone') || ''
+        }`;
+        _body += '</td>';
+
+        _body += '<td>';
+        _body += `&nbsp;${
+          data[row]?.get('eduProcess')?.get('profileSubmitted')?.get('email') ||
+          ''
+        }`;
+        _body += '</td>';
 
-        // _body += '<td>';
-        // _body += `&nbsp;${data[row]?.get('eduProcess')?.get('profileSubmitted')?.get('email') || ''}`;
-        // _body += '</td>';
+        _body += '<td>';
+        _body += `${
+          data[row]?.get('type') == '单本'
+            ? '单本'
+            : '全册 - ' + data[row]?.get('childrens')?.length || '-'
+        }`;
+        _body += '</td>';
 
         _body += '<td>';
         _body += `${this.fromatFiled(data[row]?.get('childrens'), 'author')}`;
         _body += '</td>';
 
+        _body += '<td>';
+        _body += `${this.fromatFiled(data[row]?.get('childrens'), 'unit')}`;
+        _body += '</td>';
+
+        _body += '<td>';
+        _body += `${this.fromatFiled(data[row]?.get('childrens'), 'lang')}`;
+        _body += '</td>';
+
         _body += '<td>';
         _body += `&nbsp;${this.fromatFiled(
           data[row]?.get('childrens'),
@@ -462,23 +591,59 @@ export class shellServer {
         _body += '</td>';
 
         _body += '<td>';
-        _body += `${inviteUnit}`;
+        _body += `${this.fromatFiled(
+          data[row]?.get('childrens'),
+          'editionFirst'
+        )}`;
         _body += '</td>';
 
         _body += '<td>';
         _body += `${this.fromatFiled(
           data[row]?.get('childrens'),
-          'printDate'
+          'carrierShape'
         )}`;
         _body += '</td>';
 
         _body += '<td>';
         _body += `${this.fromatFiled(
           data[row]?.get('childrens'),
-          'carrierShape'
+          'editionDate',
+          'editionNumber'
+        )}`;
+        _body += '</td>';
+
+        _body += '<td>';
+        _body += `${this.fromatFiled(
+          data[row]?.get('childrens'),
+          'printDate',
+          'printNumber'
         )}`;
         _body += '</td>';
 
+        _body += '<td>';
+        _body += `${this.fromatFiled(data[row]?.get('childrens'), 'printSum')}`;
+        _body += '</td>';
+
+        _body += '<td>';
+        _body += `${this.fromatFiled(
+          data[row]?.get('childrens'),
+          'importantProject'
+        )}`;
+        _body += '</td>';
+
+        _body += '<td>';
+        _body += `&nbsp;${
+          data[row]?.get('major')?.code + '-' + data[row]?.get('major')?.name
+        }`;
+        _body += '</td>';
+
+        _body += '<td>';
+        _body += `已报送`;
+        _body += '</td>';
+        _body += '<td>';
+        _body += `待上传`;
+        _body += '</td>';
+
         _body += '</tr>';
       }
       table += _body;
@@ -637,32 +802,34 @@ export class shellServer {
 
   /* 更新教材个别字段 */
   async updateTextbook() {
-    let arr = []
-    let list = updateDept.list6
+    let arr = [];
+    let list = updateDept.list6;
     for (let index = 0; index < list.length; index++) {
       const item = list[index];
       // let oldc=item.code.substring(0,item.code.length-1)
       // console.log(oldc);
-      let query = new Parse.Query('EduTextbook')
-      query.equalTo('code',item.code)
-      query.notEqualTo('isDeleted',true)
+      let query = new Parse.Query('EduTextbook');
+      query.equalTo('code', item.code);
+      query.notEqualTo('isDeleted', true);
       // query.equalTo('title',item.title)
-      query.include('childrens')
-      query.select('childrens')
-      let r = await query.find()
-      if(r.length <1 || r.length > 1 || r[0]?.get('childrens').length > 1){
-      // if(r.length !== 1){
-        arr.push(item.code)
-        continue
+      query.include('childrens');
+      query.select('childrens');
+      let r = await query.find();
+      if (r.length < 1 || r.length > 1 || r[0]?.get('childrens').length > 1) {
+        // if(r.length !== 1){
+        arr.push(item.code);
+        continue;
       }
-      let eduTextbookVolume = r[0]?.get('childrens')[0]
-      item.type.trim() != '暂无' && eduTextbookVolume?.set('carrierShape',item.type.trim())
-      item.isbn.trim() != '暂无' && eduTextbookVolume?.set('ISBN',item.isbn.trim())
-      await eduTextbookVolume?.save()
+      let eduTextbookVolume = r[0]?.get('childrens')[0];
+      item.type.trim() != '暂无' &&
+        eduTextbookVolume?.set('carrierShape', item.type.trim());
+      item.isbn.trim() != '暂无' &&
+        eduTextbookVolume?.set('ISBN', item.isbn.trim());
+      await eduTextbookVolume?.save();
       // r[0]?.set('code',item.code)
-      r[0]?.set('exportPDF',null)
-      await r[0]?.save()
-      console.log('update=>',item);
+      r[0]?.set('exportPDF', null);
+      await r[0]?.save();
+      console.log('update=>', item);
     }
     console.log('update over');
     console.log(arr);