From 60c33535e87b4ba807c575d7a02755f5705373d5 Mon Sep 17 00:00:00 2001 From: liyongxiang Date: Fri, 14 Mar 2025 14:15:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=B5=8B=E8=AF=95=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demos/web/controller/BasicController.java | 8 +++++++ .../example/demo/service/BasicService.java | 2 ++ .../demo/service/impl/BasicServiceImpl.java | 23 +++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/demo/src/main/java/com/example/demo/demos/web/controller/BasicController.java b/demo/src/main/java/com/example/demo/demos/web/controller/BasicController.java index e8f6a7d..ac0c4a9 100644 --- a/demo/src/main/java/com/example/demo/demos/web/controller/BasicController.java +++ b/demo/src/main/java/com/example/demo/demos/web/controller/BasicController.java @@ -45,6 +45,14 @@ public class BasicController { log.info("获取电费相关信息响应:{}", JSON.toJSONString(response)); return response; } + @PostMapping("/getElectricityInfo1") + @ResponseBody + public Object getElectricityInfo1(@RequestBody Map param) { + log.info("获取电费相1关信息入参:{}", JSON.toJSONString(param)); + Object response = basicService.getElectricityInfo1(param); + log.info("获取电费相1关信息响应:{}", JSON.toJSONString(response)); + return response; + } // http://127.0.0.1:8080/user @RequestMapping("/user") diff --git a/demo/src/main/java/com/example/demo/service/BasicService.java b/demo/src/main/java/com/example/demo/service/BasicService.java index bd8ad10..7bd1d1e 100644 --- a/demo/src/main/java/com/example/demo/service/BasicService.java +++ b/demo/src/main/java/com/example/demo/service/BasicService.java @@ -10,4 +10,6 @@ import java.util.Map; public interface BasicService { Response getElectricityInfo(Map param); + + Object getElectricityInfo1(Map param); } diff --git a/demo/src/main/java/com/example/demo/service/impl/BasicServiceImpl.java b/demo/src/main/java/com/example/demo/service/impl/BasicServiceImpl.java index 6fd2438..8abf160 100644 --- a/demo/src/main/java/com/example/demo/service/impl/BasicServiceImpl.java +++ b/demo/src/main/java/com/example/demo/service/impl/BasicServiceImpl.java @@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -64,6 +65,28 @@ public class BasicServiceImpl implements BasicService { return response; } + @Override + public Object getElectricityInfo1(Map param) { + String keyWord = (String) param.get("kw"); + DataAndView dataAndView =new DataAndView(); + List bills = new ArrayList<>(); + TypeAndQuery typeAndQuery = new TypeAndQuery(); + analysisKeyWord(keyWord,typeAndQuery); + dataAndView.setType(typeAndQuery.getType()); + log.info("数据库查询电费!"); + bills = electricityBillMapper.queryElectricityByDate(); + StringBuilder electricityBill =new StringBuilder(); + StringBuilder statementDate =new StringBuilder(); + bills.stream().forEach(bill ->{ + electricityBill.append(bill.getElectricityBill()).append(";"); + statementDate.append(bill.getStatementDate()).append(";"); + }); + Map result = new HashMap<>(); + result.put("electricityBill",electricityBill.deleteCharAt(electricityBill.length()-1).toString()); + result.put("statementDate",statementDate.deleteCharAt(electricityBill.length()-1).toString()); + dataAndView.setData(result); + return dataAndView; + } private void analysisKeyWord(String keyWord,TypeAndQuery typeAndQuery){ int querySymbol = 0;