package chart_collect import ( "github.com/beego/beego/v2/client/orm" "github.com/rdlucklib/rdluck_tools/paging" "time" ) type ChartCollect struct { ChartCollectId int `orm:"column(chart_collect_id);pk"` UserId int `orm:"column(user_id)" description:"用户ID"` BusinessCode string `orm:"column(business_code)" description:"客户编码"` RealName string `orm:"column(real_name)" description:"用户姓名"` CollectTime time.Time `orm:"column(collect_time)" description:"收藏时间"` ChartInfoId int `orm:"column(chart_info_id)" description:"图表ID"` CollectClassifyId int `orm:"column(collect_classify_id)" description:"收藏的分类ID"` ChartSource int `orm:"column(chart_source)" description:"图表来源"` CreateTime time.Time `orm:"column(create_time)" description:"创建时间"` ModifyTime time.Time `orm:"column(modify_time)" description:"修改时间"` } type ChartCollectAddReq struct { ChartInfoId int `description:"图表id"` CollectClassifyId int `description:"收藏分类id"` } type ChartCollectView struct { ChartCollectId int `orm:"column(chart_collect_id);pk"` ChartInfoId int `description:"图表id"` UserId int `description:"用户id"` CreateTime time.Time `description:"创建时间"` CollectTime string `description:"收藏时间"` CollectClassifyId int ChartName string `description:"来源名称"` ChartNameEn string `description:"英文图表名称"` ChartImage string `description:"图表图片"` UniqueCode string `description:"图表唯一编码"` } type ChartCollectListResp struct { Paging *paging.PagingItem List []*ChartCollectView } type ChartCollectEditReq struct { ChartCollectId int `description:"我的图表主键"` CurrentClassifyId int `description:"当前分类ID"` ClassifyId []int `description:"分类id,数组形式"` } func GetChartCollectPageByCondition(condition string, pars []interface{}, currentIndex, pageSize int) (item []*ChartCollectView, err error) { o := orm.NewOrm() //sql := ` SELECT * FROM chart_collect WHERE 1=1 ` sql := `SELECT a.*,b.chart_name_en,b.chart_name, b.unique_code, b.chart_image FROM chart_collect AS a INNER JOIN chart_info AS b ON a.chart_info_id=b.chart_info_id WHERE 1=1 ` if condition != "" { sql += condition } sql += ` GROUP BY a.chart_info_id order by a.chart_collect_id desc limit ?,?` _, err = o.Raw(sql, pars, currentIndex, pageSize).QueryRows(&item) return } func GetChartCollectDetailByCondition(condition string, pars []interface{}) (item []*ChartCollectView, err error) { o := orm.NewOrm() //sql := ` SELECT * FROM chart_collect WHERE 1=1 ` sql := `SELECT a.*,b.chart_name_en,b.chart_name, b.unique_code, b.chart_image FROM chart_collect AS a INNER JOIN chart_info AS b ON a.chart_info_id=b.chart_info_id WHERE 1=1 ` if condition != "" { sql += condition } sql += ` GROUP BY a.chart_info_id` _, err = o.Raw(sql, pars).QueryRows(&item) return } func GetChartCollectCountByCondition(condition string, pars []interface{}) (total int64, err error) { o := orm.NewOrm() sql := `SELECT a.chart_info_id FROM chart_collect AS a INNER JOIN chart_info AS b ON a.chart_info_id=b.chart_info_id WHERE 1=1 ` if condition != "" { sql += condition } sql += ` GROUP BY a.chart_info_id` totalSql := `select count(1) as total from (` + sql + `) as t` err = o.Raw(totalSql, pars).QueryRow(&total) return } // ModifyChartClassifyPublicReq 修改我的图库分类是否可见 type ModifyChartClassifyPublicReq struct { ClassifyId int `description:"分类id"` IsPublic int `description:"是否所有人可见,0:仅自己可见,1:所有人可见"` } // CopyChartClassifyReq 复制我的图库分类 type CopyChartClassifyReq struct { ClassifyId int `description:"分类id"` } // ChartCollectClassifyItem 我的图表分类信息 type ChartCollectClassifyItem struct { CollectClassifyId int `description:"分类ID"` ClassifyName string `description:"分类名称"` UserId int `description:"创建人id"` /*IsPublic int `description:"是否公共分类"` IsCompanyPublic int `description:"是否为用户公共分类"`*/ ChartNum int `description:"分类下的图表数量"` } // ClassifyIdAndNum 我的图表-分类ID及图表数 type ClassifyIdAndNum struct { ClassifyId int `description:"分类ID"` ChartNum int `description:"分类下的图表数量"` } type ChartCollectAddResp struct { CollectMsg string `description:"提示信息"` } func GetChartCollectByUserIdChartInfoId(userId, chartInfoId int) (item *ChartCollect, err error) { o := orm.NewOrm() sql := ` SELECT * FROM chart_collect WHERE user_id=? AND chart_info_id=? ` err = o.Raw(sql, userId, chartInfoId).QueryRow(&item) return } type ChartCollectEsItem struct { UserChartInfoId string ChartInfoId int `description:"图表id"` UserId int `description:"用户id"` CollectTime time.Time `description:"收藏时间"` ChartName string `description:"来源名称"` ChartNameEn string `description:"英文图表名称"` ChartImage string `description:"图表图片"` UniqueCode string `description:"图表唯一编码"` ChartClassifyId int `description:"图表分类id"` SysUserId int SysUserRealName string CreateTime time.Time ModifyTime time.Time ChartSource int CollectClassifyIds string ChartCollectClassifyNames string } // GetChartCollectByChartInfoIdAndUserIdByCondition 获图表收藏数据 func GetChartCollectByChartInfoIdAndUserIdByCondition(condition string, pars []interface{}) (item []*ChartCollectEsItem, err error) { o := orm.NewOrm() sql := ` SELECT a.user_id, CONCAT(a.user_id,"_", a.chart_info_id) as user_chart_info_id, max(a.collect_time) as collect_time, b.chart_info_id,b.chart_name,b.chart_name_en,b.chart_image,b.unique_code,b.chart_classify_id,b.sys_user_id,b.sys_user_real_name,b.create_time,b.modify_time,b.source as chart_source, GROUP_CONCAT(DISTINCT d.classify_name) AS chart_collect_classify_names,GROUP_CONCAT(DISTINCT d.collect_classify_id) AS collect_classify_ids FROM chart_collect AS a INNER JOIN chart_info AS b ON a.chart_info_id=b.chart_info_id INNER JOIN chart_collect_classify AS d ON a.collect_classify_id=d.collect_classify_id WHERE 1=1 ` if condition != "" { sql += condition } sql += " GROUP BY a.chart_info_id,a.user_id ORDER BY a.collect_time Desc, a.chart_collect_id DESC " _, err = o.Raw(sql, pars).QueryRows(&item) return }