1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using ProductionLineMonitor.Core.Dtos;
- using ProductionLineMonitor.Core.IRepositories;
- using ProductionLineMonitor.Core.Models;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ProductionLineMonitor.EntityFramework.Repositories
- {
- public class SpcRepository : BaseRepository<Spc>, ISpcRepository
- {
- public SpcRepository(ProductionLineContext context) : base(context)
- {
- }
- public void CreateSpc(string machineId, string lasermark, float[] values)
- {
- var spc = new Spc()
- {
- MachineId = machineId,
- Lasermark = lasermark
- };
- _entities.Add(spc);
- }
- public IEnumerable<SpcDto> GetSpcs(string machineId, DateTime startTime, DateTime endTime)
- {
- List<SpcDto> dtos = new List<SpcDto>();
- var models = _entities.Where(x => x.DataTime >= startTime && x.DataTime < endTime).OrderBy(x => x.DataTime);
- foreach (var item in models)
- {
- SpcDto dto = new SpcDto
- {
- DataTime = item.DataTime,
- MachineId = machineId,
- Lasermark = item.Lasermark
- };
- string[] modelValues = item.Values.Split(',');
- float[] dtoValues = new float[modelValues.Length];
- for (int i = 0; i < modelValues.Length; i++)
- {
- dtoValues[i] = Convert.ToSingle(modelValues[i]);
- }
- dto.Values = dtoValues;
- dtos.Add(dto);
- }
- return dtos;
- }
- }
- }
|