增强缓存操作的线程安全性
在 `Dt_TaskService.cs` 中添加了对 `_simpleCacheService` 的锁定机制,以确保在并发情况下的线程安全。注释掉了 `GetFROutTrayToCW` 方法中的请求次数和时间限制代码,可能是为了简化逻辑或暂时禁用该功能。同时,在 `TaskController.cs` 中将 `ThrottleFilter` 的节流时间从 5 秒修改为 15 秒,以降低请求频率限制的严格性。
| | |
| | | }); |
| | | try |
| | | { |
| | | _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { stock.PalletCode }); |
| | | using(_simpleCacheService.AcquireLock(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, 2000)) |
| | | { |
| | | _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { stock.PalletCode }); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogFactory.GetLog("删除缓存失败").Error(true, $"{stock.PalletCode}_删除缓存失败,异常信息:{ex.Message}"); |
| | | _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { stock.PalletCode }); |
| | | using(_simpleCacheService.AcquireLock(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, 2000)) |
| | | { |
| | | _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { stock.PalletCode }); |
| | | } |
| | | } |
| | | |
| | | return content.OK("任务完成成功", task.Remark); |
| | |
| | | _locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(locationInf, lastStatus, (int)StatusChangeTypeEnum.AutomaticStorage, task.TaskNum); |
| | | |
| | | stock.StockInfoDetails = new List<DtStockInfoDetail>() { { stock.StockInfoDetails[0] } }; |
| | | _simpleCacheService.HashAdd(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, stock.PalletCode, stock); |
| | | using(_simpleCacheService.AcquireLock(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, 2000)) |
| | | { |
| | | _simpleCacheService.HashAdd(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, stock.PalletCode, stock); |
| | | } |
| | | |
| | | content.OK("入库任务完成成功"); |
| | | } |
| | |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | string requestKey = JsonConvert.SerializeObject(taskDTO); |
| | | // 检查请求次数和时间限制 |
| | | if (requestTrackerToCW.TryGetValue(requestKey, out var requestInfo)) |
| | | { |
| | | if (requestInfo.Count > 5 && DateTime.Now < requestInfo.LastRequestTime.AddMinutes(2)) |
| | | { |
| | | // 如果请求次数超过限制且未超过10分钟,抛出异常 |
| | | throw new InvalidOperationException("请求次数已达到限制,请稍后再试。"); |
| | | } |
| | | } |
| | | //string requestKey = JsonConvert.SerializeObject(taskDTO); |
| | | //// 检查请求次数和时间限制 |
| | | //if (requestTrackerToCW.TryGetValue(requestKey, out var requestInfo)) |
| | | //{ |
| | | // if (requestInfo.Count > 5 && DateTime.Now < requestInfo.LastRequestTime.AddMinutes(2)) |
| | | // { |
| | | // // 如果请求次数超过限制且未超过10分钟,抛出异常 |
| | | // throw new InvalidOperationException("请求次数已达到限制,请稍后再试。"); |
| | | // } |
| | | //} |
| | | |
| | | // 更新请求跟踪信息 |
| | | if (requestTrackerToCW.ContainsKey(requestKey)) |
| | | { |
| | | requestTrackerToCW[requestKey] = (requestInfo.Count + 1, DateTime.Now); |
| | | } |
| | | else |
| | | { |
| | | requestTrackerToCW[requestKey] = (1, DateTime.Now); |
| | | } |
| | | //// 更新请求跟踪信息 |
| | | //if (requestTrackerToCW.ContainsKey(requestKey)) |
| | | //{ |
| | | // requestTrackerToCW[requestKey] = (requestInfo.Count + 1, DateTime.Now); |
| | | //} |
| | | //else |
| | | //{ |
| | | // requestTrackerToCW[requestKey] = (1, DateTime.Now); |
| | | //} |
| | | |
| | | var station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == taskDTO.Position && x.stationStatus == "1"); |
| | | var locations = _locationRepository.QueryData(x => x.RoadwayNo == station.Roadway && x.LocationStatus == (int)LocationEnum.Free && x.LocationType == 1); |
| | |
| | | _locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(location, lastStatus, (int)StatusChangeTypeEnum.AutomaticDelivery, task.TaskNum); |
| | | |
| | | // 返回成功响应 |
| | | requestTrackerToCW.Remove(requestKey); |
| | | //requestTrackerToCW.Remove(requestKey); |
| | | |
| | | return content.OK(data: wmsTask); |
| | | } |
| | |
| | | /// <param name="input">请求数据</param> |
| | | /// <returns></returns> |
| | | [HttpPost, AllowAnonymous, Route("GetFROutTrayToCW")] |
| | | [TypeFilter(typeof(ThrottleFilter), Arguments = new object[] { 5 })] // 5秒节流 |
| | | [TypeFilter(typeof(ThrottleFilter), Arguments = new object[] { 15 })] // 5秒节流 |
| | | public async Task<WebResponseContent> GetFROutTrayToCW([FromBody] RequestTaskDto input) |
| | | { |
| | | return await Service.GetFROutTrayToCW(input); |