소스 검색

新增酒店资料方法及相应的dto、view

wangh 2 년 전
부모
커밋
1b529fa61c

+ 122 - 6
OASystem/OASystem.Api/Controllers/ResourceController.cs

@@ -17,14 +17,16 @@ namespace OASystem.API.Controllers
         private readonly CarDataRepository _carDataRep;
         private readonly LocalGuideDataRepository _localGuideDataRep;
         private readonly ThreeCodeRepository _ThreeCodeRep;
+        private readonly HotelDataRepository _hotelDataRep;
 
-        public ResourceController(IMapper mapper, IConfiguration config, CarDataRepository carDataRep, LocalGuideDataRepository localGuideDataRep, ThreeCodeRepository threeCodeRep)
+        public ResourceController(IMapper mapper, IConfiguration config, CarDataRepository carDataRep, LocalGuideDataRepository localGuideDataRep, ThreeCodeRepository threeCodeRep, HotelDataRepository hotelDataRep)
         {
             _mapper = mapper;
             _config = config;
             _carDataRep = carDataRep;
             _localGuideDataRep = localGuideDataRep;
             _ThreeCodeRep = threeCodeRep;
+            _hotelDataRep = hotelDataRep;
         }
         #region 车公司资料板块
 
@@ -34,7 +36,7 @@ namespace OASystem.API.Controllers
         /// <returns></returns>
         [HttpPost]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
-        public async Task<IActionResult> QuerCarData(DtoBase dto)
+        public async Task<IActionResult> QuertCarData(DtoBase dto)
         {
             try
             {
@@ -209,7 +211,7 @@ namespace OASystem.API.Controllers
         /// <returns></returns>
         [HttpPost]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
-        public async Task<IActionResult> QuerLocalGuide(DtoBase dto)
+        public async Task<IActionResult> QueryLocalGuide(DtoBase dto)
         {
             try
             {
@@ -249,7 +251,7 @@ namespace OASystem.API.Controllers
         }
 
         /// <summary>
-        /// 导游地接信息操作(增改)
+        /// 导游地接信息操作(Status:1.新,2.修改)
         /// </summary>
         /// <returns></returns>
         [HttpPost]
@@ -322,7 +324,7 @@ namespace OASystem.API.Controllers
         /// <returns></returns>
         [HttpPost]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
-        public async Task<IActionResult> QuerThreeCode(DtoBase dto)
+        public async Task<IActionResult> QueryThreeCode(DtoBase dto)
         {
             try
             {
@@ -367,7 +369,7 @@ namespace OASystem.API.Controllers
         }
 
         /// <summary>
-        /// 机场编辑,添加操作
+        /// 机场三字码资料操作(Status:1.新增,2.修改)
         /// </summary>
         /// <param name="dto"></param>
         /// <returns></returns>
@@ -432,5 +434,119 @@ namespace OASystem.API.Controllers
             }
         }
         #endregion
+
+        #region 酒店资料数据
+        /// <summary>
+        /// 酒店信息查询
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> QueryHotelData(DtoBase dto)
+        {
+            try
+            {
+                if (dto.PortType == 1)
+                {
+                    var HotelData = _localGuideDataRep.QueryDto<Res_HotelData, HotelDataView>().ToList();
+                    if (HotelData.Count == 0)
+                    {
+                        return Ok(JsonView(false, "暂无数据!"));
+                    }
+                    HotelData = HotelData.OrderByDescending(s => s.CreateTime).ToList();
+                    return Ok(JsonView(true, "查询成功", HotelData));
+                }
+                else if (dto.PortType == 2)
+                {
+                    var HotelData = _localGuideDataRep.QueryDto<Res_HotelData, HotelDataView>().ToList();
+                    if (HotelData.Count == 0)
+                    {
+                        return Ok(JsonView(false, "暂无数据!"));
+                    }
+                    HotelData = HotelData.OrderByDescending(s => s.CreateTime).ToList();
+                    return Ok(JsonView(true, "查询成功", HotelData));
+                }
+                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> OperationHotelData(OperationHotelData 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 _ThreeCodeRep.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
     }
 }

+ 1 - 1
OASystem/OASystem.Api/Controllers/SystemController.cs

@@ -137,7 +137,7 @@ namespace OASystem.API.Controllers
         /// <returns></returns>
         [HttpPost]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
-        public async Task<IActionResult> QuerSetData(SetDataDto dto)
+        public async Task<IActionResult> QuerySetData(SetDataDto dto)
         {
             try
             {

+ 3 - 0
OASystem/OASystem.Domain/AutoMappers/_baseMappingProfile.cs

@@ -78,6 +78,9 @@ namespace OASystem.Domain.AutoMappers
             CreateMap<Res_ThreeCode, ThreeCodeView>();
             CreateMap<ThreeCodeOperationDto, Res_ThreeCode>();
             #endregion
+            #region 酒店资料数据
+            CreateMap<Res_HotelData, HotelDataView>();
+            #endregion
             #endregion
         }
     }

+ 75 - 0
OASystem/OASystem.Domain/Dtos/Resource/HotelDataDto.cs

@@ -0,0 +1,75 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.Dtos.Resource
+{
+    /// <summary>
+    /// 酒店资料操作(增删)
+    /// </summary>
+    public class OperationHotelData
+    {
+        /// <summary>
+        /// 操作状态
+        /// 1 添加 
+        /// 2 修改 
+        /// </summary>
+        public int Status { get; set; }
+        /// <summary>
+        /// 编号
+        /// </summary>
+        public int Id { get; set; }
+        /// <summary>
+        /// 所在城市
+        /// </summary>
+        public string City { get; set; }
+        /// <summary>
+        /// 酒店名称
+        /// </summary>
+        public string Name { get; set; }
+        /// <summary>
+        /// 酒店星级
+        /// </summary>
+        public string Level { get; set; }
+        /// <summary>
+        /// 酒店地址
+        /// </summary>
+        public string Address { get; set; }
+        /// <summary>
+        /// 酒店电话
+        /// </summary>
+        public string Tel { get; set; }
+        /// <summary>
+        /// 酒店传真
+        /// </summary>
+        public string Fax { get; set; }
+        /// <summary>
+        /// 联系人
+        /// </summary>
+        public string Contact { get; set; }
+        /// <summary>
+        /// 联系方式
+        /// </summary>
+        public string ContactPhone { get; set; }
+        /// <summary>
+        /// 酒店其他信息
+        /// </summary>
+        public string OtherInformation { get; set; }
+        /// <summary>
+        /// 创建者Id
+        /// </summary>
+        public int CreateUserId { get; set; }
+        /// <summary>
+        /// 备注
+        /// </summary>
+        public string Remark { get; set; }
+       
+    }
+    public class DelHotelDataDto
+    {
+        public int Id { get; set; }
+        public int DeleteUserId { get; set; }
+    }
+}

+ 82 - 0
OASystem/OASystem.Infrastructure/Repositories/Resource/HotelDataRepository.cs

@@ -0,0 +1,82 @@
+using AutoMapper;
+using OASystem.Domain;
+using OASystem.Domain.Dtos.Resource;
+using OASystem.Domain.Entities.Resource;
+using OASystem.Domain.ViewModels.Resource;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Infrastructure.Repositories.Resource
+{
+    public class HotelDataRepository:BaseRepository<Res_HotelData,HotelDataView>
+    {
+        private readonly IMapper _mapper;
+        public HotelDataRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
+        {
+            _mapper= mapper;
+        }
+
+        public async Task<Result> OperationHotelData(OperationHotelData dto)
+        {
+            Result result = new Result() { Code = -2, Msg = "未知错误" };
+            try
+            {
+                if (dto.Status == 1)//添加
+                {
+                    string selectSql = string.Format(@"select * from Res_HotelData where Name='{0}'"
+                                                       , dto.Name);
+                    var HotelData = await _sqlSugar.SqlQueryable<Res_HotelData>(selectSql).FirstAsync();//查询是否存在
+                    if (HotelData != null)
+                    {
+                        return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
+
+                    }
+                    else//不存在,可添加
+                    {
+                        Res_HotelData _HotelDataDto = _mapper.Map<Res_HotelData>(dto);
+                        int id = await AddAsyncReturnId(_HotelDataDto);
+                        if (id == 0)
+                        {
+                            return result = new Result() { Code = -1, Msg = "添加失败!" };
+
+                        }
+                        result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
+                    }
+                }
+                else if (dto.Status == 2)//修改
+                {
+                    bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Res_HotelData
+                    {
+                        City = dto.City,
+                        Name = dto.Name,
+                        Level = dto.Level,
+                        Address = dto.Address,
+                        Tel = dto.Tel,
+                        Fax = dto.Fax,
+                        Contact = dto.Contact,
+                        ContactPhone = dto.ContactPhone,
+                        OtherInformation = dto.OtherInformation,
+                        Remark = dto.Remark,
+                    });
+                    if (!res)
+                    {
+                        return result = new Result() { Code = -1, Msg = "修改失败!" };
+                    }
+                    result = new Result() { Code = 0, Msg = "修改成功!" };
+                }
+                else
+                {
+                    return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
+                }
+            }
+            catch (Exception ex)
+            {
+                return result = new Result() { Code = -2, Msg = "程序错误!" };
+            }
+            return result;
+        }
+    }
+}