/*
|
* Copyright 2019-2020 Zheng Jie
|
*
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
* you may not use this file except in compliance with the License.
|
* You may obtain a copy of the License at
|
*
|
* http://www.apache.org/licenses/LICENSE-2.0
|
*
|
* Unless required by applicable law or agreed to in writing, software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* See the License for the specific language governing permissions and
|
* limitations under the License.
|
*/
|
package me.zhengjie.modules.task.repository;
|
|
import me.zhengjie.modules.task.domain.TaskDailyInterface;
|
import me.zhengjie.modules.task.domain.TaskDaliy;
|
|
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
import org.springframework.data.jpa.repository.Query;
|
|
import java.sql.Timestamp;
|
import java.time.LocalDate;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @website https://eladmin.vip
|
* @author 赵士淞
|
* @date 2022-12-30
|
**/
|
public interface TaskDaliyRepository extends JpaRepository<TaskDaliy, Long>, JpaSpecificationExecutor<TaskDaliy> {
|
|
/**
|
* 根据项目ID、任务ID、用户ID查询填报日期前最近的任务日报信息
|
* @param userId
|
* @return
|
*/
|
@Query(value = "SELECT * FROM task_daliy WHERE project_id = ?1 AND task_id = ?2 AND user_id = ?3 AND fill_date < ?4 ORDER BY fill_date DESC LIMIT 1", nativeQuery = true)
|
TaskDaliy findPreviousByProjectIdAndTaskIdAndAndUserId(Long projectId, Long taskId, Long userId, Timestamp fillDate);
|
|
/**
|
* 根据项目ID、任务ID、用户ID查询填报日期后最近的任务日报信息
|
* @param userId
|
* @return
|
*/
|
@Query(value = "SELECT * FROM task_daliy WHERE project_id = ?1 AND task_id = ?2 AND user_id = ?3 AND fill_date > ?4 ORDER BY fill_date ASC LIMIT 1", nativeQuery = true)
|
TaskDaliy findNextByProjectIdAndTaskIdAndAndUserId(Long projectId, Long taskId, Long userId, Timestamp fillDate);
|
|
|
@Query(value = "SELECT avg(task_progress) as taskProgress, COALESCE(sum(consumed_workload), 0.0) as consumedWorkload, sum(consumed_hours) as consumedHours FROM task_daliy WHERE task_id = ?1 AND create_time < ?2", nativeQuery = true)
|
TaskDailyInterface collectTaskDaliyUntilDate(Long taskId, Date belongDate);
|
|
/**
|
* 根据项目ID、任务ID查询各用户填报的最大任务进度日报信息
|
* @param projectId
|
* @param taskId
|
* @return
|
*/
|
@Query(value = "SELECT td.project_id, td.task_id, td.user_id, MAX(td.task_progress) task_progress, tu.task_hours FROM task_daliy td, task_user tu WHERE td.project_id = tu.project_id AND td.task_id = tu.task_id AND td.user_id = tu.user_id AND td.project_id = ?1 AND td.task_id = ?2 GROUP BY td.project_id, td.task_id, td.user_id", nativeQuery = true)
|
List<Map> findMaxTaskProgressByProjectIdAndTaskId(Long projectId, Long taskId);
|
|
/**
|
* 根据项目ID、任务ID查询总消耗工作量
|
* @param projectId
|
* @param taskId
|
* @return
|
*/
|
@Query(value = "SELECT COALESCE(SUM(consumed_workload), 0) FROM task_daliy WHERE project_id = ?1 AND task_id = ?2", nativeQuery = true)
|
Double findSumConsumedWorkloadByProjectIdAndTaskId(Long projectId, Long taskId);
|
|
/**
|
* 根据项目ID、任务ID查询
|
* @param projectId
|
* @param taskId
|
* @return
|
*/
|
List<TaskDaliy> findByProjectIdAndTaskId(Long projectId, Long taskId);
|
|
/**
|
* 根据项目ID查询任务日报信息
|
* @param projectId
|
* @return
|
*/
|
@Query(value = "SELECT COALESCE(SUM(consumed_hours), 0.0) AS consumedHours, COALESCE(sum(consumed_workload), 0.0) as consumedWorkload FROM task_daliy WHERE project_id = ?1 AND fill_date < ?2", nativeQuery = true)
|
TaskDailyInterface collectByProjectIdAndFillDateLessThan(Long projectId, Timestamp fillDate);
|
|
/**
|
* 根据项目ID查询任务日报信息
|
* @param projectId
|
* @return
|
*/
|
@Query(value = "SELECT td.task_id AS taskId, COALESCE(MAX(td.task_progress), 0) AS taskProgress, COALESCE(SUM(consumed_hours), 0) AS consumedHours, COALESCE(sum(consumed_workload), 0.0) as consumedWorkload, plan_hours AS planHours FROM task_daliy td INNER JOIN task t ON (td.task_id = t.id) WHERE td.project_id = ?1 AND td.fill_date < ?2 GROUP BY td.task_id", nativeQuery = true)
|
List<TaskDailyInterface> collectByProjectIdAndFillDateLessThanGroupByTaskIdJoinTask(Long projectId, Timestamp fillDate);
|
|
/**
|
* 根据项目ID查询任务日报信息
|
* @param projectId
|
* @return
|
*/
|
@Query(value = "SELECT user_id AS userId, fill_date AS fillDate, COALESCE(SUM(consumed_hours), 0) AS consumedHours FROM task_daliy WHERE project_id = ?1 AND fill_date < ?2 GROUP BY user_id, fill_date", nativeQuery = true)
|
List<TaskDailyInterface> collectByProjectIdAndFillDateLessThanGroupByUserIdAndFillDate(Long projectId, Timestamp fillDate);
|
|
/**
|
* 根据项目ID、任务ID查询
|
* @param projectId
|
* @param taskId
|
* @return
|
*/
|
@Query(value = "SELECT user_id AS userId, COALESCE(SUM(consumed_hours), 0) AS consumedHours FROM task_daliy WHERE project_id = ?1 GROUP BY user_id", nativeQuery = true)
|
List<TaskDailyInterface> collectCostByProjectIdGroupUser(Long projectId);
|
|
/**
|
* 根据项目ID、任务ID查询
|
* @param projectId
|
* @return
|
*/
|
@Query(value = "SELECT user_id AS userId, task_id AS taskId, COALESCE(MAX(task_progress), 0) AS taskProgress FROM task_daliy WHERE project_id = ?1 AND fill_date BETWEEN ?2 AND ?3 GROUP BY user_id, task_id", nativeQuery = true)
|
List<TaskDailyInterface> collectCostByProjectIdAndFillDateBetweenGroupUserAndTaskId(Long projectId, Timestamp sdate, Timestamp edate);
|
|
|
/**
|
* 根据项目ID、任务ID、用户ID查询总消耗工时、总消耗工作量、最大任务进度
|
* @param projectId
|
* @param taskId
|
* @param userId
|
* @return
|
*/
|
@Query(value = "SELECT COALESCE(SUM(consumed_hours), 0) AS consumedHours, COALESCE(SUM(consumed_workload), 0) AS consumedWorkload, COALESCE(MAX(task_progress), 0) AS taskProgress FROM task_daliy WHERE project_id = ?1 AND task_id = ?2 AND user_id = ?3", nativeQuery = true)
|
TaskDailyInterface findSumConsumedHoursAndSumConsumedWorkloadAndMaxTaskProgressByProjectIdAndTaskIdAndUserId(Long projectId, Long taskId, Long userId);
|
|
/**
|
* 根据userId,开始时间结束时间范围查询日志表
|
* @param userId
|
* @param startDate
|
* @param endDate
|
* @return
|
*/
|
@Query(value = "SELECT id,project_id,task_id,user_id,fill_date,consumed_workload,task_progress,settlement_status,SUM( consumed_hours ) AS consumed_hours,remarks,create_by,create_time,update_by,update_time from task_daliy where user_id = ?1 and fill_date <= ?3 and fill_date >= ?2 group by fill_date", nativeQuery = true)
|
List<TaskDaliy> findAllByUserAndDate(Long userId, LocalDate startDate, LocalDate endDate);
|
}
|