正在显示
8 个修改的文件
包含
228 行增加
和
10 行删除
| 1 | +package com.sunyo.energy.location.dao; | ||
| 2 | + | ||
| 3 | +import com.sunyo.energy.location.model.ElectrifyInfo; | ||
| 4 | + | ||
| 5 | +import java.util.List; | ||
| 6 | + | ||
| 7 | +public interface ElectrifyInfoMapper { | ||
| 8 | + int deleteByPrimaryKey(Integer id); | ||
| 9 | + | ||
| 10 | + int insert(ElectrifyInfo record); | ||
| 11 | + | ||
| 12 | + int insertSelective(ElectrifyInfo record); | ||
| 13 | + | ||
| 14 | + ElectrifyInfo selectByPrimaryKey(Integer id); | ||
| 15 | + | ||
| 16 | + List<ElectrifyInfo> selectAll(); | ||
| 17 | + | ||
| 18 | + int updateByPrimaryKeySelective(ElectrifyInfo record); | ||
| 19 | + | ||
| 20 | + int updateByPrimaryKey(ElectrifyInfo record); | ||
| 21 | +} |
| 1 | +package com.sunyo.energy.location.model; | ||
| 2 | + | ||
| 3 | +public class ElectrifyInfo { | ||
| 4 | + private Integer id; | ||
| 5 | + | ||
| 6 | + private String deviceid; | ||
| 7 | + | ||
| 8 | + public Integer getId() { | ||
| 9 | + return id; | ||
| 10 | + } | ||
| 11 | + | ||
| 12 | + public void setId(Integer id) { | ||
| 13 | + this.id = id; | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + public String getDeviceid() { | ||
| 17 | + return deviceid; | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + public void setDeviceid(String deviceid) { | ||
| 21 | + this.deviceid = deviceid == null ? null : deviceid.trim(); | ||
| 22 | + } | ||
| 23 | +} |
| 1 | +package com.sunyo.energy.location.model; | ||
| 2 | + | ||
| 3 | +import lombok.Data; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * @author shenhailong | ||
| 7 | + * <p> | ||
| 8 | + * 2020/7/20/09:47 | ||
| 9 | + */ | ||
| 10 | +@Data | ||
| 11 | +public class ProwerResult { | ||
| 12 | + | ||
| 13 | + private String errcode; | ||
| 14 | + | ||
| 15 | + private String errmessage; | ||
| 16 | + | ||
| 17 | + private ProwerResultData data; | ||
| 18 | + | ||
| 19 | +} |
| 1 | +package com.sunyo.energy.location.model; | ||
| 2 | + | ||
| 3 | +import lombok.Data; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * @author shenhailong | ||
| 7 | + * <p> | ||
| 8 | + * 2020/7/20/09:48 | ||
| 9 | + */ | ||
| 10 | +@Data | ||
| 11 | +public class ProwerResultDatas { | ||
| 12 | + | ||
| 13 | + private Integer deviceId; | ||
| 14 | + | ||
| 15 | + private Integer action; | ||
| 16 | + | ||
| 17 | + private Boolean success; | ||
| 18 | + | ||
| 19 | + @Override | ||
| 20 | + public String toString() { | ||
| 21 | + return "ProwerResultDatas{" + | ||
| 22 | + "deviceId=" + deviceId + | ||
| 23 | + ", action=" + action + | ||
| 24 | + ", success=" + success + | ||
| 25 | + '}'; | ||
| 26 | + } | ||
| 27 | +} |
| 1 | package com.sunyo.energy.location.service.imp; | 1 | package com.sunyo.energy.location.service.imp; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
| 4 | +import com.sun.deploy.net.HttpUtils; | ||
| 4 | import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIGlobalBinding; | 5 | import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIGlobalBinding; |
| 5 | import com.sunyo.energy.location.dao.*; | 6 | import com.sunyo.energy.location.dao.*; |
| 6 | import com.sunyo.energy.location.model.*; | 7 | import com.sunyo.energy.location.model.*; |
| @@ -27,6 +28,9 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService { | @@ -27,6 +28,9 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService { | ||
| 27 | @Autowired | 28 | @Autowired |
| 28 | PayRecordsMapper payRecordsMapper; | 29 | PayRecordsMapper payRecordsMapper; |
| 29 | 30 | ||
| 31 | + @Autowired | ||
| 32 | + ElectrifyInfoMapper electrifyInfoMapper; | ||
| 33 | + | ||
| 30 | /** | 34 | /** |
| 31 | * 电表充值接口地址 | 35 | * 电表充值接口地址 |
| 32 | */ | 36 | */ |
| @@ -67,16 +71,11 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService { | @@ -67,16 +71,11 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService { | ||
| 67 | message = rechargeDevicesResultData.getSuccess(); | 71 | message = rechargeDevicesResultData.getSuccess(); |
| 68 | } | 72 | } |
| 69 | if ("0".equals(rechargeDevicesResult.getErrcode()) && message == true) { | 73 | if ("0".equals(rechargeDevicesResult.getErrcode()) && message == true) { |
| 70 | - ElectricityMeter energyInfoForRealTime = getEnergyInfoForRealTime(electricityInfo.getDeviceId()); | ||
| 71 | - if (energyInfoForRealTime.getBalance() != null){ | ||
| 72 | - int i = energyInfoForRealTime.getBalance().compareTo(BigDecimal.ZERO); | ||
| 73 | - if (i > 0){ | ||
| 74 | - Map<String, Object> map = new HashMap<>(); | ||
| 75 | - map.put("deviceId", electricityInfo.getDeviceId()); | ||
| 76 | - map.put("action", "1"); | ||
| 77 | - HttpsUtils.sendPost(remoteControlDevices, map); | ||
| 78 | - } | ||
| 79 | - } | 74 | + // 插入送电临时表 |
| 75 | + ElectrifyInfo electrifyInfo1 = new ElectrifyInfo(); | ||
| 76 | + electrifyInfo1.setDeviceid(electricityInfo.getDeviceId()); | ||
| 77 | + electrifyInfoMapper.insertSelective(electrifyInfo1); | ||
| 78 | + // 修改订单状态 | ||
| 80 | payRecordsMapper.updateStatus(electricityInfo.getOrderNumber()); | 79 | payRecordsMapper.updateStatus(electricityInfo.getOrderNumber()); |
| 81 | // 成功 删除该订单 | 80 | // 成功 删除该订单 |
| 82 | electricityInfoMapper.deleteByPrimaryKey(electricityInfo.getOrderNumber()); | 81 | electricityInfoMapper.deleteByPrimaryKey(electricityInfo.getOrderNumber()); |
| @@ -129,4 +128,50 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService { | @@ -129,4 +128,50 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService { | ||
| 129 | } | 128 | } |
| 130 | 129 | ||
| 131 | 130 | ||
| 131 | + /** | ||
| 132 | + * 定时读取电表临时表 送电 | ||
| 133 | + */ | ||
| 134 | + @Scheduled(fixedDelay = 30000) | ||
| 135 | + public void electrifyInfo() { | ||
| 136 | + try { | ||
| 137 | + List<ElectrifyInfo> electrifyInfoList = electrifyInfoMapper.selectAll(); | ||
| 138 | + for (ElectrifyInfo electrifyInfo: electrifyInfoList ){ | ||
| 139 | + ElectricityMeter energyInfoForRealTime = getEnergyInfoForRealTime(electrifyInfo.getDeviceid()); | ||
| 140 | + if (energyInfoForRealTime.getBalance() != null){ | ||
| 141 | + int i = energyInfoForRealTime.getBalance().compareTo(BigDecimal.ZERO); | ||
| 142 | + log.info("查询该设备余额是否为正数{}", i); | ||
| 143 | + if (i > 0){ | ||
| 144 | + log.info("进入送电接口----------"); | ||
| 145 | + Map<String, Object> map = new HashMap<>(); | ||
| 146 | + map.put("deviceId", electrifyInfo.getDeviceid()); | ||
| 147 | + map.put("action", "1"); | ||
| 148 | + String postResult = HttpsUtils.sendPost(remoteControlDevices, map); | ||
| 149 | + ProwerResult prowerResult = JSON.parseObject(postResult, ProwerResult.class); | ||
| 150 | + List<ProwerResultDatas> datas = prowerResult.getData().getDatas(); | ||
| 151 | + if ("0".equals(prowerResult.getErrcode())){ | ||
| 152 | + log.info("送电成功-------------------"); | ||
| 153 | + log.info("success-info-RechargeDevicesResult"); | ||
| 154 | + System.out.println(datas); | ||
| 155 | + // 成功 删除该订单 | ||
| 156 | + electrifyInfoMapper.deleteByPrimaryKey(electrifyInfo.getId()); | ||
| 157 | + }else { | ||
| 158 | + // 失败插入临时表 | ||
| 159 | + ElectrifyInfo electrifyInfo1 = new ElectrifyInfo(); | ||
| 160 | + electrifyInfo1.setDeviceid(electrifyInfo.getDeviceid()); | ||
| 161 | + electrifyInfoMapper.insertSelective(electrifyInfo1); | ||
| 162 | + log.info("送电失败插入临时表--------------------------------"); | ||
| 163 | + log.info("送电信息插入success---info"); | ||
| 164 | + | ||
| 165 | + } | ||
| 166 | + } | ||
| 167 | + } | ||
| 168 | + log.info("定时任务处理完成"); | ||
| 169 | + } | ||
| 170 | + | ||
| 171 | + }catch (Exception e){ | ||
| 172 | + e.printStackTrace(); | ||
| 173 | + } | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + | ||
| 132 | } | 177 | } |
| @@ -184,6 +184,8 @@ public class HttpsUtils { | @@ -184,6 +184,8 @@ public class HttpsUtils { | ||
| 184 | // 打开URL连接 | 184 | // 打开URL连接 |
| 185 | java.net.HttpURLConnection httpConn = (java.net.HttpURLConnection) connURL | 185 | java.net.HttpURLConnection httpConn = (java.net.HttpURLConnection) connURL |
| 186 | .openConnection(); | 186 | .openConnection(); |
| 187 | + httpConn.setConnectTimeout(50000); | ||
| 188 | + httpConn.setReadTimeout(50000); | ||
| 187 | // 设置通用属性 | 189 | // 设置通用属性 |
| 188 | httpConn.setRequestProperty("Accept", "*/*"); | 190 | httpConn.setRequestProperty("Accept", "*/*"); |
| 189 | httpConn.setRequestProperty("Connection", "Keep-Alive"); | 191 | httpConn.setRequestProperty("Connection", "Keep-Alive"); |
| 1 | +<?xml version="1.0" encoding="UTF-8" ?> | ||
| 2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > | ||
| 3 | +<mapper namespace="com.sunyo.energy.location.dao.ElectrifyInfoMapper" > | ||
| 4 | + <resultMap id="BaseResultMap" type="com.sunyo.energy.location.model.ElectrifyInfo" > | ||
| 5 | + <id column="id" property="id" jdbcType="INTEGER" /> | ||
| 6 | + <result column="deviceId" property="deviceid" jdbcType="VARCHAR" /> | ||
| 7 | + </resultMap> | ||
| 8 | + <sql id="Base_Column_List" > | ||
| 9 | + id, deviceId | ||
| 10 | + </sql> | ||
| 11 | + <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > | ||
| 12 | + select | ||
| 13 | + <include refid="Base_Column_List" /> | ||
| 14 | + from electrify_info | ||
| 15 | + where id = #{id,jdbcType=INTEGER} | ||
| 16 | + </select> | ||
| 17 | + | ||
| 18 | + <select id="selectAll" resultType="com.sunyo.energy.location.model.ElectrifyInfo"> | ||
| 19 | + select | ||
| 20 | + <include refid="Base_Column_List" /> | ||
| 21 | + from electrify_info | ||
| 22 | + </select> | ||
| 23 | + <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" > | ||
| 24 | + delete from electrify_info | ||
| 25 | + where id = #{id,jdbcType=INTEGER} | ||
| 26 | + </delete> | ||
| 27 | + <insert id="insert" parameterType="com.sunyo.energy.location.model.ElectrifyInfo" > | ||
| 28 | + insert into electrify_info (id, deviceId) | ||
| 29 | + values (#{id,jdbcType=INTEGER}, #{deviceid,jdbcType=VARCHAR}) | ||
| 30 | + </insert> | ||
| 31 | + <insert id="insertSelective" parameterType="com.sunyo.energy.location.model.ElectrifyInfo" > | ||
| 32 | + insert into electrify_info | ||
| 33 | + <trim prefix="(" suffix=")" suffixOverrides="," > | ||
| 34 | + <if test="id != null" > | ||
| 35 | + id, | ||
| 36 | + </if> | ||
| 37 | + <if test="deviceid != null" > | ||
| 38 | + deviceId, | ||
| 39 | + </if> | ||
| 40 | + </trim> | ||
| 41 | + <trim prefix="values (" suffix=")" suffixOverrides="," > | ||
| 42 | + <if test="id != null" > | ||
| 43 | + #{id,jdbcType=INTEGER}, | ||
| 44 | + </if> | ||
| 45 | + <if test="deviceid != null" > | ||
| 46 | + #{deviceid,jdbcType=VARCHAR}, | ||
| 47 | + </if> | ||
| 48 | + </trim> | ||
| 49 | + </insert> | ||
| 50 | + <update id="updateByPrimaryKeySelective" parameterType="com.sunyo.energy.location.model.ElectrifyInfo" > | ||
| 51 | + update electrify_info | ||
| 52 | + <set > | ||
| 53 | + <if test="deviceid != null" > | ||
| 54 | + deviceId = #{deviceid,jdbcType=VARCHAR}, | ||
| 55 | + </if> | ||
| 56 | + </set> | ||
| 57 | + where id = #{id,jdbcType=INTEGER} | ||
| 58 | + </update> | ||
| 59 | + <update id="updateByPrimaryKey" parameterType="com.sunyo.energy.location.model.ElectrifyInfo" > | ||
| 60 | + update electrify_info | ||
| 61 | + set deviceId = #{deviceid,jdbcType=VARCHAR} | ||
| 62 | + where id = #{id,jdbcType=INTEGER} | ||
| 63 | + </update> | ||
| 64 | +</mapper> |
-
请 注册 或 登录 后发表评论