xingzai 1 年間 前
コミット
b1cc0083cd

+ 1 - 0
controllers/cygx/report_article.go

@@ -750,6 +750,7 @@ func (this *IndustrialSubjectController) UpdateMatchTypeName() {
 		return
 	}
 	go cygxService.DoArticleOnenIdWxTemplateMsg(detailArt.ArticleId, 2)
+	go cygxService.AddCygxReportMappingCategoryGroupByArticleId(detailArt.ArticleId) // 手动修改报告归类
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "修改成功"

+ 8 - 0
models/cygx/report_article.go

@@ -482,6 +482,7 @@ type ArticleDetail struct {
 	CategoryId           int    `description:"分类ID"`
 	FileLink             string `description:"下载预览链接"`
 	ReportType           int    `description:"报告类型,2产业报告,1行业报告"`
+	TypeName             string `description:"策略平台类型字段名称"`
 }
 
 func GetArticleDetailById(articleId int) (item *ArticleDetail, err error) {
@@ -491,6 +492,13 @@ func GetArticleDetailById(articleId int) (item *ArticleDetail, err error) {
 	return
 }
 
+func GetArticleDetailByArticleId(articleId int) (item *ArticleDetail, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_article WHERE article_id = ? `
+	err = o.Raw(sql, articleId).QueryRow(&item)
+	return
+}
+
 // 修改报告匹配类型
 type UpdateReportMatchTypeNameRep struct {
 	MatchID  int `orm:"column(id);"description:"匹配ID"`

+ 65 - 0
models/cygx/report_mapping_category_group.go

@@ -0,0 +1,65 @@
+package cygx
+
+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不限制"`
+	IsByHand          int       `description:"是否手动修改过,1是,0否"`
+}
+
+type CygxReportMappingCategoryGroupResp 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 = ? AND is_by_hand = 0  `
+	_, err = o.Raw(sql, articleId).Exec()
+	if err != nil {
+		return
+	}
+	//批量插入新的关联数据
+	if len(items) > 0 {
+		//批量添加流水信息
+		_, err = o.InsertMulti(len(items), items)
+	}
+	return
+}
+
+// 列表
+func GetCygxReportMappingCategoryGroupList(condition string, pars []interface{}) (items []*CygxReportMappingCategoryGroupResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_report_mapping_category_group as art WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 11 - 0
models/cygx/report_mapping_cygx.go

@@ -49,6 +49,17 @@ func GetCygxReportMappingCygxList(condition string, pars []interface{}, startSiz
 	return
 }
 
+// 列表
+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
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
 // 获取数量
 func GetCygxReportMappingCygxCount(condition string, pars []interface{}) (count int, err error) {
 	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_report_mapping_cygx as art WHERE 1= 1  `

+ 1 - 0
models/db.go

@@ -419,6 +419,7 @@ func initCygx() {
 		new(cygx.CygxActivityPointsBill),
 		new(cygx.CygxActivityPointsCompany),
 		new(cygx.CygxTag),
+		new(cygx.CygxReportMappingCategoryGroup),
 	)
 }
 

+ 70 - 0
services/cygx/report_mapping_category_group.go

@@ -0,0 +1,70 @@
+package cygx
+
+import (
+	"errors"
+	"fmt"
+	"hongze/hz_crm_api/models/cygx"
+	"hongze/hz_crm_api/services/alarm_msg"
+	"hongze/hz_crm_api/utils"
+	"time"
+)
+
+// AddCygxReportMappingCategoryGroupByArticleId  根据文章ID建立分类分组,主客观权限分组
+func AddCygxReportMappingCategoryGroupByArticleId(articleId int) {
+	time.Sleep(5 * time.Second)
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go alarm_msg.SendAlarmMsg("根据文章ID建立分类分组,主客观权限分组,失败"+err.Error()+fmt.Sprint("articleId", articleId), 2)
+		}
+	}()
+	detail, e := cygx.GetArticleDetailByArticleId(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 := cygx.GetCygxReportMappingGroupList(condition, pars, 0, 999)
+	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)
+	}
+	condition = ` AND id  IN (` + utils.GetOrmInReplace(len(idCygxs)) + `)`
+	pars = append(pars, idCygxs)
+	cygxlist, e := cygx.GetCygxReportMappingCygxByCon(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxReportMappingCygxByCon, Err: " + e.Error())
+		return
+	}
+	var items []*cygx.CygxReportMappingCategoryGroup
+	for _, v := range cygxlist {
+		item := new(cygx.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.IsByHand = 1
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+		items = append(items, item)
+	}
+	e = cygx.AddCygxReportMappingCategoryGroupMulti(items, articleId)
+	return
+}