'use strict'; const Controller = require('../extend/baseController'); class UrgencyController extends Controller { tag() { return this.ctx.service.urgencyService; } async list() { const { ctx } = this; const user = ctx.user; ctx.query.userid = user._id; ctx.setOrder('createTime', true); // 倒序 const result = await this.tag().list(ctx.query); ctx.success(result); } // 分页查询 async listForPage() { const { ctx, service } = this; const user = ctx.user; const level = user.dept.level; // 判断当前的dept权限 和传入的5级权限 不能超过当前人dept if (!ctx.query.dept1) { delete ctx.query.dept1; } if (!ctx.query.dept2) { delete ctx.query.dept2; } if (!ctx.query.dept3) { delete ctx.query.dept3; } if (!ctx.query.dept4) { delete ctx.query.dept4; } if (!ctx.query.dept5) { delete ctx.query.dept5; } delete ctx.query.deptId; // admin的dept 存在冲突,所以它不需要结合 if (user.role._id != this.app.config.defaultAdminRoleId) { ctx.query['dept' + level] = user.dept._id; } // 判断如果当前是采集员看数据的话 只能看他自己 if (user.role._id + '' == this.app.config.defaultUserRoleId) { ctx.query.userName = user.loginName; } const result = await service.urgencyService.listForPage(ctx.query); ctx.success(result); } async urgencyFirst() { const { ctx, service } = this; const user = ctx.user; const level = user.dept.level; // 判断当前的dept权限 和传入的5级权限 不能超过当前人dept if (!ctx.query.dept1) { delete ctx.query.dept1; } if (!ctx.query.dept2) { delete ctx.query.dept2; } if (!ctx.query.dept3) { delete ctx.query.dept3; } if (!ctx.query.dept4) { delete ctx.query.dept4; } if (!ctx.query.dept5) { delete ctx.query.dept5; } delete ctx.query.deptId; // admin的dept 存在冲突,所以它不需要结合 if (user.role._id != this.app.config.defaultAdminRoleId) { ctx.query['dept' + level] = user.dept._id; } const result = await service.urgencyService.urgencyFirst(ctx.query); ctx.success(result); } } module.exports = UrgencyController;