mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
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
<?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.panzhihua.service_community.dao.ComFmsClassroomDAO">
 
    <resultMap type="com.panzhihua.service_community.entity.ComFmsClassroom" id="ComFmsClassroomMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="title" column="title" jdbcType="VARCHAR"/>
        <result property="scholars" column="scholars" jdbcType="INTEGER"/>
        <result property="cover" column="cover" jdbcType="VARCHAR"/>
        <result property="content" column="content" jdbcType="VARCHAR"/>
        <result property="viewNum" column="view_num" jdbcType="INTEGER"/>
        <result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
        <result property="createdBy" column="created_by" jdbcType="INTEGER"/>
        <result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
        <result property="updatedBy" column="updated_by" jdbcType="INTEGER"/>
        <result property="communityId" column="community_id" jdbcType="INTEGER"/>
    </resultMap>
 
    <!-- 批量插入 -->
    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into smart_life.com_fms_classroom(title, scholars, cover, content, view_num, created_at, created_by, updated_at, updated_by, community_id)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.title}, #{entity.scholars}, #{entity.cover}, #{entity.content}, #{entity.viewNum}, #{entity.createdAt}, #{entity.createdBy}, #{entity.updatedAt}, #{entity.updatedBy}, #{entity.communityId})
        </foreach>
    </insert>
    <!-- 批量插入或按主键更新 -->
    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into smart_life.com_fms_classroom(title, scholars, cover, content, view_num, created_at, created_by, updated_at, updated_by, community_id)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.title}, #{entity.scholars}, #{entity.cover}, #{entity.content}, #{entity.viewNum}, #{entity.createdAt}, #{entity.createdBy}, #{entity.updatedAt}, #{entity.updatedBy}, #{entity.communityId})
        </foreach>
        on duplicate key update
         title = values(title) , scholars = values(scholars) , cover = values(cover) , content = values(content) , view_num = values(view_num) , created_at = values(created_at) , created_by = values(created_by) , updated_at = values(updated_at) , updated_by = values(updated_by) , community_id = values(community_id)     </insert>
    <select id="pageFmsClassroomAdmin"
            resultType="com.panzhihua.common.model.vos.community.fms.ComFmsClassroomVO">
        SELECT id, title, scholars, cover, view_num, created_at
        FROM com_fms_classroom
        WHERE community_id = #{adminDTO.communityId}
        <if test='adminDTO.keyword != null and adminDTO.keyword != "" '>
            AND title LIKE CONCAT('%',#{adminDTO.keyword},'%')
        </if>
        <if test='adminDTO.createdAtBegin != null  '>
            AND created_at &gt;= #{adminDTO.createdAtBegin}
        </if>
        <if test='adminDTO.createdAtEnd != null  '>
            AND created_at &lt;= #{adminDTO.createdAtEnd}
        </if>
        ORDER BY created_at DESC
    </select>
    <select id="statisticsFmsClassroom"
            resultType="com.panzhihua.common.model.vos.community.fms.FmsClassroomTopStatisticsVO">
        SELECT
        (SELECT COUNT(id) FROM com_fms_classroom WHERE community_id = #{communityId}) AS classroomCount,
        (SELECT IF(SUM(scholars) IS NULL,0,SUM(scholars)) FROM com_fms_classroom WHERE community_id = #{communityId}) AS learnCount
    </select>
    <select id="pageFmsEvent" resultType="com.panzhihua.common.model.vos.community.fms.FmsEventVO">
        SELECT e.id, e.event_clazz, egd.grid_name, e.happent_lat_lng, e.happen_time, e.event_des,
        e.danger_level, e.urgent, e.major, e.event_process_status
        FROM `event` AS e
        LEFT JOIN event_grid_data AS egd ON egd.id = e.grid_id
        WHERE e.event_category = 1 AND e.event_status = 2 AND egd.grid_community_id = #{adminDTO.communityId}
        <if test="adminDTO.eventClazz != null and adminDTO.eventClazz != &quot;&quot;">
            AND e.event_clazz = #{adminDTO.eventClazz}
        </if>
        <if test="adminDTO.eventProcessStatus != null">
            AND e.event_process_status = #{adminDTO.eventProcessStatus}
        </if>
        <if test="adminDTO.eventProcessStatus == null">
            AND e.event_process_status IN(1,2)
        </if>
        <if test="adminDTO.type != null and adminDTO.type == 1">
            AND e.event_type = 3
        </if>
        <if test="adminDTO.type != null and adminDTO.type == 2">
            AND e.event_type = 1
        </if>
        <if test="adminDTO.keyword != null and adminDTO.keyword != &quot;&quot;">
            AND e.event_des LIKE CONCAT('%',#{adminDTO.keyword},'%')
        </if>
        ORDER BY e.happen_time DESC
    </select>
    <select id="statisticsFmsEvent"
            resultType="com.panzhihua.common.model.vos.community.fms.FmsEventTopStatisticsVO">
        SELECT
        (SELECT COUNT(e.id) FROM `event` AS e
        LEFT JOIN event_grid_data AS egd ON egd.id = e.grid_id
        WHERE e.event_category = 1 AND e.event_status = 2 AND e.event_process_status = 1 AND egd.grid_community_id = #{communityId}
        <if test="type != null and type == 1">
            AND e.event_type = 3
        </if>
        <if test="type != null and type == 2">
            AND e.event_type = 1
        </if>
        ) AS unHandledCount,
        (SELECT COUNT(e.id) FROM `event` AS e
        LEFT JOIN event_grid_data AS egd ON egd.id = e.grid_id
        WHERE e.event_category = 1 AND e.event_status = 2 AND e.event_process_status = 2 AND egd.grid_community_id = #{communityId}
        <if test="type != null and type == 1">
            AND e.event_type = 3
        </if>
        <if test="type != null and type == 2">
            AND e.event_type = 1
        </if>
        ) AS handledCount
    </select>
    <select id="pageFmsEventApplets" resultType="com.panzhihua.common.model.vos.grid.EventVO">
        SELECT e.id, e.event_clazz, e.happen_time, e.event_des, e.grid_member_id
        FROM `event` AS e
        LEFT JOIN event_grid_data AS egd ON egd.id = e.grid_id
        WHERE e.event_category = 1 AND e.event_status = 2 AND egd.grid_community_id = #{adminDTO.communityId} AND e.event_process_status = 2
        <if test="adminDTO.eventClazz != null and adminDTO.eventClazz != &quot;&quot;">
            AND e.event_clazz = #{adminDTO.eventClazz}
        </if>
        <if test="adminDTO.type != null and adminDTO.type == 1">
            AND e.event_type = 3
        </if>
        <if test="adminDTO.type != null and adminDTO.type == 2">
            AND e.event_type = 1
        </if>
        ORDER BY e.happen_time DESC
    </select>
 
</mapper>