public async Task <ResponseMessage> CratePeriod(Models.UserInfo user, [FromBody] CreatePeriodRequest createPeriodRequest) { Logger.Trace($"用户{user?.UserName ?? ""}({user?.Id ?? ""})添加赛季,请求参数为:\r\n" + (createPeriodRequest != null ? JsonHelper.ToJson(createPeriodRequest) : "")); var response = new ResponseMessage(); if (!ModelState.IsValid) { response.Code = ResponseCodeDefines.ArgumentNullError; response.Message = "模型验证失败" + ModelState.GetAllErrors(); Logger.Warn("添加赛季验证失败:\r\n{0}", response.Message ?? ""); return(response); } if (user.IsAdmin == false) { response.Code = ResponseCodeDefines.NotAllow; response.Message = "没有权限"; Logger.Trace("没有权限:\r\n{0}", response.Message ?? ""); } var prefixs = new string[] { "ScorePeriodController" }; var key = $"{user.Id}{createPeriodRequest.Caption}{createPeriodRequest.EndDate.Date}"; try { // 防止重复提交 await _cache.LockSubmit(prefixs, key, "CratePeriod", HttpContext.RequestAborted); response = await _scorePeriodManager.CreatePeriod(user, createPeriodRequest); } catch (Exception e) { response.Code = ResponseCodeDefines.ServiceError; response.Message = e.Message; Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})添加赛季,报错:{e.Message}\r\n{e.StackTrace}"); } finally { // 成功失败都要移除 await _cache.UnlockSubmit(prefixs, key); } return(response); }