廖井涛
2024-02-22 e4fe69941b2dd4582ec0bd82c32b8dfbc30d85b5
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
<?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.example.erp.mapper.sd.OrderGlassDetailMapper">
 
    <insert id="insertOrderGlassDetail" parameterType="java.lang.String">
        insert into
            order_glass_detail (
            order_id, order_number,
            technology_number,
            glass_address,
            glass_child,
            child_width,
            child_height,
            process,
            `group`)
        select
            od.order_id,
            od.order_number,
            pd.glass_sort,
            if(pd.glass_sort=1,'(外)',if(pd2.glass_sort=pd.glass_sort,'(内)','')),
            pd.detail,
            od.width,
            od.height,
            pd.process,
            pd.glass_group
        from sd.product_detail as pd
        left join order_detail as od
            on od.product_id = pd.prod_id and pd.detail_type='glass'
        LEFT JOIN (SELECT max(id) as id ,max(glass_sort) as glass_sort  from product_detail GROUP BY prod_id)as pd2
            on pd2.id=pd.id
 
        where od.order_id = #{orderId}
        ORDER BY od.order_number
    </insert>
 
    <select id="selectOrderGlassDetail">
        select * from order_glass_detail where order_id = #{orderId}
    </select>
 
    <resultMap id="orderGlassDetailMap" type="com.example.erp.entity.sd.OrderGlassDetail" >
        <id column="id" property="id"/>
        <result column="order_id" property="orderId"/>
        <result column="order_number" property="orderNumber"/>
        <result column="glass_address" property="glassAddress"/>
        <result column="technology_number" property="technologyNumber"/>
        <result column="glass_child" property="glassChild"/>
        <result column="child_width" property="childWidth"/>
        <result column="child_height" property="childHeight"/>
        <result column="process" property="process"/>
        <!--接收其他外键实体类数据-->
        <association property="orderDetail" javaType="com.example.erp.entity.sd.OrderDetail">
 
            <result column="building_number" property="buildingNumber"/>
 
            <result column="product_name" property="productName"/>
            <result column="width" property="width"/>
            <result column="height" property="height"/>
            <result column="shape" property="shape"/>
            <result column="gross_area" property="grossArea"/>
            <result column="edging_type" property="edgingType"/>
            <result column="area" property="area"/>
            <result column="quantity" property="quantity"/>
            <result column="processing_note"  property="processingNote"/>
            <result column="beizhu"  property="remarks"/>
 
        </association>
 
    </resultMap>
 
    <select id="selectOrderGlassDetailByOrderId"  resultMap="orderGlassDetailMap">
        select
            a.order_id,
            a.order_number,
            b.building_number,
            b.product_name,
            a.glass_address,
           a.technology_number,
           a.glass_child,
           b.width,
           b.height,
           b.shape,
           b.gross_area,
           b.edging_type,
           a.child_width,
           a.child_height,
           b.area,
           b.quantity,
           a.process,
           b.remarks as 'beizhu',
           b.processing_note
        from order_glass_detail as a
        left join order_detail as b
        on a.order_id = b.order_id and a.order_number = b.order_number
        where a.order_id = #{orderId}
        order by a.order_number,a.technology_number
    </select>
    
    <update id="updateSizeAndProcess" parameterType="java.util.List">
        <foreach collection="orderGlassDetails"  item="item" index="index" open="" close="" separator=";">
            update order_glass_detail
            set
                child_width = #{item.childWidth},
                child_height = #{item.childHeight},
                process = #{item.process}
            where
                order_id = #{item.orderId}
                and order_number = #{item.orderNumber}
                and technology_number = #{item.technologyNumber}
        </foreach>
 
    </update>
</mapper>