15 changed files with 778 additions and 1 deletions
@ -0,0 +1,66 @@ |
|||||||
|
package com.mh.common.core.domain.dto; |
||||||
|
|
||||||
|
import lombok.Getter; |
||||||
|
import lombok.Setter; |
||||||
|
import org.apache.commons.lang3.builder.ToStringBuilder; |
||||||
|
|
||||||
|
import java.math.BigDecimal; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author LJF |
||||||
|
* @version 1.0 |
||||||
|
* @project EEMCS |
||||||
|
* @description 冷源监视系统性能DTO |
||||||
|
* @date 2025-03-30 15:07:06 |
||||||
|
*/ |
||||||
|
@Getter |
||||||
|
public class SysPerformanceDTO { |
||||||
|
|
||||||
|
private BigDecimal realEER; |
||||||
|
|
||||||
|
private BigDecimal realPower; |
||||||
|
|
||||||
|
private BigDecimal realCold; |
||||||
|
|
||||||
|
private BigDecimal yearEER; |
||||||
|
|
||||||
|
private BigDecimal yearPower; |
||||||
|
|
||||||
|
private BigDecimal yearCold; |
||||||
|
|
||||||
|
public void setRealEER(BigDecimal realEER) { |
||||||
|
this.realEER = realEER.setScale(1, BigDecimal.ROUND_HALF_UP); |
||||||
|
} |
||||||
|
|
||||||
|
public void setRealPower(BigDecimal realPower) { |
||||||
|
this.realPower = realPower.setScale(1, BigDecimal.ROUND_HALF_UP); |
||||||
|
} |
||||||
|
|
||||||
|
public void setRealCold(BigDecimal realCold) { |
||||||
|
this.realCold = realCold.setScale(1, BigDecimal.ROUND_HALF_UP); |
||||||
|
} |
||||||
|
|
||||||
|
public void setYearEER(BigDecimal yearEER) { |
||||||
|
this.yearEER = yearEER.setScale(1, BigDecimal.ROUND_HALF_UP); |
||||||
|
} |
||||||
|
|
||||||
|
public void setYearPower(BigDecimal yearPower) { |
||||||
|
this.yearPower = yearPower.setScale(1, BigDecimal.ROUND_HALF_UP); |
||||||
|
} |
||||||
|
|
||||||
|
public void setYearCold(BigDecimal yearCold) { |
||||||
|
this.yearCold = yearCold.setScale(1, BigDecimal.ROUND_HALF_UP); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String toString() { |
||||||
|
return new ToStringBuilder(this) |
||||||
|
.append("realEER", realEER) |
||||||
|
.append("realPower", realPower) |
||||||
|
.append("realCold", realCold) |
||||||
|
.append("yearEER", yearEER) |
||||||
|
.append("yearPower", yearPower) |
||||||
|
.append("yearCold", yearCold) |
||||||
|
.toString(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,96 @@ |
|||||||
|
package com.mh.common.core.domain.entity; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat; |
||||||
|
import lombok.Getter; |
||||||
|
import lombok.Setter; |
||||||
|
import org.apache.commons.lang3.builder.ToStringBuilder; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author LJF |
||||||
|
* @version 1.0 |
||||||
|
* @project EEMCS |
||||||
|
* @description 存储天气信息表数据 |
||||||
|
* @date 2025-03-30 10:54:46 |
||||||
|
*/ |
||||||
|
@Setter |
||||||
|
@Getter |
||||||
|
@TableName("weather_data") |
||||||
|
public class WeatherData { |
||||||
|
|
||||||
|
@TableId(value = "id", type = IdType.AUTO) |
||||||
|
private Integer id; |
||||||
|
|
||||||
|
/** |
||||||
|
* 省份名称,如"广东省" |
||||||
|
*/ |
||||||
|
private String province; |
||||||
|
|
||||||
|
/** |
||||||
|
* 城市名称,如"广州市" |
||||||
|
*/ |
||||||
|
private String city; |
||||||
|
|
||||||
|
/** |
||||||
|
* 行政区划代码,如"440100" |
||||||
|
*/ |
||||||
|
private String adCode; |
||||||
|
|
||||||
|
/** |
||||||
|
* 天气现象,如"晴"、"多云"、"小雨"等 |
||||||
|
*/ |
||||||
|
private String weather; |
||||||
|
|
||||||
|
/** |
||||||
|
* 温度,单位:摄氏度 |
||||||
|
*/ |
||||||
|
private Integer temperature; |
||||||
|
|
||||||
|
/** |
||||||
|
* 相对湿度,单位:百分比(0-100) |
||||||
|
*/ |
||||||
|
private Integer humidity; |
||||||
|
|
||||||
|
/** |
||||||
|
* 风向描述,如"东北风"、"西南风" |
||||||
|
*/ |
||||||
|
private String windDirection; |
||||||
|
|
||||||
|
/** |
||||||
|
* 风力描述,如"3-4级"、"5级" |
||||||
|
*/ |
||||||
|
private String windPower; |
||||||
|
|
||||||
|
/** |
||||||
|
* 天气数据报告时间,记录数据采集的具体时间 |
||||||
|
*/ |
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||||
|
private Date reportTime; |
||||||
|
|
||||||
|
/** |
||||||
|
* 记录创建时间,自动设置为当前时间 |
||||||
|
*/ |
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||||
|
private Date createdTime; |
||||||
|
|
||||||
|
@Override |
||||||
|
public String toString() { |
||||||
|
return new ToStringBuilder(this) |
||||||
|
.append("id", id) |
||||||
|
.append("province", province) |
||||||
|
.append("city", city) |
||||||
|
.append("adCode", adCode) |
||||||
|
.append("weather", weather) |
||||||
|
.append("temperature", temperature) |
||||||
|
.append("humidity", humidity) |
||||||
|
.append("windDirection", windDirection) |
||||||
|
.append("windPower", windPower) |
||||||
|
.append("reportTime", reportTime) |
||||||
|
.append("createdTime", createdTime) |
||||||
|
.toString(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,138 @@ |
|||||||
|
package com.mh.common.utils; |
||||||
|
|
||||||
|
import java.math.BigDecimal; |
||||||
|
import java.math.RoundingMode; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author LJF |
||||||
|
* @version 1.0 |
||||||
|
* @project NewZhujiang_Server |
||||||
|
* @description 天气工具类 |
||||||
|
* @date 2024-04-15 11:16:06 |
||||||
|
*/ |
||||||
|
public class WeatherUtil { |
||||||
|
|
||||||
|
// Magnus公式常数
|
||||||
|
private static final double A = 17.27; |
||||||
|
private static final double B = 237.7; |
||||||
|
|
||||||
|
public double E(double t) { |
||||||
|
// 饱和水汽压:E(t)=611.2exp(17.67t/(243.5+t))
|
||||||
|
return 611.2 * Math.exp(17.67 * t / (243.5 + t)); |
||||||
|
} |
||||||
|
|
||||||
|
public double g(double t) { |
||||||
|
// 干空气比焓:g(t)=1.01t 1.01为干空气的定压比热,kJ/(kg℃)。
|
||||||
|
return 1.01 * t; |
||||||
|
} |
||||||
|
|
||||||
|
public double v(double t) { |
||||||
|
// 水蒸气比焓:v(t)=2501+1.85t 2501是水在0℃时变成水蒸气的汽化潜热,kJ/kg;1.85是水蒸气的定压比热,kJ/(kg℃)
|
||||||
|
return 2501 + 1.85 * t; |
||||||
|
} |
||||||
|
|
||||||
|
public double d(double t, double psi, double p) { |
||||||
|
// 湿空气的含湿量:d(t,ψ)=0.622ψE(t)/(p-ψE(t)) ψ为相对湿度;p为标准大气压101325,单位为Pa
|
||||||
|
return 0.622 * psi * E(t) / (p - psi * E(t)); |
||||||
|
} |
||||||
|
|
||||||
|
public double d2(double tg, double ts, double ds) { |
||||||
|
// tw为湿空气湿球温度,℃;t为干球温度,℃;ds为湿空气等焓加湿到饱和状态时含湿量(简称饱和含湿量),kg / kg(a)
|
||||||
|
// 此处假设ds值直接输入,不需要查表
|
||||||
|
if (ts >= 0) { |
||||||
|
return ((2530 - 2.326 * ts) * ds - 1.006 * (tg - ts)) / |
||||||
|
(2501 + 1.86 * tg - 4.186 * ts); |
||||||
|
} else { |
||||||
|
return ((2830 - 0.24 * ts) * ds - 1.006 * (tg - ts)) / |
||||||
|
(2830 + 1.86 * tg - 2.1 * ts); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public double h(double t, double psi, double p) { |
||||||
|
// 湿空气的比焓:h(t,ψ)=g(t)+d(t,ψ)v(t)
|
||||||
|
return g(t) + d(t, psi, p) * v(t); |
||||||
|
} |
||||||
|
|
||||||
|
public double computePsi(double tg, double ts, double p) { |
||||||
|
// ψ为相对湿度, tg为干球温度,ts为湿球温度
|
||||||
|
return p * (g(ts) - g(tg) + d(ts, 1, p) * v(ts)) / |
||||||
|
(E(tg) * (g(ts) - g(tg) + d(ts, 1, p) * v(ts) + 0.622 * v(tg))); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 计算湿球温度 |
||||||
|
* @param temp |
||||||
|
* @param wet |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public BigDecimal returnComputePsi(double temp, double wet, double p) { |
||||||
|
double oTs = 0; |
||||||
|
double oD = 0; |
||||||
|
for (int i = 0; i < 10000; i++) { |
||||||
|
oTs += 0 + i * 0.00001; |
||||||
|
oD = computePsi(temp, oTs, p); |
||||||
|
double gap = wet - oD; |
||||||
|
if (Math.abs(gap) <= 0.001) { |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
return new BigDecimal(oTs); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 计算含湿量 |
||||||
|
* @param temp 单位:℃ |
||||||
|
* @param wet 单位:0.01 |
||||||
|
* @param pressure 单位:KPa |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public BigDecimal returnMoistureContent(String temp, String wet, String pressure) { |
||||||
|
// 计算水蒸气饱和压力
|
||||||
|
BigDecimal divide = new BigDecimal("7.5").multiply(new BigDecimal(temp)) |
||||||
|
.divide(new BigDecimal("237") |
||||||
|
.add(new BigDecimal(temp)), 20, RoundingMode.HALF_UP); |
||||||
|
// double result = Math.pow(10, Double.parseDouble(divide.toString()))*0.611;
|
||||||
|
// System.out.println("水蒸气饱和压力==》" + result);
|
||||||
|
// 计算含湿量
|
||||||
|
BigDecimal ps = new BigDecimal(wet).multiply(BigDecimal.valueOf(Math.pow(10, Double.parseDouble(divide.toString())) * 0.611)); |
||||||
|
BigDecimal d = new BigDecimal("622").multiply( |
||||||
|
ps.divide(new BigDecimal(pressure).subtract(ps), 10, RoundingMode.HALF_UP)); |
||||||
|
return d; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 比较焓值 |
||||||
|
* @param temp 单位:℃ |
||||||
|
* @param wet 单位:0.01 |
||||||
|
* @param pressure 单位:KPa |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public BigDecimal returnEnthalpy(String temp, String wet, String pressure) { |
||||||
|
BigDecimal moistureContent = returnMoistureContent(temp, wet, pressure); |
||||||
|
BigDecimal add = (new BigDecimal("2490") |
||||||
|
.add(new BigDecimal("1.84").multiply(new BigDecimal(temp)))) |
||||||
|
.multiply(moistureContent).divide(new BigDecimal("1000"), 10, RoundingMode.HALF_UP); |
||||||
|
// 计算焓值
|
||||||
|
BigDecimal i = (new BigDecimal(temp).multiply(new BigDecimal("1.01"))).add(add); |
||||||
|
return i.setScale(1, RoundingMode.HALF_UP); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 计算露点温度 |
||||||
|
* @param temperature 当前温度(℃) |
||||||
|
* @param humidity 相对湿度(%) |
||||||
|
* @return 露点温度(℃),保留2位小数 |
||||||
|
*/ |
||||||
|
public BigDecimal calculateDewPoint(double temperature, double humidity) { |
||||||
|
// 1. 计算中间变量α
|
||||||
|
double alpha = (A * temperature) / (B + temperature) + Math.log(humidity / 100.0); |
||||||
|
|
||||||
|
// 2. 计算露点温度
|
||||||
|
double dewPoint = (B * alpha) / (A - alpha); |
||||||
|
|
||||||
|
// 3. 四舍五入保留2位小数
|
||||||
|
return BigDecimal.valueOf(dewPoint) |
||||||
|
.setScale(2, RoundingMode.HALF_UP); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,73 @@ |
|||||||
|
package com.mh.quartz.task; |
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSON; |
||||||
|
import com.alibaba.fastjson2.JSONObject; |
||||||
|
import com.mh.common.core.domain.entity.SysParams; |
||||||
|
import com.mh.common.core.domain.entity.WeatherData; |
||||||
|
import com.mh.common.utils.DateUtils; |
||||||
|
import com.mh.common.utils.StringUtils; |
||||||
|
import com.mh.system.service.ISysParamsService; |
||||||
|
import com.mh.system.service.IWeatherDataService; |
||||||
|
import jakarta.annotation.Resource; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.beans.factory.annotation.Value; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
import org.springframework.web.client.RestTemplate; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author LJF |
||||||
|
* @version 1.0 |
||||||
|
* @project EEMCS |
||||||
|
* @description 获取天气信息任务 |
||||||
|
* @date 2025-03-30 11:31:08 |
||||||
|
*/ |
||||||
|
@Slf4j |
||||||
|
@Component("getWeatherDataTask") |
||||||
|
public class GetWeatherDataTask { |
||||||
|
|
||||||
|
@Value("${amap.key}") |
||||||
|
String amapKey; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ISysParamsService sysParamsService; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private IWeatherDataService weatherDataService; |
||||||
|
|
||||||
|
public void getWeatherInfo() { |
||||||
|
// 从系统参数中获取对应的项目区域
|
||||||
|
List<SysParams> sysParams = sysParamsService.queryList(); |
||||||
|
if (null != sysParams && !sysParams.isEmpty()) { |
||||||
|
String url = "https://restapi.amap.com/v3/weather/weatherInfo?key="+amapKey+"&city="+sysParams.get(0).getProArea(); |
||||||
|
RestTemplate restTemplate = new RestTemplate(); |
||||||
|
String returnResult = restTemplate.getForObject(url, String.class); |
||||||
|
if (!StringUtils.isBlank(returnResult)) { |
||||||
|
JSONObject jsonObject = JSON.parseObject(returnResult); |
||||||
|
System.out.println(jsonObject); |
||||||
|
if ("1".equals(jsonObject.get("status"))) { |
||||||
|
try { |
||||||
|
WeatherData weatherData = new WeatherData(); |
||||||
|
weatherData.setProvince(jsonObject.getJSONArray("lives").getJSONObject(0).getString("province")); |
||||||
|
weatherData.setCity(jsonObject.getJSONArray("lives").getJSONObject(0).getString("city")); |
||||||
|
weatherData.setAdCode(jsonObject.getJSONArray("lives").getJSONObject(0).getString("adcode")); |
||||||
|
weatherData.setWeather(jsonObject.getJSONArray("lives").getJSONObject(0).getString("weather")); |
||||||
|
weatherData.setTemperature(jsonObject.getJSONArray("lives").getJSONObject(0).getInteger("temperature")); |
||||||
|
weatherData.setHumidity(jsonObject.getJSONArray("lives").getJSONObject(0).getInteger("humidity")); |
||||||
|
weatherData.setWindDirection(jsonObject.getJSONArray("lives").getJSONObject(0).getString("winddirection")); |
||||||
|
weatherData.setWindPower(jsonObject.getJSONArray("lives").getJSONObject(0).getString("windpower")); |
||||||
|
weatherData.setReportTime(DateUtils.stringToDate(jsonObject.getJSONArray("lives").getJSONObject(0).getString("reporttime"), "yyyy-MM-dd HH:mm:ss")); |
||||||
|
weatherData.setCreatedTime(new Date()); |
||||||
|
weatherDataService.insertWeatherData(weatherData); |
||||||
|
} catch (Exception e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,20 @@ |
|||||||
|
package com.mh.system.mapper; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import com.mh.common.core.domain.entity.WeatherData; |
||||||
|
import org.apache.ibatis.annotations.Mapper; |
||||||
|
import org.apache.ibatis.annotations.Param; |
||||||
|
import org.apache.ibatis.annotations.Select; |
||||||
|
/** |
||||||
|
* @author LJF |
||||||
|
* @version 1.0 |
||||||
|
* @project EEMCS |
||||||
|
* @description 天气服务mapper |
||||||
|
* @date 2025-03-30 11:03:51 |
||||||
|
*/ |
||||||
|
@Mapper |
||||||
|
public interface WeatherDataMapper extends BaseMapper<WeatherData> { |
||||||
|
|
||||||
|
@Select("select * from weather_data where report_time::date = #{date}::date order by report_time desc limit 1") |
||||||
|
WeatherData selectWeatherDataByDate(@Param("date") String date); |
||||||
|
} |
@ -0,0 +1,16 @@ |
|||||||
|
package com.mh.system.service; |
||||||
|
|
||||||
|
import com.mh.common.core.domain.entity.WeatherData; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author LJF |
||||||
|
* @version 1.0 |
||||||
|
* @project EEMCS |
||||||
|
* @description 天气服务接口 |
||||||
|
* @date 2025-03-30 11:37:46 |
||||||
|
*/ |
||||||
|
public interface IWeatherDataService { |
||||||
|
|
||||||
|
int insertWeatherData(WeatherData weatherData); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,33 @@ |
|||||||
|
package com.mh.system.service.device; |
||||||
|
|
||||||
|
import com.mh.common.core.domain.dto.SysPerformanceDTO; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author LJF |
||||||
|
* @version 1.0 |
||||||
|
* @project EEMCS |
||||||
|
* @description 冷源系统监控服务类 |
||||||
|
* @date 2025-03-30 10:28:22 |
||||||
|
*/ |
||||||
|
public interface ICoolingSystemMonitorService { |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取天气数据 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
Map<String, String> getWeatherData(); |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取运行时间 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
Map<String, String> getRunTime(); |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取系统性能数据 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
SysPerformanceDTO getSysPerformance(); |
||||||
|
} |
@ -0,0 +1,192 @@ |
|||||||
|
package com.mh.system.service.device.impl; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||||
|
import com.mh.common.core.domain.dto.SysPerformanceDTO; |
||||||
|
import com.mh.common.core.domain.entity.CollectionParamsManage; |
||||||
|
import com.mh.common.core.domain.entity.SysParams; |
||||||
|
import com.mh.common.core.domain.entity.WeatherData; |
||||||
|
import com.mh.common.utils.DateUtils; |
||||||
|
import com.mh.common.utils.WeatherUtil; |
||||||
|
import com.mh.system.mapper.SysParamsMapper; |
||||||
|
import com.mh.system.mapper.WeatherDataMapper; |
||||||
|
import com.mh.system.mapper.device.CollectionParamsManageMapper; |
||||||
|
import com.mh.system.service.device.ICollectionParamsManageService; |
||||||
|
import com.mh.system.service.device.ICoolingSystemMonitorService; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.math.BigDecimal; |
||||||
|
import java.math.RoundingMode; |
||||||
|
import java.util.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author LJF |
||||||
|
* @version 1.0 |
||||||
|
* @project EEMCS |
||||||
|
* @description 冷源系统监控实现类 |
||||||
|
* @date 2025-03-30 10:28:53 |
||||||
|
*/ |
||||||
|
@Slf4j |
||||||
|
@Service |
||||||
|
public class CoolingSystemMonitorServiceImpl implements ICoolingSystemMonitorService { |
||||||
|
|
||||||
|
private final SysParamsMapper sysParamsMapper; |
||||||
|
|
||||||
|
private final WeatherDataMapper weatherDataMapper; |
||||||
|
|
||||||
|
private final CollectionParamsManageMapper collectionParamsManageMapper; |
||||||
|
|
||||||
|
public CoolingSystemMonitorServiceImpl(SysParamsMapper sysParamsMapper, WeatherDataMapper weatherDataMapper, CollectionParamsManageMapper collectionParamsManageMapper) { |
||||||
|
this.sysParamsMapper = sysParamsMapper; |
||||||
|
this.weatherDataMapper = weatherDataMapper; |
||||||
|
this.collectionParamsManageMapper = collectionParamsManageMapper; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public SysPerformanceDTO getSysPerformance() { |
||||||
|
SysPerformanceDTO sysPerformanceDTO = new SysPerformanceDTO(); |
||||||
|
// 查询总表的数据
|
||||||
|
QueryWrapper<CollectionParamsManage> queryWrapper = new QueryWrapper<CollectionParamsManage>() |
||||||
|
.eq("system_type", "0") |
||||||
|
.eq("terminal_device_type", "15") |
||||||
|
.in("param_type", Arrays.asList("16", "17")); |
||||||
|
List<CollectionParamsManage> collectionParamsManages = collectionParamsManageMapper.selectList(queryWrapper); |
||||||
|
// 遍历获取数据
|
||||||
|
if (null != collectionParamsManages && !collectionParamsManages.isEmpty()) { |
||||||
|
for (CollectionParamsManage value : collectionParamsManages) { |
||||||
|
// 判断paramTYpe,如果16:是电表,如果是17:是冷量计
|
||||||
|
if ("16".equals(value.getParamType())) { |
||||||
|
// 电表
|
||||||
|
// 在判断cur_time是当天值,grade,40:累计值,140:瞬时值
|
||||||
|
if (DateUtils.isSameDay(new Date(), value.getCurTime())) { |
||||||
|
// 如果是当天值,判断grade,40:累计值,140:瞬时值
|
||||||
|
if (value.getGrade() == 40) { |
||||||
|
// 累计值
|
||||||
|
sysPerformanceDTO.setYearPower(value.getCurValue()); |
||||||
|
} else if (value.getGrade() == 140) { |
||||||
|
// 瞬时值
|
||||||
|
sysPerformanceDTO.setRealPower(value.getCurValue()); |
||||||
|
} |
||||||
|
} else { |
||||||
|
// 如果不是当天值,判断grade,40:累计值,140:瞬时值
|
||||||
|
BigDecimal bigDecimal = new BigDecimal("0.0"); |
||||||
|
if (value.getGrade() == 40) { |
||||||
|
// 累计值
|
||||||
|
sysPerformanceDTO.setYearPower(bigDecimal); |
||||||
|
} else if (value.getGrade() == 140) { |
||||||
|
// 瞬时值
|
||||||
|
sysPerformanceDTO.setRealPower(bigDecimal); |
||||||
|
} |
||||||
|
} |
||||||
|
} else if ("17".equals(value.getParamType())) { |
||||||
|
// 冷量计
|
||||||
|
// 在判断cur_time是当天值,grade,40:累计值,140:瞬时值
|
||||||
|
if (DateUtils.isSameDay(new Date(), value.getCurTime())) { |
||||||
|
// 如果是当天值,判断grade,40:累计值,140:瞬时值
|
||||||
|
if (value.getGrade() == 40) { |
||||||
|
// 累计值
|
||||||
|
sysPerformanceDTO.setYearCold(value.getCurValue()); |
||||||
|
} else if (value.getGrade() == 140) { |
||||||
|
// 瞬时值
|
||||||
|
sysPerformanceDTO.setRealCold(value.getCurValue()); |
||||||
|
} |
||||||
|
} else { |
||||||
|
// 如果不是当天值,判断grade,40:累计值,140:瞬时值
|
||||||
|
BigDecimal bigDecimal = new BigDecimal("0.0"); |
||||||
|
if (value.getGrade() == 40) { |
||||||
|
// 累计值
|
||||||
|
sysPerformanceDTO.setYearCold(bigDecimal); |
||||||
|
} else if (value.getGrade() == 140) { |
||||||
|
// 瞬时值
|
||||||
|
sysPerformanceDTO.setRealCold(bigDecimal); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
// 开始计算瞬时EER和累计EER
|
||||||
|
BigDecimal yearPower = sysPerformanceDTO.getYearPower(); |
||||||
|
BigDecimal yearCold = sysPerformanceDTO.getYearCold(); |
||||||
|
BigDecimal realPower = sysPerformanceDTO.getRealPower(); |
||||||
|
BigDecimal realCold = sysPerformanceDTO.getRealCold(); |
||||||
|
|
||||||
|
// 计算瞬时EER
|
||||||
|
if (realPower != null && realCold != null) { |
||||||
|
if (realPower.compareTo(BigDecimal.ZERO) == 0) { |
||||||
|
sysPerformanceDTO.setRealEER(BigDecimal.ZERO.setScale(1)); // 除数为0时赋值为0.0
|
||||||
|
} else { |
||||||
|
BigDecimal eer = realCold.divide(realPower, 1, RoundingMode.HALF_UP); |
||||||
|
sysPerformanceDTO.setRealEER(eer); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// 计算累计EER
|
||||||
|
if (yearPower != null && yearCold != null) { |
||||||
|
if (yearPower.compareTo(BigDecimal.ZERO) == 0) { |
||||||
|
sysPerformanceDTO.setYearEER(BigDecimal.ZERO.setScale(1)); // 除数为0时赋值为0.0
|
||||||
|
} else { |
||||||
|
BigDecimal yearEer = yearCold.divide(yearPower, 1, RoundingMode.HALF_UP); |
||||||
|
sysPerformanceDTO.setYearEER(yearEer); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return sysPerformanceDTO; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Map<String, String> getWeatherData() { |
||||||
|
Map<String, String> result = new HashMap<>(); |
||||||
|
// 查询跟当前时间yyyy-MM-dd HH相同的数据
|
||||||
|
WeatherData weatherData = weatherDataMapper.selectWeatherDataByDate(DateUtils.getTime()); |
||||||
|
if (weatherData != null) { |
||||||
|
WeatherUtil weatherUtil = new WeatherUtil(); |
||||||
|
// 室外温度
|
||||||
|
int temperature = weatherData.getTemperature(); |
||||||
|
result.putIfAbsent("temperature", temperature + ""); |
||||||
|
|
||||||
|
// 室外湿度
|
||||||
|
int humidity = weatherData.getHumidity(); |
||||||
|
result.putIfAbsent("humidity", humidity + ""); |
||||||
|
|
||||||
|
// 室外压力,采用标准大气压 101325 Pa
|
||||||
|
String pressure = "101.325"; |
||||||
|
// result.putIfAbsent("pressure", new BigDecimal("101.325") + "");
|
||||||
|
|
||||||
|
// 室外含湿
|
||||||
|
BigDecimal humidityRatio = weatherUtil.returnMoistureContent(String.valueOf(temperature), |
||||||
|
String.valueOf(new BigDecimal(humidity).divide(new BigDecimal("100")).setScale(1, RoundingMode.HALF_UP)), |
||||||
|
pressure); |
||||||
|
result.put("humidityRatio", humidityRatio.setScale(1, RoundingMode.HALF_UP).toString()); |
||||||
|
|
||||||
|
// 室外焓值
|
||||||
|
BigDecimal enthalpy = weatherUtil.returnEnthalpy(String.valueOf(temperature), |
||||||
|
String.valueOf(new BigDecimal(humidity).divide(new BigDecimal("100")).setScale(1, RoundingMode.HALF_UP)), |
||||||
|
pressure); |
||||||
|
result.put("enthalpy", enthalpy.setScale(1, RoundingMode.HALF_UP).toString()); |
||||||
|
|
||||||
|
// 室外露点温度
|
||||||
|
BigDecimal dewPointTemp = weatherUtil.calculateDewPoint(temperature, humidity); |
||||||
|
result.put("dewPointTemp", dewPointTemp.setScale(1, RoundingMode.HALF_UP).toString()); |
||||||
|
|
||||||
|
// 室外湿球温度
|
||||||
|
BigDecimal wetBulbTemp = weatherUtil.returnComputePsi(temperature, (double) humidity / 100, Double.parseDouble(pressure) * 1000); |
||||||
|
result.put("wetBulbTemp", wetBulbTemp.setScale(1, RoundingMode.HALF_UP).toString()); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Map<String, String> getRunTime() { |
||||||
|
List<SysParams> sysParams = sysParamsMapper.selectSysParamsList(); |
||||||
|
Map<String, String> result = new HashMap<>(); |
||||||
|
if (!sysParams.isEmpty()) { |
||||||
|
// 获取运行时间
|
||||||
|
Date operateStartTime = sysParams.get(0).getOperateStartTime(); |
||||||
|
// 比较当前时间跟运行时间的相差多少天
|
||||||
|
long days = (new Date().getTime() - operateStartTime.getTime()) / (1000 * 60 * 60 * 24); |
||||||
|
result.put("runTime", days + ""); |
||||||
|
} else { |
||||||
|
result.put("runTime", "0"); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,28 @@ |
|||||||
|
package com.mh.system.service.impl; |
||||||
|
|
||||||
|
import com.mh.common.core.domain.entity.WeatherData; |
||||||
|
import com.mh.system.mapper.WeatherDataMapper; |
||||||
|
import com.mh.system.service.IWeatherDataService; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author LJF |
||||||
|
* @version 1.0 |
||||||
|
* @project EEMCS |
||||||
|
* @description 天气服务实现类 |
||||||
|
* @date 2025-03-30 11:38:15 |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
public class WeatherDataServiceImpl implements IWeatherDataService { |
||||||
|
|
||||||
|
private final WeatherDataMapper weatherDataMapper; |
||||||
|
|
||||||
|
public WeatherDataServiceImpl(WeatherDataMapper weatherDataMapper) { |
||||||
|
this.weatherDataMapper = weatherDataMapper; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int insertWeatherData(WeatherData weatherData) { |
||||||
|
return weatherDataMapper.insert(weatherData); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue