浏览代码

粮油商务网-指标库删除-指标状态同步

gmy 8 月之前
父节点
当前提交
90694fd689

+ 14 - 9
controllers/data_manage/base_from_ly_index_controller.go

@@ -396,7 +396,7 @@ func (this *BaseFromLyIndexController) LyIndexDataExport() {
 	dir, _ := os.Executable()
 	exPath := filepath.Dir(dir)
 
-	downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
+	downLoadFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
 	xlsxFile := xlsx.NewFile()
 	frequencies, err := data_manage.GetLyIndexFrequency(classifyId)
 	if err != nil {
@@ -406,6 +406,13 @@ func (this *BaseFromLyIndexController) LyIndexDataExport() {
 	}
 
 	fileName := `粮油商务网`
+	if classifyId >= 0 && indexCode == "" {
+		lyClassify, err := data_manage.GetLyClassifyById(classifyId)
+		if err != nil {
+			return
+		}
+		fileName = lyClassify.ClassifyName
+	}
 	if frequencies == nil {
 		sheet, err := xlsxFile.AddSheet("无数据")
 		if err != nil {
@@ -419,12 +426,12 @@ func (this *BaseFromLyIndexController) LyIndexDataExport() {
 	}
 
 	for _, frequency := range frequencies {
-		lyIndices, err := data_manage.GetLyIndexByCodeAndClassify(indexCode, classifyId)
+		lyIndices, err := data_manage.GetLyIndexByCodeAndClassify(indexCode, classifyId, frequency)
 		if err != nil {
 			return
 		}
 
-		if indexCode == "" {
+		if indexCode != "" {
 			fileName = lyIndices[0].IndexName
 		}
 
@@ -496,8 +503,6 @@ func (this *BaseFromLyIndexController) LyIndexDataExport() {
 
 			for _, m := range lyIndices {
 				celData := rowData.AddCell()
-				fmt.Println(m.IndexCode)
-				fmt.Println(dataTime)
 				if dataMap[m.IndexCode][dataTime] != nil {
 					celData.SetValue(dataMap[m.IndexCode][dataTime].Value)
 				}
@@ -505,7 +510,7 @@ func (this *BaseFromLyIndexController) LyIndexDataExport() {
 		}
 	}
 
-	err = xlsxFile.Save(downLoadnFilePath)
+	err = xlsxFile.Save(downLoadFilePath)
 	if err != nil {
 		//有指标无数据时先导出一遍空表
 		sheet, err := xlsxFile.AddSheet("无数据")
@@ -517,7 +522,7 @@ func (this *BaseFromLyIndexController) LyIndexDataExport() {
 		rowSecName := sheet.AddRow()
 		celSecName := rowSecName.AddCell()
 		celSecName.SetValue("")
-		err = xlsxFile.Save(downLoadnFilePath)
+		err = xlsxFile.Save(downLoadFilePath)
 		if err != nil {
 			br.Msg = "保存文件失败"
 			br.ErrMsg = "保存文件失败"
@@ -526,9 +531,9 @@ func (this *BaseFromLyIndexController) LyIndexDataExport() {
 	}
 
 	fileName += time.Now().Format("06.01.02") + `.xlsx` //文件名称
-	this.Ctx.Output.Download(downLoadnFilePath, fileName)
+	this.Ctx.Output.Download(downLoadFilePath, fileName)
 	defer func() {
-		os.Remove(downLoadnFilePath)
+		os.Remove(downLoadFilePath)
 	}()
 	br.Ret = 200
 	br.Success = true

+ 8 - 0
models/data_manage/base_from_ly_classify.go

@@ -38,3 +38,11 @@ func GetAllLyClassify() (items []*BaseFromLyClassify, err error) {
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
+
+// GetLyClassifyById 根据分类id查询
+func GetLyClassifyById(classifyId int) (item *BaseFromLyClassify, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `SELECT * FROM base_from_ly_classify WHERE base_from_ly_classify_id=?`
+	err = o.Raw(sql, classifyId).QueryRow(&item)
+	return
+}

+ 10 - 5
models/data_manage/base_from_ly_index.go

@@ -144,14 +144,14 @@ func GetLyIndexPage(classifyId string, searchParam string, currentIndex, pageSiz
 }
 
 // UpdateLyIndexEdbExist 指标库标记已添加
-func UpdateLyIndexEdbExist(indexCode string) (err error) {
+func UpdateLyIndexEdbExist(indexCode string, isExist int) (err error) {
 	o := orm.NewOrmUsingDB("data")
 
-	// 构建 SQL 语句
-	sql := `UPDATE base_from_ly_index SET edb_exist = 1 WHERE index_code = ?`
+	// 构建 SQL 更新语句
+	sql := `UPDATE base_from_ly_index SET edb_exist = ? WHERE index_code = ?`
 
 	// 执行 SQL 语句
-	_, err = o.Raw(sql, indexCode).Exec()
+	_, err = o.Raw(sql, isExist, indexCode).Exec()
 	if err != nil {
 		return err
 	}
@@ -184,7 +184,7 @@ func GetLyDataMaxCount(classifyId int) (count int, err error) {
 }
 
 // GetLyIndexByCodeAndClassify 根据指标编码和分类查询 indexCode非必传
-func GetLyIndexByCodeAndClassify(indexCode string, classifyId int) (items []*BaseFromLyIndex, err error) {
+func GetLyIndexByCodeAndClassify(indexCode string, classifyId int, frequency *string) (items []*BaseFromLyIndex, err error) {
 	o := orm.NewOrmUsingDB("data")
 
 	// SQL 查询语句
@@ -206,6 +206,11 @@ func GetLyIndexByCodeAndClassify(indexCode string, classifyId int) (items []*Bas
 		params = append(params, indexCode)
 	}
 
+	if frequency != nil {
+		sql += ` AND a.frequency = ?`
+		params = append(params, *frequency)
+	}
+
 	sql += ` GROUP BY a.index_code, a.index_name, a.frequency, a.unit`
 
 	_, err = o.Raw(sql, params...).QueryRows(&items)

+ 1 - 1
services/data/base_from_ly_index_service.go

@@ -209,7 +209,7 @@ func LyIndexAdd(req LyIndexAddReq, lang string) (edb *data_manage.EdbInfo, err e
 	edb = edbInfo
 
 	// 标记原始指标为已添加
-	err = data_manage.UpdateLyIndexEdbExist(req.EdbCode)
+	err = data_manage.UpdateLyIndexEdbExist(req.EdbCode, utils.IS_YES)
 	if err != nil {
 		err = fmt.Errorf("BaseIndex: 标记已添加指标库失败, err: %s", err.Error())
 		return

+ 10 - 0
services/data/edb_classify.go

@@ -903,6 +903,16 @@ func Delete(classifyId, edbInfoId int, sysUser *system.Admin, requestBody, reque
 			return
 		}
 
+		// 维护粮油数据源指标领取状态
+		if edbInfo.Source == utils.DATA_SOURCE_LY {
+			err := data_manage.UpdateLyIndexEdbExist(edbInfo.EdbCode, utils.IS_NO)
+			if err != nil {
+				errMsg = "删除失败"
+				err = errors.New("删除失败,Err:" + tmpErr.Error())
+				return
+			}
+		}
+
 		// 如果是同花顺高频数据或类似数据, 还需要删除base_from_edb_mapping对应关系
 		baseMappingOb := new(data_manage.BaseFromEdbMapping)
 		{

+ 6 - 0
utils/constants.go

@@ -325,6 +325,12 @@ const (
 	PREDICT_EDB_INFO_TYPE = 1 //指标类型 1:预测指标
 )
 
+// 是否关系 无实义
+const (
+	IS_YES = 1
+	IS_NO  = 0
+)
+
 // FrequencyDaysMap 频度日期的map关系
 var FrequencyDaysMap = map[string]int{
 	"天": 1, "周": 7, "月": 30, "季": 90, "年": 365,