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.

187 lines
8.7 KiB

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