123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- package crm
- import (
- "fmt"
- "hongze/hz_crm_eta/global"
- "time"
- )
- type ChartPermission struct {
- ChartPermissionId int `gorm:"column:chart_permission_id;primary_key;AUTO_INCREMENT;NOT NULL;comment:'主键'" json:"chart_permission_id"`
- ChartPermissionName string `gorm:"column:chart_permission_name;default:NULL;comment:'名称'" json:"chart_permission_name"`
- PermissionName string `gorm:"column:permission_name;default:;comment:'权限名'" json:"permission_name"`
- Sort int `gorm:"column:sort;default:1;comment:'排序'" json:"sort"`
- Enabled int `gorm:"column:enabled;default:1;comment:'是否可用 0禁用, 1启用'" json:"enabled"`
- CreatedTime time.Time `gorm:"column:created_time;default:CURRENT_TIMESTAMP;comment:'创建时间'" json:"created_time"`
- LastUpdatedTime time.Time `gorm:"column:last_updated_time;default:CURRENT_TIMESTAMP;NOT NULL" json:"last_updated_time"`
- TeleconferenceSort int `gorm:"column:teleconference_sort;default:0;comment:'电话会类型排序'" json:"teleconference_sort"`
- Remark string `gorm:"column:remark;default:NULL" json:"remark"`
- ClassifyName string `gorm:"column:classify_name;default:NULL" json:"classify_name"`
- ProductName string `gorm:"column:product_name;default:" json:"product_name"`
- ProductId int `gorm:"column:product_id;default:0" json:"product_id"`
- ImageUrl string `gorm:"column:image_url;default:NULL;comment:'图片地址'" json:"image_url"`
- ShowType int `gorm:"column:show_type;default:0;comment:'1:查研观向小程序展示'" json:"show_type"`
- IsOther int `gorm:"column:is_other;default:0;NOT NULL;comment:'是否是其他,用于查研观向小程序后台展示'" json:"is_other"`
- IsReport int `gorm:"column:is_report;default:0;NOT NULL;comment:'是否是报告,用于查研观向小程序前台报告展示'" json:"is_report"`
- CygxAuth int `gorm:"column:cygx_auth;default:0;NOT NULL;comment:'是否是权限,用于查研观向小程序前台权限校验'" json:"cygx_auth"`
- PermissionType int `gorm:"column:permission_type;default:0;NOT NULL;comment:'1主观,2客观'" json:"permission_type"`
- YbImgUrl string `gorm:"column:yb_img_url;default:NULL;comment:'研报小程序报告列表icon'" json:"yb_img_url"`
- ProductPermissionName string `gorm:"column:product_permission_name;default:;comment:'种类权限名称'" json:"product_permission_name"`
- PriceDrivenState int `gorm:"column:price_driven_state;default:1;NOT NULL;comment:'品种价格驱动状态 0-关闭 1-开启'" json:"price_driven_state"`
- ImageUrlM string `gorm:"column:image_url_m;default:NULL;comment:'图片地址(查研观向移动端)'" json:"image_url_m"`
- ParentId int `gorm:"column:parent_id;default:0;NOT NULL;comment:'父级权限id'" json:"parent_id"`
- IsPublic int `gorm:"column:is_public;default:0;NOT NULL;comment:'是否是公有权限1:公有权限,0私有权限'" json:"is_public"`
- }
- func (c *ChartPermission) TableName() string {
- return "chart_permission"
- }
- // GetItemById 查询品种
- func (c *ChartPermission) GetItemById(chartPermissionId int) (item *ChartPermission, err error) {
- err = global.MYSQL["hz_crm"].Where("chart_permission_id = ?", chartPermissionId).First(&item).Error
- return
- }
- // GetItemsByCondition 查询列表
- func (c *ChartPermission) GetItemsByCondition(condition string, pars []interface{}) (items []*ChartPermission, err error) {
- err = global.MYSQL["hz_crm"].Where(condition, pars...).Order("sort asc, chart_permission_id asc").Find(&items).Error
- return
- }
- // GetItemByCondition 查询列表
- func (c *ChartPermission) GetItemByCondition(condition string, pars []interface{}) (item *ChartPermission, err error) {
- err = global.MYSQL["hz_crm"].Where(condition, pars...).First(&item).Error
- return
- }
- // Create 新增权限
- func (c *ChartPermission) Create() (err error) {
- err = global.MYSQL["hz_crm"].Create(c).Error
- return
- }
- // Update 更新权限
- func (c *ChartPermission) Update(cols []string) (err error) {
- err = global.MYSQL["hz_crm"].Model(c).Select(cols).Updates(c).Error
- return
- }
- // SetIsPublic 更新公有私有权限
- func (c *ChartPermission) SetIsPublic(ids []int, parentId, isPublic int) (err error) {
- err = global.MYSQL["hz_crm"].Model(c).Where("chart_permission_id in (?) and parent_id = ?", ids, parentId).Update("is_public", isPublic).Error
- return
- }
- // UpdatesByParentId 更新启动禁用
- func (c *ChartPermission) UpdateClassifyNameByParentId(parentId int, classifyName string) (err error) {
- //err = global.MYSQL["hz_crm"].Model(c).Where("parent_id = ?", parentId).Updates(map[string]interface{}{"enabled": enabled, "classify_name": classifyName}).Error
- err = global.MYSQL["hz_crm"].Model(c).Where("parent_id = ?", parentId).Update("classify_name", classifyName).Error
- return
- }
- // SetEnabledByParentId 更新启动禁用
- func (c *ChartPermission) SetEnabledByParentId(parentId, enabled int) (err error) {
- err = global.MYSQL["hz_crm"].Model(c).Where("parent_id = ?", parentId).Update("enabled", enabled).Error
- return
- }
- // SetEnabledByChartPermissionId 更新启动禁用
- func (c *ChartPermission) SetEnabledByChartPermissionId(chartPermissionId, enabled int) (err error) {
- err = global.MYSQL["hz_crm"].Model(c).Where("chart_permission_id = ?", chartPermissionId).Update("enabled", enabled).Error
- return
- }
- // Delete 删除权限
- func (c *ChartPermission) Delete() (err error) {
- err = global.MYSQL["hz_crm"].Delete(c).Error
- return
- }
- // GetMaxSort 获取最大的排序值
- func (c *ChartPermission) GetMaxSort() (maxSort int, err error) {
- err = global.MYSQL["hz_crm"].Model(c).Select("max(sort)").Scan(&maxSort).Error
- return
- }
- // GetMaxSortByParentId 获取最大的排序值
- func (c *ChartPermission) GetMaxSortByParentId(parentId int) (maxSort int, err error) {
- err = global.MYSQL["hz_crm"].Model(c).Select("max(sort)").Where("parent_id = ?", parentId).Scan(&maxSort).Error
- return
- }
- type PermissionAddReq struct {
- PermissionName string `description:"品种权限名称"`
- ParentId int `description:"父级ID"`
- Enabled int `description:"是否可用 0禁用, 1启用"` //启用,禁用操作会关联二级品种
- IsPublic int `description:"是否是公有权限1:公有权限,0私有权限"`
- ProductId int
- }
- type PermissionEditReq struct {
- ChartPermissionId int `description:"品种权限Id"`
- PermissionName string `description:"品种权限名称"`
- ParentId int `description:"父级ID"`
- IsPublic int `description:"是否是公有权限1:公有权限,0私有权限"`
- PublicPermissionIds []int `description:"公有权限的ID列表"` //一级品种没有公有私有属性
- }
- type PermissionEnabledReq struct {
- ChartPermissionId int `description:"品种权限Id"`
- Enabled int `description:"是否可用 0禁用, 1启用"`
- }
- type PermissionMoveReq struct {
- ChartPermissionId int `description:"品种id"`
- // ParentChartPermissionId int `description:"父级品种id"`
- PrevChartPermissionId int `description:"上一个兄弟节点品种id"`
- NextChartPermissionId int `description:"下一个兄弟节点品种id"`
- }
- // UpdateChartPermissionSortByParentId 根据父类id更新排序
- func UpdateChartPermissionSortByParentId(parentId, chartPermissionId, nowSort int, updateSort string, productId int) (err error) {
- 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 = global.MYSQL["hz_crm"].Exec(sql, parentId, nowSort, productId, productId).Error
- return
- }
- // GetFirstChartPermissionByParentId 获取当前父级分类下,且排序数相同 的排序第一条的数据
- func (c *ChartPermission) GetFirstChartPermissionByParentId(parentId int) (item *ChartPermission, err error) {
- err = global.MYSQL["hz_crm"].Where("parent_id = ?", parentId).Order("sort asc, chart_permission_id asc").First(&item).Error
- return
- }
|