WechatMPServices.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. //防止同一个openID绑定两个用户
  58. UnitOfWork.Remove<CF_WechatSubscribe>(x => x.OpenID == openID);
  59. var subscribe = WechatMPDAL.WechatSubscripbeRepository.GetSingle(x => x.UserID == user.UserID);
  60. if (subscribe == null)
  61. {
  62. subscribe = new CF_WechatSubscribe();
  63. subscribe.WechatSubscribeID = Guid.NewGuid();
  64. subscribe.UserID = user.UserID;
  65. UnitOfWork.Add(subscribe);
  66. }
  67. subscribe.OpenID = openID;
  68. UnitOfWork.Commit();
  69. }
  70. public void UnBindOpenID(string openID)
  71. {
  72. UnitOfWork.Delete<CF_WechatSubscribe>(x => x.OpenID == openID);
  73. }
  74. }
  75. }