package ht

import (
	"eta/eta_mini_ht_api/models"
	"time"
)

const (
	Publish = 3
)

type HTReport struct {
	Id              int    `gorm:"primary_key;auto_increment"`
	PlateId         int    `grom:"plate_id"`
	PlateName       string `gorm:"column:plate_name"`
	PermissionName  string `gorm:"column:permission_name"`
	PublishUserName string `gorm:"column:publish_user_name"`
	ReportName      string `gorm:"column:report_name"`
	PublishTime     int    `gorm:"column:publish_time"`
	PublishedTime   string `gorm:"column:published_time"`
	IsDelete        int    `gorm:"column:is_delete"`
	Status          int    `gorm:"column:status"`
}

func GetHTReports(id int) (reports []HTReport, err error) {
	db := models.HT()
	sql := "select tirtp.plate_id as plate_id, tip.plate_name as plate_name, t.id as id ,t.report_name as report_name,t.publish_user_name as publish_user_name,t.publish_time as publish_time,t.is_delete as is_delete,t.status as status from t_iirp_report_to_plate tirtp left join t_iirp_report_info t on t.id=tirtp.report_id left JOIN t_iirp_plate tip on tip.id=tirtp.plate_id  where t.is_delete =0 and t.`status` =3 and t.report_file_path<>'' and t.id > ? order by t.id asc"
	err = db.Model(&HTReport{}).Raw(sql, id).Scan(&reports).Error
	return
}
func GetUpdateHTReports() (reports []HTReport, err error) {
	duration := time.Now().Add(-30 * time.Second)
	updateTime := duration.UnixMilli()
	db := models.HT()
	sql := "select tirtp.plate_id as plate_id, tip.plate_name as plate_name, t.id as id ,t.report_name as report_name,t.publish_user_name as publish_user_name,t.publish_time as publish_time,t.is_delete as is_delete,t.status as status from t_iirp_report_to_plate tirtp left join t_iirp_report_info t on t.id=tirtp.report_id left JOIN t_iirp_plate tip on tip.id=tirtp.plate_id  where  t.report_file_path<>'' and t.update_time > ? order by t.id asc"
	err = db.Model(&HTReport{}).Raw(sql, updateTime).Scan(&reports).Error
	return
}
func GetPDFUrl(id int) (url string, err error) {
	db := models.HT()
	sql := "select report_file_path from t_iirp_report_info where id=?"
	err = db.Model(&HTReport{}).Raw(sql, id).Scan(&url).Error
	return
}

type HtQuery struct {
	Plate      string
	Permission string
}

func GetHTReportIdsByPermissionIds(query []HtQuery) (ids []int, err error) {
	return
}
