package services import ( "encoding/json" "eta/eta_api/models" excelModel "eta/eta_api/models/data_manage/excel" "eta/eta_api/models/system" "eta/eta_api/utils" "fmt" "time" ) // UpdateExcelEditMark 更新表格当前更新状态 // status 枚举值 1:编辑中,0:完成编辑, 2:只做查询 func UpdateExcelEditMark(excelInfoId, nowUserId, status int, nowUserName string) (ret models.MarkReportResp, err error) { //更新标记key key := fmt.Sprint(`crm:excel:edit:`, excelInfoId) opUserId, e := utils.Rc.RedisInt(key) var opUser models.MarkReportItem if e != nil { opUserInfoStr, tErr := utils.Rc.RedisString(key) if tErr == nil { tErr = json.Unmarshal([]byte(opUserInfoStr), &opUser) if tErr == nil { opUserId = opUser.AdminId } } } if opUserId > 0 && opUserId != nowUserId { editor := opUser.Editor if editor == "" { //查询账号的用户姓名 otherInfo, e := system.GetSysAdminById(opUserId) if e != nil { err = fmt.Errorf("查询其他编辑者信息失败") return } editor = otherInfo.RealName } ret.Status = 1 ret.Msg = fmt.Sprintf("当前%s正在编辑中", editor) ret.Editor = editor return } if status == 1 { nowUser := &models.MarkReportItem{AdminId: nowUserId, Editor: nowUserName} bt, e := json.Marshal(nowUser) if e != nil { err = fmt.Errorf("格式化编辑者信息失败") return } if opUserId > 0 { utils.Rc.Do("SETEX", key, int64(300), string(bt)) //3分钟缓存 } else { utils.Rc.SetNX(key, string(bt), time.Second*60*3) //3分钟缓存 } } else if status == 0 { //清除编辑缓存 _ = utils.Rc.Delete(key) } return } // GetTradeAnalysisTableOpButton 获取持仓分析表格的操作权限 func GetTradeAnalysisTableOpButton(belongUserId, sysUserId int, roleTypeCode string, haveOperaAuth bool) (button excelModel.ExcelInfoDetailButton) { // 这部分没有加到数据权限里,这里先注释掉 //if !haveOperaAuth { // return //} // 非管理员角色查看其他用户创建的表格,可刷新、另存为、下载表格; button.RefreshButton = true button.CopyButton = true button.DownloadButton = true // 创建人、管理员有权限编辑和删除 if belongUserId == sysUserId || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN { button.OpButton = true button.DeleteButton = true } return }