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
<?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.ComActEnterpriseDAO">
 
    <resultMap type="com.panzhihua.service_community.entity.ComActEnterprise" id="ComActEnterpriseMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="agencyCode" column="agency_code" jdbcType="VARCHAR"/>
        <result property="legalRepresentative" column="legal_representative" jdbcType="VARCHAR"/>
        <result property="phone" column="phone" jdbcType="VARCHAR"/>
        <result property="registeAt" column="registe_at" jdbcType="TIMESTAMP"/>
        <result property="communityId" column="community_id" jdbcType="INTEGER"/>
        <result property="address" column="address" jdbcType="VARCHAR"/>
        <result property="introduct" column="introduct" jdbcType="VARCHAR"/>
        <result property="logo" column="logo" jdbcType="VARCHAR"/>
        <result property="createdBy" column="created_by" jdbcType="INTEGER"/>
        <result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
        <result property="updatedBy" column="updated_by" jdbcType="INTEGER"/>
        <result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
        <result property="status" column="status" jdbcType="INTEGER"/>
        <result property="streetId" column="street_id" jdbcType="INTEGER"/>
        <result property="type" column="type" jdbcType="INTEGER"/>
    </resultMap>
 
    <!-- 批量插入 -->
    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into smart_life.com_act_enterprise(name, agency_code, legal_representative, phone, registe_at,
        community_id, address, introduct, logo, created_by, created_at, updated_by, updated_at, status, street_id)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.name}, #{entity.agencyCode}, #{entity.legalRepresentative}, #{entity.phone}, #{entity.registeAt},
            #{entity.communityId}, #{entity.address}, #{entity.introduct}, #{entity.logo}, #{entity.createdBy},
            #{entity.createdAt}, #{entity.updatedBy}, #{entity.updatedAt}, #{entity.status}, #{entity.streetId})
        </foreach>
    </insert>
    <!-- 批量插入或按主键更新 -->
    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into smart_life.com_act_enterprise(name, agency_code, legal_representative, phone, registe_at,
        community_id, address, introduct, logo, created_by, created_at, updated_by, updated_at, status, street_id)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.name}, #{entity.agencyCode}, #{entity.legalRepresentative}, #{entity.phone}, #{entity.registeAt},
            #{entity.communityId}, #{entity.address}, #{entity.introduct}, #{entity.logo}, #{entity.createdBy},
            #{entity.createdAt}, #{entity.updatedBy}, #{entity.updatedAt}, #{entity.status}, #{entity.streetId})
        </foreach>
        on duplicate key update
        name = values(name) , agency_code = values(agency_code) , legal_representative = values(legal_representative) ,
        phone = values(phone) , registe_at = values(registe_at) , community_id = values(community_id) , address =
        values(address) , introduct = values(introduct) , logo = values(logo) , created_by = values(created_by) ,
        created_at = values(created_at) , updated_by = values(updated_by) , updated_at = values(updated_at) , status =
        values(status) , street_id = values(street_id)
    </insert>
    <select id="detailEnterprise" resultType="com.panzhihua.common.model.vos.community.ComActEnterpriseVO">
        SELECT t1.*, t2.`name` AS communityName, t3.`name` AS typeName
        FROM com_act_enterprise t1
        LEFT JOIN com_act t2 ON t1.community_id = t2.community_id
        LEFT JOIN com_act_enterprise_type t3 ON t1.type = t3.id
        WHERE t1.id = #{id}
    </select>
    <select id="pageEnterprise" resultType="com.panzhihua.common.model.vos.community.ComActEnterpriseVO">
        SELECT t1.*, t2.`name` AS communityName, t3.`name` AS typeName
        FROM com_act_enterprise t1
        LEFT JOIN com_act t2 ON t1.community_id = t2.community_id
        LEFT JOIN com_act_enterprise_type t3 ON t1.type = t3.id
        <where>
            <if test="pageEnterpriseDTO.streetId != null and pageEnterpriseDTO.communityId == null">
                AND t1.street_id = #{pageEnterpriseDTO.streetId}
            </if>
            <if test="pageEnterpriseDTO.communityId != null">
                AND t1.community_id = #{pageEnterpriseDTO.communityId}
            </if>
            <if test="pageEnterpriseDTO.status != null">
                AND t1.status = #{pageEnterpriseDTO.status}
            </if>
            <if test="pageEnterpriseDTO.type != null">
                AND t1.type = #{pageEnterpriseDTO.type}
            </if>
            <if test="pageEnterpriseDTO.keyword != null and pageEnterpriseDTO.keyword != &quot;&quot;">
                AND(t1.`name` LIKE CONCAT(#{pageEnterpriseDTO.keyword}, '%')
                OR t1.legal_representative LIKE CONCAT(#{pageEnterpriseDTO.keyword}, '%')
                OR t1.phone LIKE CONCAT(#{pageEnterpriseDTO.keyword}, '%'))
            </if>
        </where>
        ORDER BY t1.created_at DESC
    </select>
    <select id="getEnterpriseServiceTypeCircleData"
            resultType="com.panzhihua.common.model.vos.community.StatisticsCommVO">
        SELECT t1.`name` AS filed, COUNT(t1.`name`) AS num
        FROM com_act_enterprise t
        LEFT JOIN com_act_enterprise_type t1 ON t.type = t1.id
        WHERE t.community_id = ${communityId} AND t.`status` = 1
        GROUP BY filed
    </select>
    <select id="getSocialWorkerAgeStageCircleData"
            resultType="com.panzhihua.common.model.vos.community.StatisticsCommVO">
        SELECT filed, SUM(num) AS num FROM (
            SELECT filed, COUNT(filed) AS num FROM (
            SELECT
            CASE
            WHEN TIMESTAMPDIFF(YEAR, SUBSTRING(id_card, 7, 8), NOW()) &lt; 30 THEN '30岁以下'
            WHEN TIMESTAMPDIFF(YEAR, SUBSTRING(id_card, 7, 8), NOW()) BETWEEN 30 AND 59 THEN '30-59岁'
            WHEN TIMESTAMPDIFF(YEAR, SUBSTRING(id_card, 7, 8), NOW()) >= 60 THEN '60岁及以上'
            END filed
            FROM com_act_social_worker WHERE community_id = ${communityId}
            ) temp WHERE filed is not null GROUP BY filed
            UNION ALL
            (SELECT '30岁以下' AS filed, 0 AS num)
            UNION ALL
            (SELECT '30-59岁' AS filed, 0 AS num)
            UNION ALL
            (SELECT '60岁及以上' AS filed, 0 AS num)
        ) t GROUP BY filed
    </select>
    <select id="getSocialWorkerServiceTypeCircleData"
            resultType="com.panzhihua.common.model.vos.community.StatisticsCommVO">
        SELECT filed, COUNT(filed) AS num FROM(
            SELECT substring_index( substring_index( t.skill_type_name, ',', b.help_topic_id + 1 ), ',',- 1 ) AS filed
            FROM com_act_social_worker t
            JOIN mysql.help_topic b ON b.help_topic_id &lt; ( length( t.skill_type_name ) - length( REPLACE ( t.skill_type_name, ',', '' ))+ 1 )
            WHERE t.community_id = ${communityId}
        ) temp GROUP BY filed
    </select>
 
</mapper>