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;