12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706 |
- package data
- import (
- "errors"
- "eta/eta_api/models"
- "eta/eta_api/models/data_manage"
- "eta/eta_api/models/data_manage/cross_variety"
- "eta/eta_api/models/data_manage/excel"
- "eta/eta_api/models/system"
- "eta/eta_api/services/data/data_manage_permission"
- "eta/eta_api/services/data_stat"
- "eta/eta_api/utils"
- "fmt"
- "strconv"
- "time"
- )
- func EdbClassifyListMakeTree(allNode []*data_manage.EdbClassifyItems, node *data_manage.EdbClassifyItems) {
- childs, _ := edbClassifyHaveChild(allNode, node)
- allEdbInfo, _ := GetEdbClassifyEdbInfo()
- if len(childs) > 0 {
- node.Children = append(node.Children, childs[0:]...)
- for _, v := range childs {
- _, has := edbClassifyHaveChild(allNode, v)
- if has {
- EdbClassifyListMakeTree(allNode, v)
- } else {
- edbInfoList := allEdbInfo[v.ClassifyId]
- v.Children = edbInfoList
- if v.Children == nil {
- childrenArr := make([]*data_manage.EdbClassifyItems, 0)
- v.Children = childrenArr
- }
- }
- }
- } else {
- childrenArr := make([]*data_manage.EdbClassifyItems, 0)
- node.Children = childrenArr
- }
- }
- func edbClassifyHaveChild(allNode []*data_manage.EdbClassifyItems, node *data_manage.EdbClassifyItems) (childs []*data_manage.EdbClassifyItems, yes bool) {
- for _, v := range allNode {
- if v.ParentId == node.ClassifyId {
- childs = append(childs, v)
- }
- }
- if len(childs) > 0 {
- yes = true
- }
- return
- }
- func GetClassifyTreeRecursive(list []*data_manage.EdbClassifyItems, parentId, level int) []*data_manage.EdbClassifyItems {
- res := make([]*data_manage.EdbClassifyItems, 0)
- for _, v := range list {
- v.SelectDisable = true
- if v.Level == level {
- v.SelectDisable = false
- }
- if v.ParentId == parentId {
- v.Children = GetClassifyTreeRecursive(list, v.ClassifyId, level)
- res = append(res, v)
- }
- }
- return res
- }
- func GetFullClassifyByClassifyId(targetClassifyId int) (targetList []*data_manage.EdbClassifyIdItems, err error, errMsg string) {
-
- targetClassify, err := data_manage.GetEdbClassifyById(targetClassifyId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- errMsg = "当前分类不存在"
- err = errors.New(errMsg)
- return
- }
- errMsg = "获取失败"
- err = errors.New("获取分类信息失败,Err:" + err.Error())
- return
- }
- if targetClassify.ParentId == 0 {
- targetItem := new(data_manage.EdbClassifyIdItems)
- targetItem.ClassifyId = targetClassify.ClassifyId
- targetItem.ParentId = targetClassify.ParentId
- targetItem.RootId = targetClassify.RootId
- targetItem.UniqueCode = targetClassify.UniqueCode
- targetItem.Level = targetClassify.Level
- targetItem.ClassifyName = targetClassify.ClassifyName
- targetItem.ClassifyNameEn = targetClassify.ClassifyNameEn
- targetItem.IsJoinPermission = targetClassify.IsJoinPermission
- targetList = append(targetList, targetItem)
- return
- }
- tmpList, err := data_manage.GetEdbClassifyByRootIdLevel(targetClassify.RootId, targetClassify.ClassifyType, "")
- if err != nil && err.Error() != utils.ErrNoRow() {
- errMsg = "获取失败"
- err = errors.New("获取数据失败,Err:" + err.Error())
- return
- }
- idMap := make(map[int]struct{})
- if len(tmpList) > 0 {
- for _, v := range tmpList {
- if v.ClassifyId == targetClassify.ClassifyId {
- idMap[v.ClassifyId] = struct{}{}
- idMap[v.ParentId] = struct{}{}
- }
- }
- for _, v := range tmpList {
- if _, ok := idMap[v.ClassifyId]; ok {
- idMap[v.ParentId] = struct{}{}
- }
- }
- for _, v := range tmpList {
- if _, ok := idMap[v.ClassifyId]; ok {
- targetItem := new(data_manage.EdbClassifyIdItems)
- targetItem.ClassifyId = v.ClassifyId
- targetItem.ParentId = v.ParentId
- targetItem.RootId = v.RootId
- targetItem.UniqueCode = v.UniqueCode
- targetItem.Level = v.Level
- targetItem.ClassifyName = v.ClassifyName
- targetItem.ClassifyNameEn = v.ClassifyNameEn
- targetItem.IsJoinPermission = v.IsJoinPermission
- targetList = append(targetList, targetItem)
- }
- }
- }
- return
- }
- func GetFullClassifyByRootId(targetClassify *data_manage.EdbClassify, tmpList []*data_manage.EdbClassifyItems) (targetList []*data_manage.EdbClassifyIdItems, err error, errMsg string) {
- if targetClassify.ParentId == 0 {
- targetItem := new(data_manage.EdbClassifyIdItems)
- targetItem.ClassifyId = targetClassify.ClassifyId
- targetItem.ParentId = targetClassify.ParentId
- targetItem.RootId = targetClassify.RootId
- targetItem.UniqueCode = targetClassify.UniqueCode
- targetItem.Level = targetClassify.Level
- targetItem.ClassifyName = targetClassify.ClassifyName
- targetItem.ClassifyName = targetClassify.ClassifyName
- targetItem.IsJoinPermission = targetClassify.IsJoinPermission
- targetList = append(targetList, targetItem)
- return
- }
- idMap := make(map[int]struct{})
- if len(tmpList) > 0 {
- for _, v := range tmpList {
- if v.ClassifyId == targetClassify.ClassifyId {
- idMap[v.ClassifyId] = struct{}{}
- idMap[v.ParentId] = struct{}{}
- }
- }
- for _, v := range tmpList {
- if _, ok := idMap[v.ClassifyId]; ok {
- idMap[v.ParentId] = struct{}{}
- }
- }
- for _, v := range tmpList {
- if _, ok := idMap[v.ClassifyId]; ok {
- targetItem := new(data_manage.EdbClassifyIdItems)
- targetItem.ClassifyId = v.ClassifyId
- targetItem.ParentId = v.ParentId
- targetItem.RootId = v.RootId
- targetItem.UniqueCode = v.UniqueCode
- targetItem.Level = v.Level
- targetItem.ClassifyName = v.ClassifyName
- targetItem.IsJoinPermission = v.IsJoinPermission
- targetList = append(targetList, targetItem)
- }
- }
- }
- return
- }
- func GetChildClassifyByClassifyId(targetClassifyId int) (targetList []*data_manage.EdbClassifyIdItems, err error, errMsg string) {
-
- targetClassify, err := data_manage.GetEdbClassifyById(targetClassifyId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- errMsg = "当前分类不存在"
- err = errors.New(errMsg)
- return
- }
- errMsg = "获取失败"
- err = errors.New("获取分类信息失败,Err:" + err.Error())
- return
- }
- orderStr := ` order by level asc, sort asc, classify_id asc`
- tmpList, err := data_manage.GetEdbClassifyByRootIdLevel(targetClassify.RootId, targetClassify.ClassifyType, orderStr)
- if err != nil && err.Error() != utils.ErrNoRow() {
- errMsg = "获取失败"
- err = errors.New("获取数据失败,Err:" + err.Error())
- return
- }
- idMap := make(map[int]struct{})
- if len(tmpList) > 0 {
- for _, v := range tmpList {
- if v.ClassifyId == targetClassify.ClassifyId {
- idMap[v.ClassifyId] = struct{}{}
- }
- }
- for _, v := range tmpList {
- if _, ok := idMap[v.ParentId]; ok {
- idMap[v.ClassifyId] = struct{}{}
- }
- }
- for _, v := range tmpList {
- if _, ok := idMap[v.ClassifyId]; ok {
- targetItem := new(data_manage.EdbClassifyIdItems)
- targetItem.ClassifyId = v.ClassifyId
- targetItem.ParentId = v.ParentId
- targetItem.RootId = v.RootId
- targetItem.UniqueCode = v.UniqueCode
- targetItem.Level = v.Level
- targetItem.ClassifyName = v.ClassifyName
- targetItem.IsJoinPermission = v.IsJoinPermission
- targetList = append(targetList, targetItem)
- }
- }
- }
- return
- }
- func GetEdbClassifyEdbInfo() (result map[int][]*data_manage.EdbClassifyItems, err error) {
- cMap := make(map[int][]*data_manage.EdbClassifyItems)
- items, err := data_manage.GetEdbInfoAll(0)
- if err != nil {
- return
- }
- for _, v := range items {
- childrenArr := make([]*data_manage.EdbClassifyItems, 0)
- v.Children = childrenArr
- if items, ok := cMap[v.ClassifyId]; ok {
- items = append(items, v)
- cMap[v.ClassifyId] = items
- } else {
- infoList := make([]*data_manage.EdbClassifyItems, 0)
- infoList = append(infoList, v)
- cMap[v.ClassifyId] = infoList
- }
- }
- result = cMap
- return
- }
- func EdbClassifyItemsMakeTree(allNode []*data_manage.EdbClassifyItems, node *data_manage.EdbClassifyItems) {
- childs, _ := edbClassifyHaveChild(allNode, node)
- if len(childs) > 0 {
- node.Children = append(node.Children, childs[0:]...)
- for _, v := range childs {
- _, has := edbClassifyHaveChild(allNode, v)
- if has {
- EdbClassifyItemsMakeTree(allNode, v)
- } else {
- childrenArr := make([]*data_manage.EdbClassifyItems, 0)
- v.Children = childrenArr
- }
- }
- } else {
- childrenArr := make([]*data_manage.EdbClassifyItems, 0)
- node.Children = childrenArr
- }
- }
- func GetEdbClassifyListByAdminId(adminId int64) (classifyIdList []string, err error) {
- list, err := models.GetEdbdataClassify(adminId)
- if err != nil {
- return
- }
- for _, parent := range list {
- if parent.Child != nil {
- for _, classify := range parent.Child {
- classifyIdList = append(classifyIdList, fmt.Sprint(classify.ClassifyId))
- }
- }
- }
- return
- }
- func GetEdbClassifyNameListByAdminId(adminId int64) (classifyNameList []string, edbDataClassifyMap map[string]*models.EdbdataClassify, err error) {
- list, err := models.GetEdbdataClassify(adminId)
- edbDataClassifyMap = make(map[string]*models.EdbdataClassify)
- if err != nil {
- return
- }
- for _, parent := range list {
- if parent.Child != nil {
- for _, classify := range parent.Child {
- classifyNameList = append(classifyNameList, classify.ClassifyName)
- edbDataClassifyMap[classify.ClassifyName] = classify
- }
- }
- }
- return
- }
- func AddEdbClassify(classifyName string, parentId, level int, classifyType uint8, sysUserId int, sysUserName, lang string) (classifyInfo *data_manage.EdbClassify, err error, errMsg string) {
-
- {
- var count int
- switch lang {
- case utils.EnLangVersion:
- count, err = data_manage.GetEdbClassifyEnCount(classifyName, parentId, classifyType)
- default:
- count, err = data_manage.GetEdbClassifyCount(classifyName, parentId, classifyType)
- }
- if err != nil {
- errMsg = `判断名称是否已存在失败`
- return
- }
- if count > 0 {
- errMsg = `分类名称已存在,请重新输入`
- err = errors.New(errMsg)
- return
- }
- }
-
- if level > 6 {
- errMsg = `最高只支持添加6级分类`
- return
- }
-
- maxSort, err := GetEdbClassifyMaxSort(parentId, classifyType)
- if err != nil {
- errMsg = "获取失败"
- err = errors.New("查询排序信息失败,Err:" + err.Error())
- return
- }
-
- rootId := 0
- if parentId > 0 {
- parentClassify, tErr := data_manage.GetEdbClassifyById(parentId)
- if tErr != nil {
- if tErr.Error() == utils.ErrNoRow() {
- errMsg = "父级分类不存在"
- err = errors.New(errMsg)
- return
- }
- errMsg = "获取失败"
- err = errors.New("获取分类信息失败,Err:" + tErr.Error())
- return
- }
- rootId = parentClassify.RootId
- }
- timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
- classifyInfo = &data_manage.EdbClassify{
-
- ClassifyType: classifyType,
- ClassifyName: classifyName,
- ClassifyNameEn: classifyName,
- ParentId: parentId,
- RootId: rootId,
- HasData: 0,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- SysUserId: sysUserId,
- SysUserRealName: sysUserName,
- Level: level + 1,
- UniqueCode: utils.MD5(utils.DATA_PREFIX + "_" + timestamp),
- Sort: maxSort + 1,
- }
- newId, err := data_manage.AddEdbClassify(classifyInfo)
- if err != nil {
- errMsg = "保存分类失败"
- return
- }
-
- {
- source := 3
- if classifyType == 1 {
- source = 4
- }
- go data_manage_permission.InheritParentClassify(source, int(classifyType), int(newId), classifyInfo.ParentId, classifyInfo.ClassifyName)
- }
- if parentId == 0 {
- classifyInfo.ClassifyId = int(newId)
- classifyInfo.RootId = int(newId)
- err = classifyInfo.Update([]string{"RootId"})
- if err != nil {
- errMsg = "更新分类失败"
- return
- }
- }
- return
- }
- func EditEdbClassify(classifyId, parentId int, classifyName, lang string, sysUser *system.Admin) (err error, errMsg string) {
- item, err := data_manage.GetEdbClassifyById(classifyId)
- if err != nil {
- errMsg = `保存失败`
- return
- }
-
- {
-
- permissionClassifyIdList, tmpErr := data_manage_permission.GetUserEdbClassifyPermissionList(sysUser.AdminId, classifyId)
- if tmpErr != nil {
- errMsg = "保存失败"
- err = errors.New("获取已授权分类id数据失败,Err:" + tmpErr.Error())
- return
- }
-
- haveOperaAuth := data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(item.IsJoinPermission, item.ClassifyId, permissionClassifyIdList)
- if item.ClassifyType == 0 {
- button := GetEdbClassifyOpButton(sysUser, item.SysUserId, haveOperaAuth)
- if !button.OpButton {
- errMsg = "无操作权限"
- err = errors.New(errMsg)
- return
- }
- } else if item.ClassifyType == 1 {
- button := GetPredictEdbClassifyOpButton(sysUser, item.SysUserId, haveOperaAuth)
- if !button.OpButton {
- errMsg = "无操作权限"
- err = errors.New(errMsg)
- return
- }
- }
- }
- if parentId != item.ParentId {
- parentClassifyInfo, e := data_manage.GetEdbClassifyById(parentId)
- if e != nil {
- err = e
- return
- }
- if item.Level != parentClassifyInfo.Level+1 {
- err = errors.New("父级分类层级异常")
- return
- }
- }
-
- updateCols := make([]string, 0)
- if parentId != item.ParentId {
- item.ParentId = parentId
- item.ModifyTime = time.Now()
- updateCols = append(updateCols, "ParentId", "ModifyTime")
- }
- switch lang {
- case utils.EnLangVersion:
-
-
-
-
-
- count, tmpErr := data_manage.GetEdbClassifyEnCount(classifyName, item.ParentId, item.ClassifyType)
- if tmpErr != nil {
- err = tmpErr
- errMsg = "判断名称是否已存在失败"
- return
- }
- if count > 0 {
- errMsg = "分类名称已存在,请重新输入"
- err = errors.New(errMsg)
- return
- }
- item.ClassifyNameEn = classifyName
- item.LastModifyUserId = sysUser.AdminId
- item.LastModifyUserRealName = sysUser.RealName
- updateCols = append(updateCols, "ClassifyNameEn", "LastModifyUserId", "LastModifyUserRealName")
- default:
-
-
-
-
-
- count, tmpErr := data_manage.GetEdbClassifyCount(classifyName, item.ParentId, item.ClassifyType)
- if tmpErr != nil {
- err = tmpErr
- errMsg = "判断名称是否已存在失败"
- return
- }
- if count > 0 {
- errMsg = "分类名称已存在,请重新输入"
- err = errors.New(errMsg)
- return
- }
- item.ClassifyName = classifyName
- item.LastModifyUserId = sysUser.AdminId
- item.LastModifyUserRealName = sysUser.RealName
- updateCols = append(updateCols, "ClassifyName", "LastModifyUserId", "LastModifyUserRealName")
- }
-
- if len(updateCols) > 0 {
- err = item.Update(updateCols)
- if err != nil {
- errMsg = "保存失败"
- }
- }
- return
- }
- func DeleteCheck(classifyId, edbInfoId int, sysUser *system.Admin) (deleteStatus int, tipsMsg string, tableList []*data_manage.ExcelBaseInfo, err error, errMsg string) {
-
- if classifyId > 0 && edbInfoId == 0 {
-
- item, tmpErr := data_manage.GetEdbClassifyById(classifyId)
- if tmpErr != nil {
- errMsg = `查找分类失败`
- err = tmpErr
- return
- }
-
- permissionClassifyIdList, tmpErr := data_manage_permission.GetUserEdbClassifyPermissionList(sysUser.AdminId, classifyId)
- if tmpErr != nil {
- errMsg = "删除检测失败"
- err = errors.New("获取已授权分类id数据失败,Err:" + tmpErr.Error())
- return
- }
-
- {
-
- haveOperaAuth := data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(item.IsJoinPermission, item.ClassifyId, permissionClassifyIdList)
- if item.ClassifyType == 0 {
- button := GetEdbClassifyOpButton(sysUser, item.SysUserId, haveOperaAuth)
- if !button.DeleteButton {
- errMsg = "无操作权限"
- err = errors.New(errMsg)
- return
- }
- } else if item.ClassifyType == 1 {
- button := GetPredictEdbClassifyOpButton(sysUser, item.SysUserId, haveOperaAuth)
- if !button.DeleteButton {
- errMsg = "无操作权限"
- err = errors.New(errMsg)
- return
- }
- }
- }
-
- count, tmpErr := data_manage.GetEdbInfoCountByClassifyId(classifyId)
- if tmpErr != nil {
- errMsg = "删除失败"
- err = errors.New("分类下是否含有指标失败,Err:" + tmpErr.Error())
- return
- }
- if count > 0 {
- deleteStatus = 1
- tipsMsg = "若目录关联指标不可删除"
- }
- }
- if deleteStatus != 1 && edbInfoId == 0 {
- classifyCount, tmpErr := data_manage.GetClassifyCountByClassifyId(classifyId)
- if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
- errMsg = "删除失败"
- err = errors.New("分类下是否含有指标失败,Err:" + tmpErr.Error())
- return
- }
- if classifyCount > 0 {
- deleteStatus = 2
- tipsMsg = "确认删除当前目录及包含的子目录吗"
- }
- }
-
- if edbInfoId > 0 {
- edbInfo, tmpErr := data_manage.GetEdbInfoById(edbInfoId)
- if tmpErr != nil {
- if tmpErr.Error() == utils.ErrNoRow() {
- errMsg = "指标已删除,请刷新页面"
- err = errors.New("指标不存在,Err:" + tmpErr.Error())
- return
- } else {
- errMsg = "删除失败"
- err = errors.New("删除失败,获取指标信息失败,Err:" + tmpErr.Error())
- return
- }
- }
- if edbInfo == nil {
- errMsg = "指标已删除,请刷新页面"
- return
- }
-
- chartCount, tmpErr := data_manage.GetChartEdbMappingCount(edbInfoId)
- if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
- errMsg = "删除失败"
- err = errors.New("判断指标是否被用于作图失败,Err:" + tmpErr.Error())
- return
- }
- if chartCount > 0 {
- deleteStatus = 3
- tipsMsg = "当前指标已用作画图,不可删除"
- return
- }
-
- correlationChart := new(data_manage.ChartInfoCorrelation)
- correlationChartCount, tmpErr := correlationChart.GetChartEdbMappingCount(edbInfoId)
- if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
- errMsg = "删除失败"
- err = errors.New("判断指标是否被用于相关性图表失败,Err:" + tmpErr.Error())
- return
- }
- if correlationChartCount > 0 {
- deleteStatus = 3
- tipsMsg = "当前指标已用作画图,不可删除"
- return
- }
-
- {
- calculateCount, tmpErr := data_manage.GetEdbInfoCalculateMappingCount(edbInfoId)
- if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
- errMsg = "删除失败"
- err = errors.New("判断指标是否被用于计算失败,GetEdbInfoCalculateCount Err:" + tmpErr.Error())
- return
- }
- if calculateCount > 0 {
- deleteStatus = 4
- tipsMsg = "当前指标已用作指标运算,不可删除"
- return
- }
- }
-
- if edbInfo.EdbInfoType == 0 {
- predictEdbInfoCount, tmpErr := data_manage.GetPredictEdbConfCount(edbInfoId)
- if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
- errMsg = "删除失败"
- err = errors.New("判断指标是否被用于预测指标失败,Err:" + tmpErr.Error())
- return
- }
- if predictEdbInfoCount > 0 {
- deleteStatus = 5
- tipsMsg = "当前指标已用作预测指标,不可删除"
- return
- }
- }
-
- {
- tableItems, tmpErr := excel.GetNoCustomAnalysisExcelEdbMapping(edbInfoId)
- if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
- errMsg = "删除失败"
- err = errors.New("判断指标是否用作表格引用,GetNoCustomAnalysisExcelEdbMappingCount Err:" + tmpErr.Error())
- return
- }
-
-
-
-
-
- if len(tableItems) > 0 {
- deleteStatus = 6
- tipsMsg = "当前指标已被表格引用,不可删除"
- var excelIds []int
- for _, tableItem := range tableItems {
- if tableItem.ParentId > 0 {
- excelIds = append(excelIds, tableItem.ParentId)
- } else {
- excelIds = append(excelIds, tableItem.ExcelInfoId)
- }
- }
- tableList, tmpErr = excel.GetExcelBaseInfoByExcelInfoIdList(excelIds)
- if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
- errMsg = "删除失败"
- err = errors.New("判断指标是否用作表格引用,GetExcelBaseInfoByExcelInfoIdList Err:" + tmpErr.Error())
- return
- }
- return
- }
- }
-
- {
-
-
- tagXList, tmpErr := cross_variety.GetChartInfoCrossVarietyByXEdbInfoId(edbInfoId)
- if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
- errMsg = "删除失败"
- err = errors.New("判断指标是否用作跨品种图表使用,GetChartInfoCrossVarietyByXEdbInfoId Err:" + tmpErr.Error())
- return
- }
- if len(tagXList) > 0 {
- deleteStatus = 7
- tipsMsg = "当前指标已添加到跨品种分析,不可删除"
- return
- }
- tagYList, tmpErr := cross_variety.GetChartInfoCrossVarietyByYEdbInfoId(edbInfoId)
- if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
- errMsg = "删除失败"
- err = errors.New("判断指标是否用作跨品种图表使用,GetChartInfoCrossVarietyByYEdbInfoId Err:" + tmpErr.Error())
- return
- }
- if len(tagYList) > 0 {
- deleteStatus = 7
- tipsMsg = "当前指标已添加到跨品种分析,不可删除"
- return
- }
-
- }
-
- {
- ob := new(data_manage.FactorEdbSeriesMapping)
- cond := fmt.Sprintf(" AND %s = ?", ob.Cols().EdbInfoId)
- pars := make([]interface{}, 0)
- pars = append(pars, edbInfoId)
- count, e := ob.GetCountByCondition(cond, pars)
- if e != nil {
- errMsg = "删除失败"
- err = fmt.Errorf("获取指标是否用于系列失败, err: %v", e)
- return
- }
- if count > 0 {
- deleteStatus = 3
- tipsMsg = "当前指标已用于因子指标系列, 不可删除"
- return
- }
- }
-
- {
- ob := new(excel.ExcelInfo)
- cond := ` AND extra_config LIKE ?`
- keyword := fmt.Sprintf(`"BaseEdbInfoId":%d`, edbInfoId)
- keyword = fmt.Sprint("%", keyword, "%")
- pars := make([]interface{}, 0)
- pars = append(pars, keyword)
- count, e := ob.GetCountByCondition(cond, pars)
- if e != nil {
- errMsg = "删除失败"
- err = fmt.Errorf("获取指标是否用于持仓分析-相关性表格失败, err: %v", e)
- return
- }
- if count > 0 {
- deleteStatus = 3
- tipsMsg = "当前指标已用于持仓分析相关性表格, 不可删除"
- return
- }
- }
- }
- return
- }
- func Delete(classifyId, edbInfoId int, sysUser *system.Admin, requestBody, requestUrl string) (nextItem *data_manage.EdbInfo, tableList []*data_manage.ExcelBaseInfo, err error, errMsg string) {
-
- if classifyId > 0 && edbInfoId == 0 {
-
- item, tmpErr := data_manage.GetEdbClassifyById(classifyId)
- if tmpErr != nil {
- errMsg = `查找分类失败`
- err = tmpErr
- return
- }
-
- permissionClassifyIdList, tmpErr := data_manage_permission.GetUserEdbClassifyPermissionList(sysUser.AdminId, classifyId)
- if tmpErr != nil {
- errMsg = "删除失败"
- err = errors.New("获取已授权分类id数据失败,Err:" + tmpErr.Error())
- return
- }
-
- {
-
- haveOperaAuth := data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(item.IsJoinPermission, item.ClassifyId, permissionClassifyIdList)
- if item.ClassifyType == 0 {
- button := GetEdbClassifyOpButton(sysUser, item.SysUserId, haveOperaAuth)
- if !button.DeleteButton {
- errMsg = "无操作权限"
- err = errors.New(errMsg)
- return
- }
- } else if item.ClassifyType == 1 {
- button := GetPredictEdbClassifyOpButton(sysUser, item.SysUserId, haveOperaAuth)
- if !button.DeleteButton {
- errMsg = "无操作权限"
- err = errors.New(errMsg)
- return
- }
- }
- }
-
- count, tmpErr := data_manage.GetEdbInfoCountByClassifyId(classifyId)
- if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
- errMsg = "删除失败"
- err = errors.New("分类下是否含有指标失败,Err:" + tmpErr.Error())
- return
- }
- if count > 0 {
- errMsg = "该目录下存在关联指标,不可删除"
- return
- }
- tmpErr = data_manage.DeleteEdbClassify(classifyId)
- if tmpErr != nil {
- errMsg = "删除失败"
- err = errors.New("删除失败,Err:" + tmpErr.Error())
- return
- }
- }
-
- if edbInfoId > 0 {
- edbInfo, tmpErr := data_manage.GetEdbInfoById(edbInfoId)
- if tmpErr != nil {
- if tmpErr.Error() == utils.ErrNoRow() {
- errMsg = "指标已删除,请刷新页面"
- err = errors.New("指标不存在,Err:" + tmpErr.Error())
- return
- } else {
- errMsg = "删除失败"
- err = errors.New("删除失败,获取指标信息失败,Err:" + tmpErr.Error())
- return
- }
- }
- if edbInfo == nil {
- errMsg = "指标已删除,请刷新页面"
- return
- }
-
- chartCount, tmpErr := data_manage.GetChartEdbMappingCount(edbInfoId)
- if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
- errMsg = "删除失败"
- err = errors.New("判断指标是否被用于作图失败,Err:" + tmpErr.Error())
- return
- }
- if chartCount > 0 {
- errMsg = "当前指标已用作画图,不可删除"
- return
- }
-
- correlationChart := new(data_manage.ChartInfoCorrelation)
- correlationChartCount, tmpErr := correlationChart.GetChartEdbMappingCount(edbInfoId)
- if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
- errMsg = "删除失败"
- err = errors.New("判断指标是否被用于相关性图表失败,Err:" + tmpErr.Error())
- return
- }
- if correlationChartCount > 0 {
- errMsg = "当前指标已用作画图,不可删除"
- return
- }
-
- if edbInfo.EdbInfoType == 0 {
- predictEdbInfoCount, tmpErr := data_manage.GetPredictEdbConfCount(edbInfoId)
- if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
- errMsg = "删除失败"
- err = errors.New("判断指标是否被用于预测指标失败,Err:" + tmpErr.Error())
- return
- }
- if predictEdbInfoCount > 0 {
- errMsg = "当前指标已用作预测指标,不可删除"
- return
- }
- }
-
- {
- calculateCount, tmpErr := data_manage.GetEdbInfoCalculateMappingCount(edbInfoId)
- if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
- errMsg = "删除失败"
- err = errors.New("判断指标是否被用于计算失败,GetEdbInfoCalculateCount Err:" + tmpErr.Error())
- return
- }
- if calculateCount > 0 {
- errMsg = "当前指标已用作,指标运算,不可删除"
- return
- }
- }
-
- {
- tableItems, tmpErr := excel.GetNoCustomAnalysisExcelEdbMapping(edbInfoId)
- if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
- errMsg = "删除失败"
- err = errors.New("判断指标是否用作表格引用,GetNoCustomAnalysisExcelEdbMappingCount Err:" + tmpErr.Error())
- return
- }
-
-
-
-
-
- if len(tableItems) > 0 {
- errMsg = "当前指标已被表格引用,不可删除"
- return
- }
- }
-
- {
-
-
- tagXList, tmpErr := cross_variety.GetChartInfoCrossVarietyByXEdbInfoId(edbInfoId)
- if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
- errMsg = "删除失败"
- err = errors.New("判断指标是否用作跨品种图表使用,GetChartInfoCrossVarietyByXEdbInfoId Err:" + tmpErr.Error())
- return
- }
- if len(tagXList) > 0 {
- errMsg = "当前指标已添加到跨品种分析,不可删除"
- return
- }
- tagYList, tmpErr := cross_variety.GetChartInfoCrossVarietyByYEdbInfoId(edbInfoId)
- if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
- errMsg = "删除失败"
- err = errors.New("判断指标是否用作跨品种图表使用,GetChartInfoCrossVarietyByYEdbInfoId Err:" + tmpErr.Error())
- return
- }
- if len(tagYList) > 0 {
- errMsg = "当前指标已添加到跨品种分析,不可删除"
- return
- }
-
- }
-
- tmpErr = data_manage.DeleteEdbInfoAndData(edbInfo.EdbInfoId, edbInfo.Source, edbInfo.SubSource)
- if tmpErr != nil {
- errMsg = "删除失败"
- err = errors.New("删除失败,Err:" + tmpErr.Error())
- return
- }
-
- baseMappingOb := new(data_manage.BaseFromEdbMapping)
- {
- cond := fmt.Sprintf(" %s = ? AND %s = ? AND %s = ?", baseMappingOb.Cols().EdbCode, baseMappingOb.Cols().Source, baseMappingOb.Cols().SubSource)
- pars := make([]interface{}, 0)
- pars = append(pars, edbInfo.EdbCode, edbInfo.Source, edbInfo.SubSource)
- if e := baseMappingOb.RemoveByCondition(cond, pars); e != nil {
- errMsg = "删除失败"
- err = fmt.Errorf("删除源指标映射失败, %v", e)
- return
- }
- }
- go data_stat.AddEdbDeleteLog(edbInfo, sysUser)
-
- go handleByDelEdbInfo(edbInfo)
-
- {
- var condition string
- var pars []interface{}
- condition += " AND edb_info_type=? AND classify_id=? "
- pars = append(pars, edbInfo.EdbInfoType, edbInfo.ClassifyId)
- condition += " AND (sort>? OR (sort=? AND edb_info_id<?) ) "
- pars = append(pars, edbInfo.Sort, edbInfo.Sort, edbInfo.EdbInfoId)
- nextItem, tmpErr = data_manage.GetNextEdbInfoByCondition(condition, pars)
- if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
- errMsg = "删除失败"
- err = errors.New("获取下一级预测指标信息失败,Err:" + tmpErr.Error())
- return
- }
-
- if nextItem == nil {
- currClassifyInfo, tmpErr := data_manage.GetEdbClassifyById(edbInfo.ClassifyId)
- if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
- errMsg = "删除失败"
- err = errors.New("获取当前预测指标分类信息失败,Err:" + tmpErr.Error())
- return
- }
- nextItem, err = data_manage.GetNextEdbInfo(edbInfo.ClassifyId, currClassifyInfo.Sort, int(currClassifyInfo.ClassifyType), edbInfo.EdbInfoType)
- if err != nil && err.Error() != utils.ErrNoRow() {
- errMsg = "删除失败"
- err = errors.New("获取下一级预测指标信息失败,Err:" + tmpErr.Error())
- return
- }
- }
- }
-
- {
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = requestBody
- edbLog.Status = "删除指标"
- edbLog.Method = requestUrl
- go data_manage.AddEdbInfoLog(edbLog)
- }
-
- DeleteEdbInfoToEs(edbInfoId)
- }
- return
- }
- func MoveEdbClassify(req data_manage.MoveEdbClassifyReq, sysUser *system.Admin, classifyType uint8) (err error, errMsg string) {
-
- classifyId := req.ClassifyId
- parentClassifyId := req.ParentClassifyId
- prevClassifyId := req.PrevClassifyId
- nextClassifyId := req.NextClassifyId
- edbInfoId := req.EdbInfoId
- prevEdbInfoId := req.PrevEdbInfoId
- nextEdbInfoId := req.NextEdbInfoId
-
-
-
-
-
- var parentEdbClassifyInfo *data_manage.EdbClassify
- if parentClassifyId > 0 {
- parentEdbClassifyInfo, err = data_manage.GetEdbClassifyById(parentClassifyId)
- if err != nil {
- errMsg = "移动失败"
- err = errors.New("获取上级分类信息失败,Err:" + err.Error())
- return
- }
- }
-
- var (
- edbClassifyInfo *data_manage.EdbClassify
- prevClassify *data_manage.EdbClassify
- nextClassify *data_manage.EdbClassify
- edbInfo *data_manage.EdbInfo
- prevEdbInfo *data_manage.EdbInfo
- nextEdbInfo *data_manage.EdbInfo
- prevSort int
- nextSort int
- )
-
- if edbInfoId == 0 {
- edbClassifyInfo, err = data_manage.GetEdbClassifyById(classifyId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- errMsg = "当前分类不存在"
- err = errors.New("获取分类信息失败,Err:" + err.Error())
- return
- }
- errMsg = "移动失败"
- err = errors.New("获取分类信息失败,Err:" + err.Error())
- return
- }
- if parentClassifyId > 0 && parentEdbClassifyInfo.Level == 6 {
- errMsg = "最高只支持添加6级分类"
- err = errors.New(errMsg)
- return
- }
-
- exists, e := data_manage.GetEdbClassifyByParentIdAndName(parentClassifyId, edbClassifyInfo.ClassifyName, classifyId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- errMsg = "移动失败"
- err = fmt.Errorf("获取父级分类下的同名分类失败, Err: %s", e.Error())
- return
- }
- if exists != nil {
- errMsg = "移动失败,分类名称已存在"
- return
- }
-
- {
-
- permissionClassifyIdList, tmpErr := data_manage_permission.GetUserEdbClassifyPermissionList(sysUser.AdminId, classifyId)
- if tmpErr != nil {
- errMsg = "移动失败"
- err = errors.New("获取已授权分类id数据失败,Err:" + tmpErr.Error())
- return
- }
-
- haveOperaAuth := data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(edbClassifyInfo.IsJoinPermission, edbClassifyInfo.ClassifyId, permissionClassifyIdList)
- if edbClassifyInfo.ClassifyType == 0 {
- button := GetEdbClassifyOpButton(sysUser, edbClassifyInfo.SysUserId, haveOperaAuth)
- if !button.MoveButton {
- errMsg = "无操作权限"
- err = errors.New(errMsg)
- return
- }
- } else if edbClassifyInfo.ClassifyType == 1 {
- button := GetPredictEdbClassifyOpButton(sysUser, edbClassifyInfo.SysUserId, haveOperaAuth)
- if !button.MoveButton {
- errMsg = "无操作权限"
- err = errors.New(errMsg)
- return
- }
- }
- }
- } else {
- edbInfo, err = data_manage.GetEdbInfoById(req.EdbInfoId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- errMsg = "当前指标不存在"
- err = errors.New("获取分类信息失败,Err:" + err.Error())
- return
- }
- errMsg = "移动失败"
- err = errors.New("获取分类信息失败,Err:" + err.Error())
- return
- }
- if parentClassifyId == 0 {
- errMsg = "移动失败,指标必须挂在分类下"
- err = errors.New(errMsg)
- return
- }
- var haveOperaAuth bool
-
- {
- haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.EdbInfoId, edbInfo.ClassifyId, edbInfo.IsJoinPermission, sysUser.AdminId)
- if err != nil {
- errMsg = "移动失败"
- err = errors.New("获取指标权限信息失败,Err:" + err.Error())
- return
- }
- }
-
- button := GetEdbOpButton(sysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth)
- if !button.MoveButton {
- errMsg = "无操作权限"
- err = errors.New(errMsg)
- return
- }
- }
- if prevClassifyId > 0 {
- prevClassify, err = data_manage.GetEdbClassifyById(prevClassifyId)
- if err != nil {
- errMsg = "移动失败"
- err = errors.New("获取上一个兄弟节点分类信息失败,Err:" + err.Error())
- return
- }
- prevSort = prevClassify.Sort
- } else if prevEdbInfoId > 0 {
- prevEdbInfo, err = data_manage.GetEdbInfoById(prevEdbInfoId)
- if err != nil {
- errMsg = "移动失败"
- err = errors.New("获取上一个兄弟节点分类信息失败,Err:" + err.Error())
- return
- }
- prevSort = prevEdbInfo.Sort
- }
- if nextClassifyId > 0 {
-
- nextClassify, err = data_manage.GetEdbClassifyById(nextClassifyId)
- if err != nil {
- errMsg = "移动失败"
- err = errors.New("获取下一个兄弟节点分类信息失败,Err:" + err.Error())
- return
- }
- nextSort = nextClassify.Sort
- } else if nextEdbInfoId > 0 {
-
- nextEdbInfo, err = data_manage.GetEdbInfoById(nextEdbInfoId)
- if err != nil {
- errMsg = "移动失败"
- err = errors.New("获取下一个兄弟节点分类信息失败,Err:" + err.Error())
- return
- }
- nextSort = nextEdbInfo.Sort
- }
- err, errMsg = moveEdbClassify(parentEdbClassifyInfo, edbClassifyInfo, prevClassify, nextClassify, edbInfo, prevEdbInfo, nextEdbInfo, parentClassifyId, prevSort, nextSort, classifyType)
- return
- }
- func moveEdbClassify(parentEdbClassifyInfo, edbClassifyInfo, prevClassify, nextClassify *data_manage.EdbClassify, edbInfo, prevEdbInfo, nextEdbInfo *data_manage.EdbInfo, parentClassifyId int, prevSort, nextSort int, classifyType uint8) (err error, errMsg string) {
- updateCol := make([]string, 0)
-
- if edbClassifyInfo != nil {
- oldParentId := edbClassifyInfo.ParentId
- oldLevel := edbClassifyInfo.Level
- var classifyIds []int
- if oldParentId != parentClassifyId {
-
- childList, e, m := GetChildClassifyByClassifyId(edbClassifyInfo.ClassifyId)
- if e != nil {
- errMsg = "移动失败"
- err = errors.New("查询子分类失败,Err:" + e.Error() + m)
- return
- }
- if len(childList) > 0 {
- for _, v := range childList {
- if v.ClassifyId == edbClassifyInfo.ClassifyId {
- continue
- }
- classifyIds = append(classifyIds, v.ClassifyId)
- }
- }
- }
-
- if edbClassifyInfo.ParentId != parentClassifyId && parentClassifyId != 0 {
- if edbClassifyInfo.Level != parentEdbClassifyInfo.Level+1 {
- errMsg = "移动失败"
- err = errors.New("不支持目录层级变更")
- return
- }
- edbClassifyInfo.ParentId = parentEdbClassifyInfo.ClassifyId
- edbClassifyInfo.RootId = parentEdbClassifyInfo.RootId
- edbClassifyInfo.Level = parentEdbClassifyInfo.Level + 1
- edbClassifyInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "ParentId", "RootId", "Level", "ModifyTime")
- } else if edbClassifyInfo.ParentId != parentClassifyId && parentClassifyId == 0 {
- errMsg = "移动失败"
- err = errors.New("不支持目录层级变更")
- return
- }
- if prevSort > 0 {
-
- if nextSort > 0 {
-
-
- if prevSort == nextSort || prevSort == edbClassifyInfo.Sort {
-
- updateSortStr := `sort + 2`
-
- if prevClassify != nil {
- _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, prevClassify.ClassifyId, prevClassify.Sort, updateSortStr, classifyType)
- } else {
- _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr, classifyType)
- }
-
- if prevEdbInfo != nil {
-
- _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, prevEdbInfo.EdbInfoId, updateSortStr)
- } else {
- _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, 0, updateSortStr)
- }
- } else {
-
- if nextSort-prevSort == 1 {
-
- updateSortStr := `sort + 1`
-
- if prevClassify != nil {
- _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, prevClassify.ClassifyId, prevSort, updateSortStr, classifyType)
- } else {
- _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr, classifyType)
- }
-
- if prevEdbInfo != nil {
-
- _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, prevEdbInfo.EdbInfoId, updateSortStr)
- } else {
- _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, 0, updateSortStr)
- }
- }
- }
- }
- edbClassifyInfo.Sort = prevSort + 1
- edbClassifyInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- } else if prevClassify == nil && nextClassify == nil && prevEdbInfo == nil && nextEdbInfo == nil && parentClassifyId > 0 {
-
- var maxSort int
- maxSort, err = GetEdbClassifyMaxSort(parentClassifyId, classifyType)
- if err != nil {
- errMsg = "移动失败"
- err = errors.New("查询组内排序信息失败,Err:" + err.Error())
- return
- }
- edbClassifyInfo.Sort = maxSort + 1
- edbClassifyInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- } else {
-
- firstClassify, tmpErr := data_manage.GetFirstEdbClassifyByParentId(parentClassifyId)
- if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
- errMsg = "移动失败"
- err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
- return
- }
-
- if firstClassify != nil && firstClassify.Sort == 0 {
- updateSortStr := ` sort + 1 `
- _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, firstClassify.ClassifyId-1, 0, updateSortStr, classifyType)
-
- _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, 0, 0, updateSortStr)
- } else {
-
- firstEdb, tErr := data_manage.GetFirstEdbInfoByClassifyId(parentClassifyId)
- if tErr != nil && tErr.Error() != utils.ErrNoRow() {
- errMsg = "移动失败"
- err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tErr.Error())
- return
- }
-
- if firstEdb != nil && firstEdb.Sort == 0 {
- updateSortStr := ` sort + 1 `
- _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, 0, firstEdb.EdbInfoId-1, updateSortStr)
- _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, 0, updateSortStr, classifyType)
- }
- }
- edbClassifyInfo.Sort = 0
- edbClassifyInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- }
-
- if len(updateCol) > 0 {
- err = edbClassifyInfo.Update(updateCol)
- if err != nil {
- errMsg = "移动失败"
- err = errors.New("修改失败,Err:" + err.Error())
- return
- }
-
- if oldParentId != parentClassifyId {
- if len(classifyIds) > 0 {
- levelStep := edbClassifyInfo.Level - oldLevel
- err = data_manage.UpdateEdbClassifyChildByParentClassifyId(classifyIds, edbClassifyInfo.RootId, levelStep)
- if err != nil {
- errMsg = "移动失败"
- err = errors.New("更新子分类失败,Err:" + err.Error())
- return
- }
- }
- }
- }
- } else {
- if edbInfo == nil {
- errMsg = "当前指标不存在"
- err = errors.New(errMsg)
- return
- }
-
- if edbInfo.ClassifyId != parentClassifyId {
- edbInfo.ClassifyId = parentClassifyId
- edbInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "ClassifyId", "ModifyTime")
- }
- if prevSort > 0 {
-
- if nextSort > 0 {
-
-
- if prevSort == nextSort || prevSort == edbInfo.Sort {
-
- updateSortStr := `sort + 2`
-
- if prevClassify != nil {
- _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, prevClassify.ClassifyId, prevClassify.Sort, updateSortStr, classifyType)
- } else {
- _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr, classifyType)
- }
-
- if prevEdbInfo != nil {
-
- _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, prevEdbInfo.EdbInfoId, updateSortStr)
- } else {
- _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, 0, updateSortStr)
- }
- } else {
-
- if nextSort-prevSort == 1 {
-
- updateSortStr := `sort + 1`
-
- if prevClassify != nil {
- _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, prevClassify.ClassifyId, prevSort, updateSortStr, classifyType)
- } else {
- _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr, classifyType)
- }
-
- if prevEdbInfo != nil {
-
- _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, prevEdbInfo.EdbInfoId, updateSortStr)
- } else {
- _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, 0, updateSortStr)
- }
- }
- }
- }
- edbInfo.Sort = prevSort + 1
- edbInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- } else if prevClassify == nil && nextClassify == nil && prevEdbInfo == nil && nextEdbInfo == nil && parentClassifyId > 0 {
-
- var maxSort int
- maxSort, err = GetEdbClassifyMaxSort(parentClassifyId, classifyType)
- if err != nil {
- errMsg = "移动失败"
- err = errors.New("查询组内排序信息失败,Err:" + err.Error())
- return
- }
- edbInfo.Sort = maxSort + 1
- edbInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- } else {
-
- firstClassify, tmpErr := data_manage.GetFirstEdbClassifyByParentId(parentClassifyId)
- if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
- errMsg = "移动失败"
- err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
- return
- }
-
- if firstClassify != nil && firstClassify.Sort == 0 {
- updateSortStr := ` sort + 1 `
- _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, firstClassify.ClassifyId-1, 0, updateSortStr, classifyType)
-
- _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, 0, 0, updateSortStr)
- } else {
-
- firstEdb, tErr := data_manage.GetFirstEdbInfoByClassifyId(parentClassifyId)
- if tErr != nil && tErr.Error() != utils.ErrNoRow() {
- errMsg = "移动失败"
- err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tErr.Error())
- return
- }
-
- if firstEdb != nil && firstEdb.Sort == 0 {
- updateSortStr := ` sort + 1 `
- _ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, 0, firstEdb.EdbInfoId-1, updateSortStr)
- _ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, 0, updateSortStr, classifyType)
- }
- }
- edbInfo.Sort = 0
- edbInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- }
-
- if len(updateCol) > 0 {
- err = edbInfo.Update(updateCol)
- if err != nil {
- errMsg = "移动失败"
- err = errors.New("修改失败,Err:" + err.Error())
- return
- }
- }
- }
- return
- }
- func GetEdbOpButton(sysUser *system.Admin, belongUserId, edbType, edbInfoType int, haveOperaAuth bool) (button data_manage.EdbClassifyItemsButton) {
-
- if !haveOperaAuth {
- return
- }
-
-
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.AdminId == belongUserId || sysUser.EdbPermission == 1 {
- button.AddButton = true
- button.OpButton = true
- button.DeleteButton = true
- button.MoveButton = true
- }
-
- if edbInfoType == 0 && edbType == 1 {
- button.InsertNewDataButton = true
- }
- button.ShowEdbRelation = true
- button.ShowChartRelation = true
- return
- }
- func GetEdbClassifyOpButton(sysUser *system.Admin, belongUserId int, haveOperaAuth bool) (button data_manage.EdbClassifyItemsButton) {
-
- if !haveOperaAuth {
- return
- }
-
-
- button.AddButton = true
- button.OpButton = true
- button.DeleteButton = true
- button.MoveButton = true
-
- return
- }
- func GetPredictEdbOpButton(sysUser *system.Admin, belongUserId int, haveOperaAuth bool) (button data_manage.EdbClassifyItemsButton) {
-
- if !haveOperaAuth {
- return
- }
-
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.AdminId == belongUserId || sysUser.PredictEdbPermission == 1 {
- button.AddButton = true
- button.OpButton = true
- button.DeleteButton = true
- button.MoveButton = true
- }
- button.ShowEdbRelation = true
- button.ShowChartRelation = true
- return
- }
- func GetPredictEdbClassifyOpButton(sysUser *system.Admin, belongUserId int, haveOperaAuth bool) (button data_manage.EdbClassifyItemsButton) {
-
- if !haveOperaAuth {
- return
- }
-
-
- button.AddButton = true
- button.OpButton = true
- button.DeleteButton = true
- button.MoveButton = true
-
- return
- }
- func GetEdbClassifyMaxSort(parentId int, classifyType uint8) (maxSort int, err error) {
-
- classifyMaxSort, err := data_manage.GetEdbClassifyMaxSort(parentId, classifyType)
- if err != nil {
- return
- }
- maxSort = classifyMaxSort
- edbMaxSort, err := data_manage.GetEdbInfoMaxSortByClassifyId(parentId)
- if err != nil {
- return
- }
- if maxSort < edbMaxSort {
- maxSort = edbMaxSort
- }
- return
- }
- func GetEdbClassifyByIsMe(adminId, parentId, edbInfoType int, classifyList []*data_manage.EdbClassifyItems) (list []*data_manage.EdbClassifyItems, err error) {
- edbInfoList, err := data_manage.GetEdbInfoListByUserId([]int{adminId}, edbInfoType)
- if err != nil {
- return
- }
- classifyIdList := make([]int, 0)
- for _, edbInfo := range edbInfoList {
- if edbInfo.ClassifyId > 0 {
- classifyIdList = append(classifyIdList, edbInfo.ClassifyId)
- }
- }
- if parentId > 0 {
- for _, v := range classifyList {
- if v.ClassifyId > 0 && v.EdbInfoId == 0 {
- classifyItems, er, _ := GetChildClassifyByClassifyId(v.ClassifyId)
- if er != nil {
- err = er
- return
- }
- existClassifyMap := make(map[int]struct{})
- for _, classify := range classifyItems {
- existClassifyMap[classify.ClassifyId] = struct{}{}
- }
- for _, edb := range edbInfoList {
- if _, ok := existClassifyMap[edb.ClassifyId]; ok {
- list = append(list, v)
- break
- }
- }
- } else {
- list = append(list, v)
- }
- }
- } else {
- edbInfoClassifyList, er := data_manage.GetEdbClassifyByIdList(classifyIdList)
- if er != nil {
- err = er
- return
- }
- existClassifyIdMap := make(map[int]struct{})
- for _, classify := range edbInfoClassifyList {
- existClassifyIdMap[classify.RootId] = struct{}{}
- }
- for _, classify := range classifyList {
- if _, ok := existClassifyIdMap[classify.ClassifyId]; ok {
- list = append(list, classify)
- }
- }
- }
- return
- }
- func GetEdbClassifyChildrenRecursive(list []*data_manage.EdbClassifyItems, parentId int) []*data_manage.EdbClassifyItems {
- var res []*data_manage.EdbClassifyItems
- for _, v := range list {
- if v.ParentId == parentId {
-
- children := GetEdbClassifyChildrenRecursive(list, v.ClassifyId)
-
- res = append(res, v)
- res = append(res, children...)
- } else if v.ClassifyId == parentId {
-
- res = append(res, v)
- }
- }
- return res
- }
- func GetEdbClassifyChildrenRecursiveByParentIds(list []*data_manage.EdbClassifyItems, parentIds []string) []*data_manage.EdbClassifyItems {
- var res []*data_manage.EdbClassifyItems
- for _, v := range list {
- for _, id := range parentIds {
- parentId, _ := strconv.Atoi(id)
- if v.ParentId == parentId || v.ClassifyId == parentId {
-
- children := GetEdbClassifyChildrenRecursive(list, v.ClassifyId)
-
- res = append(res, v)
- res = append(res, children...)
- }
- }
- }
- return res
- }
|