Browse Source

报告章节管理

xyxie 1 year ago
parent
commit
232fb2bfd2
4 changed files with 310 additions and 140 deletions
  1. 107 130
      controllers/report_chapter_type.go
  2. 22 10
      models/report_chapter_type.go
  3. 18 0
      routers/commentsRouter.go
  4. 163 0
      services/report_chapter_type.go

+ 107 - 130
controllers/report_chapter_type.go

@@ -5,7 +5,6 @@ import (
 	"eta/eta_api/models"
 	"eta/eta_api/services"
 	"eta/eta_api/utils"
-	"github.com/rdlucklib/rdluck_tools/paging"
 	"time"
 )
 
@@ -40,53 +39,15 @@ func (this *ReportChapterTypeController) List() {
 		br.Msg = "请选择报告类型"
 		return
 	}
-
-	pageSize, _ := this.GetInt("PageSize")
-	currentIndex, _ := this.GetInt("CurrentIndex")
-	var startSize int
-	if pageSize <= 0 {
-		pageSize = utils.PageSize20
-	}
-	if currentIndex <= 0 {
-		currentIndex = 1
-	}
-	startSize = paging.StartIndex(currentIndex, pageSize)
-
-	cond := ` AND research_type = ?`
-	pars := make([]interface{}, 0)
-	pars = append(pars, reportType)
-	total, e := models.GetReportChapterTypeCount(cond, pars)
-	if e != nil {
-		br.Msg = "获取失败"
-		br.ErrMsg = "获取报告章节列表总数失败, Err: " + e.Error()
-		return
-	}
-	list, e := models.GetReportChapterTypePageList(cond, pars, startSize, pageSize)
+	var req services.ChapterTypeReq
+	req.ReportType = reportType
+	resp, e := services.GetReportChapterType(req)
 	if e != nil {
 		br.Msg = "获取失败"
-		br.ErrMsg = "获取报告章节列表失败, Err: " + e.Error()
+		br.ErrMsg = "获取章节列表失败, Err: " + e.Error()
 		return
 	}
-	respList := make([]*models.ReportChapterTypeListItem, 0)
-	for i := range list {
-		respList = append(respList, &models.ReportChapterTypeListItem{
-			ReportChapterTypeId:   list[i].ReportChapterTypeId,
-			ReportChapterTypeName: list[i].ReportChapterTypeName,
-			Sort:                  list[i].Sort,
-			CreatedTime:           list[i].CreatedTime.Format(utils.FormatDateTime),
-			ResearchType:          list[i].ResearchType,
-			SelectedImage:         list[i].SelectedImage,
-			UnselectedImage:       list[i].UnselectedImage,
-			WordsImage:            list[i].YbBottomIcon, // 此处的不一样
-			EditImgUrl:            list[i].EditImgUrl,
-			IsShow:                list[i].IsShow,
-		})
-	}
 
-	resp := new(models.ReportChapterTypePageListResp)
-	page := paging.GetPaging(currentIndex, pageSize, total)
-	resp.List = respList
-	resp.Paging = page
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"
@@ -129,48 +90,12 @@ func (this *ReportChapterTypeController) Add() {
 		return
 	}
 	// 重名校验
-	cond := ` AND report_chapter_type_name = ? AND research_type = ?`
-	pars := make([]interface{}, 0)
-	pars = append(pars, req.ReportChapterTypeName, req.ResearchType)
-	exists, e := models.GetReportChapterTypeByCondition(cond, pars)
-	if e != nil && e.Error() != utils.ErrNoRow() {
-		br.Msg = "操作失败"
-		br.ErrMsg = "获取重名报告章节失败, Err:" + e.Error()
-		return
-	}
-	if exists != nil {
-		br.Msg = "章节名称已存在"
-		return
-	}
-
-	nowTime := time.Now().Local()
-	item := new(models.ReportChapterType)
-	item.ReportChapterTypeName = req.ReportChapterTypeName
-	item.Sort = req.Sort
-	item.Enabled = 1
-	item.CreatedTime = nowTime
-	item.LastUpdatedTime = nowTime
-	item.ResearchType = req.ResearchType
-	item.ReportChapterTypeName = req.ReportChapterTypeName
-	item.SelectedImage = req.SelectedImage
-	item.UnselectedImage = req.UnselectedImage
-	item.PcSelectedImage = req.SelectedImage
-	item.PcUnselectedImage = req.UnselectedImage
-	item.EditImgUrl = req.EditImgUrl
-	item.IsSet = 0
-	item.YbIconUrl = req.UnselectedImage
-	item.YbBottomIcon = req.WordsImage
-	item.IsShow = req.IsShow
-	item.ReportChapterTypeThumb = req.EditImgUrl
-	item.BannerUrl = req.UnselectedImage
-	item.ReportChapterTypeKey = req.ReportChapterTypeName
-	item.TickerTitle = req.ReportChapterTypeName
-	if e = item.Create(); e != nil {
-		br.Msg = "操作失败"
-		br.ErrMsg = "新增报告章节失败, Err:" + e.Error()
+	e, msg := services.AddReportChapterType(&req)
+	if e != nil {
+		br.Msg = msg
+		br.ErrMsg = "新增章节失败, Err: " + e.Error()
 		return
 	}
-
 	// 清除小程序端的章节缓存
 	{
 		key := "hongze_yb:report_chapter_type:GetEffectTypeID"
@@ -221,58 +146,16 @@ func (this *ReportChapterTypeController) Edit() {
 		br.Msg = "请选择报告类型"
 		return
 	}
-	// 重名校验
-	cond := ` AND report_chapter_type_name = ? AND research_type = ?`
-	pars := make([]interface{}, 0)
-	pars = append(pars, req.ReportChapterTypeName, req.ResearchType)
-	exists, e := models.GetReportChapterTypeByCondition(cond, pars)
-	if e != nil && e.Error() != utils.ErrNoRow() {
-		br.Msg = "操作失败"
-		br.ErrMsg = "获取重名报告章节失败, Err:" + e.Error()
-		return
-	}
-	if exists != nil && exists.ReportChapterTypeId != req.ReportChapterTypeId {
-		br.Msg = "章节名称已存在"
-		return
-	}
-
-	item, e := models.GetReportChapterTypeById(req.ReportChapterTypeId)
+	ret, e, msg := services.EditReportChapterType(&req)
 	if e != nil {
-		br.Msg = "操作失败"
-		br.ErrMsg = "获取报告章节失败, Err:" + e.Error()
+		br.Msg = msg
+		br.ErrMsg = "编辑章节失败, Err: " + e.Error()
 		return
 	}
-	originName := item.ReportChapterTypeName
-
-	item.ReportChapterTypeName = req.ReportChapterTypeName
-	item.Sort = req.Sort
-	item.ResearchType = req.ResearchType
-	item.SelectedImage = req.SelectedImage
-	item.UnselectedImage = req.UnselectedImage
-	item.PcSelectedImage = req.SelectedImage
-	item.PcUnselectedImage = req.UnselectedImage
-	item.EditImgUrl = req.EditImgUrl
-	item.YbIconUrl = req.UnselectedImage
-	item.YbBottomIcon = req.WordsImage
-	item.IsShow = req.IsShow
-	item.ReportChapterTypeThumb = req.EditImgUrl
-	item.BannerUrl = req.UnselectedImage
-	item.ReportChapterTypeKey = req.ReportChapterTypeName
-	item.TickerTitle = req.ReportChapterTypeName
-	updateCols := []string{"ReportChapterTypeName", "Sort", "ResearchType", "SelectedImage", "UnselectedImage",
-		"PcSelectedImage", "PcUnselectedImage", "EditImgUrl", "YbIconUrl", "YbBottomIcon", "IsShow",
-		"ReportChapterTypeThumb", "BannerUrl", "ReportChapterTypeKey", "TickerTitle",
-	}
-	if e = item.Update(updateCols); e != nil {
-		br.Msg = "操作失败"
-		br.ErrMsg = "更新报告章节失败, Err:" + e.Error()
-		return
-	}
-
 	// 更新研报章节表冗余
-	if originName != req.ReportChapterTypeName {
+	if ret.OriginReportChapterTypeName != req.ReportChapterTypeName {
 		go func() {
-			_ = models.UpdateReportChapterTypeNameByTypeId(item.ReportChapterTypeId, req.ReportChapterTypeName)
+			_ = models.UpdateReportChapterTypeNameByTypeId(req.ReportChapterTypeId, req.ReportChapterTypeName)
 		}()
 	}
 
@@ -502,3 +385,97 @@ func (this *ReportChapterTypeController) PermissionList() {
 	br.Msg = "获取成功"
 	br.Data = respList
 }
+
+// Move
+// @Title 移动章节类型
+// @Description 移动章节类型
+// @Param	request	body models.PermissionMoveReq true "type json string"
+// @Success 200 Ret=200 操作成功
+// @router /chapter_type/move [post]
+func (this *ReportChapterTypeController) Move() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		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 models.ReportChapterTypeMoveReq
+	if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + e.Error()
+		return
+	}
+
+	if req.ReportChapterTypeId == 0 {
+		br.Msg = "请选择要移动的章节类型"
+		return
+	}
+	e, msg := services.MoveReportChapterType(&req)
+	if e != nil {
+		br.Msg = msg
+		br.ErrMsg = "移动品种失败, Err: " + e.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+}
+
+// SetEnabled
+// @Title 设置启用/禁用
+// @Description 移动章节类型
+// @Param	request	body models.PermissionMoveReq true "type json string"
+// @Success 200 Ret=200 操作成功
+// @router /chapter_type/enabled/set [post]
+func (this *ReportChapterTypeController) SetEnabled() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		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 models.ReportChapterTypeEnabledReq
+	if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + e.Error()
+		return
+	}
+
+	if req.ReportChapterTypeId == 0 {
+		br.Msg = "请选择正确的章节类型"
+		return
+	}
+	if req.Enabled != 0 && req.Enabled != 1 {
+		br.Msg = "请选择正确的启用禁用状态"
+		return
+	}
+	e := services.SetEnabledReportChapterType(&req)
+	if e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "设置报告章节状态失败, Err: " + e.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+}

+ 22 - 10
models/report_chapter_type.go

@@ -3,7 +3,6 @@ package models
 import (
 	"eta/eta_api/utils"
 	"github.com/beego/beego/v2/client/orm"
-	"github.com/rdlucklib/rdluck_tools/paging"
 	"time"
 )
 
@@ -299,9 +298,8 @@ type UpdateReportChapterTypeResp struct {
 	Week []*ReportChapterType `description:"所有周报品种"`
 }
 
-type ReportChapterTypePageListResp struct {
-	List   []*ReportChapterTypeListItem
-	Paging *paging.PagingItem `description:"分页数据"`
+type ReportChapterTypeListResp struct {
+	List []*ReportChapterTypeListItem
 }
 
 // GetReportChapterTypeCount 获取章节类型总数
@@ -336,31 +334,33 @@ type ReportChapterTypeListItem struct {
 	WordsImage            string `description:"带字的icon"`
 	EditImgUrl            string `description:"管理后台编辑时选用的图"`
 	IsShow                int    `description:"显示隐藏: 1-显示; 0-隐藏"`
+	ChartPermissionIdList []int  `description:"权限id数组"`
+	Enabled               int
 }
 
 // ReportChapterTypeAddReq 新增章节类型请求体
 type ReportChapterTypeAddReq struct {
 	ReportChapterTypeName string `description:"报告章节类型名称"`
-	Sort                  int    `description:"排序字段"`
 	ResearchType          string `description:"研报类型"`
-	SelectedImage         string `description:"选中时的icon"`
+	ChartPermissionIdList []int  `description:"权限id数组"`
+	/*SelectedImage         string `description:"选中时的icon"`
 	UnselectedImage       string `description:"未选中时的icon"`
 	WordsImage            string `description:"带字的icon"`
 	EditImgUrl            string `description:"管理后台编辑时选用的图"`
-	IsShow                int    `description:"显示隐藏: 1-显示; 0-隐藏"`
+	IsShow                int    `description:"显示隐藏: 1-显示; 0-隐藏"`*/
 }
 
 // ReportChapterTypeEditReq 编辑章节类型请求体
 type ReportChapterTypeEditReq struct {
 	ReportChapterTypeId   int    `description:"报告章节类型id"`
 	ReportChapterTypeName string `description:"报告章节类型名称"`
-	Sort                  int    `description:"排序字段"`
 	ResearchType          string `description:"研报类型"`
-	SelectedImage         string `description:"选中时的icon"`
+	ChartPermissionIdList []int  `description:"权限id数组"`
+	/*SelectedImage         string `description:"选中时的icon"`
 	UnselectedImage       string `description:"未选中时的icon"`
 	WordsImage            string `description:"带字的icon"`
 	EditImgUrl            string `description:"管理后台编辑时选用的图"`
-	IsShow                int    `description:"显示隐藏: 1-显示; 0-隐藏"`
+	IsShow                int    `description:"显示隐藏: 1-显示; 0-隐藏"`*/
 }
 
 // ReportChapterTypeDelReq 删除章节类型请求体
@@ -374,6 +374,18 @@ type ReportChapterTypeAuthSettingReq struct {
 	ChartPermissionIdList []int `description:"权限id数组"`
 }
 
+type ReportChapterTypeMoveReq struct {
+	ReportChapterTypeId int `description:"报告章节类型id"`
+	//	ParentChartPermissionId int `description:"父级品种id"`
+	PrevReportChapterTypeId int `description:"上一个兄弟节点报告章节类型id"`
+	NextReportChapterTypeId int `description:"下一个兄弟节点报告章节类型id"`
+}
+
+type ReportChapterTypeEnabledReq struct {
+	ReportChapterTypeId int `description:"报告章节类型id"`
+	Enabled             int `description:"是否可用,1可用,0禁用"`
+}
+
 // GetReportChapterTypeByCondition 获取章节类型
 func GetReportChapterTypeByCondition(condition string, pars []interface{}) (item *ReportChapterType, err error) {
 	o := orm.NewOrmUsingDB("weekly")

+ 18 - 0
routers/commentsRouter.go

@@ -7117,6 +7117,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers:ReportChapterTypeController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers:ReportChapterTypeController"],
+        beego.ControllerComments{
+            Method: "SetEnabled",
+            Router: `/chapter_type/enabled/set`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers:ReportChapterTypeController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers:ReportChapterTypeController"],
         beego.ControllerComments{
             Method: "List",
@@ -7126,6 +7135,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers:ReportChapterTypeController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers:ReportChapterTypeController"],
+        beego.ControllerComments{
+            Method: "Move",
+            Router: `/chapter_type/move`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers:ReportChapterTypeController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers:ReportChapterTypeController"],
         beego.ControllerComments{
             Method: "PermissionList",

+ 163 - 0
services/report_chapter_type.go

@@ -0,0 +1,163 @@
+package services
+
+import (
+	"encoding/json"
+	"eta/eta_api/models"
+	"eta/eta_api/utils"
+	"fmt"
+)
+
+type ChapterTypeReq struct {
+	ReportType string
+}
+type ChapterTypeResp struct {
+	Code   int                              `json:"code" description:"状态码"`
+	Msg    string                           `json:"msg" description:"提示信息"`
+	Data   models.ReportChapterTypeListResp `json:"data" description:"返回数据"`
+	ErrMsg string                           `json:"-" description:"错误信息,不用返回给前端,只是做日志记录"`
+}
+
+func GetReportChapterType(pars ChapterTypeReq) (res models.ReportChapterTypeListResp, err error) {
+	if utils.CrmEtaServerUrl == "" {
+		return
+	}
+	url := fmt.Sprint(utils.CrmEtaServerUrl, "/api/crm/chapter_type/list")
+	b, err := crmEtaPost(url, pars)
+	if err != nil {
+		err = fmt.Errorf("url:%s err: %s", url, err.Error())
+		return
+	}
+	result := new(ChapterTypeResp)
+	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
+	}
+	res = result.Data
+	return
+}
+
+type ChapterTypeBaseResp struct {
+	Code   int    `json:"code" description:"状态码"`
+	Msg    string `json:"msg" description:"提示信息"`
+	ErrMsg string `json:"-" description:"错误信息,不用返回给前端,只是做日志记录"`
+}
+
+func AddReportChapterType(pars *models.ReportChapterTypeAddReq) (err error, errMsg string) {
+	if utils.CrmEtaServerUrl == "" {
+		return
+	}
+	url := fmt.Sprint(utils.CrmEtaServerUrl, "/api/crm/chapter_type/add")
+	b, err := crmEtaPost(url, pars)
+	if err != nil {
+		errMsg = "新增品种失败"
+		err = fmt.Errorf("url:%s err: %s", url, err.Error())
+		return
+	}
+	result := new(ChapterTypeBaseResp)
+	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
+}
+
+// ReportChapterTypeEditRespData 编辑章节返回
+type ReportChapterTypeEditRespData struct {
+	OriginReportChapterTypeName string `description:"报告章节类型原来的名称"`
+}
+
+type ReportChapterTypeEditResp struct {
+	Code   int                           `json:"code" description:"状态码"`
+	Msg    string                        `json:"msg" description:"提示信息"`
+	Data   ReportChapterTypeEditRespData `json:"data" description:"返回数据"`
+	ErrMsg string                        `json:"-" description:"错误信息,不用返回给前端,只是做日志记录"`
+}
+
+func EditReportChapterType(pars *models.ReportChapterTypeEditReq) (ret ReportChapterTypeEditRespData, err error, errMsg string) {
+	if utils.CrmEtaServerUrl == "" {
+		return
+	}
+	url := fmt.Sprint(utils.CrmEtaServerUrl, "/api/crm/chapter_type/edit")
+	b, err := crmEtaPost(url, pars)
+	if err != nil {
+		errMsg = "更新品种失败"
+		err = fmt.Errorf("url:%s err: %s", url, err.Error())
+		return
+	}
+	result := new(ReportChapterTypeEditResp)
+	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
+	}
+	ret = result.Data
+	return
+}
+
+func MoveReportChapterType(pars *models.ReportChapterTypeMoveReq) (err error, errMsg string) {
+	if utils.CrmEtaServerUrl == "" {
+		return
+	}
+	url := fmt.Sprint(utils.CrmEtaServerUrl, "/api/crm/chapter_type/move")
+	b, err := crmEtaPost(url, pars)
+	if err != nil {
+		errMsg = "移动品种失败"
+		err = fmt.Errorf("url:%s err: %s", url, err.Error())
+		return
+	}
+	result := new(ChapterTypeBaseResp)
+	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
+}
+
+// SetEnabledReportChapterType 设置报告分类权限
+func SetEnabledReportChapterType(req *models.ReportChapterTypeEnabledReq) (err error) {
+	if utils.CrmEtaServerUrl == "" {
+		return
+	}
+	url := fmt.Sprint(utils.CrmEtaServerUrl, "/api/crm/chapter_type/enabled/set")
+	b, err := crmEtaPost(url, req)
+	if err != nil {
+		err = fmt.Errorf("url:%s err: %s", url, err.Error())
+		return
+	}
+	result := new(ChapterTypeBaseResp)
+	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
+	}
+	return
+}