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.

206 lines
7.9 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. namespace EasyBL.WEBAPP.SYS
  9. {
  10. public class CurrencySetup_QryService : ServiceBase
  11. {
  12. #region 幣別匯率(分頁資料)
  13. /// <summary>
  14. /// 幣別匯率(分頁資料)
  15. /// </summary>
  16. /// <param name="i_crm">todo: describe i_crm parameter on QueryPage</param>
  17. /// <returns></returns>
  18. public ResponseMessage QueryPage(RequestMessage i_crm)
  19. {
  20. ResponseMessage rm = null;
  21. string sMsg = null;
  22. var db = SugarBase.DB;
  23. try
  24. {
  25. do
  26. {
  27. var pml = new PageModel
  28. {
  29. PageIndex = _fetchInt(i_crm, @"pageIndex"),
  30. PageSize = _fetchInt(i_crm, @"pageSize")
  31. };
  32. int iPageCount = 0;
  33. string sSortField = _fetchString(i_crm, @"sortField");
  34. string sSortOrder = _fetchString(i_crm, @"sortOrder");
  35. string sYear = _fetchString(i_crm, @"year");
  36. string sMonth = _fetchString(i_crm, @"month");
  37. string sCurrency = _fetchString(i_crm, @"currency");
  38. pml.DataList = db.Queryable<OTB_SYS_Currency, OTB_SYS_Arguments>
  39. ((t1, t2) =>
  40. new object[] {
  41. JoinType.Inner, t1.currency == t2.ArgumentID && t2.ArgumentClassID == "Currency" && t2.OrgID == i_crm.ORIGID
  42. }
  43. )
  44. .Where((t1, t2) => t1.OrgID == i_crm.ORIGID)
  45. .WhereIF(!string.IsNullOrEmpty(sYear), (t1, t2) => t1.year.ToString() == sYear)
  46. .WhereIF(!string.IsNullOrEmpty(sMonth), (t1, t2) => t1.month.ToString() == sMonth)
  47. .WhereIF(!string.IsNullOrEmpty(sCurrency), (t1, t2) => t1.currency.ToString() == sCurrency)
  48. .OrderBy(sSortField, sSortOrder)
  49. .Select((t1, t2) => new OTB_SYS_Currency
  50. {
  51. year = t1.year,
  52. month = t1.month,
  53. exchange_rate = t1.exchange_rate,
  54. currency = t1.currency
  55. })
  56. .ToPageList(pml.PageIndex, pml.PageSize, ref iPageCount);
  57. pml.Total = iPageCount;
  58. rm = new SuccessResponseMessage(null, i_crm);
  59. rm.DATA.Add(BLWording.REL, pml);
  60. } while (false);
  61. }
  62. catch (Exception ex)
  63. {
  64. sMsg = Util.GetLastExceptionMsg(ex);
  65. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(CurrencySetup_QryService), @"幣別匯率", @"QueryPage(幣別匯率(分頁資料))", @"", @"", @"");
  66. }
  67. finally
  68. {
  69. if (null != sMsg)
  70. {
  71. rm = new ErrorResponseMessage(sMsg, i_crm);
  72. }
  73. }
  74. return rm;
  75. }
  76. #endregion
  77. #region 幣別查詢(多筆)
  78. /// <summary>
  79. /// 幣別查詢(多筆)
  80. /// </summary>
  81. /// <param name="i_crm"></param>
  82. /// <returns></returns>
  83. public ResponseMessage CurrencyList(RequestMessage i_crm)
  84. {
  85. ResponseMessage rm = null;
  86. string sMsg = null;
  87. var db = SugarBase.GetIntance();
  88. try
  89. {
  90. do
  91. {
  92. var saArgumentClass = db.Queryable<OTB_SYS_Arguments>()
  93. .Where(x => x.OrgID == i_crm.ORIGID
  94. && x.ArgumentClassID == "Currency"
  95. && x.Effective == "Y"
  96. && x.DelStatus == "N")
  97. .OrderBy(x => x.ArgumentID)
  98. .ToList();
  99. rm = new SuccessResponseMessage(null, i_crm);
  100. rm.DATA.Add(BLWording.REL, saArgumentClass);
  101. } while (false);
  102. }
  103. catch (Exception ex)
  104. {
  105. sMsg = Util.GetLastExceptionMsg(ex);
  106. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(CurrencySetup_QryService), "", "QueryList(參數類別(多筆))", "", "", "");
  107. }
  108. finally
  109. {
  110. if (null != sMsg)
  111. {
  112. rm = new ErrorResponseMessage(sMsg, i_crm);
  113. }
  114. }
  115. return rm;
  116. }
  117. #endregion
  118. #region GetCurrencyByYear
  119. /// <summary>
  120. /// GetCurrencyByYear
  121. /// </summary>
  122. /// <param name="i_crm"></param>
  123. /// <returns></returns>
  124. public ResponseMessage GetCurrencyByYear(RequestMessage i_crm)
  125. {
  126. ResponseMessage rm = null;
  127. string sMsg = null;
  128. var db = SugarBase.GetIntance();
  129. try
  130. {
  131. do
  132. {
  133. string spYear = _fetchString(i_crm, @"year");
  134. DateTime dtParse;
  135. if (!DateTime.TryParse(spYear, out dtParse))
  136. {
  137. sMsg = "DateTime Parse Error";
  138. break;
  139. }
  140. string sYear = dtParse.Year.ToString();
  141. string sMonth = dtParse.Month.ToString();
  142. var saCurrency = db.Queryable<OTB_SYS_Currency, OTB_SYS_Arguments>
  143. ((t1, t2) =>
  144. new object[] {
  145. JoinType.Inner, t1.currency == t2.ArgumentID && t2.ArgumentClassID == "Currency" && t2.OrgID == i_crm.ORIGID
  146. }
  147. )
  148. .Where((t1, t2) => t1.OrgID == i_crm.ORIGID)
  149. .WhereIF(!string.IsNullOrEmpty(sYear), (t1, t2) => t1.year.ToString() == sYear)
  150. .WhereIF(!string.IsNullOrEmpty(sMonth), (t1, t2) => t1.month.ToString() == sMonth)
  151. .Select((t1, t2) => new OTB_SYS_Arguments
  152. {
  153. ArgumentID = t1.currency,
  154. ArgumentValue = t2.ArgumentValue,
  155. Correlation = t1.exchange_rate.ToString()
  156. })
  157. .ToList();
  158. rm = new SuccessResponseMessage(null, i_crm);
  159. foreach (OTB_SYS_Arguments item in saCurrency as List<OTB_SYS_Arguments>)
  160. {
  161. decimal dcExchangeRate;
  162. if (decimal.TryParse(item.Correlation, out dcExchangeRate))
  163. {
  164. item.Correlation = dcExchangeRate.ToString("#0.##");
  165. }
  166. }
  167. rm.DATA.Add(BLWording.REL, saCurrency);
  168. } while (false);
  169. }
  170. catch (Exception ex)
  171. {
  172. sMsg = Util.GetLastExceptionMsg(ex);
  173. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(CurrencySetup_QryService), "", "QueryList(參數類別(多筆))", "", "", "");
  174. }
  175. finally
  176. {
  177. if (null != sMsg)
  178. {
  179. rm = new ErrorResponseMessage(sMsg, i_crm);
  180. }
  181. }
  182. return rm;
  183. }
  184. #endregion
  185. }
  186. }