重构
This commit is contained in:
@ -512,10 +512,16 @@
|
||||
<select id="getStackPointByMinute" parameterType="com.xzzn.ems.domain.vo.DateSearchRequest" resultType="com.xzzn.ems.domain.vo.StackPointVo">
|
||||
WITH ranked AS (
|
||||
SELECT
|
||||
*,
|
||||
DATE_FORMAT(DATE_ADD(DATE_FORMAT(p.update_time, '%Y-%m-%d %H:00:00'), INTERVAL CEIL(MINUTE(p.update_time) / 5) * 5 MINUTE)
|
||||
, '%Y-%m-%d %H:%i:%s') AS group_time,
|
||||
ROW_NUMBER() OVER (PARTITION BY p.device_id, date_format(p.update_time, '%Y-%m-%d %H:00:00'), CEIL(MINUTE(p.update_time) / 5) ORDER BY p.data_update_time DESC) as rn
|
||||
p.site_id,
|
||||
p.device_id,
|
||||
p.stack_soc,
|
||||
p.stack_soh,
|
||||
p.avg_temperature,
|
||||
FROM_UNIXTIME(((UNIX_TIMESTAMP(p.update_time) + 299) DIV 300) * 300) AS group_time,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY p.device_id, ((UNIX_TIMESTAMP(p.update_time) + 299) DIV 300)
|
||||
ORDER BY p.data_update_time DESC
|
||||
) as rn
|
||||
FROM
|
||||
ems_battery_stack p
|
||||
<include refid="statisCommonFilter"/>
|
||||
@ -528,16 +534,27 @@
|
||||
avg(t.avg_temperature) as avgTemp
|
||||
FROM
|
||||
ranked as t
|
||||
where t.rn = 1
|
||||
GROUP BY t.site_id, t.group_time
|
||||
</select>
|
||||
|
||||
<select id="getStackDataByMinute" parameterType="com.xzzn.ems.domain.vo.DateSearchRequest" resultType="com.xzzn.ems.domain.vo.StackStatisListVo">
|
||||
WITH ranked AS (
|
||||
SELECT
|
||||
*,
|
||||
DATE_FORMAT(DATE_ADD(DATE_FORMAT(p.update_time, '%Y-%m-%d %H:00:00'), INTERVAL CEIL(MINUTE(p.update_time) / 5) * 5 MINUTE)
|
||||
, '%Y-%m-%d %H:%i:%s') AS group_time,
|
||||
ROW_NUMBER() OVER (PARTITION BY p.device_id, date_format(p.update_time, '%Y-%m-%d %H:00:00'), CEIL(MINUTE(p.update_time) / 5) ORDER BY p.data_update_time DESC) as rn
|
||||
p.site_id,
|
||||
p.device_id,
|
||||
p.stack_soc,
|
||||
p.stack_soh,
|
||||
p.avg_temperature,
|
||||
p.operating_temp,
|
||||
p.stack_current,
|
||||
p.stack_voltage,
|
||||
p.data_update_time,
|
||||
FROM_UNIXTIME(((UNIX_TIMESTAMP(p.update_time) + 299) DIV 300) * 300) AS group_time,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY p.device_id, ((UNIX_TIMESTAMP(p.update_time) + 299) DIV 300)
|
||||
ORDER BY p.data_update_time DESC
|
||||
) as rn
|
||||
FROM
|
||||
ems_battery_stack p
|
||||
<include refid="statisCommonFilter"/>
|
||||
@ -574,4 +591,4 @@
|
||||
ranked
|
||||
GROUP BY site_id,groupTime
|
||||
</select>
|
||||
</mapper>
|
||||
</mapper>
|
||||
|
||||
@ -236,26 +236,40 @@
|
||||
<select id="getRevenueDataBySiteId" resultType="com.xzzn.ems.domain.vo.AmmeterRevenueStatisListVo">
|
||||
select
|
||||
t.data_date as dataTime,
|
||||
ROUND(t.peak_charge_diff * pc.peak, 3) as activePeakPrice,
|
||||
ROUND(t.peak_discharge_diff * pc.peak, 3) as reActivePeakPrice,
|
||||
ROUND(t.high_charge_diff * pc.high, 3) as activeHighPrice,
|
||||
ROUND(t.high_discharge_diff * pc.high, 3) as reActiveHighPrice,
|
||||
ROUND(t.flat_charge_diff * pc.flat, 3) as activeFlatPrice,
|
||||
ROUND(t.flat_discharge_diff * pc.flat, 3) as reActiveFlatPrice,
|
||||
ROUND(t.valley_charge_diff * pc.valley, 3) as activeValleyPrice,
|
||||
ROUND(t.valley_discharge_diff * pc.valley, 3) as reActiveValleyPrice
|
||||
COALESCE(c.is_workday, CASE WHEN WEEKDAY(t.data_date) < 5 THEN 1 ELSE 0 END) as isWorkday,
|
||||
CASE
|
||||
WHEN COALESCE(c.is_workday, CASE WHEN WEEKDAY(t.data_date) < 5 THEN 1 ELSE 0 END) = 1 THEN '工作日'
|
||||
ELSE '节假日'
|
||||
END as dayType,
|
||||
COALESCE(NULLIF(TRIM(w.weather_desc), ''), '--') as weatherDesc,
|
||||
ROUND(IFNULL(t.peak_charge_diff, 0) * IFNULL(pc.peak, 0), 3) as activePeakPrice,
|
||||
ROUND(IFNULL(t.peak_discharge_diff, 0) * IFNULL(pc.peak, 0), 3) as reActivePeakPrice,
|
||||
ROUND(IFNULL(t.high_charge_diff, 0) * IFNULL(pc.high, 0), 3) as activeHighPrice,
|
||||
ROUND(IFNULL(t.high_discharge_diff, 0) * IFNULL(pc.high, 0), 3) as reActiveHighPrice,
|
||||
ROUND(IFNULL(t.flat_charge_diff, 0) * IFNULL(pc.flat, 0), 3) as activeFlatPrice,
|
||||
ROUND(IFNULL(t.flat_discharge_diff, 0) * IFNULL(pc.flat, 0), 3) as reActiveFlatPrice,
|
||||
ROUND(IFNULL(t.valley_charge_diff, 0) * IFNULL(pc.valley, 0), 3) as activeValleyPrice,
|
||||
ROUND(IFNULL(t.valley_discharge_diff, 0) * IFNULL(pc.valley, 0), 3) as reActiveValleyPrice
|
||||
from ems_daily_energy_data t
|
||||
left join (
|
||||
select
|
||||
id, site_id, peak, high, flat, valley,
|
||||
CONCAT(year, '-', LPAD(month, 2, '0')) as yearMonth
|
||||
from ems_energy_price_config
|
||||
where 1=1
|
||||
<if test="siteId != null">
|
||||
and site_id = #{siteId}
|
||||
</if>
|
||||
order by year, month
|
||||
) pc on pc.yearMonth = DATE_FORMAT(t.data_date, '%Y-%m')
|
||||
left join ems_calendar_day c on c.calendar_date = t.data_date
|
||||
left join ems_site_weather_day w on w.site_id = t.site_id and w.calendar_date = t.data_date
|
||||
left join ems_energy_price_config pc on pc.id = COALESCE(
|
||||
(
|
||||
select p.id
|
||||
from ems_energy_price_config p
|
||||
where p.site_id = t.site_id
|
||||
and STR_TO_DATE(CONCAT(p.year, '-', LPAD(p.month, 2, '0'), '-01'), '%Y-%m-%d') <= DATE_FORMAT(t.data_date, '%Y-%m-01')
|
||||
order by STR_TO_DATE(CONCAT(p.year, '-', LPAD(p.month, 2, '0'), '-01'), '%Y-%m-%d') desc
|
||||
limit 1
|
||||
),
|
||||
(
|
||||
select p2.id
|
||||
from ems_energy_price_config p2
|
||||
where p2.site_id = t.site_id
|
||||
order by STR_TO_DATE(CONCAT(p2.year, '-', LPAD(p2.month, 2, '0'), '-01'), '%Y-%m-%d') asc
|
||||
limit 1
|
||||
)
|
||||
)
|
||||
where 1=1
|
||||
<if test="siteId != null">
|
||||
and t.site_id = #{siteId}
|
||||
@ -266,6 +280,7 @@
|
||||
<if test="endTime != null">
|
||||
and t.data_date <= #{endTime}
|
||||
</if>
|
||||
order by t.data_date desc
|
||||
|
||||
</select>
|
||||
</mapper>
|
||||
</mapper>
|
||||
|
||||
@ -22,6 +22,12 @@
|
||||
<result property="isAlarm" column="is_alarm"/>
|
||||
<result property="pointType" column="point_type"/>
|
||||
<result property="calcExpression" column="calc_expression"/>
|
||||
<result property="collectEnabled" column="collect_enabled"/>
|
||||
<result property="collectSource" column="collect_source"/>
|
||||
<result property="modbusRegisterType" column="modbus_register_type"/>
|
||||
<result property="modbusDataType" column="modbus_data_type"/>
|
||||
<result property="modbusReadOrder" column="modbus_read_order"/>
|
||||
<result property="modbusGroup" column="modbus_group"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="updateBy" column="update_by"/>
|
||||
@ -32,6 +38,7 @@
|
||||
<sql id="selectEmsPointConfigVo">
|
||||
select id, point_id, site_id, device_category, device_id, point_name, data_key, point_desc, register_address,
|
||||
data_unit, data_a, data_k, data_b, data_bit, is_alarm, point_type, calc_expression,
|
||||
collect_enabled, collect_source, modbus_register_type, modbus_data_type, modbus_read_order, modbus_group,
|
||||
create_by, create_time, update_by, update_time, remark
|
||||
from ems_point_config
|
||||
</sql>
|
||||
@ -51,6 +58,10 @@
|
||||
<if test="dataKey != null and dataKey != ''">and data_key like concat('%', #{dataKey}, '%')</if>
|
||||
<if test="pointDesc != null and pointDesc != ''">and point_desc like concat('%', #{pointDesc}, '%')</if>
|
||||
<if test="pointType != null and pointType != ''">and point_type = #{pointType}</if>
|
||||
<if test="collectEnabled != null">and collect_enabled = #{collectEnabled}</if>
|
||||
<if test="collectSource != null and collectSource != ''">and collect_source = #{collectSource}</if>
|
||||
<if test="modbusRegisterType != null and modbusRegisterType != ''">and modbus_register_type = #{modbusRegisterType}</if>
|
||||
<if test="modbusDataType != null and modbusDataType != ''">and modbus_data_type = #{modbusDataType}</if>
|
||||
<if test="registerAddress != null and registerAddress != ''">and register_address = #{registerAddress}</if>
|
||||
</where>
|
||||
order by update_time desc, id desc
|
||||
@ -75,6 +86,12 @@
|
||||
<if test="isAlarm != null">is_alarm,</if>
|
||||
<if test="pointType != null">point_type,</if>
|
||||
<if test="calcExpression != null">calc_expression,</if>
|
||||
<if test="collectEnabled != null">collect_enabled,</if>
|
||||
<if test="collectSource != null">collect_source,</if>
|
||||
<if test="modbusRegisterType != null">modbus_register_type,</if>
|
||||
<if test="modbusDataType != null">modbus_data_type,</if>
|
||||
<if test="modbusReadOrder != null">modbus_read_order,</if>
|
||||
<if test="modbusGroup != null">modbus_group,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
@ -98,6 +115,12 @@
|
||||
<if test="isAlarm != null">#{isAlarm},</if>
|
||||
<if test="pointType != null">#{pointType},</if>
|
||||
<if test="calcExpression != null">#{calcExpression},</if>
|
||||
<if test="collectEnabled != null">#{collectEnabled},</if>
|
||||
<if test="collectSource != null">#{collectSource},</if>
|
||||
<if test="modbusRegisterType != null">#{modbusRegisterType},</if>
|
||||
<if test="modbusDataType != null">#{modbusDataType},</if>
|
||||
<if test="modbusReadOrder != null">#{modbusReadOrder},</if>
|
||||
<if test="modbusGroup != null">#{modbusGroup},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
@ -110,6 +133,7 @@
|
||||
insert into ems_point_config (
|
||||
point_id, site_id, device_category, device_id, point_name, data_key, point_desc, register_address,
|
||||
data_unit, data_a, data_k, data_b, data_bit, is_alarm, point_type, calc_expression,
|
||||
collect_enabled, collect_source, modbus_register_type, modbus_data_type, modbus_read_order, modbus_group,
|
||||
create_by, create_time, update_by, update_time, remark
|
||||
)
|
||||
values
|
||||
@ -131,6 +155,12 @@
|
||||
#{item.isAlarm},
|
||||
#{item.pointType},
|
||||
#{item.calcExpression},
|
||||
#{item.collectEnabled},
|
||||
#{item.collectSource},
|
||||
#{item.modbusRegisterType},
|
||||
#{item.modbusDataType},
|
||||
#{item.modbusReadOrder},
|
||||
#{item.modbusGroup},
|
||||
#{item.createBy},
|
||||
now(),
|
||||
#{item.updateBy},
|
||||
@ -159,6 +189,12 @@
|
||||
<if test="isAlarm != null">is_alarm = #{isAlarm},</if>
|
||||
<if test="pointType != null">point_type = #{pointType},</if>
|
||||
<if test="calcExpression != null">calc_expression = #{calcExpression},</if>
|
||||
<if test="collectEnabled != null">collect_enabled = #{collectEnabled},</if>
|
||||
<if test="collectSource != null">collect_source = #{collectSource},</if>
|
||||
<if test="modbusRegisterType != null">modbus_register_type = #{modbusRegisterType},</if>
|
||||
<if test="modbusDataType != null">modbus_data_type = #{modbusDataType},</if>
|
||||
<if test="modbusReadOrder != null">modbus_read_order = #{modbusReadOrder},</if>
|
||||
<if test="modbusGroup != null">modbus_group = #{modbusGroup},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
@ -192,11 +228,13 @@
|
||||
insert into ems_point_config (
|
||||
point_id, site_id, device_category, device_id, point_name, data_key, point_desc, register_address,
|
||||
data_unit, data_a, data_k, data_b, data_bit, is_alarm, point_type, calc_expression,
|
||||
collect_enabled, collect_source, modbus_register_type, modbus_data_type, modbus_read_order, modbus_group,
|
||||
create_by, create_time, update_by, update_time, remark
|
||||
)
|
||||
select
|
||||
concat('PT_', replace(uuid(), '-', '')), #{targetSiteId}, device_category, device_id, point_name, data_key, point_desc, register_address,
|
||||
data_unit, data_a, data_k, data_b, data_bit, is_alarm, point_type, calc_expression,
|
||||
collect_enabled, collect_source, modbus_register_type, modbus_data_type, modbus_read_order, modbus_group,
|
||||
#{operName}, now(), #{operName}, now(), remark
|
||||
from ems_point_config
|
||||
where site_id = #{templateSiteId}
|
||||
@ -287,4 +325,19 @@
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<select id="selectModbusCollectPointConfigs" resultMap="EmsPointConfigResult">
|
||||
<include refid="selectEmsPointConfigVo"/>
|
||||
where collect_enabled = 1
|
||||
and collect_source = 'MODBUS'
|
||||
and (point_type is null or point_type <> 'calc')
|
||||
and (is_alarm is null or is_alarm = 0)
|
||||
and register_address is not null and register_address <> ''
|
||||
and modbus_register_type is not null and modbus_register_type <> ''
|
||||
and modbus_data_type is not null and modbus_data_type <> ''
|
||||
<if test="siteId != null and siteId != ''">
|
||||
and site_id = #{siteId}
|
||||
</if>
|
||||
order by site_id asc, device_id asc, modbus_read_order asc, id asc
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
<?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.xzzn.ems.mapper.EmsSiteWeatherDayMapper">
|
||||
|
||||
<update id="updateWeatherDesc">
|
||||
update ems_site_weather_day
|
||||
set weather_desc = #{weatherDesc},
|
||||
weather_code = #{weatherCode},
|
||||
update_time = now()
|
||||
where site_id = #{siteId}
|
||||
and calendar_date = #{calendarDate}
|
||||
</update>
|
||||
|
||||
<select id="selectCountBySiteAndDate" resultType="int">
|
||||
select count(1)
|
||||
from ems_site_weather_day
|
||||
where site_id = #{siteId}
|
||||
and calendar_date = #{calendarDate}
|
||||
</select>
|
||||
|
||||
<insert id="insertSiteWeatherDay">
|
||||
insert into ems_site_weather_day(site_id, calendar_date, weather_desc, weather_code, source, create_time, update_time)
|
||||
values (#{siteId}, #{calendarDate}, #{weatherDesc}, #{weatherCode}, #{source}, now(), now())
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user