liuxiaolong
2019-05-09 0d1d88cdb668e75ea8609417ac18ae19947e9525
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.com.basic.safety.entity.TasksStatusInspection">
<resultMap id="BaseResultMap" type="cn.com.basic.safety.entity.TasksStatusInspection">
</resultMap>
 <select id="selectTasksInspectionItem" resultMap="BaseResultMap" parameterType="java.util.Map">
  
  
SELECT 
  s.id,
  s.category,
  s.title,
  s.start_date,
  s.end_date,
  s.publish_date,
  s.roles,
  s.periods,
  s.update_time,
  h.check_result,
  h.check_opinion,
  h.reject_id,
  h.reject_date
FROM
  (SELECT 
  t.id,
  d.category,
  t.title,
  t.start_date,
  t.end_date,
  t.publish_date,
  t.roles,
  t.periods,
  t.update_time
FROM
  t_safety_publish_task t,
  dm_safety_item_type d 
WHERE t.category_id = d.id 
  AND t.school_id = #{schoolId}
  
  <if test="itemTypeId != null" >
        AND t.category_id =#{itemTypeId}  
   </if>
  
  
  
  ) s LEFT JOIN 
  (
  
SELECT  t.publish_task_id,
    t.check_result,
    t.check_opinion,
    t.reject_id,
    t.reject_date  FROM  (SELECT * FROM  t_safety_flow_history   ORDER BY update_time DESC )  t GROUP BY publish_task_id  
 
    ) h ON s.id = h.publish_task_id 
  
    <if test="limitStart != null and limitStart>=0" >
      limit #{limitStart} , #{limitEnd}
    </if>
        <if test="sorting != null">order by ${sorting}</if>
        <if test="sorting == null">order by UPDATE_time</if>
    </select>
 <select id="selectTasksInspectionItemCount" resultType="java.lang.Long" parameterType="java.util.Map"> 
SELECT 
 COUNT(s.id)
FROM
  (SELECT 
  t.id,
  d.category,
  t.title,
  t.start_date,
  t.end_date,
  t.publish_date,
  t.roles,
  t.periods,
  t.update_time
FROM
  t_safety_publish_task t,
  dm_safety_item_type d 
WHERE t.category_id = d.id 
  AND t.school_id = #{schoolId}
  
  <if test="itemTypeId != null" >
        AND t.category_id =#{itemTypeId}  
   </if>
  ) s LEFT JOIN 
  (
  
SELECT  t.publish_task_id,
    t.check_result,
    t.check_opinion,
    t.reject_id,
    t.reject_date  FROM  (SELECT * FROM  t_safety_flow_history   ORDER BY update_time DESC )  t GROUP BY publish_task_id  
 
    ) h ON s.id = h.publish_task_id 
      
     <if test="sorting != null">order by ${sorting}</if>
    <if test="sorting == null">order by UPDATE_time</if>    
    </select>
</mapper>