349 lines
		
	
	
		
			15 KiB
		
	
	
	
		
			C#
		
	
	
			
		
		
	
	
			349 lines
		
	
	
		
			15 KiB
		
	
	
	
		
			C#
		
	
	
//--------------------------------------------------------------------
 | 
						|
//     此代码由T4模板自动生成  byzhouhang 20210918
 | 
						|
//	   生成时间 2022-03-28 16:46:23 
 | 
						|
//     对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
 | 
						|
//--------------------------------------------------------------------
 | 
						|
 | 
						|
using IRaCIS.Core.Domain.Models;
 | 
						|
using Microsoft.AspNetCore.Mvc;
 | 
						|
using IRaCIS.Core.Application.Interfaces;
 | 
						|
using IRaCIS.Core.Application.ViewModel;
 | 
						|
using Castle.Core.Internal;
 | 
						|
using IRaCIS.Core.Infra.EFCore.Dto;
 | 
						|
 | 
						|
namespace IRaCIS.Core.Application.Service 
 | 
						|
{
 | 
						|
    /// <summary>
 | 
						|
    /// FrontAuditConfigService
 | 
						|
    /// </summary>	
 | 
						|
    [ApiExplorerSettings(GroupName = "Reviewer")]
 | 
						|
    public class FrontAuditConfigService : BaseService, IFrontAuditConfigService
 | 
						|
    {
 | 
						|
 | 
						|
        private readonly IRepository<FrontAuditConfig> _frontAuditConfigRepository;
 | 
						|
 | 
						|
        public FrontAuditConfigService(IRepository<FrontAuditConfig> frontAuditConfigRepository)
 | 
						|
        {
 | 
						|
            _frontAuditConfigRepository = frontAuditConfigRepository;
 | 
						|
        }
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// 获取数据库所有表
 | 
						|
        /// </summary>
 | 
						|
        /// <returns></returns>
 | 
						|
        [HttpPost]
 | 
						|
        public async Task<List<TableList>> GetDatabaseTables()
 | 
						|
        {
 | 
						|
            return await _frontAuditConfigRepository._dbContext.GetTableList().ToListAsync();
 | 
						|
        }
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// 获取表列名
 | 
						|
        /// </summary>
 | 
						|
        /// <returns></returns>
 | 
						|
        [HttpPost]
 | 
						|
        public async Task<List<TableList>> GetTableColumn(string tableName)
 | 
						|
        {
 | 
						|
            return await _frontAuditConfigRepository._dbContext.GetTableColumn(tableName).ToListAsync();
 | 
						|
        }
 | 
						|
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// 批量添加字段
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="data">数据集</param>
 | 
						|
        /// <returns></returns>
 | 
						|
        public async Task BatchAddFrontAudit(BatchAddFrontAudit data)
 | 
						|
        {
 | 
						|
            var maxsort = await _frontAuditConfigRepository.Where(x => x.ParentId == data.ParentId).MaxAsync(x => x.Sort);
 | 
						|
 | 
						|
            List<FrontAuditConfig>  fronts=new List<FrontAuditConfig>();
 | 
						|
            foreach (var item in data.Columns)
 | 
						|
            {
 | 
						|
                maxsort++;
 | 
						|
                fronts.Add(new FrontAuditConfig()
 | 
						|
                {
 | 
						|
 | 
						|
                    Sort = maxsort,
 | 
						|
                    Code = item.Name,
 | 
						|
                    ValueCN = item.Remake,
 | 
						|
                    IsEnable = true,
 | 
						|
                    ParentId = data.ParentId
 | 
						|
                });
 | 
						|
            }
 | 
						|
 | 
						|
            await _frontAuditConfigRepository.AddRangeAsync(fronts);
 | 
						|
        }
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// 翻译稽查数据
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="dto"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        [HttpPost]
 | 
						|
        public async Task<List<string>> SetInspectionEnumValue(SetInspectionEnumValueDto dto)
 | 
						|
        {
 | 
						|
            return await _frontAuditConfigRepository.SetInspectionEnumValue(dto);
 | 
						|
        }
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// 获取子数据
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="item"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        [HttpPost]
 | 
						|
        public async Task<List<FrontAuditConfig>> GetChildrenItem(GetChildrenItem item)
 | 
						|
        {
 | 
						|
            var list =await (from data in _repository.GetQueryable<FrontAuditConfig>().Where(x => x.Identification == item.Identification)
 | 
						|
                       join childrenType in _repository.GetQueryable<FrontAuditConfig>() on data.Id equals childrenType.ParentId 
 | 
						|
                       select childrenType).OrderBy(x=>x.Sort).ToListAsync();
 | 
						|
            return list;
 | 
						|
        }
 | 
						|
         
 | 
						|
        /// <summary>
 | 
						|
        /// Cope子项数据
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="item"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        [HttpPost]
 | 
						|
        public async Task<IResponseOutput> CopyOtherToThisItem(CopyOtherToThisItem item)
 | 
						|
        {
 | 
						|
 | 
						|
            var lists = _frontAuditConfigRepository.Where(x => x.ParentId == item.AddItem).ToList();
 | 
						|
 | 
						|
            var additem = await _frontAuditConfigRepository.FirstOrDefaultAsync(x => x.Id == item.AddItem); 
 | 
						|
 | 
						|
            var alllist = _frontAuditConfigRepository.Where(x => item.DataSource.Contains(x.ParentId)).ToList().GroupBy(x => new { x.ValueCN }, (key, lst) => new FrontAuditConfig
 | 
						|
            {
 | 
						|
                Sort = lst.Select(x => x.Sort).FirstOrDefault(),
 | 
						|
                IsShowByTrialConfig= lst.Select(x => x.IsShowByTrialConfig).FirstOrDefault(),
 | 
						|
                ByTrialConfig = lst.Select(x => x.ByTrialConfig).FirstOrDefault(),
 | 
						|
                Code = lst.Max(x => x.Code),
 | 
						|
                ConfigType = lst.Select(x => x.ConfigType).FirstOrDefault(),
 | 
						|
                CreateTime = DateTime.Now,
 | 
						|
                Description = lst.Select(x => x.Description).FirstOrDefault(),
 | 
						|
                EnumList = lst.Select(x => x.EnumList).FirstOrDefault(),
 | 
						|
                IsConfig = lst.Select(x => x.IsConfig).FirstOrDefault(),
 | 
						|
                IsShowParent = lst.Select(x => x.IsShowParent).FirstOrDefault(),
 | 
						|
                ParentId = item.AddItem,
 | 
						|
                CreateUserId = _userInfo.Id,
 | 
						|
                IsEnable = lst.Select(x => x.IsEnable).FirstOrDefault(),
 | 
						|
                DictionaryKey = lst.Select(x => x.DictionaryKey).FirstOrDefault(),
 | 
						|
                EnumType = lst.Select(x => x.EnumType).FirstOrDefault(),
 | 
						|
                UpdateTime = DateTime.Now,
 | 
						|
                ValueCN = lst.Select(x => x.ValueCN).FirstOrDefault(),
 | 
						|
                Value = lst.Max(x => x.Value),
 | 
						|
                UpdateUserId = _userInfo.Id,
 | 
						|
                ChildrenTypeId= additem?.ChildrenTypeId,
 | 
						|
                ModuleTypeId = additem?.ModuleTypeId,
 | 
						|
                ObjectTypeId = additem?.ObjectTypeId,
 | 
						|
                OptTypeId = additem?.OptTypeId,
 | 
						|
                DictionaryCode = lst.Max(x => x.DictionaryCode),
 | 
						|
                DictionaryType = lst.Max(x => x.DictionaryType),
 | 
						|
                DateType = lst.Select(x => x.DateType).FirstOrDefault(),
 | 
						|
                Id =Guid.NewGuid(),
 | 
						|
            }).ToList();
 | 
						|
 | 
						|
            // 获取已存在的所有名称
 | 
						|
            var names = lists.Select(x => x.ValueCN).ToList();
 | 
						|
 | 
						|
            // 获取不存在的数据
 | 
						|
            var list = alllist.Where(x => !names.Contains(x.ValueCN)).ToList();
 | 
						|
 | 
						|
            // 获取要添加的name
 | 
						|
            var addvaluecns = list.Select(x => x.ValueCN);
 | 
						|
 | 
						|
            // 获取要修改的数据
 | 
						|
            var neewupdate = lists.Where(x => !addvaluecns.Contains(x.ValueCN));
 | 
						|
 | 
						|
            neewupdate.ForEach(x =>
 | 
						|
            {
 | 
						|
                var item = alllist.FirstOrDefault(y => y.ValueCN == x.ValueCN);
 | 
						|
                if (item != null)
 | 
						|
                { 
 | 
						|
                    x.Code=x.Code.IsNullOrEmpty()?item.Code:x.Code;
 | 
						|
                    x.Value = x.Code.IsNullOrEmpty() ? item.Value : x.Value;
 | 
						|
                    x.DictionaryType = x.DictionaryType.IsNullOrEmpty() ? item.DictionaryType : x.DictionaryType;
 | 
						|
                    x.DictionaryCode = x.DictionaryCode.IsNullOrEmpty() ? item.DictionaryCode : x.DictionaryCode;
 | 
						|
                }
 | 
						|
 | 
						|
            });
 | 
						|
 | 
						|
 | 
						|
            await  _repository.UpdateRange(neewupdate);
 | 
						|
            await  _repository.AddRangeAsync(list);
 | 
						|
            await _repository.SaveChangesAsync();
 | 
						|
 | 
						|
            return ResponseOutput.Ok();
 | 
						|
        }
 | 
						|
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// 获取Description
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="dto"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        [HttpPost]
 | 
						|
        public async Task<List<string>> GetDescriptionByModuleType(GetDescriptionByModuleTypeDto dto)
 | 
						|
        {
 | 
						|
            var result= await _frontAuditConfigRepository.Where(x=>x.ModuleTypeId== dto.ModuleType&&x.Description!=null &&x.Description!=string.Empty).Select(x=>x.Description).Distinct().ToListAsync();
 | 
						|
            return result;
 | 
						|
        }
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// 获取列表
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="iq"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        [HttpPost]
 | 
						|
        public async Task<List<FrontAuditConfigView>> GetFrontAuditConfigList(FrontAuditConfigQuery iq)
 | 
						|
        {
 | 
						|
 | 
						|
            var query = from data in _repository.GetQueryable<FrontAuditConfig>()
 | 
						|
                     join childrenType in _repository.GetQueryable<Dictionary>() on data.ChildrenTypeId equals childrenType.Id.ToString() into childrenTypetemp
 | 
						|
                     from leftchildrenType in childrenTypetemp.DefaultIfEmpty()
 | 
						|
                     join ModuleType in _repository.GetQueryable<Dictionary>() on data.ModuleTypeId equals ModuleType.Id.ToString() into ModuleTypetemp
 | 
						|
                     from leftModuleType in ModuleTypetemp.DefaultIfEmpty()
 | 
						|
                     join OptTypeId in _repository.GetQueryable<Dictionary>() on data.OptTypeId equals OptTypeId.Id.ToString() into OptTypeIdtemp
 | 
						|
                     from leftOptTypeId in OptTypeIdtemp.DefaultIfEmpty()
 | 
						|
                     join ObjectTypeId in _repository.GetQueryable<Dictionary>() on data.ObjectTypeId equals ObjectTypeId.Id.ToString() into ObjectTypeIdtemp
 | 
						|
                     from leftObjectTypeIdtemp in ObjectTypeIdtemp.DefaultIfEmpty()
 | 
						|
                     select new FrontAuditConfigView()
 | 
						|
                     {
 | 
						|
                         IsShowParent = data.IsShowParent,
 | 
						|
                         ChildrenTypeId = data.ChildrenTypeId,
 | 
						|
                         Code = data.Code,
 | 
						|
                         ConfigType = data.ConfigType,
 | 
						|
                         CreateTime = data.CreateTime,
 | 
						|
                         CreateUserId = data.CreateUserId,
 | 
						|
                         Description = data.Description,
 | 
						|
                         IsConfig = data.IsConfig,
 | 
						|
                         IsEnable = data.IsEnable,
 | 
						|
                         ModuleTypeId = data.ModuleTypeId,
 | 
						|
                         Id = data.Id,
 | 
						|
                         ParentId = data.ParentId,
 | 
						|
                         UpdateTime = data.UpdateTime,
 | 
						|
                         Value = data.Value,
 | 
						|
                         ChildrenTypeValueCN = leftchildrenType.ValueCN,
 | 
						|
                         ModuleTypeValue = leftModuleType.Value,
 | 
						|
                         ModuleTypeValueCN = leftModuleType.ValueCN,
 | 
						|
                         OptTypeId = data.OptTypeId,
 | 
						|
                         OptTypeValue = leftOptTypeId.Value,
 | 
						|
                         OptTypeValueCN = leftOptTypeId.ValueCN,
 | 
						|
                         UpdateUserId = data.UpdateUserId,
 | 
						|
                         Sort=data.Sort,
 | 
						|
                         ValueCN = data.ValueCN,
 | 
						|
                         ChildrenTypeValue = leftchildrenType.Value,
 | 
						|
                         EnumList=data.EnumList,
 | 
						|
                         DictionaryKey=data.DictionaryKey,
 | 
						|
                         EnumType=data.EnumType,
 | 
						|
                         ObjectTypeId=data.ObjectTypeId,
 | 
						|
                         ObjectTypeValue = leftObjectTypeIdtemp.Value,
 | 
						|
                         ObjectTypeValueCN = leftObjectTypeIdtemp.ValueCN,
 | 
						|
                         IsShowByTrialConfig =data.IsShowByTrialConfig,
 | 
						|
                         ByTrialConfig=data.ByTrialConfig,
 | 
						|
                         IsForwardPosition=data.IsForwardPosition,
 | 
						|
                         Identification=data.Identification,
 | 
						|
                         IsHaveReason=data.IsHaveReason,
 | 
						|
                         IsHaveSign=data.IsHaveSign,
 | 
						|
                         IsFinish=data.IsFinish,
 | 
						|
                         IsJoinPlan=data.IsJoinPlan,
 | 
						|
                         DataType=data.DataType,
 | 
						|
                         ChildDataLabel=data.ChildDataLabel,
 | 
						|
                         ChildDataValue=data.ChildDataValue,
 | 
						|
                         IsSpecialType=data.IsSpecialType,
 | 
						|
                         DateType=data.DataType,
 | 
						|
                         DictionaryCode=data.DictionaryCode,
 | 
						|
                         DictionaryType=data.DictionaryType,
 | 
						|
                         InterfaceName=data.InterfaceName,
 | 
						|
 | 
						|
                     };
 | 
						|
 | 
						|
            query = query
 | 
						|
                .WhereIf(!iq.Value.IsNullOrEmpty(), x => x.Value == iq.Value)
 | 
						|
                .WhereIf(!iq.ValueCN.IsNullOrEmpty(), x => x.ValueCN == iq.ValueCN)
 | 
						|
                .WhereIf(!iq.Description.IsNullOrEmpty(), x => x.Description == iq.Description)
 | 
						|
                .WhereIf(!iq.OptTypeId.IsNullOrEmpty(), x => x.OptTypeId == iq.OptTypeId)
 | 
						|
                .WhereIf(!iq.Code.IsNullOrEmpty(), x => x.Code == iq.Code)
 | 
						|
                .WhereIf(!iq.ChildrenTypeId.IsNullOrEmpty(), x => x.ChildrenTypeId == iq.ChildrenTypeId)
 | 
						|
                .WhereIf(!iq.ModuleTypeId.IsNullOrEmpty(), x => x.ModuleTypeId == iq.ModuleTypeId)
 | 
						|
                .WhereIf(!iq.ObjectTypeId.IsNullOrEmpty(), x => x.ObjectTypeId == iq.ObjectTypeId)
 | 
						|
                .WhereIf(!iq.ConfigType.IsNullOrEmpty(), x => x.ConfigType == iq.ConfigType);
 | 
						|
 | 
						|
            return await query.OrderBy(x=>x.Sort).ToListAsync();
 | 
						|
        }
 | 
						|
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// 修改排序
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="sortDto"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        public async Task<IResponseOutput> ChangeFrontAuditSort(ChangeFrontAuditSortDto sortDto)
 | 
						|
        {
 | 
						|
            foreach (var item in sortDto.SortData)
 | 
						|
            {
 | 
						|
                await _frontAuditConfigRepository.BatchUpdateNoTrackingAsync(x => x.Id == item.Id, x => new FrontAuditConfig
 | 
						|
                {
 | 
						|
                    Sort = item.Sort
 | 
						|
                });
 | 
						|
            }
 | 
						|
            await _frontAuditConfigRepository.SaveChangesAsync();
 | 
						|
            return ResponseOutput.Ok();
 | 
						|
        }
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// 新增或者修改
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="addOrEditFrontAuditConfig"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        public async Task<IResponseOutput> AddOrUpdateFrontAuditConfig(FrontAuditConfigAddOrEdit addOrEditFrontAuditConfig)
 | 
						|
        {
 | 
						|
            //  在此处拷贝automapper 映射
 | 
						|
 | 
						|
            //CreateMap<FrontAuditConfig, FrontAuditConfigView>();
 | 
						|
 | 
						|
            //  CreateMap< FrontAuditConfig,FrontAuditConfigAddOrEdit>().ReverseMap();
 | 
						|
 | 
						|
            if (await _frontAuditConfigRepository.AnyAsync(x =>x.Identification!=string.Empty&& x.Identification == addOrEditFrontAuditConfig.Identification && x.Id != addOrEditFrontAuditConfig.Id&&x.ConfigType=="M"&& addOrEditFrontAuditConfig.ConfigType== "M"))
 | 
						|
            {
 | 
						|
                return ResponseOutput.NotOk("标识重复");
 | 
						|
            }
 | 
						|
 | 
						|
 | 
						|
            if (await _frontAuditConfigRepository.AnyAsync(x => x.Description == addOrEditFrontAuditConfig.Description && x.Id != addOrEditFrontAuditConfig.Id && x.ConfigType == "M" && addOrEditFrontAuditConfig.ConfigType == "M"))
 | 
						|
            {
 | 
						|
                return ResponseOutput.NotOk("名称重复");
 | 
						|
            }
 | 
						|
 | 
						|
            addOrEditFrontAuditConfig.CreateTime= DateTime.Now;
 | 
						|
            addOrEditFrontAuditConfig.UpdateTime= DateTime.Now;
 | 
						|
            addOrEditFrontAuditConfig.CreateUserId = _userInfo.Id;
 | 
						|
            addOrEditFrontAuditConfig.UpdateUserId= _userInfo.Id;
 | 
						|
 | 
						|
            var entity = await _repository.InsertOrUpdateAsync<FrontAuditConfig, FrontAuditConfigAddOrEdit>(addOrEditFrontAuditConfig, true);
 | 
						|
 | 
						|
            return ResponseOutput.Ok(entity.Id.ToString());
 | 
						|
 | 
						|
        }
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// 删除
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="frontAuditConfigId"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        [HttpDelete("{frontAuditConfigId:guid}")]
 | 
						|
        public async Task<IResponseOutput> DeleteFrontAuditConfig(Guid frontAuditConfigId)
 | 
						|
        {
 | 
						|
            if (await _frontAuditConfigRepository.AnyAsync(x => x.ParentId == frontAuditConfigId))
 | 
						|
            {
 | 
						|
                return ResponseOutput.NotOk("存在子类 无法删除");
 | 
						|
            }
 | 
						|
            var success = await _repository.BatchDeleteAsync<FrontAuditConfig>(t => t.Id == frontAuditConfigId);
 | 
						|
            return ResponseOutput.Result(success);
 | 
						|
        }
 | 
						|
 | 
						|
 | 
						|
    }
 | 
						|
}
 |