package models import ( "eta_gn/eta_api/global" "eta_gn/eta_api/utils" "github.com/rdlucklib/rdluck_tools/paging" "time" ) type TargetDetailResp struct { Detail *EdbInfoItem ClassifyList []*EdbdataClassify } func GetTargetByTradeCode(tradeCode string) (item *EdbInfoItem, err error) { sql := `SELECT * FROM edbinfo WHERE TRADE_CODE = ? ` err = global.DmSQL["edb"].Raw(sql, tradeCode).First(&item).Error return } func GetCountManualUserClassify(sysUserId, classifyId int) (total int, err error) { sql := `SELECT count(1) ct FROM manual_user_classify WHERE admin_id=? AND classify_id = ? ` err = global.DmSQL["data"].Raw(sql, sysUserId, classifyId).Scan(&total).Error return } func GetManualClassifyByClassifyId(classifyId int) (item *EdbdataClassify, err error) { sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE classify_id = ? ` err = global.DmSQL["edb"].Raw(sql, classifyId).First(&item).Error return } 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 ` err = global.DmSQL["edb"].Raw(sql, tradeCode).Find(&items).Error return } type EdbInfoListItem struct { TradeCode string `orm:"column(TRADE_CODE);pk" gorm:"primaryKey" 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:"指标最新值"` } type EdbListResp struct { List []*EdbInfoListItem Paging *paging.PagingItem `description:"分页数据"` } func GetEdbInfoList(condition string, pars []interface{}, startSize, pageSize int) (items []*EdbInfoListItem, err error) { 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) pars = append(pars, pageSize) } err = global.DmSQL["edb"].Raw(sql, pars...).Find(&items).Error return } func GetCountEdbInfoList(condition string, pars []interface{}) (total int, err error) { 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 = global.DmSQL["edb"].Raw(sql, pars...).Scan(&total).Error return } func OnlyMultiAddEdbdata(items []*Edbdata) (err error) { err = global.DmSQL["edb"].CreateInBatches(items, utils.MultiAddNum).Error return } func DelEdbdataByCodeAndDateList(tradeCode string, dateList []string) (err error) { num := len(dateList) if num <= 0 { return } sql := `delete from edbdata WHERE TRADE_CODE=? AND DT in (` + utils.GetOrmInReplace(num) + `) ` err = global.DmSQL["edb"].Exec(sql, tradeCode, dateList).Error return } func UpdateManualIsJoinEdbStatus(edbCode string, isJoinEdb int8) (err error) { sql := ` UPDATE edbinfo SET is_join_edb = ? WHERE TRADE_CODE =? ` err = global.DmSQL["edb"].Exec(sql, isJoinEdb, edbCode).Error return } type BatchManualEdbReq struct { 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"` } func DelManualIndexByCodeList(codeList []string) (err error) { num := len(codeList) if num <= 0 { return } to := global.DmSQL["edb"].Begin() defer func() { if err != nil { _ = to.Rollback() } else { _ = to.Commit() } }() sql := `DELETE FROM edbinfo WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + `) ` err = to.Exec(sql, codeList).Error if err != nil { } sql = `DELETE FROM edbdata WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + `) ` err = to.Exec(sql, codeList).Error if err != nil { } return } 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='手动' ` err = global.DmSQL["edb"].Raw(sql, secNameList).Find(&items).Error return } func GetTargetsDataListByCodeList(tradeCodeList []string) (items []*Edbdata, err error) { num := len(tradeCodeList) if num <= 0 { return } sql := `SELECT * FROM edbdata WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + ` ) ORDER BY DT ASC ` err = global.DmSQL["edb"].Raw(sql, tradeCodeList).Find(&items).Error return } type EdbinfoOpRecord struct { EdbinfoOpRecordId int `gorm:"column:edbinfo_op_record_id;primaryKey;type:int" orm:"column(edbinfo_op_record_id);pk" gorm:"primaryKey" description:"操作记录ID"` TradeCode string `gorm:"column:TRADE_CODE;type:varchar(255)" orm:"column(TRADE_CODE)" description:"指标编码"` Remark string `gorm:"column:REMARK;type:varchar(255)" orm:"column(remark)" description:"操作信息"` UserId int `gorm:"column:USER_ID;type:int" orm:"column(user_id)" description:"用户id"` UserName string `gorm:"column:USER_NAME;type:varchar(255)" orm:"column(user_name)" description:"用户姓名"` CreateTime time.Time `gorm:"column:CREATE_TIME;type:datetime" orm:"column(create_time)" description:"创建时间"` } func (m *EdbinfoOpRecord) Create() (err error) { err = global.DmSQL["edb"].Create(m).Error return } func (m *EdbinfoOpRecord) MulCreate(list []*EdbinfoOpRecord) (err error) { err = global.DmSQL["edb"].CreateInBatches(list, utils.MultiAddNum).Error return } type EdbinfoOpRecordItem struct { TradeCode string `orm:"column(TRADE_CODE);pk" gorm:"primaryKey" 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:"创建时间"` } type EdbinfoOpRecordListResp struct { List []*EdbinfoOpRecordItem Paging *paging.PagingItem `description:"分页数据"` } func GetEdbinfoOpRecordPageList(tradeCode string, startSize, pageSize int) (total int, items []*EdbinfoOpRecordItem, err error) { sql := `SELECT count(1) FROM edbinfo_op_record AS a WHERE TRADE_CODE = ? ` err = global.DmSQL["edb"].Raw(sql, tradeCode).Scan(&total).Error if err != nil { return } sql = `SELECT a.* FROM edbinfo_op_record AS a WHERE TRADE_CODE = ? ORDER BY a.create_time DESC LIMIT ?,?` err = global.DmSQL["edb"].Raw(sql, tradeCode, startSize, pageSize).Find(&items).Error return } func GetManualEdbCountByCondition(condition string, pars []interface{}) (count int, err error) { sql := ` SELECT COUNT(1) AS count FROM edbinfo WHERE 1=1 ` if condition != "" { sql += condition } err = global.DmSQL["edb"].Raw(sql, pars...).Scan(&count).Error return } func DelEdbinfoOpRecordByTradeCode(tradeCode string) (err error) { sql := ` DELETE FROM edbinfo_op_record WHERE TRADE_CODE = ? ` err = global.DmSQL["edb"].Exec(sql, tradeCode).Error return }