package sandbox import ( "github.com/gin-gonic/gin" "hongze/hongze_yb/controller/response" sandboxLogic "hongze/hongze_yb/logic/sandbox" sandboxReq "hongze/hongze_yb/models/request/sandbox" responseModel "hongze/hongze_yb/models/response" sandboxModel "hongze/hongze_yb/models/tables/sandbox" "hongze/hongze_yb/services" "hongze/hongze_yb/services/company" "hongze/hongze_yb/services/user" "strconv" "strings" ) // List 获取研报列表 func List(c *gin.Context) { var req sandboxReq.ListReq if err := c.Bind(&req); err != nil { response.Fail("参数有误", c) return } // 品种id chartPermissionId := req.ChartPermissionId // 关键字 keyword := req.Keyword // 是否高亮 isHighLight := req.IsHighLight page := services.GetCurrPageByClaims(c) pageSize := services.GetPageSizeByClaims(c) userInfo := user.GetInfoByClaims(c) //权限验证 checkOk, permissionCheckInfo, tempErr := company.CheckUserSandboxPermission(userInfo.CompanyID, int(userInfo.UserID), 0) if tempErr != nil { response.FailMsg("沙盘权限验证失败", "沙盘权限验证失败:"+tempErr.Error(), c) c.Abort() return } if !checkOk { response.AuthError(permissionCheckInfo, "暂无权限", c) c.Abort() return } //获取指标信息 total, list, err, errMsg := sandboxLogic.GetList(chartPermissionId, keyword, page, pageSize) if err != nil { response.FailMsg(errMsg, err.Error(), c) return } // 如果要高亮,且有输入关键字搜索,那么就返回高亮显示字符串 if isHighLight && keyword != `` { for index, v := range list { tmpKeyword := `` + keyword + `` list[index].Name = strings.Replace(v.Name, keyword, tmpKeyword, -1) } } resp := responseModel.SandboxListResp{ List: list, Paging: responseModel.GetPaging(page, pageSize, int(total)), } response.OkData("获取成功", resp, c) } // Detail 获取研报详情 func Detail(c *gin.Context) { // 沙盘id sandboxIdStr := c.DefaultQuery("sandbox_id", "0") sandboxId, _ := strconv.Atoi(sandboxIdStr) userInfo := user.GetInfoByClaims(c) sandboxInfo, err := sandboxModel.GetBySandboxId(uint32(sandboxId)) if err != nil { response.FailMsg("获取沙盘失败", "获取沙盘失败:"+err.Error(), c) c.Abort() return } //权限验证 checkOk, permissionCheckInfo, tempErr := company.CheckUserSandboxPermission(userInfo.CompanyID, int(userInfo.UserID), int(sandboxInfo.ChartPermissionID)) if tempErr != nil { response.FailMsg("沙盘权限验证失败", "沙盘权限验证失败:"+tempErr.Error(), c) c.Abort() return } if !checkOk { response.AuthError(permissionCheckInfo, "暂无权限", c) c.Abort() return } response.OkData("获取成功", sandboxLogic.SandboxItem{ SandboxID: sandboxInfo.SandboxID, Name: sandboxInfo.Name, ChartPermissionID: sandboxInfo.ChartPermissionID, ChartPermissionName: sandboxInfo.ChartPermissionName, CurrVersion: sandboxInfo.CurrVersion, Code: sandboxInfo.Code, PicURL: sandboxInfo.PicURL, OpUserName: sandboxInfo.OpUserName, ModifyTime: sandboxInfo.ModifyTime, }, c) }