QueueAlarmConfigDal.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 QueueAlarmConfigDal
  10. {
  11. private IDatabase CurrDb = null;
  12. public QueueAlarmConfigDal(IDatabase db)
  13. {
  14. CurrDb = db;
  15. }
  16. public IEnumerable<QueueAlarmConfig> Get(int start, int length, string order, string sort, string filter, ref string errorinfo, out int total)
  17. {
  18. var pros = CurrDb.FindListForCondition<QueueAlarmConfig>($" {filter} order by {sort} {order} limit {start - 1},{length}", ref errorinfo);
  19. total = CurrDb.FindListForCondition<QueueAlarmConfig>(filter, ref errorinfo)
  20. .Count();
  21. return pros;
  22. }
  23. public QueueAlarmConfig Get(int id)
  24. {
  25. var pro = CurrDb.FindEntityFor<QueueAlarmConfig>(id);
  26. return pro;
  27. }
  28. public int Add(QueueAlarmConfig pro, string userCode, ref string errorinfo)
  29. {
  30. var entities = CurrDb.FindListForCondition<QueueAlarmConfig>($" and a.QueueName='{pro.QueueName}' ", ref errorinfo);
  31. if (entities != null && entities.Count() > 0)
  32. {
  33. errorinfo = "已存在该队列的报警阈值配置,请不要重复添加";
  34. return -1;
  35. }
  36. CurrDb.InsertFor(pro, userCode);
  37. var sql = "select @@identity;";
  38. var id = Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "-1");
  39. return id;
  40. }
  41. public int Update(QueueAlarmConfig role, string userCode, ref string errorinfo)
  42. {
  43. var entities = CurrDb.FindListForCondition<QueueAlarmConfig>($" and a.QueueName='{role.QueueName}' " +
  44. $"and a.ID<>{role.Id}", ref errorinfo);
  45. if (entities != null && entities.Count() > 0)
  46. {
  47. errorinfo = "已存在该队列的报警阈值配置";
  48. return -1;
  49. }
  50. role.ModTime = DateTime.Now;
  51. if (CurrDb.UpdateFor(role, userCode) < 0)
  52. {
  53. return -1;
  54. }
  55. return role.Id;
  56. }
  57. public int Delete(int id, ref string msg)
  58. {
  59. if (CurrDb.DeleteFor<QueueAlarmConfig>(id) < 0)
  60. {
  61. msg = "删除失败";
  62. return -1;
  63. }
  64. msg = string.Empty;
  65. return 1;
  66. }
  67. }
  68. }