123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756 |
- package models
- import (
- sql2 "database/sql"
- "eta/eta_api/global"
- "eta/eta_api/utils"
- "fmt"
- "time"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- type Classify struct {
- Id int `gorm:"column:id;primaryKey" json:"id"`
- ClassifyName string `gorm:"column:classify_name" json:"classify_name"`
- Sort int `gorm:"column:sort" json:"sort"`
- ParentId int `gorm:"column:parent_id" json:"parent_id"`
- CreateTime time.Time `gorm:"column:create_time" json:"create_time"`
- ModifyTime time.Time `gorm:"column:modify_time" json:"modify_time"`
- Abstract string `gorm:"column:abstract" json:"abstract"`
- Descript string `gorm:"column:descript" json:"descript"`
- ReportAuthor string `gorm:"column:report_author" json:"report_author"`
- AuthorDescript string `gorm:"column:author_descript" json:"author_descript"`
- ColumnImgUrl string `gorm:"column:column_img_url" json:"column_img_url"`
- HeadImgUrl string `gorm:"column:head_img_url" json:"head_img_url"`
- AvatarImgUrl string `gorm:"column:avatar_img_url" json:"avatar_img_url"`
- ReportImgUrl string `gorm:"column:report_img_url" json:"report_img_url"`
- HomeImgUrl string `gorm:"column:home_img_url" json:"home_img_url"`
- ClassifyLabel string `gorm:"column:classify_label" json:"classify_label"`
- ShowType int `gorm:"column:show_type" json:"show_type"`
- HasTeleconference int `gorm:"column:has_teleconference" json:"has_teleconference"`
- VipTitle string `gorm:"column:vip_title" json:"vip_title"`
- IsShow int `gorm:"column:is_show" json:"is_show"`
- YbFiccSort int `gorm:"column:yb_ficc_sort" json:"yb_ficc_sort"`
- YbFiccIcon string `gorm:"column:yb_ficc_icon" json:"yb_ficc_icon"`
- YbFiccPcIcon string `gorm:"column:yb_ficc_pc_icon" json:"yb_ficc_pc_icon"`
- YbIconUrl string `gorm:"column:yb_icon_url" json:"yb_icon_url"`
- YbBgUrl string `gorm:"column:yb_bg_url" json:"yb_bg_url"`
- YbListImg string `gorm:"column:yb_list_img" json:"yb_list_img"`
- YbShareBgImg string `gorm:"column:yb_share_bg_img" json:"yb_share_bg_img"`
- YbRightBanner string `gorm:"column:yb_right_banner" json:"yb_right_banner"`
- RelateTel int `gorm:"column:relate_tel" json:"relate_tel"`
- RelateVideo int `gorm:"column:relate_video" json:"relate_video"`
- IsMassSend int `gorm:"column:is_mass_send" json:"is_mass_send"`
- Enabled int `gorm:"column:enabled" json:"enabled"`
- Level int `gorm:"column:level" json:"level"`
- HasChild int `gorm:"column:has_child" json:"has_child"`
- ReportDetailShowType int `gorm:"column:report_detail_show_type" json:"report_detail_show_type"`
- }
- type ClassifyVO struct {
- Id int `gorm:"column:id;primaryKey"`
- ClassifyName string `description:"分类名称"`
- Sort int `json:"-"`
- ParentId int `description:"父级分类id"`
- ClassifyLabel string `description:"分类标签"`
- Enabled int `description:"是否可用,1可用,0禁用"`
- Level int `description:"层级"`
- Children *[]ClassifyVO
- }
- type ClassifyAddReq struct {
- ClassifyName string `description:"分类名称"`
- ParentId int `description:"父级分类id,没有父级分类传0"`
- ChartPermissionIdList []int `description:"权限id数组"`
-
- }
- func (c *Classify) Delete(childIds []int) (err error) {
- tx := global.DbMap[utils.DbNameReport].Begin()
- defer func() {
- if err != nil {
- tx.Rollback()
- } else {
- tx.Commit()
- }
- }()
-
- err = tx.Delete(c).Error
- if err != nil {
- return
- }
-
- if len(childIds) > 0 {
- sql := `DELETE FROM classify WHERE id IN (` + utils.GetOrmInReplace(len(childIds)) + `)`
- err = tx.Exec(sql, childIds).Error
- if err != nil {
- return
- }
- }
-
- if c.ParentId > 0 {
- var count int
- sql := `SELECT COUNT(*) FROM classify WHERE parent_id=? `
- var countNull sql2.NullInt64
- err = tx.Raw(sql, c.ParentId).Scan(&countNull).Error
- if err != nil {
- return
- }
- if countNull.Valid {
- count = int(countNull.Int64)
- }
- if err != nil {
- return
- }
- if count == 0 {
- sql = `UPDATE classify SET has_child=0 WHERE id=? `
- err = tx.Exec(sql, c.ParentId).Error
- if err != nil {
- return
- }
- }
- }
- deleteImgSql := `DELETE FROM banner WHERE classify_id=? `
- err = tx.Exec(deleteImgSql, c.Id).Error
- return
- }
- func GetClassifyByName(classifyName string, parentId int) (item *Classify, err error) {
- sql := `SELECT * FROM classify WHERE classify_name=? AND parent_id=? `
- err = global.DbMap[utils.DbNameReport].Raw(sql, classifyName, parentId).First(&item).Error
- return
- }
- func GetClassifyById(classifyId int) (item *Classify, err error) {
- sql := `SELECT * FROM classify WHERE id=? `
- err = global.DbMap[utils.DbNameReport].Raw(sql, classifyId).First(&item).Error
- return
- }
- func AddClassify(item *Classify) (err error) {
- err = global.DbMap[utils.DbNameReport].Create(item).Error
- return
- }
- func GetReportCountByClassifyId(classifyId int) (count int, err error) {
- sql := `SELECT COUNT(1) AS count FROM report WHERE classify_id_second=? `
- var countNull sql2.NullInt64
- err = global.DbMap[utils.DbNameReport].Raw(sql, classifyId).Scan(&countNull).Error
- if err != nil {
- return
- }
- if countNull.Valid {
- count = int(countNull.Int64)
- }
- return
- }
- func GetClassifySubCountByClassifyId(classifyId int) (count int, err error) {
- 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=? `
- var countNull sql2.NullInt64
- err = global.DbMap[utils.DbNameReport].Raw(sql, classifyId).Scan(&countNull).Error
- if err != nil {
- return
- }
- if countNull.Valid {
- count = int(countNull.Int64)
- }
- return
- }
- func GetClassifySubCountByParentId(classifyId int) (count int, err error) {
- sqlCount := `
- SELECT COUNT(1) as num FROM classify AS a
- WHERE a.parent_id=? `
- var countNull sql2.NullInt64
- err = global.DbMap[utils.DbNameReport].Raw(sqlCount, classifyId).Scan(&countNull).Error
- if err != nil {
- return
- }
- if countNull.Valid {
- count = int(countNull.Int64)
- }
- return
- }
- func FindByIdClassify(classifyId int) (item *Classify, err error) {
- sql := `SELECT * FROM classify WHERE id=? `
- err = global.DbMap[utils.DbNameReport].Raw(sql, classifyId).First(&item).Error
- return
- }
- type ClassifyList struct {
- Id int `gorm:"column:id"`
- ClassifyName string `gorm:"column:classify_name"`
- Sort int `gorm:"column:sort"`
- ParentId int `gorm:"column:parent_id"`
- CreateTime time.Time `gorm:"column:create_time"`
- ModifyTime time.Time `gorm:"column:modify_time"`
- Abstract string `gorm:"column:abstract"`
- Descript string `gorm:"column:descript"`
- ClassifyLabel string `gorm:"column:classify_label"`
- ShowType int `gorm:"column:show_type"`
- HasTeleconference int `gorm:"column:has_teleconference"`
- IsShow int `gorm:"column:is_show"`
- YbFiccSort int `gorm:"column:yb_ficc_sort"`
- YbFiccIcon string `gorm:"column:yb_ficc_icon"`
- YbFiccPcIcon string `gorm:"column:yb_ficc_pc_icon"`
- YbIconUrl string `gorm:"column:yb_icon_url"`
- YbBgUrl string `gorm:"column:yb_bg_url"`
- YbListImg string `gorm:"column:yb_list_img"`
- YbShareBgImg string `gorm:"column:yb_share_bg_img"`
- YbRightBanner string `gorm:"column:yb_right_banner"`
- RelateTel int `gorm:"column:relate_tel"`
- RelateVideo int `gorm:"column:relate_video"`
- Enabled int `gorm:"column:enabled"`
- Level int `gorm:"column:level"`
- HasChild int `gorm:"column:has_child"`
- Child []*ClassifyList `gorm:"-"`
- ClassifyMenuId int `gorm:"-"`
- ClassifyMenuList []*ClassifyMenu `gorm:"-"`
- ChartPermissionIdList []int `gorm:"-"`
- IsEnableDelete int `gorm:"-" description:"是否允许删除: 0-否; 1-是"`
- }
- type ClassifyItem struct {
- Classify
- ClassifyMenuId int `description:"二级分类-子目录ID"`
- ClassifyMenuList []*ClassifyMenu
- ChartPermissionIdList []int `description:"绑定的权限ID"`
- Child []*ClassifyItem
- }
- type ClassifyListResp struct {
- List []*ClassifyList
- }
- type ClassifyPermissionListResp struct {
- List []*ClassifyList
- Paging *paging.PagingItem `description:"分页数据"`
- }
- 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"`
- ClassifyAddReq
- }
- type FindByIdClassifyReq struct {
- ClassifyId int `description:"分类ID"`
- }
- func GetClassifyChild(parentId int, keyWord string) (items []*Classify, err error) {
- sql := ``
- pars := make([]interface{}, 0)
- if keyWord != "" {
- sql = `SELECT * FROM classify WHERE classify_name LIKE ? AND parent_id=? ORDER BY create_time ASC `
- pars = append(pars, utils.GetLikeKeyword(keyWord))
- } else {
- sql = `SELECT * FROM classify WHERE parent_id=? ORDER BY create_time ASC `
- }
- pars = append(pars, parentId)
- err = global.DbMap[utils.DbNameReport].Raw(sql, pars...).Find(&items).Error
- return
- }
- type EditClassifyPermissionReq struct {
- ClassifyId int `description:"分类ID"`
- ChartPermissionIdList []int `description:"权限id数组"`
- }
- func GetAllClassify() (list []*Classify, err error) {
- o := global.DbMap[utils.DbNameReport]
- sql := ` SELECT * FROM classify `
- err = o.Raw(sql).Find(&list).Error
- return
- }
- func GetAllClassifyWithDesc() (list []*Classify, err error) {
- o := global.DbMap[utils.DbNameReport]
- sql := ` SELECT * FROM classify ORDER BY id DESC `
- err = o.Raw(sql).Find(&list).Error
- return
- }
- func (classifyInfo *Classify) UpdateClassify(cols []string) (err error) {
- err = global.DbMap[utils.DbNameReport].Select(cols).Updates(classifyInfo).Error
- return
- }
- type SimpleClassifyList struct {
- Id int `description:"分类ID"`
- ClassifyName string `description:"分类名称"`
- ParentId int `description:"父级ID"`
- Sort int `description:"排序"`
- Child []*SimpleClassifyList
- }
- func GetClassifyByCondition(condition, orderRule string, pars []interface{}) (items []*SimpleClassifyList, err error) {
- sql := `SELECT * FROM classify WHERE 1 = 1 `
- if condition != `` {
- sql += condition
- }
- order := `sort ASC, create_time ASC`
- if orderRule != `` {
- order = orderRule
- }
- sql += ` ORDER BY ` + order
- err = global.DbMap[utils.DbNameReport].Raw(sql, pars...).Find(&items).Error
- return
- }
- type RelateTelSecClassifyWithPermissions struct {
- Id int `description:"分类ID"`
- ClassifyName string `description:"分类名称"`
- ChartPermissionIds string `description:"权限IDs"`
- }
- func UpdateClassifySortByParentId(parentId, permissionId, nowSort int, updateSort string) (err error) {
- sql := ` update classify set sort = ` + updateSort + ` WHERE parent_id=? AND sort > ? `
- if permissionId > 0 {
- sql += ` or ( id > ` + fmt.Sprint(permissionId) + ` and sort = ` + fmt.Sprint(nowSort) + `)`
- }
- err = global.DbMap[utils.DbNameReport].Exec(sql, parentId, nowSort).Error
- return
- }
- func (classifyInfo *Classify) GetMaxSortByParentId(parentId int) (maxSort int, err error) {
- sql := `SELECT max(sort) AS sort FROM classify WHERE parent_id = ? `
- if utils.DbDriverName == utils.DbDriverByDm {
- sql = `SELECT COALESCE(MAX(sort), 0) AS sort FROM classify WHERE parent_id = ? `
- }
- var maxNull sql2.NullInt64
- err = global.DbMap[utils.DbNameReport].Raw(sql, parentId).Scan(&maxNull).Error
- if err != nil {
- return
- }
- if maxNull.Valid {
- maxSort = int(maxNull.Int64)
- }
- return
- }
- func (classifyInfo *Classify) GetMaxSort() (maxSort int, err error) {
- sql := `SELECT COALESCE(MAX(sort), 0) AS sort FROM classify`
- var maxNull sql2.NullInt64
- err = global.DbMap[utils.DbNameReport].Raw(sql).Scan(&maxNull).Error
- if err != nil {
- return
- }
- if maxNull.Valid {
- maxSort = int(maxNull.Int64)
- }
- return
- }
- func (classifyInfo *Classify) GetFirstClassifyByParentId(parentId int) (item *Classify, err error) {
- sql := `SELECT * FROM classify WHERE parent_id = ? order by sort asc, id asc limit 1`
- err = global.DbMap[utils.DbNameReport].Raw(sql, parentId).First(&item).Error
- return
- }
- type ClassifyMoveReq struct {
- ClassifyId int `description:"分类ID"`
- PrevClassifyId int `description:"上一个兄弟节点分类id"`
- NextClassifyId int `description:"下一个兄弟节点分类id"`
- }
- type ClassifySetEnabledReq struct {
- ClassifyId int `description:"分类ID"`
- Enabled int `description:"是否可用,1可用,0禁用"`
- }
- func (classifyInfo *Classify) SetEnabled(id, enabled int) (err error) {
- to := global.DbMap[utils.DbNameReport].Begin()
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- sql := ` UPDATE classify SET enabled =? WHERE id = ?`
- err = to.Exec(sql, enabled, id).Error
- if err != nil {
- return
- }
- sql = ` UPDATE classify SET enabled =? WHERE parent_id = ?`
- err = to.Exec(sql, enabled, id).Error
- if err != nil {
- return
- }
- return
- }
- func GetCountClassifyChildByParentId(parentId int) (total int, err error) {
- sql := `SELECT count(1) AS total FROM classify WHERE parent_id = ? `
- var countNull sql2.NullInt64
- err = global.DbMap[utils.DbNameReport].Raw(sql, parentId).Scan(&countNull).Error
- if err != nil {
- return
- }
- if countNull.Valid {
- total = int(countNull.Int64)
- }
- return
- }
- func GetClassifyListByKeyword(keyWord string, enabled int) (items []*ClassifyList, err error) {
- sql := ``
- pars := make([]interface{}, 0)
- sql = `SELECT * FROM classify WHERE 1=1 `
- if enabled == 1 {
- sql += ` AND enabled = 1 `
- }
- if keyWord != `` {
- sql += ` AND classify_name LIKE ? `
- pars = utils.GetLikeKeywordPars(pars, keyWord, 1)
- }
- sql += ` ORDER BY sort ASC, create_time ASC`
- err = global.DbMap[utils.DbNameReport].Raw(sql, pars...).Find(&items).Error
- return
- }
- func GetClassifyListByParentIdList(parentClassifyIdList []int) (items []*ClassifyList, err error) {
- num := len(parentClassifyIdList)
- if num <= 0 {
- return
- }
- sql := `SELECT * FROM classify WHERE id in (` + utils.GetOrmInReplace(num) + `) ORDER BY sort ASC, create_time ASC`
- err = global.DbMap[utils.DbNameReport].Raw(sql, parentClassifyIdList).Find(&items).Error
- return
- }
- func GetClassifyListByIdList(classifyIdList []int) (items []*Classify, err error) {
- num := len(classifyIdList)
- if num <= 0 {
- return
- }
- sql := `SELECT * FROM classify WHERE id IN (` + utils.GetOrmInReplace(num) + `) `
- err = global.DbMap[utils.DbNameReport].Raw(sql, classifyIdList).Find(&items).Error
- return
- }
- func GetClassifyListByParentId(parentId int) (items []*Classify, err error) {
- sql := `SELECT * FROM classify WHERE parent_id = ? and enabled = 1`
- err = global.DbMap[utils.DbNameReport].Raw(sql, parentId).Find(&items).Error
- return items, err
- }
|