sfd
2025-05-22 e5a96bc789ca0252e31fd2e01bec5e471a02c0d6
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
<?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.aps.core.mapper.ApsPlateStandardRequireBomOrderDetailMapper">
    
    <resultMap type="com.aps.core.domain.ApsPlate.ApsPlateStandardRequireBomOrderDetail" id="ApsPlateStandardRequireBomOrderDetailResult">
        <result property="id"    column="id"    />
        <result property="requireId"    column="require_id"    />
        <result property="requireTrackId"    column="require_track_id"    />
        <result property="bomLineId"    column="bom_line_id"    />
        <result property="bomLineCode"    column="bom_line_code"    />
        <result property="docNo"    column="doc_no"    />
        <result property="beforeProdAmount"    column="before_prod_amount"    />
        <result property="deductionAmount"    column="deduction_amount"    />
        <result property="afterProdAmount"    column="after_prod_amount"    />
        <result property="orgCode"    column="org_code"    />
        <result property="batchNumber"    column="batch_number"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>
 
    <sql id="selectApsPlateStandardRequireBomOrderDetailVo">
        select id, require_id,require_track_id, bom_line_id, bom_line_code, doc_no,
               before_prod_amount, deduction_amount, after_prod_amount,
               org_code, batch_number, del_flag, create_time, create_by, update_by, update_time
        from aps_plate_standard_require_bom_order_detail
    </sql>
 
    <select id="selectApsPlateStandardRequireBomOrderDetailList" parameterType="com.aps.core.domain.ApsPlate.ApsPlateStandardRequireBomOrderDetail" resultMap="ApsPlateStandardRequireBomOrderDetailResult">
        <include refid="selectApsPlateStandardRequireBomOrderDetailVo"/>
        <where>  
            <if test="requireId != null  and requireId != ''"> and require_id = #{requireId}</if>
            <if test="requireTrackId != null  and requireTrackId != ''"> and require_track_id = #{requireTrackId}</if>
            <if test="bomLineId != null  and bomLineId != ''"> and bom_line_id = #{bomLineId}</if>
            <if test="bomLineCode != null  and bomLineCode != ''"> and bom_line_code = #{bomLineCode}</if>
            <if test="docNo != null  and docNo != ''"> and doc_no = #{docNo}</if>
            <if test="beforeProdAmount != null  and beforeProdAmount != ''"> and before_prod_amount = #{beforeProdAmount}</if>
            <if test="deductionAmount != null  and deductionAmount != ''"> and deduction_amount = #{deductionAmount}</if>
            <if test="afterProdAmount != null  and afterProdAmount != ''"> and after_prod_amount = #{afterProdAmount}</if>
            <if test="orgCode != null  and orgCode != ''"> and org_code = #{orgCode}</if>
            <if test="batchNumber != null  and batchNumber != ''"> and batch_number = #{batchNumber}</if>
        </where>
    </select>
    
    <select id="selectApsPlateStandardRequireBomOrderDetailById" parameterType="Long" resultMap="ApsPlateStandardRequireBomOrderDetailResult">
        <include refid="selectApsPlateStandardRequireBomOrderDetailVo"/>
        where id = #{id}
    </select>
 
    <insert id="insertApsPlateStandardRequireBomOrderDetail" parameterType="com.aps.core.domain.ApsPlate.ApsPlateStandardRequireBomOrderDetail">
        insert into aps_plate_standard_require_bom_order_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="requireId != null">require_id,</if>
            <if test="requireTrackId != null">require_track_id,</if>
 
            <if test="bomLineId != null">bom_line_id,</if>
            <if test="bomLineCode != null">bom_line_code,</if>
            <if test="docNo != null">doc_no,</if>
            <if test="beforeProdAmount != null">before_prod_amount,</if>
            <if test="deductionAmount != null">deduction_amount,</if>
            <if test="afterProdAmount != null">after_prod_amount,</if>
            <if test="orgCode != null">org_code,</if>
            <if test="batchNumber != null">batch_number,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="requireId != null">#{requireId},</if>
            <if test="requireTrackId != null">#{requireTrackId},</if>
 
            <if test="bomLineId != null">#{bomLineId},</if>
            <if test="bomLineCode != null">#{bomLineCode},</if>
            <if test="docNo != null">#{docNo},</if>
            <if test="beforeProdAmount != null">#{beforeProdAmount},</if>
            <if test="deductionAmount != null">#{deductionAmount},</if>
            <if test="afterProdAmount != null">#{afterProdAmount},</if>
            <if test="orgCode != null">#{orgCode},</if>
            <if test="batchNumber != null">#{batchNumber},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>
 
    <update id="updateApsPlateStandardRequireBomOrderDetail" parameterType="com.aps.core.domain.ApsPlate.ApsPlateStandardRequireBomOrderDetail">
        update aps_plate_standard_require_bom_order_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="requireId != null">require_id = #{requireId},</if>
            <if test="requireTrackId != null">require_track_id = #{requireTrackId},</if>
            <if test="bomLineId != null">bom_line_id = #{bomLineId},</if>
            <if test="bomLineCode != null">bom_line_code = #{bomLineCode},</if>
            <if test="docNo != null">doc_no = #{docNo},</if>
            <if test="beforeProdAmount != null">before_prod_amount = #{beforeProdAmount},</if>
            <if test="deductionAmount != null">deduction_amount = #{deductionAmount},</if>
            <if test="afterProdAmount != null">after_prod_amount = #{afterProdAmount},</if>
            <if test="orgCode != null">org_code = #{orgCode},</if>
            <if test="batchNumber != null">batch_number = #{batchNumber},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>
 
    <delete id="deleteApsPlateStandardRequireBomOrderDetailById" parameterType="Long">
        delete from aps_plate_standard_require_bom_order_detail where id = #{id}
    </delete>
 
    <delete id="deleteApsPlateStandardRequireBomOrderDetailByIds" parameterType="String">
        delete from aps_plate_standard_require_bom_order_detail where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
 
    <update id="deleteLastPatch" parameterType="String">
        update aps_plate_standard_require_bom_order_detail set del_flag = '1' where del_flag = '0' and batch_number != #{batchNumber}
    </update>
 
    <insert id="batchInsert" parameterType="com.aps.core.domain.ApsPlate.ApsPlateStandardRequireBomOrderDetail">
        insert into aps_plate_standard_require_bom_order_detail
        (id, require_id,require_track_id, bom_line_id, bom_line_code, doc_no,
         before_prod_amount, deduction_amount, after_prod_amount,
         org_code, batch_number, del_flag, create_time, create_by)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.id}, #{item.requireId},#{item.requireTrackId}, #{item.bomLineId}, #{item.bomLineCode}, #{item.docNo},
             #{item.beforeProdAmount}, #{item.deductionAmount}, #{item.afterProdAmount},
             #{item.orgCode}, #{item.batchNumber}, #{item.delFlag}, #{item.createTime}, #{item.createBy}
            )
        </foreach>
    </insert>
 
 
    <select id="selectRequireUpAndDownLevel" parameterType="Long" resultType="com.aps.core.domain.ApsPlate.ApsPlatePlan">
        with bs as (
            select id, bom_header_code,bom_line_code,  require_track_id
            from aps_plate_standard_require
            where del_flag='0' and id=#{requireId}
        ) ,cp as (
            select re.id as reqiure_id, re.bom_header_code,re.bom_line_code,re.bom_line_level,   sd.doc_no,
                   (case
                        when re.bom_line_code=bs.bom_header_code then '上阶'
                        when re.bom_header_code=bs.bom_line_code then '下阶'
                       end ) as requirement_type,
                   pp.document_number,pp.item_number, pp.plan_start_day,pp.plan_end_day,pp.production_quantity
            from aps_plate_standard_require re
                     left join aps_plate_standard_require_bom_order_detail sd on re.id=sd.require_id
                     left join aps_plate_plan pp on sd.doc_no=pp.document_number
                     left join bs on re.require_track_id=bs.require_track_id
            where re.del_flag='0'
              and re.require_track_id in (select bs.require_track_id from bs)
        )
        select *
        from cp
         where requirement_type is not null and doc_no is not null
        order by bom_line_level;
    </select>
</mapper>