chart_permission.go 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package crm
  2. import (
  3. "fmt"
  4. "hongze/hz_crm_eta/global"
  5. "time"
  6. )
  7. type ChartPermission struct {
  8. ChartPermissionId int `gorm:"column:chart_permission_id;primary_key;AUTO_INCREMENT;NOT NULL;comment:'主键'" json:"chart_permission_id"`
  9. ChartPermissionName string `gorm:"column:chart_permission_name;default:NULL;comment:'名称'" json:"chart_permission_name"`
  10. PermissionName string `gorm:"column:permission_name;default:;comment:'权限名'" json:"permission_name"`
  11. Sort int `gorm:"column:sort;default:1;comment:'排序'" json:"sort"`
  12. Enabled int `gorm:"column:enabled;default:1;comment:'是否可用 0禁用, 1启用'" json:"enabled"`
  13. CreatedTime time.Time `gorm:"column:created_time;default:CURRENT_TIMESTAMP;comment:'创建时间'" json:"created_time"`
  14. LastUpdatedTime time.Time `gorm:"column:last_updated_time;default:CURRENT_TIMESTAMP;NOT NULL" json:"last_updated_time"`
  15. TeleconferenceSort int `gorm:"column:teleconference_sort;default:0;comment:'电话会类型排序'" json:"teleconference_sort"`
  16. Remark string `gorm:"column:remark;default:NULL" json:"remark"`
  17. ClassifyName string `gorm:"column:classify_name;default:NULL" json:"classify_name"`
  18. ProductName string `gorm:"column:product_name;default:" json:"product_name"`
  19. ProductId int `gorm:"column:product_id;default:0" json:"product_id"`
  20. ImageUrl string `gorm:"column:image_url;default:NULL;comment:'图片地址'" json:"image_url"`
  21. ShowType int `gorm:"column:show_type;default:0;comment:'1:查研观向小程序展示'" json:"show_type"`
  22. IsOther int `gorm:"column:is_other;default:0;NOT NULL;comment:'是否是其他,用于查研观向小程序后台展示'" json:"is_other"`
  23. IsReport int `gorm:"column:is_report;default:0;NOT NULL;comment:'是否是报告,用于查研观向小程序前台报告展示'" json:"is_report"`
  24. CygxAuth int `gorm:"column:cygx_auth;default:0;NOT NULL;comment:'是否是权限,用于查研观向小程序前台权限校验'" json:"cygx_auth"`
  25. PermissionType int `gorm:"column:permission_type;default:0;NOT NULL;comment:'1主观,2客观'" json:"permission_type"`
  26. YbImgUrl string `gorm:"column:yb_img_url;default:NULL;comment:'研报小程序报告列表icon'" json:"yb_img_url"`
  27. ProductPermissionName string `gorm:"column:product_permission_name;default:;comment:'种类权限名称'" json:"product_permission_name"`
  28. PriceDrivenState int `gorm:"column:price_driven_state;default:1;NOT NULL;comment:'品种价格驱动状态 0-关闭 1-开启'" json:"price_driven_state"`
  29. ImageUrlM string `gorm:"column:image_url_m;default:NULL;comment:'图片地址(查研观向移动端)'" json:"image_url_m"`
  30. ParentId int `gorm:"column:parent_id;default:0;NOT NULL;comment:'父级权限id'" json:"parent_id"`
  31. IsPublic int `gorm:"column:is_public;default:0;NOT NULL;comment:'是否是公有权限1:公有权限,0私有权限'" json:"is_public"`
  32. }
  33. func (c *ChartPermission) TableName() string {
  34. return "chart_permission"
  35. }
  36. // GetItemById 查询品种
  37. func (c *ChartPermission) GetItemById(chartPermissionId int) (item *ChartPermission, err error) {
  38. err = global.MYSQL["hz_crm"].Where("chart_permission_id = ?", chartPermissionId).First(&item).Error
  39. return
  40. }
  41. // GetItemsByCondition 查询列表
  42. func (c *ChartPermission) GetItemsByCondition(condition string, pars []interface{}) (items []*ChartPermission, err error) {
  43. err = global.MYSQL["hz_crm"].Where(condition, pars...).Order("sort asc, chart_permission_id asc").Find(&items).Error
  44. return
  45. }
  46. // GetItemByCondition 查询列表
  47. func (c *ChartPermission) GetItemByCondition(condition string, pars []interface{}) (item *ChartPermission, err error) {
  48. err = global.MYSQL["hz_crm"].Where(condition, pars...).First(&item).Error
  49. return
  50. }
  51. // Create 新增权限
  52. func (c *ChartPermission) Create() (err error) {
  53. err = global.MYSQL["hz_crm"].Create(c).Error
  54. return
  55. }
  56. // Update 更新权限
  57. func (c *ChartPermission) Update(cols []string) (err error) {
  58. err = global.MYSQL["hz_crm"].Model(c).Select(cols).Updates(c).Error
  59. return
  60. }
  61. // SetIsPublic 更新公有私有权限
  62. func (c *ChartPermission) SetIsPublic(ids []int, parentId, isPublic int) (err error) {
  63. err = global.MYSQL["hz_crm"].Model(c).Where("chart_permission_id in (?) and parent_id = ?", ids, parentId).Update("is_public", isPublic).Error
  64. return
  65. }
  66. // UpdatesByParentId 更新启动禁用
  67. func (c *ChartPermission) UpdatesByParentId(parentId, enabled int, classifyName string) (err error) {
  68. err = global.MYSQL["hz_crm"].Model(c).Where("parent_id = ?", parentId).Updates(map[string]interface{}{"enabled": enabled, "classify_name": classifyName}).Error
  69. return
  70. }
  71. // SetEnabledByChartPermissionId 更新启动禁用
  72. func (c *ChartPermission) SetEnabledByChartPermissionId(chartPermissionId, enabled int) (err error) {
  73. err = global.MYSQL["hz_crm"].Model(c).Where("chart_permission_id = ?", chartPermissionId).Update("enabled", enabled).Error
  74. return
  75. }
  76. // Delete 删除权限
  77. func (c *ChartPermission) Delete() (err error) {
  78. err = global.MYSQL["hz_crm"].Delete(c).Error
  79. return
  80. }
  81. // GetMaxSort 获取最大的排序值
  82. func (c *ChartPermission) GetMaxSort() (maxSort int, err error) {
  83. err = global.MYSQL["hz_crm"].Model(c).Select("max(sort)").Scan(&maxSort).Error
  84. return
  85. }
  86. // GetMaxSortByParentId 获取最大的排序值
  87. func (c *ChartPermission) GetMaxSortByParentId(parentId int) (maxSort int, err error) {
  88. err = global.MYSQL["hz_crm"].Model(c).Select("max(sort)").Where("parent_id = ?", parentId).Scan(&maxSort).Error
  89. return
  90. }
  91. type PermissionAddReq struct {
  92. PermissionName string `description:"品种权限名称"`
  93. ParentId int `description:"父级ID"`
  94. Enabled int `description:"是否可用 0禁用, 1启用"` //启用,禁用操作会关联二级品种
  95. IsPublic int `description:"是否是公有权限1:公有权限,0私有权限"`
  96. ProductId int
  97. }
  98. type PermissionEditReq struct {
  99. ChartPermissionId int `description:"品种权限Id"` // 如果ID存在,则是更新操作,否则是新增操作
  100. PermissionName string `description:"品种权限名称"`
  101. ParentId int `description:"父级ID"`
  102. Enabled int `description:"是否可用 0禁用, 1启用"` //启用,禁用操作会关联二级品种
  103. IsPublic int `description:"是否是公有权限1:公有权限,0私有权限"`
  104. PublicPermissionIds []int `description:"公有权限的ID列表"` //一级品种没有公有私有属性
  105. }
  106. type PermissionMoveReq struct {
  107. ChartPermissionId int `description:"品种id"`
  108. // ParentChartPermissionId int `description:"父级品种id"`
  109. PrevChartPermissionId int `description:"上一个兄弟节点品种id"`
  110. NextChartPermissionId int `description:"下一个兄弟节点品种id"`
  111. }
  112. // UpdateChartPermissionSortByParentId 根据父类id更新排序
  113. func UpdateChartPermissionSortByParentId(parentId, chartPermissionId, nowSort int, updateSort string, productId int) (err error) {
  114. sql := ` update chart_permission set sort = ` + updateSort + ` WHERE parent_id=? AND sort > ? AND product_id = ? `
  115. if chartPermissionId > 0 {
  116. sql += ` or ( chart_permission_id > ` + fmt.Sprint(chartPermissionId) + ` and sort = ` + fmt.Sprint(nowSort) + `)`
  117. }
  118. err = global.MYSQL["hz_crm"].Exec(sql, parentId, nowSort, productId).Error
  119. return
  120. }
  121. // GetFirstChartPermissionByParentId 获取当前父级分类下,且排序数相同 的排序第一条的数据
  122. func (c *ChartPermission) GetFirstChartPermissionByParentId(parentId int) (item *ChartPermission, err error) {
  123. err = global.MYSQL["hz_crm"].Where("parent_id = ?", parentId).Order("sort asc, chart_permission_id asc").First(&item).Error
  124. return
  125. }