1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117 |
- package data_manage_permission
- import (
- "encoding/json"
- "eta_gn/eta_api/models"
- "eta_gn/eta_api/models/data_manage"
- "eta_gn/eta_api/models/data_manage/data_manage_permission"
- "eta_gn/eta_api/models/data_manage/excel"
- "eta_gn/eta_api/models/system"
- "eta_gn/eta_api/utils"
- "fmt"
- "strconv"
- "strings"
- "time"
- "github.com/rdlucklib/rdluck_tools/uuid"
- )
- // GetEdbChartClassifyList
- // @Description: 获取数据权限那边的分类列表
- // @author: Roc
- // @datetime 2024-04-01 09:46:29
- // @param source int
- // @param subSource int
- // @return resp data_manage.EdbChartClassifyResp
- // @return err error
- func GetEdbChartClassifyList(source, subSource, sysUserId int) (resp data_manage.EdbChartClassifyResp, err error) {
- switch source {
- case 1: //手工数据指标
- list, e := models.GetEdbdataClassify(0)
- if e != nil {
- err = e
- return
- }
- for _, v := range list {
- item := data_manage.EdbChartClassify{
- ClassifyId: v.ClassifyId,
- ClassifyName: v.ClassifyName,
- ParentId: v.ParentId,
- }
- for _, v2 := range v.Child {
- child := data_manage.EdbChartClassify{
- ClassifyId: v2.ClassifyId,
- ClassifyName: v2.ClassifyName,
- ParentId: v2.ParentId,
- }
- item.Child = append(item.Child, &child)
- }
- resp.List = append(resp.List, &item)
- }
- case 3, 7:
- // 这里拆分指标库和计算指标
- classifyType := utils.EdbClassifyTypeBase
- if source == 7 {
- classifyType = utils.EdbClassifyTypeCalculate
- }
- if classifyType == utils.EdbClassifyTypeBase {
- sysUserId = 0
- }
- // 考虑到后面可以会迭代到10层, 这里直接用递归处理
- classifyAll, e := data_manage.GetAllEdbClassifyByType(classifyType, sysUserId)
- if e != nil && !utils.IsErrNoRow(e) {
- err = e
- return
- }
- resp.List = GetEdbMenuTreeRecursive(classifyAll, 0)
- case 4:
- //ETA预测指标
- // 考虑到后面可以会迭代到10层, 这里直接用递归
- classifyAll, e := data_manage.GetAllEdbClassifyByType(1, sysUserId)
- if e != nil && !utils.IsErrNoRow(e) {
- err = e
- return
- }
- resp.List = GetEdbMenuTreeRecursive(classifyAll, 0)
- case 5: //图库
- // 考虑到后面可以会迭代到10层, 这里直接用递归处理
- classifyAll, e := data_manage.GetAllChartClassifyItemsBySource(1)
- if e != nil && !utils.IsErrNoRow(e) {
- err = e
- return
- }
- resp.List = GetChartMenuTreeRecursive(classifyAll, 0)
- case 6:
- // ETA表格
- // 考虑到后面可以会迭代到10层, 这里直接用递归处理
- classifyAll, e := excel.GetExcelClassifyBySourceOrderByLevel(subSource)
- if e != nil && !utils.IsErrNoRow(e) {
- err = e
- return
- }
- resp.List = GetExcelMenuTreeRecursive(classifyAll, 0)
- default:
- return
- }
- return
- }
- // GetEdbMenuTreeRecursive 递归指标库菜单树
- func GetEdbMenuTreeRecursive(list []*data_manage.EdbClassifyItems, parentId int) []*data_manage.EdbChartClassify {
- res := make([]*data_manage.EdbChartClassify, 0)
- for _, v := range list {
- t := new(data_manage.EdbChartClassify)
- t.ClassifyId = v.ClassifyId
- t.ClassifyName = v.ClassifyName
- t.ParentId = v.ParentId
- t.IsJoinPermission = v.IsJoinPermission
- if v.ParentId == parentId {
- t.Child = GetEdbMenuTreeRecursive(list, v.ClassifyId)
- res = append(res, t)
- }
- }
- return res
- }
- // GetChartMenuTreeRecursive 递归指标库菜单树
- func GetChartMenuTreeRecursive(list []*data_manage.ChartClassifyItems, parentId int) []*data_manage.EdbChartClassify {
- res := make([]*data_manage.EdbChartClassify, 0)
- for _, v := range list {
- t := new(data_manage.EdbChartClassify)
- t.ClassifyId = v.ChartClassifyId
- t.ClassifyName = v.ChartClassifyName
- t.ParentId = v.ParentId
- t.IsJoinPermission = v.IsJoinPermission
- if v.ParentId == parentId {
- t.Child = GetChartMenuTreeRecursive(list, v.ChartClassifyId)
- res = append(res, t)
- }
- }
- return res
- }
- // GetExcelMenuTreeRecursive
- // @Description: 递归ETA表格菜单树
- // @author: Roc
- // @datetime 2024-03-27 10:30:32
- // @param list []*data_manage.ChartClassifyItems
- // @param parentId int
- // @return []*data_manage.EdbChartClassify
- func GetExcelMenuTreeRecursive(list []*excel.ExcelClassifyItems, parentId int) []*data_manage.EdbChartClassify {
- res := make([]*data_manage.EdbChartClassify, 0)
- for _, v := range list {
- t := new(data_manage.EdbChartClassify)
- t.ClassifyId = v.ExcelClassifyId
- t.ClassifyName = v.ExcelClassifyName
- t.ParentId = v.ParentId
- t.IsJoinPermission = v.IsJoinPermission
- if v.ParentId == parentId {
- t.Child = GetExcelMenuTreeRecursive(list, v.ExcelClassifyId)
- res = append(res, t)
- }
- }
- return res
- }
- // GetMoveEdbChartList 获取待转移的指标/图表列表
- // @param source 来源 :1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库 6:ETA表格
- func GetMoveEdbChartList(source, subSource, userId int, keyword, classify string, startSize, pageSize int) (list []data_manage.MoveEdbChartList, total int, err error) {
- var condition string
- var pars []interface{}
- switch source {
- case 1: //手工数据指标
- if keyword != "" {
- condition += ` AND (a.SEC_NAME LIKE ? OR a.TRADE_CODE like ? ) `
- pars = utils.GetLikeKeywordPars(pars, keyword, 2)
- }
- if userId > 0 {
- condition += ` AND a.user_id = ? `
- pars = append(pars, userId)
- }
- if classify != "" {
- condition += ` AND a.classify_id IN (` + classify + `) `
- }
- total, err = models.GetEdbinfoListCount(condition, pars, "", 0)
- if err != nil {
- return
- }
- tmpList, tmpErr := models.GetEdbinfoItemList(condition, pars, startSize, pageSize, "", 0)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- if len(tmpList) > 0 {
- adminIdList := make([]int, 0)
- for _, v := range tmpList {
- adminIdList = append(adminIdList, v.UserId)
- }
- adminList, tmpErr := system.GetAdminListByIdListWithoutEnable(adminIdList)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- adminMap := make(map[int]string)
- for _, adminInfo := range adminList {
- adminMap[adminInfo.AdminId] = adminInfo.RealName
- }
- for _, v := range tmpList {
- list = append(list, data_manage.MoveEdbChartList{
- DataId: v.TradeCode,
- Code: v.TradeCode,
- Name: v.SecName,
- ClassifyName: v.ClassifyName,
- NameEn: v.SecName,
- ClassifyNameEn: v.ClassifyName,
- CreateUserId: v.UserId,
- CreateUserName: adminMap[v.UserId],
- })
- }
- }
- case 3, 4, utils.EdbPermissionSourceCalculate: //ETA指标库、ETA预测指标、指标加工
- if keyword != `` {
- condition += " AND (edb_code like ? OR edb_name like ? OR edb_name_en like ? OR sys_user_real_name like ? ) "
- pars = utils.GetLikeKeywordPars(pars, keyword, 4)
- }
- if userId > 0 {
- condition += ` AND sys_user_id = ? `
- pars = append(pars, userId)
- }
- if classify != "" {
- condition += ` AND classify_id IN (` + classify + `) `
- }
- edbInfoType := 0 //ETA指标库
- if source == 4 { //ETA预测指标
- edbInfoType = 1
- }
- condition += ` AND edb_info_type = ? `
- pars = append(pars, edbInfoType)
- // 指标加工
- if source != 4 {
- edbType := utils.EdbTypeBase
- if source == utils.EdbPermissionSourceCalculate {
- edbType = utils.EdbTypeCalculate
- }
- condition += ` AND edb_type = ? `
- pars = append(pars, edbType)
- }
- total, err = data_manage.GetEdbInfoByConditionCount(condition, pars)
- if err != nil {
- return
- }
- tmpList, tmpErr := data_manage.GetEdbInfoListByCondition(condition, pars, startSize, pageSize, "DESC")
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range tmpList {
- list = append(list, data_manage.MoveEdbChartList{
- DataId: strconv.Itoa(v.EdbInfoId),
- Code: v.EdbCode,
- Name: v.EdbName,
- NameEn: v.EdbNameEn,
- //ClassifyName: v.,
- CreateUserId: v.SysUserId,
- CreateUserName: v.SysUserRealName,
- })
- }
- case 5: //图库
- // 只展示eta图库
- condition += ` AND source = ? `
- pars = append(pars, utils.CHART_SOURCE_DEFAULT)
- // 关键字搜索
- if keyword != `` {
- condition += " AND (chart_name like ? or chart_name_en like ? OR sys_user_real_name like ? ) "
- pars = utils.GetLikeKeywordPars(pars, keyword, 3)
- }
- if userId > 0 {
- condition += ` AND sys_user_id = ? `
- pars = append(pars, userId)
- }
- if classify != "" {
- condition += ` AND chart_classify_id IN (` + classify + `) `
- }
- total, err = data_manage.GetChartInfoCountByCondition(condition, pars)
- if err != nil {
- return
- }
- tmpList, tmpErr := data_manage.GetChartInfoListByCondition(condition, pars, startSize, pageSize)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- // 获取所有的图表分类
- firstClassifyList, tmpErr := data_manage.GetChartClassifyByParentId(0, 1, userId)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- firstClassifyNameMap := make(map[int]string)
- firstClassifyNameEnMap := make(map[int]string)
- for _, v := range firstClassifyList {
- firstClassifyNameMap[v.ChartClassifyId] = v.ChartClassifyName
- firstClassifyNameEnMap[v.ChartClassifyId] = v.ChartClassifyNameEn
- }
- secondClassList, tmpErr := data_manage.GetChartClassifyAll(1, userId)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- secondClassifyNameMap := make(map[int]string)
- secondClassifyNameEnMap := make(map[int]string)
- for _, v := range secondClassList {
- firstName := firstClassifyNameMap[v.ParentId]
- firstNameEn := firstClassifyNameEnMap[v.ParentId]
- if firstName != `` {
- firstName = firstName + " / "
- }
- if firstNameEn != `` {
- firstNameEn = firstNameEn + " / "
- }
- secondClassifyNameMap[v.ChartClassifyId] = firstName + v.ChartClassifyName
- secondClassifyNameEnMap[v.ChartClassifyId] = firstNameEn + v.ChartClassifyNameEn
- }
- for _, v := range tmpList {
- list = append(list, data_manage.MoveEdbChartList{
- DataId: strconv.Itoa(v.ChartInfoId),
- Name: v.ChartName,
- ClassifyName: secondClassifyNameMap[v.ChartClassifyId],
- NameEn: v.ChartNameEn,
- ClassifyNameEn: secondClassifyNameEnMap[v.ChartClassifyId],
- CreateUserId: v.SysUserId,
- CreateUserName: v.SysUserRealName,
- })
- }
- case 6: //ETA表格
- if keyword != `` {
- condition += " AND (excel_name like ? OR sys_user_real_name like ? ) "
- pars = utils.GetLikeKeywordPars(pars, keyword, 2)
- }
- if userId > 0 {
- condition += ` AND sys_user_id = ? `
- pars = append(pars, userId)
- }
- if classify != "" {
- condition += ` AND excel_classify_id IN (` + classify + `) `
- }
- condition += " AND source = ? "
- pars = append(pars, subSource)
- if subSource == utils.BALANCE_TABLE {
- condition += " AND parent_id = 0 AND balance_type = 0 "
- }
- total, err = excel.GetExcelInfoCountByCondition(condition, pars)
- if err != nil {
- return
- }
- tmpList, tmpErr := excel.GetNoContentExcelInfoListByCondition(condition, pars, startSize, pageSize)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- // 获取所有的图表分类
- firstClassifyList, tmpErr := excel.GetExcelClassifyByParentId(0, subSource)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- firstClassifyNameMap := make(map[int]string)
- for _, v := range firstClassifyList {
- firstClassifyNameMap[v.ExcelClassifyId] = v.ExcelClassifyName
- }
- secondClassList, tmpErr := excel.GetExcelClassifyBySource(subSource)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- secondClassifyNameMap := make(map[int]string)
- for _, v := range secondClassList {
- firstName := firstClassifyNameMap[v.ParentId]
- if firstName != `` {
- firstName = firstName + " / "
- }
- secondClassifyNameMap[v.ExcelClassifyId] = firstName + v.ExcelClassifyName
- }
- for _, v := range tmpList {
- list = append(list, data_manage.MoveEdbChartList{
- DataId: strconv.Itoa(v.ExcelInfoId),
- Name: v.ExcelClassifyName,
- ClassifyName: secondClassifyNameMap[v.ExcelClassifyId],
- NameEn: v.ExcelClassifyName,
- ClassifyNameEn: secondClassifyNameMap[v.ExcelClassifyId],
- CreateUserId: v.SysUserId,
- CreateUserName: v.SysUserRealName,
- })
- }
- default:
- return
- }
- return
- }
- // MoveEdbChart 转移指标/图表创建人
- // @param source 来源 :1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库 6:ETA表格;7:计算指标库
- func MoveEdbChart(source, subSource, oldUserId, newUserId int, isSelectAll bool, dataId, noDataId []string, keyword, classify string, opUserId int, opUserName string) (err error, errMsg string) {
- adminInfo, err := system.GetSysAdminById(newUserId)
- if err != nil {
- return
- }
- // 如果勾选全部数据,那么
- if isSelectAll {
- // 找出不要的指标ID列表
- noDataIdMap := make(map[string]string, 0)
- for _, v := range noDataId {
- noDataIdMap[v] = v
- }
- // 需要转义的指标/图表ID列表
- dataId = make([]string, 0)
- // 获取所有指标/图表
- list, _, tmpErr := GetMoveEdbChartList(source, subSource, oldUserId, keyword, classify, 0, 100000)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range list {
- if _, ok := noDataIdMap[v.DataId]; !ok {
- dataId = append(dataId, v.DataId)
- }
- }
- }
- // 操作记录
- dataPermissionMoveRecordList := make([]*data_manage_permission.DataPermissionMoveRecord, 0)
- uniqueCode := uuid.NewUUID().Hex32()
- title := `资产转移`
- content := `资产转入`
- switch source {
- case 1: //手工数据指标
- content += `(手工指标数据)`
- tmpList, tmpErr := models.GetEdbinfoListByCodeListByCodeIdList(dataId)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- if len(tmpList) > 0 {
- for _, v := range tmpList {
- //if v.UserId == newUserId {
- // errMsg = "新创建人不可和原创建人一致"
- // err = errors.New(errMsg)
- // return
- //}
- // 操作记录
- dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
- DataPermissionMoveRecordId: 0,
- Source: int32(source),
- SubSource: int32(subSource),
- OpUniqueCode: uniqueCode,
- DataId: v.TradeCode,
- DataCode: v.TradeCode,
- DataName: v.SecName,
- OriginalUserId: int32(v.UserId),
- OriginalUserName: v.UserName,
- NewUserId: int32(adminInfo.AdminId),
- NewUserName: adminInfo.RealName,
- CreateTime: time.Now(),
- })
- }
- // 修改创建人
- err = models.ModifyEdbinfoUserIdByCodeList(dataId, newUserId, adminInfo.RealName)
- // 如果移动成功了,需要记录该指标的操作记录
- if err == nil && len(tmpList) > 0 {
- go afterMoveManualEdb(tmpList, adminInfo, opUserId, opUserName)
- }
- }
- case 3, 4, utils.EdbPermissionSourceCalculate: //ETA指标库、ETA预测指标
- if source == 3 {
- content += `(数据查看)`
- }
- if source == 4 {
- content += `(衍生指标)`
- }
- if source == utils.EdbPermissionSourceCalculate {
- content += `(指标加工)`
- }
- edbInfoIdList := make([]int, 0)
- for _, id := range dataId {
- edbInfoId, tmpErr := strconv.Atoi(id)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- edbInfoIdList = append(edbInfoIdList, edbInfoId)
- }
- tmpList, tmpErr := data_manage.GetEdbInfoListByEdbInfoId(edbInfoIdList)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- if len(tmpList) > 0 {
- for _, v := range tmpList {
- //if v.SysUserId == newUserId {
- // errMsg = "新创建人不可和原创建人一致"
- // err = errors.New(errMsg)
- // return
- //}
- // 操作记录
- dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
- DataPermissionMoveRecordId: 0,
- Source: int32(source),
- SubSource: int32(subSource),
- OpUniqueCode: uniqueCode,
- DataId: fmt.Sprint(v.EdbInfoId),
- DataCode: v.EdbCode,
- DataName: v.EdbName,
- OriginalUserId: int32(v.SysUserId),
- OriginalUserName: v.SysUserRealName,
- NewUserId: int32(adminInfo.AdminId),
- NewUserName: adminInfo.RealName,
- CreateTime: time.Now(),
- })
- }
- // 修改创建人
- err = data_manage.ModifyEdbInfoUserIdByCodeList(dataId, adminInfo.AdminId, adminInfo.RealName)
- // 移除当前用户的不可操作权限
- {
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- for _, v := range dataId {
- edbInfoId, _ := strconv.Atoi(v)
- go obj.DeleteByEdbInfoIdAndAdminId(edbInfoId, adminInfo.AdminId)
- }
- }
- }
- case 5: //图库
- content += `(图库)`
- // 只展示eta图库
- subSource = utils.CHART_SOURCE_DEFAULT
- tmpList, tmpErr := data_manage.GetChartInfoListByChartIdList(dataId)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- if len(tmpList) > 0 {
- for _, v := range tmpList {
- //if v.SysUserId == newUserId {
- // errMsg = "新创建人不可和原创建人一致"
- // err = errors.New(errMsg)
- // return
- //}
- // 操作记录
- dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
- DataPermissionMoveRecordId: 0,
- Source: int32(source),
- SubSource: int32(subSource),
- OpUniqueCode: uniqueCode,
- DataId: fmt.Sprint(v.ChartInfoId),
- DataCode: fmt.Sprint(v.ChartInfoId),
- DataName: v.ChartName,
- OriginalUserId: int32(v.SysUserId),
- OriginalUserName: v.SysUserRealName,
- NewUserId: int32(adminInfo.AdminId),
- NewUserName: adminInfo.RealName,
- CreateTime: time.Now(),
- })
- }
- // 修改创建人
- err = data_manage.ModifyChartInfoUserIdByCodeList(dataId, adminInfo.AdminId, adminInfo.RealName)
- }
- case 6: // ETA表格
- content += `(表格)`
- tmpList, tmpErr := excel.GetNoContentExcelListByExcelInfoIdList(dataId)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- var customAnalysisIds []int
- if len(tmpList) > 0 {
- for _, v := range tmpList {
- //if v.SysUserId == newUserId {
- // errMsg = "新创建人不可和原创建人一致"
- // err = errors.New(errMsg)
- // return
- //}
- // 操作记录
- dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
- DataPermissionMoveRecordId: 0,
- Source: int32(source),
- SubSource: int32(subSource),
- OpUniqueCode: uniqueCode,
- DataId: fmt.Sprint(v.ExcelInfoId),
- DataCode: fmt.Sprint(v.ExcelInfoId),
- DataName: v.ExcelName,
- OriginalUserId: int32(v.SysUserId),
- OriginalUserName: v.SysUserRealName,
- NewUserId: int32(adminInfo.AdminId),
- NewUserName: adminInfo.RealName,
- CreateTime: time.Now(),
- })
- if v.Source == utils.CUSTOM_ANALYSIS_TABLE {
- customAnalysisIds = append(customAnalysisIds, v.ExcelInfoId)
- }
- }
- // 修改创建人
- err = excel.ModifyExcelInfoUserIdByCodeList(dataId, adminInfo.AdminId, adminInfo.RealName)
- if err != nil {
- return
- }
- // 由于自定义分析表分类私有化, 如果转移的是自定义分析表, 那么需要将excel转移至未分类下
- if len(customAnalysisIds) > 0 {
- err = MoveCustomAnalysisExcel2DefaultClassify(customAnalysisIds, adminInfo.AdminId, adminInfo.RealName)
- }
- }
- default:
- return
- }
- // 转移失败了那么就直接返回了
- if err != nil {
- return
- }
- // 添加资产转移的记录
- dataPermissionMessage := &data_manage_permission.DataPermissionMessage{
- DataPermissionMessageId: 0,
- SendUserId: int32(opUserId),
- ReceiveUserId: int32(adminInfo.AdminId),
- Content: title,
- Remark: content,
- OpType: 1,
- Source: int32(source),
- SubSource: int32(subSource),
- OpUniqueCode: uniqueCode,
- IsRead: 0,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- }
- tmpErr := data_manage_permission.AddDataPermissionMoveRecord(dataPermissionMoveRecordList, dataPermissionMessage)
- // 失败的话,日志记录
- if tmpErr != nil {
- // 序列化结构体为 JSON 数据
- recordListJsonBytes, tmpErr2 := json.Marshal(dataPermissionMoveRecordList)
- if tmpErr2 != nil {
- utils.FileLog.Error(fmt.Sprintf("添加资产转移的记录失败:%s;list转json失败:;操作记录:%+v;消息记录:%+v", tmpErr.Error(), dataPermissionMoveRecordList, dataPermissionMessage))
- return
- }
- // 序列化结构体为 JSON 数据
- messageJsonBytes, tmpErr2 := json.Marshal(dataPermissionMessage)
- if tmpErr2 != nil {
- utils.FileLog.Error(fmt.Sprintf("添加资产转移的记录失败:%s;message转json失败:;操作记录:%+v;消息记录:%+v", tmpErr.Error(), dataPermissionMoveRecordList, dataPermissionMessage))
- return
- }
- utils.FileLog.Error(fmt.Sprintf("添加资产转移的记录失败:%s;操作记录:%s;消息记录:%s", tmpErr.Error(), string(recordListJsonBytes), string(messageJsonBytes)))
- }
- return
- }
- // MoveAllEdbChart
- // @Description: 通过原创建人转移指标/图表创建人
- // @author: Roc
- // @datetime 2024-03-26 15:11:12
- // @param sourceList []int 1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库 6:ETA表格
- // @param oldUserId []int
- // @param userId int
- // @param opUserId int
- // @return err error
- // @return errMsg string
- func MoveAllEdbChart(sourceList, oldUserIdList []int, userId, opUserId int) (err error, errMsg string) {
- adminInfo, err := system.GetSysAdminById(userId)
- if err != nil {
- return
- }
- // 操作记录
- dataPermissionMoveRecordList := make([]*data_manage_permission.DataPermissionMoveRecord, 0)
- uniqueCode := uuid.NewUUID().Hex32()
- title := `资产转移`
- content := `资产转入`
- sourceStrList := make([]string, 0)
- var isMoveManual, isMoveMysteelChemical, isMoveEdb, isMovePredictEdb, isMoveChart, isMoveExcel bool
- var customAnalysisIds []int
- // 遍历需要转移的模块,1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库 6:ETA表格,并找出当前需要转移的资产
- for _, source := range sourceList {
- switch source {
- case 1: //手工数据指标
- sourceStrList = append(sourceStrList, "手工指标数据")
- tmpList, tmpErr := models.GetEdbinfoListByCodeListByUserId(oldUserIdList)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- if len(tmpList) > 0 {
- for _, v := range tmpList {
- // 操作记录
- dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
- DataPermissionMoveRecordId: 0,
- Source: int32(source),
- SubSource: 0,
- OpUniqueCode: uniqueCode,
- DataId: v.TradeCode,
- DataCode: v.TradeCode,
- DataName: v.SecName,
- OriginalUserId: int32(v.UserId),
- OriginalUserName: v.UserName,
- NewUserId: int32(adminInfo.AdminId),
- NewUserName: adminInfo.RealName,
- CreateTime: time.Now(),
- })
- }
- isMoveManual = true
- }
- case 3: //ETA指标库
- sourceStrList = append(sourceStrList, "ETA指标库")
- edbInfoType := 0
- tmpList, tmpErr := data_manage.GetEdbInfoListByUserId(oldUserIdList, edbInfoType)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- if len(tmpList) > 0 {
- for _, v := range tmpList {
- // 操作记录
- dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
- DataPermissionMoveRecordId: 0,
- Source: int32(source),
- SubSource: int32(edbInfoType),
- OpUniqueCode: uniqueCode,
- DataId: fmt.Sprint(v.EdbInfoId),
- DataCode: v.EdbCode,
- DataName: v.EdbName,
- OriginalUserId: int32(v.SysUserId),
- OriginalUserName: v.SysUserRealName,
- NewUserId: int32(adminInfo.AdminId),
- NewUserName: adminInfo.RealName,
- CreateTime: time.Now(),
- })
- }
- isMoveEdb = true
- }
- case 4: //ETA预测指标
- sourceStrList = append(sourceStrList, "ETA预测指标")
- edbInfoType := 1
- tmpList, tmpErr := data_manage.GetEdbInfoListByUserId(oldUserIdList, edbInfoType)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- if len(tmpList) > 0 {
- for _, v := range tmpList {
- // 操作记录
- dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
- DataPermissionMoveRecordId: 0,
- Source: int32(source),
- SubSource: int32(edbInfoType),
- OpUniqueCode: uniqueCode,
- DataId: fmt.Sprint(v.EdbInfoId),
- DataCode: v.EdbCode,
- DataName: v.EdbName,
- OriginalUserId: int32(v.SysUserId),
- OriginalUserName: v.SysUserRealName,
- NewUserId: int32(adminInfo.AdminId),
- NewUserName: adminInfo.RealName,
- CreateTime: time.Now(),
- })
- }
- isMovePredictEdb = true
- }
- case 5: //ETA图库
- sourceStrList = append(sourceStrList, "ETA图库")
- // 只展示eta图库
- subSource := utils.CHART_SOURCE_DEFAULT
- tmpList, tmpErr := data_manage.GetChartInfoListByUserId(oldUserIdList, subSource)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- if len(tmpList) > 0 {
- for _, v := range tmpList {
- // 操作记录
- dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
- DataPermissionMoveRecordId: 0,
- Source: int32(source),
- SubSource: int32(subSource),
- OpUniqueCode: uniqueCode,
- DataId: fmt.Sprint(v.ChartInfoId),
- DataCode: fmt.Sprint(v.ChartInfoId),
- DataName: v.ChartName,
- OriginalUserId: int32(v.SysUserId),
- OriginalUserName: v.SysUserRealName,
- NewUserId: int32(adminInfo.AdminId),
- NewUserName: adminInfo.RealName,
- CreateTime: time.Now(),
- })
- }
- isMoveChart = true
- }
- case 6: // ETA表格
- sourceStrList = append(sourceStrList, "ETA表格")
- tmpList, tmpErr := excel.GetNoContentExcelListByUserId(oldUserIdList)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- if len(tmpList) > 0 {
- for _, v := range tmpList {
- // 操作记录
- dataPermissionMoveRecordList = append(dataPermissionMoveRecordList, &data_manage_permission.DataPermissionMoveRecord{
- DataPermissionMoveRecordId: 0,
- Source: int32(source),
- SubSource: int32(v.Source),
- OpUniqueCode: uniqueCode,
- DataId: fmt.Sprint(v.ExcelInfoId),
- DataCode: fmt.Sprint(v.ExcelInfoId),
- DataName: v.ExcelName,
- OriginalUserId: int32(v.SysUserId),
- OriginalUserName: v.SysUserRealName,
- NewUserId: int32(adminInfo.AdminId),
- NewUserName: adminInfo.RealName,
- CreateTime: time.Now(),
- })
- if v.Source == utils.CUSTOM_ANALYSIS_TABLE {
- customAnalysisIds = append(customAnalysisIds, v.ExcelInfoId)
- }
- }
- isMoveExcel = true
- }
- default:
- }
- }
- // 修改创建人
- err = data_manage_permission.ModifyDataUserIdByOldUserId(oldUserIdList, adminInfo.AdminId, adminInfo.RealName, isMoveManual, isMoveMysteelChemical, isMoveEdb, isMovePredictEdb, isMoveChart, isMoveExcel)
- // 转移失败了那么就直接返回了
- if err != nil {
- return
- }
- // 由于自定义分析表分类私有化, 如果转移的含自定义分析表, 那么需要将excel转移至未分类下
- if len(customAnalysisIds) > 0 {
- err = MoveCustomAnalysisExcel2DefaultClassify(customAnalysisIds, adminInfo.AdminId, adminInfo.RealName)
- if err != nil {
- err = fmt.Errorf("MoveCustomAnalysisExcel2DefaultClassify, err: %v", err)
- return
- }
- }
- // 添加资产转移的记录
- content += fmt.Sprintf("(%s)", strings.Join(sourceStrList, ","))
- dataPermissionMessage := &data_manage_permission.DataPermissionMessage{
- DataPermissionMessageId: 0,
- SendUserId: int32(opUserId),
- ReceiveUserId: int32(adminInfo.AdminId),
- Content: title,
- Remark: content,
- OpType: 2,
- OpUniqueCode: uniqueCode,
- IsRead: 0,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- }
- tmpErr := data_manage_permission.AddDataPermissionMoveRecord(dataPermissionMoveRecordList, dataPermissionMessage)
- // 失败的话,日志记录
- if tmpErr != nil {
- // 序列化结构体为 JSON 数据
- recordListJsonBytes, tmpErr2 := json.Marshal(dataPermissionMoveRecordList)
- if tmpErr2 != nil {
- utils.FileLog.Error(fmt.Sprintf("添加资产转移的记录失败:%s;list转json失败:;操作记录:%+v;消息记录:%+v", tmpErr.Error(), dataPermissionMoveRecordList, dataPermissionMessage))
- return
- }
- // 序列化结构体为 JSON 数据
- messageJsonBytes, tmpErr2 := json.Marshal(dataPermissionMessage)
- if tmpErr2 != nil {
- utils.FileLog.Error(fmt.Sprintf("添加资产转移的记录失败:%s;message转json失败:;操作记录:%+v;消息记录:%+v", tmpErr.Error(), dataPermissionMoveRecordList, dataPermissionMessage))
- return
- }
- utils.FileLog.Error(fmt.Sprintf("添加资产转移的记录失败:%s;操作记录:%s;消息记录:%s", tmpErr.Error(), string(recordListJsonBytes), string(messageJsonBytes)))
- }
- return
- }
- // GetMoveEdbChartCount 获取待转移的指标/图表列表
- // @param userId 用户
- // @param countType 来源 :1:设置资产权限;2:设置数据权限
- func GetMoveEdbChartCount(userId, countType int) (sourceMap map[int]int, err error) {
- sourceMap = make(map[int]int)
- {
- // 手工数据指标
- var condition string
- var pars []interface{}
- if userId > 0 {
- condition += ` AND a.user_id = ? `
- pars = append(pars, userId)
- }
- total, tmpErr := models.GetEdbinfoListCount(condition, pars, "", 0)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- sourceMap[1] = total
- }
- {
- // 基础指标
- var condition string
- var pars []interface{}
- if userId > 0 {
- condition += ` AND sys_user_id = ? `
- pars = append(pars, userId)
- }
- condition += ` AND edb_info_type = ? AND edb_type = ? `
- pars = append(pars, 0, utils.EdbTypeBase)
- total, tmpErr := data_manage.GetEdbInfoByConditionCount(condition, pars)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- sourceMap[3] = total
- }
- {
- // ETA预测指标库
- var condition string
- var pars []interface{}
- if userId > 0 {
- condition += ` AND sys_user_id = ? `
- pars = append(pars, userId)
- }
- //ETA预测指标
- condition += ` AND edb_info_type = ? `
- pars = append(pars, 1)
- total, tmpErr := data_manage.GetEdbInfoByConditionCount(condition, pars)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- sourceMap[4] = total
- }
- {
- // 图库
- var condition string
- var pars []interface{}
- condition += ` AND source = ? `
- pars = append(pars, utils.CHART_SOURCE_DEFAULT)
- if userId > 0 {
- condition += ` AND sys_user_id = ? `
- pars = append(pars, userId)
- }
- total, tmpErr := data_manage.GetChartInfoCountByCondition(condition, pars)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- sourceMap[5] = total
- }
- {
- // ETA表格
- var condition string
- var pars []interface{}
- condition += ` AND is_delete = 0 `
- if userId > 0 {
- condition += ` AND sys_user_id = ? `
- pars = append(pars, userId)
- }
- switch countType {
- case 2:
- condition += ` AND source in (2,3,5) `
- default:
- condition += ` AND source in (2,3,4,5) `
- }
- // 平衡表
- condition += " AND (parent_id = 0 AND balance_type = 0)"
- total, tmpErr := excel.GetExcelInfoCountByCondition(condition, pars)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- sourceMap[6] = total
- }
- {
- // 计算指标
- var condition string
- var pars []interface{}
- if userId > 0 {
- condition += ` AND sys_user_id = ? `
- pars = append(pars, userId)
- }
- condition += ` AND edb_info_type = ? AND edb_type = ? `
- pars = append(pars, 0, utils.EdbTypeCalculate)
- total, tmpErr := data_manage.GetEdbInfoByConditionCount(condition, pars)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- sourceMap[7] = total
- }
- return
- }
- // afterMoveManualEdb
- // @Description: 手工数据移动后的操作
- // @author: Roc
- // @datetime 2024-08-01 13:55:59
- // @param tmpList []*models.Edbinfo
- // @param adminInfo *system.Admin
- // @param opUserId int
- // @param opUserName string
- func afterMoveManualEdb(tmpList []*models.Edbinfo, adminInfo *system.Admin, opUserId int, opUserName string) {
- recordList := make([]*models.EdbinfoOpRecord, 0)
- for _, tmpManualInfo := range tmpList {
- remark := fmt.Sprintf("数据资产由%s转移给%s", tmpManualInfo.UserName, adminInfo.RealName)
- recordList = append(recordList, &models.EdbinfoOpRecord{
- TradeCode: tmpManualInfo.TradeCode,
- Remark: remark,
- UserId: opUserId,
- UserName: opUserName,
- CreateTime: time.Now(),
- })
- }
- obj := models.EdbinfoOpRecord{}
- _ = obj.MulCreate(recordList)
- }
- // MoveCustomAnalysisExcel2DefaultClassify 移动表格至用户未分类目录下
- func MoveCustomAnalysisExcel2DefaultClassify(excelIds []int, adminId int, realName string) (err error) {
- if len(excelIds) == 0 {
- return
- }
- var moveClassifyId int
- // 查询默认分类
- cond := ` AND excel_classify_name = ? AND sys_user_id = ?`
- pars := make([]interface{}, 0)
- pars = append(pars, "未分类", adminId)
- classify, e := excel.GetExcelClassifyByCondition(cond, pars)
- if e != nil && !utils.IsErrNoRow(e) {
- err = fmt.Errorf("获取默认分类失败, %v", e)
- return
- }
- if e == nil && classify.ExcelClassifyId > 0 {
- moveClassifyId = classify.ExcelClassifyId
- }
- // 新增一个新的分类
- if classify == nil || classify.ExcelClassifyId <= 0 {
- classifyNew := &excel.ExcelClassify{
- ExcelClassifyName: "未分类",
- Source: utils.CUSTOM_ANALYSIS_TABLE,
- SysUserId: adminId,
- SysUserRealName: realName,
- Level: 1,
- UniqueCode: utils.MD5(utils.EXCEL_DATA_PREFIX + "_" + strconv.FormatInt(time.Now().UnixNano(), 10)),
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- }
- if _, e = excel.AddExcelClassify(classifyNew); e != nil {
- err = fmt.Errorf("新增默认分类失败, %v", e)
- return
- }
- moveClassifyId = classifyNew.ExcelClassifyId
- }
- if moveClassifyId <= 0 {
- err = fmt.Errorf("移动分类ID有误")
- return
- }
- // 更新表格分类ID
- if e = excel.UpdateExcelInfoClassifyIdByIds(moveClassifyId, excelIds); e != nil {
- err = fmt.Errorf("移动多表格分类失败, %v", e)
- return
- }
- return
- }
|