using Ropin.Inspection.Model; using Ropin.Inspection.Model.Entities; using Ropin.Inspection.Model.ViewModel.DEV; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Ropin.Inspection.Repository { public class TdevBoxRepository : RepositoryBase, ITdevBoxRepository { public TdevBoxRepository(InspectionDbContext DbContext) : base(DbContext) { } public Task> GetConditionAsync(TdevBoxSearchModel searchModel) { MySqlConnector.MySqlParameter[] parameters = new[] { new MySqlConnector.MySqlParameter("Status", searchModel.C_Status), new MySqlConnector.MySqlParameter("name", "%"+searchModel.C_Name+"%"), new MySqlConnector.MySqlParameter("devName", "%"+searchModel.C_DeviceName+"%"), new MySqlConnector.MySqlParameter("StoreCode", searchModel.C_StoreCode), new MySqlConnector.MySqlParameter("Id ", searchModel.C_ID) }; StringBuilder sql = new StringBuilder(); sql.Append(@"select * from ( select b.*,t.C_ImagePath,t.C_Name as C_BoxTempName from TDEV_Box b LEFT JOIN TDEV_BoxTemplate t on (b.C_BoxTempCode=t.C_ID) ) tab where 1=1"); if (!string.IsNullOrEmpty(searchModel.C_Status)) { sql.Append(" and C_Status=@Status "); } else { sql.Append(" and C_Status!='0' "); } if (!string.IsNullOrEmpty(searchModel.C_Name)) { sql.Append(" and C_Name like @name"); } if (!string.IsNullOrEmpty(searchModel.C_StoreCode)) { sql.Append(" and C_StoreCode=@StoreCode "); } if (!string.IsNullOrEmpty(searchModel.C_ID)) { sql.Append(" and C_ID=@Id "); } if (!string.IsNullOrEmpty(searchModel.C_DeviceName)) { sql.Append(" and C_ID in ( select b.C_BoxCode from TDEV_DevBox b LEFT JOIN TDEV_DevStore d on (b.C_DevStoreCode=d.C_ID) where d.C_Name like @devName) "); } sql.Append(" order by I_Sort "); IEnumerable recordItemlist = EntityFrameworkCoreExtensions.GetList(DbContext.Database, sql.ToString(), parameters); searchModel.TotalCount = recordItemlist.First() != null ? recordItemlist.ToList().Count : 0; if (recordItemlist.Count()==1&& recordItemlist.FirstOrDefault()==null) { recordItemlist = null; return Task.FromResult(recordItemlist); } return Task.FromResult(searchModel.IsPagination ? recordItemlist.Skip((searchModel.PageIndex - 1) * searchModel.PageSize).Take(searchModel.PageSize) : recordItemlist); } } }