| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 | using Dfs.WayneChina.SinochemEps;using SinoChemCommonUtilities;using System;using System.Collections.Generic;using System.Data.SqlClient;using System.Linq;using System.Text;using System.Threading.Tasks;using Wayne.Lib.Log;namespace SinochemInternetPlusApp{    class EpsTransactionQuery    {        private static SqlCommandUtility sqlCmd = new SqlCommandUtility(SinochemEpsApp.PosDatabaseConnString);                                        public static List<EpsTransactionModel> GetAllEpsTrxModels()        {            string querySql = string.Format(" select * from eps_trx ");            return sqlCmd.ReadData<List<EpsTransactionModel>>(querySql, DbModelConstructors.ConstructEpsTrxModelList);                 }                                                              public static List<EpsTransactionModel> GetAllEpsTrxModelsOf(int nozzleId)        {            string querySql = string.Format(" select * from eps_trx where jihao={0} ", nozzleId);            return sqlCmd.ReadData<List<EpsTransactionModel>>(querySql, DbModelConstructors.ConstructEpsTrxModelList);        }                                                public static List<EpsTransactionModel> GetValidCarPlateEpsTrxModels(List<int> nozzles, int topCount, DebugLogger debugLogger)        {            const int TrxInProgressCategory = 1;            const int TrxAlreadyDoneCategory = 2;            List<EpsTransactionModel> epxTrxList = GetCarPlateEpsTrxModelsByTrxStatusCategory(nozzles, -1, TrxInProgressCategory, debugLogger);            List<EpsTransactionModel> alreadyDoneTrxList = GetCarPlateEpsTrxModelsByTrxStatusCategory(nozzles, topCount, TrxAlreadyDoneCategory, debugLogger);            epxTrxList.AddRange(alreadyDoneTrxList);            return epxTrxList;        }                                private static List<EpsTransactionModel> GetCarPlateEpsTrxModelsByTrxStatusCategory        (            List<int> nozzles,             int topCount,             int trxStatusCategory,             DebugLogger debugLogger        )        {            StringBuilder sb = new StringBuilder();                        if (topCount >= 0)            {                sb.Append(string.Format(" select top {0} * from eps_trx where", topCount));            }            else            {                sb.Append(" select * from eps_trx where");            }                        sb.Append(" (");            for (int i = 0; i < nozzles.Count; i++)            {                if (i != nozzles.Count - 1)                    sb.Append($"jihao = {nozzles[i]} or ");                else                    sb.Append($"jihao = {nozzles[i]}");            }            sb.Append(")");                        sb.Append(" and " + ConvertTrxStatusCategoryToSql(trxStatusCategory));                                sb.Append($" and mop = {(int)TransactionMode.CarPlateMode}");                        sb.Append(" order by created_time desc");            debugLogger.Add(sb);            return sqlCmd.ReadData<List<EpsTransactionModel>>(sb.ToString(), DbModelConstructors.ConstructEpsTrxModelList);        }                                                        private static string ConvertTrxStatusCategoryToSql(int trxStatusCategory)        {            string sqlWhere = "";            switch (trxStatusCategory)            {                case 1:                    sqlWhere = string.Format                        ($"(trx_status = {(int)EpsTrxStatus.BeforeFueling} " +                        $"or trx_status = {(int)EpsTrxStatus.Fueling} " +                        $"or trx_status = {(int)EpsTrxStatus.FuelingDone} " +                        $"or trx_status = {(int)EpsTrxStatus.BeforePayment})");                    break;                case 2:                    sqlWhere = string.Format                        ($"(trx_status = {(int)EpsTrxStatus.PaymentOk} " +                        $"or trx_status = {(int)EpsTrxStatus.PaymentNeedConfirm} " +                        $"or trx_status = {(int)EpsTrxStatus.PaymentFailed} " +                        $"or trx_status = {(int)EpsTrxStatus.PaymentOkButNeedRefund} " +                        $"or trx_status = {(int)EpsTrxStatus.PaymentRefunded})");                    break;                default:                    break;            }            return sqlWhere;        }                                        public static List<EpsTransaction> GetEpsTrxesByTrxStatusAndCreatedTime(EpsTrxStatus trxStatus, DateTime createdTimeStart, bool ignoreCreatedTimeStart)        {            string querySql = "";            if (ignoreCreatedTimeStart)            {                querySql = string.Format(" select * from eps_trx where trx_status = {0}",                    (int)trxStatus);            }            else            {                querySql = string.Format(" select * from eps_trx where trx_status = {0} and created_time >= '{1}'",                    (int)trxStatus, createdTimeStart.ToString("yyyy-MM-dd HH:mm:ss"));            }            return sqlCmd.ReadData<List<EpsTransaction>>(querySql, DbModelConstructors.ConstructEpsTrxList);        }                                        public static List<EpsTransaction> GetEpsTrxesByNotifyPosFlagAndCreatedTime(NotifyPosFlag notifyPos, DateTime createdTimeStart)        {            string querySql = string.Format(" select * from eps_trx where notify_pos = {0} and created_time >= '{1}'",                (int)notifyPos, createdTimeStart.ToString("yyyy-MM-dd HH:mm:ss"));            return sqlCmd.ReadData<List<EpsTransaction>>(querySql, DbModelConstructors.ConstructEpsTrxList);        }                                        public static void DeleteEpsTrxesBefore(DateTime createdTimeStop)        {            StringBuilder deleteSqlSb = new StringBuilder();            deleteSqlSb.AppendFormat(" delete from eps_trx where created_time < '{0}'", createdTimeStop.ToString("yyyy-MM-dd HH:mm:ss"));            deleteSqlSb.Append(" and (");            deleteSqlSb.AppendFormat("trx_status={0}", (int)EpsTrxStatus.Removed);            deleteSqlSb.AppendFormat(" or trx_status={0}", (int)EpsTrxStatus.PaymentRefunded);            deleteSqlSb.AppendFormat(" or trx_status={0}", (int)EpsTrxStatus.PaymentFailed);            deleteSqlSb.AppendFormat(" or (trx_status={0} and notify_pos={1})", (int)EpsTrxStatus.PaymentOk, (int)NotifyPosFlag.NotifyOk);            deleteSqlSb.Append(")");            sqlCmd.DeleteData(deleteSqlSb.ToString());        }            }}
 |