|
@@ -41,7 +41,7 @@ func (v ViewsAllCodeDevice) GetDeviceCount() ([]ViewsAllCodeDevice, error) {
|
|
|
}
|
|
|
|
|
|
// 按月统计
|
|
|
-func (v ViewsAllCodeDevice) GetMonthDeviceCount(req model.ResuestDeviceCountFilter) ([]ViewsAllCodeDevice, error) {
|
|
|
+func (v ViewsAllCodeDevice) GetMonthDeviceCount(req model.RequestDeviceCountFilter) ([]ViewsAllCodeDevice, error) {
|
|
|
var list []ViewsAllCodeDevice
|
|
|
sql := `
|
|
|
SELECT
|
|
@@ -85,7 +85,7 @@ GROUP BY
|
|
|
}
|
|
|
|
|
|
// 按年统计
|
|
|
-func (v ViewsAllCodeDevice) GetYearDeviceCount(req model.ResuestDeviceCountFilter) ([]ViewsAllCodeDevice, error) {
|
|
|
+func (v ViewsAllCodeDevice) GetYearDeviceCount(req model.RequestDeviceCountFilter) ([]ViewsAllCodeDevice, error) {
|
|
|
var list []ViewsAllCodeDevice
|
|
|
sql := `
|
|
|
SELECT
|
|
@@ -127,3 +127,46 @@ GROUP BY
|
|
|
err := Db.Debug().Model(&v).Raw(sql, v.TenantId).Scan(&list).Error
|
|
|
return list, err
|
|
|
}
|
|
|
+
|
|
|
+func (v ViewsAllCodeDevice) GetDayDeviceCount(req model.RequestDeviceCountFilter) ([]ViewsAllCodeDevice, error) {
|
|
|
+ var list []ViewsAllCodeDevice
|
|
|
+ sql := `
|
|
|
+SELECT
|
|
|
+ month_time,
|
|
|
+ sum(count_t) AS count_t,
|
|
|
+ SUM(CASE device_type WHEN 1 THEN count_t ELSE 0 END) as device_type1_count_t,
|
|
|
+ SUM(CASE device_type WHEN 2 THEN count_t ELSE 0 END) as device_type2_count_t,
|
|
|
+ SUM(CASE device_type WHEN 3 THEN count_t ELSE 0 END) as device_type3_count_t,
|
|
|
+ SUM(CASE device_type WHEN 4 THEN count_t ELSE 0 END) as device_type4_count_t,
|
|
|
+ SUM(CASE device_type WHEN 5 THEN count_t ELSE 0 END) as device_type5_count_t,
|
|
|
+ SUM(CASE device_type WHEN 6 THEN count_t ELSE 0 END) as device_type6_count_t,
|
|
|
+ SUM(CASE device_type WHEN 7 THEN count_t ELSE 0 END) as device_type7_count_t,
|
|
|
+ SUM(CASE device_type WHEN 8 THEN count_t ELSE 0 END) as device_type8_count_t,
|
|
|
+ SUM(CASE device_type WHEN 9 THEN count_t ELSE 0 END) as device_type9_count_t,
|
|
|
+ SUM(CASE device_type WHEN 10 THEN count_t ELSE 0 END) as device_type10_count_t,
|
|
|
+ SUM(CASE device_type WHEN 11 THEN count_t ELSE 0 END) as device_type11_count_t,
|
|
|
+ SUM(CASE device_type WHEN 12 THEN count_t ELSE 0 END) as device_type12_count_t,
|
|
|
+ SUM(CASE device_type WHEN 13 THEN count_t ELSE 0 END) as device_type13_count_t,
|
|
|
+ SUM(CASE device_type WHEN 14 THEN count_t ELSE 0 END) as device_type14_count_t,
|
|
|
+ SUM(CASE device_type WHEN 15 THEN count_t ELSE 0 END) as device_type15_count_t
|
|
|
+FROM
|
|
|
+ (
|
|
|
+ SELECT
|
|
|
+ device_type,
|
|
|
+ count(*) AS count_t,
|
|
|
+ date_format( create_time, '%Y-%m-%d' ) AS month_time
|
|
|
+ FROM
|
|
|
+ view_all_code
|
|
|
+ where tenant_id=? and create_time >= ? and create_time<=?
|
|
|
+ GROUP BY
|
|
|
+ device_type,
|
|
|
+ month_time
|
|
|
+ ORDER BY
|
|
|
+ month_time DESC
|
|
|
+ ) a
|
|
|
+GROUP BY
|
|
|
+ month_time
|
|
|
+`
|
|
|
+ err := Db.Debug().Model(&v).Raw(sql, v.TenantId, req.StartTime, req.EndTime).Scan(&list).Error
|
|
|
+ return list, err
|
|
|
+}
|