ProductModelSearch.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Abp.Extensions;
  7. using IwbZero.AppServiceBase;
  8. using ShwasherSys.Common.Dto;
  9. using ShwasherSys.Lambda;
  10. namespace ShwasherSys.Common
  11. {
  12. public static class ProductModelSearch
  13. {
  14. /// <summary>
  15. /// model 查询条件分割后是否有多个
  16. /// </summary>
  17. /// <param name="searchDto"></param>
  18. /// <returns>true:有多个</returns>
  19. public static bool CheckModelGreaterOneFilter(MultiSearchDto searchDto,ref object kw)
  20. {
  21. bool result = false;
  22. object keyWords = searchDto.KeyWords;
  23. if (searchDto.KeyField == "model")
  24. {
  25. var arrModels = (keyWords + "").Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  26. result = arrModels.Length > 1;
  27. kw = result?arrModels[0]: kw;
  28. }
  29. return result;
  30. }
  31. /// <summary>
  32. /// model 查询条件分割后是否有多个
  33. /// </summary>
  34. /// <param name="searchDto"></param>
  35. /// <returns>true:有多个</returns>
  36. public static bool CheckModelGreaterOneFilter(MultiSearchDto searchDto)
  37. {
  38. bool result = false;
  39. object keyWords = searchDto.KeyWords;
  40. if (searchDto.KeyField == "model")
  41. {
  42. var arrModels = (keyWords + "").Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  43. result = arrModels.Length > 1;
  44. }
  45. return result;
  46. }
  47. /// <summary>
  48. /// 获取产品规格的正则表达式
  49. /// </summary>
  50. /// <param name="searchList"></param>
  51. /// <returns></returns>
  52. public static string GetModelGreaterOneReg(List<MultiSearchDto> searchList)
  53. {
  54. string result = "";
  55. if (searchList != null && searchList.Count > 0)
  56. {
  57. foreach (var o in searchList)
  58. {
  59. if (o.KeyWords.IsNullOrEmpty())
  60. continue;
  61. object keyWords = o.KeyWords;
  62. if (ProductModelSearch.CheckModelGreaterOneFilter(o))
  63. {
  64. result = GetModelGreaterOneReg(o);
  65. }
  66. }
  67. }
  68. return result;
  69. }
  70. /// <summary>
  71. /// 获取产品规格的正则表达式
  72. /// </summary>
  73. /// <param name="searchList"></param>
  74. /// <returns></returns>
  75. public static string GetModelGreaterOneReg(List<MultiSearchDtoExt> searchList)
  76. {
  77. string result = "";
  78. if (searchList != null && searchList.Count > 0)
  79. {
  80. foreach (var o in searchList)
  81. {
  82. if (o.KeyWords.IsNullOrEmpty())
  83. continue;
  84. object keyWords = o.KeyWords;
  85. if (ProductModelSearch.CheckModelGreaterOneFilter(o))
  86. {
  87. result = GetModelGreaterOneReg(o);
  88. }
  89. }
  90. }
  91. return result;
  92. }
  93. public static string GetModelGreaterOneReg(MultiSearchDto searchDto)
  94. {
  95. string result = "";
  96. object keyWords = searchDto.KeyWords;
  97. if (searchDto.KeyField == "model")
  98. {
  99. var arrModels = (keyWords + "").Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  100. foreach (var item in arrModels)
  101. {
  102. result += ".*" + item;
  103. }
  104. }
  105. return result;
  106. }
  107. public static void AddModelFilterToLamb(this List<LambdaObject> objList,MultiSearchDto searchDto)
  108. {
  109. object keyWords = searchDto.KeyWords;
  110. if (searchDto.KeyField == "model")
  111. {
  112. //modelQuery = keyWords+"";
  113. var arrModels = (keyWords + "").Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  114. if (arrModels.Length > 0)
  115. {
  116. foreach (var arrModel in arrModels)
  117. {
  118. objList.Add(new LambdaObject
  119. {
  120. FieldType = (LambdaFieldType)searchDto.FieldType,
  121. FieldName = searchDto.KeyField,
  122. FieldValue = arrModel,
  123. ExpType = (LambdaExpType)searchDto.ExpType,
  124. });
  125. }
  126. }
  127. }
  128. }
  129. }
  130. }