Browse Source

Merge remote-tracking branch 'origin/debug' into debug

zwxi 8 months ago
parent
commit
7a74d7c748

+ 74 - 19
controllers/data_manage/base_from_ths_hf.go

@@ -1231,9 +1231,27 @@ func (this *BaseFromThsHfController) MultiOpt() {
 		br.Msg = "请选择刷新方式"
 		return
 	}
+	resp := new(data_manage.ThsHfIndexMultiOptResp)
 
-	// 批量移动
+	// 指标名称
 	indexOb := new(data_manage.BaseFromThsHfIndex)
+	indexMap := make(map[int]*data_manage.BaseFromThsHfIndex)
+	{
+		cond := fmt.Sprintf(" AND %s IN (%s)", indexOb.Cols().PrimaryId, utils.GetOrmInReplace(len(params.IndexIds)))
+		pars := make([]interface{}, 0)
+		pars = append(pars, params.IndexIds)
+		list, e := indexOb.GetItemsByCondition(cond, pars, []string{indexOb.Cols().PrimaryId, indexOb.Cols().IndexCode, indexOb.Cols().IndexName}, "")
+		if e != nil {
+			br.Msg = "删除失败"
+			br.ErrMsg = fmt.Sprintf("获取源指标列表失败, %v", e)
+			return
+		}
+		for _, v := range list {
+			indexMap[v.BaseFromThsHfIndexId] = v
+		}
+	}
+
+	// 批量移动
 	if params.OptType == 1 {
 		if e := indexOb.UpdateClassifyMulti(params.IndexIds, params.MoveClassifyId); e != nil {
 			br.Msg = "移动失败"
@@ -1244,37 +1262,73 @@ func (this *BaseFromThsHfController) MultiOpt() {
 
 	// 批量删除
 	if params.OptType == 2 {
-		// 校验是否被引用
-		edbMappingOb := new(data_manage.BaseFromEdbMapping)
+		// 被引用的指标需要提示出来, 未被引用的直接删除
+		usedIndexIds := make([]int, 0)
 		{
+			edbMappingOb := new(data_manage.BaseFromEdbMapping)
 			cond := fmt.Sprintf(" AND %s IN (%s)", edbMappingOb.Cols().BaseFromIndexId, utils.GetOrmInReplace(len(params.IndexIds)))
 			pars := make([]interface{}, 0)
 			pars = append(pars, params.IndexIds)
-			count, e := edbMappingOb.GetCountByCondition(cond, pars)
+			list, e := edbMappingOb.GetItemsByCondition(cond, pars, []string{}, "")
 			if e != nil {
 				br.Msg = "删除失败"
 				br.ErrMsg = fmt.Sprintf("获取源指标关联失败, %v", e)
 				return
 			}
-			if count > 0 {
-				br.Msg = "存在指标被引用, 不允许删除"
-				return
+			for _, v := range list {
+				if !utils.InArrayByInt(usedIndexIds, v.BaseFromIndexId) {
+					usedIndexIds = append(usedIndexIds, v.BaseFromIndexId)
+				}
 			}
 		}
 
-		if e := indexOb.MultiRemove(params.IndexIds); e != nil {
-			br.Msg = "删除失败"
-			br.ErrMsg = fmt.Sprintf("批量删除指标失败, %v", e)
-			return
+		// 可删除的指标
+		removeIndexIds := params.IndexIds
+		if len(usedIndexIds) > 0 {
+			removeIndexIds = utils.MinusInt(params.IndexIds, usedIndexIds)
+
+			// 标记不允许删除的
+			for _, v := range usedIndexIds {
+				t := indexMap[v]
+				if t == nil {
+					continue
+				}
+				resp.Fail = append(resp.Fail, &data_manage.ThsHfIndexBaseInfo{
+					IndexId:   v,
+					IndexCode: t.IndexCode,
+					IndexName: t.IndexName,
+				})
+			}
 		}
-		dataOb := new(data_manage.BaseFromThsHfData)
-		cond := fmt.Sprintf(" %s IN (%s)", dataOb.Cols().BaseFromThsHfIndexId, utils.GetOrmInReplace(len(params.IndexIds)))
-		pars := make([]interface{}, 0)
-		pars = append(pars, params.IndexIds)
-		if e := dataOb.RemoveByCondition(cond, pars); e != nil {
-			br.Msg = "删除失败"
-			br.ErrMsg = fmt.Sprintf("批量删除指标数据失败, %v", e)
-			return
+
+		if len(removeIndexIds) > 0 {
+			if e := indexOb.MultiRemove(removeIndexIds); e != nil {
+				br.Msg = "删除失败"
+				br.ErrMsg = fmt.Sprintf("批量删除指标失败, %v", e)
+				return
+			}
+			dataOb := new(data_manage.BaseFromThsHfData)
+			cond := fmt.Sprintf(" %s IN (%s)", dataOb.Cols().BaseFromThsHfIndexId, utils.GetOrmInReplace(len(removeIndexIds)))
+			pars := make([]interface{}, 0)
+			pars = append(pars, removeIndexIds)
+			if e := dataOb.RemoveByCondition(cond, pars); e != nil {
+				br.Msg = "删除失败"
+				br.ErrMsg = fmt.Sprintf("批量删除指标数据失败, %v", e)
+				return
+			}
+
+			// 标记删除成功的
+			for _, v := range removeIndexIds {
+				t := indexMap[v]
+				if t == nil {
+					continue
+				}
+				resp.Success = append(resp.Success, &data_manage.ThsHfIndexBaseInfo{
+					IndexId:   v,
+					IndexCode: t.IndexCode,
+					IndexName: t.IndexName,
+				})
+			}
 		}
 	}
 
@@ -1294,6 +1348,7 @@ func (this *BaseFromThsHfController) MultiOpt() {
 		}
 	}
 
+	br.Data = resp
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "操作成功"

+ 1 - 0
controllers/data_manage/edb_info_calculate.go

@@ -649,6 +649,7 @@ func (this *ChartInfoController) CalculateBatchSave() {
 		EdbInfoIdArr: req.EdbInfoIdArr,
 		Calendar:     req.Calendar,
 		Extra:        req.Extra,
+		EmptyType:    req.EmptyType,
 	}
 
 	// 调用指标库去更新

+ 543 - 5
controllers/data_manage/excel/custom_analysis.go

@@ -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"
@@ -413,12 +419,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 +454,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 +462,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 +627,521 @@ 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 _, 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 = "获取成功"
+}

+ 405 - 0
controllers/manual_edb.go

@@ -0,0 +1,405 @@
+package controllers
+
+import (
+	"eta/eta_api/models"
+	"eta/eta_api/models/data_manage"
+	"eta/eta_api/utils"
+	"github.com/rdlucklib/rdluck_tools/paging"
+)
+
+// EdbDetail
+// @Title 指标列表
+// @Description 指标列表
+// @Param   TradeCode   query   string  true       "指标编码"
+// @Success 200 {object} models.TargetDetailResp
+// @router /target/edb/detail [get]
+func (this *TargetController) EdbDetail() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请重新登录"
+		return
+	}
+
+	// 指标编码
+	tradeCode := this.GetString("TradeCode")
+	if tradeCode == `` {
+		br.Msg = "请输入指标编码"
+		br.IsSendEmail = false
+		return
+	}
+
+	manualEdbInfo, err := models.GetTargetByTradeCode(tradeCode)
+	if err != nil {
+		br.Msg = "获取指标失败"
+		br.ErrMsg = "获取指标失败,err:" + err.Error()
+		return
+	}
+
+	// 如果不是超管账号,那么得校验下当前用户是否有该指标的权限
+	if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
+		//获取账户所拥有权限的分类id集合
+		count, err := models.GetCountManualUserClassify(sysUser.AdminId, manualEdbInfo.ClassifyId)
+		if err != nil {
+			br.Msg = "获取分类数据失败"
+			br.ErrMsg = "获取分类数据失败,err:" + err.Error()
+			return
+		}
+
+		if count <= 0 {
+			br.Msg = "无权访问"
+			br.ErrMsg = "无权访问"
+			br.IsSendEmail = false
+			return
+		}
+	}
+
+	classifyList := make([]*models.EdbdataClassify, 0)
+	{
+		classify, err := models.GetManualClassifyByClassifyId(manualEdbInfo.ClassifyId)
+		if err != nil {
+			br.Msg = "获取分类信息失败"
+			br.ErrMsg = "获取分类信息失败,err:" + err.Error()
+			return
+		}
+		parentClassify, err := models.GetManualClassifyByClassifyId(classify.ParentId)
+		if err != nil {
+			br.Msg = "获取分类信息失败"
+			br.ErrMsg = "获取父级分类信息失败,err:" + err.Error()
+			return
+		}
+		classifyList = []*models.EdbdataClassify{
+			parentClassify, classify,
+		}
+	}
+
+	dataList, err := models.GetEdbDataListByCode(manualEdbInfo.TradeCode)
+	if err != nil {
+		br.Msg = "获取明细数据失败"
+		br.ErrMsg = "获取明细数据失败,err:" + err.Error()
+		return
+	}
+
+	manualEdbInfo.DataList = dataList
+	resp := models.TargetDetailResp{
+		Detail:       manualEdbInfo,
+		ClassifyList: classifyList,
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	//br.Data = resp
+	br.Data = resp
+}
+
+// ClassifyEdbList
+// @Title 分类指标列表
+// @Description 指标列表
+// @Param   ClassifyId   query   string  true       "分类id"
+// @Success 200 {object} models.TargetDetailResp
+// @router /target/classify/edb/list [get]
+func (this *TargetController) ClassifyEdbList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.Ret = 408
+		return
+	}
+	resp := new(models.EdbdataClassifyResp)
+
+	classifyId, _ := this.GetInt("ClassifyId") //分类
+	if classifyId <= 0 {
+		br.Msg = "请传入分类"
+		br.ErrMsg = "请传入分类"
+		br.IsSendEmail = false
+	}
+
+	var condition string
+	var pars []interface{}
+
+	// 如果不是超管账号,那么得校验下当前用户是否有该指标的权限
+	if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
+		//获取账户所拥有权限的分类id集合
+		count, err := models.GetCountManualUserClassify(sysUser.AdminId, classifyId)
+		if err != nil {
+			br.Msg = "获取分类数据失败"
+			br.ErrMsg = "获取分类数据失败,err:" + err.Error()
+			return
+		}
+
+		if count <= 0 {
+			br.Msg = "无权访问"
+			br.ErrMsg = "无权访问"
+			br.IsSendEmail = false
+			return
+		}
+	}
+
+	list := make([]*models.EdbdataClassifyList, 0)
+
+	condition += ` AND a.classify_id = ? `
+	pars = append(pars, classifyId)
+
+	tmpList, err := models.GetEdbInfoList(condition, pars, 0, 0)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+
+	for _, v := range tmpList {
+		list = append(list, &models.EdbdataClassifyList{
+			ClassifyId:   0,
+			ClassifyName: v.SecName,
+			ParentId:     v.ClassifyId,
+			Child:        nil,
+			TradeCode:    v.TradeCode,
+			UniqueCode:   utils.MD5(v.TradeCode),
+		})
+	}
+
+	resp.List = list
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// EdbSearch
+// @Title 指标搜索
+// @Description 指标搜索
+// @Param   Keyword   query   string  false       "关键字搜索"
+// @Success 200 {object} models.TargetItemListResp
+// @router /target/edb/search [get]
+func (this *TargetController) EdbSearch() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请重新登录"
+		return
+	}
+
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = utils.StartIndex(currentIndex, pageSize)
+
+	//关键字
+	keyword := this.GetString("Keyword")
+
+	var condition string
+	var pars []interface{}
+
+	userId := sysUser.AdminId
+	//超管账号可以查看分类下的所有频度数据
+	if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
+		classifyList, err := models.GetEdbdataClassify(int64(userId))
+		if err != nil {
+			br.Msg = "获取分类数据失败"
+			br.Msg = "获取拥有的分类数据失败,Err:" + err.Error()
+			return
+		}
+
+		num := len(classifyList)
+		if num > 0 {
+			classifyIdList := make([]int, 0)
+			for _, v := range classifyList {
+				classifyIdList = append(classifyIdList, v.ClassifyId)
+			}
+			condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) `
+			pars = append(pars, classifyIdList)
+		}
+
+	}
+
+	if keyword != "" {
+		condition += ` AND (a.SEC_NAME like ?  or a.TRADE_CODE like ? )`
+		pars = utils.GetLikeKeywordPars(pars, keyword, 2)
+	}
+
+	total, err := models.GetCountEdbInfoList(condition, pars)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+
+	list, err := models.GetEdbInfoList(condition, pars, startSize, pageSize)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+
+	for _, v := range list {
+		v.UniqueCode = utils.MD5(v.TradeCode)
+	}
+
+	resp := models.EdbListResp{
+		List:   list,
+		Paging: paging.GetPaging(currentIndex, pageSize, total),
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// EdbList
+// @Title 获取研究员指标
+// @Description 获取研究员指标
+// @Param   Frequency   query   string  false       "频度;枚举值:日度、周度、月度、季度、半年度、年度"
+// @Param   Keyword   query   string  false       "关键字搜索"
+// @Param   TradeCode   query   string  false       "指标唯一编码"
+// @Param   ClassifyId   query   int  false       "分类id"
+// @Param   EdbShowType   query   string  true       "指标展示类型:0,1,2; 0:不管有没有数据,指标都展示出来, 1:只展示有数据的指标, 2:只展示没有数据的指标"
+// @Success 200 {object} models.TargetItemListResp
+// @router /target/edb/list [get]
+func (this *TargetController) EdbList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请重新登录"
+		return
+	}
+
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = utils.StartIndex(currentIndex, pageSize)
+
+	//关键字
+	keyword := this.GetString("Keyword")
+	//关键字
+	classifyId, _ := this.GetInt("ClassifyId", 0)
+
+	var condition string
+	var pars []interface{}
+
+	userId := sysUser.AdminId
+	//超管账号可以查看分类下的所有频度数据
+	if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
+		classifyList, err := models.GetEdbdataClassify(int64(userId))
+		if err != nil {
+			br.Msg = "获取分类数据失败"
+			br.Msg = "获取拥有的分类数据失败,Err:" + err.Error()
+			return
+		}
+
+		num := len(classifyList)
+		if num > 0 {
+			classifyIdList := make([]int, 0)
+			for _, v := range classifyList {
+				classifyIdList = append(classifyIdList, v.ClassifyId)
+			}
+			condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) `
+			pars = append(pars, classifyIdList)
+		}
+
+	}
+
+	// 关键词
+	if keyword != "" {
+		condition += ` AND (a.SEC_NAME like ?  or a.TRADE_CODE like ? )`
+		pars = utils.GetLikeKeywordPars(pars, keyword, 2)
+	}
+
+	// 所属分类
+	if classifyId > 0 {
+		condition += ` AND a.classify_id = ? `
+		pars = append(pars, classifyId)
+	}
+
+	total, err := models.GetCountEdbInfoList(condition, pars)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+
+	list, err := models.GetEdbInfoList(condition, pars, startSize, pageSize)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+
+	edbCodeMap := make(map[string]bool)
+	listNum := len(list)
+	if listNum > 0 {
+		tradeCodeList := make([]string, 0)
+		for _, v := range list {
+			v.UniqueCode = utils.MD5(v.TradeCode)
+			tradeCodeList = append(tradeCodeList, v.TradeCode)
+		}
+
+		// 查找是否加入到指标库
+		{
+			var edbCondition string
+			var edbPars []interface{}
+			edbCondition = ` AND source = ? AND edb_code in (` + utils.GetOrmInReplace(listNum) + `) `
+			edbPars = append(pars, utils.DATA_SOURCE_MANUAL, tradeCodeList)
+
+			edbInfoList, err := data_manage.GetEdbInfoListByCond(edbCondition, edbPars)
+			if err != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取失败,Err:" + err.Error()
+				return
+			}
+			for _, v := range edbInfoList {
+				edbCodeMap[v.EdbCode] = true
+			}
+		}
+
+		for _, v := range list {
+			// 如果能通过指标编码下标找到,那么说明是加到指标库中
+			if _, ok := edbCodeMap[v.TradeCode]; ok {
+				v.EdbExist = 1
+			}
+		}
+	}
+
+	resp := models.EdbListResp{
+		List:   list,
+		Paging: paging.GetPaging(currentIndex, pageSize, total),
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 2 - 0
controllers/target.go

@@ -776,10 +776,12 @@ func (this *TargetController) ClassifyList() {
 			edbInfoGroupCountMap[edbInfoGroupCount.ClassifyId] = edbInfoGroupCount.Count
 		}
 		for _, classifyList := range list {
+			classifyList.UniqueCode = utils.MD5(fmt.Sprint(classifyList.ClassifyId))
 			if classifyList.Child != nil {
 				for _, classify := range classifyList.Child {
 					if total, ok := edbInfoGroupCountMap[classify.ClassifyId]; ok {
 						classify.EdbInfoTotal = total
+						classify.UniqueCode = utils.MD5(fmt.Sprint(classify.ClassifyId))
 					}
 				}
 			}

+ 11 - 0
models/data_manage/base_from_ths_hf.go

@@ -496,3 +496,14 @@ type ThsHfIndexMultiSave2EdbResp struct {
 	Success []*ThsHfIndexMultiSave2EdbPreItem `description:"添加成功的指标"`
 	Fail    []*ThsHfIndexMultiSave2EdbPreItem `description:"添加失败的指标"`
 }
+
+type ThsHfIndexMultiOptResp struct {
+	Success []*ThsHfIndexBaseInfo `description:"操作成功的指标"`
+	Fail    []*ThsHfIndexBaseInfo `description:"操作失败的指标"`
+}
+
+type ThsHfIndexBaseInfo struct {
+	IndexId   int    `description:"指标ID"`
+	IndexCode string `description:"指标编码"`
+	IndexName string `description:"指标名称"`
+}

+ 78 - 5
models/data_manage/data_manage_permission/excel.go

@@ -10,11 +10,12 @@ import (
 
 type ExcelInfoPermission struct {
 	ExcelInfoPermissionId int64     `json:"excel_info_permission_id" orm:"column(excel_info_permission_id);pk"`
-	ExcelInfoId           int32     `json:"excel_info_id"` // ETA表格id
-	Source                int32     `json:"source"`        // 表格来源,1:excel插件的表格,2:自定义表格,3:混合表格,4:自定义分析,默认:1
-	SysUserId             int32     `json:"sys_user_id"`   // 系统用户id
-	ModifyTime            time.Time `json:"modify_time"`   // 变更时间
-	CreateTime            time.Time `json:"create_time"`   // 关系建立时间
+	ExcelInfoId           int32     `json:"excel_info_id"`   // ETA表格id
+	Source                int32     `json:"source"`          // 表格来源,1:excel插件的表格,2:自定义表格,3:混合表格,4:自定义分析,默认:1
+	SysUserId             int32     `json:"sys_user_id"`     // 系统用户id
+	ModifyTime            time.Time `json:"modify_time"`     // 变更时间
+	CreateTime            time.Time `json:"create_time"`     // 关系建立时间
+	PermissionType        int       `json:"permission_type"` // 权限类型: 0-默认; 1-查看; 2-编辑
 }
 
 type ExcelClassifyPermission struct {
@@ -971,3 +972,75 @@ func GetExcelInfoDataPermissionClassifyNoAuthRecordListByUserId(userId, excelSou
 
 	return
 }
+
+// ExcelInfoPermissionAdminAuth 含创建人的表格权限
+type ExcelInfoPermissionAdminAuth struct {
+	ExcelInfoPermission
+	ExcelName    string `json:"excel_name"`     // 表格名称
+	UniqueCode   string `json:"unique_code"`    // 唯一编码
+	CreateUserId int    `json:"create_user_id"` // 创建人ID
+}
+
+// GetAdminAuthExcelInfoPermission 获取用户有权限的表格
+func GetAdminAuthExcelInfoPermission(source, adminId int, keywords string) (items []*ExcelInfoPermissionAdminAuth, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `SELECT a.*, b.sys_user_id AS create_user_id, b.excel_name, b.unique_code FROM excel_info_permission AS a
+		JOIN excel_info AS b ON a.excel_info_id = b.excel_info_id
+		WHERE a.source = ? AND (b.sys_user_id = ? OR a.sys_user_id = ?)`
+	var pars []interface{}
+	pars = append(pars, source, adminId, adminId)
+	if keywords != "" {
+		sql += ` AND b.excel_name LIKE ?`
+		pars = append(pars, keywords)
+	}
+	sql += ` ORDER BY a.create_time DESC`
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
+func ClearAndSetExcelInfoPermission(source, excelInfoId int, permissions []*ExcelInfoPermission) (err error) {
+	if excelInfoId <= 0 {
+		return
+	}
+	tx, e := orm.NewOrmUsingDB("data").Begin()
+	if e != nil {
+		err = fmt.Errorf("orm begin err: %v", e)
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = tx.Rollback()
+			return
+		}
+		_ = tx.Commit()
+	}()
+
+	sql := `DELETE FROM excel_info_permission WHERE excel_info_id = ? AND source = ?`
+	_, e = tx.Raw(sql, excelInfoId, source).Exec()
+	if e != nil {
+		err = fmt.Errorf("clear permission err: %v", e)
+		return
+	}
+	if len(permissions) > 0 {
+		_, e = tx.InsertMulti(500, permissions)
+		if e != nil {
+			err = fmt.Errorf("insert permissions err: %v", e)
+			return
+		}
+	}
+	return
+}
+
+func GetExcelPermissionBySourceAndId(excelId, source int) (items []*ExcelInfoPermission, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `SELECT * FROM excel_info_permission WHERE source = ? AND excel_info_id = ?`
+	_, err = o.Raw(sql, source, excelId).QueryRows(&items)
+	return
+}
+
+func GetExcelPermissionByExcelIdAndUserId(excelId, userId int) (items []*ExcelInfoPermission, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `SELECT * FROM excel_info_permission WHERE excel_info_id = ? AND sys_user_id = ?`
+	_, err = o.Raw(sql, excelId, userId).QueryRows(&items)
+	return
+}

+ 1 - 0
models/data_manage/edb_info_calculate.go

@@ -208,6 +208,7 @@ type EdbInfoCalculateBatchSaveReq struct {
 	MoveFrequency    string           `description:"移动频度:天/周/月/季/年"`
 	Extra            string           `description:"指标的额外配置"`
 	Calendar         string           `description:"公历/农历"`
+	EmptyType        int              `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
 }
 
 type EdbInfoCalculateBatchEditReq struct {

+ 14 - 0
models/data_manage/excel/excel_classify.go

@@ -7,6 +7,11 @@ import (
 	"time"
 )
 
+const (
+	CustomAnalysisMenuShareId  = 9000000 // 自定义分析目录ID-我共享的
+	CustomAnalysisMenuSharedId = 8000000 // 自定义分析目录ID-收到共享
+)
+
 // ExcelClassify excel表格分类
 type ExcelClassify struct {
 	ExcelClassifyId   int       `orm:"column(excel_classify_id);pk"`
@@ -132,6 +137,8 @@ type ExcelClassifyItems struct {
 	Children          []*ExcelClassifyItems
 	IsJoinPermission  int  `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
 	HaveOperaAuth     bool `description:"是否有数据权限"`
+	HasShare          bool `description:"是否已共享: true-是; false-否"`
+	ShowShareBtn      bool `description:"是否显示共享按钮: true-是; false-否"`
 }
 
 func GetExcelClassifyByCondition(condition string, pars []interface{}) (item *ExcelClassify, err error) {
@@ -226,3 +233,10 @@ func GetClassifyByIdList(classifyIdList []int) (items []*ExcelClassify, err erro
 
 	return
 }
+
+func GetAdminExcelClassifyBySource(source, adminId int) (items []*ExcelClassifyItems, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `SELECT * FROM excel_classify WHERE source = ? AND sys_user_id = ? AND is_delete = 0 ORDER BY sort ASC, excel_classify_id ASC;`
+	_, err = o.Raw(sql, source, adminId).QueryRows(&items)
+	return
+}

+ 7 - 0
models/data_manage/excel/request/excel_info.go

@@ -163,3 +163,10 @@ type SaveExcelInfoWorkerReq struct {
 	ExcelInfoId int    `description:"ETA表格ID"`
 	SysUserIds  string `description:"协作人ID 用英文逗号拼接"`
 }
+
+// ShareExcelInfoReq 分享表格请求
+type ShareExcelInfoReq struct {
+	ExcelInfoId int   `description:"表格ID"`
+	ViewUserIds []int `description:"查看权限用户IDs"`
+	EditUserIds []int `description:"编辑权限用户IDs"`
+}

+ 7 - 0
models/data_manage/excel/response/excel_info.go

@@ -111,3 +111,10 @@ type BalanceTableVersionListItem struct {
 type BalanceTableVersionListResp struct {
 	List []*BalanceTableVersionListItem
 }
+
+// ShareExcelInfoDetail 分享表格详情
+type ShareExcelInfoDetail struct {
+	ExcelInfoId int   `description:"表格ID"`
+	ViewUserIds []int `description:"查看权限用户IDs"`
+	EditUserIds []int `description:"编辑权限用户IDs"`
+}

+ 1 - 0
models/data_manage/predict_edb_info_calculate.go

@@ -37,6 +37,7 @@ type PredictEdbInfoCalculateBatchSaveReq struct {
 	MoveType      int    `description:"移动方式:1:领先(默认),2:滞后"`
 	MoveFrequency string `description:"移动频度:天/周/月/季/年"`
 	Calendar      string `description:"公历/农历"`
+	EmptyType     int    `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
 }
 
 // BatchPredictEdbInfoCalculateBatchSaveReq 批量添加 计算指标

+ 135 - 0
models/manual_edb.go

@@ -0,0 +1,135 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"github.com/rdlucklib/rdluck_tools/paging"
+)
+
+// TargetDetailResp 指标数据结构体
+type TargetDetailResp struct {
+	Detail       *EdbInfoItem
+	ClassifyList []*EdbdataClassify
+}
+
+// GetTargetByTradeCode
+// @Description: 根据手工指标编码获取指标信息
+// @author: Roc
+// @datetime 2024-07-16 14:18:10
+// @param tradeCode string
+// @return item *Edbinfo
+// @return err error
+func GetTargetByTradeCode(tradeCode string) (item *EdbInfoItem, err error) {
+	sql := `SELECT * FROM edbinfo WHERE TRADE_CODE = ?  `
+	o := orm.NewOrmUsingDB("edb")
+	err = o.Raw(sql, tradeCode).QueryRow(&item)
+	return
+}
+
+// GetCountManualUserClassify
+// @Description: 根据用户ID和分类ID获取关系数量
+// @author: Roc
+// @datetime 2024-07-16 14:27:58
+// @param sysUserId int
+// @param classifyId int
+// @return total int
+// @return err error
+func GetCountManualUserClassify(sysUserId, classifyId int) (total int, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `SELECT count(1) ct FROM manual_user_classify WHERE admin_id=? AND classify_id = ? `
+	err = o.Raw(sql, sysUserId, classifyId).QueryRow(&total)
+
+	return
+}
+func GetManualClassifyByClassifyId(classifyId int) (item *EdbdataClassify, err error) {
+	o := orm.NewOrmUsingDB("edb")
+	sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE classify_id = ?  `
+	err = o.Raw(sql, classifyId).QueryRow(&item)
+
+	return
+}
+
+// GetEdbDataListByCode
+// @Description: 通过指标ID获取所有数据
+// @author: Roc
+// @datetime 2024-07-16 15:32:41
+// @param tradeCode string
+// @return items []*Edbdata
+// @return err error
+func GetEdbDataListByCode(tradeCode string) (items []*Edbdata, err error) {
+	sql := ` SELECT  TRADE_CODE,DT,round(CLOSE,4) CLOSE,modify_time  FROM edbdata WHERE TRADE_CODE = ?  GROUP BY TRADE_CODE,DT ORDER BY DT DESC `
+	o := orm.NewOrmUsingDB("edb")
+	_, err = o.Raw(sql, tradeCode).QueryRows(&items)
+	return
+}
+
+// EdbInfoListItem
+type EdbInfoListItem struct {
+	TradeCode    string `orm:"column(TRADE_CODE);pk" description:"指标code"`
+	SecName      string `orm:"column(SEC_NAME);" description:"指标名称"`
+	Unit         string `orm:"column(UNIT);" description:"单位"`
+	Remark       string `orm:"column(REMARK);" description:"备注"`
+	Frequency    string `description:"频度"`
+	ClassifyId   int    `description:"分类id"`
+	ClassifyName string `description:"分类名称"`
+	CreateDate   string `description:"创建时间"`
+	UserId       int    `description:"录入用户id"`
+	NoticeTime   string `description:"通知时间"`
+	Mobile       string `description:"录入者手机号"`
+	ModifyDate   string `description:"待更新日期"`
+	Status       string `description:"状态:未完成/完成"`
+	UniqueCode   string
+	EdbExist     int `description:"指标库是否已添加:0-否;1-是"`
+}
+
+// EdbListResp 指标数据结构体
+type EdbListResp struct {
+	List   []*EdbInfoListItem
+	Paging *paging.PagingItem `description:"分页数据"`
+}
+
+// GetEdbInfoList
+// @Description: 根据条件获取指标列表
+// @author: Roc
+// @datetime 2024-07-17 10:34:05
+// @param condition string
+// @param pars []interface{}
+// @return items []*Edbinfo
+// @return err error
+func GetEdbInfoList(condition string, pars []interface{}, startSize, pageSize int) (items []*EdbInfoListItem, err error) {
+	o := orm.NewOrmUsingDB("edb")
+	sql := `SELECT DISTINCT a.* FROM edbinfo AS a  WHERE a.REMARK='手动' `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` ORDER BY a.create_date DESC `
+
+	if pageSize > 0 {
+		sql += ` LIMIT ?,? `
+		pars = append(pars, startSize, pageSize)
+	}
+
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+
+	return
+}
+
+// GetCountEdbInfoList
+// @Description: 根据条件获取指标数量
+// @author: Roc
+// @datetime 2024-07-17 14:51:00
+// @param condition string
+// @param pars []interface{}
+// @return total int
+// @return err error
+func GetCountEdbInfoList(condition string, pars []interface{}) (total int, err error) {
+	o := orm.NewOrmUsingDB("edb")
+	sql := `SELECT COUNT(1) ct FROM edbinfo AS a  WHERE a.REMARK='手动' `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` ORDER BY a.create_date DESC `
+
+	err = o.Raw(sql, pars).QueryRow(&total)
+
+	return
+}

+ 39 - 0
models/target.go

@@ -427,6 +427,8 @@ type EdbdataClassify struct {
 	ClassifyName string
 	ParentId     int
 	EdbInfoTotal int
+	TradeCode    string
+	UniqueCode   string
 }
 
 func GetEdbdataClassifyByClassifyName(classifyName string) (item *EdbdataClassify, err error) {
@@ -441,6 +443,8 @@ type EdbdataClassifyList struct {
 	ClassifyName string
 	ParentId     int
 	Child        []*EdbdataClassify
+	TradeCode    string
+	UniqueCode   string
 }
 
 func GetEdbdataClassify(userId int64) (items []*EdbdataClassifyList, err error) {
@@ -1659,3 +1663,38 @@ func GetEdbInfoAdminList() (list []int, err error) {
 	_, err = o.Raw(sql).QueryRows(&list)
 	return
 }
+
+// GetAllChildManualEdbClassify
+// @Description: 获取手工数据中所有的子分类
+// @author: Roc
+// @datetime 2024-07-16 13:27:28
+// @return items []*EdbdataClassify
+// @return err error
+func GetAllChildManualEdbClassify() (items []*EdbdataClassify, err error) {
+	o := orm.NewOrmUsingDB("edb")
+
+	sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE parent_id > 0 `
+	_, err = o.Raw(sql).QueryRows(&items)
+
+	return
+}
+
+// GetChildManualEdbClassifyByIdList
+// @Description: 获取手工数据中所有的子分类
+// @author: Roc
+// @datetime 2024-07-16 13:33:57
+// @param idList []int
+// @return items []*EdbdataClassify
+// @return err error
+func GetChildManualEdbClassifyByIdList(idList []int) (items []*EdbdataClassify, err error) {
+	num := len(idList)
+	if num <= 0 {
+		return
+	}
+	o := orm.NewOrmUsingDB("edb")
+
+	sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE classify_id in (` + utils.GetOrmInReplace(num) + `) `
+	_, err = o.Raw(sql, idList).QueryRows(&items)
+
+	return
+}

+ 72 - 0
routers/commentsRouter.go

@@ -934,6 +934,33 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/excel:CustomAnalysisController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/excel:CustomAnalysisController"],
+        beego.ControllerComments{
+            Method: "List",
+            Router: `/excel/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/excel:CustomAnalysisController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/excel:CustomAnalysisController"],
+        beego.ControllerComments{
+            Method: "Share",
+            Router: `/excel/share`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/excel:CustomAnalysisController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/excel:CustomAnalysisController"],
+        beego.ControllerComments{
+            Method: "ShareDetail",
+            Router: `/excel/share_detail`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/excel:CustomAnalysisController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/excel:CustomAnalysisController"],
         beego.ControllerComments{
             Method: "ExcelByName",
@@ -943,6 +970,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/excel:CustomAnalysisController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/excel:CustomAnalysisController"],
+        beego.ControllerComments{
+            Method: "ClassifyList",
+            Router: `/excel_classify/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/excel:CustomAnalysisController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/excel:CustomAnalysisController"],
         beego.ControllerComments{
             Method: "Save",
@@ -9745,6 +9781,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers:TargetController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers:TargetController"],
+        beego.ControllerComments{
+            Method: "ClassifyEdbList",
+            Router: `/target/classify/edb/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers:TargetController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers:TargetController"],
         beego.ControllerComments{
             Method: "TargetDelete",
@@ -9754,6 +9799,33 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers:TargetController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers:TargetController"],
+        beego.ControllerComments{
+            Method: "EdbDetail",
+            Router: `/target/edb/detail`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers:TargetController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers:TargetController"],
+        beego.ControllerComments{
+            Method: "EdbList",
+            Router: `/target/edb/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers:TargetController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers:TargetController"],
+        beego.ControllerComments{
+            Method: "EdbSearch",
+            Router: `/target/edb/search`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers:TargetController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers:TargetController"],
         beego.ControllerComments{
             Method: "TargetEdit",

+ 38 - 2
services/data/excel/excel_info.go

@@ -531,7 +531,7 @@ func GetExcelEdbBatchRefreshKey(source string, primaryId, subId int) string {
 }
 
 // GetEdbSourceByEdbInfoIdList 获取关联指标的来源
-func GetEdbSourceByEdbInfoIdList(edbInfoIdList []int) (sourceNameList, sourceNameEnList []string,err error) {
+func GetEdbSourceByEdbInfoIdList(edbInfoIdList []int) (sourceNameList, sourceNameEnList []string, err error) {
 	sourceNameList = make([]string, 0)
 	sourceNameEnList = make([]string, 0)
 	sourceMap := make(map[int]string)
@@ -580,4 +580,40 @@ func GetEdbSourceByEdbInfoIdList(edbInfoIdList []int) (sourceNameList, sourceNam
 		sourceNameEnList = append(sourceNameEnList, conf[models.BusinessConfCompanyName])
 	}
 	return
-}
+}
+
+// GetCustomAnalysisOpButton 获取自定义分析按钮权限
+func GetCustomAnalysisOpButton(sysUser *system.Admin, belongUserId int, permissionType []int) (button excel.ExcelInfoDetailButton) {
+	// 如果没有数据权限,那么直接返回
+	if len(permissionType) == 0 {
+		return
+	}
+
+	// 管理员/所属人所有权限
+	if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.AdminId == belongUserId {
+		button.RefreshButton = true
+		button.CopyButton = true
+		button.DownloadButton = true
+
+		button.OpEdbButton = true
+		button.RefreshEdbButton = true
+		button.OpButton = true
+		button.DeleteButton = true
+		return
+	}
+
+	// 非管理员-被分享人
+	for _, v := range permissionType {
+		if v == 1 {
+			button.RefreshButton = true
+			button.CopyButton = true
+			button.DownloadButton = true
+		}
+		if v == 2 {
+			button.OpEdbButton = true
+			button.RefreshEdbButton = true
+			button.OpButton = true
+		}
+	}
+	return
+}

+ 30 - 0
services/data/manual.go

@@ -1,6 +1,7 @@
 package data
 
 import (
+	"eta/eta_api/models"
 	"eta/eta_api/models/data_manage"
 	"eta/eta_api/models/system"
 	"eta/eta_api/utils"
@@ -82,3 +83,32 @@ func GetManualSysUser(keyWord string) (list []*data_manage.ManualSysUser, err er
 	}
 	return
 }
+
+// GetManualEdbClassifyListByAdminId
+// @Description: 根据账户类型获取手工指标分类ID集合
+// @author: Roc
+// @datetime 2024-07-16 13:18:39
+// @param adminId int64
+// @return classifyIdList []int
+// @return err error
+func GetManualEdbClassifyListByAdminId(adminId int64) (classifyIdList []int, err error) {
+	var list []*models.EdbdataClassify
+	if adminId <= 0 {
+		list, err = models.GetAllChildManualEdbClassify()
+	} else {
+		userClassifyList, _ := models.GetManualUserClassify(int(adminId))
+		var userClassifyIdList []int
+		for _, v := range userClassifyList {
+			userClassifyIdList = append(userClassifyIdList, v.ClassifyId)
+		}
+		list, err = models.GetChildManualEdbClassifyByIdList(userClassifyIdList)
+	}
+	if err != nil {
+		return
+	}
+	for _, classify := range list {
+		classifyIdList = append(classifyIdList, classify.ClassifyId)
+	}
+
+	return
+}