12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using System;
- using WMS.Core._02Entity;
- using WMS.Info;
- using WMS.Util;
- namespace WMS.Core
- {
- public class CacheFacade
- {
- /// <summary>
- /// 获取物料数据-entity
- /// </summary>
- /// <returns></returns>
- public static BASE_ITEM GetMatInfo(string matNo, EMatType matType)
- {
- var mat = RedisCache.HashRead<BASE_ITEM>(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;
- }
- /// <summary>
- /// 获取物料数据
- /// <summary>
- /// <returns></returns>
- private static BASE_ITEM GetItem(string matNo, EMatType matType)
- {
- try
- {
- var mat = SysDbCore.GetDbCtx().Queryable<BASE_ITEM>().Where(it => !it.F_isStop).WhereIF(!matNo.IsEmpty(), it => it.F_matNo == matNo).First();
- if (mat == null)
- {
- var fxmat = FxDbCore.GetItemData<FX_pt_mstr>($"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;
- }
- }
- }
- }
|