Beispiel #1
0
        /// <summary>
        /// 查询分组下(包括子分组)的所有通道 分页 GetChannelByPageOrResourceGroupId
        /// </summary>
        /// <param name="resourceGroup"></param>
        /// <param name="customerToken"></param>
        /// <param name="groupChannel"></param>
        /// <param name="Total"></param>
        /// <returns></returns>
        public ResponseBaseDto GetChannelByPageOrResourceGroupId
            (ResourceGroup resourceGroup, 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();

            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);
                    }
                    //查询当前用户的分组
                    List <int>            resourceGroupIdFlag = new List <int>();
                    IList <ResourceGroup> allResourceList     = new List <ResourceGroup>();
                    bool   isSubCustomer     = false;
                    int    primaryCustomerId = 0;
                    string deviceIdListStr   = "";
                    startCount -= 1;
                    startCount  = startCount < 0 ? 0 : startCount;
                    if (tcp.SignInType == (int)CustomerSignInTypeEnum.SubCustomer)
                    {
                        isSubCustomer     = true;
                        primaryCustomerId = tcp.ParentId;
                    }
                    else
                    {
                        isSubCustomer     = false;
                        primaryCustomerId = tcp.CustomerId;
                    }
                    //查找是否有授权的设备
                    Customer primaryCustomer = new Customer()
                    {
                        CustomerId = primaryCustomerId
                    };
                    IList <Device> primaryDeviceFlag =
                        deviceServer.SelectDeviceCustomerId(primaryCustomer);
                    //查询出权限表中可以使用的设备Id
                    IList <Permission> primaryPermissionFlag = permissionServer.SelectPermissionByCustomerId(primaryCustomer);
                    //当前用户下所有可以使用的设备
                    for (int i = 0; i < primaryPermissionFlag.Count; i++)
                    {
                        Permission permission = primaryPermissionFlag[0];
                        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)
                            {
                                primaryDeviceFlag.Add(otherDeviceFlag[0]);
                            }
                        }
                    }
                    //将设备集合对象中的设备ID修改为 21,22,33
                    for (int j = 0; j < primaryDeviceFlag.Count; j++)
                    {
                        if (j != primaryDeviceFlag.Count - 1)
                        {
                            deviceIdListStr += primaryDeviceFlag[j].DeviceId + ",";
                        }
                        else
                        {
                            deviceIdListStr += primaryDeviceFlag[j].DeviceId.ToString();
                        }
                    }
                    //如果用户的分组为0(isGroup=1,ResourceGroupId=0),将查询未分组的通道
                    if (resourceGroup != null && resourceGroup.ResourceGroupId == 0 &&
                        deviceIdListStr != string.Empty && deviceIdListStr != "")
                    {
                        IList <Channel> channelFlag = new List <Channel>();
                        GetChannelByNoGroup(primaryCustomerId, deviceIdListStr, isSubCustomer,
                                            startCount, requestCount, keyWord, ref channelFlag, ref total);
                        groupChannelResponseFlag =
                            channelBLL.ConvertGroupChannelResponse(tcp, primaryCustomerId, channelFlag);
                        dto.Code    = (int)CodeEnum.Success;
                        dto.Message = "通道获取完成!";
                        return(dto);
                    }

                    GetchildResourceGroup(resourceGroup, ref allResourceList);
                    allResourceList.Add(resourceGroup);
                    for (int i = 0; i < allResourceList.Count; i++)
                    {
                        resourceGroupIdFlag.Add(allResourceList[i].ResourceGroupId);
                    }
                    string resourceGroupIdListStr = string.Empty;
                    for (int j = 0; j < resourceGroupIdFlag.Count; j++)
                    {
                        if (j != resourceGroupIdFlag.Count - 1)
                        {
                            resourceGroupIdListStr += resourceGroupIdFlag[j] + ",";
                        }
                        else
                        {
                            resourceGroupIdListStr += resourceGroupIdFlag[j].ToString();
                        }
                    }
                    IList result = null;
                    if (isSubCustomer)
                    {
                        //子用户有权限
                        if (deviceIdListStr != string.Empty && deviceIdListStr != "")
                        {
                            result = groupChannelServer.SelectSubChannelByPageOrResourceGroupId
                                         (tcp.CustomerId, startCount, requestCount, keyWord, resourceGroupIdListStr);
                            total = groupChannelServer.SelectSubChannelByPageOrResourceGroupIdCount(tcp.CustomerId, keyWord, resourceGroupIdListStr);
                        }
                    }
                    else
                    {
                        //检索关键字,当前用户可用的组集合,当前可用设备的集合
                        //返回 List<object[]>输出时需装箱
                        if (deviceIdListStr != string.Empty && deviceIdListStr != "")
                        {
                            result = groupChannelServer.SelectChannelByPageOrResourceGroupId
                                         (startCount, requestCount, keyWord, deviceIdListStr, resourceGroupIdListStr);
                            total = groupChannelServer.SelectChannelByPageOrResourceGroupIdCount(keyWord, deviceIdListStr, resourceGroupIdListStr);
                        }
                    }
                    //通道数据装箱
                    if (result != null)
                    {
                        for (int i = 0; i < result.Count; i++)
                        {
                            object[]             data = (object[])result[i];
                            GroupChannelResponse gcr  = new GroupChannelResponse();
                            gcr.ChannelId       = (int)data[0];
                            gcr.ResourceGroupId = (int)data[1];
                            gcr.ChannelName     = (string)data[2];
                            gcr.ChannelNumber   = (int)data[3];
                            gcr.DeviceId        = (int)data[4];
                            gcr.IsEnable        = (int)data[5];
                            gcr.ImagePath       = (string)data[6];
                            groupChannelResponseFlag.Add(gcr);
                        }
                    }
                    //填充 需要的 授权字段
                    groupChannelResponseFlag = ConvertGroupChannelResponse(primaryCustomerId, groupChannelResponseFlag);
                    dto.Code    = (int)CodeEnum.Success;
                    dto.Message = "通道获取完成!";
                }
                catch (Exception ex)
                {
                    dto.Code    = (int)CodeEnum.ApplicationErr;
                    dto.Message = "网络异常,请刷新页面后继续";
                    myLog.WarnFormat("GetChannelByPageOrResourceGroupId方法异常, 组id:{0}, 起始值:{1},请求数量:{2}, 关键字:{3}",
                                     ex, resourceGroup.ResourceGroupId, startCount, requestCount, keyWord);
                }
            }
            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>
        ///  删除个设备(慎用)
        /// </summary>
        /// <param name="customer">customerId</param>
        /// <param name="DeviceId">设备本地数据库Id</param>
        /// <param name="customerToken"></param>
        /// <returns></returns>
        public ResponseBaseDto DeleteDeviceByDeviceId(Device device, string customerToken)
        {
            ResponseBaseDto    dto  = new ResponseBaseDto();
            UserTokenCache     utc  = UserTokenCache.GetInstance();
            OperaterLog        oLog = new OperaterLog();
            TokenCacheProperty tcp  = new TokenCacheProperty();

            oLog.Action = "删除设备";
            try
            {
                //获取 判定token
                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)
                {
                    oLog.TargetType = (int)OperaterLogEnum.Device;
                    oLog.Result     = dto.Code;
                    oLog.Remarks    = dto.Message;
                    bllHelper.AddOperaterLog(oLog, tcp);
                    return(dto);
                }
                else
                {
                    //查询本地的deviceId
                    IList <Device> deviceFlag = deviceServer.SelectDeviceByDeviceId(device);
                    if (deviceFlag == null || deviceFlag.Count <= 0)
                    {
                        dto.Code    = (int)CodeEnum.NoHardWare;
                        dto.Message = "删除时没有检索到需要的设备";
                    }
                    else if (deviceFlag[0].CustomerId != tcp.CustomerId)
                    {
                        dto.Code    = (int)CodeEnum.NoAuthorization;
                        dto.Message = "删除时用户没有拥有对此设备权限";
                    }
                    else
                    {
                        oLog.TargetId = deviceFlag[0].DeviceId;
                        bool bFlag = ClearDevice(deviceFlag[0]);
                        if (bFlag)
                        {
                            dto.Code    = (int)CodeEnum.Success;
                            dto.Message = "用户删除设备 " + deviceFlag[0].DeviceName + " 完成!";
                        }
                        else //if(bFlag==false)
                        {
                            dto.Code    = (int)CodeEnum.ServerNoToken;
                            dto.Message = "删除设备设备失败!";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                dto.Code    = (int)CodeEnum.ApplicationErr;
                dto.Message = "网络异常,请刷新页面后操作";
                myLog.ErrorFormat("DeleteDeviceByDeviceId方法异常, 设备id:{0}", ex, device.DeviceId);
            }
            oLog.TargetType = (int)OperaterLogEnum.Device;
            oLog.Result     = dto.Code;
            oLog.Remarks    = dto.Message;
            bllHelper.AddOperaterLog(oLog, tcp);
            return(dto);
        }