|
|
|
@ -12,6 +12,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.math.RoundingMode; |
|
|
|
|
import java.time.DayOfWeek; |
|
|
|
|
import java.time.LocalDate; |
|
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
|
import java.time.temporal.TemporalAdjusters; |
|
|
|
|
import java.util.Calendar; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
@ -54,34 +60,96 @@ public class PushDataToWechatJob {
|
|
|
|
|
} else { |
|
|
|
|
log.info("有数据"); |
|
|
|
|
// 开始推送数据
|
|
|
|
|
PushMsgEntity pushMsgEntity = new PushMsgEntity(); |
|
|
|
|
List<Map<String, Object>> wechatUserList = wechatService.queryWechatUser(String.valueOf(projectInfoEntity.getId())); |
|
|
|
|
for (Map<String, Object> map : wechatUserList) { |
|
|
|
|
pushMsgEntity.setTouser(map.get("open_id").toString()); |
|
|
|
|
pushMsgEntity.setTemplateId(map.get("template_id").toString()); |
|
|
|
|
pushMsgEntity.setUrl("http://jnd2.mhwsh.net:8765/"); |
|
|
|
|
First first = new First(); |
|
|
|
|
first.setValue("设备用量采集结果通知"); |
|
|
|
|
pushMsgEntity.setFirst(first); |
|
|
|
|
Key1 key1 = new Key1(); |
|
|
|
|
key1.setValue(projectInfoEntity.getProjectName()); |
|
|
|
|
pushMsgEntity.setKey1(key1); |
|
|
|
|
Key2 key2 = new Key2(); |
|
|
|
|
key2.setValue(String.valueOf(energyDataEntity.getElect()) + " kwh"); |
|
|
|
|
pushMsgEntity.setKey2(key2); |
|
|
|
|
Key3 key3 = new Key3(); |
|
|
|
|
key3.setValue(String.valueOf(energyDataEntity.getCl()) + " kwr"); |
|
|
|
|
pushMsgEntity.setKey3(key3); |
|
|
|
|
Key4 key4 = new Key4(); |
|
|
|
|
key4.setValue(String.valueOf(energyDataEntity.getCop()) + " kwr/kwh"); |
|
|
|
|
pushMsgEntity.setKey4(key4); |
|
|
|
|
Key5 key5 = new Key5(); |
|
|
|
|
key5.setValue(String.valueOf(energyDataEntity.getCurDate())); |
|
|
|
|
pushMsgEntity.setKey5(key5); |
|
|
|
|
PushMsgEntity pushMsgEntity = new PushMsgEntity(); |
|
|
|
|
// 判断模板id种类
|
|
|
|
|
switch (map.get("template_id").toString()) { |
|
|
|
|
case "qG3Odr74o4BRx8QigZuoiguLNSkw7QJ0zQI3LaHtMY8": |
|
|
|
|
// 推送单种设备消息
|
|
|
|
|
pushClParams(projectInfoEntity, map, pushMsgEntity, energyDataEntity, curDate); |
|
|
|
|
break; |
|
|
|
|
case "qG3Odr74o4BRx8QigZuoil3l3ZC2aAdDeO49robRLC8": |
|
|
|
|
// 推送用电量、用冷量、EER数据
|
|
|
|
|
pushAllParams(projectInfoEntity, map, pushMsgEntity, energyDataEntity); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
wechatService.PushMsg(pushMsgEntity); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void pushClParams(ProjectInfoEntity projectInfoEntity, Map<String, Object> map, PushMsgEntity pushMsgEntity, EnergyDataEntity energyDataEntity, String curDate) { |
|
|
|
|
pushMsgEntity.setTouser(map.get("open_id").toString()); |
|
|
|
|
pushMsgEntity.setTemplateId(map.get("template_id").toString()); |
|
|
|
|
pushMsgEntity.setUrl("http://jnd2.mhwsh.net:8765/"); |
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
|
|
|
|
LocalDate today = LocalDate.parse(curDate, formatter); |
|
|
|
|
First first = new First(); |
|
|
|
|
first.setValue("设备用量采集结果通知"); |
|
|
|
|
pushMsgEntity.setFirst(first); |
|
|
|
|
Key1 key1 = new Key1(); |
|
|
|
|
key1.setValue(projectInfoEntity.getProjectName()); |
|
|
|
|
pushMsgEntity.setKey1(key1); |
|
|
|
|
Key2 key2 = new Key2(); |
|
|
|
|
// 昨日用量
|
|
|
|
|
key2.setValue(String.valueOf(energyDataEntity.getCl()) + " kwh"); |
|
|
|
|
pushMsgEntity.setKey2(key2); |
|
|
|
|
Key3 key3 = new Key3(); |
|
|
|
|
// 本周用量
|
|
|
|
|
// 获取本周的开始日期(周一)
|
|
|
|
|
LocalDate startOfWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)); |
|
|
|
|
// 获取本周的结束日期(周日)
|
|
|
|
|
LocalDate endOfWeek = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY)); |
|
|
|
|
List<EnergyDataEntity> energyDataEntities = energyDataService.queryEnergyDataByDateRange(String.valueOf(startOfWeek), String.valueOf(endOfWeek), String.valueOf(projectInfoEntity.getId())); |
|
|
|
|
// 求和
|
|
|
|
|
double sum = energyDataEntities.stream().mapToDouble(EnergyDataEntity::getCl).sum(); |
|
|
|
|
key3.setValue(new BigDecimal(sum).setScale(2, RoundingMode.HALF_UP) + " kwh"); |
|
|
|
|
pushMsgEntity.setKey3(key3); |
|
|
|
|
|
|
|
|
|
Key4 key4 = new Key4(); |
|
|
|
|
// 本月用量
|
|
|
|
|
// 获取当月的开始日期(1号)
|
|
|
|
|
LocalDate startOfMonth = today.with(TemporalAdjusters.firstDayOfMonth()); |
|
|
|
|
// 获取当月的结束日期(该月的最后一天)
|
|
|
|
|
LocalDate endOfMonth = today.with(TemporalAdjusters.lastDayOfMonth()); |
|
|
|
|
List<EnergyDataEntity> monDatas = energyDataService.queryEnergyDataByDateRange(String.valueOf(startOfMonth), String.valueOf(endOfMonth), String.valueOf(projectInfoEntity.getId())); |
|
|
|
|
// 求和
|
|
|
|
|
double monthSum = monDatas.stream().mapToDouble(EnergyDataEntity::getCl).sum(); |
|
|
|
|
key4.setValue(new BigDecimal(monthSum).setScale(2, RoundingMode.HALF_UP) + " kwh"); |
|
|
|
|
pushMsgEntity.setKey4(key4); |
|
|
|
|
|
|
|
|
|
Key5 key5 = new Key5(); |
|
|
|
|
key5.setValue(String.valueOf(energyDataEntity.getCurDate())); |
|
|
|
|
pushMsgEntity.setKey5(key5); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void pushAllParams(ProjectInfoEntity projectInfoEntity, Map<String, Object> map, PushMsgEntity pushMsgEntity, EnergyDataEntity energyDataEntity) { |
|
|
|
|
pushMsgEntity.setTouser(map.get("open_id").toString()); |
|
|
|
|
pushMsgEntity.setTemplateId(map.get("template_id").toString()); |
|
|
|
|
pushMsgEntity.setUrl("http://jnd2.mhwsh.net:8765/"); |
|
|
|
|
First first = new First(); |
|
|
|
|
first.setValue("设备用量采集结果通知"); |
|
|
|
|
pushMsgEntity.setFirst(first); |
|
|
|
|
Key1 key1 = new Key1(); |
|
|
|
|
key1.setValue(projectInfoEntity.getProjectName()); |
|
|
|
|
pushMsgEntity.setKey1(key1); |
|
|
|
|
Key2 key2 = new Key2(); |
|
|
|
|
key2.setValue(String.valueOf(energyDataEntity.getElect()) + " kwh"); |
|
|
|
|
pushMsgEntity.setKey2(key2); |
|
|
|
|
Key3 key3 = new Key3(); |
|
|
|
|
key3.setValue(String.valueOf(energyDataEntity.getCl()) + " kwr"); |
|
|
|
|
pushMsgEntity.setKey3(key3); |
|
|
|
|
Key4 key4 = new Key4(); |
|
|
|
|
key4.setValue(String.valueOf(energyDataEntity.getCop()) + " kwr/kwh"); |
|
|
|
|
pushMsgEntity.setKey4(key4); |
|
|
|
|
Key5 key5 = new Key5(); |
|
|
|
|
key5.setValue(String.valueOf(energyDataEntity.getCurDate())); |
|
|
|
|
pushMsgEntity.setKey5(key5); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|