Ejemplo n.º 1
0
        public async Task <PopularResult <List <VeComStaDto> > > GetVeComStaAsync(VeComStaQueryDto dto)
        {
            var result                 = new PopularResult <List <VeComStaDto> >();
            var oilCostQuery           = _oilCostRepoitory.Where(x => x.RefuelingTime >= dto.StartTime && x.RefuelingTime <= dto.EndTime).GroupBy(x => x.VehicleId).Select(x => new { VeId = x.Key, OilCost = x.Sum(i => i.Expend) });
            var mileageQuery           = _vehicleMileageRepository.Where(x => x.RecordDate >= dto.StartTime && x.RecordDate <= dto.EndTime).GroupBy(x => x.VehicleId).Select(x => new { VeId = x.Key, Mileage = (x.Max(i => i.Mileage) - x.Min(i => i.Mileage)) });
            var maintenanceExpendQuery = _maintenanceRepository.Where(x => x.RecordTime >= dto.StartTime && x.RecordTime <= dto.EndTime).GroupBy(x => x.VehicleId).Select(x => new { VeId = x.Key, maintenanceExpend = x.Sum(i => i.Expend) });
            var all = from v in _vehicleRepository.Where(x => x.IsDelete == 0).WhereIf(dto.UnitId.HasValue, x => x.UnitId == dto.UnitId.Value)
                      join oil in oilCostQuery on v.Id equals oil.VeId into voil
                      from newvoil in voil.DefaultIfEmpty()
                      join mil in mileageQuery on v.Id equals mil.VeId into vmil
                      from newvmil in vmil.DefaultIfEmpty()
                      join mai in maintenanceExpendQuery on v.Id equals mai.VeId into vmai
                      from newvmai in vmai.DefaultIfEmpty()
                      select new VeComStaDto()
            {
                License     = v.License,
                OilCost     = newvoil.OilCost,
                Mileage     = newvmil.Mileage,
                Maintenance = newvmai.maintenanceExpend
            };

            var list = await AsyncExecuter.ToListAsync(all);

            result.Success(list);
            return(result);
        }
Ejemplo n.º 2
0
        public async Task <PopularResult <PagedResultDto <VehicleMileageDto> > > GetListAsync(VehicleMileageQueryDto dto)
        {
            var result = new PopularResult <PagedResultDto <VehicleMileageDto> >();

            var queryable = _vehicleMileageRepository.Where(x => x.IsDelete == dto.IsDelete)
                            .WhereIf(!dto.License.IsNullOrWhiteSpace(), vehicleMileage => vehicleMileage.Vehicle.License.Contains(dto.License));

            var query = from v in queryable.PageBy(dto.SkipCount, dto.MaxResultCount)
                        join
                        u in _vehicleRepository.WhereIf(!dto.License.IsNullOrWhiteSpace(), vehicle => vehicle.License.Contains(dto.License))
                        on v.VehicleId equals u.Id
                        into cls
                        from c in cls.DefaultIfEmpty()
                        select new VehicleMileageEntity(v.Id)
            {
                FileName   = v.FileName,
                Mileage    = v.Mileage,
                RecordDate = v.RecordDate,
                Vehicle    = c,
                VehicleId  = v.VehicleId,
                //IsDelete = v.IsDelete,
                CreateTime = v.CreateTime,
                Creator    = v.Creator,
                Remark     = v.Remark,
            };


            var vehicleMileages = await AsyncExecuter.ToListAsync(query.PageBy(dto.SkipCount, dto.MaxResultCount));

            var totalCount = await AsyncExecuter.CountAsync(queryable);

            var dtos = ObjectMapper.Map <List <VehicleMileageEntity>, List <VehicleMileageDto> >(vehicleMileages);

            result.Success(new PagedResultDto <VehicleMileageDto>(totalCount, dtos));
            return(result);
        }