package backend import ( "cron_admin/app/constants/errorcode" "cron_admin/app/http/controllers" "cron_admin/app/http/entities/backend" "cron_admin/app/models/croncmdmodel" "cron_admin/app/services" cmd_services "cron_admin/app/services/cmd_service" "cron_admin/app/utils/helper" "cron_admin/app/utils/mapstructure" "github.com/gin-gonic/gin" "strconv" ) func CronFuncLogsList(c *gin.Context) { request := controllers.GetRequest(c).(*backend.CronFuncLogsListRequest) count, funcLogsList, err := services.CronFuncLogsList(request, request.Page, request.Limit) if err != nil { controllers.HandRes(c, nil, errorcode.ParamError) } else { var funcLogsListResponse []backend.CronFuncLogsListResponse _ = mapstructure.DecodeWithTime(funcLogsList, &funcLogsListResponse, helper.DefaultFormatLayout) // 获取当前列表下的CmdName // 获取所有的cmd_id var cmdIds []string cmdIdsMap := make(map[int64]bool) for _, v := range funcLogsListResponse { if _, ok := cmdIdsMap[v.CmdId]; ok { continue } cmdIdsMap[v.CmdId] = true // v.cmdId 转成string cmdIdStr := strconv.FormatInt(v.CmdId, 10) cmdIds = append(cmdIds, cmdIdStr) } // 获取所有的cmd_id对应的CmdName _, cmdList, err := cmd_services.GetListByWhere(&backend.CmdListRequest{CmdIds: cmdIds}, 1, 100) if err != nil { return } cmdListMap := make(map[int64]croncmdmodel.CronCmd) for _, v := range cmdList { cmdListMap[int64(v.CmdId)] = v } for k, v := range funcLogsListResponse { if cmdListMap != nil && cmdListMap[v.CmdId].CmdName != "" { funcLogsListResponse[k].CmdName = cmdListMap[v.CmdId].CmdName } } controllers.HandRes(c, gin.H{"data": funcLogsListResponse, "count": count}, err) } }