Browse Source

[WHAT] 服務查詢API [WHY] feature

Dev
Janie 2 years ago
parent
commit
f1128f9ad0
  1. 176
      EuroTran/EasyBL.WEBAPP/ShowEasy/ServicesService.cs

176
EuroTran/EasyBL.WEBAPP/ShowEasy/ServicesService.cs

@ -47,13 +47,44 @@ namespace EasyBL.WEBAPP.SYS
var ServiceIDSet = new HashSet<string>(); //去重複值
var ServiceRegionSet = FilterByRegion(Lang, RegionID);
var ServiceCountrySet = FilterByCountry(Lang, CountryID);
var ServiceCitySet = FilterByCity(Lang, CityID);
var ServiceSubCategorySet = FilterBySubCategory(Lang, SubCategoryID);
foreach (var service in saService) {
if (!ServiceIDSet.Contains(service.ServiceID)) {
ServiceIDSet.Add(service.ServiceID);
}
}
if (RegionID.Count > 0) {
ServiceIDSet = FilterByRegion(ServiceIDSet, Lang, RegionID);
}
if (CountryID.Count > 0)
{
ServiceIDSet = FilterByCountry(ServiceIDSet, Lang, CountryID);
}
if (CityID.Count > 0)
{
ServiceIDSet = FilterByCity(ServiceIDSet, Lang, CityID);
}
if (SubCategoryID.Count > 0)
{
ServiceIDSet = FilterBySubCategory(ServiceIDSet, Lang, SubCategoryID);
}
saService = FilterByServiceID(ServiceIDSet, saService);
srm = new SuccessResponseMessage(null, null);
srm.DATA.Add(BLWording.REL, saService);
@ -66,15 +97,13 @@ namespace EasyBL.WEBAPP.SYS
return HttpResponseExtension.ToJson(JsonConvert.SerializeObject(srm));
}
//用區域搜尋服務(多選)
public HashSet<string> FilterByRegion(string Lang, List<string> RegionID)
public HashSet<string> FilterByRegion(HashSet<string> ServiceIDSet, string Lang, List<string> RegionID)
{
//string sMsg = null;
var db = SugarBase.GetIntance();
//去重複值
var ServiceIDSet = new HashSet<string>();
var newServiceFilter = new HashSet<string>();
var Result = new HashSet<string>();
do
{
@ -96,25 +125,35 @@ namespace EasyBL.WEBAPP.SYS
foreach (var result in saResult)
{
if (!ServiceIDSet.Contains(result.ServiceID)) //ServiceIDSet內若有包含ServiceID欄位
if (!newServiceFilter.Contains(result.ServiceID)) //ServiceIDSet內若有包含ServiceID欄位
{
ServiceIDSet.Add(result.ServiceID); //則加入該result的ServiceID欄位
newServiceFilter.Add(result.ServiceID); //則加入該result的ServiceID欄位
}
}
}
} while (false);
return ServiceIDSet;
ServiceIDSet.IntersectWith(newServiceFilter);
return Result;
}
//用國家搜尋服務(多選)
public HashSet<string> FilterByCountry(string Lang, List<string> CountryID)
public HashSet<string> FilterByCountry(HashSet<string> ServiceIDSet, string Lang, List<string> CountryID)
{
//System.Diagnostics.Debug.WriteLine("first FilterByCountry: " + ServiceIDSet.Count);
var db = SugarBase.GetIntance();
var ServiceIDSet = new HashSet<string>();
var newServiceFilter = new HashSet<string>();
var Result = new HashSet<string>();
//System.Diagnostics.Debug.WriteLine(ServiceIDSet);
do
{
@ -126,10 +165,8 @@ namespace EasyBL.WEBAPP.SYS
}
//去重複值
foreach (var Country in CountryID)
{ //參數RegionID為陣列
{
var saResult = db.Queryable<SETB_PDT_ServiceBySuitPlace>() //比對每筆資料的CountryID是否為使用者所選Filter
.Where(x => x.LangID == Lang && x.CountryID == Country)
@ -138,25 +175,35 @@ namespace EasyBL.WEBAPP.SYS
foreach (var result in saResult)
{
if (!ServiceIDSet.Contains(result.ServiceID))
if (!newServiceFilter.Contains(result.ServiceID))
{
ServiceIDSet.Add(result.ServiceID);
newServiceFilter.Add(result.ServiceID);
}
}
}
} while (false);
ServiceIDSet.IntersectWith(newServiceFilter);
//System.Diagnostics.Debug.WriteLine("last FilterByCountry: " + ServiceIDSet.Count);
return ServiceIDSet;
}
//用城市搜尋服務(多選)
public HashSet<string> FilterByCity(string Lang, List<string> CityID)
public HashSet<string> FilterByCity(HashSet<string> ServiceIDSet, string Lang, List<string> CityID)
{
var db = SugarBase.GetIntance();
var ServiceIDSet = new HashSet<string>();
var newServiceFilter = new HashSet<string>();
var Result = new HashSet<string>();
System.Diagnostics.Debug.WriteLine("first FilterByCity: " + ServiceIDSet.Count);
do
{
@ -168,8 +215,6 @@ namespace EasyBL.WEBAPP.SYS
}
//去重複值
foreach (var City in CityID)
{ //參數RegionID為陣列
@ -180,27 +225,33 @@ namespace EasyBL.WEBAPP.SYS
foreach (var result in saResult)
{
if (!ServiceIDSet.Contains(result.ServiceID))
if (!newServiceFilter.Contains(result.ServiceID))
{
ServiceIDSet.Add(result.ServiceID);
newServiceFilter.Add(result.ServiceID);
}
}
}
} while (false);
ServiceIDSet.IntersectWith(newServiceFilter);
//System.Diagnostics.Debug.WriteLine("last FilterByCity: " + ServiceIDSet.Count);
return ServiceIDSet;
}
//用子類別搜尋服務(多選)
public HashSet<string> FilterBySubCategory(string Lang, List<string> SubCategoryID)
public HashSet<string> FilterBySubCategory(HashSet<string> ServiceIDSet, string Lang, List<string> SubCategoryID)
{
var db = SugarBase.GetIntance();
var ServiceIDSet = new HashSet<string>();
var ServiceDic = new Dictionary<string, View_PDT_ServiceBaseInfo>();
var NewServiceIDSet = new HashSet<string>(); //存進NewServiceIDSet會自動去掉重複值
do
{
@ -212,42 +263,73 @@ namespace EasyBL.WEBAPP.SYS
}
foreach (var SubCategory in SubCategoryID)
{
var saResult = db.Queryable<SETB_PDT_ServiceBaseInfo>() //將所有Service列出
.Where(x => x.LangID == Lang)
.ToList(); //將結果儲存成陣列
var saResult = db.Queryable<SETB_PDT_ServiceBaseInfo>() //比對每筆資料的CountryID是否為使用者所選Filter
.Where(x => x.LangID == Lang)
.ToList(); //將結果儲存成陣列
foreach (var result in saResult)
{
foreach (var result in saResult)
if (!string.IsNullOrEmpty(result.SubCategoryID))
{
System.Diagnostics.Debug.WriteLine("result.SubCategoryID" + ": " + result.SubCategoryID);
if (!string.IsNullOrEmpty(result.SubCategoryID)) {
var rsSubCategoryIDs = JsonConvert.DeserializeObject<List<CategoryData>>(result.SubCategoryID); //把SubCategoryID JSON string 轉成 List<CategoryData> Object
var rsSubCategoryIDs = JsonConvert.DeserializeObject<List<CategoryData>>(result.SubCategoryID);
var list = rsSubCategoryIDs.Select(s => s.id).ToList(); //只取tag為id的資料並存入list
CategoryData data = rsSubCategoryIDs[0];
if (list.Intersect(SubCategoryID).Any()) { //將list和SubCategoryID做合集
//System.Diagnostics.Debug.WriteLine("categoryID" + ": " + data.id);
NewServiceIDSet.Add(result.ServiceID);
if (!ServiceIDSet.Contains(result.ServiceID))
{
ServiceIDSet.Add(result.ServiceID);
}
}
}
}
} while (false);
ServiceIDSet.IntersectWith(NewServiceIDSet);
return ServiceIDSet;
}
//FilterByServiceID
public List<SETB_PDT_ServiceBaseInfo> FilterByServiceID(HashSet<string> ServiceIDSet, List<SETB_PDT_ServiceBaseInfo> saService)
{
var saResult = new List<SETB_PDT_ServiceBaseInfo>();
do
{
//var ServiceIDList = ServiceIDSet.ToList();
var ServiceDic = new Dictionary<string, SETB_PDT_ServiceBaseInfo>();
foreach (var Service in saService) { //把所有的ServiceList轉成Dictionary
if (!ServiceDic.ContainsKey(Service.ServiceID)) {
ServiceDic.Add(Service.ServiceID, Service);
}
}
foreach (var ServiceID in ServiceIDSet) {
if (ServiceDic.ContainsKey(ServiceID)) {
saResult.Add(ServiceDic[ServiceID]); //用ServiceID當Key查Dictionary內的值並加入saResult
}
}
} while (false);
return saResult;
}
}
}
Loading…
Cancel
Save