You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ProductionSystem/ProductionSystem_Service/ProtocolDetailParaService.cs

124 lines
4.7 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using ProductionSystem_Log;
using ProductionSystem_Model.DbModel.Para;
using ProductionSystem_Model.DbModel.Protocol;
using ProductionSystem_Model.Enum;
using ProductionSystem_Model.ViewModel.Response.Protocol;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
namespace ProductionSystem_Service
{
public class ProtocolDetailParaService : DbContext
{
/// <summary>
/// 查询所有通讯协议明细与参数项的关联关系
/// </summary>
/// <returns></returns>
public ISugarQueryable<T_Protocol_Detail_Para> QueryProtocolDetailParas()
{
try
{
return db.Queryable<T_Protocol_Detail_Para>();
}
catch (Exception ex)
{
LogHelper.Error(ex, "执行ProtocolDetailParaService下QueryProtocolDetailParas时异常");
return null;
}
}
public List<ProtocolDetailParaVM> QueryProtocolDetailParaVMs(string _protocolConfigCode, string msgCode)
{
try
{
return db.Queryable<T_Protocol_Detail_Para>()
.InnerJoin<T_Protocol_Detail_Config>((a, b) => a.MsgCode == b.MsgCode && b.MsgType == MsgTypeEnum.Send.ToString() && b.IsActive)
.LeftJoin<T_ParaConfig>((a, b, c) => a.ParaCode == c.ParaCode && a.ParaCategoryCode == c.ParaCategory && c.IsActive)
.Where((a, b, c) => b.ProtocolConfigCode == _protocolConfigCode && a.MsgCode == msgCode)
.Select((a, b, c) => new ProtocolDetailParaVM
{
Id = a.Id,
ParaCategoryCode = a.ParaCategoryCode,
ParaCode = a.ParaCode,
IsActive = a.IsActive,
Remark = a.Remark
}).ToList();
}
catch (Exception ex)
{
LogHelper.Error(ex, "执行ProtocolDetailParaService下QueryProtocolDetailParaVMs时异常");
return null;
}
}
/// <summary>
/// 新增通讯协议明细与参数项的关联关系
/// </summary>
/// <param name="t_Protocol_Detail_Para"></param>
/// <returns></returns>
public int AddProtocolDetailPara(T_Protocol_Detail_Para t_Protocol_Detail_Para)
{
try
{
return db.Insertable(t_Protocol_Detail_Para).ExecuteCommand();
}
catch (Exception ex)
{
LogHelper.Error(ex, "执行ProtocolDetailParaService下AddProtocolDetailPara时异常");
return -1;
}
}
/// <summary>
/// 批量新增通讯协议明细与参数项的关联关系
/// </summary>
/// <param name="t_Protocol_Detail_Paras"></param>
/// <returns></returns>
public (bool isOk, string msg) AddProtocolDetailParas(List<T_Protocol_Detail_Para> t_Protocol_Detail_Paras)
{
var result = db.UseTran(() =>
{
var delRows = db.Deleteable<T_Protocol_Detail_Para>()
.Where(m => m.MsgCode == t_Protocol_Detail_Paras.FirstOrDefault().MsgCode).ExecuteCommand();
var rows = db.Insertable(t_Protocol_Detail_Paras).ExecuteCommand();
if (rows > 0 && rows == t_Protocol_Detail_Paras.Count)
{
return true;
}
else
{
return false;
}
});
if (!result.Data) //返回值为false
{
return (false, "批量新增通讯协议明细与参数项的关联关系,操作失败!");
}
return (true, "操作成功!");
}
/// <summary>
/// 根据Id删除通讯协议明细与参数项的关联关系
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public (bool isOk, string msg) DelProtocolDetailParaById(string id)
{
try
{
var row = db.Deleteable<T_Protocol_Detail_Para>().Where(m => m.Id == id).ExecuteCommand();
return (row > 0, row > 0 ? "操作成功!" : "操作失败!");
}
catch (Exception ex)
{
var errorMsg = $"执行ProtocolDetailParaService下DelProtocolDetailParaById时异常{ex.Message}";
LogHelper.Error(ex, errorMsg);
return (false, errorMsg);
}
}
}
}