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.

249 lines
12 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.Data;
  12. using System.Linq;
  13. namespace EasyBL.WEBAPP.EIP
  14. {
  15. public class OverTime_QryService : ServiceBase
  16. {
  17. #region 加班申請單分頁查詢
  18. /// <summary>
  19. /// 加班申請單分頁查詢
  20. /// </summary>
  21. /// <param name="i_crm"></param>
  22. /// <returns></returns>
  23. public ResponseMessage QueryPage(RequestMessage i_crm)
  24. {
  25. ResponseMessage rm = null;
  26. string sMsg = null;
  27. var db = SugarBase.GetIntance();
  28. try
  29. {
  30. do
  31. {
  32. var pml = new PageModel
  33. {
  34. PageIndex = _fetchInt(i_crm, @"pageIndex"),
  35. PageSize = _fetchInt(i_crm, @"pageSize")
  36. };
  37. var iPageCount = 0;
  38. var sSortField = _fetchString(i_crm, @"sortField");
  39. var sSortOrder = _fetchString(i_crm, @"sortOrder");
  40. var sKeyNote = _fetchString(i_crm, @"KeyNote");
  41. var sAskTheDummy = _fetchString(i_crm, @"AskTheDummy");
  42. var sImportant = _fetchString(i_crm, @"Important");
  43. var sStatus = _fetchString(i_crm, @"Status");
  44. var sRoles = _fetchString(i_crm, @"Roles");
  45. var bExcel = _fetchBool(i_crm, @"Excel");
  46. pml.DataList = db.Queryable<OTB_EIP_OverTime, OTB_SYS_Members, OTB_SYS_Departments, OTB_SYS_Members>
  47. ((t1, t2, t3, t4) =>
  48. new object[] {
  49. JoinType.Inner, t1.OrgID == t2.OrgID && t1.AskTheDummy == t2.MemberID,
  50. JoinType.Inner, t2.OrgID == t3.OrgID && t2.DepartmentID == t3.DepartmentID,
  51. JoinType.Inner, t1.OrgID == t4.OrgID && t1.Handle_Person == t4.MemberID
  52. }
  53. )
  54. .Where((t1, t2, t3, t4) => t1.OrgID == i_crm.ORIGID && t1.KeyNote.Contains(sKeyNote) && sImportant.Contains(t1.Important))
  55. .WhereIF(!string.IsNullOrEmpty(sAskTheDummy), (t1, t2, t3, t4) => t1.AskTheDummy == sAskTheDummy)
  56. .WhereIF(!string.IsNullOrEmpty(sStatus), (t1, t2, t3, t4) => sStatus.Contains(t1.Status))
  57. .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)))
  58. .Select((t1, t2, t3, t4) => new View_EIP_OverTime
  59. {
  60. Guid = SqlFunc.GetSelfAndAutoFill(t1.Guid),
  61. AskTheDummyName = t2.MemberName,
  62. Handle_PersonName = t4.MemberName,
  63. DeptName = t3.DepartmentName
  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. { "EmployeeName", "員工姓名" },
  78. { "OvertimeClass", "加班別" },
  79. { "AttendanceDate", "出勤日期" },
  80. { "StartDate", "開始日期" },
  81. { "StartTime", "開始時間" },
  82. { "EndDate", "結束日期" },
  83. { "EndTime", "結束時間" },
  84. { "OvertimeHours", "加班時數 " },
  85. { "TakeTimeOffHours", "補休時數 " },
  86. { "Field1", "補休期限 " },
  87. { "Field2", "抵用時數 " },
  88. { "Field3", "誤餐費 " },
  89. { "PrjCode", "專案代號 " },
  90. { "Reason", "事由" },
  91. { "Memo", "備註" },
  92. { "Field4", "工作門市代號" },
  93. { "Field5", "職務技能代號" }
  94. };
  95. var dt_new = new DataTable();
  96. dt_new.Columns.Add("RowIndex");
  97. dt_new.Columns.Add("WenZhongAcount");
  98. dt_new.Columns.Add("EmployeeName");
  99. dt_new.Columns.Add("OvertimeClass");
  100. dt_new.Columns.Add("AttendanceDate");
  101. dt_new.Columns.Add("StartDate");
  102. dt_new.Columns.Add("StartTime");
  103. dt_new.Columns.Add("EndDate");
  104. dt_new.Columns.Add("EndTime");
  105. dt_new.Columns.Add("OvertimeHours");
  106. dt_new.Columns.Add("TakeTimeOffHours");
  107. dt_new.Columns.Add("Field1");
  108. dt_new.Columns.Add("Field2");
  109. dt_new.Columns.Add("Field3");
  110. dt_new.Columns.Add("PrjCode");
  111. dt_new.Columns.Add("Reason");
  112. dt_new.Columns.Add("Memo");
  113. dt_new.Columns.Add("Field4");
  114. dt_new.Columns.Add("Field5");
  115. var listMerge = new List<Dictionary<string, int>>();
  116. var saInvoiceApplyInfo = pml.DataList as List<View_EIP_OverTime>;
  117. var saMembers = db.Queryable<OTB_SYS_Members>()
  118. .Select(x => new { x.OrgID, x.MemberID, x.MemberName, x.WenZhongAcount })
  119. .Where(x => x.OrgID == i_crm.ORIGID).ToList();
  120. var iIndex = 1;
  121. foreach (var item in saInvoiceApplyInfo)
  122. {
  123. var jaOverTimes = (JArray)JsonConvert.DeserializeObject(item.OverTimes);
  124. foreach (JObject overtime in jaOverTimes)
  125. {
  126. var row_new = dt_new.NewRow();
  127. var sEmployeeCode = overtime["EmployeeCode"].ToString();
  128. var oEmployee = saMembers.Single(x => x.MemberID == sEmployeeCode);
  129. row_new["RowIndex"] = iIndex;
  130. row_new["WenZhongAcount"] = oEmployee.WenZhongAcount;
  131. row_new["EmployeeName"] = overtime["EmployeeName"];
  132. row_new["OvertimeClass"] = overtime["OvertimeClass"];
  133. row_new["AttendanceDate"] = overtime["AttendanceDate"];
  134. row_new["StartDate"] = overtime["StartDate"];
  135. row_new["StartTime"] = overtime["StartTime"];
  136. row_new["EndDate"] = overtime["EndDate"];
  137. row_new["EndTime"] = overtime["EndTime"];
  138. row_new["OvertimeHours"] = overtime["OvertimeHours"];
  139. row_new["TakeTimeOffHours"] = overtime["TakeTimeOffHours"];
  140. row_new["Field1"] = "";
  141. row_new["Field2"] = "";
  142. row_new["Field3"] = "";
  143. row_new["PrjCode"] = overtime["PrjCode"];
  144. row_new["Reason"] = overtime["Reason"];
  145. row_new["Memo"] = "";
  146. row_new["Field4"] = "";
  147. row_new["Field5"] = "";
  148. dt_new.Rows.Add(row_new);
  149. iIndex++;
  150. }
  151. }
  152. var dicAlain = ExcelService.GetExportAlain(oHeader, "WenZhongAcount,EmployeeName,OvertimeClass,AttendanceDate,StartDate,StartTime,EndDate,EndTime,OvertimeHours,TakeTimeOffHours,PrjCode");
  153. var bOk = new ExcelService().CreateExcelByTb(dt_new, out string sPath, oHeader, dicAlain, listMerge, sFileName);
  154. rm.DATA.Add(BLWording.REL, sPath);
  155. }
  156. else
  157. {
  158. rm.DATA.Add(BLWording.REL, pml);
  159. }
  160. } while (false);
  161. }
  162. catch (Exception ex)
  163. {
  164. sMsg = Util.GetLastExceptionMsg(ex);
  165. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBAPP.EIP.OverTime_QryService", "", "QueryPage(加班申請單分頁查詢)", "", "", "");
  166. }
  167. finally
  168. {
  169. if (null != sMsg)
  170. {
  171. rm = new ErrorResponseMessage(sMsg, i_crm);
  172. }
  173. }
  174. return rm;
  175. }
  176. #endregion 加班申請單分頁查詢
  177. #region 加班申請單單筆查詢
  178. /// <summary>
  179. /// 加班申請單單筆查詢
  180. /// </summary>
  181. /// <param name="i_crm"></param>
  182. /// <returns></returns>
  183. public ResponseMessage QueryOne(RequestMessage i_crm)
  184. {
  185. ResponseMessage rm = null;
  186. string sMsg = null;
  187. var db = SugarBase.GetIntance();
  188. try
  189. {
  190. do
  191. {
  192. var sId = _fetchString(i_crm, @"Guid");
  193. var oEntity = db.Queryable<OTB_EIP_OverTime, OTB_SYS_Members, OTB_SYS_Departments, OTB_SYS_Members>
  194. ((t1, t2, t3, t4) =>
  195. new object[] {
  196. JoinType.Inner, t1.OrgID == t2.OrgID && t1.AskTheDummy == t2.MemberID,
  197. JoinType.Inner, t2.OrgID == t3.OrgID && t2.DepartmentID == t3.DepartmentID,
  198. JoinType.Inner, t1.OrgID == t4.OrgID && t1.Handle_Person == t4.MemberID
  199. }
  200. )
  201. .Where((t1, t2, t3, t4) => t1.OrgID == i_crm.ORIGID && t1.Guid == sId)
  202. .Select((t1, t2, t3, t4) => new View_EIP_OverTime
  203. {
  204. Guid = SqlFunc.GetSelfAndAutoFill(t1.Guid),
  205. AskTheDummyName = t2.MemberName,
  206. Handle_PersonName = t4.MemberName,
  207. DeptName = t3.DepartmentName
  208. }).Single();
  209. if (!string.IsNullOrEmpty(oEntity.RelationId))
  210. {
  211. var oRelation = db.Queryable<OTB_EIP_OverTime>().Single(x => x.OrgID == i_crm.ORIGID && x.Guid == oEntity.RelationId);
  212. if (oRelation != null)
  213. {
  214. oEntity.ExFeild1 = oRelation.KeyNote;
  215. }
  216. }
  217. rm = new SuccessResponseMessage(null, i_crm);
  218. rm.DATA.Add(BLWording.REL, oEntity);
  219. } while (false);
  220. }
  221. catch (Exception ex)
  222. {
  223. sMsg = Util.GetLastExceptionMsg(ex);
  224. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBAPP.EIP.OverTime_QryService", "", "QueryOne(加班申請單單筆查詢)", "", "", "");
  225. }
  226. finally
  227. {
  228. if (null != sMsg)
  229. {
  230. rm = new ErrorResponseMessage(sMsg, i_crm);
  231. }
  232. }
  233. return rm;
  234. }
  235. #endregion 加班申請單單筆查詢
  236. }
  237. }