|
@@ -5,6 +5,7 @@ import (
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"hongze/hongze_yb/controller/response"
|
|
|
"hongze/hongze_yb/models/request"
|
|
|
+ responseModel "hongze/hongze_yb/models/response"
|
|
|
chartInfoModel "hongze/hongze_yb/models/tables/chart_info"
|
|
|
"hongze/hongze_yb/models/tables/yb_config"
|
|
|
"hongze/hongze_yb/models/tables/yb_my_chart"
|
|
@@ -17,14 +18,50 @@ import (
|
|
|
// MyChartController 用户-我的图表
|
|
|
type MyChartController struct{}
|
|
|
|
|
|
+// List 我的图表列表
|
|
|
func (this *MyChartController) List(c *gin.Context) {
|
|
|
+ var req request.MyChartCollectListReq
|
|
|
+ if c.Bind(&req) != nil {
|
|
|
+ response.Fail("参数有误", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ cond := `1 = 1`
|
|
|
+ pars := make([]interface{}, 0)
|
|
|
+ if req.Keyword != "" {
|
|
|
+ kw := fmt.Sprint("%", req.Keyword, "%")
|
|
|
+ cond += ` AND chart_name LIKE ?`
|
|
|
+ pars = append(pars, kw)
|
|
|
+ }
|
|
|
+ if req.ClassifyId > 0 {
|
|
|
+ cond += ` AND my_chart_classify_id = ?`
|
|
|
+ pars = append(pars, req.ClassifyId)
|
|
|
+ }
|
|
|
|
|
|
+ ob := new(yb_my_chart.YbMyChart)
|
|
|
+ list, e := ob.List(cond, pars)
|
|
|
+ if e != nil {
|
|
|
+ response.FailMsg("获取失败", "获取用户图表列表失败, Err:"+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ respList := make([]*responseModel.MyChartItem, 0)
|
|
|
+ for i := range list {
|
|
|
+ respList = append(respList, &responseModel.MyChartItem{
|
|
|
+ MyChartID: list[i].MyChartID,
|
|
|
+ MyChartClassifyID: list[i].MyChartClassifyID,
|
|
|
+ ChartInfoID: list[i].ChartInfoID,
|
|
|
+ ChartName: list[i].ChartName,
|
|
|
+ UniqueCode: list[i].UniqueCode,
|
|
|
+ ChartImage: list[i].ChartImage,
|
|
|
+ UserID: list[i].UserID,
|
|
|
+ ReportID: list[i].ReportID,
|
|
|
+ ReportChapterID: list[i].ReportChapterID,
|
|
|
+ CreateTime: utils.TimeTransferString(utils.FormatDateTime, list[i].CreateTime),
|
|
|
+ })
|
|
|
+ }
|
|
|
+ response.OkData("获取成功", respList, c)
|
|
|
}
|
|
|
|
|
|
-func (this *MyChartController) Detail(c *gin.Context) {
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
+// Collect 收藏图表
|
|
|
func (this *MyChartController) Collect(c *gin.Context) {
|
|
|
var req request.MyChartCollectReq
|
|
|
if c.ShouldBind(&req) != nil {
|
|
@@ -138,6 +175,7 @@ func (this *MyChartController) Collect(c *gin.Context) {
|
|
|
response.Ok("操作成功", c)
|
|
|
}
|
|
|
|
|
|
+// 取消收藏 CollectCancel
|
|
|
func (this *MyChartController) CollectCancel(c *gin.Context) {
|
|
|
var req request.MyChartCollectCancelReq
|
|
|
if c.ShouldBind(&req) != nil {
|
|
@@ -192,6 +230,7 @@ func (this *MyChartController) CollectCancel(c *gin.Context) {
|
|
|
response.Ok("操作成功", c)
|
|
|
}
|
|
|
|
|
|
+// RelateClassify 加入分类
|
|
|
func (this *MyChartController) RelateClassify(c *gin.Context) {
|
|
|
userInfo := userService.GetInfoByClaims(c)
|
|
|
userId := int(userInfo.UserID)
|
|
@@ -204,7 +243,7 @@ func (this *MyChartController) RelateClassify(c *gin.Context) {
|
|
|
response.Fail("参数有误", c)
|
|
|
return
|
|
|
}
|
|
|
- if req.ChartInfoId <= 0 {
|
|
|
+ if req.MyChartId <= 0 {
|
|
|
response.Fail("请选择图表", c)
|
|
|
return
|
|
|
}
|
|
@@ -213,16 +252,16 @@ func (this *MyChartController) RelateClassify(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- cond := `user_id = ? AND chart_info_id = ?`
|
|
|
- pars := make([]interface{}, 0)
|
|
|
- pars = append(pars, userId, req.ChartInfoId)
|
|
|
ob := new(yb_my_chart.YbMyChart)
|
|
|
- item, e := ob.FetchByCondition(cond, pars)
|
|
|
+ item, e := ob.Fetch(req.MyChartId)
|
|
|
if e != nil {
|
|
|
- response.FailMsg("请先收藏该图表", "获取用户图表失败, Err: "+e.Error(), c)
|
|
|
+ response.FailMsg("图表信息有误", "获取用户图表失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if item.UserID != userId {
|
|
|
+ response.Fail("无权操作", c)
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
item.MyChartClassifyID = req.ClassifyId
|
|
|
item.ModifyTime = time.Now().Local()
|
|
|
if e = item.Update([]string{"MyChartClassifyID", "ModifyTime"}); e != nil {
|
|
@@ -231,3 +270,59 @@ func (this *MyChartController) RelateClassify(c *gin.Context) {
|
|
|
}
|
|
|
response.Ok("操作成功", c)
|
|
|
}
|
|
|
+
|
|
|
+// IsCollect 是否已收藏
|
|
|
+func (this *MyChartController) IsCollect(c *gin.Context) {
|
|
|
+ var req request.MyChartIsCollectReq
|
|
|
+ if c.Bind(&req) != nil {
|
|
|
+ response.Fail("参数有误", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if req.Authorization == "" {
|
|
|
+ response.Fail("用户身份有误", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if req.UniqueCode == "" {
|
|
|
+ response.Fail("请选择图表", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取用户信息
|
|
|
+ userInfo, e := userService.GetUserInfoByToken(req.Authorization)
|
|
|
+ if e != nil {
|
|
|
+ response.FailMsg("操作失败", "Token获取有效用户失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if userInfo.UserID <= 0 {
|
|
|
+ response.FailMsg("操作失败", "Token获取有效用户失败", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ userId := int(userInfo.UserID)
|
|
|
+
|
|
|
+ // 获取图表信息
|
|
|
+ chartInfo, e := chartInfoModel.GetChartInfoViewByUniqueCode(req.UniqueCode)
|
|
|
+ if e != nil {
|
|
|
+ response.FailMsg("操作失败", "UniqueCode获取图表信息失败, Err:"+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if chartInfo.ChartInfoId <= 0 {
|
|
|
+ response.FailMsg("操作失败", "图表信息有误", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 是否已收藏
|
|
|
+ ob := new(yb_my_chart.YbMyChart)
|
|
|
+ cond := `user_id = ? AND chart_info_id = ?`
|
|
|
+ pars := make([]interface{}, 0)
|
|
|
+ pars = append(pars, userId, chartInfo.ChartInfoId)
|
|
|
+ exists, e := ob.FetchByCondition(cond, pars)
|
|
|
+ if e != nil && e != utils.ErrNoRow {
|
|
|
+ response.FailMsg("操作失败", "获取用户图表失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ isCollect := false
|
|
|
+ if exists != nil && exists.MyChartID > 0 {
|
|
|
+ isCollect = true
|
|
|
+ }
|
|
|
+ response.OkData("获取成功", isCollect, c)
|
|
|
+}
|