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.

376 lines
14 KiB

2 years ago
  1. using EasyBL.WebApi.Message;
  2. using Entity.Sugar;
  3. using SqlSugar;
  4. using SqlSugar.Base;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.IO;
  8. using System.Linq;
  9. namespace EasyBL.WEBAPP.SYS
  10. {
  11. public class Language_SetService : ServiceBase
  12. {
  13. #region 多語系管理(分頁查詢)
  14. /// <summary>
  15. /// 多語系管理(分頁查詢)
  16. /// </summary>
  17. /// <param name="i_crm"></param>
  18. /// <returns></returns>
  19. public ResponseMessage QueryPage(RequestMessage i_crm)
  20. {
  21. ResponseMessage rm = null;
  22. string sMsg = null;
  23. var db = SugarBase.GetIntance();
  24. try
  25. {
  26. do
  27. {
  28. var pml = new PageModel
  29. {
  30. PageIndex = _fetchInt(i_crm, @"pageIndex"),
  31. PageSize = _fetchInt(i_crm, @"pageSize")
  32. };
  33. var iPageCount = 0;
  34. var sSortField = _fetchString(i_crm, @"sortField");
  35. var sSortOrder = _fetchString(i_crm, @"sortOrder");
  36. var sLanguageType = _fetchString(i_crm, @"LanguageType");
  37. var sCountry = _fetchString(i_crm, @"Country");
  38. var sLanguageId = _fetchString(i_crm, @"LanguageId");
  39. var sLanguageName = _fetchString(i_crm, @"LanguageName");
  40. var bExcel = _fetchBool(i_crm, @"Excel");
  41. pml.DataList = db.Queryable<OTB_SYS_Language>()
  42. .Where(x => x.OrgID == i_crm.ORIGID && x.LangId.Contains(sLanguageId) && x.LangName.Contains(sLanguageName))
  43. .WhereIF(!string.IsNullOrEmpty(sLanguageType), x => x.Type == sLanguageType)
  44. .WhereIF(!string.IsNullOrEmpty(sCountry), x => x.Country == sCountry)
  45. .OrderBy(sSortField, sSortOrder)
  46. .ToPageList(pml.PageIndex, bExcel ? 100000 : pml.PageSize, ref iPageCount);
  47. pml.Total = iPageCount;
  48. rm = new SuccessResponseMessage(null, i_crm);
  49. if (bExcel)
  50. {
  51. }
  52. else
  53. {
  54. rm.DATA.Add(BLWording.REL, pml);
  55. }
  56. } while (false);
  57. }
  58. catch (Exception ex)
  59. {
  60. sMsg = Util.GetLastExceptionMsg(ex);
  61. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBAPP.SYS.ArgumentClassMaintain_QryService", "", "QueryPage(多語系管理(分頁查詢))", "", "", "");
  62. }
  63. finally
  64. {
  65. if (null != sMsg)
  66. {
  67. rm = new ErrorResponseMessage(sMsg, i_crm);
  68. }
  69. }
  70. return rm;
  71. }
  72. #endregion 多語系管理(分頁查詢)
  73. #region 多語系管理(新增)
  74. /// <summary>
  75. /// 多語系管理(新增)
  76. /// </summary>
  77. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  78. /// <returns></returns>
  79. public ResponseMessage GridInsert(RequestMessage i_crm)
  80. {
  81. ResponseMessage rm = null;
  82. string sMsg = null;
  83. try
  84. {
  85. rm = SugarBase.ExecTran(db =>
  86. {
  87. do
  88. {
  89. var oEntity = _fetchEntity<OTB_SYS_Language>(i_crm);
  90. if (db.Queryable<OTB_SYS_Language>().Any(x => x.OrgID == i_crm.ORIGID && x.Country == oEntity.Country && x.Type == oEntity.Type && x.LangId == oEntity.LangId))
  91. {
  92. sMsg = @"該語系ID已存在!";
  93. break;
  94. }
  95. _setEntityBase(oEntity, i_crm);
  96. var iRel = db.Insertable(oEntity).ExecuteCommand();
  97. rm = new SuccessResponseMessage(null, i_crm);
  98. rm.DATA.Add(BLWording.REL, iRel);
  99. } while (false);
  100. return rm;
  101. });
  102. }
  103. catch (Exception ex)
  104. {
  105. sMsg = Util.GetLastExceptionMsg(ex);
  106. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(Language_SetService), @"多語系管理", @"GridInsert(多語系管理(新增))", @"", @"", @"");
  107. }
  108. finally
  109. {
  110. if (null != sMsg)
  111. {
  112. rm = new ErrorResponseMessage(sMsg, i_crm);
  113. }
  114. }
  115. return rm;
  116. }
  117. #endregion 多語系管理(新增)
  118. #region 多語系管理(修改)
  119. /// <summary>
  120. /// 多語系管理(修改)
  121. /// </summary>
  122. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  123. /// <returns></returns>
  124. public ResponseMessage GridUpdate(RequestMessage i_crm)
  125. {
  126. ResponseMessage rm = null;
  127. string sMsg = null;
  128. try
  129. {
  130. rm = SugarBase.ExecTran(db =>
  131. {
  132. do
  133. {
  134. var oNewEntity = _fetchEntity<OTB_SYS_Language>(i_crm);
  135. _setEntityBase(oNewEntity, i_crm);
  136. var iRel = db.Updateable(oNewEntity)
  137. .IgnoreColumns(x => new
  138. {
  139. x.NO,
  140. x.CreateUser,
  141. x.CreateDate
  142. }).ExecuteCommand();
  143. rm = new SuccessResponseMessage(null, i_crm);
  144. rm.DATA.Add(BLWording.REL, iRel);
  145. } while (false);
  146. return rm;
  147. });
  148. }
  149. catch (Exception ex)
  150. {
  151. sMsg = Util.GetLastExceptionMsg(ex);
  152. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(Language_SetService), @"多語系管理", @"GridUpdate(多語系管理(修改))", @"", @"", @"");
  153. }
  154. finally
  155. {
  156. if (null != sMsg)
  157. {
  158. rm = new ErrorResponseMessage(sMsg, i_crm);
  159. }
  160. }
  161. return rm;
  162. }
  163. #endregion 多語系管理(修改)
  164. #region 多語系管理(刪除)
  165. /// <summary>
  166. /// 多語系管理(刪除)
  167. /// </summary>
  168. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  169. /// <returns></returns>
  170. public ResponseMessage GridDelete(RequestMessage i_crm)
  171. {
  172. ResponseMessage rm = null;
  173. string sMsg = null;
  174. try
  175. {
  176. rm = SugarBase.ExecTran(db =>
  177. {
  178. do
  179. {
  180. var iNO = _fetchInt(i_crm, @"NO");
  181. var iRel = db.Deleteable<OTB_SYS_Language>()
  182. .Where(x => x.OrgID == i_crm.ORIGID && x.NO == iNO).ExecuteCommand();
  183. rm = new SuccessResponseMessage(null, i_crm);
  184. rm.DATA.Add(BLWording.REL, iRel);
  185. } while (false);
  186. return rm;
  187. });
  188. }
  189. catch (Exception ex)
  190. {
  191. sMsg = Util.GetLastExceptionMsg(ex);
  192. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(Language_SetService), @"多語系管理", @"GridDelete(多語系管理(刪除))", @"", @"", @"");
  193. }
  194. finally
  195. {
  196. if (null != sMsg)
  197. {
  198. rm = new ErrorResponseMessage(sMsg, i_crm);
  199. }
  200. }
  201. return rm;
  202. }
  203. #endregion 多語系管理(刪除)
  204. #region 查詢系統所有html文件路徑
  205. /// <summary>
  206. /// 函式名稱:GetSysHtmlPath
  207. /// 函式說明:查詢系統所有html文件路徑
  208. /// </summary>
  209. /// <param name="i_crm">todo: describe i_crm parameter on GetSysHtmlPath</param>
  210. /// <returns>
  211. /// 回傳 ENTITYS(Object):查詢數據(list),總比數,狀態...
  212. ///</returns>
  213. public ResponseMessage GetSysHtmlPath(RequestMessage i_crm)
  214. {
  215. ResponseMessage crm = null;
  216. string sMsg = null;
  217. var GetFilesPath = new List<Dictionary<string, string>>();
  218. try
  219. {
  220. do
  221. {
  222. var sProgramPath = _fetchString(i_crm, BLWording.FILEPATH);
  223. // 將虛擬路徑轉為實體路徑
  224. sProgramPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, sProgramPath);
  225. // 真實邏輯
  226. foreach (var fi in Directory.GetFiles(sProgramPath, @"*.html", SearchOption.AllDirectories))
  227. {
  228. if (fi.ToLower().IndexOf(@"page") > -1)
  229. {
  230. var dic = new Dictionary<string, string>();
  231. var sPath = fi.Replace(AppDomain.CurrentDomain.BaseDirectory, @"\").Replace(@"\", @"/");
  232. dic.Add(BLWording.ID, sPath);
  233. dic.Add(BLWording.NAME, sPath);
  234. GetFilesPath.Add(dic);
  235. }
  236. }
  237. foreach (var fi in Directory.GetFiles(sProgramPath, @"*.aspx", SearchOption.AllDirectories))
  238. {
  239. if (fi.ToLower().IndexOf(@"page") > -1)
  240. {
  241. var dic = new Dictionary<string, string>();
  242. var sPath = fi.Replace(AppDomain.CurrentDomain.BaseDirectory, @"\").Replace(@"\", @"/");
  243. dic.Add(BLWording.ID, sPath);
  244. dic.Add(BLWording.NAME, sPath);
  245. GetFilesPath.Add(dic);
  246. }
  247. }
  248. crm = new SuccessResponseMessage(null, i_crm);
  249. // 填寫回傳
  250. crm.DATA.Add(BLWording.REL, GetFilesPath);
  251. }
  252. while (false);
  253. }
  254. catch (Exception ex)
  255. {
  256. sMsg = Util.GetLastExceptionMsg(ex);
  257. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(Language_SetService), @"多語系設定", @"GetSysHtmlPath(查詢系統所有html文件路徑)", @"", @"", @"");
  258. }
  259. if (null != sMsg)
  260. {
  261. crm = new ErrorResponseMessage(sMsg, i_crm);
  262. }
  263. return crm;
  264. }
  265. #endregion 查詢系統所有html文件路徑
  266. #region 複製語系檔案
  267. /// <summary>
  268. /// 函式名稱:CopyLanguage
  269. /// 函式說明:複製語系檔案
  270. /// </summary>
  271. /// <param name="i_crm">todo: describe i_crm parameter on CopyLanguage</param>
  272. /// <returns>
  273. /// 回傳 rm(Object)
  274. ///</returns>
  275. public ResponseMessage CopyLanguage(RequestMessage i_crm)
  276. {
  277. ResponseMessage rm = null;
  278. string sMsg = null;
  279. var db = SugarBase.GetIntance();
  280. try
  281. {
  282. do
  283. {
  284. var sLangFrom = _fetchString(i_crm, @"LangFrom");
  285. var sLangTo = _fetchString(i_crm, @"LangTo");
  286. var saLangFrom = db.Queryable<OTB_SYS_Language>().Where(x => x.OrgID == i_crm.ORIGID && x.Country == sLangFrom).ToList();
  287. var saLangTo = db.Queryable<OTB_SYS_Language>().Where(x => x.OrgID == i_crm.ORIGID && x.Country == sLangTo).ToList();
  288. if (saLangFrom.Count == 0)
  289. {
  290. sMsg = @"1";
  291. break;
  292. }
  293. var ListAdd = new List<OTB_SYS_Language>();
  294. foreach (OTB_SYS_Language oLanguage in saLangFrom)
  295. {
  296. if (!saLangTo.Any(p => (p.LangId == oLanguage.LangId && p.Type == oLanguage.Type)))
  297. {
  298. ListAdd.Add(oLanguage);
  299. }
  300. }
  301. if (ListAdd.Count > 0)
  302. {
  303. foreach (OTB_SYS_Language oLanguage in ListAdd)
  304. {
  305. oLanguage.Country = sLangTo;
  306. oLanguage.Memo = oLanguage.LangName;
  307. oLanguage.LangName = sLangTo == @"zh" ? ChineseStringUtility.ToSimplified(oLanguage.LangName) : @"";
  308. oLanguage.CreateUser = i_crm.USERID;
  309. oLanguage.CreateDate = DateTime.Now;
  310. oLanguage.ModifyUser = i_crm.USERID;
  311. oLanguage.ModifyDate = DateTime.Now;
  312. }
  313. var iRel = db.Insertable(ListAdd).ExecuteCommand();
  314. if (iRel == 0) // 複製失敗
  315. {
  316. sMsg = @"0";
  317. break;
  318. }
  319. }
  320. rm = new SuccessResponseMessage(null, i_crm);
  321. //rm.DATA.Add(BLWording.REL, bSend);
  322. } while (false);
  323. }
  324. catch (Exception ex)
  325. {
  326. sMsg = Util.GetLastExceptionMsg(ex);
  327. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(Language_SetService), @"多語系設定", @"CopyLanguage(複製語系檔案)", @"", @"", @"");
  328. }
  329. finally
  330. {
  331. if (null != sMsg)
  332. {
  333. rm = new ErrorResponseMessage(sMsg, i_crm);
  334. }
  335. }
  336. return rm;
  337. }
  338. #endregion 複製語系檔案
  339. }
  340. }