bingbo
2023-11-26 5b0fccf7c888215763e812fdfdee98ce7322fcd0
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<?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.steelstock.mapper.SteelStockMapper">
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        t.steel_stock_id as steelStockId,
        t.block_id as blockId,
        t.create_time as createTime,
        t.pro_id as proId,
        t.reinforcement_id as reinforcementId,
        t.size_id as sizeId,
        t.stock as stock,
        t.update_time as updateTime
    </sql>
 
    <sql id="condition_query">
        <where>
            <trim suffixOverrides=" AND ">
                <if test="blockId!=null and blockId!=''">
                    t.block_id = #{blockId} AND
                </if>
                <if test="createTime!=null">
                    t.create_time = #{createTime} AND
                </if>
                <if test="proId!=null and proId!=''">
                    t.pro_id = #{proId} AND
                </if>
                <if test="reinforcementId!=null and reinforcementId!=''">
                    t.reinforcement_id = #{reinforcementId} AND
                </if>
                <if test="sizeId!=null and sizeId!=''">
                    t.size_id = #{sizeId} AND
                </if>
                <if test="stock!=null">
                    t.stock = #{stock} AND
                </if>
                <if test="updateTime!=null">
                    t.update_time = #{updateTime} AND
                </if>
            </trim>
        </where>
    </sql>
 
    <select id="queryById" resultType="com.thhy.mobile.modules.biz.steelstock.entity.SteelStock">
        select <include refid="Base_Column_List" />
        from t_steel_stock t
        where t.steel_stock_id=#{steelStockId}
    </select>
 
    <select id="queryVersionById" resultType="integer">
        select version from t_steel_stock
        where steel_stock_id=#{steelStockId}
    </select>
 
    <!--查询列表-->
    <select id="findList" resultType="com.thhy.mobile.modules.biz.steelstock.entity.SteelStock">
        SELECT
        <include refid="Base_Column_List" />
        from t_steel_stock t
        <include refid="condition_query" />
    </select>
 
    <!--查询列表-->
    <select id="findAll" resultType="com.thhy.mobile.modules.biz.steelstock.entity.SteelStock">
        SELECT
        <include refid="Base_Column_List" />
        from t_steel_stock t
    </select>
 
    <!--插入操作-->
    <insert id="insert">
        insert into t_steel_stock
        <trim prefix="(" suffix=")" suffixOverrides="," >
            <if test="blockId != null">
                block_id,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="proId != null">
                pro_id,
            </if>
            <if test="reinforcementId != null">
                reinforcement_id,
            </if>
            <if test="sizeId != null">
                size_id,
            </if>
            <if test="steelStockId != null">
                steel_stock_id,
            </if>
            <if test="stock != null">
                stock,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
        </trim>
 
        <trim prefix="values (" suffix=")" suffixOverrides="," >
            <if test="blockId != null">
                #{blockId},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="proId != null">
                #{proId},
            </if>
            <if test="reinforcementId != null">
                #{reinforcementId},
            </if>
            <if test="sizeId != null">
                #{sizeId},
            </if>
            <if test="steelStockId != null">
                #{steelStockId},
            </if>
            <if test="stock != null">
                #{stock},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
        </trim>
    </insert>
 
 
    <!--更新操作-->
    <update id="update">
        update t_steel_stock
        <set>
            <if test="blockId != null">
                block_id=#{blockId},
            </if>
            <if test="createTime != null">
                create_time=#{createTime},
            </if>
            <if test="proId != null">
                pro_id=#{proId},
            </if>
            <if test="reinforcementId != null">
                reinforcement_id=#{reinforcementId},
            </if>
            <if test="sizeId != null">
                size_id=#{sizeId},
            </if>
            <if test="stock != null">
                stock=#{stock},
            </if>
            <if test="updateTime != null">
                update_time=#{updateTime},
            </if>
        </set>
        where steel_stock_id=#{steelStockId}
    </update>
 
    <!--逻辑删除-->
    <update id="deletelogic">
        update t_steel_stock
        SET is_use = 0
        where steel_stock_id=#{steelStockId}
    </update>
 
    <!--根据ID删除-->
    <delete id="deleteById">
        delete from t_steel_stock
        where steel_stock_id=#{steelStockId}
    </delete>
 
    <select id="countStockByPSRB" resultType="int">
        select count(steel_stock_id) from t_steel_stock where pro_id = #{proId} and size_id = #{sizeId}
                                                          and reinforcement_id = #{reinforcementId} and  block_id =#{blockId}
    </select>
 
    <update id="updatePlusStock">
        update t_steel_stock set stock = stock+1,update_time = sysdate() where pro_id = #{proId} and size_id = #{sizeId}
         and reinforcement_id = #{reinforcementId} and  block_id =#{blockId}
    </update>
 
    <update id="updateMinusStock">
        update t_steel_stock set stock = stock-1,update_time = sysdate() where pro_id = #{proId} and size_id = #{sizeId}
                                                                           and reinforcement_id = #{reinforcementId} and  block_id =#{blockId}
    </update>
 
    <select id="querySteelStock" resultType="com.thhy.mobile.modules.biz.steelstock.entity.SteelStockListVo">
        select
        t.pro_id as proId,
        sp.pro_name as proName,
        t.reinforcement_id as reinforcementId,
        sd1.dict_name as reinforcementName,
        sd.dict_name as sizeName,
        t.size_id as sizeId,
        sd2.dict_name as blockNumName,
        t.stock as stock
        from t_steel_stock t
        left join sys_project sp on t.pro_id = sp.pro_id
        left join sys_dict sd on sd.dict_id = t.size_id
        left join sys_dict sd1 on sd1.dict_id = t.reinforcement_id
        left join sys_dict sd2 on sd2.dict_id = t.block_id
        <where>
            <trim suffixOverrides=" AND ">
                sp.company_id = #{companyId} AND
                <if test="blockId!=null and blockId!=''">
                    t.block_id = #{blockId} AND
                </if>
                <if test="proId!=null and proId!=''">
                    t.pro_id = #{proId} AND
                </if>
                <if test="reinforcementId!=null and reinforcementId!=''">
                    t.reinforcement_id = #{reinforcementId} AND
                </if>
                <if test="sizeId!=null and sizeId!=''">
                    t.size_id = #{sizeId} AND
                </if>
            </trim>
        </where>
    </select>
    
    
    
    <!--这里是钢筋理论耗量的查询-->
    <select id="queryByPSRB" resultType="com.thhy.mobile.modules.biz.steelstock.entity.SteelConsume">
        select ss.steel_id as steelId,ss.steel_name as steelName,ss.steel_model as steelModel,tsn.need_num as needNum,tsn.coefficient
        from  t_steel_need tsn
                  left join t_steel_consumption tsc on tsc.consumption_id = tsn.consumption_id
                  left join sys_steel ss on ss.steel_id = tsn.steel_id
        where tsc.pro_id = #{proId} and tsc.size_id = #{sizeId}
          and tsc.reinforcement_id = #{reinforcementId} and tsc.block_id = #{blockId}
    </select>
 
    <!--更新钢筋库存-->
    <update id="updateMinusSteelStock">
        update sys_steel set stock = (stock-(#{needNum}*#{coefficient})) where steel_id = #{steelId}
    </update>
    <!--更新钢筋库存,这里的needNum 当参数用,是减去的库存-->
    <update id="updatePlusSteelStock">
        update sys_steel set stock = (stock+#{needNum}) where steel_id = #{steelId}
    </update>
 
    <insert id="insertSteelStockRecord">
        insert into t_steel_stock_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="recordId !=null and recordId !=''">
                record_id,
            </if>
            <if test="checkRecordId !=null and checkRecordId !=''">
                check_record_id,
            </if>
            <if test="modCheckId !=null and modCheckId !=''">
                mod_check_id,
            </if>
            <if test="proId !=null and proId !=''">
                pro_id,
            </if>
            <if test="sizeId !=null and sizeId !=''">
                size_id,
            </if>
            <if test="reinforcementId !=null and reinforcementId !=''">
                reinforcement_id,
            </if>
            <if test="blockId !=null and blockId !=''">
                block_id,
            </if>
            <if test="stock !=null and stock !=''">
                stock,
            </if>
            <if test="createTime !=null and createTime !=''">
                create_time,
            </if>
            <if test="type !=null">
                type,
            </if>
        </trim>
        <trim prefix=" values (" suffix=")" suffixOverrides=",">
            <if test="recordId !=null and recordId !=''">
                #{recordId},
            </if>
            <if test="checkRecordId !=null and checkRecordId !=''">
                #{checkRecordId},
            </if>
            <if test="modCheckId !=null and modCheckId !=''">
                #{modCheckId},
            </if>
            <if test="proId !=null and proId !=''">
                #{proId},
            </if>
            <if test="sizeId !=null and sizeId !=''">
                #{sizeId},
            </if>
            <if test="reinforcementId !=null and reinforcementId !=''">
                #{reinforcementId},
            </if>
            <if test="blockId !=null and blockId !=''">
                #{blockId},
            </if>
            <if test="stock !=null and stock !=''">
                #{stock},
            </if>
            <if test="createTime !=null and createTime !=''">
                #{createTime},
            </if>
            <if test="type !=null">
                #{type},
            </if>
        </trim>
    </insert>
 
    <update id="updateSteelStockRecordByCheckId">
        update t_steel_stock_record set is_use = #{isUse} where check_record_id = #{checkRecordId}
    </update>
 
</mapper>