コード例 #1
0
        public DataResult GetSmartCapacityList([FromQuery] int qId, int capacityId, int categoryId)
        {
            var result = new DataResult();

            result.datas.AddRange(SmartCapacityListHelper.GetDetail(qId, capacityId, categoryId));
            if (qId != 0 && !result.datas.Any())
            {
                result.errno = Error.SmartCapacityListNotExist;
                return(result);
            }
            return(result);
        }
コード例 #2
0
        public object GetSmartCapacityListInfo([FromQuery] int qId, int processId)
        {
            var result           = new DataResult();
            var deviceCategoryId = 0;
            SmartCapacityListDetail capacityList = null;

            if (qId != 0)
            {
                capacityList = SmartCapacityListHelper.GetDetail(qId);
                if (capacityList == null)
                {
                    return(Result.GenError <Result>(Error.SmartCapacityListNotExist));
                }
                var capacity = SmartCapacityHelper.Instance.Get <SmartCapacity>(capacityList.CapacityId);
                if (capacity == null)
                {
                    return(Result.GenError <Result>(Error.SmartCapacityNotExist));
                }

                deviceCategoryId = capacityList.CategoryId;
            }
            else if (processId != 0)
            {
                var process = SmartProcessCodeCategoryProcessHelper.GetDetailByProcessId(processId);
                if (process == null)
                {
                    return(Result.GenError <Result>(Error.SmartProcessCodeCategoryProcessNotExist));
                }

                capacityList = new SmartCapacityListDetail
                {
                    ProcessId = process.Id
                };
                deviceCategoryId = process.CategoryId;
            }
            else
            {
                return(Result.GenError <Result>(Error.ParamError));
            }

            capacityList.PId = SmartProcessCodeCategoryProcessHelper.Instance.Get <SmartProcessCodeCategoryProcess>(capacityList.ProcessId)?.ProcessId ?? 0;
            var actDevices = new List <SmartDeviceCapacity>();

            if (deviceCategoryId != 0)
            {
                var models  = SmartDeviceModelHelper.GetDetail(0, deviceCategoryId);
                var devices = capacityList.DeviceList;
                if (models.Any())
                {
                    var modelCount = SmartDeviceHelper.GetNormalDeviceModelCount(models.Select(x => x.Id));
                    foreach (var model in models)
                    {
                        var device = devices.FirstOrDefault(x => x.ModelId == model.Id) ?? new SmartDeviceCapacity();
                        device.Category   = model.Category;
                        device.CategoryId = model.CategoryId;
                        device.ModelId    = model.Id;
                        device.Model      = model.Model;
                        device.Count      = modelCount.FirstOrDefault(x => x.ModelId == model.Id) != null
                            ? modelCount.FirstOrDefault(x => x.ModelId == model.Id).Count : 0;

                        actDevices.Add(device);
                    }
                }
            }

            var actOperators = new List <SmartOperatorCapacity>();
            var levels       = SmartOperatorLevelHelper.Instance.GetAll <SmartOperatorLevel>().OrderBy(x => x.Order);

            if (levels.Any())
            {
                var operatorCount = SmartOperatorHelper.GetNormalOperatorCount(capacityList.ProcessId);
                var operators     = capacityList.OperatorList;
                if (levels.Any())
                {
                    foreach (var level in levels)
                    {
                        var op = operators.FirstOrDefault(x => x.LevelId == level.Id) ?? new SmartOperatorCapacity();
                        op.Level   = level.Level;
                        op.LevelId = level.Id;
                        op.Count   = operatorCount.FirstOrDefault(x => x.ProcessId == capacityList.PId && x.LevelId == op.LevelId) != null
                            ? operatorCount.FirstOrDefault(x => x.ProcessId == capacityList.PId && x.LevelId == level.Id).Count : 0;

                        actOperators.Add(op);
                    }
                }
            }

            result.datas.Add(capacityList);
            return(new
            {
                errno = 0,
                errmsg = "成功",
                Devices = actDevices,
                Operators = actOperators
            });
        }