You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
513 lines
20 KiB
513 lines
20 KiB
using EasyBL.WebApi;
|
|
using EasyBL.WebApi.Common;
|
|
using EasyBL.WebApi.Message;
|
|
using Entity.ShowEasyDtos;
|
|
using Entity.Sugar;
|
|
using Entity.ViewModels;
|
|
using Newtonsoft.Json;
|
|
using SqlSugar;
|
|
using SqlSugar.Base;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
|
|
namespace EasyBL.WEBAPP.SYS
|
|
{
|
|
public class CountryMaintain_QryService : ServiceBase
|
|
{
|
|
#region 國別管理(分頁查詢)
|
|
|
|
/// <summary>
|
|
/// 國別管理(分頁查詢)SETB_ORG_Venue
|
|
/// </summary>
|
|
/// <param name="i_crm"></param>
|
|
/// <returns></returns>
|
|
public ResponseMessage QueryPage(RequestMessage i_crm)
|
|
{
|
|
ResponseMessage rm = null;
|
|
string sMsg = null;
|
|
var db = SugarBase.GetIntance();
|
|
try
|
|
{
|
|
do
|
|
{
|
|
var pml = new PageModel
|
|
{
|
|
PageIndex = _fetchInt(i_crm, @"pageIndex"),
|
|
PageSize = _fetchInt(i_crm, @"pageSize")
|
|
};
|
|
var iPageCount = 0;
|
|
var sCountryID = _fetchString(i_crm, @"CountryID");
|
|
var sLangType = _fetchString(i_crm, @"LangType");
|
|
var sSortField = _fetchString(i_crm, @"sortField");
|
|
var sSortOrder = _fetchString(i_crm, @"sortOrder");
|
|
var sCountryName = _fetchString(i_crm, @"CountryName");
|
|
var sRegionID = _fetchString(i_crm, @"RegionID");
|
|
var sEffective = _fetchString(i_crm, @"Effective");
|
|
var bExcel = _fetchBool(i_crm, @"Excel");
|
|
pml.DataList = db.Queryable<SETB_SYS_Country, SETB_SYS_Region>((t1, t2) => new object[] {
|
|
JoinType.Left, t1.OrgID == t2.OrgID && t1.RegionID == t2.RegionID && t1.LangType == t2.LangType
|
|
}
|
|
)
|
|
.Where((t1, t2) => t1.OrgID == i_crm.ORIGID && t1.DelStatus == "N" && sEffective.Contains(t1.Effective))
|
|
.WhereIF(!string.IsNullOrEmpty(sCountryID), (t1, t2) => t1.CountryID == sCountryID)
|
|
.WhereIF(!string.IsNullOrEmpty(sRegionID), (t1, t2) => t1.RegionID == sRegionID)
|
|
.WhereIF(!string.IsNullOrEmpty(sLangType),(t1, t2) => t1.LangType == sLangType)
|
|
.WhereIF(!string.IsNullOrEmpty(sCountryName), (t1, t2) => (t1.CountryName + t1.CountrySlug + t1.Country_ENCode).Contains(sCountryName))
|
|
|
|
.Select((t1, t2) => new View_SYS_Country
|
|
{
|
|
CountryID = SqlFunc.GetSelfAndAutoFill(t1.CountryID),
|
|
RegionName = t2.RegionName,
|
|
OrderCount = SqlFunc.Subqueryable<SETB_SYS_Country>().Where(p => p.RegionID == t1.RegionID && p.OrgID == t1.OrgID && p
|
|
.DelStatus == "N").Count(),
|
|
})
|
|
|
|
.MergeTable()
|
|
.OrderBy(sSortField, sSortOrder)
|
|
.ToPageList(pml.PageIndex, bExcel ? 100000 : pml.PageSize, ref iPageCount);
|
|
pml.Total = iPageCount;
|
|
rm = new SuccessResponseMessage(null, i_crm);
|
|
if (bExcel)
|
|
{
|
|
const string sFileName = "國別列表";
|
|
var oHeader = new Dictionary<string, string>
|
|
{
|
|
{ "RowIndex", "項次" },
|
|
{ "RegionName", "洲別名稱" },
|
|
{ "CountryID", "國別編號" },
|
|
{ "Country_ENCode", "國別英文代碼" },
|
|
{ "CountryName", "國別名稱" },
|
|
{ "CountrySlug", "國別簡稱" },
|
|
{ "OrderByValue", "排序" },
|
|
{ "Effective", "狀態(Y:有效;N:無效)" }
|
|
};
|
|
var dicAlain = ExcelService.GetExportAlain(oHeader, "Effective");
|
|
var saArguments = pml.DataList as List<View_SYS_Country>;
|
|
var bOk = new ExcelService().CreateExcelByList(saArguments, out string sPath, oHeader, dicAlain, sFileName);
|
|
rm.DATA.Add(BLWording.REL, sPath);
|
|
}
|
|
else
|
|
{
|
|
rm.DATA.Add(BLWording.REL, pml);
|
|
}
|
|
} while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sMsg = Util.GetLastExceptionMsg(ex);
|
|
LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBAPP.SYS.CountryMaintain_QryService", "", "QueryPage(參數類別管理(分頁查詢))", "", "", "");
|
|
}
|
|
finally
|
|
{
|
|
if (null != sMsg)
|
|
{
|
|
rm = new ErrorResponseMessage(sMsg, i_crm);
|
|
}
|
|
}
|
|
return rm;
|
|
}
|
|
|
|
#endregion 國別管理(分頁查詢)
|
|
|
|
#region 國別管理(更新排序)
|
|
|
|
/// <summary>
|
|
/// 國別管理(更新排序)
|
|
/// </summary>
|
|
/// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
|
|
/// <returns></returns>
|
|
public ResponseMessage UpdateOrderByValue(RequestMessage i_crm)
|
|
{
|
|
ResponseMessage rm = null;
|
|
string sMsg = null;
|
|
|
|
try
|
|
{
|
|
rm = SugarBase.ExecTran(db =>
|
|
{
|
|
do
|
|
{
|
|
var sCountryID = _fetchString(i_crm, @"CountryID");
|
|
var iOldOrderByValue = _fetchInt(i_crm, @"OldOrderByValue");
|
|
var iNewOrderByValue = _fetchInt(i_crm, @"NewOrderByValue");
|
|
var oOrderEntity = db.Queryable<SETB_SYS_Country>().Single(x => x.OrgID == i_crm.ORIGID && x.CountryID == sCountryID);
|
|
if (iNewOrderByValue > iOldOrderByValue)
|
|
{
|
|
var iRelUp = db.Updateable<SETB_SYS_Country>()
|
|
.UpdateColumns(x => new SETB_SYS_Country { OrderByValue = x.OrderByValue - 1 })
|
|
.Where(x => x.OrgID == oOrderEntity.OrgID && x.OrderByValue <= iNewOrderByValue && x.OrderByValue > iOldOrderByValue)
|
|
.ExecuteCommand();
|
|
}
|
|
else
|
|
{
|
|
var iRelDown = db.Updateable<SETB_SYS_Country>()
|
|
.UpdateColumns(x => new SETB_SYS_Country { OrderByValue = x.OrderByValue + 1 })
|
|
.Where(x => x.OrgID == oOrderEntity.OrgID && x.OrderByValue >= iNewOrderByValue && x.OrderByValue < iOldOrderByValue)
|
|
.ExecuteCommand();
|
|
}
|
|
var iRelSelf = db.Updateable(new SETB_SYS_Country { OrderByValue = iNewOrderByValue })
|
|
.UpdateColumns(x => x.OrderByValue)
|
|
.Where(x => x.OrgID == i_crm.ORIGID && x.CountryID == sCountryID).ExecuteCommand();
|
|
|
|
rm = new SuccessResponseMessage(null, i_crm);
|
|
rm.DATA.Add(BLWording.REL, iRelSelf);
|
|
} while (false);
|
|
|
|
return rm;
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sMsg = Util.GetLastExceptionMsg(ex);
|
|
LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(CountryMaintain_QryService), @"參數類別管理", @"UpdateOrderByValue(參數類別管理(更新排序))", @"", @"", @"");
|
|
}
|
|
finally
|
|
{
|
|
if (null != sMsg)
|
|
{
|
|
rm = new ErrorResponseMessage(sMsg, i_crm);
|
|
}
|
|
}
|
|
return rm;
|
|
}
|
|
|
|
#endregion 國別管理(更新排序)
|
|
|
|
|
|
#region 洲別選單
|
|
|
|
/// <summary>
|
|
/// 城市類別管理(查詢筆數)
|
|
/// </summary>
|
|
/// <param name="i_crm"></param>
|
|
/// <returns></returns>
|
|
public ResponseMessage QueryRegionList(RequestMessage i_crm)
|
|
{
|
|
RegionMaintain_QryService cm_upd = new RegionMaintain_QryService();
|
|
|
|
ResponseMessage rm = cm_upd.QueryRegionList(i_crm);
|
|
|
|
return rm;
|
|
}
|
|
|
|
#endregion 洲別選單
|
|
|
|
#region 語言管理 (List 查詢)
|
|
public ResponseMessage GetLanguage(RequestMessage i_crm)
|
|
{
|
|
ResponseMessage rm = null;
|
|
string sMsg = null;
|
|
var db = SugarBase.GetIntance();
|
|
try
|
|
{
|
|
do
|
|
{
|
|
|
|
var sArgumentClassID = "LanCountry";
|
|
|
|
var saLanguage = db.Queryable<OTB_SYS_Arguments>()
|
|
.Where(x => x.OrgID == i_crm.ORIGID && x.Effective == "Y" && x.DelStatus == "N")
|
|
.WhereIF(!string.IsNullOrEmpty(sArgumentClassID), t1 => t1.ArgumentClassID == sArgumentClassID)
|
|
.Select((t1) => new SETB_SYS_Language
|
|
{
|
|
|
|
LanguageID = t1.ArgumentID,
|
|
LanguageName = t1.ArgumentValue
|
|
|
|
})
|
|
.ToList();
|
|
|
|
rm = new SuccessResponseMessage(null, i_crm);
|
|
rm.DATA.Add(BLWording.REL, saLanguage);
|
|
} while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sMsg = Util.GetLastExceptionMsg(ex);
|
|
LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(CountryMaintain_QryService), "", "QueryList 語言管理 (List 查詢)", "", "", "");
|
|
}
|
|
finally
|
|
{
|
|
if (null != sMsg)
|
|
{
|
|
rm = new ErrorResponseMessage(sMsg, i_crm);
|
|
}
|
|
}
|
|
return rm;
|
|
}
|
|
|
|
#endregion 語言管理 (List 查詢)
|
|
|
|
#region 國家選單
|
|
|
|
/// <summary>
|
|
/// 城市類別管理(查詢筆數)
|
|
/// </summary>
|
|
/// <param name="i_crm"></param>
|
|
/// <returns></returns>
|
|
public ResponseMessage QueryCountryList(RequestMessage i_crm)
|
|
{
|
|
ResponseMessage rm = null;
|
|
string sMsg = null;
|
|
var db = SugarBase.GetIntance();
|
|
try
|
|
{
|
|
do
|
|
{
|
|
var sRegionID = _fetchString(i_crm, @"RegionID");
|
|
var sLangType = _fetchString(i_crm, @"LangType");
|
|
var saCountry = db.Queryable<SETB_SYS_Country>()
|
|
//搜尋條件
|
|
.Where(x => x.OrgID == i_crm.ORIGID && x.Effective == "Y" && x.DelStatus == "N")
|
|
.WhereIF(!string.IsNullOrEmpty(sRegionID), x => x.RegionID == sRegionID)
|
|
.WhereIF(!string.IsNullOrEmpty(sLangType), x => x.LangType == sLangType)
|
|
.OrderBy(o => o.CountryName, OrderByType.Asc)
|
|
.ToList();
|
|
|
|
rm = new SuccessResponseMessage(null, i_crm);
|
|
rm.DATA.Add(BLWording.REL, saCountry);
|
|
} while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sMsg = Util.GetLastExceptionMsg(ex);
|
|
LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(CountryMaintain_QryService), "", "QueryList(城市類別管理(查詢筆數))", "", "", "");
|
|
}
|
|
finally
|
|
{
|
|
if (null != sMsg)
|
|
{
|
|
rm = new ErrorResponseMessage(sMsg, i_crm);
|
|
}
|
|
}
|
|
return rm;
|
|
}
|
|
|
|
#endregion 國家選單
|
|
|
|
public Dictionary<string, SETB_SYS_Country> FindAllByIDsAsDictionary(string sLanguageID, string sRegionID, string sCountryID)
|
|
{
|
|
|
|
Dictionary<string, SETB_SYS_Country> rsResult = new Dictionary<string, SETB_SYS_Country>();
|
|
|
|
string sError = null;
|
|
|
|
var db = SugarBase.GetIntance();
|
|
|
|
try
|
|
{
|
|
do
|
|
{
|
|
if (string.IsNullOrEmpty(sLanguageID))
|
|
{
|
|
sLanguageID = WebAppGlobalConstWord.DEFAULT_LANGUAGE;
|
|
}
|
|
|
|
var rsList = db.Queryable<SETB_SYS_Country>()
|
|
|
|
.Where(t1 => t1.Effective == "Y" && t1.DelStatus == "N")
|
|
.WhereIF(!string.IsNullOrEmpty(sLanguageID), t1 => t1.LangType == sLanguageID)
|
|
.WhereIF(!string.IsNullOrEmpty(sRegionID), t1 => t1.RegionID == sRegionID)
|
|
.WhereIF(!string.IsNullOrEmpty(sCountryID), t1 => t1.CountryID == sCountryID)
|
|
.ToList();
|
|
|
|
foreach (var Country in rsList)
|
|
{
|
|
rsResult[Country.CountryID] = Country;
|
|
}
|
|
|
|
|
|
} while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sError = Util.GetLastExceptionMsg(ex);
|
|
}
|
|
|
|
return rsResult;
|
|
|
|
}
|
|
|
|
//國家選單 (英文名稱 + 中文名稱)
|
|
#region 國家選單
|
|
|
|
/// <summary>
|
|
/// 城市類別管理(查詢筆數)
|
|
/// </summary>
|
|
/// <param name="i_crm"></param>
|
|
/// <returns></returns>
|
|
public Dictionary<string, CountryDTO> QueryCountryList_TW(RequestMessage i_crm)
|
|
{
|
|
|
|
var rsCountryDic = new Dictionary<string, CountryDTO>();
|
|
|
|
string sMsg = null;
|
|
var db = SugarBase.GetIntance();
|
|
try
|
|
{
|
|
do
|
|
{
|
|
var sRegionID = _fetchString(i_crm, @"RegionID");
|
|
var sLangType = _fetchString(i_crm, @"LangType");
|
|
|
|
//var AllCountryDic = FindAllByIDsAsDictionary("", "", "");
|
|
//var TW_CountryList = AllCountryDic.Values.Where(w => w.LangType == sLangType).Select(s => new CountryDTO {
|
|
|
|
// CountryID = s.CountryID,
|
|
// CountryName = s.CountryName
|
|
|
|
//}).ToList();
|
|
|
|
//System.Diagnostics.Debug.WriteLine("TW_CountryList.Count" + ": "+TW_CountryList.Count);
|
|
|
|
//var EN_CountryList = AllCountryDic.Values.Where(w => w.LangType == "en-US").Select(s => new CountryDTO
|
|
//{
|
|
|
|
// CountryID = s.CountryID,
|
|
// CountryName = s.CountryName
|
|
|
|
//}).ToList();
|
|
|
|
//System.Diagnostics.Debug.WriteLine("EN_CountryList.Count" + ": " + EN_CountryList.Count);
|
|
|
|
//var ENCountryDic = new Dictionary<string, CountryDTO>();
|
|
|
|
//foreach(var ENCountry in EN_CountryList) {
|
|
|
|
// ENCountryDic[ENCountry.CountryID] = ENCountry;
|
|
|
|
|
|
//}
|
|
|
|
//foreach (var Country in TW_CountryList) {
|
|
|
|
// if (ENCountryDic.ContainsKey(Country.CountryID)) {
|
|
|
|
// var ENCountry = ENCountryDic[Country.CountryID];
|
|
|
|
// Country.CountryENName = ENCountry.CountryName;
|
|
|
|
// rsCountryDic[Country.CountryID] = Country;
|
|
// }
|
|
|
|
|
|
//}
|
|
|
|
|
|
//var saCountryList = db.Queryable<SETB_SYS_Country, SETB_SYS_Country>((t1, t2) => new object[] {
|
|
// JoinType.Left, t1.OrgID == t2.OrgID && t1.CountryID == t2.CountryID && t2.LangType == "en-US"
|
|
//})
|
|
// .OrderBy(o => o.CountryName, OrderByType.Asc)
|
|
// .Select((t1, t2) => new CountryDTO {
|
|
|
|
// CountryID = t1.CountryID,
|
|
// CountryName = t1.CountryName,
|
|
// CountryENName = t2.CountryName
|
|
|
|
// })
|
|
// .ToList();
|
|
|
|
//foreach (var Country in saCountryList) {
|
|
|
|
// rsCountryDic[Country.CountryID] = Country;
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var saCountry_tw = db.Queryable<SETB_SYS_Country>()
|
|
//搜尋條件
|
|
.Where(x => x.OrgID == i_crm.ORIGID && x.Effective == "Y" && x.DelStatus == "N")
|
|
.WhereIF(!string.IsNullOrEmpty(sRegionID), x => x.RegionID == sRegionID)
|
|
//.WhereIF(!string.IsNullOrEmpty(sLangType), x => x.LangType == "zh-TW")
|
|
.OrderBy(o => o.CountryName, OrderByType.Asc)
|
|
.Select(t1 => new CountryDTO
|
|
{ //只取DTO要的資料
|
|
|
|
CountryID = t1.CountryID,
|
|
CountryName = t1.CountryName
|
|
|
|
})
|
|
.ToList();
|
|
|
|
var saCountry_en = db.Queryable<SETB_SYS_Country>()
|
|
//搜尋條件
|
|
.Where(x => x.OrgID == i_crm.ORIGID && x.Effective == "Y" && x.DelStatus == "N")
|
|
.WhereIF(!string.IsNullOrEmpty(sRegionID), x => x.RegionID == sRegionID)
|
|
.WhereIF(!string.IsNullOrEmpty(sLangType), x => x.LangType == "en-US")
|
|
.OrderBy(o => o.CountryName, OrderByType.Asc)
|
|
.Select(t1 => new CountryDTO
|
|
{
|
|
|
|
CountryID = t1.CountryID,
|
|
CountryName = t1.CountryName
|
|
|
|
})
|
|
.ToList();
|
|
|
|
var CountryENDic = new Dictionary<string, CountryDTO>(); //English data DTO
|
|
|
|
foreach (var CountryEN in saCountry_en)
|
|
{
|
|
|
|
CountryENDic[CountryEN.CountryID] = CountryEN; //將English data以CountryID去重複值,塞入Dic
|
|
|
|
}
|
|
|
|
foreach (var name_tw in saCountry_tw)
|
|
{
|
|
|
|
if (CountryENDic.ContainsKey(name_tw.CountryID))
|
|
{
|
|
name_tw.CountryENName = CountryENDic[name_tw.CountryID].CountryName;
|
|
}
|
|
|
|
rsCountryDic[name_tw.CountryID] = name_tw;
|
|
|
|
|
|
//foreach(var name_en in saCountry_en)
|
|
//{
|
|
// if(name_tw.CountryID == name_en.CountryID)
|
|
// {
|
|
// Country = name_en.CountryName + " " + name_tw.CountryName;
|
|
// System.Diagnostics.Debug.WriteLine("Country with data:" + Country);
|
|
// //saCountry.Add(name_tw.CountryID, Country);
|
|
|
|
// }
|
|
//}
|
|
}
|
|
|
|
return rsCountryDic;
|
|
|
|
} while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sMsg = Util.GetLastExceptionMsg(ex);
|
|
|
|
}
|
|
|
|
return rsCountryDic;
|
|
}
|
|
|
|
#endregion 國家選單
|
|
}
|
|
}
|