WechatMPServices.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using EMIS.DataLogic.SystemDAL;
  2. using EMIS.Entities;
  3. using Bowin.Common.Linq;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Linq.Expressions;
  8. using System.Text;
  9. using EMIS.ViewModel.SystemView;
  10. using EMIS.DataLogic.Common.Students;
  11. namespace EMIS.CommonLogic.SystemServices
  12. {
  13. public class WechatMPServices : BaseServices, IWechatMPServices
  14. {
  15. public WechatMPDAL WechatMPDAL { get; set; }
  16. public UserDAL UserDAL { get; set; }
  17. public StudentsDAL StudentsDAL { get; set; }
  18. public List<string> GetOpenIDList(IList<Guid?> roleIDList, IList<Guid?> userIDList)
  19. {
  20. Expression<Func<Sys_Role, bool>> roleExp = (x => true);
  21. Expression<Func<Sys_User, bool>> userExp = (x => true);
  22. if (roleIDList != null && roleIDList.Count() > 0)
  23. {
  24. roleExp = roleExp.And(x => roleIDList.Contains(x.RoleID));
  25. }
  26. else
  27. {
  28. roleExp = (x => false);
  29. }
  30. if (userIDList != null && userIDList.Count() > 0)
  31. {
  32. userExp = userExp.And(x => userIDList.Contains(x.UserID));
  33. }
  34. else
  35. {
  36. userExp = (x => false);
  37. }
  38. var query = WechatMPDAL.GetOpenIDList(roleExp, userExp);
  39. return query.ToList();
  40. }
  41. public StudentUserView GetUserViewByOpenID(string openID)
  42. {
  43. var wechatSubscribe = WechatMPDAL.WechatSubscripbeRepository.GetSingle(x => x.OpenID == openID);
  44. if (wechatSubscribe == null)
  45. {
  46. return null;
  47. }
  48. return UserDAL.GetStudentUserView(x => x.UserID == wechatSubscribe.UserID, (x => true)).FirstOrDefault();
  49. }
  50. public void BindOpenID(string loginID, string openID)
  51. {
  52. var user = StudentsDAL.StudentRepository.GetSingle(x => x.Sys_User.LoginID == loginID);
  53. if (user == null)
  54. {
  55. return;
  56. }
  57. var subscribe = WechatMPDAL.WechatSubscripbeRepository.GetSingle(x => x.UserID == user.UserID);
  58. if (subscribe == null)
  59. {
  60. subscribe = new CF_WechatSubscribe();
  61. subscribe.WechatSubscribeID = Guid.NewGuid();
  62. subscribe.UserID = user.UserID;
  63. UnitOfWork.Add(subscribe);
  64. }
  65. subscribe.OpenID = openID;
  66. UnitOfWork.Commit();
  67. }
  68. public void UnBindOpenID(string openID)
  69. {
  70. UnitOfWork.Delete<CF_WechatSubscribe>(x => x.OpenID == openID);
  71. }
  72. }
  73. }