123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- using AutoMapper;
- using OASystem.Domain;
- using OASystem.Domain.Dtos.Groups;
- using OASystem.Domain.Entities.Financial;
- using OASystem.Domain.Entities.Groups;
- using OASystem.Domain.ViewModels.Groups;
- using OASystem.Infrastructure.Tools;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace OASystem.Infrastructure.Repositories.Groups
- {
- public class CarTouristGuideGroundRepository:BaseRepository<Grp_CarTouristGuideGroundReservations, Grp_CarTouristGuideGroundReservationsContent>
- {
- private readonly IMapper _mapper;
- public CarTouristGuideGroundRepository(SqlSugarClient sqlSugar, IMapper mapper)
- : base(sqlSugar)
- {
- _mapper = mapper;
- }
- public async Task<Result> OpCarTouristGuideGround(OpCarTouristGuideGroundDto dto)
- {
- Result result = new Result() { Code = -2, Msg = "未知错误" };
- BeginTran();
- try
- {
- //int id = 0;
- //Grp_CarTouristGuideGroundReservations grp_CarTouristGuide = _mapper.Map<Grp_CarTouristGuideGroundReservations>(dto);
- //if (dto.Status == 1)//添加
- //{
- // Grp_CarTouristGuideGroundReservations grp_CarTouristGuideGround = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().First(a => a.IsDel == 0 && a.Area == dto.Area && a.BusName == dto.BusName && a.ServiceGuide == dto.ServiceGuide);
- // if (grp_CarTouristGuideGround != null)
- // {
- // return result = new Result() { Code = -1, Msg = "该笔费用已存在,请勿重复添加!" };
- // }
- // else
- // {
- // id = await AddAsyncReturnId(grp_CarTouristGuide);
- // if (id != 0)
- // {
- // //int cId = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
- // if (true)
- // {
- // result = new Result() { Code = 0, Msg = "添加成功!" };
- // }
- // else
- // {
- // RollbackTran();
- // result = new Result() { Code = -1, Msg = "添加失败!" };
- // }
- // }
- // else
- // {
- // RollbackTran();
- // result = new Result() { Code = -1, Msg = "添加失败,请稍后重试!" };
- // }
- // }
- //}
- //else if (dto.Status == 2)//修改
- //{
- // bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_VisaInfo
- // {
- // VisaClient = grp_Visa1.VisaClient,
- // VisaPrice = grp_Visa1.VisaPrice,
- // VisaCurrency = grp_Visa1.VisaCurrency,
- // IsThird = grp_Visa1.IsThird,
- // PassengerType = grp_Visa1.PassengerType,
- // VisaNumber = grp_Visa1.VisaNumber,
- // VisaFreeNumber = grp_Visa1.VisaFreeNumber,
- // Remark = dto.Remark,
- // });
- // if (res)
- // {
- // int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == grp_Visa1.Id && a.CTable == 80).SetColumns(a => new Grp_CreditCardPayment
- // {
- // PayDId = dto.PayDId,
- // PayMoney = c.PayMoney,
- // PaymentCurrency = c.PaymentCurrency,
- // Payee = c.Payee,
- // OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
- // DayRate = c.DayRate,
- // RMBPrice = c.RMBPrice,
- // ConsumptionPatterns = c.ConsumptionPatterns,
- // ConsumptionDate = c.ConsumptionDate,
- // CTDId = c.CTDId,
- // CompanyBankNo = c.CompanyBankNo,
- // OtherBankName = c.OtherBankName,
- // OtherSideNo = c.OtherSideNo,
- // OtherSideName = c.OtherSideName,
- // BankNo = c.BankNo,
- // CardholderName = c.CardholderName,
- // Remark = c.Remark,
- // }).ExecuteCommandAsync();
- // result = new Result() { Code = 0, Msg = "修改成功!" };
- // }
- // else
- // {
- // RollbackTran();
- // result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
- // }
- //}
- //CommitTran();
- }
- catch (Exception ex)
- {
- result = new Result() { Code = -2, Msg = "未知错误" };
- }
- return result;
- }
- public async Task<Result> QueryCarTouristGuideGroundByDiId(CarTouristGuideGroundDto dto)
- {
- Result result = new Result() { Code = -2, Msg = "未知错误" };
- if (dto.PortType == 0 || string.IsNullOrWhiteSpace(dto.PortType.ToString()))
- {
- return result = new Result() { Code = -1, Msg = "请传入PortType参数,请求端口分类 1 Web 2 Android 3 IOS" };
- }
- try
- {
- #region SQL条件拼接
- string sqlWhere = string.Empty;
- sqlWhere += string.Format(@"And t.DIId={0} and t.isdel={1}", dto.DiId, 0);
- string UserId = "";
- List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 79).ToList();
- foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
- UserId += gta.UId + ",";
- if (!string.IsNullOrWhiteSpace(UserId))
- {
- UserId = UserId.Substring(0, UserId.Length - 1);
- }
- else
- {
- UserId = "0";
- }
-
- sqlWhere += string.Format(@" And t.CreateUserId in ({0})", UserId);
- if (!string.IsNullOrEmpty(sqlWhere.Trim()))
- {
- Regex r = new Regex("And");
- sqlWhere = r.Replace(sqlWhere, "Where", 1);
- }
- #endregion
- int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
- int endIndex = startIndex + dto.PageSize - 1;
- if (dto.PortType == 1)
- {
- string sql = string.Format(@"select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage,c.PayMoney from
- Grp_CarTouristGuideGroundReservations t
- left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id
- left Join Sys_SetData s on s.Id=t.CId {0}
- order by CreateTime desc", sqlWhere);
- List<Grp_CarTouristGuideGroundView> infoViews = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
- foreach (var item in infoViews)
- {
- item.PayThenMoney = Math.Round(item.PayPercentage/100 * item.ServiceQuotedPrice, 2);
- item.RemainingBalance = Math.Round(item.ServiceQuotedPrice- item.PayPercentage / 100 * item.ServiceQuotedPrice);
- }
- return result = new Result() { Code = 0, Msg = "查询成功!", Data = infoViews };
- }
- else if (dto.PortType == 2 || dto.PortType == 3)
- {
- string sql = string.Format(@"Select * From (
- Select row_number() over (order by t.Id Desc) as RowNumber,t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage
- from
- Grp_CarTouristGuideGroundReservations t
- left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id
- left Join Sys_SetData s on s.Id=t.CId {0}
- ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
- List<Grp_CarTouristGuideGroundView> grp_CarTourists = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
- foreach (var item in grp_CarTourists)
- {
- item.PayThenMoney = Math.Round(item.PayPercentage / 100 * item.ServiceQuotedPrice, 2);
- item.RemainingBalance = Math.Round(item.ServiceQuotedPrice - item.PayPercentage / 100 * item.ServiceQuotedPrice);
- }
- string CountSql = string.Format(@"Select COUNT(1) as Count From (
- select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage from
- Grp_CarTouristGuideGroundReservations t
- left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id
- left Join Sys_SetData s on s.Id=t.CId {0}
- ) temp ", sqlWhere);
- DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
- if (dataCount != null)
- {
- int count = dataCount.Count;
- float totalPage = (float)count / dto.PageSize;//总页数
- if (totalPage == 0) totalPage = 1;
- else totalPage = (int)Math.Ceiling((double)totalPage);
- ListViewBase<Grp_CarTouristGuideGroundView> rst = new ListViewBase<Grp_CarTouristGuideGroundView>();
- rst.DataList = grp_CarTourists;
- rst.DataCount = count;
- rst.CurrPageIndex = dto.PageIndex;
- rst.CurrPageSize = dto.PageSize;
- return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
- }
- }
- }
- catch (Exception)
- {
- return result = new Result() { Code = -2, Msg = "未知错误" };
- throw;
- }
- return result;
- }
- }
- }
|