lrf402788946 4 gadi atpakaļ
vecāks
revīzija
6a4307366a

+ 4 - 5
app/controller/.user.js

@@ -10,6 +10,7 @@ module.exports = {
       "remark",
       "type",
       "uid",
+      "status",
     ],
   },
   destroy: {
@@ -28,6 +29,7 @@ module.exports = {
       "remark",
       "type",
       "uid",
+      "status",
     ],
   },
   show: {
@@ -44,6 +46,7 @@ module.exports = {
         type: "type",
         openid: "openid",
         appopenid: "appopenid",
+        status: "status",
       },
     },
     service: "query",
@@ -55,10 +58,6 @@ module.exports = {
     },
   },
   appbind: {
-    requestBody: [
-      "name",
-      "mobile",
-      "appopenid",
-    ],
+    requestBody: ["name", "mobile", "appopenid"],
   },
 };

+ 1 - 1
app/controller/questionnaire.js

@@ -49,7 +49,7 @@ class QuestionnaireController extends Controller {
   }
 
   async export() {
-    const res = await this.service.export(this.ctx.request.body);
+    const res = await this.service.toExport(this.ctx.request.body);
     this.ctx.ok({ data: res });
   }
 }

+ 17 - 0
app/model/menu.js

@@ -0,0 +1,17 @@
+// 'use strict';
+// const Schema = require('mongoose').Schema;
+// const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// const Menu = {
+//   title: { type: String, required: true, maxLength: 200 }, // 名称
+//   router: { type: String, required: true, maxLength: 200 }, // 路由
+//   status: { type: String, required: true, maxLength: 200, default: '0' }, // 状态:0=>使用中;1=>已禁用
+// };
+// const schema = new Schema(Menu, { toJSON: { virtuals: true } });
+// schema.index({ id: 1 });
+// schema.plugin(metaPlugin);
+
+// module.exports = app => {
+//   const { mongoose } = app;
+//   return mongoose.model('Menu', schema, 'menu');
+// };

+ 1 - 1
app/model/user.js

@@ -14,7 +14,7 @@ const UserSchema = {
   remark: { type: String, required: false }, // 备注
   type: { type: String, required: false, maxLength: 200 }, // 身份,0、中心管理元1、班主任用户2、学校用户3、教师4、学生
   uid: { type: String, required: false, maxLength: 200 }, // 关联用户信息id
-  status: { type: String, required: false, default: '0' }, // 注册状态
+  status: { type: String, required: false, default: '0' }, // 注册状态,0注册;1正在使用;2冻结
 };
 
 

+ 1 - 2
app/service/headteacher.js

@@ -48,8 +48,7 @@ class HeadteacherService extends CrudService {
 
   async delete({ id }) {
     const res = await this.model.findByIdAndDelete(id);
-    const _user = await this.umodel.findOne({ uid: id, thpe: '1' });
-    _user.delete();
+    await this.umodel.deleteOne({ uid: id, thpe: '1' });
     return res;
   }
 

+ 9 - 2
app/service/school.js

@@ -172,23 +172,29 @@ class SchoolService extends CrudService {
   }
   // 整理excel数据
   async getDataFromExcel(url) {
+    // 请求文件
     const file = await this.ctx.curl(`${url}`);
     if (!(file && file.data)) {
       throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到上传的名单');
     }
     const workbook = new Excel.Workbook();
+    // 读取文件
     await workbook.xlsx.load(file.data);
     const worksheet = workbook.getWorksheet(1);
     if (!worksheet) {
       throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未发现excel中有工作表');
     }
+    // 获取表头,通过方法的返回值,将写死的表头数组返回 回来
     const cols = this.getStucolumn();
+    // 第一行(表头)
     const headRow = worksheet.getRow(1);
+    // 设置,检查表头
     headRow.eachCell((cell, coli) => {
       if (cell.value !== '序号') {
         const r = cols.find(f => f.key === cell.value);
         if (r) {
           const ri = cols.findIndex(f => f.key === cell.value);
+          // 表头符合要求,做上标记
           r.colIndex = coli;
           cols[ri] = r;
         } else {
@@ -197,12 +203,13 @@ class SchoolService extends CrudService {
       }
 
     });
+    // 检查表头结果,如果有没有 colIndex,说明表头里有不符合要求的,退回去
     const excelIsRigth = cols.find(f => f.colIndex);
     if (!excelIsRigth) throw new BusinessError(ErrorCode.DATA_INVALID, 'Excel表格格式不正确,请使用系统提供的模板!');
-    // 删除掉第一行
+    // 删除掉第一行 表头行,这不是数据
     worksheet.spliceRows(0, 1);
     const stuList = [];
-    // 整理数据
+    // 整理数据,根据检查合格的表头行,获取每个格子的数据,制成[object]格式
     worksheet.eachRow(row => {
       const stu = {};
       for (let i = 0; i < cols.length; i++) {

+ 55 - 10
app/service/user.js

@@ -16,12 +16,37 @@ class UserService extends CrudService {
     this.schModel = this.ctx.model.School;
     this.hModel = this.ctx.model.Headteacher;
   }
-
+  async query({ name, ...info }, options) {
+    const newoptions = await this.ctx.service.util.getQueryOptions(options);
+    const query = { ...info };
+    if (name) {
+      query.name = { $regex: name };
+    }
+    let res = await this.model.find(query, '+passwd', newoptions).exec();
+    res = JSON.parse(JSON.stringify(res));
+    for (const user of res) {
+      if (user) {
+        const { passwd } = user;
+        user.passwd = passwd.secret;
+      }
+    }
+    return res;
+  }
+  async count({ name, ...info }) {
+    const query = { ...info };
+    if (name) {
+      query.name = { $regex: name };
+    }
+    const res = await this.model.count(query);
+    return res;
+  }
   // 重写创建方法
   async create(data) {
     const { name, mobile, passwd, type, gender } = data;
     assert(name && mobile && passwd && type, '缺少部分信息项');
-    assert(/^\d{11}$/i.test(mobile), 'mobile无效');
+    if (type !== '0') {
+      assert(/^\d{11}$/i.test(mobile), 'mobile无效');
+    }
     const newdata = data;
     newdata.passwd = { secret: passwd };
     const res = await this.model.create(newdata);
@@ -35,7 +60,7 @@ class UserService extends CrudService {
     return res;
   }
 
-  async update({ id }, { name, mobile, passwd, openid }) {
+  async update({ id }, { name, mobile, passwd, openid, status }) {
     assert(id, '缺少部分信息项');
     const user = await this.model.findById(id);
     if (!user) {
@@ -53,7 +78,11 @@ class UserService extends CrudService {
     if (openid) {
       user.openid = openid;
     }
-    user.status = '1';
+    if (status) {
+      user.status = status;
+    } else {
+      user.status = '1';
+    }
     await user.save();
     return user;
   }
@@ -86,7 +115,9 @@ class UserService extends CrudService {
       user.unionid = unionid;
       await user.save();
     } else {
-      const stud = await this.stuModel.findOne({ id_number: { $regex: `^${id_number}$`, $options: 'i' } });
+      const stud = await this.stuModel.findOne({
+        id_number: { $regex: `^${id_number}$`, $options: 'i' },
+      });
       if (!stud) {
         throw new BusinessError(ErrorCode.USER_NOT_EXIST);
       }
@@ -95,7 +126,14 @@ class UserService extends CrudService {
       await stud.save();
       // 再次检查是否有该用户,需要用uid查
       const have_user = await this.model.findOne({ uid: stud.id });
-      const newdata = { name: stud.name, mobile: stud.phone, type: '4', uid: stud.id, openid, unionid };
+      const newdata = {
+        name: stud.name,
+        mobile: stud.phone,
+        type: '4',
+        uid: stud.id,
+        openid,
+        unionid,
+      };
       if (have_user) {
         if (stud.name) have_user.name = stud.name;
         if (stud.phone) have_user.mobile = stud.phone;
@@ -128,7 +166,8 @@ class UserService extends CrudService {
           headers: {
             userid: uid,
             openid,
-          } };
+          },
+        };
         await mq.topic('qrcode.bind', qrcode, msg, parm);
       } else {
         this.ctx.logger.error('!!!!!!没有配置MQ插件!!!!!!');
@@ -218,7 +257,12 @@ class UserService extends CrudService {
     for (const sch of schools) {
       const user = await this.model.findOne({ uid: sch.id, type: '2' });
       if (!user) {
-        const newdata = { name: sch.name, mobile: sch.code, type: '2', uid: sch.id };
+        const newdata = {
+          name: sch.name,
+          mobile: sch.code,
+          type: '2',
+          uid: sch.id,
+        };
         newdata.passwd = { secret: '12345678' };
         await this.model.create(newdata);
       }
@@ -229,7 +273,9 @@ class UserService extends CrudService {
   // 学生小程序绑定
   async appbind(data) {
     const { name, mobile, appopenid } = data;
-    console.error(`appBind: name=>${name} / mobile=>${mobile} / appopenid = ${appopenid}`);
+    console.error(
+      `appBind: name=>${name} / mobile=>${mobile} / appopenid = ${appopenid}`
+    );
     assert(name, '缺少姓名');
     assert(mobile, '缺少手机号');
     assert(appopenid, '缺少小程序openid');
@@ -245,7 +291,6 @@ class UserService extends CrudService {
     // );
     return res;
   }
-
 }
 
 module.exports = UserService;

+ 10 - 1
app/service/util.js

@@ -89,9 +89,18 @@ class UtilService extends CrudService {
     //   },
     //   { noAck: true }
     // );
-
     // // ch.close();
   }
+  async getQueryOptions({ skip, limit, sort, desc } = {}) {
+    if (sort && _.isString(sort)) {
+      sort = { [sort]: desc ? -1 : 1 };
+    } else if (sort && _.isArray(sort)) {
+      sort = sort
+        .map(f => ({ [f]: desc ? -1 : 1 }))
+        .reduce((p, c) => ({ ...p, ...c }), {});
+    }
+    return { skip, limit, sort };
+  }
 
   /**
    * 更新进度,状态 不存在/完成以外(不是2的值)的数值, 不添加参数,只更新进度

+ 3 - 0
config/config.default.js

@@ -129,6 +129,9 @@ module.exports = appInfo => {
   config.mission = {
     baseUrl: 'http://127.0.0.1:7004',
   };
+  config.auth = {
+    baseUrl: 'http://127.0.0.1:7006',
+  };
 
   // 安全配置
   config.security = {