package cygx import ( "github.com/beego/beego/v2/client/orm" "github.com/rdlucklib/rdluck_tools/paging" "hongze/hz_crm_api/utils" "time" ) type CygxGushouTimeLine struct { TimeLineId int `orm:"column(time_line_id);pk"` PublishTime time.Time `description:"发布日期"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` Status int `description:"0:未发布,1:已发布"` Content string `description:"内容"` ArticleId int `description:"文章ID"` ChartId int `description:"图表ID"` Link string `description:"文章或图表链接"` AdminId int `description:"管理员ID"` } type AddGushouTimeLineReq struct { TimeLineId int `orm:"column(time_line_id);pk"` PublishTime string `description:"发布日期"` Content string `description:"内容"` Link string `description:"文章或图表链接"` } type GushouTimeLineTimeLineIdReq struct { TimeLineId int `description:"ID"` } // 添加 func AddCygxGushouTimeLine(item *CygxGushouTimeLine) (err error) { o := orm.NewOrmUsingDB("hz_cygx") _, err = o.Insert(item) return } // 修改 func UpdateCygxGushouTimeLine(item *CygxGushouTimeLine) (err error) { to := orm.NewOrmUsingDB("hz_cygx") updateParams := make(map[string]interface{}) updateParams["PublishTime"] = item.PublishTime updateParams["ModifyTime"] = item.ModifyTime updateParams["Content"] = item.Content updateParams["ArticleId"] = item.ArticleId updateParams["ChartId"] = item.ChartId updateParams["Link"] = item.Link ptrStructOrTableName := "cygx_gushou_time_line" whereParam := map[string]interface{}{"time_line_id": item.TimeLineId} qs := to.QueryTable(ptrStructOrTableName) for expr, exprV := range whereParam { qs = qs.Filter(expr, exprV) } _, err = qs.Update(updateParams) return } type GetCygxGushouTimeLineResp struct { Status int `description:"0:内部可见,1:全部可见"` Paging *paging.PagingItem `description:"分页数据"` List []*CygxGushouTimeLineResp } type CygxGushouTimeLineResp struct { TimeLineId int `description:"ID"` PublishTime string `description:"发布日期"` CreateTime string `description:"创建时间"` ModifyTime string `description:"更新时间"` Status int `description:"0:未发布,1:已发布"` Content string `description:"内容"` ArticleId int `description:"文章ID"` ChartId int `description:"图表ID"` Link string `description:"文章或图表链接"` Pv int `description:"PV"` Uv int `description:"UV"` Title string `description:"标题"` } // 获取数量 func GetCygxGushouTimeLineCount(condition string, pars []interface{}) (count int, err error) { sqlCount := ` SELECT COUNT(1) AS count FROM cygx_gushou_time_line as art WHERE 1= 1 ` if condition != "" { sqlCount += condition } o := orm.NewOrmUsingDB("hz_cygx") err = o.Raw(sqlCount, pars).QueryRow(&count) return } // 列表 func GetCygxGushouTimeLineList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxGushouTimeLineResp, err error) { o := orm.NewOrmUsingDB("hz_cygx") sql := `SELECT * FROM cygx_gushou_time_line as art WHERE 1= 1 ` if condition != "" { sql += condition } sql += ` LIMIT ?,? ` _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items) return } type GetCygxGushouTimeLineDetailResp struct { Detail *CygxGushouTimeLineResp } // 通过ID获取详情 func GetCygxGushouTimeLineDetail(timeLineId int) (item *CygxGushouTimeLineResp, err error) { o := orm.NewOrmUsingDB("hz_cygx") sql := `SELECT * FROM cygx_gushou_time_line WHERE time_line_id=? ` err = o.Raw(sql, timeLineId).QueryRow(&item) return } // 删除数据 func DeleteCygxGushouTimeLine(timeLineId int) (err error) { o := orm.NewOrmUsingDB("hz_cygx") sql := ` DELETE FROM cygx_gushou_time_line WHERE time_line_id = ?` _, err = o.Raw(sql, timeLineId).Exec() return } // 修改是否展示 func EditCygxGushouTimeLineStatus(status, timeLineId int) (err error) { o := orm.NewOrmUsingDB("hz_cygx") sql := `UPDATE cygx_gushou_time_line SET status=?, modify_time=NOW() WHERE time_line_id=? ` _, err = o.Raw(sql, status, timeLineId).Exec() return } // 一键修改所有的是否展示 func EditCygxGushouTimeLineStatusAll(status int) (err error) { o := orm.NewOrmUsingDB("hz_cygx") to, err := o.Begin() if err != nil { return } defer func() { if err != nil { _ = to.Rollback() } else { _ = to.Commit() } }() sql := ` UPDATE cygx_config SET config_value=? WHERE config_code= ? ` _, err = to.Raw(sql, status, utils.CYGX_GUSHOU_TIME_LINE_STATUS).Exec() if err != nil { return } return }