123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- 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 // 图片链接
- Style 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 // 图片名称
- Style 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
- }
- // GetItemsByCondition
- // @Description: 根据条件获取所有的审批单
- // @author: Roc
- // @receiver m
- // @datetime 2024-06-27 16:12:55
- // @param condition string
- // @param pars []interface{}
- // @param fieldArr []string
- // @return items []*SmartReportResourceItem
- // @return err error
- func (m *SmartReportResource) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string) (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 `, fields, m.TableName(), condition, order)
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- // SmartReportResourceEditReq 智能研报资源编辑请求体
- type SmartReportResourceEditReq struct {
- ResourceId int `description:"资源ID"`
- ImgName string `description:"图片名称"`
- Style 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 {
- ResourceIds string `description:"资源IDs"`
- }
- // SmartReportResourceAddReq 新增智能研报资源请求体
- type SmartReportResourceAddReq struct {
- Type int `description:"类型 1-版头 2-版尾"`
- ImgUrl string `description:"图片链接"`
- ImgName string `description:"图片名称"`
- Style string `description:"版图样式"`
- }
- func GetResourceItemById(id int) (item *SmartReportResource, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := fmt.Sprintf(`SELECT * FROM smart_report_resource WHERE resource_id = ? LIMIT 1`)
- err = o.Raw(sql, id).QueryRow(&item)
- return
- }
|