123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- 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"`
- ChartPermissionName string `gorm:"column:chart_permission_name"`
- PermissionName string `gorm:"column:permission_name"`
- Sort int `gorm:"column:sort"`
- Enabled int `gorm:"column:enabled"`
- CreatedTime time.Time `gorm:"column:created_time"`
- LastUpdatedTime time.Time `gorm:"column:last_updated_time"`
- TeleconferenceSort int `gorm:"column:teleconference_sort"`
- Remark string `gorm:"column:remark"`
- ClassifyName string `gorm:"column:classify_name"`
- ProductName string `gorm:"column:product_name"`
- ProductId int `gorm:"column:product_id"`
- ImageURL string `gorm:"column:image_url"`
- ShowType int `gorm:"column:show_type"`
- IsOther int `gorm:"column:is_other"`
- IsReport int `gorm:"column:is_report"`
- CygxAuth int `gorm:"column:cygx_auth"`
- PermissionType int `gorm:"column:permission_type"`
- YbImgUrl string `gorm:"column:yb_img_url"`
- ProductPermissionName string `gorm:"column:product_permission_name"`
- PriceDrivenState int `gorm:"column:price_driven_state"`
- ImageUrlM string `gorm:"column:image_url_m"`
- ParentId int `gorm:"column:parent_id"`
- IsPublic int `gorm:"column: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"`
- 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"`
- 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
- }
|