Beispiel #1
0
        public ActionResult GetDayStatisticsPage(string pagination, string sdate, string edate)
        {
            Pagination paginationobj      = pagination.ToObject <Pagination>();
            T_Statistics_day_report model = new T_Statistics_day_report();

            model.pageIndex  = paginationobj.page;
            model.pageSize   = paginationobj.rows;
            model.totalCount = paginationobj.total;
            if (!string.IsNullOrWhiteSpace(sdate))
            {
                model.startDate = sdate + " 00:00:00";
            }
            if (!string.IsNullOrWhiteSpace(edate))
            {
                model.endDate = edate + " 23:59:59";
            }

            List <T_Statistics_day_report> list = _onlie.GetDayStatisticsPage(model);
            var jsonData = new
            {
                rows    = list,
                total   = list.Count > 0 ? list[0].total : 0,
                page    = paginationobj.page,//list[0].pageIndex,
                records = list.Count > 0 ? list[0].totalCount : 0
            };

            return(Success(jsonData));
        }
        /// <summary>
        /// 获取时间段的数据
        /// </summary>
        /// <returns></returns>
        public List <T_Statistics_day_report> GetDayStatisticsPage(T_Statistics_day_report model)
        {
            using (IDbConnection conn = DapperAdapter.MySQLOpenConnection(ConfigurationHelper.MySQLConnectionStr))
            {
                DynamicParameters param = new DynamicParameters();
                StringBuilder     sb    = new StringBuilder();
                sb.Append("select * from t_statistics_day_report WHERE 1=1 ");
                if (!string.IsNullOrWhiteSpace(model.startDate))
                {
                    sb.Append(" and createTime >=@startDate ");
                    param.Add("@startDate", model.startDate);
                }
                if (!string.IsNullOrWhiteSpace(model.endDate))
                {
                    sb.Append(" and createTime<=@endDate ");
                    param.Add("@endDate", model.endDate);
                }
                sb.Append(" order by createTime desc");

                //获取总记录数
                string sqlCount = sb.ToString().Replace("select * ", "select count(1) totalCount ");

                //分页
                if (model.pageIndex >= 0 && model.pageSize > 0)
                {
                    sb.Append(" limit " + ((model.pageIndex - 1) * model.pageSize) + "," + model.pageSize);
                }
                //分页记录列表
                var list = conn.Query <T_Statistics_day_report>(sb.ToString(), param).ToList();
                if (list != null && list.Count() > 0)
                {
                    //总记录数列表
                    dynamic identity = conn.Query(sqlCount, param).Single();
                    list[0].totalCount = Convert.ToInt64(identity.totalCount);
                    list[0].pageIndex  = model.pageIndex;
                    list[0].pageSize   = model.pageSize;
                }
                return(list);
            }
        }