liuxiaolong
2019-05-09 0d1d88cdb668e75ea8609417ac18ae19947e9525
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
<?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">
<!-- 
    namespace:必须与对应的接口全类名一致
    id:必须与对应接口的某个对应的方法名一致
    
 -->
<mapper namespace="com.basic.x01.location.mapper.LocationMapper">
    <resultMap id="TbLocDevice" type="TbLocDevice">
        <id property="schoolId" column="school_id" />
        <id property="deviceRn"    column="device_rn" />
        <result property="transferId" column="transfer_id" />
        <result property="deviceIp" column="device_ip" />
        <result property="deviceName" column="device_name" />
    </resultMap>
    
    <resultMap id="TbLocPosition" type="TbLocPosition">
        <id property="schoolId" column="school_id" />
        <id property="positionId" column="position_id" />
        <result property="positionName" column="position_name" />
        <result property="outConfig" column="out_config" />
        <result property="inConfig" column="in_config" />
        <result property="gatePosition" column="gate_position" />
    </resultMap>
 
    <resultMap id="TbSchoolStudent" type="TbSchoolStudent">
        <id property="studentId" column="student_id" />
        <result property="schoolId" column="school_id" />
        <result property="classId" column="class_id" />
        <result property="studentName" column="student_name" />
        <result property="age" column="age" />
        <result property="gender" column="gender" />
        <result property="locCardNo" column="loc_card_no" />
        <result property="status" column="status" />
    </resultMap>
    
    <resultMap id="TbSchoolClass" type="TbSchoolClass">
        <id property="classId" column="class_id" />
        <result property="schoolId" column="school_id" />
        <result property="gradeName" column="grade_name" />
        <result property="className" column="class_name" />
    </resultMap>
    
    <resultMap id="TbLocTransfer" type="TbLocTransfer">
        <id property="transferId" column="transfer_id" />
        <id property="schoolId" column="school_id" />
        <result property="transferName" column="transfer_name" />
        <result property="relayConfig" column="relay_config" />
    </resultMap>
    
        <resultMap id="Form_sign" type="Form_sign">
        <id property="sign_time" column="sign_time" />
        <id property="sign_card_id" column="sign_card_id" />
        <result property="sign_type" column="sign_type" />
        <result property="location_id" column="location_id" />
    </resultMap>
    
    <select id="getSchoolTransferDevice" resultMap="TbLocTransfer">
        select * from tb_loc_transfer
        where school_id=#{0} and transfer_id=#{1}
        limit 1
    </select>
    <select id="getValidCardNoList" resultType="java.lang.String">
        select loc_card_no from tb_school_student
        where school_id=#{0} and status='1'
            and loc_card_no is not null
            and loc_card_no !=''
    </select>
    <select id="getLocLogList" resultType="java.util.HashMap">
        select grade_name, class_name, student_name, loc_card_no, loc_time
            , (case loc_type when 0 then position_name
                when 1 then concat('(进入)',position_name)
                when 2 then concat('(离开)',position_name)
                when 3 then concat(position_name, '(门内)')
                when 4 then concat(position_name, '(门外)')
                 end) as position_name
        from tb_loc_log l 
        where exists (select 1 from tb_school_student s
            where s.student_id=l.student_id
                and s.school_id=#{schoolId}
                and instr(loc_time, #{searchDate})>0
            <if test="searchName!=null and searchName!=''">
                and (student_name like #{searchName} 
                    or loc_card_no like #{searchName}
                    )
            </if>
            )    
        order by loc_time desc
    </select>
    
    
    
    <insert id="insertForm_sign">
        INSERT INTO form_sign(
            id,
            create_by,
            create_date,
            update_by,
            update_date,
            remarks,
            del_flag,
            sign_card_id,
            sign_time,
            sign_type,
            location_id
        ) VALUES (
            #{id},
            #{create_by},
            #{create_date},
            #{update_by},
            #{update_date},
            #{remarks},
            #{del_flag},
            #{sign_card_id},
            #{sign_time},
            #{sign_type},
            #{location_id}
        )
        
    </insert>
    
    <insert id="insertTbLocLog">
        insert into tb_loc_log (
            student_id, student_name, 
            grade_name, class_name,
            loc_card_no, position_id, 
            position_name, gate_position,
            loc_time, loc_type
        ) values (
            #{stu.studentId}, #{stu.studentName}, 
            #{cls.gradeName}, #{cls.className},
            #{stu.locCardNo}, #{pos.positionId},
            #{pos.positionName}, #{pos.gatePosition},
            #{locTime}, #{locType}
        )
        
    </insert>
    
    <select id="getSchoolClassBySchoolIdClassId" resultMap="TbSchoolClass">
        select * from tb_school_class
        where school_id=#{0}
            and class_id=#{1}
        limit 1
    </select>
    
    <select id="getLocPositionBySchoolIdPositionId" resultMap="TbLocPosition">
        select * from tb_loc_position
        where school_id=#{0}
            and position_id=#{1}
        limit 1
    </select>
 
    <select id="getStudentBySchoolIdLocCardNo" resultMap="TbSchoolStudent">
        select * from tb_school_student
        where school_id=#{0}
            and loc_card_no=#{1}
        limit 1
    </select>
 
    <select id="checkSchoolAccessKey" resultType="int">
        select count(0)
        from tb_loc_school
        where school_id=#{0} and access_key=#{1}
    </select>
    
    <select id="getLocDeviceListBySchoolIdTransferId" resultMap="TbLocDevice">
        select * from tb_loc_device
        where school_id=#{0} and transfer_id=#{1}
        order by device_rn
    </select>
    
    <select id="getLocPositionListBySchoolId" resultMap="TbLocPosition">
        select * from tb_loc_position
        where school_id=#{0}
        order by position_id
    </select>
</mapper>