dictService.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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({ carType }) {
  17. const { ctx } = this;
  18. const cond = [{ $match: {} }];
  19. if (carType) {
  20. cond[0].$match._id = { $in: ctx.helper.carType[carType] };
  21. }
  22. const agg = [
  23. { $sort: { _id: -1 } },
  24. { $limit: 1 },
  25. { $unwind: '$car' },
  26. { $match: { 'car._id.series_code': { $ne: null } } },
  27. { $group: {
  28. _id: '$car._id.series_code',
  29. name: { $first: '$car.series_name' }, code: { $first: '$car._id.series_code' },
  30. children: { $addToSet: { name: '$car.model_name', code: '$car._id.model_code' } },
  31. },
  32. },
  33. ...cond,
  34. ];
  35. return await ctx.model.Local.TVehicleRecordModel.aggregateFix(agg);
  36. }
  37. // 远控失败类型
  38. async rcFailType() {
  39. const { ctx } = this;
  40. const agg = [
  41. { $unwind: '$remoteControlFailure' },
  42. { $match: { 'remoteControlFailure._id': { $ne: null } } },
  43. { $group: { _id: '$remoteControlFailure._id' } },
  44. { $project: { _id: 0, name: '$_id' } },
  45. ];
  46. return await ctx.model.Local.AppBehaviorRecordModel.aggregateFix(agg);
  47. }
  48. // 自动化测试流程id
  49. async autoTest() {
  50. const { ctx } = this;
  51. const agg = [
  52. { $unwind: '$autoTest' },
  53. { $match: { 'autoTest._id': { $ne: null } } },
  54. { $group: { _id: '$autoTest._id' } },
  55. { $project: { _id: 0, name: '$_id' } },
  56. ];
  57. return await ctx.model.Local.TBoxAutoTestingStatsModel.aggregateFix(agg);
  58. }
  59. // 获取通用字典数据
  60. async index({ p_code }) {
  61. const { ctx } = this;
  62. if (p_code) {
  63. return await ctx.model.Local.DictModel.find({ p_code });
  64. }
  65. return await ctx.model.Local.DictModel.find({});
  66. }
  67. }
  68. module.exports = DictService;