123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- 'use strict';
- const Service = require('egg').Service;
- class DictService extends Service {
- async place() {
- const { ctx } = this;
- const agg = [
- { $lookup: { from: 't_sync_city', localField: 'province_id', foreignField: 'province_id', as: 'cities' } },
- ];
- return await ctx.model.TSyncProvinceModel.aggregateFix(agg);
- }
- async msgType() {
- const { ctx } = this;
- return await ctx.model.MsgTypeModel.find({ parent_id: 0 });
- }
- // 车系
- async car({ carType }) {
- const { ctx } = this;
- const cond = [{ $match: {} }];
- if (carType) {
- cond[0].$match._id = { $in: ctx.helper.carType[carType] };
- }
- const agg = [
- { $sort: { _id: -1 } },
- { $limit: 1 },
- { $unwind: '$car' },
- { $match: { 'car._id.series_code': { $ne: null } } },
- { $group: {
- _id: '$car._id.series_code',
- name: { $first: '$car.series_name' }, code: { $first: '$car._id.series_code' },
- children: { $addToSet: { name: '$car.model_name', code: '$car._id.model_code' } },
- },
- },
- ...cond,
- ];
- return await ctx.model.Local.TVehicleRecordModel.aggregateFix(agg);
- }
- // 远控失败类型
- async rcFailType() {
- const { ctx } = this;
- const agg = [
- { $unwind: '$remoteControlFailure' },
- { $match: { 'remoteControlFailure._id': { $ne: null } } },
- { $group: { _id: '$remoteControlFailure._id' } },
- { $project: { _id: 0, name: '$_id' } },
- ];
- return await ctx.model.Local.AppBehaviorRecordModel.aggregateFix(agg);
- }
- // 自动化测试流程id
- async autoTest() {
- const { ctx } = this;
- const agg = [
- { $unwind: '$autoTest' },
- { $match: { 'autoTest._id': { $ne: null } } },
- { $group: { _id: '$autoTest._id' } },
- { $project: { _id: 0, name: '$_id' } },
- ];
- return await ctx.model.Local.TBoxAutoTestingStatsModel.aggregateFix(agg);
- }
- // 获取通用字典数据
- async index({ p_code }) {
- const { ctx } = this;
- if (p_code) {
- return await ctx.model.Local.DictModel.find({ p_code });
- }
- return await ctx.model.Local.DictModel.find({});
- }
- }
- module.exports = DictService;
|