LargeScreenControlRepository.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using Ropin.Inspection.Model.Entities;
  2. using Ropin.Inspection.Model.SearchModel.LGS;
  3. using Ropin.Inspection.Model.ViewModel.LGS;
  4. using Ropin.Inspection.Repository.LGS.Interface;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace Ropin.Inspection.Repository.LGS
  11. {
  12. public class LargeScreenControlRepository : RepositoryBase<TLGS_LargeScreenControl, string>, ILargeScreenControlRepository
  13. {
  14. public LargeScreenControlRepository(InspectionDbContext dbContext) : base(dbContext)
  15. {
  16. }
  17. public Task<bool> DeleteByLargeScreenCodeAsync(string largeScreenCode)
  18. {
  19. MySqlConnector.MySqlParameter[] parameters = new[] { new MySqlConnector.MySqlParameter("code", largeScreenCode) };
  20. string sql = "DELETE FROM TLGS_LargeScreenControl where C_LargeScreenCode=@code ";
  21. int iResult = EntityFrameworkCoreExtensions.ExecuteSqlNoQuery(DbContext.Database, sql, parameters);
  22. bool result = iResult > 0;
  23. return Task.FromResult(result);
  24. }
  25. public Task<IEnumerable<LargeScreenControlViewModel>> GetConditionAsync(LargeScreenControlSearch searchModel)
  26. {
  27. MySqlConnector.MySqlParameter[] parameters = new[] {
  28. new MySqlConnector.MySqlParameter("Status", searchModel?.C_Status),
  29. new MySqlConnector.MySqlParameter("ControlName", "%"+searchModel?.C_ControlName+"%"),
  30. new MySqlConnector.MySqlParameter("LargeScreenCode", searchModel?.C_LargeScreenCode),
  31. new MySqlConnector.MySqlParameter("type ", searchModel?.C_Type),
  32. new MySqlConnector.MySqlParameter("Id ", searchModel?.C_ID)
  33. };
  34. StringBuilder sql = new StringBuilder();
  35. sql.Append(@"select * from (
  36. select t.*,d.C_Name as C_TypeName
  37. from TLGS_LargeScreenControl t
  38. LEFT JOIN TBDM_CodeDetail d on (t.C_Type=d.C_Code)
  39. ) tab where 1=1");
  40. if (!string.IsNullOrEmpty(searchModel.C_Status))
  41. {
  42. sql.Append(" and C_Status=@Status ");
  43. }
  44. if (!string.IsNullOrEmpty(searchModel.C_ControlName))
  45. {
  46. sql.Append(" and C_ControlName like @ControlName");
  47. }
  48. if (!string.IsNullOrEmpty(searchModel.C_LargeScreenCode))
  49. {
  50. sql.Append(" and C_LargeScreenCode=@LargeScreenCode ");
  51. }
  52. if (!string.IsNullOrEmpty(searchModel.C_Type))
  53. {
  54. sql.Append(" and C_Type=@type ");
  55. }
  56. if (!string.IsNullOrEmpty(searchModel.C_ID))
  57. {
  58. sql.Append(" and C_ID=@Id ");
  59. }
  60. sql.Append(" order by D_CreateOn desc ");
  61. IEnumerable<LargeScreenControlViewModel> recordItemlist = EntityFrameworkCoreExtensions.GetList<LargeScreenControlViewModel>(DbContext.Database, sql.ToString(), parameters);
  62. searchModel.TotalCount = recordItemlist.First() != null ? recordItemlist.ToList().Count : 0;
  63. if (recordItemlist.Count() == 1 && recordItemlist.First() == null)
  64. {
  65. recordItemlist = null;
  66. }
  67. return Task.FromResult(searchModel.IsPagination ? recordItemlist?.Skip((searchModel.PageIndex - 1) * searchModel.PageSize).Take(searchModel.PageSize) : recordItemlist);
  68. }
  69. }
  70. }