Van333
2022-12-29 d8f66b834134f6b755fd3fb93bb91b56f9d31f6f
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
<?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="api.dao.PhotovoltaicEntityDao">
 
    <resultMap type="api.bean.PhotovoltaicEntity" id="PhotovoltaicEntityMap">
        <result property="photovoltaicId" column="photovoltaic_id" jdbcType="INTEGER"/>
        <result property="photovoltaicName" column="photovoltaic_name" jdbcType="VARCHAR"/>
        <result property="photovoltaicMac" column="photovoltaic_mac" jdbcType="VARCHAR"/>
        <result property="photovoltaicWorkPattern" column="photovoltaic_work_pattern" jdbcType="INTEGER"/>
        <result property="photovoltaicWorkWaring" column="photovoltaic_work_waring" jdbcType="VARCHAR"/>
        <result property="bindPoleStreelightId" column="bind_pole_streelight_id" jdbcType="INTEGER"/>
        <result property="hardwareVersion" column="hardware_version" jdbcType="VARCHAR"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="createUserId" column="create_user_id" jdbcType="INTEGER"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="softwareVersion" column="software_version" jdbcType="VARCHAR"/>
    </resultMap>
 
    <!-- 批量插入 -->
    <insert id="insertBatch" keyProperty="photovoltaicId" useGeneratedKeys="true">
        insert into machine.photovoltaic_entity(photovoltaic_name, photovoltaic_mac, photovoltaic_work_pattern, photovoltaic_work_waring, bind_pole_streelight_id, hardware_version, update_time, create_user_id, create_time, software_version)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.photovoltaicName}, #{entity.photovoltaicMac}, #{entity.photovoltaicWorkPattern}, #{entity.photovoltaicWorkWaring}, #{entity.bindPoleStreelightId}, #{entity.hardwareVersion}, #{entity.updateTime}, #{entity.createUserId}, #{entity.createTime}, #{entity.softwareVersion})
        </foreach>
    </insert>
    <!-- 批量插入或按主键更新 -->
    <insert id="insertOrUpdateBatch" keyProperty="photovoltaicId" useGeneratedKeys="true">
        insert into machine.photovoltaic_entity(photovoltaic_name, photovoltaic_mac, photovoltaic_work_pattern, photovoltaic_work_waring, bind_pole_streelight_id, hardware_version, update_time, create_user_id, create_time, software_version)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.photovoltaicName}, #{entity.photovoltaicMac}, #{entity.photovoltaicWorkPattern}, #{entity.photovoltaicWorkWaring}, #{entity.bindPoleStreelightId}, #{entity.hardwareVersion}, #{entity.updateTime}, #{entity.createUserId}, #{entity.createTime}, #{entity.softwareVersion})
        </foreach>
        on duplicate key update
         photovoltaic_name = values(photovoltaic_name) , photovoltaic_mac = values(photovoltaic_mac) , photovoltaic_work_pattern = values(photovoltaic_work_pattern) , photovoltaic_work_waring = values(photovoltaic_work_waring) , bind_pole_streelight_id = values(bind_pole_streelight_id) , hardware_version = values(hardware_version) , update_time = values(update_time) , create_user_id = values(create_user_id) , create_time = values(create_time) , software_version = values(software_version)     </insert>
 
    <select id="listAll" resultType="api.bean.PhotovoltaicEntity">
        select
        a.*,
        b.streetlight_id,b.streetlight_name,b.code_number
        from photovoltaic_entity a
        join pole_streetlight b on a.bind_pole_streelight_id = b.streetlight_id
        <if test="key != null and key != ''">
            where
            (a.bind_pole_streelight_id like '%${key}%'
            or a.photovoltaic_id like '%${key}%'
            or a.photovoltaic_name like '%${key}%'
            or b.streetlight_name like '%${key}%')
        </if>
 
    </select>
 
    <select id="listByCompanyId" resultType="api.bean.PhotovoltaicEntity">
 
        select
        a.*,
        b.streetlight_id,b.streetlight_name,b.code_number
        from
        photovoltaic_entity a
        inner join (
        select
        streetlight_id,streetlight_name,code_number
        from
        pole_streetlight
        where
        streetlight_id in
        ( SELECT streetlight_id FROM pole_user_streetlight WHERE user_id IN
        ( SELECT user_id FROM sys_user_company WHERE company_id = #{companyId})
        )
        ) b on a.bind_pole_streelight_id = b.streetlight_id
 
        <if test="key != null and key != ''">
            where
            (a.bind_pole_streelight_id like '%${key}%'
            or a.photovoltaic_id like '%${key}%'
            or a.photovoltaic_name like '%${key}%'
            or b.streetlight_name like '%${key}%')
        </if>
 
    </select>
 
    <select id="listByUserId" resultType="api.bean.PhotovoltaicEntity">
 
 
        select
        a.*,
        b.streetlight_id,b.streetlight_name,b.code_number
        from
        photovoltaic_entity a
        inner join (
        select
        streetlight_id,streetlight_name,code_number
        from
        pole_streetlight
        where
        streetlight_id in
        ( SELECT streetlight_id FROM pole_user_streetlight WHERE user_id = #{userId} )
        )  b on a.bind_pole_streelight_id = b.streetlight_id
        <if test="key != null and key != ''">
            where
            (a.bind_pole_streelight_id like '%${key}%'
            or a.photovoltaic_id like '%${key}%'
            or a.photovoltaic_name like '%${key}%'
            or b.streetlight_name like '%${key}%')
        </if>
 
    </select>
</mapper>