luocaiyang 3 år sedan
förälder
incheckning
558bad8dc0

+ 53 - 10
wispro.sp.api/Controllers/PerformanceItemController.cs

@@ -1,13 +1,17 @@
-using Microsoft.AspNetCore.Authorization;
+using DynamicExpresso;
+using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.EntityFrameworkCore;
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Linq.Expressions;
 using System.Threading.Tasks;
+using wispro.sp.api.Utility;
 using wispro.sp.entity;
 using wispro.sp.share;
+using wispro.sp.utility;
 
 namespace wispro.sp.api.Controllers
 {
@@ -264,7 +268,7 @@ namespace wispro.sp.api.Controllers
         /// <param name="userid">用户id</param>
         /// <param name="type">获取类型;0:处理中;1:所有;4:已归档</param>
         /// <returns></returns>
-        public ListApiResponse<PerformanceItem> GetMyList(int userid, int type,int pageIndex=1,int pageSize = 5)
+        public ListApiResponse<PerformanceItem> GetMyList(int userid, int type,int pageIndex=1,int pageSize = 10)
         {
             ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
             var results = Context.PerformanceItems
@@ -498,23 +502,62 @@ namespace wispro.sp.api.Controllers
 
             
         }
+
+        [HttpPost]
         public ListApiResponse<PerformanceItem> QueryFilter(QueryFilter queryFilter)
         {
 
             ListApiResponse<PerformanceItem> ret = new ListApiResponse<PerformanceItem>();
-            ret.TotalCount = Context.PerformanceItems.Count<PerformanceItem>();
 
-            List<PerformanceItem> retList = Context.PerformanceItems
-                .Where<PerformanceItem>(s => (s.ItemStaffs
-                    .Where<ItemStaff>(iStaff => iStaff.DoPerson.Name == queryFilter.PersonName) .Count() > 0 || s.Reviewer.Name == queryFilter.PersonName) && s.CalMonth.Month == queryFilter.Month && s.CalMonth.Year == queryFilter.Year)
+            string strExpress = "";
+            if (queryFilter.userId > 0)
+            {
+                strExpress = $"(s.ItemStaffs.Where<ItemStaff>(iStaff => iStaff.DoPerson.Id == {queryFilter.userId}).Count() > 0))";
+            }
+
+            if (string.IsNullOrEmpty(strExpress))
+            {
+                strExpress = $"{strExpress} && s.CalMonth.Status == {Convert.ToInt32(queryFilter.jxType)}";
+            }
+
+            
+
+            var interpreter = new Interpreter();
+            Expression<Func<PerformanceItem, bool>> dynamicWhere = interpreter.ParseAsExpression<Func<PerformanceItem, bool>>(strExpress, "s");
+
+            var response = Context.PerformanceItems.Where<PerformanceItem>(dynamicWhere);
+                
+
+
+            response = response.OrderConditions<PerformanceItem>(queryFilter.Sorts);
+            ret.TotalCount = response.Count();
+
+            var retList = response
                 .Include(pi => pi.ItemStaffs).ThenInclude(iStaff => iStaff.DoPerson)
                 .Include(pi => pi.Reviewer)
                 .Include(pi => pi.Customer)
-                
-                .OrderByDescending(o => o.Id)
-                .Skip<PerformanceItem>((queryFilter.pageIndex - 1) * queryFilter.pageSize).Take(queryFilter.pageSize).ToList<PerformanceItem>();
+                .Skip<PerformanceItem>((queryFilter.PageIndex - 1) * queryFilter.PageSize).Take(queryFilter.PageSize).ToList<PerformanceItem>();
+
+
+            #region 将某些属性设为null,避免循环取值造成返回json过大
+            foreach (PerformanceItem item in retList)
+            {
+                foreach (ItemStaff itemStaff in item.ItemStaffs)
+                {
+                    itemStaff.DoPerson.ItemStaffs = null;
+                    itemStaff.DoPerson.ReviewerItems = null;
+                    itemStaff.Item = null;
+                }
+
+                item.Reviewer.ReviewerItems = null;
+                item.Reviewer.Customers = null;
+                item.Reviewer.ItemStaffs = null;
+
+                item.Customer.PerformanceItems = null;
+                item.CalMonth.PerformanceItems = null;
+            }
+            #endregion
 
-            //Context.PerformanceItems.Where<PerformanceItem>(p=>p.ItemStaffs.Where<ItemStaff>)
             ret.Results = retList;
 
             return ret;

+ 14 - 7
wispro.sp.share/QueryFilter.cs

@@ -1,22 +1,29 @@
-using System;
+using AntDesign.TableModels;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using wispro.sp.entity;
+using wispro.sp.utility;
 
 namespace wispro.sp.share
 {
     public class QueryFilter
     {
-        public int pageIndex { get; set; }
-        public int pageSize { get; set; }
+        public int userId { get; set; }
 
-        public string PersonName { get; set; }
+        public ConditionTreeNode ConditionTree { get; set; }
 
-        public int? Year { get; set; }
+        public jxType jxType { get; set; }
 
-        public int? Month { get; set; }
+        public IList<OrderField> Sorts { get; set; }
 
-        
+        public int PageSize { get; set; }
+
+        public int PageIndex { get; set; }
     }
+
+    
+
 }

+ 1 - 0
wispro.sp.share/wispro.sp.share.csproj

@@ -10,6 +10,7 @@
   </ItemGroup>
 
   <ItemGroup>
+    <ProjectReference Include="..\wispro.sp.utility\wispro.sp.utility.csproj" />
     <ProjectReference Include="..\wospro.sp.entity\wispro.sp.entity.csproj" />
   </ItemGroup>
 

+ 107 - 0
wispro.sp.utility/EFCoreExt.cs

@@ -0,0 +1,107 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace wispro.sp.utility
+{
+    public class ConditionTreeNode
+    {
+        public ConditionTreeNode Right { get; set; }
+        public ConditionTreeNode Left { get; set; }
+    }
+
+    public class OperateNode : ConditionTreeNode
+    {
+        public LogicEnum Operator { get; set; }
+
+    }
+
+    public class FieldConditionNode : ConditionTreeNode
+    {
+        public FieldCondition FieldCondition { get; set; }
+    }
+
+    public class OrderField { 
+        /// <summary>
+        /// 排序栏位
+        /// </summary>
+        public string FieldName { get; set; }
+
+        /// <summary>
+        /// 排序 0:顺序;1:倒序
+        /// </summary>
+        public int Sort { get; set; }
+    }
+    public class FieldCondition
+    {
+        /// <summary>
+        /// 字段名称
+        /// </summary>
+        public string FieldName { get; set; }
+        /// <summary>
+        /// 值
+        /// </summary>
+        public string Value { get; set; }
+        /// <summary>
+        /// 值类型
+        /// </summary>
+        public string ValueType { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public OperatorEnum Operator { get; set; }
+    }
+
+    public enum OperatorEnum
+    {
+        Contains,
+        Equal,
+        Greater,
+        GreaterEqual,
+        Less,
+        LessEqual,
+        NotEqual,
+        In,
+        Between,
+        StartsWith,
+        EndWith,
+        NotContains
+    }
+
+    public enum LogicEnum
+    {
+        And,
+        Or
+    }
+
+    public static class EFCoreExt
+    {
+        public static IQueryable<T> OrderConditions<T>(this IQueryable<T> query, IList<OrderField> orderConditions)
+        {
+            foreach (var orderinfo in orderConditions)
+            {
+                var t = typeof(T);
+                var propertyInfo = t.GetProperty(orderinfo.FieldName);
+                var parameter = Expression.Parameter(t);
+                Expression propertySelector = Expression.Property(parameter, propertyInfo);
+
+                var orderby = Expression.Lambda<Func<T, object>>(propertySelector, parameter);
+                if (orderinfo.Sort == 1)
+                    query = query.OrderByDescending(orderby);
+                else
+                    query = query.OrderBy(orderby);
+
+            }
+            return query;
+        }
+
+        public static IQueryable<T> Pager<T>(this IQueryable<T> query, int pageindex, int pagesize, out int itemCount)
+        {
+            itemCount = query.Count();
+            return query.Skip((pageindex - 1) * pagesize).Take(pagesize);
+        }
+    }
+}

+ 5 - 1
wispro.sp.utility/wispro.sp.utility.csproj

@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
     <TargetFramework>net5.0</TargetFramework>
@@ -6,6 +6,10 @@
   </PropertyGroup>
 
   <ItemGroup>
+    <Compile Remove="Linq.Easy.cs" />
+  </ItemGroup>
+
+  <ItemGroup>
     <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.10" />
     <PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
     <PackageReference Include="NPOI" Version="2.5.4" />