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 _repository => new Repository("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); } /// /// 根据箱体码查询绑定记录 /// public CodeBindingRecord QueryByShell(string boxCode) { CodeBindingRecord record =_repository.GetFirst(x=>x.BoxCode == boxCode); return record; } /// /// 查询今天绑定记录 /// public List QueryByTime() { List list = _repository.GetList(x=>x.Position1 == 1 && x.RecordTime1 >= DateTime.Today && x.RecordTime1 < DateTime.Today.AddDays(1)); return list; } /// /// 更新绑定记录 /// public bool Update(CodeBindingRecord record) { bool result = _repository.Update(record); return result; } /// /// 查询图表信息,扫描产品类型统计 /// public async Task> QueryCharts() { try { List list = null; var _db = _repository.Context; list = await _db.SqlQueryable("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; } } } }