package models import ( "eta_gn/eta_task/global" "fmt" "github.com/rdlucklib/rdluck_tools/paging" "strings" "time" ) type Classify struct { Id int `gorm:"column:id;primaryKey"` // `orm:"column(id);pk"` ClassifyName string `description:"分类名称"` Sort int `json:"-"` ParentId int `description:"父级分类id"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"修改时间"` Abstract string `description:"栏目简介"` Descript string `description:"分享描述"` ReportAuthor string `description:"栏目作者"` AuthorDescript string `description:"作者简介"` ColumnImgUrl string `description:"栏目配图"` HeadImgUrl string `description:"头部banner"` AvatarImgUrl string `description:"头像"` ReportImgUrl string `description:"报告配图"` HomeImgUrl string `description:"首页配图"` ClassifyLabel string `description:"分类标签"` IsMassSend int `description:"1:群发,0:非群发"` ClassifyType int `gorm:"column:classify_type"` //`description:"分类类型:1-研报; IsRemind int `gorm:"column:is_remind"` //`description:"是否开启提醒:0-关闭;1-开启"` RemindTime string `gorm:"column:remind_time"` //`description:"提醒时间:可选00:00-23:59"` ReportNum int `gorm:"column:report_num"` //`description:"分类下的报告数"` LevelPath string `gorm:"column:level_path"` //`description:"分类的层级路径,英文逗号分隔"` } type ClassifyAddReq struct { ClassifyName string `description:"分类名称"` ParentId int `description:"父级分类id,没有父级分类传0"` Abstract string `description:"栏目简介"` Descript string `description:"分享描述"` ReportAuthor string `description:"栏目作者"` AuthorDescript string `description:"作者简介"` ColumnImgUrl string `description:"栏目配图"` ReportImgUrl string `description:"报告配图"` HeadImgUrl string `description:"头部banner"` AvatarImgUrl string `description:"头像"` HomeImgUrl string `description:"首页配图"` ClassifyLabel string `description:"分类标签"` } //func GetClassifyByName(classifyName string, parentId int) (item *Classify, err error) { // sql := `SELECT * FROM classify WHERE classify_name=? AND parent_id=? ` // o := orm.NewOrmUsingDB("rddp") // err = o.Raw(sql, classifyName, parentId).QueryRow(&item) // return //} func GetClassifyById(classifyId int) (item *Classify, err error) { //sql := `SELECT * FROM classify WHERE id=? ` //o := orm.NewOrmUsingDB("rddp") //err = o.Raw(sql, classifyId).QueryRow(&item) sql := `SELECT * FROM classify WHERE id=? ` err = global.DmSQL["data"].Raw(sql, classifyId).Find(&item).Error return } // //// 添加分类 //func AddClassify(item *Classify) (err error) { // o := orm.NewOrmUsingDB("rddp") // _, err = o.Insert(item) // return //} // //func GetReportCountByClassifyId(classifyId int) (count int, err error) { // o := orm.NewOrmUsingDB("rddp") // sql := `SELECT COUNT(1) AS count FROM report WHERE classify_id_second=? ` // err = o.Raw(sql, classifyId).QueryRow(&count) // return //} // //func GetClassifySubCountByClassifyId(classifyId int) (count int, err error) { // o := orm.NewOrmUsingDB("rddp") // sql := `SELECT COUNT(1) as num FROM classify AS a // INNER JOIN report AS b ON a.id=b.classify_id_second // WHERE a.parent_id=? ` // err = o.Raw(sql, classifyId).QueryRow(&count) // return //} // //func GetClassifySubCountByParentId(classifyId int) (count int, err error) { // sqlCount := ` // SELECT COUNT(1) as num FROM classify AS a // WHERE a.parent_id=? ` // o := orm.NewOrmUsingDB("rddp") // err = o.Raw(sqlCount, classifyId).QueryRow(&count) // return //} // //// 删除分类 //func DeleteClassify(classifyId int) (err error) { // sql := `DELETE FROM classify WHERE id=? ` // o := orm.NewOrmUsingDB("rddp") // _, err = o.Raw(sql, classifyId).Exec() // if err != nil { // return // } // deleteImgSql := `DELETE FROM banner WHERE classify_id=? ` // _, err = o.Raw(deleteImgSql, classifyId).Exec() // return //} // //// classifyName, abstract, descript string, parentId, classifyId int //// 修改分类 //func EditClassify(req *EditClassifyReq) (err error) { // o := orm.NewOrmUsingDB("rddp") // sql := `UPDATE classify SET classify_name = ?,abstract=?, parent_id= ?,descript=?,report_author=?,author_descript=?,column_img_url=?,head_img_url=?,avatar_img_url=?,report_img_url=?,home_img_url=?,classify_label=?, modify_time= NOW() WHERE id = ? ` // _, err = o.Raw(sql, req.ClassifyName, req.Abstract, req.ParentId, req.Descript, req.ReportAuthor, req.AuthorDescript, req.ColumnImgUrl, req.HeadImgUrl, req.AvatarImgUrl, req.ReportImgUrl, req.HomeImgUrl, req.ClassifyLabel, req.ClassifyId).Exec() // return //} // ////获取父级分类 // //func ParentClassify() (items []*Classify, err error) { // sql := `SELECT * FROM classify WHERE parent_id=0 order by id desc ` // o := orm.NewOrmUsingDB("rddp") // _, err = o.Raw(sql).QueryRows(&items) // return //} // //// 根据id获取分类详情 //func FindByIdClassify(classifyId int) (item *Classify, err error) { // sql := `SELECT * FROM classify WHERE id=? ` // o := orm.NewOrmUsingDB("rddp") // err = o.Raw(sql, classifyId).QueryRow(&item) // return //} type ClassifyList struct { Id int `gorm:"column:id;primaryKey"` // `orm:"column(id);pk"` ClassifyName string `description:"分类名称"` Sort int `json:"-"` ParentId int `description:"父级分类id"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"修改时间"` Abstract string `description:"简介"` Descript string `description:"描述"` ClassifyLabel string `description:"分类标签"` Child []*Classify `gorm:"-"` } type ClassifyListResp struct { List []*ClassifyList `gorm:"-"` Paging *paging.PagingItem `description:"分页数据"` } // //// 获取分类列表 //func GetClassifyList(startSize, pageSize int, keyWord, companyType string) (items []*ClassifyList, err error) { // sql := `` // companyTypeSqlStr := `` // if companyType == "ficc" { // companyTypeSqlStr = " AND id != 40 AND parent_id != 40 " // } else if companyType == "权益" { // companyTypeSqlStr = " AND (id = 40 or parent_id = 40) " // } // if keyWord != "" { // sql = `SELECT * FROM ( // SELECT * FROM classify // WHERE parent_id=0 ` + companyTypeSqlStr + ` AND classify_name LIKE '%` + keyWord + `%' // UNION // SELECT * FROM classify // WHERE id IN(SELECT parent_id FROM classify // WHERE parent_id>0 ` + companyTypeSqlStr + ` AND classify_name LIKE '%` + keyWord + `%') // )AS t // ORDER BY create_time ASC // LIMIT ?,? ` // } else { // sql = `SELECT * FROM classify WHERE parent_id=0 ` + companyTypeSqlStr + ` ORDER BY create_time ASC LIMIT ?,? ` // } // o := orm.NewOrmUsingDB("rddp") // _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items) // return //} // //func GetClassifyListCount(keyWord, companyType string) (count int, err error) { // sqlCount := `` // // companyTypeSqlStr := `` // if companyType == "ficc" { // companyTypeSqlStr = " AND id != 40 AND parent_id != 40 " // } else if companyType == "权益" { // companyTypeSqlStr = " AND (id = 40 or parent_id = 40) " // } // if keyWord != "" { // sqlCount = `SELECT COUNT(1) AS count FROM ( // SELECT * FROM classify // WHERE parent_id=0 ` + companyTypeSqlStr + ` AND classify_name LIKE '%` + keyWord + `%' // UNION // SELECT * FROM classify // WHERE id IN(SELECT parent_id FROM classify // WHERE parent_id>0 ` + companyTypeSqlStr + ` AND classify_name LIKE '%` + keyWord + `%') // )AS t ` // // } else { // sqlCount = `SELECT COUNT(1) AS count FROM classify WHERE parent_id=0 ` + companyTypeSqlStr // } // o := orm.NewOrmUsingDB("rddp") // err = o.Raw(sqlCount).QueryRow(&count) // return //} type CheckDeleteClassifyReq struct { ClassifyId int `description:"分类ID"` } type CheckDeleteClassifyResp struct { Code int `description:"编码:0:检测成功,可进行删除,1:分类不存在,2:该分类有关联报告,不允许删除,3:二级分类有关联报告,不允许删除,4:该分类下有关联分类,是否确认全部删除"` Msg string `description:"描述信息"` } type DeleteClassifyReq struct { ClassifyId int `description:"分类ID"` } type EditClassifyReq struct { ClassifyId int `description:"分类ID"` ClassifyName string `description:"分类名称"` ParentId int `description:"父级分类id"` Abstract string `description:"栏目简介"` Descript string `description:"分享描述"` ReportAuthor string `description:"栏目作者"` AuthorDescript string `description:"作者简介"` ColumnImgUrl string `description:"栏目配图"` HeadImgUrl string `description:"头部banner"` AvatarImgUrl string `description:"头像"` ReportImgUrl string `description:"报告配图"` HomeImgUrl string `description:"首页配图"` ClassifyLabel string `description:"分类标签"` } type FindByIdClassifyReq struct { ClassifyId int `description:"分类ID"` } //func GetClassifyChild(parentId int, keyWord string) (items []*Classify, err error) { // o := orm.NewOrmUsingDB("rddp") // sql := `` // if keyWord != "" { // sql = `SELECT * FROM classify WHERE parent_id=? AND classify_name LIKE '%` + keyWord + `%' ORDER BY create_time ASC ` // } else { // sql = `SELECT * FROM classify WHERE parent_id=? ORDER BY create_time ASC ` // } // _, err = o.Raw(sql, parentId).QueryRows(&items) // return //} func (m *Classify) TableName() string { return "classify" } func (m *Classify) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*Classify, err error) { fields := strings.Join(fieldArr, ",") if len(fieldArr) == 0 { fields = `*` } order := `ORDER BY create_time DESC` if orderRule != "" { order = ` ORDER BY ` + orderRule } sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order) err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error return }