<?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.psdc.mapper.PsdcStatisticsYearMapper" >
<resultMap type= "com.psdc.entity.PsdcStatisticsYear" id= "PsdcStatisticsYearMap" >
<result property= "yearId" column= "year_id" />
<result property= "deviceId" column= "device_id" />
<result property= "deviceName" column= "device_name" />
<result property= "yearDate" column= "year_date" />
<result property= "month01" column= "month_01" />
<result property= "month02" column= "month_02" />
<result property= "month03" column= "month_03" />
<result property= "month04" column= "month_04" />
<result property= "month05" column= "month_05" />
<result property= "month06" column= "month_06" />
<result property= "month07" column= "month_07" />
<result property= "month08" column= "month_08" />
<result property= "month09" column= "month_09" />
<result property= "month10" column= "month_10" />
<result property= "month11" column= "month_11" />
<result property= "month12" column= "month_12" />
</resultMap>
<!-- 通过ID查询单条数据 -->
<select id= "queryById" resultMap= "PsdcStatisticsYearMap" >
select
year_id,device_id,device_name,year_date,month_01,month_02,month_03,month_04,month_05,month_06,month_07,month_08,month_09,month_10,month_11,month_12
from psdc_statistics_year
where year_id = #{yearId}
</select>
<!-- 分页查询指定行数据 -->
<select id= "queryAllByLimit" resultMap= "PsdcStatisticsYearMap" >
Select
year_id,pd.device_id,pd.device_name,year_date,month_01,month_02,month_03,month_04,month_05,month_06,month_07,month_08,month_09,month_10,month_11,month_12
From psdc_statistics_year psy Left Join psdc_device pd On pd.device_id = psy.device_id
<where >
<if test= "deviceId != null and deviceId != ''" >
And psy.device_id = #{deviceId}
</if>
<!-- 开始时间检索 -->
<if test= "startTime != null and startTime != ''" >
And date_format(year_date,'%Y') > = #{startTime}
</if>
<!-- 结束时间检索 -->
<if test= "endTime != null and endTime != ''" >
And date_format(year_date,'%Y') < = #{endTime}
</if>
</where>
</select>
<!-- 新增数据 -->
<insert id= "insert" useGeneratedKeys = 'true' keyProperty= "yearId" >
insert into psdc_statistics_year(year_id,device_id,device_name,year_date,month_01,month_02,month_03,month_04,month_05,month_06,month_07,month_08,month_09,month_10,month_11,month_12)
values (#{yearId},#{deviceId},#{deviceName},#{yearDate},#{month01},#{month02},#{month03},#{month04},#{month05},#{month06},#{month07},#{month08},#{month09},#{month10},#{month11},#{month12})
</insert>
<insert id= "insertYear" useGeneratedKeys = 'true' keyProperty= "yearId" >
Insert into psdc_statistics_year(
year_date,
device_id,
device_name
<if test= "month01 != null and month01 != 0" > ,month_01,</if>
<if test= "month02 != null and month02 != 0" > month_02,</if>
<if test= "month03 != null and month03 != 0" > month_03,</if>
<if test= "month04 != null and month04 != 0" > month_04,</if>
<if test= "month05 != null and month05 != 0" > month_05,</if>
<if test= "month06 != null and month06 != 0" > month_06,</if>
<if test= "month07 != null and month07 != 0" > month_07,</if>
<if test= "month08 != null and month08 != 0" > month_08,</if>
<if test= "month09 != null and month09 != 0" > month_09,</if>
<if test= "month10 != null and month10 != 0" > month_10,</if>
<if test= "month11 != null and month11 != 0" > month_11,</if>
<if test= "month12 != null and month12 != 0" > month_12,</if>
)values(
#{yearDate},
#{deviceId},
#{deviceName}
<if test= "month01 != null and month01 != 0" > ,#{month01},</if>
<if test= "month02 != null and month02 != 0" > #{month02},</if>
<if test= "month03 != null and month03 != 0" > #{month03},</if>
<if test= "month04 != null and month04 != 0" > #{month04},</if>
<if test= "month05 != null and month05 != 0" > #{month05},</if>
<if test= "month06 != null and month06 != 0" > #{month06},</if>
<if test= "month07 != null and month07 != 0" > #{month07},</if>
<if test= "month08 != null and month08 != 0" > #{month08},</if>
<if test= "month09 != null and month09 != 0" > #{month09},</if>
<if test= "month10 != null and month10 != 0" > #{month10},</if>
<if test= "month11 != null and month11 != 0" > #{month11},</if>
<if test= "month12 != null and month12 != 0" > #{month12},</if>
)
</insert>
<!-- 更新数据 -->
<update id= "update" >
update psdc_statistics_year
<set >
<if test= "deviceId != null and deviceId != ''" >
device_id = #{deviceId},
</if>
<if test= "deviceName != null and deviceName != ''" >
device_name = #{deviceName},
</if>
<if test= "year_date != null and year_date != ''" >
year_date = #{yearDate},
</if>
<if test= "month01 != null and month01 != ''" >
month_01 = #{month01},
</if>
<if test= "month02 != null and month02 != ''" >
month_02 = #{month02},
</if>
<if test= "month03 != null and month03 != ''" >
month_03 = #{month03},
</if>
<if test= "month04 != null and month04 != ''" >
month_04 = #{month04},
</if>
<if test= "month05 != null and month05 != ''" >
month_05 = #{month05},
</if>
<if test= "month06 != null and month06 != ''" >
month_06 = #{month06},
</if>
<if test= "month07 != null and month07 != ''" >
month_07 = #{month07},
</if>
<if test= "month08 != null and month08 != ''" >
month_08 = #{month08},
</if>
<if test= "month09 != null and month09 != ''" >
month_09 = #{month09},
</if>
<if test= "month10 != null and month10 != ''" >
month_10 = #{month10},
</if>
<if test= "month11 != null and month11 != ''" >
month_11 = #{month11},
</if>
<if test= "month12 != null and month12 != ''" >
month_12 = #{month12},
</if>
</set>
where year_id = #{yearId}
</update>
<!-- 更新固定点位数据 -->
<update id= "updatePoint" >
update psdc_statistics_year
set ${yearPoint} = #{value}
where year_id = #{yearId};
</update>
<!-- 通过主键删除 -->
<delete id= "deleteById" >
delete from psdc_statistics_year where year_id = #{yearId}
</delete>
<!-- 根据设备id和日期查询 -->
<select id= "queryByDeviceIdAndDate" resultMap= "PsdcStatisticsYearMap" >
select * from psdc_statistics_year where device_id = #{deviceId} and date_format(year_date,'%Y') = #{date} Order By year_date Desc Limit 0,1
</select>
<select id= "queryOneLineSum" resultType= "double" >
select ifnull(month_01,0.0) + ifnull(month_02,0.0) + ifnull(month_03,0.0) + ifnull(month_04,0.0) + ifnull(month_05,0.0) +
ifnull(month_06,0.0) + ifnull(month_07,0.0) + ifnull(month_08,0.0) + ifnull(month_09,0.0) + ifnull(month_10,0.0) +
ifnull(month_11,0.0) + ifnull(month_12,0.0) as total
from psdc_statistics_year where device_id = #{deviceId} and date_format(year_date,'%Y') = #{datetime}
</select>
<select id= "count" resultType= "java.lang.Long" >
Select COUNT(1) From psdc_statistics_year
Where device_id = #{deviceId} And date_format(year_date,'%Y') = #{datetime}
</select>
<update id= "updateYear" >
Update psdc_statistics_year Set ${valNo} = #{powerValue}
Where device_id = #{devId} And date_format(year_date,'%Y') = #{samDate}
</update>
</mapper>