ソースを参照

fix:报告数据修复

Roc 8 ヶ月 前
コミット
162b9ba77d

+ 69 - 1
controllers/report_v2.go

@@ -1093,11 +1093,15 @@ func (this *ReportController) EditLayoutImg() {
 	br.Data = resp
 }
 
-// TODO 修复历史章节报告的品种权限
 // TODO 修复历史报告的ES数据
 
+// init
+// @Description: 修复历史报告数据
+// @author: Roc
+// @datetime 2024-06-21 09:19:05
 func init() {
 	//fixApproveRecord()
+	//fixChapterPermission()
 }
 
 // 修复研报审批数据
@@ -1136,3 +1140,67 @@ func fixApproveRecord() {
 
 	fmt.Println("审批数据修复完成")
 }
+
+// fixChapterPermission
+// @Description: 修复章节关联的品种权限
+// @author: Roc
+// @datetime 2024-06-20 18:08:34
+func fixChapterPermission() {
+	allChapterTypePermissionList, err := models.GetAllChapterTypePermission()
+	if err != nil {
+		fmt.Println("获取所有章节类型ID获取章节类型权限列表失败,Err:", err.Error())
+		return
+	}
+
+	currChapterTypePermissionIdListMap := make(map[int][]int)
+
+	hasPermissionMap := make(map[string]bool)
+	for _, v := range allChapterTypePermissionList {
+		tmpChapterTypePermissionList, ok := currChapterTypePermissionIdListMap[v.ReportChapterTypeId]
+		if !ok {
+			tmpChapterTypePermissionList = make([]int, 0)
+		}
+		key := fmt.Sprint(v.ReportChapterTypeId, "-", v.ChartPermissionId)
+		if _, has := hasPermissionMap[key]; !has {
+			hasPermissionMap[key] = true
+			currChapterTypePermissionIdListMap[v.ReportChapterTypeId] = append(tmpChapterTypePermissionList, v.ChartPermissionId)
+		}
+	}
+
+	notIdList := []int{9675, 9675, 9740, 9749, 9768, 9773, 9791, 9792, 9793, 9850, 9851, 9852, 9852, 9852, 9853, 9854, 9856, 9857, 9857, 9858, 9859, 9860, 9861, 9862, 9862, 9863, 9866}
+	allReportChapterList, err := models.GetAllReportChapter()
+	if err != nil {
+		fmt.Println("获取所有章节失败,Err:", err.Error())
+		return
+	}
+
+	addList := make([]*report.ReportChapterPermissionMapping, 0)
+	for _, v := range allReportChapterList {
+		// 如果是上面的章节id,那么就过滤掉,因为已经入库了
+		if utils.InArrayByInt(notIdList, v.ReportChapterId) {
+			continue
+		}
+		permissionIdList, ok := currChapterTypePermissionIdListMap[v.TypeId]
+		if !ok {
+			continue
+		}
+
+		for _, permissionId := range permissionIdList {
+			addList = append(addList, &report.ReportChapterPermissionMapping{
+				ReportChapterPermissionMappingId: 0,
+				ReportChapterId:                  v.ReportChapterId,
+				ChartPermissionId:                permissionId,
+				CreateTime:                       v.ModifyTime,
+			})
+		}
+
+	}
+
+	obj := report.ReportChapterPermissionMapping{}
+	err = obj.MultiAdd(addList)
+	if err != nil {
+		fmt.Println("批量添加报章节的品种权限失败,Err:", err.Error())
+	}
+
+	return
+}

+ 46 - 0
models/company/company_config.go

@@ -1,6 +1,9 @@
 package company
 
 import (
+	"encoding/json"
+	"errors"
+	"eta/eta_api/utils"
 	"github.com/beego/beego/v2/client/orm"
 )
 
@@ -41,3 +44,46 @@ type ConfEnAuthRole struct {
 	RoleName string `description:"角色名称"`
 	SyncCrm  bool   `description:"是否同步CRM"`
 }
+
+// ConfigClassifyId
+// @Description: 后台配置的报告id
+type ConfigClassifyId struct {
+	Debug   int `json:"debug"`
+	Release int `json:"release"`
+}
+
+// GetReportClassifyIdByConfigKey
+// @Description: 获取关联的报告id
+// @author: Roc
+// @datetime 2024-06-18 14:10:27
+// @param configKey string
+// @return classifyId int
+// @return err error
+func GetReportClassifyIdByConfigKey(configKey string) (classifyId int, err error) {
+	// 别问为啥要从配置里拿=_=!
+	conf, e := GetConfigDetailByCode(configKey)
+	if e != nil {
+		err = errors.New("获取配置的id失败, Err: " + e.Error())
+		return
+	}
+	if conf.ConfigValue == "" {
+		err = errors.New("ID配置有误")
+		return
+	}
+	type TwoWeekIdConf struct {
+		Debug   []int
+		Release []int
+	}
+	classifyIdConf := new(ConfigClassifyId)
+	if e = json.Unmarshal([]byte(conf.ConfigValue), &classifyIdConf); e != nil {
+		err = errors.New("解析ID配置失败, Err: " + e.Error())
+		return
+	}
+	if utils.RunMode == "debug" {
+		classifyId = classifyIdConf.Debug
+	} else {
+		classifyId = classifyIdConf.Release
+	}
+
+	return
+}

+ 32 - 0
models/report/report_chapter_permission_mapping.go

@@ -118,3 +118,35 @@ func (m ReportChapterPermissionMapping) GetPermissionListByIdList(reportChapterI
 
 	return
 }
+
+// MultiAdd
+// @Description: 批量添加
+// @author: Roc
+// @receiver m
+// @datetime 2024-06-20 18:04:33
+// @param list []*ReportChapterPermissionMapping
+// @return err error
+func (m ReportChapterPermissionMapping) MultiAdd(list []*ReportChapterPermissionMapping) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	to, err := o.Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = to.Rollback()
+		} else {
+			_ = to.Commit()
+		}
+	}()
+
+	// 新增品种权限记录
+	if len(list) > 0 {
+		_, err = to.InsertMulti(500, list)
+		if err != nil {
+			return
+		}
+	}
+
+	return
+}

+ 9 - 0
models/report_chapter.go

@@ -520,3 +520,12 @@ func (chapterChapterInfo *ReportChapter) Update(cols []string) (err error) {
 type DelReportChapterReq struct {
 	ReportChapterId int `description:"报告章节ID"`
 }
+
+// GetAllReportChapter 获取所有的报告章节
+func GetAllReportChapter() (items []*ReportChapter, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT * FROM report_chapter ORDER BY report_chapter_id asc `
+	_, err = o.Raw(sql).QueryRows(&items)
+
+	return
+}

+ 13 - 0
models/report_chapter_type_permission.go

@@ -106,3 +106,16 @@ func GetChapterTypePermissionByChapterTypeIdList(chapterTypeIdList []int) (list
 	_, err = o.Raw(sql, chapterTypeIdList).QueryRows(&list)
 	return
 }
+
+// GetAllChapterTypePermission
+// @Description: 获取所有章节类型ID获取章节类型权限列表
+// @author: Roc
+// @datetime 2024-06-03 15:42:47
+// @return list []*ReportChapterTypePermission
+// @return err error
+func GetAllChapterTypePermission() (list []*ReportChapterTypePermission, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT * FROM report_chapter_type_permission ORDER BY chart_permission_id ASC `
+	_, err = o.Raw(sql).QueryRows(&list)
+	return
+}

+ 3 - 3
models/wechat_send_msg.go

@@ -21,7 +21,7 @@ func GetOpenIdArr() (items []string, err error) {
 	return
 }
 
-func GetOpenIdArrByClassifyNameSecond(classifyNameSecond string) (items []string, err error) {
+func GetOpenIdArrByClassifyNameSecond(classifyId int) (items []string, err error) {
 	sql := ` SELECT DISTINCT ur.open_id FROM wx_user AS wu 
 			INNER JOIN company AS c ON c.company_id = wu.company_id 
 			INNER JOIN company_product AS d ON c.company_id=d.company_id
@@ -31,9 +31,9 @@ func GetOpenIdArrByClassifyNameSecond(classifyNameSecond string) (items []string
 			INNER JOIN chart_permission_search_key_word_mapping AS g ON f.chart_permission_id=g.chart_permission_id
 			WHERE ur.open_id != "" AND ur.subscribe=1 AND ur.create_platform=1 AND  d.status IN('正式','试用','永续') AND  e.status IN('正式','试用','永续') 
 			AND g.from='rddp'
-			AND g.key_word=?
+			AND g.classify_id=?
 			ORDER BY FIELD(c.company_id, 16) DESC, ur.user_record_id ASC  `
 	o := orm.NewOrmUsingDB("weekly")
-	_, err = o.Raw(sql, classifyNameSecond).QueryRows(&items)
+	_, err = o.Raw(sql, classifyId).QueryRows(&items)
 	return
 }

+ 27 - 18
services/wechat_send_msg.go

@@ -3,10 +3,11 @@ package services
 import (
 	"encoding/json"
 	"errors"
-	"fmt"
 	"eta/eta_api/models"
+	"eta/eta_api/models/company"
 	"eta/eta_api/services/alarm_msg"
 	"eta/eta_api/utils"
+	"fmt"
 	"io/ioutil"
 	"net/http"
 	"strconv"
@@ -38,7 +39,7 @@ func SendMiniProgramReportWxMsg(reportId int) (err error) {
 	}()
 	utils.FileLog.Info("%s", "services SendMsg")
 
-	report, err := models.GetReportById(reportId)
+	report, err := models.GetReportByReportId(reportId)
 	if err != nil {
 		msg = "GetReportInfo Err:" + err.Error()
 		return
@@ -61,30 +62,31 @@ func SendMiniProgramReportWxMsg(reportId int) (err error) {
 	//}
 
 	var openIdArr []string
-	if report.ClassifyIdSecond <= 0 {
+	if report.HasChapter == 1 { // 如果是章节,那就推送所有用户
 		openIdArr, err = models.GetOpenIdArr()
 		if err != nil {
 			msg = "get GetOpenIdArr err:" + err.Error()
 			return
 		}
 	} else {
-		classify, err := models.GetClassifyById(report.ClassifyIdSecond)
+		minClassifyId, err := getMinClassifyId(report)
+		if err != nil {
+			msg = "获取报告的最小分类失败 err:" + err.Error()
+			return err
+		}
+
+		// 判断分类是否存在
+		_, err = models.GetClassifyById(minClassifyId)
 		if err != nil {
 			msg = "获取报告分类失败 err:" + err.Error()
 			return err
 		}
-		if classify.IsMassSend == 1 {
-			openIdArr, err = models.GetOpenIdArr()
-			if err != nil {
-				msg = "get GetOpenIdArr err:" + err.Error()
-				return err
-			}
-		} else {
-			openIdArr, err = models.GetOpenIdArrByClassifyNameSecond(report.ClassifyNameSecond)
-			if err != nil {
-				msg = "GetOpenIdArrByClassifyNameSecond err:" + err.Error()
-				return err
-			}
+
+		// 获取该分类关联的openid列表
+		openIdArr, err = models.GetOpenIdArrByClassifyNameSecond(minClassifyId)
+		if err != nil {
+			msg = "GetOpenIdArrByClassifyNameSecond err:" + err.Error()
+			return err
 		}
 	}
 
@@ -102,7 +104,7 @@ func SendMiniProgramReportWxMsg(reportId int) (err error) {
 	first := fmt.Sprintf("Hi,最新一期%s已上线,欢迎查看", report.ClassifyNameFirst)
 	keyword1 := title
 	keyword2 := report.Title
-	keyword3 := report.PublishTime
+	keyword3 := report.PublishTime.Format(utils.FormatDateTime)
 	keyword4 := report.Abstract
 
 	//sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
@@ -116,7 +118,14 @@ func SendMiniProgramReportWxMsg(reportId int) (err error) {
 	//sendMap["data"] = sendData
 
 	var wxAppPath string
-	if report.ChapterType == utils.REPORT_TYPE_WEEK {
+	weekClassifyId, err := company.GetReportClassifyIdByConfigKey("report_week_classify_id")
+	if err != nil {
+		msg = "获取周报ID配置失败:" + err.Error()
+		return err
+	}
+
+	// 周报走这个逻辑,我也不清楚为什么,原先就是这样(2024-6-20 16:46:07)
+	if report.ClassifyIdFirst == weekClassifyId {
 		wxAppPath = fmt.Sprintf("pages-report/chapterList?reportId=%s", reportIdStr)
 	} else {
 		wxAppPath = fmt.Sprintf("pages-report/reportDetail?reportId=%s", reportIdStr)