添加缓存服务及相关功能支持
- 新增二进制文件。
- 在 `CacheConst.cs` 中定义 Redis 常量。
- 在 `LinqExtension.cs` 中添加 `ContainsAll` 扩展方法。
- 在 `ObjectExtension.cs` 中实现多个 JSON 处理扩展方法。
- 更新 `ISimpleCacheHashService.cs` 和 `ISimpleCacheService.cs` 接口,增加 HashMap 操作方法。
- 添加 `CacheSettingsOptions.cs` 类以配置 Redis 设置。
- 实现内存和 Redis 缓存服务。
- 更新项目引用,确保 `WIDESEA_Cache` 项目被正确引用。
- 在 `Program.cs` 中配置缓存服务的依赖注入和 Redis 连接验证。
- 更新 `appsettings.json` 以包含缓存设置。
¶Ô±ÈÐÂÎļþ |
| | |
| | | namespace WIDESEA_Cache; |
| | | |
| | | /// <summary> |
| | | /// Redis常é |
| | | /// </summary> |
| | | public class CacheConst |
| | | { |
| | | /// <summary> |
| | | /// Redis Keyåç¼(å¯å é¤) |
| | | /// </summary> |
| | | public const string Cache_Prefix_Web = "WIDESEA_WMSServerWeb:"; |
| | | |
| | | /// <summary> |
| | | /// Redis Keyåç¼(éè¦æä¹
åï¼ä¸éç³»ç»éå¯å é¤) |
| | | /// </summary> |
| | | public const string Cache_Prefix = "WIDESEA_WMSServer:"; |
| | | |
| | | /// <summary> |
| | | /// Redis Hashç±»å |
| | | /// </summary> |
| | | public const string Cache_Hash = "Hash"; |
| | | |
| | | /// <summary> |
| | | /// ç³»ç»é
置表ç¼åKey |
| | | /// </summary> |
| | | public const string Cache_DevConfig = Cache_Prefix_Web + "DevConfig:"; |
| | | |
| | | /// <summary> |
| | | /// ç»å½éªè¯ç ç¼åKey |
| | | /// </summary> |
| | | public const string Cache_Captcha = Cache_Prefix_Web + "Captcha:"; |
| | | |
| | | /// <summary> |
| | | /// ç¨æ·è¡¨ç¼åKey |
| | | /// </summary> |
| | | public const string Cache_SysUser = Cache_Prefix_Web + "SysUser"; |
| | | |
| | | /// <summary> |
| | | /// ç¨æ·ææºå·å
³ç³»ç¼åKey |
| | | /// </summary> |
| | | public const string Cache_SysUserPhone = Cache_Prefix_Web + "SysUserPhone"; |
| | | |
| | | /// <summary> |
| | | /// ç¨æ·Tokenç¼åKey |
| | | /// </summary> |
| | | public const string Cache_UserToken = Cache_Prefix + "UserToken"; |
| | | |
| | | /// <summary> |
| | | /// WMSåºåç¼åKey |
| | | /// </summary>Cache_AutoModel |
| | | public const string Cache_DtStockInfo = Cache_Prefix + "DtStockInfo"; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | namespace WIDESEA_Cache; |
| | | |
| | | /// <summary> |
| | | /// Linqæ©å± |
| | | /// </summary> |
| | | public static class LinqExtension |
| | | { |
| | | /// <summary> |
| | | /// æ¯å¦é½å
å« |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="first">第ä¸ä¸ªå表</param> |
| | | /// <param name="secend">第äºä¸ªå表</param> |
| | | /// <returns></returns> |
| | | public static bool ContainsAll<T>(this List<T> first, List<T> secend) |
| | | { |
| | | return secend.All(s => first.Any(f => f.Equals(s))); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Linq; |
| | | |
| | | namespace WIDESEA_Cache; |
| | | /// <summary> |
| | | /// objectæå± |
| | | /// </summary> |
| | | public static class ObjectExtension |
| | | { |
| | | /// <summary> |
| | | /// jsonå符串åºåå |
| | | /// </summary> |
| | | /// <param name="json"></param> |
| | | /// <returns></returns> |
| | | public static object ToObject(this string json) |
| | | { |
| | | return string.IsNullOrEmpty(json) ? null : JsonConvert.DeserializeObject(json); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// jsonå符串åºåå |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="json"></param> |
| | | /// <returns></returns> |
| | | public static T ToObject<T>(this string json) |
| | | { |
| | | if (json != null) |
| | | { |
| | | json = json.Replace(" ", ""); |
| | | return JsonConvert.DeserializeObject<T>(json); |
| | | } |
| | | else return default; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// jsonå符串åºåå |
| | | /// </summary> |
| | | /// <param name="json"></param> |
| | | /// <returns></returns> |
| | | public static JObject ToJObject(this string json) |
| | | { |
| | | return json == null ? JObject.Parse("{}") : JObject.Parse(json.Replace(" ", "")); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | global using Masuit.Tools; |
| | | global using Microsoft.AspNetCore.Builder; |
| | | global using Microsoft.AspNetCore.Hosting; |
| | | global using Microsoft.Extensions.DependencyInjection; |
| | | global using NewLife.Caching; |
| | | global using NewLife.Serialization; |
| | | global using SimpleRedis; |
¶Ô±ÈÐÂÎļþ |
| | |
| | | namespace WIDESEA_Cache; |
| | | |
| | | /// <summary> |
| | | /// ç¼åæå¡ |
| | | /// </summary> |
| | | public partial interface ISimpleCacheService |
| | | { |
| | | /// <summary> |
| | | /// æ·»å 䏿¡æ°æ®å°HashMap |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="key">é®</param> |
| | | /// <param name="hashKey">hashå表éçKey</param> |
| | | /// <param name="value">å¼</param> |
| | | void HashAdd<T>(string key, string hashKey, T value); |
| | | |
| | | /// <summary> |
| | | /// æ·»å 夿¡æ°æ®å°HashMap |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="key">é®</param> |
| | | /// <param name="dic">é®å¼å¯¹åå
¸</param> |
| | | /// <returns></returns> |
| | | bool HashSet<T>(string key, Dictionary<string, T> dic); |
| | | |
| | | /// <summary> |
| | | /// ä»HashMapä¸å 餿°æ® |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="key">é®</param> |
| | | /// <param name="fields">hashé®å表</param> |
| | | /// <returns>æ§è¡ç»æ</returns> |
| | | int HashDel<T>(string key, params string[] fields); |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®é®è·åhashå表ä¸çå¼ |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="key">é®</param> |
| | | /// <param name="fields">hashé®å表</param> |
| | | /// <returns>æ°æ®å表</returns> |
| | | List<T> HashGet<T>(string key, params string[] fields); |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®é®è·åhashå表ä¸çå¼ |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="key">é®</param> |
| | | /// <param name="field">hashé®</param> |
| | | /// <returns></returns> |
| | | T HashGetOne<T>(string key, string field); |
| | | |
| | | /// <summary> |
| | | /// è·åææé®å¼å¯¹ |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="key">é®</param> |
| | | /// <returns>æ°æ®åå
¸</returns> |
| | | IDictionary<string, T> HashGetAll<T>(string key); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | namespace WIDESEA_Cache; |
| | | |
| | | /// <summary> |
| | | /// ç¼åæå¡ |
| | | /// </summary> |
| | | public partial interface ISimpleCacheService |
| | | { |
| | | #region åºç¡æä½ |
| | | |
| | | /// <summary>æ¯å¦å
å«ç¼å项</summary> |
| | | /// <param name="key"></param> |
| | | /// <returns></returns> |
| | | bool ContainsKey(string key); |
| | | |
| | | /// <summary>设置ç¼å项</summary> |
| | | /// <param name="key">é®</param> |
| | | /// <param name="value">å¼</param> |
| | | /// <param name="expire">è¿ææ¶é´ï¼ç§ãå°äº0æ¶éç¨é»è®¤ç¼åæ¶é´</param> |
| | | /// <returns></returns> |
| | | bool Set<T>(string key, T value, int expire = -1); |
| | | |
| | | /// <summary>设置ç¼å项</summary> |
| | | /// <param name="key">é®</param> |
| | | /// <param name="value">å¼</param> |
| | | /// <param name="expire">è¿ææ¶é´</param> |
| | | /// <returns></returns> |
| | | bool Set<T>(string key, T value, TimeSpan expire); |
| | | |
| | | /// <summary>è·åç¼å项</summary> |
| | | /// <param name="key">é®</param> |
| | | /// <returns></returns> |
| | | T Get<T>(string key); |
| | | |
| | | /// <summary>æ¹éç§»é¤ç¼å项</summary> |
| | | /// <param name="keys">é®éå</param> |
| | | /// <returns></returns> |
| | | int Remove(params string[] keys); |
| | | |
| | | /// <summary>æ¸
空ææç¼å项</summary> |
| | | void Clear(); |
| | | |
| | | /// <summary>设置ç¼åé¡¹æææ</summary> |
| | | /// <param name="key">é®</param> |
| | | /// <param name="expire">è¿ææ¶é´</param> |
| | | bool SetExpire(string key, TimeSpan expire); |
| | | |
| | | /// <summary>è·åç¼åé¡¹æææ</summary> |
| | | /// <param name="key">é®</param> |
| | | /// <returns></returns> |
| | | TimeSpan GetExpire(string key); |
| | | |
| | | /// <summary> |
| | | /// 模ç³å é¤ |
| | | /// </summary> |
| | | /// <param name="pattern">å¹é
å
³é®å</param> |
| | | void DelByPattern(string pattern); |
| | | |
| | | #endregion åºç¡æä½ |
| | | |
| | | #region éåæä½ |
| | | |
| | | /// <summary>æ¹éè·åç¼å项</summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="keys"></param> |
| | | /// <returns></returns> |
| | | IDictionary<string, T> GetAll<T>(IEnumerable<string> keys); |
| | | |
| | | /// <summary>æ¹é设置ç¼å项</summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="values"></param> |
| | | /// <param name="expire">è¿ææ¶é´ï¼ç§ãå°äº0æ¶éç¨é»è®¤ç¼åæ¶é´</param> |
| | | void SetAll<T>(IDictionary<string, T> values, int expire = -1); |
| | | |
| | | /// <summary>è·åå表</summary> |
| | | /// <typeparam name="T">å
ç´ ç±»å</typeparam> |
| | | /// <param name="key">é®</param> |
| | | /// <returns></returns> |
| | | IList<T> GetList<T>(string key); |
| | | |
| | | /// <summary>è·ååå¸</summary> |
| | | /// <typeparam name="T">å
ç´ ç±»å</typeparam> |
| | | /// <param name="key">é®</param> |
| | | /// <returns></returns> |
| | | IDictionary<string, T> GetDictionary<T>(string key); |
| | | |
| | | /// <summary>è·åéå</summary> |
| | | /// <typeparam name="T">å
ç´ ç±»å</typeparam> |
| | | /// <param name="key">é®</param> |
| | | /// <returns></returns> |
| | | IProducerConsumer<T> GetQueue<T>(string key); |
| | | |
| | | /// <summary>è·åæ </summary> |
| | | /// <typeparam name="T">å
ç´ ç±»å</typeparam> |
| | | /// <param name="key">é®</param> |
| | | /// <returns></returns> |
| | | IProducerConsumer<T> GetStack<T>(string key); |
| | | |
| | | /// <summary>è·åSet</summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="key"></param> |
| | | /// <returns></returns> |
| | | ICollection<T> GetSet<T>(string key); |
| | | |
| | | #endregion éåæä½ |
| | | |
| | | #region é«çº§æä½ |
| | | |
| | | /// <summary>æ·»å ï¼å·²å卿¶ä¸æ´æ°</summary> |
| | | /// <typeparam name="T">å¼ç±»å</typeparam> |
| | | /// <param name="key">é®</param> |
| | | /// <param name="value">å¼</param> |
| | | /// <param name="expire">è¿ææ¶é´ï¼ç§ãå°äº0æ¶éç¨é»è®¤ç¼åæ¶é´</param> |
| | | /// <returns></returns> |
| | | bool Add<T>(string key, T value, int expire = -1); |
| | | |
| | | /// <summary>设置æ°å¼å¹¶è·åæ§å¼ï¼ååæä½</summary> |
| | | /// <remarks> |
| | | /// 常常é
åIncrement使ç¨ï¼ç¨äºç´¯å å°ä¸å®æ°åéç½®å½é¶ï¼åé¿å
å¤çº¿ç¨å²çªã |
| | | /// </remarks> |
| | | /// <typeparam name="T">å¼ç±»å</typeparam> |
| | | /// <param name="key">é®</param> |
| | | /// <param name="value">å¼</param> |
| | | /// <returns></returns> |
| | | T Replace<T>(string key, T value); |
| | | |
| | | /// <summary>å°è¯è·åæå®é®ï¼è¿åæ¯å¦å
å«å¼ãæå¯è½ç¼å项å好æ¯é»è®¤å¼ï¼æè
åªæ¯ååºåå失败ï¼è§£å³ç¼åç©¿éé®é¢</summary> |
| | | /// <typeparam name="T">å¼ç±»å</typeparam> |
| | | /// <param name="key">é®</param> |
| | | /// <param name="value">å¼ãå³ä½¿æå¼ä¹ä¸ä¸å®è½å¤è¿åï¼å¯è½ç¼å项å好æ¯é»è®¤å¼ï¼æè
åªæ¯ååºåå失败</param> |
| | | /// <returns>è¿åæ¯å¦å
å«å¼ï¼å³ä½¿ååºåå失败</returns> |
| | | bool TryGetValue<T>(string key, out T value); |
| | | |
| | | /// <summary>ç´¯å ï¼ååæä½</summary> |
| | | /// <param name="key">é®</param> |
| | | /// <param name="value">ååé</param> |
| | | /// <returns></returns> |
| | | long Increment(string key, long value); |
| | | |
| | | /// <summary>ç´¯å ï¼ååæä½</summary> |
| | | /// <param name="key">é®</param> |
| | | /// <param name="value">ååé</param> |
| | | /// <returns></returns> |
| | | double Increment(string key, double value); |
| | | |
| | | /// <summary>éåï¼ååæä½</summary> |
| | | /// <param name="key">é®</param> |
| | | /// <param name="value">ååé</param> |
| | | /// <returns></returns> |
| | | long Decrement(string key, long value); |
| | | |
| | | /// <summary>éåï¼ååæä½</summary> |
| | | /// <param name="key">é®</param> |
| | | /// <param name="value">ååé</param> |
| | | /// <returns></returns> |
| | | double Decrement(string key, double value); |
| | | |
| | | #endregion é«çº§æä½ |
| | | |
| | | #region äºå¡ |
| | | |
| | | /// <summary>æäº¤åæ´ãé¨åæä¾è
éè¦å·ç</summary> |
| | | /// <returns></returns> |
| | | int Commit(); |
| | | |
| | | /// <summary>ç³è¯·åå¸å¼é</summary> |
| | | /// <param name="key">è¦éå®çkey</param> |
| | | /// <param name="msTimeout">éçå¾
æ¶é´ï¼å使¯«ç§</param> |
| | | /// <returns></returns> |
| | | IDisposable AcquireLock(string key, int msTimeout); |
| | | |
| | | /// <summary>ç³è¯·åå¸å¼é</summary> |
| | | /// <param name="key">è¦éå®çkey</param> |
| | | /// <param name="msTimeout">éçå¾
æ¶é´ï¼ç³è¯·å 鿶妿éå°å²çªåçå¾
çæå¤§æ¶é´ï¼å使¯«ç§</param> |
| | | /// <param name="msExpire">éè¿ææ¶é´ï¼è¶
è¿è¯¥æ¶é´å¦ææ²¡æä¸»å¨éæ¾åèªå¨éæ¾éï¼å¿
é¡»æ´æ°ç§ï¼å使¯«ç§</param> |
| | | /// <param name="throwOnFailure">å¤±è´¥æ¶æ¯å¦æåºå¼å¸¸ï¼å¦æä¸æåºå¼å¸¸ï¼å¯éè¿è¿ånullå¾ç¥ç³è¯·é失败</param> |
| | | /// <returns></returns> |
| | | IDisposable AcquireLock(string key, int msTimeout, int msExpire, bool throwOnFailure); |
| | | |
| | | #endregion äºå¡ |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | //using Furion.ConfigurableOptions; |
| | | using WIDESEA_Core.Core; |
| | | |
| | | namespace WIDESEA_Cache; |
| | | |
| | | /// <summary> |
| | | /// ç¼å设置 |
| | | /// </summary> |
| | | public class CacheSettingsOptions : IConfigurableOptions |
| | | { |
| | | /// <summary> |
| | | /// 使ç¨Redis |
| | | /// </summary> |
| | | public bool UseRedis { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æ¯å¦æ¯æ¬¡å¯å¨é½æ¸
空 |
| | | /// </summary> |
| | | public RedisSettings RedisSettings { get; set; } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Redis设置 |
| | | /// </summary> |
| | | public class RedisSettings |
| | | { |
| | | /// <summary> |
| | | /// è¿æ¥å°å |
| | | /// </summary> |
| | | public string Address { get; set; } |
| | | |
| | | /// <summary> |
| | | /// å¯ç |
| | | /// </summary> |
| | | public string Password { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æ°æ®åº |
| | | /// </summary> |
| | | public int Db { get; set; } = 0; |
| | | |
| | | /// <summary> |
| | | /// æ¯å¦æ¯æ¬¡å¯å¨é½æ¸
空 |
| | | /// </summary> |
| | | public bool ClearRedis { get; set; } = false; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | namespace WIDESEA_Cache; |
| | | |
| | | /// <summary> |
| | | /// <inheritdoc cref="ISimpleCacheService"/> |
| | | /// å
åç¼å |
| | | /// </summary> |
| | | public partial class MemoryCacheService : ISimpleCacheService |
| | | { |
| | | /// <inheritdoc/> |
| | | public void HashAdd<T>(string key, string hashKey, T value) |
| | | { |
| | | //è·ååå
¸ |
| | | var exist = _memoryCache.GetDictionary<T>(key); |
| | | if (exist.ContainsKey(hashKey))//妿å
å«Key |
| | | exist[hashKey] = value;//éæ°èµå¼ |
| | | else exist.Add(hashKey, value);//å 䏿°çå¼ |
| | | _memoryCache.Set(key, exist); |
| | | } |
| | | |
| | | //private IDictionary<string,T> GetDictionary(string key,string) |
| | | |
| | | /// <inheritdoc/> |
| | | public bool HashSet<T>(string key, Dictionary<string, T> dic) |
| | | { |
| | | //è·ååå
¸ |
| | | var exist = _memoryCache.GetDictionary<T>(key); |
| | | dic.ForEach(it => |
| | | { |
| | | if (exist.ContainsKey(it.Key))//妿å
å«Key |
| | | exist[it.Key] = it.Value;//éæ°èµå¼ |
| | | else exist.Add(it.Key, it.Value);//å 䏿°çå¼ |
| | | }); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public int HashDel<T>(string key, params string[] fields) |
| | | { |
| | | int result = 0; |
| | | //è·ååå
¸ |
| | | var exist = _memoryCache.GetDictionary<T>(key); |
| | | foreach (var field in fields) |
| | | { |
| | | if (field != null && exist.ContainsKey(field))//妿å
å«Key |
| | | { |
| | | exist.Remove(field);//å é¤ |
| | | result++; |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public List<T> HashGet<T>(string key, params string[] fields) |
| | | { |
| | | List<T> list = new List<T>(); |
| | | //è·ååå
¸ |
| | | var exist = _memoryCache.GetDictionary<T>(key); |
| | | foreach (var field in fields) |
| | | { |
| | | if (exist.ContainsKey(field))//妿å
å«Key |
| | | { |
| | | list.Add(exist[field]); |
| | | } |
| | | else { list.Add(default); } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public T HashGetOne<T>(string key, string field) |
| | | { |
| | | //è·ååå
¸ |
| | | var exist = _memoryCache.GetDictionary<T>(key); |
| | | |
| | | exist.TryGetValue(field, out T result); |
| | | var data = result.DeepClone(); |
| | | return data; |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public IDictionary<string, T> HashGetAll<T>(string key) |
| | | { |
| | | var data = _memoryCache.GetDictionary<T>(key); |
| | | return data; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | namespace WIDESEA_Cache; |
| | | |
| | | /// <summary> |
| | | /// <inheritdoc cref="ISimpleCacheService"/> |
| | | /// å
åç¼å |
| | | /// </summary> |
| | | public partial class MemoryCacheService : ISimpleCacheService |
| | | { |
| | | public readonly MemoryCache _memoryCache; |
| | | |
| | | public MemoryCacheService() |
| | | { |
| | | _memoryCache = new MemoryCache(); |
| | | } |
| | | |
| | | #region æ®éæä½ |
| | | |
| | | /// <inheritdoc/> |
| | | public T Get<T>(string key) |
| | | { |
| | | var data = _memoryCache.Get<string>(key); |
| | | return data.ToObject<T>(); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public int Remove(params string[] keys) |
| | | { |
| | | return _memoryCache.Remove(keys); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public bool Set<T>(string key, T value, int expire = -1) |
| | | { |
| | | return _memoryCache.Set(key, value.ToJson(), expire); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public bool Set<T>(string key, T value, TimeSpan expire) |
| | | { |
| | | return _memoryCache.Set(key, value.ToJson(), expire); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public bool SetExpire(string key, TimeSpan expire) |
| | | { |
| | | return _memoryCache.SetExpire(key, expire); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public TimeSpan GetExpire(string key) |
| | | { |
| | | return _memoryCache.GetExpire(key); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public bool ContainsKey(string key) |
| | | { |
| | | return _memoryCache.ContainsKey(key); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public void Clear() |
| | | { |
| | | _memoryCache.Clear(); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public void DelByPattern(string pattern) |
| | | { |
| | | var keys = _memoryCache.Keys.ToList();//è·åæækey |
| | | keys.ForEach(it => |
| | | { |
| | | if (it.Contains(pattern))//妿å¹é
|
| | | _memoryCache.Remove(pattern); |
| | | }); |
| | | } |
| | | |
| | | #endregion æ®éæä½ |
| | | |
| | | #region éåæä½ |
| | | |
| | | /// <inheritdoc/> |
| | | public IDictionary<string, T> GetAll<T>(IEnumerable<string> keys) |
| | | { |
| | | IDictionary<string, T>? result = default;//å®ä¹éå |
| | | IDictionary<string, string>? data = _memoryCache.GetAll<string>(keys);//è·åæ°æ® |
| | | data.ForEach(it => |
| | | { |
| | | result.Add(it.Key, it.Value.ToObject<T>());//éåæ°æ®,æ ¼å¼åå¹¶å å°æ°çæ°æ®éå |
| | | }); |
| | | return result; |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public void SetAll<T>(IDictionary<string, T> values, int expire = -1) |
| | | { |
| | | IDictionary<string, string>? result = default;//å®ä¹éå |
| | | values.ForEach(it => |
| | | { |
| | | result.Add(it.Key, it.Value.ToJson());//éåæ°æ®,æ ¼å¼åå¹¶å å°æ°çæ°æ®éå |
| | | }); |
| | | _memoryCache.SetAll(values, expire); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public IDictionary<string, T> GetDictionary<T>(string key) |
| | | { |
| | | IDictionary<string, T>? result = default;//å®ä¹éå |
| | | var data = _memoryCache.GetDictionary<string>(key); |
| | | data.ForEach(it => |
| | | { |
| | | result.Add(it.Key, it.Value.ToObject<T>());//éåæ°æ®,æ ¼å¼åå¹¶å å°æ°çæ°æ®éå |
| | | }); |
| | | return result; |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public IProducerConsumer<T> GetQueue<T>(string key) |
| | | { |
| | | return _memoryCache.GetQueue<T>(key); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public IProducerConsumer<T> GetStack<T>(string key) |
| | | { |
| | | return _memoryCache.GetStack<T>(key); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public ICollection<T> GetSet<T>(string key) |
| | | { |
| | | return _memoryCache.GetSet<T>(key); |
| | | } |
| | | |
| | | #endregion éåæä½ |
| | | |
| | | #region é«çº§æä½ |
| | | |
| | | /// <inheritdoc/> |
| | | public bool Add<T>(string key, T value, int expire = -1) |
| | | { |
| | | return _memoryCache.Add(key, value.ToJson(), expire); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public IList<T> GetList<T>(string key) |
| | | { |
| | | IList<T> result = default;//å®ä¹éå |
| | | var data = _memoryCache.GetList<string>(key); |
| | | data.ForEach(it => |
| | | { |
| | | result.Add(it.ToObject<T>());//éåæ°æ®,æ ¼å¼åå¹¶å å°æ°çæ°æ®éå |
| | | }); |
| | | return result; |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public T Replace<T>(string key, T value) |
| | | { |
| | | return _memoryCache.Replace(key, value); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public bool TryGetValue<T>(string key, out T value) |
| | | { |
| | | var result = string.Empty; |
| | | _ = _memoryCache.TryGetValue<string>(key, out result); |
| | | value = result.ToObject<T>(); |
| | | return value == null; |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public long Decrement(string key, long value) |
| | | { |
| | | return _memoryCache.Decrement(key, value); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public double Decrement(string key, double value) |
| | | { |
| | | return _memoryCache.Decrement(key, value); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public long Increment(string key, long value) |
| | | { |
| | | return _memoryCache.Increment(key, value); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public double Increment(string key, double value) |
| | | { |
| | | return _memoryCache.Increment(key, value); |
| | | } |
| | | |
| | | #endregion é«çº§æä½ |
| | | |
| | | #region äºå¡ |
| | | |
| | | /// <inheritdoc/> |
| | | public int Commit() |
| | | { |
| | | return _memoryCache.Commit(); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public IDisposable AcquireLock(string key, int msTimeout) |
| | | { |
| | | return _memoryCache.AcquireLock(key, msTimeout); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public IDisposable AcquireLock(string key, int msTimeout, int msExpire, bool throwOnFailure) |
| | | { |
| | | return _memoryCache.AcquireLock(key, msTimeout, msExpire, throwOnFailure); |
| | | } |
| | | |
| | | #endregion äºå¡ |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | namespace WIDESEA_Cache; |
| | | |
| | | /// <summary> |
| | | /// <inheritdoc cref="ISimpleCacheService"/> |
| | | /// Redisç¼å |
| | | /// </summary> |
| | | |
| | | public partial class RedisCacheService : ISimpleCacheService |
| | | { |
| | | /// <inheritdoc/> |
| | | public void HashAdd<T>(string key, string hashKey, T value) |
| | | { |
| | | _simpleRedis.HashAdd<T>(key, hashKey, value); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public bool HashSet<T>(string key, Dictionary<string, T> dic) |
| | | { |
| | | return _simpleRedis.HashSet<T>(key, dic); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public int HashDel<T>(string key, params string[] fields) |
| | | { |
| | | return _simpleRedis.HashDel<T>(key, fields); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public List<T> HashGet<T>(string key, params string[] fields) |
| | | { |
| | | return _simpleRedis.HashGet<T>(key, fields); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public T HashGetOne<T>(string key, string field) |
| | | { |
| | | return _simpleRedis.HashGetOne<T>(key, field); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public IDictionary<string, T> HashGetAll<T>(string key) |
| | | { |
| | | return _simpleRedis.HashGetAll<T>(key); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | namespace WIDESEA_Cache; |
| | | |
| | | /// <summary> |
| | | /// <inheritdoc cref="ISimpleCacheService"/> |
| | | /// Redisç¼å |
| | | /// </summary> |
| | | public partial class RedisCacheService : ISimpleCacheService |
| | | { |
| | | private readonly ISimpleRedis _simpleRedis; |
| | | |
| | | public RedisCacheService(ISimpleRedis simpleRedis) |
| | | { |
| | | this._simpleRedis = simpleRedis; |
| | | } |
| | | |
| | | #region æ®éæä½ |
| | | |
| | | /// <inheritdoc/> |
| | | public T Get<T>(string key) |
| | | { |
| | | return _simpleRedis.Get<T>(key); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public int Remove(params string[] keys) |
| | | { |
| | | return _simpleRedis.GetFullRedis().Remove(keys); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public bool Set<T>(string key, T value, int expire = -1) |
| | | { |
| | | return _simpleRedis.Set(key, value, expire); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public bool Set<T>(string key, T value, TimeSpan expire) |
| | | { |
| | | return _simpleRedis.Set(key, value, expire); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public bool SetExpire(string key, TimeSpan expire) |
| | | { |
| | | return _simpleRedis.GetFullRedis().SetExpire(key, expire); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public TimeSpan GetExpire(string key) |
| | | { |
| | | return _simpleRedis.GetFullRedis().GetExpire(key); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public bool ContainsKey(string key) |
| | | { |
| | | return _simpleRedis.ContainsKey(key); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public void Clear() |
| | | { |
| | | _simpleRedis.Clear(); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public void DelByPattern(string pattern) |
| | | { |
| | | _simpleRedis.DelByPattern(pattern); |
| | | } |
| | | |
| | | #endregion æ®éæä½ |
| | | |
| | | #region éåæä½ |
| | | |
| | | /// <inheritdoc/> |
| | | public IDictionary<string, T> GetAll<T>(IEnumerable<string> keys) |
| | | { |
| | | return _simpleRedis.GetFullRedis().GetAll<T>(keys); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public void SetAll<T>(IDictionary<string, T> values, int expire = -1) |
| | | { |
| | | _simpleRedis.GetFullRedis().SetAll(values, expire); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public IDictionary<string, T> GetDictionary<T>(string key) |
| | | { |
| | | return _simpleRedis.GetFullRedis().GetDictionary<T>(key); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public IProducerConsumer<T> GetQueue<T>(string key) |
| | | { |
| | | return _simpleRedis.GetFullRedis().GetQueue<T>(key); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public IProducerConsumer<T> GetStack<T>(string key) |
| | | { |
| | | return _simpleRedis.GetFullRedis().GetStack<T>(key); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public ICollection<T> GetSet<T>(string key) |
| | | { |
| | | return _simpleRedis.GetFullRedis().GetSet<T>(key); |
| | | } |
| | | |
| | | #endregion éåæä½ |
| | | |
| | | #region é«çº§æä½ |
| | | |
| | | /// <inheritdoc/> |
| | | public bool Add<T>(string key, T value, int expire = -1) |
| | | { |
| | | return _simpleRedis.GetFullRedis().Add(key, value, expire); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public IList<T> GetList<T>(string key) |
| | | { |
| | | return _simpleRedis.GetFullRedis().GetList<T>(key); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public T Replace<T>(string key, T value) |
| | | { |
| | | return _simpleRedis.GetFullRedis().Replace(key, value); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public bool TryGetValue<T>(string key, out T value) |
| | | { |
| | | return _simpleRedis.GetFullRedis().TryGetValue(key, out value); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public long Decrement(string key, long value) |
| | | { |
| | | return _simpleRedis.GetFullRedis().Decrement(key, value); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public double Decrement(string key, double value) |
| | | { |
| | | return _simpleRedis.GetFullRedis().Decrement(key, value); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public long Increment(string key, long value) |
| | | { |
| | | return _simpleRedis.GetFullRedis().Increment(key, value); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public double Increment(string key, double value) |
| | | { |
| | | return _simpleRedis.GetFullRedis().Increment(key, value); |
| | | } |
| | | |
| | | #endregion é«çº§æä½ |
| | | |
| | | #region äºå¡ |
| | | |
| | | /// <inheritdoc/> |
| | | public int Commit() |
| | | { |
| | | return _simpleRedis.GetFullRedis().Commit(); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public IDisposable AcquireLock(string key, int msTimeout) |
| | | { |
| | | return _simpleRedis.GetFullRedis().AcquireLock(key, msTimeout); |
| | | } |
| | | |
| | | /// <inheritdoc/> |
| | | public IDisposable AcquireLock(string key, int msTimeout, int msExpire, bool throwOnFailure) |
| | | { |
| | | return _simpleRedis.GetFullRedis().AcquireLock(key, msTimeout, msExpire, throwOnFailure); |
| | | } |
| | | |
| | | #endregion äºå¡ |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <Project Sdk="Microsoft.NET.Sdk"> |
| | | |
| | | <PropertyGroup> |
| | | <TargetFramework>net6.0</TargetFramework> |
| | | <ImplicitUsings>enable</ImplicitUsings> |
| | | <Nullable>enable</Nullable> |
| | | </PropertyGroup> |
| | | |
| | | <ItemGroup> |
| | | <PackageReference Include="SimpleRedis" Version="1.1.9" /> |
| | | </ItemGroup> |
| | | |
| | | <ItemGroup> |
| | | <ProjectReference Include="..\WIDESEA_Core\WIDESEA_Core.csproj" /> |
| | | </ItemGroup> |
| | | |
| | | </Project> |
| | |
| | | |
| | | public Task StartAsync(CancellationToken cancellationToken) |
| | | { |
| | | _timer = new Timer(DoWork, null, 0, 10000); |
| | | _timer = new Timer(DoWork, null, TimeSpan.Zero, TimeSpan.FromMinutes(10)); |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | |
| | | using Autofac.Core; |
| | | using Mapster; |
| | | using Masuit.Tools; |
| | | using SqlSugar; |
| | | using System.Text.RegularExpressions; |
| | | using WIDESEA_Cache; |
| | | using WIDESEA_Core.Const; |
| | | using WIDESEA_DTO.MOM; |
| | | using WIDESEA_DTO.WMS; |
| | |
| | | using WIDESEA_IStoragIntegrationServices; |
| | | using WIDESEAWCS_BasicInfoRepository; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | |
| | | |
| | | namespace WIDESEA_StorageTaskServices; |
| | | |
| | |
| | | private readonly IAgingInOrOutInputService _agingInOrOutInputService; //éç½®\éå |
| | | private readonly IDt_StationManagerRepository _stationManagerRepository; |
| | | private readonly ISys_ConfigService _configService; |
| | | private readonly ISimpleCacheService _simpleCacheService; |
| | | |
| | | public Dt_TaskService(IDt_TaskRepository BaseDal, |
| | | IUnitOfWorkManage unitOfWorkManage, |
| | |
| | | IAgingInOrOutInputService agingInOrOutInputService, |
| | | IStockInfoDetailRepository stockInfoDetailRepository, |
| | | IDt_StationManagerRepository stationManagerRepository, |
| | | ISys_ConfigService configService) : base(BaseDal) |
| | | ISys_ConfigService configService, |
| | | ISimpleCacheService simpleCacheService) : base(BaseDal) |
| | | { |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _stockInfoRepository = stockInfoRepository; |
| | |
| | | _stockInfoDetailRepository = stockInfoDetailRepository; |
| | | _stationManagerRepository = stationManagerRepository; |
| | | _configService = configService; |
| | | _simpleCacheService = simpleCacheService; |
| | | } |
| | | |
| | | #region å¤é¨æ¥å£æ¹æ³ |
| | |
| | | return content.Error(result.MOMMessage); |
| | | } |
| | | |
| | | |
| | | if (result.SerialNos.Count <= 0) |
| | | { |
| | | var config = _configService.GetByConfigKey(CateGoryConst.CONFIG_SYS_InStacker, SysConfigConst.InboundIsEmpty); |
| | |
| | | return content.Error("å½åæçæ 产线,èç³»MOMæ·»å 产线"); |
| | | } |
| | | |
| | | |
| | | var stationManagers = _stationManagerRepository.QueryData(x => x.stationType == 6 && x.stationChildCode == input.Position).FirstOrDefault(); |
| | | if (stationManagers == null) |
| | | { |
| | |
| | | |
| | | //ConsoleHelper.WriteColorLine(JsonConvert.SerializeObject(stockInfo), ConsoleColor.DarkMagenta); |
| | | |
| | | |
| | | // æ°å¢éå¤ä»»å¡æ ¡éª |
| | | var hasTask = BaseDal.QueryFirst(x => x.PalletCode == stockInfo.PalletCode); |
| | | if (hasTask != null) |
| | |
| | | } |
| | | |
| | | var outBoundMateriel = AppSettings.app<OutBoundMateriel>("OutBoundMateriel"); |
| | | List<string> materielCodes = null; |
| | | if (outBoundMateriel.Count != 0) |
| | | List<string>? materielCodes = outBoundMateriel.Count != 0 |
| | | ? outBoundMateriel.Where(x => x.ProductionLine == productionLine && x.ProcessCode == area.AreaCode) |
| | | .Select(x => x.MaterielCode) |
| | | .ToList() |
| | | : null; |
| | | |
| | | IDictionary<string, DtStockInfo>? stockInfos = _simpleCacheService.HashGetAll<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo); |
| | | List<DtStockInfo> stockInfoList = stockInfos.Values.ToList(); |
| | | var result = new DtStockInfo(); |
| | | |
| | | if (stockInfoList.IsNullOrEmpty()) |
| | | { |
| | | materielCodes = outBoundMateriel.Where(x => x.ProductionLine == productionLine && x.ProcessCode == area.AreaCode).Select(x => x.MaterielCode).ToList(); |
| | | stockInfoList = await _stockInfoRepository.Db.Queryable<DtStockInfo>() |
| | | .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock).IncludesAllFirstLayer().ToListAsync(); |
| | | } |
| | | |
| | | var result = await _stockInfoRepository.Db.Queryable<DtStockInfo>() |
| | | .Includes(x => x.LocationInfo) // é¢å è½½LocationInfo |
| | | .Includes(x => x.StockInfoDetails) // é¢å è½½StockInfoDetails |
| | | .Where(x => x.AreaCode == areaCode && x.OutboundTime < DateTime.Now && x.IsFull == true) // è¿æ»¤æ¡ä»¶ |
| | | .WhereIF(!productionLine.IsNullOrEmpty(), x => x.ProductionLine == productionLine) |
| | | .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable) // è¿æ»¤æ¡ä»¶ |
| | | .WhereIF(!devices.IsNullOrEmpty(), x => devices.Contains(x.LocationInfo.RoadwayNo)) |
| | | .WhereIF(!materielCodes.IsNullOrEmpty(), x => x.StockInfoDetails.Any(y => materielCodes.Contains(y.MaterielCode))) |
| | | .OrderBy(x => x.OutboundTime) // æåº |
| | | .FirstAsync(); // è·å第ä¸ä¸ªå
ç´ |
| | | result = stockInfoList.Where(x => x.AreaCode == areaCode && x.OutboundTime < DateTime.Now && x.IsFull) |
| | | .WhereIF(!productionLine.IsNullOrEmpty(), x => x.ProductionLine == productionLine) |
| | | .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable) |
| | | .WhereIF(!devices.IsNullOrEmpty(), x => devices.Contains(x.LocationInfo.RoadwayNo)) |
| | | .WhereIF(!materielCodes.IsNullOrEmpty(), x => x.StockInfoDetails.Any(y => materielCodes.Contains(y.MaterielCode))) |
| | | .OrderBy(x => x.OutboundTime) |
| | | .FirstOrDefault(); |
| | | |
| | | //var firstOrDefault = result.FirstOrDefault(x => roadways.Contains(x.LocationInfo.RoadwayNo)); // æ¥æ¾ç¬¬ä¸ä¸ªå¹é
çå
ç´ |
| | | //var firstOrDefault = result[0]; // æ¥æ¾ç¬¬ä¸ä¸ªå¹é
çå
ç´ |
| | | //return firstOrDefault; |
| | | if (result != null) |
| | | { |
| | | stockInfoList = stockInfoList.Where(x => x != result).ToList(); |
| | | if (stockInfos.IsNullOrEmpty()) |
| | | { |
| | | foreach (var item in stockInfoList) |
| | | { |
| | | _simpleCacheService.HashAdd(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, item.PalletCode, item); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { result.PalletCode }); |
| | | } |
| | | } |
| | | |
| | | return result; |
| | | |
| | | if (stockInfoList.IsNullOrEmpty()) |
| | | { |
| | | stockInfoList = await _stockInfoRepository.Db.Queryable<DtStockInfo>().IncludesAllFirstLayer().ToListAsync(); |
| | | |
| | | result = stockInfoList.Where(x => x.AreaCode == areaCode && x.OutboundTime < DateTime.Now && x.IsFull == true) |
| | | .WhereIF(!productionLine.IsNullOrEmpty(), x => x.ProductionLine == productionLine) |
| | | .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable) // è¿æ»¤æ¡ä»¶ |
| | | .WhereIF(!devices.IsNullOrEmpty(), x => devices.Contains(x.LocationInfo.RoadwayNo)) |
| | | .WhereIF(!materielCodes.IsNullOrEmpty(), x => x.StockInfoDetails.Any(y => materielCodes.Contains(y.MaterielCode))) |
| | | .OrderBy(x => x.OutboundTime) // æåº |
| | | .FirstOrDefault(); // è·å第ä¸ä¸ªå
ç´ |
| | | |
| | | if (result != null) |
| | | { |
| | | // æé¤ result ä¸çå
ç´ |
| | | stockInfoList = stockInfoList.Where(x => x != result).ToList(); |
| | | } |
| | | foreach (var item in stockInfoList) |
| | | { |
| | | _simpleCacheService.HashAdd(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, item.PalletCode, item); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | result = stockInfoList.Where(x => x.AreaCode == areaCode && x.OutboundTime < DateTime.Now && x.IsFull == true) |
| | | .WhereIF(!productionLine.IsNullOrEmpty(), x => x.ProductionLine == productionLine) |
| | | .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable) // è¿æ»¤æ¡ä»¶ |
| | | .WhereIF(!devices.IsNullOrEmpty(), x => devices.Contains(x.LocationInfo.RoadwayNo)) |
| | | .WhereIF(!materielCodes.IsNullOrEmpty(), x => x.StockInfoDetails.Any(y => materielCodes.Contains(y.MaterielCode))) |
| | | .OrderBy(x => x.OutboundTime) // æåº |
| | | .FirstOrDefault(); // è·å第ä¸ä¸ªå
ç´ |
| | | if (result != null) |
| | | { |
| | | // æé¤ result ä¸çå
ç´ |
| | | stockInfoList = stockInfoList.Where(x => x != result).ToList(); |
| | | } |
| | | string[] xfasd = new string[] { result.PalletCode }; |
| | | _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { result.PalletCode }); |
| | | } |
| | | |
| | | #region |
| | | //var result = await _stockInfoRepository.Db.Queryable<DtStockInfo>() |
| | | // .Includes(x => x.LocationInfo) // é¢å è½½LocationInfo |
| | | // .Includes(x => x.StockInfoDetails) // é¢å è½½StockInfoDetails |
| | | // .Where(x => x.AreaCode == areaCode && x.OutboundTime < DateTime.Now && x.IsFull == true) // è¿æ»¤æ¡ä»¶ |
| | | // .WhereIF(!productionLine.IsNullOrEmpty(), x => x.ProductionLine == productionLine) |
| | | // .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable) // è¿æ»¤æ¡ä»¶ |
| | | // .WhereIF(!devices.IsNullOrEmpty(), x => devices.Contains(x.LocationInfo.RoadwayNo)) |
| | | // .WhereIF(!materielCodes.IsNullOrEmpty(), x => x.StockInfoDetails.Any(y => materielCodes.Contains(y.MaterielCode))) |
| | | // .OrderBy(x => x.OutboundTime) // æåº |
| | | // .FirstAsync(); // è·å第ä¸ä¸ªå
ç´ |
| | | #endregion |
| | | |
| | | return result; |
| | | } |
| | | |
| | |
| | | ConsoleHelper.WriteErrorLine($"æ¥è¯¢å¸¸æ¸©å®çåºåä¿¡æ¯æ¶,æªæ¾å°åºå代ç 为{JsonConvert.SerializeObject(areaCodes)}çæ°æ®"); |
| | | return null; |
| | | } |
| | | |
| | | |
| | | var outBoundMateriel = AppSettings.app<OutBoundMateriel>("OutBoundMateriel"); |
| | | List<string> materielCodes = null; |
| | |
| | | .WhereIF(!materielCodes.IsNullOrEmpty(), x => x.StockInfoDetails.Any(y => materielCodes.Contains(y.MaterielCode))) |
| | | .OrderBy(x => x.OutboundTime) // æåº |
| | | .FirstAsync(); // è·å第ä¸ä¸ªå
ç´ |
| | | |
| | | //var firstOrDefault = result.FirstOrDefault(x => roadways.Contains(x.LocationInfo.RoadwayNo)); // æ¥æ¾ç¬¬ä¸ä¸ªå¹é
çå
ç´ |
| | | //var firstOrDefault = result[0]; // æ¥æ¾ç¬¬ä¸ä¸ªå¹é
çå
ç´ |
| | | //return firstOrDefault; |
| | | return result; |
| | | } |
| | | |
| | |
| | | |
| | | ConsoleHelper.WriteColorLine(station.Roadway, ConsoleColor.Magenta); |
| | | var stackers = station.Roadway.Split(',').ToList(); |
| | | |
| | | |
| | | var devices = SqlSugarHelper.DbWCS.Queryable<Dt_DeviceInfo>() |
| | | .Where(x => x.DeviceStatus == "1") |
| | |
| | | // content.Error(ex.Message); |
| | | //} |
| | | //return content; |
| | | #endregion |
| | | #endregion éç½®å¼å¸¸å£å
¥åº |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | |
| | | return content; |
| | | } |
| | | |
| | | |
| | | private WMSTaskDTO CreateWMSTaskDTO(object source) |
| | | { |
| | | if (source is Dt_Task taskOld) |
| | |
| | | #endregion éç½®å¼å¸¸å£å
¥åº |
| | | |
| | | #endregion å¤é¨æ¥å£æ¹æ³ |
| | | |
| | | |
| | | |
| | | #region å
é¨è°ç¨æ¹æ³ |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // æ·»å åå²ä»»å¡ |
| | | var isTaskHtyAdd = await _task_HtyRepository.AddDataAsync(taskHty) > 0; |
| | | |
| | |
| | | } |
| | | |
| | | #region ä»»å¡è¯·æ±æ¹æ³ |
| | | |
| | | |
| | | private static readonly SemaphoreSlim _semaphoreUpdate = new SemaphoreSlim(1, 1); |
| | | // æ´æ°ä»»å¡è´§ä½ |
| | |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | throw; |
| | | } |
| | | finally { _semaphoreUpdate.Release(); } |
| | |
| | | return content; |
| | | } |
| | | |
| | | |
| | | private static readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1); |
| | | |
| | | /// <summary> |
| | | /// æ¥æ¾è´§ä½ |
| | | /// </summary> |
| | |
| | | |
| | | <ItemGroup> |
| | | <ProjectReference Include="..\LogLibrary\LogLibrary.csproj" /> |
| | | <ProjectReference Include="..\WIDESEA_Cache\WIDESEA_Cache.csproj" /> |
| | | <ProjectReference Include="..\WIDESEA_IBusinessServices\WIDESEA_IBusinessServices.csproj" /> |
| | | <ProjectReference Include="..\WIDESEA_IStorageBasicService\WIDESEA_IStorageBasicServices.csproj" /> |
| | | <ProjectReference Include="..\WIDESEA_IStorageOutOrderService\WIDESEA_IStorageOutOrderServices.csproj" /> |
| | |
| | | EndProject |
| | | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WIDESEA_IStoragIntegrationServices", "WIDESEA_IStoragIntegrationServices\WIDESEA_IStoragIntegrationServices.csproj", "{94D572FA-810E-4897-B673-AF988FD4019E}" |
| | | EndProject |
| | | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WIDESEA_Cache", "WIDESEA_Cache\WIDESEA_Cache.csproj", "{461A73BF-9FC7-4BFE-9BEB-2AE686CBFEEC}" |
| | | EndProject |
| | | Global |
| | | GlobalSection(SolutionConfigurationPlatforms) = preSolution |
| | | Debug|Any CPU = Debug|Any CPU |
| | |
| | | {94D572FA-810E-4897-B673-AF988FD4019E}.Release|Any CPU.Build.0 = Release|Any CPU |
| | | {94D572FA-810E-4897-B673-AF988FD4019E}.Release|x86.ActiveCfg = Release|Any CPU |
| | | {94D572FA-810E-4897-B673-AF988FD4019E}.Release|x86.Build.0 = Release|Any CPU |
| | | {461A73BF-9FC7-4BFE-9BEB-2AE686CBFEEC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
| | | {461A73BF-9FC7-4BFE-9BEB-2AE686CBFEEC}.Debug|Any CPU.Build.0 = Debug|Any CPU |
| | | {461A73BF-9FC7-4BFE-9BEB-2AE686CBFEEC}.Debug|x86.ActiveCfg = Debug|Any CPU |
| | | {461A73BF-9FC7-4BFE-9BEB-2AE686CBFEEC}.Debug|x86.Build.0 = Debug|Any CPU |
| | | {461A73BF-9FC7-4BFE-9BEB-2AE686CBFEEC}.Dev|Any CPU.ActiveCfg = Release|Any CPU |
| | | {461A73BF-9FC7-4BFE-9BEB-2AE686CBFEEC}.Dev|Any CPU.Build.0 = Release|Any CPU |
| | | {461A73BF-9FC7-4BFE-9BEB-2AE686CBFEEC}.Dev|x86.ActiveCfg = Release|Any CPU |
| | | {461A73BF-9FC7-4BFE-9BEB-2AE686CBFEEC}.Dev|x86.Build.0 = Release|Any CPU |
| | | {461A73BF-9FC7-4BFE-9BEB-2AE686CBFEEC}.Release|Any CPU.ActiveCfg = Release|Any CPU |
| | | {461A73BF-9FC7-4BFE-9BEB-2AE686CBFEEC}.Release|Any CPU.Build.0 = Release|Any CPU |
| | | {461A73BF-9FC7-4BFE-9BEB-2AE686CBFEEC}.Release|x86.ActiveCfg = Release|Any CPU |
| | | {461A73BF-9FC7-4BFE-9BEB-2AE686CBFEEC}.Release|x86.Build.0 = Release|Any CPU |
| | | EndGlobalSection |
| | | GlobalSection(SolutionProperties) = preSolution |
| | | HideSolutionNode = FALSE |
| | |
| | | using Swashbuckle.AspNetCore.SwaggerGen; |
| | | using Microsoft.OpenApi.Models; |
| | | using WIDESEA_StorageTaskServices; |
| | | using Autofac.Core; |
| | | using WIDESEA_Cache; |
| | | using SimpleRedis; |
| | | using WIDESEA_DTO.WMS; |
| | | using static NewLife.Remoting.ApiHttpClient; |
| | | using NewLife.Windows; |
| | | |
| | | var builder = WebApplication.CreateBuilder(args); |
| | | |
| | |
| | | |
| | | builder.Services.AddHostedService<MyBackgroundService>(); |
| | | |
| | | //ç¼å设置é
置转å®ä½ |
| | | builder.Services.AddConfigurableOptions<CacheSettingsOptions>(); |
| | | //ç¦æ¢å¨ä¸»æºå¯å¨æ¶éè¿ App.GetOptions<TOptions> è·åé项ï¼å¦éè·åé
ç½®é项çåºéè¿ App.GetConfig<TOptions>("é
ç½®èç¹", true)ã |
| | | var cacheSettings = AppSettings.Configuration.GetSection("CacheSettings").Get<CacheSettingsOptions>(); |
| | | //妿æredisè¿æ¥å符串 |
| | | if (cacheSettings.UseRedis) |
| | | { |
| | | var connectionString = |
| | | $"server={cacheSettings.RedisSettings.Address};db={cacheSettings.RedisSettings.Db}"; |
| | | //注å
¥redis |
| | | builder.Services.AddSimpleRedis(connectionString); |
| | | builder.Services.AddScoped<ISimpleCacheService, RedisCacheService>(); |
| | | } |
| | | else |
| | | { |
| | | builder.Services.AddScoped<ISimpleCacheService, MemoryCacheService>(); |
| | | } |
| | | |
| | | |
| | | var app = builder.Build(); |
| | | |
| | | // éªè¯ Redis æå¡æ¯å¦æå注å |
| | | using (var scope = app.Services.CreateScope()) |
| | | { |
| | | var services = scope.ServiceProvider; |
| | | var redisService = services.GetService<ISimpleCacheService>(); |
| | | if (redisService == null) |
| | | { |
| | | WIDESEA_Core.Helper.ConsoleHelper.WriteErrorLine("Redis æå¡æªæå注å"); |
| | | } |
| | | else |
| | | { |
| | | WIDESEA_Core.Helper.ConsoleHelper.WriteSuccessLine("Redis æå¡å·²æå注å"); |
| | | } |
| | | } |
| | | |
| | | // 3ãé
ç½®ä¸é´ä»¶ |
| | | app.UseMiniProfiler();//æ§è½åæå¨ |
| | |
| | | |
| | | app.MapControllers(); |
| | | |
| | | //éè¿ App.GetOptions<TOptions> è·åé项 |
| | | var cacheSettingsb = App.GetOptions<CacheSettingsOptions>(); |
| | | //妿éè¦æ¸
é¤ç¼å |
| | | if (cacheSettingsb.UseRedis && cacheSettingsb.RedisSettings.ClearRedis) |
| | | { |
| | | var redis = app.Services.CreateScope().ServiceProvider.GetService<ISimpleCacheService>(); //è·åredisæå¡ |
| | | // å é¤redisçkey |
| | | redis.DelByPattern(CacheConst.Cache_Prefix); |
| | | } |
| | | |
| | | app.Run(); |
| | | |
| | |
| | | |
| | | <ItemGroup> |
| | | <ProjectReference Include="..\WIDESEA_BusinessServices\WIDESEA_BusinessServices.csproj" /> |
| | | <ProjectReference Include="..\WIDESEA_Cache\WIDESEA_Cache.csproj" /> |
| | | <ProjectReference Include="..\WIDESEA_Services\WIDESEA_Services.csproj" /> |
| | | <ProjectReference Include="..\WIDESEA_IServices\WIDESEA_IServices.csproj" /> |
| | | <ProjectReference Include="..\WIDESEA_StorageBasicServices\WIDESEA_StorageBasicServices.csproj" /> |
| | |
| | | // 注æï¼http://127.0.0.1:1818 å http://localhost:1818 æ¯ä¸ä¸æ ·ç |
| | | "IPs": "http://127.0.0.1:8080,http://localhost:8080,http://127.0.0.1:8081,http://localhost:8081" |
| | | }, |
| | | |
| | | //ç¼å设置 |
| | | "CacheSettings": { |
| | | "UseRedis": true, //å¯ç¨redis |
| | | "RedisSettings": { |
| | | "Address": "127.0.0.1:6379", //å°å |
| | | "Password": "123456", //Redisæå¡å¯ç |
| | | "Db": 9, //é»è®¤åº |
| | | "ClearRedis": true //æ¯å¦æ¯æ¬¡å¯å¨é½æ¸
é¤Redisç¼å |
| | | } |
| | | }, |
| | | |
| | | "ApiName": "WIDESEA", |
| | | "ExpMinutes": 120, |
| | | |
| | |
| | | |
| | | // å
许åºåºçç¼ç |
| | | "OutBoundMateriel": [ |
| | | { |
| | | "MaterielCode": "CC01050001348", |
| | | "ProductionLine": "ZJ-8", |
| | | "ProcessCode": "CH001" |
| | | } |
| | | //{ |
| | | // "MaterielCode": "CC01050001348", |
| | | // "ProductionLine": "ZJ-8", |
| | | // "ProcessCode": "CH001" |
| | | //} |
| | | ] |
| | | } |
| | |
| | | [assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartAttribute("Swashbuckle.AspNetCore.SwaggerGen")] |
| | | [assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartAttribute("WIDESEA_BusinessesRepository")] |
| | | [assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartAttribute("WIDESEA_BusinessServices")] |
| | | [assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartAttribute("WIDESEA_Cache")] |
| | | [assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartAttribute("WIDESEA_Core")] |
| | | [assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartAttribute("WIDESEA_DTO")] |
| | | [assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartAttribute("WIDESEA_IBusinessesRepository")] |