123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425 |
- package models
- import (
- "eta/eta_api/utils"
- "github.com/beego/beego/v2/client/orm"
- "github.com/rdlucklib/rdluck_tools/paging"
- "time"
- )
- // TargetDetailResp 指标数据结构体
- type TargetDetailResp struct {
- Detail *EdbInfoItem
- ClassifyList []*EdbdataClassify
- }
- // GetTargetByTradeCode
- // @Description: 根据手工指标编码获取指标信息
- // @author: Roc
- // @datetime 2024-07-16 14:18:10
- // @param tradeCode string
- // @return item *Edbinfo
- // @return err error
- func GetTargetByTradeCode(tradeCode string) (item *EdbInfoItem, err error) {
- sql := `SELECT * FROM edbinfo WHERE TRADE_CODE = ? `
- o := orm.NewOrmUsingDB("edb")
- err = o.Raw(sql, tradeCode).QueryRow(&item)
- return
- }
- // GetCountManualUserClassify
- // @Description: 根据用户ID和分类ID获取关系数量
- // @author: Roc
- // @datetime 2024-07-16 14:27:58
- // @param sysUserId int
- // @param classifyId int
- // @return total int
- // @return err error
- func GetCountManualUserClassify(sysUserId, classifyId int) (total int, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT count(1) ct FROM manual_user_classify WHERE admin_id=? AND classify_id = ? `
- err = o.Raw(sql, sysUserId, classifyId).QueryRow(&total)
- return
- }
- func GetManualClassifyByClassifyId(classifyId int) (item *EdbdataClassify, err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE classify_id = ? `
- err = o.Raw(sql, classifyId).QueryRow(&item)
- return
- }
- // GetEdbDataListByCode
- // @Description: 通过指标ID获取所有数据
- // @author: Roc
- // @datetime 2024-07-16 15:32:41
- // @param tradeCode string
- // @return items []*Edbdata
- // @return err error
- func GetEdbDataListByCode(tradeCode string) (items []*Edbdata, err error) {
- sql := ` SELECT TRADE_CODE,DT,round(CLOSE,4) CLOSE,modify_time FROM edbdata WHERE TRADE_CODE = ? GROUP BY TRADE_CODE,DT ORDER BY DT DESC `
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql, tradeCode).QueryRows(&items)
- return
- }
- // EdbInfoListItem
- type EdbInfoListItem struct {
- TradeCode string `orm:"column(TRADE_CODE);pk" description:"指标code"`
- SecName string `orm:"column(SEC_NAME);" description:"指标名称"`
- Unit string `orm:"column(UNIT);" description:"单位"`
- Remark string `orm:"column(REMARK);" description:"备注"`
- Frequency string `description:"频度"`
- ClassifyId int `description:"分类id"`
- ClassifyName string `description:"分类名称"`
- CreateDate string `description:"创建时间"`
- UserId int `description:"录入用户id"`
- NoticeTime string `description:"通知时间"`
- Mobile string `description:"录入者手机号"`
- ModifyDate string `description:"待更新日期"`
- ModifyTime string `description:"数据更新时间"`
- Status string `description:"状态:未完成/完成"`
- UniqueCode string
- IsJoinEdb int8 `description:"指标库是否已添加:0-否;1-是"`
- UserName string `description:"录入用户名称"`
- StartDate string `description:"数据开始日期"`
- EndDate string `description:"数据结束日期"`
- LatestValue float64 `description:"指标最新值"`
- NextDateTime string `description:"下期时间"`
- }
- // EdbListResp 指标数据结构体
- type EdbListResp struct {
- List []*EdbInfoListItem
- Paging *paging.PagingItem `description:"分页数据"`
- }
- // GetEdbInfoList
- // @Description: 根据条件获取指标列表
- // @author: Roc
- // @datetime 2024-07-17 10:34:05
- // @param condition string
- // @param pars []interface{}
- // @return items []*Edbinfo
- // @return err error
- func GetEdbInfoList(condition string, pars []interface{}, startSize, pageSize int) (items []*EdbInfoListItem, err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := `SELECT DISTINCT a.* FROM edbinfo AS a WHERE a.classify_id > 0 `
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY a.create_date DESC `
- if pageSize > 0 {
- sql += ` LIMIT ?,? `
- pars = append(pars, startSize, pageSize)
- }
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- // GetEdbInfoSortList
- // @Description: 根据条件获取指标列表 排序
- // @author: gmy
- // @datetime 2024-09-05 15:25:05
- // @param condition string
- // @param pars []interface{}
- // @return items []*Edbinfo
- // @return err error
- func GetEdbInfoSortList(condition string, pars []interface{}, startSize, pageSize int, orderField, orderType string) (items []*EdbInfoListItem, err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := `SELECT a.* FROM edbinfo AS a WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- if orderField == "" {
- orderField = "end_date"
- }
- if orderType == "" {
- orderType = "DESC"
- }
- sql += ` ORDER BY a.` + orderField + ` ` + orderType
- if pageSize > 0 {
- sql += ` LIMIT ?,? `
- pars = append(pars, startSize, pageSize)
- }
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- // GetCountEdbInfoList
- // @Description: 根据条件获取指标数量
- // @author: Roc
- // @datetime 2024-07-17 14:51:00
- // @param condition string
- // @param pars []interface{}
- // @return total int
- // @return err error
- func GetCountEdbInfoList(condition string, pars []interface{}) (total int, err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := `SELECT COUNT(1) ct FROM edbinfo AS a WHERE a.classify_id > 0 `
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY a.create_date DESC `
- err = o.Raw(sql, pars).QueryRow(&total)
- return
- }
- // OnlyMultiAddEdbdata
- // @Description: 批量添加指标数据
- // @author: Roc
- // @datetime 2024-07-18 16:48:55
- // @param items []*Edbdata
- // @return err error
- func OnlyMultiAddEdbdata(items []*Edbdata) (err error) {
- o := orm.NewOrmUsingDB("edb")
- _, err = o.InsertMulti(utils.MultiAddNum, items)
- return
- }
- // DelEdbdataByCodeAndDateList
- // @Description: 根据指标编码和日期列表批量删除指标的明细数据
- // @author: Roc
- // @datetime 2024-07-18 16:54:27
- // @param tradeCode string
- // @param dateList []string
- // @return err error
- func DelEdbdataByCodeAndDateList(tradeCode string, dateList []string) (err error) {
- num := len(dateList)
- if num <= 0 {
- return
- }
- o := orm.NewOrmUsingDB("edb")
- sql := `delete from edbdata WHERE TRADE_CODE=? AND DT in (` + utils.GetOrmInReplace(num) + `) `
- _, err = o.Raw(sql, tradeCode, dateList).Exec()
- return
- }
- // UpdateManualIsJoinEdbStatus
- // @Description: 根据手工数据加入指标的状态
- // @author: Roc
- // @datetime 2024-07-22 11:29:13
- // @param edbCode string
- // @param isJoinEdb int 是否加入指标库
- // @return err error
- func UpdateManualIsJoinEdbStatus(edbCode string, isJoinEdb int8) (err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := ` UPDATE edbinfo SET is_join_edb = ? WHERE TRADE_CODE =? `
- _, err = o.Raw(sql, isJoinEdb, edbCode).Exec()
- return
- }
- // BatchManualEdbReq 指标数据结构体
- type BatchManualEdbReq struct {
- //IsJoinEdb int `form:"IsJoinEdb" description:"是否加到指标库,0:未加到指标库"`
- FrequencyList []string `description:"频度;枚举值:日度、周度、月度、季度、半年度、年度"`
- Keyword string `description:"关键字"`
- ClassifyIdList []int `description:"所选品种id列表"`
- UserIdList []int `description:"所选用户id列表"`
- ListAll bool `form:"ListAll" json:"ListAll" description:"列表全选"`
- TradeCodeList []string `form:"TradeCodeList" json:"TradeCodeList" description:"全选为false时, 该数组为选中; 全选为true时, 该数组为不选的指标"`
- PageSize int `form:"PageSize" json:"PageSize"`
- CurrentIndex int `form:"CurrentIndex" form:"CurrentIndex"`
- }
- // DelManualIndexByCodeList
- // @Description: 根据指标编码列表删除指标
- // @author: Roc
- // @datetime 2024-07-30 14:10:12
- // @param codeList []string
- // @return err error
- func DelManualIndexByCodeList(codeList []string) (err error) {
- num := len(codeList)
- if num <= 0 {
- return
- }
- to, err := orm.NewOrmUsingDB("edb").Begin()
- if err != nil {
- return
- }
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- // 删除指标
- sql := `DELETE FROM edbinfo WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + `) `
- _, err = to.Raw(sql, codeList).Exec()
- if err != nil {
- }
- // 删除指标数据
- sql = `DELETE FROM edbdata WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + `) `
- _, err = to.Raw(sql, codeList).Exec()
- if err != nil {
- }
- return
- }
- // GetEdbinfoListBySecNameList
- // @Description: 根据指标名称获取列表数据
- // @author: Roc
- // @datetime 2024-07-30 19:14:25
- // @param secNameList []string
- // @return item []*Edbinfo
- // @return err error
- func GetEdbinfoListBySecNameList(secNameList []string) (items []*Edbinfo, err error) {
- num := len(secNameList)
- if num <= 0 {
- return
- }
- sql := `SELECT * FROM edbinfo WHERE SEC_NAME in (` + utils.GetOrmInReplace(num) + ` ) AND REMARK='手动' `
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql, secNameList).QueryRows(&items)
- return
- }
- // GetTargetsDataListByCodeList
- // @Description: 根据code列表获取指标数据列表
- // @author: Roc
- // @datetime 2024-07-30 19:19:36
- // @param tradeCodeList []string
- // @return items []*Edbdata
- // @return err error
- func GetTargetsDataListByCodeList(tradeCodeList []string) (items []*Edbdata, err error) {
- num := len(tradeCodeList)
- if num <= 0 {
- return
- }
- o := orm.NewOrmUsingDB("edb")
- sql := `SELECT * FROM edbdata WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + ` ) ORDER BY DT ASC `
- _, err = o.Raw(sql, tradeCodeList).QueryRows(&items)
- return
- }
- // EdbinfoOpRecord
- // @Description: 手工数据的操作日志
- type EdbinfoOpRecord struct {
- EdbinfoOpRecordId int `orm:"column(edbinfo_op_record_id);pk"`
- TradeCode string `orm:"column(TRADE_CODE)" description:"指标编码"`
- Remark string `orm:"column(remark)" description:"操作信息"`
- UserId int `orm:"column(user_id)" description:"用户id"`
- UserName string `orm:"column(user_name)" description:"用户姓名"`
- CreateTime time.Time `orm:"column(create_time)" description:"创建时间"`
- }
- // Remark备注:
- // 1、创建指标
- // 2、编辑指标
- // 3、更新数据
- // 4、数据资产由<xxx>转移给<xxx>
- // Create
- // @Description: 添加手工数据的操作日志
- // @author: Roc
- // @receiver m
- // @datetime 2024-07-30 16:25:55
- // @return err error
- func (m *EdbinfoOpRecord) Create() (err error) {
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Insert(m)
- return
- }
- // MulCreate
- // @Description: 批量添加手工数据的操作日志
- // @author: Roc
- // @receiver m
- // @datetime 2024-08-01 11:05:02
- // @param list []*EdbinfoOpRecord
- // @return err error
- func (m *EdbinfoOpRecord) MulCreate(list []*EdbinfoOpRecord) (err error) {
- o := orm.NewOrmUsingDB("edb")
- _, err = o.InsertMulti(utils.MultiAddNum, list)
- return
- }
- // EdbinfoOpRecordItem
- // @Description: 手工数据的操作日志
- type EdbinfoOpRecordItem struct {
- TradeCode string `orm:"column(TRADE_CODE);pk" description:"指标编码"`
- Remark string `orm:"column(remark)" description:"操作信息"`
- UserId int `orm:"column(user_id)" description:"用户id"`
- UserName string `orm:"column(user_name)" description:"用户姓名"`
- CreateTime string `orm:"column(create_time)" description:"创建时间"`
- }
- // EdbinfoOpRecordListResp 指标数据结构体
- type EdbinfoOpRecordListResp struct {
- List []*EdbinfoOpRecordItem
- Paging *paging.PagingItem `description:"分页数据"`
- }
- // GetEdbinfoOpRecordPageList
- // @Description: 根据指标编码获取手工数据的操作日志
- // @author: Roc
- // @datetime 2024-07-30 17:32:33
- // @param tradeCode string
- // @param startSize int
- // @param total int
- // @return pageSize int
- // @return items []*EdbinfoOpRecordItem
- // @return err error
- func GetEdbinfoOpRecordPageList(tradeCode string, startSize, pageSize int) (total int, items []*EdbinfoOpRecordItem, err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := `SELECT count(1) FROM edbinfo_op_record AS a WHERE TRADE_CODE = ? `
- err = o.Raw(sql, tradeCode).QueryRow(&total)
- if err != nil {
- return
- }
- sql = `SELECT a.* FROM edbinfo_op_record AS a WHERE TRADE_CODE = ? ORDER BY a.create_time DESC LIMIT ?,?`
- _, err = o.Raw(sql, tradeCode, startSize, pageSize).QueryRows(&items)
- return
- }
- // GetManualEdbCountByCondition
- // @Description: 根据获取手工数据条数
- // @author: Roc
- // @datetime 2024-08-05 09:37:16
- // @param condition string
- // @param pars []interface{}
- // @return count int
- // @return err error
- func GetManualEdbCountByCondition(condition string, pars []interface{}) (count int, err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := ` SELECT COUNT(1) AS count FROM edbinfo WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, pars).QueryRow(&count)
- return
- }
- // DelEdbinfoOpRecordByTradeCode
- // @Description: 根据指标编码删除操作日志
- // @author: Roc
- // @datetime 2024-08-05 10:27:29
- // @param tradeCode string
- // @return err error
- func DelEdbinfoOpRecordByTradeCode(tradeCode string) (err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := ` DELETE FROM edbinfo_op_record WHERE TRADE_CODE = ? `
- _, err = o.Raw(sql, tradeCode).Exec()
- return
- }
|