package models import ( "eta_gn/eta_api/global" "eta_gn/eta_api/utils" "fmt" "time" ) const ( FiccProductId = 1 ) type ChartPermission struct { ChartPermissionId int `gorm:"column:chart_permission_id;primaryKey"` //`orm:"column(chart_permission_id);pk" gorm:"primaryKey" description:"问题ID" json:"chart_permission_id"` ChartPermissionName string `gorm:"column:chart_permission_name"` //`description:"名称" json:"chart_permission_name"` PermissionName string `gorm:"column:permission_name"` //`description:"权限名" json:"permission_name"` Sort int `gorm:"column:sort"` //`description:"排序" json:"sort"` Enabled int `gorm:"column:enabled"` //`description:"是否可用" json:"enabled"` CreatedTime time.Time `gorm:"column:created_time"` //`description:"创建时间" json:"created_time"` LastUpdatedTime time.Time `gorm:"column:last_updated_time"` //`description:"更新时间" json:"last_updated_time"` TeleconferenceSort int `gorm:"column:teleconference_sort"` //`description:"电话会类型排序" json:"teleconference_sort"` Remark string `gorm:"column:remark"` //`description:"备注" json:"remark"` ClassifyName string `gorm:"column:classify_name"` //`description:"分类名称" json:"classify_name"` ProductName string `gorm:"column:product_name"` //`description:"产品名称" json:"product_name"` ProductId int `gorm:"column:product_id"` //`description:"产品ID" json:"product_id"` ImageURL string `gorm:"column:image_url"` //`orm:"column(image_url);" description:"图片地址" json:"image_url"` ShowType int `gorm:"column:show_type"` //`description:"1:查研观向小程序展示" json:"show_type"` IsOther int `gorm:"column:is_other"` //`description:"是否是其他,用于查研观向小程序后台展示" json:"is_other"` IsReport int `gorm:"column:is_report"` //`description:"是否是报告,用于查研观向小程序前台报告展示" json:"is_report"` CygxAuth int `gorm:"column:cygx_auth"` //`description:"是否是权限,用于查研观向小程序前台权限校验" json:"cygx_auth"` PermissionType int `gorm:"column:permission_type"` //`description:"1主观,2客观" json:"permission_type"` YbImgUrl string `gorm:"column:yb_img_url"` //`description:"研报小程序报告列表icon" json:"yb_img_url"` ProductPermissionName string `gorm:"column:product_permission_name"` //`description:"种类权限名称" json:"product_permission_name"` PriceDrivenState int `gorm:"column:price_driven_state"` //`description:"品种价格驱动开启状态 0-关闭 1-开启" json:"price_driven_state"` ImageUrlM string `gorm:"column:image_url_m"` //`description:"图片地址(查研观向移动端)" json:"image_url_m"` ParentId int `gorm:"column:parent_id"` //`description:"父级权限id" json:"parent_id"` IsPublic int `gorm:"column:is_public"` //`description:"是否是公有权限1:公有权限,0私有权限" json:"is_public"` } type ChartPermissionItem struct { PermissionId int `description:"品种权限ID"` PermissionName string `description:"品种权限名称"` ParentId int `description:"父级ID"` IsPublic int `description:"是否是公有权限1:公有权限,0私有权限" ` Enabled int `description:"是否可用:1可用,0不可用" ` Sort int `description:"排序"` CreateTime string `description:"创建时间"` Child []*ChartPermissionItem } func (c *ChartPermission) Update(cols []string) (err error) { err = global.DmSQL["rddp"].Select(cols).Updates(c).Error return } type PermissionAddReq struct { PermissionName string `description:"品种权限名称"` ParentId int `description:"父级ID"` Enabled int `description:"是否可用 0禁用, 1启用"` //启用,禁用操作会关联二级品种 IsPublic int `description:"是否是公有权限1:公有权限,0私有权限"` } type PermissionEditReq struct { PermissionId int `description:"品种权限Id"` // 如果ID存在,则是更新操作,否则是新增操作 PermissionName string `description:"品种权限名称"` ParentId int `description:"父级ID"` Enabled int `description:"是否可用 0禁用, 1启用"` //启用,禁用操作会关联二级品种 IsPublic int `description:"是否是公有权限1:公有权限,0私有权限"` PublicPermissionIds []int `description:"公有权限的ID列表"` //一级品种没有公有私有属性 } type PermissionEnabledReq struct { PermissionId int `description:"品种权限Id"` // 如果ID存在,则是更新操作,否则是新增操作 Enabled int `description:"是否可用 0禁用, 1启用"` //启用,禁用操作会关联二级品种 } type PermissionMoveReq struct { PermissionId int `description:"品种id"` PrevPermissionId int `description:"上一个兄弟节点品种id"` NextPermissionId int `description:"下一个兄弟节点品种id"` } func (c *ChartPermission) SetEnabled(id, enabled int) (err error) { to := global.DmSQL["rddp"].Begin() defer func() { if err != nil { _ = to.Rollback() } else { _ = to.Commit() } }() sql := ` UPDATE chart_permission SET enabled =? WHERE id = ?` err = to.Exec(sql, enabled, id).Error if err != nil { return } sql = ` UPDATE chart_permission SET enabled =? WHERE parent_id = ?` err = to.Exec(sql, enabled, id).Error if err != nil { return } return } func (c *ChartPermission) Create() (err error) { err = global.DmSQL["rddp"].Create(c).Error return } func (c *ChartPermission) SetIsPublic(ids []int, parentId, isPublic int) (err error) { sql := `update chart_permission set is_public=? WHERE parent_id = ? and chart_permission_id IN (` + utils.GetOrmInReplace(len(ids)) + `)` err = global.DmSQL["rddp"].Exec(sql, isPublic, parentId, ids).Error return } func (c *ChartPermission) UpdateClassifyNameByParentId(parentId int, classifyName string) (err error) { sql := `update chart_permission set classify_name=? WHERE parent_id = ?` err = global.DmSQL["rddp"].Exec(sql, classifyName, parentId).Error return } func (c *ChartPermission) SetEnabledByParentId(parentId, enabled int) (err error) { sql := ` UPDATE chart_permission SET enabled =? WHERE parent_id = ?` err = global.DmSQL["rddp"].Exec(sql, enabled, parentId).Error return } func (c *ChartPermission) SetEnabledByChartPermissionId(chartPermissionId, enabled int) (err error) { sql := ` UPDATE chart_permission SET enabled =? WHERE chart_permission_id = ?` err = global.DmSQL["rddp"].Exec(sql, enabled, chartPermissionId).Error return } func (c *ChartPermission) GetItemById(chartPermissionId int) (item *ChartPermission, err error) { sql := `select * from chart_permission WHERE chart_permission_id = ?` err = global.DmSQL["rddp"].Raw(sql, chartPermissionId).First(&item).Error return } func (c *ChartPermission) GetItemsByCondition(condition string, pars []interface{}) (items []*ChartPermission, err error) { sql := `select * from chart_permission WHERE 1=1 ` + condition + ` order by sort asc, chart_permission_id asc` err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error return } func (c *ChartPermission) GetItemByCondition(condition string, pars []interface{}) (item *ChartPermission, err error) { sql := `select * from chart_permission WHERE 1=1 ` + condition err = global.DmSQL["rddp"].Raw(sql, pars...).First(&item).Error return } func UpdateChartPermissionSortByParentId(parentId, chartPermissionId, nowSort int, updateSort string, productId int) (err error) { sql := ` update chart_permission set sort = ` + updateSort + ` WHERE parent_id=? AND product_id = ? AND (sort > ? ` if chartPermissionId > 0 { sql += ` or ( chart_permission_id > ` + fmt.Sprint(chartPermissionId) + ` and sort = ` + fmt.Sprint(nowSort) + `))` } else { sql += `)` } err = global.DmSQL["rddp"].Exec(sql, parentId, productId, nowSort).Error return } func (c *ChartPermission) GetMaxSort() (maxSort int, err error) { sql := `select COALESCE(MAX(sort), 0) as max_sort from chart_permission ` err = global.DmSQL["rddp"].Raw(sql).Scan(&maxSort).Error return } func (c *ChartPermission) GetMaxSortByParentId(parentId int) (maxSort int, err error) { sql := `select COALESCE(MAX(sort), 0) as max_sort from chart_permission WHERE parent_id=? ` err = global.DmSQL["rddp"].Raw(sql, parentId).Scan(&maxSort).Error return } func (c *ChartPermission) GetFirstChartPermissionByParentId(parentId int) (item *ChartPermission, err error) { sql := `select * from chart_permission WHERE parent_id=? ORDER BY sort ASC, chart_permission_id ASC LIMIT 1` err = global.DmSQL["rddp"].Raw(sql, parentId).First(&item).Error return } func GetChartPermissionById(permissionId int) (item *ChartPermission, err error) { sql := `SELECT * FROM chart_permission WHERE chart_permission_id = ?` err = global.DmSQL["rddp"].Raw(sql, permissionId).First(&item).Error return } type SimpleChartPermission struct { ChartPermissionId int `description:"品种ID"` ChartPermissionName string `description:"品种名称"` Sort int `description:"排序"` Children []*SimpleChartPermission `gorm:"-" description:"子分类"` } func FormatChartPermission2Simple(origin *ChartPermission) (item *SimpleChartPermission) { if origin == nil { return } item = new(SimpleChartPermission) item.ChartPermissionId = origin.ChartPermissionId item.ChartPermissionName = origin.PermissionName item.Sort = origin.Sort return } func GetChartPermissionsByProductId() (list []*ChartPermission, err error) { sql := `SELECT * FROM chart_permission WHERE product_id = ? AND enabled = 1 ORDER BY parent_id ASC, sort ASC, created_time ASC` err = global.DmSQL["rddp"].Raw(sql, FiccProductId).Find(&list).Error return } func GetChartPermissionByIdList(permissionIdList []int) (items []*ChartPermission, err error) { num := len(permissionIdList) if num <= 0 { return } sql := `SELECT * FROM chart_permission WHERE chart_permission_id in (` + utils.GetOrmInReplace(num) + `) ` err = global.DmSQL["rddp"].Raw(sql, permissionIdList).Find(&items).Error return }