123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- 'use strict';
- const Controller = require('../extend/baseController');
- const moment = require('moment/moment');
- class SysDeptController extends Controller {
- tag() {
- return this.ctx.service.sysDeptService;
- }
- async addDeptAndPerson() {
- const { ctx } = this;
- const query = ctx.request.body;
- delete query._id;
- const result = await this.tag()
- .addDeptAndPerson(query);
- if (result) {
- ctx.error(result);
- } else {
- ctx.success();
- }
- }
- async updateDeptAndPerson() {
- const { ctx, service } = this;
- const query = ctx.request.body;
- const { id } = query;
- delete query.id;
- const result = await service.sysDeptService.updateDeptAndPerson(id, query);
- if (result) {
- ctx.error(result);
- } else {
- ctx.success();
- }
- }
- // 数据迁移
- async dataMigration() {
- const { ctx, service } = this;
- const query = ctx.request.body;
- const { id } = query;
- delete query.id;
- const result = await service.sysDeptService.dataMigration(id, query);
- if (result) {
- ctx.error(result);
- } else {
- ctx.success();
- }
- }
- // 迁移数据查询
- async listDept() {
- const { ctx } = this;
- ctx.setOrder();
- const result = await this.tag().listDept(ctx.query);
- ctx.success(result);
- }
- async deleteWithSub() {
- const { ctx } = this;
- const query = ctx.query;
- const { id } = query;
- const result = await this.tag()
- .deleteWithSub(id);
- if (result) {
- ctx.error(result);
- } else {
- ctx.success();
- }
- }
- async listSortAsc() {
- const { ctx } = this;
- ctx.setOrder();
- const result = await this.tag()
- .list(ctx.query);
- ctx.success(result);
- }
- async listSortAscWithUser() {
- const { ctx } = this;
- const query = ctx.query;
- const user = ctx.user;
- ctx.setOrder();
- if (user.role._id != this.app.config.defaultAdminRoleId) {
- if (user[ 'dept' + query.level ]) {
- ctx.query._id = this.app.mongoose.Types.ObjectId(user[ 'dept' + query.level ]._id);
- }
- }
- const result = await this.tag()
- .list(query);
- ctx.success(result);
- }
- async listForPageSortWithUser() {
- const { ctx, service } = this;
- const query = ctx.query;
- const user = ctx.user;
- query.deptId = user.dept._id;
- query.level = user.dept.level;
- query.roleId = user.role._id;
- ctx.setOrder();
- const result = await service.sysDeptService.listForPageSortWithUser(query);
- ctx.success(result);
- }
- async orderChange() {
- const { ctx, service } = this;
- const query = ctx.query;
- const { id, type } = query;
- const result = await service.sysDeptService.orderChange(id, type);
- if (result) {
- ctx.error(result);
- } else {
- ctx.success();
- }
- }
- async findLink() {
- const { ctx, service } = this;
- const query = ctx.query;
- const result = await service.sysDeptService.findLink(query);
- ctx.logic(result);
- }
- async managerPayByDept5() {
- const { ctx } = this;
- const { model } = this.ctx;
- const query = ctx.request.body;
- if (!query.useDay) {
- ctx.error('请输入使用期限!');
- return;
- }
- const today = moment(Date.now()).format('YYYY-MM-DD');
- const nowTime = moment(Date.now()).format('YYYY-MM-DD HH:mm:ss');
- const afterTime = moment(Date.now()).add(query.useDay, 'day').format('YYYY-MM-DD HH:mm:ss');// 意思是10分钟以前
- const user = ctx.user;
- query.dept1 = user.dept1;
- query.dept2 = user.dept2;
- query.dept3 = user.dept3;
- query.dept4 = user.dept4;
- query.dept5 = user.dept5;
- query.userid = user._id;
- query.startTime = nowTime;
- query.endTime = afterTime;
- query.status = 1;
- if (user.role._id != this.app.config.defaultManagerRoleId) {
- ctx.error('当前系统仅支持社区/村级管理员享受服务,如有其他需求请联系管理员!');
- return;
- }
- const result = await model.SysDeptPayModel.create(query);
- ctx.success(result);
- }
- async managerPayByDept5List() {
- const { ctx } = this;
- const { model } = this.ctx;
- const query = ctx.request.body;
- const user = ctx.user;
- // query.userid = user._id;
- query.dept5 = user.dept5;
- query.status = 1;
- const result = await model.SysDeptPayModel.find(query).count();
- ctx.success(result);
- }
- }
- module.exports = SysDeptController;
|