123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- 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"
- )
- func List(c *gin.Context) {
- var req sandboxReq.ListReq
- if err := c.Bind(&req); err != nil {
- response.Fail("参数有误", c)
- return
- }
-
- chartPermissionId := req.ChartPermissionId
-
- keyword := req.Keyword
-
- isHighLight := req.IsHighLight
- page := services.GetCurrPageByClaims(c)
- pageSize := services.GetPageSizeByClaims(c)
- userInfo := user.GetInfoByClaims(c)
-
- checkOk, companyPermissionIdList, permissionCheckInfo, tempErr := company.CheckUserSandboxPermission(userInfo.CompanyID, int(userInfo.UserID), chartPermissionId)
- 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, companyPermissionIdList, keyword, page, pageSize)
- if err != nil {
- response.FailMsg(errMsg, err.Error(), c)
- return
- }
-
- if isHighLight && keyword != `` {
- for index, v := range list {
- tmpKeyword := `<span style="color:#E3B377">` + keyword + `</span>`
- 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)
- }
- func Detail(c *gin.Context) {
-
- 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)
- }
- func PermissionCountList(c *gin.Context) {
- userInfo := user.GetInfoByClaims(c)
-
- checkOk, companyPermissionIdList, 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
- }
-
- list, err, errMsg := sandboxLogic.GetPermissionCountList(companyPermissionIdList)
- if err != nil {
- response.FailMsg(errMsg, err.Error(), c)
- return
- }
- response.OkData("获取成功", list, c)
- }
|