Beispiel #1
0
        /// <summary>
        /// 查询用户设备下的通道
        /// </summary>
        /// <param name="customer">customerId</param>
        /// <param name="customerToken">token</param>
        /// <param name="deviceChannel">返回数据:通道</param>
        /// <returns></returns>
        public ResponseBaseDto GetChannelByCustomerId(string customerToken, ref IList <Channel> deviceChannel)
        {
            ResponseBaseDto    dto = new ResponseBaseDto();
            UserTokenCache     utc = UserTokenCache.GetInstance();
            TokenCacheProperty tcp = new TokenCacheProperty();
            int customerId         = 0;

            if (utc.IsValid(customerToken) == false)
            {
                dto.Code    = (int)CodeEnum.ServerNoToken;
                dto.Message = "用户token已失效,请重新登录后继续";
            }
            else
            {
                try
                {
                    dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                    if (dto.Code != 0)
                    {
                        return(dto);
                    }
                    else
                    {
                        //获取当前用户所有的Device
                        //区分主用户与子用户
                        Customer customer = new Customer();
                        customer.CustomerId = tcp.CustomerId;
                        customerId          = tcp.CustomerId;
                        IList <Customer> customerFlag = customerServer.SelectCustomerByCustomerId(customer);
                        if (customerFlag[0].ParentId != 0 && customerFlag[0].SignInType != 2)
                        {
                            //子账户将查询主用户的分组信息
                            customerFlag[0].CustomerId = customerFlag[0].ParentId;
                        }
                        //获取用户下的设备
                        IList <Device> customerDevice = deviceServer.SelectDeviceCustomerId(customer);
                        //获取设备下的通道
                        if (customerDevice != null && customerDevice.Count != 0)
                        {
                            List <int> deviceIdFlag = new List <int>();
                            for (int i = 0; i < customerDevice.Count; i++)
                            {
                                deviceIdFlag.Add(customerDevice[0].DeviceId);
                            }
                            deviceChannel = channelServer.SelectChannelByDeviceIdList(deviceIdFlag);
                        }
                        dto.Code    = (int)CodeEnum.Success;
                        dto.Message = "设备数据获取完成";
                    }
                }
                catch (Exception ex)
                {
                    dto.Code    = (int)CodeEnum.ApplicationErr;
                    dto.Message = "网络异常,请刷新页面后继续";
                    myLog.WarnFormat("GetChannelByCustomerId方法异常,用户Id:{0},", ex, customerId);
                }
            }
            return(dto);
        }
Beispiel #2
0
        /// <summary>
        /// 通道分页
        /// </summary>
        /// <param name="startCount">从那一条数据开始</param>
        /// <param name="requestCount">需要多少条</param>
        /// <param name="customerToken"></param>
        /// <param name="Total">返回总数据数</param>
        /// <param name="channelFlag">返回通道</param>
        /// <returns></returns>
        public ResponseBaseDto GetChannelByPage(int startCount, int requestCount,
                                                string keyWord, string customerToken,
                                                ref IList <GroupChannelResponse> groupChannelResponseFlag, ref int Total)
        {
            ResponseBaseDto    dto = new ResponseBaseDto();
            UserTokenCache     utc = UserTokenCache.GetInstance();
            TokenCacheProperty tcp = new TokenCacheProperty();

            try
            {
                if (utc.IsValid(customerToken) == false)
                {
                    dto.Code    = (int)CodeEnum.ServerNoToken;
                    dto.Message = "用户token已失效,请重新登录后继续";
                    return(dto);
                }
                dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                if (dto.Code != 0)
                {
                    return(dto);
                }
                else
                {
                    //查询当前用户下的设备
                    Customer customer = new Customer();
                    customer.CustomerId = tcp.CustomerId;
                    int primaryCustomerId = tcp.CustomerId;
                    int subCustomerId     = tcp.CustomerId;
                    if (tcp.SignInType == (int)CustomerSignInTypeEnum.SubCustomer)
                    {
                        primaryCustomerId   = tcp.ParentId;
                        customer.CustomerId = tcp.ParentId;
                    }

                    IList <Device> deviceFlag = deviceServer.SelectDeviceCustomerId(customer);
                    //查询出权限表中可以使用的设备Id
                    IList <Permission> permissionFlag = permissionServer.SelectPermissionByCustomerId(customer);
                    //当前用户下所有可以使用的设备
                    for (int i = 0; i < permissionFlag.Count; i++)
                    {
                        Permission permission = permissionFlag[i];
                        if (permission.NodeType == (int)PermissionNodeTypeEnum.Device && permission.IsEnable == 1)
                        {
                            Device device = new Device();
                            device.DeviceId = permission.NodeId;
                            IList <Device> otherDeviceFlag = deviceServer.SelectDeviceByDeviceId(device);
                            if (otherDeviceFlag != null && otherDeviceFlag.Count == 1)
                            {
                                deviceFlag.Add(otherDeviceFlag[0]);
                            }
                        }
                    }
                    string     deviceIdListStr = "";
                    List <int> deviceIdList    = new List <int>();
                    for (int j = 0; j < deviceFlag.Count; j++)
                    {
                        if (j != deviceFlag.Count - 1)
                        {
                            deviceIdListStr += deviceFlag[j].DeviceId + ",";
                        }
                        else
                        {
                            deviceIdListStr += deviceFlag[j].DeviceId.ToString();
                        }
                        deviceIdList.Add(deviceFlag[j].DeviceId);
                    }
                    startCount -= 1;
                    startCount  = startCount < 0 ? 0 : startCount;

                    IList <Channel> channelFlag = null;
                    if (tcp.SignInType == (int)CustomerSignInTypeEnum.SubCustomer)
                    {
                        //子用户登陆权限
                        if (deviceIdListStr != string.Empty && deviceIdListStr != "")
                        {
                            channelFlag = channelServer.SelectSubChannelByDeviceIdListPage(subCustomerId, deviceIdListStr, startCount, requestCount, keyWord);
                            Total       = channelServer.SelectSubChannelByDeviceIdListPageCount(subCustomerId, deviceIdListStr, keyWord);
                        }
                    }
                    else if (tcp.SignInType == (int)CustomerSignInTypeEnum.PrimaryCustomer)
                    {
                        //主用户登陆后数据
                        if (deviceIdListStr != string.Empty && deviceIdListStr != "")
                        {
                            channelFlag = channelServer.SelectChannelByDeviceIdListPage(deviceIdListStr, startCount, requestCount, keyWord);
                            Total       = channelServer.SelectChannelByDeviceIdListPageCount(deviceIdListStr, keyWord);
                        }
                    }

                    //填充 需要的 授权字段
                    groupChannelResponseFlag = ConvertGroupChannelResponse(tcp, primaryCustomerId, channelFlag);
                    dto.Code    = (int)CodeEnum.Success;
                    dto.Message = "通道数据获取完成";
                }/*end if(utc.IsValid(customerToken) == false)*/
            }
            catch (Exception ex)
            {
                dto.Code    = (int)CodeEnum.ApplicationErr;
                dto.Message = "网络异常,请刷新页面后继续";
                myLog.WarnFormat("GetChannelByPage方法异常,用户id:{0},起始条数:{1},请求条数:{2},关键字:{3}",
                                 ex, tcp.CustomerId, startCount, requestCount, keyWord);
            }
            return(dto);
        }
Beispiel #3
0
        /// <summary>
        ///  以用户Id返回所有设备
        /// </summary>
        /// <param name="customer">CustomerId</param>
        /// <param name="customerToken">token</param>
        /// <param name="deviceFlag">返回结果 设备</param>
        /// <returns></returns>
        public ResponseBaseDto GetDeviceByCustomerId(string customerToken, ref List <DeviceResponse> deviceResponseFlag)
        {
            ResponseBaseDto    dto = new ResponseBaseDto();
            UserTokenCache     utc = UserTokenCache.GetInstance();
            TokenCacheProperty tcp = new TokenCacheProperty();
            int customerId         = 0;

            try
            {
                if (utc.IsValid(customerToken) == false)
                {
                    dto.Code    = (int)CodeEnum.TokenTimeOut;
                    dto.Message = "用户token已失效,请重新登录后继续";
                    return(dto);
                }
                dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp);
                if (dto.Code != 0)
                {
                    return(dto);
                }
                else if (tcp.SignInType != (int)CustomerSignInTypeEnum.PrimaryCustomer)
                {
                    dto.Code    = (int)CodeEnum.NoUser;
                    dto.Message = "没有权限";
                    return(dto);
                }
                else
                {
                    Customer customer = new Customer();
                    customerId          = tcp.CustomerId;
                    customer.CustomerId = tcp.CustomerId;
                    List <int> authorizeDeviceIdList = new  List <int>();
                    //当前主账号下的设备
                    IList <Device> deviceFlag = deviceServer.SelectDeviceCustomerId(customer);
                    //准备返回的结果集
                    deviceResponseFlag = new List <DeviceResponse>();
                    //添加授权的设备
                    IList <Permission> permissionFlag = permissionServer.SelectPermissionByCustomerId(customer);
                    for (int j = 0; j < permissionFlag.Count; j++)
                    {
                        //判定当前用户对授权设备是否是可用的
                        if (permissionFlag[j].IsEnable == 1 && permissionFlag[j].NodeType == 1)
                        {
                            IList <Device> otherDeviceFalg =
                                deviceServer.SelectDeviceByDeviceId(new Device()
                            {
                                DeviceId = permissionFlag[j].NodeId
                            });
                            if (otherDeviceFalg != null && otherDeviceFalg.Count == 1)
                            {
                                authorizeDeviceIdList.Add(otherDeviceFalg[0].DeviceId);
                                deviceFlag.Add(otherDeviceFalg[0]);
                            }
                        }
                    }
                    Bsr.ServiceProxy.Utils.ServiceFactory serviceFactory = new ServiceProxy.Utils.ServiceFactory();
                    var seviceAddr = bllHelper.GetServerModelStr();
                    for (int i = 0; i < deviceFlag.Count; i++)
                    {
                        DeviceResponse dr = new DeviceResponse();
                        Bsr.Cloud.Model.Entities.Device device = deviceFlag[i];
                        dr.DeviceId     = device.DeviceId;
                        dr.DeviceName   = device.DeviceName;
                        dr.DeviceType   = device.DeviceType;
                        dr.SerialNumber = device.SerialNumber;
                        dr.HardwareType = device.HardwareType;
                        dr.IsAuthorize  = 0;
                        if (authorizeDeviceIdList.Contains(device.DeviceId))
                        {
                            dr.IsAuthorize = 1;
                        }
                        deviceResponseFlag.Add(dr);
                    }
                    dto.Code    = (int)CodeEnum.Success;
                    dto.Message = "设备已获取完成";
                }
            }
            catch (Exception ex)
            {
                dto.Code    = (int)CodeEnum.ApplicationErr;
                dto.Message = "网络异常,请刷新页面后继续";
                myLog.ErrorFormat("GetDeviceByCustomerId方法异常, 用户Id:{0}", ex, customerId);
            }
            return(dto);
        }