chart_permission.go 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hz_crm_api/utils"
  5. "time"
  6. )
  7. // ChartPermission 报告权限表
  8. type ChartPermission struct {
  9. ChartPermissionId int `orm:"column(chart_permission_id);pk" description:"问题ID"`
  10. ChartPermissionName string `description:"名称"`
  11. PermissionName string `description:"权限名"`
  12. Sort int `description:"排序"`
  13. Enabled int `description:"是否可用"`
  14. CreatedTime time.Time `description:"创建时间"`
  15. LastUpdatedTime time.Time `description:"更新时间"`
  16. TeleconferenceSort int `description:"电话会类型排序"`
  17. Remark string `description:"备注"`
  18. ClassifyName string `description:"分类名称"`
  19. ProductName string `description:"产品名称"`
  20. ProductId int `description:"产品ID"`
  21. ImageURL string `description:"图片地址"`
  22. ShowType int `description:"1:查研观向小程序展示"`
  23. IsOther int `description:"是否是其他,用于查研观向小程序后台展示"`
  24. IsReport int `description:"是否是报告,用于查研观向小程序前台报告展示"`
  25. CygxAuth int `description:"是否是权限,用于查研观向小程序前台权限校验"`
  26. YbImgUrl string `description:"研报小程序报告列表icon"`
  27. PriceDrivenState int `description:"品种价格驱动开启状态 0-关闭 1-开启"`
  28. ParentId int `description:"父级权限id"`
  29. IsPublic int `description:"是否是公有权限1:公有权限,0私有权限"`
  30. }
  31. // GetChartPermissionById 主键获取权限
  32. func GetChartPermissionById(permissionId int) (item *ChartPermission, err error) {
  33. o := orm.NewOrm()
  34. sql := `SELECT * FROM chart_permission WHERE chart_permission_id = ? LIMIT 1`
  35. err = o.Raw(sql, permissionId).QueryRow(&item)
  36. return
  37. }
  38. // Update 更新
  39. func (chartPermissionInfo *ChartPermission) Update(cols []string) (err error) {
  40. o := orm.NewOrm()
  41. _, err = o.Update(chartPermissionInfo, cols...)
  42. return
  43. }
  44. // YbChartPermissionFirst 研报一级品种分类
  45. type YbChartPermissionFirst struct {
  46. Id int
  47. ClassifyName string `description:"权限一级分类名称,与chart_permission的classify_name一致"`
  48. YbIndexShow int `description:"是否展示在研报小程序首页页面 1-展示;0-不展示"`
  49. YbIndexName string `description:"研报小程序首页简称"`
  50. YbIndexSort string `description:"研报小程序首页排序"`
  51. YbIndexIcon string `description:"研报小程序首页图标地址"`
  52. }
  53. // GetYbChartPermissionFirst 获取研报一级品种分类
  54. func GetYbChartPermissionFirst() (list []*YbChartPermissionFirst, err error) {
  55. o := orm.NewOrm()
  56. sql := `SELECT * FROM chart_permission_first ORDER BY yb_index_sort ASC`
  57. _, err = o.Raw(sql).QueryRows(&list)
  58. return
  59. }
  60. // GetFiccPermissionExceptTactic 获取除了市场策略外的ficc权限
  61. func GetFiccPermissionExceptTactic() (items []*ChartPermission, err error) {
  62. o := orm.NewOrm()
  63. sql := `SELECT * FROM chart_permission WHERE enabled = 1 AND permission_type = 0 AND product_id = 1 and classify_name != '市场策略' ORDER BY sort ASC`
  64. _, err = o.Raw(sql).QueryRows(&items)
  65. return
  66. }
  67. // GetFiccPermissionSecondPublic 获取ficc公有的二级品种
  68. func GetFiccPermissionSecondPublic() (items []*ChartPermission, err error) {
  69. o := orm.NewOrm()
  70. sql := `SELECT * FROM chart_permission WHERE enabled = 1 AND permission_type = 0 AND product_id = 1 and parent_id>0 and is_public=1 ORDER BY sort ASC`
  71. _, err = o.Raw(sql).QueryRows(&items)
  72. return
  73. }
  74. // GetPermissionFirstByProductId 获取一级品种
  75. func GetPermissionFirstByProductId(productId int) (items []*ChartPermission, err error) {
  76. o := orm.NewOrm()
  77. sql := `SELECT * FROM chart_permission WHERE enabled = 1 AND product_id = ? and parent_id=0 ORDER BY sort ASC`
  78. _, err = o.Raw(sql, productId).QueryRows(&items)
  79. return
  80. }
  81. // GetPermissionFirst 获取一级品种
  82. func GetPermissionFirst() (items []*ChartPermission, err error) {
  83. o := orm.NewOrm()
  84. sql := `SELECT * FROM chart_permission WHERE enabled = 1 and parent_id=0 ORDER BY sort ASC`
  85. _, err = o.Raw(sql).QueryRows(&items)
  86. return
  87. }
  88. // GetPermissionByProductIdAndClassifyName 获取子分类
  89. func GetPermissionByProductIdAndClassifyName(productId int, classifyName string) (items []*ChartPermission, err error) {
  90. o := orm.NewOrm()
  91. sql := `SELECT * FROM chart_permission WHERE parent_id > 0 and enabled = 1 AND product_id = ? AND classify_name = ? AND permission_type = 0 ORDER BY sort ASC`
  92. _, err = o.Raw(sql, productId, classifyName).QueryRows(&items)
  93. return
  94. }
  95. // GetChartPermissionById 主键获取权限
  96. func GetChartPermissionByRemark(remark string) (item *ChartPermission, err error) {
  97. o := orm.NewOrm()
  98. sql := `SELECT * FROM chart_permission WHERE parent_id > 0 and remark = ? LIMIT 1`
  99. err = o.Raw(sql, remark).QueryRow(&item)
  100. return
  101. }
  102. // GetChartPermissionByIds 主键获取权限
  103. func GetChartPermissionByIds(permissionIds []string) (list []*ChartPermission, err error) {
  104. qb, _ := orm.NewQueryBuilder("mysql")
  105. // 构建查询对象
  106. qb.Select("*").From("chart_permission").
  107. Where("parent_id > 0 and chart_permission_id").In(permissionIds...)
  108. // 导出 SQL 语句
  109. sql := qb.String()
  110. // 执行 SQL 语句
  111. o := orm.NewOrm()
  112. _, err = o.Raw(sql).QueryRows(&list)
  113. return
  114. }
  115. // GetChartPermissionByIdList 主键获取权限
  116. func GetChartPermissionByIdList(chartPermissionIdList []int) (list []*ChartPermission, err error) {
  117. num := len(chartPermissionIdList)
  118. if num <= 0 {
  119. return
  120. }
  121. o := orm.NewOrm()
  122. sql := `select * from chart_permission where parent_id > 0 and chart_permission_id in (` + utils.GetOrmInReplace(num) + `)`
  123. _, err = o.Raw(sql, chartPermissionIdList).QueryRows(&list)
  124. return
  125. }
  126. // GetChartPermissionByNames 主键获取权限
  127. func GetChartPermissionByNames(permissionNames []string) (list []*ChartPermission, err error) {
  128. qb, _ := orm.NewQueryBuilder("mysql")
  129. // 构建查询对象
  130. qb.Select("*").From("chart_permission").
  131. Where("parent_id > 0 and chart_permission_name").In(permissionNames...)
  132. // 导出 SQL 语句
  133. sql := qb.String()
  134. // 执行 SQL 语句
  135. o := orm.NewOrm()
  136. _, err = o.Raw(sql).QueryRows(&list)
  137. return
  138. }
  139. func GetChartPermissionByNamesByRai(permissionNames []string) (list []*ChartPermission, err error) {
  140. qb, _ := orm.NewQueryBuilder("mysql")
  141. // 构建查询对象
  142. qb.Select("*").From("chart_permission").
  143. Where("parent_id > 0 AND product_id = 2 and chart_permission_name").In(permissionNames...)
  144. // 导出 SQL 语句
  145. sql := qb.String()
  146. // 执行 SQL 语句
  147. o := orm.NewOrm()
  148. _, err = o.Raw(sql).QueryRows(&list)
  149. return
  150. }
  151. // GetChartPermissionList 获取品种权限列表
  152. func GetChartPermissionList() (list []*ChartPermission, err error) {
  153. o := orm.NewOrm()
  154. sql := `SELECT * FROM chart_permission WHERE parent_id > 0 ORDER BY product_id ASC, sort ASC`
  155. _, err = o.Raw(sql).QueryRows(&list)
  156. return
  157. }
  158. func GetChartPermissionListRai() (items []*ChartPermission, err error) {
  159. o := orm.NewOrm()
  160. sql := `SELECT * FROM chart_permission WHERE product_id=2 and parent_id > 0 ORDER BY sort ASC `
  161. _, err = o.Raw(sql).QueryRows(&items)
  162. return
  163. }
  164. // 获取权益主观权限
  165. func GetChartPermissionListRaiSubjectivity() (items []*ChartPermission, err error) {
  166. o := orm.NewOrm()
  167. sql := `SELECT * FROM chart_permission WHERE product_id=2 AND permission_type = 1 and parent_id > 0 ORDER BY sort ASC `
  168. _, err = o.Raw(sql).QueryRows(&items)
  169. return
  170. }
  171. func GetChartPermissionListByCondition(condition string, pars []interface{}) (items []*ChartPermission, err error) {
  172. o := orm.NewOrm()
  173. sql := `SELECT * FROM chart_permission WHERE parent_id > 0 `
  174. if condition != `` {
  175. sql += condition
  176. }
  177. sql += ` ORDER BY sort ASC `
  178. _, err = o.Raw(sql, pars).QueryRows(&items)
  179. return
  180. }