Esempio n. 1
0
 /// <summary>
 /// 编辑分控信息
 /// </summary>
 /// <param name="cache">当前操作用户的缓存</param>
 /// <param name="datas">待编辑的数据集合</param>
 /// <returns></returns>
 public OperationResult EditSubControls(CacheUser cache, params SubControlInputDto[] datas) => SubControlRepository.Update(datas,
                                                                                                                           checkAction: (dto, entity) =>
 {
     if (dto.SubNum != entity.SubNum)
     {
         if (SubControlRepository.CheckExists(m => m.SubNum == dto.SubNum && m.LigthPoleOne_Id == dto.LigthPoleOne_Id))
         {
             throw new Exception($"id:分控编号{dto.SubNum}已经存在!不能在同一台主机上添加相同的分控编号");
         }
     }
 },
                                                                                                                           updateFunc: (dto, entity) =>
 {
     var aggregation = SubAggregationRepository.Entities.FirstOrDefault(m => m.SubControl_Id == entity.Id);
     if (aggregation.LightPole_Id != entity.LigthPoleOne_Id)
     {
         var poleone = LightPoleRepository.Entities.FirstOrDefault(m => m.Id == entity.LigthPoleOne_Id);
         if (poleone == null)
         {
             throw new Exception("id:分控关联的灯杆不存在");
         }
         aggregation.LightPole_Id = entity.LigthPoleOne_Id;
         aggregation.Host_Id      = poleone.Host_Id;
         aggregation.Organzie_Id  = poleone.HostOne.Organize_Id;
         SubAggregationRepository.Update(aggregation);
     }
     return(entity);
 });
Esempio n. 2
0
        /// <summary>
        /// 编辑分控的经纬度
        /// </summary>
        /// <param name="Id">分控主键</param>
        /// <param name="Longitude">精度</param>
        /// <param name="Latitude">纬度</param>
        /// <returns></returns>
        public OperationResult EidtSubLocation(Guid Id, double Longitude, double Latitude)
        {
            int count = 0;
            var value = SubControlRepository.TrackEntities.FirstOrDefault(m => m.Id == Id);

            if (value != null)
            {
                value.Longitude = Longitude;
                value.Latitude  = Latitude;
                count          += SubControlRepository.Update(value);
            }
            return(count > 0 ? new OperationResult(OperationResultType.Success, $"更新分控经纬度成功,影响行数{count}") :
                   new OperationResult());
        }
Esempio n. 3
0
        /// <summary>
        /// 添加分控信息
        /// </summary>
        /// <param name="cache">当前操作用户的缓存</param>
        /// <param name="datas">待添加的数据集合</param>
        /// <returns></returns>
        public OperationResult AddSubControls(CacheUser cache, params SubControlInputDto[] datas)
        {
            int count = 0;

            SubAggregationRepository.UnitOfWork.BeginTransaction();
            foreach (var data in datas)
            {
                SubControl sub = data.MapTo <SubControl>();
                sub.CreatedTime = DateTime.Now;
                var poleone = LightPoleRepository.Entities.FirstOrDefault(m => m.Id == sub.LigthPoleOne_Id);
                if (poleone == null)
                {
                    throw new Exception("id:指定灯杆信息不存在");
                }
                if (SubControlRepository.CheckExists(m => m.SubNum == data.SubNum && m.LigthPoleOne.Host_Id == poleone.Host_Id))
                {
                    throw new Exception($"id:分控编号{data.SubNum}已经存在!不能在同一台主机上添加相同的分控编号");
                }
                if (poleone == null)
                {
                    throw new Exception("id:分控关联的灯杆不存在");
                }
                SubAggregation aggregation = new SubAggregation
                {
                    CreatedTime   = DateTime.Now,
                    SubControlOne = sub,
                    LightPole_Id  = sub.LigthPoleOne_Id,
                    Host_Id       = poleone.Host_Id,
                    Organzie_Id   = poleone.HostOne.Organize_Id
                };
                count += SubAggregationRepository.Insert(aggregation);
            }
            ;
            SubAggregationRepository.UnitOfWork.Commit();
            return(count > 0 ? new OperationResult(OperationResultType.Success, $"成功添加{count/2}条数据") :
                   new OperationResult());
        }
Esempio n. 4
0
        /// <summary>
        /// 更新分控的UID
        /// </summary>
        /// <param name="_0X29_In">数据</param>
        /// <returns></returns>
        public OperationResult UpdatedHost_0x29(SubControl_0x29_In _0X29_In)
        {
            var host = HostRepository.Entities.FirstOrDefault(m => m.RegPackage == _0X29_In.RegPackage);

            if (host == null)
            {
                return(new OperationResult(OperationResultType.QueryNull, $"分控所属主机:{_0X29_In.RegPackage} 不存在!"));
            }
            else
            {
                var sub = SubControlRepository.TrackEntities.FirstOrDefault(m => m.SubNum == _0X29_In.SubNum && m.LigthPoleOne.Host_Id == host.Id);
                if (sub == null)
                {
                    return(new OperationResult(OperationResultType.QueryNull, $"主机:{_0X29_In.RegPackage} 分控:{_0X29_In.SubNum} 信息不存在"));
                }
                else
                {
                    sub.UID = _0X29_In.UID;
                    return(SubControlRepository.Update(sub) > 0 ?
                           new OperationResult(OperationResultType.Success, $"主机:{_0X29_In.RegPackage} 分控:{_0X29_In.SubNum} UID更新成功!") :
                           new OperationResult(OperationResultType.NoChanged, $"主机:{_0X29_In.RegPackage} 分控:{_0X29_In.SubNum} UID更新未发生改变!"));
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 删除分控信息
        /// </summary>
        /// <param name="cache">当前操作用户的缓存</param>
        /// <param name="datas">待删除的数据Id集合</param>
        /// <returns></returns>
        public OperationResult DeleteSubControls(CacheUser cache, params Guid[] Ids)
        {
            try
            {
                int count = 0;
                SubControlRepository.UnitOfWork.BeginTransaction();
                foreach (var id in Ids)
                {
                    count += SubControlRepository.DeleteDirect(id);

                    // 删除分控关联的能耗信息
                    var ditem = DataItemDetailRepository.Entities.FirstOrDefault(m => m.QueryCoding == "ECType" && m.Index == 1);
                    var ect   = AnnualElectricityRepository.TrackEntities.Where(m => m.ObjectId == id && m.DataItemDetail_Id == ditem.Id).ToList();
                    AnnualElectricityRepository.Delete(ect);
                }
                SubControlRepository.UnitOfWork.Commit();
                return(count > 0 ? new OperationResult(OperationResultType.Success, $"成功删除{count}条数据") :
                       new OperationResult());
            }
            catch (Exception ex)
            {
                throw new Exception($"id:出现错误:{ex.Message}");
            }
        }