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