叶松
2023-11-27 111a401f033749c965f02f58c586a8feafd9afd1
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<?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.materials.modules.biz.mixingstationstorage.mapper.MinXingPlantMapper">
 
  <insert id="insert" >
      insert into t_material_stock_record
      <trim prefix="(" suffix=")" suffixOverrides=",">
          <if test="id != null">
              id,
          </if>
          <if test="createDate != null">
              create_date,
          </if>
          <if test="type != null">
              type,
          </if>
          <if test="opType != null">
              op_type,
          </if>
          <if test="dictId != null">
              material_name,
          </if>
          <if test="materialValue != null">
              material_value,
          </if>
          <if test="beforeStock != null">
              before_stock,
          </if>
          <if test="afterStock != null">
              after_stock,
          </if>
          <if test="companyId != null">
              company_id,
          </if>
          <if test="remark != null">
              remark,
          </if>
          <if test="createUser != null">
              create_user,
          </if>
          <if test="supplierName != null">
              supplier_name,
          </if>
      </trim>
      <trim prefix="values (" suffix=")" suffixOverrides=",">
          <if test="id != null">
              #{id},
          </if>
          <if test="createDate != null">
              #{createDate},
          </if>
          <if test="type != null">
              #{type},
          </if>
          <if test="opType != null">
              #{opType},
          </if>
          <if test="dictId != null">
              #{dictId},
          </if>
          <if test="materialValue != null">
              #{materialValue},
          </if>
          <if test="beforeStock != null">
              #{beforeStock},
          </if>
          <if test="afterStock != null">
              #{afterStock},
          </if>
          <if test="companyId != null">
              #{companyId},
          </if>
          <if test="remark != null">
              #{remark},
          </if>
          <if test="createUser != null">
              #{createUser},
          </if>
          <if test="supplierName != null">
              #{supplierName},
          </if>
      </trim>
  </insert>
 
  <select id="selectAllList" parameterType="com.thhy.materials.modules.biz.mixingstationstorage.dto.MinXingPlantDto" resultType="com.thhy.materials.modules.biz.mixingstationstorage.entity.MinXingPlantVo">
      SELECT
          DATE_FORMAT(a.create_date, '%Y-%m-%d %H:%i:%S') createDate,
          b.dict_name dictName,
          a.material_value changeStock,
          d.real_name username,
          '吨' unit,
          a.supplier_name supplierName
      FROM t_material_stock_record a
      LEFT JOIN sys_dict b ON b.dict_id = a.material_name
      LEFT JOIN sys_users d ON d.user_id = a.create_user
      where
      a.op_type =1  and a.company_id = #{companyId}
      <if test="dictId != null and dictId != ''">
          AND a.material_name = #{dictId}
      </if>
      <if test="supplierName != null and supplierName != ''">
          AND a.supplier_name regexp #{supplierName}
      </if>
      <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
          AND a.create_date BETWEEN #{startTime} AND #{endTime}
      </if>
      order by a.create_date desc
  </select>
 
  <!--  库存管理 -->
  <select id="selectInventoryList" resultType="java.util.Map">
    SELECT
            a.id,
            b.dict_name materialName,
            '吨' unit,
            FORMAT(a.material_value, 4) materialValue,
            a.material_name dictId
    FROM t_material_stock a
    LEFT JOIN sys_dict b ON b.dict_id = material_name
    where a.company_id = #{companyId}
    <if test="id != null and id != ''">
      AND a.id =  #{id}
    </if>
    <if test="materialName != null and materialName != ''">
      AND a.material_name in (SELECT dict_id FROM sys_dict WHERE dict_type = 'pipe_materials' and dict_name LIKE CONCAT('%',#{materialName},'%'))
    </if>
    order by a.create_time desc
  </select>
 
  <update id="updateInventory" parameterType="com.thhy.materials.modules.biz.mixingstationstorage.entity.TMaterialStockVo">
    <if test=" id != null">
      UPDATE t_material_stock SET material_value = #{materialValue} WHERE id = #{id}
    </if>
    <if test="dictId != null">
      update t_material_stock set material_value=material_value+#{materialValue}  WHERE material_name= #{dictId}
    </if>
  </update>
  <!-- 库存管理结束 -->
 
  <!-- 校正记录 -->
  <insert id="insertInventoryRecord">
    insert into t_material_stock_record
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="createDate != null">
        create_date,
      </if>
      <if test="type != null">
        type,
      </if>
      <if test="opType != null">
        op_type,
      </if>
      <if test="materialName != null">
        material_name,
      </if>
      <if test="materialValue != null">
        material_value,
      </if>
      <if test="beforeStock != null">
        before_stock,
      </if>
      <if test="afterStock != null">
        after_stock,
      </if>
      <if test="companyId != null">
        company_id,
      </if>
      <if test="remark != null">
        remark,
      </if>
      <if test="createUser != null">
        create_user,
      </if>
      <if test="supplierName != null">
        supplier_name,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id},
      </if>
      <if test="createDate != null">
        #{createDate},
      </if>
      <if test="type != null">
        #{type},
      </if>
      <if test="opType != null">
        #{opType},
      </if>
      <if test="materialName != null">
        #{materialName},
      </if>
      <if test="materialValue != null">
        #{materialValue},
      </if>
      <if test="beforeStock != null">
        #{beforeStock},
      </if>
      <if test="afterStock != null">
        #{afterStock},
      </if>
      <if test="companyId != null">
        #{companyId},
      </if>
      <if test="remark != null">
        #{remark},
      </if>
      <if test="createUser != null">
        #{createUser},
      </if>
      <if test="supplierName != null">
        #{supplierName},
      </if>
    </trim>
  </insert>
  <select id="selectInventoryRecordList" parameterType="com.thhy.materials.modules.biz.mixingstationstorage.dto.TMaterialStockRecordDto" resultType="com.thhy.materials.modules.biz.mixingstationstorage.entity.TMaterialStockRecordVo">
    SELECT
            a.id,
            DATE_FORMAT(a.create_date, '%Y-%m-%d %H:%i:%S') createTime,
            b.dict_name materialName,
            '吨' unit,
            a.material_value  materialValue,
            a.before_stock beforeStock,
            a.after_stock afterStock,
            a.remark remark,
            a.create_user createUser
    FROM t_material_stock_record a
                 LEFT JOIN sys_dict b ON b.dict_id = material_name
    WHERE a.type = 3 and a.company_id = #{companyId}
    <if test="dictId != null and dictId != ''">
      AND a.material_name = #{dictId}
    </if>
    <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
      AND a.create_date BETWEEN #{startTime} AND #{endTime}
    </if>
    order by a.create_date desc
  </select>
 
  <!-- 校正记录结束 -->
 
 
  <!-- 消耗记录 Consumption records -->
  <select id="selectAllConsumptionList" parameterType="com.thhy.materials.modules.biz.mixingstationstorage.dto.ConsumptionRecordDto" resultType="com.thhy.materials.modules.biz.mixingstationstorage.entity.MXConsumptionRecordsVo">
      SELECT
              DATE_FORMAT(a.create_date, '%Y-%m-%d %H:%i:%S') createDate,
              d.dict_name materialName,
              '吨' unit,
              FORMAT(a.material_value, 4) materialValue,
              a.pipe_num pipNum,
              c.pro_name proName
      FROM t_material_stock_record a
         LEFT JOIN t_pipe_info b ON b.pipe_id = a.pipe_id
         LEFT JOIN sys_project c ON c.pro_id = b.pro_id
         LEFT JOIN sys_dict d ON d.dict_id = a.material_name
        WHERE a.type = 2 AND a.company_id = #{companyId}
    <if test="dictId != null and dictId != ''">
      AND a.material_name = #{dictId}
    </if>
    <if test="proId != null and proId != ''">
      AND b.pro_id = #{proId}
    </if>
    <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
      AND a.create_date BETWEEN #{startTime} AND #{endTime}
    </if>
  </select>
  
  <select id="numberOfMaterials" parameterType="com.thhy.materials.modules.biz.mixingstationstorage.dto.NumberOfMaterialsDto" resultType="java.util.Map">
      SELECT
            a.dict_name materialName,
            IFNULL(FORMAT(sum(b.materialValue),4),0) materialValue
      FROM sys_dict a
      LEFT JOIN
           (SELECT
                  a.material_value materialValue,
                  a.material_name dict_id
            FROM t_material_stock_record a
            WHERE a.type = 2
              and a.create_date BETWEEN #{startDay} and #{endDay}
              and a.company_id = #{companyId}
            )b on b.dict_id = a.dict_id
      WHERE a.dict_type ='pipe_materials' and a.is_use = 1
      <if test="dictId != null and dictId !=''">
        and a.dict_id =#{dictId}
      </if>
      GROUP BY a.dict_name
  </select>
 
  <select id="queryValueMonth" parameterType="com.thhy.materials.modules.biz.mixingstationstorage.dto.NumberOfMaterialsDto" resultType="com.thhy.materials.modules.biz.materialsplan.entity.StatVo">
 
    SELECT
    d.moth shuDate,
    IFNULL(c.materialValue,0) materialValue
    FROM (
        SELECT moth FROM (
            SELECT
            DATE_FORMAT( date_add( concat( #{startDay} ), INTERVAL ( help_topic_id  ) DAY ), '%Y-%m' ) moth
            FROM
            mysql.help_topic
            WHERE
            help_topic_id &lt;= timestampdiff( DAY, concat( #{startDay} ), concat( #{endDay} ) )
        ) m GROUP BY m.moth
    ) d
    LEFT JOIN (
        SELECT createDate,
          sum(materialValue) materialValue,
          dictId
        FROM(
            SELECT
            DATE_FORMAT( a.create_date, '%Y-%m') createDate,
            a.material_value materialValue,
            a.material_name dictId
            FROM t_material_stock_record a
            WHERE a.material_name = #{dictId} AND a.type = 2 AND a.company_id = #{companyId}
        ) b
        GROUP BY b.createDate,b.dictId
    ) c on c.createDate = d.moth
  </select>
 
  <select id="queryValueDay" parameterType="com.thhy.materials.modules.biz.mixingstationstorage.dto.NumberOfMaterialsDto" resultType="com.thhy.materials.modules.biz.materialsplan.entity.StatVo">
    SELECT
            d.moth shuDate,
            IFNULL(c.materialValue,0) materialValue
    FROM (
      SELECT
      DATE_FORMAT( date_add( concat( #{startDay} ), INTERVAL ( help_topic_id  ) DAY ), '%Y-%m-%d' ) moth
      FROM
      mysql.help_topic
      WHERE
      help_topic_id &lt;= timestampdiff( DAY, concat( #{startDay} ), concat( #{endDay} ) )
    ) d
    LEFT JOIN (
        SELECT createDate,
        sum(materialValue) materialValue,
        dictId
        FROM(
            SELECT
            DATE_FORMAT( a.create_date, '%Y-%m-%d') createDate,
            a.material_value materialValue,
            a.material_name dictId
            FROM t_material_stock_record a
            WHERE a.material_name = #{dictId} AND a.type = 2 AND a.company_id = #{companyId}
        ) b
        GROUP BY b.createDate,b.dictId
    ) c on c.createDate = d.moth
  </select>
  <!--消耗记录结束 -->
</mapper>