作者 shenhailong

添加电表短信通知后缴费成功 改回未通知

... ... @@ -41,4 +41,6 @@ public interface LocationMapper {
int editEeId(@Param(value = "name") String name,
@Param(value = "deviceId") String deviceId);
String findRoomName(@Param(value = "eeId") String eeId);
}
\ No newline at end of file
... ...
package com.sunyo.energy.location.dao;
import com.sunyo.energy.location.model.NoteForm;
import org.apache.ibatis.annotations.Param;
public interface NoteFormMapper {
int deleteByPrimaryKey(Integer id);
int insert(NoteForm record);
int insertSelective(NoteForm record);
int count(@Param("roomName") String roomName);
NoteForm selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(NoteForm record);
int updateByPrimaryKey(NoteForm record);
}
\ No newline at end of file
... ...
package com.sunyo.energy.location.model;
import java.util.Date;
public class NoteForm {
private Integer id;
private String roomName;
private String waterEleType;
private String informMoney;
private String informStatus;
private String informPhone;
private Date informDate;
private String status;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getRoomName() {
return roomName;
}
public void setRoomName(String roomName) {
this.roomName = roomName == null ? null : roomName.trim();
}
public String getWaterEleType() {
return waterEleType;
}
public void setWaterEleType(String waterEleType) {
this.waterEleType = waterEleType == null ? null : waterEleType.trim();
}
public String getInformMoney() {
return informMoney;
}
public void setInformMoney(String informMoney) {
this.informMoney = informMoney == null ? null : informMoney.trim();
}
public String getInformStatus() {
return informStatus;
}
public void setInformStatus(String informStatus) {
this.informStatus = informStatus == null ? null : informStatus.trim();
}
public String getInformPhone() {
return informPhone;
}
public void setInformPhone(String informPhone) {
this.informPhone = informPhone == null ? null : informPhone.trim();
}
public Date getInformDate() {
return informDate;
}
public void setInformDate(Date informDate) {
this.informDate = informDate;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status == null ? null : status.trim();
}
}
\ No newline at end of file
... ...
... ... @@ -8,18 +8,7 @@ import java.io.UnsupportedEncodingException;
public interface WaterMeterService {
int realTime();
WaterMeter findRealTime(String wmId);
ResultJson payWater(String payFees, String wmId);
ResultJson waterMeterAll(String wmId);
/**
* 请求返回二维码
*/
ResultJson qrCode(String payFees, String wmId, String userId, String realName, String eeId) throws UnsupportedEncodingException;
}
... ...
... ... @@ -37,6 +37,9 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService {
@Autowired
ElectrifyInfoMapper electrifyInfoMapper;
@Autowired
NoteFormMapper noteFormMapper;
/**
* 获取电表实时数据/余额
... ... @@ -119,6 +122,20 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService {
electrifyInfo1.setDeviceid(deviceId);
electrifyInfoMapper.insertSelective(electrifyInfo1);
log.info("送电信息插入临时表-----------------------------------");
/**
* 修改短信通知状态
*/
ElectricityMeter energyInfoForRealTime = getEnergyInfoForRealTime(deviceId);
if (energyInfoForRealTime.getBalance().compareTo(new BigDecimal(50)) == 1){
String roomName = locationMapper.findRoomName(deviceId);
if (noteFormMapper.count(roomName) > 0){
NoteForm noteForm = new NoteForm();
noteForm.setInformStatus("1");
noteForm.setWaterEleType("2");
noteForm.setRoomName(roomName);
noteFormMapper.updateByPrimaryKeySelective(noteForm);
}
}
return 1;
} else {
log.info("电表充值失败,充值额度:{}", money);
... ...
package com.sunyo.energy.location.service.imp;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.sunyo.energy.location.controller.response.ResultJson;
import com.sunyo.energy.location.dao.LocationMapper;
import com.sunyo.energy.location.dao.PayRecordsMapper;
import com.sunyo.energy.location.dao.WaterMeterMapper;
import com.sunyo.energy.location.dao.WaterMeterSaccMapper;
import com.sunyo.energy.location.demopay.QrDemo;
import com.sunyo.energy.location.model.PayRecords;
import com.sunyo.energy.location.model.WaterMeter;
import com.sunyo.energy.location.model.WaterMeterSacc;
import com.sunyo.energy.location.service.WaterMeterService;
import com.sunyo.energy.location.utils.AllUtils;
import com.sunyo.energy.location.utils.HttpsUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Service
... ... @@ -51,76 +41,6 @@ public class WaterMeterServiceImp implements WaterMeterService {
private static final String addUrl = "http://123.56.159.203:8023/nowwmrd/getSelectNowwmrdbyProjectID";
@Override
@Scheduled(cron = "0 0 03 * * ?")
public int realTime() {
try {
Map<String, Object> datas = new HashMap<>();
datas.put("ProjectID", "33-99-00-00-00-00-01");
// 远程调用
String s = HttpsUtils.httpRequest(addUrl, datas);
JSONArray jsonArray = JSON.parseArray(s);
for (Object jsonObject : jsonArray) {
WaterMeter waterMeter = new WaterMeter();
Map<String, Object> map = (Map) jsonObject;
if (!map.containsKey("state")) {
waterMeter.setWmId(map.get("wm_id").toString());
waterMeter.setWmErrmessage(map.get("wm_errmessage").toString());
waterMeter.setWmFmstate(map.get("wm_fmstate").toString());
waterMeter.setWmSacc(map.get("wm_sacc").toString());
waterMeter.setWmLacc(map.get("wm_lacc").toString());
waterMeter.setWmRdtime(map.get("wm_rdtime").toString());
waterMeter.setWmSignalpower(map.get("wm_signalpower").toString());
waterMeter.setWmVoltage(map.get("wm_voltage").toString());
waterMeter.setCreattime(new Date());
waterMeter.setReamke1(map.get("wm_sacc").toString());
waterMeterMapper.insertSelective(waterMeter);
} else {
if ("0".equals(map.get("state").toString())) {
return 1;
}
return 0;
}
}
return 1;
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
@Override
public WaterMeter findRealTime(String wmId) {
try {
Map<String, Object> datas = new HashMap<>();
datas.put("MtId", wmId);
String s = HttpsUtils.httpRequest(selectUrl, datas);
JSONArray jsonArray = JSON.parseArray(s);
WaterMeter waterMeter = new WaterMeter();
for (Object jsonObject : jsonArray) {
Map<String, Object> map = (Map) jsonObject;
if (!map.containsKey("state")) {
waterMeter.setWmId(map.get("wm_id").toString());
waterMeter.setWmErrmessage(map.get("wm_errmessage").toString());
waterMeter.setWmFmstate(map.get("wm_fmstate").toString());
waterMeter.setWmSacc(map.get("wm_sacc").toString());
waterMeter.setWmLacc(map.get("wm_lacc").toString());
waterMeter.setWmRdtime(map.get("wm_rdtime").toString());
waterMeter.setWmSignalpower(map.get("wm_signalpower").toString());
waterMeter.setWmVoltage(map.get("wm_voltage").toString());
}
}
return waterMeter;
} catch (Exception e) {
e.printStackTrace();
return new WaterMeter();
}
}
/**
* 水费充值 换算总水量 生成订单
*
... ... @@ -163,66 +83,6 @@ public class WaterMeterServiceImp implements WaterMeterService {
}
}
@Override
public ResultJson waterMeterAll(String wmId) {
ResultJson<Object> resultJson = new ResultJson<>();
try {
List<WaterMeter> waterMeterList = waterMeterMapper.waterMeterAll(wmId);
return new ResultJson("200", "success", waterMeterList);
} catch (Exception e) {
e.printStackTrace();
resultJson.setCode("203");
return resultJson;
}
}
// 请求返回二维码
@Override
public ResultJson qrCode(String payFees, String wmId, String userId, String realName, String eeId) throws UnsupportedEncodingException {
ResultJson<Object> resultJson = new ResultJson<>();
// 成功生成水费订单
if (!"".equals(wmId)) {
PayRecords payRecords = payRecords(payFees, wmId, userId, realName, "");
// 请求返回二维码lujing
String url = QrDemo.orUrl(payRecords.getOrdernumber(), payFees);
if (!"".equals(url)) {
payRecords.setReamke2(url);
// 返回map 包含订单号 二维码url
Map<String, Object> map = new HashMap<>();
map.put("url", url);
map.put("orderNumber", payRecords.getOrdernumber());
resultJson.setData(map);
}
int i = payRecordsMapper.insertSelective(payRecords);
if (i > 0) {
resultJson.setCode("200");
}
} else {
PayRecords payRecords = payRecords(payFees, "", userId, realName, eeId);
// 请求返回二维码lujing
String url = QrDemo.orUrl(payRecords.getOrdernumber(), payFees);
if (!"".equals(url)) {
payRecords.setReamke2(url);
// 返回map 包含订单号 二维码url
Map<String, Object> map = new HashMap<>();
map.put("url", url);
map.put("orderNumber", payRecords.getOrdernumber());
resultJson.setData(map);
}
int i = payRecordsMapper.insertSelective(payRecords);
if (i > 0) {
resultJson.setCode("200");
}
}
return resultJson;
}
/**
* 总水量 换算
*
... ... @@ -250,40 +110,4 @@ public class WaterMeterServiceImp implements WaterMeterService {
return datas;
}
/**
* 订单生成
*
* @param payFees
* @param wmId
* @param userId
* @param realName
* @return
*/
public PayRecords payRecords(String payFees, String wmId, String userId, String realName, String eeId) {
PayRecords payRecords = new PayRecords();
payRecords.setOrdernumber(AllUtils.getOrderIdByTime());
payRecords.setPayfees(new BigDecimal(payFees));
payRecords.setPaystatus(false);
if (!"".equals(wmId)) {
payRecords.setPaytype(false);
payRecords.setPaytypeaddress(wmId);
String roomNumber = locationMapper.selectRoomNumber(wmId);
payRecords.setPaylocationname(roomNumber);
} else {
payRecords.setPaytype(true);
payRecords.setPaytypeaddress(eeId);
String roomNumber = locationMapper.selectRoomNumberElectricity(eeId);
payRecords.setPaylocationname(roomNumber);
}
payRecords.setReamke1("0");
payRecords.setPayuserid(Integer.valueOf(userId));
payRecords.setPaytime(new Date());
payRecords.setPayusername(realName);
return payRecords;
}
}
... ...
... ... @@ -43,18 +43,6 @@ public class AllUtils {
}
// 订单号生成 时间加随机数
public static String getOrderIdByTime() {
// 商户码
String merchantId = "105001453995827";
String result = "";
Random random = new Random();
for (int i = 0; i < 3; i++) {
result += random.nextInt(10);
}
return merchantId + result;
}
/**
* 处理水表编号加 '-' 问题
* @param replace 水表编号
... ...
... ... @@ -30,6 +30,10 @@
<!--</if>-->
</select>
<select id="findRoomName" parameterType="string" resultType="string">
select adrName from location where ee_id=#{eeId, jdbcType=VARCHAR}
</select>
<select id="selectAllAdrName" resultMap="BaseResultMap" parameterType="java.lang.String">
select
*
... ...
<?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.NoteFormMapper" >
<resultMap id="BaseResultMap" type="com.sunyo.energy.location.model.NoteForm" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="room_name" property="roomName" jdbcType="VARCHAR" />
<result column="water_ele_type" property="waterEleType" jdbcType="VARCHAR" />
<result column="inform_money" property="informMoney" jdbcType="VARCHAR" />
<result column="inform_status" property="informStatus" jdbcType="VARCHAR" />
<result column="inform_phone" property="informPhone" jdbcType="VARCHAR" />
<result column="inform_date" property="informDate" jdbcType="TIMESTAMP" />
<result column="status" property="status" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, room_name, water_ele_type, inform_money, inform_status, inform_phone, inform_date,
status
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from note_inform
where id = #{id,jdbcType=INTEGER}
</select>
<select id="count" resultType="int" parameterType="string">
select count(*) from note_form where room_name = #{roomName,jdbcType=VARCHAR }
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from note_inform
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.sunyo.energy.location.model.NoteForm" >
insert into note_inform (id, room_name, water_ele_type,
inform_money, inform_status, inform_phone,
inform_date, status)
values (#{id,jdbcType=INTEGER}, #{roomName,jdbcType=VARCHAR}, #{waterEleType,jdbcType=VARCHAR},
#{informMoney,jdbcType=VARCHAR}, #{informStatus,jdbcType=VARCHAR}, #{informPhone,jdbcType=VARCHAR},
#{informDate,jdbcType=TIMESTAMP}, #{status,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.sunyo.energy.location.model.NoteForm" >
insert into note_inform
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="roomName != null" >
room_name,
</if>
<if test="waterEleType != null" >
water_ele_type,
</if>
<if test="informMoney != null" >
inform_money,
</if>
<if test="informStatus != null" >
inform_status,
</if>
<if test="informPhone != null" >
inform_phone,
</if>
<if test="informDate != null" >
inform_date,
</if>
<if test="status != null" >
status,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="roomName != null" >
#{roomName,jdbcType=VARCHAR},
</if>
<if test="waterEleType != null" >
#{waterEleType,jdbcType=VARCHAR},
</if>
<if test="informMoney != null" >
#{informMoney,jdbcType=VARCHAR},
</if>
<if test="informStatus != null" >
#{informStatus,jdbcType=VARCHAR},
</if>
<if test="informPhone != null" >
#{informPhone,jdbcType=VARCHAR},
</if>
<if test="informDate != null" >
#{informDate,jdbcType=TIMESTAMP},
</if>
<if test="status != null" >
#{status,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.sunyo.energy.location.model.NoteForm" >
update note_inform
<set >
<if test="informStatus != null" >
inform_status = #{informStatus,jdbcType=VARCHAR},
</if>
</set>
where room_name = #{roomName,jdbcType=INTEGER}
and water_ele_type = #{waterEleType,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="com.sunyo.energy.location.model.NoteForm" >
update note_inform
set room_name = #{roomName,jdbcType=VARCHAR},
water_ele_type = #{waterEleType,jdbcType=VARCHAR},
inform_money = #{informMoney,jdbcType=VARCHAR},
inform_status = #{informStatus,jdbcType=VARCHAR},
inform_phone = #{informPhone,jdbcType=VARCHAR},
inform_date = #{informDate,jdbcType=TIMESTAMP},
status = #{status,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...