134 lines
5.9 KiB

  1. namespace CounsellorBL.PRD
  2. {
  3. using CounsellorBL.BLStructure;
  4. using CounsellorBL.Helper;
  5. using CounsellorBL.PRD.ConstDefinition;
  6. using MonumentDefine;
  7. using Newtonsoft.Json;
  8. using Newtonsoft.Json.Linq;
  9. using OT.COM.ArsenalDB;
  10. using OT.COM.ArsenalDB.SQL;
  11. using OT.COM.SignalerMessage;
  12. using Util = OT.COM.LogisticsUtil.Util;
  13. using SoldierData.EnterprizeV4;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Linq;
  17. class ProductManageService : SingleDataTableTemplate<tb_prd_product>
  18. {
  19. public ProductManageService()
  20. {
  21. dgReadCommandPostDataHandler = readCommandPostDataHandler;
  22. }
  23. public CResponseMessage ProductByArticle(CRequestMessage i_crmInput)
  24. {
  25. string sMsg = null;
  26. Command cRes = null;
  27. Dictionary<string, object> dicWhereData = GetQueryMasterFirstWhereData(i_crmInput);
  28. if (dicWhereData != null && dicWhereData.ContainsKey(tb_prd_article2product.CN_ARTICLE_UID))
  29. {
  30. string sArticlueUid = dicWhereData[tb_prd_article2product.CN_ARTICLE_UID].ToString();
  31. PrdSQLLib psl = new PrdSQLLib(new MSSQLDirectSQLHelper());
  32. sMsg = psl.GetArticleProduct(sArticlueUid, out cRes);
  33. }
  34. else
  35. {
  36. sMsg = MessageWording.PARAM_NOT_EXPECTED;
  37. }
  38. return simpleRead(i_crmInput, sMsg, cRes);
  39. }
  40. protected string readCommandPostDataHandler(CRequestMessage i_crmInput, ArsenalInterface i_aiArsenal, Command i_cCmd, JArray i_jaData, tb_sys_session i_sSessionUser, out object o_c,
  41. [System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
  42. [System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
  43. [System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "")
  44. {
  45. if (i_sSourcePath is null)
  46. {
  47. throw new ArgumentNullException(nameof(i_sSourcePath));
  48. }
  49. string sMsg;
  50. Command cRes = null;
  51. object oResultData = null;
  52. try
  53. {
  54. do
  55. {
  56. sMsg = ScheduleRange.ParseLogStartEnd(tb_prd_product.CN_CREATE_DATE, i_jaData, out ScheduleRange sr);
  57. if (sMsg != null)
  58. {
  59. break;
  60. }
  61. Dictionary<string, string> dicCondition = GetQueryMasterFirstQJEDicwherecols(i_crmInput);
  62. var lsBranch = ProjectHelper.GetUserGroup(i_crmInput);
  63. QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
  64. QueryJsonElement qjeA = lBlocks.GetInst<tb_prd_product>();
  65. qjeA.displaycols = new List<string>()
  66. {
  67. tb_prd_product.CN_UID,
  68. tb_prd_product.CN_NAME,
  69. tb_prd_product.CN_MEMO,
  70. tb_prd_product.CN_STATUS_FLAG,
  71. tb_prd_product.CN_WHOLESALE_PRICE,
  72. tb_prd_product.CN_PRICE,
  73. tb_prd_product.CN_SERIAL_NUMBER,
  74. tb_prd_product.CN_GROUP_ID
  75. };
  76. qjeA.ordercols = new List<Tuple<QueryJsonElement, string, string>>() {
  77. new Tuple<QueryJsonElement, string, string>(qjeA, tb_prd_product.CN_CREATE_DATE, BLWording.ORDER_DESC) };
  78. List<WhereNode> lwnMainInfo = new List<WhereNode>();
  79. if (dicCondition.ContainsKey(tb_prd_product.CN_NAME))
  80. {
  81. lwnMainInfo.Add(new WhereNode(tb_prd_product.CN_NAME, WhereNode.EColumnOperation.EOT_LIKE, typeof(tb_ord_message_log), dicCondition[tb_prd_product.CN_NAME]));
  82. }
  83. if (dicCondition.ContainsKey(tb_prd_product.CN_STATUS_FLAG))
  84. {
  85. lwnMainInfo.Add(new WhereNode(tb_prd_product.CN_STATUS_FLAG, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_ord_message_log), dicCondition[tb_prd_product.CN_STATUS_FLAG]));
  86. }
  87. lwnMainInfo.Add(new WhereNode(tb_prd_product.CN_GROUP_ID, WhereNode.EColumnOperation.EOT_IN, typeof(tb_prd_product), lsBranch.ToArray()));
  88. qjeA.wherecols = lwnMainInfo.Count == 1 ? lwnMainInfo.Single() : new WhereNode(WhereNode.ENodeOperation.ENO_AND, lwnMainInfo.ToArray());
  89. lBlocks.Add(qjeA);
  90. QueryJsonElement qjeB = lBlocks.GetInst<tb_grp_group>();
  91. qjeB.aliascols = new Dictionary<string, List<string>>() {
  92. { tb_grp_group.CN_NAME, new List<string>(){ "group_name" } }
  93. };
  94. qjeB.jointype = QueryJsonElement.JOIN;
  95. qjeB.jointable = qjeA;
  96. qjeB.joincols = new Dictionary<string, string>() {
  97. {tb_grp_group.CN_UID, tb_prd_product.CN_GROUP_ID }
  98. };
  99. lBlocks.Add(qjeB);
  100. sMsg = MakeSelectJoinByBlocks(lBlocks, out cRes);
  101. ArsenalInterface ai = ArsenalDBMgr.GetInst(cRes);
  102. QueryDataSet qds = ai.RunQueryDataSet(cRes);
  103. oResultData = new QueryResponse(qds);
  104. }
  105. while (false);
  106. }
  107. catch (Exception ex)
  108. {
  109. LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath);
  110. sMsg = $"{nameof(readCommandPostDataHandler)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. Call from {i_sMemberName} {i_sSourcePath}({i_nCodeLine}).";
  111. #if DEBUG
  112. System.Diagnostics.Debug.WriteLine(sMsg);
  113. #endif
  114. }
  115. o_c = oResultData;
  116. return sMsg;
  117. }
  118. }
  119. }