jiangping
2023-08-17 6365ab0a976afdd247742c9b3dca15deb3a7a7a1
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<?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="doumeemes.dao.ext.WTransferExtMapper">
 
  <!-- 管理页面查询 -->
  <resultMap id="WTransferExtListVO" type="doumeemes.dao.ext.vo.WTransferExtListVO" autoMapping="true">
    <id column="ID" jdbcType="INTEGER" property="id"/>
  </resultMap>
  <select id="selectList" parameterType="doumeemes.dao.ext.dto.QueryWTransferExtDTO" resultMap="WTransferExtListVO">
    SELECT
      a.*
    FROM w_transfer a
    <where>
      <if test="id != null">
        AND a.ID = #{id}
      </if>
      <if test="deleted != null">
        AND a.DELETED = #{deleted}
      </if>
      <if test="createUser != null">
        AND a.CREATE_USER = #{createUser}
      </if>
      <if test="createTime != null">
        AND a.CREATE_TIME = #{createTime}
      </if>
      <if test="updateUser != null">
        AND a.UPDATE_USER = #{updateUser}
      </if>
      <if test="updateTime != null">
        AND a.UPDATE_TIME = #{updateTime}
      </if>
      <if test="remark != null and remark != ''">
        AND a.REMARK = #{remark}
      </if>
      <if test="rootDepartId != null">
        AND a.ROOT_DEPART_ID = #{rootDepartId}
      </if>
      <if test="code != null and code != ''">
        AND a.CODE = #{code}
      </if>
      <if test="origin != null">
        AND a.ORIGIN = #{origin}
      </if>
      <if test="validDate != null">
        AND a.VALID_DATE = #{validDate}
      </if>
      <if test="originType != null">
        AND a.ORIGIN_TYPE = #{originType}
      </if>
      <if test="originCode != null and originCode != ''">
        AND a.ORIGIN_CODE = #{originCode}
      </if>
      <if test="originId != null">
        AND a.ORIGIN_ID = #{originId}
      </if>
      <if test="abstracts != null and abstracts != ''">
        AND a.ABSTRACTS = #{abstracts}
      </if>
      <if test="outDepartId != null">
        AND a.OUT_DEPART_ID = #{outDepartId}
      </if>
      <if test="outUserId != null">
        AND a.OUT_USER_ID = #{outUserId}
      </if>
      <if test="outWarehouseId != null">
        AND a.OUT_WAREHOUSE_ID = #{outWarehouseId}
      </if>
      <if test="outPlandate != null">
        AND a.OUT_PLANDATE = #{outPlandate}
      </if>
      <if test="outActdate != null">
        AND a.OUT_ACTDATE = #{outActdate}
      </if>
      <if test="inUserId != null">
        AND a.IN_USER_ID = #{inUserId}
      </if>
      <if test="inWarehouseId != null">
        AND a.IN_WAREHOUSE_ID = #{inWarehouseId}
      </if>
      <if test="inPlandate != null">
        AND a.IN_PLANDATE = #{inPlandate}
      </if>
      <if test="inActdate != null">
        AND a.IN_ACTDATE = #{inActdate}
      </if>
      <if test="status != null">
        AND a.STATUS = #{status}
      </if>
      <if test="type != null">
        AND a.TYPE = #{type}
      </if>
      and to_days(`a`.`CREATE_TIME`)=to_days(now())
    </where>
  </select>
  <select id="selectCountToday" parameterType="doumeemes.dao.ext.dto.QueryWTransferExtDTO" resultType="java.lang.Integer">
    SELECT
      count(1)
    FROM w_transfer a
    <where>
      <if test="id != null">
        AND a.ID = #{id}
      </if>
      <if test="deleted != null">
        AND a.DELETED = #{deleted}
      </if>
      <if test="createUser != null">
        AND a.CREATE_USER = #{createUser}
      </if>
      <if test="createTime != null">
        AND a.CREATE_TIME = #{createTime}
      </if>
      <if test="updateUser != null">
        AND a.UPDATE_USER = #{updateUser}
      </if>
      <if test="updateTime != null">
        AND a.UPDATE_TIME = #{updateTime}
      </if>
      <if test="remark != null and remark != ''">
        AND a.REMARK = #{remark}
      </if>
      <if test="rootDepartId != null">
        AND a.ROOT_DEPART_ID = #{rootDepartId}
      </if>
      <if test="code != null and code != ''">
        AND a.CODE = #{code}
      </if>
      <if test="origin != null">
        AND a.ORIGIN = #{origin}
      </if>
      <if test="validDate != null">
        AND a.VALID_DATE = #{validDate}
      </if>
      <if test="originType != null">
        AND a.ORIGIN_TYPE = #{originType}
      </if>
      <if test="originCode != null and originCode != ''">
        AND a.ORIGIN_CODE = #{originCode}
      </if>
      <if test="originId != null">
        AND a.ORIGIN_ID = #{originId}
      </if>
      <if test="abstracts != null and abstracts != ''">
        AND a.ABSTRACTS = #{abstracts}
      </if>
      <if test="outDepartId != null">
        AND a.OUT_DEPART_ID = #{outDepartId}
      </if>
      <if test="outUserId != null">
        AND a.OUT_USER_ID = #{outUserId}
      </if>
      <if test="outWarehouseId != null">
        AND a.OUT_WAREHOUSE_ID = #{outWarehouseId}
      </if>
      <if test="outPlandate != null">
        AND a.OUT_PLANDATE = #{outPlandate}
      </if>
      <if test="outActdate != null">
        AND a.OUT_ACTDATE = #{outActdate}
      </if>
      <if test="inUserId != null">
        AND a.IN_USER_ID = #{inUserId}
      </if>
      <if test="inWarehouseId != null">
        AND a.IN_WAREHOUSE_ID = #{inWarehouseId}
      </if>
      <if test="inPlandate != null">
        AND a.IN_PLANDATE = #{inPlandate}
      </if>
      <if test="inActdate != null">
        AND a.IN_ACTDATE = #{inActdate}
      </if>
      <if test="status != null">
        AND a.STATUS = #{status}
      </if>
      <if test="type != null">
        AND a.TYPE = #{type}
      </if>
    </where>
  </select>
 
 
 
  <select id="selectAdminList" parameterType="doumeemes.dao.ext.beanDto.QueryWTransferDto" resultMap="WTransferExtListVO">
    SELECT
        a.* , outWarehouse.NAME as outWarehouseName , inWarehouse.NAME as inWarehouseName,
        outD.NAME outDepartName , inD.NAME inDepartName, su.REALNAME as createName ,
     ( select s.REALNAME from  system_user s where s.id = a.OUT_USER_ID ) as outUserName ,
    ( select s.REALNAME from  system_user s where s.id = a.IN_USER_ID ) as inUserName
    FROM  w_transfer a
    left join warehouse outWarehouse on a.OUT_WAREHOUSE_ID = outWarehouse.id
    left join warehouse inWarehouse on a.IN_WAREHOUSE_ID = inWarehouse.id
    left join department outD on a.OUT_DEPART_ID = outD.id
    left join department inD on a.IN_DEPART_ID = inD.id
    left join `system_user` su on a.CREATE_USER = su.ID
    <where>
      <if test="code != null and code != ''">
        AND a.CODE like CONCAT('%',#{code},'%')
      </if>
      <if test="outPlanDateStart != null">
        AND a.OUT_PLANDATE >= #{outPlanDateStart}
      </if>
      <if test="outPlanDateEnd != null">
        AND #{outPlanDateEnd} >= a.OUT_PLANDATE
      </if>
      <if test="inDepartId != null">
        AND a.IN_DEPART_ID = #{inDepartId}
      </if>
      <if test="outDepartId != null">
        AND a.OUT_DEPART_ID = #{outDepartId}
      </if>
      <if test="outWarehouseId != null">
        AND a.OUT_WAREHOUSE_ID = #{outWarehouseId}
      </if>
      <if test="inWarehouseId != null">
        AND a.IN_WAREHOUSE_ID = #{inWarehouseId}
      </if>
      <if test="status != null">
        AND a.STATUS = #{status}
      </if>
      <if test="type != null">
        AND a.TYPE = #{type}
      </if>
 
      <if test="rootDepartId != null">
        AND `a`.`ROOT_DEPART_ID` = #{rootDepartId}
      </if>
 
 
      <if test="departId != null">
        AND ( `a`.`OUT_DEPART_ID` = #{departId} or `a`.`IN_DEPART_ID` = #{departId} )
      </if>
 
 
<!--      <if test="proUserId != null">-->
<!--        AND `a`.`CREATE_USER` = #{proUserId}-->
<!--      </if>-->
 
    <choose>
      <when test="departIds != null and departIds.size()>0">
        AND (
        a.CREATE_USER=#{createUser}  or a.OUT_USER_ID=#{createUser}  or a.IN_USER_ID=#{createUser}
        or
        exists (select d.id from company_user d where (d.user_id= a.CREATE_USER or d.user_id=a.OUT_USER_ID  or d.user_id= a.IN_USER_ID ) and d.department_id
        in <foreach collection="departIds" item="item" separator="," open="(" close=")">#{item}</foreach>)
        )
      </when>
    <otherwise>
      <if test="createUser!=null">
        and ( a.CREATE_USER=#{createUser}  or a.OUT_USER_ID=#{createUser}  or a.IN_USER_ID=#{createUser})
      </if>
    </otherwise>
    </choose>
 
    </where>
    order by a.CREATE_TIME desc
  </select>
 
 
 
 
  <select id="selectCount" parameterType="doumeemes.dao.ext.beanDto.QueryWTransferDto" resultType="java.lang.Integer">
    SELECT
        count(1)
      FROM  w_transfer a
      left join warehouse outWarehouse on a.OUT_WAREHOUSE_ID = outWarehouse.id
      left join warehouse inWarehouse on a.IN_WAREHOUSE_ID = inWarehouse.id
      left join department outD on a.OUT_DEPART_ID = outD.id
      left join department inD on a.IN_DEPART_ID = inD.id
      left join `system_user` su on a.CREATE_USER = su.ID
    <where>
      <if test="code != null and code != ''">
        AND a.CODE like CONCAT('%',#{code},'%')
      </if>
      <if test="outPlanDateStart != null">
        AND a.OUT_PLANDATE >= #{outPlanDateStart}
      </if>
      <if test="outPlanDateEnd != null">
        AND #{outPlanDateEnd} >= a.OUT_PLANDATE
      </if>
      <if test="inDepartId != null">
        AND a.IN_DEPART_ID = #{inDepartId}
      </if>
      <if test="outDepartId != null">
        AND a.OUT_DEPART_ID = #{outDepartId}
      </if>
      <if test="outWarehouseId != null">
        AND a.OUT_WAREHOUSE_ID = #{outWarehouseId}
      </if>
      <if test="inWarehouseId != null">
        AND a.IN_WAREHOUSE_ID = #{inWarehouseId}
      </if>
      <if test="status != null">
        AND a.STATUS = #{status}
      </if>
      <if test="type != null">
        AND a.TYPE = #{type}
      </if>
 
      <if test="rootDepartId != null">
        AND `a`.`ROOT_DEPART_ID` = #{rootDepartId}
      </if>
      <if test="departId != null">
        AND ( `a`.`OUT_DEPART_ID` = #{departId} or `a`.`IN_DEPART_ID` = #{departId} )
      </if>
      <!--      <if test="proUserId != null">-->
      <!--        AND `a`.`CREATE_USER` = #{proUserId}-->
      <!--      </if>-->
 
      <choose>
      <when test="departIds != null and departIds.size()>0">
        AND (
        a.CREATE_USER=#{createUser}  or a.OUT_USER_ID=#{createUser}  or a.IN_USER_ID=#{createUser}
        or
        exists (select d.id from company_user d where (d.user_id= a.CREATE_USER or d.user_id=a.OUT_USER_ID  or d.user_id= a.IN_USER_ID ) and d.department_id
        in <foreach collection="departIds" item="item" separator="," open="(" close=")">#{item}</foreach>)
        )
      </when>
      <otherwise>
        <if test="createUser!=null">
          and ( a.CREATE_USER=#{createUser}  or a.OUT_USER_ID=#{createUser}  or a.IN_USER_ID=#{createUser})
        </if>
      </otherwise>
      </choose>
    </where>
    order by a.CREATE_TIME desc
  </select>
 
  <select id="wTransferById"  resultType="doumeemes.dao.business.model.WTransfer">
    SELECT w.* ,
           outDepartment.name as outDepartName , outW.name as  outWarehouseName, outUser.REALNAME as outUserName,
           ( select wo.CODE from w_outbound wo where wo.ORIGIN_ID = w.id and wo.TYPE = 0  and wo.ORIGIN_CODE = w.`CODE`   limit 1  ) as outBillCode,
           inDepartment.name as inDepartName,inW.name as inWarehouseName,inUser.REALNAME as  inUserName,
           ( select wo.CODE from w_outbound wo where wo.ORIGIN_ID = w.id and wo.TYPE = 1  and wo.ORIGIN_CODE = w.`CODE`  limit 1  ) inBillCode ,
            cancel.REALNAME as cancelUserName , cancel.mobile as cancelUserMobile
           from w_transfer w
    left join department outDepartment on w.OUT_DEPART_ID = outDepartment.id
    left join department inDepartment on w.IN_DEPART_ID = inDepartment.id
    left join warehouse outW on w.OUT_WAREHOUSE_ID = outW.id
    left join warehouse inW on w.IN_WAREHOUSE_ID = inW.id
    left join `system_user` outUser on w.OUT_USER_ID = outUser.id
    left join `system_user` inUser on w.IN_USER_ID = inUser.id
    left join `system_user` cancel on w.CANCEL_USER_ID = cancel.id
    where 1 = 1 and w.id = #{id}
    limit 1
  </select>
 
 
  <select id="selectListByWorkorder"  resultType="doumeemes.dao.ext.bean.WTransferBean">
    select '1' as origin , CURDATE() as validDate , 3 as type ,  #{userId} as outUserId ,
           CURDATE() as outPlandate , CURDATE() as inPlandate ,a2.PICKING_WAREHOUSE_ID as outWarehouseId ,
           a4.WAREHOUSE_ID as inWarehouseId ,  ( select wu.PRO_USER_ID from workorder_user wu where wu.WORKORDER_ID = a1.id and wu.DELETED = 0  limit 1 )  as inUserId , a4.id as inLocationId ,
      a2.ID as proceduresId, a5.DEPART_ID as inDepartId ,  a6.DEPART_ID as outDepartId ,
      a1.BACKORDER_ID as backOrderId, GROUP_CONCAT( a1.CODE ) AS workorderCode,
           GROUP_CONCAT( a1.id ) AS workorderId
    from  workorder a1
    left join procedures a2 on a1.PROCEDURE_ID = a2.id
    left join device a3  on a1.PRO_GROUP_ID = a3.id
    left join warehouse_location a4 on a3.PRODUCE_WAREHOUSE_LOCATION_ID = a4.id
    LEFT JOIN warehouse a5 on a4.WAREHOUSE_ID = a5.id
    LEFT JOIN warehouse a6 on a2.PRODUCE_WAREHOUSE_ID = a6.id
    LEFT JOIN ( select GROUP_CONCAT( PRO_USER_ID  ) as proUserId , WORKORDER_ID from  workorder_user
    where  DELETED = 0 and FIND_IN_SET(workorder_user.WORKORDER_ID, #{ids}  ) group by  workorder_user.WORKORDER_ID ) a7 on a7.WORKORDER_ID = a1.id
    where  1 = 1 and FIND_IN_SET(a1.id, #{ids} )
    group by  a7.proUserId , a2.PRODUCE_WAREHOUSE_ID  , a1.PRO_USER_ID , a4.WAREHOUSE_ID , a4.id,   a1.BACKORDER_ID
  </select>
 
 
 
</mapper>