package data_manage import ( sql2 "database/sql" "eta/eta_task/global" "eta/eta_task/utils" "github.com/rdlucklib/rdluck_tools/paging" "gorm.io/gorm" "time" ) type BaseFromGprRiskIndex struct { BaseFromGprRiskIndexId int `gorm:"column:base_from_gpr_risk_index_id;primaryKey;autoIncrement"` ClassifyId int IndexCode string IndexName string Frequency string Unit string Sort int StartDate string `description:"开始日期"` EndDate string `description:"结束日期"` EndValue float64 CreateTime time.Time ModifyTime time.Time } func (m *BaseFromGprRiskIndex) AfterFind(db *gorm.DB) (err error) { m.StartDate = utils.GormDateStrToDateStr(m.StartDate) m.EndDate = utils.GormDateStrToDateStr(m.EndDate) return } // BaseFromGprRiskClassify GprRisk原始数据分类表 type BaseFromGprRiskClassify struct { ClassifyId int `gorm:"column:classify_id;primaryKey;autoIncrement"` ClassifyName string `description:"分类名称"` ParentId int `description:"父级id"` SysUserId int `description:"创建人id"` SysUserRealName string `description:"创建人姓名"` Level int `description:"层级"` Sort int `description:"排序字段,越小越靠前,默认值:10"` ModifyTime time.Time `description:"修改时间"` CreateTime time.Time `description:"创建时间"` } func GetBaseFromGprRiskIndexMaxDate() (maxDate time.Time, err error) { o := global.DbMap[utils.DbNameIndex] sql := ` SELECT max(a.modify_time) AS max_date FROM base_from_gpr_risk_data as a ` var timeNull sql2.NullTime err = o.Raw(sql).Scan(&timeNull).Error if err != nil { return } if timeNull.Valid { maxDate = timeNull.Time } return } type GprRiskIndexResp struct { Ret int Msg string ErrMsg string ErrCode string Data []*BaseFromGprRiskIndex } func GetBaseFromGprRiskIndexAll(dateStr string) (list []*BaseFromGprRiskIndex, err error) { o := global.DbMap[utils.DbNameIndex] sql := `SELECT * FROM base_from_gpr_risk_index WHERE end_date>=?` err = o.Raw(sql, dateStr).Find(&list).Error return } func (obj *BaseFromGprRiskIndex) AddBaseFromGprRiskIndex(item *BaseFromGprRiskIndex) (lastId int64, err error) { err = global.DbMap[utils.DbNameIndex].Create(item).Error return } func (obj *BaseFromGprRiskIndex) InsertOrUpdateBaseFromGprRiskIndex(item *BaseFromGprRiskIndex) (lastId int64, err error) { saveItem := *item o := global.DbMap[utils.DbNameIndex] result := o.FirstOrCreate(item, "base_from_gpr_risk_index_id = ?", item.BaseFromGprRiskIndexId) if result.Error != nil { err = result.Error return } if result.RowsAffected == 0 { saveItem.BaseFromGprRiskIndexId = 0 result = o.Model(item).Where("base_from_gpr_risk_index_id = ?", item.BaseFromGprRiskIndexId).Updates(saveItem) if result.Error != nil { err = result.Error return } } return int64(item.BaseFromGprRiskIndexId), nil } type GprRiskClassifyResp struct { Ret int Msg string ErrMsg string ErrCode string Data []*BaseFromGprRiskClassify } func GetBaseFromGprRiskClassifyAll() (list []*BaseFromGprRiskClassify, err error) { o := global.DbMap[utils.DbNameIndex] sql := `SELECT * FROM base_from_gpr_risk_classify ` err = o.Raw(sql).Find(&list).Error return } func AddBaseFromGprRiskClassify(item *BaseFromGprRiskClassify) (lastId int64, err error) { err = global.DbMap[utils.DbNameIndex].Create(item).Error return } func InsertOrUpdateBaseFromGprRiskClassify(item *BaseFromGprRiskClassify) (lastId int64, err error) { saveItem := *item o := global.DbMap[utils.DbNameIndex] result := o.FirstOrCreate(item, "classify_id = ?", item.ClassifyId) if result.Error != nil { err = result.Error return } if result.RowsAffected == 0 { saveItem.ClassifyId = 0 result = o.Model(item).Where("classify_id = ?", item.ClassifyId).Updates(saveItem) if result.Error != nil { err = result.Error return } } return int64(item.ClassifyId), nil } // GetBaseFromGprRiskMaxDate 获取GprRisk消费者指数最大数据 func GetBaseFromGprRiskMaxDate() (maxDate time.Time, err error) { o := global.DbMap[utils.DbNameIndex] sql := ` SELECT max(a.modify_time) as max_date FROM base_from_gpr_risk_data as a ` var timeNull sql2.NullTime err = o.Raw(sql).Scan(&timeNull).Error if err != nil { return } if timeNull.Valid { maxDate = timeNull.Time } return } type BaseFromGprRiskData struct { BaseFromGprRiskDataId int `gorm:"column:base_from_gpr_risk_data_id;primaryKey;autoIncrement"` BaseFromGprRiskIndexId int `description:"指标id"` IndexCode string `description:"指标编码"` DataTime string `description:"日期"` Value string `description:"值"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"修改时间"` } // GetAllBaseFromGprRiskDataList 获取GprRisk消费者指数数据 func GetAllBaseFromGprRiskDataList(startDate string) (list []*BaseFromGprRiskData, err error) { o := global.DbMap[utils.DbNameIndex] sql := `SELECT * FROM base_from_gpr_risk_data WHERE modify_time>=? ORDER BY base_from_gpr_risk_data_id ASC ` err = o.Raw(sql, startDate).Find(&list).Error return } type BaseFromGprRiskDataResp struct { Ret int Msg string ErrMsg string ErrCode string Data BaseFromGprRiskDataIndexAndDataResp } // BaseFromGprRiskDataIndexAndDataResp 分页列表响应体 type BaseFromGprRiskDataIndexAndDataResp struct { List []*BaseFromGprRiskData Paging *paging.PagingItem `description:"分页数据"` } // MultiAddBaseFromGprRiskDataIndex 批量添加数据 func MultiAddBaseFromGprRiskDataIndex(items []*BaseFromGprRiskData) (lastId int64, err error) { num := len(items) if num <= 0 { return } o := global.DbMap[utils.DbNameIndex] err = o.CreateInBatches(items, utils.MultiAddNum).Error return }