SpcRepository.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using ProductionLineMonitor.Core.Dtos;
  2. using ProductionLineMonitor.Core.IRepositories;
  3. using ProductionLineMonitor.Core.Models;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. namespace ProductionLineMonitor.EntityFramework.Repositories
  8. {
  9. public class SpcRepository : BaseRepository<Spc>, ISpcRepository
  10. {
  11. public SpcRepository(ProductionLineContext context) : base(context)
  12. {
  13. }
  14. public void CreateSpc(string machineId, string lasermark, float[] values)
  15. {
  16. var spc = new Spc()
  17. {
  18. MachineId = machineId,
  19. Lasermark = lasermark
  20. };
  21. _entities.Add(spc);
  22. }
  23. public IEnumerable<SpcDto> GetSpcs(string machineId, DateTime startTime, DateTime endTime)
  24. {
  25. List<SpcDto> dtos = new List<SpcDto>();
  26. var models = _entities.Where(x => x.DataTime >= startTime && x.DataTime < endTime).OrderBy(x => x.DataTime);
  27. foreach (var item in models)
  28. {
  29. SpcDto dto = new SpcDto
  30. {
  31. DataTime = item.DataTime,
  32. MachineId = machineId,
  33. Lasermark = item.Lasermark
  34. };
  35. string[] modelValues = item.Values.Split(',');
  36. float[] dtoValues = new float[modelValues.Length];
  37. for (int i = 0; i < modelValues.Length; i++)
  38. {
  39. dtoValues[i] = Convert.ToSingle(modelValues[i]);
  40. }
  41. dto.Values = dtoValues;
  42. dtos.Add(dto);
  43. }
  44. return dtos;
  45. }
  46. }
  47. }