lrf402788946 3 anni fa
parent
commit
1f54518e86
3 ha cambiato i file con 30 aggiunte e 19 eliminazioni
  1. 11 2
      app/controller/.mission.js
  2. 14 12
      app/model/mission.js
  3. 5 5
      app/service/mission.js

+ 11 - 2
app/controller/.mission.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ["title", "params", "user", "!tenant"],
+    requestBody: ["title", "params", "user", "!tenant", "remark"],
   },
   destroy: {
     params: ["!id"],
@@ -8,7 +8,15 @@ module.exports = {
   },
   update: {
     params: ["!id"],
-    requestBody: ["title", "params", "status", "dot", "progress", "uri"],
+    requestBody: [
+      "title",
+      "params",
+      "status",
+      "dot",
+      "progress",
+      "uri",
+      "remark",
+    ],
   },
   show: {
     parameters: {
@@ -25,6 +33,7 @@ module.exports = {
         dot: "dot",
         user: "user",
         project: "params.project",
+        tenant: "tenant",
       },
     },
     service: "query",

+ 14 - 12
app/model/mission.js

@@ -1,39 +1,41 @@
-"use strict";
-const moment = require("moment");
-const Schema = require("mongoose").Schema;
-const metaPlugin = require("naf-framework-mongoose/lib/model/meta-plugin");
+'use strict';
+const moment = require('moment');
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
 // params不做限制,方便扩展,Object就行
 const params = {
   project: { type: String, required: true }, // 项目名称(需要设置好,然后找对应路由前置)
   router: { type: String, required: true }, // 要执行的路由
-  service: { type: String, required: true }, //服务
+  service: { type: String, required: true }, // 服务
   method: { type: String, required: true }, // 方法, get,post,delete...
   type: { type: String, required: false }, // 类型,需要怎么处理;例如,文件,需要下载
-  body: { type: [Object, Array] },
+  body: { type: [ Object, Array ] },
   query: { type: Object },
 };
 
 const Mission = {
-  title: { type: String, required: true, maxLength: 200 }, // 教师
+  title: { type: String, required: true, maxLength: 200 }, // 标题
   create_time: {
     type: String,
     required: false,
     maxLength: 200,
-    default: moment().format("YYYY-MM-DD HH:SS:mm"),
+    default: moment().format('YYYY-MM-DD HH:SS:mm'),
   }, // 创建时间
   params: { type: Object, required: false },
-  status: { type: String, maxLength: 200, default: "0" }, // 状态:0=>未开始;1=>正在进行;2=>已完成;3=>失败
+  status: { type: String, maxLength: 200, default: '0' }, // 状态:0=>未开始;1=>正在进行;2=>已完成;3=>失败
   dot: { type: Boolean, default: true }, // 需要提醒
   progress: { type: String, required: false, maxLength: 200 },
   user: { type: String, required: false, maxLength: 200 }, // 用户,监听指定用户用,没有的话,mq就监听项目
   uri: { type: String, required: false }, // 文件/图片等需要地址的地方就放这
-  tenant: { type: String, required: true }, //所属项目
+  tenant: { type: String, required: true }, // 所属项目
+  remark: { type: String },
 };
 const schema = new Schema(Mission, { toJSON: { virtuals: true } });
 schema.index({ id: 1 });
+schema.index({ user: 1 });
 schema.plugin(metaPlugin);
 
-module.exports = (app) => {
+module.exports = app => {
   const { mongoose } = app;
-  return mongoose.model("Mission", schema, "mission");
+  return mongoose.model('Mission', schema, 'mission');
 };

+ 5 - 5
app/service/mission.js

@@ -37,7 +37,7 @@ class MissionService extends CrudService {
       }
     }
     if (obj.status === '2') obj.progress = '100';
-    const mission = await this.model.update({ _id: ObjectId(id) }, obj);
+    const mission = await this.model.updateOne({ _id: ObjectId(id) }, obj);
     await this.toMq({ id });
     return mission;
   }
@@ -68,15 +68,15 @@ class MissionService extends CrudService {
       );
     } catch (error) {
       console.error(error.toString());
-      await this.update({ id }, { status: '3' });
+      await this.updateOne({ id }, { status: '3' });
       throw new BusinessError(ErrorCode.SERVICE_FAULT, '执行任务失败');
     }
-    await this.update({ id }, { status: '1', progress: undefined });
+    await this.updateOne({ id }, { status: '1', progress: undefined });
   }
 
-  async updateProgress({ id, progress, status = '1' }) {
+  async updateProgress({ id, progress, status = '1', remark }) {
     if (id && progress) {
-      await this.model.update({ _id: ObjectId(id) }, { progress, status });
+      await this.model.updateOne({ _id: ObjectId(id) }, { progress, status, remark });
       this.toMq({ id });
     }
   }