CacheFacade.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using WMS.Core._02Entity;
  3. using WMS.Info;
  4. using WMS.Util;
  5. namespace WMS.Core
  6. {
  7. public class CacheFacade
  8. {
  9. /// <summary>
  10. /// 获取物料数据-entity
  11. /// </summary>
  12. /// <returns></returns>
  13. public static BASE_ITEM GetMatInfo(string matNo, EMatType matType)
  14. {
  15. var mat = RedisCache.HashRead<BASE_ITEM>(nameof(BASE_ITEM), matNo, ERedisCacheNo.Data);
  16. if (mat == null)
  17. {
  18. mat = GetItem(matNo, matType);
  19. if (mat == null)
  20. throw SysExCore.ThrowFailException("未匹配到有效的物料信息!");
  21. RedisCache.HashWrite(nameof(BASE_ITEM), matNo, mat, ERedisCacheNo.Data);
  22. }
  23. return mat;
  24. }
  25. /// <summary>
  26. /// 获取物料数据
  27. /// <summary>
  28. /// <returns></returns>
  29. private static BASE_ITEM GetItem(string matNo, EMatType matType)
  30. {
  31. try
  32. {
  33. var mat = SysDbCore.GetDbCtx().Queryable<BASE_ITEM>().Where(it => !it.F_isStop).WhereIF(!matNo.IsEmpty(), it => it.F_matNo == matNo).First();
  34. if (mat == null)
  35. {
  36. 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}'");
  37. if (fxmat == null)
  38. throw SysExCore.ThrowFailException("未找到物料信息!");
  39. mat = new BASE_ITEM
  40. {
  41. F_addTime = DateTime.Now,
  42. F_addUserNo = "system",
  43. F_isStop = false,
  44. F_matNo = fxmat.pt_part,
  45. F_matType = (int)matType,
  46. F_matName = fxmat.pt_desc1,
  47. F_matName1 = fxmat.pt_desc2,
  48. F_partType = fxmat.pt_part_type,
  49. F_unit = fxmat.pt_um,
  50. F_projectNo = fxmat.pt_prod_line,
  51. F_domain = fxmat.pt_domain
  52. };
  53. SysDbCore.GetDbCtx().Insertable(mat).ExecuteCommand();
  54. }
  55. return mat;
  56. }
  57. catch (Exception ex)
  58. {
  59. throw ex;
  60. }
  61. }
  62. }
  63. }