新增投料口开/投料口关、小料称量信息上传接口

dep_wangsr
CaesarBao 6 months ago
parent d4b2ee7465
commit 422d9ff842

@ -415,6 +415,21 @@
<param name="view">json 对象</param>
<returns></returns>
</member>
<member name="M:Admin.Core.Api.Controllers.Business.WarehouseController.ExecPlcState(System.String,System.Int32)">
<summary>
投料口开/投料口关
</summary>
<param name="code"></param>
<param name="state"></param>
<returns></returns>
</member>
<member name="M:Admin.Core.Api.Controllers.Business.WarehouseController.GetWeight(System.String)">
<summary>
查询称量重量
</summary>
<param name="WeightNo"></param>
<returns></returns>
</member>
<member name="M:Admin.Core.Api.Controllers.Business.WarehouseController.GetWarehousePlan(System.String)">
<summary>
查询反应釜计划

@ -2447,6 +2447,11 @@
Nullable:True
</summary>
</member>
<member name="P:Admin.Core.Model.xl_plan.ProductName">
<summary>
产品名称
</summary>
</member>
<member name="P:Admin.Core.Model.xl_plan.Plan_State">
<summary>
Desc:计划状态

@ -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<bool>("执行失败!");
}
[HttpGet]
public async Task<MessageModel<bool>> 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<bool>("执行失败!");
}
/// <summary>
/// 投料口开/投料口关
/// </summary>
/// <param name="code"></param>
/// <param name="state"></param>
/// <returns></returns>
[HttpGet]
public async Task<MessageModel<bool>> ExecPlcState(string code,int state)
{
if (!code.IsNotEmptyOrNull() || !state.IsNotEmptyOrNull())
{
return Failed<bool>("传入参数为空!");
}
var result = await _hw_WarehouseService.UpdatePlcState(code,state);
if (result)
{
return Success(result);
}
return Failed<bool>("执行失败!");
}
/// <summary>
/// 查询称量重量
/// </summary>
/// <param name="WeightNo"></param>
/// <returns></returns>
[HttpGet]
public async Task<MessageModel<string>> GetWeight(string WeightNo)
{
if (!WeightNo.IsNotEmptyOrNull())
{
return Failed<string>("传入参数为空!");
}
var result = await _hw_WarehouseService.RealWeightInfo(WeightNo);
if (result != "")
{
return Success(result,"成功");
}
return Failed<string>("执行失败!");
}
#endregion
#region 查询反应釜计划

@ -10,7 +10,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>E:\发布文件</PublishUrl>
<PublishUrl>F:\发布文件</PublishUrl>
<WebPublishMethod>FileSystem</WebPublishMethod>
<SiteUrlToLaunchAfterPublish />
<TargetFramework>net6.0</TargetFramework>

@ -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"
}
}
}

@ -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();

@ -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": {

@ -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"
}

@ -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<WarehouseView> QueryByCode(string code,string planId);
Task<bool> UpdatePlcState(KettleView view);
Task<bool> UpdatePlcState(string code,int state);
Task<string> RealWeightInfo(string WeightNo);
Task<BarrelView> GetXlInfo(string kettleBarCode, string planId, string code);
Task<List<string>> GetWarehousePlan(string code);
Task<bool> InsertXLPlanInfo(DateTime planDate, string recipeGUID, string batch, string productName);
}
}

@ -42,6 +42,8 @@ namespace Admin.Core.Model
/// Nullable:True
/// </summary>
public int Plan_Serial { get; set; }
public string Batch { get; set; }
/// <summary>
/// Desc:配方GUID
/// Default:
@ -150,6 +152,11 @@ namespace Admin.Core.Model
/// Nullable:True
/// </summary>
public string Plan_Batch { get; set; }
/// <summary>
/// 产品名称
/// </summary>
public string ProductName { get; set; }
/// <summary>
/// Desc:计划状态
/// Default:

@ -0,0 +1,6 @@
namespace Admin.Core.Model.ViewModels;
public class XLPlanList
{
}

@ -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)

@ -22,7 +22,7 @@
<ItemGroup>
<Reference Include="HslCommunication">
<HintPath>E:\普力通处理\dll\HslCommunication.dll</HintPath>
<HintPath>..\dll\HslCommunication.dll</HintPath>
</Reference>
</ItemGroup>

@ -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<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_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
/// <summary>
/// 获取下一个可用的序号
/// </summary>
/// <param name="planDate">计划生产日期</param>
/// <returns>返回可用的序号</returns>
public int GetNextSerialNumAsync()
{
string strSql = "SELECT MAX(Plan_Serial) FROM xl_plan";
Expression<Func<xl_plan, bool>> exp = s1 => true;
Expression<Func<xl_plan, object>> 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
/// <summary>
/// 获取下一个可用的计划号 (6位日期、2位机台、1位班次、1位网络/本机、2位流水)
/// </summary>
/// <param name="equipCode">机台号</param>
/// <param name="planDate">计划生产日期</param>
/// <param name="shiftID">班次</param>
/// <returns>返回生成的12位计划号</returns>
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"
/// <summary>
/// 按字符串位数补0
/// </summary>
/// <param name="CharTxt">字符串</param>
/// <param name="CharLen">字符长度</param>
/// <returns></returns>
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<bool> 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 查询反应釜下所有的物料
/// <summary>
@ -179,6 +316,186 @@ namespace Admin.Core.Service
#endregion
#region 更新PLC状态
public async Task<string> 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;
}
}
/// <summary>
/// 投料口开/投料口关
/// </summary>
/// <param name="Kcode">投料釜条码</param>
/// <param name="state">状态 0:关闭 1:开启</param>
/// <returns></returns>
public async Task<bool> UpdatePlcState(string Kcode, int state)
{
List<Hw_WareHouse_Sub> 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;
}
/// <summary>
/// 更新PLC状态
/// </summary>

@ -503,6 +503,8 @@ namespace Admin.Core.Service
};
await _lrPlanRepository.AddAsync(lr);
}
#endregion
#region 更新计划数-完成

@ -14,11 +14,19 @@
<Page Remove="Locator\**" />
</ItemGroup>
<ItemGroup>
<Compile Remove="View\FaultAppPage.xaml.cs" />
</ItemGroup>
<ItemGroup>
<None Remove="appsettings.json" />
<None Remove="Log4net.config" />
</ItemGroup>
<ItemGroup>
<Page Remove="View\FaultAppPage.xaml" />
</ItemGroup>
<ItemGroup>
<Content Include="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>

@ -7,7 +7,7 @@
<ItemGroup>
<Reference Include="HslCommunication">
<HintPath>D:\soft\Gitee\ComponentLib\dll\HslCommunication.dll</HintPath>
<HintPath>..\dll\HslCommunication.dll</HintPath>
</Reference>
</ItemGroup>

Loading…
Cancel
Save