You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.3 KiB

  1. using Dapper;
  2. using Npgsql;
  3. using Shentun.Peis.Asbitems;
  4. using Shentun.Peis.Enums;
  5. using Shentun.Peis.PlugIns.ChargeRequests;
  6. using Shentun.Peis.PlugIns.LisRequests;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Data.Common;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace Shentun.Peis.PlugIns.SyncAsbitemPrice
  14. {
  15. public class SyncAsbitemPricePlugInsBase : ThirdPlugInsBase
  16. {
  17. public SyncAsbitemPricePlugInsBase(Guid thirdInterfaceId) : base(thirdInterfaceId)
  18. {
  19. }
  20. public virtual async Task SyncAsbitemPriceAsync()
  21. {
  22. }
  23. public async Task<List<AsbitemForSyncAsbitem>> GetAsbitemsAsync()
  24. {
  25. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  26. {
  27. string sql;
  28. sql = @" select * from asbitem
  29. ";
  30. var asbitems = (await conn.QueryAsync<AsbitemForSyncAsbitem>(sql
  31. )).ToList();
  32. return asbitems;
  33. }
  34. }
  35. public async Task UpdateAsbitemPriceAsync(AsbitemForSyncAsbitem asbitem)
  36. {
  37. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  38. {
  39. await conn.OpenAsync();
  40. using (var trans = await conn.BeginTransactionAsync())
  41. {
  42. try
  43. {
  44. string sql;
  45. sql = @" update asbitem set price = @Price" +
  46. @" where id = @AsbitemId and concurrency_stamp = @ConcurrencyStamp
  47. ";
  48. await conn.ExecuteAsync(sql,
  49. new
  50. {
  51. asbitem.Price,
  52. asbitem.Id,
  53. asbitem.ConcurrencyStamp
  54. }, trans);
  55. await trans.CommitAsync();
  56. }
  57. catch (Exception ex)
  58. {
  59. await trans.RollbackAsync();
  60. throw ex;
  61. }
  62. }
  63. }
  64. }
  65. public override Task DoWork()
  66. {
  67. SyncAsbitemPriceAsync().Wait();
  68. return Task.CompletedTask;
  69. }
  70. }
  71. }