using OASystem.API.OAMethodLib; using OASystem.Domain.Dtos.Resource; using OASystem.Domain.Entities.Groups; using OASystem.Infrastructure.Repositories.Groups; using System.Collections.Generic; namespace OASystem.API.Controllers { /// /// 资料相关 /// //[Authorize] [Route("api/[controller]/[action]")] public class ResourceController : ControllerBase { private readonly IMapper _mapper; 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; public ResourceController(IMapper mapper, IConfiguration config, CarDataRepository carDataRep, LocalGuideDataRepository localGuideDataRep, ThreeCodeRepository threeCodeRep, HotelDataRepository hotelDataRep, ResItemInfoRepository resItemInfoRep, SetDataRepository setDataRepository, CountryFeeRepository countryFeeRep, SetDataTypeRepository setDataTypeRep, AirTicketAgentRepository airTicketAgentRep, InvitationOfficialActivityDataRepository invitationOfficialActivityDataRep, OfficialActivitiesRepository officialActivitiesRep) { _mapper = mapper; _config = config; _carDataRep = carDataRep; _localGuideDataRep = localGuideDataRep; _ThreeCodeRep = threeCodeRep; _hotelDataRep = hotelDataRep; _resItemInfoRep = resItemInfoRep; _setDataRepository = setDataRepository; _countryFeeRep = countryFeeRep; _setDataTypeRep = setDataTypeRep; _airTicketAgentRep = airTicketAgentRep; _InvitationOfficialActivityDataRep = invitationOfficialActivityDataRep; _officialActivitiesRep = officialActivitiesRep; } #region 车公司资料板块 /// /// 车公司信息查询 /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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; } } /// /// 车公司资料下拉框数据 /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task QueryCarSelect() { try { var CarData = _carDataRep.QueryDto().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 data = new List(); 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; } } /// /// 车公司信息添加 /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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(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(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; } } /// /// 车公司信息修改 /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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; } } /// /// 车公司信息删除 /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task DelCarData(DelCarDataDto dto) { try { bool res = await _carDataRep.SoftDeleteByIdAsync(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 导游地接资料板块 /// /// 导游地接资料查询 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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; } } /// /// 导游地接资料下拉框数据 /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task QueryLocalGuideSelect() { try { var LocalGuide = _carDataRep.QueryDto().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 data = new List(); 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; } } /// /// 导游地接信息操作(Status:1.新增,2.修改) /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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; } } /// /// 导游地接信息操作(删除) /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task DelLocalGuide(LocalGuideDelDto dto) { try { var res = await _localGuideDataRep.SoftDeleteByIdAsync(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 机场三字码信息 /// /// 机场三字码查询 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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; } } /// /// 机场三字码数据城市下拉框数据 /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task QueryThreeCodeSelect() { try { var ThreeCode = _carDataRep.QueryDto().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 data = new List(); 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; } } /// /// 机场三字码资料操作(Status:1.新增,2.修改) /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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; } } /// /// 机场三字码资料操作(删除) /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task DelThreeCode(ThreeCodeDelDto dto) { try { var res = await _ThreeCodeRep.SoftDeleteByIdAsync(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 代理出票合作方资料 /// /// 代理出票合作方资料 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task QueryAirTicketAgent(DtoBase dto) { try { List res_AirTicketAgents = _airTicketAgentRep.Query(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 _AirTicketAgent = new List(); 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; } } /// /// 代理出票合作方资料操作(Status:1.新增,2.修改) /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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; } } /// /// 代理出票合作方资料操作(删除) /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task DelAirTicketAgent(DelBaseDto dto) { try { var res = await _airTicketAgentRep.SoftDeleteByIdAsync(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 酒店资料数据 /// /// 酒店信息查询 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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; } } /// /// 酒店资料下拉框数据 /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task QueryHotelDataSelect() { try { var HotelData = _carDataRep.QueryDto().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 data = new List(); 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; } } /// /// 酒店资料操作(Status:1.新增,2.修改) /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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; } } /// /// 酒店资料操作(删除) /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task DelHotelData(DelHotelDataDto dto) { try { var res = await _hotelDataRep.SoftDeleteByIdAsync(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 签证费用资料 /// /// 签证费用资料查询 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task QueryCountryFeeCost(DtoBase dto) { try { if (dto.PortType == 1) { var CountryFee = _countryFeeRep.QueryDto().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().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; } } /// /// 签证费用资料操作(Status:1.新增,2.修改) /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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; } } /// /// 签证费用资料操作(删除) /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task DelCountryFeeCost(DelCountryFeeCostDto dto) { try { var res = await _countryFeeRep.SoftDeleteByIdAsync(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 供应商 /// /// 物料供应商查询 /// /// Json序列化 /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task PostSearchItemVendor(JsonDtoBase _jsonDto) { if (string.IsNullOrEmpty(_jsonDto.Paras)) { return Ok(JsonView(false, "参数为空")); } Search_ResItemVendorDto _ItemVendorDto = System.Text.Json.JsonSerializer.Deserialize(_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)); } /// /// 创建/编辑/删除供应商信息 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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(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(_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(_dto); rst = await _resItemInfoRep.delVendorInfo(_entity); } return Ok(JsonView(rst)); } #endregion #region 物料信息 /// /// 物料信息查询 /// /// Json序列化 /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task PostSearchItemInfo(string paras) { if (string.IsNullOrEmpty(paras)) { return Ok(JsonView(false, "参数为空")); } Search_ItemInfoDto _ItemInfoDto = System.Text.Json.JsonSerializer.Deserialize(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)); } /// /// 创建/编辑/删除物料信息 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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(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(_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(_entity) > 0; } else if (_dto.EditType == 1) { if (_dto.ItemId > 0) { Res_ItemDetailInfo _entity = _mapper.Map(_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(_dto); rst = await _resItemInfoRep.delItemInfo(_entity); } return Ok(JsonView(rst)); } #endregion #region 物料类型获取 #endregion #endregion #region 备忘录 /// /// 备忘录查询 /// /// Json序列化 /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task PostSearchMemo(JsonDtoBase _jsonDto) { if (string.IsNullOrEmpty(_jsonDto.Paras)) { return Ok(JsonView(false, "参数为空")); } Search_ResMemoDto _memoDto = JsonConvert.DeserializeObject(_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 dataSource = _carDataRep._sqlSugar.SqlQueryable(sql).ToList(); Dictionary userDic = new Dictionary(); foreach (var item in dataSource) { if (userDic.ContainsKey(item.LastedEditorId)) { item.LastedEditor = userDic[item.LastedEditorId]; } else { Sys_Users _sysUser = _carDataRep.Query(s => s.Id == item.LastedEditorId).First(); userDic[item.LastedEditorId] = _sysUser.CnName; item.LastedEditor = _sysUser.CnName; } } rst.DataList = new List(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(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(sqlSingle).First(); if (_result != null) { Sys_Users _sysUser = _carDataRep.Query(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)); } /// /// 创建/编辑/删除备忘录信息 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task PostEditMemo(Edit_ResMemoDto _dto) { bool rst = false; if (_dto.SysUserId < 1) { return Ok(JsonView(false, "操作人失效")); } Sys_Users _sysUser = _resItemInfoRep.Query(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(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() .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(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() .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 商邀资料 /// /// 商邀资料查询 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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; } } /// /// 根据商邀资料Id查询信息 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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; } } /// /// 商邀资料操作(Status:1.新增,2.修改) /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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; } } /// /// 删除商邀资料信息 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task DelInvitationOfficialActivity(DelBaseDto dto) { try { var res = await _InvitationOfficialActivityDataRep.SoftDeleteByIdAsync(dto.Id.ToString(), dto.DeleteUserId); if (!res) { return Ok(JsonView(false, "删除失败")); } return Ok(JsonView(true, "删除成功!")); } catch (Exception ex) { return Ok(JsonView(false, "程序错误!")); throw; } } #region 公务出访 [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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; } } /// /// 根据公务出访数据Id查询数据 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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; } } /// /// 公务出访操作(Status:1.新增,2.修改) /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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; } } #endregion } #endregion }