|
|
@@ -1,29 +1,37 @@
|
|
|
package com.ufo.project.model.service.impl;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.time.ZonedDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.time.format.DateTimeParseException;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import com.ufo.base.common.utils.DateUtils;
|
|
|
+
|
|
|
import com.ufo.project.model.domain.DataElectricityLocal;
|
|
|
import com.ufo.project.model.mapper.DataElectricityLocalMapper;
|
|
|
import com.ufo.project.model.service.IDataElectricityLocalService;
|
|
|
|
|
|
/**
|
|
|
* 功率采样数据Service业务层处理
|
|
|
- *
|
|
|
+ *
|
|
|
* @author oleauto
|
|
|
* @date 2026-06-24
|
|
|
*/
|
|
|
@Service
|
|
|
-public class DataElectricityLocalServiceImpl implements IDataElectricityLocalService
|
|
|
+public class DataElectricityLocalServiceImpl implements IDataElectricityLocalService
|
|
|
{
|
|
|
@Autowired
|
|
|
private DataElectricityLocalMapper dataElectricityLocalMapper;
|
|
|
|
|
|
/**
|
|
|
* 查询功率采样数据
|
|
|
- *
|
|
|
+ *
|
|
|
* @param tm 功率采样数据主键
|
|
|
* @return 功率采样数据
|
|
|
*/
|
|
|
@@ -35,7 +43,7 @@ public class DataElectricityLocalServiceImpl implements IDataElectricityLocalSer
|
|
|
|
|
|
/**
|
|
|
* 查询功率采样数据列表
|
|
|
- *
|
|
|
+ *
|
|
|
* @param dataElectricityLocal 功率采样数据
|
|
|
* @return 功率采样数据
|
|
|
*/
|
|
|
@@ -47,21 +55,79 @@ public class DataElectricityLocalServiceImpl implements IDataElectricityLocalSer
|
|
|
|
|
|
/**
|
|
|
* 查询场站时间段内的实发功率数据
|
|
|
+ * <p>支持的时间格式:</p>
|
|
|
+ * <ul>
|
|
|
+ * <li>ISO 8601 带时区:2026-08-02T00:00:00+08:00</li>
|
|
|
+ * <li>日期:yyyy-MM-dd</li>
|
|
|
+ * <li>日期时间:yyyy-MM-dd HH:mm:ss</li>
|
|
|
+ * <li>毫秒时间戳(字符串或纯数字):1722547200000</li>
|
|
|
+ * </ul>
|
|
|
+ * 仅日期格式默认使用 Asia/Shanghai 时区。
|
|
|
*
|
|
|
* @param configStationId 场站id
|
|
|
- * @param startTime 起始时间(ISO 8601带时区字符串,如 2026-08-02T00:00:00+08:00)
|
|
|
- * @param endTime 结束时间(ISO 8601带时区字符串)
|
|
|
+ * @param startTime 起始时间(见上格式说明)
|
|
|
+ * @param endTime 结束时间(见上格式说明)
|
|
|
* @return 功率采样数据集合(按 tm 升序)
|
|
|
*/
|
|
|
@Override
|
|
|
public List<DataElectricityLocal> selectActualPowerList(Long configStationId, String startTime, String endTime)
|
|
|
{
|
|
|
- return dataElectricityLocalMapper.selectActualPowerList(configStationId, startTime, endTime);
|
|
|
+ String start = parseToISO8601(startTime);
|
|
|
+ String end = parseToISO8601(endTime);
|
|
|
+ return dataElectricityLocalMapper.selectActualPowerList(configStationId, start, end);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将多种时间格式转换为 ISO 8601 带时区字符串(如 2026-08-02T00:00:00+08:00)。
|
|
|
+ * 仅日期格式默认使用 Asia/Shanghai 时区。
|
|
|
+ */
|
|
|
+ private String parseToISO8601(String time)
|
|
|
+ {
|
|
|
+ if (time == null || time.isEmpty())
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1) ISO 8601 带时区(已有 +08:00 等形式,直接返回)
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ZonedDateTime.parse(time);
|
|
|
+ return time;
|
|
|
+ }
|
|
|
+ catch (DateTimeParseException ignored)
|
|
|
+ {
|
|
|
+ // fall through
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2) 毫秒时间戳
|
|
|
+ try
|
|
|
+ {
|
|
|
+ long ts = Long.parseLong(time);
|
|
|
+ LocalDateTime ldt = LocalDateTime.ofInstant(
|
|
|
+ java.time.Instant.ofEpochMilli(ts), ZoneId.of("Asia/Shanghai"));
|
|
|
+ return ldt.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
|
|
+ }
|
|
|
+ catch (NumberFormatException e)
|
|
|
+ {
|
|
|
+ // not a timestamp, fall through
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3) yyyy-MM-dd 或 yyyy-MM-dd HH:mm:ss(借助 DateUtils)
|
|
|
+ Date date = DateUtils.parseDate(time);
|
|
|
+ if (date != null)
|
|
|
+ {
|
|
|
+ ZonedDateTime zdt = date.toInstant()
|
|
|
+ .atZone(ZoneId.of("Asia/Shanghai"));
|
|
|
+ return zdt.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4) 无法解析,原样返回让 SQL 层报错
|
|
|
+ return time;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 新增功率采样数据
|
|
|
- *
|
|
|
+ *
|
|
|
* @param dataElectricityLocal 功率采样数据
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@@ -73,7 +139,7 @@ public class DataElectricityLocalServiceImpl implements IDataElectricityLocalSer
|
|
|
|
|
|
/**
|
|
|
* 修改功率采样数据
|
|
|
- *
|
|
|
+ *
|
|
|
* @param dataElectricityLocal 功率采样数据
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@@ -85,7 +151,7 @@ public class DataElectricityLocalServiceImpl implements IDataElectricityLocalSer
|
|
|
|
|
|
/**
|
|
|
* 批量删除功率采样数据
|
|
|
- *
|
|
|
+ *
|
|
|
* @param tms 需要删除的功率采样数据主键
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@@ -97,7 +163,7 @@ public class DataElectricityLocalServiceImpl implements IDataElectricityLocalSer
|
|
|
|
|
|
/**
|
|
|
* 删除功率采样数据信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param tm 功率采样数据主键
|
|
|
* @return 结果
|
|
|
*/
|