NoteInformController.java
5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package com.sunyo.energy.location.controller;
import com.sunyo.energy.location.model.*;
import com.sunyo.energy.location.service.InformElectricityService;
import com.sunyo.energy.location.service.InformWaterService;
import com.sunyo.energy.location.service.NoteInformService;
import com.sunyo.energy.location.utils.CallWebServiceUtils;
import com.sunyo.energy.location.utils.WaterEleUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import java.util.List;
/**
* @author shenhailong
* <p>
* 2020/7/20/10:32
*/
@Slf4j
@RestController
@RequestMapping(value = "/noteInform")
public class NoteInformController {
@Autowired
InformElectricityService informElectricityService;
@Autowired
NoteInformService noteInformService;
@Autowired
InformWaterService informWaterService;
@Autowired
WaterEleUtils waterEleUtils;
/**
* 电表短信通知接口
*/
@RequestMapping("/note")
@Scheduled(cron = "0 0 10 * * ?")
public void note_ele(){
/**
* 通知电表
*/
try {
List<InformElectricity> informElectricitieList = informElectricityService.selectAll();
// 取出每一个房间信息
for (InformElectricity informElectricity: informElectricitieList){
// 循环查询该设备用电余额
ElectricityMeter energyInfoForRealTime = waterEleUtils.getEnergyInfoForRealTime(informElectricity.getEeId());
// 是否满足通知条件
boolean eleMoney = waterEleUtils.eleMoney(energyInfoForRealTime.getBalance(), "50");
if (eleMoney){
log.info("需要提醒手机号码为:{}", informElectricity.getInformPhone());
int i = CallWebServiceUtils.sendSMSPost(informElectricity.getInformPhone(),
"您所在的宿舍" + informElectricity.getRoomName() + "电费已不足50元,为避免停电造成不便,请及时充值。",
"");
if (i > 0){
// 成功修改为通知状态为否
NoteInform noteInform = new NoteInform();
noteInform.setInformStatus("1");
noteInform.setId(informElectricity.getId());
noteInformService.updateByPrimaryKeySelective(noteInform);
log.info("电表余额短信提醒成功房间号码为:{}", informElectricity.getRoomName());
log.info("电表余额短信提醒成功电话号码为:{}", informElectricity.getInformPhone());
}
}
}
}catch (Exception e){
e.printStackTrace();
}
}
/**
* 短信水表通知接口
*/
@RequestMapping("/note_water")
@Scheduled(cron = "0 0 10 * * ?")
public void note_water(){
try {
List<InformWater> informWaterList = informWaterService.selectAll();
// 取出每一个房间信息
for (InformWater informWater: informWaterList){
// 查询该水表 累计消费量
String realTime = waterEleUtils.findRealTime(informWater.getWmId());
// 查询水表累计充值量
WaterMeterSacc waterMeterSacc = informWaterService.selectByPrimaryKey(informWater.getWmId());
if (!StringUtils.isEmpty(realTime) && waterMeterSacc != null){
// 计算现有量
String margin = waterEleUtils.nubmerSubtraction(String.valueOf(waterMeterSacc.getWmSacc()), realTime);
boolean eleMoney = waterEleUtils.eleMoney(new BigDecimal(margin), "3");
if (eleMoney){
log.info("需要提醒手机号码为:{}", informWater.getInformPhone());
int i = CallWebServiceUtils.sendSMSPost(informWater.getInformPhone(),
"您所在的宿舍" + informWater.getRoomName() + "水量已不足3吨,为避免停水造成不便,请及时充值。",
"");
if (i > 0){
// 成功修改为通知状态为否
NoteInform noteInform = new NoteInform();
noteInform.setInformStatus("1");
noteInform.setId(informWater.getId());
noteInformService.updateByPrimaryKeySelective(noteInform);
log.info("水表余额短信提醒成功房间号码为:{}", informWater.getRoomName());
log.info("水表余额短信提醒成功电话号码为:{}", informWater.getInformPhone());
}
}
}
}
}catch (Exception e){
e.printStackTrace();
}
}
}