|
|
|
@ -1,13 +1,9 @@ |
|
|
|
|
package com.psdc.service.impl; |
|
|
|
|
|
|
|
|
|
import com.psdc.entity.PsdcScene; |
|
|
|
|
import com.psdc.entity.PsdcStrategy; |
|
|
|
|
import com.psdc.entity.PsdcStrategyLog; |
|
|
|
|
import com.psdc.entity.*; |
|
|
|
|
import com.psdc.entity.res.PsdcThermometerDataRes; |
|
|
|
|
import com.psdc.entity.vo.SceneVo; |
|
|
|
|
import com.psdc.mapper.PsdcElectricHtdataMapper; |
|
|
|
|
import com.psdc.mapper.PsdcSceneMapper; |
|
|
|
|
import com.psdc.mapper.PsdcStrategyLogMapper; |
|
|
|
|
import com.psdc.mapper.PsdcStrategyMapper; |
|
|
|
|
import com.psdc.mapper.*; |
|
|
|
|
import com.psdc.service.IPsdcStrategyLogService; |
|
|
|
|
import com.psdc.utils.SecurityUtils; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
@ -16,7 +12,7 @@ import javax.annotation.Resource; |
|
|
|
|
import java.text.DecimalFormat; |
|
|
|
|
import java.text.ParseException; |
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @Author:戴仕崑 |
|
|
|
@ -37,6 +33,12 @@ public class PsdcStrategyLogService implements IPsdcStrategyLogService { |
|
|
|
|
PsdcSceneMapper sceneMapper; |
|
|
|
|
@Resource |
|
|
|
|
PsdcElectricHtdataMapper electricHtDataMapper; |
|
|
|
|
@Resource |
|
|
|
|
PsdcThermometerHtdataMapper thermometerHtDataMapper; |
|
|
|
|
@Resource |
|
|
|
|
PsdcThermometerRtdataMapper thermometerRtDataMapper; |
|
|
|
|
@Resource |
|
|
|
|
PsdcDeviceMapper deviceMapper; |
|
|
|
|
|
|
|
|
|
DecimalFormat df = new DecimalFormat("#.00"); |
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
@ -65,8 +67,6 @@ public class PsdcStrategyLogService implements IPsdcStrategyLogService { |
|
|
|
|
Integer deviceId = sv.getDeviceId(); |
|
|
|
|
Double energy = electricHtDataMapper.selTodayUseEnergy(deviceId, psl.getStartTime(), psl.getEndTime()); |
|
|
|
|
strategyUseEnergy = strategyUseEnergy + energy; |
|
|
|
|
// System.out.println("\n策略名称: " + psl.getStrategyName() + ",步骤名称: " + sv.getSceneName()
|
|
|
|
|
// + ",设备名称: " + sv.getDeviceName() + ",当前用能: " + energy + ",目前累计用能: " + strategyUseEnergy + "。\n");
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -91,10 +91,57 @@ public class PsdcStrategyLogService implements IPsdcStrategyLogService { |
|
|
|
|
|
|
|
|
|
psl.setOneUseEnergy(s); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Date date ; |
|
|
|
|
try { |
|
|
|
|
date = sdf.parse(psl.getStartTime()); |
|
|
|
|
} catch (ParseException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
date = new Date(); |
|
|
|
|
} |
|
|
|
|
long twoHour = date.getTime() - 7200000; |
|
|
|
|
date.setTime(twoHour); |
|
|
|
|
String tb = sdf.format(date); |
|
|
|
|
long tomorrow = twoHour + 86400000; |
|
|
|
|
date.setTime(tomorrow); |
|
|
|
|
String te = sdf.format(date); |
|
|
|
|
System.out.println("策略名称: " + psl.getStrategyName() + ",开始=" + tb + ",结束=" + te + "。\n"); |
|
|
|
|
Integer countIn = deviceMapper.selDevCounts(userId, "温度传感器", "室内"); |
|
|
|
|
List<Double> listTempIn = new ArrayList(); // 今天室内历史温度集合
|
|
|
|
|
List<String> timesIn = new ArrayList(); // 今天室内历史温度时间轴
|
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
|
List<PsdcThermometerHtdata> tempInList = thermometerHtDataMapper.selTodayThermometer2("室内", tb, te); |
|
|
|
|
getaDouble(countIn, listTempIn, timesIn, tempInList); |
|
|
|
|
map.put("listTempIn", listTempIn); |
|
|
|
|
map.put("timesIn", timesIn); |
|
|
|
|
psl.setTempInAry(map); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
return logList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void getaDouble(int count, List<Double> listTemp, List<String> times, List<PsdcThermometerHtdata> tempList) { |
|
|
|
|
if (tempList.size() == 0) { |
|
|
|
|
count = 1; |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
long time1 = 0; |
|
|
|
|
for (int i = 0; i < tempList.size(); i++) { |
|
|
|
|
PsdcThermometerHtdata scr1 = tempList.get(i); |
|
|
|
|
long time2 = sdf.parse(scr1.getUpdateTime()).getTime(); |
|
|
|
|
long time3 = time2 - time1; |
|
|
|
|
if(time3 >= 900000){ |
|
|
|
|
Double evIn = scr1.getThermometerValue() / count; |
|
|
|
|
listTemp.add(Double.parseDouble(df.format(evIn))); |
|
|
|
|
times.add(scr1.getUpdateTime().split(" ")[1].substring(0,5)); |
|
|
|
|
time1 = sdf.parse(scr1.getUpdateTime()).getTime(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (Exception e){ |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public PsdcStrategyLog selMyNewLog(Long code) { |
|
|
|
|
return strategyLogMapper.selMyNewLog(SecurityUtils.getUserId(), code); |
|
|
|
|