Pārlūkot izejas kodu

新增机场三字码方法及dto、view

wangh 1 gadu atpakaļ
vecāks
revīzija
d0d5c48670

+ 12 - 0
OASystem/OASystem.Api/Controllers/BaseController.cs

@@ -60,6 +60,18 @@ public class ControllerBase : Microsoft.AspNetCore.Mvc.ControllerBase
             return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = msg };
         }
     }
+
+    protected virtual JsonView JsonView(bool s, string msg, object obj,int count)
+    {
+        if (s)
+        {
+            return new JsonView { Code = StatusCodes.Status200OK, Msg = msg, Data = obj, Count=count };
+        }
+        else
+        {
+            return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = msg };
+        }
+    }
     protected virtual JsonView JsonView(int code, string msg, object obj)
     {
         return new JsonView { Code = code, Msg = msg, Data = obj };

+ 81 - 8
OASystem/OASystem.Api/Controllers/ResourceController.cs

@@ -1,5 +1,8 @@
 
 
+using NetTaste;
+using System.Drawing.Printing;
+
 namespace OASystem.API.Controllers
 {
     /// <summary>
@@ -251,7 +254,7 @@ namespace OASystem.API.Controllers
         /// <returns></returns>
         [HttpPost]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
-        public async Task<IActionResult> LocalGuideOperation(LocalGuideOperationDto dto)
+        public async Task<IActionResult> OperationLocalGuide(LocalGuideOperationDto dto)
         {
             try
             {
@@ -277,7 +280,7 @@ namespace OASystem.API.Controllers
                 {
                     return Ok(JsonView(false, result.Msg));
                 }
-                return Ok(JsonView(true, result.Msg, new { Id = result.Data }));
+                return Ok(JsonView(true, result.Msg));
             }
             catch (Exception ex)
             {
@@ -292,7 +295,7 @@ namespace OASystem.API.Controllers
         /// <returns></returns>
         [HttpPost]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
-        public async Task<IActionResult> LocalGuideDel(LocalGuideDelDto dto)
+        public async Task<IActionResult> DelLocalGuide(LocalGuideDelDto dto)
         {
             try
             {
@@ -335,13 +338,18 @@ namespace OASystem.API.Controllers
                 }
                 else if (dto.PortType == 2)
                 {
-                    var ThreeCode = _localGuideDataRep.QueryDto<Res_ThreeCode, ThreeCodeView>().ToList();
-                    if (ThreeCode.Count == 0)
+                    //分页写法
+                    if (dto.PageIndex==0 || dto.PageSize==0)
                     {
-                        return Ok(JsonView(false, "暂无数据!"));
+                        return Ok(JsonView(false, "请传入PageIndex和PageSize参数"));
                     }
-                    ThreeCode = ThreeCode.OrderByDescending(s => s.CreateTime).ToList();
-                    return Ok(JsonView(true, "查询成功", ThreeCode));
+                    JsonView _ThreeCode = await _ThreeCodeRep.QuerThreeCode(dto.PageIndex, dto.PageSize);
+                    if (_ThreeCode.Code != 0)
+                    {
+                        return Ok(JsonView(false, _ThreeCode.Msg));
+                    }
+
+                    return Ok(_ThreeCode);
                 }
                 else
                 {
@@ -358,6 +366,71 @@ namespace OASystem.API.Controllers
 
         }
 
+        /// <summary>
+        /// 机场编辑,添加操作
+        /// </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
     }
 }

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

@@ -76,6 +76,7 @@ namespace OASystem.Domain.AutoMappers
 
             #region 机场三字码资料
             CreateMap<Res_ThreeCode, ThreeCodeView>();
+            CreateMap<ThreeCodeOperationDto, Res_ThreeCode>();
             #endregion
             #endregion
         }

+ 62 - 0
OASystem/OASystem.Domain/Dtos/Resource/ThreeCodeDto.cs

@@ -0,0 +1,62 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.Dtos.Resource
+{
+    public class ThreeCodeOperationDto
+    {
+        /// <summary>
+        /// 操作状态
+        /// 1 添加 
+        /// 2 修改 
+        /// </summary>
+        public int Status { get; set; }
+        /// <summary>
+        /// 主键Id
+        /// </summary>
+        public int Id { get; set; }
+        /// <summary>
+        /// 三字码
+        /// </summary>
+        public string Three { get; set; }
+        /// <summary>
+        /// 四字码
+        /// </summary>
+        public string Four { get; set; }
+        /// <summary>
+        /// 国家
+        /// </summary>
+        public string Country { get; set; }
+        /// <summary>
+        /// 城市
+        /// </summary>
+        public string City { get; set; }
+        /// <summary>
+        /// 机场
+        /// </summary>
+        public string AirPort { get; set; }
+        /// <summary>
+        /// 机场英文名
+        /// </summary>
+        public string AirPort_En { get; set; }
+
+        /// <summary>
+        /// 创建者Id
+        /// </summary>
+        public int CreateUserId { get; set; }
+       
+        /// <summary>
+        /// 备注
+        /// </summary>
+        public string Remark { get; set; }
+       
+    }
+    public class ThreeCodeDelDto
+    {
+        public int Id { get; set; }
+        public int DeleteUserId { get; set; }
+    }
+}

+ 13 - 0
OASystem/OASystem.Domain/ViewModels/Resource/HotelDataView.cs

@@ -0,0 +1,13 @@
+using OASystem.Domain.Entities.Resource;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.ViewModels.Resource
+{
+    public class HotelDataView:Res_HotelData
+    {
+    }
+}

+ 4 - 0
OASystem/OASystem.Infrastructure/Repositories/Resource/LocalGuideDataRepository.cs

@@ -74,6 +74,10 @@ namespace OASystem.Infrastructure.Repositories.Resource
                     }
                     result = new Result() { Code = 0, Msg = "修改成功!" };
                 }
+                else
+                {
+                    return  result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
+                }
             }
             catch (Exception ex)
             {

+ 98 - 0
OASystem/OASystem.Infrastructure/Repositories/Resource/ThreeCodeRepository.cs

@@ -1,6 +1,9 @@
 using AutoMapper;
+using OASystem.Domain;
+using OASystem.Domain.Dtos.Resource;
 using OASystem.Domain.Entities.Resource;
 using OASystem.Domain.ViewModels.Resource;
+using SqlSugar;
 
 namespace OASystem.Infrastructure.Repositories.Resource
 {
@@ -11,5 +14,100 @@ namespace OASystem.Infrastructure.Repositories.Resource
         {
             _mapper = mapper;
         }
+        /// <summary>
+        /// sqlSugar分页查询
+        /// </summary>
+        /// <param name="PageIndex"></param>
+        /// <param name="PageSize"></param>
+        /// <returns></returns>
+
+        public async Task<JsonView> QuerThreeCode(int PageIndex, int PageSize)
+        {
+            JsonView result = new JsonView();
+            try
+            {
+               
+                int totalCount = 0;
+                List<Res_ThreeCode> page = _sqlSugar.Queryable<Res_ThreeCode>().ToPageList(PageIndex, PageSize, ref totalCount);
+                if (page.Count != 0)
+                {
+                    result=new JsonView(){Code=200,Msg = "查询成功!",Data = page,Count = totalCount };
+                }
+                else
+                {
+                    result = new JsonView(){ Code = 400, Msg = "查询失败!", Data = page, Count = totalCount };
+                }
+            }
+            catch (Exception)
+            {
+                result = new JsonView() { Code = 400, Msg = "程序错误!", Data = null, Count = 0 };
+                throw;
+            }
+            
+           
+            return result;
+        }
+
+        /// <summary>
+        /// 添加、编辑操作
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        public async Task<Result> ThreeCodeOperation(ThreeCodeOperationDto dto)
+        {
+            Result result = new Result() { Code = -2, Msg = "未知错误" };
+            try
+            {
+                if (dto.Status == 1)//添加
+                {
+                    string selectSql = string.Format(@"select * from Res_ThreeCode where Three='{0}' and Country='{1}' and City='{2}' and AirPort='{3}'"
+                                                       , dto.Three, dto.Country, dto.City, dto.AirPort);
+                    var ThreeCode = await _sqlSugar.SqlQueryable<Res_ThreeCode>(selectSql).FirstAsync();//查询是否存在
+                    if (ThreeCode != null)
+                    {
+                        return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
+
+                    }
+                    else//不存在,可添加
+                    {
+                        Res_ThreeCode _ThreeCodeDto = _mapper.Map<Res_ThreeCode>(dto);
+                        int id = await AddAsyncReturnId(_ThreeCodeDto);
+                        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_ThreeCode
+                    {
+                        Three=dto.Three,
+                        Four=dto.Four,
+                        Country=dto.Country,
+                        City = dto.City,
+                        AirPort = dto.AirPort,
+                        AirPort_En = dto.AirPort_En,
+                        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;
+        }
     }
 }