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.

402 lines
16 KiB

2 years ago
  1. using EasyBL.WebApi.Message;
  2. using Entity.Sugar;
  3. using Entity.ViewModels;
  4. using SqlSugar;
  5. using SqlSugar.Base;
  6. using System;
  7. namespace EasyBL.WEBAPP.WSM
  8. {
  9. public class WebSiteSetupService : ServiceBase
  10. {
  11. #region 官網設定(分頁查詢)
  12. /// <summary>
  13. /// 官網設定(分頁查詢)
  14. /// </summary>
  15. /// <param name="i_crm"></param>
  16. /// <returns></returns>
  17. public ResponseMessage QueryPage(RequestMessage i_crm)
  18. {
  19. ResponseMessage rm = null;
  20. string sMsg = null;
  21. var db = SugarBase.GetIntance();
  22. try
  23. {
  24. do
  25. {
  26. var pml = new PageModel
  27. {
  28. PageIndex = _fetchInt(i_crm, @"pageIndex"),
  29. PageSize = _fetchInt(i_crm, @"pageSize")
  30. };
  31. var iPageCount = 0;
  32. var sSortField = _fetchString(i_crm, @"sortField");
  33. var sSortOrder = _fetchString(i_crm, @"sortOrder");
  34. var sSetType = _fetchString(i_crm, @"SetType");
  35. var sLangId = _fetchString(i_crm, @"LangId");
  36. var sParentId = _fetchString(i_crm, @"ParentId");
  37. var bExcel = _fetchBool(i_crm, @"Excel");
  38. pml.DataList = db.Queryable<OTB_WSM_WebSiteSetting>()
  39. .Where(x => x.OrgID == i_crm.ORIGID && x.SetType == sSetType && x.LangId == sLangId)
  40. .WhereIF(!string.IsNullOrEmpty(sParentId), x => x.ParentId == sParentId)
  41. .Select(x => new View_WSM_WebSiteSetting
  42. {
  43. Guid = SqlFunc.GetSelfAndAutoFill(x.Guid),
  44. OrderCount = SqlFunc.Subqueryable<OTB_WSM_WebSiteSetting>()
  45. .Where(p => p.OrgID == x.OrgID && p.LangId == x.LangId && p.SetType == x.SetType && ((SqlFunc.HasValue(p.ParentId) && p.ParentId == x.ParentId) || (!SqlFunc.HasValue(x.ParentId) && SqlFunc.IsNull(p.ParentId, "") == "")))
  46. .Count()
  47. })
  48. .OrderBy(sSortField, sSortOrder)
  49. .ToPageList(pml.PageIndex, pml.PageSize, ref iPageCount);
  50. pml.Total = iPageCount;
  51. rm = new SuccessResponseMessage(null, i_crm);
  52. if (bExcel)
  53. {
  54. }
  55. else
  56. {
  57. rm.DATA.Add(BLWording.REL, pml);
  58. }
  59. } while (false);
  60. }
  61. catch (Exception ex)
  62. {
  63. sMsg = Util.GetLastExceptionMsg(ex);
  64. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(WebSiteSetupService), "", "QueryPage(官網設定(分頁查詢))", "", "", "");
  65. }
  66. finally
  67. {
  68. if (null != sMsg)
  69. {
  70. rm = new ErrorResponseMessage(sMsg, i_crm);
  71. }
  72. }
  73. return rm;
  74. }
  75. #endregion 官網設定(分頁查詢)
  76. #region 組織資訊(單筆)
  77. /// <summary>
  78. /// 組織資訊(單筆)
  79. /// </summary>
  80. /// <param name="i_crm"></param>
  81. /// <returns></returns>
  82. public ResponseMessage QueryOne(RequestMessage i_crm)
  83. {
  84. ResponseMessage rm = null;
  85. string sMsg = null;
  86. var db = SugarBase.GetIntance();
  87. try
  88. {
  89. do
  90. {
  91. var oEntity = db.Queryable<OTB_SYS_Organization, OTB_SYS_Members, OTB_SYS_Members>
  92. ((t1, t2, t3) =>
  93. new object[] {
  94. JoinType.Left, t1.OrgID == t2.OrgID && t1.CreateUser == t2.MemberID,
  95. JoinType.Left, t1.OrgID == t3.OrgID && t1.ModifyUser == t3.MemberID
  96. }
  97. )
  98. .Where((t1, t2, t3) => t1.OrgID == i_crm.ORIGID)
  99. .Select((t1, t2, t3) => new OTB_SYS_Organization
  100. {
  101. OrgID = SqlFunc.GetSelfAndAutoFill(t1.OrgID),
  102. CreateUserName = t2.MemberName,
  103. ModifyUserName = t3.MemberName
  104. })
  105. .Single();
  106. rm = new SuccessResponseMessage(null, i_crm);
  107. rm.DATA.Add(BLWording.REL, oEntity);
  108. } while (false);
  109. }
  110. catch (Exception ex)
  111. {
  112. sMsg = Util.GetLastExceptionMsg(ex);
  113. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(WebSiteSetupService), "", "QueryOne(組織資訊(單筆))", "", "", "");
  114. }
  115. finally
  116. {
  117. if (null != sMsg)
  118. {
  119. rm = new ErrorResponseMessage(sMsg, i_crm);
  120. }
  121. }
  122. return rm;
  123. }
  124. #endregion 組織資訊(單筆)
  125. #region 官網設定(基本資料修改)
  126. /// <summary>
  127. /// 官網設定(基本資料修改)
  128. /// </summary>
  129. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  130. /// <returns></returns>
  131. public ResponseMessage Update(RequestMessage i_crm)
  132. {
  133. ResponseMessage rm = null;
  134. string sMsg = null;
  135. try
  136. {
  137. rm = SugarBase.ExecTran(db =>
  138. {
  139. do
  140. {
  141. var oNewEntity = _fetchEntity<OTB_SYS_Organization>(i_crm);
  142. _setEntityBase(oNewEntity, i_crm);
  143. var iRel = db.Updateable(oNewEntity)
  144. .UpdateColumns(x => new
  145. {
  146. x.VideoUrl,
  147. x.VideoUrl_CN,
  148. x.VideoUrl_EN,
  149. x.Introduction,
  150. x.Introduction_CN,
  151. x.Introduction_EN,
  152. x.MissionAndVision_TW,
  153. x.MissionAndVision_CN,
  154. x.MissionAndVision_EN,
  155. x.ServiceTitle,
  156. x.ServiceTitle_CN,
  157. x.ServiceTitle_EN,
  158. x.VideoDescription,
  159. x.VideoDescription_CN,
  160. x.VideoDescription_EN,
  161. x.ModifyUser,
  162. x.ModifyDate
  163. }).ExecuteCommand();
  164. rm = new SuccessResponseMessage(null, i_crm);
  165. rm.DATA.Add(BLWording.REL, iRel);
  166. } while (false);
  167. return rm;
  168. });
  169. }
  170. catch (Exception ex)
  171. {
  172. sMsg = Util.GetLastExceptionMsg(ex);
  173. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(WebSiteSetupService), @"官網設定", @"Update(官網設定(基本資料修改))", @"", @"", @"");
  174. }
  175. finally
  176. {
  177. if (null != sMsg)
  178. {
  179. rm = new ErrorResponseMessage(sMsg, i_crm);
  180. }
  181. }
  182. return rm;
  183. }
  184. #endregion 官網設定(基本資料修改)
  185. #region 官網設定(新增)
  186. /// <summary>
  187. /// 官網設定(新增)
  188. /// </summary>
  189. /// <param name="i_crm">todo: describe i_crm parameter on InsertImportCustomers</param>
  190. /// <returns></returns>
  191. public ResponseMessage GridInsert(RequestMessage i_crm)
  192. {
  193. ResponseMessage rm = null;
  194. string sMsg = null;
  195. var db = SugarBase.GetIntance();
  196. try
  197. {
  198. do
  199. {
  200. var oEntity = _fetchEntity<OTB_WSM_WebSiteSetting>(i_crm);
  201. oEntity.Guid = Guid.NewGuid().ToString();
  202. oEntity.Title = oEntity.Title ?? "";
  203. _setEntityBase(oEntity, i_crm);
  204. var iRel = db.Insertable(oEntity).ExecuteCommand();
  205. rm = new SuccessResponseMessage(null, i_crm);
  206. rm.DATA.Add(BLWording.REL, iRel);
  207. } while (false);
  208. }
  209. catch (Exception ex)
  210. {
  211. sMsg = Util.GetLastExceptionMsg(ex);
  212. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(WebSiteSetupService), @"官網設定", @"Add(官網設定(新增))", @"", @"", @"");
  213. }
  214. finally
  215. {
  216. if (null != sMsg)
  217. {
  218. rm = new ErrorResponseMessage(sMsg, i_crm);
  219. }
  220. }
  221. return rm;
  222. }
  223. #endregion 官網設定(新增)
  224. #region 官網設定(修改)
  225. /// <summary>
  226. /// 官網設定(修改)
  227. /// </summary>
  228. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  229. /// <returns></returns>
  230. public ResponseMessage GridUpdate(RequestMessage i_crm)
  231. {
  232. ResponseMessage rm = null;
  233. string sMsg = null;
  234. var db = SugarBase.GetIntance();
  235. try
  236. {
  237. do
  238. {
  239. var oEntity = _fetchEntity<OTB_WSM_WebSiteSetting>(i_crm);
  240. _setEntityBase(oEntity, i_crm);
  241. var iRel = db.Updateable(oEntity)
  242. .IgnoreColumns(x => new
  243. {
  244. x.OrgID,
  245. x.CreateDate,
  246. x.CreateUser
  247. }).ExecuteCommand();
  248. rm = new SuccessResponseMessage(null, i_crm);
  249. rm.DATA.Add(BLWording.REL, iRel);
  250. } while (false);
  251. }
  252. catch (Exception ex)
  253. {
  254. sMsg = Util.GetLastExceptionMsg(ex);
  255. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(WebSiteSetupService), @"官網設定", @"Update(官網設定(修改))", @"", @"", @"");
  256. }
  257. finally
  258. {
  259. if (null != sMsg)
  260. {
  261. rm = new ErrorResponseMessage(sMsg, i_crm);
  262. }
  263. }
  264. return rm;
  265. }
  266. #endregion 官網設定(修改)
  267. #region 官網設定(刪除)
  268. /// <summary>
  269. /// 官網設定(刪除)
  270. /// </summary>
  271. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  272. /// <returns></returns>
  273. public ResponseMessage GridDelete(RequestMessage i_crm)
  274. {
  275. ResponseMessage rm = null;
  276. string sMsg = null;
  277. var db = SugarBase.GetIntance();
  278. try
  279. {
  280. do
  281. {
  282. var sGuid = _fetchString(i_crm, @"Guid");
  283. var oWebSiteSetting = db.Queryable<OTB_WSM_WebSiteSetting>().Single(x => x.Guid == sGuid);
  284. var iRel = db.Deleteable<OTB_WSM_WebSiteSetting>().Where(x => x.Guid == sGuid).ExecuteCommand();
  285. var iRelUp = db.Updateable<OTB_WSM_WebSiteSetting>()
  286. .UpdateColumns(x => new OTB_WSM_WebSiteSetting { OrderByValue = x.OrderByValue - 1 })
  287. .Where(x => x.OrgID == oWebSiteSetting.OrgID && x.SetType == oWebSiteSetting.SetType && x.LangId == oWebSiteSetting.LangId && SqlFunc.IsNull(x.ParentId, "") == SqlFunc.IsNull(oWebSiteSetting.ParentId, "") && x.OrderByValue > oWebSiteSetting.OrderByValue).ExecuteCommand();
  288. i_crm.DATA.Add("FileID", oWebSiteSetting.CoverId);
  289. i_crm.DATA.Add("IDType", "parent");
  290. new CommonService().DelFile(i_crm);
  291. rm = new SuccessResponseMessage(null, i_crm);
  292. rm.DATA.Add(BLWording.REL, iRel);
  293. } while (false);
  294. }
  295. catch (Exception ex)
  296. {
  297. sMsg = Util.GetLastExceptionMsg(ex);
  298. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(WebSiteSetupService), @"官網設定", @"Delete(官網設定(刪除))", @"", @"", @"");
  299. }
  300. finally
  301. {
  302. if (null != sMsg)
  303. {
  304. rm = new ErrorResponseMessage(sMsg, i_crm);
  305. }
  306. }
  307. return rm;
  308. }
  309. #endregion 官網設定(刪除)
  310. #region 官網設定(更新排序)
  311. /// <summary>
  312. /// 官網設定(更新排序)
  313. /// </summary>
  314. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  315. /// <returns></returns>
  316. public ResponseMessage UpdateOrderByValue(RequestMessage i_crm)
  317. {
  318. ResponseMessage rm = null;
  319. string sMsg = null;
  320. try
  321. {
  322. rm = SugarBase.ExecTran(db =>
  323. {
  324. do
  325. {
  326. var sId = _fetchString(i_crm, @"Id");
  327. var iOldOrderByValue = _fetchInt(i_crm, @"OldOrderByValue");
  328. var iNewOrderByValue = _fetchInt(i_crm, @"NewOrderByValue");
  329. var oOrderEntity = db.Queryable<OTB_WSM_WebSiteSetting>().Single(x => x.Guid == sId);
  330. if (iNewOrderByValue > iOldOrderByValue)
  331. {
  332. var iRelUp = db.Updateable<OTB_WSM_WebSiteSetting>()
  333. .UpdateColumns(x => new OTB_WSM_WebSiteSetting { OrderByValue = x.OrderByValue - 1 })
  334. .Where(x => x.OrgID == oOrderEntity.OrgID && x.SetType == oOrderEntity.SetType && x.LangId == oOrderEntity.LangId && SqlFunc.IsNull(x.ParentId, "") == SqlFunc.IsNull(oOrderEntity.ParentId, "") && x.OrderByValue <= iNewOrderByValue && x.OrderByValue > iOldOrderByValue).ExecuteCommand();
  335. }
  336. else
  337. {
  338. var iRelDown = db.Updateable<OTB_WSM_WebSiteSetting>()
  339. .UpdateColumns(x => new OTB_WSM_WebSiteSetting { OrderByValue = x.OrderByValue + 1 })
  340. .Where(x => x.OrgID == oOrderEntity.OrgID && x.SetType == oOrderEntity.SetType && x.LangId == oOrderEntity.LangId && SqlFunc.IsNull(x.ParentId, "") == SqlFunc.IsNull(oOrderEntity.ParentId, "") && x.OrderByValue >= iNewOrderByValue && x.OrderByValue < iOldOrderByValue).ExecuteCommand();
  341. }
  342. var iRelSelf = db.Updateable(new OTB_WSM_WebSiteSetting { OrderByValue = iNewOrderByValue })
  343. .UpdateColumns(x => x.OrderByValue)
  344. .Where(x => x.Guid == sId).ExecuteCommand();
  345. rm = new SuccessResponseMessage(null, i_crm);
  346. rm.DATA.Add(BLWording.REL, iRelSelf);
  347. } while (false);
  348. return rm;
  349. });
  350. }
  351. catch (Exception ex)
  352. {
  353. sMsg = Util.GetLastExceptionMsg(ex);
  354. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(WebSiteSetupService), @"官網設定", @"UpdateOrderByValue(官網設定(更新排序))", @"", @"", @"");
  355. }
  356. finally
  357. {
  358. if (null != sMsg)
  359. {
  360. rm = new ErrorResponseMessage(sMsg, i_crm);
  361. }
  362. }
  363. return rm;
  364. }
  365. #endregion 官網設定(更新排序)
  366. }
  367. }