| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411 | using AutoMapper;using OASystem.Domain;using OASystem.Domain.Dtos.Groups;using OASystem.Domain.Entities.Groups;using OASystem.Domain.Entities.Resource;using OASystem.Domain.ViewModels.Groups;using OASystem.Infrastructure.Repositories.Resource;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace OASystem.Infrastructure.Repositories.Groups{    /// <summary>    /// 团组签证费用详情 info    /// 仓储    /// </summary>    public class VisaFeeInfoRepository:BaseRepository<Grp_VisaFeeInfo,VisaInfoView>    {        private readonly IMapper _mapper;        private Result _result;        private readonly CountryFeeRepository _countryFeeRep;        private readonly DelegationInfoRepository _groupRep;        public VisaFeeInfoRepository(SqlSugarClient sqlSugar, IMapper mapper, CountryFeeRepository countryFeeRep, DelegationInfoRepository groupRep)            : base(sqlSugar)        {            _mapper = mapper;            _result = new Result() { Code = -2,Msg = "操作失败!"};            _countryFeeRep = countryFeeRep;            _groupRep = groupRep;        }        /// <summary>        /// Init        /// </summary>        /// <param name="portType"></param>        /// <param name="diId"></param>        /// <returns></returns>        public async Task<Result> _Init()        {            var data = await _sqlSugar.Queryable<Res_CountryFeeCost>().Where(it => it.IsDel == 0).ToListAsync();            _result.Code = 0;            _result.Data = data;            _result.Msg = "操作成功!";            return _result;        }        /// <summary>        /// List        /// </summary>        /// <param name="portType"></param>        /// <param name="diId"></param>        /// <returns></returns>        public async Task<Result> _List(int portType, int diId)        {            if (diId < 0) return _result = new Result() { Code = -1, Msg = "请传入有效的DiId参数" };            if (portType < 1  || portType > 3) return _result = new Result() { Code = -1, Msg = "请传入有效的portType参数" };            string sql = string.Format($@"Select vfi.Id,vfi.IsChecked,cfc.VisaCountry AS Country,cfc.VisaPrice As VisaFee,                                          vfi.OBType,vfi.AgencyFee,vfi.OtherFee,vfi.Remark                                           From Grp_VisaFeeInfo vfi                                          Left Join Res_CountryFeeCost cfc On vfi.CountryVisaFeeId = cfc.Id                                          Where vfi.Isdel = 0  And vfi.Diid = {diId}");            var data = await _sqlSugar.SqlQueryable<VisaFeeInfosView>(sql).ToListAsync();            //默认十行 雷怡 2024-26-08 11:26:40             if (data.Count == 0)            {                var groupInfo = await _groupRep.PostShareGroupInfo(new ShareGroupInfoDto() { PortType = 1, Id = diId });                List<string> countrys = new List<string>();                if (groupInfo.Code == 200)                {                    countrys = _groupRep.GroupSplitCountry((groupInfo.Data as Web_ShareGroupInfoView)?.VisitCountry ?? "");                }                if (countrys.Any())                {                    //int dataRow = 0;                    foreach (var country in countrys)                    {                        var countryInfo = _sqlSugar.Queryable<Res_CountryFeeCost>().Where(it => it.IsDel == 0 && it.VisaCountry.Equals(country)).First();                        if (countryInfo != null)                        {                            data.Add(new VisaFeeInfosView()                            {                                IsChecked = 0,                                Country = country,                                VisaFee = countryInfo.VisaPrice,                                OBType = 1,                                AgencyFee = countryInfo.GrandBusinessAgencyFee                            });                            data.Add(new VisaFeeInfosView()                            {                                IsChecked = 0,                                Country = country,                                VisaFee = countryInfo.VisaPrice,                                OBType = 2,                                AgencyFee = countryInfo.PettyBusinessAgencyFee                            });                        }                        else                        {                            data.Add(new VisaFeeInfosView()                            {                                IsChecked = 0,                                Country = country,                                OBType = 1,                            });                            data.Add(new VisaFeeInfosView()                            {                                IsChecked = 0,                                Country = country,                                OBType = 2,                            });                        }                    }                    if (data.Count < 10)                    {                        int defaultRow = 10 - data.Count;                        for (int i = 0; i < defaultRow; i++)                        {                            data.Add(new VisaFeeInfosView()                            {                                Id = 0,                                OBType = 1                            });                        }                    }                }                else                {                    for (int i = 0; i < 10; i++)                    {                        data.Add(new VisaFeeInfosView()                        {                            Id = 0,                            OBType = 1                        });                    }                }            }            else if (data.Count <= 10)            {                int defaultRow = 10 - data.Count;                for (int i = 0; i < defaultRow; i++)                {                    data.Add(new VisaFeeInfosView()                    {                        Id = 0,                        OBType = 1                    });                }            }            _result.Code = 0;            _result.Data = data;            _result.Msg = "操作成功!";            return _result;        }        /// <summary>        /// List        /// </summary>        /// <param name="dto"></param>        /// <returns></returns>        public async Task<Result> _Update(VisaFeeAddAndUpdateDto dto)        {            if (dto.VisaFeeInfos.Count  < 1) return _result = new Result() { Code = -1, Msg = "请传入有效的签证费用集合参数" };            if (dto.PortType < 1 || dto.PortType > 3) return _result = new Result() { Code = -1, Msg = "请传入有效的portType参数" };            List<Grp_VisaFeeInfo> visaInfos = new List<Grp_VisaFeeInfo>();            BeginTran();            //bool visaFeeUpdate = false;            var countrys = dto.VisaFeeInfos.GroupBy(x => x.Country);            foreach (var country in countrys)            {                int countryVisaFeeId = 0;                decimal _grandBusinessAgencyFee = 0;                decimal _pettyBusinessAgencyFee = 0;                decimal _visaFee = 0;                foreach (var item in country.ToList())                {                    _visaFee = item.VisaFee;                    if (item.OBType == 1) _grandBusinessAgencyFee = item.AgencyFee;                    else if (item.OBType == 2) _pettyBusinessAgencyFee = item.AgencyFee;                }                var info = await _countryFeeRep._InfoByCountryName(country.Key);                if (info == null) //添加                {                    int addId = _sqlSugar.Insertable(                        new Res_CountryFeeCost()                        {                            VisaCountry = country.Key,                            VisaPrice = _visaFee,                            GrandBusinessAgencyFee = _grandBusinessAgencyFee,                            PettyBusinessAgencyFee = _pettyBusinessAgencyFee,                            LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),                            CreateUserId = dto.OpUserId,                        }).ExecuteReturnIdentity();                    if (addId > 0) countryVisaFeeId = addId;                }                else //修改                {                    countryVisaFeeId = info.Id;                    if (_visaFee != info.VisaPrice) //价格不同的时候执行修改                    {                        Res_CountryFeeCost _CountryFeeCost = new Res_CountryFeeCost()                        {                            Id = info.Id,                            VisaPrice = _visaFee,                            GrandBusinessAgencyFee = _grandBusinessAgencyFee,                            PettyBusinessAgencyFee = _pettyBusinessAgencyFee,                            LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),                        };                        int update1 = _sqlSugar.Updateable(_CountryFeeCost).UpdateColumns(it => new { it.VisaPrice, it.LastUpdateTime }).WhereColumns(it => it.Id).ExecuteCommand();                        //if (update1 > 0)                        //{                        //    visaFeeUpdate = true;                        //}                    }                }                foreach (var item in country.ToList())                {                    visaInfos.Add(new Grp_VisaFeeInfo()                    {                        Id = item.Id,                        DiId = dto.DiId,                        IsChecked = item.IsChecked,                        CountryVisaFeeId = countryVisaFeeId,                        OBType = item.OBType,                        AgencyFee = item.AgencyFee,                        OtherFee = item.OtherFee                    });                }            }            //执行删除            var update = _sqlSugar.Updateable<Grp_VisaFeeInfo>().SetColumns(it => new Grp_VisaFeeInfo()            {                DeleteUserId = dto.OpUserId,                DeleteTime = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"),                IsDel = 1            }).Where(it => it.DiId == dto.DiId).ExecuteCommand();            var add = _sqlSugar.Insertable(visaInfos).ExecuteCommand();            if (add > 0)            {                CommitTran();                 return new Result() {Code = 0 ,Msg = "操作成功!" };            }                       RollbackTran();            return _result;        }        /// <summary>        /// 出入境费用签证费用提示        /// </summary>        /// <param name="portType"></param>        /// <param name="diId"></param>        /// <returns></returns>        public async Task<Result> EnterExitCostVisaTips(int diId)        {            if (diId < 1) return _result = new Result() { Code = -1, Msg = "请传入有效的DiId参数" };            var visaData = await _sqlSugar.Queryable<Grp_VisaFeeInfo>().Where(it => it.IsDel == 0 && it.DiId == diId).ToListAsync();            List<int> ids = visaData.Select (it => it.CountryVisaFeeId).ToList();            var visaCountryDatas = await _sqlSugar.Queryable<Res_CountryFeeCost>().Where(it => ids.Contains(it.Id)).ToListAsync();            List<dynamic> datas = new List<dynamic>();            string remark = "";            decimal feeTotal = 0.00M;            visaData = visaData.Where(it => it.IsChecked == 1).ToList();            var visaData1 = visaData.GroupBy(it => it.CountryVisaFeeId);                        //费用报价系数            decimal priceCoeff = 1.00M;             foreach (var kvp in visaData1)            {                var countryData = visaCountryDatas.Find(it => it.Id == kvp.Key);                decimal _otherFee = kvp.FirstOrDefault()?.OtherFee * priceCoeff ?? 0;                decimal _visaFee = Convert.ToDecimal(countryData?.VisaPrice ?? 0.00M) * priceCoeff;                decimal visaFeeTotal = _visaFee + _otherFee;                decimal _agencyFee = 0;                decimal _GrandBusinessAgencyFee = 0;                decimal _PettyBusinessAgencyFee = 0;                                string remark1 = $"签证费:{_visaFee.ToString("#0.00")}元、";                foreach (var item in kvp.ToList())                {                    if (item.OBType == 1)                    {                        if (item.AgencyFee > 0)                        {                            remark1 += $@"大公务代办费:{item.AgencyFee.ToString("#0.00")}元、";                            _agencyFee += item.AgencyFee;                            _GrandBusinessAgencyFee = item.AgencyFee * priceCoeff;                        }                    }                    else if (item.OBType == 1)                    {                        if (item.AgencyFee > 0)                        {                            remark1 += $@"小公务代办费:{item.AgencyFee.ToString("#0.00")}元、";                            _agencyFee += item.AgencyFee;                            _PettyBusinessAgencyFee = item.AgencyFee * priceCoeff;                        }                    }                }                if (remark1.Length > 0) remark1 = remark1.Substring(0, remark1.Length - 1);                if (_otherFee > 0) remark1 += $@"其他费用:{_otherFee.ToString("#0.00")}元";                visaFeeTotal += (_GrandBusinessAgencyFee + _PettyBusinessAgencyFee);                remark += $@"{countryData?.VisaCountry ?? ""}:签证总费用:{visaFeeTotal}元/人 其中({remark1});";                feeTotal += visaFeeTotal;                datas.Add(new                {                    Country = countryData?.VisaCountry ?? "",                    visaFeeTotal = visaFeeTotal,                    VisaFee = countryData?.VisaPrice ?? 0.00M,                    GrandBusinessAgencyFee = _GrandBusinessAgencyFee,                    PettyBusinessAgencyFee = _PettyBusinessAgencyFee,                    OtherFee = _otherFee                });            }            _result.Code = 0;            _result.Data = new {                 feeTotal = feeTotal,                data = datas,                remark = remark            };            return _result;        }        /// <summary>        /// 出入境费用草稿签证费用提示        /// </summary>        /// <param name="portType"></param>        /// <param name="diId"></param>        /// <returns></returns>        public async Task<(decimal,string)> EnterExitCostDraftVisaTips(string[] countrys)        {            var visaCountryDatas = await _sqlSugar.Queryable<Res_CountryFeeCost>().Where(it => countrys.Contains(it.VisaCountry)).ToListAsync();            string remark = "";            decimal feeTotal = 0.00M;            //费用报价系数            decimal priceCoeff = 1.00M;            foreach (var kvp in visaCountryDatas)            {                var countryName = kvp?.VisaCountry ?? "";                //免签                if (kvp.IsVisaExemption == 0)                {                    remark += $@"{countryName}:免签;";                    continue;                }                decimal visaFee = Convert.ToDecimal(kvp?.VisaPrice ?? 0.00M) * priceCoeff;                                decimal gbAgencyFee = kvp.GrandBusinessAgencyFee;                decimal pbAgencyFee = kvp.PettyBusinessAgencyFee;                string remark1 = $"签证费:{visaFee.ToString("#0.00")}元、";                if (gbAgencyFee > 0.00M)                {                    remark1 += $@"大公务代办费:{gbAgencyFee.ToString("#0.00")}元、";                    gbAgencyFee *=  priceCoeff;                }                if (pbAgencyFee > 0.00M)                {                    remark1 += $@"小公务代办费:{pbAgencyFee.ToString("#0.00")}元、";                    pbAgencyFee *= priceCoeff;                }                if (remark1.Length > 0) remark1 = remark1.Substring(0, remark1.Length - 1);                decimal visaFeeTotal = visaFee + gbAgencyFee + pbAgencyFee;                remark += $@"{countryName}:签证总费用:{visaFeeTotal}元/人 其中({remark1});";                feeTotal += visaFeeTotal;            }            return (feeTotal,remark);        }    }}
 |