作者 shenhailong

短信服务 水表余额通知

... ... @@ -156,4 +156,5 @@ eeUrl:
#获取电表实时数据/余额
# electricityBanlanceUrl: "http://10.5.10.102:8000/api/emcs/getEnergyInfoForRealTime"
electricityBanlanceUrl: "http://192.168.1.199:18080/api/emcs/getEnergyInfoForRealTime"
informMoney: "50"
waterUrl:
getSelectNowwmrdbyMtId: "http://123:56:159:203:8023/nowwmrd/getSelectNowwmrdbyMtId"
... ...
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());
}
}
}
}
... ...
package com.sunyo.energy.location.dao;
import com.sunyo.energy.location.model.InformWater;
import jdk.internal.dynalink.linker.LinkerServices;
import java.util.List;
public interface InformWaterMapper {
int insert(InformWater record);
int insertSelective(InformWater record);
List<InformWater> selectAll();
}
\ No newline at end of file
... ...
package com.sunyo.energy.location.dao;
import com.sunyo.energy.location.model.WaterMeterSacc;
public interface WaterMeterSaccMapper {
int deleteByPrimaryKey(String wmId);
int insert(WaterMeterSacc record);
int insertSelective(WaterMeterSacc record);
WaterMeterSacc selectByPrimaryKey(String wmId);
int updateByPrimaryKeySelective(WaterMeterSacc record);
int updateByPrimaryKey(WaterMeterSacc record);
}
\ No newline at end of file
... ...
package com.sunyo.energy.location.model;
public class InformWater {
private String informMoney;
private String informPhone;
private String roomName;
private String wmId;
private Integer id;
public String getInformMoney() {
return informMoney;
}
public void setInformMoney(String informMoney) {
this.informMoney = informMoney == null ? null : informMoney.trim();
}
public String getInformPhone() {
return informPhone;
}
public void setInformPhone(String informPhone) {
this.informPhone = informPhone == null ? null : informPhone.trim();
}
public String getRoomName() {
return roomName;
}
public void setRoomName(String roomName) {
this.roomName = roomName == null ? null : roomName.trim();
}
public String getWmId() {
return wmId;
}
public void setWmId(String wmId) {
this.wmId = wmId == null ? null : wmId.trim();
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
\ No newline at end of file
... ...
package com.sunyo.energy.location.model;
import java.math.BigDecimal;
public class WaterMeterSacc {
private String wmId;
private String ardname;
private BigDecimal unitPrice;
private BigDecimal wmSacc;
public String getWmId() {
return wmId;
}
public void setWmId(String wmId) {
this.wmId = wmId == null ? null : wmId.trim();
}
public String getArdname() {
return ardname;
}
public void setArdname(String ardname) {
this.ardname = ardname == null ? null : ardname.trim();
}
public BigDecimal getUnitPrice() {
return unitPrice;
}
public void setUnitPrice(BigDecimal unitPrice) {
this.unitPrice = unitPrice;
}
public BigDecimal getWmSacc() {
return wmSacc;
}
public void setWmSacc(BigDecimal wmSacc) {
this.wmSacc = wmSacc;
}
}
\ No newline at end of file
... ...
package com.sunyo.energy.location.service.Imp;
import com.sunyo.energy.location.dao.InformWaterMapper;
import com.sunyo.energy.location.dao.WaterMeterSaccMapper;
import com.sunyo.energy.location.model.InformWater;
import com.sunyo.energy.location.model.WaterMeterSacc;
import com.sunyo.energy.location.service.InformWaterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author shenhailong
* <p>
* 2020/7/24/10:15
*/
@Service
public class InformWaterServiceImp implements InformWaterService {
@Autowired
InformWaterMapper informWaterMapper;
@Autowired
WaterMeterSaccMapper waterMeterSaccMapper;
@Override
public List<InformWater> selectAll() {
return informWaterMapper.selectAll();
}
@Override
public WaterMeterSacc selectByPrimaryKey(String wmId) {
return waterMeterSaccMapper.selectByPrimaryKey(wmId);
}
}
... ...
package com.sunyo.energy.location.service;
import com.sunyo.energy.location.model.InformWater;
import com.sunyo.energy.location.model.WaterMeterSacc;
import java.util.List;
/**
* @author shenhailong
* <p>
* 2020/7/24/10:14
*/
public interface InformWaterService {
List<InformWater> selectAll();
WaterMeterSacc selectByPrimaryKey(String wmId);
}
... ...
... ... @@ -24,8 +24,8 @@ import java.util.Map;
*/
public class CallWebServiceUtils {
private static final String CorpID="HNJC002221";// 接口账号
private static final String Pwd="dxpt2221"; // 接口密码
private static final String CorpID="HNJC010282";// 接口账号
private static final String Pwd="dxpt0282"; // 接口密码
public static void main(String[] args) throws MalformedURLException, UnsupportedEncodingException {
... ... @@ -33,7 +33,7 @@ public class CallWebServiceUtils {
System.out.println(i);
}
/**
/**782540484
* Hppt POST请求发送方法 返回值>0 为 提交成功
*
* @param Mobile
... ...
package com.sunyo.energy.location.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.sunyo.energy.location.model.ElectricityBalanceOne;
import com.sunyo.energy.location.model.ElectricityMeter;
import org.springframework.beans.factory.annotation.Value;
... ... @@ -26,11 +27,9 @@ public class WaterEleUtils {
@Value("${eeUrl.electricityBanlanceUrl}")
private String electricityBanlanceUrl;
/**
* 电表通知余额
*/
@Value("${eeUrl.informMoney}")
private String informMoney;
@Value("${waterUrl.getSelectNowwmrdbyMtId}")
private String getSelectNowwmrdbyMtId;
/**
* 实施获取电表数据
... ... @@ -62,12 +61,49 @@ public class WaterEleUtils {
return datas;
}
public boolean eleMoney(BigDecimal bigDecimal){
if (bigDecimal.compareTo(new BigDecimal(informMoney)) == -1){
public boolean eleMoney(BigDecimal bigDecimal, String money){
if (bigDecimal.compareTo(new BigDecimal(money)) == -1){
return true;
}else {
return false;
}
}
/**
* 实施获取水表信息
*/
public String findRealTime(String wmId) {
try {
Map<String, Object> datas = new HashMap<>();
datas.put("MtId", wmId);
String s = HttpsUtils.httpRequest(getSelectNowwmrdbyMtId, datas);
JSONArray jsonArray = JSON.parseArray(s);
String wmLacc = "";
for (Object jsonObject : jsonArray) {
Map<String, Object> map = (Map) jsonObject;
if (!map.containsKey("state")) {
// 获取累计消费量
wmLacc = map.get("wm_lacc").toString();
}
}
return wmLacc;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
// 数字相减 参数1 减去 参数2
public String nubmerSubtraction(String sacc, String lacc) {
BigDecimal saccBigDecimal = new BigDecimal(sacc);
BigDecimal laccBigDecimal = new BigDecimal(lacc);
String surplus = saccBigDecimal.subtract(laccBigDecimal).toString();
return surplus;
}
}
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.sunyo.energy.location.dao.InformWaterMapper" >
<resultMap id="BaseResultMap" type="com.sunyo.energy.location.model.InformWater" >
<result column="inform_money" property="informMoney" jdbcType="VARCHAR" />
<result column="inform_phone" property="informPhone" jdbcType="VARCHAR" />
<result column="room_name" property="roomName" jdbcType="VARCHAR" />
<result column="wm_id" property="wmId" jdbcType="VARCHAR" />
<result column="id" property="id" jdbcType="INTEGER" />
</resultMap>
<select id="selectAll" resultMap="BaseResultMap">
select * from inform_water
</select>
<insert id="insert" parameterType="com.sunyo.energy.location.model.InformWater" >
insert into inform_water (inform_money, inform_phone, room_name,
wm_id, id)
values (#{informMoney,jdbcType=VARCHAR}, #{informPhone,jdbcType=VARCHAR}, #{roomName,jdbcType=VARCHAR},
#{wmId,jdbcType=VARCHAR}, #{id,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.sunyo.energy.location.model.InformWater" >
insert into inform_water
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="informMoney != null" >
inform_money,
</if>
<if test="informPhone != null" >
inform_phone,
</if>
<if test="roomName != null" >
room_name,
</if>
<if test="wmId != null" >
wm_id,
</if>
<if test="id != null" >
id,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="informMoney != null" >
#{informMoney,jdbcType=VARCHAR},
</if>
<if test="informPhone != null" >
#{informPhone,jdbcType=VARCHAR},
</if>
<if test="roomName != null" >
#{roomName,jdbcType=VARCHAR},
</if>
<if test="wmId != null" >
#{wmId,jdbcType=VARCHAR},
</if>
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
</trim>
</insert>
</mapper>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.sunyo.energy.location.dao.WaterMeterSaccMapper" >
<resultMap id="BaseResultMap" type="com.sunyo.energy.location.model.WaterMeterSacc" >
<id column="wm_id" property="wmId" jdbcType="VARCHAR" />
<result column="ardname" property="ardname" jdbcType="VARCHAR" />
<result column="unit_price" property="unitPrice" jdbcType="DECIMAL" />
<result column="wm_sacc" property="wmSacc" jdbcType="DECIMAL" />
</resultMap>
<sql id="Base_Column_List" >
wm_id, ardname, unit_price, wm_sacc
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
<include refid="Base_Column_List" />
from water_meter_sacc
where wm_id = #{wmId,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
delete from water_meter_sacc
where wm_id = #{wmId,jdbcType=VARCHAR}
</delete>
<insert id="insert" parameterType="com.sunyo.energy.location.model.WaterMeterSacc" >
insert into water_meter_sacc (wm_id, ardname, unit_price,
wm_sacc)
values (#{wmId,jdbcType=VARCHAR}, #{ardname,jdbcType=VARCHAR}, #{unitPrice,jdbcType=DECIMAL},
#{wmSacc,jdbcType=DECIMAL})
</insert>
<insert id="insertSelective" parameterType="com.sunyo.energy.location.model.WaterMeterSacc" >
insert into water_meter_sacc
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="wmId != null" >
wm_id,
</if>
<if test="ardname != null" >
ardname,
</if>
<if test="unitPrice != null" >
unit_price,
</if>
<if test="wmSacc != null" >
wm_sacc,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="wmId != null" >
#{wmId,jdbcType=VARCHAR},
</if>
<if test="ardname != null" >
#{ardname,jdbcType=VARCHAR},
</if>
<if test="unitPrice != null" >
#{unitPrice,jdbcType=DECIMAL},
</if>
<if test="wmSacc != null" >
#{wmSacc,jdbcType=DECIMAL},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.sunyo.energy.location.model.WaterMeterSacc" >
update water_meter_sacc
<set >
<if test="ardname != null" >
ardname = #{ardname,jdbcType=VARCHAR},
</if>
<if test="unitPrice != null" >
unit_price = #{unitPrice,jdbcType=DECIMAL},
</if>
<if test="wmSacc != null" >
wm_sacc = #{wmSacc,jdbcType=DECIMAL},
</if>
</set>
where wm_id = #{wmId,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="com.sunyo.energy.location.model.WaterMeterSacc" >
update water_meter_sacc
set ardname = #{ardname,jdbcType=VARCHAR},
unit_price = #{unitPrice,jdbcType=DECIMAL},
wm_sacc = #{wmSacc,jdbcType=DECIMAL}
where wm_id = #{wmId,jdbcType=VARCHAR}
</update>
</mapper>
\ No newline at end of file
... ...