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.

235 lines
11 KiB

2 years ago
  1. using EasyBL.WebApi.Message;
  2. using EasyNet;
  3. using Entity.Sugar;
  4. using Entity.ViewModels;
  5. using SqlSugar;
  6. using SqlSugar.Base;
  7. using System;
  8. namespace EasyBL.WEBAPP.SYS
  9. {
  10. public class Task_QryService : ServiceBase
  11. {
  12. #region 代辦管理
  13. /// <summary>
  14. /// 代辦管理
  15. /// </summary>
  16. /// <param name="i_crm">todo: describe i_crm parameter on GetTasks</param>
  17. /// <returns></returns>
  18. public ResponseMessage GetTasks(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 saTasks = db.Queryable<OTB_SYS_Task, OTB_SYS_Members, OTB_SYS_Members, OTB_SYS_ProgramList>
  28. ((t1, t2, t3, t4) =>
  29. new object[] {
  30. JoinType.Left, t1.OrgID == t2.OrgID && t1.Owner == t2.MemberID,
  31. JoinType.Left, t2.OrgID == t3.OrgID && t2.CreateUser == t3.MemberID,
  32. JoinType.Left, t1.OrgID == t4.OrgID && t1.SourceFrom == t4.ProgramID
  33. }
  34. )
  35. .Where((t1, t2, t3, t4) => t1.OrgID == i_crm.ORIGID && t1.Owner == i_crm.USERID && t1.Status != @"O" && SqlFunc.HasValue(t1.EventNo))
  36. .OrderBy((t1, t2, t3, t4) => t1.CreateDate, OrderByType.Desc)
  37. .Select((t1, t2, t3, t4) => new
  38. {
  39. OwnerName = t2.MemberName,
  40. CreateUserName = t3.MemberName,
  41. ProgressShow = t1.Progress + "%",
  42. ImportantName = SqlFunc.IIF(t1.Important == "M", "普通", "緊急"),
  43. SourceFromName = t4.ProgramName,
  44. EventID = SqlFunc.GetSelfAndAutoFill(t1.EventID),
  45. }).ToList();
  46. //var saTasks = db.Queryable<OVW_SYS_Task>()
  47. // .Where(p => p.OrgID == i_crm.ORIGID && p.Owner == i_crm.USERID && p.Status != @"O" && SqlFunc.IsNull(p.EventNo, @"") != @"")
  48. // .OrderBy(p => p.CreateDate, OrderByType.Desc).ToList();
  49. rm = new SuccessResponseMessage(null, i_crm);
  50. rm.DATA.Add(BLWording.REL, saTasks);
  51. } while (false);
  52. }
  53. catch (Exception ex)
  54. {
  55. sMsg = Util.GetLastExceptionMsg(ex);
  56. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(Task_QryService), @"代辦事項", @"GetTasks(代辦管理)", @"", @"", @"");
  57. }
  58. finally
  59. {
  60. if (null != sMsg)
  61. {
  62. rm = new ErrorResponseMessage(sMsg, i_crm);
  63. }
  64. }
  65. return rm;
  66. }
  67. #endregion 代辦管理
  68. #region 代辦管理(分頁資料)
  69. /// <summary>
  70. /// 代辦管理(分頁資料)
  71. /// </summary>
  72. /// <param name="i_crm">todo: describe i_crm parameter on QueryPage</param>
  73. /// <returns></returns>
  74. public ResponseMessage QueryPage(RequestMessage i_crm)
  75. {
  76. ResponseMessage rm = null;
  77. string sMsg = null;
  78. var db = SugarBase.DB;
  79. try
  80. {
  81. do
  82. {
  83. var pml = new PageModel
  84. {
  85. PageIndex = _fetchInt(i_crm, @"pageIndex"),
  86. PageSize = _fetchInt(i_crm, @"pageSize")
  87. };
  88. var iPageCount = 0;
  89. var sSortField = _fetchString(i_crm, @"sortField");
  90. var sSortOrder = _fetchString(i_crm, @"sortOrder");
  91. var sEventName = _fetchString(i_crm, @"EventName");
  92. var sOwner = _fetchString(i_crm, @"Owner");
  93. var sCreateUser = _fetchString(i_crm, @"CreateUser");
  94. var sIsIncludReady = _fetchString(i_crm, @"IsIncludReady");
  95. var bIsEIP = _fetchBool(i_crm, @"IsEIP");
  96. pml.DataList = db.Queryable<OTB_SYS_Task, OTB_SYS_Members, OTB_SYS_Members, OTB_SYS_ProgramList>
  97. ((t1, t2, t3, t4) =>
  98. new object[] {
  99. JoinType.Inner, t1.OrgID == t2.OrgID && t1.Owner == t2.MemberID,
  100. JoinType.Inner, t1.OrgID == t3.OrgID && t1.CreateUser == t3.MemberID,
  101. JoinType.Inner, t1.OrgID == t4.OrgID && t1.SourceFrom == t4.ProgramID
  102. }
  103. )
  104. .Where((t1, t2, t3, t4) => t1.OrgID == i_crm.ORIGID)
  105. .WhereIF(sEventName == null, (t1, t2, t3, t4) => t1.Owner == i_crm.USERID && t1.Status != @"O" && SqlFunc.HasValue(t1.EventNo))
  106. .WhereIF(sEventName == null && bIsEIP, (t1, t2, t3, t4) => SqlFunc.HasValue(t1.EIP_Status))
  107. .WhereIF(sEventName == null && !bIsEIP, (t1, t2, t3, t4) => !SqlFunc.HasValue(t1.EIP_Status))
  108. .WhereIF(sEventName != null, (t1, t2, t3, t4) => t1.EventName.Contains(sEventName))
  109. .WhereIF(sEventName != null && !string.IsNullOrEmpty(sOwner), (t1, t2, t3, t4) => t1.Owner == sOwner)
  110. .WhereIF(sEventName != null && !string.IsNullOrEmpty(sCreateUser), (t1, t2, t3, t4) => t1.CreateUser == sCreateUser)
  111. .WhereIF(sEventName != null, (t1, t2, t3, t4) => sIsIncludReady.Contains(t1.Status))
  112. .WhereIF(sEventName != null, (t1, t2, t3, t4) => t1.Owner == i_crm.USERID || t1.CreateUser == i_crm.USERID)
  113. .Select((t1, t2, t3, t4) => new View_SYS_Task
  114. {
  115. EventID = SqlFunc.GetSelfAndAutoFill(t1.EventID),
  116. OwnerName = t2.MemberName,
  117. CreateUserName = t3.MemberName,
  118. ProgressShow = t1.Progress.ToString() + "%",
  119. ImportantName = SqlFunc.IIF(t1.Important == "M", "普通", "緊急"),
  120. SourceFromName = t4.ProgramName
  121. })
  122. .MergeTable()
  123. .OrderBy(sSortField, sSortOrder)
  124. .ToPageList(pml.PageIndex, pml.PageSize, ref iPageCount);
  125. pml.Total = iPageCount;
  126. rm = new SuccessResponseMessage(null, i_crm);
  127. rm.DATA.Add(BLWording.REL, pml);
  128. } while (false);
  129. }
  130. catch (Exception ex)
  131. {
  132. sMsg = Util.GetLastExceptionMsg(ex);
  133. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(Task_QryService), @"代辦事項", @"GetTasksPage(代辦管理(分頁資料))", @"", @"", @"");
  134. }
  135. finally
  136. {
  137. if (null != sMsg)
  138. {
  139. rm = new ErrorResponseMessage(sMsg, i_crm);
  140. }
  141. }
  142. return rm;
  143. }
  144. #endregion 代辦管理(分頁資料)
  145. /// <summary>
  146. /// 修改代辦狀態
  147. /// </summary>
  148. /// <param name="sOrgId"></param>
  149. /// <param name="sSourceID"></param>
  150. /// <param name="db">todo: describe db parameter on TaskStatusUpd</param>
  151. /// <param name="sOwner">todo: describe sOwner parameter on TaskStatusUpd</param>
  152. public static void TaskStatusUpd(SqlSugarClient db, string sOrgId, string sSourceID, string sOwner = null)
  153. {
  154. var oTaskUpd = new OTB_SYS_Task
  155. {
  156. Status = @"O",
  157. Progress = 100
  158. };
  159. db.Updateable(oTaskUpd).UpdateColumns(it => new { it.Status, it.ModifyDate, it.ModifyUser })
  160. .Where(it => it.SourceID == sSourceID && it.OrgID == sOrgId && (it.Owner == sOwner || SqlFunc.IsNullOrEmpty(sOwner))).ExecuteCommand();
  161. }
  162. /// <summary>
  163. /// 修改代辦狀態
  164. /// </summary>
  165. /// <param name="i_crm">todo: describe i_crm parameter on TipsAdd</param>
  166. /// <param name="sTitle">todo: describe sTitle parameter on TipsAdd</param>
  167. /// <param name="sOwner">todo: describe sOwner parameter on TipsAdd</param>
  168. /// <param name="Url">todo: describe Url parameter on TipsAdd</param>
  169. /// <param name="sTipsType">todo: describe sTipsType parameter on TipsAdd</param>
  170. public static OTB_SYS_Tips TipsAdd(RequestMessage i_crm, string sTitle, string sOwner, string Url, string sTipsType)
  171. {
  172. var oTipsAdd = new OTB_SYS_Tips
  173. {
  174. OrgID = i_crm.ORIGID,
  175. Owner = sOwner.Trim().Replace("\r\n",""),
  176. TipsType = sTipsType,
  177. Title = sTitle,
  178. IsRead = @"N",
  179. Url = Url,
  180. CreateUser = i_crm.USERID,
  181. CreateDate = DateTime.Now,
  182. ModifyUser = i_crm.USERID,
  183. ModifyDate = DateTime.Now
  184. };
  185. return oTipsAdd;
  186. }
  187. /// <summary>
  188. /// 修改代辦狀態
  189. /// </summary>
  190. /// <param name="sSourceID"></param>
  191. /// <param name="i_crm">todo: describe i_crm parameter on TaskAdd</param>
  192. /// <param name="sOwner">todo: describe sOwner parameter on TaskAdd</param>
  193. /// <param name="sTitle">todo: describe sTitle parameter on TaskAdd</param>
  194. /// <param name="sSourceFrom">todo: describe sSourceFrom parameter on TaskAdd</param>
  195. /// <param name="sParams">todo: describe sParams parameter on TaskAdd</param>
  196. /// <param name="sEIP_Status">todo: describe sEIP_Status parameter on TaskAdd</param>
  197. public static OTB_SYS_Task TaskAdd(RequestMessage i_crm, string sSourceID, string sOwner, string sTitle, string sSourceFrom, string sParams, string sEIP_Status = null)
  198. {
  199. var oTaskAdd = new OTB_SYS_Task();
  200. var sEventID = Guid.NewGuid().ToString();
  201. oTaskAdd.OrgID = i_crm.ORIGID;
  202. oTaskAdd.EventID = sEventID;
  203. oTaskAdd.EventName = sTitle;
  204. oTaskAdd.Owner = sOwner.Trim().Replace("\r\n", "");
  205. oTaskAdd.StartDate = DateTime.Now;
  206. oTaskAdd.Progress = 0;
  207. oTaskAdd.PreProgress = 0;
  208. oTaskAdd.Important = @"M";
  209. oTaskAdd.Status = @"U";
  210. oTaskAdd.SourceFrom = sSourceFrom;
  211. oTaskAdd.SourceID = sSourceID;
  212. oTaskAdd.SourceFromID = sSourceID;
  213. oTaskAdd.Params = sParams;
  214. oTaskAdd.EIP_Status = sEIP_Status ?? @"";
  215. oTaskAdd.CreateUser = i_crm.USERID;
  216. oTaskAdd.CreateDate = DateTime.Now;
  217. oTaskAdd.ModifyUser = i_crm.USERID;
  218. oTaskAdd.ModifyDate = DateTime.Now;
  219. oTaskAdd.EventNo = SerialNumber.GetMaxNumberByType(i_crm.ORIGID, @"", MaxNumberType.DayForSix, i_crm.USERID, 4);
  220. return oTaskAdd;
  221. }
  222. }
  223. }