dictService.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. 'use strict';
  2. const Service = require('egg').Service;
  3. class DictService extends Service {
  4. async place() {
  5. const { ctx } = this;
  6. const agg = [
  7. { $lookup: { from: 't_sync_city', localField: 'province_id', foreignField: 'province_id', as: 'cities' } },
  8. ];
  9. return await ctx.model.TSyncProvinceModel.aggregateFix(agg);
  10. }
  11. async msgType() {
  12. const { ctx } = this;
  13. return await ctx.model.MsgTypeModel.find({ parent_id: 0 });
  14. }
  15. // 车系
  16. async car() {
  17. const { ctx } = this;
  18. const agg = [
  19. { $sort: { _id: -1 } },
  20. { $limit: 1 },
  21. { $unwind: '$car' },
  22. { $match: { 'car._id.series_code': { $ne: null } } },
  23. { $group: {
  24. _id: '$car._id.series_code',
  25. name: { $first: '$car.series_name' }, code: { $first: '$car._id.series_code' },
  26. children: { $addToSet: { name: '$car.model_name', code: '$car._id.model_code' } },
  27. },
  28. },
  29. ];
  30. return await ctx.model.Local.TVehicleRecordModel.aggregateFix(agg);
  31. }
  32. // 远控失败类型
  33. async rcFailType() {
  34. const { ctx } = this;
  35. const agg = [
  36. { $unwind: '$remoteControlFailure' },
  37. { $match: { 'remoteControlFailure._id': { $ne: null } } },
  38. { $group: { _id: '$remoteControlFailure._id' } },
  39. { $project: { _id: 0, name: '$_id' } },
  40. ];
  41. return await ctx.model.Local.AppBehaviorRecordModel.aggregateFix(agg);
  42. }
  43. // 自动化测试流程id
  44. async autoTest() {
  45. const { ctx } = this;
  46. const agg = [
  47. { $unwind: '$autoTest' },
  48. { $match: { 'autoTest._id': { $ne: null } } },
  49. { $group: { _id: '$autoTest._id' } },
  50. { $project: { _id: 0, name: '$_id' } },
  51. ];
  52. return await ctx.model.Local.TBoxAutoTestingStatsModel.aggregateFix(agg);
  53. }
  54. }
  55. module.exports = DictService;