李昊 4 years ago
parent
commit
a53f9a435c

+ 68 - 2
GxPress/Repository/GxPress.Repository.Implement/WorkFlow/FlowTodoRepository.cs

@@ -704,7 +704,29 @@ namespace GxPress.Repository.Implement.WorkFlow
         {
             return await _repository.GetAsync(query);
         }
-
+        /// <summary>
+        /// 获取未处理的
+        /// </summary>
+        /// <param name="flowId"></param>
+        /// <returns></returns>
+        public async Task<FlowTodo> GetUCheckedAsync(int flowId)
+        {
+            string sql = $@" SELECT 
+                                    a.*
+                                    FROM
+                                        tede_flow_todo a
+                                            INNER JOIN
+                                        tede_user b ON a.UserId = b.Id
+                                    WHERE
+                                        a.FlowId ={flowId} AND a.IsDone = 0
+                                            AND a.Type = 'ApproverCheck'
+                                            AND IsChecked = 0 order by a.Sort limit 1";
+            var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
+            var database = new Database(databaseType, _connectionString);
+            var connection = database.GetConnection();
+            var result = await connection.QueryFirstOrDefaultAsync<FlowTodo>(sql);
+            return result;
+        }
         public async Task<bool> UpdateAsync(FlowTodo todo)
         {
             return await _repository.UpdateAsync(todo);
@@ -777,7 +799,51 @@ namespace GxPress.Repository.Implement.WorkFlow
                 .Where(nameof(FlowTodo.IsDone), true)
             );
         }
-
+        /// <summary>
+        /// 获取操作成功数量
+        /// </summary>
+        /// <param name="flowId"></param>
+        /// <returns></returns>
+        public async Task<int> CheckedCountAsync(int flowId)
+        {
+            string sql = $@"SELECT 
+                                count(1)
+                                FROM
+                                    tede_flow_todo a
+                                        INNER JOIN
+                                    tede_user b ON a.UserId = b.Id
+                                WHERE
+                                    a.FlowId ={flowId} AND a.IsDone = 1
+                                        AND a.Type = 'ApproverCheck'
+                                        AND IsChecked = 1";
+            var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
+            var database = new Database(databaseType, _connectionString);
+            var connection = database.GetConnection();
+            var result = await connection.ExecuteScalarAsync<int>(sql);
+            return result;
+        }
+        /// <summary>
+        /// 获取所有数量
+        /// </summary>
+        /// <param name="flowId"></param>
+        /// <returns></returns>
+        public async Task<int> AllCountAsync(int flowId)
+        {
+            string sql = $@"SELECT 
+                                count(1)
+                                FROM
+                                    tede_flow_todo a
+                                        INNER JOIN
+                                    tede_user b ON a.UserId = b.Id
+                                WHERE
+                                    a.FlowId ={flowId} 
+                                    AND a.Type = 'ApproverCheck'";
+            var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
+            var database = new Database(databaseType, _connectionString);
+            var connection = database.GetConnection();
+            var result = await connection.ExecuteScalarAsync<int>(sql);
+            return result;
+        }
         public async Task<int> CountAsync(SqlKata.Query query)
         {
             return await _repository.CountAsync(query);

+ 19 - 1
GxPress/Repository/GxPress.Repository.Interface/WorkFlow/IFlowTodoRepository.cs

@@ -56,11 +56,29 @@ namespace GxPress.Repository.Interface.WorkFlow
 
         Task<int> GetReadCountAsync(int userId, string type, FlowListRequest request, bool isRead);
 
-         /// <summary>
+        /// <summary>
         /// 抄送未读数量
         /// </summary>
         /// <param name="userId"></param>
         /// <returns></returns>
         Task<int> FlowCcUReadCountAsync(int userId);
+        /// <summary>
+        /// 获取操作成功数量
+        /// </summary>
+        /// <param name="flowId"></param>
+        /// <returns></returns>
+        Task<int> CheckedCountAsync(int flowId);
+        /// <summary>
+        /// 获取所有数量
+        /// </summary>
+        /// <param name="flowId"></param>
+        /// <returns></returns>
+        Task<int> AllCountAsync(int flowId);
+        /// <summary>
+        /// 获取未处理的
+        /// </summary>
+        /// <param name="flowId"></param>
+        /// <returns></returns>
+       Task<FlowTodo> GetUCheckedAsync(int flowId);
     }
 }

+ 3 - 3
GxPress/Service/GxPress.Service.Implement/Flow/FlowService.Actions2.Check.cs

@@ -54,8 +54,8 @@ namespace GxPress.Service.Implement
                     }
                 }
                 //是否审核通过
-                var checkedCount = await _flowTodoRepository.CountAsync(Q.Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), flow.Id).Where(nameof(Entity.WorkFlow.FlowTodo.IsDone), true).Where(nameof(Entity.WorkFlow.FlowTodo.Type), nameof(TodoTypeConst.ApproverCheck)).Where(nameof(Entity.WorkFlow.FlowTodo.IsChecked), true));
-                var allCount = await _flowTodoRepository.CountAsync(Q.Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), flow.Id).Where(nameof(Entity.WorkFlow.FlowTodo.Type), nameof(TodoTypeConst.ApproverCheck)));
+                var checkedCount = await _flowTodoRepository.CheckedCountAsync(flow.Id);
+                var allCount = await _flowTodoRepository.AllCountAsync(flow.Id);
                 //判断是否最后一个通过
                 if (checkedCount == allCount)
                 {
@@ -68,7 +68,7 @@ namespace GxPress.Service.Implement
                 else
                 {
                     //修改可操作人
-                    var flowTodo = await _flowTodoRepository.GetAsync(Q.Where(nameof(Entity.WorkFlow.FlowTodo.IsChecked), false).Where(nameof(Entity.WorkFlow.FlowTodo.IsDone), false).Where(nameof(Entity.WorkFlow.FlowTodo.Type), nameof(TodoTypeConst.ApproverCheck)).Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), todo.FlowId).OrderBy(nameof(Entity.WorkFlow.FlowTodo.Sort)));
+                    var flowTodo = await _flowTodoRepository.GetUCheckedAsync(todo.FlowId);
                     if (flowTodo.IsCaseOr && flowTodo.ParentId > 0)
                     {
                         var flowDtos = await _flowTodoRepository.GetAllAsync(Q.Where(nameof(Entity.WorkFlow.FlowTodo.ParentId), flowTodo.ParentId).Where(nameof(Entity.WorkFlow.FlowTodo.IsCaseOr), true).Where(nameof(Entity.WorkFlow.FlowTodo.FlowId), flowTodo.FlowId));