package smart_report import ( "eta_gn/eta_api/global" "fmt" "strings" "time" "github.com/rdlucklib/rdluck_tools/paging" ) type SmartReportResource struct { ResourceId int `orm:"column(resource_id);pk" gorm:"column:resource_id;primaryKey" description:"智能研报资源ID"` ImgUrl string `gorm:"column:img_url" description:"图片链接"` // 图片链接 Style string `gorm:"column:style" description:"版图样式"` // 版图样式 ImgName string `gorm:"column:img_name" description:"图片名称"` // 图片名称 Type int `gorm:"column:type" description:"类型 1-版头 2-版尾"` // 类型 1-版头 2-版尾 CreateTime time.Time `gorm:"column:create_time" description:"创建时间"` // 创建时间 } func (m *SmartReportResource) TableName() string { return "smart_report_resource" } func (m *SmartReportResource) PrimaryId() string { return "resource_id" } func (m *SmartReportResource) Create() (err error) { o := global.DmSQL["rddp"] err = o.Create(m).Error return } func (m *SmartReportResource) Update(cols []string) (err error) { o := global.DmSQL["rddp"] err = o.Model(m).Select(cols).Updates(m).Error return } func (m *SmartReportResource) Del() (err error) { o := global.DmSQL["rddp"] sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId()) err = o.Exec(sql, m.ResourceId).Error return } type SmartReportResourceItem struct { ResourceId int `orm:"column(resource_id);pk" gorm:"column:resource_id;primaryKey" description:"智能研报资源ID"` ImgUrl string `gorm:"column:img_url" description:"图片链接"` // 图片链接 ImgName string `gorm:"column:img_name" description:"图片名称"` // 图片名称 Style string `gorm:"column:style" description:"版图样式"` // 版图样式 Type int `gorm:"column:type" description:"类型 1-版头 2-版尾"` // 类型 1-版头 2-版尾 CreateTime string `gorm:"column:create_time" description:"创建时间"` // 创建时间 } // SmartReportResourceListResp 智能研报资源库 type SmartReportResourceListResp struct { List []*SmartReportResourceItem Paging *paging.PagingItem `description:"分页数据"` } func (m *SmartReportResource) GetCountByCondition(condition string, pars []interface{}) (count int, err error) { o := global.DmSQL["rddp"] sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition) err = o.Raw(sql, pars...).Scan(&count).Error return } func (m *SmartReportResource) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, startSize, pageSize int) (items []*SmartReportResourceItem, err error) { o := global.DmSQL["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) pars = append(pars, startSize, pageSize) err = o.Raw(sql, pars...).Find(&items).Error 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 := global.DmSQL["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...).Find(&items).Error 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 := global.DmSQL["rddp"] sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId()) err = o.Raw(sql, id).First(&item).Error 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 := global.DmSQL["rddp"] sql := fmt.Sprintf(`SELECT * FROM smart_report_resource WHERE resource_id = ? LIMIT 1`) err = o.Raw(sql, id).First(&item).Error return }