public Result PostSmartDeviceModel([FromBody] IEnumerable <SmartDeviceModel> deviceModels) { if (deviceModels == null || !deviceModels.Any()) { return(Result.GenError <Result>(Error.ParamError)); } if (deviceModels.Any(x => x.Model.IsNullOrEmpty())) { return(Result.GenError <Result>(Error.SmartDeviceModelNotEmpty)); } if (deviceModels.GroupBy(x => x.Model).Any(y => y.Count() > 1)) { return(Result.GenError <Result>(Error.SmartDeviceModelDuplicate)); } var cId = deviceModels.FirstOrDefault()?.CategoryId ?? 0; var sames = deviceModels.Select(x => x.Model); if (SmartDeviceModelHelper.GetHaveSame(cId, sames)) { return(Result.GenError <Result>(Error.SmartDeviceModelIsExist)); } var userId = Request.GetIdentityInformation(); var markedDateTime = DateTime.Now; foreach (var model in deviceModels) { model.CreateUserId = userId; model.MarkedDateTime = markedDateTime; model.Remark = model.Remark ?? ""; } SmartDeviceModelHelper.Instance.Add(deviceModels); return(Result.GenError <Result>(Error.Success)); }
public DataResult GetSmartDeviceModel([FromQuery] int qId, int cId, int wId, bool menu) { var result = new DataResult(); result.datas.AddRange(menu ? SmartDeviceModelHelper.GetMenu(qId, cId, wId) : SmartDeviceModelHelper.GetDetail(qId, cId, wId)); if (qId != 0 && !result.datas.Any()) { result.errno = Error.SmartDeviceModelNotExist; return(result); } return(result); }
public Result PutSmartDeviceModel([FromBody] IEnumerable <SmartDeviceModel> deviceModels) { if (deviceModels == null || !deviceModels.Any()) { return(Result.GenError <Result>(Error.ParamError)); } if (deviceModels.Any(x => x.Model.IsNullOrEmpty())) { return(Result.GenError <Result>(Error.SmartDeviceModelNotEmpty)); } if (deviceModels.GroupBy(x => x.Model).Any(y => y.Count() > 1)) { return(Result.GenError <Result>(Error.SmartDeviceModelDuplicate)); } var cId = deviceModels.FirstOrDefault()?.CategoryId ?? 0; var sames = deviceModels.Select(x => x.Model); var ids = deviceModels.Select(x => x.Id); if (SmartDeviceModelHelper.GetHaveSame(cId, sames, ids)) { return(Result.GenError <Result>(Error.SmartDeviceModelIsExist)); } var oldModels = SmartDeviceModelHelper.Instance.GetByIds <SmartDeviceModel>(ids); if (oldModels.Count() != deviceModels.Count()) { return(Result.GenError <Result>(Error.SmartDeviceModelNotExist)); } var updates = new List <Tuple <int, int> >(); var markedDateTime = DateTime.Now; foreach (var model in deviceModels) { model.MarkedDateTime = markedDateTime; model.Remark = model.Remark ?? ""; var first = oldModels.FirstOrDefault(x => x.Id == model.Id); if (first != null && first.CategoryId != model.CategoryId) { updates.Add(new Tuple <int, int>(model.Id, model.CategoryId)); } } SmartDeviceModelHelper.Instance.Update(deviceModels); SmartDeviceHelper.UpdateSmartDeviceCategory(updates); return(Result.GenError <Result>(Error.Success)); }
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 }); }