linwe
2024-08-09 8b7258c9427882bb1798f1502eaa35184c6e374e
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?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="org.springblade.modules.patrol.mapper.PatrolGroupMapper">
 
    <select id="getPatrolGroupByProjectId" resultType="org.springblade.modules.patrol.entity.PatrolGroup">
        SELECT g.id,g.name
        FROM jczz_patrol_group g
        WHERE g.is_deleted = 0
        AND g.project_id = #{projectId}
    </select>
 
    <!-- 通用查询映射结果 -->
    <resultMap id="patrolGroupResultMap" type="org.springblade.modules.patrol.vo.PatrolGroupVO">
        <id property="id" column="id"/>
        <result property="name" column="name"/>
        <collection property="patrolGroupItemList" javaType="java.util.List" select="selectPatrolGroupItem"
                    column="id"
                    ofType="org.springblade.modules.patrol.vo.PatrolGroupItemVO" autoMapping="true">
        </collection>
 
    </resultMap>
 
    <select id="selectPatrolGroupItem" resultType="org.springblade.modules.patrol.vo.PatrolGroupItemVO">
        select
            id,
            group_id,
            items_name,
            description,
            create_user,
            create_time,
            update_time,
            is_deleted,
            type
        from
            jczz_patrol_group_item
        where group_id = #{houseCode} and  is_deleted = 0
    </select>
 
    <select id="selectPatrolGroupPage" resultMap="patrolGroupResultMap">
        select * from jczz_patrol_group
        <where>
            <if test="patrolGroup.id != null "> and id = #{patrolGroup.id}</if>
            <if test="patrolGroup.name != null  and patrolGroup.name != ''"> and name = #{patrolGroup.name}</if>
            <if test="patrolGroup.createUser != null "> and create_user = #{patrolGroup.createUser}</if>
            <if test="patrolGroup.createTime != null "> and create_time = #{patrolGroup.createTime}</if>
            <if test="patrolGroup.updateTime != null "> and update_time = #{patrolGroup.updateTime}</if>
            <if test="patrolGroup.isDeleted != null "> and is_deleted = #{patrolGroup.isDeleted}</if>
            <if test="patrolGroup.type != null "> and type = #{patrolGroup.type}</if>
        </where>
    </select>
 
    <!--查询巡查项树数据-->
    <select id="getPatrolGroupTree" resultType="org.springblade.core.tool.node.TreeNode" >
        SELECT
        spg.id,
        spg.name as title,
        0 as parentId,
        (
            SELECT
                CASE WHEN count(1) > 0 THEN 1 ELSE 0 END
            FROM
                jczz_patrol_group_item
            WHERE
                group_id = spg.id and is_deleted = 0
        ) AS "has_children"
        FROM jczz_patrol_group spg
        <where>
              spg.is_deleted = 0
            <if test="param1 != null">
                and spg.type = #{param1}
            </if>
        </where>
        order by spg.create_time desc
    </select>
 
    <!--查询巡查项树数据-->
    <select id="getPatrolGroupItemTree" resultType="org.springblade.core.tool.node.TreeNode" >
        SELECT
        spgi.id,
        spgi.items_name as title,
        spgi.group_id as parentId,
        false AS hasChildren
        FROM jczz_patrol_group_item spgi where spgi.is_deleted = 0
        <if test="param1 != null">
            and spgi.type = #{param1}
        </if>
        order by spgi.create_time desc
    </select>
    <select id="getPatrolGroupByItemId" resultType="org.springblade.modules.patrol.entity.PatrolGroup">
        SELECT distinct b.ID,b.NAME FROM
        (
            SELECT ID,GROUP_ID FROM SM_PATROL_GROUP_ITEM WHERE ID IN
            <foreach collection="itemIds.split(',')" item="item" index="index" open="(" separator="," close=")">
                #{item}
            </foreach>
        ) a ,SM_PATROL_GROUP b
        WHERE b.is_deleted = 0 AND a.group_id = b.id
    </select>
    <select id="getAllPatrolGroupByTaskId" resultType="org.springblade.modules.patrol.vo.PatrolGroupVO">
        SELECT G.*,IF(C.GROUP_ID,1,2) isSelect,IFNULL(C.problemCount,0) problemCount  FROM SM_PATROL_GROUP G
        LEFT JOIN (
            <!--获取巡查记录表中的已选项,并获取问题数量-->
            SELECT DISTINCT I.GROUP_ID,D.problemCount FROM SM_PATROL_RECORD R
            INNER JOIN SM_PATROL_GROUP_ITEM I ON R.ITEM_ID = I.ID
            LEFT JOIN (
                SELECT I.GROUP_ID,COUNT(*) problemCount FROM SM_PATROL_RECORD R
                INNER JOIN SM_PATROL_GROUP_ITEM I ON R.ITEM_ID = I.ID
                WHERE R.IS_DELETED = 0 AND R.TASK_ID = #{taskId}
                AND R.STATUS = 2
                AND R.SOLUTION = 2
                AND R.state = 0
                GROUP BY I.GROUP_ID
            )D ON D.GROUP_ID = I.GROUP_ID
            WHERE R.IS_DELETED = 0 AND R.TASK_ID = #{taskId}
        )C ON C.GROUP_ID = G.ID
        WHERE IS_DELETED = 0
        ORDER BY G.CREATE_TIME
    </select>
 
    <resultMap id="patrolGroupDTO" type="org.springblade.modules.patrol.dto.PatrolGroupDTO">
        <id property="id" column="id"/>
        <result property="name" column="gname"/>
    </resultMap>
 
 
    <select id="getPatrolGroupDTO" resultMap="patrolGroupDTO">
       SELECT G.ID,
              G.NAME AS gname,
             R.ID AS rId,
              R.VIDEOS,
              R.IMAGES,
              R.STATUS,
              R.IS_DELETED,
              R.ITEM_ID  AS itemId,
        I.ITEMS_NAME AS itemsName,
              R.TASK_ID AS taskId ,
              R.SOLUTION,
              R.CONTENT
       FROM SM_PATROL_GROUP G
       LEFT JOIN SM_PATROL_GROUP_ITEM I ON I.GROUP_ID = G.ID
       LEFT JOIN SM_PATROL_RECORD R ON R.ITEM_ID = I.ID
       WHERE G.IS_DELETED = 0
       AND R.STATUS = 2 AND R.state = 0 AND R.SOLUTION = 2
       AND R.TASK_ID = #{taskId}
    </select>
 
 
    <select id="getPatrolGroupByTaskId" resultType="org.springblade.modules.patrol.entity.PatrolGroup">
       SELECT G.ID,G.NAME FROM SM_PATROL_GROUP G
       LEFT JOIN SM_PATROL_GROUP_ITEM I ON I.GROUP_ID = G.ID
       LEFT JOIN SM_PATROL_REPORT R ON R.ITEM_ID = I.ID
       WHERE G.IS_DELETED = 0
       AND R.STATUS = 2
       AND R.TASK_ID = #{taskId}
    </select>
    <select id="getGroupDTORecord" resultMap="patrolGroupDTO">
        SELECT G.ID,
               G.NAME AS gname,
               R.ID AS rId,
               R.VIDEOS,
               R.IMAGES,
               R.STATUS,
               R.IS_DELETED,
               R.ITEM_ID  AS itemId,
               I.ITEMS_NAME AS itemsName,
               R.TASK_ID AS taskId ,
               R.SOLUTION,
               R.CONTENT
        FROM SM_PATROL_GROUP G
                 LEFT JOIN SM_PATROL_GROUP_ITEM I ON I.GROUP_ID = G.ID
                 LEFT JOIN SM_PATROL_RECORD R ON R.ITEM_ID = I.ID
        WHERE G.IS_DELETED = 0
          AND R.STATUS = 2
          AND R.TASK_ID = #{taskId}
    </select>
 
 
 
<!--    <select id="selectPatrolGroupItemById" parameterType="long" resultMap="PatrolGroupItemDTOResult">-->
<!--        <include refid="selectPatrolGroupItem"/>-->
<!--        where-->
<!--        id = #{id}-->
<!--    </select>-->
 
<!--    <select id="selectPatrolGroupItemList" parameterType="org.springblade.modules.patrol.dto.PatrolGroupItemDTO" resultMap="PatrolGroupItemDTOResult">-->
<!--        <include refid="selectPatrolGroupItem"/>-->
<!--        <where>-->
<!--            <if test="id != null "> and id = #{id}</if>-->
<!--            <if test="groupId != null "> and group_id = #{groupId}</if>-->
<!--            <if test="itemsName != null  and itemsName != ''"> and items_name = #{itemsName}</if>-->
<!--            <if test="description != null  and description != ''"> and description = #{description}</if>-->
<!--            <if test="createUser != null "> and create_user = #{createUser}</if>-->
<!--            <if test="createTime != null "> and create_time = #{createTime}</if>-->
<!--            <if test="updateTime != null "> and update_time = #{updateTime}</if>-->
<!--            <if test="isDeleted != null "> and is_deleted = #{isDeleted}</if>-->
<!--        </where>-->
<!--    </select>-->
</mapper>