|
@@ -5,6 +5,7 @@ import (
|
|
|
"eta_gn/eta_api/utils"
|
|
|
"fmt"
|
|
|
"github.com/rdlucklib/rdluck_tools/paging"
|
|
|
+ "strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
@@ -94,6 +95,43 @@ func (m *EdbCollect) RemoveByCondition(condition string, pars []interface{}) (er
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// RemoveAndCreateMulti
|
|
|
+// @Description: 清除原有配置并新增收藏
|
|
|
+// @receiver m
|
|
|
+// @param delCondition
|
|
|
+// @param delPars
|
|
|
+// @param items
|
|
|
+// @return err
|
|
|
+func (m *EdbCollect) RemoveAndCreateMulti(delCondition string, delPars []interface{}, items []*EdbCollect) (err error) {
|
|
|
+ to := global.DmSQL["data"].Begin()
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ _ = to.Rollback()
|
|
|
+ } else {
|
|
|
+ _ = to.Commit()
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ // 先删除
|
|
|
+ {
|
|
|
+ if delCondition == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ sql := fmt.Sprintf(`DELETE FROM %s WHERE %s`, m.TableName(), delCondition)
|
|
|
+ err = to.Exec(sql, delPars...).Error
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(items) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = to.CreateInBatches(items, utils.MultiAddNum).Error
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
func (m *EdbCollect) GetItemById(id int) (item *EdbCollect, err error) {
|
|
|
sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
|
|
|
err = global.DmSQL["data"].Raw(sql, id).First(&item).Error
|
|
@@ -154,16 +192,17 @@ func GetCollectEdbInfoByClassifyId(classifyId int) (items []*EdbInfo, err error)
|
|
|
|
|
|
// EdbCollectReq 加入/取消收藏
|
|
|
type EdbCollectReq struct {
|
|
|
- ClassifyId int `description:"分类ID"`
|
|
|
- EdbInfoId int `description:"指标ID"`
|
|
|
+ ClassifyId int `description:"分类ID"`
|
|
|
+ ClassifyIdList []int `description:"分类ID列表"`
|
|
|
+ EdbInfoId int `description:"指标ID"`
|
|
|
}
|
|
|
|
|
|
// GetCollectEdbInfoCount 获取收藏的指标信息总数
|
|
|
func GetCollectEdbInfoCount(condition string, pars []interface{}) (total int64, err error) {
|
|
|
sql := fmt.Sprintf(`SELECT COUNT(1) AS ct FROM (
|
|
|
- SELECT b.* FROM edb_collect AS a JOIN edb_info AS b ON a.edb_info_id = b.edb_info_id
|
|
|
+ SELECT b.edb_info_id FROM edb_collect AS a JOIN edb_info AS b ON a.edb_info_id = b.edb_info_id
|
|
|
WHERE 1=1 %s
|
|
|
- ORDER BY a.create_time DESC
|
|
|
+ GROUP BY b.edb_info_id
|
|
|
) AS sub`, condition)
|
|
|
err = global.DmSQL["data"].Raw(sql, pars...).Scan(&total).Error
|
|
|
return
|
|
@@ -171,9 +210,26 @@ func GetCollectEdbInfoCount(condition string, pars []interface{}) (total int64,
|
|
|
|
|
|
// GetCollectEdbInfoPageList 获取收藏的指标信息列表-分页
|
|
|
func GetCollectEdbInfoPageList(condition string, pars []interface{}, startSize, pageSize int) (list []*CollectEdbInfoQuery, err error) {
|
|
|
- sql := fmt.Sprintf(`SELECT b.*, a.edb_collect_classify_id AS collect_classify_id FROM edb_collect AS a JOIN edb_info AS b ON a.edb_info_id = b.edb_info_id
|
|
|
+ sql := fmt.Sprintf(`SELECT b."edb_info_id",
|
|
|
+ WM_CONCAT(DISTINCT a."edb_collect_classify_id") AS "collect_classify_id",
|
|
|
+MAX(a.create_time) as collect_time,
|
|
|
+MAX(b."edb_code") AS "edb_code",
|
|
|
+MAX(b."edb_name") "edb_name",
|
|
|
+MAX(b."edb_info_type") "edb_info_type",
|
|
|
+MAX(b."edb_type") "edb_type",
|
|
|
+MAX(b."source") "source",
|
|
|
+MAX(b."source_name") "source_name",
|
|
|
+MAX(b."frequency") "frequency",
|
|
|
+MAX(b."unit") "unit",
|
|
|
+MAX(b."classify_id") "classify_id",
|
|
|
+MAX(b."create_time") "create_time",
|
|
|
+MAX(b."unique_code") "unique_code",
|
|
|
+MAX(b."chart_image") "chart_image",
|
|
|
+MAX(b."modify_time") "modify_time"
|
|
|
+ FROM edb_collect AS a JOIN edb_info AS b ON a.edb_info_id = b.edb_info_id
|
|
|
WHERE 1=1 %s
|
|
|
- ORDER BY a.create_time DESC LIMIT ?,?`, condition)
|
|
|
+ GROUP BY b.edb_info_id
|
|
|
+ORDER BY collect_time DESC LIMIT ?,?`, condition)
|
|
|
pars = append(pars, startSize, pageSize)
|
|
|
err = global.DmSQL["data"].Raw(sql, pars...).Scan(&list).Error
|
|
|
return
|
|
@@ -181,24 +237,24 @@ func GetCollectEdbInfoPageList(condition string, pars []interface{}, startSize,
|
|
|
|
|
|
type CollectEdbInfoQuery struct {
|
|
|
EdbInfo
|
|
|
- CollectClassifyId int `gorm:"column:collect_classify_id" description:"收藏分类ID"`
|
|
|
+ CollectClassifyIdStr string `gorm:"column:collect_classify_id" description:"收藏分类ID"`
|
|
|
}
|
|
|
|
|
|
// CollectEdbInfoItem 收藏列表指标信息
|
|
|
type CollectEdbInfoItem struct {
|
|
|
- EdbInfoId int `description:"指标ID"`
|
|
|
- EdbInfoType int `description:"指标类型:0-普通指标; 1-预测指标"`
|
|
|
- EdbType int `description:"指标类型:1-基础指标; 2-计算指标"`
|
|
|
- Source int `description:"来源ID"`
|
|
|
- SourceName string `description:"来源名称"`
|
|
|
- EdbCode string `description:"指标编码"`
|
|
|
- EdbName string `description:"指标名称"`
|
|
|
- Frequency string `description:"频率"`
|
|
|
- Unit string `description:"单位"`
|
|
|
- UniqueCode string `description:"唯一编码"`
|
|
|
- ChartImage string `description:"图表图片"`
|
|
|
- ClassifyId int `description:"指标分类ID"`
|
|
|
- CollectClassifyId int `description:"收藏分类ID"`
|
|
|
+ EdbInfoId int `description:"指标ID"`
|
|
|
+ EdbInfoType int `description:"指标类型:0-普通指标; 1-预测指标"`
|
|
|
+ EdbType int `description:"指标类型:1-基础指标; 2-计算指标"`
|
|
|
+ Source int `description:"来源ID"`
|
|
|
+ SourceName string `description:"来源名称"`
|
|
|
+ EdbCode string `description:"指标编码"`
|
|
|
+ EdbName string `description:"指标名称"`
|
|
|
+ Frequency string `description:"频率"`
|
|
|
+ Unit string `description:"单位"`
|
|
|
+ UniqueCode string `description:"唯一编码"`
|
|
|
+ ChartImage string `description:"图表图片"`
|
|
|
+ ClassifyId int `description:"指标分类ID"`
|
|
|
+ CollectClassifyIdList []int `description:"收藏分类ID列表"`
|
|
|
}
|
|
|
|
|
|
func FormatEdbInfo2CollectItem(origin *CollectEdbInfoQuery) (item *CollectEdbInfoItem) {
|
|
@@ -215,7 +271,18 @@ func FormatEdbInfo2CollectItem(origin *CollectEdbInfoQuery) (item *CollectEdbInf
|
|
|
item.UniqueCode = origin.UniqueCode
|
|
|
item.ChartImage = origin.ChartImage
|
|
|
item.ClassifyId = origin.ClassifyId
|
|
|
- item.CollectClassifyId = origin.CollectClassifyId
|
|
|
+ collectClassifyIdList := make([]int, 0)
|
|
|
+ if origin.CollectClassifyIdStr != `` {
|
|
|
+ collectClassifyIdStrList := strings.Split(origin.CollectClassifyIdStr, ",")
|
|
|
+ for _, v := range collectClassifyIdStrList {
|
|
|
+ //collectClassifyIdList =
|
|
|
+ collectClassifyId, tmpErr := strconv.Atoi(v)
|
|
|
+ if tmpErr == nil {
|
|
|
+ collectClassifyIdList = append(collectClassifyIdList, collectClassifyId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ item.CollectClassifyIdList = collectClassifyIdList
|
|
|
return
|
|
|
}
|
|
|
|