diff --git a/Admin.Core.Api/Admin.Core.Api.xml b/Admin.Core.Api/Admin.Core.Api.xml index 256eacb..db9e744 100644 --- a/Admin.Core.Api/Admin.Core.Api.xml +++ b/Admin.Core.Api/Admin.Core.Api.xml @@ -415,6 +415,21 @@ json 对象 + + + 投料口开/投料口关 + + + + + + + + 查询称量重量 + + + + 查询反应釜计划 diff --git a/Admin.Core.Api/Admin.Core.Model.xml b/Admin.Core.Api/Admin.Core.Model.xml index 0a0b5ba..ef42034 100644 --- a/Admin.Core.Api/Admin.Core.Model.xml +++ b/Admin.Core.Api/Admin.Core.Model.xml @@ -2447,6 +2447,11 @@ Nullable:True + + + 产品名称 + + Desc:计划状态 diff --git a/Admin.Core.Api/Controllers/Business/WarehouseController.cs b/Admin.Core.Api/Controllers/Business/WarehouseController.cs index 76441f3..fd2b1e7 100644 --- a/Admin.Core.Api/Controllers/Business/WarehouseController.cs +++ b/Admin.Core.Api/Controllers/Business/WarehouseController.cs @@ -14,6 +14,7 @@ using System.Linq; using Admin.Core.Model.ViewModels; using Microsoft.AspNetCore.Mvc.ViewEngines; using System.Collections; +using NPOI.SS.Formula.Functions; namespace Admin.Core.Api.Controllers.Business { @@ -124,6 +125,68 @@ namespace Admin.Core.Api.Controllers.Business } return Failed("执行失败!"); } + + [HttpGet] + public async Task> DownLoadplanInfo() + { + try + { + string ss1 = "a82d016e813c4ac3bca0244c519da591"; + string ss2 = "2408090522"; + var ss3 = "D1-813"; + var result = await _hw_WarehouseService.InsertXLPlanInfo(DateTime.Now, ss1, ss2, ss3); + if (result) + { + return Success(result); + } + } + catch (Exception ex) + { + + } + return Failed("执行失败!"); + } + + + /// + /// 投料口开/投料口关 + /// + /// + /// + /// + [HttpGet] + public async Task> ExecPlcState(string code,int state) + { + if (!code.IsNotEmptyOrNull() || !state.IsNotEmptyOrNull()) + { + return Failed("传入参数为空!"); + } + var result = await _hw_WarehouseService.UpdatePlcState(code,state); + if (result) + { + return Success(result); + } + return Failed("执行失败!"); + } + /// + /// 查询称量重量 + /// + /// + /// + [HttpGet] + public async Task> GetWeight(string WeightNo) + { + if (!WeightNo.IsNotEmptyOrNull()) + { + return Failed("传入参数为空!"); + } + var result = await _hw_WarehouseService.RealWeightInfo(WeightNo); + if (result != "") + { + return Success(result,"成功"); + } + return Failed("执行失败!"); + } #endregion #region 查询反应釜计划 diff --git a/Admin.Core.Api/Properties/PublishProfiles/FolderProfile.pubxml b/Admin.Core.Api/Properties/PublishProfiles/FolderProfile.pubxml index 2fd6b5e..cc9f716 100644 --- a/Admin.Core.Api/Properties/PublishProfiles/FolderProfile.pubxml +++ b/Admin.Core.Api/Properties/PublishProfiles/FolderProfile.pubxml @@ -10,7 +10,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121. Release Any CPU FileSystem - E:\发布文件 + F:\发布文件 FileSystem net6.0 diff --git a/Admin.Core.Api/Properties/launchSettings.json b/Admin.Core.Api/Properties/launchSettings.json index 1005fe4..70fe2ba 100644 --- a/Admin.Core.Api/Properties/launchSettings.json +++ b/Admin.Core.Api/Properties/launchSettings.json @@ -24,7 +24,9 @@ "ASPNETCORE_ENVIRONMENT": "Development" }, "dotnetRunMessages": "true", - "applicationUrl": "http://localhost:5001;http://localhost:5000" + //"applicationUrl": "http://localhost:5001;http://localhost:5000" + "applicationUrl": "http://192.168.137.1:5001;http://192.168.137.1:5000" + } } } \ No newline at end of file diff --git a/Admin.Core.Api/Startup.cs b/Admin.Core.Api/Startup.cs index f4f008a..04e8b69 100644 --- a/Admin.Core.Api/Startup.cs +++ b/Admin.Core.Api/Startup.cs @@ -219,17 +219,17 @@ namespace Admin.Core.Api // תhttps //app.UseHttpsRedirection(); // ʹþ̬ļע⣺ڶӦĿ¼ļУᱨ - app.UseStaticFiles(new StaticFileOptions - { - FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "file")), - RequestPath = "/file", - OnPrepareResponse = ctx => - { - ctx.Context.Response.Headers.Append("Cache-Control", "public,max-age=600"); - } - }); - // ʹþ̬ļ - app.UseStaticFiles(); + // app.UseStaticFiles(new StaticFileOptions + // { + // FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "file")), + // RequestPath = "/file", + // OnPrepareResponse = ctx => + // { + // ctx.Context.Response.Headers.Append("Cache-Control", "public,max-age=600"); + // } + // }); + // // ʹþ̬ļ + // app.UseStaticFiles(); app.UseSession(); //app.UseCookiePolicy(); diff --git a/Admin.Core.Api/appsettings.Development.json b/Admin.Core.Api/appsettings.Development.json index 696a942..dc08c8b 100644 --- a/Admin.Core.Api/appsettings.Development.json +++ b/Admin.Core.Api/appsettings.Development.json @@ -80,7 +80,9 @@ "DBType": 1, "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=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=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" } @@ -123,7 +125,8 @@ "RetryCount": 3 }, "Siemens": { - "ConString": "192.168.10.100", + //"ConString": "192.168.10.100", + "ConString": "127.0.0.1", "Port": 102 }, "EventBus": { diff --git a/Admin.Core.Api/appsettings.json b/Admin.Core.Api/appsettings.json index 696a942..8c7a8d2 100644 --- a/Admin.Core.Api/appsettings.json +++ b/Admin.Core.Api/appsettings.json @@ -80,7 +80,7 @@ "DBType": 1, "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=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" } diff --git a/Admin.Core.IService/IService_New/IHw_WarehouseServices.cs b/Admin.Core.IService/IService_New/IHw_WarehouseServices.cs index 20c5999..6039138 100644 --- a/Admin.Core.IService/IService_New/IHw_WarehouseServices.cs +++ b/Admin.Core.IService/IService_New/IHw_WarehouseServices.cs @@ -2,6 +2,7 @@ using Admin.Core.IService; using Admin.Core.Model; using Admin.Core.Model.ViewModels; +using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -14,7 +15,11 @@ namespace Admin.Core.IService { Task QueryByCode(string code,string planId); Task UpdatePlcState(KettleView view); + Task UpdatePlcState(string code,int state); + Task RealWeightInfo(string WeightNo); Task GetXlInfo(string kettleBarCode, string planId, string code); Task> GetWarehousePlan(string code); + + Task InsertXLPlanInfo(DateTime planDate, string recipeGUID, string batch, string productName); } } \ No newline at end of file diff --git a/Admin.Core.Model/Model_New/xl_plan.cs b/Admin.Core.Model/Model_New/xl_plan.cs index f4dd88d..6b060ef 100644 --- a/Admin.Core.Model/Model_New/xl_plan.cs +++ b/Admin.Core.Model/Model_New/xl_plan.cs @@ -42,6 +42,8 @@ namespace Admin.Core.Model /// Nullable:True /// public int Plan_Serial { get; set; } + + public string Batch { get; set; } /// /// Desc:配方GUID /// Default: @@ -150,6 +152,11 @@ namespace Admin.Core.Model /// Nullable:True /// public string Plan_Batch { get; set; } + + /// + /// 产品名称 + /// + public string ProductName { get; set; } /// /// Desc:计划状态 /// Default: diff --git a/Admin.Core.Model/ViewModels/XLPlanList.cs b/Admin.Core.Model/ViewModels/XLPlanList.cs new file mode 100644 index 0000000..bca57dd --- /dev/null +++ b/Admin.Core.Model/ViewModels/XLPlanList.cs @@ -0,0 +1,6 @@ +namespace Admin.Core.Model.ViewModels; + +public class XLPlanList +{ + +} \ No newline at end of file diff --git a/Admin.Core.PlcServer/PlcConnect.cs b/Admin.Core.PlcServer/PlcConnect.cs index c854ce3..0fb5518 100644 --- a/Admin.Core.PlcServer/PlcConnect.cs +++ b/Admin.Core.PlcServer/PlcConnect.cs @@ -25,13 +25,16 @@ namespace Admin.Core.PlcServer SiemensPLCS siemensPLCS = SiemensPLCS.S1500; SiemensS7Net s7 = new SiemensS7Net(siemensPLCS); //配料IP - s7.IpAddress = "192.168.10.130"; + //s7.IpAddress = "192.168.10.130"; + s7.IpAddress = "127.0.0.1"; s7.Port = 102; var su = s7.ConnectServer(); if (!su.IsSuccess) { - s7.IpAddress ="192.168.10.130"; + //s7.IpAddress ="192.168.10.130"; + s7.IpAddress = "127.0.0.1"; + s7.Port = 102; var su1 = s7.ConnectServer(); if (!su1.IsSuccess) diff --git a/Admin.Core.Service/Admin.Core.Service.csproj b/Admin.Core.Service/Admin.Core.Service.csproj index 879f9bb..b332b8b 100644 --- a/Admin.Core.Service/Admin.Core.Service.csproj +++ b/Admin.Core.Service/Admin.Core.Service.csproj @@ -22,7 +22,7 @@ - E:\普力通处理\dll\HslCommunication.dll + ..\dll\HslCommunication.dll diff --git a/Admin.Core.Service/Service_New/Hw_WarehouseServices.cs b/Admin.Core.Service/Service_New/Hw_WarehouseServices.cs index 093daa8..804c9b0 100644 --- a/Admin.Core.Service/Service_New/Hw_WarehouseServices.cs +++ b/Admin.Core.Service/Service_New/Hw_WarehouseServices.cs @@ -9,6 +9,12 @@ using log4net; using System.Collections.Generic; using Microsoft.Data.SqlClient; using Admin.Core.PlcServer; +using System.Data; +using SqlSugar; +using System.Numerics; +using System.Text; +using NPOI.POIFS.FileSystem; +using System.Linq.Expressions; namespace Admin.Core.Service { @@ -23,11 +29,13 @@ namespace Admin.Core.Service private readonly Ixl_materialRepository _materialRepository; private readonly Ixl_recipeRepository _recipeRepository; private readonly ILR_weighRepository _lrWeighRepository; + private readonly Ixl_planRepository _planRepository;//小料计划 + public Hw_WarehouseServices(IBaseRepository 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_recipeRepository recipeRepository, ILR_weighRepository lrWeighRepository, Ixl_planRepository planRepository) { this._dal = dal; base.BaseDal = dal; @@ -38,6 +46,7 @@ namespace Admin.Core.Service _materialRepository = materialRepository; _recipeRepository = recipeRepository; _lrWeighRepository = lrWeighRepository; + _planRepository = planRepository; } #region 扫描桶二维码,获取绑定的小料配方物料 @@ -126,6 +135,134 @@ namespace Admin.Core.Service } } #endregion + #region GetNextSerialNum 获取下一个可用的序号SerialNum 规则:同机台、同日期、同班次 计划号最后2位的最大值加1 + /// + /// 获取下一个可用的序号 + /// + /// 计划生产日期 + /// 返回可用的序号 + public int GetNextSerialNumAsync() + { + + string strSql = "SELECT MAX(Plan_Serial) FROM xl_plan"; + Expression> exp = s1 => true; + Expression> order = (x) => x.Plan_Serial; + var result = _planRepository.Query(exp,order,false).First(); + if (result == null) + { + return 1; + } + else + { + return Convert.ToInt32(result.Plan_Serial) + 1; + } + } + public int GetNextSerialNumFromLRPlan(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); + 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; + } + } + + #endregion + /// + /// 获取下一个可用的计划号 (6位日期、2位机台、1位班次、1位网络/本机、2位流水) + /// + /// 机台号 + /// 计划生产日期 + /// 班次 + /// 返回生成的12位计划号 + public static string GenerateNextPlanIDNew(DateTime planDate, int shiftID, int sNum) + { + string code = "01"; + return String.Format("{0:yyyyMMdd}{1}{2}", planDate, code, shiftID) + FillZero(sNum.ToString(), 2); + } + #region "按字符串位数补0" + /// + /// 按字符串位数补0 + /// + /// 字符串 + /// 字符长度 + /// + public static string FillZero(string CharTxt, int CharLen) + { + if (CharTxt.Length < CharLen) + { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < CharLen - CharTxt.Length; i++) + { + sb.Append("0"); + } + sb.Append(CharTxt); + return sb.ToString(); + } + else + { + return CharTxt; + } + } + + #endregion + public async Task InsertXLPlanInfo(DateTime planDate, string recipeGUID, string batch, string productName) + { + try + { + int shiftID = 1; + //根据配方编号查询 + var recipe = await _recipeRepository.FirstAsync(d => d.Recipe_Verify == 1 && d.ID == recipeGUID); + + 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, + Start_Date = DateTime.Now.ToString("yyyy-mm-dd hh:MM:ss"), + Plan_State = 5, + Plan_StateText = "未启动", + Plan_Date = DateTime.Now.ToString("yyyy-mm-dd"), + IF_FLAG = 1, + }; + var result = _planRepository.Add(xl_plan); + return true; + } + catch (Exception ex) + { + return false; + } + return false; + } + #region 根据传入的二维码、计划Id 查询反应釜下所有的物料 /// @@ -179,6 +316,186 @@ namespace Admin.Core.Service #endregion #region 更新PLC状态 + + public async Task RealWeightInfo(string WeightNo) + { + string WeightInfo = ""; + try + { + string name = string.Empty; + if (string.IsNullOrEmpty(WeightNo)) + { + log.Error("点位名称为空!"); + return "点位名称为空!"; + } + switch (WeightNo) + { + case "1": + name = "DB104.DBW132"; + break; + case "2": + name = "DB109.DBW134"; + break; + case "3": + name = "DB104.DBW136"; + break; + case "4": + name = "DB104.DBW138"; + break; + case "5": + name = "DB104.DBW140"; + break; + case "6": + name = "DB104.DBW142"; + break; + case "7": + name = "DB104.DBW144"; + break; + case "8": + name = "DB104.DBW146"; + break; + case "9": + name = "DB104.DBW148"; + break; + case "10": + name = "DB104.DBW150"; + break; + case "11": + name = "DB104.DBW152"; + break; + case "12": + name = "DB104.DBW154"; + break; + case "13": + name = "DB104.DBW156"; + break; + case "14": + name = "DB104.DBW158"; + break; + case "15": + name = "DB104.DBW160"; + break; + case "16": + name = "DB104.DBW162"; + break; + default: + break; + } + + var s7 = PlcConnect.Instance; + var result = s7.ReadInt16(name);//反应釜点位 + log.Error($"读取重量:{result.IsSuccess},返回信息:{result.Message}"); + if (result.IsSuccess) + { + + return (result.Content / 1000).ToString(); + } + else + { + log.Error(result.Message+",读取失败!"); + return WeightNo+"称,读取失败!"; + } + + //return WeightInfo; + } + catch (Exception ex) + { + log.Error(ex.Message); + return WeightInfo; + } + } + + + /// + /// 投料口开/投料口关 + /// + /// 投料釜条码 + /// 状态 0:关闭 1:开启 + /// + + public async Task UpdatePlcState(string Kcode, int state) + { + List subList = null; + Hw_Warehouse wh = null; + string name = string.Empty; + + wh = await _wareHouse.FirstAsync(d => d.BarCode == Kcode); + if (wh == null) return false; + #region 反应釜工位信号 + //反应釜工位报警 + switch (wh.ID) + { + case 1: + name = "DB109.DBW4.0"; + break; + case 2: + name = "DB109.DBW10.0"; + break; + case 3: + name = "DB109.DBW16.0"; + break; + case 4: + name = "DB109.DBW22.0"; + break; + case 5: + name = "DB109.DBW28.0"; + break; + case 6: + name = "DB109.DBW34.0"; + break; + case 7: + name = "DB109.DBW40.0"; + break; + case 8: + name = "DB109.DBW46.0"; + break; + case 9: + name = "DB109.DBW52.0"; + break; + case 10: + name = "DB109.DBW58.0"; + break; + case 11: + name = "DB109.DBW64.0"; + break; + case 12: + name = "DB109.DBW70.0"; + break; + case 13: + name = "DB109.DBW76.0"; + break; + case 14: + name = "DB109.DBW82.0"; + break; + case 15: + name = "DB109.DBW88.0"; + break; + default: + break; + } + #endregion + + if (string.IsNullOrEmpty(name)) + { + log.Error("点位名称为空!"); + return false; + } + var s7 = PlcConnect.Instance; + var result = s7.Write(name, short.Parse(state.ToString()));//反应釜点位 + log.Error($"反应釜开启点位状态:{result.IsSuccess},返回信息:{result.Message}"); + if (result.IsSuccess) + { + return result.IsSuccess; + } + else + { + log.Error("反应釜写入点位失败!"); + return result.IsSuccess; + } + + + return true; + } /// /// 更新PLC状态 /// diff --git a/Admin.Core.Service/Service_New/xl_materialServices.cs b/Admin.Core.Service/Service_New/xl_materialServices.cs index 39a0d27..3dc53e7 100644 --- a/Admin.Core.Service/Service_New/xl_materialServices.cs +++ b/Admin.Core.Service/Service_New/xl_materialServices.cs @@ -503,6 +503,8 @@ namespace Admin.Core.Service }; await _lrPlanRepository.AddAsync(lr); } + + #endregion #region 更新计划数-完成 diff --git a/Admin.Core.Wpf/Admin.Core.Wpf.csproj b/Admin.Core.Wpf/Admin.Core.Wpf.csproj index 4e41db2..55d2b1e 100644 --- a/Admin.Core.Wpf/Admin.Core.Wpf.csproj +++ b/Admin.Core.Wpf/Admin.Core.Wpf.csproj @@ -14,11 +14,19 @@ + + + + + + + + Always diff --git a/S71500/S71500.csproj b/S71500/S71500.csproj index b1843c9..727808c 100644 --- a/S71500/S71500.csproj +++ b/S71500/S71500.csproj @@ -7,7 +7,7 @@ - D:\soft\Gitee\ComponentLib\dll\HslCommunication.dll + ..\dll\HslCommunication.dll