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.

181 lines
8.5 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.EIP
  9. {
  10. public class BillChangeApply_QryService : ServiceBase
  11. {
  12. #region 帳單更改申請單分頁查詢
  13. /// <summary>
  14. /// 帳單更改申請單分頁查詢
  15. /// </summary>
  16. /// <param name="i_crm"></param>
  17. /// <returns></returns>
  18. public ResponseMessage QueryPage(RequestMessage i_crm)
  19. {
  20. ResponseMessage rm = null;
  21. string sMsg = null;
  22. var db = SugarBase.GetIntance();
  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. var iPageCount = 0;
  33. var sSortField = _fetchString(i_crm, @"sortField");
  34. var sSortOrder = _fetchString(i_crm, @"sortOrder");
  35. var sKeyNote = _fetchString(i_crm, @"KeyNote");
  36. var sApplicant = _fetchString(i_crm, @"Applicant");
  37. var sImportant = _fetchString(i_crm, @"Important");
  38. var sStatus = _fetchString(i_crm, @"Status");
  39. var sRoles = _fetchString(i_crm, @"Roles");
  40. var bExcel = _fetchBool(i_crm, @"Excel");
  41. pml.DataList = db.Queryable<OTB_EIP_BillChangeApply, OTB_SYS_Members, OTB_SYS_Departments, OTB_SYS_Members>
  42. ((t1, t2, t3, t4) =>
  43. new object[] {
  44. JoinType.Inner, t1.OrgID == t2.OrgID && t1.Applicant == t2.MemberID,
  45. JoinType.Inner, t2.OrgID == t3.OrgID && t2.DepartmentID == t3.DepartmentID,
  46. JoinType.Inner, t1.OrgID == t4.OrgID && t1.Handle_Person == t4.MemberID
  47. }
  48. )
  49. .Where((t1, t2, t3, t4) => t1.OrgID == i_crm.ORIGID && t1.KeyNote.Contains(sKeyNote) && sImportant.Contains(t1.Important))
  50. .WhereIF(!string.IsNullOrEmpty(sApplicant), (t1, t2, t3, t4) => t1.Applicant == sApplicant)
  51. .WhereIF(!string.IsNullOrEmpty(sStatus), (t1, t2, t3, t4) => sStatus.Contains(t1.Status))
  52. .WhereIF(!(sRoles.Contains("Admin") || sRoles.Contains("EipManager") || sRoles.Contains("EipView")), (t1, t2, t3, t4) => (t1.Applicant == i_crm.USERID || t1.Handle_Person == i_crm.USERID || t1.CheckFlows.Contains(i_crm.USERID)))
  53. .Select((t1, t2, t3, t4) => new View_EIP_BillChangeApply
  54. {
  55. Guid = SqlFunc.GetSelfAndAutoFill(t1.Guid),
  56. ApplicantName = t2.MemberName,
  57. DeptName = t3.DepartmentName,
  58. Handle_PersonName = t4.MemberName
  59. })
  60. .MergeTable()
  61. .OrderBy(sSortField, sSortOrder)
  62. .ToPageList(pml.PageIndex, bExcel ? 100000 : pml.PageSize, ref iPageCount);
  63. pml.Total = iPageCount;
  64. rm = new SuccessResponseMessage(null, i_crm);
  65. if (bExcel)
  66. {
  67. const string sFileName = "請款單(廠商)費用明細";
  68. var oHeader = new Dictionary<string, string>
  69. {
  70. { "RowIndex", "項次" },
  71. { "WenZhongAcount", "員工代號" },
  72. { "AskTheDummyName", "員工姓名" },
  73. { "FillBrushDate", "補刷卡日期" },
  74. { "FillBrushType", "補刷卡時間" },
  75. { "FillBrushReason", "補刷卡說明 " },
  76. { "Memo", "備註" }
  77. };
  78. var saAttendanceDiff = pml.DataList as List<View_EIP_AttendanceDiff>;
  79. foreach (var item in saAttendanceDiff)
  80. {
  81. item.FillBrushDate = Convert.ToDateTime(Convert.ToDateTime(item.FillBrushDate).ToString("yyyy/MM/dd"));
  82. item.FillBrushType = item.FillBrushType == "A" ? "上午" : item.FillBrushType == "P" ? "下午" : "全天";
  83. }
  84. var dicAlain = ExcelService.GetExportAlain(oHeader, new string[] { "Currency", "PayeeCode", "BillNO" }, "Amount");
  85. var bOk = new ExcelService().CreateExcelByList(saAttendanceDiff, out string sPath, oHeader, dicAlain, sFileName);
  86. rm.DATA.Add(BLWording.REL, sPath);
  87. }
  88. else
  89. {
  90. rm.DATA.Add(BLWording.REL, pml);
  91. }
  92. } while (false);
  93. }
  94. catch (Exception ex)
  95. {
  96. sMsg = Util.GetLastExceptionMsg(ex);
  97. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBAPP.EIP.BillChangeApply_QryService", "", "QueryPage(帳單更改申請單分頁查詢)", "", "", "");
  98. }
  99. finally
  100. {
  101. if (null != sMsg)
  102. {
  103. rm = new ErrorResponseMessage(sMsg, i_crm);
  104. }
  105. }
  106. return rm;
  107. }
  108. #endregion 帳單更改申請單分頁查詢
  109. #region 帳單更改申請單筆查詢
  110. /// <summary>
  111. /// 帳單更改申請單筆查詢
  112. /// </summary>
  113. /// <param name="i_crm"></param>
  114. /// <returns></returns>
  115. public ResponseMessage QueryOne(RequestMessage i_crm)
  116. {
  117. ResponseMessage rm = null;
  118. string sMsg = null;
  119. var db = SugarBase.GetIntance();
  120. try
  121. {
  122. do
  123. {
  124. var sId = _fetchString(i_crm, @"Guid");
  125. var oEntity = db.Queryable<OTB_EIP_BillChangeApply, OTB_SYS_Members, OTB_SYS_Departments, OTB_SYS_Members>
  126. ((t1, t2, t3, t4) =>
  127. new object[] {
  128. JoinType.Inner, t1.OrgID == t2.OrgID && t1.Applicant == t2.MemberID,
  129. JoinType.Inner, t2.OrgID == t3.OrgID && t2.DepartmentID == t3.DepartmentID,
  130. JoinType.Inner, t1.OrgID == t4.OrgID && t1.Handle_Person == t4.MemberID
  131. }
  132. )
  133. .Where((t1, t2, t3, t4) => t1.OrgID == i_crm.ORIGID && t1.Guid == sId)
  134. .Select((t1, t2, t3, t4) => new View_EIP_BillChangeApply
  135. {
  136. Guid = SqlFunc.GetSelfAndAutoFill(t1.Guid),
  137. ApplicantName = t2.MemberName,
  138. DeptName = t3.DepartmentName,
  139. Handle_PersonName = t4.MemberName
  140. }).Single();
  141. if (!string.IsNullOrEmpty(oEntity.RelationId))
  142. {
  143. var oRelation = db.Queryable<OTB_EIP_BillChangeApply>().Single(x => x.OrgID == i_crm.ORIGID && x.Guid == oEntity.RelationId);
  144. if (oRelation != null)
  145. {
  146. oEntity.ExFeild1 = oRelation.KeyNote;
  147. }
  148. }
  149. rm = new SuccessResponseMessage(null, i_crm);
  150. rm.DATA.Add(BLWording.REL, oEntity);
  151. } while (false);
  152. }
  153. catch (Exception ex)
  154. {
  155. sMsg = Util.GetLastExceptionMsg(ex);
  156. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBAPP.EIP.BillChangeApply_QryService", "", "QueryOne(帳單更改申請單筆查詢)", "", "", "");
  157. }
  158. finally
  159. {
  160. if (null != sMsg)
  161. {
  162. rm = new ErrorResponseMessage(sMsg, i_crm);
  163. }
  164. }
  165. return rm;
  166. }
  167. #endregion 帳單更改申請單筆查詢
  168. }
  169. }