using Org.BouncyCastle.Crypto; using Ropin.Inspection.Model; using Ropin.Inspection.Model.Entities; using Ropin.Inspection.Repository.SYS.Interface; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Ropin.Inspection.Repository.SYS { public class TsysMessageFileRepository : RepositoryBase, ITsysMessageFileRepository { public TsysMessageFileRepository(InspectionDbContext dbContext) : base(dbContext) { } /// /// IdList和messageCode值传一个 /// /// 根据多个ID删除 /// 根据消息ID删除 /// public Task DeleteMultitByID(List IdList,string messageCode) { MySqlConnector.MySqlParameter[] parameters = null; if (IdList!=null&& IdList.Count>0) { string idSre=string.Join("','", IdList); string sql = $" DELETE from TSYS_MessageFile where C_ID in ('{idSre}') "; int iResult = EntityFrameworkCoreExtensions.ExecuteSqlNoQuery(DbContext.Database, sql, parameters); bool result = iResult > 0; return Task.FromResult(result); } else { parameters= new[] { new MySqlConnector.MySqlParameter("code", messageCode) }; string sql = $" DELETE from TSYS_MessageFile where C_MessageCode=@code; "; int iResult = EntityFrameworkCoreExtensions.ExecuteSqlNoQuery(DbContext.Database, sql, parameters); bool result = iResult > 0; return Task.FromResult(result); } } public Task> GetList(TsysMessageFileSearchModel searchModel) { MySqlConnector.MySqlParameter[] parameters = new[] { new MySqlConnector.MySqlParameter("Status", searchModel.C_Status), new MySqlConnector.MySqlParameter("id", searchModel.C_ID), new MySqlConnector.MySqlParameter("messageCode", searchModel.C_MessageCode) }; StringBuilder sql = new StringBuilder(); sql.Append(@" select * from TSYS_MessageFile "); if (!string.IsNullOrEmpty(searchModel.C_Status)) { sql.Append(" where C_Status=@Status "); } else { sql.Append(" where C_Status!='0' "); } if (!string.IsNullOrEmpty(searchModel.C_ID)) { sql.Append(" and C_ID=@id "); } if (searchModel.C_MessageCode != null) { sql.Append(" and C_MessageCode=@messageCode "); } sql.Append(" order by D_CreateOn desc "); IEnumerable recordItemlist = EntityFrameworkCoreExtensions.GetList(DbContext.Database, sql.ToString(), parameters); searchModel.TotalCount = recordItemlist.First() != null ? recordItemlist.ToList().Count : 0; if (searchModel.TotalCount == 0) { recordItemlist = new List(); } return Task.FromResult(searchModel.IsPagination ? recordItemlist.Skip((searchModel.PageIndex - 1) * searchModel.PageSize).Take(searchModel.PageSize) : recordItemlist); } } }