12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using EMIS.DataLogic.SystemDAL;
- using EMIS.Entities;
- using Bowin.Common.Linq;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Text;
- using EMIS.ViewModel.SystemView;
- using EMIS.DataLogic.Common.Students;
- namespace EMIS.CommonLogic.SystemServices
- {
- public class WechatMPServices : BaseServices, IWechatMPServices
- {
- public WechatMPDAL WechatMPDAL { get; set; }
- public UserDAL UserDAL { get; set; }
- public StudentsDAL StudentsDAL { get; set; }
- public List<string> GetOpenIDList(IList<Guid?> roleIDList, IList<Guid?> userIDList)
- {
- Expression<Func<Sys_Role, bool>> roleExp = (x => true);
- Expression<Func<Sys_User, bool>> userExp = (x => true);
- if (roleIDList != null && roleIDList.Count() > 0)
- {
- roleExp = roleExp.And(x => roleIDList.Contains(x.RoleID));
- }
- else
- {
- roleExp = (x => false);
- }
- if (userIDList != null && userIDList.Count() > 0)
- {
- userExp = userExp.And(x => userIDList.Contains(x.UserID));
- }
- else
- {
- userExp = (x => false);
- }
- var query = WechatMPDAL.GetOpenIDList(roleExp, userExp);
- return query.ToList();
- }
- public StudentUserView GetUserViewByOpenID(string openID)
- {
- var wechatSubscribe = WechatMPDAL.WechatSubscripbeRepository.GetSingle(x => x.OpenID == openID);
- if (wechatSubscribe == null)
- {
- return null;
- }
- return UserDAL.GetStudentUserView(x => x.UserID == wechatSubscribe.UserID, (x => true)).FirstOrDefault();
- }
- public void BindOpenID(string loginID, string openID)
- {
- var user = StudentsDAL.StudentRepository.GetSingle(x => x.Sys_User.LoginID == loginID);
- if (user == null)
- {
- return;
- }
- //防止同一个openID绑定两个用户
- UnitOfWork.Remove<CF_WechatSubscribe>(x => x.OpenID == openID);
- var subscribe = WechatMPDAL.WechatSubscripbeRepository.GetSingle(x => x.UserID == user.UserID);
- if (subscribe == null)
- {
- subscribe = new CF_WechatSubscribe();
- subscribe.WechatSubscribeID = Guid.NewGuid();
- subscribe.UserID = user.UserID;
- UnitOfWork.Add(subscribe);
- }
- subscribe.OpenID = openID;
- UnitOfWork.Commit();
- }
- public void UnBindOpenID(string openID)
- {
- UnitOfWork.Delete<CF_WechatSubscribe>(x => x.OpenID == openID);
- }
- }
- }
|