urgencyService.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. 'use strict';
  2. const Service = require('../service/baseService');
  3. const sm4 = require('../util/sm4').sma4;
  4. class UrgencyService extends Service {
  5. tag() {
  6. return this.ctx.model.UrgencyModel;
  7. }
  8. // 分页查询
  9. async listForPage(data) {
  10. const { model } = this.ctx;
  11. const page = data.page;
  12. const rows = Number.parseInt(data.rows) || this.app.config.defaultPageSize;
  13. delete data.page;
  14. delete data.rows;
  15. const where = {};
  16. if (data.dept1) {
  17. where.dept1 = this.app.mongoose.Types.ObjectId(data.dept1);// 省
  18. }
  19. if (data.dept2) {
  20. where.dept2 = this.app.mongoose.Types.ObjectId(data.dept2); // 市
  21. }
  22. if (data.dept3) {
  23. where.dept3 = this.app.mongoose.Types.ObjectId(data.dept3); // 区
  24. }
  25. if (data.dept4) {
  26. where.dept4 = this.app.mongoose.Types.ObjectId(data.dept4); // 乡
  27. }
  28. if (data.dept5) {
  29. where.dept5 = this.app.mongoose.Types.ObjectId(data.dept5); // 社区
  30. }
  31. if (data.userName) {
  32. const result = await model.SysUserModel.find({ loginName: { $regex: data.userName } }); // TODO 数据加密处理-CH 这里不用加,因为这个前端传的是loginName
  33. if (result.length > 0) {
  34. where.userid = result[0]._id;
  35. } else {
  36. return '';
  37. }
  38. }
  39. if (data.managerName) {
  40. const result = await model.SysUserModel.find({ loginName: { $regex: data.managerName } });
  41. if (result.length > 0) {
  42. where.managerid = result[0]._id;
  43. } else {
  44. return '';
  45. }
  46. }
  47. if (data.oldName) {
  48. where.oldName = sm4.encrypt_ECB(data.oldName); // TODO 数据加密处理-CH
  49. }
  50. if (data.status) {
  51. where.status = '' + data.status;
  52. }
  53. if (data.startTime && data.endTime) {
  54. where.createTime = { $gte: new Date(data.startTime + ' 00:00:00'), $lt: new Date(data.endTime + ' 23:59:59') };
  55. }
  56. this.ctx.logger.info('条件', where);
  57. const pop = [
  58. {
  59. path: 'dept1',
  60. select: 'name',
  61. },
  62. {
  63. path: 'dept2',
  64. select: 'name',
  65. },
  66. {
  67. path: 'dept3',
  68. select: 'name',
  69. },
  70. {
  71. path: 'dept4',
  72. select: 'name',
  73. },
  74. {
  75. path: 'dept5',
  76. select: 'name',
  77. },
  78. {
  79. path: 'visitId',
  80. },
  81. {
  82. path: 'userid',
  83. select: 'loginName userName',
  84. },
  85. {
  86. path: 'managerid',
  87. select: 'loginName userName',
  88. },
  89. ];
  90. const total = await model.UrgencyModel.find(where).populate(pop).countDocuments();
  91. const result = await model.UrgencyModel.find(where).populate(pop).skip((page - 1) * rows)
  92. .limit(rows)
  93. .sort({ createTime: -1 });
  94. return {
  95. count: total,
  96. list: result,
  97. };
  98. }
  99. async urgencyFirst(data) {
  100. const { model } = this.ctx;
  101. const infodata = data;
  102. if (infodata.dept4) {
  103. infodata.status = 2;
  104. } else {
  105. infodata.status = 1;
  106. }
  107. const total = await model.InfoModel.find(infodata).countDocuments();
  108. data.status = '0';
  109. const JJtotal = await model.UrgencyModel.find(data).countDocuments();
  110. return {
  111. count: total,
  112. jjcount: JJtotal,
  113. };
  114. }
  115. }
  116. module.exports = UrgencyService;