| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422 | using AutoMapper;using OASystem.Domain.Dtos.Resource;using OASystem.Domain.Entities.Resource;using OASystem.Domain.ViewModels.Resource;namespace OASystem.Infrastructure.Repositories.Resource{    public class CountryFeeRepository : BaseRepository<Res_CountryFeeCost, CountryFeeCostView>    {        private readonly IMapper _mapper;        public CountryFeeRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)        {            _mapper = mapper;        }        public async Task<Res_CountryFeeCost> InfoByCountryName(string countryName)        {            if (string.IsNullOrEmpty(countryName)) return null;            return await _sqlSugar.Queryable<Res_CountryFeeCost>()                .FirstAsync(it => it.VisaCountry == countryName);        }        public async Task<JsonView> OperationCountryFeeCost(OperationCountryFeeCostDto dto)        {            var result = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "未知错误" };            var countryFeeCost = _mapper.Map<Res_CountryFeeCost>(dto);            countryFeeCost.LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");            if (dto.Status == 1)//添加            {                var exists = await _sqlSugar.Queryable<Res_CountryFeeCost>()                    .AnyAsync(x => x.IsDel == 0 &&                                   x.VisaFeeType == dto.VisaFeeType &&                                   x.VisaContinent == dto.VisaContinent &&                                   x.VisaCountry == dto.VisaCountry);                if (exists)                {                    result.Msg = "该国家已存在,请勿重复添加!";                    return result;                }                else//不存在,可添加                {                    int id = await AddAsyncReturnId(countryFeeCost);                    if (id == 0)                    {                        result.Msg = "添加失败!";                        return result;                    }                    result.Code = StatusCodes.Status200OK;                    result.Msg = "添加成功!";                }            }            else if (dto.Status == 2)//修改            {                var update = await _sqlSugar                    .Updateable(countryFeeCost)                    .IgnoreColumns(it => new { it.Id, it.DeleteUserId, it.DeleteTime, it.CreateUserId, it.CreateTime, it.IsDel })                    .Where(it => it.Id == countryFeeCost.Id)                    .ExecuteCommandAsync();                //bool res = await UpdateAsync(a => a.Id == dto.Id, a => _CountryFeeCost);                if (update < 1)                {                    result.Msg = "修改失败!";                    return result;                }                result.Code = StatusCodes.Status200OK;                result.Msg = "修改成功!";            }            else            {                result.Msg = "请传入Status参数,1添加 2修改!";            }            return result;        }        #region New        /// <summary>        /// Page List Async        /// </summary>        /// <param name="dto"></param>        /// <returns></returns>        public async Task<JsonView> PageListAsync(VisaFeeStandardListDto dto)        {            int pageIndex = dto.PageIndex <= 0 ? 1 : dto.PageIndex;            int pageSize = dto.PageSize <= 0 ? 10 : dto.PageSize;            int feeType = dto.VisaFeeType < 0 ? -1 : dto.VisaFeeType; // -1:全部 0:因公 1:因私            string countryName = dto.CountryName?.Trim() ?? string.Empty;            var query = _sqlSugar.Queryable<Res_VisaFeeStandard>()                .LeftJoin<Sys_Users>((x, y) => x.LastUpdateUserId == y.Id)                .Where((x, y) => x.IsDel == 0 && x.FeeType == feeType)                .WhereIF(!string.IsNullOrEmpty(countryName), x => x.Country.Contains(countryName) || countryName.Contains(x.Country))                .OrderByDescending((x, y) => x.LastUpdateTime)                .Select((x, y) => new VisaFeeStandardListView                {                    Id = x.Id,                    Continent = x.Continent,                    Country = x.Country,                    FeeType = x.FeeType,                    LastUpdateUserName = y.CnName,                    LastUpdateTime = x.LastUpdateTime                });            RefAsync<int> total = 0;            var pageList = await query.ToPageListAsync(pageIndex, pageSize, total);            if (!pageList.Any())            {                return new JsonView                {                    Code = StatusCodes.Status200OK,                    Data = pageList,                    Count = total,                    Msg = "暂无数据!"                };            }            var ids = pageList.Select(x => x.Id).ToList();            var detailsList = await _sqlSugar.Queryable<Res_VisaFeeStandardDetails>()                 .LeftJoin<Sys_Cities>((x, y) => x.ProvinceId == y.Id && (y.Level == 1 || y.Level == 4))                 .Where((x, y) => ids.Contains(x.ParentId) && x.IsDel == 0)                 .Select((x, y) => new VisaFeeStandardDetails                 {                     Id = x.Id,                     ParentId = x.ParentId,                     ProvinceId = x.ProvinceId,                     ProvinceName = y.Name_CN,                     VisaAddress = x.VisaAddress,                     IsVisaOnArrival = x.IsVisaOnArrival,                     IsElectronicSign = x.IsElectronicSign,                     VisaTime = x.VisaTime,                     IsVisaExemptionLarge = x.IsVisaExemptionLarge,                     LargeVisaPrice = x.LargeVisaPrice,                     LargeAgencyFee = x.LargeAgencyFee,                     IsVisaExemptionSmall = x.IsVisaExemptionSmall,                     SmallVisaPrice = x.SmallVisaPrice,                     SmallAgencyFee = x.SmallAgencyFee,                     NormExtFee = x.NormExtFee,                     UrgExtFee = x.UrgExtFee,                     IsUrgent = x.IsUrgent,                     UrgentTime = x.UrgentTime,                     UrgentPrice = x.UrgentPrice,                     UrgentPriceDesc = x.UrgentPriceDesc,                     Remark = x.Remark,                 })                 .ToListAsync();            var specifiedOrder = new List<string> { "四川", "重庆", "贵州", "云南" };            foreach (var item in pageList)            {                var provinceDetails = detailsList.Where(x => x.ParentId == item.Id).ToList();                if (provinceDetails.Any())                    provinceDetails = VisaFeeStandardDetails.SortByProvinces(provinceDetails, specifiedOrder);                item.VisaFees = provinceDetails;            }            return new JsonView            {                Code = StatusCodes.Status200OK,                Data = pageList,                Count = total,                Msg = "操作成功!"            };        }        /// <summary>        /// info Async        /// </summary>        /// <param name="id"></param>        /// <returns></returns>        public async Task<JsonView> InfoAsync(int id)        {            var view = await Query<Res_VisaFeeStandard>(x => x.Id == id)                .Select(x => new VisaFeeStandardInfoView()                {                    Id = x.Id,                    Continent = x.Continent,                    Country = x.Country,                    FeeType = x.FeeType,                })                .FirstAsync();            if (view == null)            {                return new JsonView                {                    Code = StatusCodes.Status200OK,                    Msg = "暂无数据!",                    Data = view                };            }            var detailsList = await _sqlSugar.Queryable<Res_VisaFeeStandardDetails>()                .LeftJoin<Sys_Cities>((x, y) => x.ProvinceId == y.Id && (y.Level == 1 || y.Level == 4))                .Where((x, y) => x.ParentId == view.Id && x.IsDel == 0)                .Select((x, y) => new VisaFeeStandardDetails                {                    Id = x.Id,                    ParentId = x.ParentId,                    ProvinceId = x.ProvinceId,                    ProvinceName = y.Name_CN,                    VisaAddress = x.VisaAddress,                    IsVisaOnArrival = x.IsVisaOnArrival,                    IsElectronicSign = x.IsElectronicSign,                    VisaTime = x.VisaTime,                    IsVisaExemptionLarge = x.IsVisaExemptionLarge,                    LargeVisaPrice = x.LargeVisaPrice,                    LargeAgencyFee = x.LargeAgencyFee,                    IsVisaExemptionSmall = x.IsVisaExemptionSmall,                    SmallVisaPrice = x.SmallVisaPrice,                    SmallAgencyFee = x.SmallAgencyFee,                    NormExtFee = x.NormExtFee,                    UrgExtFee = x.UrgExtFee,                    IsUrgent = x.IsUrgent,                    UrgentTime = x.UrgentTime,                    UrgentPrice = x.UrgentPrice,                    UrgentPriceDesc = x.UrgentPriceDesc,                    Remark = x.Remark,                })                .ToListAsync();            // 指定的省份顺序            var specifiedOrder = new List<string> { "四川", "重庆", "贵州", "云南" };            if (detailsList.Any())                detailsList = VisaFeeStandardDetails.SortByProvinces(detailsList, specifiedOrder);            view.VisaFees = detailsList;            return new JsonView            {                Code = StatusCodes.Status200OK,                Msg = "操作成功!",                Data = view            };        }        /// <summary>        /// Save Async        /// </summary>        /// <param name="id"></param>        /// <returns></returns>        public async Task<JsonView> SaveAsync(VisaFeeStandardSaveDto dto)        {            var now = DateTime.Now;            var standardInfo = _mapper.Map<Res_VisaFeeStandard>(dto);            standardInfo.LastUpdateTime = now;            standardInfo.LastUpdateUserId = dto.CurrUserId;            standardInfo.CreateTime = now;            standardInfo.CreateUserId = dto.CurrUserId;            // 指定的省份顺序            var specifiedOrder = new List<string> { "四川", "重庆", "贵州", "云南" };            if (dto.VisaFees.Any())                dto.VisaFees = VisaFeeStandardDetails.SortByProvinces(dto.VisaFees, specifiedOrder);            var standardDetails = _mapper.Map<List<Res_VisaFeeStandardDetails>>(dto.VisaFees);            standardDetails.ForEach(x =>            {                x.CreateUserId = dto.CurrUserId;                x.CreateTime = now;            });            _sqlSugar.BeginTran();            try            {                if (standardInfo.Id < 1) // 添加                {                    var insertId = await _sqlSugar.Insertable(standardInfo).ExecuteReturnIdentityAsync();                    if (insertId < 1)                    {                        _sqlSugar.RollbackTran();                        return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = "添加失败!" };                    }                    standardDetails.ForEach(x => x.ParentId = insertId);                    var detailsResult = await _sqlSugar.Insertable(standardDetails).ExecuteCommandAsync();                    if (detailsResult < 1)                    {                        _sqlSugar.RollbackTran();                        return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = "添加失败!" };                    }                }                else // 修改                {                    var updStatus = await _sqlSugar.Updateable(standardInfo)                        .IgnoreColumns(x => new { x.IsDel, x.CreateUserId, x.CreateTime, x.DeleteUserId, x.DeleteTime })                        .ExecuteCommandAsync();                    if (updStatus < 1)                    {                        _sqlSugar.RollbackTran();                        return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = "修改失败!" };                    }                    await _sqlSugar.Deleteable<Res_VisaFeeStandardDetails>()                        .Where(x => x.ParentId == standardInfo.Id)                        .ExecuteCommandAsync();                    standardDetails.ForEach(x => x.ParentId = standardInfo.Id);                    var detailsResult = await _sqlSugar.Insertable(standardDetails).ExecuteCommandAsync();                    if (detailsResult < 1)                    {                        _sqlSugar.RollbackTran();                        return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = "修改失败!" };                    }                }                _sqlSugar.CommitTran();                return new JsonView { Code = StatusCodes.Status200OK, Msg = "操作成功!" };            }            catch (Exception ex)            {                _sqlSugar.RollbackTran();                return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = ex.Message };            }        }        /// <summary>        /// SoftDel Async        /// </summary>        /// <param name="userId"></param>        /// <param name="id"></param>        /// <returns></returns>        public async Task<JsonView> SoftDelAsync(int userId, int id)        {            _sqlSugar.BeginTran();            try            {                var nowString = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");                // 主表软删除                var delStatus = await _sqlSugar.Updateable<Res_VisaFeeStandard>()                    .SetColumns(x => x.DeleteUserId == userId)                    .SetColumns(x => x.DeleteTime == nowString)                    .SetColumns(x => x.IsDel == 1)                    .Where(x => x.Id == id)                    .ExecuteCommandAsync();                if (delStatus < 1)                {                    _sqlSugar.RollbackTran();                    return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = "删除失败!" };                }                // 子表软删除                await _sqlSugar.Updateable<Res_VisaFeeStandardDetails>()                    .SetColumns(x => x.DeleteUserId == userId)                    .SetColumns(x => x.DeleteTime == nowString)                    .SetColumns(x => x.IsDel == 1)                    .Where(x => x.ParentId == id)                    .ExecuteCommandAsync();                _sqlSugar.CommitTran();                return new JsonView { Code = StatusCodes.Status200OK, Msg = "操作成功!" };            }            catch (Exception ex)            {                _sqlSugar.RollbackTran();                return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = ex.Message };            }        }        /// <summary>        /// 签证费用报价计算 Async        /// </summary>        /// <param name="provinceId"></param>        /// <param name="countryName"></param>        /// <returns></returns>        public async Task<JsonView> VisaFeeQuoteAsync(int provinceId, string countryName)        {            var info = await _sqlSugar.Queryable<Res_VisaFeeStandard>()                .FirstAsync(x => x.IsDel == 0 && x.Country.Contains(countryName));            if (info == null)                return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = $"{countryName} 该国家签证费用信息不存在" };            var details = await _sqlSugar.Queryable<Res_VisaFeeStandardDetails>()                .FirstAsync(x => x.IsDel == 0 && x.ParentId == info.Id && x.ProvinceId == provinceId);            if (details == null)                return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = $"{countryName} 该国家签证费用信息不存在" };            decimal largeVisaQuote = 0.00M,  // 公务签证报价                    smallVisaQuote = 0.00M,  // 公务普通签证报价                    quotePrice1 = 0.00M;     // 报价费用1            var visaFeeLabel = new StringBuilder(); //签证费用描述            // 103  重庆            // 108  贵州            // 122  四川            // 132  云南            if (provinceId == 103) //重庆            {            }            else if (provinceId == 108) //贵州            {            }            else if (provinceId == 122) //四川            {            }            else if (provinceId == 132) //云南            {            }            return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = "-" };        }        #endregion    }}
 |