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.

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