import { Injectable } from '@angular/core';
import Parse from 'parse';
import { HttpClient } from '@angular/common/http';
import { updateDept } from './importDept';
import { ProvierOssAli } from '../app/comp-upload/provider-oss-aliyun';
import { textbookServer } from './textbook';

@Injectable({
  providedIn: 'root',
})
export class shellServer {
  ossProvider:
    | any
    | { 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 [];
    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 [];
    }
  }
  /* 获取已有联系人出版单位、未注册联系人出版单位 */
  async getUnitList() {
    let title = '未注册出版社';
    let arr = [
      '甘肃人民出版社',
      '河南人民出版社',
      '湖南人民出版社',
      '江苏人民出版社',
      '企业管理出版社',
      '海洋出版社',
      '线装书局',
      '中国工人出版社',
      '中国海关出版社',
      '中国青年出版总社',
      '中国原子能出版社',
      '中国标准出版社',
      '国家图书馆出版社',
      '中国戏剧出版社',
      '北京人民出版社',
      '中国社会科学出版社',
      '新星出版社',
      '河北大学出版社',
      '测试流程开始',
      '北京科学技术出版社',
      '吉林人民出版社',
      '南京东南大学出版社',
      '陕西师范大学出版总社',
      '上海教育出版社',
      '成都西南交大出版社',
      '重庆西南师范大学电子音像出版社',
    ];
    let unitMap: any = {};
    let unitList = new Set<string>(); //单位出版社
    let queryParamsbook: any = {
      where: {
        $or: [
          {
            childrens: {
              $inQuery: {
                where: {
                  editionUnit: { $in: arr },
                },
                className: 'EduTextbookVolume',
              },
            },
          },
        ],
      },
    };
    let query = Parse.Query.fromJSON('EduTextbook', queryParamsbook);
    query.equalTo('status', '400');
    query.notEqualTo('isDeleted', true);
    query.notEqualTo('discard', true);
    query.include('user.phone', 'user.name', 'childrens.editionUnit');
    query.select('user.phone', 'user.name', 'childrens.editionUnit');
    query.limit(10000);
    let r = await query.find();
    let tb = `<table border="1px" cellspacing="0" cellpadding="0">
      <thead>
        <tr>
          <th>手机号</th>
          <th>姓名</th>
          <th>关联出版社</th>
        </tr>
      </thead>
      <tbody>
      `;

    let _body = '';
    for (let row = 0; row < r.length; row++) {
      _body += '<tr>';
      _body += '<td>';
      _body += `&nbsp;${r[row]?.get('user')?.get('phone') || ''}`;
      _body += '</td>';

      _body += '<td>';
      _body += `${r[row]?.get('user')?.get('name') || ''}`;
      _body += '</td>';

      _body += '<td>';
      _body += ` &nbsp;${
        this.fromatFiled(r[row]?.get('childrens'), 'editionUnit') || ''
      }`;
      _body += '</td>';

      _body += '</tr>';
    }
    tb += _body;
    tb += '</tbody>';
    tb += '</table>';
    this.excel(tb, `${title}.xls`);
    return;
    r.forEach((item) => {
      item.get('childrens')?.forEach((child: any) => {
        if (!child?.get('editionUnit')) {
          console.log(item);
        }
        unitList.add(child?.get('editionUnit'));
        unitMap[child?.get('editionUnit')] = unitMap[child?.get('editionUnit')]
          ? unitMap[child?.get('editionUnit')] + 1
          : 1;
      });
    });
    let unitArr = Array.from(unitList);
    console.log('已被选择的申报单位：', unitArr);
    console.log(unitMap);

    let queryParams: any = {
      where: {
        $or: [
          {
            department: {
              $inQuery: {
                where: {
                  name: { $in: unitArr },
                },
                className: 'Department',
              },
            },
          },
        ],
      },
    };
    let queryEduProcess = Parse.Query.fromJSON('EduProcess', queryParams);
    queryEduProcess.include('profileSubmitted.user');
    queryEduProcess.select('profileSubmitted.user.phone', 'name');
    queryEduProcess.notEqualTo('isDeleted', true);
    queryEduProcess.limit(1000);
    let list = await queryEduProcess.find();
    // console.log(list);
    let unitPhoneList = new Set<string>(); //出版单位联系人
    let notUnitPhoneList = new Set<string>(); //出版单位联系人
    list.map((item) => {
      if (item?.get('profileSubmitted')?.get('user')?.get('phone')) {
        // unitPhoneList.add(item?.get('profileSubmitted')?.get('user')?.get('phone'))
        unitPhoneList.add(item?.get('name'));
      } else {
        notUnitPhoneList.add(item?.get('name'));
      }
    });
    let a = Array.from(unitPhoneList),
      b = Array.from(notUnitPhoneList);
    console.log('已注册联系：', Array.from(unitPhoneList));
    console.log('未注册联系：', Array.from(notUnitPhoneList));
    return;
    // let len = a.length > b.length ? a.length : b.length
    //  let table = `<table border="1px" cellspacing="0" cellpadding="0">
    //       <thead>
    //         <tr>
    //           <th>已注册</th>
    //           <th>教材数量</th>
    //           <th>未注册</th>
    //           <th>教材数量</th>
    //         </tr>
    //       </thead>
    //       <tbody>
    //       `;

    //   let _body = '';
    //   for (let row = 0; row < len; row++) {
    //     _body += '<tr>';
    //     _body += '<td>';
    //     _body += `${a[row] || ''}`;
    //     _body += '</td>';

    //     _body += '<td>';
    //     _body += `${unitMap[a[row]] || ''}`;
    //     _body += '</td>';

    //     _body += '<td>';
    //     _body += ` &nbsp;${b[row] || ''}`;
    //     _body += '</td>';

    //     _body += '<td>';
    //     _body += `${unitMap[b[row]] || ''}`;
    //     _body += '</td>';

    //     _body += '</tr>';
    //   }
    //   table += _body;
    //   table += '</tbody>';
    //   table += '</table>';
    //   this.excel(table, `${title}.xls`);
  }

  /* 获取高等教育出版社教材 */
  async getGdjy() {
    let queryParams: any = {
      where: {
        $or: [
          {
            childrens: {
              $inQuery: {
                where: {
                  editionUnit: '高等教育出版社',
                },
                className: 'EduTextbookVolume',
              },
            },
          },
        ],
      },
    };
    let query = Parse.Query.fromJSON('EduTextbook', queryParams);
    query.equalTo('status', '400');
    query.notEqualTo('isDeleted', true);
    query.notEqualTo('discard', true);
    query.include('user');
    query.limit(2000);
    let data = await query.find();
    console.log(data);
    let table = `<table border="1px" cellspacing="0" cellpadding="0">
        <thead>
          <tr>
            <th>教材名称</th>
            <th>申报编号</th>
            <th>用户名</th>
            <th>手机号</th>
            <th>专业类</th>
          </tr>
        </thead>
        <tbody>
        `;

    let _body = '';
    for (let row = 0; row < data.length; row++) {
      _body += '<tr>';
      _body += '<td>';
      _body += `${data[row]?.get('title') || ''}`;
      _body += '</td>';

      _body += '<td>';
      _body += `&nbsp;${data[row]?.get('code') || ''}`;
      _body += '</td>';

      _body += '<td>';
      _body += `${data[row]?.get('user')?.get('name') || ''}`;
      _body += '</td>';

      _body += '<td>';
      _body += `${data[row]?.get('user')?.get('phone') || ''}`;
      _body += '</td>';

      _body += '<td>';
      _body += `${
        data[row]?.get('discipline')?.code +
          '/' +
          data[row]?.get('discipline')?.name || ''
      }`;
      _body += '</td>';

      _body += '</tr>';
    }
    table += _body;
    table += '</tbody>';
    table += '</table>';
    let title = '高等教育出版社';
    this.excel(table, `${title}.xls`);
  }

  /* 格式化拓展表字段 */
  fromatFiled(
    list: Array<Parse.Object>,
    filed: string,
    numFiled?: string
  ): string {
    let arr: Array<string | null> = [];
    let isDate = false;
    // 监测空值
    list?.forEach((item: Parse.Object) => {
      if (
        isDate ||
        Object.prototype.toString.call(item.get(filed)).indexOf('Date') != -1
      ) {
        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 || filed != 'printSum') {
      j = Array.from(new Set(arr)).join(' ');
    }
    return j || '-';
  }
  //导出表格
  async exportEduTextbook() {
    let unitName = '全部教材';
    try {
      let queryParams: any = {
        where: {
          $or: [
            {
              childrens: {
                $inQuery: {
                  where: {
                    // editionUnit: unitName,
                    // collectStatus: { $ne: '200' },
                    collectStatus: '200',
                  },
                  className: 'EduTextbookVolume',
                },
              },
            },
          ],
        },
      };
      let query = Parse.Query.fromJSON('EduTextbook', queryParams);
      // let query = new Parse.Query('EduTextbook');
      query.notEqualTo('isDeleted', true);
      query.notEqualTo('discard', true);
      query.equalTo('render', true);
      query.select(
        'title',
        'childrens.ISBN',
        'childrens.author',
        'childrens.unit',
        'childrens.printDate',
        'childrens.printNumber',
        'childrens.editionUnit',
        'childrens.carrierShape',
        'childrens.lang',
        'childrens.editionFirst',
        'childrens.editionDate',
        'childrens.editionNumber',
        'childrens.printSum',
        'childrens.importantProject',

        'childrens.collectFiles',
        'childrens.collectLink',
        'childrens.collectDigitFiles',
        'childrens.collectCheck',

        'user.department',
        'department.branch',
        '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']);
      // query.containedIn('objectId',updateDept.list5)
      query.ascending('createdAt');
      let count = await query.count();
      console.log(count);
      query.limit(10000);
      query.skip(0);
      let data = await query.find();
      let table = `<table border="1px" cellspacing="0" cellpadding="0">
        <thead>
          <tr>
            <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>教材主要语种类型</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>纸质教材PDF名称</th>
            <th>数字教材链接</th>
            <th>链接和账号密码</th>
            <th>数字教材文件名称</th>

          </tr>
        </thead>
        <tbody>
        `;
      // let table = `<table border="1px" cellspacing="0" cellpadding="0">
      // <thead>
      //   <tr>
      //     <th>申报编号</th>
      //     <th>申报教材名称</th>
      //     <th>所属单位</th>
      //     <th>单位联系人</th>
      //     <th>联系人电话</th>
      //     <th>联系人邮箱</th>
      //   </tr>
      // </thead>
      // <tbody>
      // `;
      let _body = '';
      for (let row = 0; row < data.length; row++) {
        // console.log(data[row]?.get('user')?.get('department'));
        let inviteUnit = data[row]?.get('inviteUnit');
        if (
          data[row]?.get('department')?.get('branch') == '省级教育行政部门' ||
          data[row]?.get('department')?.get('branch') ==
            '有关部门（单位）教育司（局）'
        ) {
          let parentMap = await this.formatNode(
            data[row]?.get('user')?.get('department')?.id
          );
          inviteUnit = parentMap[2]?.title;
        }
        _body += '<tr>';
        _body += '<td>';
        _body += `&nbsp;${data[row]?.get('code') || ''}`;
        _body += '</td>';

        _body += '<td>';
        _body += `&nbsp;${data[row]?.get('title') || '-'}`;
        _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('phone') || ''
        }`;
        _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'),
          'ISBN'
        )}`;
        _body += '</td>';

        _body += '<td>';
        _body += `${this.fromatFiled(
          data[row]?.get('childrens'),
          'editionUnit'
        )}`;
        _body += '</td>';

        _body += '<td>';
        _body += `&nbsp;${this.fromatFiled(
          data[row]?.get('childrens'),
          'editionFirst'
        )}`;
        _body += '</td>';

        _body += '<td>';
        _body += `${this.fromatFiled(
          data[row]?.get('childrens'),
          'carrierShape'
        )}`;
        _body += '</td>';

        _body += '<td>';
        _body += `${this.fromatFiled(
          data[row]?.get('childrens'),
          '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 += '<td>';
        _body += `${this.fromatFiledCollect(
          data[row]?.get('childrens')
        )}`;
        _body += '</td>';

        _body += '<td>';
        _body += `${this.fromatFiledCollect(
          data[row]?.get('childrens'),
          '链接'
        )}`;
        _body += '</td>';


        _body += '<td>';
        _body += `${this.fromatFiledCollect(
          data[row]?.get('childrens'),
          '链接和账号密码'
        )}`;
        _body += '</td>';

        _body += '<td>';
        _body += `${this.fromatFiledCollect(
          data[row]?.get('childrens'),
          '上传文件'
        )}`;
        _body += '</td>';

        _body += '</tr>';
      }
      table += _body;
      table += '</tbody>';
      table += '</table>';
      // let title = '已提交教材';
      this.excel(table, `${unitName}.xls`);
    } catch (err) {
      console.log(err);
    }
  }

  /* 格式化拓展表字段教材文件 */
  fromatFiledCollect(list: Array<Parse.Object>, radioValue?: string): string {
    let arr: Array<string | null> = [];
    // 监测空值
    list?.forEach((item: Parse.Object) => {
      if(radioValue){
        switch (radioValue) {
          case '链接':
            item.get('collectCheck') == '链接' && arr.push('链接：' + item.get('collectLink').url);
            break;
          case '链接和账号密码':
            item.get('collectCheck') == '链接和账号密码' && arr.push(`链接：lian${item.get('collectLink').url}
            账号：lian${item.get('collectLink').username}
            密码：lian${item.get('collectLink').password}
            `);
            break;
          default:
            if(item.get('collectCheck') == '上传文件'){
              let list:Array<string> = []
              item.get('collectDigitFiles')?.forEach((i:any)=>list.push(i.name))
              arr.push(...list);
            }
            break;
        }
      }else{
        let list:Array<string> = []
        item.get('collectFiles')?.forEach((i:any)=>list.push(i.name))
        arr.push(...list);
      }
    });
    let j = Array.from(arr).join(',');
    return j || '-';
  }

  excel(data: any, filename: string) {
    let html =
      "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>";
    html +=
      '<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">';
    html += '<meta http-equiv="content-type" content="application/vnd.ms-excel';
    html += '; charset=UTF-8">';
    html += '<head>';
    html += '</head>';
    html += '<body>';
    html += data;
    html += '</body>';
    html += '</html>';
    let uri =
      'data:application/vnd.ms-excel;charset=utf-8,' + encodeURIComponent(html);
    let link = document.createElement('a');
    link.href = uri;
    link.download = `${filename}`;
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
  }

  /* 发送出版社及教师通知短信 */
  async sendNoticeMSG() {
    let teacherList = new Set<string>();
    let unitList = new Set<string>(); //单位出版社

    let query = new Parse.Query('EduTextbook');
    query.equalTo('status', '400');
    query.notEqualTo('isDeleted', true);
    query.notEqualTo('discard', true);
    query.include('user.phone', 'childrens.editionUnit');
    query.select('user.phone', 'childrens.editionUnit');
    query.limit(10000);
    let r = await query.find();
    r.forEach((item) => {
      teacherList.add(item?.get('user')?.get('phone'));
      item
        .get('childrens')
        ?.forEach((child: any) => unitList.add(child?.get('editionUnit')));
    });
    let teacherArr = Array.from(teacherList);
    let unitArr = Array.from(unitList);
    console.log('教师电话：', teacherArr);
    // console.log(unitArr);
    let last = teacherArr.slice(5000, 5999);
    last.push(...['13581837652', '13407973043', '18510409671']);
    console.log(last);

    let arr: any = [
      // teacherArr.slice(0,999),
      // teacherArr.slice(1000,1999),
      // teacherArr.slice(2000,2999),
      // teacherArr.slice(3000,3999),
      // teacherArr.slice(4000,4999),
      last,
    ];
    // arr.forEach((list:any)=> {
    //   Parse.Cloud.run('aliSmsSend', {
    //     mobileList: [list],
    //     templateCode: 'SMS_474205136',
    //     params: {},
    //     signName: '普通高等教育教材网',
    //   });
    // })

    // return
    let queryParams: any = {
      where: {
        $or: [
          {
            department: {
              $inQuery: {
                where: {
                  name: { $in: unitArr },
                },
                className: 'Department',
              },
            },
          },
        ],
      },
    };
    let queryEduProcess = Parse.Query.fromJSON('EduProcess', queryParams);
    queryEduProcess.include('profileSubmitted.user');
    queryEduProcess.select('profileSubmitted.user.phone');
    queryEduProcess.limit(1000);
    let list = await queryEduProcess.find();
    // console.log(list);
    let unitPhoneList = new Set<string>(); //出版单位联系人
    list.map((item) => {
      if (item?.get('profileSubmitted')?.get('user')?.get('phone')) {
        unitPhoneList.add(
          item?.get('profileSubmitted')?.get('user')?.get('phone')
        );
      }
    });
    let unitPhoneArr = Array.from(unitPhoneList);
    unitPhoneArr.push(...['13581837652', '13407973043', '18510409671']);

    // Parse.Cloud.run('aliSmsSend', {
    //   mobileList: [unitPhoneArr],
    //   templateCode: 'SMS_474290139',
    //   params: {end_date:'2024-10-20 16:00'},
    //   signName: '普通高等教育教材网',
    // });
    console.log('出版社电话：', unitPhoneArr);
  }

  /* 获取10月9号之前上传的教材文件转私有 */
  async getEtxVolCollect() {
    let queryParams: any = {
      where: {
        $or: [
          {
            collectFiles: { $exists: true },
            collectDigitFiles: { $exists: true },
          },
        ],
      },
    };
    let query = Parse.Query.fromJSON('EduTextbookVolume', queryParams);
    query.lessThan('updatedAt', new Date('2024-10-10 18:00'));
    query.select('collectFiles', 'collectDigitFiles');
    query.limit(2000);
    let r = await query.find();
    let urlList: Array<string> = [];
    r.forEach((item) => {
      item?.get('collectFiles')?.forEach((f: any) => {
        urlList.push(f?.url);
      });
      item?.get('collectDigitFiles')?.forEach((d: any) => {
        urlList.push(d?.url);
      });
    });

    console.log(urlList);
    for (let index = 0; index < urlList.length; index++) {
      const u = urlList[index];
      console.log(u);
      // await this.ossProvider?.setACLPrivate(u)
    }
  }

  /* 更新教材个别字段 */
  async updateTextbook() {
    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);
      // 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;
      }
      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);
    }
    console.log('update over');
    console.log(arr);
  }

  /* 导出评审系统表格数据 */
  async exportUrl() {
    let unitName = '教材文件excel';
    let query = new Parse.Query('EduTextbook');
    query.notEqualTo('isDeleted', true);
    query.notEqualTo('discard', true);
    query.equalTo('render', true);
    query.select('title', 'code');
    query.containedIn('status', ['400']);
    query.limit(10000);
    query.skip(0);
    let data = await query.find();
    let table = `<table border="1px" cellspacing="0" cellpadding="0">
        <thead>
          <tr>
            <th>教材名称</th>
            <th>申报编号</th>
            <th>文件链接</th>
          </tr>
        </thead>
        <tbody>
        `;
    let _body = '';
    for (let row = 0; row < data.length; row++) {
      _body += '<tr>';

      _body += '<td>';
      _body += `${data[row]?.get('title') || '-'}`;
      _body += '</td>';

      _body += '<td>';
      _body += `&nbsp;${data[row]?.get('code') || ''}`;
      _body += '</td>';

      _body += '<td>';
      _body += `https://145.tbook.com.cn/external/review/detail/${data[row].id}`;
      _body += '</td>';

      _body += '</tr>';
    }
    table += _body;
    table += '</tbody>';
    table += '</table>';
    this.excel(table, `${unitName}.xls`);
  }
}
