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.

729 lines
28 KiB

2 years ago
2 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using EasyNet.DBUtility;
  4. using EasyNet;
  5. using Entity.Sugar;
  6. using EasyBL.WebApi.Message;
  7. using SqlSugar.Base;
  8. using System.IO;
  9. using System.Net;
  10. using System.Text;
  11. using System.Text.RegularExpressions;
  12. using SqlSugar;
  13. using System.Net.Sockets;
  14. using System.Linq;
  15. namespace EasyBL
  16. {
  17. public class CommonService : ServiceBase
  18. {
  19. #region 查詢單筆資料
  20. /// <summary>
  21. /// 查詢單筆資料
  22. /// </summary>
  23. /// <param name="i_crm"></param>
  24. /// <returns></returns>
  25. public ResponseMessage QueryOne(RequestMessage i_crm)
  26. {
  27. ResponseMessage rm = null;
  28. string sMsg = null;
  29. try
  30. {
  31. do
  32. {
  33. var rel = DBHelper.QueryOne("", i_crm.DATA);
  34. rm = new SuccessResponseMessage(null, i_crm);
  35. rm.DATA.Add(BLWording.REL, rel);
  36. } while (false);
  37. }
  38. catch (Exception ex)
  39. {
  40. sMsg = Util.GetLastExceptionMsg(ex);
  41. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.CommonService", "公用API", "QueryOne(查詢單筆資料)", "", "", "");
  42. }
  43. finally
  44. {
  45. if (null != sMsg)
  46. {
  47. rm = new ErrorResponseMessage(sMsg, i_crm);
  48. }
  49. }
  50. return rm;
  51. }
  52. #endregion 查詢單筆資料
  53. #region 獲取流水號
  54. /// <summary>
  55. /// 獲取流水號
  56. /// </summary>
  57. /// <param name="i_crm"></param>
  58. /// <returns></returns>
  59. public ResponseMessage GetSerialNumber(RequestMessage i_crm)
  60. {
  61. ResponseMessage rm = null;
  62. string sMsg = null;
  63. var list = new List<OTB_CRM_Customers>();
  64. try
  65. {
  66. do
  67. {
  68. var iLen = 0;
  69. var sType = _fetchString(i_crm, "Type");
  70. var sFlag = _fetchString(i_crm, "Flag");
  71. var sLen = _fetchString(i_crm, "Len");
  72. var sStr = _fetchString(i_crm, "Str");
  73. var sAddType = _fetchString(i_crm, "AddType");
  74. var sPlusType = _fetchString(i_crm, "PlusType");
  75. if (!string.IsNullOrWhiteSpace(sLen))
  76. {
  77. iLen = int.Parse(sLen);
  78. }
  79. var sSerialNumber = SerialNumber.GetMaxNumberByType(i_crm.ORIGID, sType, SerialNumber.GetMaxNumberType(sFlag), i_crm.USERID, iLen, sStr, sAddType); //獲取最大編號
  80. if (sPlusType == "checkcode")
  81. {
  82. sSerialNumber += SerialNumber.Pcheck(sSerialNumber);
  83. }
  84. else if (sPlusType.StartsWith("randomcode_"))
  85. {
  86. var saPlusType = sPlusType.Split('_');
  87. var iLen_Chid = int.Parse(saPlusType[1].ToString());
  88. sSerialNumber += SecurityUtil.GetRandomNumber(iLen_Chid);
  89. }
  90. rm = new SuccessResponseMessage(null, i_crm);
  91. rm.DATA.Add(BLWording.REL, sSerialNumber);
  92. } while (false);
  93. }
  94. catch (Exception ex)
  95. {
  96. sMsg = Util.GetLastExceptionMsg(ex);
  97. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.CommonService", "公用API", "GetSerialNumber(獲取流水號)", "", "", "");
  98. }
  99. finally
  100. {
  101. if (null != sMsg)
  102. {
  103. rm = new ErrorResponseMessage(sMsg, i_crm);
  104. }
  105. LogService.mo_Log.Debug("CommonService.GetSerialNumber Debug(Param:" + JsonToString(i_crm) + ";Response:" + JsonToString(rm) + ")---------------");
  106. }
  107. return rm;
  108. }
  109. #endregion 獲取流水號
  110. #region 獲取單個系統配置值
  111. /// <summary>
  112. /// 獲取單個系統配置值
  113. /// </summary>
  114. /// <param name="i_crm"></param>
  115. /// <returns></returns>
  116. public ResponseMessage GetSysSet(RequestMessage i_crm)
  117. {
  118. ResponseMessage rm = null;
  119. string sMsg = null;
  120. var db = SugarBase.GetIntance();
  121. try
  122. {
  123. do
  124. {
  125. var sSetItemID = _fetchString(i_crm, "SetItemID");
  126. var oSetItem = new object();
  127. if (string.IsNullOrEmpty(sSetItemID))
  128. {
  129. oSetItem = db.Queryable<OTB_SYS_SystemSetting>()
  130. .Where(x => x.OrgID == i_crm.ORIGID && x.Effective == "Y")
  131. .Select(x => new { x.SettingItem, x.SettingValue })
  132. .ToList();
  133. }
  134. else
  135. {
  136. oSetItem = db.Queryable<OTB_SYS_SystemSetting>()
  137. .Where(x => x.OrgID == i_crm.ORIGID && x.SettingItem == sSetItemID)
  138. .Select(x => x.SettingValue)
  139. .Single();
  140. }
  141. rm = new SuccessResponseMessage(null, i_crm);
  142. rm.DATA.Add(BLWording.REL, oSetItem);
  143. } while (false);
  144. }
  145. catch (Exception ex)
  146. {
  147. sMsg = Util.GetLastExceptionMsg(ex);
  148. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.CommonService", "公用API", "GetSysSet(獲取單個系統配置值)", "", "", "");
  149. }
  150. finally
  151. {
  152. if (null != sMsg)
  153. {
  154. rm = new ErrorResponseMessage(sMsg, i_crm);
  155. }
  156. }
  157. return rm;
  158. }
  159. #endregion 獲取單個系統配置值
  160. #region 獲取參數值
  161. /// <summary>
  162. /// 獲取參數值
  163. /// </summary>
  164. /// <param name="i_crm"></param>
  165. /// <returns></returns>
  166. public ResponseMessage GetArguments(RequestMessage i_crm)
  167. {
  168. ResponseMessage rm = null;
  169. string sMsg = null;
  170. var db = SugarBase.DB;
  171. try
  172. {
  173. do
  174. {
  175. var sArgClassID = _fetchString(i_crm, "ArgClassID");
  176. var sParentID = _fetchString(i_crm, "ParentID");
  177. var sArgIDs = _fetchString(i_crm, "ArgIDs");
  178. var sOrderBy = _fetchString(i_crm, "OrderBy") ?? "OrderByValue";
  179. var sOrderType = _fetchString(i_crm, "OrderType") ?? "asc";
  180. var iLevelOfArgument = _fetchInt(i_crm, "LevelOfArgument");
  181. var sOrgID = _fetchString(i_crm, "OrgID");
  182. var UsingOrgID = string.IsNullOrWhiteSpace(sOrgID) ? i_crm.ORIGID: sOrgID;
  183. var saArguments = db.Queryable<OTB_SYS_Arguments>()
  184. .OrderBy(sOrderBy, sOrderType)
  185. .Where(x => x.OrgID == UsingOrgID && x.DelStatus == "N" && x.Effective == "Y")
  186. .Where(x => x.ArgumentClassID == sArgClassID)
  187. .WhereIF(iLevelOfArgument != -1, x => x.LevelOfArgument == iLevelOfArgument)
  188. .WhereIF(!string.IsNullOrEmpty(sArgIDs), x => sArgIDs.Contains(x.ArgumentID))
  189. .WhereIF(!string.IsNullOrEmpty(sParentID), x => SqlFunc.IsNull(x.ParentArgument, "") == sParentID)
  190. .Select(x => new
  191. {
  192. id = x.ArgumentID,
  193. text = x.ArgumentValue,
  194. text_cn = x.ArgumentValue_CN,
  195. text_en = x.ArgumentValue_EN,
  196. label = x.ArgumentID + "-" + x.ArgumentValue,
  197. x.Correlation
  198. })
  199. .ToList();
  200. rm = new SuccessResponseMessage(null, i_crm);
  201. rm.DATA.Add(BLWording.REL, saArguments);
  202. } while (false);
  203. }
  204. catch (Exception ex)
  205. {
  206. sMsg = Util.GetLastExceptionMsg(ex);
  207. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.CommonService", "公用API", "GetArguments(獲取參數值)", "", "", "");
  208. }
  209. finally
  210. {
  211. if (null != sMsg)
  212. {
  213. rm = new ErrorResponseMessage(sMsg, i_crm);
  214. }
  215. }
  216. return rm;
  217. }
  218. #endregion 獲取參數值
  219. #region 獲取人員資料
  220. /// <summary>
  221. /// 獲取人員資料
  222. /// </summary>
  223. /// <param name="i_crm"></param>
  224. /// <returns></returns>
  225. public ResponseMessage GetUserList(RequestMessage i_crm)
  226. {
  227. ResponseMessage rm = null;
  228. string sMsg = null;
  229. var db = SugarBase.DB;
  230. try
  231. {
  232. do
  233. {
  234. var sDepartmentID = _fetchString(i_crm, "DepartmentID");
  235. var sMemberID = _fetchString(i_crm, "MemberID");
  236. var sUserIDs = _fetchString(i_crm, "UserIDs");
  237. var sNotUserIDs = _fetchString(i_crm, "NotUserIDs");
  238. var sServiceCode = _fetchString(i_crm, "ServiceCode");
  239. var sEffective = _fetchString(i_crm, "Effective");
  240. var saQueryMembers = db.Queryable<OTB_SYS_Members, OTB_SYS_Departments, OTB_SYS_Jobtitle>
  241. ((t1, t2, t3) =>
  242. new object[] {
  243. JoinType.Left, t1.OrgID == t2.OrgID && t1.DepartmentID == t2.DepartmentID,
  244. JoinType.Left, t1.OrgID == t3.OrgID && t1.JobTitle == t3.JobtitleID
  245. }
  246. )
  247. .OrderBy((t1, t2, t3) => t1.MemberID)
  248. .Where((t1, t2, t3) => t1.OrgID == i_crm.ORIGID && t1.ServiceCode != "API")
  249. .WhereIF(!string.IsNullOrEmpty(sDepartmentID), (t1, t2, t3) => t1.DepartmentID == sDepartmentID)
  250. .WhereIF(!string.IsNullOrEmpty(sMemberID), (t1, t2, t3) => t1.MemberID == sMemberID)
  251. .WhereIF(!string.IsNullOrEmpty(sUserIDs), (t1, t2, t3) => sUserIDs.Contains(t1.MemberID))
  252. .WhereIF(!string.IsNullOrEmpty(sNotUserIDs), (t1, t2, t3) => !sNotUserIDs.Contains(t1.MemberID))
  253. .WhereIF(!string.IsNullOrEmpty(sServiceCode), (t1, t2, t3) => sServiceCode.Contains(t1.ServiceCode))
  254. .WhereIF(!string.IsNullOrEmpty(sEffective), (t1, t2, t3) => t1.Effective == sEffective)
  255. .Select((t1, t2, t3) => new
  256. {
  257. t1.OrgID,
  258. t1.MemberID,
  259. t1.MemberName,
  260. t1.Email,
  261. t1.OutlookAccount,
  262. t1.ServiceCode,
  263. t1.DepartmentID,
  264. t1.MemberPic,
  265. t1.Effective,
  266. t2.DepartmentName,
  267. t3.JobtitleName
  268. })
  269. .ToList();
  270. rm = new SuccessResponseMessage(null, i_crm);
  271. rm.DATA.Add(BLWording.REL, saQueryMembers);
  272. } while (false);
  273. }
  274. catch (Exception ex)
  275. {
  276. sMsg = Util.GetLastExceptionMsg(ex);
  277. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.CommonService", "公用API", "GetUserList(獲取人員資料)", "", "", "");
  278. }
  279. finally
  280. {
  281. if (null != sMsg)
  282. {
  283. rm = new ErrorResponseMessage(sMsg, i_crm);
  284. }
  285. }
  286. return rm;
  287. }
  288. #endregion 獲取人員資料
  289. #region 獲取Office模版
  290. /// <summary>
  291. /// 獲取Office模版
  292. /// </summary>
  293. /// <param name="i_crm"></param>
  294. /// <returns></returns>
  295. public ResponseMessage GetOfficeTempls(RequestMessage i_crm)
  296. {
  297. ResponseMessage rm = null;
  298. string sMsg = null;
  299. var db = SugarBase.DB;
  300. try
  301. {
  302. do
  303. {
  304. var sTemplID = _fetchString(i_crm, "TemplID");
  305. var saOfficeTemplate = db.Queryable<OTB_SYS_OfficeTemplate>()
  306. .OrderBy(x => x.TemplID)
  307. .Where(x => x.OrgID == i_crm.ORIGID)
  308. .WhereIF(!string.IsNullOrEmpty(sTemplID), x => sTemplID.Contains(x.TemplID))
  309. //.Select(x => new { x.MemberID, x.MemberName, x.ServiceCode, x.DepartmentName, x.JobtitleName })
  310. .ToList();
  311. rm = new SuccessResponseMessage(null, i_crm);
  312. rm.DATA.Add(BLWording.REL, saOfficeTemplate);
  313. } while (false);
  314. }
  315. catch (Exception ex)
  316. {
  317. sMsg = Util.GetLastExceptionMsg(ex);
  318. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.CommonService", "公用API", "GetOfficeTempls( 獲取Office模版)", "", "", "");
  319. }
  320. finally
  321. {
  322. if (null != sMsg)
  323. {
  324. rm = new ErrorResponseMessage(sMsg, i_crm);
  325. }
  326. }
  327. return rm;
  328. }
  329. #endregion 獲取Office模版
  330. #region 獲取首頁公告
  331. /// <summary>
  332. /// 獲取首頁公告
  333. /// </summary>
  334. /// <param name="i_crm"></param>
  335. /// <returns></returns>
  336. public ResponseMessage GetAnnlist(RequestMessage i_crm)
  337. {
  338. ResponseMessage rm = null;
  339. string sMsg = null;
  340. var db = SugarBase.DB;
  341. try
  342. {
  343. do
  344. {
  345. var saAnnlist = db.Queryable<OTB_SYS_Announcement, OTB_SYS_Arguments, OTB_SYS_Members, OTB_SYS_Announcement_Read>((a, b, c, d) => new object[] {
  346. JoinType.Inner, a.OrgID==b.OrgID && a.Ann_Type==b.ArgumentID&&b.ArgumentClassID=="Ann_Type",
  347. JoinType.Inner, a.OrgID==c.OrgID && a.CreateUser==c.MemberID,
  348. JoinType.Left, a.AnnouncementID==d.AnnouncementID && d.CreateUser==i_crm.USERID
  349. })
  350. .Where((a) => a.OrgID == i_crm.ORIGID && a.StartDateTime <= DateTime.Now && a.EndDateTime >= DateTime.Now)
  351. .Select((a, b, c, d) =>
  352. new
  353. {
  354. a.AnnouncementID,
  355. a.Ann_Type,
  356. a.Title,
  357. a.Description,
  358. a.FontColor,
  359. a.StartDateTime,
  360. a.EndDateTime,
  361. a.CreateUser,
  362. a.CreateDate,
  363. a.GoTop,
  364. a.GoTop_Time,
  365. Ann_TypeName = b.ArgumentValue,
  366. CreateUserName = c.MemberName,
  367. IsAlert = d.SN
  368. }).ToList();
  369. rm = new SuccessResponseMessage(null, i_crm);
  370. rm.DATA.Add(BLWording.REL, saAnnlist);
  371. } while (false);
  372. }
  373. catch (Exception ex)
  374. {
  375. sMsg = Util.GetLastExceptionMsg(ex);
  376. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.CommonService", "公用API", "GetAnnlist(獲取首頁公告)", "", "", "");
  377. }
  378. finally
  379. {
  380. if (null != sMsg)
  381. {
  382. rm = new ErrorResponseMessage(sMsg, i_crm);
  383. }
  384. }
  385. return rm;
  386. }
  387. #endregion 獲取首頁公告
  388. #region 取得上週缺勤
  389. public ResponseMessage GetAbsenceFromLastWeek(RequestMessage i_crm)
  390. {
  391. var StartDt = DateTime.Now;
  392. if (StartDt.DayOfWeek != DayOfWeek.Monday)
  393. return new ResponseMessage();
  394. ResponseMessage rm = null;
  395. string sMsg = null;
  396. StartDt = StartDt.AddDays(-7).Date;
  397. var EndDt = StartDt.AddDays(4).Date.AddSeconds( 24*60 * 60 -1);
  398. var db = SugarBase.DB;
  399. try
  400. {
  401. do
  402. {
  403. var ToBeNotification = new List<OTB_EIP_Attendance>();
  404. var saAttendances = db.Queryable<OTB_EIP_Attendance>()
  405. .Where( x => x.CardDate >= StartDt && x.CardDate < EndDt && !SqlFunc.IsNullOrEmpty(x.Memo) && x.OrgID == i_crm.ORIGID && x.UserID == i_crm.USERID)
  406. .ToList();
  407. //取得所有差勤異常(by 日子)
  408. var saAttendanceDiffStatus = new string[] { @"B", @"E", @"H-O" };
  409. var saAttendanceDiff = db.Queryable<OTB_EIP_AttendanceDiff>().Where(it => saAttendanceDiffStatus.Contains(it.Status) && it.AskTheDummy == i_crm.USERID).ToList();
  410. //取得請假資料
  411. var saLeaveStatus = new string[] { @"B", @"E", @"H-O" };
  412. var saLeave = db.Queryable<OTB_EIP_Leave>().Where(it => saLeaveStatus.Contains(it.Status) && it.AskTheDummy == i_crm.USERID).ToList();
  413. foreach (var Ad in saAttendances)
  414. {
  415. var ThisDay = Ad.CardDate.Date;
  416. var FoundInAttendaceDiff = saAttendanceDiff.Any(c => c.FillBrushDate.Value.Date == ThisDay);
  417. var FoundInLeave = saLeave.Any(c => c.StartDate.Value.Date <= ThisDay && c.EndDate.Value.Date >= ThisDay);
  418. if (!FoundInAttendaceDiff && !FoundInLeave)
  419. ToBeNotification.Add(Ad);
  420. }
  421. rm = new SuccessResponseMessage(null, i_crm);
  422. rm.DATA.Add(BLWording.REL, ToBeNotification);
  423. } while (false);
  424. }
  425. catch (Exception ex)
  426. {
  427. sMsg = Util.GetLastExceptionMsg(ex);
  428. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.CommonService", "公用API", nameof(GetAbsenceFromLastWeek) + "(取得上週缺勤)", "", "", "");
  429. }
  430. finally
  431. {
  432. if (null != sMsg)
  433. {
  434. rm = new ErrorResponseMessage(sMsg, i_crm);
  435. }
  436. }
  437. return rm;
  438. }
  439. #endregion
  440. #region 獲取上傳文件(附件)
  441. /// <summary>
  442. /// 獲取上傳文件(附件)
  443. /// </summary>
  444. /// <param name="i_crm"></param>
  445. /// <returns></returns>
  446. public ResponseMessage GetUploadFiles(RequestMessage i_crm)
  447. {
  448. ResponseMessage rm = null;
  449. string sMsg = null;
  450. var db = SugarBase.DB;
  451. try
  452. {
  453. do
  454. {
  455. var sParentID = _fetchString(i_crm, "ParentID");
  456. var saFiles = db.Queryable<OTB_SYS_Files>()
  457. .OrderBy(x => x.OrderByValue)
  458. .Where(x => x.ParentID == sParentID && x.OrgID == i_crm.ORIGID)
  459. .ToList();
  460. rm = new SuccessResponseMessage(null, i_crm);
  461. rm.DATA.Add(BLWording.REL, saFiles);
  462. } while (false);
  463. }
  464. catch (Exception ex)
  465. {
  466. sMsg = Util.GetLastExceptionMsg(ex);
  467. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.CommonService", "公用API", "GetUploadFiles(獲取上傳文件(附件))", "", "", "");
  468. }
  469. finally
  470. {
  471. if (null != sMsg)
  472. {
  473. rm = new ErrorResponseMessage(sMsg, i_crm);
  474. }
  475. }
  476. return rm;
  477. }
  478. #endregion 獲取上傳文件(附件)
  479. #region 編輯文件(附件)
  480. /// <summary>
  481. /// 編輯文件(附件)
  482. /// </summary>
  483. /// <param name="i_crm"></param>
  484. /// <returns></returns>
  485. public ResponseMessage EditFile(RequestMessage i_crm)
  486. {
  487. ResponseMessage rm = null;
  488. string sMsg = null;
  489. var db = SugarBase.GetIntance();
  490. try
  491. {
  492. do
  493. {
  494. var oEntity = _fetchEntity<OTB_SYS_Files>(i_crm);
  495. _setEntityBase(oEntity, i_crm);
  496. var iRel = db.Updateable(oEntity)
  497. .UpdateColumns(x => new
  498. {
  499. x.FileName,
  500. x.Link,
  501. x.Description,
  502. x.ModifyDate,
  503. x.ModifyUser
  504. }).ExecuteCommand();
  505. rm = new SuccessResponseMessage(null, i_crm);
  506. rm.DATA.Add(BLWording.REL, iRel);
  507. } while (false);
  508. }
  509. catch (Exception ex)
  510. {
  511. sMsg = Util.GetLastExceptionMsg(ex);
  512. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.CommonService", "公用API", "DelFile(刪除文件(附件))", "", "", "");
  513. }
  514. finally
  515. {
  516. if (null != sMsg)
  517. {
  518. rm = new ErrorResponseMessage(sMsg, i_crm);
  519. }
  520. }
  521. return rm;
  522. }
  523. #endregion 編輯文件(附件)
  524. #region 刪除文件(附件)
  525. /// <summary>
  526. /// 刪除文件(附件)
  527. /// </summary>
  528. /// <param name="i_crm"></param>
  529. /// <returns></returns>
  530. public ResponseMessage DelFile(RequestMessage i_crm)
  531. {
  532. ResponseMessage rm = null;
  533. string sMsg = null;
  534. var db = SugarBase.GetIntance();
  535. try
  536. {
  537. do
  538. {
  539. var sFileID = _fetchString(i_crm, "FileID");
  540. var sIdType = _fetchString(i_crm, "IDType");
  541. var bParent = sIdType == "parent";
  542. var bDel = false;
  543. var saFiles = db.Queryable<OTB_SYS_Files>()
  544. .Where(x => x.OrgID == i_crm.ORIGID)
  545. .WhereIF(bParent, it => it.ParentID == sFileID)
  546. .WhereIF(!bParent, it => it.FileID == sFileID).ToList();
  547. if (saFiles.Count > 0)
  548. {
  549. bDel = db.Deleteable(saFiles).ExecuteCommandHasChange();
  550. if (bDel)
  551. {
  552. var Pdf = new PdfService();
  553. foreach (var file in saFiles)
  554. {
  555. bDel = PdfService.DelFile(file.FilePath);
  556. }
  557. }
  558. }
  559. rm = new SuccessResponseMessage(null, i_crm);
  560. rm.DATA.Add(BLWording.REL, bDel);
  561. } while (false);
  562. }
  563. catch (Exception ex)
  564. {
  565. sMsg = Util.GetLastExceptionMsg(ex);
  566. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.CommonService", "公用API", "DelFile(刪除文件(附件))", "", "", "");
  567. }
  568. finally
  569. {
  570. if (null != sMsg)
  571. {
  572. rm = new ErrorResponseMessage(sMsg, i_crm);
  573. }
  574. }
  575. return rm;
  576. }
  577. #endregion 刪除文件(附件)
  578. #region 获得當前公网ip
  579. /// <summary>
  580. /// 获得當前公网ip
  581. /// </summary>
  582. /// <param name="i_crm"></param>
  583. /// <returns></returns>
  584. public ResponseMessage GetPublicIP(RequestMessage i_crm)
  585. {
  586. ResponseMessage rm = null;
  587. string sMsg = null;
  588. try
  589. {
  590. do
  591. {
  592. var sIp = GetPubIP();
  593. rm = new SuccessResponseMessage(null, i_crm);
  594. rm.DATA.Add(BLWording.REL, sIp);
  595. } while (false);
  596. }
  597. catch (Exception ex)
  598. {
  599. sMsg = Util.GetLastExceptionMsg(ex);
  600. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.CommonService", "公用方法", "GetPublicIP(获得當前公网ip)", "", "", "");
  601. }
  602. finally
  603. {
  604. if (null != sMsg)
  605. {
  606. rm = new ErrorResponseMessage(sMsg, i_crm);
  607. }
  608. }
  609. return rm;
  610. }
  611. #endregion 获得當前公网ip
  612. #region 获得公网ip信息
  613. /// <summary>
  614. /// 获得公网ip信息
  615. /// </summary>
  616. /// <param name="i_crm"></param>
  617. /// <returns></returns>
  618. public ResponseMessage GetIPInfo(RequestMessage i_crm)
  619. {
  620. ResponseMessage rm = null;
  621. string sMsg = null;
  622. try
  623. {
  624. do
  625. {
  626. var sIp = _fetchString(i_crm, "ip");
  627. var sValue = String.Empty;
  628. var strUrl = "http://ip.taobao.com/service/getIpInfo.php?ip=" + sIp; //获得IP的网址
  629. var uri = new Uri(strUrl);
  630. var wr = WebRequest.Create(uri);
  631. var s = wr.GetResponse().GetResponseStream();
  632. using (var sr = new StreamReader(s, Encoding.UTF8))
  633. {
  634. var sInfo = sr.ReadToEnd(); //读取网站的数据
  635. rm = new SuccessResponseMessage(null, i_crm);
  636. rm.DATA.Add(BLWording.REL, sInfo);
  637. }
  638. } while (false);
  639. }
  640. catch (Exception ex)
  641. {
  642. sMsg = Util.GetLastExceptionMsg(ex);
  643. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.CommonService", "公用方法", "GetIPInfo(获得公网ip信息)", "", "", "");
  644. }
  645. finally
  646. {
  647. if (null != sMsg)
  648. {
  649. rm = new ErrorResponseMessage(sMsg, i_crm);
  650. }
  651. }
  652. return rm;
  653. }
  654. #endregion 获得公网ip信息
  655. public static string GetPubIP()
  656. {
  657. string sIp;
  658. try
  659. {
  660. const string strUrl = "http://www.taobao.com/help/getip.php"; //获得IP的网址
  661. var uri = new Uri(strUrl);
  662. var wr = WebRequest.Create(uri);
  663. var s = wr.GetResponse().GetResponseStream();
  664. using (var sr = new StreamReader(s, Encoding.Default))
  665. {
  666. var all = sr.ReadToEnd(); //读取网站的数据
  667. Match match;
  668. const string pattern = "(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)";
  669. match = Regex.Match(all, pattern, RegexOptions.IgnoreCase);
  670. sIp = match.ToString();
  671. return sIp;
  672. }
  673. }
  674. catch (Exception ex)
  675. {
  676. LogService.mo_Log.Error("CommonService.GetIP Error." + ex.Message, ex);
  677. return "";
  678. }
  679. }
  680. }
  681. }