Browse Source

no message

xingzai 1 year ago
parent
commit
e07379d644

+ 12 - 18
models/article.go

@@ -172,6 +172,7 @@ type ArticleDetail struct {
 	IsRoadShow              bool   `description:"是否是路演精华"`
 	ReportType              int    `description:"报告类型,1行业报告,2产业报告,0无"`
 	FieldName               string `description:"策略平台的领域字段名称"`
+	TypeName                string `description:"策略平台类型字段名称"`
 }
 
 type ArticleDetailFileLink struct {
@@ -798,7 +799,6 @@ func GetCygxCygxArticleListByCondition(articleTypesCond, activityTypesCond, indu
 		err = o.Raw(artSql).QueryRow(&artIds)
 	}
 
-
 	actSql += ` WHERE 1=1 `
 	if activityTypesCond != "" || (articleTypesCond == "" && activityTypesCond == "") {
 		if industryStr != "" && subjectNameStr != "" {
@@ -816,7 +816,7 @@ func GetCygxCygxArticleListByCondition(articleTypesCond, activityTypesCond, indu
 	if strings.Contains(articleTypeStr, "晨会精华") {
 		mmSql += ` WHERE 1=1 `
 		if industryStr != "" && subjectNameStr != "" {
-			mmSql +=  ` AND (im.industry_name In (` + industryStr + `) OR cis.subject_name In (` + subjectNameStr + `) )`
+			mmSql += ` AND (im.industry_name In (` + industryStr + `) OR cis.subject_name In (` + subjectNameStr + `) )`
 		} else if industryStr == "" && subjectNameStr != "" {
 			mmSql += ` AND  cis.subject_name In (` + subjectNameStr + `) `
 		} else if industryStr != "" && subjectNameStr == "" {
@@ -828,8 +828,6 @@ func GetCygxCygxArticleListByCondition(articleTypesCond, activityTypesCond, indu
 	return
 }
 
-
-
 // 单个tag时用,取合集
 func GetCygxCygxArticleListByConditionSoloTag(articleTypeCondSlice, activityTypesCondSlice, industriesCondSlice, subjectNamesSlice, articleTypeSlice []string) (artIds, actIds, mmIds string, err error) {
 	o := orm.NewOrm()
@@ -840,7 +838,7 @@ func GetCygxCygxArticleListByConditionSoloTag(articleTypeCondSlice, activityType
 	mmSql := ` SELECT GROUP_CONCAT(DISTINCT mmc.id SEPARATOR ',') AS mm_ids FROM cygx_morning_meeting_review_chapter as mmc `
 
 	for _, s := range industriesCondSlice {
-		if s != ""{
+		if s != "" {
 			artSql += ` INNER JOIN cygx_industrial_article_group_management  AS iam ON iam.article_id = art.article_id 
 				INNER JOIN cygx_industrial_management AS im ON im.industrial_management_id=iam.industrial_management_id  `
 			actSql += ` INNER JOIN cygx_industrial_activity_group_management  AS iam ON iam.activity_id = act.activity_id 
@@ -852,7 +850,7 @@ func GetCygxCygxArticleListByConditionSoloTag(articleTypeCondSlice, activityType
 		}
 	}
 	for _, s := range subjectNamesSlice {
-		if s != ""{
+		if s != "" {
 			artSql += ` INNER JOIN cygx_industrial_article_group_subject  AS ias ON ias.article_id = art.article_id 
 				INNER JOIN cygx_industrial_subject AS cis ON cis.industrial_subject_id=ias.industrial_subject_id  `
 			actSql += ` INNER JOIN cygx_industrial_activity_group_subject  AS ias ON ias.activity_id = act.activity_id 
@@ -874,7 +872,6 @@ func GetCygxCygxArticleListByConditionSoloTag(articleTypeCondSlice, activityType
 		subjectNameStr := subjectNamesSlice[i]
 		articleTypeStr := articleTypeSlice[i]
 
-
 		if articleTypesCond != "" || (articleTypesCond == "" && activityTypesCond == "") {
 			if industryStr != "" && subjectNameStr != "" {
 				artSql += articleTypesCond + ` AND (im.industry_name In (` + industryStr + `) OR cis.subject_name In (` + subjectNameStr + `) )`
@@ -886,7 +883,7 @@ func GetCygxCygxArticleListByConditionSoloTag(articleTypeCondSlice, activityType
 				artSql += articleTypesCond
 			}
 
-			if i == len(articleTypeCondSlice) -1 {
+			if i == len(articleTypeCondSlice)-1 {
 				artSql += `)) `
 			} else {
 				artSql += `) OR (1=1 `
@@ -895,8 +892,6 @@ func GetCygxCygxArticleListByConditionSoloTag(articleTypeCondSlice, activityType
 			isNeedArt = true
 		}
 
-
-
 		if activityTypesCond != "" || (articleTypesCond == "" && activityTypesCond == "") {
 			if industryStr != "" && subjectNameStr != "" {
 				actSql += activityTypesCond + ` AND (im.industry_name In (` + industryStr + `) OR cis.subject_name In (` + subjectNameStr + `) )`
@@ -908,7 +903,7 @@ func GetCygxCygxArticleListByConditionSoloTag(articleTypeCondSlice, activityType
 				actSql += activityTypesCond
 			}
 
-			if i == len(articleTypeCondSlice) -1 {
+			if i == len(articleTypeCondSlice)-1 {
 				actSql += `)) `
 			} else {
 				actSql += `) OR (1=1 `
@@ -919,14 +914,14 @@ func GetCygxCygxArticleListByConditionSoloTag(articleTypeCondSlice, activityType
 
 		if strings.Contains(articleTypeStr, "晨会精华") {
 			if industryStr != "" && subjectNameStr != "" {
-				mmSql +=  ` AND (im.industry_name In (` + industryStr + `) OR cis.subject_name In (` + subjectNameStr + `) )`
+				mmSql += ` AND (im.industry_name In (` + industryStr + `) OR cis.subject_name In (` + subjectNameStr + `) )`
 			} else if industryStr == "" && subjectNameStr != "" {
 				mmSql += ` AND  cis.subject_name In (` + subjectNameStr + `) `
 			} else if industryStr != "" && subjectNameStr == "" {
 				mmSql += ` AND im.industry_name In (` + industryStr + `) `
 			}
 
-			if i == len(articleTypeCondSlice) -1 {
+			if i == len(articleTypeCondSlice)-1 {
 				mmSql += `)) `
 			} else {
 				mmSql += `) OR (1=1 `
@@ -938,23 +933,22 @@ func GetCygxCygxArticleListByConditionSoloTag(articleTypeCondSlice, activityType
 
 	if isNeedArt {
 		err = o.Raw(artSql).QueryRow(&artIds)
-		if err != nil{
+		if err != nil {
 			return
 		}
 	}
-	if isNeedAct{
+	if isNeedAct {
 		err = o.Raw(actSql).QueryRow(&actIds)
-		if err != nil{
+		if err != nil {
 			return
 		}
 	}
 	if isNeedMm {
 		err = o.Raw(mmSql).QueryRow(&mmIds)
-		if err != nil{
+		if err != nil {
 			return
 		}
 	}
 
-
 	return
 }

+ 0 - 16
models/article_category_mapping.go

@@ -2,7 +2,6 @@ package models
 
 import (
 	"github.com/beego/beego/v2/client/orm"
-	"time"
 	//"time"
 )
 
@@ -30,21 +29,6 @@ func AddCygxArticleCategoryMapping(item *CygxArticleCategoryMapping) (lastId int
 	return
 }
 
-type CygxReportMappingGroup struct {
-	Id              int       `orm:"column(id);pk" description:"id"`
-	IdCygx          int       `description:"分类ID"`
-	CategoryIdCelue int       `description:"分类ID"`
-	CreateTime      time.Time `description:"创建时间"`
-	ModifyTime      time.Time `description:"更新时间"`
-}
-
-// 添加
-func AddCygxReportMappingGroup(item *CygxReportMappingGroup) (lastId int64, err error) {
-	o := orm.NewOrm()
-	lastId, err = o.Insert(item)
-	return
-}
-
 // 添加
 func AddCygxReportMappingCygx(item *CygxReportMappingCygx) (lastId int64, err error) {
 	o := orm.NewOrm()

+ 1 - 0
models/db.go

@@ -156,6 +156,7 @@ func init() {
 		new(CygxActivityPointsBill),
 		new(CygxActivityPointsCompany),
 		new(CygxTagHistory),
+		new(CygxReportMappingCategoryGroup),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 43 - 0
models/report_mapping_category_group.go

@@ -0,0 +1,43 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxReportMappingCategoryGroup struct {
+	Id                int       `orm:"column(id);pk" description:"id"`
+	ChartPermissionId int       `description:"行业ID"`
+	IdCygx            int       `description:"表cygx_report_mapping_cygx 主键ID"`
+	ArticleId         int       `description:"报告Id"`
+	CreateTime        time.Time `description:"创建时间"`
+	ModifyTime        time.Time `description:"更新时间"`
+	PermissionType    int       `description:"1主观,2客观 ,0不限制"`
+}
+
+// AddCygxReportMappingCategoryGroupMulti 批量添加
+func AddCygxReportMappingCategoryGroupMulti(items []*CygxReportMappingCategoryGroup, articleId int) (err error) {
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err == nil {
+			o.Commit()
+		} else {
+			o.Rollback()
+		}
+	}()
+	//删除原有数据
+	sql := ` DELETE FROM cygx_report_mapping_category_group WHERE article_id = ?  `
+	_, err = o.Raw(sql, articleId).Exec()
+	if err != nil {
+		return
+	}
+	//批量插入新的关联数据
+	if len(items) > 0 {
+		//批量添加流水信息
+		_, err = o.InsertMulti(len(items), items)
+	}
+	return
+}

+ 1 - 2
models/report_mapping_cygx.go

@@ -19,13 +19,12 @@ type CygxReportMappingCygx struct {
 }
 
 // 列表
-func GetCygxReportMappingCygxByCon(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxReportMappingCygx, err error) {
+func GetCygxReportMappingCygxByCon(condition string, pars []interface{}) (items []*CygxReportMappingCygx, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT * FROM cygx_report_mapping_cygx as art WHERE 1= 1 `
 	if condition != "" {
 		sql += condition
 	}
-	//sql += ` LIMIT ?,?  `
 	_, err = o.Raw(sql, pars).QueryRows(&items)
 	return
 }

+ 32 - 0
models/report_mapping_group.go

@@ -0,0 +1,32 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxReportMappingGroup struct {
+	Id              int       `orm:"column(id);pk" description:"id"`
+	IdCygx          int       `description:"分类ID"`
+	CategoryIdCelue int       `description:"分类ID"`
+	CreateTime      time.Time `description:"创建时间"`
+	ModifyTime      time.Time `description:"更新时间"`
+}
+
+// 添加
+func AddCygxReportMappingGroup(item *CygxReportMappingGroup) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+// 列表
+func GetCygxReportMappingGroupList(condition string, pars []interface{}) (items []*CygxReportMappingGroup, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_report_mapping_group  WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 1 - 1
services/init_10.5.1.go

@@ -69,7 +69,7 @@ func init123() {
 
 	var topCond string
 	var topPars []interface{}
-	toplist, err := models.GetCygxReportMappingCygxByCon(topCond, topPars, 0, 0)
+	toplist, err := models.GetCygxReportMappingCygxByCon(topCond, topPars)
 	if err != nil {
 		return
 	}

+ 83 - 0
services/report_mapping_category_group.go

@@ -0,0 +1,83 @@
+package services
+
+import (
+	"errors"
+	"fmt"
+	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
+	"time"
+)
+
+func init232() {
+	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)
+	var err error
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("记录用户文章浏览记录,失败"+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.PermissionType = v.PermissionType
+		item.ArticleId = articleId
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+		items = append(items, item)
+	}
+	e = models.AddCygxReportMappingCategoryGroupMulti(items, articleId)
+	fmt.Println(items)
+	return
+
+}