Browse Source

Merge branch 'feature/eta1.6.7_permission' of http://8.136.199.33:3000/hongze/hz_crm_api into feature/eta1.6.7_permission

# Conflicts:
#	services/report_chapter_type_sync.go
xyxie 11 tháng trước cách đây
mục cha
commit
c57039e0ee
6 tập tin đã thay đổi với 407 bổ sung223 xóa
  1. 228 26
      controllers/classify.go
  2. 74 13
      models/classify.go
  3. 57 0
      models/classify_menu.go
  4. 37 0
      models/classify_menu_relation.go
  5. 0 184
      services/classify.go
  6. 11 0
      utils/common.go

+ 228 - 26
controllers/classify.go

@@ -3,8 +3,8 @@ package controllers
 import (
 	"encoding/json"
 	"hongze/hz_crm_api/models"
-	"hongze/hz_crm_api/services"
 	"hongze/hz_crm_api/utils"
+	"time"
 )
 
 // ClassifyController 分类
@@ -26,21 +26,112 @@ func (this *ClassifyController) ListClassify() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
+
 	keyWord := this.GetString("KeyWord")
 	companyType := this.GetString("CompanyType")
 	hideDayWeek, _ := this.GetInt("HideDayWeek")
 
-	req := new(services.GetClassifyListReq)
-	req.Keyword = keyWord
-	req.CompanyType = companyType
-	req.HideDayWeek = hideDayWeek
-	resp, err := services.GetClassifyList(req)
+	reqEnabled, _ := this.GetInt("Enabled", -1)
+	enabled := -1
+	if reqEnabled == 1 {
+		enabled = reqEnabled
+	}
+
+	list, err := models.GetClassifyList(keyWord, companyType, hideDayWeek, enabled)
 	if err != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取失败,Err:" + err.Error()
 		return
 	}
 
+	parentIds := make([]int, 0)
+	for i := range list {
+		parentIds = append(parentIds, list[i].Id)
+	}
+	parentIdLen := len(parentIds)
+	if parentIdLen == 0 {
+		resp := &models.ClassifyListResp{
+			List: list,
+		}
+		br.Data = resp
+		br.Ret = 200
+		br.Success = true
+		br.Msg = "获取成功"
+		return
+	}
+
+	// 获取一级分类-子目录列表
+	menuListMap := make(map[int][]*models.ClassifyMenu, 0)
+	var menuCond string
+	var menuPars []interface{}
+	menuCond += ` AND classify_id IN (` + utils.GetOrmInReplace(parentIdLen) + `)`
+	menuPars = append(menuPars, parentIds)
+	parentMenus, e := models.GetClassifyMenuList(menuCond, menuPars)
+	if e != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取一级分类子目录列表失败"
+		return
+	}
+	for i := range parentMenus {
+		if menuListMap[parentMenus[i].ClassifyId] == nil {
+			menuListMap[parentMenus[i].ClassifyId] = make([]*models.ClassifyMenu, 0)
+		}
+		menuListMap[parentMenus[i].ClassifyId] = append(menuListMap[parentMenus[i].ClassifyId], parentMenus[i])
+	}
+
+	// 获取子分类
+	children, e := models.GetClassifyChildByParentIds(parentIds, keyWord, enabled)
+	if e != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取子分类失败"
+		return
+	}
+	childrenIds := make([]int, 0)
+	for i := range children {
+		childrenIds = append(childrenIds, children[i].Id)
+	}
+	childrenIdsLen := len(childrenIds)
+
+	// 获取二级分类-子目录关联
+	relateMap := make(map[int]int, 0)
+	if childrenIdsLen > 0 {
+		var relateCond string
+		var relatePars []interface{}
+		relateCond += ` AND classify_id IN (` + utils.GetOrmInReplace(childrenIdsLen) + `)`
+		relatePars = append(relatePars, childrenIds)
+		relates, e := models.GetClassifyMenuRelationList(relateCond, relatePars)
+		if e != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取二级分类子目录关联失败, Err: " + e.Error()
+			return
+		}
+		for i := range relates {
+			relateMap[relates[i].ClassifyId] = relates[i].MenuId
+		}
+	}
+
+	// 二级分类
+	childrenMap := make(map[int][]*models.ClassifyItem, 0)
+	for i := range children {
+
+		if childrenMap[children[i].ParentId] == nil {
+			childrenMap[children[i].ParentId] = make([]*models.ClassifyItem, 0)
+		}
+		tmp := &models.ClassifyItem{
+			Classify:       *children[i],
+			ClassifyMenuId: relateMap[children[i].Id],
+		}
+		childrenMap[children[i].ParentId] = append(childrenMap[children[i].ParentId], tmp)
+	}
+
+	// 一级分类
+	for i := range list {
+		list[i].ClassifyMenuList = menuListMap[list[i].Id]
+		list[i].Child = childrenMap[list[i].Id]
+	}
+
+	resp := new(models.ClassifyListResp)
+	resp.List = list
 	br.Data = resp
 	br.Ret = 200
 	br.Success = true
@@ -52,7 +143,6 @@ func (this *ClassifyController) ListClassify() {
 // @Success 200 {object} models.Classify
 // @router /tel_list [get]
 func (this *ClassifyController) TelListClassify() {
-	// todo 获取电话会 是否需要改成从中间服务项目中获取
 	br := new(models.BaseResponse).Init()
 	defer func() {
 		this.Data["json"] = br
@@ -97,43 +187,155 @@ func (this *ClassifyController) TelListClassify() {
 // @router /edit [post]
 func (this *ClassifyController) Edit() {
 	br := new(models.BaseResponse).Init()
-	br.IsSendEmail = false
 	defer func() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
-	sysUser := this.SysUser
-	if sysUser == nil {
-		br.Msg = "请登录"
-		br.ErrMsg = "请登录,SysUser Is Empty"
-		br.Ret = 408
-		return
-	}
-	var req services.EditClassifyReq
-	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
+	var req models.EditClassifyReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
 		br.Msg = "参数解析异常!"
 		br.ErrMsg = "参数解析失败,Err:" + err.Error()
 		return
 	}
+
 	if req.ClassifyId <= 0 {
-		br.Msg = "分类ID有误"
+		br.Msg = "参数错误"
 		return
 	}
 
-	err, errMsg := services.EditReportClassify(&req)
+	item, err := models.GetClassifyById(req.ClassifyId)
 	if err != nil {
-		br.Msg = errMsg
-		br.ErrMsg = "编辑报告分类失败, Err:" + err.Error()
+		if err.Error() == utils.ErrNoRow() {
+			br.Msg = "分类不存在, 或已被删除"
+			br.ErrMsg = "获取分类信息失败, Err: " + err.Error()
+			return
+		}
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取信息失败,Err:" + err.Error()
+		return
+	}
+
+	if item.ParentId != 0 && req.ShowType == 0 {
+		br.Msg = "展示类型不可为空"
+		return
+	}
+	if (req.ShowType == 1 || req.ShowType == 3) && req.YbRightBanner == "" && item.ParentId == 0 { //当一级报告分类为列表、品种时,增加“报告合集配图”的配置项
+		br.Msg = "报告合集配图不可为空"
+		return
+	}
+	//originRelateTel := item.RelateTel
+	item.ModifyTime = time.Now().Local()
+	/*item.Abstract = req.Abstract
+	item.Descript = req.Descript
+	item.ReportAuthor = req.ReportAuthor
+	item.AuthorDescript = req.AuthorDescript
+	item.ColumnImgUrl = req.ColumnImgUrl
+	item.HeadImgUrl = req.HeadImgUrl
+	item.AvatarImgUrl = req.AvatarImgUrl
+	item.ReportImgUrl = req.ReportImgUrl
+	item.HomeImgUrl = req.HomeImgUrl*/
+	item.ClassifyLabel = req.ClassifyLabel
+	item.ShowType = req.ShowType
+	/*	item.HasTeleconference = req.HasTeleconference
+		item.VipTitle = req.VipTitle*/
+	//	item.Sort = req.Sort
+	item.IsShow = req.IsShow
+	item.YbFiccSort = req.YbFiccSort
+	item.YbFiccIcon = req.YbFiccIcon
+	item.YbFiccPcIcon = req.YbFiccPcIcon
+	item.YbIconUrl = req.YbIconUrl
+	item.YbBgUrl = req.YbBgUrl
+	item.YbListImg = req.YbListImg
+	item.YbShareBgImg = req.YbShareBgImg
+	item.YbRightBanner = req.YbRightBanner
+	//item.RelateTel = req.RelateTel
+	item.RelateVideo = req.RelateVideo
+	item.ModifyTime = time.Now().Local()
+	cols := make([]string, 0)
+	/*cols = append(cols, "Abstract", "Descript", "ReportAuthor", "AuthorDescript", "ColumnImgUrl",
+	"HeadImgUrl", "AvatarImgUrl", "ReportImgUrl", "HomeImgUrl", "ClassifyLabel", "ShowType", "HasTeleconference", "VipTitle",
+	"IsShow", "YbFiccSort", "YbFiccIcon", "YbFiccPcIcon", "YbIconUrl", "YbBgUrl", "YbListImg", "YbShareBgImg", "YbRightBanner",
+	"RelateTel", "RelateVideo", "ModifyTime")*/
+	cols = append(cols, "ClassifyLabel", "ShowType",
+		"IsShow", "YbFiccSort", "YbFiccIcon", "YbFiccPcIcon", "YbIconUrl", "YbBgUrl", "YbListImg", "YbShareBgImg", "YbRightBanner", "RelateVideo", "ModifyTime")
+	if e := item.UpdateClassify(cols); e != nil {
+		br.Msg = "修改失败"
+		br.ErrMsg = "修改失败,Err:" + e.Error()
 		return
 	}
 
-	// 清除小程序端的章节缓存
-	{
-		key := "hongze_yb:report_chapter_type:GetEffectTypeID"
-		_ = utils.Rc.Delete(key)
+	// 获取编辑前子目录列表
+	classifyId := item.Id
+	var menuCond string
+	var menuPars []interface{}
+	menuCond += ` AND classify_id = ?`
+	menuPars = append(menuPars, classifyId)
+	menuList, e := models.GetClassifyMenuList(menuCond, menuPars)
+	if e != nil {
+		br.Msg = "保存失败"
+		br.ErrMsg = "获取分类子目录列表失败, Err:" + e.Error()
+		return
+	}
+	oriMenuIds := make([]int, 0)
+	for i := range menuList {
+		oriMenuIds = append(oriMenuIds, menuList[i].MenuId)
+	}
+
+	// 一级分类-新增/编辑/删除子目录
+	if item.ParentId == 0 && len(req.MenuList) > 0 {
+		nowTime := time.Now().Local()
+		insertMenus := make([]*models.ClassifyMenu, 0)
+		editMenus := make([]*models.ClassifyMenu, 0)
+		deleteMenuIds := make([]int, 0)
+		menuIds := make([]int, 0)
+		for i := range req.MenuList {
+			m := req.MenuList[i]
+
+			v := new(models.ClassifyMenu)
+			v.MenuName = req.MenuList[i].MenuName
+			v.ClassifyId = classifyId
+			v.Sort = i + 1
+			v.MenuId = m.MenuId
+			v.ModifyTime = nowTime
+			if v.MenuId > 0 {
+				// 编辑
+				editMenus = append(editMenus, v)
+				menuIds = append(menuIds, m.MenuId)
+			} else {
+				// 新增
+				v.CreateTime = nowTime
+				insertMenus = append(insertMenus, v)
+			}
+		}
+		// 编辑前存在子目录则取"编辑前子目录IDs与编辑时子目录IDs的差集"作为删除IDs
+		if len(oriMenuIds) > 0 {
+			deleteMenuIds = utils.MinusInt(oriMenuIds, menuIds)
+		}
+		if e = models.InsertAndUpdateClassifyMenu(insertMenus, editMenus, deleteMenuIds); e != nil {
+			br.Msg = "保存失败"
+			br.ErrMsg = "新增/编辑/删除分类子目录失败, Err:" + e.Error()
+			return
+		}
+	}
+
+	// 二级分类-新增子目录关联
+	if item.ParentId > 0 {
+		if e := models.DeleteAndInsertClassifyMenuRelation(classifyId, req.ClassifyMenuId); e != nil {
+			br.Msg = "新增子目录关联失败"
+			br.ErrMsg = "新增子目录关联失败, Err:" + e.Error()
+			return
+		}
 	}
 
+	// 关联电话会选项被更改时, 同步FICC活动分类
+	//if originRelateTel != req.RelateTel {
+	//	go func() {
+	//		_ = yb.SyncClassifyAndFiccActivityType()
+	//	}()
+	//}
+
 	br.Ret = 200
 	br.Success = true
-	br.Msg = "操作成功"
+	br.Msg = "修改成功"
 }

+ 74 - 13
models/classify.go

@@ -71,9 +71,9 @@ type ClassifyList struct {
 	YbRightBanner     string    `description:"Pc端详情页,右侧,报告合集背景图"`
 	RelateTel         int       `description:"是否在电话会中可选: 0-否; 1-是"`
 	RelateVideo       int       `description:"是否在路演视频中可选: 0-否; 1-是"`
-	Enabled           int       `description:"是否可用,1可用,0禁用"`
 	Child             []*ClassifyItem
 	ClassifyMenuList  []*ClassifyMenu
+	Enabled           int `description:"是否可用,1可用,0禁用"`
 }
 
 type ClassifyItem struct {
@@ -87,7 +87,7 @@ type ClassifyListResp struct {
 }
 
 // 获取分类列表
-func GetClassifyList(startSize, pageSize int, keyWord, companyType string, hideDayWeek int) (items []*ClassifyList, err error) {
+func GetClassifyList(keyWord, companyType string, hideDayWeek, enabled int) (items []*ClassifyList, err error) {
 	sql := ``
 	companyTypeSqlStr := ``
 	if companyType == "ficc" {
@@ -95,26 +95,33 @@ func GetClassifyList(startSize, pageSize int, keyWord, companyType string, hideD
 	} else if companyType == "权益" {
 		companyTypeSqlStr = " AND (id = 40 or parent_id = 40)  "
 	}
+	if enabled == 1 {
+		companyTypeSqlStr += ` AND enabled = 1 `
+	}
+	pars := make([]interface{}, 0)
 	if keyWord != "" {
 		sql = `SELECT * FROM (
                    SELECT * FROM classify
-                   WHERE parent_id=0 ` + companyTypeSqlStr + `  AND classify_name LIKE '%` + keyWord + `%'
+                   WHERE parent_id=0 ` + companyTypeSqlStr + `  AND classify_name LIKE ?
                    UNION
                    SELECT * FROM classify
-                   WHERE id IN(SELECT parent_id FROM classify
-                   WHERE parent_id>0 ` + companyTypeSqlStr + `  AND classify_name LIKE '%` + keyWord + `%')
+                   WHERE id IN( SELECT parent_id FROM classify
+                   WHERE parent_id>0 ` + companyTypeSqlStr + `  AND classify_name LIKE ? )
                    )AS t
-                   ORDER BY sort ASC,create_time ASC
-                   LIMIT ?,? `
+                   ORDER BY sort ASC,create_time ASC`
+		pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
 	} else {
 		sql = `SELECT * FROM classify WHERE parent_id=0 ` + companyTypeSqlStr
 		if hideDayWeek == 1 {
 			sql += ` AND classify_name <> '晨报' AND classify_name <> '周报' `
 		}
-		sql += ` ORDER BY sort ASC, create_time ASC LIMIT ?,? `
+
+		sql += ` ORDER BY sort ASC, create_time ASC`
 	}
+	pars = append(pars)
+
 	o := orm.NewOrmUsingDB("rddp")
-	_, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
+	_, err = o.Raw(sql, pars...).QueryRows(&items)
 	return
 }
 
@@ -152,19 +159,28 @@ type FindByIdClassifyReq struct {
 	ClassifyId int `description:"分类ID"`
 }
 
-func GetClassifyChildByParentIds(parentId []int, keyWord string) (items []*Classify, err error) {
+func GetClassifyChildByParentIds(parentId []int, keyWord string, enabled int) (items []*Classify, err error) {
 	parentIdLen := len(parentId)
 	if parentIdLen == 0 {
 		return
 	}
 	o := orm.NewOrmUsingDB("rddp")
 	sql := ``
+	pars := make([]interface{}, 0)
+	pars = append(pars, parentId)
 	if keyWord != "" {
-		sql = `SELECT * FROM classify WHERE parent_id IN (` + utils.GetOrmInReplace(parentIdLen) + `) AND classify_name LIKE '%` + keyWord + `%' ORDER BY create_time ASC `
+		sql = `SELECT * FROM classify WHERE parent_id IN (` + utils.GetOrmInReplace(parentIdLen) + `) AND classify_name LIKE ? `
+		pars = append(pars, utils.GetLikeKeyword(keyWord))
 	} else {
-		sql = `SELECT * FROM classify WHERE parent_id IN (` + utils.GetOrmInReplace(parentIdLen) + `) ORDER BY create_time ASC `
+		sql = `SELECT * FROM classify WHERE parent_id IN (` + utils.GetOrmInReplace(parentIdLen) + `) `
 	}
-	_, err = o.Raw(sql, parentId).QueryRows(&items)
+
+	if enabled == 1 {
+		sql += ` AND enabled=1 `
+	}
+	sql += ` ORDER BY create_time ASC `
+	_, err = o.Raw(sql, pars...).QueryRows(&items)
+
 	return
 }
 
@@ -200,3 +216,48 @@ func GetClassifyByCondition(condition, orderRule string, pars []interface{}) (it
 	_, err = o.Raw(sql, pars).QueryRows(&items)
 	return
 }
+
+type EditClassifyReq struct {
+	ClassifyId int `description:"分类ID"`
+	/*Abstract          string                 `description:"栏目简介"`
+	Descript          string                 `description:"分享描述"`
+	ReportAuthor      string                 `description:"栏目作者"`
+	AuthorDescript    string                 `description:"作者简介"`
+	ColumnImgUrl      string                 `description:"栏目配图"`
+	ReportImgUrl      string                 `description:"报告配图"`
+	HeadImgUrl        string                 `description:"头部banner"`
+	AvatarImgUrl      string                 `description:"头像"`
+	HomeImgUrl        string                 `description:"首页配图"`*/
+	ClassifyLabel string `description:"分类标签"`
+	ShowType      int    `description:"展示类型:1-列表 2-专栏"`
+	/*HasTeleconference int                    `description:"是否有电话会:0-否 1-是"`
+	VipTitle          string                 `description:"研究员头衔"`*/
+	//Sort              int                    `description:"后台排序"`
+	IsShow         int                    `description:"是否在小程序显示:1-显示 0-隐藏"`
+	YbFiccSort     int                    `description:"小程序FICC页排序"`
+	YbFiccIcon     string                 `description:"小程序FICC页icon"`
+	YbFiccPcIcon   string                 `description:"小程序PC端FICC页背景图"`
+	YbIconUrl      string                 `description:"小程序已购页icon"`
+	YbBgUrl        string                 `description:"小程序已购详情背景图"`
+	YbListImg      string                 `description:"小程序研报列表封面图"`
+	YbShareBgImg   string                 `description:"小程序研报详情分享背景图"`
+	YbRightBanner  string                 `description:"Pc端详情页,右侧,报告合集背景图"`
+	MenuList       []*ClassifyMenuSaveReq `description:"子目录列表"`
+	ClassifyMenuId int                    `description:"二级分类-子目录ID"`
+	//RelateTel      int                    `description:"是否在电话会中可选: 0-否; 1-是"`
+	RelateVideo int `description:"是否在路演视频中可选: 0-否; 1-是"`
+}
+
+// ClassifyMenuSaveReq 保存分类子目录请求体
+type ClassifyMenuSaveReq struct {
+	MenuId   int    `description:"子目录ID, 0为新增, 大于0为编辑"`
+	MenuName string `description:"子目录名称"`
+}
+
+// UpdateClassify 更新分类
+func (classifyInfo *Classify) UpdateClassify(cols []string) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	_, err = o.Update(classifyInfo, cols...)
+
+	return
+}

+ 57 - 0
models/classify_menu.go

@@ -1,6 +1,7 @@
 package models
 
 import (
+	"fmt"
 	"github.com/beego/beego/v2/client/orm"
 	"time"
 )
@@ -32,3 +33,59 @@ func GetClassifyMenuList(condition string, pars []interface{}) (list []*Classify
 	_, err = o.Raw(sql, pars).QueryRows(&list)
 	return
 }
+
+// InsertAndUpdateClassifyMenu 新增/编辑/删除分类子目录
+func InsertAndUpdateClassifyMenu(insertMenus []*ClassifyMenu, editMenus []*ClassifyMenu, deleteMenuIds []int) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	tx, err := o.Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = tx.Rollback()
+		} else {
+			_ = tx.Commit()
+		}
+	}()
+
+	// 编辑
+	sql := ``
+	if len(editMenus) > 0 {
+		for i := range editMenus {
+			sql = fmt.Sprintf(`UPDATE classify_menu SET menu_name = '%s', sort = %d, modify_time = NOW() WHERE menu_id = %d`,
+				editMenus[i].MenuName, editMenus[i].Sort, editMenus[i].MenuId)
+			if _, e := tx.Raw(sql).Exec(); e != nil {
+				err = e
+				return
+			}
+		}
+	}
+
+	// 删除
+	if len(deleteMenuIds) > 0 {
+		for i := range deleteMenuIds {
+			sql = fmt.Sprintf(`DELETE FROM classify_menu WHERE menu_id = %d LIMIT 1`, deleteMenuIds[i])
+			if _, e := tx.Raw(sql).Exec(); e != nil {
+				err = e
+				return
+			}
+			// 删除关联关系
+			sql = fmt.Sprintf(`DELETE FROM classify_menu_relation WHERE menu_id = %d`, deleteMenuIds[i])
+			if _, e := tx.Raw(sql).Exec(); e != nil {
+				err = e
+				return
+			}
+		}
+	}
+
+	// 新增
+	if len(insertMenus) > 0 {
+		_, e := tx.InsertMulti(len(insertMenus), insertMenus)
+		if e != nil {
+			err = e
+			return
+		}
+	}
+	return
+}

+ 37 - 0
models/classify_menu_relation.go

@@ -22,3 +22,40 @@ func GetClassifyMenuRelationList(condition string, pars []interface{}) (list []*
 	_, err = o.Raw(sql, pars).QueryRows(&list)
 	return
 }
+
+// DeleteAndInsertClassifyMenuRelation 新增子目录关联
+func DeleteAndInsertClassifyMenuRelation(classifyId, menuId int) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	tx, err := o.Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = tx.Rollback()
+		} else {
+			_ = tx.Commit()
+		}
+	}()
+
+	// 删除
+	sql := `DELETE FROM classify_menu_relation WHERE classify_id = ?`
+	if _, e := tx.Raw(sql, classifyId).Exec(); e != nil {
+		err = e
+		return
+	}
+
+	// 新增
+	if menuId > 0 {
+		relate := &ClassifyMenuRelation{
+			ClassifyId: classifyId,
+			MenuId:     menuId,
+			CreateTime: time.Now().Local(),
+		}
+		_, e := tx.Insert(relate)
+		if e != nil {
+			err = e
+		}
+	}
+	return
+}

+ 0 - 184
services/classify.go

@@ -1,184 +0,0 @@
-package services
-
-import (
-	"encoding/json"
-	"fmt"
-	"hongze/hz_crm_api/models"
-	"hongze/hz_crm_api/utils"
-	"io/ioutil"
-	"net/http"
-	"strings"
-)
-
-type GetClassifyListReq struct {
-	Keyword     string
-	CompanyType string
-	HideDayWeek int
-}
-
-type ClassifySetEnabledReq struct {
-	ClassifyId int `description:"分类ID"`
-	Enabled    int `description:"是否可用,1可用,0禁用"`
-}
-
-type EditClassifyReq struct {
-	ClassifyId int `description:"分类ID"`
-	/*Abstract          string                 `description:"栏目简介"`
-	Descript          string                 `description:"分享描述"`
-	ReportAuthor      string                 `description:"栏目作者"`
-	AuthorDescript    string                 `description:"作者简介"`
-	ColumnImgUrl      string                 `description:"栏目配图"`
-	ReportImgUrl      string                 `description:"报告配图"`
-	HeadImgUrl        string                 `description:"头部banner"`
-	AvatarImgUrl      string                 `description:"头像"`
-	HomeImgUrl        string                 `description:"首页配图"`*/
-	ClassifyLabel string `description:"分类标签"`
-	ShowType      int    `description:"展示类型:1-列表 2-专栏"`
-	/*HasTeleconference int                    `description:"是否有电话会:0-否 1-是"`
-	VipTitle          string                 `description:"研究员头衔"`*/
-	//Sort              int                    `description:"后台排序"`
-	IsShow         int                    `description:"是否在小程序显示:1-显示 0-隐藏"`
-	YbFiccSort     int                    `description:"小程序FICC页排序"`
-	YbFiccIcon     string                 `description:"小程序FICC页icon"`
-	YbFiccPcIcon   string                 `description:"小程序PC端FICC页背景图"`
-	YbIconUrl      string                 `description:"小程序已购页icon"`
-	YbBgUrl        string                 `description:"小程序已购详情背景图"`
-	YbListImg      string                 `description:"小程序研报列表封面图"`
-	YbShareBgImg   string                 `description:"小程序研报详情分享背景图"`
-	YbRightBanner  string                 `description:"Pc端详情页,右侧,报告合集背景图"`
-	MenuList       []*ClassifyMenuSaveReq `description:"子目录列表"`
-	ClassifyMenuId int                    `description:"二级分类-子目录ID"`
-	RelateTel      int                    `description:"是否在电话会中可选: 0-否; 1-是"`
-	RelateVideo    int                    `description:"是否在路演视频中可选: 0-否; 1-是"`
-}
-
-// ClassifyMenuSaveReq 保存分类子目录请求体
-type ClassifyMenuSaveReq struct {
-	MenuId   int    `description:"子目录ID, 0为新增, 大于0为编辑"`
-	MenuName string `description:"子目录名称"`
-}
-
-type CrmEtaBaseResp struct {
-	Code   int    `json:"code" description:"状态码"`
-	Msg    string `json:"msg" description:"提示信息"`
-	ErrMsg string `json:"-" description:"错误信息,不用返回给前端,只是做日志记录"`
-}
-
-func crmEtaPost(url string, param interface{}) (respBody []byte, err error) {
-	data, e := json.Marshal(param)
-	if e != nil {
-		err = fmt.Errorf("data json marshal err: %s", e.Error())
-		return
-	}
-
-	body := ioutil.NopCloser(strings.NewReader(string(data)))
-	client := &http.Client{}
-	req, e := http.NewRequest("POST", url, body)
-	if e != nil {
-		err = fmt.Errorf("http create request err: %s", e.Error())
-		return
-	}
-
-	contentType := "application/json;charset=utf-8"
-	req.Header.Set("Content-Type", contentType)
-	req.Header.Set("Authorization", utils.CrmEtaAuthorization)
-	resp, e := client.Do(req)
-	if e != nil {
-		err = fmt.Errorf("http client do err: %s", e.Error())
-		return
-	}
-	defer func() {
-		_ = resp.Body.Close()
-	}()
-	b, e := ioutil.ReadAll(resp.Body)
-	if e != nil {
-		err = fmt.Errorf("resp body read err: %s", e.Error())
-		return
-	}
-	if len(b) == 0 {
-		err = fmt.Errorf("resp body is empty")
-		return
-	}
-	// 生产环境解密, 注意有个坑前后的双引号
-	if utils.RunMode == "release" {
-		str := string(b)
-		str = strings.Trim(str, `"`)
-		b = utils.DesBase64Decrypt([]byte(str))
-	}
-
-	respBody = b
-	return
-}
-
-func EditReportClassify(pars *EditClassifyReq) (err error, errMsg string) {
-	if utils.CrmEtaServerUrl == "" {
-		return
-	}
-	url := fmt.Sprint(utils.CrmEtaServerUrl, "/api/eta/classify/edit")
-	b, err := crmEtaPost(url, pars)
-	if err != nil {
-		errMsg = "更新品种失败"
-		err = fmt.Errorf("url:%s err: %s", url, err.Error())
-		return
-	}
-	result := new(CrmEtaBaseResp)
-	if e := json.Unmarshal(b, &result); e != nil {
-		errMsg = "更新分类失败"
-		err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
-		return
-	}
-	utils.FileLog.Info("%s", string(b))
-	if result.Code != 200 {
-		err = fmt.Errorf("result: %s, err: %s", string(b), result.ErrMsg)
-		errMsg = result.Msg
-		return
-	}
-	return
-}
-
-type EditClassifyPermissionReq struct {
-	Keyword               string
-	ChartPermissionIdList []int `description:"权限id数组"`
-	NewKeyword            string
-}
-
-// GetClassifyList 获取报告分类已绑定的权限
-func GetClassifyList(req *GetClassifyListReq) (list models.ClassifyListResp, err error) {
-	if utils.CrmEtaServerUrl == "" {
-		return
-	}
-	url := fmt.Sprint(utils.CrmEtaServerUrl, "/api/eta/classify/list")
-	b, err := crmEtaPost(url, req)
-	if err != nil {
-		err = fmt.Errorf("url:%s err: %s", url, err.Error())
-		return
-	}
-	//result := new(models.ResultData)
-	result := new(GetClassifyListResp)
-	if e := json.Unmarshal(b, &result); e != nil {
-		err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
-		return
-	}
-	utils.FileLog.Info("%s", string(b))
-	if result.Code != 200 {
-		err = fmt.Errorf("result: %s", string(b))
-		return
-	}
-	list = result.Data
-	return
-}
-
-type ClassifyPermissionReq struct {
-	Keyword string
-}
-
-type ClassifyPermissionList struct {
-	List []*models.ChartPermissionSearchKeyWordMapping
-}
-
-type GetClassifyListResp struct {
-	Code   int                     `json:"code" description:"状态码"`
-	Msg    string                  `json:"msg" description:"提示信息"`
-	Data   models.ClassifyListResp `json:"data" description:"返回数据"`
-	ErrMsg string                  `json:"-" description:"错误信息,不用返回给前端,只是做日志记录"`
-}

+ 11 - 0
utils/common.go

@@ -2201,3 +2201,14 @@ func GetLikeKeywordPars(pars []interface{}, keyword string, num int) (newPars []
 	}
 	return
 }
+
+// GetLikeKeyword
+//
+//	@Description: 获取sql查询中的like查询字段
+//	@author: Roc
+//	@datetime2023-10-23 14:46:32
+//	@param keyword string
+//	@return string
+func GetLikeKeyword(keyword string) string {
+	return `%` + keyword + `%`
+}