LargeScreenEventRepository.cs 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 LargeScreenEventRepository : RepositoryBase<TLGS_LargeScreenEvent, string>, ILargeScreenEventRepository
  13. {
  14. public LargeScreenEventRepository(InspectionDbContext dbContext) : base(dbContext)
  15. {
  16. }
  17. public Task<IEnumerable<LargeScreenEventViewModel>> GetConditionAsync(LargeScreenEventSearch searchModel)
  18. {
  19. MySqlConnector.MySqlParameter[] parameters = new[] {
  20. new MySqlConnector.MySqlParameter("Status", searchModel?.C_Status),
  21. new MySqlConnector.MySqlParameter("name", "%"+searchModel?.C_Name+"%"),
  22. new MySqlConnector.MySqlParameter("ControlCode", searchModel?.C_ControlCode),
  23. new MySqlConnector.MySqlParameter("devStoreCode", searchModel?.C_DevStoreCode),
  24. new MySqlConnector.MySqlParameter("boxCode", searchModel?.C_BoxCode),
  25. new MySqlConnector.MySqlParameter("type ", searchModel?.C_Type),
  26. new MySqlConnector.MySqlParameter("Id ", searchModel?.C_ID)
  27. };
  28. StringBuilder sql = new StringBuilder();
  29. sql.Append(@"select * from (
  30. select t.*,c.C_ControlName,s.C_Name as C_DevStoreName,b.C_Name as C_BoxName,d.C_Name as C_TypeName
  31. from TLGS_LargeScreenEvent t
  32. LEFT JOIN TLGS_LargeScreenControl c on (t.C_ControlCode=c.C_ID)
  33. LEFT JOIN TDEV_DevStore s on (t.C_DevStoreCode=s.C_ID)
  34. LEFT JOIN TDEV_Box b on (t.C_BoxCode=b.C_ID)
  35. LEFT JOIN TBDM_CodeDetail d on (t.C_Type=d.C_Code)
  36. ) tab where 1=1");
  37. if (!string.IsNullOrEmpty(searchModel.C_Status))
  38. {
  39. sql.Append(" and C_Status=@Status ");
  40. }
  41. if (!string.IsNullOrEmpty(searchModel.C_Name))
  42. {
  43. sql.Append(" and C_Name like @name");
  44. }
  45. if (!string.IsNullOrEmpty(searchModel.C_ControlCode))
  46. {
  47. sql.Append(" and C_ControlCode=@ControlCode ");
  48. }
  49. if (!string.IsNullOrEmpty(searchModel.C_DevStoreCode))
  50. {
  51. sql.Append(" and C_DevStoreCode=@devStoreCode ");
  52. }
  53. if (!string.IsNullOrEmpty(searchModel.C_BoxCode))
  54. {
  55. sql.Append(" and C_BoxCode=@boxCode ");
  56. }
  57. if (!string.IsNullOrEmpty(searchModel.C_Type))
  58. {
  59. sql.Append(" and C_Type=@type ");
  60. }
  61. if (!string.IsNullOrEmpty(searchModel.C_ID))
  62. {
  63. sql.Append(" and C_ID=@Id ");
  64. }
  65. sql.Append(" order by D_CreateOn desc ");
  66. IEnumerable<LargeScreenEventViewModel> recordItemlist = EntityFrameworkCoreExtensions.GetList<LargeScreenEventViewModel>(DbContext.Database, sql.ToString(), parameters);
  67. searchModel.TotalCount = recordItemlist.First() != null ? recordItemlist.ToList().Count : 0;
  68. if (recordItemlist.Count() == 1 && recordItemlist.First() == null)
  69. {
  70. recordItemlist = null;
  71. }
  72. return Task.FromResult(searchModel.IsPagination ? recordItemlist?.Skip((searchModel.PageIndex - 1) * searchModel.PageSize).Take(searchModel.PageSize) : recordItemlist);
  73. }
  74. public Task<bool> UpdateLargeScreenEventStatusBYId(string Id,string satus)
  75. {
  76. MySqlConnector.MySqlParameter[] parameters = new[] {
  77. new MySqlConnector.MySqlParameter("satus", satus),
  78. new MySqlConnector.MySqlParameter("id", Id)
  79. };
  80. string sql = "UPDATE TLGS_LargeScreenEvent SET C_Status = @satus WHERE (C_ID =@id); ";
  81. int iResult = EntityFrameworkCoreExtensions.ExecuteSqlNoQuery(DbContext.Database, sql, parameters);
  82. return Task.FromResult(true);
  83. }
  84. }
  85. }