You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AUCMA_SCADA/Admin.Core.Service/Service_New/RecordBoxFoamFixtureComplat...

313 lines
12 KiB
C#

using Admin.Core.IRepository;
using Admin.Core.IService;
using Admin.Core.IService.IService_New;
using Admin.Core.Model;
using Admin.Core.Model.Model_New;
using Admin.Core.Model.ViewModels;
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Admin.Core.Service.Service_New
{
public class RecordBoxFoamFixtureComplateServices : BaseServices<RecordBoxFoamFixtureComplate>, IRecordBoxFoamFixtureComplateServices
{
private static readonly log4net.ILog logHelper = LogManager.GetLogger(typeof(RecordBoxFoamFixtureComplate));
private readonly IBaseRepository<RecordBoxFoamFixtureComplate> _dal;
private readonly IOldBoxFoamTypeServices _boxFoamTypeServices;
private readonly IBoxFoamPlanServices _boxFoamPlanServices;
private readonly IBoxFoamDataServices _oldBoxFoamDataServices;
private readonly ISysUserInfoServices _sysUserInfoServices;
private readonly IBaseSpaceInfoServices _baseSpaceInfoServices;
public RecordBoxFoamFixtureComplateServices(IBaseRepository<RecordBoxFoamFixtureComplate> dal, IOldBoxFoamTypeServices boxFoamTypeServices, IBoxFoamPlanServices boxFoamPlanServices, IBoxFoamDataServices oldBoxFoamDataServices, ISysUserInfoServices sysUserInfoServices, IBaseSpaceInfoServices baseSpaceInfoServices)
{
this._dal = dal;
base.BaseDal = dal;
_boxFoamTypeServices = boxFoamTypeServices;
_boxFoamPlanServices = boxFoamPlanServices;
_oldBoxFoamDataServices = oldBoxFoamDataServices;
_sysUserInfoServices = sysUserInfoServices;
_baseSpaceInfoServices = baseSpaceInfoServices;
}
/// <summary>
/// 保存夹具生产数量
/// </summary>
/// <param name="fixture"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public bool SaveFixtureComplate(List<RecordBoxFoamFixtureComplate> fixture,string productLineCode,string stationCode)
{
bool result = false;
try
{
foreach(var item in fixture)
{
//获取当前工位,前一条数据
var lastFixtureList = _dal.Query(x => x.ProductionLine == productLineCode && x.StationCode == stationCode && x.FixtureCode == item.FixtureCode);
if(lastFixtureList != null)
{
if (lastFixtureList.Count > 0)
{
RecordBoxFoamFixtureComplate lastFixtureComplate = lastFixtureList.OrderByDescending(x => x.RecordTime).First();
if (lastFixtureComplate != null)
{
if (item.FixtureBoxType == lastFixtureComplate.FixtureBoxType)
{
if (item.FixtureOutPut > lastFixtureComplate.FixtureOutPut)
{
item.RealOutPut = item.FixtureOutPut - lastFixtureComplate.FixtureOutPut;
//更新生产计划
UpdatePlanInfo(item,productLineCode,stationCode);
_dal.Add(item);
//更新小时数据
UpdateHourInfo(item, productLineCode, stationCode);
break;
}
}
}
}
}
_dal.Add(item);
//更新小时数据
UpdateHourInfo(item, productLineCode, stationCode);
}
}catch (Exception ex)
{
logHelper.Error("保存夹具生产完成记录异常", ex);
}
return result;
}
/// <summary>
/// 更新生产计划
/// </summary>
/// <param name="item"></param>
private void UpdatePlanInfo(RecordBoxFoamFixtureComplate item,string productLineCode,string stationCode)
{
try
{
//var boxFoamTypeList = _boxFoamTypeServices.Query(x => x.Boxtype == item.FixtureBoxType); //MaterialCode物料型号
var boxFoamTypeList = GetMaterialTypeBySpaceInfo(item.StationCode, item.FixtureBoxType);
if (boxFoamTypeList != null)
{
if (boxFoamTypeList.Count > 0)
{
foreach (var boxFoamType in boxFoamTypeList)
{
var boxPlanList = _boxFoamPlanServices.Query(x => x.ProductLineCode == productLineCode && x.StationCode == stationCode && x.MaterialCode == boxFoamType && x.PlanAmount > x.CompleteAmount);
if (boxPlanList != null)
{
if (boxPlanList.Count > 0)
{
var boxPlan = boxPlanList.OrderBy(x => x.CreateTime).First();
if (boxPlan != null)
{
boxPlan.CompleteAmount = boxPlan.CompleteAmount + item.RealOutPut;
bool planResult = _boxFoamPlanServices.UpdateAsync(boxPlan).Result;
if (planResult)
{
Console.WriteLine($"生产计划更新成功:{boxPlan.CompleteAmount}");
}
else
{
Console.WriteLine("生产计划更新失败");
}
break;
}
}
}
}
}
}
}catch (Exception ex)
{
logHelper.Error("更新计划信息异常", ex);
}
}
/// <summary>
/// 更新小时产量
/// </summary>
/// <param name="item"></param>
private void UpdateHourInfo(RecordBoxFoamFixtureComplate item,string producLineCode,string stationCode)
{
BoxFoamData hourData;
var hourDataList = _oldBoxFoamDataServices.Query(x=>x.ProductLineCode == producLineCode && x.StationCode == stationCode && x.MainId == item.FixtureCode && x.Fixtureboxtype == item.FixtureBoxType);
if(hourDataList != null)
{
if(hourDataList.Count > 0)
{
hourData = hourDataList.First();
if (hourData != null)
{
hourData = SetHourValue(hourData, item);
hourData.UpdatedTime = DateTime.Now;
hourData.Fixturestatus = item.FixtureStatus;
_oldBoxFoamDataServices.UpdateAsync(hourData);
return;
}
}
}
//添加小时计划
hourData = new BoxFoamData()
{
ProductLineCode = item.ProductionLine,
StationCode = item.StationCode,
Fixtureboxtype = item.FixtureBoxType,
MainId = item.FixtureCode,
UpdatedTime = DateTime.Now,
};
hourData = SetHourValue(hourData, item);
_oldBoxFoamDataServices.AddAsync(hourData);
}
private BoxFoamData SetHourValue(BoxFoamData hourData, RecordBoxFoamFixtureComplate item)
{
int hour = GetTeamHour(DateTime.Now).Seq;
switch (hour)
{
case 1:
hourData.AnHour = hourData.AnHour + item.RealOutPut;
break;
case 2:
hourData.TwoHour = hourData.TwoHour + item.RealOutPut; ;
break;
case 3:
hourData.ThreeHour = hourData.ThreeHour + item.RealOutPut;;
break;
case 4:
hourData.FourHour = hourData.FourHour + item.RealOutPut;;
break;
case 5:
hourData.FiveHour = hourData.FiveHour + item.RealOutPut;;
break;
case 6:
hourData.SixHour = hourData.SixHour + item.RealOutPut;;
break;
case 7:
hourData.SevenHour = hourData.SevenHour + item.RealOutPut;;
break;
case 8:
hourData.EightHour = hourData.EightHour + item.RealOutPut;;
break;
case 9:
hourData.NineHour = hourData.NineHour + item.RealOutPut;;
break;
case 10:
hourData.TenHour = hourData.TenHour + item.RealOutPut;;
break;
case 11:
hourData.ElevenHour = hourData.ElevenHour + item.RealOutPut;;
break;
case 12:
hourData.TwelveHour = hourData.TwelveHour + item.RealOutPut;;
break;
default:
break;
}
return hourData;
}
private CurrentTeamTimeView GetTeamHour(DateTime now)
{
var obj = _sysUserInfoServices.GetTeamData(now).Result;
if (obj != null)
{
return obj;
}
return null;
}
/// <summary>
/// 通过夹具箱型获取物料型号
/// 老线通过boxFoamTypeServices获取
/// 新线通过baseSpaceInfoServices获取夹具箱型添加在物料类型后通过_分割
/// </summary>
/// <param name="stationCode">老线1005新线1105</param>
/// <param name="boxType"></param>
/// <returns></returns>
private List<string> GetMaterialTypeBySpaceInfo(string stationCode,string boxType)
{
List<string> result = null;
if(stationCode == "1105")
{
if (string.IsNullOrEmpty(boxType))
{
var boxFoamTypeList = _boxFoamTypeServices.Query(x => x.Boxtype == boxType); //MaterialCode物料型号
if (boxFoamTypeList != null)
{
result = new List<string>();
foreach(var item in boxFoamTypeList)
{
result.Add(item.MaterialCode);
}
}
}
}
else
{
if (!string.IsNullOrEmpty(boxType))
{
List<BaseSpaceInfo> spaceInfos = _baseSpaceInfoServices.GetSpaceInfos("PQK-001");
if (spaceInfos != null)
{
var info = spaceInfos.Where(x=>x.BoxType == boxType);
if(info != null)
{
spaceInfos = info.ToList();
if (spaceInfos != null)
{
result = new List<string>();
foreach (var item in spaceInfos)
{
result.Add(item.MaterialType);
}
}
}
}
}
}
return result;
}
}
}