123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297 |
- using AutoMapper;
- using Ropin.Core.Common;
- using Ropin.Inspection.Common.Accessor.Interface;
- using Ropin.Inspection.Model.Entities;
- using Ropin.Inspection.Model.SearchModel.DEV;
- using Ropin.Inspection.Model.ViewModel.DEV;
- using Ropin.Inspection.Repository.DEV.Interface;
- using Ropin.Inspection.Service.DEV.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.DEV
- {
- public class DEVCmdService: IDEVCmdService
- {
- private readonly IDevCmdRepository _repository;
- private readonly IDevInstructionRepository _InstructionRepository;
- private readonly IDevCmdInstructionRepository _CmdInstructionRepository;
- private readonly IMapper _mapper;
- private readonly IClaimsAccessor _claims;
- private readonly InspectionDbContext _sqlDBContext;
- public DEVCmdService(IClaimsAccessor claims, InspectionDbContext sqlDBContext, IDevCmdRepository repository, IMapper mapper, IDevInstructionRepository InstructionRepository, IDevCmdInstructionRepository CmdInstructionRepository)
- {
- _repository = repository;
- _mapper = mapper;
- _claims = claims;
- _sqlDBContext = sqlDBContext;
- _InstructionRepository = InstructionRepository;
- _CmdInstructionRepository = CmdInstructionRepository;
- }
- #region 命令
- //新增【命令】
- public async Task CreateOneAsync(DevCmdViewModel viewModel)
- {
- var id = Guid.NewGuid().ToString();
- var content = _mapper.Map<TDEV_Cmd>(viewModel);
- content.C_ID = id;
- content.C_CreateBy = _claims.ApiUserId.ToString();
- content.D_CreateOn = DateTime.Now;
- content.C_Creator = _claims.ApiUserName;
- content.C_Status = "1";
- _repository.Create(content);
- var result = await _repository.SaveAsync();
- if (!result)
- {
- throw new Exception("创建失败");
- }
- }
- //删除【命令】
- public async Task DeleteAsync(string id)
- {
- var content = await _repository.GetByIdAsync(id);
- if (content == null)
- {
- throw new Exception("数据库中没有此数据");
- }
- var data = await _CmdInstructionRepository.GetByConditionAsync(t => t.C_CmdCode == id);
- if (data != null && data.Count() > 0)
- {
- throw new Exception("该数据已被关联,无法删除");
- }
- _repository.Delete(content);
- var result = await _repository.SaveAsync();
- if (!result)
- {
- throw new Exception("删除失败");
- }
- }
- //修改为禁用【命令】
- public async Task DisableAsync(string id)
- {
- var content = await _repository.GetByIdAsync(id);
- if (content == null)
- {
- throw new Exception("数据库中没有此数据");
- }
- content.C_LastUpdatedBy = _claims.ApiUserId.ToString();
- content.D_LastUpdatedOn = DateTime.Now;
- content.C_Modifier = _claims.ApiUserName;
- content.C_Status = "0";
- _repository.Update(content);
- var result = await _repository.SaveAsync();
- if (!result)
- {
- throw new Exception("删除失败");
- }
- }
- //根据ID获取实体【命令】
- public async Task<DevCmdViewModel> GetByIdAsync(string id)
- {
- DevCmdSearchModel searchModel = new DevCmdSearchModel();
- searchModel.C_ID = id;
- searchModel.IsPagination = false;
- var items = await _repository.GetConditionAsync(searchModel);
- var content = items.FirstOrDefault();
- return content;
- }
- // 更新
- public async Task UpdateAsync(string code, DevCmdViewModel updateModel)
- {
- TDEV_Cmd content = await _repository.GetByIdAsync(code);
- if (content == null)
- {
- throw new Exception("没有此数据");
- }
- content.C_LastUpdatedBy = _claims.Linsence == null ? _claims.ApiUserId.ToString() : "6e864cbc-5252-11ec-8681-fa163e02b3e4";
- content.D_LastUpdatedOn = DateTime.Now;
- content.C_Modifier = _claims.ApiUserName;
- _mapper.Map(updateModel, content, typeof(DevCmdViewModel), typeof(TDEV_Cmd));
- _repository.Update(content);
- var result = await _repository.SaveAsync();
- if (!result)
- {
- throw new Exception("更新失败");
- }
- }
- public async Task<IEnumerable<DevCmdViewModel>> GetConditionAsync(DevCmdSearchModel searchModel)
- {
- var dtoList = await _repository.GetConditionAsync(searchModel);
- return dtoList;
- }
- public Task<bool> IsExistAsync(string id)
- {
- throw new NotImplementedException();
- }
- public Task<int> UpdateOneAsync(DevCmdViewModel viewModel, params string[] fields)
- {
- throw new NotImplementedException();
- }
- #endregion
- #region 指令
- //新增
- public async Task InstructionCreateOneAsync(DevInstructionViewModel viewModel)
- {
- var id = Guid.NewGuid().ToString();
- var content = _mapper.Map<TDEV_Instruction>(viewModel);
- content.C_ID = id;
- content.C_CreateBy = _claims.ApiUserId.ToString();
- content.D_CreateOn = DateTime.Now;
- content.C_Creator = _claims.ApiUserName;
- content.C_Status = "1";
- _InstructionRepository.Create(content);
- var result = await _InstructionRepository.SaveAsync();
- if (!result)
- {
- throw new Exception("创建失败");
- }
- }
- //删除
- public async Task InstructionDeleteAsync(string id,bool bol=false)
- {
- var content = await _InstructionRepository.GetByIdAsync(id);
- if (content == null)
- {
- throw new Exception("数据库中没有此数据");
- }
- if (bol)
- {
- var data = await _CmdInstructionRepository.GetByConditionAsync(t => t.C_Instruction == id);
- if (data != null&&data.Count()>0)
- {
- throw new Exception("该数据已被关联,无法删除");
- }
- else
- {
- _InstructionRepository.Delete(content);
- }
- }
- else
- {
- content.C_LastUpdatedBy = _claims.ApiUserId.ToString();
- content.D_LastUpdatedOn = DateTime.Now;
- content.C_Modifier = _claims.ApiUserName;
- content.C_Status = "0";
- _InstructionRepository.Update(content);
- }
- var result = await _InstructionRepository.SaveAsync();
- if (!result)
- {
- throw new Exception("删除失败");
- }
- }
- //根据ID获取实体
- public async Task<DevInstructionViewModel> GetInstructionByIdAsync(string id)
- {
- DevInstructionSearchModel searchModel = new DevInstructionSearchModel();
- searchModel.C_ID = id;
- searchModel.IsPagination = false;
- var items = await _InstructionRepository.GetConditionAsync(searchModel);
- var content = items.FirstOrDefault();
- return content;
- }
- // 更新
- public async Task InstructionUpdateAsync(string code, DevInstructionViewModel updateModel)
- {
- TDEV_Instruction content = await _InstructionRepository.GetByIdAsync(code);
- if (content == null)
- {
- throw new Exception("没有此数据");
- }
- content.C_LastUpdatedBy = _claims.Linsence == null ? _claims.ApiUserId.ToString() : "6e864cbc-5252-11ec-8681-fa163e02b3e4";
- content.D_LastUpdatedOn = DateTime.Now;
- content.C_Modifier = _claims.ApiUserName;
- _mapper.Map(updateModel, content, typeof(DevInstructionViewModel), typeof(TDEV_Instruction));
- _InstructionRepository.Update(content);
- var result = await _InstructionRepository.SaveAsync();
- if (!result)
- {
- throw new Exception("更新失败");
- }
- }
- public async Task<IEnumerable<DevInstructionViewModel>> GetInstructionConditionAsync(DevInstructionSearchModel searchModel)
- {
- var dtoList = await _InstructionRepository.GetConditionAsync(searchModel);
- return dtoList;
- }
- public async Task<List<DevInstructionInfo>> GetInstructionByCmdCode(DevInstructionSearchModel searchModel)
- {
- var dtoList = await _InstructionRepository.GetInstructionByCmdCode(searchModel);
- return dtoList;
- }
- #endregion
- #region 命令-指令
- //新增
- public async Task CmdInstructionCreateOneAsync(DevCmdInstructionViewModel viewModel)
- {
- var id = Guid.NewGuid().ToString();
- var content = _mapper.Map<TDEV_CmdInstruction>(viewModel);
- content.C_ID = id;
- content.C_CreateBy = _claims.ApiUserId.ToString();
- content.D_CreateOn = DateTime.Now;
- content.C_Creator = _claims.ApiUserName;
- _CmdInstructionRepository.Create(content);
- var result = await _CmdInstructionRepository.SaveAsync();
- if (!result)
- {
- throw new Exception("创建失败");
- }
- }
- //删除
- public async Task CmdInstructionDeleteAsync(string id)
- {
- var content = await _CmdInstructionRepository.GetByIdAsync(id);
- if (content == null)
- {
- throw new Exception("数据库中没有此数据");
- }
- _CmdInstructionRepository.Delete(content);
- var result = await _CmdInstructionRepository.SaveAsync();
- if (!result)
- {
- throw new Exception("删除失败");
- }
- }
- //根据ID获取实体
- public async Task<DevCmdInstructionViewModel> GetCmdInstructionByIdAsync(string id)
- {
- DevCmdInstructionSearchModel searchModel = new DevCmdInstructionSearchModel();
- searchModel.C_ID = id;
- searchModel.IsPagination = false;
- var items = await _CmdInstructionRepository.GetConditionAsync(searchModel);
- var content = items.FirstOrDefault();
- return content;
- }
- // 更新
- public async Task CmdInstructionUpdateAsync(string code, DevCmdInstructionViewModel updateModel)
- {
- TDEV_CmdInstruction content = await _CmdInstructionRepository.GetByIdAsync(code);
- if (content == null)
- {
- throw new Exception("没有此数据");
- }
- _mapper.Map(updateModel, content, typeof(DevCmdInstructionViewModel), typeof(TDEV_CmdInstruction));
- _CmdInstructionRepository.Update(content);
- var result = await _CmdInstructionRepository.SaveAsync();
- if (!result)
- {
- throw new Exception("更新失败");
- }
- }
- public async Task<IEnumerable<DevCmdInstructionViewModel>> GetCmdInstructionConditionAsync(DevCmdInstructionSearchModel searchModel)
- {
- var dtoList = await _CmdInstructionRepository.GetConditionAsync(searchModel);
- return dtoList;
- }
- #endregion
- }
- }
|