chart_permission.go 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. package models
  2. import (
  3. "eta/eta_mobile/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "time"
  7. )
  8. // ChartPermission 报告权限表
  9. type ChartPermission struct {
  10. ChartPermissionId int `orm:"column(chart_permission_id);pk" description:"问题ID" json:"chart_permission_id"`
  11. ChartPermissionName string `description:"名称" json:"chart_permission_name"`
  12. PermissionName string `description:"权限名" json:"permission_name"`
  13. Sort int `description:"排序" json:"sort"`
  14. Enabled int `description:"是否可用" json:"enabled"`
  15. CreatedTime time.Time `description:"创建时间" json:"created_time"`
  16. LastUpdatedTime time.Time `description:"更新时间" json:"last_updated_time"`
  17. TeleconferenceSort int `description:"电话会类型排序" json:"teleconference_sort"`
  18. Remark string `description:"备注" json:"remark"`
  19. ClassifyName string `description:"分类名称" json:"classify_name"`
  20. ProductName string `description:"产品名称" json:"product_name"`
  21. ProductId int `description:"产品ID" json:"product_id"`
  22. ImageURL string `orm:"column(image_url);" description:"图片地址" json:"image_url"`
  23. ShowType int `description:"1:查研观向小程序展示" json:"show_type"`
  24. IsOther int `description:"是否是其他,用于查研观向小程序后台展示" json:"is_other"`
  25. IsReport int `description:"是否是报告,用于查研观向小程序前台报告展示" json:"is_report"`
  26. CygxAuth int `description:"是否是权限,用于查研观向小程序前台权限校验" json:"cygx_auth"`
  27. PermissionType int `description:"1主观,2客观" json:"permission_type"`
  28. YbImgUrl string `description:"研报小程序报告列表icon" json:"yb_img_url"`
  29. ProductPermissionName string `description:"种类权限名称" json:"product_permission_name"`
  30. PriceDrivenState int `description:"品种价格驱动开启状态 0-关闭 1-开启" json:"price_driven_state"`
  31. ImageUrlM string `description:"图片地址(查研观向移动端)" json:"image_url_m"`
  32. ParentId int `description:"父级权限id" json:"parent_id"`
  33. IsPublic int `description:"是否是公有权限1:公有权限,0私有权限" json:"is_public"`
  34. }
  35. type ChartPermissionItem struct {
  36. PermissionId int `description:"品种权限ID"`
  37. PermissionName string `description:"品种权限名称"`
  38. ParentId int `description:"父级ID"`
  39. IsPublic int `description:"是否是公有权限1:公有权限,0私有权限" `
  40. Enabled int `description:"是否可用:1可用,0不可用" `
  41. Sort int `description:"排序"`
  42. CreateTime string `description:"创建时间"`
  43. Child []*ChartPermissionItem
  44. }
  45. // Update 更新
  46. func (c *ChartPermission) Update(cols []string) (err error) {
  47. o := orm.NewOrmUsingDB("rddp")
  48. _, err = o.Update(c, cols...)
  49. return
  50. }
  51. type PermissionAddReq struct {
  52. PermissionName string `description:"品种权限名称"`
  53. ParentId int `description:"父级ID"`
  54. Enabled int `description:"是否可用 0禁用, 1启用"` //启用,禁用操作会关联二级品种
  55. IsPublic int `description:"是否是公有权限1:公有权限,0私有权限"`
  56. }
  57. type PermissionEditReq struct {
  58. PermissionId int `description:"品种权限Id"` // 如果ID存在,则是更新操作,否则是新增操作
  59. PermissionName string `description:"品种权限名称"`
  60. ParentId int `description:"父级ID"`
  61. Enabled int `description:"是否可用 0禁用, 1启用"` //启用,禁用操作会关联二级品种
  62. IsPublic int `description:"是否是公有权限1:公有权限,0私有权限"`
  63. PublicPermissionIds []int `description:"公有权限的ID列表"` //一级品种没有公有私有属性
  64. }
  65. type PermissionEnabledReq struct {
  66. PermissionId int `description:"品种权限Id"` // 如果ID存在,则是更新操作,否则是新增操作
  67. Enabled int `description:"是否可用 0禁用, 1启用"` //启用,禁用操作会关联二级品种
  68. }
  69. type PermissionMoveReq struct {
  70. PermissionId int `description:"品种id"`
  71. // ParentChartPermissionId int `description:"父级品种id"`
  72. PrevPermissionId int `description:"上一个兄弟节点品种id"`
  73. NextPermissionId int `description:"下一个兄弟节点品种id"`
  74. }
  75. func (c *ChartPermission) SetEnabled(id, enabled int) (err error) {
  76. o := orm.NewOrmUsingDB("rddp")
  77. to, err := o.Begin()
  78. if err != nil {
  79. return
  80. }
  81. defer func() {
  82. if err != nil {
  83. _ = to.Rollback()
  84. } else {
  85. _ = to.Commit()
  86. }
  87. }()
  88. sql := ` UPDATE chart_permission SET enabled =? WHERE id = ?`
  89. _, err = to.Raw(sql, enabled, id).Exec()
  90. if err != nil {
  91. return
  92. }
  93. sql = ` UPDATE chart_permission SET enabled =? WHERE parent_id = ?`
  94. _, err = to.Raw(sql, enabled, id).Exec()
  95. if err != nil {
  96. return
  97. }
  98. return
  99. }
  100. // Create 新增权限
  101. func (c *ChartPermission) Create() (err error) {
  102. o := orm.NewOrmUsingDB("rddp")
  103. id, err := o.Insert(c)
  104. if err != nil {
  105. return
  106. }
  107. c.ChartPermissionId = int(id)
  108. return
  109. }
  110. // SetIsPublic 更新公有私有权限
  111. func (c *ChartPermission) SetIsPublic(ids []int, parentId, isPublic int) (err error) {
  112. o := orm.NewOrmUsingDB("rddp")
  113. sql := `update chart_permission set is_public=? WHERE parent_id = ? and chart_permission_id IN (` + utils.GetOrmInReplace(len(ids)) + `)`
  114. _, err = o.Raw(sql, isPublic, parentId, ids).Exec()
  115. return
  116. }
  117. // UpdatesByParentId 更新启动禁用
  118. func (c *ChartPermission) UpdateClassifyNameByParentId(parentId int, classifyName string) (err error) {
  119. o := orm.NewOrmUsingDB("rddp")
  120. sql := `update chart_permission set classify_name=? WHERE parent_id = ?`
  121. _, err = o.Raw(sql, classifyName, parentId).Exec()
  122. return
  123. }
  124. // SetEnabledByParentId 更新启动禁用
  125. func (c *ChartPermission) SetEnabledByParentId(parentId, enabled int) (err error) {
  126. o := orm.NewOrmUsingDB("rddp")
  127. sql := ` UPDATE chart_permission SET enabled =? WHERE parent_id = ?`
  128. _, err = o.Raw(sql, enabled, parentId).Exec()
  129. return
  130. }
  131. // SetEnabledByChartPermissionId 更新启动禁用
  132. func (c *ChartPermission) SetEnabledByChartPermissionId(chartPermissionId, enabled int) (err error) {
  133. o := orm.NewOrmUsingDB("rddp")
  134. sql := ` UPDATE chart_permission SET enabled =? WHERE chart_permission_id = ?`
  135. _, err = o.Raw(sql, enabled, chartPermissionId).Exec()
  136. return
  137. }
  138. // GetItemById 查询品种
  139. func (c *ChartPermission) GetItemById(chartPermissionId int) (item *ChartPermission, err error) {
  140. o := orm.NewOrmUsingDB("rddp")
  141. sql := `select * from chart_permission WHERE chart_permission_id = ?`
  142. err = o.Raw(sql, chartPermissionId).QueryRow(&item)
  143. return
  144. }
  145. // GetItemsByCondition 查询列表
  146. func (c *ChartPermission) GetItemsByCondition(condition string, pars []interface{}) (items []*ChartPermission, err error) {
  147. o := orm.NewOrmUsingDB("rddp")
  148. sql := `select * from chart_permission WHERE 1=1 ` + condition + ` order by sort asc, chart_permission_id asc`
  149. _, err = o.Raw(sql, pars).QueryRows(&items)
  150. return
  151. }
  152. // GetItemByCondition 查询列表
  153. func (c *ChartPermission) GetItemByCondition(condition string, pars []interface{}) (item *ChartPermission, err error) {
  154. o := orm.NewOrmUsingDB("rddp")
  155. sql := `select * from chart_permission WHERE 1=1 ` + condition
  156. err = o.Raw(sql, pars).QueryRow(&item)
  157. return
  158. }
  159. // UpdateChartPermissionSortByParentId 根据父类id更新排序
  160. func UpdateChartPermissionSortByParentId(parentId, chartPermissionId, nowSort int, updateSort string, productId int) (err error) {
  161. o := orm.NewOrmUsingDB("rddp")
  162. sql := ` update chart_permission set sort = ` + updateSort + ` WHERE parent_id=? AND product_id = ? AND (sort > ? `
  163. if chartPermissionId > 0 {
  164. sql += ` or ( chart_permission_id > ` + fmt.Sprint(chartPermissionId) + ` and sort = ` + fmt.Sprint(nowSort) + `))`
  165. } else {
  166. sql += `)`
  167. }
  168. _, err = o.Raw(sql, parentId, productId, nowSort).Exec()
  169. return
  170. }
  171. // GetMaxSort 获取最大的排序值
  172. func (c *ChartPermission) GetMaxSort() (maxSort int, err error) {
  173. o := orm.NewOrmUsingDB("rddp")
  174. sql := `select max(sort) from chart_permission `
  175. err = o.Raw(sql).QueryRow(&maxSort)
  176. return
  177. }
  178. // GetMaxSortByParentId 获取最大的排序值
  179. func (c *ChartPermission) GetMaxSortByParentId(parentId int) (maxSort int, err error) {
  180. o := orm.NewOrmUsingDB("rddp")
  181. sql := `select max(sort) from chart_permission WHERE parent_id=? `
  182. err = o.Raw(sql, parentId).QueryRow(&maxSort)
  183. return
  184. }
  185. // GetFirstChartPermissionByParentId 获取当前父级分类下,且排序数相同 的排序第一条的数据
  186. func (c *ChartPermission) GetFirstChartPermissionByParentId(parentId int) (item *ChartPermission, err error) {
  187. o := orm.NewOrmUsingDB("rddp")
  188. sql := `select * from chart_permission WHERE parent_id=? ORDER BY sort ASC, chart_permission_id ASC LIMIT 1`
  189. err = o.Raw(sql, parentId).QueryRow(&item)
  190. return
  191. }