zwxi 1 年之前
父節點
當前提交
00e7f6a7b7
共有 5 個文件被更改,包括 447 次插入0 次删除
  1. 302 0
      controllers/smart_report/smart_resource.go
  2. 1 0
      models/db.go
  3. 107 0
      models/smart_report/smart_resource.go
  4. 36 0
      routers/commentsRouter.go
  5. 1 0
      routers/router.go

+ 302 - 0
controllers/smart_report/smart_resource.go

@@ -0,0 +1,302 @@
+package smart_report
+
+import (
+	"encoding/json"
+	"eta/eta_api/controllers"
+	"eta/eta_api/models"
+	"eta/eta_api/models/smart_report"
+	"eta/eta_api/utils"
+	"fmt"
+	"github.com/rdlucklib/rdluck_tools/paging"
+	"strings"
+	"time"
+)
+
+// SmartReportResourceController 智能研报资源库
+type SmartReportResourceController struct {
+	controllers.BaseAuthController
+}
+
+// List
+// @Title 资源库列表
+// @Description 资源库列表
+// @Param   PageSize			query	int		true	"每页数据条数"
+// @Param   CurrentIndex		query	int		true	"当前页页码"
+// @Param   Type				query	int		false	"资源类型: 1-版头; 2-版尾"
+// @Param   Keyword				query	string	false	"搜索关键词"
+// @Success 200 {object} smart_report.SmartReportListResp
+// @router /resource/list [get]
+func (this *SmartReportResourceController) List() {
+	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
+	}
+	type SmartReportResourceListReq struct {
+		PageSize     int    `form:"PageSize"`
+		CurrentIndex int    `form:"CurrentIndex"`
+		Type         int    `form:"Type"`
+		Keyword      string `form:"Keyword"`
+	}
+	params := new(SmartReportResourceListReq)
+	if e := this.ParseForm(params); e != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "入参解析失败, Err: " + e.Error()
+		return
+	}
+
+	var condition string
+	var pars []interface{}
+	// 筛选项
+	{
+		keyword := strings.TrimSpace(params.Keyword)
+		if keyword != "" {
+			kw := fmt.Sprint("%", keyword, "%")
+			condition += fmt.Sprintf(` AND img_name LIKE ?`)
+			pars = append(pars, kw)
+		}
+
+		if params.Type > 0 {
+			condition += ` AND type = ?`
+			pars = append(pars, params.Type)
+		}
+	}
+
+	resp := new(smart_report.SmartReportResourceListResp)
+	reportOB := new(smart_report.SmartReportResource)
+	total, e := reportOB.GetCountByCondition(condition, pars)
+	if e != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取报告总数失败, Err:" + e.Error()
+		return
+	}
+	if total <= 0 {
+		page := paging.GetPaging(params.CurrentIndex, params.PageSize, total)
+		resp.Paging = page
+		br.Ret = 200
+		br.Success = true
+		br.Msg = "获取成功"
+		br.Data = resp
+		return
+	}
+
+	// 分页列表
+	var startSize int
+	if params.PageSize <= 0 {
+		params.PageSize = utils.PageSize20
+	}
+	if params.CurrentIndex <= 0 {
+		params.CurrentIndex = 1
+	}
+	startSize = utils.StartIndex(params.CurrentIndex, params.PageSize)
+
+	fields := []string{
+		"resource_id",  "create_time", "img_name", "img_url",
+	}
+	if params.Type > 0 {
+		fields = []string{
+			"resource_id",  "create_time", "img_name", "img_url", "type",
+		}
+	}
+	list, e := reportOB.GetPageItemsByCondition(condition, pars, fields, startSize, params.PageSize)
+	if e != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取资源库分页列表失败, Err:" + e.Error()
+		return
+	}
+
+	page := paging.GetPaging(params.CurrentIndex, params.PageSize, total)
+	resp.Paging = page
+	resp.List = list
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// Rename
+// @Title 重命名
+// @Description 重命名
+// @Param	request	body smart_report.SmartReportPublishReq true "type json string"
+// @Success 200 string "操作成功"
+// @router /resource/rename [post]
+func (this *SmartReportResourceController) Rename() {
+	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 smart_report.SmartReportRenameReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.ResourceId <= 0 {
+		br.Msg = "参数有误"
+		br.ErrMsg = "报告ID为空"
+		return
+	}
+
+	ob := new(smart_report.SmartReportResource)
+	item, e := ob.GetItemById(req.ResourceId)
+	if e != nil {
+		if e.Error() == utils.ErrNoRow() {
+			br.Msg = "资源不存在, 请刷新页面"
+			return
+		}
+		br.Msg = "操作失败"
+		br.ErrMsg = "获取资源图片失败, Err: " + e.Error()
+		return
+	}
+
+	cols := []string{"ImgName"}
+	item.ImgName = req.ImgName
+
+	if e = item.Update(cols); e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "更新资源失败, Err: " + e.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+}
+
+// Remove
+// @Title 删除
+// @Description 删除
+// @Param	request	body smart_report.SmartReportRemoveReq true "type json string"
+// @Success 200 string "操作成功"
+// @router /resource/remove [post]
+func (this *SmartReportResourceController) Remove() {
+	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 smart_report.SmartReportResourceRemoveReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.ResourceId <= 0 {
+		br.Msg = "参数有误"
+		br.ErrMsg = "报告ID为空"
+		return
+	}
+
+	ob := new(smart_report.SmartReportResource)
+	item, e := ob.GetItemById(req.ResourceId)
+	if e != nil {
+		if e.Error() == utils.ErrNoRow() {
+			br.Ret = 200
+			br.Success = true
+			br.Msg = "操作成功"
+			return
+		}
+		br.Msg = "操作失败"
+		br.ErrMsg = "获取资源失败, Err: " + e.Error()
+		return
+	}
+	if e = item.Del(); e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "删除资源失败, Err: " + e.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+}
+
+// Add
+// @Title 新增
+// @Description 新增
+// @Param	request	body smart_report.SmartReportAddReq true "type json string"
+// @Success 200 {object} smart_report.SmartReportItem
+// @router /resource/add [post]
+func (this *SmartReportResourceController) Add() {
+	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 smart_report.SmartReportResourceAddReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.Type != 1 && req.Type != 2 {
+		br.Msg = "请选择新增方式"
+		return
+	}
+
+	req.ImgName = strings.TrimSpace(req.ImgName)
+	if req.ImgName == "" {
+		br.Msg = "请输入图片名称"
+		return
+	}
+
+	item := new(smart_report.SmartReportResource)
+	item.Type = req.Type
+	item.ImgName = req.ImgName
+	item.ImgUrl = req.ImgUrl
+	item.CreateTime = time.Now().Local()
+
+	if e := item.Create(); e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "新增资源失败, Err: " + e.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+}

+ 1 - 0
models/db.go

@@ -454,5 +454,6 @@ func initSmartReport() {
 	orm.RegisterModel(
 		new(smart_report.SmartReport),        // 智能研报主表
 		new(smart_report.SmartReportSaveLog), // 智能研报-保存记录表
+		new(smart_report.SmartReportResource), // 智能研报-资源表
 	)
 }

+ 107 - 0
models/smart_report/smart_resource.go

@@ -0,0 +1,107 @@
+package smart_report
+
+import (
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+	"github.com/rdlucklib/rdluck_tools/paging"
+	"strings"
+	"time"
+)
+
+type SmartReportResource struct {
+	ResourceId int       `orm:"column(resource_id);pk" description:"智能研报资源ID"`
+	ImgUrl     string    // 图片链接
+	ImgName    string    // 图片名称
+	Type       int       // 类型 1-版头 2-版尾
+	CreateTime time.Time // 创建时间
+}
+
+func (m *SmartReportResource) TableName() string {
+	return "smart_report_resource"
+}
+
+func (m *SmartReportResource) PrimaryId() string {
+	return "resource_id"
+}
+
+func (m *SmartReportResource) Create() (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	id, err := o.Insert(m)
+	if err != nil {
+		return
+	}
+	m.ResourceId = int(id)
+	return
+}
+
+func (m *SmartReportResource) Update(cols []string) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	_, err = o.Update(m, cols...)
+	return
+}
+
+func (m *SmartReportResource) Del() (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
+	_, err = o.Raw(sql, m.ResourceId).Exec()
+	return
+}
+
+type SmartReportResourceItem struct {
+	ResourceId int    `orm:"column(resource_id);pk" description:"智能研报资源ID"`
+	ImgUrl     string // 图片链接
+	ImgName    string // 图片名称
+	Type       int    // 类型 1-版头 2-版尾
+	CreateTime string // 创建时间
+}
+
+// SmartReportResourceListResp 智能研报资源库
+type SmartReportResourceListResp struct {
+	List   []*SmartReportResourceItem
+	Paging *paging.PagingItem `description:"分页数据"`
+}
+
+func (m *SmartReportResource) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
+	err = o.Raw(sql, pars).QueryRow(&count)
+	return
+}
+
+func (m *SmartReportResource) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, startSize, pageSize int) (items []*SmartReportResourceItem, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	fields := strings.Join(fieldArr, ",")
+	if len(fieldArr) == 0 {
+		fields = `*`
+	}
+	order := ` ORDER BY create_time DESC`
+
+	sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+// SmartReportRenameReq 智能研报资源重命名请求体
+type SmartReportRenameReq struct {
+	ResourceId int    `description:"资源ID"`
+	ImgName    string `description:"图片名称"`
+}
+
+func (m *SmartReportResource) GetItemById(id int) (item *SmartReportResource, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
+	err = o.Raw(sql, id).QueryRow(&item)
+	return
+}
+
+// SmartReportResourceRemoveReq 删除智能研报资源请求体
+type SmartReportResourceRemoveReq struct {
+	ResourceId int `description:"资源ID"`
+}
+
+// SmartReportResourceAddReq 新增智能研报资源请求体
+type SmartReportResourceAddReq struct {
+	Type    int    `description:"类型 1-版头 2-版尾"`
+	ImgUrl  string `description:"图片链接"`
+	ImgName string `description:"图片名称"`
+}

+ 36 - 0
routers/commentsRouter.go

@@ -4912,6 +4912,42 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers/smart_report:SmartReportResourceController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/smart_report:SmartReportResourceController"],
+        beego.ControllerComments{
+            Method: "Add",
+            Router: `/resource/add`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/smart_report:SmartReportResourceController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/smart_report:SmartReportResourceController"],
+        beego.ControllerComments{
+            Method: "List",
+            Router: `/resource/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/smart_report:SmartReportResourceController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/smart_report:SmartReportResourceController"],
+        beego.ControllerComments{
+            Method: "Remove",
+            Router: `/resource/remove`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/smart_report:SmartReportResourceController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/smart_report:SmartReportResourceController"],
+        beego.ControllerComments{
+            Method: "Rename",
+            Router: `/resource/rename`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers/trade_analysis:TradeAnalysisController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/trade_analysis:TradeAnalysisController"],
         beego.ControllerComments{
             Method: "GetClassifyName",

+ 1 - 0
routers/router.go

@@ -303,6 +303,7 @@ func init() {
 		web.NSNamespace("/smart_report",
 			web.NSInclude(
 				&smart_report.SmartReportController{},
+				&smart_report.SmartReportResourceController{},
 			),
 		),
 	)