123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- using AutoMapper;
- using Ropin.Inspection.Common.Accessor.Interface;
- using Ropin.Inspection.Model.Entities;
- using Ropin.Inspection.Model.SearchModel;
- using Ropin.Inspection.Model.ViewModel;
- using Ropin.Inspection.Repository;
- using Ropin.Inspection.Repository.Interface;
- using Ropin.Inspection.Service.Interface;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Text;
- using System.Threading.Tasks;
- namespace Ropin.Inspection.Service
- {
- public class TispSpotUserService : ITispSpotUserService
- {
- private readonly ITispSpotUserRepository _repository;
- private readonly IMapper _mapper;
- private readonly IClaimsAccessor _claims;
- public TispSpotUserService(IClaimsAccessor claims, ITispSpotUserRepository repository, IMapper mapper)
- {
- _repository = repository;
- _mapper = mapper;
- _claims = claims;
- }
- public async Task CreateOneAsync(TispSpotUserViewModel viewModel)
- {
- var content = _mapper.Map<TISP_SpotUser>(viewModel);
- content.C_CreateBy = _claims.ApiUserId;
- content.D_CreateOn = DateTime.Now;
- //content.C_LastUpdatedBy = _claims.ApiUserId;
- //content.D_LastUpdatedOn = DateTime.Now;
- _repository.Create(content);
- var result = await _repository.SaveAsync();
- if (!result)
- {
- throw new Exception("创建失败");
- }
- }
- public async Task CreateSpotsUsersAsync(TispSpotUserCreateViewModel viewModel)
- {
-
- foreach (Guid spotId in viewModel.spotIdList)
- {
- await _repository.DeleteBySpotIdAsync(spotId);
- foreach (Guid userId in viewModel.userIdList)
- {
- //int iCount = await _repository.GetBySpotIdAndUserIdAsync(spotId, userId);
- //if (iCount >0)
- //{
- // continue;
- //}
- TISP_SpotUser spotUser = new TISP_SpotUser()
- {
- C_SpotCode = spotId,
- C_UserCode = userId,
- C_Remark = viewModel.C_Remark,
- C_CreateBy = _claims.ApiUserId,
- D_CreateOn = DateTime.Now,
- //C_LastUpdatedBy = _claims.ApiUserId,
- //D_LastUpdatedOn = DateTime.Now,
- //C_Status = '1',
- };
- _repository.Create(spotUser);
- }
- }
- var result = await _repository.SaveAsync();
- if (!result)
- {
- throw new Exception("创建失败");
- }
- }
- public async Task CreateSpotsUserAsync(TispSpotUserCreateViewModel viewModel)
- {
- foreach (Guid userId in viewModel.userIdList)
- {
- await _repository.DeleteByUserIdAsync(userId);
- foreach (Guid spotId in viewModel.spotIdList)
- {
- TISP_SpotUser spotUser = new TISP_SpotUser()
- {
- C_SpotCode = spotId,
- C_UserCode = userId,
- C_Remark = viewModel.C_Remark,
- C_CreateBy = _claims.ApiUserId,
- D_CreateOn = DateTime.Now,
- //C_LastUpdatedBy = _claims.ApiUserId,
- //D_LastUpdatedOn = DateTime.Now,
- //C_Status = '1',
- };
- _repository.Create(spotUser);
- }
- }
- var result = await _repository.SaveAsync();
- if (!result)
- {
- throw new Exception("创建失败");
- }
- }
- //public async Task UpdateSpotsUsersAsync(TispSpotUserCreateViewModel viewModel)
- //{
- //}
- public async Task<IEnumerable<TispSpotUsersViewModel>> GetSpotUsersAsyncByPage(int pageSize, int pageIndex)
- {
- var pagedList = await _repository.GetGroupBySpotAsyncByPage(pageSize, pageIndex);
- return pagedList;
- }
- public async Task<IEnumerable<TispSpotUsersViewModel>> GetSpotUsersAsyncByPage(TispSpotUserSearchModel searchViewModel)
- {
- var pagedList = await _repository.GetGroupBySpotAsyncByPage(searchViewModel);
- searchViewModel.TotalCount = pagedList == null ? 0 : pagedList.Totals;
- return pagedList.Rows;
- }
- 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 async Task<IEnumerable<TispSpotUserViewModel>> GetAllAsync()
- {
- var pagedList = await _repository.GetAllAsync();
- var contentDtoList = _mapper.Map<IEnumerable<TispSpotUserViewModel>>(pagedList);
- return contentDtoList.ToList();
- }
- public async Task<IEnumerable<TispSpotUserViewModel>> GetAsyncByPage(int pageSize, int pageIndex)
- {
- var pagedList = await _repository.GetAsyncByPage(pageSize, pageIndex);
- return pagedList;
- }
- public Task<IEnumerable<TispSpotUserViewModel>> GetByConditionAsync(Expression<Func<TispSpotUserViewModel, bool>> expression)
- {
- throw new NotImplementedException();
- }
- public async Task<TispSpotUserViewModel> GetByIdAsync(Guid id)
- {
- var content = await _repository.GetByIdAsync(id);
- var contentDto = _mapper.Map<TispSpotUserViewModel>(content);
- return contentDto;
- }
- public async Task<IEnumerable<TispSpotUserViewModel>> GetBySpotIdAsync(Guid spotId)
- {
- var content = await _repository.GetBySpotIdAsync(spotId);
- return content;
- }
- public async Task<IEnumerable<TispUserStoreRouteSpotViewModel>> GetByUserIdAsync(Guid userId)
- {
- var content = await _repository.GetByUserIdAsync(userId);
- return content;
- }
- public Task<bool> IsExistAsync(Guid id)
- {
- throw new NotImplementedException();
- }
- public async Task UpdateAsync(Guid id, TispSpotUserUpdateViewModel updateModel)
- {
- var content = await _repository.GetByIdAsync(id);
- if (content == null)
- {
- throw new Exception("没有此巡检点人员");
- }
- //content.C_LastUpdatedBy = _claims.ApiUserId;
- //content.D_LastUpdatedOn = DateTime.Now;
- _mapper.Map(updateModel, content, typeof(TispSpotUserUpdateViewModel), typeof(TISP_SpotContent));
- _repository.Update(content);
- var result = await _repository.SaveAsync();
- if (!result)
- {
- throw new Exception("更新失败");
- }
- }
- public Task<int> UpdateOneAsync(TispSpotUserViewModel viewModel, params string[] fields)
- {
- throw new NotImplementedException();
- }
- }
- }
|