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
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
<?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.ComActSocialOrgHatchDAO">
 
    <resultMap type="com.panzhihua.service_community.entity.ComActSocialOrgHatch" id="ComActSocialOrgHatchMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="responsibility" column="responsibility" jdbcType="VARCHAR"/>
        <result property="phone" column="phone" jdbcType="VARCHAR"/>
        <result property="hatchUnit" column="hatch_unit" jdbcType="INTEGER"/>
        <result property="hatchUnitType" column="hatch_unit_type" jdbcType="INTEGER"/>
        <result property="hatchUnitName" column="hatch_unit_name" jdbcType="VARCHAR"/>
        <result property="status" column="status" jdbcType="INTEGER"/>
        <result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
        <result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
        <result property="introduction" column="introduction" jdbcType="VARCHAR"/>
        <result property="logo" column="logo" jdbcType="VARCHAR"/>
        <result property="applyReason" column="apply_reason" jdbcType="VARCHAR"/>
        <result property="serviceScope" column="service_scope" jdbcType="VARCHAR"/>
    </resultMap>
 
    <!-- 批量插入 -->
    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into smart_life.com_act_social_org_hatch(name, responsibility, phone, hatch_unit, hatch_unit_type,
        hatch_unit_name, status, created_at, updated_at, introduction, logo, apply_reason, service_scope)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.name}, #{entity.responsibility}, #{entity.phone}, #{entity.hatchUnit}, #{entity.hatchUnitType},
            #{entity.hatchUnitName}, #{entity.status}, #{entity.createdAt}, #{entity.updatedAt}, #{entity.introduction},
            #{entity.logo}, #{entity.applyReason}, #{entity.serviceScope})
        </foreach>
    </insert>
    <!-- 批量插入或按主键更新 -->
    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into smart_life.com_act_social_org_hatch(name, responsibility, phone, hatch_unit, hatch_unit_type,
        hatch_unit_name, status, created_at, updated_at, introduction, logo, apply_reason, service_scope)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.name}, #{entity.responsibility}, #{entity.phone}, #{entity.hatchUnit}, #{entity.hatchUnitType},
            #{entity.hatchUnitName}, #{entity.status}, #{entity.createdAt}, #{entity.updatedAt}, #{entity.introduction},
            #{entity.logo}, #{entity.applyReason}, #{entity.serviceScope})
        </foreach>
        on duplicate key update
        name = values(name) , responsibility = values(responsibility) , phone = values(phone) , hatch_unit =
        values(hatch_unit) , hatch_unit_type = values(hatch_unit_type) , hatch_unit_name = values(hatch_unit_name) ,
        status = values(status) , created_at = values(created_at) , updated_at = values(updated_at) , introduction =
        values(introduction) , logo = values(logo) , apply_reason = values(apply_reason) , service_scope =
        values(service_scope)
    </insert>
    <select id="pageOrgHatch" resultType="com.panzhihua.common.model.vos.community.social.SocialOrgHatchVO">
        SELECT id, `name`, responsibility, phone, hatch_unit_name, created_at, `status`
        FROM com_act_social_org_hatch
        <where>
            <if test="pageHatchDTO.keyword != null and pageHatchDTO.keyword != &quot;&quot;">
                AND (`name` LIKE CONCAT(#{pageHatchDTO.keyword}, '%')
                OR responsibility LIKE CONCAT(#{pageHatchDTO.keyword}, '%')
                OR phone LIKE CONCAT(#{pageHatchDTO.keyword}, '%'))
            </if>
            <if test="pageHatchDTO.hatchUnit != null and pageHatchDTO.hatchUnitType != null">
                AND hatch_unit = #{pageHatchDTO.hatchUnit} AND hatch_unit_type = #{pageHatchDTO.hatchUnitType}
            </if>
            <if test="pageHatchDTO.status != null">
                AND `status` = #{pageHatchDTO.status}
            </if>
        </where>
        ORDER BY created_at DESC
    </select>
    <select id="detailOrgHatch" resultType="com.panzhihua.common.model.vos.community.social.SocialOrgHatchVO">
        SELECT a.*, GROUP_CONCAT(c.`name`) AS serviceScopeName
        FROM com_act_social_org_hatch a
        JOIN mysql.help_topic b ON b.help_topic_id &lt; ( length( a.service_scope ) - length( REPLACE ( a.service_scope, ',', '' ))+ 1 )
        LEFT JOIN com_act_column c ON substring_index( substring_index( a.service_scope, ',', b.help_topic_id + 1 ), ',',- 1 ) = c.id
        WHERE a.id = #{id}
    </select>
    <select id="getHatchBaseData"
            resultType="com.panzhihua.common.model.vos.community.bigscreen.BigScreenHatchStatisticsInfo">
        SELECT
        (SELECT COUNT(id) FROM (SELECT id
        FROM com_act_social_org_hatch_audit t
        LEFT JOIN com_act t1 ON t.hatch_unit = t1.community_id
        WHERE t.hatch_unit_type = 2 AND t.`status` IN(1,2) AND t1.street_id = #{streetId}
        UNION ALl
        SELECT id
        FROM com_act_social_org_hatch_audit
        WHERE hatch_unit_type = 1 AND `status` IN(1,2) AND hatch_unit = #{streetId}
        UNION ALL
        SELECT id
        FROM com_act_social_org t
        LEFT JOIN com_act t1 ON t.affiliated_unit = t1.community_id
        WHERE t.build_type = 1 AND t.is_society = 1 AND t.affiliated_unit_type = 2 AND t.`status` = 1 AND t1.street_id = #{streetId}
        UNION ALl
        SELECT id
        FROM com_act_social_org
        WHERE build_type = 1 AND is_society = 1 AND affiliated_unit_type = 1 AND `status` = 1 AND affiliated_unit = #{streetId}
        ) temp) AS hatchCenterTotal,
        (SELECT COUNT(id) FROM (SELECT id
        FROM com_act_social_org t
        LEFT JOIN com_act t1 ON t.affiliated_unit = t1.community_id
        WHERE t.build_type = 1 AND t.is_society = 1 AND t.affiliated_unit_type = 2 AND t.`status` = 1 AND t1.street_id = #{streetId}
        UNION ALl
        SELECT id
        FROM com_act_social_org
        WHERE build_type = 1 AND is_society = 1 AND affiliated_unit_type = 1 AND `status` = 1 AND affiliated_unit = #{streetId}) temp) AS hatchResultTotal,
        (SELECT COUNT(id) FROM (SELECT id
        FROM com_act_social_org t
        LEFT JOIN com_act t1 ON t.affiliated_unit = t1.community_id
        WHERE t.build_type = 1 AND t.is_society = 1 AND t.affiliated_unit_type = 2 AND t.`status` = 1 AND t1.area_code = '510423'
        UNION ALL
        SELECT id
        FROM com_act_social_org t
        LEFT JOIN com_street t1 ON t.affiliated_unit = t1.street_id
        WHERE t.build_type = 1 AND t.is_society = 1 AND t.affiliated_unit_type = 1 AND t.`status` = 1 AND t1.area_code = '510423') temp) AS westAreaOrgTotal
    </select>
    <select id="getHatchScheduleCircleData"
            resultType="com.panzhihua.common.model.vos.community.StatisticsCommVO">
        SELECT filed, COUNT(filed) AS num FROM (
        SELECT
        CASE
        WHEN t.`status` = 1 THEN '孵化中'
        WHEN t.`status` = 2 THEN '孵化完成'
        END filed
        FROM com_act_social_org_hatch t
        LEFT JOIN com_act t1 ON t.hatch_unit = t1.community_id
        WHERE t.hatch_unit_type = 2 AND t1.street_id = #{streetId}
        UNION ALl
        SELECT
        CASE
        WHEN `status` = 1 THEN '孵化中'
        WHEN `status` = 2 THEN '孵化完成'
        END filed
        FROM com_act_social_org_hatch
        WHERE hatch_unit_type = 1 AND hatch_unit = #{streetId}
        ) temp GROUP BY filed
    </select>
    <select id="getHatchStatusColumnData"
            resultType="com.panzhihua.common.model.vos.community.StatisticsCommVO">
        SELECT filed, SUM(num) AS num FROM (
        SELECT '已进驻' AS filed, COUNT(id) AS num
        FROM com_act_social_org_hatch_audit t
        LEFT JOIN com_act t1 ON t.hatch_unit = t1.community_id
        WHERE t.hatch_unit_type = 2 AND t.`status` = 1 AND t1.street_id = #{streetId}
        UNION ALl
        SELECT '已进驻' AS filed, COUNT(id) AS num
        FROM com_act_social_org_hatch_audit
        WHERE hatch_unit_type = 1 AND `status` = 1 AND hatch_unit = #{streetId}
        UNION ALl
        SELECT '孵化中' AS filed, COUNT(id) AS num
        FROM com_act_social_org_hatch t
        LEFT JOIN com_act t1 ON t.hatch_unit = t1.community_id
        WHERE t.hatch_unit_type = 2 AND t.`status` = 1 AND t1.street_id = #{streetId}
        UNION ALL
        SELECT '孵化中' AS filed, COUNT(id) AS num
        FROM com_act_social_org_hatch
        WHERE hatch_unit_type = 1 AND `status` = 1 AND hatch_unit = #{streetId}
        UNION ALl
        SELECT '通过评估' AS filed, COUNT(id) AS num
        FROM com_act_social_org_hatch t
        LEFT JOIN com_act t1 ON t.hatch_unit = t1.community_id
        WHERE t.hatch_unit_type = 2 AND t.`status` = 2 AND t1.street_id = #{streetId}
        UNION ALL
        SELECT '通过评估' AS filed, COUNT(id) AS num
        FROM com_act_social_org_hatch
        WHERE hatch_unit_type = 1 AND `status` = 2 AND hatch_unit = #{streetId}
        UNION ALL
        SELECT '出壳' AS filed, COUNT(id) AS num
        FROM com_act_social_org t
        LEFT JOIN com_act t1 ON t.affiliated_unit = t1.community_id
        WHERE t.build_type = 1 AND t.is_society = 1 AND t.affiliated_unit_type = 2 AND t.`status` = 1 AND t1.street_id = #{streetId}
        UNION ALL
        SELECT '出壳' AS filed, COUNT(id) AS num
        FROM com_act_social_org
        WHERE build_type = 1 AND is_society = 1 AND affiliated_unit_type = 1 AND `status` = 1 AND affiliated_unit = #{streetId}
        ) temp GROUP BY filed
    </select>
    <select id="getStreetOrgColumnData" resultType="com.panzhihua.common.model.vos.community.StatisticsCommVO">
        SELECT t2.`name` AS filed, COUNT(t2.`name`) AS num
        FROM com_act_social_org t
        JOIN com_street t2 ON t.street_id = t2.street_id
        WHERE t2.area_code = '510423' AND t.is_society = 1
        GROUP BY filed
    </select>
    <select id="getStreetOrgChildData" resultType="com.panzhihua.common.model.vos.community.StatisticsCommVO">
        SELECT filed, COUNT(filed) AS num FROM(
        SELECT substring_index( substring_index( t.service_type, ',', b.help_topic_id + 1 ), ',',- 1 ) AS filed
        FROM com_act_social_org t
        JOIN com_street t2 ON t.street_id = t2.street_id
        JOIN mysql.help_topic b ON b.help_topic_id &lt; ( length( t.service_type ) - length( REPLACE ( t.service_type, ',', '' ))+ 1 )
        WHERE t2.area_code = '510423' AND t.is_society = 1 AND t2.`name` = #{streetName}) temp
        GROUP BY filed
    </select>
 
</mapper>