|
@@ -47,6 +47,30 @@ export class PatentService extends BaseService<modelType> {
|
|
|
|
|
|
@Inject()
|
|
|
rabbitmqService: RabbitmqService;
|
|
|
+
|
|
|
+ async beforeQuery(query) {
|
|
|
+ const { _id, type, code } = this.ctx.user;
|
|
|
+ assert(_id, '未获取到用户信息');
|
|
|
+ const { skip = 0, limit = 0, ...info } = query;
|
|
|
+ if (type === '2') {
|
|
|
+ const person: any = await this.adminAxios.get(`/personal?code=${code}`);
|
|
|
+ if (person && person.total > 0) {
|
|
|
+ const list = [];
|
|
|
+ for (const val of person.data) {
|
|
|
+ const arr = { users: { $elemMatch: { user_id: val._id } } };
|
|
|
+ list.push(arr);
|
|
|
+ }
|
|
|
+ info.$or = list;
|
|
|
+ }
|
|
|
+ } else if (type === '4') info.users = { $elemMatch: { user_id: _id } };
|
|
|
+ const data = await this.model
|
|
|
+ .find(info)
|
|
|
+ .skip(skip)
|
|
|
+ .limit(limit)
|
|
|
+ .sort({ create_date: -1 });
|
|
|
+ const total = await this.model.count(info);
|
|
|
+ return { data, total };
|
|
|
+ }
|
|
|
// 导入
|
|
|
async import({ url, code }) {
|
|
|
assert(url, '未获取到文件地址');
|
|
@@ -258,19 +282,31 @@ export class PatentService extends BaseService<modelType> {
|
|
|
arr.push('');
|
|
|
if (_.isArray(value)) {
|
|
|
const img = _.get(_.head(value), 'url');
|
|
|
- if (img && img.includes('image/png')) {
|
|
|
- const imgId = workbook.addImage({
|
|
|
+ let imgId;
|
|
|
+ if (img.includes('base64,')) {
|
|
|
+ imgId = workbook.addImage({
|
|
|
base64: img,
|
|
|
- extension: 'png',
|
|
|
+ extension: 'jpeg',
|
|
|
});
|
|
|
- const sheetRange = {
|
|
|
- tl: { col: 13, row: k + 1 },
|
|
|
- ext: { width: 60, height: 60 },
|
|
|
- editAs: 'oneCell',
|
|
|
- };
|
|
|
- if (_.isFunction(sheet.addImage))
|
|
|
- sheet.addImage(imgId, sheetRange);
|
|
|
+ } else if (img.includes('/files')) {
|
|
|
+ const prefix = `${this.root_path}`;
|
|
|
+ const new_url = img.replace('/files', prefix);
|
|
|
+ const suffix = Path.extname(img).substring(1);
|
|
|
+ imgId = workbook.addImage({
|
|
|
+ filename: new_url,
|
|
|
+ extension: suffix,
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ // 什么都不是,那就下一个
|
|
|
+ continue;
|
|
|
}
|
|
|
+ const sheetRange = {
|
|
|
+ tl: { col: meta.length - 1, row: k + 1 },
|
|
|
+ ext: { width: 60, height: 60 },
|
|
|
+ editAs: 'oneCell',
|
|
|
+ };
|
|
|
+ if (_.isFunction(sheet.addImage))
|
|
|
+ sheet.addImage(imgId, sheetRange);
|
|
|
}
|
|
|
} else if (model === 'type') {
|
|
|
const data = typeList.data.find(i => i.value === d[model]);
|
|
@@ -331,7 +367,7 @@ export class PatentService extends BaseService<modelType> {
|
|
|
const exportPath = `${this.root_path}${sep}${this.export_dir}`;
|
|
|
if (!fs.existsSync(exportPath)) {
|
|
|
// 如果不存在文件夹,就创建
|
|
|
- fs.mkdirSync(exportPath);
|
|
|
+ this.mkdir(exportPath);
|
|
|
}
|
|
|
await compressing.zip.compressDir(path, `${exportPath}${sep}${zipName}`);
|
|
|
const downloadPath = `/files/${this.export_dir}/${zipName}`;
|
|
@@ -356,7 +392,62 @@ export class PatentService extends BaseService<modelType> {
|
|
|
}
|
|
|
this.dirDelete(path);
|
|
|
}
|
|
|
+ // 批量分配
|
|
|
+ async updateUser({ list, user_id, name }) {
|
|
|
+ if (!list || !_.isArray(list)) {
|
|
|
+ throw new ServiceError(
|
|
|
+ '专利信息参数错误',
|
|
|
+ FrameworkErrorEnum.DATA_NOT_FOUND
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (!user_id) {
|
|
|
+ throw new ServiceError(
|
|
|
+ '用户信息参数错误',
|
|
|
+ FrameworkErrorEnum.DATA_NOT_FOUND
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (!name) {
|
|
|
+ throw new ServiceError(
|
|
|
+ '用户信息参数错误',
|
|
|
+ FrameworkErrorEnum.DATA_NOT_FOUND
|
|
|
+ );
|
|
|
+ }
|
|
|
+ for (const val of list) {
|
|
|
+ const data: any = await this.model.find({
|
|
|
+ _id: val,
|
|
|
+ });
|
|
|
+ for (const i of data) {
|
|
|
+ i.users = _.unionBy([...i.users, ...[{ user_id, name }]], 'user_id');
|
|
|
+ await i.save();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量删除
|
|
|
+ * @param {Object} query 参数,查询范围
|
|
|
+ */
|
|
|
+ async deleteManys({ list }) {
|
|
|
+ if (!list || !_.isArray(list)) {
|
|
|
+ throw new ServiceError(
|
|
|
+ '专利信息参数错误',
|
|
|
+ FrameworkErrorEnum.DATA_NOT_FOUND
|
|
|
+ );
|
|
|
+ }
|
|
|
+ const res = await this.model.deleteMany({
|
|
|
+ _id: { $in: list },
|
|
|
+ });
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 一键删除
|
|
|
+ */
|
|
|
+ async deletion() {
|
|
|
+ const res = await this.model.deleteMany();
|
|
|
+ return res;
|
|
|
+ }
|
|
|
|
|
|
+ // mq
|
|
|
async sendToMQ(data) {
|
|
|
if (
|
|
|
_.get(data, 'progress') &&
|