李林
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
<?xml version="1.0" encoding="UTF-8"?>
 
<!--
  ~
  ~      Copyright (c) 2018-2025, ztt All rights reserved.
  ~
  ~  Redistribution and use in source and binary forms, with or without
  ~  modification, are permitted provided that the following conditions are met:
  ~
  ~ Redistributions of source code must retain the above copyright notice,
  ~  this list of conditions and the following disclaimer.
  ~  Redistributions in binary form must reproduce the above copyright
  ~  notice, this list of conditions and the following disclaimer in the
  ~  documentation and/or other materials provided with the distribution.
  ~  Neither the name of the pig4cloud.com developer nor the names of its
  ~  contributors may be used to endorse or promote products derived from
  ~  this software without specific prior written permission.
  ~  Author: ztt
  ~
  -->
 
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 
<mapper namespace="com.chinaztt.mes.warehouse.mapper.CheckDetailMapper">
 
    <resultMap id="checkDetailMap" type="com.chinaztt.mes.warehouse.dto.CheckDetailDTO">
        <id property="id" column="id"/>
        <result property="warehouseCheckId" column="warehouse_check_id"/>
        <result property="partId" column="part_id"/>
        <result property="partBatchNo" column="part_batch_no"/>
        <result property="locationId" column="location_id"/>
        <result property="locQty" column="loc_qty"/>
        <result property="unit" column="unit"/>
        <result property="chkQty" column="chk_qty"/>
        <result property="chkDiffQty" column="chk_diff_qty"/>
        <result property="partNo" column="part_no"/>
        <result property="locName" column="loc_name"/>
        <result property="locNo" column="loc_no"/>
        <result property="status" column="status"/>
        <result property="systemNo" column="system_no"/>
        <result property="adjQty" column="adj_qty"/>
        <result property="adjReason" column="adj_reason"/>
    </resultMap>
    <select id="getCheckDetail" resultMap="checkDetailMap">
        INSERT INTO warehouse_check_detail(location_id,part_id,part_batch_no,loc_qty,unit,warehouse_check_id,status,system_no)
        SELECT
        ws.location_id,ws.part_id,ws.part_batch_no,ws.stock_quantity,bp.unit,#{ew.id} as warehouse_check_id,'待盘' as
        status,ws.system_no
        from warehouse_stock ws
        left join basic_location wl on wl."id"=ws.location_id
        left join basic_warehouse ww on ww."id"=wl.loc_group
        left join basic_factory bf on bf."id"=ww.factory_id
        left join basic_part bp on bp."id"=ws.part_id
        where
        bf."id"=#{ew.factoryId}
        <if test="ew.warehouseId!=null and ew.warehouseId!=''">
            and ww."id"=#{ew.warehouseId}
        </if>
        <if test="ew.locationIds!=null and ew.locationIds.size>0">
            AND EXISTS(select 1 from warehouse_check_location wcl where wcl.location_id=wl."id" and
            wcl.check_main_id=#{ew.id})
        </if>
        <if test="ew.partIds!=null and ew.partIds.size>0">
            AND EXISTS (select 1 from warehouse_check_part wcp where wcp.part_id=ws.part_id and
            wcp.check_main_id=#{ew.id})
        </if>
    </select>
    <select id="getCheckDetailPage" resultMap="checkDetailMap">
        SELECT
        a.chk_diff_qty,a.chk_qty,a."id",a.loc_qty,a.part_batch_no,a.unit,a.warehouse_check_id,b.part_no,c.loc_name,a.status,c.loc_no
        FROM warehouse_check_detail a
        LEFT JOIN basic_part b ON b."id" = a.part_id
        LEFT JOIN basic_location c ON c."id" = a.location_id
        <if test="ew.emptyOfWhere == false">
            ${ew.customSqlSegment}
        </if>
    </select>
    <select id="getCheckDetailById" resultMap="checkDetailMap">
        SELECT
a.chk_diff_qty,a.chk_qty,a."id",a.loc_qty,a.part_batch_no,a.unit,a.warehouse_check_id,b.part_no,c.loc_name,a.status
FROM warehouse_check_detail  a
LEFT JOIN basic_part b ON b."id" = a.part_id
LEFT JOIN basic_location c ON c."id" = a.location_id
where a."id" = #{id}
    </select>
    <select id="findCheckDetailByNo" resultMap="checkDetailMap">
SELECT
    A.chk_diff_qty,
    A.chk_qty,
    A.status,
    A."id",
    A.loc_qty,
    A.location_id,
    A.part_batch_no,
    A.part_id,
    A.unit,
    A.warehouse_check_id,
    b.part_no,
    C.loc_name,
    C.loc_no
FROM
    warehouse_check_main e
    LEFT JOIN warehouse_check_detail A ON A.warehouse_check_id = e."id"
    LEFT JOIN basic_part b ON b."id" = A.part_id
    LEFT JOIN basic_location C ON C."id" = A.location_id
where e.chk_no = #{ew.chkNo}
    </select>
    <select id="getCheckDetailByNo" resultMap="checkDetailMap">
        SELECT
    A.*
    FROM
    warehouse_check_main e
    LEFT JOIN warehouse_check_detail A ON A.warehouse_check_id = e."id"
    LEFT JOIN basic_part b ON b."id" = A.part_id
    LEFT JOIN basic_location C ON C."id" = A.location_id
    where e.chk_no = #{ew.chkNo}
    and b.part_no =#{ew.partNo}
    and C.loc_no = #{ew.locNo}
    and A.part_batch_no = #{ew.partBatchNo}
    </select>
    <select id="getCheckDetailByPage" resultMap="checkDetailMap">
        SELECT
        a.chk_diff_qty,a.chk_qty,a."id",a.loc_qty,a.part_batch_no,a.unit,a.warehouse_check_id,b.part_no,c.loc_name,a.status,d.adj_qty,d.adj_reason,c.loc_no
        FROM warehouse_check_detail a
        LEFT JOIN basic_part b ON b."id" = a.part_id
        LEFT JOIN basic_location c ON c."id" = a.location_id
        LEFT JOIN warehouse_check_diffadj_detail d on d.check_detail_id = a."id"
        WHERE a.status in ('盘盈','盘亏')
        <if test="ew.emptyOfWhere == false">
            and ${ew.SqlSegment}
        </if>
    </select>
</mapper>