using Aucma.Scada.Model.domain ;
using Aucma.Scada.Model.dto ;
using HighWayIot.Log4net ;
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
namespace HighWayIot.Repository.service.Impl
{
public class CodeBindingRecordServiceImpl : ICodeBindingRecordServices
{
Repository < CodeBindingRecord > _repository = > new Repository < CodeBindingRecord > ( "scada" ) ;
private LogHelper logHelper = LogHelper . Instance ;
public bool BindingCode ( string boxCode , string linerCode , BaseMaterialInfo materialInfo )
{
CodeBindingRecord codeBindingRecord = new CodeBindingRecord ( ) ;
if ( materialInfo = = null )
{
codeBindingRecord . BoxName = "" ;
}
else
{
codeBindingRecord . BoxName = materialInfo . MaterialName ;
}
codeBindingRecord . BoxCode = boxCode ;
codeBindingRecord . LinerCode = linerCode ;
codeBindingRecord . RecordTime1 = DateTime . Now ;
codeBindingRecord . BindingResult = "成功" ;
codeBindingRecord . Position1 = 1 ;
return _repository . Insert ( codeBindingRecord ) ;
}
/// <summary>
/// 根据箱体码查询绑定记录
/// </summary>
public CodeBindingRecord QueryByShell ( string boxCode )
{
CodeBindingRecord record = _repository . GetFirst ( x = > x . BoxCode = = boxCode ) ;
return record ;
}
/// <summary>
/// 查询今天绑定记录
/// </summary>
public List < CodeBindingRecord > QueryByTime ( )
{
List < CodeBindingRecord > list = _repository . GetList ( x = > x . Position1 = = 1 & & x . RecordTime1 > = DateTime . Today & & x . RecordTime1 < DateTime . Today . AddDays ( 1 ) ) ;
return list ;
}
/// <summary>
/// 更新绑定记录
/// </summary>
public bool Update ( CodeBindingRecord record )
{
bool result = _repository . Update ( record ) ;
return result ;
}
/// <summary>
/// 查询图表信息,扫描产品类型统计
/// </summary>
public async Task < List < CodeBindCharts > > QueryCharts ( )
{
try
{
List < CodeBindCharts > list = null ;
var _db = _repository . Context ;
list = await _db . SqlQueryable < CodeBindCharts > ( "SELECT BOX_NAME as BoxName, COUNT(*) as Amount FROM CODE_BINDING WHERE POSITION1=1 AND TRUNC(RECORD_TIME1) = TRUNC(SYSDATE) GROUP BY BOX_NAME" ) . ToListAsync ( ) ;
list . OrderBy ( x = > x . BoxName ) ;
return list ;
}
catch ( Exception )
{
return null ;
}
}
}
}