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.

324 lines
19 KiB

2 years ago
  1. using EasyBL.WebApi.Message;
  2. using Entity.Sugar;
  3. using Entity.ViewModels;
  4. using SqlSugar;
  5. using SqlSugar.Base;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. namespace EasyBL.WEBAPP.OPM
  10. {
  11. public class Exhibition_QryService : ServiceBase
  12. {
  13. #region 展覽管理分頁查詢
  14. /// <summary>
  15. /// 展覽管理分頁查詢
  16. /// </summary>
  17. /// <param name="i_crm"></param>
  18. /// <returns></returns>
  19. public ResponseMessage QueryPage(RequestMessage i_crm)
  20. {
  21. ResponseMessage rm = null;
  22. string sMsg = null;
  23. var db = SugarBase.GetIntance();
  24. try
  25. {
  26. do
  27. {
  28. var pml = new PageModel
  29. {
  30. PageIndex = _fetchInt(i_crm, @"pageIndex"),
  31. PageSize = _fetchInt(i_crm, @"pageSize")
  32. };
  33. var iPageCount = 0;
  34. var sSortField = _fetchString(i_crm, @"sortField");
  35. var sSortOrder = _fetchString(i_crm, @"sortOrder");
  36. var sExhibitionCode = _fetchString(i_crm, @"ExhibitionCode");
  37. var sExhibitioname = _fetchString(i_crm, @"Exhibitioname");
  38. var sExhibitionDateStart = _fetchString(i_crm, @"ExhibitionDateStart");
  39. var sExhibitionDateEnd = _fetchString(i_crm, @"ExhibitionDateEnd");
  40. var sCreateDateStart = _fetchString(i_crm, @"CreateDateStart");
  41. var sCreateDateEnd = _fetchString(i_crm, @"CreateDateEnd");
  42. var sModifyDateStart = _fetchString(i_crm, @"ModifyDateStart");
  43. var sModifyDateEnd = _fetchString(i_crm, @"ModifyDateEnd");
  44. var sIsShowWebSite = _fetchString(i_crm, @"IsShowWebSite");
  45. var sCreateUser = _fetchString(i_crm, @"CreateUser");
  46. var sArea = _fetchString(i_crm, @"Area");
  47. var sState = _fetchString(i_crm, @"State");
  48. var sExhibitionAddress = _fetchString(i_crm, @"ExhibitionAddress");
  49. var sEffective = _fetchString(i_crm, @"Effective");
  50. var sIsTransfer = _fetchString(i_crm, @"IsTransfer");
  51. var bExcel = _fetchBool(i_crm, @"Excel");
  52. var sExcelType = _fetchString(i_crm, @"ExcelType");
  53. var rExhibitionDateStart = new DateTime();
  54. var rExhibitionDateEnd = new DateTime();
  55. var rCreateDateStart = new DateTime();
  56. var rCreateDateEnd = new DateTime();
  57. var rModifyDateStart = new DateTime();
  58. var rModifyDateEnd = new DateTime();
  59. if (!string.IsNullOrEmpty(sExhibitionDateStart))
  60. {
  61. rExhibitionDateStart = SqlFunc.ToDate(sExhibitionDateStart);
  62. }
  63. if (!string.IsNullOrEmpty(sExhibitionDateEnd))
  64. {
  65. rExhibitionDateEnd = SqlFunc.ToDate(sExhibitionDateEnd).AddDays(1);
  66. }
  67. if (!string.IsNullOrEmpty(sCreateDateStart))
  68. {
  69. rCreateDateStart = SqlFunc.ToDate(sCreateDateStart);
  70. }
  71. if (!string.IsNullOrEmpty(sCreateDateEnd))
  72. {
  73. rCreateDateEnd = SqlFunc.ToDate(sCreateDateEnd).AddDays(1);
  74. }
  75. if (!string.IsNullOrEmpty(sModifyDateStart))
  76. {
  77. rModifyDateStart = SqlFunc.ToDate(sModifyDateStart);
  78. }
  79. if (!string.IsNullOrEmpty(sModifyDateEnd))
  80. {
  81. rModifyDateEnd = SqlFunc.ToDate(sModifyDateEnd).AddDays(1);
  82. }
  83. pml.DataList = db.Queryable<OTB_OPM_Exhibition, OTB_SYS_Members, OTB_SYS_Arguments, OTB_SYS_Arguments, OTB_SYS_Arguments>
  84. ((t1, t2, t3, t4, t5) =>
  85. new object[] {
  86. JoinType.Left, t1.OrgID == t2.OrgID && t1.CreateUser == t2.MemberID,
  87. JoinType.Left, t1.OrgID == t3.OrgID && t1.Area == t3.ArgumentID && t3.ArgumentClassID == "Area",
  88. JoinType.Left, t1.OrgID == t4.OrgID && t1.State == t4.ArgumentID && t4.ArgumentClassID == "Area",
  89. JoinType.Left, t1.OrgID == t5.OrgID && t1.ExhibitionAddress == t5.ArgumentID && t5.ArgumentClassID == "EHalls"
  90. }
  91. )
  92. .Where((t1, t2, t3, t4, t5) => t1.OrgID == i_crm.ORIGID && t1.ExhibitionCode.Contains(sExhibitionCode) && sIsShowWebSite.Contains(t1.IsShowWebSite) && sEffective.Contains(t1.Effective) && sIsTransfer.Contains(t1.IsTransfer) && (t1.Exhibitioname_EN.Contains(sExhibitioname) || t1.Exhibitioname_TW.Contains(sExhibitioname) || t1.Exhibitioname_CN.Contains(sExhibitioname) || t1.ExhibitioShotName_TW.Contains(sExhibitioname) || t1.ExhibitioShotName_CN.Contains(sExhibitioname) || t1.ExhibitioShotName_EN.Contains(sExhibitioname)))
  93. .WhereIF(!string.IsNullOrEmpty(sExhibitionDateStart), (t1, t2, t3, t4, t5) => t1.ExhibitionDateStart >= rExhibitionDateStart.Date)
  94. .WhereIF(!string.IsNullOrEmpty(sExhibitionDateEnd), (t1, t2, t3, t4, t5) => t1.ExhibitionDateEnd <= rExhibitionDateEnd.Date)
  95. .WhereIF(!string.IsNullOrEmpty(sCreateDateStart), (t1, t2, t3, t4, t5) => t1.CreateDate >= rCreateDateStart.Date)
  96. .WhereIF(!string.IsNullOrEmpty(sCreateDateEnd), (t1, t2, t3, t4, t5) => t1.CreateDate <= rCreateDateEnd.Date)
  97. .WhereIF(!string.IsNullOrEmpty(sModifyDateStart), (t1, t2, t3, t4, t5) => t1.ModifyDate >= rModifyDateStart.Date)
  98. .WhereIF(!string.IsNullOrEmpty(sModifyDateEnd), (t1, t2, t3, t4, t5) => t1.ModifyDate <= rModifyDateEnd.Date)
  99. .WhereIF(!string.IsNullOrEmpty(sArea), (t1, t2, t3, t4, t5) => t1.Area == sArea)
  100. .WhereIF(!string.IsNullOrEmpty(sState), (t1, t2, t3, t4, t5) => t1.State == sState)
  101. .WhereIF(!string.IsNullOrEmpty(sExhibitionAddress), (t1, t2, t3, t4, t5) => t1.ExhibitionAddress == sExhibitionAddress)
  102. .WhereIF(!string.IsNullOrEmpty(sCreateUser), (t1, t2, t3, t4, t5) => t1.CreateUser == sCreateUser)
  103. .Select((t1, t2, t3, t4, t5) => new View_OPM_Exhibition
  104. {
  105. SN = SqlFunc.GetSelfAndAutoFill(t1.SN),
  106. CreateUserName = t2.MemberName,
  107. AreaName = t3.ArgumentValue,
  108. Area_CN = t3.ArgumentValue_CN,
  109. Area_EN = t3.ArgumentValue_EN,
  110. StateName = t4.ArgumentValue,
  111. State_CN = t4.ArgumentValue_CN,
  112. State_EN = t4.ArgumentValue_EN,
  113. ExhibitionAddressName = t5.ArgumentValue,
  114. ExhibitionAddress_CN = t5.ArgumentValue_CN,
  115. ExhibitionAddress_EN = t5.ArgumentValue_EN,
  116. ExhibitioFullName = SqlFunc.IIF(SqlFunc.HasValue(t1.ExhibitioShotName_TW), "(" + SqlFunc.IsNull(t1.ExhibitioShotName_TW, "") + ")", "") + t1.Exhibitioname_TW,
  117. Exhibitioname = t1.Exhibitioname_CN + t1.Exhibitioname_EN
  118. })
  119. .MergeTable()
  120. .OrderBy(sSortField, sSortOrder)
  121. .ToPageList(pml.PageIndex, bExcel ? 100000 : pml.PageSize, ref iPageCount);
  122. pml.Total = iPageCount;
  123. rm = new SuccessResponseMessage(null, i_crm);
  124. if (bExcel)
  125. {
  126. var sFileName = "";
  127. var oHeader = new Dictionary<string, string>();
  128. var listMerge = new List<Dictionary<string, int>>();
  129. var dicAlain = new Dictionary<string, string>();
  130. var dt_new = new DataTable();
  131. var saCustomers1 = pml.DataList;
  132. var saExhibition = pml.DataList as List<View_OPM_Exhibition>;
  133. switch (sExcelType)
  134. {
  135. case "Exhibition_BasicInformation":
  136. {
  137. sFileName = "展覽管理基本資料";
  138. oHeader = new Dictionary<string, string>
  139. {
  140. { "RowIndex", "項次" },
  141. { "ExhibitionCode", "專案代號" },
  142. { "ExhibitioShotName_TW", "活動/展覽簡稱" },
  143. { "Exhibitioname_TW", "活動/展覽名稱" },
  144. { "Exhibitioname_EN", "活動/展覽英文展名" },
  145. { "ExhibitionDateStart", "展覽期間" },
  146. { "CreateUserName", "創建人" },
  147. { "CreateDate", "創建時間" }
  148. };
  149. dt_new.Columns.Add("RowIndex");
  150. dt_new.Columns.Add("ExhibitionCode");
  151. dt_new.Columns.Add("ExhibitioShotName_TW");
  152. dt_new.Columns.Add("Exhibitioname_TW");
  153. dt_new.Columns.Add("Exhibitioname_EN");
  154. dt_new.Columns.Add("ExhibitionDateStart");
  155. dt_new.Columns.Add("CreateUserName");
  156. dt_new.Columns.Add("CreateDate");
  157. foreach (var exhibition in saExhibition)
  158. {
  159. var row_new = dt_new.NewRow();
  160. var sStart = "";
  161. var sEnd = "";
  162. if (exhibition.ExhibitionDateStart != null)
  163. {
  164. sStart = Convert.ToDateTime(exhibition.ExhibitionDateStart).ToString("yyyy/MM/dd");
  165. }
  166. if (exhibition.ExhibitionDateEnd != null)
  167. {
  168. sEnd = Convert.ToDateTime(exhibition.ExhibitionDateEnd).ToString("yyyy/MM/dd");
  169. }
  170. if (exhibition.CreateDate != null)
  171. {
  172. row_new["CreateDate"] = Convert.ToDateTime(exhibition.CreateDate).ToString("yyyy/MM/dd HH:mm");
  173. }
  174. else
  175. {
  176. row_new["CreateDate"] = @"";
  177. }
  178. row_new["RowIndex"] = exhibition.RowIndex;
  179. row_new["ExhibitionCode"] = exhibition.ExhibitionCode;
  180. row_new["ExhibitioShotName_TW"] = exhibition.ExhibitioShotName_TW;
  181. row_new["Exhibitioname_TW"] = exhibition.Exhibitioname_TW;
  182. row_new["Exhibitioname_EN"] = exhibition.Exhibitioname_EN;
  183. row_new["CreateUserName"] = exhibition.CreateUserName;
  184. row_new["ExhibitionDateStart"] = sStart + "~" + sEnd;
  185. dt_new.Rows.Add(row_new);
  186. }
  187. dicAlain = ExcelService.GetExportAlain(oHeader, "ExhibitionCode,ExhibitionDateStart,IsShowWebSite,CreateUserName,CreateDate");
  188. }
  189. break;
  190. case "Exhibition_WenzhongPrjFile":
  191. {
  192. sFileName = "文中專案檔";
  193. oHeader = new Dictionary<string, string>
  194. {
  195. { "RowIndex", "項次" },
  196. { "ExhibitionCode", "專案代號" },
  197. { "ExhibitioShotName_TW", "專案名稱" },
  198. { "CusField1", "專案負責人" },
  199. { "CusField2", "失效日期" }
  200. };
  201. dt_new.Columns.Add("RowIndex");
  202. dt_new.Columns.Add("ExhibitionCode");
  203. dt_new.Columns.Add("ExhibitioShotName_TW");
  204. dt_new.Columns.Add("CusField1");
  205. dt_new.Columns.Add("CusField2");
  206. foreach (var exhibition in saExhibition)
  207. {
  208. var row_new = dt_new.NewRow();
  209. row_new["RowIndex"] = exhibition.RowIndex;
  210. row_new["ExhibitionCode"] = exhibition.ExhibitionCode;
  211. row_new["ExhibitioShotName_TW"] = exhibition.ExhibitioShotName_TW;
  212. row_new["CusField1"] = exhibition.CreateUser.Split('.')[0];
  213. row_new["CusField2"] = "";
  214. dt_new.Rows.Add(row_new);
  215. }
  216. dicAlain = ExcelService.GetExportAlain(oHeader, new string[] { "ExhibitionCode", "CusField1", "CusField2" });
  217. }
  218. break;
  219. default:
  220. {
  221. break;
  222. }
  223. }
  224. var bOk = new ExcelService().CreateExcelByTb(dt_new, out string sPath, oHeader, dicAlain, listMerge, sFileName);
  225. rm.DATA.Add(BLWording.REL, sPath);
  226. }
  227. else
  228. {
  229. rm.DATA.Add(BLWording.REL, pml);
  230. }
  231. } while (false);
  232. }
  233. catch (Exception ex)
  234. {
  235. sMsg = Util.GetLastExceptionMsg(ex);
  236. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBAPP.OPM.Exhibition_QryService", "", "QueryPage(展覽管理分頁查詢)", "", "", "");
  237. }
  238. finally
  239. {
  240. if (null != sMsg)
  241. {
  242. rm = new ErrorResponseMessage(sMsg, i_crm);
  243. }
  244. }
  245. return rm;
  246. }
  247. #endregion 展覽管理分頁查詢
  248. #region 展覽管理單筆查詢
  249. /// <summary>
  250. /// 展覽管理單筆查詢
  251. /// </summary>
  252. /// <param name="i_crm"></param>
  253. /// <returns></returns>
  254. public ResponseMessage QueryOne(RequestMessage i_crm)
  255. {
  256. ResponseMessage rm = null;
  257. string sMsg = null;
  258. var db = SugarBase.GetIntance();
  259. try
  260. {
  261. do
  262. {
  263. var iId = _fetchInt(i_crm, @"Guid");
  264. var oExportExhibition = db.Queryable<OTB_OPM_Exhibition, OTB_SYS_Members, OTB_SYS_Arguments, OTB_SYS_Arguments, OTB_SYS_Arguments>
  265. ((t1, t2, t3, t4, t5) =>
  266. new object[] {
  267. JoinType.Left, t1.OrgID == t2.OrgID && t1.CreateUser == t2.MemberID,
  268. JoinType.Left, t1.OrgID == t3.OrgID && t1.Area == t3.ArgumentID && t3.ArgumentClassID == "Area",
  269. JoinType.Left, t1.OrgID == t4.OrgID && t1.State == t4.ArgumentID && t4.ArgumentClassID == "Area",
  270. JoinType.Left, t1.OrgID == t5.OrgID && t1.ExhibitionAddress == t5.ArgumentID && t5.ArgumentClassID == "EHalls"
  271. }
  272. )
  273. .Where((t1, t2, t3) => t1.OrgID == i_crm.ORIGID && t1.SN == iId)
  274. .Select((t1, t2, t3, t4, t5) => new View_OPM_Exhibition
  275. {
  276. SN = SqlFunc.GetSelfAndAutoFill(t1.SN),
  277. CreateUserName = t2.MemberName,
  278. AreaName = t3.ArgumentValue,
  279. Area_CN = t3.ArgumentValue_CN,
  280. Area_EN = t3.ArgumentValue_EN,
  281. StateName = t4.ArgumentValue,
  282. State_CN = t4.ArgumentValue_CN,
  283. State_EN = t4.ArgumentValue_EN,
  284. ExhibitionAddressName = t5.ArgumentValue,
  285. ExhibitionAddress_CN = t5.ArgumentValue_CN,
  286. ExhibitionAddress_EN = t5.ArgumentValue_EN,
  287. ExhibitioFullName = SqlFunc.IIF(SqlFunc.HasValue(t1.ExhibitioShotName_TW), "(" + SqlFunc.IsNull(t1.ExhibitioShotName_TW, "") + ")", "") + t1.Exhibitioname_TW,
  288. Exhibitioname = t1.Exhibitioname_CN + t1.Exhibitioname_EN
  289. }).Single();
  290. rm = new SuccessResponseMessage(null, i_crm);
  291. rm.DATA.Add(BLWording.REL, oExportExhibition);
  292. } while (false);
  293. }
  294. catch (Exception ex)
  295. {
  296. sMsg = Util.GetLastExceptionMsg(ex);
  297. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBAPP.OPM.Exhibition_QryService", "", "QueryOne(展覽管理單筆查詢)", "", "", "");
  298. }
  299. finally
  300. {
  301. if (null != sMsg)
  302. {
  303. rm = new ErrorResponseMessage(sMsg, i_crm);
  304. }
  305. }
  306. return rm;
  307. }
  308. #endregion 展覽管理單筆查詢
  309. }
  310. }