123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- package services
- import (
- "errors"
- "fmt"
- "hongze/hongze_mfyx/models"
- "hongze/hongze_mfyx/utils"
- "strings"
- "time"
- )
- //func init() {
- // var condition string
- // var pars []interface{}
- // condition += ` AND publish_status = 1 `
- //
- // list, err := models.GetArticleList(condition, pars)
- // fmt.Println(err)
- // for _, v := range list {
- // AddCygxReportMappingCategoryGroupByArticleId(v.ArticleId)
- // }
- //}
- // AddCygxReportMappingCategoryGroupByArticleId 根据文章ID建立分类分组,主客观权限分组
- func AddCygxReportMappingCategoryGroupByArticleId(articleId int) {
- fmt.Println(articleId)
- time.Sleep(5 * time.Second)
- var err error
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("根据文章ID建立分类分组,主客观权限分组,失败"+err.Error(), 2)
- }
- }()
- detail, e := models.GetArticleDetailById(articleId)
- if e != nil {
- err = errors.New("GetArticleDetailById, Err: " + e.Error())
- return
- }
- categoryId := detail.CategoryId
- var condition string
- var pars []interface{}
- condition += ` AND category_id_celue = ? `
- pars = append(pars, categoryId)
- list, e := models.GetCygxReportMappingGroupList(condition, pars)
- if e != nil {
- err = errors.New("GetCygxReportMappingGroupList, Err: " + e.Error())
- return
- }
- pars = make([]interface{}, 0)
- var idCygxs []int
- for _, v := range list {
- idCygxs = append(idCygxs, v.IdCygx)
- fmt.Println(v)
- }
- condition = ` AND id IN (` + utils.GetOrmInReplace(len(idCygxs)) + `)`
- pars = append(pars, idCygxs)
- cygxlist, e := models.GetCygxReportMappingCygxByCon(condition, pars)
- if e != nil {
- err = errors.New("GetCygxReportMappingCygxByCon, Err: " + e.Error())
- return
- }
- var items []*models.CygxReportMappingCategoryGroup
- for _, v := range cygxlist {
- item := new(models.CygxReportMappingCategoryGroup)
- item.IdCygx = v.Id
- item.ChartPermissionId = v.ChartPermissionId
- //如果类型是报告就是主观,类型是纪要就是客观
- if detail.TypeName == "报告" {
- item.PermissionType = 1
- }
- if detail.TypeName == "纪要" {
- item.PermissionType = 2
- }
- item.ArticleId = articleId
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- items = append(items, item)
- }
- e = models.AddCygxReportMappingCategoryGroupMulti(items, articleId)
- fmt.Println(items)
- return
- }
- // 校验文章主客观权限
- func CheckArticlePermissionType(articleId int, user *models.WxUserItem) (checkPermissionType bool) {
- var err error
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("记录用户文章浏览记录,失败"+err.Error(), 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
- }
|