Преглед на файлове

fix:报告章节管理,报告章节停更设置

Roc преди 8 месеца
родител
ревизия
519ab9bd36
променени са 5 файла, в които са добавени 163 реда и са изтрити 48 реда
  1. 60 11
      controllers/report.go
  2. 6 7
      controllers/report_chapter_type.go
  3. 48 2
      models/company/company_config.go
  4. 48 27
      models/report_chapter_type.go
  5. 1 1
      services/report_chapter_type_sync.go

+ 60 - 11
controllers/report.go

@@ -5,6 +5,7 @@ import (
 	"fmt"
 	"github.com/beego/beego/v2/server/web"
 	"hongze/hz_crm_api/models"
+	"hongze/hz_crm_api/models/company"
 	"hongze/hz_crm_api/services"
 	"hongze/hz_crm_api/services/alarm_msg"
 	"hongze/hz_crm_api/utils"
@@ -60,6 +61,21 @@ func (this *ReportController) GetDayWeekReportChapterTypeList() {
 		return
 	}
 
+	dayClassifyId, err := company.GetReportClassifyIdByConfigKey("report_day_classify_id")
+	if err != nil {
+		br.Msg = "获取晨报ID配置失败"
+		br.ErrMsg = "获取配置失败"
+		br.IsSendEmail = false
+		return
+	}
+	weekClassifyId, err := company.GetReportClassifyIdByConfigKey("report_week_classify_id")
+	if err != nil {
+		br.Msg = "获取周报ID配置失败"
+		br.ErrMsg = "获取配置失败"
+		br.IsSendEmail = false
+		return
+	}
+
 	dayList := make([]*models.ReportChapterType, 0)
 	weekList := make([]*models.ReportChapterType, 0)
 
@@ -68,8 +84,8 @@ func (this *ReportController) GetDayWeekReportChapterTypeList() {
 		tmpCondition := condition
 		tmpPars := pars
 		// 报告类型
-		tmpCondition += ` AND research_type = ? `
-		tmpPars = append(tmpPars, "day")
+		tmpCondition += ` AND report_classify_id = ? `
+		tmpPars = append(tmpPars, dayClassifyId)
 
 		list, err := models.GetAllReportChapterTypeList(tmpCondition, tmpPars)
 		if err != nil {
@@ -96,8 +112,8 @@ func (this *ReportController) GetDayWeekReportChapterTypeList() {
 		tmpCondition := condition
 		tmpPars := pars
 		// 报告类型
-		tmpCondition += ` AND research_type = ? `
-		tmpPars = append(tmpPars, "week")
+		tmpCondition += ` AND report_classify_id = ? `
+		tmpPars = append(tmpPars, weekClassifyId)
 
 		list, err := models.GetAllReportChapterTypeList(tmpCondition, tmpPars)
 		if err != nil {
@@ -196,8 +212,26 @@ func (this *ReportController) SetDayWeekReportUpdateRule() {
 		return
 	}
 
+	classifyIdKey := ``
+	switch researchType {
+	case "day":
+		classifyIdKey = `report_day_classify_id`
+	case "week":
+		classifyIdKey = `report_week_classify_id`
+	default:
+		br.Msg = "报告类型异常"
+		return
+	}
+	reportClassifyId, err := company.GetReportClassifyIdByConfigKey(classifyIdKey)
+	if err != nil {
+		br.Msg = "获取分类ID配置失败"
+		br.ErrMsg = "获取配置失败,key:" + classifyIdKey
+		br.IsSendEmail = false
+		return
+	}
+
 	// 设置章节类型的暂停时间
-	if err := models.SetDayWeekReportUpdateRule(researchType, req.List); err != nil {
+	if err := models.SetDayWeekReportUpdateRule(reportClassifyId, req.List); err != nil {
 		br.Msg = "设置暂停时间失败"
 		br.ErrMsg = "设置暂停时间失败, Err: " + err.Error()
 		return
@@ -205,7 +239,7 @@ func (this *ReportController) SetDayWeekReportUpdateRule() {
 	// 同步eta系统的章节更新配置
 	go func() {
 		ruleSyncReq := new(services.EditReportChapterTypeRuleSyncReq)
-		ruleSyncReq.ResearchType = researchType
+		ruleSyncReq.ReportClassifyId = reportClassifyId
 		_, _ = services.EditReportChapterTypeRuleSync(ruleSyncReq)
 	}()
 
@@ -301,24 +335,39 @@ func (this *ReportController) GetStopDayWeekReportChapterTypeList() {
 		return
 	}
 
+	dayClassifyId, err := company.GetReportClassifyIdByConfigKey("report_day_classify_id")
+	if err != nil {
+		br.Msg = "获取晨报ID配置失败"
+		br.ErrMsg = "获取配置失败"
+		br.IsSendEmail = false
+		return
+	}
+	weekClassifyId, err := company.GetReportClassifyIdByConfigKey("report_week_classify_id")
+	if err != nil {
+		br.Msg = "获取周报ID配置失败"
+		br.ErrMsg = "获取配置失败"
+		br.IsSendEmail = false
+		return
+	}
+
 	for _, v := range stopList {
-		if v.ResearchType == "day" {
+		if v.ReportClassifyId == dayClassifyId {
 			stopDay = append(stopDay, v)
-		} else {
+		} else if v.ReportClassifyId == weekClassifyId {
 			stopWeek = append(stopWeek, v)
 		}
 	}
 
-	disableList, err := models.GetDisableUpdateReportChapterTypeListByResearchType()
+	disableList, err := models.GetDisableUpdateReportChapterTypeListByResearchTypeByClassifyIdList([]int{dayClassifyId, weekClassifyId})
 	if err != nil {
 		br.Msg = "获取停止更新报告章节类型列表失败"
 		br.ErrMsg = "获取停止更新报告章节类型列表失败, Err: " + err.Error()
 		return
 	}
 	for _, v := range disableList {
-		if v.ResearchType == "day" {
+		if v.ReportClassifyId == dayClassifyId {
 			disableDay = append(disableDay, v)
-		} else {
+		} else if v.ReportClassifyId == weekClassifyId {
 			disableWeek = append(disableWeek, v)
 		}
 	}

+ 6 - 7
controllers/report_chapter_type.go

@@ -15,7 +15,7 @@ type ReportChapterTypeController struct {
 // List
 // @Title 报告章节列表
 // @Description 报告章节列表
-// @Param   ReportType  query  string  true  "报告类型: day-晨报; week-周报"
+// @Param   ClassifyId  query  int  true  "所属分类id"
 // @Success 200 {object} models.ReportChapterTypePageListResp
 // @router /chapter_type/list [get]
 func (this *ReportChapterTypeController) List() {
@@ -32,16 +32,15 @@ func (this *ReportChapterTypeController) List() {
 		br.Ret = 408
 		return
 	}
-	reportType := this.GetString("ReportType")
-	typeArr := []string{utils.REPORT_TYPE_DAY, utils.REPORT_TYPE_WEEK}
-	if !utils.InArrayByStr(typeArr, reportType) {
-		br.Msg = "请选择报告类型"
+	classifyId, _ := this.GetInt("ClassifyId", 0)
+	if classifyId <= 0 {
+		br.Msg = "请选择分类"
 		return
 	}
 
-	cond := ` AND research_type = ?`
+	cond := ` AND report_classify_id = ?`
 	pars := make([]interface{}, 0)
-	pars = append(pars, reportType)
+	pars = append(pars, classifyId)
 	list, e := models.GetReportChapterTypePageList(cond, pars)
 	if e != nil {
 		br.Msg = "获取失败"

+ 48 - 2
models/company/company_config.go

@@ -1,7 +1,10 @@
 package company
 
 import (
+	"encoding/json"
+	"errors"
 	"github.com/beego/beego/v2/client/orm"
+	"hongze/hz_crm_api/utils"
 )
 
 const (
@@ -9,11 +12,10 @@ const (
 )
 
 type CrmConfig struct {
-	ConfigCode   string `description:"详情Code"`
+	ConfigCode  string `description:"详情Code"`
 	ConfigValue string `description:"详情"`
 }
 
-
 func GetConfigValueByCode(configCode string) (total int, err error) {
 	o := orm.NewOrm()
 	sql := ` SELECT config_value FROM crm_config WHERE config_code=? `
@@ -29,9 +31,53 @@ func CrmConfigUpdate(newValue, configCode string) (err error) {
 	return
 }
 
+// ConfigClassifyId
+// @Description: 后台配置的报告id
+type ConfigClassifyId struct {
+	Debug   int `json:"debug"`
+	Release int `json:"release"`
+}
+
 func GetConfigDetailByCode(configCode string) (item CrmConfig, err error) {
 	o := orm.NewOrm()
 	sql := ` SELECT * FROM crm_config WHERE config_code=? `
 	err = o.Raw(sql, configCode).QueryRow(&item)
 	return
 }
+
+// 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) {
+	// 别问为啥要从配置里拿=_=!
+	confKey := "report_day_classify_id"
+	conf, e := GetConfigDetailByCode(confKey)
+	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
+}

+ 48 - 27
models/report_chapter_type.go

@@ -7,28 +7,30 @@ import (
 )
 
 type ReportChapterType struct {
-	ReportChapterTypeId    int       `orm:"column(report_chapter_type_id);pk" description:"报告章节类型id"`
-	ReportChapterTypeKey   string    `description:"章节key"`
-	ReportChapterTypeThumb string    `description:"H5展示的图片"`
-	BannerUrl              string    `description:"banner显示图片"`
-	ReportChapterTypeName  string    `description:"报告章节类型名称"`
-	Sort                   int       `description:"排序字段"`
-	Enabled                int       `description:"启禁用状态"`
-	CreatedTime            time.Time `description:"创建时间"`
-	LastUpdatedTime        time.Time `description:"更新时间"`
-	ResearchType           string    `description:"研报类型"`
-	SelectedImage          string    `description:"选中时的图片"`
-	UnselectedImage        string    `description:"没选中时的图片"`
-	PcSelectedImage        string    `description:"PC-选中的图片"`
-	PcUnselectedImage      string    `description:"PC-未选中的图片"`
-	EditImgUrl             string    `description:"管理后台编辑时选用的图"`
-	TickerTitle            string    `description:"指标列的标题"`
-	IsShow                 int       `description:"是否显示(研报小程序端根据此字段判断)"`
-	PauseStartTime         string    `description:"暂停开始日期"`
-	PauseEndTime           string    `description:"暂停结束日期"`
-	IsSet                  int       `description:"是否设置:0为设置,1已设置"`
-	YbIconUrl              string    `description:"研报小程序icon"`
-	YbBottomIcon           string    `description:"研报小程序详情底部icon"`
+	ReportChapterTypeId        int       `orm:"column(report_chapter_type_id);pk" description:"报告章节类型id"`
+	ReportChapterTypeKey       string    `description:"章节key"`
+	ReportChapterTypeThumb     string    `description:"H5展示的图片"`
+	BannerUrl                  string    `description:"banner显示图片"`
+	ReportChapterTypeName      string    `description:"报告章节类型名称"`
+	Sort                       int       `description:"排序字段"`
+	Enabled                    int       `description:"启禁用状态"`
+	CreatedTime                time.Time `description:"创建时间"`
+	LastUpdatedTime            time.Time `description:"更新时间"`
+	ResearchType               string    `description:"研报类型"`
+	SelectedImage              string    `description:"选中时的图片"`
+	UnselectedImage            string    `description:"没选中时的图片"`
+	PcSelectedImage            string    `description:"PC-选中的图片"`
+	PcUnselectedImage          string    `description:"PC-未选中的图片"`
+	EditImgUrl                 string    `description:"管理后台编辑时选用的图"`
+	TickerTitle                string    `description:"指标列的标题"`
+	IsShow                     int       `description:"是否显示(研报小程序端根据此字段判断)"`
+	PauseStartTime             string    `description:"暂停开始日期"`
+	PauseEndTime               string    `description:"暂停结束日期"`
+	IsSet                      int       `description:"是否设置:0为设置,1已设置"`
+	YbIconUrl                  string    `description:"研报小程序icon"`
+	YbBottomIcon               string    `description:"研报小程序详情底部icon"`
+	ReportClassifyId           int       `description:"所属分类id"`
+	InheritReportChapterTypeId int       `description:"继承的报告章节类型id"`
 }
 
 func (item *ReportChapterType) Create() (err error) {
@@ -183,7 +185,7 @@ func ResetDayWeekReportUpdateRule(researchType string) (err error) {
 }
 
 // SetDayWeekReportUpdateRule 设置章节类型的暂停时间
-func SetDayWeekReportUpdateRule(researchType string, list []DayWeekReportUpdateRule) (err error) {
+func SetDayWeekReportUpdateRule(classifyId int, list []DayWeekReportUpdateRule) (err error) {
 	o := orm.NewOrm()
 	to, err := o.Begin()
 	if err != nil {
@@ -198,8 +200,8 @@ func SetDayWeekReportUpdateRule(researchType string, list []DayWeekReportUpdateR
 	}()
 
 	// 先将所有品种的状态变更为启用
-	sql := ` UPDATE report_chapter_type SET pause_start_time = null, pause_end_time = null, is_set = 0 WHERE research_type = ?`
-	_, err = to.Raw(sql, researchType).Exec()
+	sql := ` UPDATE report_chapter_type SET pause_start_time = null, pause_end_time = null, is_set = 0 WHERE report_classify_id = ?`
+	_, err = to.Raw(sql, classifyId).Exec()
 	if err != nil {
 		return
 	}
@@ -208,8 +210,8 @@ func SetDayWeekReportUpdateRule(researchType string, list []DayWeekReportUpdateR
 		if v.PauseStartTime == `` || v.PauseEndTime == `` {
 			continue
 		}
-		tmpSql := ` UPDATE report_chapter_type SET pause_start_time = ?, pause_end_time = ?, is_set = 1 WHERE research_type = ? AND report_chapter_type_id = ? `
-		_, err = to.Raw(tmpSql, v.PauseStartTime, v.PauseEndTime, researchType, v.ReportChapterTypeId).Exec()
+		tmpSql := ` UPDATE report_chapter_type SET pause_start_time = ?, pause_end_time = ?, is_set = 1 WHERE report_classify_id = ? AND report_chapter_type_id = ? `
+		_, err = to.Raw(tmpSql, v.PauseStartTime, v.PauseEndTime, classifyId, v.ReportChapterTypeId).Exec()
 		if err != nil {
 			return
 		}
@@ -292,6 +294,25 @@ func GetDisableUpdateReportChapterTypeListByResearchType() (list []*ReportChapte
 	return
 }
 
+// GetDisableUpdateReportChapterTypeListByResearchTypeByClassifyIdList
+// @Description: 根据分类id列表获取停止更新的章节类型列表
+// @author: Roc
+// @datetime 2024-06-18 14:13:50
+// @param classifyIdList []int
+// @return list []*ReportChapterType
+// @return err error
+func GetDisableUpdateReportChapterTypeListByResearchTypeByClassifyIdList(classifyIdList []int) (list []*ReportChapterType, err error) {
+	num := len(classifyIdList)
+	if num <= 0 {
+		return
+	}
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM report_chapter_type WHERE enabled = 0 AND report_classify_id in (` + utils.GetOrmInReplace(num) + `) `
+	_, err = o.Raw(sql, classifyIdList).QueryRows(&list)
+
+	return
+}
+
 // UpdateReportChapterTypeResp 停止更新的报告分类列表
 type UpdateReportChapterTypeResp struct {
 	Day  []*ReportChapterType `description:"所有晨报品种"`

+ 1 - 1
services/report_chapter_type_sync.go

@@ -44,7 +44,7 @@ func EditReportChapterTypeSync(pars *EditReportChapterTypeSyncReq) (err error, e
 }
 
 type EditReportChapterTypeRuleSyncReq struct {
-	ResearchType string `description:"研报类型"`
+	ReportClassifyId int `description:"研报分类id"`
 }
 
 // EditReportChapterTypeRuleSync 同步章节更新设置