Пример #1
0
        public void Execute(IJobExecutionContext context)
        {
            IConfig        c   = new IniConfigSource(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ConsoleJob.ini")).Configs["config"];
            DbNetDataProxy dbp = new DbNetDataProxy(c.Get("DbConnectionString"));
            DbNetData      db  = null;

            try
            {
                db = dbp.GetDb();
                db.BeginTransaction();

                QueryCommandConfig xsQry = new QueryCommandConfig("select org_guid from t_org_reginfo where org_type =3");
                DataTable          xsDt  = db.GetDataTable(xsQry);

                foreach (DataRow r in xsDt.Rows)
                {
                    QueryCommandConfig vegQry = new QueryCommandConfig("select vegname,amount from t_xs_wdat_kc where xs_guid = @xs_guid");
                    vegQry.Params["xs_guid"] = r["org_guid"];
                    DataTable vegDt = dbp.GetDataTable(vegQry);

                    if (vegDt.Rows.Count > 0)
                    {
                        var vegEnum = from veg in vegDt.AsEnumerable() orderby veg.Field <decimal>("amount") descending select veg.Field <string>("vegname");

                        UpdateCommandConfig xskcUpd = new UpdateCommandConfig("t_org_reginfo");
                        xskcUpd.FilterParams["org_guid"] = r["org_guid"];
                        xskcUpd.Params["business"]       = string.Join("|", vegEnum);
                        db.ExecuteUpdate(xskcUpd);
                    }
                }
                db.Commit();

                DC.DCLogger.LogTrace("Job successed [Job_GenerateXsBusiness]");
            }
            catch (Exception ex)
            {
                DC.DCLogger.LogError("Job failed [Job_GenerateXsBusiness]:{0}", ex);
            }
            finally
            {
                if (db.Transaction != null)
                {
                    db.Transaction.Dispose();
                }
                dbp.PutDb(db);
            }
        }
Пример #2
0
        public void Execute(IJobExecutionContext context)
        {
            IConfig        c   = new IniConfigSource(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ConsoleJob.ini")).Configs["config"];
            DbNetDataProxy dbp = new DbNetDataProxy(c.Get("DbConnectionString"));
            DbNetData      db  = null;

            try
            {
                db = dbp.GetDb();
                db.BeginTransaction();

                Dictionary <string, VegunitTrans> vtDic = new Dictionary <string, VegunitTrans>();
                QueryCommandConfig xskcQry = new QueryCommandConfig("select * from t_xs_wdat_kc");
                DataTable          xskcDt  = db.GetDataTable(xskcQry);

                foreach (DataRow r in xskcDt.Rows)
                {
                    string statSql = "SELECT vegname,date_format(recdate, '%Y-%m-%d') as date,round(max(totalprice/kilo),3) as max,round(min(totalprice/kilo),3) as min,round(avg(totalprice/kilo),3) as avg FROM t_xs_wdat_xsmx where recdate >= @startdate and recdate < @enddate and amount != kilo and vegname = @vegname and xs_guid in ({0}) group by vegname,date_format(recdate, '%Y-%m-%d')";

                    QueryCommandConfig statQry = new QueryCommandConfig(string.Format(statSql, "'" + r["xs_guid"] + "'"));
                    statQry.Params["startdate"] = DateTime.Now.Date.AddMonths(-6);
                    statQry.Params["enddate"]   = DateTime.Now.Date.AddDays(1);
                    statQry.Params["vegname"]   = r["vegname"];
                    DataTable statDt = dbp.GetDataTable(statQry);
                    if (statDt.Rows.Count > 0)
                    {
                        var result =
                            from statTbl in statDt.AsEnumerable()
                            orderby DateTime.Parse(statTbl.Field <string>("date")) descending
                                where DateTime.Parse(statTbl.Field <string>("date")) <= DateTime.Now.Date.AddDays(1)
                            select new ResponseData
                        {
                            max = statTbl.Field <decimal?>("max") ?? 0,
                            min = statTbl.Field <decimal?>("min") ?? 0,
                        };
                        decimal min = 0;
                        decimal max = 0;
                        foreach (ResponseData d in result)
                        {
                            if (d.max > 0 || d.min > 0)
                            {
                                min = d.min;
                                max = d.max;
                                break;
                            }
                        }
                        DataRow             statR   = statDt.Rows[0];
                        UpdateCommandConfig xskcUpd = new UpdateCommandConfig("t_xs_wdat_kc");
                        xskcUpd.FilterParams["xs_guid"] = r["xs_guid"];
                        xskcUpd.FilterParams["vegname"] = r["vegname"];
                        xskcUpd.Params["xs_price_min"]  = min;
                        xskcUpd.Params["xs_price_max"]  = max;
                        db.ExecuteUpdate(xskcUpd);
                    }
                }
                db.Commit();

                DC.DCLogger.LogTrace("Job successed [Job_CalXsgh]");
            }
            catch (Exception ex)
            {
                DC.DCLogger.LogError("Job failed [Job_CalXsgh]:{0}", ex);
            }
            finally
            {
                if (db.Transaction != null)
                {
                    db.Transaction.Dispose();
                }
                dbp.PutDb(db);
            }
        }