123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572 |
- import { Injectable } from '@angular/core';
- import Parse from 'parse';
- import { HttpClient } from '@angular/common/http';
- import { updateDept } from './importDept';
- import { NzMessageService } from 'ng-zorro-antd/message';
- @Injectable({
- providedIn: 'root',
- })
- export class textbookServer {
- company: string = localStorage.getItem('company')!;
- theme: boolean = false; //深色主题模式
- profile: any = JSON.parse(localStorage.getItem('profile')!);
- constructor(private http: HttpClient) {}
- authMobile(mobile: string): boolean {
- let a = /^1[3456789]\d{9}$/;
- if (!String(mobile).match(a)) {
- return false;
- }
- return true;
- }
- randomPassword(): string {
- let sCode =
- 'A,B,C,E,F,G,H,J,K,L,M,N,P,Q,R,S,T,W,X,Y,Z,1,2,3,4,5,6,7,8,9,0,q,w,e,r,t,y,u,i,o,p,a,s,d,f,g,h,j,k,l,z,x,c,v,b,n,m';
- let aCode = sCode.split(',');
- let aLength = aCode.length; //获取到数组的长度
- let str = [];
- for (let i = 0; i <= 16; i++) {
- let j = Math.floor(Math.random() * aLength); //获取到随机的索引值
- let txt = aCode[j]; //得到随机的一个内容
- str.push(txt);
- }
- return str.join('');
- }
- formatTime(fmt: string, date1: Date) {
- let ret;
- let date = new Date(date1);
- const opt: any = {
- 'Y+': date.getFullYear().toString(), // 年
- 'm+': (date.getMonth() + 1).toString(), // 月
- 'd+': date.getDate().toString(), // 日
- 'H+': date.getHours().toString(), // 时
- 'M+': date.getMinutes().toString(), // 分
- 'S+': date.getSeconds().toString(), // 秒
- // 有其他格式化字符需求可以继续添加,必须转化成字符串
- };
- for (let k in opt) {
- ret = new RegExp('(' + k + ')').exec(fmt);
- if (ret) {
- fmt = fmt.replace(
- ret[1],
- ret[1].length == 1 ? opt[k] : opt[k].padStart(ret[1].length, '0')
- );
- }
- }
- return fmt;
- }
- //格式化链
- 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)));
- }
- return arr;
- }
- //获取下级所有部门
- async getChild(id: string): Promise<Array<string>> {
- // console.log(id);
- let arr: Array<string> = [id];
- let query = new Parse.Query('Department');
- query.equalTo('parent', id);
- query.notEqualTo('isDeleted', true);
- query.select('id', 'hasChildren');
- query.limit(500);
- let r = await query.find();
- for (let index = 0; index < r.length; index++) {
- if (r[index].get('hasChildren')) {
- let child: Array<string> = await this.getChild(r[index].id);
- arr.push(...child);
- } else {
- arr.push(r[index].id);
- }
- }
- return Array.from(new Set([...arr]));
- }
- userFind(phone: string) {
- return new Promise((res) => {
- Parse.Cloud.run('userFind', { mobile: phone })
- .then((data) => {
- if (data) {
- res(false);
- } else {
- res(true);
- }
- })
- .catch(() => res(true));
- });
- }
- async tbookExportReport(options: { processId?: string; bookList?: any[] }) {
- let url = Parse.serverURL + '/api/tbook/export';
- // console.log(url)
- let response = await fetch(url, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'X-Parse-Application-Id': 'edu-textbook',
- },
- body: JSON.stringify(options),
- });
- let result = await response.json();
- let zipUrl = result?.result?.zipUrl;
- if (result?.code == 200) {
- zipUrl = zipUrl.replaceAll('http://', 'https://');
- const a = document.createElement('a'); // 创建一个<a>元素
- a.href = zipUrl; // 设置链接的href属性为要下载的文件的URL
- a.download = '报送流程'; // 设置下载文件的名称
- document.body.appendChild(a); // 将<a>元素添加到文档中
- a.click(); // 模拟点击<a>元素
- document.body.removeChild(a); // 下载后移除<a>元素
- }
- // console.log(result)
- return result;
- Parse.Cloud.run('tbookExportReport', options).then((data) => {
- console.log(data);
- let url = data.zipUrl;
- url = url.replaceAll('http://', 'https://');
- const a = document.createElement('a'); // 创建一个<a>元素
- a.href = url; // 设置链接的href属性为要下载的文件的URL
- a.download = '报送流程'; // 设置下载文件的名称
- document.body.appendChild(a); // 将<a>元素添加到文档中
- a.click(); // 模拟点击<a>元素
- document.body.removeChild(a); // 下载后移除<a>元素
- });
- }
- async preview(options: { bookid: string }) {
- let url = Parse.serverURL + '/api/tbook/preview';
- let response = await fetch(url, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'X-Parse-Application-Id': 'edu-textbook',
- },
- body: JSON.stringify(options),
- });
- let result = await response.json();
- let { urlPdf } = result?.data;
- console.log(urlPdf);
- window.open(urlPdf);
- }
- async getEduProcess(id: string): Promise<string | undefined> {
- if (!id) return;
- let query = new Parse.Query('EduProcess');
- query.equalTo('department', id);
- query.lessThanOrEqualTo('startDate', new Date());
- query.greaterThan('deadline', new Date());
- query.notEqualTo('isDeleted', true);
- query.containedIn('status', ['200', '300']);
- query.select('objectId');
- let res = await query.first();
- return res?.id;
- }
- //需要删除是否存在为联系人情况
- async getEduProcessProf(filter: Array<string>): Promise<string | undefined> {
- let query = new Parse.Query('EduProcess');
- query.notEqualTo('isDeleted', true);
- query.containedIn('profileSubmitted', filter);
- query.select('objectId', 'name');
- let res = await query.first();
- if (res?.id) {
- return res.get('name');
- }
- return;
- }
- //更新工作联系人
- async updateProfileSubmitted(
- pid: string,
- type: string,
- dpid?: string,
- msg?: NzMessageService
- ): Promise<boolean | undefined> {
- console.log(pid, type, dpid);
- let query = new Parse.Query('EduProcess');
- if (!dpid) {
- query.equalTo('profileSubmitted', pid);
- } else {
- query.equalTo('department', dpid);
- }
- query.include('profileSubmitted');
- query.select('objectId', 'profileSubmitted');
- query.notEqualTo('isDeleted', true);
- let res = await query.first();
- if (!res?.id) {
- msg?.warning('所属单位不存在');
- return false;
- }
- if (type == 'del') {
- //删除工作联系人
- res.set('profileSubmitted', null);
- await res.save();
- return true;
- } else {
- //添加工作联系人
- if (res?.get('profileSubmitted')?.get('user')) {
- msg?.warning('该单位已有部门联系人,请先移除后再操作');
- return false;
- }
- res?.set('profileSubmitted', {
- __type: 'Pointer',
- className: 'Profile',
- objectId: pid,
- });
- await res.save();
- return true;
- }
- return false;
- }
- /* 批量预设(临时) */
- async saveProcess() {
- let count = 0;
- /* 批量关联流程管理员 */
- // let queryEdupro = new Parse.Query('EduProcess')
- // queryEdupro.select('department','name')
- // queryEdupro.equalTo('profileSubmitted',null)
- // queryEdupro.limit(1000)
- // let res = await queryEdupro.find()
- // console.log(res);
- // for (let index = 0; index < res.length; index++) {
- // const item = res[index];
- // let queryParams: any = {
- // where: {
- // $or: [
- // {
- // user: {
- // $inQuery: {
- // where: {
- // "department":item?.get('department')?.id,
- // "accountState":'已认证',
- // },
- // className: '_User',
- // },
- // },
- // },
- // ],
- // },
- // };
- // let query = Parse.Query.fromJSON('Profile', queryParams);
- // query.equalTo('identity','工作联系人')
- // query.select('objectId')
- // let p = await query.first()
- // if(p?.id){
- // item.set('profileSubmitted',p.toPointer())
- // await item.save()
- // console.log('绑定成功'+p.id+':'+item?.get('name'));
- // count++
- // }
- // }
- // let arr = [];
- // 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.editionUnit',
- // 'inviteUnit'
- // );
- // query.limit(3000);
- // query.containedIn('status', ['400']);
- // let eduTextbook = await query.find();
- // for (let index = 0; index < eduTextbook.length; index++) {
- // const item = eduTextbook[index];
- // let ISBN = '',
- // author = '',
- // editionUnit = '';
- // item?.get('childrens').forEach((children: any) => {
- // ISBN = children?.get('ISBN') + ' ' + ISBN;
- // author = children?.get('author') + ' ' + author;
- // editionUnit = children?.get('editionUnit') + ' ' + editionUnit;
- // });
- // arr.push({
- // 教材名称: item?.get('title'),
- // ISBN: ISBN,
- // 作者: author,
- // 出版社: editionUnit,
- // 所属院校: item?.get('inviteUnit'),
- // });
- // }
- // console.log(arr);
- }
- /* 格式化拓展表字段 */
- fromatFiled(list: Array<Parse.Object>, filed: 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
- ) {
- arr.push(
- this.formatTime('YYYY-mm-dd', item.get(filed)) +
- '/' +
- item.get('printNumber')
- );
- isDate = true;
- } else {
- arr.push(item.get(filed));
- }
- });
- let j = Array.from(arr).join(',');
- if (!isDate) {
- j = Array.from(new Set(arr)).join(' ');
- }
- return j || '-';
- }
- //导出表格
- async exportEduTextbook() {
- try {
- 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.printDate',
- 'childrens.printNumber',
- 'childrens.editionUnit',
- 'inviteUnit',
- 'user.department',
- 'department.branch',
- 'code'
- // 'eduProcess.profileSubmitted',
- // 'eduProcess.profileSubmitted.email',
- // 'eduProcess.profileSubmitted.user.name',
- // 'eduProcess.profileSubmitted.user.phone'
- );
- 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(2000);
- query.skip(2000);
- let data = await query.find();
- let table = `<table border="1px" cellspacing="0" cellpadding="0">
- <thead>
- <tr>
- <th>序号</th>
- <th>申报教材名称</th>
- <th>第一主编/作者</th>
- <th>ISBN</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>code</th>
- // <th>所属单位</th>
- // <th>单位联系人</th>
- // <th>联系人电话</th>
- // <th>联系人邮箱</th>
- // </tr>
- // </thead>
- // <tbody>
- // `;
- let _body = '';
- for (var 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 += `${row + 2001}`;
- _body += '</td>';
- _body += '<td>';
- _body += ` ${data[row].get('title') || '-'}`;
- _body += '</td>';
- // _body += '<td>';
- // _body += ` ${data[row].get('code') || ''}`;
- // _body += '</td>';
- // _body += '<td>';
- // _body += ` ${data[row].get('inviteUnit') || ''}`;
- // _body += '</td>';
- // _body += '<td>';
- // _body += ` ${data[row]?.get('eduProcess')?.get('profileSubmitted')?.get('user')?.get('name') || ''}`;
- // _body += '</td>';
- // _body += '<td>';
- // _body += ` ${data[row]?.get('eduProcess')?.get('profileSubmitted')?.get('user')?.get('phone') || ''}`;
- // _body += '</td>';
- // _body += '<td>';
- // _body += ` ${data[row]?.get('eduProcess')?.get('profileSubmitted')?.get('email') || ''}`;
- // _body += '</td>';
- _body += '<td>';
- _body += `${this.fromatFiled(data[row]?.get('childrens'), 'author')}`;
- _body += '</td>';
- _body += '<td>';
- _body += ` ${this.fromatFiled(
- data[row]?.get('childrens'),
- 'ISBN'
- )}`;
- _body += '</td>';
- _body += '<td>';
- _body += `${this.fromatFiled(
- data[row]?.get('childrens'),
- 'editionUnit'
- )}`;
- _body += '</td>';
- _body += '<td>';
- _body += `${inviteUnit}`;
- _body += '</td>';
- _body += '<td>';
- _body += `${this.fromatFiled(
- data[row]?.get('childrens'),
- 'printDate'
- )}`;
- _body += '</td>';
- _body += '</tr>';
- }
- table += _body;
- table += '</tbody>';
- table += '</table>';
- let title = '已提交教材';
- this.excel(table, `${title}.xls`);
- } catch (err) {
- console.log(err);
- }
- }
- 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(1000);
- 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);
- // Parse.Cloud.run('aliSmsSend', {
- // mobileList: [teacherArr],
- // templateCode: 'SMS_474205136',
- // params: {},
- // signName: '普通高等教育教材网',
- // });
- 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')
- query.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)
- // Parse.Cloud.run('aliSmsSend', {
- // mobileList: [unitPhoneArr],
- // templateCode: 'SMS_474290139',
- // params: {end_date:'2024-10-20 16:00'},
- // signName: '普通高等教育教材网',
- // });
- console.log('出版社电话:',unitPhoneArr);
-
- }
- }
|