提交最新源码

main
CaesarBao 2 weeks ago
parent 2270faec18
commit bd28d4f107

@ -300,6 +300,11 @@
<returns></returns>
</member>
<!-- Badly formed XML comment ignored for member "M:Admin.Core.Api.xl_materialController.ExecPlcCode(System.Int32,System.Int32,System.String,System.Decimal,System.String)" -->
<member name="M:Admin.Core.Api.xl_materialController.GetBindBarrelWeight">
<summary>
查询料桶重量
</summary>
</member>
<member name="M:Admin.Core.Api.xl_materialController.BindBarrel(System.String)">
<summary>
检量称扫码绑定桶(新加)
@ -421,6 +426,13 @@
<param name="view">json 对象</param>
<returns></returns>
</member>
<member name="M:Admin.Core.Api.Controllers.Business.WarehouseController.DownLoadplanInfo(System.Collections.Generic.List{Admin.Core.Model.ViewModels.MesDownLoadPlanList})">
<summary>
MES计划下发
</summary>
<param name="MesDownLoadPlanList"></param>
<returns></returns>
</member>
<member name="M:Admin.Core.Api.Controllers.Business.WarehouseController.ExecPlcState(System.String,System.Int32)">
<summary>
投料口开/投料口关
@ -431,7 +443,7 @@
</member>
<member name="M:Admin.Core.Api.Controllers.Business.WarehouseController.GetWeight">
<summary>
查询称量重量
查询称量信息
</summary>
<param name="WeightNo"></param>
<returns></returns>

@ -1949,6 +1949,21 @@
Nullable:True
</summary>
</member>
<member name="P:Admin.Core.Model.Pmt_weigh.TheoryRate">
<summary>
理论固含
</summary>
</member>
<member name="P:Admin.Core.Model.Pmt_weigh.IsRate">
<summary>
是否有固含
</summary>
</member>
<member name="P:Admin.Core.Model.Pmt_weigh.RateWeight">
<summary>
固含量
</summary>
</member>
<member name="T:Admin.Core.Model.RT_plan">
<summary>
生产计划
@ -2660,6 +2675,11 @@
Nullable:True
</summary>
</member>
<member name="P:Admin.Core.Model.xl_recipe.IsCheck">
<summary>
是否产前验证
</summary>
</member>
<member name="T:Admin.Core.Model.xl_weigh">
<summary>
配方信息
@ -4582,12 +4602,12 @@
投料整包完整信息
</summary>
</member>
<member name="P:Admin.Core.Model.ViewModels.MesDownLoadPlanList.RecipeID">
<member name="P:Admin.Core.Model.ViewModels.MesDownLoadPlanList.No">
<summary>
配方编号
</summary>
</member>
<member name="P:Admin.Core.Model.ViewModels.MesDownLoadPlanList.Batch">
<member name="P:Admin.Core.Model.ViewModels.MesDownLoadPlanList.PId">
<summary>
批次号
</summary>

@ -150,6 +150,24 @@ namespace Admin.Core.Api
}
#endregion
/// <summary>
/// 查询料桶重量
/// </summary>
[HttpGet]
public async Task<MessageModel<decimal>> GetBindBarrelWeight()
{
try
{
decimal result = await _xl_materialService.GetBindBarrelWeight();
return Success(result, "成功");
}
catch (Exception ex)
{
return Failed<decimal>("执行失败!");
}
}
#region 检量称扫码绑定桶(新加)
/// <summary>
/// 检量称扫码绑定桶(新加)

@ -15,6 +15,7 @@ using Admin.Core.Model.ViewModels;
using Microsoft.AspNetCore.Mvc.ViewEngines;
using System.Collections;
using NPOI.SS.Formula.Functions;
using TouchSocket.Core;
namespace Admin.Core.Api.Controllers.Business
{
@ -125,36 +126,49 @@ namespace Admin.Core.Api.Controllers.Business
}
return Failed<bool>("执行失败!");
}
/// <summary>
/// MES计划下发
/// </summary>
/// <param name="MesDownLoadPlanList"></param>
/// <returns></returns>
[HttpPost]
public async Task<MessageModel<bool>> DownLoadplanInfo([FromBody] List<MesDownLoadPlanList> MesDownLoadPlanList)
{
try
{
int iFlag = 0;
if (MesDownLoadPlanList == null || MesDownLoadPlanList.Count == 0)
{
return Failed<bool>("传入参数为空!");
}
string result1 = await _hw_WarehouseService.DownRJPlanAsync(MesDownLoadPlanList);
string result2 = await _hw_WarehouseService.DownZBPlanAsync(MesDownLoadPlanList);
string result3 = await _hw_WarehouseService.DownXLPlanAsync(MesDownLoadPlanList);
foreach (var item in MesDownLoadPlanList)
{
if (item.RecipeID == "")
if (result1.Contains("成功"))
{
return Failed<bool>("传入参数为空!");
if (result2.Contains("成功"))
{
if (result3.Contains("成功"))
{
return Success(true);
}
var result = await _hw_WarehouseService.InsertXLPlanInfo(DateTime.Now, item.RecipeID, item.Batch, item.ProductName);
if (result)
else
{
iFlag = iFlag + 1;
return Failed<bool>(result3 + "执行失败!");
}
}
if (iFlag == MesDownLoadPlanList.Count)
else
{
return Success(true);
return Failed<bool>(result2 + "执行失败!");
}
}
else
{
return Failed<bool>(result1 + "执行失败!");
}
////配方名或配方编号
//string ss1 = "a82d016e813c4ac3bca0244c519da591";
////批次号
@ -166,7 +180,7 @@ namespace Admin.Core.Api.Controllers.Business
}
catch (Exception ex)
{
return Failed<bool>(ex.Message + "执行失败!");
}
return Failed<bool>("执行失败!");
}
@ -193,7 +207,7 @@ namespace Admin.Core.Api.Controllers.Business
return Failed<bool>("执行失败!");
}
/// <summary>
/// 查询称量重量
/// 查询称量信息
/// </summary>
/// <param name="WeightNo"></param>
/// <returns></returns>

@ -42,7 +42,8 @@ namespace Admin.Core.Api
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseIIS().UseStartup<Startup>();
webBuilder.UseUrls("http://*:6062").UseIIS().UseStartup<Startup>();
//webBuilder.UseIIS().UseStartup<Startup>();
})
.ConfigureLogging((hostingContext, builder) =>
{

@ -24,7 +24,7 @@
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": "true",
"applicationUrl": "http://localhost:5001;http://localhost:5000"
"applicationUrl": "http://119.45.202.115:5001;http://119.45.202.115:6061"
//"applicationUrl": "http://192.168.137.1:5001;http://192.168.137.1:5000"
}

@ -81,7 +81,7 @@
"Enabled": true,
"HitRate": 50,
//"Connection": "Data Source=192.168.10.50;Initial Catalog=cwss_xl;User ID=sa;Password=sa;Integrated Security=false;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",
"Connection": "Data Source=127.0.0.1;Initial Catalog=cwss_xl;User ID=sa;Password=123456;Integrated Security=false;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",
"Connection": "Data Source=119.45.202.115;Initial Catalog=cwss_xl;User ID=sa;Password=haiwei@123;Integrated Security=false;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",
//"Connection": "Data Source=192.168.10.50;Initial Catalog=cwss_xl;User ID=sa;Password=sa;Integrated Security=false;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",
"ProviderName": "System.Data.SqlClient"
@ -171,7 +171,7 @@
{
"Id": 2,
"EquipName": "溶剂PLC",
"IP": "127.0.0.1",
"IP": "127.0.0.2",
"Port": 102
}
],

@ -80,7 +80,7 @@
"DBType": 1,
"Enabled": true,
"HitRate": 50,
"Connection": "Data Source=127.0.0.1;Initial Catalog=cwss_xl;User ID=sa;Password=123456;Integrated Security=false;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",
"Connection": "Data Source=127.0.0.1;Initial Catalog=cwss_xl;User ID=sa;Password=haiwei@123;Integrated Security=false;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",
//"Connection": "Data Source=192.168.10.50;Initial Catalog=cwss_xl;User ID=sa;Password=sa;Integrated Security=false;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",
"ProviderName": "System.Data.SqlClient"
}

@ -19,8 +19,10 @@ namespace Admin.Core.IService
Task<string> RealWeightInfo(string WeightNo);
Task<BarrelView> GetXlInfo(string kettleBarCode, string planId, string code);
Task<List<string>> GetWarehousePlan(string code);
Task<string> DownRJPlanAsync(List<MesDownLoadPlanList> MesDownLoadPlanList);
Task<string> DownZBPlanAsync(List<MesDownLoadPlanList> MesDownLoadPlanList);
Task<bool> InsertXLPlanInfo(DateTime planDate, string recipeGUID, string batch, string productName);
Task<string> DownXLPlanAsync(List<MesDownLoadPlanList> MesDownLoadPlanList);
Task<List<XLPlanWeightView>> GetPlanWeightInfo();
}

@ -29,6 +29,13 @@ namespace Admin.Core.IService
/// <returns></returns>
Task<int> BindBarrel(string code);
/// <summary>
/// 查询料桶重量
/// add by CaesarBao,2024.10.14
/// </summary>
/// <returns></returns>
Task<decimal> GetBindBarrelWeight();
Task<MessageModel<bool>> MaterialVerification(string barCode);
Task<bool> xlInsertMaterial(string materialCode, string materialName);

@ -64,5 +64,20 @@ namespace Admin.Core.Model
/// Nullable:True
/// </summary>
public decimal? Cpk_Error { get; set; }
/// <summary>
/// 理论固含
/// </summary>
public decimal TheoryRate { get; set; }
/// <summary>
/// 是否有固含
/// </summary>
public bool IsRate { get; set; }
/// <summary>
/// 固含量
/// </summary>
public double RateWeight { get; set; }
}
}

@ -20,7 +20,7 @@ namespace Admin.Core.Model
/// Default:
/// Nullable:False
/// </summary>
[SugarColumn(IsPrimaryKey = true)]
// [SugarColumn(IsPrimaryKey = true)]
public int Dosing_Id { get; set; }
/// <summary>
/// Desc:
@ -34,7 +34,7 @@ namespace Admin.Core.Model
/// Default:
/// Nullable:False
/// </summary>
[SugarColumn(IsPrimaryKey = true)]
// [SugarColumn(IsPrimaryKey = true)]
public string Equip_Code { get; set; }
/// <summary>
/// Desc:

@ -20,7 +20,6 @@ namespace Admin.Core.Model
/// Default:
/// Nullable:False
/// </summary>
[SugarColumn(IsPrimaryKey = true)]
public int Dosing_Id { get; set; }
/// <summary>
/// Desc:计划Id
@ -34,7 +33,6 @@ namespace Admin.Core.Model
/// Default:
/// Nullable:False
/// </summary>
[SugarColumn(IsPrimaryKey = true)]
public string Equip_Code { get; set; }
/// <summary>
/// Desc:排序字段

@ -153,5 +153,9 @@ public string Creator { get; set; }
/// Nullable:True
/// </summary>
public DateTime? CreateDateTime { get; set; }
/// <summary>
/// 是否产前验证
/// </summary>
public int IsCheck { get; set; }
}
}

@ -5,15 +5,36 @@ public class MesDownLoadPlanList
/// <summary>
/// 配方编号
/// </summary>
public string RecipeID { get; set; }
public string No { get; set; }
/// <summary>
/// 批次号
/// </summary>
public string Batch { get; set; }
public string PId { get; set; }
/// <summary>
/// 产品名称
/// </summary>
public string ProductName { get; set; }
public string BinId { get; set; }
public string Material_Code { get; set; }
public string MaterialName { get; set; }
public string MaterialType { get; set; }
public string SetWeight { get; set; }
public string SetError { get; set; }
public string Difference { get; set; }
public string Fixed { get; set; }
public string FixedRatio { get; set; }
public string PumpCode { get; set; }
public string Weighbridge { get; set; }
public string Recipe { get; set; }
public string Remark { get; set; }
public string Tare { get; set; }
public string MainId { get; set; }
}

@ -10,6 +10,7 @@ namespace Admin.Core.Repository
{
public Pmt_materialRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
{
}
}
}

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@ -17,6 +17,7 @@
<ItemGroup>
<ProjectReference Include="..\Admin.Core.IRepository\Admin.Core.IRepository.csproj" />
<ProjectReference Include="..\Admin.Core.IService\Admin.Core.IService.csproj" />
<ProjectReference Include="..\Admin.Core.Repository\Admin.Core.Repository.csproj" />
<ProjectReference Include="..\Admin.Core.RunPlc\Admin.Core.RunPlc.csproj" />
</ItemGroup>

@ -15,6 +15,10 @@ using System.Numerics;
using System.Text;
using NPOI.POIFS.FileSystem;
using System.Linq.Expressions;
using NPOI.SS.Formula.Functions;
using Admin.Core.Repository;
using Microsoft.AspNetCore.SignalR;
using Admin.Core.Common;
namespace Admin.Core.Service
{
@ -23,6 +27,7 @@ namespace Admin.Core.Service
private static readonly log4net.ILog log = LogManager.GetLogger(typeof(Hw_WarehouseServices));
private readonly IBaseRepository<Hw_Warehouse> _dal;
private readonly IHw_WarehouseRepository _wareHouse;
private readonly IPmt_materialRepository _material;
private readonly IHw_WareHouse_SubRepository _wareHouse_Sub;
private readonly IHw_FeedReportRepository _feed;
private readonly IHw_BarrelRepository _barrel;
@ -30,13 +35,21 @@ namespace Admin.Core.Service
private readonly Ixl_recipeRepository _recipeRepository;
private readonly ILR_weighRepository _lrWeighRepository;
private readonly Ixl_planRepository _planRepository;//小料计划
private readonly IHw_PumpRepository _hwPumpRepository;
private readonly IRT_planRepository _rtplanRepository;
private readonly IPmt_weighRepository _pmtWeighRepository;
private readonly IPmt_BinRepository _binRepository;
private readonly IPmt_recipeRepository _pmtRecipeRepository;
private readonly IUnitOfWork _unitOfWork;
private readonly Ixl_weighRepository _xlWeighRepository;
private readonly IXLPlan_weightRepository _XLPlan_weightRepository;
public Hw_WarehouseServices(IBaseRepository<Hw_Warehouse> dal, IHw_WarehouseRepository wareHouse,
IHw_WareHouse_SubRepository wareHouse_Sub, IHw_FeedReportRepository feed,
IHw_BarrelRepository barrel, Ixl_materialRepository materialRepository,
Ixl_recipeRepository recipeRepository, ILR_weighRepository lrWeighRepository, Ixl_planRepository planRepository, IXLPlan_weightRepository IXLPlan_weightRepository, IXLPlan_weightRepository xLPlan_weightRepository)
Ixl_recipeRepository recipeRepository, ILR_weighRepository lrWeighRepository, Ixl_planRepository planRepository, IXLPlan_weightRepository IXLPlan_weightRepository, IXLPlan_weightRepository xLPlan_weightRepository, IPmt_materialRepository PmtmaterialRepository, IHw_PumpRepository hwPumpRepository, IRT_planRepository rtplanRepository, IPmt_recipeRepository pmtRecipeRepository, IUnitOfWork unitOfWork, IPmt_weighRepository pmtWeighRepository, IPmt_BinRepository binRepository, Ixl_weighRepository xlWeighRepository)
{
this._dal = dal;
base.BaseDal = dal;
@ -49,6 +62,14 @@ namespace Admin.Core.Service
_lrWeighRepository = lrWeighRepository;
_planRepository = planRepository;
_XLPlan_weightRepository = xLPlan_weightRepository;
_material = PmtmaterialRepository;
_hwPumpRepository = hwPumpRepository;
_rtplanRepository = rtplanRepository;
_pmtRecipeRepository = pmtRecipeRepository;
_unitOfWork = unitOfWork;
_pmtWeighRepository = pmtWeighRepository;
_binRepository = binRepository;
_xlWeighRepository = xlWeighRepository;
}
#region 扫描桶二维码,获取绑定的小料配方物料
@ -137,6 +158,8 @@ namespace Admin.Core.Service
}
}
#endregion
#region GetNextSerialNum 获取下一个可用的序号SerialNum 规则:同机台、同日期、同班次 计划号最后2位的最大值加1
/// <summary>
/// 获取下一个可用的序号
@ -144,6 +167,22 @@ namespace Admin.Core.Service
/// <param name="planDate">计划生产日期</param>
/// <returns>返回可用的序号</returns>
public int GetNextSerialNumAsync()
{
string strSql = "SELECT MAX(Plan_Serial) FROM RT_plan";
Expression<Func<RT_plan, bool>> exp = s1 => true;
Expression<Func<RT_plan, object>> order = (x) => x.Plan_Serial;
var result = _rtplanRepository.Query(exp,order,false).First();
if (result == null)
{
return 1;
}
else
{
return Convert.ToInt32(result.Plan_Serial) + 1;
}
}
public int GetXLNextSerialNumAsync()
{
string strSql = "SELECT MAX(Plan_Serial) FROM xl_plan";
@ -160,6 +199,24 @@ namespace Admin.Core.Service
}
}
public int GetNextSerialNumFromLRPlan(DateTime planDate)
{
string strSql = "SELECT MAX(RIGHT(Plan_Id,2)) FROM Hw_plan WHERE LEFT(Plan_Id,8) = @PlanDate";
string ss = String.Format("{0:yyyyMMdd}", planDate);
SugarParameter[] parameters = new SugarParameter[]
{
new SugarParameter($"@PlanDate", String.Format("{0:yyyyMMdd}", planDate))
};
var result = _planRepository.ExecSql(strSql, parameters);
if (result == null)
{
return 1;
}
else
{
return Convert.ToInt32(result) + 1;
}
}
public int GetXLNextSerialNumFromLRPlan(DateTime planDate)
{
string strSql = "SELECT MAX(RIGHT(Plan_Id,2)) FROM LR_plan WHERE LEFT(Plan_Id,8) = @PlanDate";
string ss = String.Format("{0:yyyyMMdd}", planDate);
@ -177,7 +234,6 @@ namespace Admin.Core.Service
return Convert.ToInt32(result) + 1;
}
}
#endregion
/// <summary>
/// 获取下一个可用的计划号 (6位日期、2位机台、1位班次、1位网络/本机、2位流水)
@ -217,66 +273,672 @@ namespace Admin.Core.Service
}
#endregion
public async Task<bool> InsertXLPlanInfo(DateTime planDate, string recipeGUID, string batch, string productName)
public async Task<string> DownRJPlanAsync(List<MesDownLoadPlanList> MesDownLoadPlanList)
{
try
{
int shiftID = 1;
//根据配方编号查询
var recipe = await _recipeRepository.FirstAsync(d => d.Recipe_Verify == 1 && d.ID == recipeGUID);
if (recipe == null)
var list = MesDownLoadPlanList;
List<Hw_WareHouse_Sub> subList = new List<Hw_WareHouse_Sub>();
List<Pmt_recipe> recipeList = new List<Pmt_recipe>();
list.ForEach((a) =>
{
Hw_WareHouse_Sub sb = new Hw_WareHouse_Sub();
sb.MainId = int.Parse(a.MainId);
sb.PId = a.PId;
sb.ProductName = a.ProductName;
sb.MaterialID = a.Material_Code;
sb.Material_Code = a.Material_Code;
sb.MaterialName = a.MaterialName;
sb.MaterialType = a.MaterialType;
sb.SetWeight = Convert.ToDecimal(a.SetWeight);
sb.SetError = Convert.ToDecimal(a.SetError);
sb.Difference = a.Difference;
sb.Fixed = a.Fixed == "" || a.Fixed == null ? false : true;
sb.FixedRatio = a.FixedRatio == "" || a.FixedRatio == null ? Convert.ToDecimal(0.00) : Convert.ToDecimal(a.FixedRatio);
sb.Weighbridge = a.Weighbridge;
sb.PumpCode = a.PumpCode;
sb.Recipe = a.Recipe;
sb.Remark = a.Remark;
sb.CreateTime = DateTime.Now;
sb.Tare = Convert.ToDecimal(a.Tare);
subList.Add(sb);
});
//查询溶剂数据
var xlList = subList.Where(d => d.MaterialType.Contains("溶剂")).ToList();
var xt = (from d in xlList
select new
{
d.PId,
d.ProductName,
d.MaterialType,
d.Recipe,
d.Weighbridge,
d.PumpCode
}).Distinct().ToList();
if (xt.Count == 0)
{
return "成功";
}
foreach (var item in xt)
{
try
{
recipe.ID = recipeGUID;
recipe.Recipe_Name = recipeGUID;
#region 配方
string recipeCode = Guid.NewGuid().ToString("N");
string recipeID = Guid.NewGuid().ToString("N");
Pmt_recipe recipe = new Pmt_recipe();
recipe.ID = recipeID;
recipe.Equip_Code = "01";
recipe.Recipe_Code = recipeCode;
recipe.Version = "1";
recipe.Recipe_Name = item.Recipe;
recipe.Recipe_Verify = 1;
recipe.Total_Weight = 0;
recipe.Total_Error = 0;
recipe.CreateDateTime = DateTime.Now;
#endregion
#region 物料
var repiceList = xlList.Where(d => item.PId.Equals(d.PId) && item.ProductName.Equals(d.ProductName) && item.Recipe.Equals(d.Recipe)).ToList();
int i = 1;
List<Pmt_weigh> weighList = new List<Pmt_weigh>();
foreach (var sub in repiceList)
{
Pmt_weigh material = new Pmt_weigh();
material.ID = Guid.NewGuid().ToString("N");
material.Equip_Code = "01";
material.Recipe_ID = recipeID;
material.Weight_Id = i;
if (sub.Material_Code == null | sub.Material_Code == "")
{
throw new Exception("未查询到物料!");
}
var obj = await _material.FirstAsync(d => d.Material_code == sub.Material_Code);
if (obj == null)
{
throw new Exception("未查询到当前物料!");
}
material.Material_ID = obj.ID.ToString();
material.Set_Weight = Convert.ToDecimal(sub.SetWeight);
material.Set_Error = Convert.ToDecimal(sub.SetError);
recipe.Total_Weight = recipe.Total_Weight + material.Set_Weight;
recipe.Total_Error = recipe.Total_Error + material.Set_Error;
if (sub.Fixed)
{
material.IsRate = true;
material.TheoryRate = Convert.ToDecimal(sub.FixedRatio);
}
else
{
material.IsRate = false;
material.TheoryRate = 0;
}
weighList.Add(material);
i++;
}
#endregion
#region 计划
RT_plan plan = new RT_plan();
plan.Dosing_Id = 0;
plan.Equip_Code = "01";
plan.Batch = item.PId;
plan.ProductName = item.ProductName;
int serialNum = 0;
int rtPlanSNum = GetNextSerialNumAsync(); //xl_plan序号
//int lrPlanSNum = GetNextSerialNumFromLRPlan(planDate); //LR_Plan序号
string planID = GenerateNextPlanIDNew(planDate, shiftID, rtPlanSNum); //计划号hlcs0929
xl_plan xl_plan = new xl_plan()
{
Equip_Code = "01",
Dosing_Id = 0,
Plan_Id = planID,
Batch = batch,
ProductName= productName,
Plan_Serial = rtPlanSNum,
Recipe_ID = recipe.ID,
Recipe_Code = recipe.ID,
Recipe_Name = recipe.Recipe_Name,
Version = recipe.Version,
Mixer_Line = "0",
Recipe_Type = 0,
Shift_Id = "1",
Shift_Class = "0",
Plan_Num = 1,
Real_Num = 0,
Duration_Time = 0,
Plan_State = 5,
Plan_StateText = "未启动",
Plan_Date = DateTime.Now.ToString("yyyy-mm-dd"),
IF_FLAG = 1,
int lrPlanSNum = GetNextSerialNumFromLRPlan(DateTime.Now); //Hw_Plan序号
if (rtPlanSNum >= lrPlanSNum)
{
serialNum = rtPlanSNum;
}
else
{
serialNum = lrPlanSNum;
}
string planID = GenerateNextPlanIDNew(DateTime.Now, 1, serialNum); //计划号
plan.Plan_Id = planID;
plan.Plan_Serial = serialNum;
plan.Recipe_ID = recipeID;
plan.Recipe_Code = recipeCode;
plan.Recipe_Name = item.Recipe;
plan.Version = "1";
plan.Mixer_Line = null;
plan.Recipe_Type = 0;
plan.Shift_Id = "1";
plan.Shift_Class = "";
plan.Plan_Num = 1;
plan.Real_Num = 0;
plan.Duration_Time = 0;
plan.End_Date = null;
plan.Weight_Man = null;
plan.Stock_Man = null;
plan.Plan_Batch = null;
plan.Plan_State = 5;
plan.Plan_StateText = "未启动";
plan.Plan_Date = String.Format("{0:yyyy-MM-dd}", DateTime.Now);
plan.IF_FLAG = 1;
if (string.IsNullOrEmpty(item.Weighbridge))
{
throw new Exception("地磅不可为空!");
}
plan.Weighbridge = item.Weighbridge;
plan.PumpBarCode = item.PumpCode;
if (item.PumpCode == null || item.PumpCode == "")
{
throw new Exception("投料泵为空!");
}
var pumpList = _hwPumpRepository.Query();
var pump = pumpList.FirstOrDefault(d => d.BarCode == item.PumpCode);
plan.PumpName = pump.Name;
#endregion
if (recipe == null)
{
throw new Exception("配方数据不可为空!");
}
if (weighList == null)
{
throw new Exception("配方物料数据不可为空!");
}
if (plan == null)
{
throw new Exception("计划数据不可为空!");
}
if (repiceList == null)
{
throw new Exception("反应釜计划数据不可为空!");
}
bool r = SaveRecipe(recipe, weighList, plan, repiceList.ToList());
if (r == false)
{
string msg = $"批次[{plan.Batch}];配方[{item.Recipe}],导入数据失败!";
return msg;
Console.WriteLine($"批次[{plan.Batch}];配方[{item.Recipe}],导入数据失败!");
}
return "成功";
//Console.WriteLine($"{item.PId}——{item.ProductName}——{item.Recipe};状态:{r}");
}
catch (Exception ex)
{
string msg = $"配方[{item.Recipe}] 导入失败!异常信息:{ex.Message}";
return msg;
}
}
}
catch (Exception ex)
{
return ex.Message;
}
return "执行失败";
}
public async Task<string> DownZBPlanAsync(List<MesDownLoadPlanList> MesDownLoadPlanList)
{
try
{
var list = MesDownLoadPlanList;
List<Hw_WareHouse_Sub> subList = new List<Hw_WareHouse_Sub>();
List<Pmt_recipe> recipeList = new List<Pmt_recipe>();
list.ForEach((a) =>
{
Hw_WareHouse_Sub sb = new Hw_WareHouse_Sub();
sb.MainId = int.Parse(a.MainId);
sb.PId = a.PId;
sb.ProductName = a.ProductName;
sb.MaterialID = a.Material_Code;
sb.Material_Code = a.Material_Code;
sb.MaterialName = a.MaterialName;
sb.MaterialType = a.MaterialType;
sb.SetWeight = Convert.ToDecimal(a.SetWeight);
sb.SetError = Convert.ToDecimal(a.SetError);
sb.Difference = a.Difference;
sb.PumpCode = a.PumpCode;
sb.Weighbridge = a.Weighbridge;
sb.Recipe = a.Recipe;
sb.Remark = a.Remark;
sb.CreateTime = DateTime.Now;
sb.Tare = Convert.ToDecimal(a.Tare);
subList.Add(sb);
});
//查询数据
var xlList = subList.Where(d => d.MaterialType.Contains("整包")).ToList();
var xt = from d in xlList
group d by new { PId = d.PId, ProductName = d.ProductName, Material_Code = d.Material_Code, MaterialType = d.MaterialType, Recipe = d.Recipe, SetWeight = d.Recipe, SetError = d.SetError, Weighbridge = d.Weighbridge } into g
select new
{
g.Key.PId,
g.Key.ProductName,
g.Key.Material_Code,
g.Key.MaterialType,
g.Key.Recipe,
SetWeight = g.Sum(m => m.SetWeight),
SetError = g.Sum(m => m.SetError),
g.Key.Weighbridge
};
var result = await _planRepository.Add(xl_plan);
if (result == 1)
if (xt.ToList().Count == 0)
{
return true;
return "成功";
}
foreach (var item in xt)
{
try
{
#region 配方
string recipeID = Guid.NewGuid().ToString("N");
string recipeCode = Guid.NewGuid().ToString("N");
Pmt_recipe recipe = new Pmt_recipe();
{
recipe.ID = recipeID;
recipe.Equip_Code = "01";
recipe.Recipe_Code = recipeCode;
recipe.Version = "1";
recipe.Recipe_Name = item.Recipe;
recipe.Recipe_Verify = 1;
recipe.Total_Weight = 0;
recipe.Total_Error = 0;
recipe.CreateDateTime = DateTime.Now;
}
#endregion
#region 物料
List<Pmt_weigh> weighList = new List<Pmt_weigh>();
{
Pmt_weigh material = new Pmt_weigh();
material.ID = Guid.NewGuid().ToString("N");
material.Equip_Code = "01";
material.Recipe_ID = recipe.ID;
material.Weight_Id = 1;
if (item.Material_Code == null | item.Material_Code == "")
{
throw new Exception("未查询到物料!");
}
var obj = await _material.FirstAsync(d => d.Material_code == item.Material_Code);
if (obj == null)
{
throw new Exception("未查询到当前物料!");
}
material.Material_ID = obj.ID;
material.Set_Weight = Convert.ToDecimal(item.SetWeight);
material.Set_Error = Convert.ToDecimal(item.SetError);
recipe.Total_Weight = Convert.ToDecimal(item.SetWeight);
recipe.Total_Error = Convert.ToDecimal(item.SetError);
weighList.Add(material);
}
#endregion
#region 计划
RT_plan plan = new RT_plan();
plan.Dosing_Id = 0;
plan.Equip_Code = "01";
plan.Batch = item.PId;
plan.ProductName = item.ProductName;
int serialNum = 0;
int rtPlanSNum = GetNextSerialNumAsync(); //xl_plan序号
int lrPlanSNum = GetNextSerialNumFromLRPlan(DateTime.Now); //Hw_Plan序号
if (rtPlanSNum >= lrPlanSNum)
{
serialNum = rtPlanSNum;
}
else
{
return false;
serialNum = lrPlanSNum;
}
string planID = GenerateNextPlanIDNew(DateTime.Now, 1, serialNum); //计划号
plan.Plan_Id = planID;
plan.Plan_Serial = serialNum;
plan.Recipe_ID = recipe.ID;
plan.Recipe_Code = recipeCode;
plan.Recipe_Name = item.Recipe;
plan.Version = "1";
plan.Mixer_Line = null;
plan.Recipe_Type = 0;
plan.Shift_Id = "1";
plan.Shift_Class = "";
plan.Plan_Num = 1;
plan.Real_Num = 0;
plan.Duration_Time = 0;
plan.End_Date = null;
plan.Weight_Man = null;
plan.Stock_Man = null;
plan.Plan_Batch = null;
plan.Plan_State = 5;
plan.Plan_StateText = "未启动";
plan.Plan_Date = String.Format("{0:yyyy-MM-dd}", DateTime.Now);
plan.IF_FLAG = 1;
if (string.IsNullOrEmpty(item.Weighbridge))
{
throw new Exception("地磅不可为空!");
}
plan.Weighbridge = item.Weighbridge;
#endregion
if (recipe == null)
{
throw new Exception("配方数据不可为空!");
}
if (weighList == null)
{
throw new Exception("配方物料数据不可为空!");
}
if (plan == null)
{
throw new Exception("计划数据不可为空!");
}
var repiceList = xlList.Where(d => item.PId.Equals(d.PId) && item.ProductName.Equals(d.ProductName) && item.Recipe.Equals(d.Recipe)).ToList();
if (repiceList == null)
{
throw new Exception("反应釜计划数据不可为空!");
}
bool r = SaveRecipe(recipe, weighList, plan, repiceList.ToList());
if (r == false)
{
string msg = $"批次[{plan.Batch}];配方[{item.Recipe}],导入数据失败!";
return msg;
//Console.WriteLine($"批次[{plan.Batch}];配方[{item.Recipe}],导入数据失败!");
}
//Console.WriteLine($"{item.PId}——{item.ProductName}——{item.Recipe};状态:{r}");
return "成功";
}
catch (Exception ex)
{
string msg = $"配方[{item.Recipe}] 导入失败!异常信息:{ex.Message}";
return msg;
//Console.WriteLine($"配方[{item.Recipe}] 导入失败!异常信息:{ex.Message}");
}
}
}
catch (Exception ex)
{
return ex.Message;
}
return "执行失败";
}
public async Task<string> DownXLPlanAsync(List<MesDownLoadPlanList> MesDownLoadPlanList)
{
try
{
var list = MesDownLoadPlanList;
List <Hw_WareHouse_Sub> subList = new List<Hw_WareHouse_Sub>();
List<xl_recipe> recipeList = new List<xl_recipe>();
list.ForEach((a) =>
{
Hw_WareHouse_Sub sb = new Hw_WareHouse_Sub();
sb.MainId = int.Parse(a.MainId);
sb.PId = a.PId;
sb.ProductName = a.ProductName;
sb.BinId = a.BinId == "" || a.BinId == null ? 0 : int.Parse(a.BinId);
sb.MaterialID = a.Material_Code;
sb.Material_Code = a.Material_Code;
sb.MaterialName = a.MaterialName;
sb.MaterialType = a.MaterialType;
sb.SetWeight = Convert.ToDecimal(a.SetWeight);
sb.SetError = Convert.ToDecimal(a.SetError);
sb.Difference = a.Difference;
sb.Fixed = a.Fixed == "" || a.Fixed == null ? false : true;
sb.FixedRatio = a.FixedRatio == a.FixedRatio ? Convert.ToDecimal(0.00) : Convert.ToDecimal(a.FixedRatio);
sb.Recipe = a.Recipe;
sb.Remark = a.Remark;
subList.Add(sb);
});
//查询小料数据
var xlList = subList.Where(d => d.MaterialType.Contains("尾料")).ToList();
var xt = (from d in xlList
select new
{
d.PId,
d.ProductName,
d.MaterialType,
d.Recipe,
}).Distinct();
foreach (var item in xt)
{
try
{
string recipeID = Guid.NewGuid().ToString("N");
string recipeCode = Guid.NewGuid().ToString("N");
#region 配方
xl_recipe recipe = new xl_recipe();
recipe.ID = recipeID;
recipe.Equip_Code = "01";
recipe.Recipe_Code = recipeCode;
recipe.Version = "1";
recipe.Recipe_Name = item.Recipe;
recipe.Recipe_Verify = 1;
recipe.Total_Weight = 0;
recipe.Total_Error = 0;
recipe.CreateDateTime = DateTime.Now;
recipe.IsCheck = 0;
#endregion
#region 物料
var repiceList = xlList.Where(d => item.PId.Equals(d.PId) && item.ProductName.Equals(d.ProductName) && item.Recipe.Equals(d.Recipe)).ToList();
int i = 1;
List<xl_weigh> weighList = new List<xl_weigh>();
foreach (var sub in repiceList)
{
xl_weigh material = new xl_weigh();
material.Equip_Code = "01";
material.Recipe_ID = recipe.ID;
material.Weight_Id = i;
if (sub.Material_Code == null | sub.Material_Code == "")
{
throw new Exception("未查询到物料!");
}
var obj = await _materialRepository.FirstAsync(d => d.Material_code == sub.Material_Code);
if (obj == null)
{
throw new Exception("未查询到当前物料!");
}
material.Material_ID = obj.ID;
if (sub.BinId == 0)
{
throw new Exception("未查询到对应料仓!");
}
var binInfo = await _binRepository.FirstAsync(d => d.Bin_Serial == sub.BinId && d.Material_ID == obj.ID);
if (binInfo == null)
{
throw new Exception("未查询到对应料仓!");
}
material.Bin_Serial = sub.BinId;
material.Set_Weight = Convert.ToDecimal(sub.SetWeight);
material.Set_Error = Convert.ToDecimal(sub.SetError);
recipe.Total_Weight = recipe.Total_Weight + material.Set_Weight;
recipe.Total_Error = recipe.Total_Error + material.Set_Error;
weighList.Add(material);
i++;
}
#endregion
#region 计划
xl_plan plan = new xl_plan();
plan.Dosing_Id = 0;
plan.Equip_Code = "01";
plan.Batch = item.PId;
plan.ProductName = item.ProductName;
int serialNum = 0;
int rtPlanSNum = GetXLNextSerialNumAsync(); //xl_plan序号
int lrPlanSNum = GetXLNextSerialNumFromLRPlan(DateTime.Now); //LR_Plan序号
if (rtPlanSNum >= lrPlanSNum)
{
serialNum = rtPlanSNum;
}
else
{
serialNum = lrPlanSNum;
}
string planID = GenerateNextPlanIDNew(DateTime.Now, 1, serialNum); //计划号
plan.Plan_Id = planID;
plan.Plan_Serial = serialNum;
plan.Recipe_ID = recipe.ID;
plan.Recipe_Code = recipeID;
plan.Recipe_Name = item.Recipe;
plan.Version = "1";
plan.Recipe_Type = 0;
plan.Shift_Id = "1";
plan.Shift_Class = "";
plan.Plan_Num = 1;
plan.Real_Num = 0;
plan.Duration_Time = 0;
plan.Mixer_Line = "0";
plan.End_Date = null;
plan.Weight_Man = null;
plan.Stock_Man = null;
plan.Plan_Batch = null;
plan.Plan_State = 5;
plan.Plan_StateText = "未启动";
plan.Plan_Date = String.Format("{0:yyyy-MM-dd}", DateTime.Now);
plan.IF_FLAG = 1;
#endregion
if (recipe == null)
{
throw new Exception("配方数据不可为空!");
}
if (weighList == null)
{
throw new Exception("配方物料数据不可为空!");
}
if (plan == null)
{
throw new Exception("计划数据不可为空!");
}
if (repiceList == null)
{
throw new Exception("反应釜计划数据不可为空!");
}
bool r = SaveXLRecipe(recipe, weighList, plan, repiceList.ToList());
if (r == false)
{
string msg = $"批次[{plan.Batch}];配方[{item.Recipe}],导入数据失败!";
return msg;
//Console.WriteLine($"批次[{plan.Batch}];配方[{item.Recipe}],导入数据失败!");
}
else
{
return "成功";
}
//Console.WriteLine($"{item.PId}——{item.ProductName}——{item.Recipe};状态:{r}");
}
catch (Exception ex)
{
string msg = $"配方[{item.Recipe}] 导入失败!异常信息:{ex.Message}";
return msg;
//Console.WriteLine($"配方[{item.Recipe}] 导入失败!异常信息:{ex.Message}");
}
}
}
catch (Exception ex)
{
return ex.Message;
}
return "执行失败";
}
#region 保存配方、计划物料信息
/// <summary>
/// 保存配方、计划物料信息
/// </summary>
/// <param name="recipeList">配方、物料</param>
/// <param name="xl_weighList"></param>
/// <param name="plan"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public bool SaveRecipe(Pmt_recipe recipeList, List<Pmt_weigh> pmt_weighList, RT_plan plan, List<Hw_WareHouse_Sub> sub)
{
try
{
var iflag3 = _rtplanRepository.Add(plan);
if (iflag3.Result < 1)
throw new Exception("保存计划失败!");
var iflag4 = _wareHouse_Sub.Add(sub);
if (iflag4 < 1)
throw new Exception("保存反应釜计划失败!");
var iflag1 = _pmtRecipeRepository.Add(recipeList);
if (iflag1.Result < 1)
throw new Exception("保存溶剂配方失败!");
var iflag2 = _pmtWeighRepository.Add(pmt_weighList);
if (iflag2 < 1)
throw new Exception("保存配方物料失败!");
return true;
}
catch (Exception ex)
{
return false;
}
}
public bool SaveXLRecipe(xl_recipe recipeList, List<xl_weigh> pmt_weighList, xl_plan plan, List<Hw_WareHouse_Sub> sub)
{
try
{
var iflag3 = _planRepository.Add(plan);
if (iflag3.Result < 1)
throw new Exception("保存计划失败!");
var iflag4 = _wareHouse_Sub.Add(sub);
if (iflag4 < 1)
throw new Exception("保存反应釜计划失败!");
var iflag1 = _recipeRepository.Add(recipeList);
if (iflag1.Result < 1)
throw new Exception("保存溶剂配方失败!");
var iflag2 = _xlWeighRepository.Add(pmt_weighList);
if (iflag2 < 1)
throw new Exception("保存配方物料失败!");
return true;
}
catch (Exception ex)
{
return false;
}
}
#endregion
#region 根据二维码获取物料
public async Task<Pmt_material> GetMaterialAsync(string barCode)
{
Pmt_material sub = await _material.FirstAsync(d => d.Material_code == barCode);
return sub;
}
#endregion
#region 根据传入的二维码、计划Id 查询反应釜下所有的物料
/// <summary>

@ -522,13 +522,13 @@ namespace Admin.Core.Service
else
{
var s7 = PlcConnect.Instance;
int planNum = s7.ReadInt16("DB110.DBW2.0").Content;//执行批次
int planNum = s7.ReadInt16("DB111.DBW2.0").Content;//执行批次
if (plan.Plan_Num > planNum)
{
var rtPlanList = await _planRepository.QueryAsync(d => d.Plan_State == 3);
var rtPlan = rtPlanList.FirstOrDefault(d => d.Plan_Id == plan.Plan_Id);
execNum = rtPlan.Exec_Num;
int materialNo = s7.ReadInt16("DB110.DBW1758").Content;//当前执行物料
int materialNo = s7.ReadInt16("DB111.DBW1758").Content;//当前执行物料
var hwWeigh = hwWeighList.FirstOrDefault(d => d.MID == materialNo);
if (hwWeigh == null) return null;

@ -307,6 +307,31 @@ namespace Admin.Core.Service
#endregion
#region 扫码料桶,绑定物料、重量批次信息
public async Task<decimal> GetBindBarrelWeight()
{
try
{
var plcList = PlcHelper.siemensList.SingleOrDefault(d => d.EquipName.Equals("小料PLC"));
if (plcList.plc.IsConnected) // 000533
{
decimal tcheckWeight = Convert.ToDecimal(plcList.plc.ReadInt16("DB104.DBW164")) / 1000;//检量秤重量
log.Info($"重量:{tcheckWeight}");
return tcheckWeight;
}
else
{
return 0;
}
}
catch (Exception ex)
{
log.Error(ex.Message);
return 0;//异常报错
}
}
/// <summary>
/// 扫码料桶,绑定物料、重量批次信息
/// </summary>

Loading…
Cancel
Save