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.

312 lines
17 KiB

2 years ago
  1. using EasyBL.WebApi.Message;
  2. using EasyNet;
  3. using Entity.Sugar;
  4. using Newtonsoft.Json;
  5. using Newtonsoft.Json.Linq;
  6. using SqlSugar;
  7. using SqlSugar.Base;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. namespace EasyBL.WEBAPP.EIP
  12. {
  13. public class AttendanceDiff_UpdService : ServiceBase
  14. {
  15. #region 差勤異常申請表提交簽核
  16. /// <summary>
  17. /// 差勤異常申請表提交簽核
  18. /// </summary>
  19. /// <param name="i_crm">todo: describe i_crm parameter on AttendanceDiffToAudit</param>
  20. /// <returns></returns>
  21. public ResponseMessage AttendanceDiffToAudit(RequestMessage i_crm)
  22. {
  23. ResponseMessage rm = null;
  24. string sMsg = null;
  25. try
  26. {
  27. rm = SugarBase.ExecTran(db =>
  28. {
  29. do
  30. {
  31. var sId = _fetchString(i_crm, EasyNetGlobalConstWord.GUID);
  32. var sdb = new SimpleClient<OTB_EIP_AttendanceDiff>(db);
  33. var oEip = sdb.GetById(sId);
  34. if (oEip == null)
  35. {
  36. sMsg = @"系統找不到對應的差勤異常申請表資料,請核查!";
  37. break;
  38. }
  39. var oAskTheDummy = db.Queryable<OTB_SYS_Members>().Single(x => x.OrgID == i_crm.ORIGID && x.MemberID == oEip.AskTheDummy);
  40. var sTitle = oAskTheDummy.MemberName + @"的差勤異常申請表申請「" + oEip.KeyNote + @"」簽呈編號:" + oEip.SignedNumber;
  41. if (i_crm.LANG == @"zh")
  42. {
  43. sTitle = ChineseStringUtility.ToSimplified(sTitle);
  44. }
  45. //更新基本資料
  46. var oEipUpd = new OTB_EIP_AttendanceDiff
  47. {
  48. Status = @"B",
  49. ModifyUser = i_crm.USERID,
  50. ModifyDate = DateTime.Now
  51. };
  52. db.Updateable(oEipUpd)
  53. .UpdateColumns(it => new { it.Status, it.ModifyUser, it.ModifyDate })
  54. .Where(it => it.Guid == sId).ExecuteCommand();
  55. //更新代辦
  56. SYS.Task_QryService.TaskStatusUpd(db, i_crm.ORIGID, sId);
  57. var jaCheckFlows = (JArray)JsonConvert.DeserializeObject(oEip.CheckFlows);
  58. var MinOrderToNotice = jaCheckFlows.Min(x => ((JObject)x)["Order"].ToString()).ToString();
  59. var saSignedId = jaCheckFlows.Where(x => ((JObject)x)["Order"].ToString() == MinOrderToNotice).Select(x => ((JObject)x)["SignedId"].ToString()).ToList();
  60. if (saSignedId.Count > 0)
  61. {
  62. foreach (string signedId in saSignedId)
  63. {
  64. //添加提醒消息
  65. var oTipsAdd = SYS.Task_QryService.TipsAdd(i_crm, sTitle, signedId, @"AttendanceDiff_View" + @"|?Action=Upd&Guid=" + oEip.Guid, WebAppGlobalConstWord.BELL);
  66. db.Insertable(oTipsAdd).ExecuteCommand();
  67. //添加代辦
  68. var oTaskAdd = SYS.Task_QryService.TaskAdd(i_crm, oEip.Guid, signedId, sTitle, @"AttendanceDiff_View", @"?Action=Upd&Guid=" + oEip.Guid, @"B");
  69. db.Insertable(oTaskAdd).ExecuteCommand();
  70. }
  71. }
  72. //檢核未打卡提示中有沒有提醒資料,如果有的話就刪除
  73. var saClockTips = db.Queryable<OTB_SYS_ClockTips>()
  74. .Where(x => x.OrgID == i_crm.ORIGID && x.Owner == oEip.AskTheDummy && x.TipsDate.Value.Date == oEip.FillBrushDate.Value.Date)
  75. .ToList();
  76. if (saClockTips.Count > 0)
  77. {
  78. db.Deleteable(saClockTips).ExecuteCommand();
  79. }
  80. rm = new SuccessResponseMessage(null, i_crm);
  81. rm.DATA.Add(BLWording.REL, saSignedId);
  82. } while (false);
  83. return rm;
  84. });
  85. }
  86. catch (Exception ex)
  87. {
  88. sMsg = Util.GetLastExceptionMsg(ex);
  89. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(AttendanceDiff_UpdService), @"差勤異常申請表管理", @"AttendanceDiffToAudit(差勤異常申請表提交簽核)", @"", @"", @"");
  90. }
  91. finally
  92. {
  93. if (null != sMsg)
  94. {
  95. rm = new ErrorResponseMessage(sMsg, i_crm);
  96. }
  97. }
  98. return rm;
  99. }
  100. #endregion 差勤異常申請表提交簽核
  101. #region 差勤異常申請表簽核|签辦
  102. /// <summary>
  103. /// 差勤異常申請表簽核|签辦
  104. /// </summary>
  105. /// <param name="i_crm">todo: describe i_crm parameter on AttendanceDiffAudit</param>
  106. /// <returns></returns>
  107. public ResponseMessage AttendanceDiffAudit(RequestMessage i_crm)
  108. {
  109. ResponseMessage rm = null;
  110. string sMsg = null;
  111. try
  112. {
  113. rm = SugarBase.ExecTran(db =>
  114. {
  115. do
  116. {
  117. var sId = _fetchString(i_crm, @"Guid");
  118. var sAction = _fetchString(i_crm, @"Action");
  119. var sGoNext = _fetchString(i_crm, @"GoNext");
  120. var sHandlePerson = _fetchString(i_crm, @"HandlePerson");
  121. var sNextSignedWays = _fetchString(i_crm, @"NextSignedWays");
  122. var sNextUsers = _fetchString(i_crm, @"NextUsers");
  123. var sTipsUsers = _fetchString(i_crm, @"TipsUsers");
  124. var sCheckFlows = _fetchString(i_crm, @"CheckFlows");
  125. var sHandleFlows = _fetchString(i_crm, @"HandleFlows");
  126. var sSignedDecision = _fetchString(i_crm, @"SignedDecision");
  127. var sHandleDecision = _fetchString(i_crm, @"HandleDecision");
  128. var sdb = new SimpleClient<OTB_EIP_AttendanceDiff>(db);
  129. var oEip = sdb.GetById(sId);
  130. if (oEip == null)
  131. {
  132. sMsg = @"系統找不到對應的差勤異常申請表資料,請核查!";
  133. break;
  134. }
  135. var saNextSignedWays = (JArray)JsonConvert.DeserializeObject(sNextSignedWays);
  136. var saNextUsers = (JArray)JsonConvert.DeserializeObject(sNextUsers);
  137. var saTipsUsers = (JArray)JsonConvert.DeserializeObject(sTipsUsers);
  138. var oUser_Self = db.Queryable<OTB_SYS_Members>().Single(x => x.OrgID == i_crm.ORIGID && x.MemberID == i_crm.USERID);
  139. var oAskTheDummy = db.Queryable<OTB_SYS_Members>().Single(x => x.OrgID == i_crm.ORIGID && x.MemberID == oEip.AskTheDummy);
  140. var sTitle_Self = @"";
  141. var sTitle_Handle = oUser_Self.MemberName + @"審批了" + oAskTheDummy.MemberName + @"的差勤異常申請表「" + oEip.KeyNote + @"」簽呈編號:" + oEip.SignedNumber;
  142. var sTitle_Next = oAskTheDummy.MemberName + @"的差勤異常申請表申請「" + oEip.KeyNote + @"」簽呈編號:" + oEip.SignedNumber;
  143. var sTitle_Notice = @"";
  144. var sStatus = @"B";
  145. var TipsType = WebAppGlobalConstWord.CHECK;
  146. if (sAction == @"Signed")
  147. {
  148. sTitle_Self = oUser_Self.MemberName + @"審批了您的差勤異常申請表「" + oEip.KeyNote + @"」簽呈編號:" + oEip.SignedNumber;
  149. sTitle_Notice = oAskTheDummy.MemberName + @"的差勤異常申請表申請「" + oEip.KeyNote + @"」簽呈編號:" + oEip.SignedNumber + @",請點擊查看...";
  150. if (sSignedDecision == @"Y")
  151. {
  152. sTitle_Self += @",審批結果:同意";
  153. if (sHandlePerson != @"")
  154. {
  155. sStatus = @"E";
  156. }
  157. }
  158. else if (sSignedDecision == @"N")
  159. {
  160. sTitle_Self += @",審批結果:不同意";
  161. sStatus = @"D-O";
  162. TipsType = WebAppGlobalConstWord.FAIL;
  163. }
  164. else if (sSignedDecision == @"O")
  165. {
  166. sTitle_Self += @",審批結果:先加簽";
  167. }
  168. }
  169. else
  170. {
  171. sTitle_Self = oUser_Self.MemberName + @"签辦了您的差勤異常申請表「" + oEip.KeyNote + @"」簽呈編號:" + oEip.SignedNumber;
  172. if (sHandleDecision == @"Y")
  173. {
  174. sTitle_Self += @"簽辦結果:同意";
  175. sStatus = @"H-O";
  176. }
  177. else if (sHandleDecision == @"O")
  178. {
  179. sTitle_Self += @"簽辦結果:先轉呈其他主管審批";
  180. }
  181. }
  182. if (i_crm.LANG == @"zh")
  183. {
  184. sTitle_Self = ChineseStringUtility.ToSimplified(sTitle_Self);
  185. sTitle_Next = ChineseStringUtility.ToSimplified(sTitle_Next);
  186. sTitle_Notice = ChineseStringUtility.ToSimplified(sTitle_Notice);
  187. }
  188. //更新基本資料
  189. var oEipUpd = new OTB_EIP_AttendanceDiff
  190. {
  191. Status = sStatus,
  192. CheckFlows = sCheckFlows,
  193. HandleFlows = sHandleFlows,
  194. ModifyUser = i_crm.USERID,
  195. ModifyDate = DateTime.Now
  196. };
  197. db.Updateable(oEipUpd)
  198. .UpdateColumns(it => new { it.Status, it.CheckFlows, it.HandleFlows, it.ModifyUser, it.ModifyDate })
  199. .Where(it => it.Guid == sId).ExecuteCommand();
  200. var sOwner = @"";
  201. if (sSignedDecision == @"Y" && sGoNext == @"N")
  202. {
  203. sOwner = i_crm.USERID;
  204. }
  205. //更新代辦
  206. SYS.Task_QryService.TaskStatusUpd(db, i_crm.ORIGID, sId, sOwner);
  207. var listTips = new List<OTB_SYS_Tips>();
  208. var listTask = new List<OTB_SYS_Task>();
  209. var listToTips = new List<string>();
  210. if (sStatus != @"D-O")
  211. {
  212. foreach (string flow in saNextSignedWays)
  213. {
  214. if (sGoNext == @"Y")
  215. {
  216. if (flow == @"flow4")//添加通知和提醒給下個流程所有要通知的人
  217. {
  218. foreach (string user in saTipsUsers)
  219. {
  220. //添加提醒消息
  221. var oTipsAdd = SYS.Task_QryService.TipsAdd(i_crm, sTitle_Notice, user, @"AttendanceDiff_View" + @"|?Action=Upd&Guid=" + oEip.Guid, WebAppGlobalConstWord.BELL);
  222. listTips.Add(oTipsAdd);
  223. listToTips.Add(user);
  224. }
  225. }
  226. else if (flow == @"flow5")//添加通知和提醒給經辦人
  227. {
  228. if (sHandlePerson != @"")
  229. {
  230. if (sHandleDecision != @"N")
  231. {
  232. //添加代辦
  233. var oTaskAdd = SYS.Task_QryService.TaskAdd(i_crm, oEip.Guid, sHandlePerson, sTitle_Handle, @"AttendanceDiff_View", @"?Action=Upd&Guid=" + oEip.Guid, @"E");
  234. listTask.Add(oTaskAdd);
  235. //添加提醒消息
  236. var oTipsAdd = SYS.Task_QryService.TipsAdd(i_crm, sTitle_Handle, sHandlePerson, @"AttendanceDiff_View" + @"|?Action=Upd&Guid=" + oEip.Guid, WebAppGlobalConstWord.BELL);
  237. listTips.Add(oTipsAdd);
  238. listToTips.Add(sHandlePerson);
  239. }
  240. }
  241. }
  242. else
  243. {
  244. foreach (string user in saNextUsers)//添加通知和提醒給下一個審核的人
  245. {
  246. if (sSignedDecision == @"Y" || sSignedDecision == @"O")
  247. {
  248. //添加代辦
  249. var oTaskAdd = SYS.Task_QryService.TaskAdd(i_crm, oEip.Guid, user, sTitle_Next, @"AttendanceDiff_View", @"?Action=Upd&Guid=" + oEip.Guid, @"G");
  250. listTask.Add(oTaskAdd);
  251. //添加提醒消息
  252. var oTipsAdd = SYS.Task_QryService.TipsAdd(i_crm, sTitle_Next, user, @"AttendanceDiff_View" + @"|?Action=Upd&Guid=" + oEip.Guid, WebAppGlobalConstWord.BELL);
  253. listTips.Add(oTipsAdd);
  254. listToTips.Add(user);
  255. }
  256. }
  257. }
  258. }
  259. }
  260. }
  261. //添加提醒消息(給請假的人)
  262. var oTips_AskTheDummy = SYS.Task_QryService.TipsAdd(i_crm, sTitle_Self, oEip.AskTheDummy, @"AttendanceDiff_View" + @"|?Action=Upd&Guid=" + oEip.Guid, TipsType);
  263. listTips.Add(oTips_AskTheDummy);
  264. listToTips.Add(oEip.AskTheDummy);
  265. if (listTips.Count > 0)
  266. {
  267. db.Insertable(listTips).ExecuteCommand();
  268. }
  269. if (listTask.Count > 0)
  270. {
  271. db.Insertable(listTask).ExecuteCommand();
  272. }
  273. rm = new SuccessResponseMessage(null, i_crm);
  274. rm.DATA.Add(BLWording.REL, listToTips);
  275. } while (false);
  276. return rm;
  277. });
  278. }
  279. catch (Exception ex)
  280. {
  281. sMsg = Util.GetLastExceptionMsg(ex);
  282. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(AttendanceDiff_UpdService), @"差勤異常申請表管理", @"AttendanceDiffAudit(差勤異常申請表簽核|签辦)", @"", @"", @"");
  283. }
  284. finally
  285. {
  286. if (null != sMsg)
  287. {
  288. rm = new ErrorResponseMessage(sMsg, i_crm);
  289. }
  290. }
  291. return rm;
  292. }
  293. #endregion 差勤異常申請表簽核|签辦
  294. }
  295. }