using NPOI.HPSF;
using OASystem.API.OAMethodLib;
using OASystem.Domain.Dtos.Resource;
using OASystem.Domain.Entities.Groups;
using OASystem.Infrastructure.Repositories.Groups;
using Org.BouncyCastle.Utilities;
using Quartz.Util;
using System.Collections.Generic;
using System.Net.Http.Headers;

namespace OASystem.API.Controllers
{
    /// <summary>
    /// 资料相关
    /// </summary>
    //[Authorize]
    [Route("api/[controller]/[action]")]
    public class ResourceController : ControllerBase
    {
        private readonly IMapper _mapper;
        private readonly SqlSugarClient _sqlSugar;
        private readonly IConfiguration _config;
        private readonly CarDataRepository _carDataRep;
        private readonly LocalGuideDataRepository _localGuideDataRep;
        private readonly ThreeCodeRepository _ThreeCodeRep;
        private readonly HotelDataRepository _hotelDataRep;
        private readonly ResItemInfoRepository _resItemInfoRep;
        private readonly SetDataRepository _setDataRepository;
        private readonly CountryFeeRepository _countryFeeRep;
        private readonly SetDataTypeRepository _setDataTypeRep;
        private readonly AirTicketAgentRepository _airTicketAgentRep;
        private readonly InvitationOfficialActivityDataRepository _InvitationOfficialActivityDataRep;
        private readonly OfficialActivitiesRepository _officialActivitiesRep;
        private readonly AskDataRepository _askDataRep;
        private readonly TicketBlackCodeRepository _ticketBlackCodeRep;

        public ResourceController(IMapper mapper, IConfiguration config, SqlSugarClient sqlSugar, CarDataRepository carDataRep,LocalGuideDataRepository localGuideDataRep, 
            ThreeCodeRepository threeCodeRep,HotelDataRepository hotelDataRep, ResItemInfoRepository resItemInfoRep, SetDataRepository setDataRepository,
            CountryFeeRepository countryFeeRep, SetDataTypeRepository setDataTypeRep, AirTicketAgentRepository airTicketAgentRep,
            InvitationOfficialActivityDataRepository invitationOfficialActivityDataRep, OfficialActivitiesRepository officialActivitiesRep, AskDataRepository askDataRep, 
            TicketBlackCodeRepository ticketBlackCodeRep)
        {
            _mapper = mapper;
            _config = config;
            _sqlSugar = sqlSugar;
            _carDataRep = carDataRep;
            _localGuideDataRep = localGuideDataRep;
            _ThreeCodeRep = threeCodeRep;
            _hotelDataRep = hotelDataRep;
            _resItemInfoRep = resItemInfoRep;
            _setDataRepository = setDataRepository;
            _countryFeeRep = countryFeeRep;
            _setDataTypeRep = setDataTypeRep;
            _airTicketAgentRep = airTicketAgentRep;
            _InvitationOfficialActivityDataRep = invitationOfficialActivityDataRep;
            _officialActivitiesRep = officialActivitiesRep;
            _askDataRep = askDataRep;
            _ticketBlackCodeRep=ticketBlackCodeRep;
        }


        #region 车公司资料板块

        /// <summary>
        /// 车公司信息查询
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> QueryCarData(QueryCarDataDto dto)
        {
            try
            {
                Result LocalGuide = await _carDataRep.QueryCarData(dto);
                if (LocalGuide.Code == 0)
                {
                    return Ok(JsonView(true, "查询成功", LocalGuide.Data));
                }
                else
                {
                    return Ok(JsonView(false, LocalGuide.Msg));
                }
            }
            catch (Exception)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }


        }

        /// <summary>
        /// 车公司资料下拉框数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> QueryCarSelect()
        {
            try
            {
                var CarData = _carDataRep.QueryDto<Res_CarData, CarDataSelectView>().ToList();
                if (CarData.Count == 0)
                {
                    return Ok(JsonView(false, "暂无数据！"));
                }
                CarData.Add(new CarDataSelectView { Id = 0, UnitArea = "全部" });
                CarData = CarData.Where((x, i) => CarData.FindIndex(z => z.UnitArea == x.UnitArea) == i).ToList();
                CarData = CarData.OrderBy(x => x.Id).ToList();
                List<CarDataSelectView> data = new List<CarDataSelectView>();
                foreach (CarDataSelectView car in CarData)
                {
                    if (!string.IsNullOrWhiteSpace(car.UnitArea))
                    {
                        data.Add(car);
                    }
                }
                return Ok(JsonView(true, "查询成功", data));
            }
            catch (Exception)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }
        /// <summary>
        /// 车公司信息添加
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> AddCarData(AddCarDataDto dto)
        {
            try
            {
                if (dto.UnitArea == "")
                {
                    return Ok(JsonView(false, "请检查单位区域是否填写！"));
                }
                if (dto.UnitName == "")
                {
                    return Ok(JsonView(false, "请检查单位名称是否填写！"));
                }
                if (dto.Contact == "")
                {
                    return Ok(JsonView(false, "请检查单位联系人是否填写！"));
                }
                if (dto.ContactTel == "")
                {
                    return Ok(JsonView(false, "请检查联系方式是否填写正确！"));
                }

                var carDada = _carDataRep.QueryDto<Res_CarData, CarDataView>(a => a.UnitArea == dto.UnitArea && a.UnitName == dto.UnitName && a.Contact == dto.Contact && a.ContactTel == dto.ContactTel).ToList();
                if (carDada.Count != 0)
                {
                    return Ok(JsonView(false, "该信息已存在，请勿重复添加！"));
                }
                Res_CarData _CarData = _mapper.Map<Res_CarData>(dto);
                int id = await _carDataRep.AddAsyncReturnId(_CarData);
                if (id == 0)
                {
                    return Ok(JsonView(false, "添加失败！"));
                }
                return Ok(JsonView(true, "添加成功", new { Id = id }));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }

        /// <summary>
        /// 车公司信息修改
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> UpCarData(UpCarDataDto dto)
        {
            try
            {
                if (dto.UnitArea == "")
                {
                    return Ok(JsonView(false, "请检查单位区域是否填写！"));
                }
                if (dto.UnitName == "")
                {
                    return Ok(JsonView(false, "请检查单位名称是否填写！"));
                }
                if (dto.Contact == "")
                {
                    return Ok(JsonView(false, "请检查单位联系人是否填写！"));
                }
                if (dto.ContactTel == "")
                {
                    return Ok(JsonView(false, "请检查联系方式是否填写正确！"));
                }
                bool res = await _carDataRep.UpdateAsync(a => a.Id == dto.Id, a => new Res_CarData
                {
                    UnitArea = dto.UnitArea,
                    UnitName = dto.UnitName,
                    Address = dto.Address,
                    Contact = dto.Contact,
                    ContactTel = dto.ContactTel,
                    ContactEmail = dto.ContactEmail,
                    ContactFax = dto.ContactFax,
                    CarDes = dto.CarDes,
                    CarPicPaths = dto.CarPicPaths,
                    OtherInfo = dto.OtherInfo,
                    Score = dto.Score,
                    QualificationScore = dto.QualificationScore,
                    CarAgeScore = dto.CarAgeScore,
                    CleanImgScore = dto.CleanImgScore,
                    SmellScore = dto.SmellScore,
                    WaterPaperScore = dto.WaterPaperScore,
                    HardwareScore = dto.HardwareScore,
                    TimeScore = dto.TimeScore,
                    SafetyScore = dto.SafetyScore,
                    DrivingAgeScore = dto.DrivingAgeScore,
                    Remark = dto.Remark,
                });
                if (!res) { return Ok(JsonView(false, "修改失败！")); }
                return Ok(JsonView(true, "修改成功"));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }
        /// <summary>
        /// 车公司信息删除
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> DelCarData(DelCarDataDto dto)
        {
            try
            {
                bool res = await _carDataRep.SoftDeleteByIdAsync<Res_CarData>(dto.Id.ToString(), dto.DeleteUserId);
                if (!res) { return Ok(JsonView(false, "删除失败！")); }
                return Ok(JsonView(true, "删除成功"));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }
        #endregion

        #region 导游地接资料板块
        /// <summary>
        /// 导游地接资料查询
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> QueryLocalGuide(QueryLocalGuide dto)
        {
            try
            {
                Result LocalGuide = await _localGuideDataRep.QueryLocalGuide(dto);
                if (LocalGuide.Code == 0)
                {
                    return Ok(JsonView(true, "查询成功", LocalGuide.Data));
                }
                else
                {
                    return Ok(JsonView(false, LocalGuide.Msg));
                }

            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }


        }

        /// <summary>
        /// 导游地接资料下拉框数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> QueryLocalGuideSelect()
        {
            try
            {
                var LocalGuide = _carDataRep.QueryDto<Res_LocalGuideData, QueryLocalGuideSelectView>().ToList();
                if (LocalGuide.Count == 0)
                {
                    return Ok(JsonView(false, "暂无数据！"));
                }
                LocalGuide.Add(new QueryLocalGuideSelectView { Id = 0, UnitArea = "全部" });
                LocalGuide = LocalGuide.Where((x, i) => LocalGuide.FindIndex(z => z.UnitArea == x.UnitArea && z.UnitArea != "") == i).ToList();
                LocalGuide = LocalGuide.OrderBy(x => x.Id).ToList();
                List<QueryLocalGuideSelectView> data = new List<QueryLocalGuideSelectView>();
                foreach (QueryLocalGuideSelectView Local in LocalGuide)
                {
                    if (!string.IsNullOrWhiteSpace(Local.UnitArea))
                    {
                        data.Add(Local);
                    }
                }
                return Ok(JsonView(true, "查询成功", data));
            }
            catch (Exception)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }

        /// <summary>
        /// 导游地接信息操作（Status:1.新增,2.修改）
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> OperationLocalGuide(LocalGuideOperationDto dto)
        {
            try
            {
                if (dto.UnitArea == "")
                {
                    return Ok(JsonView(false, "请检查单位区域是否填写！"));
                }
                if (dto.UnitName == "")
                {
                    return Ok(JsonView(false, "请检查单位名称是否填写！"));
                }
                if (dto.Contact == "")
                {
                    return Ok(JsonView(false, "请检查单位联系人是否填写！"));
                }
                if (dto.ContactTel == "")
                {
                    return Ok(JsonView(false, "请检查联系方式是否填写正确！"));
                }

                Result result = await _localGuideDataRep.LocalGuideOperation(dto);
                if (result.Code != 0)
                {
                    return Ok(JsonView(false, result.Msg));
                }
                return Ok(JsonView(true, result.Msg));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }

        /// <summary>
        /// 导游地接信息操作（删除）
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> DelLocalGuide(LocalGuideDelDto dto)
        {
            try
            {
                var res = await _localGuideDataRep.SoftDeleteByIdAsync<Res_LocalGuideData>(dto.Id.ToString(), dto.DeleteUserId);
                if (!res)
                {
                    return Ok(JsonView(false, "删除失败"));
                }
                return Ok(JsonView(true, "删除成功！"));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }
        #endregion

        #region 机场三字码信息
        /// <summary>
        /// 机场三字码查询
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> QueryThreeCode(QueryThreeCodeDto dto)
        {
            try
            {
                Result LocalGuide = await _ThreeCodeRep.QueryThreeCode(dto);
                if (LocalGuide.Code == 0)
                {
                    return Ok(JsonView(true, "查询成功", LocalGuide.Data));
                }
                else
                {
                    return Ok(JsonView(false, LocalGuide.Msg));
                }
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }


        }
        /// <summary>
        /// 机场三字码数据城市下拉框数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> QueryThreeCodeSelect()
        {
            try
            {
                var ThreeCode = _carDataRep.QueryDto<Res_ThreeCode, ThreeCodeSelectView>().ToList();
                if (ThreeCode.Count == 0)
                {
                    return Ok(JsonView(false, "暂无数据！"));
                }
                ThreeCode.Add(new ThreeCodeSelectView { Id = 0, City = "全部" });
                ThreeCode = ThreeCode.Where((x, i) => ThreeCode.FindIndex(z => z.City == x.City && z.City != "") == i).ToList();
                ThreeCode = ThreeCode.OrderBy(x => x.Id).ToList();
                List<ThreeCodeSelectView> data = new List<ThreeCodeSelectView>();
                foreach (ThreeCodeSelectView _ThreeCode in ThreeCode)
                {
                    if (!string.IsNullOrWhiteSpace(_ThreeCode.City))
                    {
                        data.Add(_ThreeCode);
                    }
                }
                return Ok(JsonView(true, "查询成功", data));
            }
            catch (Exception)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }

        /// <summary>
        /// 机场三字码资料操作（Status:1.新增,2.修改）
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> OperationThreeCode(ThreeCodeOperationDto dto)
        {
            try
            {
                if (dto.Three == "")
                {
                    return Ok(JsonView(false, "请检查三字码是否填写！"));
                }
                if (dto.Country == "")
                {
                    return Ok(JsonView(false, "请检查国家是否填写！"));
                }
                if (dto.City == "")
                {
                    return Ok(JsonView(false, "请检查城市是否填写正确！"));
                }
                if (dto.AirPort == "")
                {
                    return Ok(JsonView(false, "请检查机场是否填写正确！"));
                }

                Result result = await _ThreeCodeRep.ThreeCodeOperation(dto);
                if (result.Code != 0)
                {
                    return Ok(JsonView(false, result.Msg));
                }
                return Ok(JsonView(true, result.Msg));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }

        /// <summary>
        /// 机场三字码资料操作（删除）
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> DelThreeCode(ThreeCodeDelDto dto)
        {
            try
            {
                var res = await _ThreeCodeRep.SoftDeleteByIdAsync<Res_ThreeCode>(dto.Id.ToString(), dto.DeleteUserId);
                if (!res)
                {
                    return Ok(JsonView(false, "删除失败"));
                }
                return Ok(JsonView(true, "删除成功！"));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }
        #endregion

        #region 代理出票合作方资料
        /// <summary>
        /// 代理出票合作方资料
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> QueryAirTicketAgent(DtoBase dto)
        {

            try
            {
                List<Res_AirTicketAgent> res_AirTicketAgents = _airTicketAgentRep.Query<Res_AirTicketAgent>(a => a.IsDel == 0).ToList();
                if (res_AirTicketAgents.Count != 0)
                {
                    res_AirTicketAgents = res_AirTicketAgents.OrderByDescending(a => a.CreateTime).ToList();
                    if (dto.PageSize == 0 && dto.PageIndex == 0)
                    {
                        return Ok(JsonView(true, "查询成功！", res_AirTicketAgents));
                    }
                    else
                    {
                        int count = res_AirTicketAgents.Count;
                        float totalPage = (float)count / dto.PageSize;//总页数
                        if (totalPage == 0) totalPage = 1;
                        else totalPage = (int)Math.Ceiling((double)totalPage);

                        List<Res_AirTicketAgent> _AirTicketAgent = new List<Res_AirTicketAgent>();
                        for (int i = 0; i < dto.PageSize; i++)
                        {
                            var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
                            if (RowIndex < res_AirTicketAgents.Count)
                            {
                                _AirTicketAgent.Add(res_AirTicketAgents[RowIndex]);
                            }
                            else
                            {
                                break;
                            }
                        }
                        return Ok(JsonView(true, "查询成功！", new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = _AirTicketAgent }));

                    }
                }
                else
                {
                    return Ok(JsonView(false, "暂无数据！"));
                }

            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }

        /// <summary>
        /// 代理出票合作方资料操作（Status:1.新增,2.修改）
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> OpAirTicketAgent(OpAirTicketAgentDto dto)
        {
            try
            {

                if (dto.Account == "")
                {
                    return Ok(JsonView(false, "请检查代理商账户是否填写！"));
                }
                if (dto.Bank == "")
                {
                    return Ok(JsonView(false, "请检查代理商银行是否填写！"));
                }
                if (dto.Name == "")
                {
                    return Ok(JsonView(false, "请检查代理商名称是否填写正确！"));
                }
                Result result = await _airTicketAgentRep.OpAirTicketAgent(dto);
                if (result.Code != 0)
                {
                    return Ok(JsonView(false, result.Msg));
                }
                return Ok(JsonView(true, result.Msg));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }

        /// <summary>
        /// 代理出票合作方资料操作（删除）
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> DelAirTicketAgent(DelBaseDto dto)
        {
            try
            {
                var res = await _airTicketAgentRep.SoftDeleteByIdAsync<Res_AirTicketAgent>(dto.Id.ToString(), dto.DeleteUserId);
                if (!res)
                {
                    return Ok(JsonView(false, "删除失败"));
                }
                return Ok(JsonView(true, "删除成功！"));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }

        #endregion

        #region 酒店资料数据
        /// <summary>
        /// 酒店信息查询
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> QueryHotelData(QueryHotelDataDto dto)
        {
            try
            {

                Result hotelData = await _hotelDataRep.QueryHotelData(dto);
                if (hotelData.Code == 0)
                {
                    return Ok(JsonView(true, "查询成功", hotelData.Data));
                }
                else
                {
                    return Ok(JsonView(false, hotelData.Msg));
                }

            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }


        }
        /// <summary>
        /// 酒店资料下拉框数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> QueryHotelDataSelect()
        {
            try
            {
                var HotelData = _carDataRep.QueryDto<Res_HotelData, QueryHotelDataSelect>().ToList();
                if (HotelData.Count == 0)
                {
                    return Ok(JsonView(false, "暂无数据！"));
                }
                HotelData.Add(new QueryHotelDataSelect { Id = 0, City = "全部" });
                HotelData = HotelData.Where((x, i) => HotelData.FindIndex(z => z.City == x.City && z.City != "") == i).ToList();
                HotelData = HotelData.OrderBy(x => x.Id).ToList();
                List<QueryHotelDataSelect> data = new List<QueryHotelDataSelect>();
                foreach (QueryHotelDataSelect Hotel in HotelData)
                {
                    if (!string.IsNullOrWhiteSpace(Hotel.City))
                    {
                        data.Add(Hotel);
                    }
                }
                return Ok(JsonView(true, "查询成功", data));
            }
            catch (Exception)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }
        /// <summary>
        /// 酒店资料操作（Status:1.新增,2.修改）
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> OperationHotelData(OperationHotelDto dto)
        {
            try
            {
                if (dto.City == "")
                {
                    return Ok(JsonView(false, "请检查酒店所在城市是否填写！"));
                }
                if (dto.Name == "")
                {
                    return Ok(JsonView(false, "请检查酒店名称是否填写！"));
                }
                if (dto.Address == "")
                {
                    return Ok(JsonView(false, "请检查酒店地址是否填写正确！"));
                }
                if (dto.Tel == "")
                {
                    return Ok(JsonView(false, "请检查酒店联系方式是否填写正确！"));
                }

                Result result = await _hotelDataRep.OperationHotelData(dto);
                if (result.Code != 0)
                {
                    return Ok(JsonView(false, result.Msg));
                }
                return Ok(JsonView(true, result.Msg));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }

        /// <summary>
        /// 酒店资料操作（删除）
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> DelHotelData(DelHotelDataDto dto)
        {
            try
            {
                var res = await _hotelDataRep.SoftDeleteByIdAsync<Res_HotelData>(dto.Id.ToString(), dto.DeleteUserId);
                if (!res)
                {
                    return Ok(JsonView(false, "删除失败"));
                }
                return Ok(JsonView(true, "删除成功！"));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }
        #endregion

        #region 签证费用资料
        /// <summary>
        /// 签证费用资料查询
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> QueryCountryFeeCost(DtoBase dto)
        {
            try
            {
                if (dto.PortType == 1)
                {
                    var CountryFee = _countryFeeRep.QueryDto<Res_CountryFeeCost, CountryFeeCostView>().ToList();
                    if (CountryFee.Count == 0)
                    {
                        return Ok(JsonView(false, "暂无数据！"));
                    }
                    CountryFee = CountryFee.OrderByDescending(s => s.CreateTime).ToList();
                    return Ok(JsonView(true, "查询成功", CountryFee));
                }
                else if (dto.PortType == 2)
                {
                    var CountryFee = _countryFeeRep.QueryDto<Res_CountryFeeCost, CountryFeeCostView>().ToList();
                    if (CountryFee.Count == 0)
                    {
                        return Ok(JsonView(false, "暂无数据！"));
                    }
                    CountryFee = CountryFee.OrderByDescending(s => s.CreateTime).ToList();
                    return Ok(JsonView(true, "查询成功", CountryFee));
                }
                else
                {
                    return Ok(JsonView(false, "请传入PortType参数！1:Web，2:Android,3:IOS"));
                }
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }

        }

        /// <summary>
        /// 签证费用资料操作（Status:1.新增,2.修改）
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> OperationCountryFeeCost(OperationCountryFeeCostDto dto)
        {
            try
            {
                if (dto.VisaContinent == "")
                {
                    return Ok(JsonView(false, "请检查州名是否填写！"));
                }
                if (dto.VisaCountry == "")
                {
                    return Ok(JsonView(false, "请检查国家名是否填写！"));
                }
                if (dto.VisaTime == "1")
                {
                    return Ok(JsonView(false, "请检一般签证时间是否填写正确！"));
                }
                if (dto.UrgentTime == "1")
                {
                    return Ok(JsonView(false, "请检加急时间是否填写正确！"));
                }
                if (dto.VisaPrice == 0)
                {
                    return Ok(JsonView(false, "请检查签证费用是否填写正确,小数点后可1到2位！"));
                }
                if (dto.VisaPrice == 1)
                {
                    return Ok(JsonView(false, "请检查签证加急费用是否填写正确,小数点后可1到2位！"));
                }
                Result result = await _countryFeeRep.OperationCountryFeeCost(dto);
                if (result.Code != 0)
                {
                    return Ok(JsonView(false, result.Msg));
                }
                return Ok(JsonView(true, result.Msg));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }

        }

        /// <summary>
        /// 签证费用资料操作（删除）
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> DelCountryFeeCost(DelCountryFeeCostDto dto)
        {
            try
            {
                var res = await _countryFeeRep.SoftDeleteByIdAsync<Res_CountryFeeCost>(dto.Id.ToString(), dto.DeleteUserId);
                if (!res)
                {
                    return Ok(JsonView(false, "删除失败"));
                }
                return Ok(JsonView(true, "删除成功！"));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }
        #endregion

        #region 物料信息、供应商维护
        #region 供应商
        /// <summary>
        /// 物料供应商查询
        /// </summary>
        /// <param name="paras">Json序列化</param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> PostSearchItemVendor(JsonDtoBase _jsonDto)
        {
            if (string.IsNullOrEmpty(_jsonDto.Paras))
            {
                return Ok(JsonView(false, "参数为空"));
            }

            Search_ResItemVendorDto _ItemVendorDto = System.Text.Json.JsonSerializer.Deserialize<Search_ResItemVendorDto>(_jsonDto.Paras);
            if (_ItemVendorDto != null)
            {
                if (_ItemVendorDto.SearchType == 2) //获取列表
                {
                    Res_ItemVendorListView rstList = _resItemInfoRep.GetVendorList(_ItemVendorDto);
                    return Ok(rstList);
                }
                else
                {
                    Res_ItemVendorView rstInfo = _resItemInfoRep.getVendorInfo(_ItemVendorDto);
                    return Ok(rstInfo);
                }
            }
            else
            {
                return Ok(JsonView(false, "参数反序列化失败"));
            }

            return Ok(JsonView(false));
        }

        /// <summary>
        /// 创建/编辑/删除供应商信息
        /// </summary>
        /// <param name="_dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> PostEditItemVendor(Edit_ResItemVendorDto _dto)
        {
            bool rst = false;

            if (_dto.EditType >= 0)
            {

                if (string.IsNullOrEmpty(_dto.VendorFullName))
                {
                    return Ok(JsonView(false, "全称未填写"));
                }

                if (string.IsNullOrEmpty(_dto.VendorLinker))
                {
                    return Ok(JsonView(false, "联系人未填写"));
                }

                if (string.IsNullOrEmpty(_dto.VendorMobile))
                {
                    return Ok(JsonView(false, "联系人手机号未填写"));
                }

                if (string.IsNullOrEmpty(_dto.BusRange))
                {
                    return Ok(JsonView(false, "经营范围未选择"));
                }

                if (_dto.EditType == 0)
                {
                    var checkEmpty = _resItemInfoRep.Query<Res_ItemVendor>(s => s.FullName == _dto.VendorFullName).First();
                    if (checkEmpty != null)
                    {
                        return Ok(JsonView(false, "已存在同名供应商"));
                    }

                    rst = await _resItemInfoRep.addVendorInfo(_dto);
                }
                else if (_dto.EditType == 1)
                {
                    if (_dto.VendorId > 0)
                    {
                        Res_ItemVendor _entity = _mapper.Map<Res_ItemVendor>(_dto);

                        rst = await _resItemInfoRep.updVendorInfo(_entity);
                    }
                    else
                    {
                        return Ok(JsonView(false, "供应商不存在"));
                    }
                }
            }
            else
            {
                if (_dto.VendorId < 1 || _dto.SysUserId < 1)
                {
                    return Ok(JsonView(false, "用户Id或供应商Id不存在"));
                }
                Res_ItemVendor _entity = _mapper.Map<Res_ItemVendor>(_dto);

                rst = await _resItemInfoRep.delVendorInfo(_entity);

            }

            return Ok(JsonView(rst));
        }

        #endregion
        #region 物料信息
        /// <summary>
        /// 物料信息查询
        /// </summary>
        /// <param name="paras">Json序列化</param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> PostSearchItemInfo(string paras)
        {
            if (string.IsNullOrEmpty(paras))
            {
                return Ok(JsonView(false, "参数为空"));
            }

            Search_ItemInfoDto _ItemInfoDto = System.Text.Json.JsonSerializer.Deserialize<Search_ItemInfoDto>(paras);
            if (_ItemInfoDto != null)
            {
                if (_ItemInfoDto.SearchType == 2) //获取列表
                {
                    Res_ItemInfoListView rstList = _resItemInfoRep.GetItemList(_ItemInfoDto);
                    return Ok(rstList);
                }
                else
                {
                    Res_ItemInfoView rstInfo = _resItemInfoRep.getItemInfo(_ItemInfoDto);
                    return Ok(rstInfo);
                }
            }
            else
            {
                return Ok(JsonView(false, "参数反序列化失败"));
            }

            return Ok(JsonView(false));
        }

        /// <summary>
        /// 创建/编辑/删除物料信息
        /// </summary>
        /// 
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> PostEditItemInfo(Edit_ResItemInfoDto _dto)
        {
            bool rst = false;

            if (_dto.EditType >= 0)
            {
                if (_dto.VendorId < 1)
                {
                    return Ok(JsonView(false, "未选择供应商"));
                }
                if (string.IsNullOrEmpty(_dto.ItemName))
                {
                    return Ok(JsonView(false, "物料名称为空"));
                }
                if (_dto.ItemTypeId < 1)
                {
                    return Ok(JsonView(false, "未选择物料类型"));
                }
                if (_dto.SysUserId < 1)
                {
                    return Ok(JsonView(false, "当前操作用户Id为空"));
                }
                if (_dto.CurrRate <= 0)
                {
                    return Ok(JsonView(false, "物料录入价格不能小于等于0"));
                }

                if (_dto.EditType == 0)
                {
                    //判断物料名称、类型、供应商全部重复
                    var checkEmpty = _resItemInfoRep.Query<Res_ItemDetailInfo>(s => s.ItemName == _dto.ItemName && s.ItemTypeId == _dto.ItemTypeId && s.VendorId == _dto.VendorId).First();
                    if (checkEmpty != null)
                    {
                        return Ok(JsonView(false, "已存在重复物料信息"));
                    }
                    Res_ItemDetailInfo _entity = _mapper.Map<Res_ItemDetailInfo>(_dto);
                    DateTime dtNow = DateTime.Now;
                    _entity.CreateUserId = _dto.SysUserId;
                    _entity.IsDel = 0;
                    _entity.MaxRate = _dto.CurrRate;
                    _entity.MaxDt = dtNow;
                    _entity.CurrRate = _dto.CurrRate;
                    _entity.CurrDt = dtNow;
                    _entity.MinRate = _dto.CurrRate;
                    _entity.MinDt = dtNow;

                    rst = await _resItemInfoRep.AddAsync<Res_ItemDetailInfo>(_entity) > 0;
                }
                else if (_dto.EditType == 1)
                {
                    if (_dto.ItemId > 0)
                    {
                        Res_ItemDetailInfo _entity = _mapper.Map<Res_ItemDetailInfo>(_dto);
                        _entity.Id = _dto.ItemId;

                        rst = await _resItemInfoRep.updItemInfo(_entity);
                    }
                    else
                    {
                        return Ok(JsonView(false, "供应商不存在"));
                    }
                }
            }
            else
            {
                if (_dto.ItemId < 1 || _dto.SysUserId < 1)
                {
                    return Ok(JsonView(false, "用户Id或物料信息Id不存在"));
                }
                Res_ItemDetailInfo _entity = _mapper.Map<Res_ItemDetailInfo>(_dto);

                rst = await _resItemInfoRep.delItemInfo(_entity);
            }

            return Ok(JsonView(rst));
        }
        #endregion
        #region 物料类型获取

        #endregion
        #endregion

        #region 备忘录
        /// <summary>
        /// 备忘录查询
        /// </summary>
        /// <param name="paras">Json序列化</param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> PostSearchMemo(JsonDtoBase _jsonDto)
        {
            if (string.IsNullOrEmpty(_jsonDto.Paras))
            {
                return Ok(JsonView(false, "参数为空"));
            }

            Search_ResMemoDto _memoDto = JsonConvert.DeserializeObject<Search_ResMemoDto>(_jsonDto.Paras);
            if (_memoDto != null)
            {
                if (_memoDto.SearchType == 2)
                {
                    //获取列表
                    string sqlWhere = string.Format(" Where IsDel=0 ");

                    #region SqlWhere

                    if (!string.IsNullOrEmpty(_memoDto.Abstracts))
                    {
                        sqlWhere += string.Format(@" And m.Abstracts Like '%{0}%' ", _memoDto.Abstracts);
                    }
                    if (!string.IsNullOrEmpty(_memoDto.Title))
                    {
                        sqlWhere += string.Format(@" And m.Title Like '%{0}%' ", _memoDto.Title);
                    }
                    if (_memoDto.ReadLevel > 0)
                    {
                        sqlWhere += string.Format(@" And m.ReadLevel = {0} ", _memoDto.ReadLevel);
                    }
                    #endregion

                    int currPIndex = (((_memoDto.PageIndex > 0) ? (_memoDto.PageIndex - 1) : 0) * _memoDto.PageSize) + 1;
                    int currPSize = (((_memoDto.PageIndex > 0) ? (_memoDto.PageIndex - 1) : 0) + 1) * _memoDto.PageSize;
                    string sql = string.Format(@" Select * From(Select ROW_NUMBER() Over(order By m.Id desc) as RowNumber,
m.Id as MemoId,d.DepName as DepartmentName,m.ReadLevel,m.Title,m.Abstracts,
m.LastedEditDt,m.LastedEditorId
From Res_Memo as m With(Nolock) Inner Join Sys_Users as u With(Nolock) On m.CreateUserId=u.Id
Inner Join Sys_Department as d With(Nolock) On u.DepId=d.Id {2}
) as tb Where tb.RowNumber Between {0} And {1} ", currPIndex, currPSize, sqlWhere);
                    Res_MemoListView rst = new Res_MemoListView();
                    rst.CurrPageIndex = currPIndex;
                    rst.CurrPageSize = currPSize;
                    List<Res_MemoView> dataSource = _carDataRep._sqlSugar.SqlQueryable<Res_MemoView>(sql).ToList();
                    Dictionary<int, string> userDic = new Dictionary<int, string>();

                    foreach (var item in dataSource)
                    {
                        if (userDic.ContainsKey(item.LastedEditorId))
                        {
                            item.LastedEditor = userDic[item.LastedEditorId];
                        }
                        else
                        {
                            Sys_Users _sysUser = _carDataRep.Query<Sys_Users>(s => s.Id == item.LastedEditorId).First();
                            userDic[item.LastedEditorId] = _sysUser.CnName;
                            item.LastedEditor = _sysUser.CnName;
                        }
                    }
                    rst.DataList = new List<Res_MemoView>(dataSource);

                    if (rst.DataList.Count > 0)
                    {
                        string sqlCount = string.Format(@" Select Id From Res_Memo as m With(Nolock) {0} ", sqlWhere);
                        int dataCount = _carDataRep._sqlSugar.SqlQueryable<Res_MemoInfo>(sqlCount).Count();
                        rst.DataCount = dataCount;
                    }
                    return Ok(JsonView(rst));
                }
                else
                {
                    //获取对象
                    string sqlSingle = string.Format(@" Select 
m.Id as MemoId,d.DepName as DepartmentName,m.ReadLevel,m.Title,m.Abstracts,
m.LastedEditDt,m.LastedEditor,m.MDFilePath
From Res_Memo as m With(Nolock) Inner Join Sys_Users as u With(Nolock) On m.CreateUserId=u.Id
Inner Join Sys_Department as d With(Nolock) On u.DepId=d.Id Where m.Id={0} ", _memoDto.MemoId);
                    Res_MemoView _result = _carDataRep._sqlSugar.SqlQueryable<Res_MemoView>(sqlSingle).First();
                    if (_result != null)
                    {
                        Sys_Users _sysUser = _carDataRep.Query<Sys_Users>(s => s.Id == _result.LastedEditorId).First();
                        _result.LastedEditor = _sysUser.CnName;
                        _result.MarkDownContent = new IOOperatorHelper().Read(_result.MDFilePath);
                        return Ok(JsonView(_result));
                    }
                }
            }
            else
            {
                return Ok(JsonView(false, "参数反序列化失败"));
            }




            return Ok(JsonView(false));
        }


        /// <summary>
        /// 创建/编辑/删除备忘录信息
        /// </summary>
        /// <param name="_dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> PostEditMemo(Edit_ResMemoDto _dto)
        {
            bool rst = false;
            if (_dto.SysUserId < 1)
            {
                return Ok(JsonView(false, "操作人失效"));
            }
            Sys_Users _sysUser = _resItemInfoRep.Query<Sys_Users>(s => s.Id == _dto.SysUserId).First();
            if (_sysUser == null)
            {
                return Ok(JsonView(false, "操作人失效02"));
            }

            if (_dto.EditType >= 0)
            {
                if (_dto.ReadLevel < 1)
                {
                    return Ok(JsonView(false, "未知的阅读等级"));
                }
                if (string.IsNullOrEmpty(_dto.Title.Trim()))
                {
                    return Ok(JsonView(false, "标题不能为空"));
                }
                if (string.IsNullOrEmpty(_dto.Content.Trim()))
                {
                    return Ok(JsonView(false, "正文内容不能为空"));
                }
                //新增备忘录
                DateTime dtNow = DateTime.Now;
                string dir = AppSettingsHelper.Get("MemoCurrPath");
                string fileName = dtNow.ToString("yyyyMMddHHmmss") + _dto.Title + ".md";
                string content = JsonConvert.SerializeObject(_dto.Content);
                if (_dto.EditType == 0)//新增
                {
                    string savePath = new IOOperatorHelper().Write_CoverFile(content, dir, fileName);

                    if (savePath.Length > 0)
                    {
                        Res_MemoInfo _insert = new Res_MemoInfo();
                        _insert.Abstracts = _dto.Abstracts;
                        _insert.Title = _dto.Title;
                        _insert.DepartmentId = _sysUser.DepId;
                        _insert.CreateUserId = _sysUser.Id;
                        _insert.LastedEditDt = dtNow;
                        _insert.LastedEditor = _sysUser.Id;
                        _insert.MDFilePath = savePath;
                        _insert.ReadLevel = _dto.ReadLevel;
                        _insert.Title = _dto.Title;
                        int result = await _resItemInfoRep.AddAsync(_insert);
                        return Ok(JsonView(result > 0));
                    }
                    else
                    {
                        return Ok(JsonView(false, "路径保存失败"));
                    }
                }
                else//修改
                {
                    if (_dto.MemoId < 1)
                    {
                        return Ok(JsonView(false, "MemoId不存在"));
                    }

                    Res_MemoInfo _source = _resItemInfoRep.Query<Res_MemoInfo>(s => s.Id == _dto.MemoId).First();
                    if (_source == null)
                    {
                        return Ok(JsonView(false, "MemoInfo不存在"));
                    }
                    //修改
                    string sourcePath = _source.MDFilePath;
                    string recycDir = AppSettingsHelper.Get("MemoRecycleBinPath");
                    new IOOperatorHelper().MoveFile(sourcePath, recycDir);
                    string savePath = new IOOperatorHelper().Write_CoverFile(content, dir, fileName);

                    if (savePath.Length > 0)
                    {
                        var result = await _resItemInfoRep._sqlSugar.Updateable<Res_MemoInfo>()
                                                                    .SetColumns(it => it.LastedEditDt == DateTime.Now)
                                                                    .SetColumns(it => it.LastedEditor == _sysUser.Id)
                                                                    .SetColumns(it => it.Abstracts == _dto.Abstracts)
                                                                    .SetColumns(it => it.MDFilePath == savePath)
                                                                    .SetColumns(it => it.ReadLevel == _dto.ReadLevel)
                                                                    .SetColumns(it => it.Title == _dto.Title)
                                                                    .Where(s => s.Id == _source.Id)
                                                                    .ExecuteCommandAsync();
                        return Ok(JsonView(result > 0));
                    }
                }
            }
            else
            {
                //删除
                if (_dto.MemoId < 1)
                {
                    return Ok(JsonView(false, "MemoId不存在"));
                }

                Res_MemoInfo _source = _resItemInfoRep.Query<Res_MemoInfo>(s => s.Id == _dto.MemoId).First();
                if (_source == null)
                {
                    return Ok(JsonView(false, "MemoInfo不存在"));
                }
                //修改
                string sourcePath = _source.MDFilePath;
                string recycDir = AppSettingsHelper.Get("MemoRecycleBinPath");
                new IOOperatorHelper().MoveFile(sourcePath, recycDir);

                var result = await _resItemInfoRep._sqlSugar.Updateable<Res_MemoInfo>()
                                                            .SetColumns(it => it.IsDel == 1)
                                                            .SetColumns(it => it.DeleteUserId == _sysUser.Id)
                                                            .SetColumns(it => it.DeleteTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
                                                            .Where(s => s.Id == _source.Id)
                                                            .ExecuteCommandAsync();
                return Ok(JsonView(result > 0));

            }

            return Ok(JsonView(rst));
        }

        #endregion

        #region 商邀资料
        /// <summary>
        /// 商邀资料查询
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> QueryInvitationOfficialActivityData(QueryInvitationOfficialActivityDataDto dto)
        {
            try
            {
                Result groupData = await _InvitationOfficialActivityDataRep.QueryInvitationOfficialActivityData(dto);
                if (groupData.Code != 0)
                {
                    return Ok(JsonView(false, groupData.Msg));
                }
                return Ok(JsonView(true, groupData.Msg, groupData.Data));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }
        /// <summary>
        /// 根据商邀资料Id查询信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> QueryInvitationOfficialActivityById(QueryInvitationOfficialActivityByIdDto dto)
        {
            try
            {
                Result groupData = await _InvitationOfficialActivityDataRep.QueryInvitationOfficialActivityById(dto);
                if (groupData.Code != 0)
                {
                    return Ok(JsonView(false, groupData.Msg));
                }
                return Ok(JsonView(true, groupData.Msg, groupData.Data));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }
        /// <summary>
        /// 商邀资料操作（Status:1.新增,2.修改）
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> OpInvitationOfficialActivity(OpInvitationOfficialActivityDto dto)
        {
            try
            {
                Result groupData = await _InvitationOfficialActivityDataRep.OpInvitationOfficialActivity(dto);
                if (groupData.Code != 0)
                {
                    return Ok(JsonView(false, groupData.Msg));
                }
                return Ok(JsonView(true, groupData.Msg, groupData.Data));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }
        /// <summary>
        /// 删除商邀资料信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> DelInvitationOfficialActivity(DelBaseDto dto)
        {
            try
            {
                var res = await _InvitationOfficialActivityDataRep.SoftDeleteByIdAsync<Res_InvitationOfficialActivityData>(dto.Id.ToString(), dto.DeleteUserId);
                if (!res)
                {
                    return Ok(JsonView(false, "删除失败"));
                }
                return Ok(JsonView(true, "删除成功！"));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }
        #endregion

        #region 公务出访
        /// <summary>
        ///  获取团组所有信息,绑定下拉框
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> GetGroupAllList(OfficialActivitiesByDiIdDto dto)
        {
            List<Grp_DelegationInfo> _DelegationInfos = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(a => a.IsDel == 0).OrderBy(a => a.CreateTime, OrderByType.Desc).ToList();
            List<Sys_SetData> data = await _sqlSugar.Queryable<Sys_SetData>().Where(a => a.IsDel == 0 && a.STid == 38).ToListAsync();
            List<Grp_DeleFile> _DeleFile = _sqlSugar.Queryable<Grp_DeleFile>().Where(a => a.Diid == dto.DiId && a.IsDel == 0 && a.Category == 970).ToList();
            return Ok(JsonView(true, "查询成功！", new { Delegation = _DelegationInfos, SetData = data, DeleFile = _DeleFile }));
        }
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> QueryOfficialActivitiesByDiId(OfficialActivitiesByDiIdDto dto)
        {
            try
            {
                Result groupData = await _officialActivitiesRep.QueryOfficialActivitiesByDiId(dto);
                if (groupData.Code != 0)
                {
                    return Ok(JsonView(false, groupData.Msg));
                }
                return Ok(JsonView(true, groupData.Msg, groupData.Data));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }
        /// <summary>
        /// 根据公务出访数据Id查询数据
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> QueryOfficialActivitiesById(OfficialActivitiesDiIdDto dto)
        {
            try
            {
                Result groupData = await _officialActivitiesRep.QueryOfficialActivitiesById(dto);
                if (groupData.Code != 0)
                {
                    return Ok(JsonView(false, groupData.Msg));
                }
                return Ok(JsonView(true, groupData.Msg, groupData.Data));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }
        /// <summary>
        /// 公务出访操作（Status:1.新增,2.修改）
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> OpOfficialActivities(OpOfficialActivitiesDto dto)
        {
            try
            {
                Result groupData = await _officialActivitiesRep.OpOfficialActivities(dto);
                if (groupData.Code != 0)
                {
                    return Ok(JsonView(false, groupData.Msg));
                }
                return Ok(JsonView(true, groupData.Msg, groupData.Data));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> UploadOfficialActivities(IFormFile file)
        {
            try
            {
                int Type = int.Parse(Request.Headers["Type"]);//1公务方简介，2公务活动图片，3发票
                int DiId = int.Parse(Request.Headers["DiId"]);
                int CreateUserId = int.Parse(Request.Headers["CreateUserId"]);
                if (file != null)
                {
                    var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
                    //文件名称
                    string projectFileName = file.FileName;
                    //上传的文件的路径
                    string filePath = "";
                    if (!Directory.Exists(fileDir))
                    {
                        Directory.CreateDirectory(fileDir);
                    }

                    //上传的文件的路径
                    filePath = fileDir + $@"\商邀相关文件\{projectFileName}";
                    using (FileStream fs = System.IO.File.Create(filePath))
                    {
                        file.CopyTo(fs);
                        fs.Flush();
                    }
                    Grp_DeleFile d = new Grp_DeleFile();
                    d.Diid = DiId;
                    d.Category = 970;
                    if (Type == 1) d.Kind = 1;
                    else if (Type == 2) d.Kind = 2;
                    else if (Type == 3) d.Kind = 3;
                    d.FileName = projectFileName;
                    d.FilePath = "";
                    d.CreateUserId = CreateUserId;
                    int id = await _sqlSugar.Insertable(d).ExecuteReturnIdentityAsync();

                    return Ok(JsonView(true, "上传成功！", projectFileName));
                }
                else
                {
                    return Ok(JsonView(false, "上传失败！"));
                }
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }
        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> DelloadOfficialActivities(DelBaseDto dto)
        {
            try
            {
                var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
                Grp_DeleFile _DeleFile = await _sqlSugar.Queryable<Grp_DeleFile>().FirstAsync(a => a.Id == dto.Id);
                if (_DeleFile != null)
                {
                    string fileName = _DeleFile.FileName;
                    string filePath = fileDir + "/团组增减款项相关文件/" + fileName;
                    // 删除该文件
                    System.IO.File.Delete(filePath);
                    int id = await _sqlSugar.Updateable<Grp_DeleFile>().Where(a => a.Id == dto.Id).SetColumns(a => new Grp_DeleFile { IsDel = 1, DeleteUserId = dto.DeleteUserId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }).ExecuteCommandAsync();
                    return Ok(JsonView(true, "取消文件成功！"));
                }
                else
                {
                    return Ok(JsonView(false, "取消文件失败！"));
                }
                
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }

        /// <summary>
        /// 删除公务出访信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> DelOfficialActivities(DelBaseDto dto)
        {
            try
            {
                var res = await _officialActivitiesRep.SoftDeleteByIdAsync<Res_OfficialActivities>(dto.Id.ToString(), dto.DeleteUserId);
                if (!res)
                {
                    return Ok(JsonView(false, "删除失败"));
                }
                return Ok(JsonView(true, "删除成功！"));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }
        #endregion

        #region 请示数据库
        /// <summary>
        /// 查询请示数据库初始化
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> QueryAskData(QueryAskDataDto dto)
        {
            try
            {
                Result groupData = await _askDataRep.QueryAskData(dto);
                if (groupData.Code != 0)
                {
                    return Ok(JsonView(false, groupData.Msg));
                }
                return Ok(JsonView(true, groupData.Msg, groupData.Data));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }

        /// <summary>
        /// 根据Id查询请示数据库单挑数据
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> QueryAskDataById(QueryAskDataByIdDto dto)
        {
            try
            {
                Res_AskData _AskData = await _sqlSugar.Queryable<Res_AskData>().FirstAsync(a => a.IsDel == 0 && a.Id == dto.id);
                if (_AskData==null)
                {
                    return Ok(JsonView(true, "暂无数据！", _AskData));
                }
                return Ok(JsonView(true, "查询成功！", _AskData));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }
        /// <summary>
        /// 请示数据库操作（Status:1.新增,2.修改）
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> OpAskData(OpAskDataDto dto)
        {
            try
            {
                Result groupData = await _askDataRep.OpAskData(dto);
                if (groupData.Code != 0)
                {
                    return Ok(JsonView(false, groupData.Msg));
                }
                return Ok(JsonView(true, groupData.Msg, groupData.Data));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }
        /// <summary>
        /// 删除请示资料信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> DelAskData(DelBaseDto dto)
        {
            try
            {
                var res = await _askDataRep.SoftDeleteByIdAsync<Res_AskData>(dto.Id.ToString(), dto.DeleteUserId);
                if (!res)
                {
                    return Ok(JsonView(false, "删除失败"));
                }
                return Ok(JsonView(true, "删除成功！"));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }


        /// <summary>
        /// 导出省外办请示
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> AskAdviceDerive(AskAdviceDerive dto)
        {
            try
            {
                string Air = "";//机票信息
                string Area = "";//城市
                string Area2 = "";//城市
                string ClientName = "";//人员
                string ClientName2 = "";//人员
                int ClientNumber =0;//总人数
                string Content = "";//行程安排
                string CountryAndDay = "";//各个国家待的天数
                string Destination = "";//此行目的
                string Destination2 = "";//此行目的
                string Duration = "";//出访时间
                int Durationdays = 0;//出访天数
                int Durationdays2 =0;//出访天数
                string Official = "";//对谁的邀请
                string Temp = "";//出访任务
                string VisitDate = "";//出访日期，多少号到多少号


                return Ok(JsonView(true, "导出成功！"));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }

        /// <summary>
        /// 导出市外办请示
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> AskCityDerive(AskAdviceDerive dto)
        {
            try
            {
              
                return Ok(JsonView(true, "导出成功！"));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }
        #endregion

        #region 机票黑屏代码
        /// <summary>
        /// 根据团组Id查询黑屏代码列表
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> QueryTicketBlackCodeByDiId(QueryTicketBlackCodeByDiIdDto dto)
        {
            try
            {
                Result groupData = await _ticketBlackCodeRep.QueryTicketBlackCodeByDiId(dto);
                if (groupData.Code != 0)
                {
                    return Ok(JsonView(false, groupData.Msg));
                }
                return Ok(JsonView(true, groupData.Msg, groupData.Data));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }
        /// <summary>
        /// 根据黑屏代码数据Id查询信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> QueryTicketBlackCodeById(QueryTicketBlackCodeByIdDto dto)
        {
            try
            {
                Result groupData = await _ticketBlackCodeRep.QueryTicketBlackCodeById(dto);
                if (groupData.Code != 0)
                {
                    return Ok(JsonView(false, groupData.Msg));
                }
                return Ok(JsonView(true, groupData.Msg, groupData.Data));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }
        /// <summary>
        /// 黑屏代码操作（Status:1.新增,2.修改）
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> OpTicketBlackCode(OpTicketBlackCodeDto dto)
        {
            try
            {
                Result groupData = await _ticketBlackCodeRep.OpTicketBlackCode(dto);
                if (groupData.Code != 0)
                {
                    return Ok(JsonView(false, groupData.Msg));
                }
                return Ok(JsonView(true, groupData.Msg, groupData.Data));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }

        /// <summary>
        /// 删除黑屏代码
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
        public async Task<IActionResult> DelTicketBlackCode(DelBaseDto dto)
        {
            try
            {
                var res = await _ticketBlackCodeRep.SoftDeleteByIdAsync<Air_TicketBlackCode>(dto.Id.ToString(), dto.DeleteUserId);
                if (!res)
                {
                    return Ok(JsonView(false, "删除失败"));
                }
                return Ok(JsonView(true, "删除成功！"));
            }
            catch (Exception ex)
            {
                return Ok(JsonView(false, "程序错误！"));
                throw;
            }
        }
        #endregion
    }


}

