chengsc
2025-05-06 d06e44eb1c8818c8d19709602631eb7888d4f0e9
Admin.NET/WCS.Application/Util/AGVStorageUtil.cs
@@ -15,290 +15,60 @@
    private static readonly ISqlSugarClient _db = SqlSugarSetup.ITenant.GetConnectionScope(SqlSugarConst.MainConfigId);
    private static readonly SysCacheService sysCacheService = App.GetRequiredService<SysCacheService>();
    private static readonly SysConfigService _sysConfigService = App.GetRequiredService<SysConfigService>();
    private static List<string[]> listStorage = new List<string[]>();
    private static string[] listPallet = new[] { "cache_Z53", "cache_Z52", "cache_Z51" };
    static AGVStorageUtil()
    {
        listStorage.Add(new[] { "cache_Z11", "cache_Z12", "cache_Z13" });
        listStorage.Add(new[] { "cache_Z21", "cache_Z22", "cache_Z23" });
        listStorage.Add(new[] { "cache_Z31", "cache_Z32", "cache_Z33" });
        listStorage.Add(new[] { "cache_Z41", "cache_Z42", "cache_Z43" });
    }
    /// <summary>
    /// 获取成品数量
    /// </summary>
    /// <returns></returns>
    public static int ProductCount()
    public static string GetTaskModle(string straLocate,string endLocate,out string type1,out string type2,out string jiebo)
    {
        int i = 0;
        foreach (var item in listStorage)
        type1 = "";
        type2 = "";
        jiebo = "";
        var locate1 = _db.Queryable<WcsStorageLocat>().First(m => m.IsDelete == false && m.LocatNo == straLocate);
        var locate2 = _db.Queryable<WcsStorageLocat>().First(m => m.IsDelete == false && m.LocatNo == endLocate);
        if (locate1 == null || locate2 == null)
        {
            foreach (var mod in item.Reverse())
            {
                var value = _sysConfigService.GetConfigValue<bool>(mod).Result;
                if (value)
                    i++;
            }
            return "";
        }
        return i;
    }
    /// <summary>
    /// 获取成品要入的储位
    /// </summary>
    /// <returns></returns>
    public static string GetProductInStorage(string TaskNo = "")
    {
        List<string> listResult = new List<string>();
        foreach (var item in listStorage)
        switch (locate1.WareHouseNo)
        {
            List<string> listItem = new List<string>();
            foreach (var mod in item.Reverse())
            {
                var value = _sysConfigService.GetConfigValue<bool>(mod).Result;
                if (!value)
                    listItem.Add(mod.Split('_')[1]);
                else
                    break;
            }
            listResult.AddRange(listItem.AsEnumerable().Reverse());
        }
        //检查是否有正在入的任务
        foreach (var result in listResult)
        {
            if (!_db.Queryable<WcsTask>().Where(s => s.Type == PLCTypeEnum.AGV && s.Status <= TaskStatusEnum.Doing && s.EndLocate == result && s.TaskNo != TaskNo).Any())
                return result;
        }
        return "";
        //Log.Error("无可入的储位");
        //throw Oops.Bah("无可入的储位");
    }
    /// <summary>
    /// 获取成品要出的储位
    /// </summary>
    /// <returns></returns>
    public static string GetProductOutStorage()
    {
        foreach (var item in listStorage.AsEnumerable().Reverse())
        {
            foreach (var mod in item.Reverse())
            {
                var value = _sysConfigService.GetConfigValue<bool>(mod).Result;
                if (value)
                    return mod.Split('_')[1];
            }
        }
        return "";
        //Log.Error("无可出的储位");
        //throw Oops.Bah("无可出的储位");
    }
    /// <summary>
    /// 获取托盘要入的储位
    /// </summary>
    /// <returns></returns>
    public static string GetPalletInStorage(string TaskNo = "")
    {
        List<string> listResult = new List<string>();
        foreach (var item in listPallet)
        {
            var value = _sysConfigService.GetConfigValue<bool>(item).Result;
            if (!value)
                listResult.Add(item.Split('_')[1]);
            else
            case "W02":
                type1 = "SITE";
                break;
            case "W04":
                type1 = "STORAGE";
                break;
            default:
                break;
        }
        //检查是否有正在入的任务
        foreach (var result in listResult.AsEnumerable().Reverse())
        switch (locate2.WareHouseNo)
        {
            if (!_db.Queryable<WcsTask>().Where(s => s.Type == PLCTypeEnum.AGV && s.Status <= TaskStatusEnum.Doing && s.EndLocate == result && s.TaskNo != TaskNo).Any())
                return result;
            case "W02":
                type2 = "SITE";
                break;
            case "W04":
                type2 = "STORAGE";
                break;
            default:
                break;
        }
        return "";
        //Log.Error("无可入的储位");
        //throw Oops.Bah("无可入的储位");
    }
    /// <summary>
    /// 获取托盘要出的储位
    /// </summary>
    /// <returns></returns>
    public static string GetPalletOutStorage()
    {
        foreach (var item in listPallet)
        var Area1002 = new List<string>() { "",""};//1002车间区域
        var Area1003 = new List<string>() { "",""};//1003车间区域
        if (Area1002.Contains(locate2.AreaNo))
        {
            var value = _sysConfigService.GetConfigValue<bool>(item).Result;
            if (value)
                return item.Split('_')[1];
            jiebo = "1JB";//接驳位
        }
        return "";
        //Log.Error("无可出的储位");
        //throw Oops.Bah("无可出的储位");
        if (Area1003.Contains(locate2.AreaNo))
        {
            jiebo = "2JB";
        }
        if (type1 == "" || type2 == "")
        {
            return "";
        }
        return "CJ1";
    }
    #region 属性
    public static bool Z11
    {
        get
        {
            return _sysConfigService.GetConfigValue<bool>("cache_Z11").Result;
        }
        set
        {
            _sysConfigService.UpdateConfigValue("cache_Z11", value);
        }
    }
    public static bool Z12
    {
        get
        {
            return _sysConfigService.GetConfigValue<bool>("cache_Z12").Result;
        }
        set
        {
            _sysConfigService.UpdateConfigValue("cache_Z12", value);
        }
    }
    public static bool Z13
    {
        get
        {
            return _sysConfigService.GetConfigValue<bool>("cache_Z13").Result;
        }
        set
        {
            _sysConfigService.UpdateConfigValue("cache_Z13", value);
        }
    }
    public static bool Z21
    {
        get
        {
            return _sysConfigService.GetConfigValue<bool>("cache_Z21").Result;
        }
        set
        {
            _sysConfigService.UpdateConfigValue("cache_Z21", value);
        }
    }
    public static bool Z22
    {
        get
        {
            return _sysConfigService.GetConfigValue<bool>("cache_Z22").Result;
        }
        set
        {
            _sysConfigService.UpdateConfigValue("cache_Z22", value);
        }
    }
    public static bool Z23
    {
        get
        {
            return _sysConfigService.GetConfigValue<bool>("cache_Z23").Result;
        }
        set
        {
            _sysConfigService.UpdateConfigValue("cache_Z23", value);
        }
    }
    public static bool Z31
    {
        get
        {
            return _sysConfigService.GetConfigValue<bool>("cache_Z31").Result;
        }
        set
        {
            _sysConfigService.UpdateConfigValue("cache_Z31", value);
        }
    }
    public static bool Z32
    {
        get
        {
            return _sysConfigService.GetConfigValue<bool>("cache_Z32").Result;
        }
        set
        {
            _sysConfigService.UpdateConfigValue("cache_Z32", value);
        }
    }
    public static bool Z33
    {
        get
        {
            return _sysConfigService.GetConfigValue<bool>("cache_Z33").Result;
        }
        set
        {
            _sysConfigService.UpdateConfigValue("cache_Z33", value);
        }
    }
    public static bool Z41
    {
        get
        {
            return _sysConfigService.GetConfigValue<bool>("cache_Z41").Result;
        }
        set
        {
            _sysConfigService.UpdateConfigValue("cache_Z41", value);
        }
    }
    public static bool Z42
    {
        get
        {
            return _sysConfigService.GetConfigValue<bool>("cache_Z42").Result;
        }
        set
        {
            _sysConfigService.UpdateConfigValue("cache_Z42", value);
        }
    }
    public static bool Z43
    {
        get
        {
            return _sysConfigService.GetConfigValue<bool>("cache_Z43").Result;
        }
        set
        {
            _sysConfigService.UpdateConfigValue("cache_Z43", value);
        }
    }
    public static bool Z51
    {
        get
        {
            return _sysConfigService.GetConfigValue<bool>("cache_Z51").Result;
        }
        set
        {
            _sysConfigService.UpdateConfigValue("cache_Z51", value);
        }
    }
    public static bool Z52
    {
        get
        {
            return _sysConfigService.GetConfigValue<bool>("cache_Z52").Result;
        }
        set
        {
            _sysConfigService.UpdateConfigValue("cache_Z52", value);
        }
    }
    public static bool Z53
    {
        get
        {
            return _sysConfigService.GetConfigValue<bool>("cache_Z53").Result;
        }
        set
        {
            _sysConfigService.UpdateConfigValue("cache_Z53", value);
        }
    }
    #endregion
}