Fixiaobai
2023-09-09 e7f7daae5d21ad2988cadd25b6987ca5e7ef8001
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
<?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.yuanchu.limslaboratory.mapper.MaterialMapper">
    <select id="selectMaterialLimit" resultType="Map">
        select id, code, name
        from lims_laboratory.material
        where state = 1
          and type = #{type}
        order by create_time desc
            limit #{num1}, #{num2}
    </select>
    <select id="selectMaterialById" resultType="Map">
        select m.id,
               m.num,
               m.supplier,
               m.name,
               m.location,
               m.batch,
               m.reel_number                reelNumber,
               concat(s.name, '/', sn.name) specificationSerialNum,
               s.voltage_level              voltageLevel,
               s.cross_section              crossSection,
               s.number_of_cores            numberOfCores,
               s.instruct
        from lims_laboratory.material m,
             lims_laboratory.specifications s,
             lims_laboratory.serial_number sn
        where m.specifications_id = s.id
          and s.serial_id = sn.id
          and m.id = #{materialId}
    </select>
 
    <resultMap id="OneLevelTreeMap" type="Map">
        <id property="type" column="type"/>
        <collection property="children" resultMap="TwoLevelTreeMap" javaType="List"/>
    </resultMap>
 
    <resultMap id="TwoLevelTreeMap" type="Map">
        <id property="id" column="materialId"/>
        <result property="name" column="materialName"/>
        <collection property="children" resultMap="ThreeLevelTreeMap" javaType="List"/>
    </resultMap>
 
    <resultMap id="ThreeLevelTreeMap" type="Map">
        <id property="id" column="standardId"/>
        <result property="name" column="standardName"/>
        <collection property="children" resultMap="FourLevelTreeMap" javaType="List"/>
    </resultMap>
 
    <resultMap id="FourLevelTreeMap" type="Map">
        <id property="id" column="specificationsId"/>
        <result property="name" column="specificationsName"/>
    </resultMap>
 
    <select id="FourTree" resultMap="OneLevelTreeMap">
        SELECT m.`type`,
               m.`id`   materialId,
               m.`name` materialName,
               s.id     standardId,
               s.name   standardName,
               f.id     specificationsId,
               f.name   specificationsName
        FROM material m
                 LEFT JOIN (SELECT s.`id`, s.`name`, s.`material_id` FROM standard s WHERE s.`state` = 1) s
                           ON s.material_id = m.`id`
                 LEFT JOIN (SELECT f.`id`, f.`name`, f.`standard_id`, f.`create_time`
                            FROM specifications f
                            WHERE f.`state` = 1) f
                           ON f.standard_id = s.id
        WHERE m.`state` = 1
        ORDER BY f.create_time DESC
    </select>
 
    <select id="getTreeByMaterialId" resultMap="getTreeById">
        SELECT m.id      mId,
               m.`name`  mName,
               sd.id     sdId,
               sd.`name` sdName,
               ss.id     ssId,
               ss.`name` ssName
        FROM material m,
             standard sd,
             specifications ss
        WHERE m.id = sd.material_id
          AND sd.id = ss.standard_id
          AND m.id = #{id}
          AND m.state != 0
    AND sd.state != 0
    AND ss.state !=0
    </select>
    <resultMap id="getTreeById" type="map">
        <result property="id" column="mId"/>
        <result property="name" column="mName"/>
        <collection property="children" resultMap="getStan" javaType="List"/>
    </resultMap>
    <resultMap id="getStan" type="map">
        <result property="id" column="sdId"/>
        <result property="name" column="sdName"/>
        <collection property="children" resultMap="getModel" javaType="List"/>
    </resultMap>
    <resultMap id="getModel" type="map">
        <result property="id" column="ssId"/>
        <result property="name" column="ssName"/>
    </resultMap>
</mapper>