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.

281 lines
11 KiB

2 years ago
  1. using EasyBL.WebApi.Message;
  2. using Entity.Sugar;
  3. using SqlSugar;
  4. using SqlSugar.Base;
  5. using System;
  6. namespace EasyBL.WEBAPP.WSM
  7. {
  8. public class ModuleMaintain_UpdService : ServiceBase
  9. {
  10. #region 模組管理(單筆查詢)
  11. /// <summary>
  12. /// 模組管理(單筆查詢)
  13. /// </summary>
  14. /// <param name="i_crm"></param>
  15. /// <returns></returns>
  16. public ResponseMessage QueryOne(RequestMessage i_crm)
  17. {
  18. ResponseMessage rm = null;
  19. string sMsg = null;
  20. var db = SugarBase.GetIntance();
  21. try
  22. {
  23. do
  24. {
  25. var sModuleID = _fetchString(i_crm, @"ModuleID");
  26. var oEntity = db.Queryable<OTB_SYS_ModuleList, OTB_SYS_Members, OTB_SYS_Members>
  27. ((t1, t2, t3) =>
  28. new object[] {
  29. JoinType.Left, t1.OrgID == t2.OrgID && t1.CreateUser == t2.MemberID,
  30. JoinType.Left, t1.OrgID == t3.OrgID && t1.ModifyUser == t3.MemberID
  31. }
  32. )
  33. .Where((t1, t2, t3) => t1.OrgID == i_crm.ORIGID && t1.ModuleID == sModuleID)
  34. .Select((t1, t2, t3) => new OTB_SYS_ModuleList
  35. {
  36. ModuleID = SqlFunc.GetSelfAndAutoFill(t1.ModuleID),
  37. CreateUserName = t2.MemberName,
  38. ModifyUserName = t3.MemberName
  39. })
  40. .Single();
  41. rm = new SuccessResponseMessage(null, i_crm);
  42. rm.DATA.Add(BLWording.REL, oEntity);
  43. } while (false);
  44. }
  45. catch (Exception ex)
  46. {
  47. sMsg = Util.GetLastExceptionMsg(ex);
  48. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(ArgumentMaintain_UpdService), "", "QueryOne(模組管理(單筆查詢))", "", "", "");
  49. }
  50. finally
  51. {
  52. if (null != sMsg)
  53. {
  54. rm = new ErrorResponseMessage(sMsg, i_crm);
  55. }
  56. }
  57. return rm;
  58. }
  59. #endregion 模組管理(單筆查詢)
  60. #region 模組管理(新增)
  61. /// <summary>
  62. /// 模組管理(新增)
  63. /// </summary>
  64. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  65. /// <returns></returns>
  66. public ResponseMessage Insert(RequestMessage i_crm)
  67. {
  68. ResponseMessage rm = null;
  69. string sMsg = null;
  70. try
  71. {
  72. rm = SugarBase.ExecTran(db =>
  73. {
  74. do
  75. {
  76. var oEntity = _fetchEntity<OTB_SYS_ModuleList>(i_crm);
  77. _setEntityBase(oEntity, i_crm);
  78. oEntity.ShowTop = oEntity.ShowTop ?? false;
  79. var iOldCout = db.Queryable<OTB_SYS_ModuleList>().Count(x => x.OrgID == i_crm.ORIGID);
  80. if (oEntity.OrderByValue <= iOldCout)
  81. {
  82. var iRelUp = db.Updateable<OTB_SYS_ModuleList>()
  83. .UpdateColumns(x => new OTB_SYS_ModuleList { OrderByValue = x.OrderByValue + 1 })
  84. .Where(x => x.OrgID == i_crm.ORIGID && x.OrderByValue >= oEntity.OrderByValue)
  85. .ExecuteCommand();
  86. }
  87. var iRel = db.Insertable(oEntity).ExecuteCommand();
  88. rm = new SuccessResponseMessage(null, i_crm);
  89. rm.DATA.Add(BLWording.REL, iRel);
  90. } while (false);
  91. return rm;
  92. });
  93. }
  94. catch (Exception ex)
  95. {
  96. sMsg = Util.GetLastExceptionMsg(ex);
  97. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(ModuleMaintain_UpdService), @"模組管理", @"Add(模組管理(新增))", @"", @"", @"");
  98. }
  99. finally
  100. {
  101. if (null != sMsg)
  102. {
  103. rm = new ErrorResponseMessage(sMsg, i_crm);
  104. }
  105. }
  106. return rm;
  107. }
  108. #endregion 模組管理(新增)
  109. #region 模組管理(修改)
  110. /// <summary>
  111. /// 模組管理(修改)
  112. /// </summary>
  113. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  114. /// <returns></returns>
  115. public ResponseMessage Update(RequestMessage i_crm)
  116. {
  117. ResponseMessage rm = null;
  118. string sMsg = null;
  119. try
  120. {
  121. rm = SugarBase.ExecTran(db =>
  122. {
  123. do
  124. {
  125. var oNewEntity = _fetchEntity<OTB_SYS_ModuleList>(i_crm);
  126. _setEntityBase(oNewEntity, i_crm);
  127. oNewEntity.ShowTop = oNewEntity.ShowTop ?? false;
  128. var iOldEntity = db.Queryable<OTB_SYS_ModuleList>().Single(x => x.OrgID == i_crm.ORIGID && x.ModuleID == oNewEntity.ModuleID);
  129. if (oNewEntity.OrderByValue > iOldEntity.OrderByValue)
  130. {
  131. var iRelUp = db.Updateable<OTB_SYS_ModuleList>()
  132. .UpdateColumns(x => new OTB_SYS_ModuleList { OrderByValue = x.OrderByValue - 1 })
  133. .Where(x => x.OrgID == oNewEntity.OrgID && x.OrderByValue <= oNewEntity.OrderByValue && x.OrderByValue > iOldEntity.OrderByValue).ExecuteCommand();
  134. }
  135. else
  136. {
  137. var iRelDown = db.Updateable<OTB_SYS_ModuleList>()
  138. .UpdateColumns(x => new OTB_SYS_ModuleList { OrderByValue = x.OrderByValue + 1 })
  139. .Where(x => x.OrgID == oNewEntity.OrgID && x.OrderByValue >= oNewEntity.OrderByValue && x.OrderByValue < iOldEntity.OrderByValue).ExecuteCommand();
  140. }
  141. var iRel = db.Updateable(oNewEntity)
  142. .IgnoreColumns(x => new
  143. {
  144. x.CreateUser,
  145. x.CreateDate
  146. }).ExecuteCommand();
  147. rm = new SuccessResponseMessage(null, i_crm);
  148. rm.DATA.Add(BLWording.REL, iRel);
  149. } while (false);
  150. return rm;
  151. });
  152. }
  153. catch (Exception ex)
  154. {
  155. sMsg = Util.GetLastExceptionMsg(ex);
  156. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(ModuleMaintain_UpdService), @"模組管理", @"Update(模組管理(修改))", @"", @"", @"");
  157. }
  158. finally
  159. {
  160. if (null != sMsg)
  161. {
  162. rm = new ErrorResponseMessage(sMsg, i_crm);
  163. }
  164. }
  165. return rm;
  166. }
  167. #endregion 模組管理(修改)
  168. #region 模組管理(刪除)
  169. /// <summary>
  170. /// 模組管理(刪除)
  171. /// </summary>
  172. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  173. /// <returns></returns>
  174. public ResponseMessage Delete(RequestMessage i_crm)
  175. {
  176. ResponseMessage rm = null;
  177. string sMsg = null;
  178. try
  179. {
  180. rm = SugarBase.ExecTran(db =>
  181. {
  182. do
  183. {
  184. var sModuleID = _fetchString(i_crm, @"ModuleID");
  185. var iExsitChild = db.Queryable<OTB_SYS_ModuleForProgram>().Count(x => x.OrgID == i_crm.ORIGID && x.ModuleID == sModuleID);
  186. if (iExsitChild > 0)
  187. {
  188. sMsg = "message.ToDelPrograms";//請先刪除該模組下的程式資料
  189. break;
  190. }
  191. var oEntity = db.Queryable<OTB_SYS_ModuleList>().Single(x => x.OrgID == i_crm.ORIGID && x.ModuleID == sModuleID);
  192. var iRel = db.Deleteable<OTB_SYS_ModuleList>().Where(x => x.ModuleID == sModuleID).ExecuteCommand();
  193. var iRelUp = db.Updateable<OTB_SYS_ModuleList>()
  194. .UpdateColumns(x => new OTB_SYS_ModuleList { OrderByValue = x.OrderByValue - 1 })
  195. .Where(x => x.OrgID == oEntity.OrgID && x.OrderByValue > oEntity.OrderByValue)
  196. .ExecuteCommand();
  197. rm = new SuccessResponseMessage(null, i_crm);
  198. rm.DATA.Add(BLWording.REL, iRel);
  199. } while (false);
  200. return rm;
  201. });
  202. }
  203. catch (Exception ex)
  204. {
  205. sMsg = Util.GetLastExceptionMsg(ex);
  206. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(ModuleMaintain_UpdService), @"模組管理", @"Delete(模組管理(刪除))", @"", @"", @"");
  207. }
  208. finally
  209. {
  210. if (null != sMsg)
  211. {
  212. rm = new ErrorResponseMessage(sMsg, i_crm);
  213. }
  214. }
  215. return rm;
  216. }
  217. #endregion 模組管理(刪除)
  218. #region 模組管理(查詢筆數)
  219. /// <summary>
  220. /// 模組管理(查詢筆數)
  221. /// </summary>
  222. /// <param name="i_crm"></param>
  223. /// <returns></returns>
  224. public ResponseMessage QueryCout(RequestMessage i_crm)
  225. {
  226. ResponseMessage rm = null;
  227. string sMsg = null;
  228. var db = SugarBase.GetIntance();
  229. try
  230. {
  231. do
  232. {
  233. var sModuleID = _fetchString(i_crm, @"ModuleID");
  234. var iCout = db.Queryable<OTB_SYS_ModuleList>()
  235. .WhereIF(!string.IsNullOrEmpty(sModuleID), x => x.ModuleID == sModuleID)
  236. .Count(x => x.OrgID == i_crm.ORIGID);
  237. rm = new SuccessResponseMessage(null, i_crm);
  238. rm.DATA.Add(BLWording.REL, iCout);
  239. } while (false);
  240. }
  241. catch (Exception ex)
  242. {
  243. sMsg = Util.GetLastExceptionMsg(ex);
  244. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(ArgumentClassMaintain_UpdService), "", "QueryCout(模組管理(查詢筆數))", "", "", "");
  245. }
  246. finally
  247. {
  248. if (null != sMsg)
  249. {
  250. rm = new ErrorResponseMessage(sMsg, i_crm);
  251. }
  252. }
  253. return rm;
  254. }
  255. #endregion 模組管理(查詢筆數)
  256. }
  257. }