lixiaojun
2022-08-03 aa5aa380cb4e3f63b2e98c5e686b69becefce332
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using AutoMapper;
using IStation.Untity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace IStation.Service
{
    public partial class MonitorHourRecord
    {
        //Entity to Model
        private Model.MonitorHourRecord Entity2Model(Entity.MonitorHourRecord entity)
        {
            if (entity == null)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.MonitorHourRecord, Model.MonitorHourRecord>()
            .ForMember(d => d.DataStatus, opt => opt.MapFrom(src => DataStatusHelper.ToList(src.DataStatus)))
            ).CreateMapper();
            var model = mapper.Map<Entity.MonitorHourRecord, Model.MonitorHourRecord>(entity);
            return model;
        }
 
        //Entities to Models
        private List<Model.MonitorHourRecord> Entity2Models(List<Entity.MonitorHourRecord> entities)
        {
            if (entities == null || entities.Count() < 1)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.MonitorHourRecord, Model.MonitorHourRecord>()
            .ForMember(d => d.DataStatus, opt => opt.MapFrom(src => DataStatusHelper.ToList(src.DataStatus)))
            ).CreateMapper();
            var models = mapper.Map<List<Entity.MonitorHourRecord>, List<Model.MonitorHourRecord>>(entities);
            return models;
        }
 
        //Model to Entity
        private Entity.MonitorHourRecord Model2Entity(Model.MonitorHourRecord model)
        {
            if (model == null)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.MonitorHourRecord, Entity.MonitorHourRecord>()
            .ForMember(d => d.DataStatus, opt => opt.MapFrom(src => DataStatusHelper.ToString(src.DataStatus)))
            ).CreateMapper();
            var entity = mapper.Map<Model.MonitorHourRecord, Entity.MonitorHourRecord>(model);
            return entity;
        }
 
        //Models to Entities
        private List<Entity.MonitorHourRecord> Model2Entities(List<Model.MonitorHourRecord> models)
        {
            if (models == null || models.Count < 1)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.MonitorHourRecord, Entity.MonitorHourRecord>()
            .ForMember(d => d.DataStatus, opt => opt.MapFrom(src => DataStatusHelper.ToString(src.DataStatus)))
            ).CreateMapper();
            var entities = mapper.Map<List<Model.MonitorHourRecord>, List<Entity.MonitorHourRecord>>(models);
            return entities;
        }
 
        //Model to Entity
        private void Model2Entity(Model.MonitorHourRecord model, Entity.MonitorHourRecord entity)
        {
            if (model == null || entity == null)
                return;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.MonitorHourRecord, Entity.MonitorHourRecord>()
            .ForMember(d => d.DataStatus, opt => opt.MapFrom(src => DataStatusHelper.ToString(src.DataStatus)))
            ).CreateMapper();
            mapper.Map(model, entity);
        }
 
        #region entity to basic content
 
        private Model.MonitorBasicRecordContent Entity2BasicContent(Entity.MonitorHourRecord entity)
        {
            if (entity == null)
                return default;
            var model = new Model.MonitorBasicRecordContent();
            model.SrcTime = entity.SrcTime;
            model.SrcValue = entity.SrcValue;
            model.DataTime = entity.DataTime;
            model.DataValue = entity.DataValue;
            model.DataStatus = DataStatusHelper.ToList(entity.DataStatus);
            return model;
        }
 
        private List<Model.MonitorBasicRecordContent> Entity2BasicContents(List<Entity.MonitorHourRecord> list)
        {
            return list?.Select(x => Entity2BasicContent(x)).ToList();
 
        }
 
        #endregion
 
    }
}