using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WIDESEA_Core; using WIDESEA_Core.BaseRepository; using WIDESEA_Core.BaseServices; using WIDESEA_Core.Helper; using WIDESEA_DTO.ERP; using WIDESEA_DTO.Inbound; using WIDESEA_DTO.MES; using WIDESEA_External.ERPService; using WIDESEA_IBasicRepository; using WIDESEA_IInboundRepository; using WIDESEA_IInboundService; using WIDESEA_Model.Models; namespace WIDESEA_InboundService { public class ProInStatisticsService : ServiceBase, IProInStatisticsService { public IProInStatisticsRepository Repository => BaseDal; private readonly IUnitOfWorkManage _unitOfWorkManage; private readonly IInvokeERPService _invokeERPService; private readonly IBasicRepository _basicRepository; public ProInStatisticsService(IProInStatisticsRepository BaseDal, IUnitOfWorkManage unitOfWorkManag,IInvokeERPService invokeERPService,IBasicRepository basicRepository) : base(BaseDal) { _unitOfWorkManage = unitOfWorkManag; _invokeERPService = invokeERPService; _basicRepository = basicRepository; } public void SaveStatic(MesBagInfoModel mesBagInfoModel) { List mESBagDetails = mesBagInfoModel.BagDetails.GroupBy(x=>new { x.ProductCode, x.ProductVersion }).Select(x=>new ProInStaticDTO { ProductCode= x.Key.ProductCode, ProductVersion= x.Key.ProductVersion, SumPcs=x.Sum(x => x.OKPCSQTY) }).ToList(); List proInStatistics= new List(); Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x=>x.WarehouseCode==mesBagInfoModel.WarehouseCode); foreach (var m in mESBagDetails) { string response = _invokeERPService.InvokeProInErpStatic(m.ProductCode, m.ProductCode + m.ProductVersion); ErpProInErpStaticResponseContent erpProInErpStatic = response.DeserializeObject(); if (erpProInErpStatic.Code != 200) { return; } float adjusted = (float)Math.Round(erpProInErpStatic.Data[0].UnitArea, 3); Dt_ProInStatistics inStatistics = new Dt_ProInStatistics() { WarehouseId = warehouse.WarehouseId, ProductCode = m.ProductCode, ProductRev = m.ProductVersion, PcsQty = m.SumPcs, SquareMeter = (float)Math.Round((adjusted * m.SumPcs), 3), Remark = mesBagInfoModel.BatchNo }; proInStatistics.Add(inStatistics); } BaseDal.AddData(proInStatistics); } /// /// 获取月份产量 /// /// public WebResponseContent GetMonthProductions() { WebResponseContent content=new WebResponseContent(); try { DateTime date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); List list = new List(); //本月总天数 int daysInMonth = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month); for (int i = 1; i <= daysInMonth; i++) { DateTime dateTime = date.AddDays(i); //获取数据 var dayProDuctions = BaseDal.QueryData(x => x.CreateDate <= dateTime && x.CreateDate >= dateTime.AddDays(-1)).Sum(x => x.SquareMeter); list.Add(new { dateNow= dateTime.AddHours(-1).ToString("yyyy-MM-dd"), dayProDuctions }); } content.OK("成功",list); } catch (Exception ex) { content.Error(ex.Message); } return content; } } }