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.
434 lines
16 KiB
434 lines
16 KiB
using EasyBL.WebApi.Message;
|
|
using EasyBL.WEBAPP.WSM;
|
|
using Entity.Sugar;
|
|
using Entity.ViewModels;
|
|
using SqlSugar;
|
|
using SqlSugar.Base;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace EasyBL.WEBAPP.SYS
|
|
{
|
|
public class SurveyMaintain_QryService : ServiceBase
|
|
{
|
|
#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.DB;
|
|
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 sSurveyType = _fetchString(i_crm, @"SurveyType");
|
|
|
|
var sCategoryID = _fetchString(i_crm, @"CategoryID");
|
|
var sAnswerType = _fetchString(i_crm, @"AnswerType");
|
|
|
|
var sSurveyName = _fetchString(i_crm, @"SurveyName");
|
|
var sEffective = _fetchString(i_crm, @"Effective");
|
|
var bExcel = _fetchBool(i_crm, @"Excel");
|
|
|
|
pml.DataList = db.Queryable<SETB_SAL_Survey, SETB_SYS_Category, OTB_SYS_Arguments, OTB_SYS_Arguments>((t1, t2, t3, t4) => new object[] {
|
|
|
|
JoinType.Left, t1.CategoryID == t2.CategoryID,
|
|
JoinType.Left, t1.SurveyType == t3.ArgumentID && t3.ArgumentClassID == "SurveyType",
|
|
JoinType.Left, t1.AnswerType == t4.ArgumentID && t4.ArgumentClassID == "AnswerType"
|
|
|
|
})
|
|
|
|
|
|
.Where(t1 => t1.OrgID == i_crm.ORIGID && t1.DelStatus != "Y" && t1.SurveyName.Contains(sSurveyName) && sEffective.Contains(t1.Effective))
|
|
.WhereIF(!String.IsNullOrEmpty(sSurveyType), t1 => t1.SurveyType == sSurveyType)
|
|
.WhereIF(!string.IsNullOrEmpty(sAnswerType), t1 => t1.AnswerType == sAnswerType)
|
|
.WhereIF(!string.IsNullOrEmpty(sCategoryID), t1 => t1.CategoryID == sCategoryID)
|
|
.Select((t1, t2, t3, t4) => new View_SAL_Survey
|
|
{
|
|
|
|
SurveyID = SqlFunc.GetSelfAndAutoFill(t1.SurveyID),
|
|
SurveyTypeName = t3.ArgumentValue,
|
|
CategoryName = t2.CategoryName,
|
|
AnswerTypeName = t4.ArgumentValue,
|
|
OrderCount = SqlFunc.Subqueryable<SETB_SAL_Survey>()
|
|
|
|
.Where(p => 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", "項次" },
|
|
{ "SurveyID","問卷編號" },
|
|
{ "SurveyName","問卷名稱" },
|
|
{ "CategoryName","類別名稱" },
|
|
{ "AnswerTypeName", "答案類別名稱" },
|
|
{ "Answer", "答案" },
|
|
{ "Effective", "狀態(Y:有效;N:無效)" },
|
|
{ "OrderByValue", "排序" }
|
|
|
|
};
|
|
|
|
var dicAlain = ExcelService.GetExportAlain(oHeader, "Effective");
|
|
var saSurvey = pml.DataList as List<View_SAL_Survey>;
|
|
|
|
|
|
var bOk = new ExcelService().CreateExcelByList(saSurvey, 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, nameof(SurveyMaintain_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 iSurveyID = _fetchInt(i_crm, @"SurveyID");
|
|
|
|
var oEntity = db.Queryable<SETB_SAL_Survey, 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.SurveyID == iSurveyID)
|
|
.Select((t1, t2, t3) => new SETB_SAL_Survey
|
|
{
|
|
SurveyID = SqlFunc.GetSelfAndAutoFill(t1.SurveyID),
|
|
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 Upd service)
|
|
|
|
/// <summary>
|
|
/// 問卷管理(更新排序 call Upd service)
|
|
/// </summary>
|
|
/// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
|
|
/// <returns></returns>
|
|
/// Origtek framwork API
|
|
public ResponseMessage UpdateOrderByValue(RequestMessage i_crm)
|
|
{
|
|
|
|
SurveyMaintain_UpdService sm_upd = new SurveyMaintain_UpdService();
|
|
|
|
ResponseMessage rm = sm_upd.UpdateOrderByValue(i_crm);
|
|
|
|
return rm;
|
|
}
|
|
|
|
#endregion 問卷管理(更新排序 Upd)
|
|
|
|
#region 問卷管理(List 查詢)
|
|
|
|
/// <summary>
|
|
/// 問卷管理(List 查詢)
|
|
/// </summary>
|
|
/// <param name="i_crm"></param>
|
|
/// <returns></returns>
|
|
/// Origtek framwork API
|
|
public ResponseMessage QueryList(RequestMessage i_crm)
|
|
{
|
|
ResponseMessage rm = null;
|
|
return rm;
|
|
}
|
|
|
|
#endregion 問卷管理(List 查詢)
|
|
|
|
#region 問卷管理-問卷類別查詢(List 查詢類別)
|
|
|
|
/// <summary>
|
|
/// 問卷管理-類別查詢(List 查詢類別)
|
|
/// </summary>
|
|
/// <param name="i_crm"></param>
|
|
/// <returns></returns>
|
|
public ResponseMessage QuerySurveyTypeList(RequestMessage i_crm)
|
|
{
|
|
ResponseMessage rm = null;
|
|
string sMsg = null;
|
|
var db = SugarBase.GetIntance();
|
|
|
|
var sArgumentClassID = "SurveyType";
|
|
|
|
try
|
|
{
|
|
do
|
|
{
|
|
var saSurveyTypeList = db.Queryable<OTB_SYS_Arguments>()
|
|
//搜尋條件
|
|
.Where(x => x.OrgID == i_crm.ORIGID && x.Effective == "Y" && x.DelStatus == "N")
|
|
.Where(x => x.ArgumentClassID == sArgumentClassID)
|
|
.ToList();
|
|
|
|
rm = new SuccessResponseMessage(null, i_crm);
|
|
rm.DATA.Add(BLWording.REL, saSurveyTypeList);
|
|
} while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sMsg = Util.GetLastExceptionMsg(ex);
|
|
LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(SurveyMaintain_QryService), "", "QuerySurveyList 問卷管理-問卷類別查詢(List 查詢類別)", "", "", "");
|
|
}
|
|
finally
|
|
{
|
|
if (null != sMsg)
|
|
{
|
|
rm = new ErrorResponseMessage(sMsg, i_crm);
|
|
}
|
|
}
|
|
return rm;
|
|
}
|
|
|
|
#endregion 問卷管理-問卷類別查詢(List 查詢類別)
|
|
|
|
#region 問卷管理(List 查詢所有子類別 Call CategoryMaintain_QryService QueryAllSubCategoryList)
|
|
|
|
/// <summary>
|
|
/// 問卷管理(List 查詢所有子類別 Call CategoryMaintain_QryService QueryAllSubCategoryList)
|
|
/// </summary>
|
|
/// <param name="i_crm"></param>
|
|
/// <returns></returns>
|
|
public ResponseMessage QueryCategoryList(RequestMessage i_crm)
|
|
{
|
|
|
|
CategoryMaintain_QryService cm_qry = new CategoryMaintain_QryService();
|
|
|
|
ResponseMessage rm = cm_qry.QueryAllSubCategoryList(i_crm);
|
|
|
|
return rm;
|
|
}
|
|
|
|
#endregion 問卷管理(List 查詢所有子類別 Call CategoryMaintain_QryService QueryAllSubCategoryList)
|
|
|
|
#region 問卷管理-答案類別查詢(List 查詢類別)
|
|
|
|
/// <summary>
|
|
/// 問卷管理-答案類別查詢(List 查詢類別)
|
|
/// </summary>
|
|
/// <param name="i_crm"></param>
|
|
/// <returns></returns>
|
|
public ResponseMessage QueryAnswerTypeList(RequestMessage i_crm)
|
|
{
|
|
ResponseMessage rm = null;
|
|
string sMsg = null;
|
|
var db = SugarBase.GetIntance();
|
|
|
|
var sArgumentClassID = "AnswerType";
|
|
|
|
try
|
|
{
|
|
do
|
|
{
|
|
var saAnswerTypeList = db.Queryable<OTB_SYS_Arguments>()
|
|
//搜尋條件
|
|
.Where(x => x.OrgID == i_crm.ORIGID && x.Effective == "Y" && x.DelStatus == "N")
|
|
.Where(x => x.ArgumentClassID == sArgumentClassID)
|
|
.ToList();
|
|
|
|
rm = new SuccessResponseMessage(null, i_crm);
|
|
rm.DATA.Add(BLWording.REL, saAnswerTypeList);
|
|
|
|
} while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sMsg = Util.GetLastExceptionMsg(ex);
|
|
LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(SurveyMaintain_QryService), "", "QueryAnswerTypeList 問卷管理-答案類別查詢(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>
|
|
/// 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), "", "QueryCout 問卷管理(查詢排序)", "", "", "");
|
|
}
|
|
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 sSurveyType = _fetchString(i_crm, @"SurveyType");
|
|
var sSurveyName = _fetchString(i_crm, @"SurveyName");
|
|
|
|
iCount = db.Queryable<SETB_SAL_Survey>()
|
|
.Where(x => x.OrgID == i_crm.ORIGID && x.DelStatus != "Y")
|
|
.WhereIF(!string.IsNullOrEmpty(sSurveyType), t1 => t1.SurveyType == sSurveyType)
|
|
.WhereIF(!string.IsNullOrEmpty(sSurveyName), t1 => t1.SurveyName == sSurveyName)
|
|
.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(SurveyMaintain_QryService), "", "QueryIntCount 問卷管理(查詢int筆數)", "", "", "");
|
|
}
|
|
finally
|
|
{
|
|
if (null != sMsg)
|
|
{
|
|
rm = new ErrorResponseMessage(sMsg, i_crm);
|
|
}
|
|
}
|
|
return iCount;
|
|
}
|
|
#endregion 類別管理(查詢int筆數)
|
|
}
|
|
}
|