廖井涛
3 天以前 ac225bd66eb7c21b5af1d8533dc59376ea53da6c
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
<?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.BomDataMapper">
 
    <insert id="saveMaterialBomDataMp">
        insert into sd.bom_base
            (material_id, material, status, type, consume, price,unit,create_time)
        values
            (#{id}, #{name}, 0, #{type}, #{consume},#{price}, #{unit},now())
    </insert>
 
    <select id="getMaterialId">
        select count(*) from sd.bom_base where material_id= #{id}
    </select>
 
    <update id="updateMaterialBomDataMp">
        update sd.bom_base
        set type=#{type},consume=#{consume},price=#{price},unit=#{unit},create_time=now()
        where material_id = #{id}
    </update>
 
    <insert id="saveProductBOMMp">
        insert into sd.bom_product
                (product_id,base_id,product_layer)
        values (#{produceId},#{tabId},#{layer})
    </insert>
 
    <select id="getOrderBomDataMp">
        SELECT  product_id,product_name,SUM(quantity) as quantity,
            SUM(gross_area) as area,SUM(perimeter) as perimeter,order_id from sd.order_detail where order_id=#{orderId}
            GROUP BY product_id
    </select>
 
    <select id="getBOMDetails">
        select bp.*,bb.*,(consume*price) as materialPric,od.quantity from sd.bom_product as bp
            left join sd.bom_base as bb on bb.id=bp.base_id
            left join ( select order_id,product_id,SUM(quantity) as quantity from sd.order_detail GROUP BY  order_id,product_id
        ) as od on od.product_id = bp.product_id
        where bp.product_id = #{productId} and od.order_id = #{orderId} ORDER BY product_layer
    </select>
 
    <select id="getOrderBomSumDataMp">
        SELECT  product_id,product_name,SUM(quantity) as quantity,SUM(gross_area) as area,SUM(perimeter) as perimeter
        from sd.order_detail where order_id=#{orderId}
    </select>
 
    <select id="getOrderBomsumDataDatilsMp">
        SELECT
            od.order_id,
            bp.product_id,
            bb.material_id,
            bb.material,
            bb.`status`,
            bb.type,
            sum(bb.consume) as consume,
            sum(bb.price) as price,
            sum(bb.consume * bb.price) AS materialPrice,
            od.quantity
        FROM
            sd.bom_product AS bp
                LEFT JOIN sd.bom_base AS bb ON bb.id = bp.base_id
                LEFT JOIN (
                select order_id,product_id,SUM(quantity) as quantity from sd.order_detail GROUP BY  order_id,product_id
            ) as od on od.product_id = bp.product_id
 
        WHERE od.order_id=#{orderId}
        GROUP BY bb.material_id
        ORDER BY bp.product_layer
    </select>
 
    <select id="getEditProductBOMSv">
        SELECT
            bp.product_layer,
            bb.material_id,
            bb.material,
            JSON_UNQUOTE(
                    JSON_EXTRACT( ms.json, '$.thickness' )) AS thickness,
            JSON_UNQUOTE(
                    JSON_EXTRACT( ms.json, '$.width' )) AS width,
            JSON_UNQUOTE(
                    JSON_EXTRACT( ms.json, '$.height' )) AS height,
            JSON_UNQUOTE(
                    JSON_EXTRACT( ms.json, '$.unit' )) AS unit,
            bb.consume,
            bb.price
        FROM
            bom_product AS bp
                LEFT JOIN bom_base AS bb ON bb.id = bp.base_id
                LEFT JOIN mm.material_store AS ms ON ms.id = bb.material_id
        WHERE
            bp.product_id = #{produceId}
    </select>
</mapper>