【修复】修复mysql下报表统计异常问题,优化显示数量问题。

This commit is contained in:
jianweie code
2023-03-06 23:37:25 +08:00
parent 36674d1db0
commit 3d8a6b3ec8
5 changed files with 42 additions and 28 deletions

View File

@@ -19,6 +19,7 @@ using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.ViewModels.Basics; using CoreCms.Net.Model.ViewModels.Basics;
using CoreCms.Net.Model.ViewModels.Echarts; using CoreCms.Net.Model.ViewModels.Echarts;
using CoreCms.Net.Model.ViewModels.UI; using CoreCms.Net.Model.ViewModels.UI;
using CoreCms.Net.Utility.Helper;
using SqlSugar; using SqlSugar;
@@ -73,22 +74,21 @@ namespace CoreCms.Net.Services
else if (dbTypeString == DbType.MySql.ToString()) else if (dbTypeString == DbType.MySql.ToString())
{ {
sqlStr = @"select tmp_x.x,ifnull(sum(o.orderAmount),0) as val,count(o.orderId) as num sqlStr = @"select tmp_x.x,ifnull(sum(o.orderAmount),0) as val,count(o.orderId) as num
from from
(SELECT @xi:=@xi+1 as x from (SELECT @xi:=@xi+1 as x from
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 UNION SELECT 10) x1, (SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 UNION SELECT 10) x1,
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 UNION SELECT 10) x2, (SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 UNION SELECT 10) x2,
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 UNION SELECT 10) x3, (SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 UNION SELECT 10) x3,
(SELECT @xi:=-1) x0 limit 0," + num + @") tmp_x (SELECT @xi:=-1) x0 limit 0," + num + @") tmp_x
left join ( left join (
select * from CoreCmsOrder select * from CoreCmsOrder
where 1 = 1 where 1 = 1
" + where + @" " + where + @"
) o on tmp_x.x = ((cast(date(o." + joinVal + @") as signed) - " + sTime.ToString("yyyyMMdd") + @") div(" + section + @")) ) o on tmp_x.x = ((unix_timestamp(o." + joinVal + @") - " + CommonHelper.ConvertDateTimeToInt(sTime) + @") div(" + section + @"))
group by tmp_x.x group by tmp_x.x
"; ";
} }
Console.WriteLine(sqlStr);
var sp = new List<SugarParameter>(); var sp = new List<SugarParameter>();
var list = _dal.SqlQuery(sqlStr, sp); var list = _dal.SqlQuery(sqlStr, sp);
@@ -141,7 +141,7 @@ namespace CoreCms.Net.Services
select * from CoreCmsBillPayments select * from CoreCmsBillPayments
where 1 = 1 where 1 = 1
" + where + @" " + where + @"
) o on tmp_x.x = ((cast(date(o." + joinVal + @") as signed) - " + sTime.ToString("yyyy-MM-dd") + @") div(" + section + @")) ) o on tmp_x.x = ((unix_timestamp(o." + joinVal + @") - " + CommonHelper.ConvertDateTimeToInt(sTime) + @") div(" + section + @"))
group by tmp_x.x group by tmp_x.x
"; ";
} }
@@ -201,7 +201,7 @@ namespace CoreCms.Net.Services
select* from CoreCmsBillRefund select* from CoreCmsBillRefund
where 1 = 1 where 1 = 1
" + where + @" " + where + @"
) o on tmp_x.x = ((cast(date(o." + joinVal + @") as signed) - " + sTime.ToString("yyyy-MM-dd") + @") div(" + section + @")) ) o on tmp_x.x = ((unix_timestamp(o." + joinVal + @") - " + CommonHelper.ConvertDateTimeToInt(sTime) + @") div(" + section + @"))
group by tmp_x.x group by tmp_x.x
"; ";
} }
@@ -258,7 +258,7 @@ namespace CoreCms.Net.Services
select * from CoreCmsUserTocash select * from CoreCmsUserTocash
where 1 = 1 where 1 = 1
" + where + @" " + where + @"
) o on tmp_x.x = ((cast(date(o." + joinVal + @") as signed) - " + sTime.ToString("yyyy-MM-dd") + @") div(" + section + @")) ) o on tmp_x.x = ((unix_timestamp(o." + joinVal + @") - " + CommonHelper.ConvertDateTimeToInt(sTime) + @") div(" + section + @"))
group by tmp_x.x group by tmp_x.x
"; ";
} }

View File

@@ -733,5 +733,19 @@ namespace CoreCms.Net.Utility.Helper
// 如果上传文件大于限定的容量 // 如果上传文件大于限定的容量
return !(fileSize > size); return !(fileSize > size);
} }
/// <summary>
/// 10位时间戳 转化
/// </summary>
/// <param name="time"></param>
/// <returns></returns>
public static long ConvertDateTimeToInt(System.DateTime time)
{
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0));
long t = (time.Ticks - startTime.Ticks) / 10000000; //除10000000调整为10位
return t;
}
} }
} }

View File

@@ -110,29 +110,29 @@ namespace CoreCms.Net.Utility.Helper
case 3600: //小时 case 3600: //小时
if (dateArr.num <= 24) if (dateArr.num <= 24)
{ {
xType = "H时"; xType = "d日H时";
} }
else if (dateArr.num <= 720) else if (dateArr.num <= 720)
{ {
xType = "d日H时"; xType = "M月d日H时";
} }
else else
{ {
xType = "m月d日H时"; xType = "M月d日H时";
} }
break; break;
case 86400: //天 case 86400: //天
if (dateArr.num <= 31) if (dateArr.num <= 31)
{ {
xType = "d号"; xType = "M月d号";
} }
else if (dateArr.num <= 365) else if (dateArr.num <= 365)
{ {
xType = "m.d"; xType = "yyyy年M月dd日";
} }
else else
{ {
xType = "Y.m.d"; xType = "yyyy年M月dd日";
} }
break; break;
} }

View File

@@ -84,8 +84,8 @@
defaultToolbar: ['filter', 'print', 'exports'], defaultToolbar: ['filter', 'print', 'exports'],
//height: 'full-127', //height: 'full-127',
page: false, page: false,
limit: 30, limit: 8760,
limits: [10, 15, 20, 25, 30, 50, 100, 200], //limits: [10, 15, 20, 25, 30, 50, 100, 200],
text: { none: '暂无相关数据' }, text: { none: '暂无相关数据' },
totalRow: true, totalRow: true,
cols: [ cols: [

View File

@@ -85,8 +85,8 @@
//height: 'full-127', //height: 'full-127',
page: false, page: false,
cellMinWidth: '80', cellMinWidth: '80',
limit: 30, limit: 8760,
limits: [10, 15, 20, 25, 30, 50, 100, 200], //limits: [10, 15, 20, 25, 30, 50, 100, 200],
text: { none: '暂无相关数据' }, text: { none: '暂无相关数据' },
totalRow: true, totalRow: true,
cols: [ cols: [