Browse Source

团组信息 新增 团组列表筛选分页api PostGroupNameScreen

leiy 9 months ago
parent
commit
b730baa68a

+ 27 - 0
OASystem/OASystem.Api/Controllers/BusinessController.cs

@@ -1,4 +1,5 @@
 using Microsoft.AspNetCore.Mvc;
+using NetTaste;
 using NPOI.SS.Formula.Functions;
 using OASystem.API.OAMethodLib;
 using OASystem.API.OAMethodLib.ALiYun;
@@ -99,6 +100,32 @@ namespace OASystem.API.Controllers
             return Ok(JsonView(groupData.Data, groupData.Data.Count));
         }
 
+
+        /// <summary>
+        /// 团组信息 团组名称 Page List
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> PostGroupNameScreen(GroupNameScreenDto dto)
+        {
+            //验证
+            var validator = new GroupNameScreenDtoFoaValidator();
+            var validatorRes = await validator.ValidateAsync(dto);
+            if (!validatorRes.IsValid)
+            {
+                var errors = new StringBuilder();
+                foreach (var error in validatorRes.Errors) errors.AppendLine(error.ErrorMessage);
+                return Ok(JsonView(false,errors.ToString()));
+            }
+
+            //获取数据
+            var res = await _groupRep.GetGroupNameList(dto.PortType, dto.PageIndex, dto.PageSize, dto.groupName, dto.userId);
+
+            return Ok(res);
+        }
+
         /// <summary>
         /// 获取团组指向分类
         /// </summary>

+ 3 - 3
OASystem/OASystem.Api/Controllers/FinancialController.cs

@@ -4057,7 +4057,7 @@ Group by PriceType ", dto.diId);
 
                     for (int j = 0; j < dt.Rows.Count; j++)//遍历行
                     {
-                        DataRow dr = dt.NewRow(); //获取每一行的数据
+                        DataRow dr = dt1.NewRow(); //获取每一行的数据
                         dr["TradingDay"] = dt.Rows[j][0].ToString();
                         dr["TallyDay"] = dt.Rows[j][1].ToString();
                         dr["TransactionDesc"] = dt.Rows[j][2].ToString();
@@ -4084,7 +4084,7 @@ Group by PriceType ", dto.diId);
                     dt1.DefaultView.Sort = "TradingDay asc";
                     dt1 = dt1.DefaultView.ToTable();
 
-                    foreach (DataRow item in dt.Rows)
+                    foreach (DataRow item in dt1.Rows)
                     {
                         if (item["TradingDay"] == "" && item["RMBMoney"] == "")
                         {
@@ -4168,7 +4168,7 @@ Group by PriceType ", dto.diId);
                     Dictionary<string, object> pairs = new Dictionary<string, object>();
                     List<DataTable> datas = new List<DataTable>();
                     datas.Add(dt1);
-                    url = AsposeHelper.ExpertExcelToModel("信用卡对账模板-招行卡.xls", "TB", fileName1, pairs, datas);
+                    url = AsposeHelper.ExpertExcelToModel("信用卡对账模板-招行卡.xls", "CreditCardBill", fileName1, pairs, datas);
 
 
                     #endregion

+ 82 - 0
OASystem/OASystem.Api/Middlewares/ExceptionHandlingMiddleware.cs

@@ -0,0 +1,82 @@
+using Microsoft.AspNetCore.Http;
+
+namespace OASystem.API.Middlewares
+{
+    /// <summary>
+    /// 全局异常捕获中间件
+    /// </summary>
+    public class ExceptionHandlingMiddleware
+    {
+        private readonly RequestDelegate _next;  // 用来处理上下文请求
+        private readonly ILogger<ExceptionHandlingMiddleware> _logger;
+
+        /// <summary>
+        /// 初始化
+        /// </summary>
+        /// <param name="next"></param>
+        /// <param name="logger"></param>
+        public ExceptionHandlingMiddleware(RequestDelegate next, ILogger<ExceptionHandlingMiddleware> logger)
+        {
+            _next = next;
+            _logger = logger;
+        }
+
+        /// <summary>
+        /// 执行中间件
+        /// </summary>
+        /// <param name="httpContext"></param>
+        /// <returns></returns>
+        public async Task InvokeAsync(HttpContext httpContext)
+        {
+            try
+            {
+                await _next(httpContext); //要么在中间件中处理,要么被传递到下一个中间件中去
+            }
+            catch (Exception ex)
+            {
+                await HandleExceptionAsync(httpContext, ex); // 捕获异常了 在HandleExceptionAsync中处理
+            }
+        }
+
+        /// <summary>
+        /// 异步处理异常
+        /// </summary>
+        /// <param name="context"></param>
+        /// <param name="exception"></param>
+        /// <returns></returns>
+        private async Task HandleExceptionAsync(HttpContext context, Exception exception)
+        {
+            context.Response.ContentType = "application/json";  // 返回json 类型
+            var response = context.Response;
+            var errorResponse = new JsonView
+            {
+                Code = StatusCodes.Status400BadRequest,
+                Data = ""
+            };  // 自定义的异常错误信息类型
+            switch (exception)
+            {
+                case ApplicationException ex:
+                    if (ex.Message.Contains("Invalid token"))
+                    {
+                        response.StatusCode = StatusCodes.Status403Forbidden;
+                        errorResponse.Msg = ex.Message;
+                        break;
+                    }
+                    response.StatusCode = StatusCodes.Status400BadRequest;
+                    errorResponse.Msg = ex.Message;
+                    break;
+                case KeyNotFoundException ex:
+                    response.StatusCode = StatusCodes.Status404NotFound;
+                    errorResponse.Msg = ex.Message;
+                    break;
+                default:
+                    response.StatusCode = StatusCodes.Status500InternalServerError;
+                    errorResponse.Msg = "Internal Server errors. Check Logs!";
+                    break;
+            }
+            _logger.LogError(exception.Message);
+            var result = JsonConvert.SerializeObject(errorResponse);
+            await context.Response.WriteAsync(result);
+        }
+    }
+}

+ 3 - 0
OASystem/OASystem.Api/Program.cs

@@ -28,6 +28,7 @@ using OASystem.API.OAMethodLib.Hub.HubClients;
 using Microsoft.Extensions.Options;
 using Microsoft.AspNetCore.Identity;
 using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
+using OASystem.API.Middlewares;
 
     var builder = WebApplication.CreateBuilder(args);
 var basePath = AppContext.BaseDirectory;
@@ -316,6 +317,8 @@ if (!app.Environment.IsDevelopment())
 }
 app.UseStaticFiles();
 
+app.UseMiddleware<ExceptionHandlingMiddleware>();
+
 app.UseRouting();
 app.UseCors("Cors");  //Cors
 

+ 24 - 1
OASystem/OASystem.Domain/Dtos/Groups/GroupListDto.cs

@@ -1,4 +1,5 @@
-using Newtonsoft.Json;
+using FluentValidation;
+using Newtonsoft.Json;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
@@ -249,6 +250,28 @@ namespace OASystem.Domain.Dtos.Groups
 
     }
 
+    public class GroupNameScreenDto : DtoBase
+    {
+        public string groupName { get; set; } = "";
+
+        public int userId { get; set; } = -1;
+    }
+
+    #region GroupNameScreenDto 验证
+
+    public class GroupNameScreenDtoFoaValidator : AbstractValidator<GroupNameScreenDto>
+    {
+        public GroupNameScreenDtoFoaValidator() {
+            RuleFor(it => it.PortType)
+                .NotNull()
+                .NotEmpty()
+                .InclusiveBetween(1, 3)
+                .WithMessage(MsgTips.Port);
+        }
+    }
+
+    #endregion
+
     /// <summary>
     /// 
     /// </summary>

+ 1 - 1
OASystem/OASystem.Domain/Result.cs

@@ -60,7 +60,7 @@ namespace OASystem.Domain
         /// <summary>
         /// UserId错误消息提示
         /// </summary>
-        public static string UserId = "请检查状态UserId是否正确!";
+        public static string UserId = "请检查UserId是否正确!";
     }
 
    

+ 5 - 0
OASystem/OASystem.Domain/ViewModels/Groups/DelegationInfoView.cs

@@ -530,6 +530,11 @@ namespace OASystem.Domain.ViewModels.Groups
         public string GroupName { get; set; }
     }
 
+    public class GroupNamePageView : GroupNameView
+    {
+        public int RowNumber { get; set; }
+    }
+
     /// <summary>
     /// 根据团组ID 查询客户
     /// </summary>

+ 40 - 0
OASystem/OASystem.Infrastructure/Repositories/Groups/DelegationInfoRepository.cs

@@ -902,6 +902,46 @@ namespace OASystem.Infrastructure.Repositories.Groups
             return result;
         }
 
+        //PostGroupNameScreen
+
+        /// <summary>
+        /// 获取接团名称 PAge List
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        public async Task<JsonView> GetGroupNameList(int portType,int pageIndex,int pageSize, string groupName,int userId)
+        {
+            var _res = new JsonView() {  Code = 400 ,  Msg = MsgTips.Fail };
+
+            if (portType == 1 || portType == 2 || portType == 3) //web
+            {
+                string sqlWhere = "";
+                if (!string.IsNullOrEmpty(groupName))
+                {
+                    sqlWhere += string.Format($@"And TeamName Like '%{groupName}%'");
+                }
+
+                if (userId != -1)
+                {
+                    sqlWhere += string.Format($@"And JietuanOperator = {userId}");
+                }
+
+
+                string sql = string.Format($@"Select ROW_NUMBER()Over(Order By Id Desc) as RowNumber,Id,TeamName GroupName From  Grp_DelegationInfo 
+                                             Where IsDel = 0 {sqlWhere}");
+
+                RefAsync<int> total = 0;
+                var groupNamePageData = await _sqlSugar.SqlQueryable<GroupNamePageView>(sql).ToPageListAsync(pageIndex, pageSize, total);
+
+                _res.Code = 200;
+                _res.Data = groupNamePageData;
+                _res.Msg = MsgTips.Succeed;
+                _res.Count = total;
+            }
+            return _res;
+        }
+
+
         /// <summary>
         /// 获取接团名称List And 签证国别
         /// </summary>