heheng
2025-05-16 8485affcb0d4de05059d80cb1e844d6b18291654
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.gkhy.labRiskManage.domain.riskReport.repository.jpa;
 
import com.gkhy.labRiskManage.domain.riskReport.entity.RiskAssessPlan;
import com.gkhy.labRiskManage.domain.riskReport.model.bo.ExecStatusSubmitBO;
import com.gkhy.labRiskManage.domain.riskReport.model.dto.AssessPlanQueryDTO;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
 
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
 
/**
 * 风险评估-评估项
 */
@Repository
public interface RiskAssessPlanRepository extends JpaRepository<RiskAssessPlan, Long>, JpaSpecificationExecutor<RiskAssessPlan> {
 
    /**
     * 风险评估计划-查询 by name
     */
    @Query(value = "select t from RiskAssessPlan t where t.assessPlanName = :assessPlanName and t.deleteStatus = 0")
    RiskAssessPlan getAssessPlanByName(String assessPlanName);
    /**
     * 风险评估计划-查询 by id
     */
    @Query(value = "select t from RiskAssessPlan t where t.id = :id and t.deleteStatus = 0")
    RiskAssessPlan getAssessPlanById(Long id);
    /**
     * 风险评估计划-提交 辨识-评价 结果   --弃用
     */
    @Query(value = "update RiskAssessPlan set plan_exec_status = :#{#execStatusSubmitBO.ExecStatus} where id = :#{#execStatusSubmitBO.id}", nativeQuery = true)
    RiskAssessPlan execStatusSubmit(ExecStatusSubmitBO execStatusSubmitBO);
    /**
     * 风险评估计划- 辨识删除 --弃用
     */
    @Query(value = "update RiskAssessPlan set identification_time = :#date where id = :id", nativeQuery = true)
    RiskAssessPlan deleteIdentification(Long id, LocalDateTime date);
    /**
     * 风险评估计划- 评价删除  --弃用
     */
    @Query(value = "update RiskAssessPlan set evaluate_time = :date where id = :id", nativeQuery = true)
    RiskAssessPlan deleteEvaluate(Long id, LocalDateTime date);
    /**
     * 风险评估计划 - 查询 by 实验id
     */
    @Query(value = "select t from RiskAssessPlan t where t.experimentId = :experimentId and t.deleteStatus = 0")
    List<RiskAssessPlan> getAssessPlanByExperimentId(Long experimentId);
 
    @Query(value = "select t from RiskAssessPlan t where t.riskUnitId = :riskUnitId and t.deleteStatus = 0")
    List<RiskAssessPlan> getAssessPlanByUnitId(Long riskUnitId);
 
    /**
     * 评估计划 - 查询已派发
     */
    @Query(value = "select t from RiskAssessPlan t where t.planSellStatus = :status and t.deleteStatus = 0")
    List<RiskAssessPlan>  listAssessPlan(Byte status);
 
    @Query(value = "select t from RiskAssessPlan t where t.deleteStatus = 0 and (t.identificationUserId = :currentUserId or t.evaluateUserId = :currentUserId)")
    List<RiskAssessPlan> getAssessPlanBySpecialist(Long currentUserId);
 
    @Query(value = "select t from RiskAssessPlan t where t.deleteStatus = 0 and t.riskUnitId = :basicId and riskType = 1")
    List<RiskAssessPlan> getAssessPlanByInherentUnit(Long basicId);
 
 
    @Query("SELECT COUNT(DISTINCT p.id) FROM RiskAssessPlan p " +
            "WHERE p.deleteStatus = 0 " +
            "AND (:assessPlanName IS NULL OR p.assessPlanName LIKE %:assessPlanName%) " +
            "AND (:experimentId IS NULL OR p.experimentId = :experimentId) " +
            "AND (:planUserId IS NULL OR p.planUserId = :planUserId) " +
            "and(coalesce(:riskUnitIds,null) is null  or p.riskUnitId in :riskUnitIds)")
    Long countDynamic(
            String assessPlanName,
            Long experimentId,
            Long planUserId,
            List<Long> riskUnitIds);
 
 
}