package models import ( "github.com/beego/beego/v2/client/orm" "strings" ) type ChartPermission struct { ChartPermissionId int `description:"权限id"` PermissionName string `description:"权限名称"` IsShowSustainable bool `description:"是否展示限免标签"` ImageUrlM string `description:"图片地址"` IsChoose bool `description:"是否选择"` } type ActivityChartPermission struct { ChartPermissionId int `description:"权限id"` PermissionName string `description:"权限名称"` IsChoose bool `description:"是否选择"` } type ChartPermissionResp struct { List []*ChartPermission } func GetChartPermissionById(chartPermissionId int) (item *ChartPermission, err error) { o := orm.NewOrmUsingDB("weekly_report") sql := `SELECT * FROM chart_permission WHERE chart_permission_id = ? ` err = o.Raw(sql, chartPermissionId).QueryRow(&item) return } func GetChartPermissionActivity() (items []*ActivityChartPermission, err error) { o := orm.NewOrmUsingDB("weekly_report") sql := `SELECT * FROM chart_permission WHERE chart_permission_id IN (19,20,21,22,23,31) ORDER BY sort ASC ` _, err = o.Raw(sql).QueryRows(&items) return } // 处理添加主观客观之后的分类ID错误 func GetUserCompanyPermission(companyId int) (items []*ActivityChartPermission, err error) { list, err := GetUserCompanyPermissionSandO(companyId) if err != nil { return } if len(list) == 0 { return } var chartPermissionName string for _, v := range list { chartPermissionName += "'" + v.PermissionName + "'" + "," } chartPermissionName = strings.Trim(chartPermissionName, ",") sql := ` SELECT b.* FROM company_report_permission AS a INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id WHERE a.product_id=2 AND c.is_suspend=0 AND b.cygx_auth=1 AND b.is_other=0 AND c.status IN('正式','试用','永续') AND a.status IN('正式','试用','永续') AND b.chart_permission_name IN (` + chartPermissionName + `) GROUP BY b.chart_permission_name ORDER BY b.sort ASC ` o := orm.NewOrmUsingDB("weekly_report") _, err = o.Raw(sql).QueryRows(&items) return } func GetUserCompanyPermissionSandO(companyId int) (items []*ActivityChartPermission, err error) { sql := ` SELECT b.* FROM company_report_permission AS a INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id WHERE a.company_id=? AND a.product_id=2 AND c.is_suspend=0 AND b.cygx_auth=1 AND b.is_other=0 AND c.status IN('正式','试用','永续') AND a.status IN('正式','试用','永续') AND b.chart_permission_name != '专家' GROUP BY b.chart_permission_name ORDER BY b.sort ASC ` o := orm.NewOrmUsingDB("weekly_report") _, err = o.Raw(sql, companyId).QueryRows(&items) return }