正在显示
6 个修改的文件
包含
153 行增加
和
6 行删除
| @@ -166,3 +166,5 @@ devops: | @@ -166,3 +166,5 @@ devops: | ||
| 166 | tianbo-tcs-recept: D:\Data\Receive | 166 | tianbo-tcs-recept: D:\Data\Receive |
| 167 | cfps-subscribe-dir: D:\系统部署\imf_Warehouse_reader\xmlFromImf | 167 | cfps-subscribe-dir: D:\系统部署\imf_Warehouse_reader\xmlFromImf |
| 168 | #10079 | 168 | #10079 |
| 169 | +eeid: | ||
| 170 | + ipAddress: 192.168.50.23 |
| @@ -7,13 +7,12 @@ import com.sunyo.energy.location.service.ElectricityMeterService; | @@ -7,13 +7,12 @@ import com.sunyo.energy.location.service.ElectricityMeterService; | ||
| 7 | import com.sunyo.energy.location.service.WaterElectricityParameterService; | 7 | import com.sunyo.energy.location.service.WaterElectricityParameterService; |
| 8 | import io.swagger.annotations.ApiOperation; | 8 | import io.swagger.annotations.ApiOperation; |
| 9 | import org.springframework.beans.factory.annotation.Autowired; | 9 | import org.springframework.beans.factory.annotation.Autowired; |
| 10 | +import org.springframework.beans.factory.annotation.Value; | ||
| 10 | import org.springframework.stereotype.Controller; | 11 | import org.springframework.stereotype.Controller; |
| 11 | import org.springframework.web.bind.annotation.RequestMapping; | 12 | import org.springframework.web.bind.annotation.RequestMapping; |
| 12 | import org.springframework.web.bind.annotation.RequestParam; | 13 | import org.springframework.web.bind.annotation.RequestParam; |
| 13 | import org.springframework.web.bind.annotation.ResponseBody; | 14 | import org.springframework.web.bind.annotation.ResponseBody; |
| 14 | 15 | ||
| 15 | -import java.util.Date; | ||
| 16 | - | ||
| 17 | @RequestMapping("/electricity_meter") | 16 | @RequestMapping("/electricity_meter") |
| 18 | @Controller | 17 | @Controller |
| 19 | public class ElectricityParameterController { | 18 | public class ElectricityParameterController { |
| @@ -27,7 +26,6 @@ public class ElectricityParameterController { | @@ -27,7 +26,6 @@ public class ElectricityParameterController { | ||
| 27 | @Autowired | 26 | @Autowired |
| 28 | ElectricityMeterService electricityMeterService; | 27 | ElectricityMeterService electricityMeterService; |
| 29 | 28 | ||
| 30 | - | ||
| 31 | @ApiOperation(value = "电表参数配置") | 29 | @ApiOperation(value = "电表参数配置") |
| 32 | @RequestMapping("/add") | 30 | @RequestMapping("/add") |
| 33 | @ResponseBody | 31 | @ResponseBody |
| @@ -96,6 +94,7 @@ public class ElectricityParameterController { | @@ -96,6 +94,7 @@ public class ElectricityParameterController { | ||
| 96 | * @param eeId | 94 | * @param eeId |
| 97 | * @return | 95 | * @return |
| 98 | */ | 96 | */ |
| 97 | + @ApiOperation(value = "电表实时信息查询") | ||
| 99 | @RequestMapping(value = "/getEnergyInfoForRealTime") | 98 | @RequestMapping(value = "/getEnergyInfoForRealTime") |
| 100 | @ResponseBody | 99 | @ResponseBody |
| 101 | public ElectricityBalanceThree getEnergyInfoForRealTime(@RequestParam(value = "eeId", required = false) String eeId){ | 100 | public ElectricityBalanceThree getEnergyInfoForRealTime(@RequestParam(value = "eeId", required = false) String eeId){ |
| @@ -109,4 +108,21 @@ public class ElectricityParameterController { | @@ -109,4 +108,21 @@ public class ElectricityParameterController { | ||
| 109 | } | 108 | } |
| 110 | } | 109 | } |
| 111 | 110 | ||
| 111 | + /** | ||
| 112 | + * 电表充值 | ||
| 113 | + * @param eeId | ||
| 114 | + * @return | ||
| 115 | + */ | ||
| 116 | + @ApiOperation(value = "电表充值缴费") | ||
| 117 | + @RequestMapping(value = "/rechargeDevices") | ||
| 118 | + @ResponseBody | ||
| 119 | + public ResultJson rechargeDevices(@RequestParam(value = "eeId", required = false) String eeId, | ||
| 120 | + @RequestParam(value = "money", required = false) String money, | ||
| 121 | + @RequestParam(value = "actionType", required = false) String actionType){ | ||
| 122 | + | ||
| 123 | + int i = electricityMeterService.rechargeDevices(eeId, money, actionType); | ||
| 124 | + | ||
| 125 | + return i > 0 ? new ResultJson("200", "充值成功") : new ResultJson("500", "网络异常"); | ||
| 126 | + } | ||
| 127 | + | ||
| 112 | } | 128 | } |
| @@ -3,6 +3,7 @@ package com.sunyo.energy.location.service; | @@ -3,6 +3,7 @@ package com.sunyo.energy.location.service; | ||
| 3 | import com.sunyo.energy.location.controller.response.ResultJson; | 3 | import com.sunyo.energy.location.controller.response.ResultJson; |
| 4 | import com.sunyo.energy.location.model.ElectricityBalanceThree; | 4 | import com.sunyo.energy.location.model.ElectricityBalanceThree; |
| 5 | 5 | ||
| 6 | +import java.math.BigDecimal; | ||
| 6 | import java.util.Map; | 7 | import java.util.Map; |
| 7 | 8 | ||
| 8 | /** | 9 | /** |
| @@ -19,4 +20,6 @@ public interface ElectricityMeterService { | @@ -19,4 +20,6 @@ public interface ElectricityMeterService { | ||
| 19 | */ | 20 | */ |
| 20 | ElectricityBalanceThree getEnergyInfoForRealTime(String deviceId) throws Exception; | 21 | ElectricityBalanceThree getEnergyInfoForRealTime(String deviceId) throws Exception; |
| 21 | 22 | ||
| 23 | + int rechargeDevices(String deviceId, String money, String actionType); | ||
| 24 | + | ||
| 22 | } | 25 | } |
| @@ -6,9 +6,14 @@ import com.sunyo.energy.location.controller.response.ResultJson; | @@ -6,9 +6,14 @@ import com.sunyo.energy.location.controller.response.ResultJson; | ||
| 6 | import com.sunyo.energy.location.model.*; | 6 | import com.sunyo.energy.location.model.*; |
| 7 | import com.sunyo.energy.location.service.ElectricityMeterService; | 7 | import com.sunyo.energy.location.service.ElectricityMeterService; |
| 8 | import com.sunyo.energy.location.utils.HttpsUtils; | 8 | import com.sunyo.energy.location.utils.HttpsUtils; |
| 9 | +import com.sunyo.energy.location.utils.Md5Utils; | ||
| 10 | +import org.springframework.beans.factory.annotation.Value; | ||
| 9 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
| 12 | +import sun.security.provider.MD5; | ||
| 10 | 13 | ||
| 11 | import java.awt.*; | 14 | import java.awt.*; |
| 15 | +import java.math.BigDecimal; | ||
| 16 | +import java.math.RoundingMode; | ||
| 12 | import java.util.HashMap; | 17 | import java.util.HashMap; |
| 13 | import java.util.List; | 18 | import java.util.List; |
| 14 | import java.util.Map; | 19 | import java.util.Map; |
| @@ -27,7 +32,17 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService { | @@ -27,7 +32,17 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService { | ||
| 27 | /** | 32 | /** |
| 28 | * 获取电表实时数据/余额 | 33 | * 获取电表实时数据/余额 |
| 29 | */ | 34 | */ |
| 30 | - private final static String electricityBanlance = "http://192.168.1.2:18080/api/emcs/getEnergyInfoForRealTime"; | 35 | + private final static String electricityBanlanceUrl = "http://192.168.1.2:18080/api/emcs/getEnergyInfoForRealTime"; |
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 电表充值接口读取配置文件ip地址 | ||
| 39 | + */ | ||
| 40 | + @Value("${eeid.ipAddress}") | ||
| 41 | + private String ipAddress; | ||
| 42 | + /** | ||
| 43 | + * 电表充值接口地址 | ||
| 44 | + */ | ||
| 45 | + private final static String rechargeDevicesUrl = "http://192.168.1.2:18080/api/emcs/rechargeDevices"; | ||
| 31 | 46 | ||
| 32 | /** | 47 | /** |
| 33 | * 电费查询 | 48 | * 电费查询 |
| @@ -101,7 +116,7 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService { | @@ -101,7 +116,7 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService { | ||
| 101 | public Number balance(String deviceId){ | 116 | public Number balance(String deviceId){ |
| 102 | 117 | ||
| 103 | // 获取电表余额 | 118 | // 获取电表余额 |
| 104 | - String s1 = HttpsUtils.sendPostHttpRequest(electricityBanlance, "1"); | 119 | + String s1 = HttpsUtils.sendPostHttpRequest(electricityBanlanceUrl, "1"); |
| 105 | 120 | ||
| 106 | ElectricityBalanceOne electricityBalanceOne = JSON.parseObject(s1, ElectricityBalanceOne.class); | 121 | ElectricityBalanceOne electricityBalanceOne = JSON.parseObject(s1, ElectricityBalanceOne.class); |
| 107 | 122 | ||
| @@ -124,7 +139,7 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService { | @@ -124,7 +139,7 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService { | ||
| 124 | datas.put("deviceId", "1"); | 139 | datas.put("deviceId", "1"); |
| 125 | try { | 140 | try { |
| 126 | 141 | ||
| 127 | - String infoForRealTime = HttpsUtils.sendPost(electricityBanlance, datas); | 142 | + String infoForRealTime = HttpsUtils.sendPost(electricityBanlanceUrl, datas); |
| 128 | ElectricityBalanceOne electricityBalanceOne = JSON.parseObject(infoForRealTime, ElectricityBalanceOne.class); | 143 | ElectricityBalanceOne electricityBalanceOne = JSON.parseObject(infoForRealTime, ElectricityBalanceOne.class); |
| 129 | List<ElectricityBalanceThree> infoForRealTimeList = electricityBalanceOne.getData().getDatas(); | 144 | List<ElectricityBalanceThree> infoForRealTimeList = electricityBalanceOne.getData().getDatas(); |
| 130 | for (ElectricityBalanceThree electricityBalanceThree: infoForRealTimeList){ | 145 | for (ElectricityBalanceThree electricityBalanceThree: infoForRealTimeList){ |
| @@ -138,4 +153,33 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService { | @@ -138,4 +153,33 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService { | ||
| 138 | return null; | 153 | return null; |
| 139 | } | 154 | } |
| 140 | } | 155 | } |
| 156 | + | ||
| 157 | + @Override | ||
| 158 | + public int rechargeDevices(String deviceId, String money, String actionType) { | ||
| 159 | + | ||
| 160 | + Map<String, Object> map = new HashMap<>(); | ||
| 161 | + map.put("actionType", actionType); | ||
| 162 | + map.put("deviceId", deviceId); | ||
| 163 | + map.put("money", money); | ||
| 164 | + map.put("ipAddress", ipAddress); | ||
| 165 | + // 设置secret值 设备id 跟金额 盐 需要进行加密 | ||
| 166 | + BigDecimal bigDecimal = new BigDecimal(money).setScale(2, RoundingMode.HALF_UP); | ||
| 167 | + String moneyString = String.valueOf(bigDecimal); | ||
| 168 | + String secret = Md5Utils.getMD5(deviceId + moneyString + "tiansu", true, 32); | ||
| 169 | + map.put("secret", secret); | ||
| 170 | + try { | ||
| 171 | + | ||
| 172 | + String result = HttpsUtils.sendPost(rechargeDevicesUrl, map); | ||
| 173 | + RechargeDevicesResult rechargeDevicesResult = JSON.parseObject(result, RechargeDevicesResult.class); | ||
| 174 | + | ||
| 175 | + if ("0".equals(rechargeDevicesResult.getErrcode())){ | ||
| 176 | + return 1; | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + }catch (Exception e){ | ||
| 180 | + e.printStackTrace(); | ||
| 181 | + return 0; | ||
| 182 | + } | ||
| 183 | + return 0; | ||
| 184 | + } | ||
| 141 | } | 185 | } |
| 1 | +package com.sunyo.energy.location.utils; | ||
| 2 | + | ||
| 3 | +import sun.misc.BASE64Encoder; | ||
| 4 | + | ||
| 5 | +import java.security.MessageDigest; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * @author shenhailong | ||
| 9 | + * <p> | ||
| 10 | + * 2020/6/2/17:30 | ||
| 11 | + */ | ||
| 12 | +public class Md5Utils { | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * 通用加密方法 | ||
| 16 | + * @param str 需要加密的字符串 | ||
| 17 | + * @param isUpper 字母大小写(false为小写,true为大写) | ||
| 18 | + * @param bit 加密的位数(16,32,64) | ||
| 19 | + * @return | ||
| 20 | + */ | ||
| 21 | + public static String getMD5(String str, boolean isUpper, Integer bit) { | ||
| 22 | + String md5 = null; | ||
| 23 | + try { | ||
| 24 | + // 创建加密对象 | ||
| 25 | + MessageDigest md = MessageDigest.getInstance("md5"); | ||
| 26 | + if (bit == 64) { | ||
| 27 | + BASE64Encoder bw = new BASE64Encoder(); | ||
| 28 | + md5 = bw.encode(md.digest(str.getBytes("utf-8"))); | ||
| 29 | + } else { | ||
| 30 | + // 计算MD5函数 | ||
| 31 | + md.update(str.getBytes()); | ||
| 32 | + byte b[] = md.digest(); | ||
| 33 | + int i; | ||
| 34 | + StringBuilder sb = new StringBuilder(); | ||
| 35 | + for (byte aB : b) { | ||
| 36 | + i = aB; | ||
| 37 | + if (i < 0) { | ||
| 38 | + i += 256; | ||
| 39 | + } | ||
| 40 | + if (i < 16) { | ||
| 41 | + sb.append("0"); | ||
| 42 | + } | ||
| 43 | + sb.append(Integer.toHexString(i)); | ||
| 44 | + } | ||
| 45 | + md5 = sb.toString(); | ||
| 46 | + if (bit == 16) { | ||
| 47 | + //截取32位md5为16位 | ||
| 48 | + md5 = md5.substring(8, 24); | ||
| 49 | + if (isUpper) { | ||
| 50 | + md5 = md5.toUpperCase(); | ||
| 51 | + } | ||
| 52 | + return md5; | ||
| 53 | + } | ||
| 54 | + } | ||
| 55 | + //转换成大写 | ||
| 56 | + if (isUpper) { | ||
| 57 | + md5 = md5.toUpperCase(); | ||
| 58 | + } | ||
| 59 | + } catch (Exception e) { | ||
| 60 | + e.printStackTrace(); | ||
| 61 | + } | ||
| 62 | + return md5; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | +} |
-
请 注册 或 登录 后发表评论