123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- 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;
- public VisaFeeInfoRepository(SqlSugarClient sqlSugar, IMapper mapper, CountryFeeRepository countryFeeRep)
- : base(sqlSugar)
- {
- _mapper = mapper;
- _result = new Result() { Code = -2,Msg = "操作失败!"};
- _countryFeeRep = countryFeeRep;
- }
- /// <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.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();
- _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> _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;
- foreach (var item in dto.VisaFeeInfos)
- {
- int countryVisaFeeId = 0;
- var info =await _countryFeeRep._InfoByCountryName(item.Country);
- if (info == null) //添加
- {
- int addId = _sqlSugar.Insertable(
- new Res_CountryFeeCost()
- {
- VisaCountry = item.Country,
- VisaPrice = item.VisaFee,
- LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
- CreateUserId = dto.OpUserId,
- }).ExecuteReturnIdentity();
- if (addId > 0) countryVisaFeeId = addId;
- }
- else //修改
- {
- countryVisaFeeId = info.Id;
- if (item.VisaFee != info.VisaPrice) //价格不同的时候执行修改
- {
- Res_CountryFeeCost _CountryFeeCost = new Res_CountryFeeCost()
- {
- Id = info.Id,
- VisaPrice = item.VisaFee,
- 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;
- }
-
- }
- }
- visaInfos.Add(new Grp_VisaFeeInfo()
- {
- Id = item.Id,
- DiId = dto.DiId,
- IsChecked = item.IsChecked,
- CountryVisaFeeId = countryVisaFeeId,
- 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> EntryAndExitTips(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;
- foreach (var item in visaData)
- {
- if (item.IsChecked == 1)
- {
- var countryData = visaCountryDatas.Find(it => it.Id == item.CountryVisaFeeId);
- decimal visaFeeTotal = countryData?.VisaPrice ?? 0.00M + item.AgencyFee + item.OtherFee;
- remark += $@"{countryData?.VisaCountry ?? ""}:签证总费用:{visaFeeTotal}元/人 其中(";
- if (countryData?.VisaPrice > 0) remark += $@"签证费用:{countryData?.VisaPrice.ToString("#0.00")}元、";
- if (item.AgencyFee > 0) remark += $@"代办费:{item.AgencyFee.ToString("#0.00")}元、";
- if (item.OtherFee > 0) remark += $@"其他费用:{item.OtherFee.ToString("#0.00")}元";
- if (visaFeeTotal > 0) remark = remark.Substring(0,remark.Length -1);
- remark += ");";
- feeTotal += visaFeeTotal;
- datas.Add(new
- {
- Country = countryData?.VisaCountry ?? "",
- visaFeeTotal = visaFeeTotal,
- VisaFee = countryData?.VisaPrice ?? 0.00M,
- item.AgencyFee,
- item.OtherFee
- });
- }
- }
- _result.Code = 0;
- _result.Data = new {
- feeTotal = feeTotal,
- data = datas,
- remark = remark
- };
- return _result;
- }
- }
- }
|