<?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.PhotovoltaicErrorDao">
|
|
<resultMap type="api.bean.PhotovoltaicError" id="PhotovoltaicErrorMap">
|
<result property="errorId" column="error_id" jdbcType="INTEGER"/>
|
<result property="mac" column="mac" jdbcType="VARCHAR"/>
|
<result property="errorCode" column="error_code" jdbcType="VARCHAR"/>
|
<result property="errorMsg" column="error_msg" jdbcType="VARCHAR"/>
|
<result property="destinationAddress" column="destination_address" jdbcType="VARCHAR"/>
|
<result property="timestamp" column="timestamp" jdbcType="TIMESTAMP"/>
|
</resultMap>
|
|
<!-- 批量插入 -->
|
<insert id="insertBatch" keyProperty="" useGeneratedKeys="true">
|
insert into machine.photovoltaic_error(error_id, mac, error_code, error_msg, destination_address, timestamp)
|
values
|
<foreach collection="entities" item="entity" separator=",">
|
(#{entity.errorId}, #{entity.mac}, #{entity.errorCode}, #{entity.errorMsg}, #{entity.destinationAddress},
|
#{entity.timestamp})
|
</foreach>
|
</insert>
|
<!-- 批量插入或按主键更新 -->
|
<insert id="insertOrUpdateBatch" keyProperty="" useGeneratedKeys="true">
|
insert into machine.photovoltaic_error(error_id, mac, error_code, error_msg, destination_address, timestamp)
|
values
|
<foreach collection="entities" item="entity" separator=",">
|
(#{entity.errorId}, #{entity.mac}, #{entity.errorCode}, #{entity.errorMsg}, #{entity.destinationAddress},
|
#{entity.timestamp})
|
</foreach>
|
on duplicate key update
|
error_id = values(error_id) , mac = values(mac) , error_code = values(error_code) , error_msg =
|
values(error_msg) , destination_address = values(destination_address) , timestamp = values(timestamp)
|
</insert>
|
|
|
<select id="findAllBySort" resultType="api.bean.PhotovoltaicError">
|
select
|
ps.streetlight_name ,
|
ps.streetlight_id,
|
pe.photovoltaic_name,
|
pe.photovoltaic_id,
|
phd.*
|
from
|
pole_streetlight ps
|
right join
|
(
|
select
|
*
|
from
|
photovoltaic_error phe
|
join
|
(
|
select
|
max(error_id) as id
|
from
|
photovoltaic_error
|
group by
|
streetlight_mac
|
limit #{page},#{size}
|
) a
|
on
|
error_id = a.id ) phd
|
on
|
phd.streetlight_mac = ps.code_number
|
join
|
photovoltaic_entity pe
|
on
|
pe.bind_pole_streelight_id = streetlight_id
|
</select>
|
|
|
|
<select id="findByCompanyBySort" resultType="api.bean.PhotovoltaicError">
|
select
|
*
|
from
|
photovoltaic_error phe
|
join
|
(
|
select
|
*
|
from
|
(
|
select
|
ps.streetlight_id ,
|
ps.streetlight_name,
|
ps.code_number
|
from
|
pole_streetlight ps
|
where
|
ps.streetlight_id in (
|
select
|
pus.streetlight_id
|
from
|
pole_user_streetlight pus
|
where
|
pus.company_id in(
|
select
|
suc.company_id
|
from
|
sys_user_company suc
|
where
|
suc.user_id =
|
#{userId}
|
)
|
)
|
limit #{page},#{size}) streetlight
|
join
|
(
|
select
|
max(error_id) as maxid,
|
streetlight_mac
|
from
|
photovoltaic_error
|
group by
|
streetlight_mac
|
) a
|
on
|
a.streetlight_mac = streetlight.code_number)
|
b
|
on
|
b.maxid = phe.error_id
|
join
|
photovoltaic_entity pe
|
on
|
pe.bind_pole_streelight_id = streetlight_id
|
|
</select>
|
|
|
|
<select id="findByPhotovoltaicId" resultType="api.bean.PhotovoltaicError"
|
parameterType="java.lang.Integer">
|
|
select
|
ps.streetlight_name ,
|
ps.streetlight_id,
|
phe.*,
|
pe.photovoltaic_name,
|
pe.photovoltaic_id
|
from
|
pole_streetlight ps
|
right join
|
(
|
select
|
*
|
from
|
photovoltaic_error
|
) phe
|
on
|
phe.streetlight_mac = ps.code_number
|
join
|
photovoltaic_entity pe
|
on
|
pe.bind_pole_streelight_id = streetlight_id
|
where ps.streetlight_id in (
|
select pe.bind_pole_streelight_id from photovoltaic_entity pe where pe.photovoltaic_id = #{photovoltaicId})
|
order by error_id desc
|
</select>
|
</mapper>
|