using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using AutoMapper; namespace IStation.Service { /// /// /// public class InspectRecord { #region 编辑 /// /// /// /// /// /// /// /// /// public Model.InspectRecordAndDetail GetOrCreateRecord(long CorpID, long ProductID, DateTime recordDay, long EmployeeID, List ContentID) { IStation.DAL.InspectRecord _dal = new IStation.DAL.InspectRecord(); var entity = _dal.GetOrCreateRecord(CorpID, ProductID, recordDay, EmployeeID, ContentID); if (entity == null) return null; var model_Record = Entity2Model(entity.Record); var mapper_InspectRecordDetail = new MapperConfiguration(cfg => cfg.CreateMap() //.ForMember(d => d.MapPosition, opt => opt.MapFrom(src => Model.Map.PointInfo.ToModel(src.MapPosition))) //.ForMember(d => d.GisPosition, opt => opt.MapFrom(src => Model.Gis.PointInfo.ToModel(src.GisPosition))) ).CreateMapper(); var models_detail = mapper_InspectRecordDetail.Map, List>(entity.Details); return new Model.InspectRecordAndDetail() { Record = model_Record, Details = models_detail }; } /// /// /// /// /// /// public bool UpdateRecord( IStation.Model.InspectRecord Record, List Details) { var mapper_InspectRecord = new MapperConfiguration(cfg => cfg.CreateMap() //.ForMember(d => d.MapPosition, opt => opt.MapFrom(src => Model.Map.PointInfo.ToModel(src.MapPosition))) //.ForMember(d => d.GisPosition, opt => opt.MapFrom(src => Model.Gis.PointInfo.ToModel(src.GisPosition))) ).CreateMapper(); var entity_Record = mapper_InspectRecord.Map(Record); var mapper_InspectRecordDetail = new MapperConfiguration(cfg => cfg.CreateMap() //.ForMember(d => d.MapPosition, opt => opt.MapFrom(src => Model.Map.PointInfo.ToModel(src.MapPosition))) //.ForMember(d => d.GisPosition, opt => opt.MapFrom(src => Model.Gis.PointInfo.ToModel(src.GisPosition))) ).CreateMapper(); var entitys_detail = mapper_InspectRecordDetail.Map, List>(Details); IStation.DAL.InspectRecord _dal = new IStation.DAL.InspectRecord(); return _dal.UpdateRecord(entity_Record, entitys_detail); } /// /// /// /// /// /// public bool UpdateRecord( IStation.Model.InspectRecord Record, List details) { if (details == null || details.Count() == 0) return false; if (Record == null) return false; var mapper_InspectRecordDetail = new MapperConfiguration(cfg => cfg.CreateMap() //.ForMember(d => d.MapPosition, opt => opt.MapFrom(src => Model.Map.PointInfo.ToModel(src.MapPosition))) //.ForMember(d => d.GisPosition, opt => opt.MapFrom(src => Model.Gis.PointInfo.ToModel(src.GisPosition))) ).CreateMapper(); var entity_details = mapper_InspectRecordDetail.Map, List>(details); foreach (var detail in entity_details) { detail.Time = DateTime.Now; } var mapper_InspectRecord = new MapperConfiguration(cfg => cfg.CreateMap() //.ForMember(d => d.MapPosition, opt => opt.MapFrom(src => Model.Map.PointInfo.ToModel(src.MapPosition))) //.ForMember(d => d.GisPosition, opt => opt.MapFrom(src => Model.Gis.PointInfo.ToModel(src.GisPosition))) ).CreateMapper(); var entity_record = mapper_InspectRecord.Map(Record); entity_record.CompleteStatus = (int)Record.CompleteStatus; IStation.DAL.InspectRecord _dal = new IStation.DAL.InspectRecord(); return _dal.UpdateRecord(entity_record, entity_details); } #endregion /// /// 某日某产品的巡检记录 /// /// /// /// public Model.InspectRecordAndDetail GetByProductID(long ProductID, DateTime recordDay) { IStation.DAL.InspectRecord _dal = new IStation.DAL.InspectRecord(); var entity = _dal.GetRecordAndDetail(ProductID, recordDay); if (entity == null) return null; var mapper_InspectRecord = new MapperConfiguration(cfg => cfg.CreateMap() //.ForMember(d => d.MapPosition, opt => opt.MapFrom(src => Model.Map.PointInfo.ToModel(src.MapPosition))) //.ForMember(d => d.GisPosition, opt => opt.MapFrom(src => Model.Gis.PointInfo.ToModel(src.GisPosition))) ).CreateMapper(); var model_Record = mapper_InspectRecord.Map(entity.Record); var mapper_InspectRecordDetail = new MapperConfiguration(cfg => cfg.CreateMap() //.ForMember(d => d.MapPosition, opt => opt.MapFrom(src => Model.Map.PointInfo.ToModel(src.MapPosition))) //.ForMember(d => d.GisPosition, opt => opt.MapFrom(src => Model.Gis.PointInfo.ToModel(src.GisPosition))) ).CreateMapper(); var models_detail = mapper_InspectRecordDetail.Map, List>(entity.Details); return new Model.InspectRecordAndDetail() { Record = model_Record, Details = models_detail }; } /// /// 某日的巡检记录 /// /// /// /// public List GetByRecordDay(long CorpID,DateTime recordDay) { IStation.DAL.InspectRecord _dal = new IStation.DAL.InspectRecord(); var entitys = _dal.GetByRecordDay(CorpID, recordDay); return Entity2Model(entitys); } /// /// 某巡检点的巡检记录 /// /// /// /// public List GetDetailByContentID(long ContentID, int Year ) { if (Year < 2022) Year = 2022; IStation.DAL.InspectRecordDetail _dal = new IStation.DAL.InspectRecordDetail(); var entitys = _dal.GetDetailByContentID(ContentID, Year); var mapper_InspectRecordDetail = new MapperConfiguration(cfg => cfg.CreateMap() //.ForMember(d => d.MapPosition, opt => opt.MapFrom(src => Model.Map.PointInfo.ToModel(src.MapPosition))) //.ForMember(d => d.GisPosition, opt => opt.MapFrom(src => Model.Gis.PointInfo.ToModel(src.GisPosition))) ).CreateMapper(); return mapper_InspectRecordDetail.Map, List>(entitys); } /// /// 某巡检点的巡检记录 /// /// /// /// /// public List GetDetailByContentID(long ContentID, DateTime StartDay,DateTime EndDay) { if (EndDay <= StartDay) return null; IStation.DAL.InspectRecordDetail _dal = new IStation.DAL.InspectRecordDetail(); var entitys = _dal.GetDetailByContentID(ContentID, StartDay, EndDay); var mapper_InspectRecordDetail = new MapperConfiguration(cfg => cfg.CreateMap() //.ForMember(d => d.MapPosition, opt => opt.MapFrom(src => Model.Map.PointInfo.ToModel(src.MapPosition))) //.ForMember(d => d.GisPosition, opt => opt.MapFrom(src => Model.Gis.PointInfo.ToModel(src.GisPosition))) ).CreateMapper(); return mapper_InspectRecordDetail.Map, List>(entitys); } /// /// 某巡检点的巡检记录 /// /// /// /// /// public List GetRecordByContentID(long ContentID, DateTime StartDay, DateTime EndDay) { if (EndDay <= StartDay) return null; IStation.DAL.InspectRecord _dal = new IStation.DAL.InspectRecord(); var entitys = _dal.GetRecordByContentID(ContentID, StartDay, EndDay); var mapper_InspectRecordDetail = new MapperConfiguration(cfg => cfg.CreateMap() //.ForMember(d => d.MapPosition, opt => opt.MapFrom(src => Model.Map.PointInfo.ToModel(src.MapPosition))) //.ForMember(d => d.GisPosition, opt => opt.MapFrom(src => Model.Gis.PointInfo.ToModel(src.GisPosition))) ).CreateMapper(); return mapper_InspectRecordDetail.Map, List>(entitys); } #region 统计 /// /// 根据月份,统计 , 某日的巡检人数 /// public List GetDayEmployeeCountByMonth(long CorpID, int Year, int Month) { var start_day = new DateTime(Year, Month, 1); var end_day = start_day.AddMonths(1).AddDays(-1); return GetDayEmployeeCountByDay(CorpID, start_day, end_day); } /// /// /// /// /// /// /// public List GetDayEmployeeCountByDay(long CorpID, DateTime start_day, DateTime end_day) { IStation.DAL.InspectRecord _dal = new IStation.DAL.InspectRecord(); var entitys = _dal.GetEmployeeStaticByDay(CorpID, start_day, end_day ); var mapper = new MapperConfiguration(cfg => cfg.CreateMap() //.ForMember(d => d.RecordDay, t => t.MapFrom(src => src.RecordDay.ToString("yyyy-MM-dd")))) ).CreateMapper(); return mapper.Map, List>(entitys); } /// /// 隐患数量统计 /// /// /// /// /// public List GetWorryCountStaticByProduct(long CorpID, DateTime start_day, DateTime end_day) { IStation.DAL.InspectRecord _dal = new IStation.DAL.InspectRecord(); var entitys = _dal.GetWorryCountStaticByProduct(CorpID, start_day.ToString("yyyy-MM-dd"), end_day.ToString("yyyy-MM-dd")); var mapper = new MapperConfiguration(cfg => cfg.CreateMap()).CreateMapper(); return mapper.Map, List>(entitys); } #endregion #region 最后一条记录(最近记录) /// /// 获取产品最后一条记录 /// /// /// public List GetProductLastRecordByCorpID(long CorpID) { IStation.DAL.InspectRecord _dal = new IStation.DAL.InspectRecord(); var list = _dal.GetProductLastRecordByCorpID(CorpID); return Entity2Model(list); } /// /// 获取产品最后一条记录 /// /// /// public List GetProductLastRecordByProductID(IEnumerable ProductID) { if (ProductID == null || ProductID.Count() == 0) return null; IStation.DAL.InspectRecord _dal = new IStation.DAL.InspectRecord(); var list = _dal.GetProductLastRecordByProductID(ProductID); return Entity2Model(list); } /// /// 获取员工最后一条记录 /// /// /// public List GetEmployeeLastRecord( long CorpID) { IStation.DAL.InspectRecord _dal = new IStation.DAL.InspectRecord(); var list = _dal.GetEmployeeLastRecord(CorpID); return Entity2Model(list); } #endregion #region 分页 /// /// 获取某产品的所有巡检记录(分页) /// /// /// /// 页码序号(从0开始) /// 每一页的条数 /// /// public List GetPageListByProductID(int PageIndex, int PageSize, long CorpID, long ProductID, out int Total) { IStation.DAL.InspectRecord _dal = new IStation.DAL.InspectRecord(); var entity_list = _dal.GetPageListByProductID(PageIndex, PageSize, CorpID, ProductID, out Total); return Entity2Model(entity_list); } /// /// 某员工的巡检记录(历史):这个同一天会有多条记录(多个产品) /// /// /// /// /// public List GetPageListByEmployeeID(int PageIndex, int PageSize, long EmployeeID ) { IStation.DAL.InspectRecord _dal = new IStation.DAL.InspectRecord(); var entity_list = _dal.GetPageListByEmployeeID(PageIndex, PageSize, EmployeeID ); if (entity_list == null || entity_list.Count() == 0) return null; var mapper = new MapperConfiguration(cfg => cfg.CreateMap() ).CreateMapper(); var models = mapper.Map, List>(entity_list); return models; } #endregion private List Entity2Model(List entities) { if (entities == null || entities.Count() < 1) return default; var mapper = new MapperConfiguration(cfg => cfg.CreateMap() //.ForMember(d => d.RecordDay , opt => opt.MapFrom(src => Model.RecordDay.ToModel(src.MapPosition))) ).CreateMapper(); var models = mapper.Map, List>(entities); return models; } private static Entity.InspectRecord Model2Entity(Model.InspectRecord model) { if (model == null) return default; var mapper = new MapperConfiguration(cfg => cfg.CreateMap() //.ForMember(d => d.RecordDay, opt => opt.MapFrom(src => src.RecordDay)) //.ForMember(d => d.GisPosition, opt => opt.MapFrom(src => Model.Gis.PointInfo.ToModel(src.GisPosition))) ).CreateMapper(); var entity = mapper.Map(model); //entity.LogType = (int)model.LogType; //entity.SoftType = (int)model.SoftType; //entity.UserType = (int)model.UserType; entity.RecordDay = DateTime.Parse( model.RecordDay ); return entity; } private Model.InspectRecord Entity2Model(Entity.InspectRecord entity) { if (entity == null) return default; var mapper = new MapperConfiguration(cfg => cfg.CreateMap() ).CreateMapper(); var model = mapper.Map(entity); return model; } } }