|
|
using Admin.Core.IRepository;
|
|
|
using Admin.Core.IService;
|
|
|
using Admin.Core.Model;
|
|
|
using Admin.Core.Model.Model_New;
|
|
|
using Admin.Core.Model.ViewModels;
|
|
|
using Consul;
|
|
|
using log4net;
|
|
|
using Microsoft.IdentityModel.Logging;
|
|
|
using SqlSugar;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace Admin.Core.Service
|
|
|
{
|
|
|
public class CodeBindingRecordServices : BaseServices<CodeBindingRecord>, ICodeBindingRecordServices
|
|
|
{
|
|
|
#region 对象引用
|
|
|
private static readonly log4net.ILog log = LogManager.GetLogger(typeof(CodeBindingRecordServices));
|
|
|
#endregion
|
|
|
|
|
|
private readonly IBaseRepository<CodeBindingRecord> _dal;
|
|
|
private ICodeBindingRecordRepository _codeBindingRecordRepository;
|
|
|
public CodeBindingRecordServices(IBaseRepository<CodeBindingRecord> dal, ICodeBindingRecordRepository codeBindingRecordRepository)
|
|
|
{
|
|
|
this._dal = dal;
|
|
|
base.BaseDal = dal;
|
|
|
_codeBindingRecordRepository = codeBindingRecordRepository;
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 查询图表信息,扫描产品类型统计
|
|
|
/// </summary>
|
|
|
public async Task<List<CodeBindCharts>> QueryCharts()
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
List<CodeBindCharts> list = null;
|
|
|
var _db = this.BaseDal.Db;
|
|
|
list = await _db.CopyNew().Ado.SqlQueryAsync<CodeBindCharts>("SELECT BOX_NAME as BoxName,COUNT(*) as Amount FROM CODE_BINDING WHERE PRODUCT_CODE IS NOT NULL GROUP BY BOX_NAME ");
|
|
|
list.OrderBy(x =>x.BoxName);
|
|
|
return list;
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 时间段条件查询
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public async Task<List<CodeBindingRecord>> QueryAllByTime(string time1, string time2)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
List<CodeBindingRecord> list = null;
|
|
|
// 默认查询最近三天的数据,防止信息过多
|
|
|
if (string.IsNullOrEmpty(time1) && string.IsNullOrEmpty(time2))
|
|
|
{
|
|
|
list = await _codeBindingRecordRepository.QueryAsync(d => d.RecordTime2 >= System.DateTime.Now.AddDays(-1));
|
|
|
}
|
|
|
else if (!string.IsNullOrEmpty(time1) && string.IsNullOrEmpty(time2))
|
|
|
{
|
|
|
DateTime BeginTime = Convert.ToDateTime(Convert.ToDateTime(time1).ToString("yyyy-MM-dd"));
|
|
|
list = await _codeBindingRecordRepository.QueryAsync(d => d.RecordTime2 >= BeginTime);
|
|
|
}
|
|
|
else if (string.IsNullOrEmpty(time1) && !string.IsNullOrEmpty(time2))
|
|
|
{
|
|
|
DateTime EndTime = Convert.ToDateTime(Convert.ToDateTime(time2).ToString("yyyy-MM-dd"));
|
|
|
list = await _codeBindingRecordRepository.QueryAsync(d => d.RecordTime2 <= EndTime);
|
|
|
}
|
|
|
else if (!string.IsNullOrEmpty(time1) && !string.IsNullOrEmpty(time2))
|
|
|
{
|
|
|
DateTime BeginTime = Convert.ToDateTime(Convert.ToDateTime(time1).ToString("yyyy-MM-dd"));
|
|
|
DateTime EndTime = Convert.ToDateTime(Convert.ToDateTime(time2).ToString("yyyy-MM-dd"));
|
|
|
list = await _codeBindingRecordRepository.QueryAsync(d => d.RecordTime2 >= BeginTime && d.RecordTime2 <= EndTime);
|
|
|
}
|
|
|
return list.OrderByDescending(x => x.RecordTime2).ToList();
|
|
|
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
log.Error("时间段条件查询QueryAllByTime()出现异常:" + ex);
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 查询第一条数据
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public async Task<CodeBindingRecord> FirstAsync()
|
|
|
{
|
|
|
|
|
|
return await _codeBindingRecordRepository.FirstAsync();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
///查询条码2为null的数据,并取最新的一条
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public async Task<List<CodeBindingRecord>> QueryByTime()
|
|
|
{
|
|
|
return await _codeBindingRecordRepository.QueryAsync(x => x.ProductCode == null, "RECORD_TIME1 DESC");
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|