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.

293 lines
12 KiB

2 years ago
  1. using EasyBL.WebApi.Message;
  2. using Entity.Sugar;
  3. using Newtonsoft.Json.Linq;
  4. using SqlSugar;
  5. using SqlSugar.Base;
  6. using System;
  7. using System.Collections.Generic;
  8. namespace EasyBL.WEBAPP
  9. {
  10. public class SysComService : ServiceBase
  11. {
  12. #region 查詢系統所有功能資料
  13. /// <summary>
  14. /// 查詢系統所有功能資料
  15. /// </summary>
  16. /// <param name="i_crm"></param>
  17. /// <returns></returns>
  18. public ResponseMessage GetSysFNList(RequestMessage i_crm)
  19. {
  20. ResponseMessage rm = null;
  21. string sMsg = null;
  22. var db = SugarBase.DB;
  23. try
  24. {
  25. do
  26. {
  27. var spOrgID = new SugarParameter("@OrgID", i_crm.ORIGID);
  28. var spUserID = new SugarParameter("@UserID", i_crm.USERID);
  29. var dt = db.Ado.UseStoredProcedure().GetDataTable("OSP_Common_GetSysFnListByUserID", spOrgID, spUserID);
  30. rm = new SuccessResponseMessage(null, i_crm);
  31. rm.DATA.Add(BLWording.REL, dt);
  32. } while (false);
  33. }
  34. catch (Exception ex)
  35. {
  36. sMsg = Util.GetLastExceptionMsg(ex);
  37. LogAndSendEmail(sMsg + @"Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(SysComService), "", @"GetSysFNList(查詢系統所有功能資料)", @"", @"", @"");
  38. }
  39. finally
  40. {
  41. if (null != sMsg)
  42. {
  43. rm = new ErrorResponseMessage(sMsg, i_crm);
  44. }
  45. }
  46. return rm;
  47. }
  48. #endregion 查詢系統所有功能資料
  49. #region 查詢系統所模組
  50. /// <summary>
  51. /// 查詢系統所模組
  52. /// </summary>
  53. /// <param name="i_crm"></param>
  54. /// <returns></returns>
  55. public ResponseMessage GetModuleList(RequestMessage i_crm)
  56. {
  57. ResponseMessage rm = null;
  58. string sMsg = null;
  59. var db = SugarBase.DB;
  60. try
  61. {
  62. do
  63. {
  64. var spOrgID = new SugarParameter("@OrgID", i_crm.ORIGID);
  65. var dt = db.Ado.UseStoredProcedure().GetDataTable("OSP_Common_GetModuleList", spOrgID);
  66. rm = new SuccessResponseMessage(null, i_crm);
  67. rm.DATA.Add(BLWording.REL, dt);
  68. } while (false);
  69. }
  70. catch (Exception ex)
  71. {
  72. sMsg = Util.GetLastExceptionMsg(ex);
  73. LogAndSendEmail(sMsg + @"Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(SysComService), "", @"GetModuleList(查詢系統所模組)", @"", @"", @"");
  74. }
  75. finally
  76. {
  77. if (null != sMsg)
  78. {
  79. rm = new ErrorResponseMessage(sMsg, i_crm);
  80. }
  81. }
  82. return rm;
  83. }
  84. #endregion 查詢系統所模組
  85. #region 查詢所有有效的客戶資料
  86. /// <summary>
  87. /// 查詢所有有效的客戶資料
  88. /// </summary>
  89. /// <param name="i_crm"></param>
  90. /// <returns></returns>
  91. public ResponseMessage GetCustomerlist(RequestMessage i_crm)
  92. {
  93. ResponseMessage rm = null;
  94. string sMsg = null;
  95. var db = SugarBase.DB;
  96. try
  97. {
  98. do
  99. {
  100. var spm = new SugarParameter(@"OrgID", i_crm.ORIGID);
  101. var saCustomerlist = db.Ado.GetDataTable(@"select guid id,CustomerNO CusNO,case isnull(CustomerShotCName,'') when '' then (case CustomerCName when '' then CustomerEName else CustomerCName end) else '('+CustomerShotCName+')'+(case CustomerCName when '' then CustomerEName else CustomerCName end) end text,CustomerCName textcn,CustomerEName texteg,UniCode,Contactors,Email,Telephone,IsAudit from OTB_CRM_Customers WHERE Effective='Y' and OrgID=@OrgID order by CustomerCName desc", spm);
  102. rm = new SuccessResponseMessage(null, i_crm);
  103. rm.DATA.Add(BLWording.REL, saCustomerlist);
  104. } while (false);
  105. }
  106. catch (Exception ex)
  107. {
  108. sMsg = Util.GetLastExceptionMsg(ex);
  109. LogAndSendEmail(sMsg + @"Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(SysComService), "", @"GetCustomerlist(查詢所有有效的客戶資料)", @"", @"", @"");
  110. }
  111. finally
  112. {
  113. if (null != sMsg)
  114. {
  115. rm = new ErrorResponseMessage(sMsg, i_crm);
  116. }
  117. }
  118. return rm;
  119. }
  120. #endregion 查詢所有有效的客戶資料
  121. #region 查詢系統所有部門
  122. /// <summary>
  123. /// 查詢系統所有部門
  124. /// </summary>
  125. /// <param name="i_crm"></param>
  126. /// <returns></returns>
  127. public ResponseMessage GetDepartmentList(RequestMessage i_crm)
  128. {
  129. ResponseMessage rm = null;
  130. string sMsg = null;
  131. var db = SugarBase.DB;
  132. try
  133. {
  134. do
  135. {
  136. var sDeptID = _fetchString(i_crm, @"DeptID");
  137. var spOrgID = new SugarParameter("@OrgID", i_crm.ORIGID);
  138. var spDeptID = new SugarParameter("@DeptID", sDeptID);
  139. var dt = db.Ado.UseStoredProcedure().GetDataTable("OSP_Common_GetDepartmentList", spOrgID, spDeptID);
  140. rm = new SuccessResponseMessage(null, i_crm);
  141. rm.DATA.Add(BLWording.REL, dt);
  142. } while (false);
  143. }
  144. catch (Exception ex)
  145. {
  146. sMsg = Util.GetLastExceptionMsg(ex);
  147. LogAndSendEmail(sMsg + @"Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(SysComService), "", @"GetDepartmentList(查詢系統所有部門)", @"", @"", @"");
  148. }
  149. finally
  150. {
  151. if (null != sMsg)
  152. {
  153. rm = new ErrorResponseMessage(sMsg, i_crm);
  154. }
  155. }
  156. return rm;
  157. }
  158. #endregion 查詢系統所有部門
  159. public ResponseMessage GetDepartmentListNoVoid(RequestMessage i_crm)
  160. {
  161. ResponseMessage rm = null;
  162. string sMsg = null;
  163. var db = SugarBase.DB;
  164. try
  165. {
  166. do
  167. {
  168. var sDeptID = _fetchString(i_crm, @"DeptID");
  169. var spOrgID = new SugarParameter("@OrgID", i_crm.ORIGID);
  170. var spDeptID = new SugarParameter("@DeptID", sDeptID);
  171. var dt = db.Ado.UseStoredProcedure().GetDataTable("OSP_Common_GetDepartmentListNoVoid", spOrgID, spDeptID);
  172. rm = new SuccessResponseMessage(null, i_crm);
  173. rm.DATA.Add(BLWording.REL, dt);
  174. } while (false);
  175. }
  176. catch (Exception ex)
  177. {
  178. sMsg = Util.GetLastExceptionMsg(ex);
  179. LogAndSendEmail(sMsg + @"Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(SysComService), "", @"GetDepartmentList(查詢系統所有部門)", @"", @"", @"");
  180. }
  181. finally
  182. {
  183. if (null != sMsg)
  184. {
  185. rm = new ErrorResponseMessage(sMsg, i_crm);
  186. }
  187. }
  188. return rm;
  189. }
  190. #region 查詢系統所有人員
  191. /// <summary>
  192. /// 查詢系統所有人員
  193. /// </summary>
  194. /// <param name="i_crm"></param>
  195. /// <returns></returns>
  196. public ResponseMessage GetAllMembersByUserId(RequestMessage i_crm)
  197. {
  198. ResponseMessage rm = null;
  199. string sMsg = null;
  200. var db = SugarBase.DB;
  201. try
  202. {
  203. do
  204. {
  205. var spOrgID = new SugarParameter("@OrgID", i_crm.ORIGID);
  206. var spUserID = new SugarParameter("@UserID", i_crm.USERID);
  207. var dt = db.Ado.UseStoredProcedure().GetDataTable("OSP_Common_GetAllMemberListByUserID", spOrgID, spUserID);
  208. rm = new SuccessResponseMessage(null, i_crm);
  209. rm.DATA.Add(BLWording.REL, dt);
  210. } while (false);
  211. }
  212. catch (Exception ex)
  213. {
  214. sMsg = Util.GetLastExceptionMsg(ex);
  215. LogAndSendEmail(sMsg + @"Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(SysComService), "", @"GetAllMembersByUserId(查詢系統所有人員)", @"", @"", @"");
  216. }
  217. finally
  218. {
  219. if (null != sMsg)
  220. {
  221. rm = new ErrorResponseMessage(sMsg, i_crm);
  222. }
  223. }
  224. return rm;
  225. }
  226. #endregion 查詢系統所有人員
  227. #region 查詢個人信息
  228. /// <summary>
  229. /// 查詢個人信息
  230. /// </summary>
  231. /// <param name="i_crm"></param>
  232. /// <returns></returns>
  233. public ResponseMessage GetUserInfo(RequestMessage i_crm)
  234. {
  235. ResponseMessage rm = null;
  236. string sMsg = null;
  237. var db = SugarBase.DB;
  238. try
  239. {
  240. do
  241. {
  242. var saSpm = new List<SugarParameter>();
  243. var spm1 = new SugarParameter(@"OrgID", i_crm.ORIGID);
  244. saSpm.Add(spm1);
  245. var spm2 = new SugarParameter(@"UserID", i_crm.USERID);
  246. saSpm.Add(spm2);
  247. var saUserInfo = db.Ado.GetDataTable(@"SELECT MemberID,MemberName,Email,j.JobtitleName,m.DepartmentID,d.DepartmentName,m.Effective,CalColor,MemberPic,SysShowMode,Country,ServiceCode,Address
  248. ,(SELECT RuleID+',' FROM dbo.OTB_SYS_MembersToRule WHERE MemberID=@UserID and OrgID=@OrgID FOR XML PATH('')) AS roles,
  249. ImmediateSupervisor+','+(select ISNULL(ChiefOfDepartmentID,'') from OTB_SYS_Departments where DepartmentID=m.DepartmentID and OrgID=m.OrgID) as Supervisors,
  250. ISNULL((select MemberID+',' FROM OTB_SYS_Members where DepartmentID in (select DepartmentID from OTB_SYS_Departments where ChiefOfDepartmentID=m.MemberID and OrgID=m.OrgID) and OrgID=@OrgID for xml path('')),'') as UsersDown,
  251. ISNULL((select MemberID+',' FROM OTB_SYS_Members c where c.ImmediateSupervisor=m.MemberID and c.OrgID=m.OrgID for xml path('')),'') as UsersBranch
  252. FROM OTB_SYS_Members m
  253. inner join OTB_SYS_Jobtitle j on m.JobTitle=j.JobtitleID and m.OrgID=j.OrgID
  254. inner join OTB_SYS_Departments d on m.DepartmentID=d.DepartmentID and m.OrgID=d.OrgID
  255. WHERE MemberID=@UserID and m.OrgID=@OrgID", saSpm);
  256. rm = new SuccessResponseMessage(null, i_crm);
  257. rm.DATA.Add(BLWording.REL, saUserInfo.Rows[0]);
  258. } while (false);
  259. }
  260. catch (Exception ex)
  261. {
  262. sMsg = Util.GetLastExceptionMsg(ex);
  263. LogAndSendEmail(sMsg + @"Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(SysComService), "", @"GetUserInfo(查詢個人信息)", @"", @"", @"");
  264. }
  265. finally
  266. {
  267. if (null != sMsg)
  268. {
  269. rm = new ErrorResponseMessage(sMsg, i_crm);
  270. }
  271. }
  272. return rm;
  273. }
  274. #endregion 查詢個人信息
  275. }
  276. }