zs 1 vuosi sitten
vanhempi
commit
c367bf9de9

+ 27 - 9
src/controller/patent.controller.ts

@@ -14,12 +14,13 @@ import {
   CDTO_patent,
   CVO_patent,
   FVO_patent,
-  QDTO_patent,
+  // QDTO_patent,
   QVO_patent,
   UDTO_patent,
   UVAO_patent,
   ImportDTO,
   ExportDTO,
+  updateUserDTO,
 } from '../interface/patent.interface';
 import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
 import { Validate } from '@midwayjs/validate';
@@ -40,18 +41,14 @@ export class PatentController extends BaseController {
   @Get('/')
   @ApiQuery({ name: 'query' })
   @ApiResponse({ type: QVO_patent })
-  async query(
-    @Query() filter: QDTO_patent,
-    @Query('skip') skip: number,
-    @Query('limit') limit: number
-  ) {
-    const list = await this.service.query(filter, { skip, limit });
+  async query(@Query() filter: any) {
+    const list = await this.service.beforeQuery(filter);
     const data = [];
-    for (const i of list) {
+    for (const i of list.data) {
       const newData = new QVO_patent(i);
       data.push(newData);
     }
-    const total = await this.service.count(filter);
+    const total = list.total;
     return { data, total };
   }
 
@@ -92,6 +89,27 @@ export class PatentController extends BaseController {
     return result;
   }
 
+  @Post('/updateUser')
+  @Validate()
+  async updateUser(@Body() body: updateUserDTO) {
+    const result = await this.service.updateUser(body);
+    return result;
+  }
+
+  @Post('/deleteMany')
+  @Validate()
+  async deleteManys(@Body() body: updateUserDTO) {
+    const result = await this.service.deleteManys(body);
+    return result;
+  }
+
+  @Get('/deletion')
+  @Validate()
+  async deletion() {
+    const result = await this.service.deletion();
+    return result;
+  }
+
   async createMany(...args: any[]) {
     throw new Error('Method not implemented.');
   }

+ 3 - 3
src/controller/safeg.controller.ts

@@ -16,7 +16,7 @@ import {
   FVO_safeg,
   QDTO_safeg,
   QVO_safeg,
-  UDTO_safeg,
+  // UDTO_safeg,
   UVAO_safeg,
 } from '../interface/safeg.interface';
 import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
@@ -64,8 +64,8 @@ export class SafegController extends BaseController {
   @Post('/:id')
   @Validate()
   @ApiResponse({ type: UVAO_safeg })
-  async update(@Param('id') id: string, @Body() body: UDTO_safeg) {
-    const result = await this.service.updateOne(id, body);
+  async update(@Param('id') id: string, @Body() body: any) {
+    const result = await this.service.update(id, body);
     return result;
   }
 

+ 11 - 0
src/interface/patent.interface.ts

@@ -335,3 +335,14 @@ export class ExportDTO {
   @Rule(RuleType['string']().empty(''))
   'end_num': string = undefined;
 }
+export class updateUserDTO {
+  @ApiProperty({ description: '数组', example: [] })
+  @Rule(RuleType['array']().empty(''))
+  'list': Array<any> = undefined;
+  @ApiProperty({ description: '用户id', example: '' })
+  @Rule(RuleType['string']().empty(''))
+  'user_id': string = undefined;
+  @ApiProperty({ description: '名字', example: '' })
+  @Rule(RuleType['string']().empty(''))
+  'name': string = undefined;
+}

+ 15 - 8
src/service/assessment.service.ts

@@ -16,14 +16,14 @@ export class AssessmentService extends BaseService<modelType> {
 
   //添加处理数据
   async create(body) {
-    const { status, user_id, admin_id, user_name, name } = body;
+    const { status, user_id, admin_id, user_name, patent_name } = body;
     if (status === '0') {
       const info = {
         status: status,
         create_time: moment().format('YYYY-MM-DD HH:mm:ss'),
         save_id: user_id,
         save_name: user_name,
-        content: `${user_name}提交了${name}专利的价值评估单,请及时查看并处理`,
+        content: `${user_name}提交了${patent_name}专利的价值评估单,请及时查看并处理`,
       };
       if (body.record) body.record.push(info);
       else body.record = [info];
@@ -42,15 +42,22 @@ export class AssessmentService extends BaseService<modelType> {
 
   // 修改处理数据
   async update(id, body) {
-    const { status, user_id, user_name, name, admin_id, admin_name, desc } =
-      body;
+    const {
+      status,
+      user_id,
+      user_name,
+      patent_name,
+      admin_id,
+      admin_name,
+      desc,
+    } = body;
     if (status === '0') {
       const info = {
         status: status,
         create_time: moment().format('YYYY-MM-DD HH:mm:ss'),
         save_id: user_id,
         save_name: user_name,
-        content: `${user_name}提交了${name}专利的价值评估单,请及时查看并处理`,
+        content: `${user_name}提交了${patent_name}专利的价值评估单,请及时查看并处理`,
       };
       if (body.record) body.record.push(info);
       else body.record = [info];
@@ -68,7 +75,7 @@ export class AssessmentService extends BaseService<modelType> {
         create_time: moment().format('YYYY-MM-DD HH:mm:ss'),
         save_id: admin_id,
         save_name: admin_name,
-        content: `${user_name}提交了${name}专利的价值评估单已经审核完成,审核意见:${
+        content: `${user_name}提交了${patent_name}专利的价值评估单已经审核完成,审核意见:${
           desc || '无'
         },请及时查看审核通知消息`,
       };
@@ -88,7 +95,7 @@ export class AssessmentService extends BaseService<modelType> {
         create_time: moment().format('YYYY-MM-DD HH:mm:ss'),
         save_id: admin_id,
         save_name: admin_name,
-        content: `${user_name}提交了${name}专利的价值评估单已发报告,请及时查看审核通知消息`,
+        content: `${user_name}提交了${patent_name}专利的价值评估单已发报告,请及时查看审核通知消息`,
       };
       if (body.record) body.record.push(info);
       else body.record = [info];
@@ -106,7 +113,7 @@ export class AssessmentService extends BaseService<modelType> {
         create_time: moment().format('YYYY-MM-DD HH:mm:ss'),
         save_id: user_id,
         save_name: user_name,
-        content: `${user_name}提交了${name}专利的价值评估单,审核意见:${
+        content: `${user_name}提交了${patent_name}专利的价值评估单,审核意见:${
           desc || '无'
         },报告已接收`,
       };

+ 102 - 11
src/service/patent.service.ts

@@ -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') &&

+ 122 - 0
src/service/safeg.service.ts

@@ -3,9 +3,131 @@ import { InjectEntityModel } from '@midwayjs/typegoose';
 import { ReturnModelType } from '@typegoose/typegoose';
 import { BaseService } from 'free-midway-component';
 import { Safeg } from '../entity/safeg.entity';
+import { ExamNotice } from '../entity/examNotice.entity';
+const moment = require('moment');
 type modelType = ReturnModelType<typeof Safeg>;
 @Provide()
 export class SafegService extends BaseService<modelType> {
   @InjectEntityModel(Safeg)
   model: modelType;
+
+  @InjectEntityModel(ExamNotice)
+  examModel: ReturnModelType<typeof ExamNotice>;
+
+  //添加处理数据
+  async create(body) {
+    const { status, user_id, admin_id, user_name, patent_name } = body;
+    if (status === '0') {
+      const info = {
+        status: status,
+        create_time: moment().format('YYYY-MM-DD HH:mm:ss'),
+        save_id: user_id,
+        save_name: user_name,
+        content: `${user_name}提交了${patent_name}专利的价值评估单,请及时查看并处理`,
+      };
+      if (body.record) body.record.push(info);
+      else body.record = [info];
+      const exam = {
+        send_id: user_id,
+        send_date: info.create_time,
+        receive_id: admin_id,
+        content: info.content,
+        is_read: '0',
+      };
+      await this.examModel.create(exam);
+    }
+    const res = await this.model.create(body);
+    return res;
+  }
+
+  // 修改处理数据
+  async update(id, body) {
+    const {
+      status,
+      user_id,
+      user_name,
+      patent_name,
+      admin_id,
+      admin_name,
+      desc,
+    } = body;
+    if (status === '0') {
+      const info = {
+        status: status,
+        create_time: moment().format('YYYY-MM-DD HH:mm:ss'),
+        save_id: user_id,
+        save_name: user_name,
+        content: `${user_name}提交了${patent_name}专利的价值评估单,请及时查看并处理`,
+      };
+      if (body.record) body.record.push(info);
+      else body.record = [info];
+      const exam = {
+        send_id: user_id,
+        send_date: info.create_time,
+        receive_id: admin_id,
+        content: info.content,
+        is_read: '0',
+      };
+      await this.examModel.create(exam);
+    } else if (status === '1' || status === '2') {
+      const info = {
+        status: status,
+        create_time: moment().format('YYYY-MM-DD HH:mm:ss'),
+        save_id: admin_id,
+        save_name: admin_name,
+        content: `${user_name}提交了${patent_name}专利的价值评估单已经审核完成,审核意见:${
+          desc || '无'
+        },请及时查看审核通知消息`,
+      };
+      if (body.record) body.record.push(info);
+      else body.record = [info];
+      const exam = {
+        send_id: admin_id,
+        send_date: info.create_time,
+        receive_id: user_id,
+        content: info.content,
+        is_read: '0',
+      };
+      await this.examModel.create(exam);
+    } else if (status === '3') {
+      const info = {
+        status: status,
+        create_time: moment().format('YYYY-MM-DD HH:mm:ss'),
+        save_id: admin_id,
+        save_name: admin_name,
+        content: `${user_name}提交了${patent_name}专利的价值评估单已发报告,请及时查看审核通知消息`,
+      };
+      if (body.record) body.record.push(info);
+      else body.record = [info];
+      const exam = {
+        send_id: admin_id,
+        send_date: info.create_time,
+        receive_id: user_id,
+        content: info.content,
+        is_read: '0',
+      };
+      await this.examModel.create(exam);
+    } else if (status === '4') {
+      const info: any = {
+        status: status,
+        create_time: moment().format('YYYY-MM-DD HH:mm:ss'),
+        save_id: user_id,
+        save_name: user_name,
+        content: `${user_name}提交了${patent_name}专利的价值评估单,审核意见:${
+          desc || '无'
+        },报告已接收`,
+      };
+      if (body.record) body.record.push(info);
+      else body.record = [info];
+      const exam = {
+        send_id: user_id,
+        send_date: info.create_time,
+        receive_id: admin_id,
+        content: info.content,
+        is_read: '0',
+      };
+      await this.examModel.create(exam);
+    }
+    await this.model.updateOne({ _id: id }, body);
+  }
 }