李林
2023-10-07 658d4927d468c47208fd012d9128b09249c07eff
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
<?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.chinaztt.mes.basic.mapper.LocationMapper">
 
    <resultMap id="locationMap" type="com.chinaztt.mes.basic.entity.Location">
        <id property="id" column="id"/>
        <result property="factoryId" column="factory_id"/>
        <result property="pType" column="p_type"/>
        <result property="locNo" column="loc_no"/>
        <result property="locName" column="loc_name"/>
        <result property="locDesc" column="loc_desc"/>
        <result property="locType" column="loc_type"/>
        <result property="locAddr" column="loc_addr"/>
        <result property="locMap" column="loc_map"/>
        <result property="locStatus" column="loc_status"/>
        <result property="locRemark" column="loc_remark"/>
        <result property="createTime" column="create_time"/>
        <result property="locGroup" column="loc_group"/>
        <result property="factoryName" column="factory_name"/>
        <result property="ifsLocation" column="ifs_location"/>
        <result property="ifsLocationGroup" column="location_type_group"/>
        <result property="transportLocationNo" column="transport_location_no"/>
    </resultMap>
    <resultMap id="locationMapDto" type="com.chinaztt.mes.basic.dto.LocationDTO">
        <id property="id" column="id"/>
        <result property="factoryId" column="factory_id"/>
        <result property="pType" column="p_type"/>
        <result property="locNo" column="loc_no"/>
        <result property="locName" column="loc_name"/>
        <result property="locDesc" column="loc_desc"/>
        <result property="locType" column="loc_type"/>
        <result property="locAddr" column="loc_addr"/>
        <result property="locMap" column="loc_map"/>
        <result property="locStatus" column="loc_status"/>
        <result property="locRemark" column="loc_remark"/>
        <result property="createTime" column="create_time"/>
        <result property="locGroup" column="loc_group"/>
        <result property="factoryName" column="factory_name"/>
        <result property="disabled" column="disabled"/>
        <result property="key" column="id"/>
        <result property="label" column="loc_name"/>
        <result property="value" column="id"/>
        <result property="workstationId" column="workstation_id"/>
        <result property="workstationName" column="workstation_name"/>
        <result property="workstationNo" column="workstation_no"/>
        <result property="partNo" column="part_no"/>
        <result property="partName" column="part_name"/>
        <result property="partBatchNo" column="part_batch_no"/>
        <result property="ifsLocation" column="ifs_location"/>
        <result property="ifsLocationGroup" column="location_type_group"/>
        <result property="locationType" column="location_type"/>
        <result property="transportLocationNo" column="transport_location_no"/>
    </resultMap>
 
    <select id="getLocationDtoPage" resultMap="locationMapDto">
        select * from(<include refid="LocExt"/>) tempA
        <if test="ew.emptyOfWhere == false">
                ${ew.customSqlSegment}
        </if>
    </select>
 
    <select id="getLoc" resultMap="locationMap">
        select * from(<include refid="Loc"/>) a
        <if test="ew.emptyOfWhere == false">
            <where>
                ${ew.SqlSegment}
            </where>
        </if>
    </select>
 
    <sql id="LocExt">
        select
            bf.factory_name,
            bl."id",
            bl.p_type,
            bl.loc_no,
            bl.loc_name,
            bl.loc_desc,
            bl.loc_type,
            bl.loc_addr,
            bl.loc_map,
            bl.loc_status,
            bl.loc_remark,
            bl.create_time,
            bl.loc_group,
            bw.id workstation_id,
            bw.workstation_no,
            bwl.location_type
        FROM basic_location bl
                 left join basic_factory bf on bf."id" = bl.factory_id
                 left join basic_workstation_location bwl on bwl.location_id = bl."id"
                 left join basic_workstation bw on bw.id = bwl.workstation_id
        where bl.active = true
    </sql>
 
    <sql id="Loc">
        select
            bf.factory_name,
            wl."id",
            wl.p_type,
            wl.loc_no,
            wl.loc_name,
            wl.loc_desc,
            wl.loc_type,
            wl.loc_addr,
            wl.loc_map,
            wl.loc_status,
            wl.loc_remark,
            wl.create_time,
            wl.ifs_location,
            wl.ifs_location_group,
            wl.loc_group
        FROM basic_location wl
                 left join basic_factory bf on wl.factory_id = bf."id"
        where wl.active = true
    </sql>
 
    <update id="upLocationDate">
        UPDATE basic_location
        SET loc_no = null
        where id in
        <foreach item="item" index="index" collection="ids" open="(" separator="," close=")">
            #{item}
        </foreach>
    </update>
 
    <select id="getNoWorkstationLocation" resultMap="locationMapDto">
        SELECT FALSE disabled,
               wl."id",
               wl.loc_name
        FROM
            basic_location wl
        WHERE
            wl.active = TRUE
    </select>
 
    <select id="getPrepare" resultMap="locationMap">
        SELECT wl.loc_name,wl.id,wl.loc_no
        from basic_location wl
        where wl.active = true
    </select>
 
    <select id="pdaList" resultType="com.alibaba.fastjson.JSONObject">
        select distinct workstation_no   "workstationNo",
                        workstation_name "workstationName",
                        loc_no           "locNo",
                        loc_name         "locName",
                        loc_type         "locType"
        from (
                 select bw.workstation_no,
                        bw."name" workstation_name,
                        bl.loc_no,
                        bl.loc_name,
                        sdi.label loc_type,
                        bp.part_no,
                        bp.part_name,
                        ws.part_batch_no
                 from basic_location bl
                          left join warehouse_stock ws on ws.location_id = bl."id"
                          left join basic_part bp on bp."id" = ws.part_id
                          left join basic_workstation_location bwl on bwl.location_id = bl."id"
                          left join basic_workstation bw on bw."id" = bwl.workstation_id
                          left join sys_dict_item sdi on sdi."value" = bl.loc_type and sdi.dict_id = 37
                 where bl.active = true
             ) tempA
        <if test="ew.emptyOfWhere == false">
            <where>
                ${ew.SqlSegment}
            </where>
        </if>
        order by workstation_no
    </select>
 
    <select id="getLocationByLocationNo" resultMap="locationMap">
        SELECT * FROM basic_location WHERE loc_no = #{locationNo} AND  active = 't' LIMIT 1
    </select>
 
 
    <select id="getLocation4" resultType="com.chinaztt.mes.basic.entity.Location">
        SELECT
            bl.*
        FROM
            basic_location bl
                LEFT JOIN basic_workstation_location bwl ON bl."id" = bwl.location_id
        WHERE bwl.location_type = 4
          AND bwl.workstation_id = #{workstationId}
    </select>
 
    <select id="getLocationByWorkstationId" resultType="com.chinaztt.mes.basic.entity.Location">
        SELECT
        bl.*
        FROM
        basic_location bl
        LEFT JOIN basic_workstation_location bwl ON bl."id" = bwl.location_id
        WHERE
        bwl.workstation_id = #{workstationId}
        AND bwl.location_type = #{locationType}
        AND bl.active = true
        AND bl.loc_status = 1
    </select>
 
 
    <select id="getLocationByGroups" resultType="java.util.Map">
        SELECT id,loc_no as locNo from basic_location
        where loc_group in
        <foreach item="item" index="index" collection="localGroups" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>
    <select id="getReturnLocationByWorkstationId" resultType="com.chinaztt.mes.basic.entity.Location">
        SELECT
            bl.*
        FROM
            basic_location bl
                LEFT JOIN basic_workstation_location bwl ON bl."id" = bwl.location_id
        WHERE
            bwl.workstation_id = #{workstationId}
          AND bwl.location_type in 
          <foreach collection="locationTypeList" index="index" item="locationType" open="(" separator=","
                   close=")">
              #{locationType}
          </foreach>
        AND bl.active = true
        AND bl.loc_status = 1
        order by bwl.location_type
    </select>
</mapper>