TsysMessageRepository.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using Ropin.Inspection.Model;
  2. using Ropin.Inspection.Model.Common;
  3. using Ropin.Inspection.Model.Entities;
  4. using Ropin.Inspection.Model.SearchModel.MTN;
  5. using Ropin.Inspection.Model.ViewModel.MTN;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace Ropin.Inspection.Repository
  12. {
  13. public class TsysMessageRepository : RepositoryBase<TSYS_Message, string>, ITsysMessageRepository
  14. {
  15. public TsysMessageRepository(InspectionDbContext dbContext) : base(dbContext)
  16. {
  17. }
  18. public Task<bool> UpdateMsgStatus(string id,int? msgStatus)
  19. {
  20. MySqlConnector.MySqlParameter[] parameters = new[] {
  21. new MySqlConnector.MySqlParameter("code", id),
  22. new MySqlConnector.MySqlParameter("msgStatus", msgStatus)
  23. };
  24. string sql = $" UPDATE TSYS_Message SET I_MsgStatus = @msgStatus WHERE (C_ID =@code); ";
  25. int iResult = EntityFrameworkCoreExtensions.ExecuteSqlNoQuery(DbContext.Database, sql, parameters);
  26. bool result = iResult > 0;
  27. return Task.FromResult(result);
  28. }
  29. public Task<IEnumerable<TsysMessageViewModel>> GetList(TsysMessageSearchModel searchModel)
  30. {
  31. MySqlConnector.MySqlParameter[] parameters = new[] {
  32. new MySqlConnector.MySqlParameter("Status", searchModel.C_Status),
  33. new MySqlConnector.MySqlParameter("id", searchModel.C_ID),
  34. new MySqlConnector.MySqlParameter("generationType", searchModel.I_GenerationType),
  35. new MySqlConnector.MySqlParameter("msgTypeCode", searchModel.C_MsgTypeCode),
  36. new MySqlConnector.MySqlParameter("pushMsgToCode", searchModel.C_PushMsgToCode),
  37. new MySqlConnector.MySqlParameter("storeCode", searchModel.C_StoreCode),
  38. new MySqlConnector.MySqlParameter("devCode", searchModel.C_DevCode),
  39. new MySqlConnector.MySqlParameter("content", "%"+searchModel.C_Content+"%"),
  40. new MySqlConnector.MySqlParameter("beginTme", searchModel.BeginTime?.ToString("yyyy-MM-dd")),
  41. new MySqlConnector.MySqlParameter("endTime ", searchModel.EndTime?.ToString("yyyy-MM-dd"))
  42. };
  43. StringBuilder sql = new StringBuilder();
  44. StringBuilder pushMsgSql= new StringBuilder();
  45. if (!string.IsNullOrEmpty(searchModel.C_PushMsgToCode))
  46. {
  47. pushMsgSql.Append(" and C_PushMsgToCode=@pushMsgToCode ");
  48. }
  49. sql.Append(@"
  50. select * from (
  51. select m.*,d.C_StoreCode,d.C_Name as C_DevName,d.C_Url,d.C_StaticUrl,c.C_Name as C_MsgTypeName,ifnull(f.cut4,0) as IsVideo
  52. from TSYS_Message m
  53. LEFT JOIN TDEV_DevStore d on (m.C_DevStoreCode=d.C_ID)
  54. LEFT JOIN TBDM_CodeDetail c on (m.C_MsgTypeCode=c.C_Code)
  55. LEFT JOIN ( select C_MessageCode,count(CASE WHEN C_Type='FILE_TYP_001' THEN 1 END) as cut1,
  56. count(CASE WHEN C_Type='FILE_TYP_002' THEN 1 END) as cut2,count(CASE WHEN C_Type='FILE_TYP_003' THEN 1 END) as cut3,
  57. count(CASE WHEN C_Type='FILE_TYP_004' THEN 1 END) as cut4,count(CASE WHEN C_Type='FILE_TYP_005' THEN 1 END) as cut5,
  58. count(CASE WHEN C_Type='FILE_TYP_006' THEN 1 END) as cut6
  59. from TSYS_MessageFile group by C_MessageCode) f on (m.C_ID=f.C_MessageCode)
  60. ) tab ");
  61. if (!string.IsNullOrEmpty(searchModel.C_Status))
  62. {
  63. sql.Append(" where C_Status=@Status ");
  64. }
  65. else
  66. {
  67. sql.Append(" where C_Status!='0' ");
  68. }
  69. if (!string.IsNullOrEmpty(searchModel.C_ID))
  70. {
  71. sql.Append(" and C_ID=@id ");
  72. }
  73. if (searchModel.I_GenerationType!=null)
  74. {
  75. sql.Append(" and I_GenerationType=@generationType ");
  76. }
  77. if (searchModel.MsgStatus != null&& searchModel.MsgStatus.Count>0)
  78. {
  79. string msgStatus=string.Join(", ", searchModel.MsgStatus);
  80. sql.Append($" and I_MsgStatus in ({msgStatus})");
  81. }
  82. if (!string.IsNullOrEmpty(searchModel.C_MsgTypeCode))
  83. {
  84. sql.Append(" and C_MsgTypeCode=@msgTypeCode ");
  85. }
  86. if (searchModel.MsgTypeList != null && searchModel.MsgTypeList.Count > 0)
  87. {
  88. StringBuilder contsql = new StringBuilder();
  89. sql.Append($" and C_MsgTypeCode in ('{String.Join("','", searchModel.MsgTypeList)}') ");
  90. }
  91. if (!string.IsNullOrEmpty(searchModel.C_StoreCode))
  92. {
  93. sql.Append(" and C_StoreCode=@storeCode ");
  94. }
  95. if (!string.IsNullOrEmpty(searchModel.C_DevCode))
  96. {
  97. sql.Append(" and C_DevStoreCode=@devCode ");
  98. }
  99. if (!string.IsNullOrEmpty(searchModel.C_Content))
  100. {
  101. sql.Append(" and C_Content like @content ");
  102. }
  103. if (searchModel.BeginTime != null && searchModel.BeginTime != DateTime.MinValue)
  104. {
  105. sql.Append(" and DATE_FORMAT(D_MsgCreateOn, '%Y-%m-%d')>=@beginTme ");
  106. }
  107. if (searchModel.EndTime != null && searchModel.EndTime != DateTime.MinValue)
  108. {
  109. sql.Append(" and DATE_FORMAT(D_MsgCreateOn, '%Y-%m-%d')<=@endTime ");
  110. }
  111. if (pushMsgSql.Length>0)
  112. {
  113. sql.Append($" and C_ID in (select C_MessageCode from TMTN_PushMsgResult where C_Status='1' {pushMsgSql.ToString()} group by C_MessageCode) ");
  114. }
  115. sql.Append(" order by D_MsgCreateOn desc ");
  116. IEnumerable<TsysMessageViewModel> recordItemlist = EntityFrameworkCoreExtensions.GetList<TsysMessageViewModel>(DbContext.Database, sql.ToString(), parameters);
  117. searchModel.TotalCount = recordItemlist.First() != null ? recordItemlist.ToList().Count : 0;
  118. if (searchModel.TotalCount == 0)
  119. {
  120. recordItemlist = new List<TsysMessageViewModel>();
  121. }
  122. return Task.FromResult(searchModel.IsPagination ? recordItemlist.Skip((searchModel.PageIndex - 1) * searchModel.PageSize).Take(searchModel.PageSize) : recordItemlist);
  123. }
  124. }
  125. }