Exemple #1
0
        /// <summary>
        /// 解绑设备
        /// </summary>
        /// <param name="equipmentIds"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public virtual async Task UnbindUser(int[] equipmentIds, long userId)
        {
            var equipmentOperatorHistoryManager = Resolve <EquipmentOperatorHistoryManager>();
            var equipments = await GetListByIdsAsync(equipmentIds);

            foreach (var equipment in equipments)
            {
                var history = new EquipmentOperatorHistory()
                {
                    OperatorId              = equipment.OperatorId.Value,
                    EquipmentId             = equipment.Id,
                    EquipmentTransitionType = EquipmentTransitionType.Out
                };
                await equipmentOperatorHistoryManager.InsertAsync(history);

                equipment.OperatorId = null;
            }
        }
Exemple #2
0
        /// <summary>
        /// 绑定用户至设备
        /// </summary>
        /// <param name="equipmentId"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public virtual async Task BindUser(int[] equipmentIds, long userId)
        {
            var equipmentOperatorHistoryManager = Resolve <EquipmentOperatorHistoryManager>();
            var equipments = await GetListByIdsAsync(equipmentIds);

            foreach (var equipment in equipments)
            {
                //如果设备绑定人员就是当前人员,不做处理
                if (equipment.OperatorId != null && equipment.OperatorId.Value == userId)
                {
                    continue;
                }
                //如果设备有绑定人员
                if (equipment.OperatorId != null)
                {
                    //产生原有绑定人员的交接出记录
                    var history = new EquipmentOperatorHistory()
                    {
                        OperatorId              = equipment.OperatorId.Value,
                        EquipmentId             = equipment.Id,
                        EquipmentTransitionType = EquipmentTransitionType.Out
                    };
                    await equipmentOperatorHistoryManager.InsertAsync(history);
                }
                //如果设备没有绑定人员或者设备绑定人员与当前人员不同
                if (equipment.OperatorId == null || equipment.OperatorId != userId)
                {
                    //产生交接记录
                    var history = new EquipmentOperatorHistory()
                    {
                        OperatorId              = userId,
                        EquipmentId             = equipment.Id,
                        EquipmentTransitionType = EquipmentTransitionType.In
                    };
                    await equipmentOperatorHistoryManager.InsertAsync(history);
                }

                equipment.OperatorId = userId;
                //设置当前用户的绑定设备
                //var user = await UserManager.GetByIdAsync(userId);
                //user.SetPropertyValue("EquipmentId", equipmentId);
            }
        }