Browse Source

Merge branch 'refs/heads/eta_2.0.8_ly_0804@guomengyuan'

# Conflicts:
#	models/edb_data_table.go
#	routers/commentsRouter.go
#	routers/router.go
#	utils/constants.go
gmy 1 month ago
parent
commit
2f7655a3c1

+ 515 - 0
controllers/base_from_ly.go

@@ -0,0 +1,515 @@
+// @Author gmy 2024/8/13 16:01:00
+package controllers
+
+import (
+	"encoding/json"
+	"eta/eta_index_lib/logic"
+	"eta/eta_index_lib/models"
+	"eta/eta_index_lib/services"
+	"eta/eta_index_lib/utils"
+	"strconv"
+	"time"
+)
+
+type BaseFromLyController struct {
+	BaseAuthController
+}
+
+// Add
+// @Title 新增粮油商务网指标
+// @Description 新增粮油商务网指标
+// @router /add [post]
+func (this *BaseFromLyController) Add() {
+	br := new(models.BaseResponse).Init()
+	var cacheKey string
+	defer func() {
+		utils.Rc.Delete(cacheKey)
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	source := utils.DATA_SOURCE_LY
+	var req models.AddEdbInfoReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.EdbCode == "" {
+		br.Msg = "请输入指标编码!"
+		br.ErrMsg = "请输入指标编码,指标编码为空"
+		return
+	}
+	cacheKey = utils.CACHE_EDB_DATA_ADD + strconv.Itoa(source) + "_" + req.EdbCode
+	if !utils.Rc.IsExist(cacheKey) {
+		utils.Rc.SetNX(cacheKey, 1, 1*time.Minute)
+		err = models.AddEdbDataFromLy(req.EdbCode)
+		if err != nil {
+			br.Msg = "获取指标信息失败!"
+			br.ErrMsg = "获取指标信息失败 AddEdbDataFromSci99,Err:" + err.Error()
+			return
+		}
+		br.Ret = 200
+		br.Success = true
+		br.Msg = "获取成功"
+	} else {
+		br.Ret = 501
+		br.Success = true
+		br.Msg = "系统处理中,请稍后重试"
+	}
+}
+
+// Refresh
+// @Title 刷新粮油商务网指标接口
+// @Description 刷新粮油商务网指标接口
+// @Success 200 {object} models.RefreshEdbInfoReq
+// @router /refresh [post]
+func (this *BaseFromLyController) Refresh() {
+	br := new(models.BaseResponse).Init()
+	var cacheKey string
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		_ = utils.Rc.Delete(cacheKey)
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	source := utils.DATA_SOURCE_LY
+	var req models.RefreshEdbInfoReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.EdbCode == "" {
+		br.Msg = "请输入指标编码!"
+		br.ErrMsg = "请输入指标编码,指标编码为空"
+		return
+	}
+	if req.EdbInfoId <= 0 {
+		br.Msg = "请输入指标ID!"
+		br.ErrMsg = "请输入指标ID"
+		return
+	}
+
+	// 获取指标详情
+	edbInfo, err := models.GetEdbInfoByEdbCode(source, req.EdbCode)
+	if err != nil {
+		br.Msg = "指标不存在!"
+		br.ErrMsg = "指标不存在"
+		return
+	}
+	cacheKey = utils.CACHE_EDB_DATA_REFRESH + strconv.Itoa(source) + "_" + req.EdbCode
+	if utils.Rc.IsExist(cacheKey) {
+		br.Ret = 501
+		br.Success = true
+		br.Msg = "系统处理中,请稍后重试"
+		return
+	}
+	dataUpdateTime := time.Now().Format(utils.FormatDateTime)
+	utils.Rc.SetNX(cacheKey, 1, 1*time.Minute)
+	err = models.RefreshEdbDataFromBloomberg(req.EdbInfoId, req.EdbCode, req.StartDate)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "刷新指标信息失败!"
+		br.ErrMsg = "刷新指标信息失败 RefreshEdbDataFromBloomberg,Err:" + err.Error()
+		return
+	}
+
+	// 更新指标最大最小值
+	erDataUpdateDate, err, errMsg := models.UnifiedModifyEdbInfoMaxAndMinInfoDataUpdate(edbInfo, dataUpdateTime)
+	if err != nil {
+		br.Msg = errMsg
+		br.ErrMsg = err.Error()
+		return
+	}
+	// 添加指标刷新成功日志
+	if erDataUpdateDate != "" {
+		_ = services.AddEdbInfoUpdateLog(edbInfo.EdbInfoId, 1, "", 1, "", 0, 0)
+	} else {
+		_ = services.AddEdbInfoUpdateLog(edbInfo.EdbInfoId, 1, "", 2, "未刷新到数据", 0, 0)
+	}
+
+	// 更新ES
+	go logic.UpdateEs(edbInfo.EdbInfoId)
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+}
+
+// GetLyClassifyByName
+// @Title 获取分类
+// @Description 获取分类
+// @Success 200 {object} models.BaseFromLyClassify
+// @router /get/ly/classify/by/name [get]
+func (this *BaseFromLyController) GetLyClassifyByName() {
+	br := new(models.BaseResponse).Init()
+	var cacheKey string
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		_ = utils.Rc.Delete(cacheKey)
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	categoryName := this.GetString("CategoryName")
+
+	if categoryName == "" {
+		br.Msg = "请输入分类!"
+		br.ErrMsg = "请输入分类"
+		return
+	}
+
+	lyClassify, err := models.GetLyClassifyByName(categoryName)
+	if err != nil {
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Data = lyClassify
+	br.Msg = "获取成功"
+}
+
+// GetLyIndexRecordByUrl
+// @Title 根据url获取指标已读取记录
+// @Description 根据url获取指标已读取记录
+// @Success 200 {object} models.BaseFromLyIndexRecord
+// @router /get/ly/index/record/by/url [get]
+func (this *BaseFromLyController) GetLyIndexRecordByUrl() {
+	br := new(models.BaseResponse).Init()
+	var cacheKey string
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		_ = utils.Rc.Delete(cacheKey)
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	url := this.GetString("Url")
+
+	if url == "" {
+		br.Msg = "请输入地址链接!"
+		br.ErrMsg = "请输入地址链接"
+		return
+	}
+
+	lyIndexRecord, err := models.GetLyIndexRecordByUrl(url)
+	if err != nil {
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Data = lyIndexRecord
+	br.Msg = "获取成功"
+}
+
+// AddLyIndexRecord
+// @Title 维护指标数据读取进度到数据库
+// @Description 维护指标数据读取进度到数据库
+// @Success 200 string "处理成功"
+// @router /add/ly/index/record [post]
+func (this *BaseFromLyController) AddLyIndexRecord() {
+	br := new(models.BaseResponse).Init()
+	var cacheKey string
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		_ = utils.Rc.Delete(cacheKey)
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req models.BaseFromLyIndexRecord
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	_, err = models.AddLyIndexRecord(&req)
+	if err != nil {
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "处理成功"
+}
+
+// AddLyDataList
+// @Title 新增指标数据
+// @Description 新增指标数据列表
+// @Success 200 string "处理成功"
+// @router /add/ly/data/list [post]
+func (this *BaseFromLyController) AddLyDataList() {
+	br := new(models.BaseResponse).Init()
+	var cacheKey string
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		_ = utils.Rc.Delete(cacheKey)
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req []models.BaseFromLyData
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	err = models.AddLyDataList(req)
+	if err != nil {
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "处理成功"
+}
+
+// AddLyIndex
+// @Title 新增指标
+// @Description 新增指标
+// @Success 200 string "处理成功"
+// @router /add/ly/index [post]
+func (this *BaseFromLyController) AddLyIndex() {
+	br := new(models.BaseResponse).Init()
+	var cacheKey string
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		_ = utils.Rc.Delete(cacheKey)
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req models.BaseFromLyIndex
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	indexId, err := models.AddLyIndex(&req)
+	if err != nil {
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Data = indexId
+	br.Msg = "处理成功"
+}
+
+// GetLyDataByIndexIdAndDataTime
+// @Title 根据指标id和时间获取指标数据
+// @Description 根据指标id和时间获取指标数据
+// @Success 200 {object} models.BaseFromLyData
+// @router /get/ly/data/by/index/id/and/data/time [get]
+func (this *BaseFromLyController) GetLyDataByIndexIdAndDataTime() {
+	br := new(models.BaseResponse).Init()
+	var cacheKey string
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		_ = utils.Rc.Delete(cacheKey)
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	indexId, err := this.GetInt("IndexId")
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if indexId == 0 {
+		br.Msg = "请输入指标id!"
+		br.ErrMsg = "请输入指标id"
+		return
+	}
+
+	dataTime := this.GetString("DataTime")
+
+	if dataTime == "" {
+		br.Msg = "请输入时间!"
+		br.ErrMsg = "请输入时间"
+		return
+	}
+
+	lyData, err := models.GetLyDataByIndexIdAndDataTime(indexId, dataTime)
+	if err != nil {
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Data = lyData
+	br.Msg = "获取成功"
+}
+
+// GetLyDataByIndexIdAndDataTimeYM
+// @Title 根据指标id和年月时间获取指标数据
+// @Description 根据指标id和年月时间获取指标数据
+// @Success 200 {object} models.BaseFromLyData
+// @router /get/ly/data/by/index/id/and/data/time/ym [get]
+func (this *BaseFromLyController) GetLyDataByIndexIdAndDataTimeYM() {
+	br := new(models.BaseResponse).Init()
+	var cacheKey string
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		_ = utils.Rc.Delete(cacheKey)
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	indexId, err := this.GetInt("IndexId")
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if indexId == 0 {
+		br.Msg = "请输入指标id!"
+		br.ErrMsg = "请输入指标id"
+		return
+	}
+
+	yearMonth := this.GetString("YearMonth")
+
+	if yearMonth == "" {
+		br.Msg = "请输入时间!"
+		br.ErrMsg = "请输入时间"
+		return
+	}
+
+	lyData, err := models.GetLyDataByIndexIdAndDataTimeYM(indexId, yearMonth)
+	if err != nil {
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Data = lyData
+	br.Msg = "获取成功"
+}
+
+// UpdateLyDataById
+// @Title 更新数据源指标数据
+// @Description 更新数据源指标数据
+// @Success 200 string "处理成功"
+// @router /update/ly/data/by/id [get]
+func (this *BaseFromLyController) UpdateLyDataById() {
+	br := new(models.BaseResponse).Init()
+	var cacheKey string
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		_ = utils.Rc.Delete(cacheKey)
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	id, err := this.GetInt("Id")
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if id == 0 {
+		br.Msg = "请输入id!"
+		br.ErrMsg = "请输入id"
+		return
+	}
+
+	value, err := this.GetFloat("Value")
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	if value == 0 {
+		br.Msg = "请输入值!"
+		br.ErrMsg = "请输入值"
+		return
+	}
+
+	err = models.UpdateLyDataById(id, value)
+	if err != nil {
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "处理成功"
+}
+
+// UpdateLyEdbDataById
+// @Title 更新指标库指标数据
+// @Description 更新数据源指标数据
+// @Success 200 string "处理成功"
+// @router /update/ly/edb/data/by/id [get]
+func (this *BaseFromLyController) UpdateLyEdbDataById() {
+	br := new(models.BaseResponse).Init()
+	var cacheKey string
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		_ = utils.Rc.Delete(cacheKey)
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	id, err := this.GetInt("Id")
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if id == 0 {
+		br.Msg = "请输入id!"
+		br.ErrMsg = "请输入id"
+		return
+	}
+
+	value, err := this.GetFloat("Value")
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	if value == 0 {
+		br.Msg = "请输入值!"
+		br.ErrMsg = "请输入值"
+		return
+	}
+
+	err = models.UpdateLyDataById(id, value)
+	if err != nil {
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "处理成功"
+}

+ 26 - 0
models/base_from_ly_classify.go

@@ -0,0 +1,26 @@
+// @Author gmy 2024/8/7 9:26:00
+package models
+
+import "github.com/beego/beego/v2/client/orm"
+
+type BaseFromLyClassify struct {
+	BaseFromLyClassifyId int    `orm:"column(base_from_ly_classify_id);pk"` // 分类ID
+	CreateTime           string `orm:"column(create_time)"`                 // 创建时间
+	ModifyTime           string `orm:"column(modify_time)"`                 // 修改时间
+	ClassifyName         string `orm:"column(classify_name)"`               // 分类名称
+	ParentId             int    `orm:"column(parent_id)"`                   // 上级id
+	Sort                 int    `orm:"column(sort)"`                        // 排序字段,越小越靠前
+	ClassifyNameEn       string `orm:"column(classify_name_en)"`            // 英文分类名称
+}
+
+func init() {
+	orm.RegisterModel(new(BaseFromLyClassify))
+}
+
+// GetLyClassifyByName 根据分类名称查询
+func GetLyClassifyByName(classifyName string) (item *BaseFromLyClassify, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `SELECT * FROM base_from_ly_classify WHERE classify_name=?`
+	err = o.Raw(sql, classifyName).QueryRow(&item)
+	return
+}

+ 60 - 0
models/base_from_ly_data.go

@@ -0,0 +1,60 @@
+// @Author gmy 2024/8/7 9:50:00
+package models
+
+import "github.com/beego/beego/v2/client/orm"
+
+type BaseFromLyData struct {
+	BaseFromLyDataId  int     `orm:"column(base_from_ly_data_id);pk"` // 数据ID
+	CreateTime        string  `orm:"column(create_time)"`             // 创建时间
+	ModifyTime        string  `orm:"column(modify_time)"`             // 修改时间
+	BaseFromLyIndexId int     `orm:"column(base_from_ly_index_id)"`   // 指标id
+	IndexCode         string  `orm:"column(index_code)"`              // 指标编码
+	DataTime          string  `orm:"column(data_time)"`               // 数据日期
+	Value             float64 `orm:"column(value)"`                   // 数据值
+}
+
+func init() {
+	orm.RegisterModel(new(BaseFromLyData))
+}
+
+// AddLyDataList 批量插入数据记录列表
+func AddLyDataList(items []BaseFromLyData) (err error) {
+	o := orm.NewOrmUsingDB("data")
+	_, err = o.InsertMulti(len(items), items)
+	return
+}
+
+// GetLyDataByIndexIdAndDataTime 根据指标id和数据日期查询数据
+func GetLyDataByIndexIdAndDataTime(indexId int, dataTime string) (items []BaseFromLyData, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `SELECT * FROM base_from_ly_data WHERE base_from_ly_index_id=? AND data_time=?`
+	_, err = o.Raw(sql, indexId, dataTime).QueryRows(&items)
+	return
+}
+
+// GetLyDataByIndexIdAndDataTimeYM 根据指标id和数据日期的年月查询数据
+func GetLyDataByIndexIdAndDataTimeYM(indexId int, dataTime string) (items []BaseFromLyData, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `SELECT * FROM base_from_ly_data WHERE base_from_ly_index_id=? AND data_time like ?`
+	_, err = o.Raw(sql, indexId, dataTime+"%").QueryRows(&items)
+	return
+}
+
+// UpdateLyDataById 根据主键id更新数据
+func UpdateLyDataById(dataId int, value float64) (err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `UPDATE base_from_ly_data SET value=? WHERE base_from_ly_data_id=?`
+	_, err = o.Raw(sql, value, dataId).Exec()
+	return
+}
+
+// GetBaseFromLyDataByIndexCode 根据指标编码查询
+func GetBaseFromLyDataByIndexCode(condition string, pars []interface{}) (items []BaseFromLyData, err error) {
+	sql := `SELECT * FROM base_from_ly_data WHERE 1=1 `
+	o := orm.NewOrm()
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars...).QueryRows(&items)
+	return
+}

+ 57 - 0
models/base_from_ly_index.go

@@ -0,0 +1,57 @@
+// Package models
+// @Author gmy 2024/8/7 9:38:00
+package models
+
+import (
+	"errors"
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type BaseFromLyIndex struct {
+	BaseFromLyIndexId    int    `orm:"column(base_from_ly_index_id);pk"` // 指标ID
+	CreateTime           string `orm:"column(create_time)"`              // 创建时间
+	ModifyTime           string `orm:"column(modify_time)"`              // 修改时间
+	BaseFromLyClassifyId int    `orm:"column(base_from_ly_classify_id)"` // 原始数据指标分类id
+	IndexCode            string `orm:"column(index_code)"`               // 指标编码
+	IndexName            string `orm:"column(index_name)"`               // 指标名称
+	Frequency            string `orm:"column(frequency)"`                // 频度
+	Unit                 string `orm:"column(unit)"`                     // 单位
+	EdbExist             int    `orm:"column(edb_exist)"`                // 指标库是否已添加:0-否;1-是
+}
+
+// 在 init 函数中注册模型
+func init() {
+	orm.RegisterModel(new(BaseFromLyIndex))
+}
+
+// AddLyIndexList 批量插入指标记录列表
+func AddLyIndexList(items []*BaseFromLyIndex) (err error) {
+	o := orm.NewOrmUsingDB("data")
+	_, err = o.InsertMulti(len(items), items)
+	return
+}
+
+// AddLyIndex 添加指标
+func AddLyIndex(item *BaseFromLyIndex) (int64, error) {
+	item.CreateTime = time.Now().Format("2006-01-02 15:04:05")
+	o := orm.NewOrmUsingDB("data")
+	id, err := o.Insert(item)
+	if err != nil {
+		return 0, err
+	}
+	return id, nil
+}
+
+// GetLyIndexByCode 查询指标编码是否存在
+func GetLyIndexByCode(indexCode string) (item *BaseFromLyIndex, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `SELECT * FROM base_from_ly_index WHERE index_code=?`
+	err = o.Raw(sql, indexCode).QueryRow(&item)
+
+	if errors.Is(err, orm.ErrNoRows) {
+		return nil, nil
+	}
+
+	return
+}

+ 46 - 0
models/base_from_ly_index_record.go

@@ -0,0 +1,46 @@
+// Package models
+// @Author gmy 2024/8/7 9:38:00
+package models
+
+import (
+	"errors"
+	"github.com/beego/beego/v2/client/orm"
+)
+
+type BaseFromLyIndexRecord struct {
+	BaseFromLyIndexRecordId int    `orm:"column(base_from_ly_index_record_id);pk"` // 指标记录ID
+	CreateTime              string `orm:"column(create_time)"`                     // 创建时间
+	ModifyTime              string `orm:"column(modify_time)"`                     // 修改时间
+	Product                 string `orm:"column(product)"`                         // 产品
+	Category                string `orm:"column(category)"`                        // 分类
+	Url                     string `orm:"column(url)"`                             // 指标页面地址
+	DataTime                string `orm:"column(data_time)"`                       // 数据日期
+}
+
+// 在 init 函数中注册模型
+func init() {
+	orm.RegisterModel(new(BaseFromLyIndexRecord))
+}
+
+// AddLyIndexRecord 添加指标记录
+func AddLyIndexRecord(item *BaseFromLyIndexRecord) (int64, error) {
+	o := orm.NewOrmUsingDB("data")
+	id, err := o.Insert(item)
+	if err != nil {
+		return 0, err
+	}
+	return id, nil
+}
+
+// GetLyIndexRecordByUrl 查询指标记录是否存在
+func GetLyIndexRecordByUrl(url string) (item *BaseFromLyIndexRecord, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `SELECT * FROM base_from_ly_index_record WHERE url=?`
+	err = o.Raw(sql, url).QueryRow(&item)
+
+	if errors.Is(err, orm.ErrNoRows) {
+		return nil, nil
+	}
+
+	return
+}

+ 172 - 0
models/ebd_data_ly.go

@@ -0,0 +1,172 @@
+// @Author gmy 2024/9/14 16:13:00
+package models
+
+// AddEdbDataFromLy 新增指标数据
+func AddEdbDataFromLy(edbCode string) (err error) {
+	o := orm.NewOrm()
+
+	var condition string
+	var pars []interface{}
+
+	if edbCode != "" {
+		condition += " AND index_code = ? "
+		pars = append(pars, edbCode)
+	}
+
+	dataAll, err := GetBaseFromLyDataByIndexCode(condition, pars)
+	if err != nil {
+		return err
+	}
+	dataLen := len(dataAll)
+
+	existMap := make(map[string]string)
+	if dataLen > 0 {
+		var isAdd bool
+		addSql := ` INSERT INTO edb_data_ly (edb_info_id,edb_code,data_time,value,create_time,modify_time,data_timestamp) values `
+		for i := 0; i < dataLen; i++ {
+			item := dataAll[i]
+			eDate := item.DataTime
+			sValue := utils.SubFloatToString(item.Value, 4)
+			if sValue != "" {
+				if _, ok := existMap[eDate]; !ok {
+					dataTime, err := time.ParseInLocation(utils.FormatDate, eDate, time.Local)
+					if err != nil {
+						return err
+					}
+					timestamp := dataTime.UnixNano() / 1e6
+					timeStr := fmt.Sprintf("%d", timestamp)
+					addSql += GetAddSql("0", edbCode, eDate, timeStr, sValue)
+					isAdd = true
+				}
+			}
+			existMap[eDate] = eDate
+		}
+		if isAdd {
+			addSql = strings.TrimRight(addSql, ",")
+			utils.FileLog.Info("addSql:" + addSql)
+			_, err = o.Raw(addSql).Exec()
+			if err != nil {
+				return err
+			}
+		}
+	}
+	return
+}
+
+func RefreshEdbDataFromLy(edbInfoId int, edbCode, startDate string) (err error) {
+	source := utils.DATA_SOURCE_LY
+	subSource := utils.DATA_SUB_SOURCE_EDB
+
+	o := orm.NewOrm()
+	if err != nil {
+		return
+	}
+	edbInfoIdStr := strconv.Itoa(edbInfoId)
+	//计算数据
+	var condition string
+	var pars []interface{}
+
+	if edbCode != "" {
+		condition += " AND index_code=? "
+		pars = append(pars, edbCode)
+	}
+
+	if startDate != "" {
+		condition += " AND data_time>=? "
+		pars = append(pars, startDate)
+	}
+
+	dataList, err := GetBaseFromLyDataByIndexCode(condition, pars)
+	if err != nil {
+		return
+	}
+
+	// 真实数据的最大日期  , 插入规则配置的日期
+	var realDataMaxDate, edbDataInsertConfigDate time.Time
+	var edbDataInsertConfig *EdbDataInsertConfig
+	var isFindConfigDateRealData bool //是否找到配置日期的实际数据的值
+	{
+		edbDataInsertConfig, err = GetEdbDataInsertConfigByEdbId(edbInfoId)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			return
+		}
+		if edbDataInsertConfig != nil {
+			edbDataInsertConfigDate = edbDataInsertConfig.Date
+		}
+	}
+
+	var existCondition string
+	var existPars []interface{}
+
+	existCondition += " AND edb_info_id=? "
+	existPars = append(existPars, edbInfoId)
+	if startDate != "" {
+		existCondition += " AND data_time>=? "
+		existPars = append(existPars, startDate)
+	}
+	//获取指标所有数据
+	existList, err := GetEdbDataByCondition(source, subSource, existCondition, existPars)
+	if err != nil {
+		return err
+	}
+	existMap := make(map[string]*EdbInfoSearchData)
+	for _, v := range existList {
+		existMap[v.DataTime] = v
+	}
+
+	addSql := ` INSERT INTO ebd_data_ly(edb_info_id,edb_code,data_time,value,create_time,modify_time,data_timestamp) values `
+	var isAdd bool
+	addMap := make(map[string]string)
+	for _, v := range dataList {
+		item := v
+		eDate := item.DataTime
+		sValue := utils.SubFloatToString(item.Value, 4)
+
+		dataTime, err := time.ParseInLocation(utils.FormatDate, eDate, time.Local)
+		if err != nil {
+			return err
+		}
+		if findItem, ok := existMap[v.DataTime]; !ok {
+			if sValue != "" {
+				timestamp := dataTime.UnixNano() / 1e6
+				timeStr := fmt.Sprintf("%d", timestamp)
+				saveValue := sValue
+
+				if _, addOk := addMap[eDate]; !addOk {
+					addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, saveValue)
+					isAdd = true
+				}
+			}
+		} else {
+			if findItem != nil && utils.SubFloatToString(findItem.Value, 4) != sValue {
+				err = ModifyEdbDataById(source, subSource, findItem.EdbDataId, sValue)
+				if err != nil {
+					return err
+				}
+			}
+		}
+		addMap[v.DataTime] = v.DataTime
+
+		// 下面代码主要目的是处理掉手动插入的数据判断
+		{
+			if realDataMaxDate.IsZero() || dataTime.After(realDataMaxDate) {
+				realDataMaxDate = dataTime
+			}
+			if edbDataInsertConfigDate.IsZero() || dataTime.Equal(edbDataInsertConfigDate) {
+				isFindConfigDateRealData = true
+			}
+		}
+	}
+
+	// 处理手工数据补充的配置
+	HandleConfigInsertEdbData(realDataMaxDate, edbDataInsertConfig, edbInfoId, source, subSource, existMap, isFindConfigDateRealData)
+
+	if isAdd {
+		addSql = strings.TrimRight(addSql, ",")
+		_, err = o.Raw(addSql).Exec()
+		if err != nil {
+			return err
+		}
+	}
+	return
+}

+ 2 - 0
models/edb_data_table.go

@@ -170,6 +170,8 @@ func GetEdbDataTableName(source, subSource int) (tableName string) {
 		tableName = "edb_data_sci_hq"
 	case utils.DATA_SOURCE_TRADE_ANALYSIS: // 持仓分析->92
 		tableName = "edb_data_trade_analysis"
+	case utils.DATA_SOURCE_LY: // 粮油商务网->91
+		tableName = "edb_data_ly"
 	default:
 		edbSource := EdbSourceIdMap[source]
 		if edbSource != nil {

+ 99 - 0
routers/commentsRouter.go

@@ -106,6 +106,105 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_index_lib/controllers:BaseFromLyController"] = append(beego.GlobalControllerRouter["eta/eta_index_lib/controllers:BaseFromLyController"],
+        beego.ControllerComments{
+            Method: "Add",
+            Router: `/add`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_index_lib/controllers:BaseFromLyController"] = append(beego.GlobalControllerRouter["eta/eta_index_lib/controllers:BaseFromLyController"],
+        beego.ControllerComments{
+            Method: "AddLyDataList",
+            Router: `/add/ly/data/list`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_index_lib/controllers:BaseFromLyController"] = append(beego.GlobalControllerRouter["eta/eta_index_lib/controllers:BaseFromLyController"],
+        beego.ControllerComments{
+            Method: "AddLyIndex",
+            Router: `/add/ly/index`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_index_lib/controllers:BaseFromLyController"] = append(beego.GlobalControllerRouter["eta/eta_index_lib/controllers:BaseFromLyController"],
+        beego.ControllerComments{
+            Method: "AddLyIndexRecord",
+            Router: `/add/ly/index/record`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_index_lib/controllers:BaseFromLyController"] = append(beego.GlobalControllerRouter["eta/eta_index_lib/controllers:BaseFromLyController"],
+        beego.ControllerComments{
+            Method: "GetLyClassifyByName",
+            Router: `/get/ly/classify/by/name`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_index_lib/controllers:BaseFromLyController"] = append(beego.GlobalControllerRouter["eta/eta_index_lib/controllers:BaseFromLyController"],
+        beego.ControllerComments{
+            Method: "GetLyDataByIndexIdAndDataTime",
+            Router: `/get/ly/data/by/index/id/and/data/time`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_index_lib/controllers:BaseFromLyController"] = append(beego.GlobalControllerRouter["eta/eta_index_lib/controllers:BaseFromLyController"],
+        beego.ControllerComments{
+            Method: "GetLyDataByIndexIdAndDataTimeYM",
+            Router: `/get/ly/data/by/index/id/and/data/time/ym`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_index_lib/controllers:BaseFromLyController"] = append(beego.GlobalControllerRouter["eta/eta_index_lib/controllers:BaseFromLyController"],
+        beego.ControllerComments{
+            Method: "GetLyIndexRecordByUrl",
+            Router: `/get/ly/index/record/by/url`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_index_lib/controllers:BaseFromLyController"] = append(beego.GlobalControllerRouter["eta/eta_index_lib/controllers:BaseFromLyController"],
+        beego.ControllerComments{
+            Method: "Refresh",
+            Router: `/refresh`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_index_lib/controllers:BaseFromLyController"] = append(beego.GlobalControllerRouter["eta/eta_index_lib/controllers:BaseFromLyController"],
+        beego.ControllerComments{
+            Method: "UpdateLyDataById",
+            Router: `/update/ly/data/by/id`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_index_lib/controllers:BaseFromLyController"] = append(beego.GlobalControllerRouter["eta/eta_index_lib/controllers:BaseFromLyController"],
+        beego.ControllerComments{
+            Method: "UpdateLyEdbDataById",
+            Router: `/update/ly/edb/data/by/id`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_index_lib/controllers:BloombergController"] = append(beego.GlobalControllerRouter["eta/eta_index_lib/controllers:BloombergController"],
         beego.ControllerComments{
             Method: "Add",

+ 5 - 0
routers/router.go

@@ -287,6 +287,11 @@ func init() {
 				&factor_edb_series.FactorEdbSeriesController{},
 			),
 		),
+		beego.NSNamespace("/ly",
+			beego.NSInclude(
+				&controllers.BaseFromLyController{},
+			),
+		),
 		beego.NSNamespace("/oilchem",
 			beego.NSInclude(
 				&controllers.OilchemController{},

+ 1 - 0
utils/constants.go

@@ -113,6 +113,7 @@ const (
 	DATA_SOURCE_SCI_HQ                               = 88 // 卓创红期->88
 	DATA_SOURCE_OILCHEM                              = 89 // 隆众资讯 -> 89
 	DATA_SOURCE_PREDICT_CALCULATE_RANGEANLYSIS       = 90 // 预测指标区间计算->90
+	DATA_SOURCE_LY            						 = 91 // 粮油商务网
 	DATA_SOURCE_TRADE_ANALYSIS                       = 92 // 持仓分析
 )