using AutoMapper; using EyeSoft.Collections.Generic; using EyeSoft.Extensions; using OASystem.Domain; using OASystem.Domain.Dtos.Groups; using OASystem.Domain.Dtos.Resource; using OASystem.Domain.Entities.Groups; using OASystem.Domain.Entities.Resource; using OASystem.Domain.ViewModels.Groups; using OASystem.Domain.ViewModels.Resource; using SqlSugar.Extensions; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace OASystem.Infrastructure.Repositories.Resource { public class TicketBlackCodeRepository : BaseRepository { private readonly IMapper _mapper; public TicketBlackCodeRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar) { _mapper = mapper; } /// /// 黑屏代码操作(Status:1.新增,2.修改) /// /// /// /// public async Task OpTicketBlackCode(OpTicketBlackCodeDto dto) { Result result = new Result() { Code = -2, Msg = "未知错误" }; try { if (dto.Status == 1)//添加 { Air_TicketBlackCode _TicketBlackCode = await _sqlSugar.Queryable().FirstAsync(a=>a.IsDel==0 && a.BlackCode==dto.BlackCode && a.DiId==dto.DiId);//查询是否存在 if (_TicketBlackCode != null) { return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" }; } else//不存在,可添加 { Air_TicketBlackCode air_TicketBlack = _mapper.Map(dto); int id = await _sqlSugar.Insertable(air_TicketBlack).ExecuteReturnIdentityAsync(); if (id == 0) { return result = new Result() { Code = -1, Msg = "添加失败!" }; } return result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } }; } } else if (dto.Status == 2)//修改 { bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Air_TicketBlackCode { DiId=dto.DiId, BlackCode=dto.BlackCode, Price=dto.Price, NowPrice=dto.NowPrice, BCPrice=dto.BCPrice, ECPrice=dto.ECPrice, CreateUserId = dto.CreateUserId, Remark = dto.Remark, }); if (!res) { return result = new Result() { Code = -1, Msg = "修改失败!" }; } return result = new Result() { Code = 0, Msg = "修改成功!", Data = new { Id = dto.Id } }; } else { return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" }; } } catch (Exception ex) { return result = new Result() { Code = -2, Msg = "程序错误!" }; } } public async Task QueryTicketBlackCodeByDiId(QueryTicketBlackCodeByDiIdDto dto) { Result result = new Result() { Code = -2, Msg = "未知错误" }; try { string sqlWhere = string.Empty; sqlWhere += string.Format(@" And a.IsDel={0} And a.DiId={1}", 0, dto.DiId); if (!string.IsNullOrEmpty(sqlWhere.Trim())) { Regex r = new Regex("And"); sqlWhere = r.Replace(sqlWhere, "Where", 1); } string sql = string.Format(@"select *,(select CnName from Sys_Users where id=a.CreateUserId) as CreateName from Air_TicketBlackCode a {0}", sqlWhere); List _TicketBlackCodes = await _sqlSugar.SqlQueryable(sql).ToListAsync(); Grp_DelegationInfo _DelegationInfo=await _sqlSugar.Queryable().FirstAsync(a=>a.IsDel==0 && a.Id==dto.DiId); if (_TicketBlackCodes.Count!=0) { return result = new Result() { Code = 0, Msg = "查询成功", Data = new { TicketBlackCodes= _TicketBlackCodes, DelegationInfo= _DelegationInfo }, }; } else { return result = new Result() { Code = 0, Msg = "暂无数据", Data = new { TicketBlackCodes = _TicketBlackCodes, DelegationInfo = _DelegationInfo }, }; } } catch (Exception) { return result; throw; } } public async Task QueryTicketBlackCodeById(QueryTicketBlackCodeByIdDto dto) { Result result = new Result() { Code = -2, Msg = "未知错误" }; try { //查询成本和团组信息 Grp_GroupCostParameter _GroupCostParameter = _sqlSugar.Queryable().First(a => a.DiId == dto.DiId && a.IsDel==0);//团组成本 AirGroupCostParameterView _AirgroupCostParameter = _mapper.Map(_GroupCostParameter); Grp_DelegationInfo _DelegationInfo=_sqlSugar.Queryable().First(a=>a.Id == dto.DiId && a.IsDel==0);//团组信息 Air_TicketBlackCode _TicketBlackCode=new Air_TicketBlackCode(); if (dto.Id!=0 && !string.IsNullOrWhiteSpace(dto.Id.ToString())) { _TicketBlackCode = _sqlSugar.Queryable().First(a => a.IsDel==0 && a.Id==dto.Id); return result = new Result() { Code = 0, Msg = "查询成功!", Data = new { GroupCostParameter = _AirgroupCostParameter, DelegationInfo = _DelegationInfo, TicketBlackCode = _TicketBlackCode }, }; } else { return result = new Result() { Code = 0, Msg = "查询成功!", Data = new { GroupCostParameter = _AirgroupCostParameter, DelegationInfo = _DelegationInfo, }, }; } } catch (Exception) { return result; throw; } } /// /// 三公费用提示 /// 使用 /// /// /// public async Task EntryAndExitTips(int diId) { if (diId < 1) return new Result() { Code = -1, Msg = "请输入有效的DiId参数!" }; Air_TicketBlackCode _TicketBlackCode = await _sqlSugar.Queryable().FirstAsync(a => a.IsDel == 0 && a.DiId == diId); if (_TicketBlackCode != null) { return new Result() { Code = 0, Msg = "操作成功!", Data = new { jjcCurrentRate = _TicketBlackCode.ECPrice, gwcCurrentRate = _TicketBlackCode.BCPrice, Remark = $"经济舱现价:{_TicketBlackCode.ECPrice.ToString("#0.00")} 元/人 公务舱:{_TicketBlackCode.BCPrice.ToString("#0.00")} 元/人" } }; } return new Result() { Code = -1,Msg="操作失败" }; } public Result DescBlackToVisa(int diid) { Result rt = new Result(); rt.Data = Array.Empty(); var group = _sqlSugar.Queryable() .First(x => x.Id == diid && x.IsDel == 0); Func RemoveSpecialCharacters = ( string input ) => { string pattern = @"[^\u4e00-\u9fa5]+"; // 用空字符串替换所有匹配到的字符 return Regex.Replace(input, pattern, "|"); }; if (group != null) { var country = RemoveSpecialCharacters(group.VisitCountry); if (!country.IsNullOrWhiteSpace()) { var countryArr = country.Split('|'); var blackCode = _sqlSugar.Queryable().First(x => x.IsDel == 0 && x.DiId == diid); //去除序号 string[] CodeList = Regex.Split(blackCode.BlackCode, "\\d+\\.", RegexOptions.IgnoreCase) .Where(str => !string.IsNullOrWhiteSpace(str)).ToArray(); var threeCodeList = new List(); //读取单条黑屏代码 for (int j = 0; j < CodeList.Count(); j++) { //去除多余空格,方法二使用Split()方法进行分割,分割有一个选项是RemoveEmptyEntries CodeList[j] = CodeList[j].Replace("\r\n", string.Empty).Replace("\\r\\n", string.Empty).TrimStart().TrimEnd(); string[] Info = CodeList[j].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var threeCode = Info[2]; var startTimeStr = Info[3]; var endTimeStr = Info[4]; var monthEn = Info[1].Substring(4, 3); //月 int month = Convert.ToInt32(GetLonger(monthEn)); //日 int day = Convert.ToInt32(Info[1].Substring(2, 2)); var startTime = new DateTime(DateTime.Now.Year, month, day, startTimeStr.Substring(0,2).ObjToInt(), startTimeStr.Substring(2, 2).ObjToInt(), 00); // var endTime = new DateTime(DateTime.Now.Year, month, day, endTimeStr.Substring(0, 2).ObjToInt(), endTimeStr.Substring(2, 2).ObjToInt(), 00); // if (!threeCode.IsNullOrWhiteSpace() && threeCode.Length > 5) { var start = threeCode.Substring(0, 3).ToLower(); var end = threeCode.Substring(3, 3).ToLower(); if (!threeCodeList.Select(x => x.Code).Contains(end)) { var temp = new CountryDataTime { Code = end, StartTime = startTime, EndTime = endTime, Country = "" }; threeCodeList.Add(temp); } } } var dbThreeCode = _sqlSugar.Queryable() .Where(x => x.IsDel == 0 && threeCodeList.Select(x => x.Code).Contains(x.Three.ToLower())) .ToList(); var data = new List(); var info = new List(); foreach (var code in dbThreeCode) { for (int i = 0; i < threeCodeList.Count; i++) { if (threeCodeList[i].Code == code.Three.ToLower()) { threeCodeList[i].Country = code.Country; if (countryArr.Contains(code.Country)) { var copy = new CountryDataTime { Code = threeCodeList[i].Code, EndTime = threeCodeList[i].EndTime, StartTime = threeCodeList[i].StartTime, Country = threeCodeList[i].Country, }; try { threeCodeList[i].StartTime = threeCodeList[i].EndTime; threeCodeList[i].EndTime = threeCodeList[i + 1].StartTime; info.Add($@"{code.Country} 抵达:{threeCodeList[i].EndTime.ToString("yyyy-MM-dd HH:mm")} 离开:{threeCodeList[i + 1].StartTime.ToString("yyyy-MM-dd HH:mm")} "); } catch (Exception) { threeCodeList[i] = copy; info.Add($@"{code.Country} 抵达:{threeCodeList[i].EndTime.ToString("yyyy-MM-dd HH:mm")} 离开: 未知 "); } data.Add(threeCodeList[i]); } break; } } } rt.Msg = "SUCCESS!"; rt.Code = 0; rt.Data = new { data = data, info = info }; } } return rt; } public string GetLonger(string temp) { string str = ""; switch (temp.ToUpper()) { case "美元": str = "USD"; break; case "日元": str = "JPY"; break; case "英镑": str = "GBP"; break; case "欧元": str = "EUR"; break; case "港币": str = "HKD"; break; case "MO": str = "星期一"; break; case "TU": str = "星期二"; break; case "WE": str = "星期三"; break; case "TH": str = "星期四"; break; case "FR": str = "星期五"; break; case "SA": str = "星期六"; break; case "SU": str = "星期天"; break; case "JAN": str = "01"; break; case "FEB": str = "02"; break; case "MAR": str = "03"; break; case "APR": str = "04"; break; case "MAY": str = "05"; break; case "JUN": str = "06"; break; case "JUL": str = "07"; break; case "AUG": str = "08"; break; case "SEP": str = "09"; break; case "OCT": str = "10"; break; case "NOV": str = "11"; break; case "DEC": str = "12"; break; case "MONDAY": str = "星期一"; break; case "TUESDAY": str = "星期二"; break; case "WEDNESDAY": str = "星期三"; break; case "THURSDAY": str = "星期四"; break; case "FRIDAY": str = "星期五"; break; case "SATURDAY": str = "星期六"; break; case "SUNDAY": str = "星期日"; break; case "01": str = "JAN"; break; case "02": str = "FEB"; break; case "03": str = "MAR"; break; case "04": str = "APR"; break; case "05": str = "MAY"; break; case "06": str = "JUN"; break; case "07": str = "JUL"; break; case "08": str = "AUG"; break; case "09": str = "SEP"; break; case "10": str = "OCT"; break; case "11": str = "NOV"; break; case "12": str = "DEC"; break; case "2": str = "空客A"; break; case "3": str = "空客A"; break; case "7": str = "波音"; break; } return str; } } }