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, IOffLineInfoServices { private readonly IBaseRepository _dal; public OffLineInfoServices(IBaseRepository dal) { this._dal = dal; base.BaseDal = dal; } /// /// 图表统计,按白夜班时间 /// public async Task> QueryCharts(DateTime startTime, DateTime endTime) { try { List list = null; var _db = this.BaseDal.Db; list = await _db.Ado.SqlQueryAsync($"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; } } } }