123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package services
- import (
- "errors"
- "fmt"
- "hongze/hongze_clpt/models"
- "hongze/hongze_clpt/utils"
- "strings"
- )
- // 校验文章主客观权限
- func CheckArticlePermissionType(articleId int, user *models.WxUserItem) (checkPermissionType bool) {
- var err error
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("校验文章主客观权限,失败"+err.Error()+fmt.Sprint("uid:", user.UserId, "articleId", articleId), 2)
- }
- }()
- permissionStr, e := models.GetCompanyPermissionByUser(user.CompanyId)
- if e != nil {
- err = errors.New("GetCompanyPermissionByUser, Err: " + e.Error())
- return
- }
- var condition string
- var pars []interface{}
- condition += ` AND article_id = ? `
- pars = append(pars, articleId)
- list, e := models.GetCygxReportMappingCategoryGroupList(condition, pars)
- if e != nil {
- err = errors.New("GetCygxReportMappingCategoryGroupList, Err: " + e.Error())
- return
- }
- if len(list) == 0 {
- checkPermissionType = true
- return
- }
- var chartPermissionId int
- var chartPermissionName string
- var permissionTypeZg bool
- var permissionTypeKg bool
- for _, v := range list {
- chartPermissionId = v.ChartPermissionId
- if v.PermissionType == 1 || v.PermissionType == 0 {
- permissionTypeZg = true
- }
- if v.PermissionType == 2 || v.PermissionType == 0 {
- permissionTypeKg = true
- }
- }
- categoryinfo, e := models.GetChartPermissionById(chartPermissionId)
- if e != nil {
- err = errors.New("GetChartPermissionById, Err: " + e.Error())
- return
- }
- if permissionTypeZg {
- chartPermissionName = categoryinfo.PermissionName + "(主观)"
- }
- if permissionTypeKg {
- chartPermissionName = categoryinfo.PermissionName + "(客观)"
- }
- if permissionTypeKg && permissionTypeZg {
- chartPermissionName = categoryinfo.PermissionName
- }
- if strings.Contains(permissionStr, chartPermissionName) {
- checkPermissionType = true
- }
- return
- }
|