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.

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