瀏覽代碼

data_manage数据库兼容

kobe6258 2 月之前
父節點
當前提交
7a793b1b87

+ 2 - 2
controllers/data_manage/gpr_risk_data.go

@@ -172,8 +172,8 @@ func (this *BaseFromGprRiskController) GprRiskIndexData() {
 			return
 		}
 		if len(dataTimes) > 0 {
-			startDate := dataTimes[len(dataTimes)-1]
-			endDate := dataTimes[0]
+			startDate := utils.GormDateStrToDateStr(dataTimes[len(dataTimes)-1])
+			endDate := utils.GormDateStrToDateStr(dataTimes[0])
 			// 把截止日往后加1天
 			endDateT, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
 			endDate = endDateT.AddDate(0, 0, 1).Format(utils.FormatDate)

+ 6 - 1
models/data_manage/base_from_clarksons_index.go

@@ -160,7 +160,12 @@ func GetClarksonsIndexByClassifyId(classifyIds []int, startSize, pageSize int) (
 	CASE WHEN e.edb_info_id IS NULL THEN 0 ELSE 1 END AS edb_exist
 	FROM base_from_clarksons_index AS b
 	LEFT JOIN edb_info AS e ON b.index_code=e.edb_code AND e.source=101
-	WHERE b.classify_id IN (` + utils.GetOrmInReplace(len(classifyIds)) + `) ORDER BY b.sort ASC LIMIT ?,? `
+	WHERE b.classify_id IN ? ORDER BY b.sort ASC LIMIT ?,? `
+	//sql := ` SELECT b.*, e.edb_info_id,
+	//CASE WHEN e.edb_info_id IS NULL THEN 0 ELSE 1 END AS edb_exist
+	//FROM base_from_clarksons_index AS b
+	//LEFT JOIN edb_info AS e ON b.index_code=e.edb_code AND e.source=101
+	//WHERE b.classify_id IN (` + utils.GetOrmInReplace(len(classifyIds)) + `) ORDER BY b.sort ASC LIMIT ?,? `
 	err = global.DbMap[utils.DbNameIndex].Raw(sql, classifyIds, startSize, pageSize).Find(&items).Error
 	return
 }

+ 7 - 6
models/data_manage/base_from_gpr_risk.go

@@ -41,9 +41,9 @@ type BaseFromGprRiskIndexList struct {
 	Sort                   int
 	CreateTime             string
 	ModifyTime             string
-	EdbExist               int `description:"指标库是否已添加:0-否;1-是"`
-	DataList               []*BaseFromGprRiskData
-	Paging                 *paging.PagingItem `description:"分页数据"`
+	EdbExist               int                    `description:"指标库是否已添加:0-否;1-是"`
+	DataList               []*BaseFromGprRiskData `gorm:"-"`
+	Paging                 *paging.PagingItem     `description:"分页数据" gorm:"-"`
 }
 type BaseFromGprRiskIndexSearchList struct {
 	List   []*BaseFromGprRiskIndexList
@@ -76,13 +76,13 @@ func GetGprRiskIndexByClassifyId(classifyId int) (items []*BaseFromGprRiskIndex,
 	return
 }
 
-func GetGprRiskIndex(condition string, pars interface{}) (items []*BaseFromGprRiskIndexList, err error) {
+func GetGprRiskIndex(condition string, pars []interface{}) (items []*BaseFromGprRiskIndexList, err error) {
 	sql := ` SELECT * FROM base_from_gpr_risk_index WHERE 1=1  `
 	if condition != "" {
 		sql += condition
 	}
 	sql += ` ORDER BY sort ASC, base_from_gpr_risk_index_id asc`
-	err = global.DbMap[utils.DbNameIndex].Raw(sql, pars).Find(&items).Error
+	err = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).Find(&items).Error
 	return
 }
 
@@ -118,7 +118,8 @@ func GetGprRiskIndexDataByDataTime(indexCodes []string, startDate, endDate strin
 }
 
 func GetGprRiskIndexDataTimePageByCodes(indexCodes []string, startSize, pageSize int) (dataTimes []string, err error) {
-	sql := ` SELECT data_time FROM base_from_gpr_risk_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCodes)) + `) GROUP BY data_time ORDER BY data_time DESC LIMIT ?,? `
+	//sql := ` SELECT data_time FROM base_from_gpr_risk_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCodes)) + `) GROUP BY data_time ORDER BY data_time DESC LIMIT ?,? `
+	sql := ` SELECT data_time FROM base_from_gpr_risk_data WHERE index_code in ? GROUP BY data_time ORDER BY data_time DESC LIMIT ?,? `
 	err = global.DbMap[utils.DbNameIndex].Raw(sql, indexCodes, startSize, pageSize).Find(&dataTimes).Error
 	return
 }

+ 4 - 4
models/data_manage/edb_info.go

@@ -457,11 +457,11 @@ type EdbInfoList struct {
 	ChartImage       string                  `description:"图表图片"`
 	RuleType         int                     `description:"预测规则,1:最新,2:固定值"`
 	FixedValue       float64                 `description:"固定值"`
-	DataList         []*EdbData              `description:"实际指标数据"`
-	PredictDataList  []*EdbData              `description:"预测指标数据"`
-	Button           EdbClassifyItemsButton  `description:"操作权限"`
+	DataList         []*EdbData              `description:"实际指标数据" gorm:"-"`
+	PredictDataList  []*EdbData              `description:"预测指标数据" gorm:"-"`
+	Button           EdbClassifyItemsButton  `description:"操作权限" gorm:"-"`
 	IsEnEdb          bool                    `description:"是否展示英文标识"`
-	DataInsertConfig EdbDataInsertConfigItem `description:"指标数据插入配置"`
+	DataInsertConfig EdbDataInsertConfigItem `description:"指标数据插入配置" gorm:"-"`
 	DataDateType     string                  `description:"数据日期类型,枚举值:交易日、自然日"`
 	EmptyType        int                     `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
 	MaxEmptyType     int                     `description:"MAX、MIN公式空值处理类型(1、等于0;2、跳过空值)"`

+ 1 - 1
services/data/base_from_clarksons.go

@@ -277,7 +277,7 @@ func ClarksonsIndexSource2Edb(req ClarksonsIndexSource2EdbReq, lang string) (edb
 		err = fmt.Errorf("获取指标是否存在失败, err: %s", e.Error())
 		return
 	}
-	if exist != nil {
+	if exist != nil && exist.EdbInfoId > 0 {
 		skip = true
 		return
 	}

+ 23 - 0
utils/common.go

@@ -2882,3 +2882,26 @@ func IsErrNoRow(err error) bool {
 	}
 	return errors.Is(err, gorm.ErrRecordNotFound)
 }
+
+// GormDateStrToDateStr
+// @Description: gorm日期字符串格式转正常显示的日期字符串
+// @param originalString
+// @return formatStr
+func GormDateStrToDateStr(originalString string) (formatStr string) {
+	formatStr = originalString
+	if !strings.Contains(originalString, "T") {
+		return
+	}
+
+	// 解析原始字符串
+	t, err := time.Parse(FormatDateWallWithLoc, originalString)
+	if err != nil {
+		fmt.Println("Error parsing time:", err)
+		return
+	}
+
+	// 重新格式化时间
+	formatStr = t.Format(FormatDate)
+
+	return
+}

+ 17 - 16
utils/constants.go

@@ -7,22 +7,23 @@ import (
 
 // 常量定义
 const (
-	FormatTime                 = "15:04:05"                //时间格式
-	FormatTimeHm               = "15:04"                   //时间格式
-	FormatDate                 = "2006-01-02"              //日期格式
-	FormatDateUnSpace          = "20060102"                //日期格式
-	ormatDateUnSpace           = "2006.01.02"              //日期格式
-	FormatDateTime             = "2006-01-02 15:04:05"     //完整时间格式
-	HlbFormatDateTime          = "2006-01-02_15:04:05.999" //完整时间格式
-	FormatDateTimeUnSpace      = "20060102150405"          //完整时间格式
-	FormatShortDateTimeUnSpace = "060102150405"            //省去开头两位年份的时间格式
-	EmptyDateTimeStr           = "0000-00-00 00:00:00"     //DateTime零值字符串
-	EmptyDateStr               = "0000-00-00"              //Date零值字符串
-	FormatMonthDayUnSpace      = "0102"                    //日期格式
-	FormatMonthDay             = "01-02"                   //日期格式
-	FormatYearMonthDate        = "2006-01"                 //日期格式
-	FormatYearDate             = "2006"                    //日期格式
-	PageSize15                 = 15                        //列表页每页数据量
+	FormatTime                 = "15:04:05"                  //时间格式
+	FormatTimeHm               = "15:04"                     //时间格式
+	FormatDate                 = "2006-01-02"                //日期格式
+	FormatDateUnSpace          = "20060102"                  //日期格式
+	ormatDateUnSpace           = "2006.01.02"                //日期格式
+	FormatDateTime             = "2006-01-02 15:04:05"       //完整时间格式
+	HlbFormatDateTime          = "2006-01-02_15:04:05.999"   //完整时间格式
+	FormatDateTimeUnSpace      = "20060102150405"            //完整时间格式
+	FormatShortDateTimeUnSpace = "060102150405"              //省去开头两位年份的时间格式
+	EmptyDateTimeStr           = "0000-00-00 00:00:00"       //DateTime零值字符串
+	EmptyDateStr               = "0000-00-00"                //Date零值字符串
+	FormatMonthDayUnSpace      = "0102"                      //日期格式
+	FormatMonthDay             = "01-02"                     //日期格式
+	FormatYearMonthDate        = "2006-01"                   //日期格式
+	FormatDateWallWithLoc      = "2006-01-02T15:04:05-07:00" //日期格式
+	FormatYearDate             = "2006"                      //日期格式
+	PageSize15                 = 15                          //列表页每页数据量
 	PageSize5                  = 5
 	PageSize10                 = 10
 	PageSize20                 = 20