|
@@ -3,7 +3,6 @@ package models
|
|
|
import (
|
|
|
"eta_gn/eta_api/utils"
|
|
|
"fmt"
|
|
|
- "github.com/beego/beego/v2/client/orm"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -13,30 +12,30 @@ const (
|
|
|
|
|
|
// ChartPermission 报告权限表
|
|
|
type ChartPermission struct {
|
|
|
- ChartPermissionId int `orm:"column(chart_permission_id);pk" description:"问题ID" json:"chart_permission_id"`
|
|
|
- ChartPermissionName string `description:"名称" json:"chart_permission_name"`
|
|
|
- PermissionName string `description:"权限名" json:"permission_name"`
|
|
|
- Sort int `description:"排序" json:"sort"`
|
|
|
- Enabled int `description:"是否可用" json:"enabled"`
|
|
|
- CreatedTime time.Time `description:"创建时间" json:"created_time"`
|
|
|
- LastUpdatedTime time.Time `description:"更新时间" json:"last_updated_time"`
|
|
|
- TeleconferenceSort int `description:"电话会类型排序" json:"teleconference_sort"`
|
|
|
- Remark string `description:"备注" json:"remark"`
|
|
|
- ClassifyName string `description:"分类名称" json:"classify_name"`
|
|
|
- ProductName string `description:"产品名称" json:"product_name"`
|
|
|
- ProductId int `description:"产品ID" json:"product_id"`
|
|
|
- ImageURL string `orm:"column(image_url);" description:"图片地址" json:"image_url"`
|
|
|
- ShowType int `description:"1:查研观向小程序展示" json:"show_type"`
|
|
|
- IsOther int `description:"是否是其他,用于查研观向小程序后台展示" json:"is_other"`
|
|
|
- IsReport int `description:"是否是报告,用于查研观向小程序前台报告展示" json:"is_report"`
|
|
|
- CygxAuth int `description:"是否是权限,用于查研观向小程序前台权限校验" json:"cygx_auth"`
|
|
|
- PermissionType int `description:"1主观,2客观" json:"permission_type"`
|
|
|
- YbImgUrl string `description:"研报小程序报告列表icon" json:"yb_img_url"`
|
|
|
- ProductPermissionName string `description:"种类权限名称" json:"product_permission_name"`
|
|
|
- PriceDrivenState int `description:"品种价格驱动开启状态 0-关闭 1-开启" json:"price_driven_state"`
|
|
|
- ImageUrlM string `description:"图片地址(查研观向移动端)" json:"image_url_m"`
|
|
|
- ParentId int `description:"父级权限id" json:"parent_id"`
|
|
|
- IsPublic int `description:"是否是公有权限1:公有权限,0私有权限" json:"is_public"`
|
|
|
+ ChartPermissionId int `gorm:"column:chart_permission_id"` //`orm:"column(chart_permission_id);pk" 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 {
|
|
@@ -52,8 +51,9 @@ type ChartPermissionItem struct {
|
|
|
|
|
|
// Update 更新
|
|
|
func (c *ChartPermission) Update(cols []string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- _, err = o.Update(c, cols...)
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //_, err = o.Update(c, cols...)
|
|
|
+ err = DmSQL["rddp"].Select(cols).Updates(c).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -86,8 +86,9 @@ type PermissionMoveReq struct {
|
|
|
}
|
|
|
|
|
|
func (c *ChartPermission) SetEnabled(id, enabled int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- to, err := o.Begin()
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //to, err := o.Begin()
|
|
|
+ to := DmSQL["rddp"].Begin()
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -99,12 +100,14 @@ func (c *ChartPermission) SetEnabled(id, enabled int) (err error) {
|
|
|
}
|
|
|
}()
|
|
|
sql := ` UPDATE chart_permission SET enabled =? WHERE id = ?`
|
|
|
- _, err = to.Raw(sql, enabled, id).Exec()
|
|
|
+ //_, err = to.Raw(sql, enabled, id).Exec()
|
|
|
+ err = to.Exec(sql, enabled, id).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
sql = ` UPDATE chart_permission SET enabled =? WHERE parent_id = ?`
|
|
|
- _, err = to.Raw(sql, enabled, id).Exec()
|
|
|
+ //_, err = to.Raw(sql, enabled, id).Exec()
|
|
|
+ err = to.Exec(sql, enabled, id).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -113,121 +116,148 @@ func (c *ChartPermission) SetEnabled(id, enabled int) (err error) {
|
|
|
|
|
|
// Create 新增权限
|
|
|
func (c *ChartPermission) Create() (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- id, err := o.Insert(c)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- c.ChartPermissionId = int(id)
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //id, err := o.Insert(c)
|
|
|
+ //if err != nil {
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //c.ChartPermissionId = int(id)
|
|
|
+ err = DmSQL["rddp"].Create(c).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// SetIsPublic 更新公有私有权限
|
|
|
func (c *ChartPermission) SetIsPublic(ids []int, parentId, isPublic int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //sql := `update chart_permission set is_public=? WHERE parent_id = ? and chart_permission_id IN (` + utils.GetOrmInReplace(len(ids)) + `)`
|
|
|
+ //_, err = o.Raw(sql, isPublic, parentId, ids).Exec()
|
|
|
sql := `update chart_permission set is_public=? WHERE parent_id = ? and chart_permission_id IN (` + utils.GetOrmInReplace(len(ids)) + `)`
|
|
|
- _, err = o.Raw(sql, isPublic, parentId, ids).Exec()
|
|
|
+ err = DmSQL["rddp"].Exec(sql, isPublic, parentId, ids).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// UpdatesByParentId 更新启动禁用
|
|
|
func (c *ChartPermission) UpdateClassifyNameByParentId(parentId int, classifyName string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //sql := `update chart_permission set classify_name=? WHERE parent_id = ?`
|
|
|
+ //_, err = o.Raw(sql, classifyName, parentId).Exec()
|
|
|
sql := `update chart_permission set classify_name=? WHERE parent_id = ?`
|
|
|
- _, err = o.Raw(sql, classifyName, parentId).Exec()
|
|
|
+ err = DmSQL["rddp"].Exec(sql, classifyName, parentId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// SetEnabledByParentId 更新启动禁用
|
|
|
func (c *ChartPermission) SetEnabledByParentId(parentId, enabled int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //sql := ` UPDATE chart_permission SET enabled =? WHERE parent_id = ?`
|
|
|
+ //_, err = o.Raw(sql, enabled, parentId).Exec()
|
|
|
sql := ` UPDATE chart_permission SET enabled =? WHERE parent_id = ?`
|
|
|
- _, err = o.Raw(sql, enabled, parentId).Exec()
|
|
|
+ err = DmSQL["rddp"].Exec(sql, enabled, parentId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// SetEnabledByChartPermissionId 更新启动禁用
|
|
|
func (c *ChartPermission) SetEnabledByChartPermissionId(chartPermissionId, enabled int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //sql := ` UPDATE chart_permission SET enabled =? WHERE chart_permission_id = ?`
|
|
|
+ //_, err = o.Raw(sql, enabled, chartPermissionId).Exec()
|
|
|
sql := ` UPDATE chart_permission SET enabled =? WHERE chart_permission_id = ?`
|
|
|
- _, err = o.Raw(sql, enabled, chartPermissionId).Exec()
|
|
|
+ err = DmSQL["rddp"].Exec(sql, enabled, chartPermissionId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetItemById 查询品种
|
|
|
func (c *ChartPermission) GetItemById(chartPermissionId int) (item *ChartPermission, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //sql := `select * from chart_permission WHERE chart_permission_id = ?`
|
|
|
+ //err = o.Raw(sql, chartPermissionId).QueryRow(&item)
|
|
|
sql := `select * from chart_permission WHERE chart_permission_id = ?`
|
|
|
- err = o.Raw(sql, chartPermissionId).QueryRow(&item)
|
|
|
+ err = DmSQL["rddp"].Raw(sql, chartPermissionId).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetItemsByCondition 查询列表
|
|
|
func (c *ChartPermission) GetItemsByCondition(condition string, pars []interface{}) (items []*ChartPermission, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //sql := `select * from chart_permission WHERE 1=1 ` + condition + ` order by sort asc, chart_permission_id asc`
|
|
|
+ //_, err = o.Raw(sql, pars).QueryRows(&items)
|
|
|
sql := `select * from chart_permission WHERE 1=1 ` + condition + ` order by sort asc, chart_permission_id asc`
|
|
|
- _, err = o.Raw(sql, pars).QueryRows(&items)
|
|
|
+ err = DmSQL["rddp"].Raw(sql, pars).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetItemByCondition 查询列表
|
|
|
func (c *ChartPermission) GetItemByCondition(condition string, pars []interface{}) (item *ChartPermission, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //sql := `select * from chart_permission WHERE 1=1 ` + condition
|
|
|
+ //err = o.Raw(sql, pars).QueryRow(&item)
|
|
|
sql := `select * from chart_permission WHERE 1=1 ` + condition
|
|
|
- err = o.Raw(sql, pars).QueryRow(&item)
|
|
|
+ err = DmSQL["rddp"].Raw(sql, pars).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// UpdateChartPermissionSortByParentId 根据父类id更新排序
|
|
|
func UpdateChartPermissionSortByParentId(parentId, chartPermissionId, nowSort int, updateSort string, productId int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+
|
|
|
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 = o.Raw(sql, parentId, productId, nowSort).Exec()
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //_, err = o.Raw(sql, parentId, productId, nowSort).Exec()
|
|
|
+ err = DmSQL["rddp"].Exec(sql, parentId, productId, nowSort).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetMaxSort 获取最大的排序值
|
|
|
func (c *ChartPermission) GetMaxSort() (maxSort int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //sql := `select max(sort) from chart_permission `
|
|
|
+ //err = o.Raw(sql).QueryRow(&maxSort)
|
|
|
sql := `select max(sort) from chart_permission `
|
|
|
- err = o.Raw(sql).QueryRow(&maxSort)
|
|
|
+ err = DmSQL["rddp"].Raw(sql).Scan(&maxSort).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetMaxSortByParentId 获取最大的排序值
|
|
|
func (c *ChartPermission) GetMaxSortByParentId(parentId int) (maxSort int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //sql := `select max(sort) from chart_permission WHERE parent_id=? `
|
|
|
+ //err = o.Raw(sql, parentId).QueryRow(&maxSort)
|
|
|
sql := `select max(sort) from chart_permission WHERE parent_id=? `
|
|
|
- err = o.Raw(sql, parentId).QueryRow(&maxSort)
|
|
|
+ err = DmSQL["rddp"].Raw(sql, parentId).Scan(&maxSort).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetFirstChartPermissionByParentId 获取当前父级分类下,且排序数相同 的排序第一条的数据
|
|
|
func (c *ChartPermission) GetFirstChartPermissionByParentId(parentId int) (item *ChartPermission, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //sql := `select * from chart_permission WHERE parent_id=? ORDER BY sort ASC, chart_permission_id ASC LIMIT 1`
|
|
|
+ //err = o.Raw(sql, parentId).QueryRow(&item)
|
|
|
sql := `select * from chart_permission WHERE parent_id=? ORDER BY sort ASC, chart_permission_id ASC LIMIT 1`
|
|
|
- err = o.Raw(sql, parentId).QueryRow(&item)
|
|
|
+ err = DmSQL["rddp"].Raw(sql, parentId).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetChartPermissionById 主键获取品种
|
|
|
func GetChartPermissionById(permissionId int) (item *ChartPermission, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //sql := `SELECT * FROM chart_permission WHERE chart_permission_id = ?`
|
|
|
+ //err = o.Raw(sql, permissionId).QueryRow(&item)
|
|
|
sql := `SELECT * FROM chart_permission WHERE chart_permission_id = ?`
|
|
|
- err = o.Raw(sql, permissionId).QueryRow(&item)
|
|
|
+ err = DmSQL["rddp"].Raw(sql, permissionId).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetSecondaryChartPermissions 获取二级权限列表
|
|
|
func GetSecondaryChartPermissions() (list []*ChartPermission, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //sql := `SELECT * FROM chart_permission WHERE product_id = ? AND parent_id > 0 AND enabled = 1 ORDER BY parent_id ASC, sort ASC, created_time ASC`
|
|
|
+ //_, err = o.Raw(sql, FiccProductId).QueryRows(&list)
|
|
|
sql := `SELECT * FROM chart_permission WHERE product_id = ? AND parent_id > 0 AND enabled = 1 ORDER BY parent_id ASC, sort ASC, created_time ASC`
|
|
|
- _, err = o.Raw(sql, FiccProductId).QueryRows(&list)
|
|
|
+ err = DmSQL["rddp"].Raw(sql, FiccProductId).Find(&list).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -252,10 +282,11 @@ func FormatChartPermission2Simple(origin *ChartPermission) (item *SimpleChartPer
|
|
|
|
|
|
// GetChartPermissionsByProductId 获取权限列表
|
|
|
func GetChartPermissionsByProductId() (list []*ChartPermission, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //sql := `SELECT * FROM chart_permission WHERE product_id = ? AND enabled = 1 ORDER BY parent_id ASC, sort ASC, created_time ASC`
|
|
|
+ //_, err = o.Raw(sql, FiccProductId).QueryRows(&list)
|
|
|
sql := `SELECT * FROM chart_permission WHERE product_id = ? AND enabled = 1 ORDER BY parent_id ASC, sort ASC, created_time ASC`
|
|
|
- _, err = o.Raw(sql, FiccProductId).QueryRows(&list)
|
|
|
-
|
|
|
+ err = DmSQL["rddp"].Raw(sql, FiccProductId).Find(&list).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -271,9 +302,10 @@ func GetChartPermissionByIdList(permissionIdList []int) (items []*ChartPermissio
|
|
|
if num <= 0 {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //sql := `SELECT * FROM chart_permission WHERE chart_permission_id in (` + utils.GetOrmInReplace(num) + `) `
|
|
|
+ //_, err = o.Raw(sql, permissionIdList).QueryRows(&items)
|
|
|
sql := `SELECT * FROM chart_permission WHERE chart_permission_id in (` + utils.GetOrmInReplace(num) + `) `
|
|
|
- _, err = o.Raw(sql, permissionIdList).QueryRows(&items)
|
|
|
-
|
|
|
+ err = DmSQL["rddp"].Raw(sql, permissionIdList).Find(&items).Error
|
|
|
return
|
|
|
}
|