12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- package models
- import (
- "eta/eta_index_lib/utils"
- "github.com/beego/beego/v2/client/orm"
- "strconv"
- "time"
- )
- type BaseFromSmmClassify struct {
- ClassifyId int `orm:"column(classify_id);pk"`
- ClassifyName string `description:"分类名称"`
- ParentId int `description:"父级id"`
- SysUserId int `description:"创建人id"`
- SysUserRealName string `description:"创建人姓名"`
- Level int `description:"层级"`
- Sort int `description:"排序字段,越小越靠前,默认值:10"`
- ModifyTime time.Time `description:"修改时间"`
- CreateTime time.Time `description:"创建时间"`
- }
- func AddSmmClassify(item *BaseFromSmmClassify) (lastId int64, err error) {
- o := orm.NewOrm()
- lastId, err = o.Insert(item)
- return
- }
- type AddSmmClassifyReq struct {
- ClassifyName string `description:"分类名称"`
- ParentId int `description:"父级id,第一级传0"`
- Level int `description:"层级,第一级传0,其余传上一级的层级"`
- SysUserId int `description:"操作人id"`
- SysUserRealName string `description:"操作人真实名称"`
- }
- // 判断分类名称是否存在
- func GetSmmClassify(classifyName string, parentId int) (item *BaseFromSmmClassify, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM base_from_smm_classify WHERE parent_id=? AND classify_name=? `
- err = o.Raw(sql, parentId, classifyName).QueryRow(&item)
- return
- }
- // 添加指标分类
- func SaveSmmClassify(classifyName string, parentId, level int, sysUserId, sysUserName string) (classifyInfo *BaseFromSmmClassify, err error, errMsg string) {
- edbClassify, err := GetSmmClassify(classifyName, parentId)
- var isAdd bool
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- isAdd = true
- } else {
- errMsg = `判断名称是否已存在失败`
- return
- }
- }
- if edbClassify != nil && edbClassify.ClassifyId > 0 {
- classifyInfo = edbClassify
- return edbClassify, nil, ""
- } else {
- isAdd = true
- }
- if isAdd {
- sysUserIdInt, _ := strconv.Atoi(sysUserId)
- //获取该层级下最大的排序数
- maxSort, err := GetMysteelClassifyMaxSort(parentId)
- classifyInfo = &BaseFromSmmClassify{
- ClassifyName: classifyName,
- ParentId: parentId,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- SysUserId: sysUserIdInt,
- SysUserRealName: sysUserName,
- Level: level + 1,
- Sort: maxSort,
- }
- classifyId, err := AddSmmClassify(classifyInfo)
- if err != nil {
- errMsg = "保存分类失败"
- }
- classifyInfo.ClassifyId = int(classifyId)
- }
- return
- }
|