南昌市物联网技防平台-学校版后台
zengh
2021-06-03 723946c6b272e5aa4c7ec110ff1395f6c2b23e89
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<?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="org.springblade.jfpt.healthcode.mapper.healthcodeMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="healthcodeResultMap" type="org.springblade.jfpt.healthcode.entity.Healthcode">
        <id column="id" property="id"/>
        <result column="type" property="type"/>
        <result column="sex" property="sex"/>
        <result column="province" property="province"/>
        <result column="city" property="city"/>
        <result column="district" property="district"/>
        <result column="dtime" property="dtime"/>
    </resultMap>
 
    <sql id="key">
        <trim suffixOverrides=",">
            <if test="type!=null and type!=''">
                type,
            </if>
            <if test="sex!=null and sex!=''">
                sex,
            </if>
            <if test="province!=null and province!=''">
                province,
            </if>
            <if test="city!=null and city!=''">
                city,
            </if>
            <if test="district!=null and district!=''">
                district,
            </if>
            <if test="dtime!=null and dtime!=''">
                dtime,
            </if>
        </trim>
    </sql>
    <sql id="value">
        <trim suffixOverrides=",">
            <if test="type!=null and type!=''">
                #{type},
            </if>
            <if test="sex!=null and sex!=''">
                #{sex},
            </if>
            <if test="province!=null and province!=''">
                #{province},
            </if>
            <if test="city!=null and city!=''">
                #{city},
            </if>
            <if test="district!=null and district!=''">
                #{district},
            </if>
            <if test="dtime!=null and dtime!=''">
                #{dtime},
            </if>
        </trim>
    </sql>
 
    <sql id="detailCondition">
        <if test="healthcodeVO.status==0">
            and to_days(dtime)=to_days(now())
        </if>
        <if test="healthcodeVO.status==1">
            and YEARWEEK(date_format(dtime,'%Y-%m-%d'),1) = YEARWEEK(now(),1)
        </if>
        <if test="healthcodeVO.status==2">
            and date_format(dtime,'%Y%m') = date_format(now(),'%Y%m')
        </if>
        <if test="healthcodeVO.province!=null">
            and province like concat('%',#{healthcodeVO.province},'%')
        </if>
        <if test="healthcodeVO.city!=null">
            and city like concat('%',#{healthcodeVO.city},'%')
        </if>
        <if test="healthcodeVO.district!=null">
            and district like concat('%',#{healthcodeVO.district},'%')
        </if>
        <if test="healthcodeVO.begTime!=null and healthcodeVO.begTime!='' and healthcodeVO.begTime!='undefined'  and healthcodeVO.endTime!='undefined'
        and healthcodeVO.endTime!=null and healthcodeVO.endTime!='' ">
            and date(dtime) between #{healthcodeVO.begTime} and #{healthcodeVO.endTime}
        </if>
        <if test="healthcodeVO.timeDesc!=null and healthcodeVO.timeDesc!='' and healthcodeVO.timeDesc!='undefined' ">
            <if test="healthcodeVO.timeDesc=='0-2'">
                and hour(dtime)>=0 and hour(dtime) &lt;2
            </if>
            <if test="healthcodeVO.timeDesc=='2-4'">
                and hour(dtime)>=2 and hour(dtime) &lt;4
            </if>
            <if test="healthcodeVO.timeDesc=='4-6'">
                and hour(dtime)>=4 and hour(dtime) &lt;6
            </if>
            <if test="healthcodeVO.timeDesc=='6-8'">
                and hour(dtime)>=6 and hour(dtime) &lt;8
            </if>
            <if test="healthcodeVO.timeDesc=='8-10'">
                and hour(dtime)>=8 and hour(dtime) &lt;10
            </if>
            <if test="healthcodeVO.timeDesc=='10-12'">
                and hour(dtime)>=10 and hour(dtime) &lt;12
            </if>
            <if test="healthcodeVO.timeDesc=='12-14'">
                and hour(dtime)>=12 and hour(dtime) &lt;14
            </if>
            <if test="healthcodeVO.timeDesc=='14-16'">
                and hour(dtime)>=14 and hour(dtime) &lt;16
            </if>
            <if test="healthcodeVO.timeDesc=='16-18'">
                and hour(dtime)>=16 and hour(dtime) &lt;18
            </if>
            <if test="healthcodeVO.timeDesc=='18-20'">
                and hour(dtime)>=18 and hour(dtime) &lt;20
            </if>
            <if test="healthcodeVO.timeDesc=='20-22'">
                and hour(dtime)>=20 and hour(dtime) &lt;22
            </if>
            <if test="healthcodeVO.timeDesc=='22-24'">
                and hour(dtime)>=22 and hour(dtime) &lt;24
            </if>
        </if>
    </sql>
 
 
    <insert id="insert">
        insert into healthcode(<include refid="key"/>) values(<include refid="value"/>)
    </insert>
 
<!--    <select id="selectCountr" resultType="java.util.HashMap">-->
<!--         SELECT COUNT( * ) AS num,type-->
<!--            FROM-->
<!--         healthcode-->
<!--            WHERE-->
<!--         DATE_FORMAT(dtime,'%Y-%m-%d')=#{time} GROUP BY type-->
<!--    </select>-->
 
    <!--查询当天的健康码统计数据  2021-03-13 arsn修改-->
    <select id="selectCountr" resultType="java.util.HashMap">
        SELECT COUNT( * ) AS num,1 as type FROM healthcode WHERE
             TO_DAYS(dtime)=TO_DAYS(NOW()) and type=1
                     union all
        SELECT COUNT( * ) AS num,2 as type FROM healthcode WHERE
             TO_DAYS(dtime)=TO_DAYS(NOW()) and type=2
               union all
        SELECT COUNT( * ) AS num,3 as type FROM healthcode WHERE
             TO_DAYS(dtime)=TO_DAYS(NOW()) and type=3
    </select>
 
    <select id="selectCountz" resultType="java.util.HashMap">
        SELECT
        COUNT( * ) AS num,
        type
        FROM
        healthcode
        WHERE
        DATE_FORMAT(dtime,'%Y-%m-%d')&gt;=#{beginTime} and DATE_FORMAT(dtime,'%Y-%m-%d')&lt;=#{endTime} GROUP BY type
    </select>
 
 
    <!--统计7天内每天红色健康码人数数量数据-->
    <select id="selectRedCodeDataStatis" resultType="java.lang.Integer">
        select ifnull(b.count,0) as count from
        (
        SELECT DATE_FORMAT(date_sub(curdate(), interval 6 day),'%Y-%m-%d') as click_date
            union all
        SELECT DATE_FORMAT(date_sub(curdate(), interval 5 day),'%Y-%m-%d') as click_date
            union all
        SELECT DATE_FORMAT(date_sub(curdate(), interval 4 day),'%Y-%m-%d') as click_date
            union all
        SELECT DATE_FORMAT(date_sub(curdate(), interval 3 day),'%Y-%m-%d') as click_date
            union all
        SELECT DATE_FORMAT(date_sub(curdate(), interval 2 day),'%Y-%m-%d') as click_date
            union all
        SELECT DATE_FORMAT(date_sub(curdate(), interval 1 day),'%Y-%m-%d') as click_date
            union all
        SELECT DATE_FORMAT(curdate(),'%Y-%m-%d')  as click_date
        ) a
        left join
        (
        select DATE_FORMAT(dtime,'%Y-%m-%d') as datetime, count(*) as count from healthcode
                        where `type`=3
            group by DATE_FORMAT(dtime,'%Y-%m-%d')
        ) b
         on
         a.click_date = b.datetime
         order by a.click_date asc
    </select>
 
 
    <!--自定义健康码分页/健康码统计图表点击事件-->
    <select id="selectHealthcodeListPage" resultType="org.springblade.jfpt.healthcode.entity.Healthcode">
        SELECT * FROM healthcode
        where 1=1
        <if test="healthcodeVO.type!=null and healthcodeVO.type!='undefined' ">
            and type=#{healthcodeVO.type}
        </if>
        <include refid="detailCondition"></include>
        ORDER BY dtime desc
    </select>
 
    <!--查询当前时间段红色健康码总个数-->
    <select id="selHealthcodeTimeCount" resultType="java.lang.Integer">
        select count(*) from healthcode
        where type = 3
        <if test="conditionVo.startTime!=null and conditionVo.startTime!='' and conditionVo.endTime!=null and conditionVo.endTime!=''">
            and dtime between #{conditionVo.startTime} and #{conditionVo.endTime}
        </if>
    </select>
 
    <!--查询当前时间段区间时间红色健康码个数-->
    <select id="selRedCodeTimeData" resultType="org.springblade.jfpt.healthcode.entity.Healthcode">
        SELECT type,dtime FROM healthcode
            where type =3
        and dtime between #{conditionVo.startTime} and #{conditionVo.endTime}
    </select>
 
    <!--统计时间段内红色健康码人数数量数据-->
    <select id="selectHealthcodeTimeData" resultType="java.lang.Integer">
        select ifnull(count,0) count from
        (
            SELECT @date := DATE_ADD( @date, INTERVAL + 1 DAY ) days FROM
            (
                SELECT @date := DATE_ADD( #{conditionVo.startTime}, INTERVAL - 1 DAY ) FROM sys_date
            ) time
            WHERE to_days( @date ) &lt; to_days( #{conditionVo.endTime} )
        ) a
        left join
        (
            select DATE_FORMAT(dtime,'%Y-%m-%d') as datetime, count(*) as count from healthcode
            where type=3
            group by DATE_FORMAT(dtime,'%Y-%m-%d')
        ) b
        on
        a.days = b.datetime
    </select>
 
    <!--导出健康码数据表格-->
    <select id="exportHealthcode" resultType="org.springblade.common.entity.HealthcodeExcel">
        SELECT * FROM healthcode
        where 1=1
        <if test="healthcodeVO.type!=null and healthcodeVO.type!='undefined' ">
            and type=#{healthcodeVO.type}
        </if>
            <include refid="detailCondition"></include>
        ORDER BY dtime desc
    </select>
 
    <!--导出健康码数据报表-->
    <select id="getHealthcodePie" resultType="org.springblade.common.entity.ReportReturnData">
        select if(1=1,'绿色健康码',0) type,ifnull(count(*),0) count from healthcode where type=1
            <include refid="detailCondition"></include>
        union all
        select if(1=1,'黄色健康码',0) type,ifnull(count(*),0) count from healthcode where type=2
            <include refid="detailCondition"></include>
        union all
        select if(1=1,'红色健康码',0) type,ifnull(count(*),0) count from healthcode where type=3
            <include refid="detailCondition"></include>
    </select>
</mapper>