Browse Source

answerTea&agentMech表;密码中间件

lrf 3 years ago
parent
commit
9717217b3a

+ 43 - 0
app/controller/patent/.agent_mech.js

@@ -0,0 +1,43 @@
+module.exports = {
+  create: {
+    requestBody: ['pid', 'pid_name', 'mech_name', 'name', '!phone', 'password', 'role', 'remark'],
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete',
+  },
+  update: {
+    params: ['!id'],
+    requestBody: ['pid', 'pid_name', 'mech_name', 'name', '!phone', 'password', 'role', 'remark'],
+  },
+  show: {
+    parameters: {
+      params: ['!id'],
+    },
+    service: 'fetch',
+  },
+  index: {
+    parameters: {
+      query: {
+        pid: 'pid',
+        pid_name: '%pid_name%',
+        mech_name: '%mech_name%',
+        name: '%name%',
+        phone: 'phone',
+        role: 'role',
+        'meta.createdAt@start': 'meta.createdAt@start',
+        'meta.createdAt@end': 'meta.createdAt@end',
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 48 - 0
app/controller/patent/.answer_tea.js

@@ -0,0 +1,48 @@
+module.exports = {
+  create: {
+    requestBody: ['name', 'phone', 'password', 'card', 'email', 'address', 'zwzc', 'school', 'major', 'word_tel', 'type', 'role'],
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete',
+  },
+  update: {
+    params: ['!id'],
+    requestBody: ['name', 'phone', 'password', 'card', 'email', 'address', 'zwzc', 'school', 'major', 'word_tel', 'type', 'role'],
+  },
+  show: {
+    parameters: {
+      params: ['!id'],
+    },
+    service: 'fetch',
+  },
+  index: {
+    parameters: {
+      query: {
+        name: '%name%',
+        phone: 'phone',
+        card: 'card',
+        email: '%email%',
+        address: '%address%',
+        zwzc: '%zwzc%',
+        school: '%school%',
+        major: '%major%',
+        word_tel: 'word_tel',
+        type: 'type',
+        role: 'role',
+        'meta.createdAt@start': 'meta.createdAt@start',
+        'meta.createdAt@end': 'meta.createdAt@end',
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 13 - 0
app/controller/patent/agent_mech.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./.agent_mech.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 代理机构
+class Agent_mechController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.patent.agentMech;
+  }
+}
+module.exports = CrudController(Agent_mechController, meta);

+ 13 - 0
app/controller/patent/answer_tea.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./.answer_tea.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 代理机构
+class Answer_teaController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.patent.answerTea;
+  }
+}
+module.exports = CrudController(Answer_teaController, meta);

+ 24 - 0
app/middleware/create_password.js

@@ -0,0 +1,24 @@
+'use strict';
+/**
+ * 处理密码类型的数据的中间件
+ * 在处理前拦截,在传来的数据中 找是否有 key 在keyWord列表中. 
+ * 将在列表中的key的值转换成{secret:${value}},再去提交,免去重写create函数
+ */
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const keyWord = ['password', 'passwd', 'pwd'];
+module.exports = (options) => {
+  return async function createPassword(ctx, next) {
+    const { method, url } = ctx.request;
+    if (method === 'POST') {
+      const body = ctx.request.body;
+      const mid = _.pick(body, keyWord);
+      if (Object.keys(mid).length > 0) {
+        for (const key of Object.keys(mid)) {
+          ctx.request.body[key] = { secret: body[key] };
+        }
+      }
+    }
+    await next();
+  };
+};

+ 30 - 0
app/model/patent/agent_mech.js

@@ -0,0 +1,30 @@
+'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 { Secret } = require('naf-framework-mongoose/lib/model/schema');
+// 代理机构表
+const agent_mech = {
+  pid: { type: ObjectId }, // 管理员id
+  pid_name: { type: String }, // 管理员名称
+  mech_name: { type: String }, //机构名称
+  name: { type: String }, // 姓名
+  phone: { type: String }, // 手机号
+  password: { type: Secret, select: false }, // 密码
+  role: { type: String, default: '4' }, // 角色
+  remark: { type: String },
+};
+const schema = new Schema(agent_mech, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ pid: 1 });
+schema.index({ pid_name: 1 });
+schema.index({ mech_name: 1 });
+schema.index({ name: 1 });
+schema.index({ phone: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = (app) => {
+  const { mongoose } = app;
+  return mongoose.model('AgentMech', schema, 'agent_mech');
+};

+ 41 - 0
app/model/patent/answer_tea.js

@@ -0,0 +1,41 @@
+'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 { Secret } = require('naf-framework-mongoose/lib/model/schema');
+// 答题师表
+const answer_tea = {
+  name: { type: String }, // 姓名
+  phone: { type: String }, // 手机号
+  password: { type: Secret, select: false }, // 密码
+  card: { type: String }, // 身份证号
+  email: { type: String }, // 电子邮箱
+  address: { type: String }, // 地址
+  zwzc: { type: String }, // 职务职称
+  school: { type: String }, // 院校
+  major: { type: String }, // 专业
+  word_tel: { type: String }, // 办公电话
+  type: { type: String }, // 用户类型:1-咨询师;2-代理师;3-分析师
+  role: { type: String, default: '5' }, // 角色
+  remark: { type: String },
+};
+const schema = new Schema(answer_tea, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ name: 1 });
+schema.index({ phone: 1 });
+schema.index({ card: 1 });
+schema.index({ email: 1 });
+schema.index({ address: 1 });
+schema.index({ zwzc: 1 });
+schema.index({ school: 1 });
+schema.index({ major: 1 });
+schema.index({ word_tel: 1 });
+schema.index({ type: 1 });
+schema.index({ role: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = (app) => {
+  const { mongoose } = app;
+  return mongoose.model('AnswerTea', schema, 'answer_tea');
+};

+ 2 - 1
app/model/personal.js

@@ -24,6 +24,7 @@ const personal = {
   major: { type: String, required: false, maxLength: 200 }, // 专业
   card: { type: String, required: false, maxLength: 200 }, // 身份证号
   zwzc: { type: String, required: false, maxLength: 200 }, // 职务职称
+  role: { type: String, required: false, default: '3' }, // 角色
   create_time: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss') },
 };
 const schema = new Schema(personal, { toJSON: { virtuals: true } });
@@ -36,7 +37,7 @@ schema.index({ juris: 1 });
 schema.index({ profession: 1 });
 schema.index({ 'meta.createdAt': 1 });
 schema.plugin(metaPlugin);
-module.exports = app => {
+module.exports = (app) => {
   const { mongoose } = app;
   return mongoose.model('Personal', schema, 'personal');
 };

+ 5 - 2
app/router.js

@@ -3,7 +3,7 @@
 /**
  * @param {Egg.Application} app - egg application
  */
-module.exports = app => {
+module.exports = (app) => {
   const { router, controller } = app;
   router.get('/', controller.home.index);
   const profix = '/api/live/';
@@ -93,4 +93,7 @@ module.exports = app => {
   require('./router/patent/patenttrans')(app); // 专利交易表
   require('./router/patent/patenttechol')(app); // 专利需求表
   require('./router/patent/patentsafeg')(app); // 专利维权表
-};
+
+  require('./router/patent/agent_mech')(app); // 代理机构表
+  require('./router/patent/answer_tea')(app); // 答题师表
+};;

+ 12 - 0
app/router/patent/agent_mech.js

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

+ 12 - 0
app/router/patent/answer_tea.js

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

+ 15 - 0
app/service/patent/agent_mech.js

@@ -0,0 +1,15 @@
+'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 Agent_mechService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'agent_mech');
+    this.model = this.ctx.model.Patent.AgentMech;
+  }
+}
+
+module.exports = Agent_mechService;

+ 15 - 0
app/service/patent/answer_tea.js

@@ -0,0 +1,15 @@
+'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 Answer_teaService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'answer_tea');
+    this.model = this.ctx.model.Patent.AnswerTea;
+  }
+}
+
+module.exports = Answer_teaService;