func Del_link_for_topic_all(db *goku.MysqlDB) error { err := del_link_for_topic_later_top("tui_link_for_topic_top", "reddit_score DESC,link_id DESC", db) if err == nil { err = del_link_for_topic_later_top("tui_link_for_topic_later", "link_id DESC", db) } if err == nil { _, err = db.Query(`DELETE FROM tui_link_for_topic_hot WHERE (time_type=2 AND create_time<?) OR (time_type=3 AND create_time<?) OR (time_type=4 AND create_time<?) OR (time_type=5 AND create_time<?) OR (time_type=6 AND create_time<?)`, utils.ThisHour(), utils.ThisDate(), utils.ThisWeek(), utils.ThisMonth(), utils.ThisYear()) if err == nil { err = del_link_for_topic_hot_vote("tui_link_for_topic_hot", "dispute_score DESC,link_id DESC", db) } } if err == nil { _, err = db.Query(`DELETE FROM tui_link_for_topic_vote WHERE (time_type=2 AND create_time<?) OR (time_type=3 AND create_time<?) OR (time_type=4 AND create_time<?) OR (time_type=5 AND create_time<?) OR (time_type=6 AND create_time<?)`, utils.ThisHour(), utils.ThisDate(), utils.ThisWeek(), utils.ThisMonth(), utils.ThisYear()) if err == nil { err = del_link_for_topic_hot_vote("tui_link_for_topic_vote", "vote DESC,link_id DESC", db) } } return err }
/** * 链接推送给话题(热议) 2:这个小时;3:今天;4:这周;5:这个月;6:今年 */ func link_for_topic_hop_time(timeType int, handleTime time.Time, db *goku.MysqlDB) error { var t time.Time switch { case timeType == 2: t = utils.ThisHour() case timeType == 3: t = utils.ThisDate() case timeType == 4: t = utils.ThisWeek() case timeType == 5: t = utils.ThisMonth() case timeType == 6: t = utils.ThisYear() } sql := `INSERT ignore INTO tui_link_for_topic_hot(topic_id,link_id,create_time,dispute_score,time_type) ( SELECT TL.topic_id,H.link_id,H.create_time,L.dispute_score,? AS time_type FROM tui_link_for_handle H INNER JOIN topic_link TL ON H.insert_time<=? AND H.create_time>=? AND H.link_id=TL.link_id INNER JOIN link L ON L.id=H.link_id );` _, err := db.Query(sql, timeType, handleTime, t) return err }
/** * 链接推送给网站首页(热议)[3:全部时间;10:这个小时;11:今天;12:这周;13:这个月;14:今年] */ func link_for_home_hot(dataType int, handleTime time.Time, db *goku.MysqlDB) error { var t time.Time switch { case dataType == 10: t = utils.ThisHour() case dataType == 11: t = utils.ThisDate() case dataType == 12: t = utils.ThisWeek() case dataType == 13: t = utils.ThisMonth() case dataType == 14: t = utils.ThisYear() } var err error if dataType == 3 { //3:全部时间 sql := `INSERT ignore INTO tui_link_for_home(link_id,create_time,data_type,score) ( SELECT H.link_id,H.create_time,?,L.dispute_score FROM tui_link_for_handle H INNER JOIN link L ON H.insert_time<=? AND L.id=H.link_id ); ` _, err = db.Query(sql, dataType, handleTime) } else { sql := `INSERT ignore INTO tui_link_for_home(link_id,create_time,data_type,score) ( SELECT H.link_id,H.create_time,?,L.dispute_score FROM tui_link_for_handle H INNER JOIN link L ON H.insert_time<=? AND H.create_time>=? AND L.id=H.link_id ); ` _, err = db.Query(sql, dataType, handleTime, t) } return err }
/** * 链接推送给网站首页(投票)[投票时间范围: 4:全部时间;5:这个小时;6:今天;7:这周;8:这个月;9:今年] */ func link_for_home_vote(dataType int, handleTime time.Time, db *goku.MysqlDB) error { var t time.Time switch { case dataType == 5: t = utils.ThisHour() case dataType == 6: t = utils.ThisDate() case dataType == 7: t = utils.ThisWeek() case dataType == 8: t = utils.ThisMonth() case dataType == 9: t = utils.ThisYear() } var err error if dataType == 4 { //4:全部时间 sql := `INSERT ignore INTO tui_link_for_home(link_id,create_time,data_type,score) ( SELECT H.link_id,H.create_time,?,L.vote_up-L.vote_down FROM tui_link_for_handle H INNER JOIN link L ON H.insert_time<=? AND L.id=H.link_id );` _, err = db.Query(sql, dataType, handleTime) } else { sql := `INSERT ignore INTO tui_link_for_home(link_id,create_time,data_type,score) ( SELECT H.link_id,H.create_time,?,L.vote_up-L.vote_down FROM tui_link_for_handle H INNER JOIN link L ON H.insert_time<=? AND L.create_time>=? AND L.id=H.link_id ); ` _, err = db.Query(sql, dataType, handleTime, t) } return err }
func Del_link_for_home_all(db *goku.MysqlDB) error { err := del_link_for_home("data_type=2", "score DESC,link_id DESC", db) if err == nil { _, err = db.Query(`DELETE FROM tui_link_for_home WHERE ((data_type=10 OR data_type=5) AND create_time<?) OR ((data_type=11 OR data_type=6) AND create_time<?) OR ((data_type=12 OR data_type=7) AND create_time<?) OR ((data_type=13 OR data_type=8) AND create_time<?) OR ((data_type=14 OR data_type=9) AND create_time<?)`, utils.ThisHour(), utils.ThisDate(), utils.ThisWeek(), utils.ThisMonth(), utils.ThisYear()) } if err == nil { if err == nil { err = del_link_for_home("data_type IN(3,10,11,12,13,14)", "score DESC,link_id DESC", db) } } if err == nil { err = del_link_for_home("data_type IN(4,5,6,7,8,9)", "score DESC,link_id DESC", db) } return err }