From beba4dae71b45ee9b83fa19c058c055bc7e7153a Mon Sep 17 00:00:00 2001 From: WL <790517410@qq.com> Date: Tue, 18 Mar 2025 20:08:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=9C=80=E6=96=B0=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demos/web/controller/BasicController.java | 11 +++++++ .../demo/mapper/ElecPrivceHistoryMapper.java | 10 ++++++ .../example/demo/model/ElePriceInfoModel.java | 18 +++++++++++ .../example/demo/model/ElecPriceHistory.java | 20 ++++++++++++ .../example/demo/service/BasicService.java | 3 ++ .../demo/service/impl/BasicServiceImpl.java | 32 ++++++++++++++++--- .../mapper/ElecPriceHistoryMapper.xml | 5 +++ 7 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 demo/src/main/java/com/example/demo/mapper/ElecPrivceHistoryMapper.java create mode 100644 demo/src/main/java/com/example/demo/model/ElePriceInfoModel.java create mode 100644 demo/src/main/java/com/example/demo/model/ElecPriceHistory.java create mode 100644 demo/src/main/resources/mapper/ElecPriceHistoryMapper.xml 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 398ad22..c48f10c 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 @@ -17,6 +17,7 @@ package com.example.demo.demos.web.controller; import com.alibaba.fastjson.JSON; +import com.example.demo.model.ElePriceInfoModel; import com.example.demo.model.ElecBindInfoModel; import com.example.demo.model.Response; import com.example.demo.model.User; @@ -75,6 +76,16 @@ public class BasicController { return response; } + @PostMapping("/getElePriceInfo") + @ResponseBody + public Object getElePriceInfo(@RequestBody ElePriceInfoModel model) { + Object response = new Object(); + log.info("获取历史电价信息入参:model:{}", JSON.toJSONString(model)); + response = basicService.getElePriceInfo(model); + log.info("获取绑定信息返回:{}", JSON.toJSONString(response)); + return response; + } + // http://127.0.0.1:8080/user @RequestMapping("/user") @ResponseBody diff --git a/demo/src/main/java/com/example/demo/mapper/ElecPrivceHistoryMapper.java b/demo/src/main/java/com/example/demo/mapper/ElecPrivceHistoryMapper.java new file mode 100644 index 0000000..396059f --- /dev/null +++ b/demo/src/main/java/com/example/demo/mapper/ElecPrivceHistoryMapper.java @@ -0,0 +1,10 @@ +package com.example.demo.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.example.demo.model.ElecPriceHistory; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface ElecPrivceHistoryMapper extends BaseMapper { + +} diff --git a/demo/src/main/java/com/example/demo/model/ElePriceInfoModel.java b/demo/src/main/java/com/example/demo/model/ElePriceInfoModel.java new file mode 100644 index 0000000..fa8eee5 --- /dev/null +++ b/demo/src/main/java/com/example/demo/model/ElePriceInfoModel.java @@ -0,0 +1,18 @@ +package com.example.demo.model; + +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; +import org.springframework.stereotype.Component; + +@Data +@Component +public class ElePriceInfoModel { + + private String province; + private String city; + private String isSummer; + private String elecGradient; + private String elecType; + private String startTime; + private String endTime; +} diff --git a/demo/src/main/java/com/example/demo/model/ElecPriceHistory.java b/demo/src/main/java/com/example/demo/model/ElecPriceHistory.java new file mode 100644 index 0000000..eef4eed --- /dev/null +++ b/demo/src/main/java/com/example/demo/model/ElecPriceHistory.java @@ -0,0 +1,20 @@ +package com.example.demo.model; + +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; +import org.springframework.stereotype.Component; + +@Data +@Component +public class ElecPriceHistory { + + @TableId + private String id; + private String province; + private String city; + private String isSummer; + private String elecGradient; + private String elecType; + private String effectiveTime; + private String elecPrice; +} 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 b6fc3ad..3821461 100644 --- a/demo/src/main/java/com/example/demo/service/BasicService.java +++ b/demo/src/main/java/com/example/demo/service/BasicService.java @@ -1,5 +1,6 @@ package com.example.demo.service; +import com.example.demo.model.ElePriceInfoModel; import com.example.demo.model.ElecBindInfoModel; import com.example.demo.model.Response; import org.springframework.stereotype.Service; @@ -15,4 +16,6 @@ public interface BasicService { Object getElectricityInfo1(Map param); Object getBindingInfo(ElecBindInfoModel model); + + Object getElePriceInfo(ElePriceInfoModel model); } 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 4387822..c3bbaa1 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 @@ -1,18 +1,15 @@ package com.example.demo.service.impl; -import com.alibaba.fastjson.JSON; -import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments; import com.example.demo.constant.EleConstant; import com.example.demo.constant.StaConstant; import com.example.demo.mapper.ElecBillInfoMapper; +import com.example.demo.mapper.ElecPrivceHistoryMapper; import com.example.demo.mapper.ElectricityBillMapper; import com.example.demo.model.*; import com.example.demo.service.BasicService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; import java.util.ArrayList; @@ -30,6 +27,9 @@ public class BasicServiceImpl implements BasicService { @Autowired ElecBillInfoMapper elecBillInfoMapper; + @Autowired + ElecPrivceHistoryMapper elecPrivceHistoryMapper; + @Override public Response getElectricityInfo(Map param) { String keyWord = (String) param.get("kw"); @@ -97,7 +97,7 @@ public class BasicServiceImpl implements BasicService { QueryWrapper queryWrapper =new QueryWrapper<>(); Map map = new HashMap<>(); map.put("phone",model.getPhone()); - map.put("province","广东省"); + map.put("province",model.getProvince()); map.put("city",model.getCity()); map.put("elec_number",model.getElecNumber()); map.put("city_code",model.getCityCode()); @@ -106,6 +106,28 @@ public class BasicServiceImpl implements BasicService { return elecBillInfoMapper.selectList(queryWrapper); } + @Override + public Object getElePriceInfo(ElePriceInfoModel model) { + QueryWrapper queryWrapper =new QueryWrapper<>(); + Map map = new HashMap<>(); + List> result = new ArrayList<>(); + map.put("is_summer",model.getIsSummer()); + map.put("elec_gradient",model.getElecGradient()); + map.put("elec_type",model.getElecType()); + queryWrapper.allEq(map,false) + .between("effective_time",model.getStartTime(),model.getEndTime()) + .like("province",model.getProvince()) + .like("city",model.getCity()); + List elecPriceHistories = elecPrivceHistoryMapper.selectList(queryWrapper); + elecPriceHistories.stream().forEach(e ->{ + Map priceMap = new HashMap<>(); + priceMap.put("price",e.getElecPrice()); + priceMap.put("date",e.getEffectiveTime()); + result.add(priceMap); + }); + return result; + } + private void analysisKeyWord(String keyWord,TypeAndQuery typeAndQuery){ int querySymbol = 0; String type = EleConstant.LINE_TYPE_BG; diff --git a/demo/src/main/resources/mapper/ElecPriceHistoryMapper.xml b/demo/src/main/resources/mapper/ElecPriceHistoryMapper.xml new file mode 100644 index 0000000..d2fad0f --- /dev/null +++ b/demo/src/main/resources/mapper/ElecPriceHistoryMapper.xml @@ -0,0 +1,5 @@ + + + + +