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.
500 lines
17 KiB
500 lines
17 KiB
using EasyBL.WebApi.Message;
|
|
using Entity.Sugar;
|
|
using Entity.ViewModels;
|
|
using SqlSugar;
|
|
using SqlSugar.Base;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using EasyBL.WEBAPP.WSM;
|
|
using System.Linq;
|
|
using System.Collections;
|
|
|
|
namespace EasyBL.WEBAPP.SYS
|
|
{
|
|
public class CategoryMaintain_QryService_Backup : ServiceBase
|
|
{
|
|
|
|
//public static string LANGUAGEID = "zh-TW";
|
|
|
|
#region 類別管理(分頁查詢)
|
|
|
|
/// <summary>
|
|
/// 類別管理(分頁查詢)
|
|
/// </summary>
|
|
/// <param name="i_crm"></param>
|
|
/// <returns></returns>
|
|
/// Origtek framwork API
|
|
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 sSortField = _fetchString(i_crm, @"sortField");
|
|
var sSortOrder = _fetchString(i_crm, @"sortOrder");
|
|
|
|
var sLanguageID = _fetchString(i_crm, @"LanguageID");
|
|
|
|
var sCategoryName = _fetchString(i_crm, @"CategoryName");
|
|
var sCategoryType = _fetchString(i_crm, @"CategoryType");
|
|
|
|
var sIsMainCategory = _fetchString(i_crm, @"IsMainCategory");
|
|
|
|
var sEffective = _fetchString(i_crm, @"Effective");
|
|
var bExcel = _fetchBool(i_crm, @"Excel");
|
|
|
|
System.Diagnostics.Debug.WriteLine("i_crm.LANG" + ": " + i_crm.LANG);
|
|
|
|
pml.DataList = db.Queryable<SETB_SYS_Category>()
|
|
|
|
.Where(t1 => t1.OrgID == i_crm.ORIGID && t1.DelStatus != "Y" && sEffective.Contains(t1.Effective))
|
|
.WhereIF(!string.IsNullOrEmpty(sCategoryName), t1 => t1.CategoryName.Contains(sCategoryName))
|
|
.Where(t1 => t1.CategoryType == sCategoryType)
|
|
.Where(t1 => t1.IsMainCategory == sIsMainCategory)
|
|
.Where(t1 => t1.LanguageID == sLanguageID)
|
|
.Select(t1 => new View_SYS_Category
|
|
{
|
|
CategoryID = SqlFunc.GetSelfAndAutoFill(t1.CategoryID)
|
|
|
|
})
|
|
.OrderBy(sSortField, sSortOrder)
|
|
.ToPageList(pml.PageIndex, bExcel ? 100000 : pml.PageSize, ref iPageCount);
|
|
|
|
var dataList = pml.DataList as List<View_SYS_Category>;
|
|
|
|
dataList = SetCount(i_crm, dataList);
|
|
dataList = Translate(i_crm, dataList, sLanguageID);
|
|
|
|
pml.DataList = dataList;
|
|
|
|
pml.Total = iPageCount;
|
|
|
|
rm = new SuccessResponseMessage(null, i_crm);
|
|
if (bExcel)
|
|
{
|
|
const string sFileName = "類別";
|
|
var oHeader = new Dictionary<string, string>
|
|
{
|
|
{ "RowIndex", "項次" },
|
|
{ "CategoryID", "類別編號" },
|
|
{ "ParentID", "父類別編號" },
|
|
{ "CategoryName", "類別名稱" },
|
|
{ "CategoryType", "類別類型" },
|
|
{ "OrderByValue", "排序" },
|
|
{ "Effective", "狀態(Y:有效;N:無效)" }
|
|
};
|
|
|
|
var dicAlain = ExcelService.GetExportAlain(oHeader, "Effective");
|
|
var saCategory = pml.DataList as List<View_SYS_Category>;
|
|
var bOk = new ExcelService().CreateExcelByList(saCategory, 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.ShowEasy.CategoryMaintain_QryService", "", "QueryPage(類別管理(分頁查詢))", "", "", "");
|
|
}
|
|
finally
|
|
{
|
|
if (null != sMsg)
|
|
{
|
|
rm = new ErrorResponseMessage(sMsg, i_crm);
|
|
}
|
|
}
|
|
return rm;
|
|
}
|
|
|
|
#endregion 類別管理(分頁查詢)
|
|
|
|
#region 類別管理(單筆查詢)
|
|
|
|
/// <summary>
|
|
/// 類別管理(單筆查詢)
|
|
/// </summary>
|
|
/// <param name="i_crm"></param>
|
|
/// <returns></returns>
|
|
/// Origtek framwork API
|
|
public ResponseMessage QueryOne(RequestMessage i_crm)
|
|
{
|
|
ResponseMessage rm = null;
|
|
string sMsg = null;
|
|
var db = SugarBase.GetIntance();
|
|
try
|
|
{
|
|
do
|
|
{
|
|
var sCategoryID = _fetchString(i_crm, @"CategoryID");
|
|
|
|
var sLanguageID = _fetchString(i_crm, @"LanguageID");
|
|
|
|
var oEntity = db.Queryable<SETB_SYS_Category, OTB_SYS_Members, OTB_SYS_Members>
|
|
((t1, t2, t3) =>
|
|
new object[] {
|
|
JoinType.Left, t1.OrgID == t2.OrgID && t1.CreateUser == t2.MemberID,
|
|
JoinType.Left, t1.OrgID == t3.OrgID && t1.ModifyUser == t3.MemberID
|
|
}
|
|
)
|
|
.Where((t1, t2, t3) => t1.OrgID == i_crm.ORIGID && t1.CategoryID == sCategoryID)
|
|
.Where(t1 => t1.LanguageID == sLanguageID)
|
|
.Select((t1, t2, t3) => new View_SYS_Category
|
|
{
|
|
CategoryID = SqlFunc.GetSelfAndAutoFill(t1.CategoryID),
|
|
CreateUserName = t2.MemberName,
|
|
ModifyUserName = t3.MemberName
|
|
})
|
|
.Single();
|
|
|
|
rm = new SuccessResponseMessage(null, i_crm);
|
|
rm.DATA.Add(BLWording.REL, oEntity);
|
|
} while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
sMsg = Util.GetLastExceptionMsg(ex);
|
|
LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(CategoryMaintain_QryService), "", "QueryOne(類別管理(單筆查詢))", "", "", "");
|
|
}
|
|
finally
|
|
{
|
|
if (null != sMsg)
|
|
{
|
|
rm = new ErrorResponseMessage(sMsg, i_crm);
|
|
}
|
|
}
|
|
return rm;
|
|
}
|
|
|
|
#endregion 類別管理(單筆查詢)
|
|
|
|
#region 類別管理(更新排序 call CategoryMaintainUpd UpdateOrderByValue)
|
|
|
|
/// <summary>
|
|
/// 類別管理(更新排序 call CategoryMaintainUpd UpdateOrderByValue)
|
|
/// </summary>
|
|
/// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
|
|
/// <returns></returns>
|
|
/// Origtek framwork API
|
|
public ResponseMessage UpdateOrderByValue(RequestMessage i_crm)
|
|
{
|
|
|
|
CategoryMaintain_UpdService cm_upd = new CategoryMaintain_UpdService();
|
|
|
|
ResponseMessage rm = cm_upd.UpdateOrderByValue(i_crm);
|
|
|
|
return rm;
|
|
}
|
|
|
|
#endregion 類別管理(更新排序 call CategoryMaintainUpd UpdateOrderByValue)
|
|
|
|
#region 類別管理(查詢筆數)
|
|
|
|
/// <summary>
|
|
/// 類別管理(查詢筆數)
|
|
/// </summary>
|
|
/// <param name="i_crm"></param>
|
|
/// <returns></returns>
|
|
/// Origtek framwork API
|
|
public ResponseMessage QueryCout(RequestMessage i_crm)
|
|
{
|
|
ResponseMessage rm = null;
|
|
string sMsg = null;
|
|
var db = SugarBase.GetIntance();
|
|
try
|
|
{
|
|
do
|
|
{
|
|
|
|
int iCount = QueryIntCount(i_crm);
|
|
|
|
rm = new SuccessResponseMessage(null, i_crm);
|
|
rm.DATA.Add(BLWording.REL, iCount);
|
|
|
|
} while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sMsg = Util.GetLastExceptionMsg(ex);
|
|
LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(CategoryMaintain_QryService), "", "QueryOrder 類別管理(查詢筆數)", "", "", "");
|
|
}
|
|
finally
|
|
{
|
|
if (null != sMsg)
|
|
{
|
|
rm = new ErrorResponseMessage(sMsg, i_crm);
|
|
}
|
|
}
|
|
return rm;
|
|
}
|
|
#endregion 類別管理(查詢筆數)
|
|
|
|
#region 類別管理(查詢int筆數)
|
|
|
|
/// <summary>
|
|
/// 類別管理(查詢int筆數)
|
|
/// </summary>
|
|
/// <param name="i_crm"></param>
|
|
/// <returns></returns>
|
|
public int QueryIntCount(RequestMessage i_crm)
|
|
{
|
|
ResponseMessage rm = null;
|
|
string sMsg = null;
|
|
var db = SugarBase.GetIntance();
|
|
|
|
int iCount = 0;
|
|
|
|
try
|
|
{
|
|
do
|
|
{
|
|
|
|
var sCategoryID = _fetchString(i_crm, @"CategoryID");
|
|
|
|
var sLanguageID = _fetchString(i_crm, @"LanguageID");
|
|
var sCategoryType = _fetchString(i_crm, @"CategoryType");
|
|
|
|
var sIsMainCategory = _fetchString(i_crm, @"IsMainCategory");
|
|
|
|
var dataList = db.Queryable<SETB_SYS_Category>()
|
|
.Where(t1 => t1.OrgID == i_crm.ORIGID && t1.DelStatus == "N")
|
|
.WhereIF(!string.IsNullOrEmpty(sCategoryID), t1 => t1.CategoryID == sCategoryID)
|
|
.Where(t1 => t1.IsMainCategory == sIsMainCategory)
|
|
.Where(t1 => t1.CategoryType == sCategoryType)
|
|
.Select(t1 => new View_SYS_Category {
|
|
|
|
CategoryID = SqlFunc.GetSelfAndAutoFill(t1.CategoryID)
|
|
|
|
})
|
|
.ToList();
|
|
|
|
dataList = GetUniqueList(dataList);
|
|
|
|
iCount = dataList.Count;
|
|
|
|
rm = new SuccessResponseMessage(null, i_crm);
|
|
rm.DATA.Add(BLWording.REL, iCount);
|
|
|
|
} while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sMsg = Util.GetLastExceptionMsg(ex);
|
|
LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(CategoryMaintain_QryService), "", "QueryCount 類別管理(查詢int筆數)", "", "", "");
|
|
}
|
|
finally
|
|
{
|
|
if (null != sMsg)
|
|
{
|
|
rm = new ErrorResponseMessage(sMsg, i_crm);
|
|
}
|
|
}
|
|
return iCount;
|
|
}
|
|
#endregion 類別管理(查詢int筆數)
|
|
|
|
#region 類別管理(父類別查詢)
|
|
|
|
/// <summary>
|
|
/// 類別管理(父類別查詢)
|
|
/// </summary>
|
|
/// <param name="i_crm"></param>
|
|
/// <returns></returns>
|
|
public ResponseMessage QueryParentList(RequestMessage i_crm)
|
|
{
|
|
ResponseMessage rm = null;
|
|
string sMsg = null;
|
|
var db = SugarBase.GetIntance();
|
|
try
|
|
{
|
|
do
|
|
{
|
|
var sLanguageID = _fetchString(i_crm, @"LanguageID");
|
|
var sCategoryType = _fetchString(i_crm, @"CategoryType");
|
|
|
|
var saCategory = db.Queryable<SETB_SYS_Category>()
|
|
.Where(x => x.OrgID == i_crm.ORIGID && x.Effective == "Y" && x.DelStatus == "N")
|
|
.Where(x => x.CategoryType == sCategoryType)
|
|
.Where(x => x.IsMainCategory == "Y")
|
|
.Select(x => new View_SYS_Category
|
|
{
|
|
|
|
CategoryID = SqlFunc.GetSelfAndAutoFill(x.CategoryID)
|
|
|
|
})
|
|
.ToList();
|
|
|
|
saCategory = Translate(i_crm, saCategory, sLanguageID);
|
|
|
|
rm = new SuccessResponseMessage(null, i_crm);
|
|
rm.DATA.Add(BLWording.REL, saCategory);
|
|
} while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sMsg = Util.GetLastExceptionMsg(ex);
|
|
LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(CategoryMaintain_QryService), "", "QueryParentList 類別管理(父類別查詢)", "", "", "");
|
|
}
|
|
finally
|
|
{
|
|
if (null != sMsg)
|
|
{
|
|
rm = new ErrorResponseMessage(sMsg, i_crm);
|
|
}
|
|
}
|
|
return rm;
|
|
}
|
|
|
|
#endregion 父類別查詢
|
|
|
|
#region 類別管理(以ID查詢)
|
|
|
|
/// <summary>
|
|
/// 類別管理(以ID查詢)
|
|
/// </summary>
|
|
/// <param name="i_crm"></param>
|
|
/// <returns></returns>
|
|
public List<SETB_SYS_Category> FindByIDs(RequestMessage i_crm, string sCategoryID, string sLanguage) {
|
|
|
|
ResponseMessage rm = null;
|
|
string sMsg = null;
|
|
var db = SugarBase.GetIntance();
|
|
|
|
var saCategoryList = new List<SETB_SYS_Category>();
|
|
|
|
try
|
|
{
|
|
do
|
|
{
|
|
|
|
saCategoryList = db.Queryable<SETB_SYS_Category>()
|
|
.Where(x => x.OrgID == i_crm.ORIGID && x.Effective == "Y" && x.DelStatus == "N")
|
|
.Where(t1 => t1.CategoryID == sCategoryID)
|
|
.Where(t1 => t1.LanguageID == sLanguage)
|
|
.ToList();
|
|
|
|
rm = new SuccessResponseMessage(null, i_crm);
|
|
rm.DATA.Add(BLWording.REL, saCategoryList);
|
|
} while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sMsg = Util.GetLastExceptionMsg(ex);
|
|
LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(CategoryMaintain_QryService), "", "FindByIDs 類別管理(以ID查詢)", "", "", "");
|
|
|
|
}
|
|
finally
|
|
{
|
|
if (null != sMsg)
|
|
{
|
|
rm = new ErrorResponseMessage(sMsg, i_crm);
|
|
}
|
|
}
|
|
|
|
return saCategoryList;
|
|
|
|
}
|
|
|
|
#endregion 類別管理(以ID查詢)
|
|
|
|
#region 類別管理(設定Count)
|
|
|
|
/// <summary>
|
|
/// 類別管理(設定Count)
|
|
/// </summary>
|
|
/// <param name="i_crm"></param>
|
|
/// <returns></returns>
|
|
public List<View_SYS_Category> SetCount(RequestMessage i_crm, List<View_SYS_Category> dataList) {
|
|
|
|
dataList = GetUniqueList(dataList);
|
|
|
|
for (int i = 0; i < dataList.Count; i++) {
|
|
|
|
dataList[i].OrderCount = dataList.Count;
|
|
|
|
}
|
|
|
|
return dataList;
|
|
|
|
}
|
|
|
|
#endregion 類別管理(設定Count)
|
|
|
|
#region 類別管理(List 取唯一值)
|
|
|
|
/// <summary>
|
|
/// 類別管理(List 取唯一值)
|
|
/// </summary>
|
|
/// <param name="i_crm"></param>
|
|
/// <returns></returns>
|
|
public List<View_SYS_Category> GetUniqueList(List<View_SYS_Category> categoryList) {
|
|
|
|
Dictionary<string, View_SYS_Category> dic_Category = new Dictionary<string, View_SYS_Category>();
|
|
|
|
foreach (View_SYS_Category Category in categoryList)
|
|
{
|
|
|
|
dic_Category[Category.CategoryID] = Category;
|
|
|
|
}
|
|
|
|
categoryList.Clear();
|
|
|
|
foreach (KeyValuePair<string, View_SYS_Category> entry in dic_Category)
|
|
{
|
|
|
|
categoryList.Add(entry.Value);
|
|
|
|
}
|
|
|
|
return categoryList;
|
|
|
|
}
|
|
|
|
#endregion 類別管理(List 取唯一值)
|
|
|
|
#region 類別管理(List 翻譯)
|
|
|
|
/// <summary>
|
|
/// 類別管理(List 翻譯)
|
|
/// </summary>
|
|
/// <param name="i_crm"></param>
|
|
/// <returns></returns>
|
|
|
|
public List<View_SYS_Category> Translate(RequestMessage i_crm, List<View_SYS_Category> categoryList, string sLanguage) {
|
|
|
|
categoryList = GetUniqueList(categoryList);
|
|
|
|
for (int i = 0; i < categoryList.Count; i++) {
|
|
|
|
var Category = categoryList[i];
|
|
var translatedCategory = FindByIDs(i_crm, Category.CategoryID, sLanguage).FirstOrDefault();
|
|
|
|
if (translatedCategory != null)
|
|
{
|
|
|
|
categoryList[i].CategoryName = translatedCategory.CategoryName;
|
|
|
|
}
|
|
}
|
|
|
|
return categoryList;
|
|
}
|
|
|
|
#endregion 類別管理(List 翻譯)
|
|
|
|
}
|
|
}
|