123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- using Microsoft.AspNetCore.Mvc;
- using ProductionLineMonitor.Application.Services;
- using ProductionLineMonitor.Application.Services.OEEService;
- using ProductionLineMonitor.Application.Services.OEEService.Dtos;
- using ProductionLineMonitor.Core.Dtos;
- using ProductionLineMonitor.Core.IRepositories;
- using ProductionLineMonitor.Core.Models;
- using ProductionLineMonitor.Core.Services;
- using ProductionLineMonitor.Core.Utils;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ProductionLineMonitor.Web.Controllers
- {
- public class ReportFormController : BaseController
- {
- private readonly IReportFormService _reportFormService;
- private readonly IOEEService _oeeService;
- private readonly IExcelService _excelService;
- private readonly IUnitOfWork _unitOfWork;
- public ReportFormController(
- IReportFormService reportFormService,
- IOEEService oeeService,
- IExcelService excelService,
- IUnitOfWork unitOfWork)
- {
- _reportFormService = reportFormService;
- _oeeService = oeeService;
- _excelService = excelService;
- _unitOfWork = unitOfWork;
- }
- [HttpGet]
- public IActionResult Index()
- {
- //_excelService.EquipmentOperationReport(DateTime.Parse("2024-09-12 08:00:00"));
- return View();
- }
- [HttpGet]
- public IActionResult EquipmentOperationReport(DateTime dateTime)
- {
- _excelService.EquipmentOperationReport(dateTime);
- return Ok();
- }
- [HttpPost]
- public IActionResult GetMachineStatistic(string id, DateTime startTime, DateTime endTime)
- {
- ReportFormDto reportFormDto = new ReportFormDto();
- reportFormDto.Date = DateTimeHelper.GetDate(startTime, endTime);
- var oees = _reportFormService.GetMachineOEE(id, startTime, endTime.AddDays(1));
- var moduleTypes = GetModuleTypes(oees);
- foreach (var moduleType in moduleTypes)
- {
- Form form = new Form();
- form.Name = moduleType;
- form.Oee = GetOee(moduleType, oees);
- form.Capacity = GetCapacity(moduleType, oees);
- reportFormDto.Forms.Add(form);
- }
- return Ok(ResultDto<ReportFormDto>.Success(reportFormDto));
- }
- [HttpPost]
- public IActionResult GetMachineStatisticV1(string id, DateTime startTime, DateTime endTime)
- {
- //MachineOEE machine = new MachineOEE();
- List<MachineOEEInfo> lst = _oeeService.GetOEE(id,
- startTime.ToString("yyyy-MM-dd"), endTime.ToString("yyyy-MM-dd"));
- return Ok(ResultDto<List<MachineOEEInfo>>.Success(lst));
- }
- //[HttpPost]
- //public IActionResult GetMachineStatisticV2(string id, DateTime startTime, DateTime endTime, int peroid)
- //{
- // //MachineOEE machine = new MachineOEE();
- // Dictionary<string, List<MachineOEEInfoByPeriod>> lst = new Dictionary<string, List<MachineOEEInfoByPeriod>>();
- // if (peroid == 3)
- // {
- // lst = _oeeService.GetOEEByPeriod(id,
- // startTime.ToString("yyyy-MM"), endTime.ToString("yyyy-MM"), peroid,0);
- // }
- // else
- // {
- // lst = _oeeService.GetOEEByPeriod(id,
- // startTime.ToString("yyyy-MM-dd"), endTime.ToString("yyyy-MM-dd"), peroid, 0);
- // }
- // return Ok(ResultDto<Dictionary<string, List<MachineOEEInfoByPeriod>>>.Success(lst));
- //}
- [HttpPost]
- public IActionResult GetMachineStatisticV3(string id, DateTime startTime, DateTime endTime, int peroid, int shift)
- {
- List<MachineOEEInfoByPeriod> lst = new List<MachineOEEInfoByPeriod>();
- if (peroid == 3)
- {
- lst = _oeeService.GetOEEByPeriodV2(id,
- startTime.ToString("yyyy-MM"), endTime.ToString("yyyy-MM"), peroid, shift);
- }
- else
- {
- lst = _oeeService.GetOEEByPeriodV2(id,
- startTime.ToString("yyyy-MM-dd"), endTime.ToString("yyyy-MM-dd"), peroid, shift);
- }
- return Ok(ResultDto<List<MachineOEEInfoByPeriod>>.Success(lst));
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="id"></param>
- /// <param name="startTime"></param>
- /// <param name="endTime"></param>
- /// <param name="peroid"></param>//0:按班;1:天;2:周;3:月
- /// <param name="dayOrnight"></param>//peroid为0时有效,0:汇总,1:白班数据,2:夜班数据
- /// <returns></returns>
- [HttpPost]
- public IActionResult GetMachineStatisticV4(string id, DateTime startTime, DateTime endTime, int peroid, int dayOrnight)
- {
- var list = _oeeService.GetOEEByPeriod(id, startTime, endTime, peroid, dayOrnight);
- return Ok(ResultDto<Dictionary<string, List<MachineOEEInfoByPeriod>>>.Success(list));
- }
- [HttpPost]
- public IActionResult GetOEEExtendSetting(string ids)
- {
- var idList = ids.Split(',');
- var machine = _unitOfWork.Repository<Machine>().GetList().Where(x => idList.Contains(x.Id));
- Dictionary<string, string> DicOEEExtend = new Dictionary<string, string>();
- if (machine != null && machine.Count() != 0)
- {
- foreach (var item in machine)
- {
- DicOEEExtend.Add(item.Id, string.IsNullOrEmpty(item.OEEExtendSettings) ? "" : item.OEEExtendSettings);
- }
- }
- return Ok(ResultDto<Dictionary<string, string>>.Success(DicOEEExtend));
- }
- private List<object[]> GetOee(string moduleType, IEnumerable<MachineStatistic> oees)
- {
- var result = new List<object[]>();
- var data = oees.Where(x => x.ModuleType == moduleType);
- foreach (var item in data)
- {
- object[] o = new object[2];
- o[0] = item.Date.ToString("yyyy-MM-dd");
- if (item.OEE != null)
- {
- o[1] = Math.Round(item.OEE.Value * 100, 2);
- }
- result.Add(o);
- }
- return result;
- }
- private List<object[]> GetCapacity(string moduleType, IEnumerable<MachineStatistic> oees)
- {
- var result = new List<object[]>();
- var data = oees.Where(x => x.ModuleType == moduleType);
- foreach (var item in data)
- {
- object[] o = new object[2];
- o[0] = item.Date.ToString("yyyy-MM-dd");
- o[1] = item.Capacity;
- result.Add(o);
- }
- return result;
- }
- private List<string> GetModuleTypes(IEnumerable<MachineStatistic> oees)
- {
- List<string> result = new List<string>();
- foreach (var item in oees)
- {
- if (!result.Contains(item.ModuleType))
- {
- result.Add(item.ModuleType);
- }
- }
- return result;
- }
- }
- }
|