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 { /// /// 查询所有通讯协议明细与参数项的关联关系 /// /// public ISugarQueryable QueryProtocolDetailParas() { try { return db.Queryable(); } catch (Exception ex) { LogHelper.Error(ex, "执行ProtocolDetailParaService下QueryProtocolDetailParas时异常"); return null; } } public List QueryProtocolDetailParaVMs(string _protocolConfigCode, string msgCode) { try { return db.Queryable() .InnerJoin((a, b) => a.MsgCode == b.MsgCode && b.MsgType == MsgTypeEnum.Send.ToString() && b.IsActive) .LeftJoin((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; } } /// /// 新增通讯协议明细与参数项的关联关系 /// /// /// 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; } } /// /// 批量新增通讯协议明细与参数项的关联关系 /// /// /// public (bool isOk, string msg) AddProtocolDetailParas(List t_Protocol_Detail_Paras) { var result = db.UseTran(() => { var delRows = db.Deleteable() .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, "操作成功!"); } /// /// 根据Id删除通讯协议明细与参数项的关联关系 /// /// /// public (bool isOk, string msg) DelProtocolDetailParaById(string id) { try { var row = db.Deleteable().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); } } } }