using AutoMapper; using Ropin.Inspection.Common.Accessor.Interface; using Ropin.Inspection.Model.Entities; using Ropin.Inspection.Model.ViewModel; using Ropin.Inspection.Repository.Interface; using Ropin.Inspection.Service.Interface; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Ropin.Inspection.Service { public class TispContentGroupItemService : ITispContentGroupItemService { private readonly ITispContentGroupItemRepository _repository; private readonly IMapper _mapper; private readonly IClaimsAccessor _claims; public TispContentGroupItemService(IClaimsAccessor claims, ITispContentGroupItemRepository repository, IMapper mapper) { _repository = repository; _mapper = mapper; _claims = claims; } public async Task CreateContentGroupItemsAsync(IEnumerable items) { foreach (var item in items) { await _repository.DeleteByGroupIdAsync(item.G_ContentGroupCode); _repository.Create(new TISP_ContentGroupItem { G_ContentGroupCode = item.G_ContentGroupCode,G_ContentCode = item.G_ContentCode }); } var result = await _repository.SaveAsync(); if (!result) { throw new Exception("创建失败"); } } public async Task> GetContentGroupItemByGroupIdAsync(Guid groupId) { return await _repository.GetContentGroupItemByGroupIdAsync(groupId); } public async Task CreateOneAsync(TispContentGroupItemViewModel viewModel) { var content = _mapper.Map(viewModel); //content.G_CreateBy = _claims.ApiUserId; //content.D_CreateOn = DateTime.Now; //content.C_Status = "1"; _repository.Create(content); var result = await _repository.SaveAsync(); if (!result) { throw new Exception("创建失败"); } } public async Task DeleteAsync(Guid id) { var content = await _repository.GetByIdAsync(id); if (content == null) { throw new Exception("没有此巡检内容分组详情"); } _repository.Delete(content); var result = await _repository.SaveAsync(); if (!result) { throw new Exception("删除失败"); } } public Task> GetAllAsync() { throw new NotImplementedException(); } public Task GetByIdAsync(Guid id) { throw new NotImplementedException(); } public Task IsExistAsync(Guid id) { throw new NotImplementedException(); } public Task UpdateOneAsync(TispContentGroupItemViewModel viewModel, params string[] fields) { throw new NotImplementedException(); } } }