123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490 |
- 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<Air_TicketBlackCode, TicketBlackCodeView>
- {
- private readonly IMapper _mapper;
- public TicketBlackCodeRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
- {
- _mapper = mapper;
- }
- /// <summary>
- /// 黑屏代码操作(Status:1.新增,2.修改)
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- /// <exception cref="NotImplementedException"></exception>
- public async Task<Result> OpTicketBlackCode(OpTicketBlackCodeDto dto)
- {
- Result result = new Result() { Code = -2, Msg = "未知错误" };
- try
- {
- if (dto.Status == 1)//添加
- {
- Air_TicketBlackCode _TicketBlackCode = await _sqlSugar.Queryable<Air_TicketBlackCode>().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<Air_TicketBlackCode>(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<Result> 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<TicketBlackCodeView> _TicketBlackCodes = await _sqlSugar.SqlQueryable<TicketBlackCodeView>(sql).ToListAsync();
- Grp_DelegationInfo _DelegationInfo=await _sqlSugar.Queryable<Grp_DelegationInfo>().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<Result> QueryTicketBlackCodeById(QueryTicketBlackCodeByIdDto dto)
- {
- Result result = new Result() { Code = -2, Msg = "未知错误" };
- try
- {
- //查询成本和团组信息
- Grp_GroupCostParameter _GroupCostParameter = _sqlSugar.Queryable<Grp_GroupCostParameter>().First(a => a.DiId == dto.DiId && a.IsDel==0);//团组成本
- AirGroupCostParameterView _AirgroupCostParameter = _mapper.Map<AirGroupCostParameterView>(_GroupCostParameter);
- Grp_DelegationInfo _DelegationInfo=_sqlSugar.Queryable<Grp_DelegationInfo>().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<Air_TicketBlackCode>().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;
- }
- }
- /// <summary>
- /// 三公费用提示
- /// 使用
- /// </summary>
- /// <param name="diId"></param>
- /// <returns></returns>
- public async Task<Result> EntryAndExitTips(int diId)
- {
- if (diId < 1) return new Result() { Code = -1, Msg = "请输入有效的DiId参数!" };
- Air_TicketBlackCode _TicketBlackCode = await _sqlSugar.Queryable<Air_TicketBlackCode>().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<string>();
- var group = _sqlSugar.Queryable<Grp_DelegationInfo>()
- .First(x => x.Id == diid && x.IsDel == 0);
- Func<string,string> 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<Air_TicketBlackCode>().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<CountryDataTime>();
- //读取单条黑屏代码
- 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<Res_ThreeCode>()
- .Where(x => x.IsDel == 0 && threeCodeList.Select(x => x.Code).Contains(x.Three.ToLower()))
- .ToList();
- var data = new List<CountryDataTime>();
- var info = new List<string>();
- 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;
- }
- }
- }
|