|
@@ -4,13 +4,19 @@ import (
|
|
|
"encoding/json"
|
|
|
"eta/eta_api/controllers"
|
|
|
"eta/eta_api/models"
|
|
|
+ excelPermissionModel "eta/eta_api/models/data_manage/data_manage_permission"
|
|
|
excelModel "eta/eta_api/models/data_manage/excel"
|
|
|
"eta/eta_api/models/data_manage/excel/request"
|
|
|
"eta/eta_api/models/data_manage/excel/response"
|
|
|
+ "eta/eta_api/models/system"
|
|
|
"eta/eta_api/services"
|
|
|
"eta/eta_api/services/data/data_manage_permission"
|
|
|
"eta/eta_api/services/data/excel"
|
|
|
+ excel2 "eta/eta_api/services/data/excel"
|
|
|
"eta/eta_api/utils"
|
|
|
+ "fmt"
|
|
|
+ "github.com/rdlucklib/rdluck_tools/paging"
|
|
|
+ "sort"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
@@ -53,7 +59,7 @@ func (c *CustomAnalysisController) ExcelByName() {
|
|
|
|
|
|
excelName = utils.TrimLRStr(excelName)
|
|
|
// 获取数据详情
|
|
|
- excelDetail, err := excelModel.GetNoContentExcelInfoByName(excelName, utils.CUSTOM_ANALYSIS_TABLE)
|
|
|
+ excelDetail, err := excelModel.GetNoContentExcelInfoByName(excelName, utils.CUSTOM_ANALYSIS_TABLE, sysUser.AdminId)
|
|
|
if err != nil {
|
|
|
if err.Error() == utils.ErrNoRow() {
|
|
|
br.Ret = 200
|
|
@@ -173,6 +179,9 @@ func (c *CustomAnalysisController) Add() {
|
|
|
condition += " AND excel_name=? "
|
|
|
pars = append(pars, req.ExcelName)
|
|
|
|
|
|
+ condition += " AND sys_user_id = ? "
|
|
|
+ pars = append(pars, sysUser.AdminId)
|
|
|
+
|
|
|
count, err := excelModel.GetExcelInfoCountByCondition(condition, pars)
|
|
|
if err != nil {
|
|
|
br.Msg = "判断表格名称是否存在失败"
|
|
@@ -413,12 +422,25 @@ func (c *CustomAnalysisController) BaseExcelDetail() {
|
|
|
}
|
|
|
|
|
|
// 数据权限
|
|
|
- haveOperaAuth, err := data_manage_permission.CheckExcelPermissionByExcelInfoId(excelDetail.ExcelInfoId, excelDetail.ExcelClassifyId, excelDetail.IsJoinPermission, c.SysUser.AdminId)
|
|
|
- if err != nil {
|
|
|
- br.Msg = "获取ETA表格失败"
|
|
|
- br.ErrMsg = "获取ETA表格权限失败,Err:" + err.Error()
|
|
|
+ //haveOperaAuth, err := data_manage_permission.CheckExcelPermissionByExcelInfoId(excelDetail.ExcelInfoId, excelDetail.ExcelClassifyId, excelDetail.IsJoinPermission, c.SysUser.AdminId)
|
|
|
+ //if err != nil {
|
|
|
+ // br.Msg = "获取ETA表格失败"
|
|
|
+ // br.ErrMsg = "获取ETA表格权限失败,Err:" + err.Error()
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+
|
|
|
+ // 自定义分析权限与其他表格略有差别...
|
|
|
+ permissions, e := excelPermissionModel.GetExcelPermissionByExcelIdAndUserId(excelDetail.ExcelInfoId, sysUser.AdminId)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = fmt.Sprintf("获取表格权限失败, %v", e)
|
|
|
return
|
|
|
}
|
|
|
+ var permissionType []int
|
|
|
+ for _, v := range permissions {
|
|
|
+ permissionType = append(permissionType, v.PermissionType)
|
|
|
+ }
|
|
|
+ opButton := excel.GetCustomAnalysisOpButton(sysUser, excelDetail.SysUserId, permissionType)
|
|
|
|
|
|
resp.IsFind = true
|
|
|
resp.ExcelInfo = response.FindExcelInfo{
|
|
@@ -435,7 +457,7 @@ func (c *CustomAnalysisController) BaseExcelDetail() {
|
|
|
Sort: excelDetail.Sort,
|
|
|
ModifyTime: excelDetail.ModifyTime,
|
|
|
CreateTime: excelDetail.CreateTime,
|
|
|
- Button: excel.GetExcelInfoOpButton(sysUser, excelDetail.SysUserId, excelDetail.Source, haveOperaAuth),
|
|
|
+ Button: opButton,
|
|
|
HaveOperaAuth: true,
|
|
|
}
|
|
|
if markStatus.Status == 0 {
|
|
@@ -443,6 +465,7 @@ func (c *CustomAnalysisController) BaseExcelDetail() {
|
|
|
} else {
|
|
|
resp.ExcelInfo.Editor = markStatus.Editor
|
|
|
}
|
|
|
+
|
|
|
if excelDetail != nil {
|
|
|
sheetList, err := excelModel.GetAllSheetItemList(excelDetail.ExcelInfoId)
|
|
|
if err != nil {
|
|
@@ -607,3 +630,525 @@ func (c *CustomAnalysisController) ExcelDataList() {
|
|
|
br.Msg = "获取成功"
|
|
|
br.Data = sheetList
|
|
|
}
|
|
|
+
|
|
|
+// ClassifyList
|
|
|
+// @Title 分类列表
|
|
|
+// @Description 分类列表
|
|
|
+// @Param IsShare query bool false "是否共享表格: true-是; false-否(默认)"
|
|
|
+// @Success 200 {object} response.ExcelClassifyListResp
|
|
|
+// @router /excel_classify/list [get]
|
|
|
+func (c *CustomAnalysisController) ClassifyList() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ if br.ErrMsg == "" {
|
|
|
+ br.IsSendEmail = false
|
|
|
+ }
|
|
|
+ c.Data["json"] = br
|
|
|
+ c.ServeJSON()
|
|
|
+ }()
|
|
|
+ sysUser := c.SysUser
|
|
|
+ if sysUser == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ source := utils.CUSTOM_ANALYSIS_TABLE
|
|
|
+ isShare, _ := c.GetBool("IsShare")
|
|
|
+
|
|
|
+ resp := new(response.ExcelClassifyListResp)
|
|
|
+
|
|
|
+ // 查询我分享的/分享给我的表格
|
|
|
+ excels, e := excelPermissionModel.GetAdminAuthExcelInfoPermission(source, sysUser.AdminId, "")
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = fmt.Sprintf("获取我分享的/分享给我的表格失败, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ hasShareMap := make(map[int]bool) // 是否已分享标记
|
|
|
+ for _, v := range excels {
|
|
|
+ if v.CreateUserId == sysUser.AdminId {
|
|
|
+ hasShareMap[int(v.ExcelInfoId)] = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 共享
|
|
|
+ if isShare {
|
|
|
+ shareExcel := new(excelModel.ExcelClassifyItems)
|
|
|
+ shareExcel.ExcelClassifyId = excelModel.CustomAnalysisMenuShareId
|
|
|
+ shareExcel.ExcelClassifyName = "我共享的"
|
|
|
+ shareExcel.Level = 1
|
|
|
+ shareExcel.Sort = 1
|
|
|
+ shareExcel.UniqueCode = fmt.Sprintf("SHARE%d", shareExcel.ExcelClassifyId)
|
|
|
+ shareExcel.HaveOperaAuth = true
|
|
|
+ shareExcel.Children = make([]*excelModel.ExcelClassifyItems, 0)
|
|
|
+
|
|
|
+ sharedExcel := new(excelModel.ExcelClassifyItems)
|
|
|
+ sharedExcel.ExcelClassifyId = excelModel.CustomAnalysisMenuSharedId
|
|
|
+ sharedExcel.ExcelClassifyName = "收到共享"
|
|
|
+ sharedExcel.Level = 1
|
|
|
+ sharedExcel.Sort = 2
|
|
|
+ sharedExcel.UniqueCode = fmt.Sprintf("SHARED%d", sharedExcel.ExcelClassifyId)
|
|
|
+ sharedExcel.HaveOperaAuth = true
|
|
|
+ sharedExcel.Children = make([]*excelModel.ExcelClassifyItems, 0)
|
|
|
+
|
|
|
+ // 收到共享细分目录
|
|
|
+ sharedUserClassify := make(map[int]*excelModel.ExcelClassifyItems)
|
|
|
+ adminIdName := make(map[int]string)
|
|
|
+ {
|
|
|
+ adminOb := new(system.Admin)
|
|
|
+ adminList, e := adminOb.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = fmt.Sprintf("获取用户列表失败, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range adminList {
|
|
|
+ adminIdName[v.AdminId] = v.RealName
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sortUser := make([]int, 0) // 分享人目录排序
|
|
|
+ shareExists := make(map[int]bool)
|
|
|
+ for _, v := range excels {
|
|
|
+ item := new(excelModel.ExcelClassifyItems)
|
|
|
+ item.ExcelInfoId = int(v.ExcelInfoId)
|
|
|
+ item.ExcelClassifyName = v.ExcelName
|
|
|
+ item.UniqueCode = v.UniqueCode
|
|
|
+ item.HaveOperaAuth = true
|
|
|
+ item.HasShare = hasShareMap[int(v.ExcelInfoId)]
|
|
|
+ // 我共享的
|
|
|
+ if v.CreateUserId == sysUser.AdminId && !shareExists[int(v.ExcelInfoId)] {
|
|
|
+ shareExists[int(v.ExcelInfoId)] = true
|
|
|
+ item.Level = 2
|
|
|
+ item.ParentId = shareExcel.ExcelClassifyId
|
|
|
+ item.ShowShareBtn = true
|
|
|
+ shareExcel.Children = append(shareExcel.Children, item)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ // 收到共享
|
|
|
+ if int(v.SysUserId) == sysUser.AdminId {
|
|
|
+ if adminIdName[v.CreateUserId] == "" {
|
|
|
+ // 分享人用户不存在, 那么不显示该分类
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if !utils.InArrayByInt(sortUser, v.CreateUserId) {
|
|
|
+ sortUser = append(sortUser, v.CreateUserId)
|
|
|
+ }
|
|
|
+ if sharedUserClassify[v.CreateUserId] == nil {
|
|
|
+ us := new(excelModel.ExcelClassifyItems)
|
|
|
+ us.ExcelClassifyId = v.CreateUserId // 用户ID作为分类ID
|
|
|
+ us.ExcelClassifyName = fmt.Sprintf("%s的表格", adminIdName[v.CreateUserId])
|
|
|
+ us.Level = 2
|
|
|
+ us.UniqueCode = fmt.Sprintf("%d-%d", sharedExcel.ExcelClassifyId, v.CreateUserId)
|
|
|
+ us.HaveOperaAuth = true
|
|
|
+ us.ShowShareBtn = false
|
|
|
+ us.Children = make([]*excelModel.ExcelClassifyItems, 0)
|
|
|
+ sharedUserClassify[v.CreateUserId] = us
|
|
|
+ }
|
|
|
+ item.Level = 3
|
|
|
+ item.ParentId = sharedUserClassify[v.CreateUserId].ExcelClassifyId
|
|
|
+ sharedUserClassify[v.CreateUserId].Children = append(sharedUserClassify[v.CreateUserId].Children, item)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 按照分享人第一次分享时间降序=_=!, 查询的时候是升序, 这里反过来
|
|
|
+ for i, j := 0, len(sortUser)-1; i < j; i, j = i+1, j-1 {
|
|
|
+ sortUser[i], sortUser[j] = sortUser[j], sortUser[i]
|
|
|
+ }
|
|
|
+ for _, v := range sortUser {
|
|
|
+ if sharedUserClassify[v] != nil {
|
|
|
+ sharedExcel.Children = append(sharedExcel.Children, sharedUserClassify[v])
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ resp.AllNodes = make([]*excelModel.ExcelClassifyItems, 0)
|
|
|
+ resp.AllNodes = append(resp.AllNodes, shareExcel, sharedExcel)
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+ br.Data = resp
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 我的表格
|
|
|
+ classifyList, err := excelModel.GetAdminExcelClassifyBySource(source, sysUser.AdminId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取数据失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ classifyMap := make(map[int]*excelModel.ExcelClassifyItems)
|
|
|
+ for _, v := range classifyList {
|
|
|
+ v.HaveOperaAuth = true
|
|
|
+ classifyMap[v.ExcelClassifyId] = v
|
|
|
+ }
|
|
|
+ allExcelInfo, err := excelModel.GetNoContentExcelInfoAll(source, sysUser.AdminId)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取表格信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ excelInfoMap := make(map[int][]*excelModel.ExcelClassifyItems)
|
|
|
+ for _, v := range allExcelInfo {
|
|
|
+ v.HaveOperaAuth = true
|
|
|
+ v.ShowShareBtn = true
|
|
|
+ v.HasShare = hasShareMap[v.ExcelInfoId]
|
|
|
+ excelInfoMap[v.ExcelClassifyId] = append(excelInfoMap[v.ExcelClassifyId], v)
|
|
|
+ }
|
|
|
+
|
|
|
+ classifyListMap := make(map[int][]*excelModel.ExcelClassifyItems)
|
|
|
+ for _, v := range classifyList {
|
|
|
+ if v.ParentId > 0 {
|
|
|
+ classifyListMap[v.ParentId] = append(classifyListMap[v.ParentId], v)
|
|
|
+ }
|
|
|
+ if existItems, ok := excelInfoMap[v.ExcelClassifyId]; ok {
|
|
|
+ v.Children = existItems
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for key, classify := range classifyList {
|
|
|
+ subList, ok := classifyListMap[classify.ExcelClassifyId]
|
|
|
+ if ok {
|
|
|
+ classifyList[key].Children = append(classifyList[key].Children, subList...)
|
|
|
+ sort.Slice(classifyList[key].Children, func(i, j int) bool {
|
|
|
+ return excelModel.ExcelClassifyItemBySort(classifyList[key].Children[i], classifyList[key].Children[j])
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ nodeAll := make([]*excelModel.ExcelClassifyItems, 0)
|
|
|
+ for _, v := range classifyList {
|
|
|
+ if v.ParentId == 0 {
|
|
|
+ sort.Slice(v.Children, func(i, j int) bool {
|
|
|
+ return excelModel.ExcelClassifyItemBySort(v.Children[i], v.Children[j])
|
|
|
+ })
|
|
|
+ nodeAll = append(nodeAll, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ resp.AllNodes = nodeAll
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+ br.Data = resp
|
|
|
+}
|
|
|
+
|
|
|
+// List
|
|
|
+// @Title 自定义分析列表
|
|
|
+// @Description ETA表格列表接口
|
|
|
+// @Param PageSize query int true "每页数据条数"
|
|
|
+// @Param CurrentIndex query int true "当前页页码,从1开始"
|
|
|
+// @Param ExcelClassifyId query int true "分类id"
|
|
|
+// @Param Keyword query string true "搜索关键词"
|
|
|
+// @Param IsShare query bool false "是否共享表格: true-是; false-否(默认)"
|
|
|
+// @Success 200 {object} response.ExcelListResp
|
|
|
+// @router /excel/list [get]
|
|
|
+func (c *CustomAnalysisController) List() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ if br.ErrMsg == "" {
|
|
|
+ br.IsSendEmail = false
|
|
|
+ }
|
|
|
+ c.Data["json"] = br
|
|
|
+ c.ServeJSON()
|
|
|
+ }()
|
|
|
+ sysUser := c.SysUser
|
|
|
+ if sysUser == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ excelClassifyId, _ := c.GetInt("ExcelClassifyId")
|
|
|
+ pageSize, _ := c.GetInt("PageSize")
|
|
|
+ currentIndex, _ := c.GetInt("CurrentIndex")
|
|
|
+ keyword := c.GetString("Keyword")
|
|
|
+ keyword = strings.TrimSpace(keyword)
|
|
|
+ adminId := sysUser.AdminId
|
|
|
+ isShare, _ := c.GetBool("IsShare")
|
|
|
+ source := utils.CUSTOM_ANALYSIS_TABLE
|
|
|
+
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+ condition += " AND source = ?"
|
|
|
+ pars = append(pars, source)
|
|
|
+ // 共享的
|
|
|
+ //hasShareMap := make(map[int]bool)
|
|
|
+ if isShare {
|
|
|
+ if keyword != "" {
|
|
|
+ keyword = fmt.Sprint("%", keyword, "%")
|
|
|
+ }
|
|
|
+ // 查询我分享的/分享给我的表格
|
|
|
+ excels, e := excelPermissionModel.GetAdminAuthExcelInfoPermission(source, adminId, keyword)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = fmt.Sprintf("获取我分享的/分享给我的表格失败, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var excelIds, shareIds, sharedIds, userIds []int
|
|
|
+ for _, v := range excels {
|
|
|
+ id := int(v.ExcelInfoId)
|
|
|
+ // 无分类ID
|
|
|
+ if excelClassifyId <= 0 && !utils.InArrayByInt(excelIds, id) {
|
|
|
+ excelIds = append(excelIds, id)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ // 用户分类
|
|
|
+ if excelClassifyId == v.CreateUserId {
|
|
|
+ userIds = append(userIds, id)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ // 我共享的
|
|
|
+ if excelClassifyId == excelModel.CustomAnalysisMenuShareId && v.CreateUserId == sysUser.AdminId {
|
|
|
+ shareIds = append(shareIds, id)
|
|
|
+ //hasShareMap[id] = true
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ // 收到共享
|
|
|
+ if excelClassifyId == excelModel.CustomAnalysisMenuSharedId && int(v.SysUserId) == sysUser.AdminId {
|
|
|
+ sharedIds = append(sharedIds, id)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if excelClassifyId > 0 {
|
|
|
+ switch excelClassifyId {
|
|
|
+ case excelModel.CustomAnalysisMenuShareId: // 我共享的
|
|
|
+ excelIds = shareIds
|
|
|
+ case excelModel.CustomAnalysisMenuSharedId: // 收到共享
|
|
|
+ excelIds = sharedIds
|
|
|
+ default: // 用户目录
|
|
|
+ excelIds = userIds
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(excelIds) == 0 {
|
|
|
+ page := paging.GetPaging(currentIndex, pageSize, 0)
|
|
|
+ resp := response.ExcelListResp{
|
|
|
+ Paging: page,
|
|
|
+ List: make([]*excelModel.MyExcelInfoList, 0),
|
|
|
+ }
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+ br.Data = resp
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ condition += fmt.Sprintf(` AND excel_info_id IN (%s)`, utils.GetOrmInReplace(len(excelIds)))
|
|
|
+ pars = append(pars, excelIds)
|
|
|
+
|
|
|
+ } else {
|
|
|
+ condition += ` AND sys_user_id = ?`
|
|
|
+ pars = append(pars, adminId)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 筛选分类
|
|
|
+ if !isShare && excelClassifyId > 0 {
|
|
|
+ _, err := excelModel.GetExcelClassifyById(excelClassifyId)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取表格信息失败"
|
|
|
+ br.ErrMsg = "获取信息失败,GetExcelClassify,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ childClassify, e, _ := excel2.GetChildClassifyByClassifyId(excelClassifyId, source)
|
|
|
+ if e != nil && e.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取分类信息失败, GetEdbClassify,Err:" + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(childClassify) == 0 {
|
|
|
+ condition += " AND excel_classify_id = ? "
|
|
|
+ pars = append(pars, excelClassifyId)
|
|
|
+ } else {
|
|
|
+ classifyIds := []int{excelClassifyId}
|
|
|
+ for _, v := range childClassify {
|
|
|
+ classifyIds = append(classifyIds, v.ExcelClassifyId)
|
|
|
+ }
|
|
|
+ condition += fmt.Sprintf(` AND excel_classify_id IN (%s) `, utils.GetOrmInReplace(len(classifyIds)))
|
|
|
+ pars = append(pars, classifyIds)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if keyword != "" {
|
|
|
+ condition += ` AND (excel_name LIKE ?)`
|
|
|
+ pars = utils.GetLikeKeywordPars(pars, keyword, 1)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取表格信息
|
|
|
+ var total int
|
|
|
+ page := paging.GetPaging(currentIndex, pageSize, total)
|
|
|
+ var startSize int
|
|
|
+ if pageSize <= 0 {
|
|
|
+ pageSize = utils.PageSize20
|
|
|
+ }
|
|
|
+ if currentIndex <= 0 {
|
|
|
+ currentIndex = 1
|
|
|
+ }
|
|
|
+ startSize = paging.StartIndex(currentIndex, pageSize)
|
|
|
+ list, err := excelModel.GetNoContentExcelListByCondition(condition, pars, startSize, pageSize)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取表格信息失败"
|
|
|
+ br.ErrMsg = "获取表格信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range list {
|
|
|
+ v.HaveOperaAuth = true
|
|
|
+ //v.Button.CancelShareButton = hasShareMap[v.ExcelInfoId]
|
|
|
+ }
|
|
|
+
|
|
|
+ // 总数据量
|
|
|
+ dataCount, err := excelModel.GetExcelListCountByCondition(condition, pars)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取表格列表信息失败"
|
|
|
+ br.ErrMsg = "获取表格列表数据总数失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ page = paging.GetPaging(currentIndex, pageSize, dataCount)
|
|
|
+
|
|
|
+ resp := response.ExcelListResp{
|
|
|
+ Paging: page,
|
|
|
+ List: list,
|
|
|
+ }
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+ br.Data = resp
|
|
|
+}
|
|
|
+
|
|
|
+// Share
|
|
|
+// @Title 分享表格
|
|
|
+// @Description 分享表格
|
|
|
+// @Param request body request.ShareExcelInfoReq true "type json string"
|
|
|
+// @Success 200 string "操作成功"
|
|
|
+// @router /excel/share [post]
|
|
|
+func (c *CustomAnalysisController) Share() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ if br.ErrMsg != "" {
|
|
|
+ br.IsSendEmail = false
|
|
|
+ }
|
|
|
+ c.Data["json"] = br
|
|
|
+ c.ServeJSON()
|
|
|
+ }()
|
|
|
+ var req request.ShareExcelInfoReq
|
|
|
+ err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ sysUser := c.SysUser
|
|
|
+ if sysUser == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if req.ExcelInfoId <= 0 {
|
|
|
+ br.Msg = "请选择表格"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ excelInfo, e := excelModel.GetExcelInfoById(req.ExcelInfoId)
|
|
|
+ if e != nil {
|
|
|
+ if e.Error() == utils.ErrNoRow() {
|
|
|
+ br.Msg = "表格不存在, 请刷新页面"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = fmt.Sprintf("获取表格失败, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if excelInfo.SysUserId != sysUser.AdminId {
|
|
|
+ br.Msg = "无权操作"
|
|
|
+ br.ErrMsg = fmt.Sprintf("无权设置表格权限, ExcelInfoId: %d, SysAdminId: %d", req.ExcelInfoId, sysUser.AdminId)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ source := utils.CUSTOM_ANALYSIS_TABLE
|
|
|
+ newPermissions := make([]*excelPermissionModel.ExcelInfoPermission, 0)
|
|
|
+ for _, v := range req.ViewUserIds {
|
|
|
+ newPermissions = append(newPermissions, &excelPermissionModel.ExcelInfoPermission{
|
|
|
+ ExcelInfoId: int32(req.ExcelInfoId),
|
|
|
+ Source: int32(source),
|
|
|
+ SysUserId: int32(v),
|
|
|
+ CreateTime: time.Now().Local(),
|
|
|
+ ModifyTime: time.Now().Local(),
|
|
|
+ PermissionType: 1,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ for _, v := range req.EditUserIds {
|
|
|
+ newPermissions = append(newPermissions, &excelPermissionModel.ExcelInfoPermission{
|
|
|
+ ExcelInfoId: int32(req.ExcelInfoId),
|
|
|
+ Source: int32(source),
|
|
|
+ SysUserId: int32(v),
|
|
|
+ CreateTime: time.Now().Local(),
|
|
|
+ ModifyTime: time.Now().Local(),
|
|
|
+ PermissionType: 2,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if e := excelPermissionModel.ClearAndSetExcelInfoPermission(source, req.ExcelInfoId, newPermissions); e != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = fmt.Sprintf("设置表格权限失败, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "操作成功"
|
|
|
+}
|
|
|
+
|
|
|
+// ShareDetail
|
|
|
+// @Title 分享表格-详情
|
|
|
+// @Description 分享表格-详情
|
|
|
+// @Param ExcelInfoId query int true "表格ID"
|
|
|
+// @Success 200 {object} response.ShareExcelInfoDetail
|
|
|
+// @router /excel/share_detail [get]
|
|
|
+func (c *CustomAnalysisController) ShareDetail() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ if br.ErrMsg != "" {
|
|
|
+ br.IsSendEmail = false
|
|
|
+ }
|
|
|
+ c.Data["json"] = br
|
|
|
+ c.ServeJSON()
|
|
|
+ }()
|
|
|
+ sysUser := c.SysUser
|
|
|
+ if sysUser == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+ excelInfoId, _ := c.GetInt("ExcelInfoId")
|
|
|
+ if excelInfoId <= 0 {
|
|
|
+ br.Msg = "请选择表格"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ permissions, e := excelPermissionModel.GetExcelPermissionBySourceAndId(excelInfoId, utils.CUSTOM_ANALYSIS_TABLE)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = fmt.Sprintf("获取表格权限失败, %v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp := new(response.ShareExcelInfoDetail)
|
|
|
+ resp.ExcelInfoId = excelInfoId
|
|
|
+ for _, v := range permissions {
|
|
|
+ if v.PermissionType == 1 {
|
|
|
+ resp.ViewUserIds = append(resp.ViewUserIds, int(v.SysUserId))
|
|
|
+ }
|
|
|
+ if v.PermissionType == 2 {
|
|
|
+ resp.EditUserIds = append(resp.EditUserIds, int(v.SysUserId))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ br.Data = resp
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+}
|