NoticeConfigDal.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. using Cksoft.Data;
  2. using DllEapEntity;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. namespace DllEapDal.OFILM
  8. {
  9. public class NoticeConfigDal
  10. {
  11. private IDatabase CurrDb = null;
  12. public NoticeConfigDal(IDatabase db)
  13. {
  14. CurrDb = db;
  15. }
  16. public IEnumerable<NoticeConfig> Get(int start, int length, string order, string sort, string filter, string errorinfo)
  17. {
  18. var pros = CurrDb.FindListForCondition<NoticeConfig>($" {filter} order by {sort} {order} limit {start - 1},{length}", ref errorinfo);
  19. if (pros != null && pros.Count() > 0)
  20. {
  21. foreach (var item in pros)
  22. {
  23. item.NoticeConfigDetails = CurrDb.FindListForCondition<NoticeConfigDetail>($" and a.MstId={item.Id}", ref errorinfo);
  24. item.PushNames = string.Join("|", item.NoticeConfigDetails.Select(c => c.FName));
  25. }
  26. }
  27. return pros;
  28. }
  29. public int GetCount(string filter)
  30. {
  31. string errorinfo = string.Empty;
  32. var entities = CurrDb.FindListForCondition<NoticeConfig>(filter, ref errorinfo);
  33. if (entities != null)
  34. {
  35. return entities.Count();
  36. }
  37. return 0;
  38. }
  39. public NoticeConfig Get(int id)
  40. {
  41. var pro = CurrDb.FindEntityFor<NoticeConfig>(id);
  42. string errorinfo = string.Empty;
  43. if (pro != null)
  44. {
  45. pro.NoticeConfigDetails = CurrDb.FindListForCondition<NoticeConfigDetail>($" and a.MstId={pro.Id}", ref errorinfo);
  46. }
  47. return pro;
  48. }
  49. public NoticeConfig GetByFactory(int factoryId)
  50. {
  51. string errorinfo = string.Empty;
  52. var pro = CurrDb.FindListForCondition<NoticeConfig>($" and a.factoryId={factoryId} and a.isUse=1", ref errorinfo).FirstOrDefault();
  53. if (pro != null)
  54. {
  55. pro.NoticeConfigDetails = CurrDb.FindListForCondition<NoticeConfigDetail>($" and a.MstId={pro.Id}", ref errorinfo);
  56. }
  57. return pro;
  58. }
  59. public int Add(NoticeConfig pro, string userCode, ref string errorinfo)
  60. {
  61. var entities = CurrDb.FindListForCondition<NoticeConfig>($" and a.factoryId='{pro.FactoryId}' ", ref errorinfo);
  62. if (entities != null && entities.Count() > 0)
  63. {
  64. errorinfo = "已存在该园区的蓝信推送人员配置,请不要重复添加";
  65. return -1;
  66. }
  67. pro.IsUse = 1;
  68. CurrDb.InsertFor(pro, userCode);
  69. var sql = "select @@identity;";
  70. var id = Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "-1");
  71. if (pro.NoticeConfigDetails != null && pro.NoticeConfigDetails.Count() > 0)
  72. {
  73. var details = new List<NoticeConfigDetail>();
  74. foreach (var item in pro.NoticeConfigDetails)
  75. {
  76. details.Add(new NoticeConfigDetail
  77. {
  78. MstId = id,
  79. RecCode = userCode,
  80. ModCode = userCode,
  81. StaffId = item.StaffId
  82. });
  83. }
  84. if (CurrDb.InsertFor<NoticeConfigDetail>(details, string.Empty) < 0)
  85. {
  86. errorinfo = "新增人员配置信息失败";
  87. return -1;
  88. }
  89. }
  90. return id;
  91. }
  92. public int Update(NoticeConfig role, string userCode, ref string errorinfo)
  93. {
  94. var entities = CurrDb.FindListForCondition<NoticeConfig>($" and a.FactoryId='{role.FactoryId}' " +
  95. $"and a.ID<>{role.Id}", ref errorinfo);
  96. if (entities != null && entities.Count() > 0)
  97. {
  98. errorinfo = "已存在该园区的蓝信推送人员配置,请不要重复添加";
  99. return -1;
  100. }
  101. var sql = $"delete from noticeconfigdetail where mstid={role.Id}";
  102. if (CurrDb.ExecuteBySql(sql) < 0)
  103. {
  104. errorinfo = "删除原人员信息失败";
  105. return -1;
  106. }
  107. if (role.NoticeConfigDetails != null && role.NoticeConfigDetails.Count() > 0)
  108. {
  109. var details = new List<NoticeConfigDetail>();
  110. foreach (var item in role.NoticeConfigDetails)
  111. {
  112. details.Add(new NoticeConfigDetail
  113. {
  114. MstId = role.Id,
  115. StaffId = item.StaffId
  116. });
  117. }
  118. if (CurrDb.InsertFor<NoticeConfigDetail>(details, string.Empty) < 0)
  119. {
  120. errorinfo = "修改人员配置信息失败";
  121. return -1;
  122. }
  123. }
  124. role.ModTime = DateTime.Now;
  125. if (CurrDb.UpdateFor(role, userCode) < 0)
  126. {
  127. return -1;
  128. }
  129. return role.Id;
  130. }
  131. public int Delete(int id, ref string msg)
  132. {
  133. if (CurrDb.DeleteFor<NoticeConfig>(id) < 0)
  134. {
  135. msg = "删除失败";
  136. return -1;
  137. }
  138. msg = string.Empty;
  139. return 1;
  140. }
  141. public int ChangeIsUse(NoticeConfig noticeConfig, ref string errorinfo)
  142. {
  143. var sql = $"update NoticeConfig set isUse={noticeConfig.IsUse} " +
  144. $"where id={noticeConfig.Id}";
  145. if (CurrDb.ExecuteBySql(sql) < 0)
  146. {
  147. errorinfo = "修改失败";
  148. return -1;
  149. }
  150. return 1;
  151. }
  152. }
  153. }