|
@@ -1,6 +1,7 @@
|
|
|
package models
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
"hongze/hongze_api/utils"
|
|
|
"rdluck_tools/orm"
|
|
|
"time"
|
|
@@ -15,19 +16,20 @@ type BillDetailResp struct {
|
|
|
ListenReportCount int `description:"收听报告次数"`
|
|
|
ListenReportDuration float64 `description:"收听报告时长"`
|
|
|
MaxReadReportDate string `description:"阅读报告最多的一天"`
|
|
|
- MaxReadReportCount int `description:"阅读报告最多的一天,报告数量"`
|
|
|
+ MaxReadReportCount int `description:"阅读报告最多的一天,报告数量"`
|
|
|
LatestReadReportDate string `description:"阅读报告时间最晚的一天"`
|
|
|
LatestReadReportTime string `description:"阅读报告时间最晚的一天,最晚的时间"`
|
|
|
- LatestReadReportDateDuration string `description:"阅读报告时间最晚的一天,总共阅读报告的时长"`
|
|
|
+ LatestReadReportDateDuration float64 `description:"阅读报告时间最晚的一天,总共阅读报告的时长"`
|
|
|
MaxOpenReportClassify string `description:"打开次数最多报告的栏目"`
|
|
|
- MaxOpenReportCount string `description:"打开次数最多报告的栏目下,用户阅读的报告数"`
|
|
|
- TotalReadDuration string `description:"总阅读时长"`
|
|
|
- TotalReportDayCount string `description:"总阅读晨报数"`
|
|
|
- TotalReportWeekCount string `description:"总阅读周报数"`
|
|
|
- TotalReportMonthCount string `description:"总阅读月报数"`
|
|
|
- TotalReportTwoWeekCount string `description:"总阅读双周报数"`
|
|
|
- TotalReportRddpCount string `description:"总阅读点评数"`
|
|
|
- LearnDay string `description:"连续学习天数"`
|
|
|
+ MaxOpenReportCount int `description:"打开次数最多报告的栏目下,用户阅读的报告数"`
|
|
|
+ TotalReadDuration float64 `description:"总阅读时长"`
|
|
|
+ TotalReportDayCount int `description:"总阅读晨报数"`
|
|
|
+ TotalReportWeekCount int `description:"总阅读周报数"`
|
|
|
+ TotalReportMonthCount int `description:"总阅读月报数"`
|
|
|
+ TotalReportTwoWeekCount int `description:"总阅读双周报数"`
|
|
|
+ TotalReportRddpCount int `description:"总阅读点评数"`
|
|
|
+ TotalReport int `description:"总阅读报告数"`
|
|
|
+ LearnDay int `description:"连续学习天数"`
|
|
|
}
|
|
|
|
|
|
type ReadReportType struct {
|
|
@@ -37,29 +39,29 @@ type ReadReportType struct {
|
|
|
Stage int
|
|
|
}
|
|
|
|
|
|
-func GetRddpMinReportType(uid int) (item *ReadReportType, err error) {
|
|
|
+func GetRddpMinReportType(uid int, startDate string) (item *ReadReportType, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
o.Using("rddp")
|
|
|
sql := `SELECT 'rddp' AS report_type,MIN(a.create_time) AS create_time,b.title,b.stage FROM report_view_record AS a
|
|
|
INNER JOIN report AS b ON a.report_id=b.id
|
|
|
- WHERE a.user_id=? `
|
|
|
- err = o.Raw(sql, uid).QueryRow(&item)
|
|
|
+ WHERE a.user_id=? AND a.create_time>=? `
|
|
|
+ err = o.Raw(sql, uid, startDate).QueryRow(&item)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func GetWeekMinReportType(uid int) (item *ReadReportType, err error) {
|
|
|
+func GetWeekMinReportType(uid int, startDate string) (item *ReadReportType, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
sql := `SELECT b.type AS report_type,MIN(a.created_time) AS create_time,b.research_report_name AS title,b.periods AS stage FROM user_view_history AS a
|
|
|
INNER JOIN research_report AS b ON a.research_report_id=b.research_report_id
|
|
|
- WHERE a.user_id=? `
|
|
|
- err = o.Raw(sql, uid).QueryRow(&item)
|
|
|
+ WHERE a.user_id=? AND a.created_time>=? `
|
|
|
+ err = o.Raw(sql, uid, startDate).QueryRow(&item)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func GetFirstReportInfo(uid int) (firstReadReportType, firstReadReportTitle string, err error) {
|
|
|
+func GetFirstReportInfo(uid int, startDate string) (firstReadReportType, firstReadReportTitle string, err error) {
|
|
|
rddpFlag := true
|
|
|
weekFlag := true
|
|
|
- rddpMinReportItem, err := GetRddpMinReportType(uid)
|
|
|
+ rddpMinReportItem, err := GetRddpMinReportType(uid, startDate)
|
|
|
if err != nil {
|
|
|
if err.Error() == utils.ErrNoRow() {
|
|
|
rddpFlag = false
|
|
@@ -70,7 +72,7 @@ func GetFirstReportInfo(uid int) (firstReadReportType, firstReadReportTitle stri
|
|
|
if rddpMinReportItem == nil {
|
|
|
rddpFlag = false
|
|
|
}
|
|
|
- weekMinReportItem, err := GetWeekMinReportType(uid)
|
|
|
+ weekMinReportItem, err := GetWeekMinReportType(uid, startDate)
|
|
|
if err != nil {
|
|
|
if err.Error() == utils.ErrNoRow() {
|
|
|
weekFlag = false
|
|
@@ -108,29 +110,29 @@ type Listen struct {
|
|
|
VideoPlaySeconds float64
|
|
|
}
|
|
|
|
|
|
-func GetRddpListen(uid int) (item *Listen, err error) {
|
|
|
+func GetRddpListen(uid int, startDate string) (item *Listen, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
o.Using("rddp")
|
|
|
- sql := ` SELECT COUNT(1),SUM(b.video_play_seconds) FROM report_audio_record AS a
|
|
|
+ sql := ` SELECT COUNT(1) AS count,SUM(b.video_play_seconds) AS video_play_seconds FROM report_audio_record AS a
|
|
|
INNER JOIN report AS b ON a.report_id=b.id
|
|
|
- WHERE user_id=? LIMIT 1`
|
|
|
- err = o.Raw(sql, uid).QueryRow(&item)
|
|
|
+ WHERE user_id=? AND a.create_time>=? LIMIT 1`
|
|
|
+ err = o.Raw(sql, uid, startDate).QueryRow(&item)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func GetWeekListen(uid int) (item *Listen, err error) {
|
|
|
+func GetWeekListen(uid int, startDate string) (item *Listen, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
sql := `SELECT COUNT(1) AS count,SUM(b.video_play_seconds) AS video_play_seconds FROM voice_record AS a
|
|
|
INNER JOIN teleconference AS b ON a.teleconference_id=b.teleconference_id
|
|
|
- WHERE a.uid=? LIMIT 1`
|
|
|
- err = o.Raw(sql, uid).QueryRow(&item)
|
|
|
+ WHERE a.uid=? AND a.create_time>=? LIMIT 1`
|
|
|
+ err = o.Raw(sql, uid, startDate).QueryRow(&item)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func GetListenInfo(uid int) (count int, videoPlaySeconds float64, err error) {
|
|
|
+func GetListenInfo(uid int, startDate string) (count int, videoPlaySeconds float64, err error) {
|
|
|
rddpFlag := true
|
|
|
weekFlag := true
|
|
|
- rddpListenItem, err := GetRddpListen(uid)
|
|
|
+ rddpListenItem, err := GetRddpListen(uid, startDate)
|
|
|
if err != nil {
|
|
|
if err.Error() == utils.ErrNoRow() {
|
|
|
rddpFlag = false
|
|
@@ -141,7 +143,7 @@ func GetListenInfo(uid int) (count int, videoPlaySeconds float64, err error) {
|
|
|
if rddpListenItem == nil {
|
|
|
rddpFlag = false
|
|
|
}
|
|
|
- weekListenItem, err := GetWeekListen(uid)
|
|
|
+ weekListenItem, err := GetWeekListen(uid, startDate)
|
|
|
if err != nil {
|
|
|
if err.Error() == utils.ErrNoRow() {
|
|
|
weekFlag = false
|
|
@@ -169,38 +171,114 @@ func GetListenInfo(uid int) (count int, videoPlaySeconds float64, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+type LatestReadReport struct {
|
|
|
+ LatestTime string
|
|
|
+ CreateTime time.Time
|
|
|
+}
|
|
|
+
|
|
|
+func GetRddpLatestReadReport(uid int, startDate string) (item *LatestReadReport, err error) {
|
|
|
+ o := orm.NewOrm()
|
|
|
+ o.Using("rddp")
|
|
|
+ sql := ` SELECT DATE_FORMAT(create_time,'%H:%i:%s') AS latest_time,create_time FROM report_view_record
|
|
|
+ WHERE user_id=? AND create_time>=? AND (DATE_FORMAT(create_time,'%H:%i:%s')<='06:00:00' OR DATE_FORMAT(create_time,'%H:%i:%s')>'06:00:00')
|
|
|
+ ORDER BY DATE_FORMAT(create_time,'%H:%i:%s') DESC
|
|
|
+ LIMIT 1 `
|
|
|
+ err = o.Raw(sql, uid, startDate).QueryRow(&item)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetWeekLatestReadReportCount(uid int, startDate string) (item *LatestReadReport, err error) {
|
|
|
+ o := orm.NewOrm()
|
|
|
+ sql := ` SELECT DATE_FORMAT(created_time,'%H:%i:%s') AS latest_time,created_time FROM user_view_history
|
|
|
+ WHERE user_id=? AND created_time>=? AND (DATE_FORMAT(created_time,'%H:%i:%s')<='06:00:00' OR DATE_FORMAT(created_time,'%H:%i:%s')>'06:00:00')
|
|
|
+ ORDER BY DATE_FORMAT(created_time,'%H:%i:%s') DESC
|
|
|
+ LIMIT 1 `
|
|
|
+ err = o.Raw(sql, uid, startDate).QueryRow(&item)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetLatestReadReportInfo(uid int, startDate string) (latestTime string, latestCreateTime time.Time, err error) {
|
|
|
+ rddpFlag := true
|
|
|
+ weekFlag := true
|
|
|
+ rddpReadReportItem, err := GetRddpLatestReadReport(uid, startDate)
|
|
|
+ if err != nil {
|
|
|
+ if err.Error() == utils.ErrNoRow() {
|
|
|
+ rddpFlag = false
|
|
|
+ } else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if rddpReadReportItem == nil {
|
|
|
+ rddpFlag = false
|
|
|
+ }
|
|
|
+ weekReadReportItem, err := GetWeekLatestReadReportCount(uid, startDate)
|
|
|
+ if err != nil {
|
|
|
+ if err.Error() == utils.ErrNoRow() {
|
|
|
+ weekFlag = false
|
|
|
+ } else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if weekReadReportItem == nil {
|
|
|
+ weekFlag = false
|
|
|
+ }
|
|
|
+
|
|
|
+ if rddpFlag && weekFlag {
|
|
|
+ if rddpReadReportItem.CreateTime.After(weekReadReportItem.CreateTime) {
|
|
|
+ latestTime = rddpReadReportItem.LatestTime
|
|
|
+ latestCreateTime = rddpReadReportItem.CreateTime
|
|
|
+ } else {
|
|
|
+ latestTime = weekReadReportItem.LatestTime
|
|
|
+ latestCreateTime = weekReadReportItem.CreateTime
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if rddpFlag == false && weekFlag {
|
|
|
+ latestTime = weekReadReportItem.LatestTime
|
|
|
+ latestCreateTime = weekReadReportItem.CreateTime
|
|
|
+ }
|
|
|
+ if rddpFlag && weekFlag == false {
|
|
|
+ latestTime = rddpReadReportItem.LatestTime
|
|
|
+ latestCreateTime = rddpReadReportItem.CreateTime
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fmt.Println("line 244")
|
|
|
+ fmt.Println(latestTime, latestCreateTime)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
type MaxReadReportCount struct {
|
|
|
Count int
|
|
|
CreateDate time.Time
|
|
|
}
|
|
|
|
|
|
-func GetRddpMaxReadReportCount(uid int) (item *MaxReadReportCount, err error) {
|
|
|
+func GetRddpMaxReadReportCount(uid int, startDate string) (item *MaxReadReportCount, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
o.Using("rddp")
|
|
|
sql := ` SELECT DATE(create_time)AS create_date,COUNT(1) AS count FROM report_view_record AS a
|
|
|
WHERE a.user_id=?
|
|
|
+ AND create_time>=?
|
|
|
GROUP BY DATE(create_time)
|
|
|
- ORDER BY num DESC
|
|
|
+ ORDER BY count DESC
|
|
|
LIMIT 1 `
|
|
|
- err = o.Raw(sql, uid).QueryRow(&item)
|
|
|
+ err = o.Raw(sql, uid, startDate).QueryRow(&item)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func GetWeekMaxReadReportCount(uid int) (item *MaxReadReportCount, err error) {
|
|
|
+func GetWeekMaxReadReportCount(uid int, startDate string) (item *MaxReadReportCount, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
sql := ` SELECT DATE(a.created_time)AS create_date,COUNT(1) AS count FROM user_view_history AS a
|
|
|
- WHERE a.user_id=?
|
|
|
+ WHERE a.user_id=? AND created_time>=?
|
|
|
GROUP BY DATE(created_time)
|
|
|
- ORDER BY num DESC
|
|
|
+ ORDER BY count DESC
|
|
|
LIMIT 1 `
|
|
|
- err = o.Raw(sql, uid).QueryRow(&item)
|
|
|
+ err = o.Raw(sql, uid, startDate).QueryRow(&item)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func GetMaxReadReportInfo(uid int) (count int, createDate time.Time, err error) {
|
|
|
+func GetMaxReadReportInfo(uid int, startDate string) (count int, createDate time.Time, err error) {
|
|
|
rddpFlag := true
|
|
|
weekFlag := true
|
|
|
- rddpReadReportItem, err := GetRddpMaxReadReportCount(uid)
|
|
|
+ rddpReadReportItem, err := GetRddpMaxReadReportCount(uid, startDate)
|
|
|
if err != nil {
|
|
|
if err.Error() == utils.ErrNoRow() {
|
|
|
rddpFlag = false
|
|
@@ -211,7 +289,7 @@ func GetMaxReadReportInfo(uid int) (count int, createDate time.Time, err error)
|
|
|
if rddpReadReportItem == nil {
|
|
|
rddpFlag = false
|
|
|
}
|
|
|
- weekReadReportItem, err := GetWeekMaxReadReportCount(uid)
|
|
|
+ weekReadReportItem, err := GetWeekMaxReadReportCount(uid, startDate)
|
|
|
if err != nil {
|
|
|
if err.Error() == utils.ErrNoRow() {
|
|
|
weekFlag = false
|
|
@@ -224,99 +302,230 @@ func GetMaxReadReportInfo(uid int) (count int, createDate time.Time, err error)
|
|
|
}
|
|
|
|
|
|
if rddpFlag && weekFlag {
|
|
|
- if rddpReadReportItem.Count>weekReadReportItem.Count {
|
|
|
- count=rddpReadReportItem.Count
|
|
|
- createDate=rddpReadReportItem.CreateDate
|
|
|
- }else{
|
|
|
- count=weekReadReportItem.Count
|
|
|
- createDate=weekReadReportItem.CreateDate
|
|
|
+ if rddpReadReportItem.Count > weekReadReportItem.Count {
|
|
|
+ count = rddpReadReportItem.Count
|
|
|
+ createDate = rddpReadReportItem.CreateDate
|
|
|
+ } else {
|
|
|
+ count = weekReadReportItem.Count
|
|
|
+ createDate = weekReadReportItem.CreateDate
|
|
|
}
|
|
|
} else {
|
|
|
if rddpFlag == false && weekFlag {
|
|
|
- count=weekReadReportItem.Count
|
|
|
- createDate=weekReadReportItem.CreateDate
|
|
|
+ count = weekReadReportItem.Count
|
|
|
+ createDate = weekReadReportItem.CreateDate
|
|
|
}
|
|
|
if rddpFlag && weekFlag == false {
|
|
|
- count=rddpReadReportItem.Count
|
|
|
- createDate=rddpReadReportItem.CreateDate
|
|
|
+ count = rddpReadReportItem.Count
|
|
|
+ createDate = rddpReadReportItem.CreateDate
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//
|
|
|
-//
|
|
|
-//type MaxReadReportCount struct {
|
|
|
-// Count int
|
|
|
-// CreateDate time.Time
|
|
|
-//}
|
|
|
-//
|
|
|
-//func GetRddpMaxReadReportCount(uid int) (item *MaxReadReportCount, err error) {
|
|
|
-// o := orm.NewOrm()
|
|
|
-// o.Using("rddp")
|
|
|
-// sql := ` SELECT DATE(create_time)AS create_date,COUNT(1) AS count FROM report_view_record AS a
|
|
|
-// WHERE a.user_id=?
|
|
|
-// GROUP BY DATE(create_time)
|
|
|
-// ORDER BY num DESC
|
|
|
-// LIMIT 1 `
|
|
|
-// err = o.Raw(sql, uid).QueryRow(&item)
|
|
|
-// return
|
|
|
-//}
|
|
|
-//
|
|
|
-//func GetWeekMaxReadReportCount(uid int) (item *MaxReadReportCount, err error) {
|
|
|
-// o := orm.NewOrm()
|
|
|
-// sql := ` SELECT DATE(a.created_time)AS create_date,COUNT(1) AS count FROM user_view_history AS a
|
|
|
-// WHERE a.user_id=?
|
|
|
-// GROUP BY DATE(created_time)
|
|
|
-// ORDER BY num DESC
|
|
|
-// LIMIT 1 `
|
|
|
-// err = o.Raw(sql, uid).QueryRow(&item)
|
|
|
-// return
|
|
|
-//}
|
|
|
-//
|
|
|
-//func GetMaxReadReportInfo(uid int) (count int, createDate time.Time, err error) {
|
|
|
-// rddpFlag := true
|
|
|
-// weekFlag := true
|
|
|
-// rddpReadReportItem, err := GetRddpMaxReadReportCount(uid)
|
|
|
-// if err != nil {
|
|
|
-// if err.Error() == utils.ErrNoRow() {
|
|
|
-// rddpFlag = false
|
|
|
-// } else {
|
|
|
-// return
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if rddpReadReportItem == nil {
|
|
|
-// rddpFlag = false
|
|
|
-// }
|
|
|
-// weekReadReportItem, err := GetWeekMaxReadReportCount(uid)
|
|
|
-// if err != nil {
|
|
|
-// if err.Error() == utils.ErrNoRow() {
|
|
|
-// weekFlag = false
|
|
|
-// } else {
|
|
|
-// return
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if weekReadReportItem == nil {
|
|
|
-// weekFlag = false
|
|
|
-// }
|
|
|
-//
|
|
|
-// if rddpFlag && weekFlag {
|
|
|
-// if rddpReadReportItem.Count>weekReadReportItem.Count {
|
|
|
-// count=rddpReadReportItem.Count
|
|
|
-// createDate=rddpReadReportItem.CreateDate
|
|
|
-// }else{
|
|
|
-// count=weekReadReportItem.Count
|
|
|
-// createDate=weekReadReportItem.CreateDate
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// if rddpFlag == false && weekFlag {
|
|
|
-// count=weekReadReportItem.Count
|
|
|
-// createDate=weekReadReportItem.CreateDate
|
|
|
-// }
|
|
|
-// if rddpFlag && weekFlag == false {
|
|
|
-// count=rddpReadReportItem.Count
|
|
|
-// createDate=rddpReadReportItem.CreateDate
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return
|
|
|
-//}
|
|
|
+func GetRddpReadReportCountByDate(uid int, readDate string) (count int, video_play_seconds float64, err error) {
|
|
|
+ o := orm.NewOrm()
|
|
|
+ o.Using("rddp")
|
|
|
+ sql := ` SELECT COUNT(1) AS count,SUM(b.video_play_seconds) AS video_play_seconds FROM report_view_record AS a
|
|
|
+ LEFT JOIN report AS b ON a.report_id=b.id
|
|
|
+ WHERE a.user_id=? AND DATE(a.create_time)=? LIMIT 1`
|
|
|
+ err = o.Raw(sql, uid, readDate).QueryRow(&count, &video_play_seconds)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetWeekReadReportCountByDate(uid int, readDate string) (count int, err error) {
|
|
|
+ o := orm.NewOrm()
|
|
|
+ sql := ` SELECT COUNT(1) AS count FROM user_view_history AS a
|
|
|
+ WHERE a.user_id=? AND DATE(a.created_time)=?
|
|
|
+ LIMIT 1 `
|
|
|
+ err = o.Raw(sql, uid, readDate).QueryRow(&count)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+type MaxOpenReport struct {
|
|
|
+ OpenReportCount int
|
|
|
+ ClassifyName string
|
|
|
+}
|
|
|
+
|
|
|
+func GetRddpOpenReadReport(uid int, startDate string) (item *MaxOpenReport, err error) {
|
|
|
+ o := orm.NewOrm()
|
|
|
+ o.Using("rddp")
|
|
|
+ sql := ` SELECT COUNT(b.classify_id_second) AS open_report_count,b.classify_name_second AS classify_name
|
|
|
+ FROM report_view_record AS a
|
|
|
+ INNER JOIN report AS b ON a.report_id=b.id
|
|
|
+ WHERE a.user_id=? AND a.create_time>=?
|
|
|
+ GROUP BY b.classify_id_second
|
|
|
+ ORDER BY COUNT(b.classify_id_second) DESC
|
|
|
+ LIMIT 1 `
|
|
|
+ err = o.Raw(sql, uid, startDate).QueryRow(&item)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetWeekOpenReadReportCount(uid int, startDate string) (item *MaxOpenReport, err error) {
|
|
|
+ o := orm.NewOrm()
|
|
|
+ sql := ` SELECT COUNT(b.research_report_name) AS open_report_count,b.research_report_name AS classify_name
|
|
|
+ FROM user_view_history AS a
|
|
|
+ LEFT JOIN research_report AS b ON a.research_report_id=b.research_report_id
|
|
|
+ WHERE user_id=? AND a.created_time=?
|
|
|
+ GROUP BY b.research_report_name
|
|
|
+ ORDER BY COUNT(b.research_report_name) DESC
|
|
|
+ LIMIT 1 `
|
|
|
+ err = o.Raw(sql, uid, startDate).QueryRow(&item)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetOpenReadReportInfo(uid int, startDate string) (maxOpenReportClassify string, maxOpenReportCount int, err error) {
|
|
|
+ rddpFlag := true
|
|
|
+ weekFlag := true
|
|
|
+ rddpReadReportItem, err := GetRddpOpenReadReport(uid, startDate)
|
|
|
+ if err != nil {
|
|
|
+ if err.Error() == utils.ErrNoRow() {
|
|
|
+ rddpFlag = false
|
|
|
+ } else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if rddpReadReportItem == nil {
|
|
|
+ rddpFlag = false
|
|
|
+ }
|
|
|
+ weekReadReportItem, err := GetWeekOpenReadReportCount(uid, startDate)
|
|
|
+ if err != nil {
|
|
|
+ if err.Error() == utils.ErrNoRow() {
|
|
|
+ weekFlag = false
|
|
|
+ } else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if weekReadReportItem == nil {
|
|
|
+ weekFlag = false
|
|
|
+ }
|
|
|
+
|
|
|
+ if rddpFlag && weekFlag {
|
|
|
+ if rddpReadReportItem.OpenReportCount > weekReadReportItem.OpenReportCount {
|
|
|
+ maxOpenReportCount = rddpReadReportItem.OpenReportCount
|
|
|
+ maxOpenReportClassify = rddpReadReportItem.ClassifyName
|
|
|
+ } else {
|
|
|
+ maxOpenReportCount = weekReadReportItem.OpenReportCount
|
|
|
+ maxOpenReportClassify = weekReadReportItem.ClassifyName
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if rddpFlag == false && weekFlag {
|
|
|
+ maxOpenReportCount = weekReadReportItem.OpenReportCount
|
|
|
+ maxOpenReportClassify = weekReadReportItem.ClassifyName
|
|
|
+ }
|
|
|
+ if rddpFlag && weekFlag == false {
|
|
|
+ maxOpenReportCount = rddpReadReportItem.OpenReportCount
|
|
|
+ maxOpenReportClassify = rddpReadReportItem.ClassifyName
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetRddpTotalReadDuration(uid int, startDate string) (video_play_seconds float64, total int, err error) {
|
|
|
+ sql := `SELECT SUM(b.video_play_seconds) AS video_play_seconds ,COUNT(1) AS total FROM report_view_record AS a
|
|
|
+ INNER JOIN report AS b ON a.report_id=b.id
|
|
|
+ WHERE a.user_id=? AND a.create_time=? `
|
|
|
+ o := orm.NewOrm()
|
|
|
+ o.Using("rddp")
|
|
|
+ err = o.Raw(sql, uid, startDate).QueryRow(&video_play_seconds, &total)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetWeekTotalRead(uid int, startDate string) (report_count int, err error) {
|
|
|
+ o := orm.NewOrm()
|
|
|
+ sql := ` SELECT SUM(1) AS report_count
|
|
|
+ FROM user_view_history AS a
|
|
|
+ INNER JOIN research_report AS b ON a.research_report_id=b.research_report_id
|
|
|
+ WHERE a.user_id=? AND a.created_time>=? `
|
|
|
+ err = o.Raw(sql, uid, startDate).QueryRow(&report_count)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetWeekTotalReadByType(uid int, reportType string, startDate string) (report_count int, err error) {
|
|
|
+ o := orm.NewOrm()
|
|
|
+ sql := `SELECT count(DISTINCT a.research_report_id) AS report_count
|
|
|
+ FROM user_view_history AS a
|
|
|
+ INNER JOIN research_report AS b ON a.research_report_id=b.research_report_id
|
|
|
+ WHERE a.user_id=? AND a.created_time>=? AND b.type=?`
|
|
|
+ err = o.Raw(sql, uid, startDate, reportType).QueryRow(&report_count)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetRddpLearnDay(uid int, startDate, endDate string) (learn_day int, err error) {
|
|
|
+ //, MIN(login_day) start_date,MAX(login_day) end_date
|
|
|
+ o := orm.NewOrm()
|
|
|
+ o.Using("rddp")
|
|
|
+ sql := ` SELECT MAX(days) AS learn_day
|
|
|
+ FROM (SELECT user_id,
|
|
|
+ @cont_day :=
|
|
|
+ (CASE
|
|
|
+ WHEN (@last_uid = user_id AND DATEDIFF(login_dt, @last_dt)=1) THEN
|
|
|
+ (@cont_day + 1)
|
|
|
+ WHEN (@last_uid = user_id AND DATEDIFF(login_dt, @last_dt)<1) THEN
|
|
|
+ (@cont_day + 0)
|
|
|
+ ELSE
|
|
|
+ 1
|
|
|
+ END) AS days,
|
|
|
+ (@cont_ix := (@cont_ix + IF(@cont_day = 1, 1, 0))) AS cont_ix,
|
|
|
+ @last_uid := user_id,
|
|
|
+ @last_dt := login_dt login_day
|
|
|
+ FROM (SELECT user_id, DATE(create_time) AS login_dt
|
|
|
+ FROM report_view_record
|
|
|
+ WHERE
|
|
|
+ user_id=?
|
|
|
+ AND create_time>=?
|
|
|
+ ORDER BY user_id, create_time) AS t,
|
|
|
+ (SELECT @last_uid := '',
|
|
|
+ @last_dt := '',
|
|
|
+ @cont_ix := 0,
|
|
|
+ @cont_day := 0) AS t1) AS t2
|
|
|
+ GROUP BY user_id, cont_ix
|
|
|
+ ORDER BY MAX(days) DESC
|
|
|
+ LIMIT 1 `
|
|
|
+ err = o.Raw(sql, uid, startDate).QueryRow(&learn_day)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetWeekpLearnDay(uid int, startDate string) (learn_day int, err error) {
|
|
|
+ //MIN(login_day) start_date,MAX(login_day) end_date
|
|
|
+ o := orm.NewOrm()
|
|
|
+ sql := ` SELECT MAX(days) lianxu_days
|
|
|
+ FROM (SELECT user_id,
|
|
|
+ @cont_day :=
|
|
|
+ (CASE
|
|
|
+ WHEN (@last_uid = user_id AND DATEDIFF(login_dt, @last_dt)=1) THEN
|
|
|
+ (@cont_day + 1)
|
|
|
+ WHEN (@last_uid = user_id AND DATEDIFF(login_dt, @last_dt)<1) THEN
|
|
|
+ (@cont_day + 0)
|
|
|
+ ELSE
|
|
|
+ 1
|
|
|
+ END) AS days,
|
|
|
+ (@cont_ix := (@cont_ix + IF(@cont_day = 1, 1, 0))) AS cont_ix,
|
|
|
+ @last_uid := user_id,
|
|
|
+ @last_dt := login_dt login_day
|
|
|
+ FROM (SELECT user_id, DATE(created_time) AS login_dt
|
|
|
+ FROM user_view_history
|
|
|
+ WHERE
|
|
|
+ user_id=?
|
|
|
+ AND created_time>=?
|
|
|
+ ORDER BY user_id, created_time) AS t,
|
|
|
+ (SELECT @last_uid := '',
|
|
|
+ @last_dt := '',
|
|
|
+ @cont_ix := 0,
|
|
|
+ @cont_day := 0) AS t1) AS t2
|
|
|
+ GROUP BY user_id, cont_ix
|
|
|
+ ORDER BY MAX(days) DESC
|
|
|
+ LIMIT 1 `
|
|
|
+ err = o.Raw(sql, uid, startDate).QueryRow(&learn_day)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetRddpTotalReadByType(uid int, startDate string) (report_count int, err error) {
|
|
|
+ o := orm.NewOrm()
|
|
|
+ o.Using("rddp")
|
|
|
+ sql := `SELECT count(DISTINCT a.report_id) AS report_count
|
|
|
+ FROM report_view_record AS a
|
|
|
+ INNER JOIN report AS b ON a.report_id=b.id
|
|
|
+ WHERE a.user_id=? AND a.create_time>=? `
|
|
|
+ err = o.Raw(sql, uid, startDate).QueryRow(&report_count)
|
|
|
+ return
|
|
|
+}
|