Merge branch 'dep_wangsr'

# Conflicts:
#	Admin.Core.Api/Controllers/Business/WarehouseController.cs
#	Admin.Core.Model/Model_New/xl_recipe.cs
#	Admin.Core.Service/Service_New/Hw_WarehouseServices.cs
main
SoulStar 2 weeks ago
commit 0657fe2dcb

@ -330,7 +330,7 @@
</summary>
<returns></returns>
</member>
<member name="M:Admin.Core.Api.xl_materialController.xlDownLoadMateralInfo(System.String,System.String)">
<member name="M:Admin.Core.Api.xl_materialController.XlDownLoadMateralInfo(System.String,System.String,System.Int32,System.DateTime)">
<summary>
小料同步MES物料信息
</summary>
@ -395,12 +395,24 @@
投料仓服务
</summary>
</member>
<member name="M:Admin.Core.Api.Controllers.Business.WarehouseController.#ctor(Admin.Core.IService.IHw_WarehouseServices,Admin.Core.IService.ISys.ISysUserService)">
<member name="F:Admin.Core.Api.Controllers.Business.WarehouseController._hw_BarrelService">
<summary>
料筒服务类
</summary>
</member>
<member name="F:Admin.Core.Api.Controllers.Business.WarehouseController._lr_weighService">
<summary>
称重服务类
</summary>
</member>
<member name="M:Admin.Core.Api.Controllers.Business.WarehouseController.#ctor(Admin.Core.IService.IHw_WarehouseServices,Admin.Core.IService.ISys.ISysUserService,Admin.Core.IService.IService_New.IHw_BarrelServices,Admin.Core.IService.ILR_weighServices)">
<summary>
构造方法
</summary>
<param name="hw_WarehouseServices"></param>
<param name="sysUserService"></param>
<param name="hwBarrelService"></param>
<param name="lrweighService"></param>
</member>
<member name="M:Admin.Core.Api.Controllers.Business.WarehouseController.GetByBarrelInfo(System.String,System.String,System.String)">
<summary>
@ -454,6 +466,13 @@
</summary>
<returns></returns>
</member>
<member name="M:Admin.Core.Api.Controllers.Business.WarehouseController.GetWeightInfoByBarrelID(System.String)">
<summary>
根据罐号查询称量列表
</summary>
<param name="barrelID"></param>
<returns></returns>
</member>
<member name="T:Admin.Core.Api.SeedController">
<summary>
Controller代码生成
@ -1730,6 +1749,216 @@
DeleteSubscriptionFiles
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.BomData.pageCount">
<summary>
总页数
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.BomData.pageIndex">
<summary>
页码
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.BomData.recordList">
<summary>
数据对象
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.BomData.recordCount">
<summary>
总记录数
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.BomData.pageSize">
<summary>
每页记录数
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.BomData.endPageIndex">
<summary>
尾页编号
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.BomData.beginPageIndex">
<summary>
起始页编号
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.BomRecordListItem.id">
<summary>
物料id
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.BomRecordListItem.name">
<summary>
物料名称
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.BomRecordListItem.status">
<summary>
物料状态0禁用 1启用
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.BomRecordListItem.code">
<summary>
物料编号
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.BomRecordListItem.createTime">
<summary>
物料创建时间
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.MaterialData.pageCount">
<summary>
总页数
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.MaterialData.pageIndex">
<summary>
页码
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.MaterialData.recordList">
<summary>
数据对象
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.MaterialData.recordCount">
<summary>
总记录数
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.MaterialData.pageSize">
<summary>
每页记录数
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.MaterialData.endPageIndex">
<summary>
尾页编号
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.MaterialData.beginPageIndex">
<summary>
起始页编号
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.MaterialRecordListItem.id">
<summary>
物料id
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.MaterialRecordListItem.name">
<summary>
物料名称
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.MaterialRecordListItem.status">
<summary>
物料状态0禁用 1启用
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.MaterialRecordListItem.code">
<summary>
物料编号
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.MaterialRecordListItem.createTime">
<summary>
物料创建时间
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.ResponseRoot`1.code">
<summary>
状态码
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.ResponseRoot`1.message">
<summary>
消息提示
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.ResponseRoot`1.Data">
<summary>
结果对象
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.TokenData.token">
<summary>
Token(后续请求需要携带这个Token)
</summary>
</member>
<member name="P:Admin.Core.Api.PLTBusiness.Entity.TokenData.expiration">
<summary>
Token失效时间
</summary>
</member>
<member name="M:Admin.Core.Api.PLTBusiness.HttpService.ExecuteAsync(System.Threading.CancellationToken)">
<summary>
循环执行的服务
</summary>
<param name="stoppingToken"></param>
<returns></returns>
</member>
<member name="M:Admin.Core.Api.PLTBusiness.HttpService.GetMaterialDataPageList">
<summary>
分页拉取所有Mes物料信息
</summary>
<returns></returns>
</member>
<member name="M:Admin.Core.Api.PLTBusiness.HttpService.GetRecipeDataPageList">
<summary>
分页拉取所有MesBom配方信息
</summary>
<returns></returns>
</member>
<member name="M:Admin.Core.Api.PLTBusiness.HttpService.GetToken">
<summary>
获取Token
</summary>
</member>
<member name="M:Admin.Core.Api.PLTBusiness.HttpService.RefreshToken">
<summary>
刷新Token
</summary>
</member>
<member name="M:Admin.Core.Api.PLTBusiness.HttpService.PostAsync(System.String,System.String,System.String,System.String,System.Collections.Generic.Dictionary{System.String,System.String},System.Int32)">
<summary>
发起POST异步请求
</summary>
<param name="url">请求地址</param>
<param name="body">POST提交的内容</param>
<param name="bodyMediaType">POST内容的媒体类型application/xml、application/json</param>
<param name="responseContentType">HTTP响应上的content-type内容头的值,如application/xml、application/json、application/text、application/x-www-form-urlencoded等</param>
<param name="headers">请求头信息</param>
<param name="timeOut">请求超时时间,单位秒</param>
<returns>返回string</returns>
</member>
<member name="M:Admin.Core.Api.PLTBusiness.HttpService.GetAsync(System.String,System.Collections.Generic.Dictionary{System.String,System.String},System.Int32)">
<summary>
发起GET异步请求
</summary>
<typeparam name="T">返回类型</typeparam>
<param name="url">请求地址</param>
<param name="headers">请求头信息</param>
<param name="timeOut">请求超时时间,单位秒</param>
<returns>返回string</returns>
</member>
<member name="M:Admin.Core.Api.PLTBusiness.HttpService.GetHostName(System.String)">
<summary>
获取请求的主机名
</summary>
<param name="url"></param>
<returns></returns>
</member>
<member name="M:Admin.Core.Api.PLTBusiness.XlBusiness.InsertNewMaterialData(System.Collections.Generic.List{Admin.Core.Api.PLTBusiness.Entity.MaterialRecordListItem})">
<summary>
向物料数据库中动态同步mes数据没有就插入不同就修改
</summary>
<param name="list"></param>
<returns></returns>
</member>
<member name="T:Admin.Core.Api.Program">
<summary>
Program

@ -45,7 +45,6 @@ namespace Admin.Core.Api
_xl_materialService = xl_materialServices;
_binServices = binServices;
_xlPlanServices = xlPlanServices;
_xlPlanServices = xlPlanServices;
}
#endregion
@ -265,21 +264,24 @@ namespace Admin.Core.Api
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<MessageModel<bool>> xlDownLoadMateralInfo(string materialCode, string materialName)
public async Task<MessageModel<bool>> XlDownLoadMateralInfo(string materialCode, string materialName, int isEnable, DateTime createDateTime)
{
try
{
var result = await _xl_materialService.xlInsertMaterial(materialCode, materialName);
var result = await _xl_materialService.xlInsertMaterial(Guid.NewGuid().ToString("N"), materialCode, materialName, isEnable, createDateTime);
if (result)
{
return Success(result);
return Success(result, "成功");
}
else
{
return Failed<bool>("执行失败!");
}
}
catch (Exception ex)
{
}
return Failed<bool>("执行失败!");
}
}
}
}

@ -15,7 +15,12 @@ using Admin.Core.Model.ViewModels;
using Microsoft.AspNetCore.Mvc.ViewEngines;
using System.Collections;
using NPOI.SS.Formula.Functions;
<<<<<<< HEAD
using TouchSocket.Core;
=======
using System.Numerics;
using Admin.Core.IService.IService_New;
>>>>>>> dep_wangsr
namespace Admin.Core.Api.Controllers.Business
{
@ -39,16 +44,30 @@ namespace Admin.Core.Api.Controllers.Business
/// </summary>
private readonly IHw_WarehouseServices _hw_WarehouseService;
/// <summary>
/// 料筒服务类
/// </summary>
private readonly IHw_BarrelServices _hw_BarrelService;
/// <summary>
/// 称重服务类
/// </summary>
private readonly ILR_weighServices _lr_weighService;
#region 构造方法
/// <summary>
/// 构造方法
/// </summary>
/// <param name="hw_WarehouseServices"></param>
/// <param name="sysUserService"></param>
public WarehouseController(IHw_WarehouseServices hw_WarehouseServices, ISysUserService sysUserService) : base(sysUserService)
/// <param name="hwBarrelService"></param>
/// <param name="lrweighService"></param>
public WarehouseController(IHw_WarehouseServices hw_WarehouseServices, ISysUserService sysUserService, IHw_BarrelServices hwBarrelService, ILR_weighServices lrweighService) : base(sysUserService)
{
_sysUserService = sysUserService;
_hw_WarehouseService = hw_WarehouseServices;
_hw_BarrelService = hwBarrelService;
_lr_weighService = lrweighService;
}
#endregion
@ -62,13 +81,13 @@ namespace Admin.Core.Api.Controllers.Business
/// <param name="code">料桶Id</param>
/// <returns></returns>
[HttpGet]
public async Task<MessageModel<BarrelView>> GetByBarrelInfo(string kettleBarCode, string planId,string code)
public async Task<MessageModel<BarrelView>> GetByBarrelInfo(string kettleBarCode, string planId, string code)
{
if (!code.IsNotEmptyOrNull())
{
return Failed<BarrelView>("传入参数为空!");
}
var query = await _hw_WarehouseService.GetXlInfo(kettleBarCode.Trim(),planId.Trim(),code.Trim());
var query = await _hw_WarehouseService.GetXlInfo(kettleBarCode.Trim(), planId.Trim(), code.Trim());
if (query == null)
{
return Failed<BarrelView>("查询失败!");
@ -85,7 +104,7 @@ namespace Admin.Core.Api.Controllers.Business
/// <param name="planId">计划Id</param>
/// <returns></returns>
[HttpGet]
public async Task<MessageModel<WarehouseView>> GetByCode(string code,string planId)
public async Task<MessageModel<WarehouseView>> GetByCode(string code, string planId)
{
if (!code.IsNotEmptyOrNull())
@ -98,7 +117,7 @@ namespace Admin.Core.Api.Controllers.Business
}
var query = await _hw_WarehouseService.QueryByCode(code.Trim(), planId);
if (query==null)
if (query == null)
{
return Failed<WarehouseView>("查询失败!");
}
@ -193,13 +212,13 @@ namespace Admin.Core.Api.Controllers.Business
/// <param name="state"></param>
/// <returns></returns>
[HttpGet]
public async Task<MessageModel<bool>> ExecPlcState(string code,int state)
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);
var result = await _hw_WarehouseService.UpdatePlcState(code, state);
if (result)
{
return Success(result);
@ -222,7 +241,7 @@ namespace Admin.Core.Api.Controllers.Business
var result = await _hw_WarehouseService.GetPlanWeightInfo();
if (result != null)
{
return Success(result,"成功");
return Success(result, "成功");
}
return Failed<List<XLPlanWeightView>>("执行失败!");
}
@ -250,5 +269,32 @@ namespace Admin.Core.Api.Controllers.Business
return Success(list);
}
#endregion
/// <summary>
/// 根据罐号查询称量列表
/// </summary>
/// <param name="barrelID"></param>
/// <returns></returns>
[HttpGet]
public async Task<MessageModel<List<LR_weigh>>> GetWeightInfoByBarrelID(string barrelBarcode)
{
if (!barrelBarcode.IsNotEmptyOrNull())
{
return Failed<List<LR_weigh>>("传入参数为空!");
}
MessageModel<List<LR_weigh>> messageModel = new MessageModel<List<LR_weigh>>();
string planID = _hw_BarrelService.GetPlanIdByBarrelID(barrelBarcode.Trim());
if (string.IsNullOrEmpty(planID))
{
return Failed<List<LR_weigh>>("查询不到罐号对应的计划ID!");
}
List<LR_weigh> list = _lr_weighService.GetRecentWeightList(planID);
if (list != null)
{
return Success(list);
}
return Failed<List<LR_weigh>>("执行失败!");
}
}
}

@ -6,7 +6,7 @@
<appender name="ErrorLog" type="log4net.Appender.RollingFileAppender">
<!--不加utf-8编码格式中文字符将显示成乱码-->
<param name="Encoding" value="utf-8" />
<file value="E:\log\"/>
<file value="../../../Log/"/>
<appendToFile value="true" />
<rollingStyle value="Date" />
<!--日期的格式,每天换一个文件记录,如不设置则永远只记录一天的日志,需设置-->
@ -26,8 +26,6 @@
</appender>
<!--Error-->
<!--Info-->
<appender name="InfoLog" type="log4net.Appender.RollingFileAppender">
<!--不加utf-8编码格式中文字符将显示成乱码-->
@ -53,6 +51,15 @@
</appender>
<!--Info-->
<!--Console-->
<appender name="ConsoleLog" type="log4net.Appender.ConsoleAppender">
<!--布局(向用户显示最后经过格式化的输出信息)-->
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date | %-5level | %message%newline" />
</layout>
</appender>
<!--Console-->
<root>
<!-- 控制级别由低到高ALL|DEBUG|INFO|WARN|ERROR|FATAL|OFF -->
<!-- 比如定义级别为INFO则INFO级别向下的级别比如DEBUG日志将不会被记录 -->
@ -61,5 +68,6 @@
<!-- 按日期切分日志文件,并将日期作为日志文件的名字 -->
<appender-ref ref="ErrorLog" />
<appender-ref ref="InfoLog" />
<appender-ref ref="ConsoleLog" />
</root>
</log4net>

@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SqlSugar;
namespace Admin.Core.Api.PLTBusiness.Entity
{
public class BomData
{
/// <summary>
/// 总页数
/// </summary>
public int pageCount { get; set; }
/// <summary>
/// 页码
/// </summary>
public int pageIndex { get; set; }
/// <summary>
/// 数据对象
/// </summary>
public List<BomRecordListItem> recordList { get; set; }
/// <summary>
/// 总记录数
/// </summary>
public int recordCount { get; set; }
/// <summary>
/// 每页记录数
/// </summary>
public int pageSize { get; set; }
/// <summary>
/// 尾页编号
/// </summary>
public int endPageIndex { get; set; }
/// <summary>
/// 起始页编号
/// </summary>
public int beginPageIndex { get; set; }
}
public class BomRecordListItem
{
/// <summary>
/// 物料id
/// </summary>
public int id { get; set; }
/// <summary>
/// 物料名称
/// </summary>
public string name { get; set; }
/// <summary>
/// 物料状态0禁用 1启用
/// </summary>
public int status { get; set; }
/// <summary>
/// 物料编号
/// </summary>
public string code { get; set; }
/// <summary>
/// 物料创建时间
/// </summary>
public string createTime { get; set; }
}
}

@ -0,0 +1,24 @@
using System;
namespace Admin.Core.Api.PLTBusiness.Entity
{
public class LRWeighData
{
public string BinSerial { get; set; }
public string SetWeight { get; set; }
public string RealWeight { get; set; }
public string MainID { get; set; }
public DateTime EndTime { get; set; }
}
}

@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SqlSugar;
namespace Admin.Core.Api.PLTBusiness.Entity
{
public class MaterialData
{
/// <summary>
/// 总页数
/// </summary>
public int pageCount { get; set; }
/// <summary>
/// 页码
/// </summary>
public int pageIndex { get; set; }
/// <summary>
/// 数据对象
/// </summary>
public List<MaterialRecordListItem> recordList { get; set; }
/// <summary>
/// 总记录数
/// </summary>
public int recordCount { get; set; }
/// <summary>
/// 每页记录数
/// </summary>
public int pageSize { get; set; }
/// <summary>
/// 尾页编号
/// </summary>
public int endPageIndex { get; set; }
/// <summary>
/// 起始页编号
/// </summary>
public int beginPageIndex { get; set; }
}
public class MaterialRecordListItem
{
/// <summary>
/// 物料id
/// </summary>
public int id { get; set; }
/// <summary>
/// 物料名称
/// </summary>
public string name { get; set; }
/// <summary>
/// 物料状态0禁用 1启用
/// </summary>
public int status { get; set; }
/// <summary>
/// 物料编号
/// </summary>
public string code { get; set; }
/// <summary>
/// 物料创建时间
/// </summary>
public string createTime { get; set; }
}
}

@ -0,0 +1,24 @@
using System;
using System.Linq;
using System.Text;
using SqlSugar;
namespace Admin.Core.Api.PLTBusiness.Entity
{
public class ResponseRoot<T>
{
/// <summary>
/// 状态码
/// </summary>
public int code { get; set; }
/// <summary>
/// 消息提示
/// </summary>
public string message { get; set; }
/// <summary>
/// 结果对象
/// </summary>
public T Data { get; set; }
}
}

@ -0,0 +1,20 @@
using System;
using System.Linq;
using System.Text;
using SqlSugar;
namespace Admin.Core.Api.PLTBusiness.Entity
{
public class TokenData
{
/// <summary>
/// Token(后续请求需要携带这个Token)
/// </summary>
public string token { get; set; }
/// <summary>
/// Token失效时间
/// </summary>
public int expiration { get; set; }
}
}

@ -0,0 +1,458 @@
using Admin.Core.Api.PLTBusiness.Entity;
using Admin.Core.Common;
using Admin.Core.IService;
using Admin.Core.PlcServer;
using Admin.Core.Service;
using log4net;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using NPOI.HSSF.Record;
using RabbitMQ.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Security.Policy;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
namespace Admin.Core.Api.PLTBusiness
{
public class HttpService : BackgroundService
{
private readonly log4net.ILog log = LogManager.GetLogger(typeof(HttpService));
private readonly IServiceScopeFactory _scopeFactory;
private readonly IHttpClientFactory _httpClientFactory;
private readonly Ixl_recipeServices _xlrecipeServices;
private readonly string _host = "http://192.168.111.141:8090";
private string _token;
private int _tokenExpirationTime = 0;
public HttpService(IHttpClientFactory httpClientFactory, IServiceScopeFactory scopeFactory, Ixl_recipeServices xlrecipeServices)
{
_httpClientFactory = httpClientFactory;
_scopeFactory = scopeFactory;
_xlrecipeServices = xlrecipeServices;
}
/// <summary>
/// 循环执行的服务
/// </summary>
/// <param name="stoppingToken"></param>
/// <returns></returns>
protected async override Task ExecuteAsync(CancellationToken stoppingToken)
{
int second = 1000 * 10;
using var scope = _scopeFactory.CreateScope();
var services = scope.ServiceProvider;
var xlBusiness = services.GetService<XlBusiness>();
while (!stoppingToken.IsCancellationRequested)
{
//执行任务
//log.Info($"{DateTime.Now}");
if (_tokenExpirationTime == 0)
{
if (await GetToken())
{
log.Info("Token Get! Value:" + _token);
}
else
{
log.Error("Token Get Falied");
}
}
else if (_tokenExpirationTime <= 86400)
{
RefreshToken();
}
else
{
_tokenExpirationTime = _tokenExpirationTime - (second / 1000);
}
try
{
//物料信息同步
if (_token.IsNotEmptyOrNull())
{
await xlBusiness.InsertNewMaterialData(await GetMaterialDataPageList());
//await _xlrecipeServices.xlUpdateOrAdd();
}
else
{
log.Error("No Token!!!");
}
}
catch (Exception ex)
{
log.Error("Error: " + ex);
}
await Task.Delay(second);
}
}
#region Mes信息拉取
/// <summary>
/// 分页拉取所有Mes物料信息
/// </summary>
/// <returns></returns>
private async Task<List<MaterialRecordListItem>> GetMaterialDataPageList()
{
int pageSize = 200;
int pageIndex = 0;
int pageCount = 1;
string orgCode = "Mesnac";
List<MaterialRecordListItem> allMaterials = new List<MaterialRecordListItem>();
Dictionary<string, object> _pageInfo = new Dictionary<string, object>()
{
{"pageIndex", 200},
{"pageSize", 0},
{"orgCode", "Mesnac"},
};
try
{
do
{
string body = JsonSerializer.Serialize(_pageInfo);
string materialJson = await PostAsync(_host + "/qtn/api/q7/com/inventory/page",
body, "application/json", "application/json",
new Dictionary<string, string> { { "token", _token } }, 10);
ResponseRoot<MaterialData> responseRoot = JsonSerializer.Deserialize<ResponseRoot<MaterialData>>(materialJson);
if (responseRoot == null)
{
log.Error("物料信息拉取失败!");
return null;
}
if (responseRoot.code != 200)
{
log.Error("ERROR 状态码:" + responseRoot.code);
return null;
}
pageCount = responseRoot.Data.pageCount;
pageIndex = responseRoot.Data.pageIndex;
allMaterials.AddRange(responseRoot.Data.recordList);
pageIndex = pageIndex + 1;
}
while (pageIndex < pageSize);
}
catch (Exception ex)
{
log.Error("Mes物料信息拉取失败 Error: " + ex);
return null;
}
return allMaterials;
}
/// <summary>
/// 分页拉取所有MesBom配方信息
/// </summary>
/// <returns></returns>
private async Task<List<BomRecordListItem>> GetRecipeDataPageList()
{
int pageSize = 200;
int pageIndex = 0;
int pageCount = 1;
string orgCode = "Mesnac";
List<BomRecordListItem> allBoms = new List<BomRecordListItem>();
Dictionary<string, object> _pageInfo = new Dictionary<string, object>()
{
{"pageIndex", 200},
{"pageSize", 0},
{"orgCode", "Mesnac"},
};
try
{
do
{
string body = JsonSerializer.Serialize(_pageInfo);
string bomJson = await PostAsync(_host + "/qtn/api/q7/com/bom/page",
body, "application/json", "application/json",
new Dictionary<string, string> { { "token", _token } }, 10);
ResponseRoot<BomData> responseRoot = JsonSerializer.Deserialize<ResponseRoot<BomData>>(bomJson);
if (responseRoot == null)
{
log.Error("Bom信息拉取失败");
return null;
}
if (responseRoot.code != 200)
{
log.Error("ERROR 状态码:" + responseRoot.code);
return null;
}
pageCount = responseRoot.Data.pageCount;
pageIndex = responseRoot.Data.pageIndex;
allBoms.AddRange(responseRoot.Data.recordList);
pageIndex = pageIndex + 1;
}
while (pageIndex < pageSize);
}
catch (Exception ex)
{
log.Error("MesBom信息拉取失败 Error: " + ex);
return null;
}
return allBoms;
}
#endregion
#region Token获取
/// <summary>
/// 获取Token
/// </summary>
private async Task<bool> GetToken()
{
Dictionary<string, string> _tokenDictionary = new Dictionary<string, string>()
{
{"authCode", "QT_XXX"},
{"appid", "q7cloud_XXX"},
{"secret", "f434eab8b9652524dc719e33f4ff255a45570XXX"}
};
try
{
string body = JsonSerializer.Serialize(_tokenDictionary);
string tokenJson = await PostAsync(_host + "/qtn/api/auth/token", body, "application/json", "application/json", null, 10);
ResponseRoot<TokenData> responseRoot = JsonSerializer.Deserialize<ResponseRoot<TokenData>>(tokenJson);
if (responseRoot == null)
{
log.Error("Token获取失败");
return false;
}
if (responseRoot.code != 200)
{
log.Error("ERROR 状态码:" + responseRoot.code);
return false;
}
_token = responseRoot.Data.token;
_tokenExpirationTime = responseRoot.Data.expiration;
log.Info("Token获取成功" + _token + "超时时间:" + _tokenExpirationTime);
return true;
}
catch (Exception ex)
{
log.Error("Token获取失败 ERROR: " + ex.ToString());
return false;
}
}
/// <summary>
/// 刷新Token
/// </summary>
private async Task<bool> RefreshToken()
{
try
{
string tokenJson = await PostAsync(_host + "/qtn/api/auth/token/refresh", ""
, "application/json", "application/x-www-form-urlencoded"
, new Dictionary<string, string>() { { "token", _token } }, 10);
ResponseRoot<TokenData> responseRoot = JsonSerializer.Deserialize<ResponseRoot<TokenData>>(tokenJson);
if (responseRoot == null)
{
log.Error("Token更新失败");
return false;
}
if (responseRoot.code != 200)
{
log.Error("ERROR 状态码:" + responseRoot.code);
return false;
}
_token = responseRoot.Data.token;
_tokenExpirationTime = responseRoot.Data.expiration;
log.Info("Token更新成功" + _token + "超时时间:" + _tokenExpirationTime);
return true;
}
catch (Exception ex)
{
log.Error("Token更新失败 ERROR: " + ex.ToString());
return false;
}
}
#endregion
#region HTTP操作
/// <summary>
/// 发起POST异步请求
/// </summary>
/// <param name="url">请求地址</param>
/// <param name="body">POST提交的内容</param>
/// <param name="bodyMediaType">POST内容的媒体类型application/xml、application/json</param>
/// <param name="responseContentType">HTTP响应上的content-type内容头的值,如application/xml、application/json、application/text、application/x-www-form-urlencoded等</param>
/// <param name="headers">请求头信息</param>
/// <param name="timeOut">请求超时时间,单位秒</param>
/// <returns>返回string</returns>
private async Task<string> PostAsync(string url, string body,
string bodyMediaType = null,
string responseContentType = null,
Dictionary<string, string> headers = null,
int timeOut = 30)
{
try
{
var hostName = GetHostName(url);
using (HttpClient client = _httpClientFactory.CreateClient(hostName))
{
client.Timeout = TimeSpan.FromSeconds(timeOut);
if (headers?.Count > 0)
{
foreach (string key in headers.Keys)
{
client.DefaultRequestHeaders.Add(key, headers[key]);
}
}
StringContent content = new StringContent(body, System.Text.Encoding.UTF8, mediaType: bodyMediaType);
if (!string.IsNullOrWhiteSpace(responseContentType))
{
content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(responseContentType);
}
using (HttpResponseMessage response = await client.PostAsync(url, content))
{
if (response.IsSuccessStatusCode)
{
string responseString = await response.Content.ReadAsStringAsync();
return responseString;
}
else
{
return string.Empty;
}
}
}
}
catch (Exception ex)
{
log.Error($"Post请求失败 URL{url} ERROR: {ex.ToString()} Time: {DateTime.Now}");
throw;
}
}
/// <summary>
/// 发起GET异步请求
/// </summary>
/// <typeparam name="T">返回类型</typeparam>
/// <param name="url">请求地址</param>
/// <param name="headers">请求头信息</param>
/// <param name="timeOut">请求超时时间,单位秒</param>
/// <returns>返回string</returns>
private async Task<string> GetAsync(string url, Dictionary<string, string> headers = null, int timeOut = 30)
{
try
{
var hostName = GetHostName(url);
using (HttpClient client = _httpClientFactory.CreateClient(hostName))
{
client.Timeout = TimeSpan.FromSeconds(timeOut);
if (headers?.Count > 0)
{
foreach (string key in headers.Keys)
{
client.DefaultRequestHeaders.Add(key, headers[key]);
}
}
using (HttpResponseMessage response = await client.GetAsync(url))
{
if (response.IsSuccessStatusCode)
{
string responseString = await response.Content.ReadAsStringAsync();
return responseString;
}
else
{
return string.Empty;
}
}
}
}
catch (Exception ex)
{
log.Error($"Get请求失败 URL{url} ERROR: {ex.ToString()} Time: {DateTime.Now}");
throw;
}
}
private async Task Post(string url, Dictionary<string, string> headers = null)
{
var hostName = GetHostName(url);
// 创建 HttpClient 实例
var client = _httpClientFactory.CreateClient(hostName);
// 定义要发送的对象
//var data = new
//{
// Name = "John Doe",
// Age = 30,
// Email = "john.doe@example.com"
//};
// 序列化对象为 JSON
var json = JsonSerializer.Serialize(headers);
// 创建 HttpContent设置内容为 JSON 格式
var content = new StringContent(json, Encoding.UTF8, "application/json");
// 发送 POST 请求
var response = await client.PostAsync(url, content);
// 检查响应状态码
if (response.IsSuccessStatusCode)
{
// 读取响应内容
var responseBody = await response.Content.ReadAsStringAsync();
log.Info($"Response: {responseBody}");
}
else
{
log.Error($"Error: {response.StatusCode}");
}
}
#endregion
#region 私有函数
/// <summary>
/// 获取请求的主机名
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
private static string GetHostName(string url)
{
if (!string.IsNullOrWhiteSpace(url))
{
return url.Replace("https://", "").Replace("http://", "").Split('/')[0];
}
else
{
return "AnyHost";
}
}
#endregion
}
}

@ -0,0 +1,76 @@
using Admin.Core.Api.PLTBusiness.Entity;
using Admin.Core.IService;
using Admin.Core.Model;
using Admin.Core.Service;
using Microsoft.Extensions.Hosting;
using RabbitMQ.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Security.Policy;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
namespace Admin.Core.Api.PLTBusiness
{
public class XlBusiness
{
private readonly Ixl_materialServices _xl_materialService;
public XlBusiness(Ixl_materialServices xl_materialService)
{
_xl_materialService = xl_materialService;
}
/// <summary>
/// 向物料数据库中动态同步mes数据没有就插入不同就修改
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
public async Task<bool> InsertNewMaterialData(List<MaterialRecordListItem> list)
{
try
{
foreach (var mesMaterial in list)
{
// Step 3: 在B表中查询是否存在相同ID的记录
var material = await _xl_materialService.SelectXlMaterialById(mesMaterial.id.ToString());
if (material == null)
{
// Step 4: 如果B表中不存在该物料插入新物料
await _xl_materialService.xlInsertMaterial(
mesMaterial.id.ToString(),
mesMaterial.code, mesMaterial.name, mesMaterial.status,
Convert.ToDateTime(mesMaterial.createTime));
}
else
{
// Step 5: 如果B表中存在该物料且有更新更新物料信息
if (material.Material_code != mesMaterial.code ||
material.Material_name != mesMaterial.name ||
material.IsEnable != (mesMaterial.status == 1 ? "是" : "否") ||
material.CreateDateTime != Convert.ToDateTime(mesMaterial.createTime))
{
await _xl_materialService.xlUpdateMaterial(
mesMaterial.id.ToString(),
mesMaterial.code, mesMaterial.name, mesMaterial.status,
Convert.ToDateTime(mesMaterial.createTime));
}
}
}
return true;
}
catch (Exception ex)
{
throw;
}
}
}
}

@ -28,6 +28,8 @@ namespace Admin.Core.Api
// 运行 web 应用程序并阻止调用线程, 直到主机关闭。
// ※※※※ 有异常,查看 Log 文件夹下的异常日志 ※※※※
.Run();
}
/// <summary>
@ -59,5 +61,6 @@ namespace Admin.Core.Api
// 默认log4net.confg
builder.AddLog4Net(Path.Combine(Directory.GetCurrentDirectory(), "Log4net.config"));
});
}
}

@ -1,3 +1,4 @@
using Admin.Core.Api.PLTBusiness;
using Admin.Core.Common;
using Admin.Core.Extensions;
using Admin.Core.IService.ISys;
@ -23,6 +24,7 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using TouchSocket.Http;
namespace Admin.Core.Api
{
@ -103,11 +105,16 @@ namespace Admin.Core.Api
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});
//×¢²áhttpÇëÇó·þÎñ
services.AddHttpClient();
//ÈÎÎñµ÷¶È
services.AddJobSetup();
//Ìí¼ÓPLC
services.AddPlcSetup();
//Ìí¼Ó·þÎñ
//services.AddHostedService<PLTBusiness.HttpService>();
//services.AddScoped<PLTBusiness.XlBusiness>();
//Redis»º´æ
//services.AddRedisCacheSetup();
//Redis¶ÓÁÐ

@ -0,0 +1,22 @@
using Admin.Core.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Admin.Core.IService.IService_New
{
/// <summary>
/// 料筒服务类
/// </summary>
public interface IHw_BarrelServices : IBaseServices<Hw_Barrel>
{
/// <summary>
/// 根据罐号获取料罐ID
/// </summary>
/// <param name="barrelID"></param>
/// <returns></returns>
string GetPlanIdByBarrelID(string barrelBarcode);
}
}

@ -1,5 +1,6 @@
using Admin.Core.IService;
using Admin.Core.Model;
using System.Collections.Generic;
namespace Admin.Core.IService
{
@ -8,5 +9,10 @@ namespace Admin.Core.IService
/// </summary>
public interface ILR_weighServices :IBaseServices<LR_weigh>
{
/// <summary>
/// 通过计划号获取最近一次的称量列表
/// </summary>
/// <returns></returns>
List<LR_weigh> GetRecentWeightList(string planCode);
}
}

@ -3,6 +3,7 @@ using Admin.Core.IService;
using Admin.Core.Model;
using Admin.Core.Model.ViewModels;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Admin.Core.IService
@ -38,6 +39,49 @@ namespace Admin.Core.IService
Task<MessageModel<bool>> MaterialVerification(string barCode);
Task<bool> xlInsertMaterial(string materialCode, string materialName);
/// <summary>
/// 物料插入
/// </summary>
/// <param name="id"></param>
/// <param name="materialCode"></param>
/// <param name="materialName"></param>
/// <param name="isEnable"></param>
/// <param name="createDatetime"></param>
/// <returns></returns>
Task<bool> xlInsertMaterial(
string id,
string materialCode,
string materialName,
int isEnable,
DateTime createDatetime);
/// <summary>
/// 物料更新
/// </summary>
/// <param name="id"></param>
/// <param name="materialCode"></param>
/// <param name="materialName"></param>
/// <param name="isEnable"></param>
/// <param name="createDatetime"></param>
/// <returns></returns>
Task<bool> xlUpdateMaterial(
string id,
string materialCode,
string materialName,
int isEnable,
DateTime createDatetime);
/// <summary>
/// 物料查询
/// </summary>
/// <returns></returns>
Task<List<xl_material>> xlMaterialList();
/// <summary>
/// 根据ID查询
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<xl_material> SelectXlMaterialById(string id);
}
}

@ -1,5 +1,7 @@
using Admin.Core.IService;
using Admin.Core.Model;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Admin.Core.IService
{
@ -8,5 +10,31 @@ namespace Admin.Core.IService
/// </summary>
public interface Ixl_recipeServices :IBaseServices<xl_recipe>
{
/// <summary>
/// 新增配方信息
/// </summary>
/// <param name="recipe"></param>
/// <returns></returns>
Task<bool> xlInsertRecipe(xl_recipe recipe);
/// <summary>
/// 更新配方信息
/// </summary>
/// <param name="recipe"></param>
/// <returns></returns>
Task<bool> xlUpdateRecipe(xl_recipe recipe);
/// <summary>
/// 获取配方列表
/// </summary>
/// <returns></returns>
Task<List<xl_recipe>> xlGetAllRecipes();
/// <summary>
/// 如果有记录就更新,没有记录就新增
/// </summary>
/// <param name="recipe"></param>
/// <returns></returns>
Task<bool> xlUpdateOrAdd(xl_recipe recipe);
}
}

@ -9,7 +9,7 @@ namespace Admin.Core.Model
///<summary>
///配方信息
///</summary>
[SugarTable( "xl_recipe", "cwss_xl")]
[SugarTable("xl_recipe", "cwss_xl")]
public class xl_recipe
{
public xl_recipe()
@ -20,142 +20,138 @@ namespace Admin.Core.Model
/// Default:
/// Nullable:False
/// </summary>
public string ID { get; set; }
public string ID { get; set; }
/// <summary>
/// Desc:机台号
/// Default:
/// Nullable:True
/// </summary>
public string Equip_Code { get; set; }
public string Equip_Code { get; set; }
/// <summary>
/// Desc:配方编码
/// Default:
/// Nullable:True
/// </summary>
public string Recipe_Code { get; set; }
public string Recipe_Code { get; set; }
/// <summary>
/// Desc:配方版本号
/// Default:
/// Nullable:True
/// </summary>
public string Version { get; set; }
public string Version { get; set; }
/// <summary>
/// Desc:配方别名
/// Default:
/// Nullable:True
/// </summary>
public string Recipe_Name { get; set; }
public string Recipe_Name { get; set; }
/// <summary>
/// Desc:配方版本号
/// Default:
/// Nullable:True
/// </summary>
public string Mixer_line { get; set; }
public string Mixer_line { get; set; }
/// <summary>
/// Desc:配方类型
/// Default:
/// Nullable:True
/// </summary>
public int? Recipe_type { get; set; }
public int? Recipe_type { get; set; }
/// <summary>
/// Desc:配方习惯
/// Default:
/// Nullable:True
/// </summary>
public int? Recipe_Used { get; set; }
public int? Recipe_Used { get; set; }
/// <summary>
/// Desc:配方验证
/// Default:0
/// Nullable:True
/// </summary>
public int? Recipe_Verify { get; set; }
public int? Recipe_Verify { get; set; }
/// <summary>
/// Desc:总计重量
/// Default:
/// Nullable:True
/// </summary>
public decimal? Total_Weight { get; set; }
public decimal? Total_Weight { get; set; }
/// <summary>
/// Desc:总计误差
/// Default:
/// Nullable:True
/// </summary>
public decimal? Total_Error { get; set; }
public decimal? Total_Error { get; set; }
/// <summary>
/// Desc:结束时间
/// Default:
/// Nullable:True
/// </summary>
public string End_datetime { get; set; }
public string End_datetime { get; set; }
/// <summary>
/// Desc:备注
/// Default:
/// Nullable:True
/// </summary>
public string Remark { get; set; }
public string Remark { get; set; }
/// <summary>
/// Desc:附件用户
/// Default:
/// Nullable:True
/// </summary>
public int? Attach_User { get; set; }
public int? Attach_User { get; set; }
/// <summary>
/// Desc:分组袋
/// Default:
/// Nullable:True
/// </summary>
public int? GroupBags { get; set; }
public int? GroupBags { get; set; }
/// <summary>
/// Desc:
/// Default:
/// Nullable:True
/// </summary>
public int? IF_FLAG { get; set; }
public int? IF_FLAG { get; set; }
/// <summary>
/// Desc:有效性
/// Default:
/// Nullable:True
/// </summary>
public int? Validity { get; set; }
public int? Validity { get; set; }
/// <summary>
/// Desc:有效天数
/// Default:
/// Nullable:True
/// </summary>
public int? ValidDays { get; set; }
public int? ValidDays { get; set; }
/// <summary>
/// Desc:
/// Default:
/// Nullable:True
/// </summary>
public string UpdateByID { get; set; }
public string UpdateByID { get; set; }
/// <summary>
/// Desc:
/// Default:
/// Nullable:True
/// </summary>
public string UpdateBy { get; set; }
public string UpdateBy { get; set; }
/// <summary>
/// Desc:
/// Default:
/// Nullable:True
/// </summary>
public string CreatorID { get; set; }
public string CreatorID { get; set; }
/// <summary>
/// Desc:
/// Default:
/// Nullable:True
/// </summary>
public string Creator { get; set; }
public string Creator { get; set; }
/// <summary>
/// Desc:
/// Default:
/// Nullable:True
/// </summary>
public DateTime? CreateDateTime { get; set; }
/// <summary>
/// 是否产前验证
/// </summary>
public int IsCheck { get; set; }
public DateTime? CreateDateTime { get; set; }
}
}

@ -507,7 +507,7 @@ namespace Admin.Core.PlcServer
{
siemensS7Net.ReceiveTimeOut = 2000;
OperateResult<bool> read = await siemensS7Net.ReadBoolAsync(address);
log.Info($"心跳方法是否成功:{read.IsSuccess};反馈:{read.Message}");
//log.Info($"心跳方法是否成功:{read.IsSuccess};反馈:{read.Message}");
if (read.IsSuccess)
{
IsConnected = true;

@ -0,0 +1,36 @@
using Admin.Core.IRepository;
using Admin.Core.IService;
using Admin.Core.IService.IService_New;
using Admin.Core.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Admin.Core.Service.Service_New
{
public class Hw_BarrelServices : BaseServices<Hw_Barrel>, IHw_BarrelServices
{
private readonly IBaseRepository<Hw_Barrel> _dal;
public Hw_BarrelServices(IBaseRepository<Hw_Barrel> dal)
{
this._dal = dal;
base.BaseDal = dal;
}
public string GetPlanIdByBarrelID(string barrelBarcode)
{
try
{
string planId = _dal.Query(x => x.BarCode == barrelBarcode).FirstOrDefault().PlanId.ToString();
return planId;
}
catch
{
throw;
}
}
}
}

@ -2,6 +2,9 @@
using Admin.Core.Service;
using Admin.Core.IService;
using Admin.Core.Model;
using System.Collections.Generic;
using System.Linq;
using System;
namespace Admin.Core.Service
{
@ -13,5 +16,20 @@ namespace Admin.Core.Service
this._dal = dal;
base.BaseDal = dal;
}
public List<LR_weigh> GetRecentWeightList(string planCode)
{
try
{
List<LR_weigh> list = _dal.Query(x => x.Plan_ID == planCode).ToList();
int maxMainID = list.Max(x => x.MainId);
List<LR_weigh> groupList = list.Where(x => x.MainId == maxMainID).ToList();
return groupList;
}
catch
{
throw;
}
}
}
}

@ -658,6 +658,7 @@ namespace Admin.Core.Service
#endregion
#region 料框防错验证——只验证单料
public async Task<MessageModel<bool>> MaterialVerification(string barCode)
{
MessageModel<bool> messageModel = new MessageModel<bool>();
@ -709,30 +710,36 @@ namespace Admin.Core.Service
}
#endregion
/// <summary>
/// 小料上位机同步插入物料信息
/// 小料上位机插入物料信息
/// </summary>
/// <param name="planDate"></param>
/// <param name="recipeGUID"></param>
/// <param name="batch"></param>
/// <param name="productName"></param>
/// <returns></returns>
public async Task<bool> xlInsertMaterial(string materialCode, string materialName)
public async Task<bool> xlInsertMaterial(
string id,
string materialCode,
string materialName,
int isEnable,
DateTime createDatetime)
{
try
{
xl_material xl_m = new xl_material()
{
ID = Guid.NewGuid().ToString("N"),
ID = id,
Material_code = materialCode,
Material_name = materialName,
CreateDateTime = DateTime.Now,
CreateDateTime = createDatetime,
Remark = null,
Batch_number = null,
Barcode1 = null,
Barcode2 = null,
Barcode3 = null,
IsEnable = "是"
IsEnable = isEnable == 1 ? "是" : "否"
};
var result = await _xl_materialRepository.Add(xl_m);
@ -747,10 +754,87 @@ namespace Admin.Core.Service
}
catch (Exception ex)
{
return false;
throw;
}
}
/// <summary>
/// 小料上位机更新物料信息
/// </summary>
/// <param name="planDate"></param>
/// <param name="recipeGUID"></param>
/// <param name="batch"></param>
/// <param name="productName"></param>
/// <returns></returns>
public async Task<bool> xlUpdateMaterial(
string id,
string materialCode,
string materialName,
int isEnable,
DateTime createDatetime)
{
try
{
xl_material xl_m = new xl_material()
{
ID = id,
Material_code = materialCode,
Material_name = materialName,
CreateDateTime = createDatetime,
Remark = null,
Batch_number = null,
Barcode1 = null,
Barcode2 = null,
Barcode3 = null,
IsEnable = isEnable == 1 ? "是" : "否"
};
bool result = await _xl_materialRepository.UpdateAsync(xl_m, $"ID = '{id}'");
return result;
}
catch (Exception e)
{
throw;
}
}
/// <summary>
/// 获取小料上位机物料信息
/// </summary>
/// <param name="planDate"></param>
/// <param name="recipeGUID"></param>
/// <param name="batch"></param>
/// <param name="productName"></param>
/// <returns></returns>
public async Task<List<xl_material>> xlMaterialList()
{
try
{
return await _xl_materialRepository.QueryAsync();
}
catch (Exception ex)
{
throw;
}
}
/// <summary>
/// 根据ID查询物料信息
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async Task<xl_material> SelectXlMaterialById(string id)
{
try
{
return await _xl_materialRepository.QueryByIdAsync(id);
}
catch (Exception ex)
{
throw;
}
}
}
}

@ -2,6 +2,13 @@
using Admin.Core.Service;
using Admin.Core.IService;
using Admin.Core.Model;
using System.Threading.Tasks;
using System.Collections.Generic;
using System;
using Serilog;
using NPOI.SS.Formula.Functions;
using System.Linq;
using Microsoft.Extensions.Logging;
namespace Admin.Core.Service
{
@ -13,5 +20,69 @@ namespace Admin.Core.Service
this._dal = dal;
base.BaseDal = dal;
}
public async Task<List<xl_recipe>> xlGetAllRecipes()
{
try
{
return await _dal.QueryAsync();
}
catch(Exception ex)
{
throw;
}
}
public async Task<bool> xlInsertRecipe(xl_recipe recipe)
{
try
{
if(await _dal.AddAsync(recipe) == 1)
{
return true;
}
else
{
return false;
}
}
catch(Exception ex)
{
throw;
}
}
public async Task<bool> xlUpdateRecipe(xl_recipe recipe)
{
try
{
return await _dal.UpdateAsync(recipe);
}
catch(Exception ex)
{
throw;
}
}
public async Task<bool> xlUpdateOrAdd(xl_recipe recipe)
{
try
{
var record = await _dal.QueryAsync(x => x.Recipe_Code == recipe.Recipe_Code);
if(record == null || record.Count == 0)
{
recipe.ID = record[0].ID;
return await xlUpdateRecipe(recipe);
}
else
{
return await xlInsertRecipe(recipe);
}
}
catch (Exception ex)
{
throw;
}
}
}
}
Loading…
Cancel
Save