12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103 |
- 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 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
- }
- // 考虑到后面可以会迭代到10层, 这里直接用递归处理
- classifyAll, e := data_manage.GetAllEdbClassifyByType(classifyType)
- if e != nil && !utils.IsErrNoRow(e) {
- err = e
- return
- }
- resp.List = GetEdbMenuTreeRecursive(classifyAll, 0)
- case 4:
- //ETA预测指标
- // 考虑到后面可以会迭代到10层, 这里直接用递归
- classifyAll, e := data_manage.GetAllEdbClassifyByType(1)
- 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)
- 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表格;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 += `(指标加工)`
- }
- 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图库
- 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
- }
|