123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- using Applications.FDC;
- using Edge.Core.Database;
- using Edge.Core.Processor;
- using Edge.Core.IndustryStandardInterface.Pump;
- using Microsoft.Extensions.Logging;
- using MySql.Data.MySqlClient;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Threading.Tasks;
- using Wayne.FDCPOSLibrary;
- using Edge.Core.Processor.Dispatcher.Attributes;
- using System.Threading;
- namespace Applications.PumpInfoToSinoChemPosSqlServerOrMySql
- {
- [MetaPartsDescriptor(
- "lang-zh-cn:加油机信息转发代理 MySQLlang-en-us:Pump Info Agent to MySQL",
- "lang-zh-cn:用于将加油机的状态和交易数据插入至 MySQL 目标数据库中" +
- "lang-en-us:Used for proxing pump state and trx to target MY SQL database",
- new[] { "lang-zh-cn:中化lang-en-us:SinoChem" })]
- public class AppMySql : AppBase, IAppProcessor
- {
- public string MetaConfigName { get; set; }
- /// <summary>
- ///
- /// </summary>
- /// <param name="appConfig"></param>
- /// <param name="services"></param>
- [ParamsJsonSchemas("appCtorParamsJsonSchema")]
- public AppMySql(AppConfigV1 appConfig, IServiceProvider services) : base(appConfig, services)
- {
- }
- public void Init(IEnumerable<IProcessor> processors)
- {
- base.fdcServerHostApp = processors.OfType<FdcServerHostApp>().First();
- base.HandlePumpStateChangeToDatabase(
- () => new MySqlConnection(base.appConfig.DatabaseConnStr),
- () => new MySqlCommand());
- }
- protected override string InitTable_jy_info_SqlCommand(string siteLevelNozzleId, string gradeFriendlyName,
- double totalizerVol, double totalizerAmt)
- {
- return "call insert_jy_info_by_jihao('" + siteLevelNozzleId + "','F','" + gradeFriendlyName + "',0,0," + totalizerVol + "," + totalizerAmt + "); ";
- }
- public Task<bool> Start()
- {
- //using (var posSqlConnection = new MySqlConnection(this.databaseConnStr))
- //{
- // try
- // {
- // var createMySqlProcedureCmd = new MySqlCommand();
- // //createMySqlProcedureCmd.CommandType = CommandType.StoredProcedure;
- // createMySqlProcedureCmd.Connection = posSqlConnection;
- // createMySqlProcedureCmd.CommandText = "drop procedure if exists insert_jy_info_by_jihao;" +
- // " create procedure insert_jy_info_by_jihao(" +
- // "IN input_jihao varchar(10)," +
- // "IN input_status varchar(10)," +
- // "IN input_youpin varchar(12)," +
- // "IN input_qty float," +
- // "IN input_amount float," +
- // "IN input_fzqty float," +
- // "IN input_fzamount float)" +
- // " BEGIN IF NOT EXISTS(select* from jy_info where jihao = input_jihao) THEN " +
- // " insert into jy_info(jihao, status, youpin, qty, amount, fzqty, fzamount) " +
- // " values(input_jihao, input_status, input_youpin, input_qty, input_amount, input_fzqty, input_fzamount);" +
- // " END IF;" //+
- // //"\n"
- // //"end $$; "
- // ;
- // posSqlConnection.Open();
- // createMySqlProcedureCmd.ExecuteNonQuery();
- // }
- // catch (Exception ex)
- // {
- // logger.LogError("creating MySql procedure: 'insert_jy_info_by_jihao' failed, exception detail: " + ex);
- // return false;
- // }
- //}
- return Task.FromResult(
- base.ReCreatePumpLayoutToDatabase(
- () => new MySqlConnection(base.appConfig.DatabaseConnStr),
- () => new MySqlCommand()));
- }
- public Task<bool> Stop()
- {
- return Task.FromResult(true);
- }
- }
- }
|