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 { private readonly IMapper _mapper; public CarTouristGuideGroundRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar) { _mapper = mapper; } public async Task OpCarTouristGuideGround(OpCarTouristGuideGroundDto dto) { Result result = new Result() { Code = -2, Msg = "未知错误" }; BeginTran(); try { //int id = 0; //Grp_CarTouristGuideGroundReservations grp_CarTouristGuide = _mapper.Map(dto); //if (dto.Status == 1)//添加 //{ // Grp_CarTouristGuideGroundReservations grp_CarTouristGuideGround = _sqlSugar.Queryable().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().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 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 gtaUIdList = _sqlSugar.Queryable().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 infoViews = _sqlSugar.SqlQueryable(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_CarTourists = _sqlSugar.SqlQueryable(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(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 rst = new ListViewBase(); 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; } } }