123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- using AutoMapper;
- using LinqKit;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.NodeServices;
- using Microsoft.EntityFrameworkCore;
- using Newtonsoft.Json;
- using Ropin.Core.Common;
- using Ropin.Inspection.Common;
- using Ropin.Inspection.Common.Accessor.Interface;
- using Ropin.Inspection.Common.Helper;
- using Ropin.Inspection.Model;
- using Ropin.Inspection.Model.Entities;
- using Ropin.Inspection.Repository;
- using Ropin.Inspection.Repository.Interface;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.ComponentModel.DataAnnotations;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml.Linq;
- using static System.Net.Mime.MediaTypeNames;
- namespace Ropin.Inspection.Service
- {
- public class TdevBoxDevSpotService : ITdevBoxDevSpotService
- {
- private readonly ITdevBoxDevSpotRepository _repository;
- private readonly IMapper _mapper;
- private readonly IClaimsAccessor _claims;
- private readonly InspectionDbContext _sqlDBContext;
- private readonly ITmtnDevOpsRecordRepository _tmtnDevOpsRecordRepository;
- public TdevBoxDevSpotService(ITmtnDevOpsRecordRepository tmtnDevOpsRecordRepository,IClaimsAccessor claims, InspectionDbContext sqlDBContext, ITdevBoxDevSpotRepository repository, IMapper mapper)
- {
- _repository = repository;
- _mapper = mapper;
- _claims = claims;
- _sqlDBContext = sqlDBContext;
- _tmtnDevOpsRecordRepository = tmtnDevOpsRecordRepository;
- }
- public async Task CreateOneAsync(TdevBoxDevSpotViewModel viewModel)
- {
- var item = await _repository.GetByConditionAsync(C => C.C_ChineseName == viewModel.C_ChineseName&&C.C_BoxCode==viewModel.C_BoxCode);
- if (item.FirstOrDefault() != null)
- {
- throw new Exception("中文名已被占用");
- }
- var id = Guid.NewGuid().ToString();
- var content = _mapper.Map<TDEV_BoxDevSpot>(viewModel);
- content.C_ID = id;
- content.C_CreateBy = _claims.ApiUserId;
- content.D_CreateOn = DateTime.Now;
- content.C_DevSpotCode= Guid.NewGuid().ToString();
- if (string.IsNullOrEmpty(content.C_DevSpotCode))
- {
- content.C_DevSpotCode = id;
- }
- 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("数据库中没有此数据");
- }
- content.C_LastUpdatedBy = _claims.ApiUserId;
- content.D_LastUpdatedOn = DateTime.Now;
- content.C_Status = "0";
- _repository.Update(content);
- var result = await _repository.SaveAsync();
- if (!result)
- {
- throw new Exception("删除失败");
- }
- }
- public async Task UpdateAsync(string code, TdevBoxDevSpotUpdateModel updateModel)
- {
- var items = await _repository.GetByConditionAsync(C => C.C_ID == code);
- var content = items.FirstOrDefault();
- if (content == null)
- {
- throw new Exception("没有此数据");
- }
- if (content.C_ChineseName != updateModel.C_ChineseName)
- {
- var item = await _repository.GetByConditionAsync(C => C.C_ChineseName == updateModel.C_ChineseName && C.C_BoxCode == updateModel.C_BoxCode&& C.C_ID != code);
- if (item.FirstOrDefault() != null)
- {
- throw new Exception("中文名已被占用");
- }
- }
- content.C_LastUpdatedBy = _claims.Linsence == null ? _claims.ApiUserId : Guid.Parse("6e864cbc-5252-11ec-8681-fa163e02b3e4");
- content.D_LastUpdatedOn = DateTime.Now;
- _mapper.Map(updateModel, content, typeof(TdevBoxDevSpotViewModel), typeof(TDEV_BoxDevSpot));
- _repository.Update(content);
- var result = await _repository.SaveAsync();
- if (!result)
- {
- throw new Exception("更新失败");
- }
- }
- public async Task<IEnumerable<TdevBoxDevSpotViewModel>> GetConditionAsync(TdevBoxDevSpotSearchModel searchModel)
- {
- var predicate = PredicateBuilder.New<TDEV_BoxDevSpot>(true);//查询条件,推荐后台使用这种方式灵活筛选
- #region 添加条件查询
- if (!string.IsNullOrEmpty(searchModel.C_Status))
- {
- if (searchModel.C_Status!="2")
- {
- predicate = predicate.And(i => i.C_Status.Equals(searchModel.C_Status));
- }
- }
- else
- {
- predicate = predicate.And(i => !i.C_Status.Equals("0"));
- }
- if (!string.IsNullOrEmpty(searchModel.C_ID))
- {
- predicate = predicate.And(i => i.C_ID.Equals(searchModel.C_ID));
- }
- if (!string.IsNullOrEmpty(searchModel.C_BoxCode))
- {
- predicate = predicate.And(i => i.C_BoxCode.Equals(searchModel.C_BoxCode));
- }
- if (!string.IsNullOrEmpty(searchModel.C_DevSpotCode))
- {
- predicate = predicate.And(i => i.C_DevSpotCode == searchModel.C_DevSpotCode);
- }
- if (!string.IsNullOrEmpty(searchModel.C_ChineseName))
- {
- predicate = predicate.And(i => i.C_ChineseName.Contains(searchModel.C_ChineseName));
- }
- #endregion
- var list = await _repository.GetPageAsync(predicate, "C_ChineseName,-D_CreateOn", searchModel.IsPagination, searchModel.PageIndex, searchModel.PageSize);
- searchModel.TotalCount = list.Totals;
- var dtoList = _mapper.Map<List<TDEV_BoxDevSpot>, List<TdevBoxDevSpotViewModel>>(list.Rows);
- return dtoList;
- }
- public Task<int> UpdateOneAsync(TdevBoxDevSpotViewModel viewModel, params string[] fields)
- {
- throw new NotImplementedException();
- }
- public Task<TdevBoxDevSpotViewModel> GetByIdAsync(string id)
- {
- throw new NotImplementedException();
- }
- public Task<bool> IsExistAsync(string id)
- {
- throw new NotImplementedException();
- }
- }
- }
|