|  |  | package com.sunyo.energy.location.controller; | 
|  |  |  | 
|  |  |  | 
|  |  | import com.sunyo.energy.location.model.ElectricityMeter; | 
|  |  | import com.sunyo.energy.location.model.InformElectricity; | 
|  |  | import com.sunyo.energy.location.model.NoteInform; | 
|  |  | 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; | 
|  |  |  | 
|  |  | /** | 
| ... | ... | @@ -32,27 +33,33 @@ public class NoteInformController { | 
|  |  | @Autowired | 
|  |  | NoteInformService noteInformService; | 
|  |  |  | 
|  |  | @Autowired | 
|  |  | InformWaterService informWaterService; | 
|  |  |  | 
|  |  | @Autowired | 
|  |  | WaterEleUtils waterEleUtils; | 
|  |  |  | 
|  |  | /** | 
|  |  | * 短信通知接口 | 
|  |  | * 电表短信通知接口 | 
|  |  | */ | 
|  |  | @RequestMapping("/note") | 
|  |  | @Scheduled | 
|  |  | public void note(){ | 
|  |  | @Scheduled(cron = "0 0 10 * * ?") | 
|  |  | public void note_ele(){ | 
|  |  | /** | 
|  |  | *  通知电表 | 
|  |  | */ | 
|  |  | try { | 
|  |  | List<InformElectricity> informElectricitieList = informElectricityService.selectAll(); | 
|  |  | WaterEleUtils waterEleUtils = new WaterEleUtils(); | 
|  |  | // 取出每一个房间信息 | 
|  |  | for (InformElectricity informElectricity: informElectricitieList){ | 
|  |  | // 循环查询该设备用电余额 | 
|  |  | ElectricityMeter energyInfoForRealTime = waterEleUtils.getEnergyInfoForRealTime(informElectricity.getEeId()); | 
|  |  | // 是否满足通知条件 | 
|  |  | boolean eleMoney = waterEleUtils.eleMoney(energyInfoForRealTime.getBalance()); | 
|  |  | boolean eleMoney = waterEleUtils.eleMoney(energyInfoForRealTime.getBalance(), "50"); | 
|  |  | if (eleMoney){ | 
|  |  | log.info("需要提醒手机号码为:{}", informElectricity.getInformPhone()); | 
|  |  | int i = CallWebServiceUtils.sendSMSPost(informElectricity.getInformPhone(), | 
|  |  | "您所在的宿舍" + informElectricity.getRoomName() + "电费已不足50元,为避免停电造成不变,请及时充值", | 
|  |  | "您所在的宿舍" + informElectricity.getRoomName() + "电费已不足50元,为避免停电造成不便,请及时充值。", | 
|  |  | ""); | 
|  |  | if (i > 0){ | 
|  |  | // 成功修改为通知状态为否 | 
| ... | ... | @@ -61,6 +68,48 @@ public class NoteInformController { | 
|  |  | 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()); | 
|  |  | } | 
|  |  | } | 
|  |  | } | 
|  |  | } | 
... | ... |  |