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.

267 lines
10 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 Organization_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 sOrgID = _fetchString(i_crm, @"OrgID");
  26. var oEntity = db.Queryable<OTB_SYS_Organization, OTB_SYS_Members, OTB_SYS_Members>
  27. ((t1, t2, t3) =>
  28. new object[] {
  29. JoinType.Left, t1.ParentOrgID == t2.OrgID && t1.CreateUser == t2.MemberID,
  30. JoinType.Left, t1.ParentOrgID == t3.OrgID && t1.ModifyUser == t3.MemberID
  31. }
  32. )
  33. .Where((t1, t2, t3) => t1.ParentOrgID == i_crm.ORIGID && t1.OrgID == sOrgID)
  34. .Select((t1, t2, t3) => new OTB_SYS_Organization
  35. {
  36. OrgID = SqlFunc.GetSelfAndAutoFill(t1.OrgID),
  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(Organization_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 sOrgID = _fetchString(i_crm, @"OrgID");
  77. var oEntity = _fetchEntity<OTB_SYS_Organization>(i_crm);
  78. _setEntityBase(oEntity, i_crm);
  79. oEntity.OrgID = sOrgID;
  80. oEntity.ParentOrgID = i_crm.ORIGID;
  81. var iRel = db.Insertable(oEntity).ExecuteCommand();
  82. rm = new SuccessResponseMessage(null, i_crm);
  83. rm.DATA.Add(BLWording.REL, iRel);
  84. } while (false);
  85. return rm;
  86. });
  87. }
  88. catch (Exception ex)
  89. {
  90. sMsg = Util.GetLastExceptionMsg(ex);
  91. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(Organization_UpdService), @"組織管理", @"Add(組織管理(新增))", @"", @"", @"");
  92. }
  93. finally
  94. {
  95. if (null != sMsg)
  96. {
  97. rm = new ErrorResponseMessage(sMsg, i_crm);
  98. }
  99. }
  100. return rm;
  101. }
  102. #endregion 組織管理(新增)
  103. #region 組織管理(修改)
  104. /// <summary>
  105. /// 組織管理(修改)
  106. /// </summary>
  107. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  108. /// <returns></returns>
  109. public ResponseMessage Update(RequestMessage i_crm)
  110. {
  111. ResponseMessage rm = null;
  112. string sMsg = null;
  113. try
  114. {
  115. rm = SugarBase.ExecTran(db =>
  116. {
  117. do
  118. {
  119. var sOrgID = _fetchString(i_crm, @"OrgID");
  120. var oNewEntity = _fetchEntity<OTB_SYS_Organization>(i_crm);
  121. _setEntityBase(oNewEntity, i_crm);
  122. oNewEntity.OrgID = sOrgID;
  123. var iRel = db.Updateable(oNewEntity)
  124. .IgnoreColumns(x => new
  125. {
  126. x.CreateUser,
  127. x.CreateDate
  128. }).ExecuteCommand();
  129. rm = new SuccessResponseMessage(null, i_crm);
  130. rm.DATA.Add(BLWording.REL, iRel);
  131. } while (false);
  132. return rm;
  133. });
  134. }
  135. catch (Exception ex)
  136. {
  137. sMsg = Util.GetLastExceptionMsg(ex);
  138. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(Organization_UpdService), @"組織管理", @"Update(組織管理(修改))", @"", @"", @"");
  139. }
  140. finally
  141. {
  142. if (null != sMsg)
  143. {
  144. rm = new ErrorResponseMessage(sMsg, i_crm);
  145. }
  146. }
  147. return rm;
  148. }
  149. #endregion 組織管理(修改)
  150. #region 組織管理(刪除)
  151. /// <summary>
  152. /// 組織管理(刪除)
  153. /// </summary>
  154. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  155. /// <returns></returns>
  156. public ResponseMessage Delete(RequestMessage i_crm)
  157. {
  158. ResponseMessage rm = null;
  159. string sMsg = null;
  160. try
  161. {
  162. rm = SugarBase.ExecTran(db =>
  163. {
  164. do
  165. {
  166. var sOrgID = _fetchString(i_crm, @"OrgID");
  167. var oOrganization = db.Queryable<OTB_SYS_Organization>().Single(x => x.ParentOrgID == i_crm.ORIGID && x.OrgID == sOrgID);
  168. var iRel = db.Deleteable<OTB_SYS_Organization>().Where(x => x.ParentOrgID == i_crm.ORIGID && x.OrgID == sOrgID).ExecuteCommand();
  169. var fileService = new CommonService();
  170. i_crm.DATA.Add("FileID", oOrganization.LoGoId);
  171. i_crm.DATA.Add("IDType", "parent");
  172. fileService.DelFile(i_crm);
  173. i_crm.DATA["FileID"] = oOrganization.BackgroundImage;
  174. fileService.DelFile(i_crm);
  175. i_crm.DATA["FileID"] = oOrganization.WebsiteLgoId;
  176. fileService.DelFile(i_crm);
  177. i_crm.DATA["FileID"] = oOrganization.PicShowId;
  178. fileService.DelFile(i_crm);
  179. i_crm.DATA["FileID"] = oOrganization.WebsiteLgoId_CN;
  180. fileService.DelFile(i_crm);
  181. i_crm.DATA["FileID"] = oOrganization.PicShowId_CN;
  182. fileService.DelFile(i_crm);
  183. i_crm.DATA["FileID"] = oOrganization.WebsiteLgoId_EN;
  184. fileService.DelFile(i_crm);
  185. i_crm.DATA["FileID"] = oOrganization.PicShowId_EN;
  186. fileService.DelFile(i_crm);
  187. rm = new SuccessResponseMessage(null, i_crm);
  188. rm.DATA.Add(BLWording.REL, iRel);
  189. } while (false);
  190. return rm;
  191. });
  192. }
  193. catch (Exception ex)
  194. {
  195. sMsg = Util.GetLastExceptionMsg(ex);
  196. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(Organization_UpdService), @"組織管理", @"Delete(組織管理(刪除))", @"", @"", @"");
  197. }
  198. finally
  199. {
  200. if (null != sMsg)
  201. {
  202. rm = new ErrorResponseMessage(sMsg, i_crm);
  203. }
  204. }
  205. return rm;
  206. }
  207. #endregion 組織管理(刪除)
  208. #region 組織管理(查詢筆數)
  209. /// <summary>
  210. /// 組織管理(查詢筆數)
  211. /// </summary>
  212. /// <param name="i_crm"></param>
  213. /// <returns></returns>
  214. public ResponseMessage QueryCout(RequestMessage i_crm)
  215. {
  216. ResponseMessage rm = null;
  217. string sMsg = null;
  218. var db = SugarBase.GetIntance();
  219. try
  220. {
  221. do
  222. {
  223. var sOrgID = _fetchString(i_crm, @"OrgID");
  224. var iCout = db.Queryable<OTB_SYS_Organization>()
  225. .WhereIF(!string.IsNullOrEmpty(sOrgID), x => x.ParentOrgID == i_crm.ORIGID && x.OrgID == sOrgID)
  226. .Count();
  227. rm = new SuccessResponseMessage(null, i_crm);
  228. rm.DATA.Add(BLWording.REL, iCout);
  229. } while (false);
  230. }
  231. catch (Exception ex)
  232. {
  233. sMsg = Util.GetLastExceptionMsg(ex);
  234. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(Organization_UpdService), "", "QueryCout(組織管理(查詢筆數))", "", "", "");
  235. }
  236. finally
  237. {
  238. if (null != sMsg)
  239. {
  240. rm = new ErrorResponseMessage(sMsg, i_crm);
  241. }
  242. }
  243. return rm;
  244. }
  245. #endregion 組織管理(查詢筆數)
  246. }
  247. }