MachineInfoChangeLogDal.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using Cksoft.Data;
  2. using Cksoft.Data.Repository;
  3. using DllEapEntity;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace DllEapDal.OFILM
  10. {
  11. public class MachineInfoChangeLogDal
  12. {
  13. private IDatabase CurrDb = null;
  14. public MachineInfoChangeLogDal()
  15. {
  16. }
  17. public MachineInfoChangeLogDal(IDatabase db)
  18. {
  19. CurrDb = db;
  20. }
  21. /// <summary>
  22. /// 获取最后一次修改机台信息的记录
  23. /// </summary>
  24. /// <param name="macCode"></param>
  25. /// <returns></returns>
  26. public async Task<MachineInfoChangeLog> GetLastModifyRecord(string macCode)
  27. {
  28. string errorinfo = string.Empty;
  29. var log = await CurrDb.FindListForConditionAsync<MachineInfoChangeLog>($" and a.maccode='{macCode}' " +
  30. $"order by id desc limit 0,1",
  31. ref errorinfo);
  32. return log.FirstOrDefault();
  33. }
  34. /// <summary>
  35. /// 新增修改记录
  36. /// </summary>
  37. /// <param name="macCode"></param>
  38. /// <param name="userCode"></param>
  39. /// <param name="operation"></param>
  40. /// <param name="content"></param>
  41. /// <returns></returns>
  42. public async Task<bool> InsertLog(string macCode, string userCode, string operation,
  43. string content)
  44. {
  45. string errorinfo = string.Empty;
  46. var log = new MachineInfoChangeLog
  47. {
  48. MacCode = macCode,
  49. Operation = operation,
  50. OperatonContent = content,
  51. RecCode = userCode,
  52. RecTime = DateTime.Now
  53. };
  54. using (IDatabase db = DbFactory.Base("eap"))
  55. {
  56. db.InsertFor(log, userCode);
  57. }
  58. return await Task.FromResult(true);
  59. }
  60. /// <summary>
  61. /// 批量新增机台信息修改日志
  62. /// </summary>
  63. /// <param name="macCodes"></param>
  64. /// <param name="userCode"></param>
  65. /// <param name="operation"></param>
  66. /// <param name="content"></param>
  67. /// <returns></returns>
  68. public async Task<bool> InsertLog(IEnumerable<string> macCodes, string userCode, string operation,
  69. string content)
  70. {
  71. var list = new List<MachineInfoChangeLog>();
  72. foreach (var item in macCodes)
  73. {
  74. list.Add(new MachineInfoChangeLog
  75. {
  76. MacCode = item,
  77. Operation = operation,
  78. OperatonContent = content,
  79. RecCode = userCode,
  80. RecTime = DateTime.Now
  81. });
  82. }
  83. using(IDatabase db = DbFactory.Base("eap"))
  84. {
  85. db.Insert<MachineInfoChangeLog>(list);
  86. }
  87. return await Task.FromResult(true);
  88. }
  89. }
  90. }