You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.7 KiB
C#

using Admin.Core.IRepository;
using Admin.Core.IService;
using Admin.Core.Model;
using Admin.Core.Model.Model_New;
using Admin.Core.Model.ViewModels;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Admin.Core.Service
{
public class OffLineInfoServices : BaseServices<OffLineInfo>, IOffLineInfoServices
{
private readonly IBaseRepository<OffLineInfo> _dal;
public OffLineInfoServices(IBaseRepository<OffLineInfo> dal)
{
this._dal = dal;
base.BaseDal = dal;
}
/// <summary>
/// 图表统计,按白夜班时间
/// </summary>
public async Task<List<ChartsByTime>> QueryCharts(DateTime startTime, DateTime endTime)
{
try
{
List<ChartsByTime> list = null;
var _db = this.BaseDal.Db;
list = await _db.Ado.SqlQueryAsync<ChartsByTime>($"WITH AllHours AS (SELECT TO_CHAR(to_date('{startTime}', 'YYYY-MM-DD HH24:MI:SS') + (LEVEL-1)/24, 'YYYY-MM-DD HH24') AS Hour FROM dual CONNECT BY LEVEL <= 12)SELECT AllHours.Hour AS HourlyTime, COUNT(PRODUCT_OFFLINE.PRODUCT_SCANTIME) AS Amount FROM AllHours LEFT JOIN AUCMA_SCADA.PRODUCT_OFFLINE ON AllHours.Hour = TO_CHAR(PRODUCT_OFFLINE.PRODUCT_SCANTIME, 'YYYY-MM-DD HH24') AND PRODUCT_OFFLINE.PRODUCT_SCANTIME >= TO_DATE('{startTime}', 'YYYY-MM-DD HH24:MI:SS') AND PRODUCT_OFFLINE.PRODUCT_SCANTIME <= TO_DATE('{endTime}', 'YYYY-MM-DD HH24:MI:SS') GROUP BY AllHours.Hour ORDER BY AllHours.Hour");
return list;
}
catch (Exception)
{
return null;
}
}
}
}