|
@@ -0,0 +1,209 @@
|
|
|
+package data_manage
|
|
|
+
|
|
|
+import (
|
|
|
+ "eta_gn/eta_api/global"
|
|
|
+ "eta_gn/eta_api/utils"
|
|
|
+ "fmt"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+// EdbCollectClassify 指标收藏分类
|
|
|
+type EdbCollectClassify struct {
|
|
|
+ EdbCollectClassifyId int `gorm:"primaryKey;autoIncrement;column:edb_collect_classify_id;type:int(10) unsigned;not null"`
|
|
|
+ ClassifyName string `gorm:"column:classify_name;type:varchar(255);not null;default:''"` // 分类名称
|
|
|
+ ParentId int `gorm:"column:parent_id;type:int(10) unsigned;not null;default:0"` // 父级Id
|
|
|
+ SysUserId int `gorm:"column:sys_user_id;type:int(10) unsigned;not null;default:0"` // 创建人Id
|
|
|
+ SysUserRealName string `gorm:"column:sys_user_real_name;type:varchar(128);not null"` // 创建人姓名
|
|
|
+ UniqueCode string `gorm:"unique;column:unique_code;type:varchar(64);not null;default:''"` // 唯一编码
|
|
|
+ Level int `gorm:"column:level;type:int(10) unsigned;not null;default:0"` // 层级
|
|
|
+ Sort int `gorm:"column:sort;type:int(10) unsigned;not null;default:0"` // 排序
|
|
|
+ RootId int `gorm:"column:root_id;type:int(10) unsigned;not null;default:0"` // 顶级Id
|
|
|
+ LevelPath string `gorm:"column:level_path;type:varchar(255);not null;default:''"`
|
|
|
+ CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间
|
|
|
+ ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 修改时间
|
|
|
+}
|
|
|
+
|
|
|
+func (m *EdbCollectClassify) TableName() string {
|
|
|
+ return "edb_collect_classify"
|
|
|
+}
|
|
|
+
|
|
|
+type EdbCollectClassifyCols struct {
|
|
|
+ PrimaryId string
|
|
|
+ ClassifyName string
|
|
|
+ ParentId string
|
|
|
+ SysUserId string
|
|
|
+ SysUserRealName string
|
|
|
+ UniqueCode string
|
|
|
+ Level string
|
|
|
+ Sort string
|
|
|
+ RootId string
|
|
|
+ LevelPath string
|
|
|
+ CreateTime string
|
|
|
+ ModifyTime string
|
|
|
+}
|
|
|
+
|
|
|
+func (m *EdbCollectClassify) Cols() EdbCollectClassifyCols {
|
|
|
+ return EdbCollectClassifyCols{
|
|
|
+ PrimaryId: "edb_collect_classify_id",
|
|
|
+ ClassifyName: "classify_name",
|
|
|
+ ParentId: "parent_id",
|
|
|
+ SysUserId: "sys_user_id",
|
|
|
+ SysUserRealName: "sys_user_real_name",
|
|
|
+ UniqueCode: "unique_code",
|
|
|
+ Level: "level",
|
|
|
+ Sort: "sort",
|
|
|
+ RootId: "root_id",
|
|
|
+ LevelPath: "level_path",
|
|
|
+ CreateTime: "create_time",
|
|
|
+ ModifyTime: "modify_time",
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func (m *EdbCollectClassify) Create() (err error) {
|
|
|
+ err = global.DmSQL["data"].Create(m).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *EdbCollectClassify) CreateMulti(items []*EdbCollectClassify) (err error) {
|
|
|
+ if len(items) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = global.DmSQL["data"].CreateInBatches(items, utils.MultiAddNum).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *EdbCollectClassify) Update(cols []string) (err error) {
|
|
|
+ err = global.DmSQL["data"].Select(cols).Updates(m).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *EdbCollectClassify) Remove() (err error) {
|
|
|
+ sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
|
|
|
+ err = global.DmSQL["data"].Exec(sql, m.EdbCollectClassifyId).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *EdbCollectClassify) MultiRemove(ids []int) (err error) {
|
|
|
+ if len(ids) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.Cols().PrimaryId, utils.GetOrmInReplace(len(ids)))
|
|
|
+ err = global.DmSQL["data"].Exec(sql, ids).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *EdbCollectClassify) RemoveByCondition(condition string, pars []interface{}) (err error) {
|
|
|
+ if condition == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ sql := fmt.Sprintf(`DELETE FROM %s WHERE %s`, m.TableName(), condition)
|
|
|
+ err = global.DmSQL["data"].Exec(sql, pars...).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *EdbCollectClassify) GetItemById(id int) (item *EdbCollectClassify, err error) {
|
|
|
+ sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
|
|
|
+ err = global.DmSQL["data"].Raw(sql, id).First(&item).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *EdbCollectClassify) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *EdbCollectClassify, err error) {
|
|
|
+ order := ``
|
|
|
+ if orderRule != "" {
|
|
|
+ order = ` ORDER BY ` + orderRule
|
|
|
+ }
|
|
|
+ sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
|
|
|
+ err = global.DmSQL["data"].Raw(sql, pars...).First(&item).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *EdbCollectClassify) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
|
|
|
+ sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
|
|
|
+ err = global.DmSQL["data"].Raw(sql, pars...).Scan(&count).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *EdbCollectClassify) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*EdbCollectClassify, err error) {
|
|
|
+ fields := strings.Join(fieldArr, ",")
|
|
|
+ if len(fieldArr) == 0 {
|
|
|
+ fields = `*`
|
|
|
+ }
|
|
|
+ order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
|
|
|
+ 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["data"].Raw(sql, pars...).Find(&items).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *EdbCollectClassify) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*EdbCollectClassify, err error) {
|
|
|
+ fields := strings.Join(fieldArr, ",")
|
|
|
+ if len(fieldArr) == 0 {
|
|
|
+ fields = `*`
|
|
|
+ }
|
|
|
+ order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
|
|
|
+ if orderRule != "" {
|
|
|
+ order = ` ORDER BY ` + orderRule
|
|
|
+ }
|
|
|
+ sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
|
|
|
+ pars = append(pars, startSize, pageSize)
|
|
|
+ err = global.DmSQL["data"].Raw(sql, pars...).Find(&items).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *EdbCollectClassify) GetSortMax(parentId int) (sort int, err error) {
|
|
|
+ sql := fmt.Sprintf(`SELECT COALESCE(MAX(%s), 0) FROM %s WHERE %s = ?`, m.Cols().Sort, m.TableName(), m.Cols().ParentId)
|
|
|
+ err = global.DmSQL["data"].Raw(sql, parentId).Scan(&sort).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// EdbCollectClassifyItem 指标收藏分类
|
|
|
+type EdbCollectClassifyItem struct {
|
|
|
+ ClassifyId int `description:"收藏ID"`
|
|
|
+ ClassifyName string `description:"指标收藏分类ID"`
|
|
|
+ ParentId int `description:"指标ID"`
|
|
|
+ UniqueCode string `description:"指标ID"`
|
|
|
+ Level int `description:"指标ID"`
|
|
|
+ Sort int `description:"指标ID"`
|
|
|
+}
|
|
|
+
|
|
|
+func (m *EdbCollectClassify) Format2Item() (item *EdbCollectClassifyItem) {
|
|
|
+ item = new(EdbCollectClassifyItem)
|
|
|
+ item.ClassifyId = m.EdbCollectClassifyId
|
|
|
+ item.ClassifyName = m.ClassifyName
|
|
|
+ item.ParentId = m.ParentId
|
|
|
+ item.UniqueCode = m.UniqueCode
|
|
|
+ item.Level = m.Level
|
|
|
+ item.Sort = m.Sort
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// EdbCollectClassifyListItem 指标收藏分类列表
|
|
|
+type EdbCollectClassifyListItem struct {
|
|
|
+ NodeType int `description:"类型: 1-分类; 2-指标"`
|
|
|
+ ClassifyId int `description:"分类ID"`
|
|
|
+ ClassifyName string `description:"分类名称"`
|
|
|
+ EdbInfoId int `description:"指标ID"`
|
|
|
+ EdbCode string `description:"指标编码"`
|
|
|
+ EdbName string `description:"指标名称"`
|
|
|
+ ParentId int `description:"父级ID"`
|
|
|
+ Level int `description:"层级"`
|
|
|
+ Sort int `description:"排序"`
|
|
|
+ UniqueCode string `description:"唯一编码, 指标的话用indexCode"`
|
|
|
+ Children []*EdbCollectClassifyListItem `description:"子分类"`
|
|
|
+}
|
|
|
+
|
|
|
+// EdbCollectClassifyAddReq 新增分类
|
|
|
+type EdbCollectClassifyAddReq struct {
|
|
|
+ ClassifyName string `description:"分类名称"`
|
|
|
+ ParentId int `description:"父级ID"`
|
|
|
+ Level int `description:"层级"`
|
|
|
+}
|
|
|
+
|
|
|
+// EdbCollectClassifyEditReq 编辑分类
|
|
|
+type EdbCollectClassifyEditReq struct {
|
|
|
+ ClassifyId int `description:"分类ID"`
|
|
|
+ ClassifyName string `description:"分类名称"`
|
|
|
+}
|