123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491 |
- package data_manage_permission
- import (
- "encoding/json"
- "eta/eta_api/models"
- "eta/eta_api/models/data_manage"
- "eta/eta_api/models/data_manage/data_manage_permission"
- "eta/eta_api/models/data_manage/excel"
- "eta/eta_api/models/system"
- "eta/eta_api/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/uuid"
- "strconv"
- "strings"
- "time"
- )
- // 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 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 2: //钢联化工数据库
- rootList, e := data_manage.GetBaseFromMysteelChemicalClassifyByParentId(0)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = e
- return
- }
- classifyAll, e := data_manage.GetAllBaseFromMysteelChemicalClassify()
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = e
- return
- }
- rootChildMap := make(map[int][]*data_manage.BaseFromMysteelChemicalClassifyItems)
- for _, v := range classifyAll {
- rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
- }
- nodeAll := make([]*data_manage.BaseFromMysteelChemicalClassifyItems, 0)
- for _, v := range rootList {
- if existItems, ok := rootChildMap[v.BaseFromMysteelChemicalClassifyId]; ok {
- v.Children = existItems
- } else {
- items := make([]*data_manage.BaseFromMysteelChemicalClassifyItems, 0)
- v.Children = items
- }
- nodeAll = append(nodeAll, v)
- }
- for _, v := range nodeAll {
- item := data_manage.EdbChartClassify{
- ClassifyId: v.BaseFromMysteelChemicalClassifyId,
- ClassifyName: v.ClassifyName,
- ParentId: v.ParentId,
- }
- for _, v2 := range v.Children {
- child := data_manage.EdbChartClassify{
- ClassifyId: v2.BaseFromMysteelChemicalClassifyId,
- ClassifyName: v2.ClassifyName,
- ParentId: v2.ParentId,
- }
- item.Child = append(item.Child, &child)
- }
- resp.List = append(resp.List, &item)
- }
- case 3:
- //ETA指标库
- //rootList, e := data_manage.GetEdbClassifyByParentId(0, 0)
- //if e != nil && e.Error() != utils.ErrNoRow() {
- // err = e
- // return
- //}
- // 考虑到后面可以会迭代到10层, 这里直接用递归处理
- classifyAll, e := data_manage.GetAllEdbClassifyByType(0)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = e
- return
- }
- resp.List = GetEdbMenuTreeRecursive(classifyAll, 0)
- case 4:
- //ETA预测指标
- // 考虑到后面可以会迭代到10层, 这里直接用递归
- classifyAll, e := data_manage.GetAllEdbClassifyByType(1)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = e
- return
- }
- resp.List = GetEdbMenuTreeRecursive(classifyAll, 0)
- case 5: //图库
- // 考虑到后面可以会迭代到10层, 这里直接用递归处理
- classifyAll, e := data_manage.GetAllChartClassifyItemsBySource(1)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = e
- return
- }
- resp.List = GetChartMenuTreeRecursive(classifyAll, 0)
- // 将数据加入缓存
- //if utils.Re == nil {
- // utils.Rc.Delete(key)
- //}
- case 6:
- // ETA表格
- // 考虑到后面可以会迭代到10层, 这里直接用递归处理
- classifyAll, e := excel.GetExcelClassifyBySourceOrderByLevel(subSource)
- if e != nil && e.Error() != utils.ErrNoRow() {
- 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 2: //钢联化工数据库
- if keyword != `` {
- condition += " AND (index_name like ? OR index_code 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 base_from_mysteel_chemical_classify_id IN (` + classify + `) `
- }
- total, err = data_manage.GetMysteelChemicalIndexCount(condition, pars)
- if err != nil {
- return
- }
- tmpList, tmpErr := data_manage.GetMysteelChemicalIndexList(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.BaseFromMysteelChemicalIndexId),
- Code: v.IndexCode,
- Name: v.IndexName,
- NameEn: v.IndexName,
- //ClassifyName: v.,
- CreateUserId: v.SysUserId,
- CreateUserName: v.SysUserRealName,
- })
- }
- case 3, 4: //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)
- 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)
- 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)
- 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表格
- 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 2: //钢联化工数据库
- content += `(钢联化工数据库)`
- tmpList, tmpErr := data_manage.GetMysteelChemicalIndexListByIndexId(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.BaseFromMysteelChemicalIndexId),
- DataCode: v.IndexCode,
- DataName: v.IndexName,
- OriginalUserId: int32(v.SysUserId),
- OriginalUserName: v.SysUserRealName,
- NewUserId: int32(adminInfo.AdminId),
- NewUserName: adminInfo.RealName,
- CreateTime: time.Now(),
- })
- }
- // 修改创建人
- err = data_manage.ModifyMysteelChemicalIndexUserIdByCodeList(dataId, adminInfo.AdminId, adminInfo.RealName)
- }
- case 3, 4: //ETA指标库、ETA预测指标
- if source == 3 {
- content += `(ETA指标库)`
- } else {
- content += `(ETA预测指标)`
- }
- tmpList, tmpErr := data_manage.GetEdbInfoListByEdbInfoId(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.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图库)`
- // 只展示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 += `(ETA表格)`
- 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
- }
- // MoveAllEdbChartOld
- // @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 MoveAllEdbChartOld(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)
- 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(),
- })
- }
- // 修改创建人
- err = models.ModifyEdbinfoUserIdByOldUserId(oldUserIdList, userId)
- }
- case 2: //钢联化工数据库
- sourceStrList = append(sourceStrList, "钢联化工数据库")
- tmpList, tmpErr := data_manage.GetMysteelChemicalIndexListByUserId(oldUserIdList)
- 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: 0,
- OpUniqueCode: uniqueCode,
- DataId: fmt.Sprint(v.BaseFromMysteelChemicalIndexId),
- DataCode: v.IndexCode,
- DataName: v.IndexName,
- OriginalUserId: int32(v.SysUserId),
- OriginalUserName: v.SysUserRealName,
- NewUserId: int32(adminInfo.AdminId),
- NewUserName: adminInfo.RealName,
- CreateTime: time.Now(),
- })
- }
- // 修改创建人
- err = data_manage.ModifyMysteelChemicalIndexUserIdByOldUserId(oldUserIdList, adminInfo.AdminId, adminInfo.RealName)
- }
- 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(),
- })
- }
- // 修改创建人
- err = data_manage.ModifyEdbInfoUserIdByOldUserId(oldUserIdList, edbInfoType, adminInfo.AdminId, adminInfo.RealName)
- }
- 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(),
- })
- }
- // 修改创建人
- err = data_manage.ModifyEdbInfoUserIdByOldUserId(oldUserIdList, edbInfoType, adminInfo.AdminId, adminInfo.RealName)
- }
- 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(),
- })
- }
- // 修改创建人
- err = data_manage.ModifyChartInfoUserIdByOldUserId(oldUserIdList, adminInfo.AdminId, adminInfo.RealName)
- }
- 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(),
- })
- }
- // 修改创建人
- err = excel.ModifyExcelInfoUserIdByOldUserId(oldUserIdList, adminInfo.AdminId, adminInfo.RealName)
- }
- default:
- }
- // 转移失败了那么就直接返回了
- if err != nil {
- 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
- }
- // 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 2: //钢联化工数据库
- sourceStrList = append(sourceStrList, "钢联化工数据库")
- tmpList, tmpErr := data_manage.GetMysteelChemicalIndexListByUserId(oldUserIdList)
- 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: 0,
- OpUniqueCode: uniqueCode,
- DataId: fmt.Sprint(v.BaseFromMysteelChemicalIndexId),
- DataCode: v.IndexCode,
- DataName: v.IndexName,
- OriginalUserId: int32(v.SysUserId),
- OriginalUserName: v.SysUserRealName,
- NewUserId: int32(adminInfo.AdminId),
- NewUserName: adminInfo.RealName,
- CreateTime: time.Now(),
- })
- }
- isMoveMysteelChemical = 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)
- }
- total, tmpErr := data_manage.GetMysteelChemicalIndexCount(condition, pars)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- sourceMap[2] = 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, 0)
- 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{}
- 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) `
- default:
- condition += ` AND source in (2,3,4) `
- }
- total, tmpErr := excel.GetExcelInfoCountByCondition(condition, pars)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- sourceMap[6] = 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 && e.Error() != utils.ErrNoRow() {
- err = fmt.Errorf("获取默认分类失败, %v", e)
- return
- }
- if classify != nil {
- moveClassifyId = classify.ExcelClassifyId
- }
- // 新增一个新的分类
- if classify == nil {
- 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
- }
|