PreTaskStockSheetMapper.xml
8.81 KB
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
<?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.lframework.xingyun.sc.mappers.PreTakeStockSheetMapper">
    <resultMap id="PreTakeStockSheet" type="com.lframework.xingyun.sc.entity.PreTakeStockSheet">
        <id column="id" property="id"/>
        <result column="code" property="code"/>
        <result column="sc_id" property="scId"/>
        <result column="take_status" property="takeStatus"/>
        <result column="description" property="description"/>
        <result column="create_by" property="createBy"/>
        <result column="create_time" property="createTime"/>
        <result column="update_by" property="updateBy"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>
    <resultMap id="PreTakeStockSheetFullDto" type="com.lframework.xingyun.sc.dto.stock.take.pre.PreTakeStockSheetFullDto">
        <id column="id" property="id"/>
        <result column="code" property="code"/>
        <result column="sc_id" property="scId"/>
        <result column="take_status" property="takeStatus"/>
        <result column="description" property="description"/>
        <result column="update_by" property="updateBy"/>
        <result column="update_time" property="updateTime"/>
        <collection property="details" ofType="com.lframework.xingyun.sc.dto.stock.take.pre.PreTakeStockSheetFullDto$SheetDetailDto" javaType="java.util.ArrayList">
            <id column="detail_id" property="id"/>
            <result column="detail_product_id" property="productId"/>
            <result column="detail_first_num" property="firstNum"/>
            <result column="detail_second_num" property="secondNum"/>
            <result column="detail_rand_num" property="randNum"/>
        </collection>
    </resultMap>
    <resultMap id="QueryPreTakeStockSheetProductDto" type="com.lframework.xingyun.sc.dto.stock.take.pre.QueryPreTakeStockSheetProductDto">
        <result column="product_id" property="productId"/>
        <result column="first_num" property="firstNum"/>
        <result column="second_num" property="secondNum"/>
        <result column="rand_num" property="randNum"/>
        <result column="take_status" property="takeStatus"/>
    </resultMap>
    <resultMap id="PreTakeStockProductDto" type="com.lframework.xingyun.sc.dto.stock.take.pre.PreTakeStockProductDto">
        <id column="id" property="id"/>
        <result column="code" property="code"/>
        <result column="name" property="name"/>
        <result column="category_id" property="categoryId"/>
        <result column="category_name" property="categoryName"/>
        <result column="brand_id" property="brandId"/>
        <result column="brand_name" property="brandName"/>
        <result column="sku_code" property="skuCode"/>
        <result column="external_code" property="externalCode"/>
        <result column="spec" property="spec"/>
        <result column="unit" property="unit"/>
    </resultMap>
    <sql id="PreTakeStockSheetDto_sql">
        SELECT
            tb.*
        FROM tbl_pre_take_stock_sheet AS tb
    </sql>
    <sql id="PreTakeStockSheetFullDto_sql">
        SELECT
            tb.id,
            tb.code,
            tb.sc_id,
            tb.take_status,
            tb.description,
            tb.update_by,
            tb.update_time,
            d.id AS detail_id,
            d.product_id AS detail_product_id,
            d.first_num AS detail_first_num,
            d.second_num AS detail_second_num,
            d.rand_num AS detail_rand_num
        FROM tbl_pre_take_stock_sheet AS tb
        LEFT JOIN tbl_pre_take_stock_sheet_detail AS d ON d.sheet_id = tb.id
    </sql>
    <sql id="PreTakeStockSheetSelectorDto_sql">
        SELECT
            tb.id,
            tb.code,
            tb.sc_id,
            tb.take_status,
            tb.description,
            tb.create_by,
            tb.create_time,
            tb.update_by,
            tb.update_time
        FROM tbl_pre_take_stock_sheet AS tb
    </sql>
    <sql id="QueryPreTakeStockSheetProductDto_sql">
        SELECT
            tb.product_id,
            tb.first_num,
            tb.second_num,
            tb.rand_num,
            sh.take_status
        FROM tbl_pre_take_stock_sheet_detail AS tb
        LEFT JOIN tbl_pre_take_stock_sheet AS sh ON sh.id = tb.sheet_id
    </sql>
    <sql id="PreTakeStockProductDto_sql">
        SELECT
            g.id,
            g.code,
            g.name,
            c.id AS category_id,
            c.name AS category_name,
            b.id AS brand_id,
            b.name AS brand_name,
            g.sku_code,
            g.external_code,
            g.spec,
            g.unit
        FROM base_data_product AS g
        LEFT JOIN base_data_product_category AS c ON c.id = g.category_id
        LEFT JOIN base_data_product_brand AS b ON b.id = g.brand_id
        LEFT JOIN recursion_mapping AS rm ON rm.node_id = c.id and rm.node_type = 2
    </sql>
    <select id="query" resultMap="PreTakeStockSheet">
        <include refid="PreTakeStockSheetDto_sql"/>
        <where>
            <if test="vo.code != null and vo.code != ''">
                AND tb.code = #{vo.code}
            </if>
            <if test="vo.scId != null and vo.scId != ''">
                AND tb.sc_id = #{vo.scId}
            </if>
            <if test="vo.takeStatus != null">
                AND tb.take_status = #{vo.takeStatus}
            </if>
            <if test="vo.updateBy != null and vo.updateBy != ''">
                AND tb.update_by_id = #{vo.updateBy}
            </if>
            <if test="vo.updateTimeStart != null">
                AND tb.update_time >= #{vo.updateTimeStart}
            </if>
            <if test="vo.updateTimeEnd != null">
                <![CDATA[
                AND tb.update_time <= #{vo.updateTimeEnd}
                ]]>
            </if>
        </where>
        ORDER BY tb.update_time DESC
    </select>
    <select id="getDetail" resultMap="PreTakeStockSheetFullDto">
        <include refid="PreTakeStockSheetFullDto_sql"/>
        WHERE tb.id = #{id}
        ORDER BY d.order_no
    </select>
    <select id="selector" resultMap="PreTakeStockSheet">
        <include refid="PreTakeStockSheetDto_sql"/>
        <where>
            <if test="vo.code != null and vo.code != ''">
                AND tb.code = #{vo.code}
            </if>
            <if test="vo.scId != null and vo.scId != ''">
                AND tb.sc_id = #{vo.scId}
            </if>
            <if test="vo.takeStatus != null">
                AND tb.take_status = #{vo.takeStatus}
            </if>
            <if test="vo.updateTimeStart != null">
                AND tb.update_time >= #{vo.updateTimeStart}
            </if>
            <if test="vo.updateTimeEnd != null">
                <![CDATA[
                AND tb.update_time <= #{vo.updateTimeEnd}
                ]]>
            </if>
        </where>
        ORDER BY tb.update_time DESC
    </select>
    <select id="getProducts" resultMap="QueryPreTakeStockSheetProductDto">
        <include refid="QueryPreTakeStockSheetProductDto_sql"/>
        WHERE tb.sheet_id = #{id}
        <if test="planId != null and planId != ''">
            AND tb.product_id IN (SELECT product_id FROM tbl_take_stock_plan_detail WHERE plan_id = #{planId})
        </if>
        ORDER BY tb.order_no
    </select>
    <select id="queryPreTakeStockList" resultMap="PreTakeStockProductDto">
        <include refid="PreTakeStockProductDto_sql"/>
        <where>
            <if test="vo != null">
                <if test="vo.condition != null and vo.condition != ''">
                    AND (
                    g.code LIKE CONCAT('%', #{vo.condition}, '%')
                    OR g.name LIKE CONCAT('%', #{vo.condition}, '%')
                    OR g.sku_code LIKE CONCAT('%', #{vo.condition}, '%')
                    OR g.external_code LIKE CONCAT('%', #{vo.condition}, '%')
                    )
                </if>
                <if test="vo.brandId != null and vo.brandId != ''">
                    AND b.id = #{vo.brandId}
                </if>
                <if test="vo.categoryId != null and vo.categoryId != ''">
                    AND (c.id = #{vo.categoryId} OR FIND_IN_SET(#{vo.categoryId}, rm.path))
                </if>
            </if>
            AND g.product_type = 1
        </where>
        ORDER BY g.code
    </select>
    <select id="queryPreTakeStockByCondition" resultMap="PreTakeStockProductDto">
        <include refid="PreTakeStockProductDto_sql"/>
        <where>
            AND (
            g.code LIKE CONCAT('%', #{condition}, '%')
            OR g.name LIKE CONCAT('%', #{condition}, '%')
            OR g.sku_code LIKE CONCAT('%', #{condition}, '%')
            OR g.external_code LIKE CONCAT('%', #{condition}, '%')
            )
            AND g.product_type = 1
        </where>
        ORDER BY g.code
    </select>
</mapper>