lrf402788946 4 년 전
부모
커밋
2eceabdc7f

+ 85 - 0
app/controller/users/.project_solic.js

@@ -0,0 +1,85 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "name",
+      "pro_user",
+      "!pro_phone",
+      "field",
+      "scale",
+      "techol_stage",
+      "techol_level",
+      "proposal_company",
+      "proposal_user",
+      "proposal_phone",
+      "coopera_company",
+      "coopera_user",
+      "coopera_phone",
+      "project_back",
+      "sign",
+      "work_basics",
+      "content",
+      "route",
+      "quota",
+      "influence",
+      "!question_id",
+      "user_id",
+      "status"
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "name",
+      "pro_user",
+      "!pro_phone",
+      "field",
+      "scale",
+      "techol_stage",
+      "techol_level",
+      "proposal_company",
+      "proposal_user",
+      "proposal_phone",
+      "coopera_company",
+      "coopera_user",
+      "coopera_phone",
+      "project_back",
+      "sign",
+      "work_basics",
+      "content",
+      "route",
+      "quota",
+      "influence",
+      "status"
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        question_id: "question_id",
+        user_id: "user_id",
+        "create_time@start": "create_time@start",
+        "create_time@end": "create_time@end",
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 63 - 0
app/controller/users/.question.js

@@ -0,0 +1,63 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "title",
+      "origin",
+      "img_path",
+      "file_path",
+      "content",
+      "create_id",
+      "create_code",
+      "create_date",
+      "remark",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "title",
+      "origin",
+      "img_path",
+      "file_path",
+      "content",
+      "create_id",
+      "create_code",
+      "create_date",
+      "remark",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        title: "title",
+        origin: "origin",
+        user_id: "user_id",
+        exist: "exist",
+        create_id: "create_id",
+        create_code: "create_code",
+        "create_date@start": "create_date@start",
+        "create_date@end": "create_date@end",
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 13 - 0
app/controller/users/project_solic.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./.project_solic.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 项目征集
+class Project_SolicController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.users.projectSolic;
+  }
+}
+module.exports = CrudController(Project_SolicController, meta);

+ 17 - 0
app/controller/users/question.js

@@ -0,0 +1,17 @@
+'use strict';
+const meta = require('./.question.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 调研考察
+class QuestionController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.users.question;
+  }
+  async index() {
+    const { data = [], total = 0 } = await this.service.query(this.ctx.query);
+    this.ctx.ok({ data, total });
+  }
+}
+module.exports = CrudController(QuestionController, meta);

+ 48 - 0
app/model/project_solic.js

@@ -0,0 +1,48 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const moment = require('moment');
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+const { ObjectId } = require('mongoose').Types;
+// 项目征集表
+const projectsolic = {
+  name: { type: String, required: false, maxLength: 500 }, // 项目名称
+  pro_user: { type: String, required: true, maxLength: 500 }, // 项目负责人
+  pro_phone: { type: String, required: true, maxLength: 500 }, // 项目负责人电话
+  field: { type: String, required: false, maxLength: 500 }, // 领域分类
+  scale: { type: String, required: false, maxLength: 500 }, // 市场预估
+  techol_stage: { type: String, required: false, maxLength: 500 }, // 技术阶段
+  techol_level: { type: String, required: false, maxLength: 500 }, // 技术水平
+  proposal_company: { type: String, required: false, maxLength: 500 }, // 建议单位名称
+  proposal_user: { type: String, required: false, maxLength: 500 }, // 建议单位联系人
+  proposal_phone: { type: String, required: false, maxLength: 500 }, // 建议单位联系电话
+  coopera_company: { type: String, required: false, maxLength: 500 }, // 合作单位名称
+  coopera_user: { type: String, required: false, maxLength: 500 }, // 合作单位联系人
+  coopera_phone: { type: String, required: false, maxLength: 500 }, // 合作单位联系电话
+  project_back: { type: String, required: false, maxLength: 500 }, // 项目背景
+  sign: { type: String, required: false, maxLength: 500 }, // 立项意义
+  work_basics: { type: String, required: false, maxLength: 500 }, // 前期基础
+  content: { type: String, required: false, maxLength: 500 }, // 研究内容
+  route: { type: String, required: false, maxLength: 500 }, // 技术路线
+  quota: { type: String, required: false, maxLength: 500 }, // 核心指标
+  influence: { type: String, required: false, maxLength: 500 }, // 经济效益
+
+  question_id: { type: ObjectId, required: true, maxLength: 500 }, // 调研调查表id
+  user_id: { type: ObjectId, required: true, maxLength: 500 }, // 用户id
+  remark: { type: String, maxLength: 200 },
+  status: { type: String, default: '0' }, // 0-可修改;1-不可修改
+  create_time: {
+    type: String,
+    default: moment().format('YYYY-MM-DD HH:mm:ss'),
+  },
+};
+const schema = new Schema(projectsolic, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ question_id: 1 });
+schema.index({ user_id: 1 });
+schema.index({ pro_user: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Project_solic', schema, 'project_solic');
+};

+ 26 - 0
app/model/question.js

@@ -0,0 +1,26 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const moment = require('moment');
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+// 调研考察表
+const question = {
+  title: { type: String, maxLength: 500 }, // 标题
+  origin: { type: String, maxLength: 500 }, // 来源
+  img_path: { type: String, maxLength: 500 }, // 图片
+  file_path: { type: String, maxLength: 500 }, // 文件
+  content: { type: String, maxLength: 500 }, // 内容
+  create_id: { type: String }, // 创建人id
+  create_code: { type: String }, // 创建人角色
+  remark: { type: String, maxLength: 200 },
+  create_date: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss') },
+};
+const schema = new Schema(question, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ create_id: 1 });
+schema.index({ create_code: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('question', schema, 'question');
+};

+ 2 - 0
app/router.js

@@ -16,6 +16,8 @@ module.exports = app => {
   require('./router/users/product')(app); // 产品
   require('./router/users/person_room')(app); // 个人聊天房间
   require('./router/users/person_chat')(app); // 个人聊天
+  require('./router/users/question')(app); // 调研调查
+  require('./router/users/project_solic')(app); // 项目征集
   require('./router/system/menu')(app); // 菜单
   require('./router/system/category')(app); // 字典类别
   require('./router/system/code')(app); // 字典

+ 12 - 0
app/router/users/project_solic.js

@@ -0,0 +1,12 @@
+'use strict';
+
+
+module.exports = app => {
+  const { router, controller } = app;
+  const profix = '/api/live/';
+  const vision = 'v0';
+  const index = 'users';
+  const target = 'projectSolic';
+  router.resources(target, `${profix}${vision}/${index}/${target}`, controller[index][target]); // index、create、show、destroy
+  router.post(target, `${profix}${vision}/${index}/${target}/update/:id`, controller[index][target].update);
+};

+ 12 - 0
app/router/users/question.js

@@ -0,0 +1,12 @@
+'use strict';
+
+
+module.exports = app => {
+  const { router, controller } = app;
+  const profix = '/api/live/';
+  const vision = 'v0';
+  const index = 'users';
+  const target = 'question';
+  router.resources(target, `${profix}${vision}/${index}/${target}`, controller[index][target]); // index、create、show、destroy
+  router.post(target, `${profix}${vision}/${index}/${target}/update/:id`, controller[index][target].update);
+};

+ 48 - 0
app/service/users/project_solic.js

@@ -0,0 +1,48 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const assert = require('assert');
+
+// 项目征集
+class ProjectsolicService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'projectsolic');
+    this.model = this.ctx.model.ProjectSolic;
+    this.question = this.ctx.model.Question;
+    this.user = this.ctx.model.Personal;
+  }
+
+  async create(body) {
+    const { question_id, user_id, pro_phone, pro_user, code } = body;
+    assert(pro_phone, '请填写手机号');
+    const has = await this.question.findById(question_id);
+    if (!has) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到指定调研考察数据');
+    if (!user_id) {
+      const user = await this.user.findOne({ phone: pro_phone });
+      if (user) {
+        body.user_id = user._id;
+      } else {
+        const data = { phone: pro_phone, name: pro_user, code: 'JLAXMZJ', password: '111111', status: '1' };
+        const res = await this.ctx.service.user.create(data);
+        body.user_id = res._id;
+      }
+
+    }
+    return await this.model.create(body);
+  }
+
+  async query(query, { skip = 0, limit = 0 } = {}) {
+    query = this.ctx.service.util.util.turnDateRangeQuery(this.ctx.service.util.util.turnFilter(query));
+    const res = await this.model.find(query).skip(parseInt(skip)).limit(parseInt(limit))
+      .populate([
+        {
+          path: 'question_id',
+          model: 'question',
+        },
+      ]);
+    return res;
+  }
+}
+
+module.exports = ProjectsolicService;

+ 55 - 0
app/service/users/question.js

@@ -0,0 +1,55 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const assert = require('assert');
+
+// 调研调查
+class QuestionService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'question');
+    this.model = this.ctx.model.Question;
+    this.solic = this.ctx.model.ProjectSolic;
+  }
+  async query(query) {
+    const { skip = 0, limit = 0, user_id, exist, ...condition } = query;
+    let data = [];
+    let total = 0;
+    if (!user_id) {
+      data = await this.model.find(condition).skip(parseInt(skip)).limit(parseInt(limit));
+      total = await this.model.count(condition);
+    } else {
+      if (exist === undefined) {
+        data = await this.model.find(condition).skip(parseInt(skip)).limit(parseInt(limit));
+        data = await this.checkExist(data, user_id);
+        total = await this.model.count(condition);
+      } else {
+        data = await this.model.find(condition);
+        data = await this.checkExist(data, user_id);
+        data = data.filter(f => `${f.exist}` === `${exist}`);
+        total = data.length;
+        data = _.slice(data, skip, limit === 0 ? '10' : limit);
+      }
+    }
+
+    return { data, total };
+  }
+
+  async checkExist(data, user_id) {
+    if (data.length > 0) {
+      const ids = data.map(i => i._id);
+      const list = await this.solic.find({ question_id: ids, user_id }, '_id question_id');
+      data = JSON.parse(JSON.stringify(data));
+      data = data.map(i => {
+        const res = list.find(f => ObjectId(i._id).equals(f.question_id));
+        if (res)i.exist = true;
+        else i.exist = false;
+        return i;
+      });
+    }
+    return data;
+  }
+}
+
+module.exports = QuestionService;