/// <summary> /// 更新或添加来自主机的分组信息 /// </summary> /// <param name="data">分组信息数据</param> /// <returns></returns> public OperationResult GroupControls_0x18(GroupControl_0x18_In data) { var host = HostRepository.Entities.FirstOrDefault(m => m.RegPackage == data.RegPackage); if (host == null) { return(new OperationResult(OperationResultType.QueryNull, $"注册包:{data.RegPackage}的主机信息不存在")); } else { var item = DataItemDetailRepository.Entities.FirstOrDefault(m => m.QueryCoding == "GroupType" && m.Index == 0); if (item == null) { return(new OperationResult(OperationResultType.QueryNull, $"未能查找到分组类型主键")); } var group = GroupControlRepository.TrackEntities.FirstOrDefault(m => m.ObjectId == host.Id && m.Organzie_Id == host.Organize_Id && m.GrounpNum == data.GrounpNum && m.DataItemDetail_Id == item.Id); if (group == null) { //分组信息未存在,系统帮添加信息 group = data.MapTo <GroupControl>(); group.ObjectId = host.Id; group.Organzie_Id = host.Organize_Id; group.DataItemDetail_Id = item.Id; group.GrounpName = $"HostGroups_{data.GrounpNum}"; group.CreatedTime = DateTime.Now; group.UpdateTime = DateTime.Now; return(GroupControlRepository.Insert(group) > 0 ? new OperationResult(OperationResultType.Success, $"更新主机:{data.RegPackage} 的分组:{data.GrounpNum}信息成功!") : new OperationResult(OperationResultType.NoChanged, $"更新主机:{data.RegPackage} 的分组信息未发生任何改变")); } else { group.UpdateTime = DateTime.Now; group.GroupContent = data.GroupContent; return(GroupControlRepository.Update(group) > 0 ? new OperationResult(OperationResultType.Success, $"更新主机:{data.RegPackage} 的分组:{data.GrounpNum}信息成功!") : new OperationResult(OperationResultType.NoChanged, $"更新主机:{data.RegPackage} 的分组信息未发生任何改变")); } } }
/// <summary> /// 编辑分组信息 /// </summary> /// <param name="cache">当前操作用户的缓存</param> /// <param name="datas">待编辑的数据集合</param> /// <returns></returns> public OperationResult EditGroupControls(CacheUser cache, params GroupControlInputDto[] datas) => GroupControlRepository.Update(datas, checkAction: (dto, entity) => { if (dto.DataItemDetail_Id == entity.DataItemDetail_Id && dto.GrounpNum != entity.GrounpNum) { if (GroupControlRepository.CheckExists(m => m.GrounpNum == dto.GrounpNum && m.ObjectId == dto.ObjectId && m.Organzie_Id == dto.Organzie_Id)) { throw new Exception($"id:更新数据失败,因为已经存在相同的类型数据"); } } }, updateFunc: (dto, entity) => { return(entity); });