123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- package data
- import (
- "eta/eta_hub/models/data_manage"
- "eta/eta_hub/utils"
- "fmt"
- )
- /*// GetEdbRelationList 获取指标引用列表
- func GetEdbRelationList(source, edbType int, classifyId, sysUserId, frequency, keyword, status string, startSize, pageSize int, sortParam, sortType string) (total int, list []*data_manage.BaseRelationEdbInfo, err error) {
- var pars []interface{}
- var condition string
- list = make([]*data_manage.BaseRelationEdbInfo, 0)
- isStop := -1
- switch status {
- case `暂停`:
- isStop = 1
- case `启用`:
- isStop = 0
- case `供应商停用`:
- isStop = 3
- }
- // 关联表语句
- var addFieldStr, joinTableStr string
- switch source {
- case 0: // 计算指标,不校验source
- default:
- condition += ` AND e.source = ? `
- pars = append(pars, source)
- }
- if edbType == 2 { //计算指标
- condition += ` AND e.edb_type = ? AND e.edb_info_type = 0`
- pars = append(pars, edbType)
- }
- switch isStop {
- case -1:
- // 供应商停用
- if source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
- joinTableStr = ` LEFT JOIN base_from_mysteel_chemical_index z ON e.edb_code = z.index_code `
- addFieldStr = ` ,z.is_supplier_stop `
- }
- case 0, 1:
- condition += " AND e.no_update = ? "
- pars = append(pars, isStop)
- // 供应商停用
- if source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
- condition += " AND z.is_supplier_stop = ? "
- pars = append(pars, 0)
- joinTableStr = ` LEFT JOIN base_from_mysteel_chemical_index z ON e.edb_code = z.index_code `
- addFieldStr = ` ,z.is_supplier_stop `
- }
- case 3:
- // 供应商停用
- if source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
- condition += " AND z.is_supplier_stop = ? "
- pars = append(pars, 1)
- joinTableStr = ` LEFT JOIN base_from_mysteel_chemical_index z ON e.edb_code = z.index_code `
- addFieldStr = ` ,z.is_supplier_stop `
- }
- }
- if classifyId != `` {
- classifyIdSlice := strings.Split(classifyId, ",")
- condition += ` AND e.classify_id IN (` + utils.GetOrmInReplace(len(classifyIdSlice)) + `)`
- pars = append(pars, classifyIdSlice)
- }
- if sysUserId != `` {
- sysUserIdSlice := strings.Split(sysUserId, ",")
- condition += ` AND e.sys_user_id IN (` + utils.GetOrmInReplace(len(sysUserIdSlice)) + `)`
- pars = append(pars, sysUserIdSlice)
- }
- if frequency != `` {
- frequencySlice := strings.Split(frequency, ",")
- condition += ` AND e.frequency IN (` + utils.GetOrmInReplace(len(frequencySlice)) + `)`
- pars = append(pars, frequencySlice)
- }
- if keyword != `` {
- keywordSlice := strings.Split(keyword, " ")
- if len(keywordSlice) > 0 {
- tmpConditionSlice := make([]string, 0)
- tmpConditionSlice = append(tmpConditionSlice, ` e.edb_name like ? or e.edb_code like ? `)
- pars = utils.GetLikeKeywordPars(pars, keyword, 2)
- for _, v := range keywordSlice {
- if v == ` ` || v == `` {
- continue
- }
- tmpConditionSlice = append(tmpConditionSlice, ` e.edb_name like ? or e.edb_code like ? `)
- pars = utils.GetLikeKeywordPars(pars, v, 2)
- }
- condition += ` AND (` + strings.Join(tmpConditionSlice, " or ") + `)`
- } else {
- condition += ` AND (e.edb_name like ? or e.edb_code like ? )`
- pars = utils.GetLikeKeywordPars(pars, keyword, 2)
- }
- }
- sortStr := ``
- if sortParam != `` {
- sortStr = fmt.Sprintf("%s %s,e.edb_info_id desc ", sortParam, sortType)
- }
- total, list, err = data_manage.GetEdbInfoRelationList(condition, pars, addFieldStr, joinTableStr, sortStr, startSize, pageSize)
- return
- }
- */
- // GetCalculateEdbByFromEdbInfo 找到依赖于该基础指标的所有计算指标
- func GetCalculateEdbByFromEdbInfo(edbInfoIds []int, calculateEdbIds []int, hasFind map[int]struct{}) (newCalculateEdbIds []int, err error) {
- if len(edbInfoIds) == 0 {
- return
- }
- newCalculateEdbIds = calculateEdbIds
- newEdbInfoIds := make([]int, 0)
- for _, v := range edbInfoIds {
- if _, ok := hasFind[v]; ok {
- continue
- }
- newEdbInfoIds = append(newEdbInfoIds, v)
- }
- if len(newEdbInfoIds) == 0 {
- return
- }
- var condition string
- var pars []interface{}
- // 关联指标
- condition += ` AND b.from_edb_info_id in (` + utils.GetOrmInReplace(len(newEdbInfoIds)) + `)`
- pars = append(pars, newEdbInfoIds)
- //获取关联图表列表
- list, err := data_manage.GetRelationEdbInfoListMappingByCondition(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- err = fmt.Errorf("获取关联指标信息失败,Err:%s", err.Error())
- return
- }
- calculateEdbIdsTmp := make([]int, 0)
- for _, mapping := range list {
- if mapping.EdbType == 2 && mapping.EdbInfoType == 0 { // 如果指标库里的计算指标,则加入,否则继续找
- newCalculateEdbIds = append(newCalculateEdbIds, mapping.EdbInfoId)
- calculateEdbIdsTmp = append(calculateEdbIdsTmp, mapping.EdbInfoId)
- }
- }
- for _, v := range newEdbInfoIds {
- hasFind[v] = struct{}{}
- }
- if len(calculateEdbIdsTmp) > 0 {
- newCalculateEdbIds, err = GetCalculateEdbByFromEdbInfo(calculateEdbIdsTmp, newCalculateEdbIds, hasFind)
- if err != nil {
- return
- }
- }
- return
- }
|