Browse Source

添加平衡表按钮权限

xyxie 9 months ago
parent
commit
9b7ae63905

+ 39 - 6
controllers/data_manage/excel/excel_info.go

@@ -452,6 +452,7 @@ func (c *ExcelInfoController) List() {
 		classifyIdList := make([]int, 0)
 		for _, v := range list {
 			classifyIdList = append(classifyIdList, v.ExcelClassifyId)
+
 		}
 		classifyMap := make(map[int]*excel3.ExcelClassify)
 
@@ -475,11 +476,28 @@ func (c *ExcelInfoController) List() {
 			return
 		}
 
-		for _, v := range list {
+		for k, v := range list {
 			// 数据权限
 			if classifyInfo, ok := classifyMap[v.ExcelClassifyId]; ok {
 				v.HaveOperaAuth = data_manage_permission.CheckExcelPermissionByPermissionIdList(v.IsJoinPermission, classifyInfo.IsJoinPermission, v.ExcelInfoId, v.ExcelClassifyId, permissionEdbIdList, permissionClassifyIdList)
 			}
+			if v.Source == utils.BALANCE_TABLE {
+				//处理按钮权限和编辑状态
+				markStatus, err := services.UpdateExcelEditMark(v.ExcelInfoId, sysUser.AdminId, 2, sysUser.RealName)
+				if err != nil {
+					br.Msg = "查询标记状态失败"
+					br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
+					return
+				}
+				if markStatus.Status == 0 {
+					list[k].CanEdit = true
+				} else {
+					list[k].Editor = markStatus.Editor
+				}
+
+				// excel表格按钮权限
+				list[k].Button = excel2.GetBalanceExcelInfoOpButton(sysUser.AdminId, v.SysUserId, v.HaveOperaAuth, v.ExcelInfoId, v.SysUserId)
+			}
 		}
 
 	}
@@ -538,9 +556,18 @@ func (c *ExcelInfoController) Detail() {
 		br.ErrMsg = err.Error()
 		return
 	}
-
+	checkExcelInfoId := excelInfoId
+	if excelDetail.Source == utils.BALANCE_TABLE {
+		if excelDetail.BalanceType == 1 { // 平衡表静态表编辑状态以动态表的编辑状态为准
+			checkExcelInfoId = excelDetail.RelExcelInfoId
+		} else {
+			if excelDetail.ParentId > 0 { //  子表编辑状态以父表的编辑状态为准
+				checkExcelInfoId = excelDetail.ParentId
+			}
+		}
+	}
 	// 编辑状态
-	markStatus, err := services.UpdateExcelEditMark(excelInfoId, sysUser.AdminId, 2, sysUser.RealName)
+	markStatus, err := services.UpdateExcelEditMark(checkExcelInfoId, sysUser.AdminId, 2, sysUser.RealName)
 	if err != nil {
 		br.Msg = "查询标记状态失败"
 		br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
@@ -553,7 +580,9 @@ func (c *ExcelInfoController) Detail() {
 	}
 
 	// excel表格按钮权限
-	excelDetail.Button = excel2.GetExcelInfoOpButton(sysUser, excelDetail.SysUserId, excelDetail.Source, excelDetail.HaveOperaAuth)
+	if excelDetail.Source != utils.BALANCE_TABLE {
+		excelDetail.Button = excel2.GetExcelInfoOpButton(sysUser, excelDetail.SysUserId, excelDetail.Source, excelDetail.HaveOperaAuth)
+	}
 
 	br.Ret = 200
 	br.Success = true
@@ -1990,7 +2019,10 @@ func (c *ExcelInfoController) Refresh() {
 
 	// 操作权限校验
 	{
-		button := excel2.GetExcelInfoOpButton(sysUser, excelDetail.SysUserId, excelDetail.Source, excelDetail.HaveOperaAuth)
+		button := excelDetail.Button
+		if excelDetail.Source != utils.BALANCE_TABLE {
+			button = excel2.GetExcelInfoOpButton(sysUser, excelDetail.SysUserId, excelDetail.Source, excelDetail.HaveOperaAuth)
+		}
 		if !button.RefreshButton {
 			br.Msg = "无操作权限"
 			br.IsSendEmail = false
@@ -2025,7 +2057,8 @@ func (c *ExcelInfoController) Refresh() {
 	}
 
 	// 数据刷新-混合表格
-	if excelDetail.Source == utils.MIXED_TABLE {
+	if excelDetail.Source == utils.MIXED_TABLE || excelDetail.Source == utils.BALANCE_TABLE {
+		// todo 刷新动态表的所有子表中关联的指标数据
 		jsonByte, e := json.Marshal(excelDetail.TableData)
 		if e != nil {
 			br.Msg = "刷新失败"

+ 32 - 17
models/data_manage/excel/excel_info.go

@@ -41,23 +41,26 @@ func (excelInfo *ExcelInfo) Update(cols []string) (err error) {
 }
 
 type MyExcelInfoList struct {
-	ExcelInfoId        int       `orm:"column(excel_info_id);pk"`
-	Source             int       `description:"表格来源,1:excel插件的表格,2:自定义表格,默认:1"`
-	ExcelType          int       `description:"表格类型,1:指标列,2:日期列,默认:1"`
-	ExcelName          string    `description:"表格名称"`
-	UniqueCode         string    `description:"表格唯一编码"`
-	ExcelClassifyId    int       `description:"表格分类id"`
-	SysUserId          int       `description:"操作人id"`
-	SysUserRealName    string    `description:"操作人真实姓名"`
-	ExcelImage         string    `description:"表格图片"`
-	FileUrl            string    `description:"表格下载地址"`
-	Sort               int       `description:"排序字段,数字越小越排前面"`
-	ModifyTime         time.Time `description:"最近修改日期"`
-	CreateTime         time.Time `description:"创建日期"`
-	IsJoinPermission   int       `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
-	HaveOperaAuth      bool      `description:"是否有数据权限"`
-	UpdateUserId       int       `description:"更新人id"`
-	UpdateUserRealName string    `description:"更新人真实姓名"`
+	ExcelInfoId        int                   `orm:"column(excel_info_id);pk"`
+	Source             int                   `description:"表格来源,1:excel插件的表格,2:自定义表格,默认:1"`
+	ExcelType          int                   `description:"表格类型,1:指标列,2:日期列,默认:1"`
+	ExcelName          string                `description:"表格名称"`
+	UniqueCode         string                `description:"表格唯一编码"`
+	ExcelClassifyId    int                   `description:"表格分类id"`
+	SysUserId          int                   `description:"操作人id"`
+	SysUserRealName    string                `description:"操作人真实姓名"`
+	ExcelImage         string                `description:"表格图片"`
+	FileUrl            string                `description:"表格下载地址"`
+	Sort               int                   `description:"排序字段,数字越小越排前面"`
+	ModifyTime         time.Time             `description:"最近修改日期"`
+	CreateTime         time.Time             `description:"创建日期"`
+	IsJoinPermission   int                   `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
+	HaveOperaAuth      bool                  `description:"是否有数据权限"`
+	UpdateUserId       int                   `description:"更新人id"`
+	UpdateUserRealName string                `description:"更新人真实姓名"`
+	Button             ExcelInfoDetailButton `description:"操作权限"`
+	CanEdit            bool                  `description:"是否可编辑"`
+	Editor             string                `description:"编辑人"`
 }
 
 // AddExcelInfo 新增表格
@@ -682,3 +685,15 @@ func GetChildExcelInfoByParentId(parentId int) (items []*ExcelInfo, err error) {
 	_, err = o.Raw(sql, parentId).QueryRows(&items)
 	return
 }
+
+// ExcelInfoDetailButton 操作按钮
+type ExcelInfoDetailButton struct {
+	RefreshButton    bool `description:"是否可刷新"`
+	CopyButton       bool `description:"是否可另存为"`
+	DownloadButton   bool `description:"是否可下载"`
+	OpButton         bool `description:"是否可编辑"`
+	DeleteButton     bool `description:"是否可删除"`
+	OpEdbButton      bool `description:"是否可生成指标"`
+	RefreshEdbButton bool `description:"是否可刷新指标"`
+	OpWorkerButton   bool `description:"是否修改协作人"`
+}

+ 26 - 36
models/data_manage/excel/response/excel_info.go

@@ -56,42 +56,32 @@ type TableDetailResp struct {
 
 // ExcelInfoDetail excel表格详情(前端使用)
 type ExcelInfoDetail struct {
-	ExcelInfoId        int                   `orm:"column(excel_info_id);pk"`
-	Source             int                   `description:"表格来源,1:excel插件的表格,2:自定义表格,默认:1"`
-	ExcelType          int                   `description:"表格类型,1:指标列,2:日期列,默认:1"`
-	ExcelName          string                `description:"表格名称"`
-	UniqueCode         string                `description:"表格唯一编码"`
-	ExcelClassifyId    int                   `description:"表格分类id"`
-	SysUserId          int                   `description:"操作人id"`
-	SysUserRealName    string                `description:"操作人真实姓名"`
-	Content            string                `description:"表格内容"`
-	ExcelImage         string                `description:"表格图片"`
-	FileUrl            string                `description:"表格下载地址"`
-	Sort               int                   `description:"排序字段,数字越小越排前面"`
-	IsDelete           int                   `description:"是否删除,0:未删除,1:已删除"`
-	ModifyTime         time.Time             `description:"最近修改日期"`
-	CreateTime         time.Time             `description:"创建日期"`
-	TableData          interface{}           `description:"表格内容"`
-	Button             ExcelInfoDetailButton `description:"操作权限"`
-	CanEdit            bool                  `description:"是否可编辑"`
-	Editor             string                `description:"编辑人"`
-	IsJoinPermission   int                   `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
-	HaveOperaAuth      bool                  `description:"是否有数据权限"`
-	ParentId           int                   `description:"表格的父级id"`
-	BalanceType        int                   `description:"平衡表类型:0 动态表,1静态表"`
-	UpdateUserId       int                   `description:"更新人id"`
-	UpdateUserRealName string                `description:"更新人真实姓名"`
-}
-
-// ExcelInfoDetailButton 操作按钮
-type ExcelInfoDetailButton struct {
-	RefreshButton    bool `description:"是否可刷新"`
-	CopyButton       bool `description:"是否可另存为"`
-	DownloadButton   bool `description:"是否可下载"`
-	OpButton         bool `description:"是否可编辑"`
-	DeleteButton     bool `description:"是否可删除"`
-	OpEdbButton      bool `description:"是否可生成指标"`
-	RefreshEdbButton bool `description:"是否可刷新指标"`
+	ExcelInfoId        int                          `orm:"column(excel_info_id);pk"`
+	Source             int                          `description:"表格来源,1:excel插件的表格,2:自定义表格,默认:1"`
+	ExcelType          int                          `description:"表格类型,1:指标列,2:日期列,默认:1"`
+	ExcelName          string                       `description:"表格名称"`
+	UniqueCode         string                       `description:"表格唯一编码"`
+	ExcelClassifyId    int                          `description:"表格分类id"`
+	SysUserId          int                          `description:"操作人id"`
+	SysUserRealName    string                       `description:"操作人真实姓名"`
+	Content            string                       `description:"表格内容"`
+	ExcelImage         string                       `description:"表格图片"`
+	FileUrl            string                       `description:"表格下载地址"`
+	Sort               int                          `description:"排序字段,数字越小越排前面"`
+	IsDelete           int                          `description:"是否删除,0:未删除,1:已删除"`
+	ModifyTime         time.Time                    `description:"最近修改日期"`
+	CreateTime         time.Time                    `description:"创建日期"`
+	TableData          interface{}                  `description:"表格内容"`
+	Button             excel2.ExcelInfoDetailButton `description:"操作权限"`
+	CanEdit            bool                         `description:"是否可编辑"`
+	Editor             string                       `description:"编辑人"`
+	IsJoinPermission   int                          `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
+	HaveOperaAuth      bool                         `description:"是否有数据权限"`
+	ParentId           int                          `description:"表格的父级id"`
+	BalanceType        int                          `description:"平衡表类型:0 动态表,1静态表"`
+	UpdateUserId       int                          `description:"更新人id"`
+	UpdateUserRealName string                       `description:"更新人真实姓名"`
+	RelExcelInfoId     int                          `description:"平衡表里静态表关联的动态表excel id"`
 }
 
 type BalanceChildTableResp struct {

+ 17 - 17
models/data_manage/excel/response/sheet.go

@@ -14,21 +14,21 @@ type FindExcelInfoResp struct {
 
 // FindExcelInfo excel的数据详情
 type FindExcelInfo struct {
-	ExcelInfoId     int                   `orm:"column(excel_info_id);pk"`
-	Source          int                   `description:"表格来源,1:excel插件的表格,2:自定义表格,默认:1"`
-	ExcelType       int                   `description:"表格类型,1:指标列,2:日期列,默认:1"`
-	ExcelName       string                `description:"表格名称"`
-	UniqueCode      string                `description:"表格唯一编码"`
-	ExcelClassifyId int                   `description:"表格分类id"`
-	SysUserId       int                   `description:"操作人id"`
-	SysUserRealName string                `description:"操作人真实姓名"`
-	ExcelImage      string                `description:"表格图片"`
-	FileUrl         string                `description:"表格下载地址"`
-	Sort            int                   `description:"排序字段,数字越小越排前面"`
-	ModifyTime      time.Time             `description:"最近修改日期"`
-	CreateTime      time.Time             `description:"创建日期"`
-	Button          ExcelInfoDetailButton `description:"操作权限"`
-	CanEdit         bool                  `description:"是否可编辑"`
-	Editor          string                `description:"编辑人"`
-	HaveOperaAuth   bool                  `description:"是否有数据权限,默认:false"`
+	ExcelInfoId     int                         `orm:"column(excel_info_id);pk"`
+	Source          int                         `description:"表格来源,1:excel插件的表格,2:自定义表格,默认:1"`
+	ExcelType       int                         `description:"表格类型,1:指标列,2:日期列,默认:1"`
+	ExcelName       string                      `description:"表格名称"`
+	UniqueCode      string                      `description:"表格唯一编码"`
+	ExcelClassifyId int                         `description:"表格分类id"`
+	SysUserId       int                         `description:"操作人id"`
+	SysUserRealName string                      `description:"操作人真实姓名"`
+	ExcelImage      string                      `description:"表格图片"`
+	FileUrl         string                      `description:"表格下载地址"`
+	Sort            int                         `description:"排序字段,数字越小越排前面"`
+	ModifyTime      time.Time                   `description:"最近修改日期"`
+	CreateTime      time.Time                   `description:"创建日期"`
+	Button          excel.ExcelInfoDetailButton `description:"操作权限"`
+	CanEdit         bool                        `description:"是否可编辑"`
+	Editor          string                      `description:"编辑人"`
+	HaveOperaAuth   bool                        `description:"是否有数据权限,默认:false"`
 }

+ 1 - 1
services/data/data_manage_permission/data_move.go

@@ -416,7 +416,7 @@ func GetMoveEdbChartList(source, subSource, userId int, keyword, classify string
 		pars = append(pars, subSource)
 
 		if source == utils.BALANCE_TABLE {
-			condition += " AND parent_id = 0 "
+			condition += " AND parent_id = 0 AND balance_type = 0 "
 		}
 
 		total, err = excel.GetExcelInfoCountByCondition(condition, pars)

+ 56 - 3
services/data/excel/excel_info.go

@@ -55,8 +55,27 @@ func GetExcelDetailInfoByUnicode(unicode string, sysUserId int) (excelDetail res
 }
 
 func formatExcelInfo2Detail(excelInfo *excel.ExcelInfo, sysUserId int) (excelDetail response.ExcelInfoDetail, errMsg string, err error) {
+	checkExcelInfo := excelInfo
+	if excelInfo.Source == utils.BALANCE_TABLE {
+		checkExcelInfoId := excelInfo.ExcelInfoId
+		if excelInfo.BalanceType == 1 {
+			checkExcelInfoId = excelInfo.RelExcelInfoId
+		} else {
+			if excelInfo.ParentId > 0 {
+				checkExcelInfoId = excelInfo.ParentId
+			}
+		}
+		if checkExcelInfoId != excelInfo.ExcelInfoId {
+			checkExcelInfo, err = excel.GetExcelInfoById(excelInfo.ExcelInfoId)
+			if err != nil {
+				errMsg = "获取平衡表格信息失败"
+				err = errors.New("获取平衡表格信息失败,Err:" + err.Error())
+				return
+			}
+		}
+	}
 	// 数据权限
-	haveOperaAuth, err := data_manage_permission.CheckExcelPermissionByExcelInfoId(excelInfo.ExcelInfoId, excelInfo.ExcelClassifyId, excelInfo.IsJoinPermission, sysUserId)
+	haveOperaAuth, err := data_manage_permission.CheckExcelPermissionByExcelInfoId(checkExcelInfo.ExcelInfoId, checkExcelInfo.ExcelClassifyId, checkExcelInfo.IsJoinPermission, sysUserId)
 	if err != nil {
 		err = errors.New("获取表格权限信息失败,Err" + err.Error())
 		return
@@ -84,6 +103,7 @@ func formatExcelInfo2Detail(excelInfo *excel.ExcelInfo, sysUserId int) (excelDet
 		BalanceType:        excelInfo.BalanceType,
 		UpdateUserId:       excelInfo.UpdateUserId,
 		UpdateUserRealName: excelInfo.UpdateUserRealName,
+		RelExcelInfoId:     excelInfo.RelExcelInfoId,
 	}
 
 	// 无权限,不需要返回数据
@@ -157,11 +177,14 @@ func formatExcelInfo2Detail(excelInfo *excel.ExcelInfo, sysUserId int) (excelDet
 		result.Data = newData
 		excelDetail.TableData = result
 	}
+	if excelDetail.Source == utils.BALANCE_TABLE {
+		excelDetail.Button = GetBalanceExcelInfoOpButton(sysUserId, excelDetail.SysUserId, excelDetail.HaveOperaAuth, checkExcelInfo.ExcelInfoId, checkExcelInfo.SysUserId)
+	}
 	return
 }
 
 // GetExcelInfoOpButton 获取ETA表格的操作权限
-func GetExcelInfoOpButton(sysUser *system.Admin, belongUserId, source int, haveOperaAuth bool) (button response.ExcelInfoDetailButton) {
+func GetExcelInfoOpButton(sysUser *system.Admin, belongUserId, source int, haveOperaAuth bool) (button excel.ExcelInfoDetailButton) {
 	// 如果没有数据权限,那么直接返回
 	if !haveOperaAuth {
 		return
@@ -187,8 +210,38 @@ func GetExcelInfoOpButton(sysUser *system.Admin, belongUserId, source int, haveO
 		}
 	}
 
-	//todo 如果是平衡表,判断是否是协作人
+	return
+}
 
+// GetBalanceExcelInfoOpButton 获取ETA平衡表格的操作权限
+func GetBalanceExcelInfoOpButton(sysUserId, belongUserId int, haveOperaAuth bool, parentExcelInfoId, parentSysUserId int) (button excel.ExcelInfoDetailButton) {
+	// 如果没有数据权限,那么直接返回
+	if !haveOperaAuth {
+		return
+	}
+	//非管理员角色查看其他用户创建的表格,可刷新、另存为、下载表格;
+	button.RefreshButton = true
+	button.CopyButton = true
+	button.DownloadButton = true
+
+	belongUserId = parentSysUserId
+	if sysUserId == belongUserId {
+		button.OpEdbButton = true
+		button.RefreshEdbButton = true
+		button.OpWorkerButton = true
+	} else {
+		obj := new(excel.ExcelWorker)
+		workerList, err := obj.GetByExcelInfoId(parentExcelInfoId)
+		if err == nil {
+			for _, v := range workerList {
+				if v.SysUserId == sysUserId {
+					button.OpEdbButton = true
+					button.RefreshEdbButton = true
+					break
+				}
+			}
+		}
+	}
 	return
 }