diff --git a/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/controller/XhpcServiceDataUpdateController.java b/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/controller/XhpcServiceDataUpdateController.java new file mode 100644 index 00000000..746824c4 --- /dev/null +++ b/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/controller/XhpcServiceDataUpdateController.java @@ -0,0 +1,33 @@ +package com.xhpc.general.controller; + +import com.xhpc.common.core.web.domain.AjaxResult; +import com.xhpc.general.service.IXhpcServiceDataUpdateService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import static com.xhpc.general.service.XhpcSmsServiceImpl.REDIS; + +/** + * program: ruoyi + * User: HongYun + * Date:2021-08-12 13 + */ +@RestController +@RequestMapping("/SDataUpdate") +public class XhpcServiceDataUpdateController { + + @Autowired + IXhpcServiceDataUpdateService xhpcServiceDataUpdateService; + + @GetMapping("/show") + public AjaxResult showList(){ + + return AjaxResult.success(xhpcServiceDataUpdateService.getServiceData()); + } + + @PostMapping("/update") + public AjaxResult updateDate(@RequestParam(required = false) String SOC, @RequestParam(required = false) String version, @RequestParam(required = false) String phone){ + + return xhpcServiceDataUpdateService.updateServiceData(SOC, version, phone); + } +} diff --git a/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/service/IXhpcServiceDataUpdateService.java b/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/service/IXhpcServiceDataUpdateService.java new file mode 100644 index 00000000..0debc468 --- /dev/null +++ b/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/service/IXhpcServiceDataUpdateService.java @@ -0,0 +1,19 @@ +package com.xhpc.general.service; + +import com.xhpc.common.core.web.domain.AjaxResult; + +import java.util.Map; + +/** + * program: ruoyi + * User: HongYun + * Date:2021-08-12 13 + */ +public interface IXhpcServiceDataUpdateService { + + Map getServiceData(); + + AjaxResult updateServiceData(String SOC, String version, String phone); + + +} diff --git a/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/service/XhpcServiceDataUpdateServiceImpl.java b/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/service/XhpcServiceDataUpdateServiceImpl.java new file mode 100644 index 00000000..8b9d9c7d --- /dev/null +++ b/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/service/XhpcServiceDataUpdateServiceImpl.java @@ -0,0 +1,56 @@ +package com.xhpc.general.service; + +import com.xhpc.common.core.web.domain.AjaxResult; +import com.xhpc.common.redis.service.RedisService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.Map; + +/** + * program: ruoyi + * User: HongYun + * Date:2021-08-12 14 + */ +@Service +public class XhpcServiceDataUpdateServiceImpl implements IXhpcServiceDataUpdateService{ + + @Autowired + private RedisService redisService; + @Override + public Map getServiceData() { + + Map list=new HashMap<>(); + String cacheSOC = redisService.getCacheObject("global:SOC"); + String cacheVersion = redisService.getCacheObject("global:version"); + String cachePhone = redisService.getCacheObject("global:phone"); + list.put("SOC",cacheSOC); + list.put("version",cacheVersion); + list.put("phone",cachePhone); + return list; + } + + + @Override + public AjaxResult updateServiceData(String SOC, String version, String phone) { + + if(SOC!=null) { + int soc = Integer.parseInt(SOC); + if (!(soc >= 1 && soc <= 100)) { + return AjaxResult.error("范围应为[1-100]"); + } + } + if(phone!=null) { + if (phone.length() > 20) { + return AjaxResult.error("号码格式错误"); + } + } + + redisService.setCacheObject("global:SOC",SOC); + redisService.setCacheObject("global:version",version); + redisService.setCacheObject("global:phone",phone); + + return AjaxResult.success(); + } +} diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RealtimeDataLogic.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RealtimeDataLogic.java index ef45e343..fff8fffe 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RealtimeDataLogic.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RealtimeDataLogic.java @@ -69,6 +69,11 @@ public class RealtimeDataLogic implements ServiceLogic { } Integer balance = (Integer) cacheOrder.get("balance"); CacheRealtimeData cacheRealtimeData = translate(realtimeData); + realtimeDataList.add(cacheRealtimeData); + cacheOrder.put("soc", realtimeData.getSoc()); + cacheOrder.put("status", statusplain); + cacheOrder.put("realtimeDataList", realtimeDataList); + REDIS.setCacheMap(orderkey, cacheOrder); if ((balance - cacheRealtimeData.getAmountCharged()) < 500) { String alerted = (String) cacheOrder.get("alerted"); String tel = (String) cacheOrder.get("tel"); @@ -77,11 +82,6 @@ public class RealtimeDataLogic implements ServiceLogic { cacheOrder.put("alerted", "true"); } } - realtimeDataList.add(cacheRealtimeData); - cacheOrder.put("soc", realtimeData.getSoc()); - cacheOrder.put("status", statusplain); - cacheOrder.put("realtimeDataList", realtimeDataList); - REDIS.setCacheMap(orderkey, cacheOrder); } return new ServiceResult(false); } diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/tx/ServiceResult.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/tx/ServiceResult.java index 360786fe..bbb3ceed 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/tx/ServiceResult.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/tx/ServiceResult.java @@ -22,7 +22,7 @@ public class ServiceResult { public ServiceResult(String code, String body) { - Map map = new HashMap(); + Map map = new HashMap<>(); String messageCode = "0101"; if (code != null && code.trim().length() > 0) { messageCode = code;