张晓波
2023-09-19 164694c47c35d6654df69b533e8dbf8b5423efc5
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<?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="com.thhy.mobile.modules.biz.repo.mapper.RepoRecordMapper">
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        t.record_id as recordId,
        t.create_time as createTime,
        t.create_user as createUser,
        t.repo_id as repoId,
        t.repo_unit_id as repoUnitId,
        t.ring_num as ringNum
    </sql>
 
    <sql id="condition_query">
        <where>
            <trim suffixOverrides=" AND ">
                <if test="createTime!=null">
                    t.create_time = #{createTime} AND
                </if>
                <if test="createUser!=null and createUser!=''">
                    t.create_user = #{createUser} AND
                </if>
                <if test="repoId!=null and repoId!=''">
                    t.repo_id = #{repoId} AND
                </if>
                <if test="repoUnitId!=null and repoUnitId!=''">
                    t.repo_unit_id = #{repoUnitId} AND
                </if>
                <if test="ringNum!=null and ringNum!=''">
                    t.ring_num = #{ringNum} AND
                </if>
            </trim>
        </where>
    </sql>
 
    <select id="queryById" resultType="com.thhy.mobile.modules.biz.repo.entity.RepoRecord">
        select <include refid="Base_Column_List" />
        from t_repo_record t
        where t.record_id=#{recordId}
    </select>
 
    <select id="queryVersionById" resultType="integer">
        select version from t_repo_record
        where record_id=#{recordId}
    </select>
 
    <!--查询列表-->
    <select id="findList" resultType="com.thhy.mobile.modules.biz.repo.entity.RepoRecord">
        SELECT
        <include refid="Base_Column_List" />
        from t_repo_record t
        <include refid="condition_query" />
    </select>
 
    <!--查询列表-->
    <select id="findAll" resultType="com.thhy.mobile.modules.biz.repo.entity.RepoRecord">
        SELECT
        <include refid="Base_Column_List" />
        from t_repo_record t
    </select>
 
    <!--插入操作-->
    <insert id="insert">
        insert into t_repo_record
        <trim prefix="(" suffix=")" suffixOverrides="," >
            <if test="createTime != null">
                create_time,
            </if>
            <if test="createUser != null">
                create_user,
            </if>
            <if test="recordId != null">
                record_id,
            </if>
            <if test="repoId != null">
                repo_id,
            </if>
            <if test="repoUnitId != null">
                repo_unit_id,
            </if>
            <if test="ringNum != null">
                ring_num,
            </if>
        </trim>
 
        <trim prefix="values (" suffix=")" suffixOverrides="," >
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="createUser != null">
                #{createUser},
            </if>
            <if test="recordId != null">
                #{recordId},
            </if>
            <if test="repoId != null">
                #{repoId},
            </if>
            <if test="repoUnitId != null">
                #{repoUnitId},
            </if>
            <if test="ringNum != null">
                #{ringNum},
            </if>
        </trim>
    </insert>
 
 
    <!--更新操作-->
    <update id="update">
        update t_repo_record
        <set>
            <if test="createTime != null">
                create_time=#{createTime},
            </if>
            <if test="createUser != null">
                create_user=#{createUser},
            </if>
            <if test="repoId != null">
                repo_id=#{repoId},
            </if>
            <if test="repoUnitId != null">
                repo_unit_id=#{repoUnitId},
            </if>
            <if test="ringNum != null">
                ring_num=#{ringNum},
            </if>
        </set>
        where record_id=#{recordId}
    </update>
 
    <!--逻辑删除-->
    <update id="deletelogic">
        update t_repo_record
        SET is_use = 0
        where record_id=#{recordId}
    </update>
 
    <!--根据ID删除-->
    <delete id="deleteById">
        delete from t_repo_record
        where record_id=#{recordId}
    </delete>
 
    <select id="countByRingNum" resultType="int">
        select count(record_id) from t_repo_record where ring_num = #{ringNum}
    </select>
 
    <!--插入操作-->
    <insert id="insertRecordPipe">
        insert into t_repo_record_pipe
        <trim prefix="(" suffix=")" suffixOverrides="," >
            <if test="id != null">
                id,
            </if>
            <if test="pipeNum != null">
                pipe_num,
            </if>
            <if test="recordId != null">
                record_id,
            </if>
            <if test="ringNum != null">
                ring_num,
            </if>
            <if test="repoId != null">
                repo_id,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
        </trim>
 
        <trim prefix="values (" suffix=")" suffixOverrides="," >
            <if test="id != null">
                #{id},
            </if>
            <if test="pipeNum != null">
                #{pipeNum},
            </if>
            <if test="recordId != null">
                #{recordId},
            </if>
            <if test="ringNum != null">
                #{ringNum},
            </if>
            <if test="repoId != null">
                #{repoId},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
        </trim>
    </insert>
 
    <select id="recordList" resultType="com.thhy.mobile.modules.biz.repo.entity.IntoListVo">
        SELECT a.*,sp.pro_name as proName from
            (select tpr.record_id as recordId,tpr.ring_num as ringNum,repo.repo_name as repoName,tpr.create_time as createTime,su.real_name as createUser,(select pro_id from t_pipe_info where ring_num = tpr.ring_num limit 1) as proId
            from t_repo_record tpr
            left join t_repo repo on tpr.repo_id = repo.repo_id
            left join sys_users su on su.user_id = tpr.create_user
            <where>
                <trim suffixOverrides=" AND ">
                    repo.company_id = #{companyId} AND
                    <if test="repoId !=null and repoId !=''">
                        tpr.repo_id = #{repoId} AND
                    </if>
                    <if test="ringNum !=null and ringNum !=''">
                        tpr.ring_num LIKE concat('%',#{ringNum},'%') AND
                    </if>
                </trim>
            </where>
            ) a
            left join sys_project sp on sp.pro_id = a.proId
        order by a.createTime desc
    </select>
 
 
 
    <select id="countRecordByRepoId" resultType="int">
        select count(record_id) from t_repo_record where repo_id = #{repoId}
    </select>
 
    <select id="countByUnitId" resultType="int">
        select count(record_id) from t_repo_record where repo_unit_id = #{unitId}
    </select>
 
    <select id="repoDetail" resultType="com.thhy.mobile.modules.biz.repo.entity.RepoRecordListVo">
        select r.repo_name as repoName,ru.unit_name as unitName,rrp.pipe_num as pipeNum,rrp.ring_num as ringNum,
               sp.pro_name as proName,sd1.dict_name as turnName,sd2.dict_name as sizeName,sd3.dict_name as blockNumName,
               sd4.dict_name as reinforcementName,sd5.dict_name as groutingHolesName,rr.create_time as createTime,rrp.out_repo_time as outRepoTime,
               (select SYSDATE() BETWEEN rr.create_time and DATE_ADD(rr.create_time,INTERVAL r.save_time DAY)) as timeOut
        from t_repo_record_pipe rrp
                 left join t_repo_record rr on rr.record_id = rrp.record_id
                 left join t_repo r on r.repo_id = rr.repo_id
                 left join t_repo_unit ru on ru.unit_id = rr.repo_unit_id
                 left join t_pipe_info tpi on tpi.pipe_num = rrp.pipe_num
                 left join sys_project sp on sp.pro_id = tpi.pro_id
                 left join sys_dict sd1 on sd1.dict_id = tpi.turn
                 left join sys_dict sd2 on sd2.dict_id = tpi.size
                 left join sys_dict sd3 on sd3.dict_id = tpi.block_num
                 left join sys_dict sd4 on sd4.dict_id = tpi.reinforcement
                 left join sys_dict sd5 on sd5.dict_id = tpi.grouting_holes
        <where>
            <trim suffixOverrides=" AND ">
                r.repo_id = #{repoId} AND
                <if test="ringNum !=null and ringNum !=''">
                    rrp.ring_num LIKE concat('%',#{ringNum},'%') AND
                </if>
                <if test="unitId !=null and unitId !=''">
                    ru.unit_id = #{unitId} AND
                </if>
                <if test="blockNum !=null and blockNum !=''">
                    tpi.block_num = #{blockNum} AND
                </if>
                <if test="reinforcement !=null and reinforcement !=''">
                    tpi.reinforcement = #{reinforcement} AND
                </if>
                <if test="groutingHoles !=null and groutingHoles !=''">
                    tpi.grouting_holes = #{groutingHoles} AND
                </if>
                <if test="timeOut !=null and timeOut !=''">
                    <if test="timeOut == 1">
                        (SYSDATE() BETWEEN rr.create_time and DATE_ADD(rr.create_time,INTERVAL r.save_time DAY)) AND
                    </if>
                    <if test="timeOut == 2">
                        (sysdate() &lt; rr.create_time or sysdate() &gt; DATE_ADD(rr.create_time,INTERVAL r.save_time DAY)) AND
                    </if>
                </if>
                <if test="startTime !=null">
                    rr.create_time &gt; #{startTime} AND
                </if>
                <if test="endTime !=null">
                    rr.create_time &lt; #{endTime} AND
                </if>
            </trim>
        </where>
    </select>
 
</mapper>