chart_permission.go 12 KB

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