AppMySql.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using Applications.FDC;
  2. using Edge.Core.Database;
  3. using Edge.Core.Processor;
  4. using Edge.Core.IndustryStandardInterface.Pump;
  5. using Microsoft.Extensions.Logging;
  6. using MySql.Data.MySqlClient;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Data;
  10. using System.Linq;
  11. using System.Threading.Tasks;
  12. using Wayne.FDCPOSLibrary;
  13. using Edge.Core.Processor.Dispatcher.Attributes;
  14. using System.Threading;
  15. namespace Applications.PumpInfoToSinoChemPosSqlServerOrMySql
  16. {
  17. [MetaPartsDescriptor(
  18. "lang-zh-cn:加油机信息转发代理 MySQLlang-en-us:Pump Info Agent to MySQL",
  19. "lang-zh-cn:用于将加油机的状态和交易数据插入至 MySQL 目标数据库中" +
  20. "lang-en-us:Used for proxing pump state and trx to target MY SQL database",
  21. new[] { "lang-zh-cn:中化lang-en-us:SinoChem" })]
  22. public class AppMySql : AppBase, IAppProcessor
  23. {
  24. public string MetaConfigName { get; set; }
  25. /// <summary>
  26. ///
  27. /// </summary>
  28. /// <param name="appConfig"></param>
  29. /// <param name="services"></param>
  30. [ParamsJsonSchemas("appCtorParamsJsonSchema")]
  31. public AppMySql(AppConfigV1 appConfig, IServiceProvider services) : base(appConfig, services)
  32. {
  33. }
  34. public void Init(IEnumerable<IProcessor> processors)
  35. {
  36. base.fdcServerHostApp = processors.OfType<FdcServerHostApp>().First();
  37. base.HandlePumpStateChangeToDatabase(
  38. () => new MySqlConnection(base.appConfig.DatabaseConnStr),
  39. () => new MySqlCommand());
  40. }
  41. protected override string InitTable_jy_info_SqlCommand(string siteLevelNozzleId, string gradeFriendlyName,
  42. double totalizerVol, double totalizerAmt)
  43. {
  44. return "call insert_jy_info_by_jihao('" + siteLevelNozzleId + "','F','" + gradeFriendlyName + "',0,0," + totalizerVol + "," + totalizerAmt + "); ";
  45. }
  46. public Task<bool> Start()
  47. {
  48. //using (var posSqlConnection = new MySqlConnection(this.databaseConnStr))
  49. //{
  50. // try
  51. // {
  52. // var createMySqlProcedureCmd = new MySqlCommand();
  53. // //createMySqlProcedureCmd.CommandType = CommandType.StoredProcedure;
  54. // createMySqlProcedureCmd.Connection = posSqlConnection;
  55. // createMySqlProcedureCmd.CommandText = "drop procedure if exists insert_jy_info_by_jihao;" +
  56. // " create procedure insert_jy_info_by_jihao(" +
  57. // "IN input_jihao varchar(10)," +
  58. // "IN input_status varchar(10)," +
  59. // "IN input_youpin varchar(12)," +
  60. // "IN input_qty float," +
  61. // "IN input_amount float," +
  62. // "IN input_fzqty float," +
  63. // "IN input_fzamount float)" +
  64. // " BEGIN IF NOT EXISTS(select* from jy_info where jihao = input_jihao) THEN " +
  65. // " insert into jy_info(jihao, status, youpin, qty, amount, fzqty, fzamount) " +
  66. // " values(input_jihao, input_status, input_youpin, input_qty, input_amount, input_fzqty, input_fzamount);" +
  67. // " END IF;" //+
  68. // //"\n"
  69. // //"end $$; "
  70. // ;
  71. // posSqlConnection.Open();
  72. // createMySqlProcedureCmd.ExecuteNonQuery();
  73. // }
  74. // catch (Exception ex)
  75. // {
  76. // logger.LogError("creating MySql procedure: 'insert_jy_info_by_jihao' failed, exception detail: " + ex);
  77. // return false;
  78. // }
  79. //}
  80. return Task.FromResult(
  81. base.ReCreatePumpLayoutToDatabase(
  82. () => new MySqlConnection(base.appConfig.DatabaseConnStr),
  83. () => new MySqlCommand()));
  84. }
  85. public Task<bool> Stop()
  86. {
  87. return Task.FromResult(true);
  88. }
  89. }
  90. }