using System; using WMS.Core._02Entity; using WMS.Info; using WMS.Util; namespace WMS.Core { public class CacheFacade { /// /// 获取物料数据-entity /// /// public static BASE_ITEM GetMatInfo(string matNo, EMatType matType) { var mat = RedisCache.HashRead(nameof(BASE_ITEM), matNo, ERedisCacheNo.Data); if (mat == null) { mat = GetItem(matNo, matType); if (mat == null) throw SysExCore.ThrowFailException("未匹配到有效的物料信息!"); RedisCache.HashWrite(nameof(BASE_ITEM), matNo, mat, ERedisCacheNo.Data); } return mat; } /// /// 获取物料数据 /// /// private static BASE_ITEM GetItem(string matNo, EMatType matType) { try { var mat = SysDbCore.GetDbCtx().Queryable().Where(it => !it.F_isStop).WhereIF(!matNo.IsEmpty(), it => it.F_matNo == matNo).First(); if (mat == null) { var fxmat = FxDbCore.GetItemData($"select top 100 pt_domain,pt_part,pt_desc1,pt_desc2,pt_part_type,pt_um,pt_prod_line from pub.pt_mstr where pt_domain = 'AFCN' and pt_part='{matNo}'"); if (fxmat == null) throw SysExCore.ThrowFailException("未找到物料信息!"); mat = new BASE_ITEM { F_addTime = DateTime.Now, F_addUserNo = "system", F_isStop = false, F_matNo = fxmat.pt_part, F_matType = (int)matType, F_matName = fxmat.pt_desc1, F_matName1 = fxmat.pt_desc2, F_partType = fxmat.pt_part_type, F_unit = fxmat.pt_um, F_projectNo = fxmat.pt_prod_line, F_domain = fxmat.pt_domain }; SysDbCore.GetDbCtx().Insertable(mat).ExecuteCommand(); } return mat; } catch (Exception ex) { throw ex; } } } }