From 2787fec8348841929dd502c8fa3a4de7b606bd97 Mon Sep 17 00:00:00 2001 From: wen <1455474577@qq.com> Date: Tue, 19 Oct 2021 12:17:21 +0800 Subject: [PATCH] temp commit, to fix compile issue --- .../com/xhpc/evcs/dto/EquipBizResponse.java | 45 +++ .../java/com/xhpc/evcs/dto/PolicyInfos.java | 20 ++ .../QueryEquipBusinessPolicyController.java | 128 ++++++++ .../evcs/jpa/EquipBizPolicyRepository.java | 16 + .../xhpc/evcs/jpa/XhpcTerminalRepository.java | 24 ++ evcs-modules/pom.xml | 1 - .../station/utils/img/QrImgUtils.java | 6 +- .../com/xhpc/test/excel/ReadExcelUtil.java | 295 ++++++++++++++++++ 8 files changed, 531 insertions(+), 4 deletions(-) create mode 100644 evcs-modules/evcs-common/src/main/java/com/xhpc/evcs/dto/EquipBizResponse.java create mode 100644 evcs-modules/evcs-common/src/main/java/com/xhpc/evcs/dto/PolicyInfos.java create mode 100644 evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryEquipBusinessPolicyController.java create mode 100644 evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/jpa/EquipBizPolicyRepository.java create mode 100644 evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/jpa/XhpcTerminalRepository.java create mode 100644 xhpc-modules/xhpc-charging-station/src/test/java/com/xhpc/test/excel/ReadExcelUtil.java diff --git a/evcs-modules/evcs-common/src/main/java/com/xhpc/evcs/dto/EquipBizResponse.java b/evcs-modules/evcs-common/src/main/java/com/xhpc/evcs/dto/EquipBizResponse.java new file mode 100644 index 00000000..cb079d01 --- /dev/null +++ b/evcs-modules/evcs-common/src/main/java/com/xhpc/evcs/dto/EquipBizResponse.java @@ -0,0 +1,45 @@ +package com.xhpc.evcs.dto; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE, + setterVisibility = JsonAutoDetect.Visibility.NONE, creatorVisibility = JsonAutoDetect.Visibility.NONE) +//定义该对象转换后的json对象的键值对顺序 +@JsonPropertyOrder({ + "EquipBizSeq", + "ConnectorID", + "SuccStat", + "FailReason", + "SumPeriod", + "PolicyInfos", +}) +public class EquipBizResponse { + + @JsonProperty("EquipBizSeq") + String equipBizSeq; + @JsonProperty("ConnectorID") + String connectorId; + + /** + * 操作结果 + */ + //JsonProperty的作用是将该字段,按照所指定的key转换成json键值对。 + @JsonProperty("SuccStat") + int succStat; + + @JsonProperty("FailReason") + int failReason; + + @JsonProperty("SumPeriod") + int sumPeriod; + + @JsonProperty("PolicyInfos") + PolicyInfos[] policyInfos; + +} diff --git a/evcs-modules/evcs-common/src/main/java/com/xhpc/evcs/dto/PolicyInfos.java b/evcs-modules/evcs-common/src/main/java/com/xhpc/evcs/dto/PolicyInfos.java new file mode 100644 index 00000000..bc221ec3 --- /dev/null +++ b/evcs-modules/evcs-common/src/main/java/com/xhpc/evcs/dto/PolicyInfos.java @@ -0,0 +1,20 @@ +package com.xhpc.evcs.dto; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE, + setterVisibility = JsonAutoDetect.Visibility.NONE, creatorVisibility = JsonAutoDetect.Visibility.NONE) +public class PolicyInfos { + + @JsonProperty("StartTime") + String startTime; + @JsonProperty("ElecPrice") + double elecPrice; + @JsonProperty("ServicePrice") + double servicePrice; +} diff --git a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryEquipBusinessPolicyController.java b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryEquipBusinessPolicyController.java new file mode 100644 index 00000000..e1cd097f --- /dev/null +++ b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryEquipBusinessPolicyController.java @@ -0,0 +1,128 @@ +package com.xhpc.evcs.api; + +import com.xhpc.common.data.redis.CacheRateModel; +import com.xhpc.common.domain.XhpcTerminal; +import com.xhpc.evcs.dto.EquipBizRequest; +import com.xhpc.evcs.dto.EquipBizResponse; +import com.xhpc.evcs.dto.PolicyInfos; +import com.xhpc.evcs.jpa.XhpcTerminalRepository; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import java.util.*; + +import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS; + +@Slf4j +@RestController +public class QueryEquipBusinessPolicyController { + + @Autowired + private XhpcTerminalRepository XhpcTerminalRepository; + + @PostMapping("/v1/query_equip_business_policy") + public EquipBizResponse queryEquipBusinessPolicy(@RequestBody EquipBizRequest equipBizRequest) { + //获取充电设备接口编码(枪编码) + String connectorId = equipBizRequest.getConnectorId(); + //获取枪所对应的桩编码 + Optional bySerialNumber = XhpcTerminalRepository.findBySerialNumber(connectorId); + XhpcTerminal xhpcTerminal = bySerialNumber.get(); + String pileSerialNumber = xhpcTerminal.getPileSerialNumber(); + //通过桩编码,进入redis,找到其所用的费率模型id + Map cacheMap = REDIS.getCacheMap("pile:" + pileSerialNumber); + Long rateModelId = (Long) cacheMap.get("rateModelId"); + //通过指定费率模型id,找到其对应的费率模型 + CacheRateModel rateModel = REDIS.getCacheObject("rateModel:" + rateModelId); + String[] tfPricesSeq = rateModel.getTfPricesSeq(); + + //查询所需要的数据 + EquipBizResponse equipBizResponse = load(tfPricesSeq,equipBizRequest); + + + /*//遍历获取每一个值 + ArrayList intervalList = new ArrayList<>(); + + //添加计数器: + int flag = 0; + for (int i = 0; i < tfPricesSeq.length-1; i++) { + if (!tfPricesSeq[i].equals(tfPricesSeq[i+1])){ + intervalList.add(tfPricesSeq[i]); + + } + } + for (String value : tfPricesSeq) { + if(!value.equals(store)){ + flag = 0; //将计数器置为0 + } + flag++; + store = value; + }*/ + return equipBizResponse; + } + + public EquipBizResponse load(String[] arr,EquipBizRequest equipBizRequest) { + Map priceMap = new HashMap<>(); + Map svcPriceMap = new HashMap<>(); + String[] keys = {"01","02","03","04"}; + String[] values1 = {"t1Price","t2Price","t3Price","t4Price"}; + String[] values2 = {"t1SvcPrice","t2SvcPrice","t3SvcPrice","t4SvcPrice"}; + for(int i = 0; i < keys.length; i ++){ + priceMap.put(keys[i],values1[i]); + svcPriceMap.put(keys[i],values2[i]); + } + List timeSigns = new ArrayList<>(); + List locations = new ArrayList<>(); + for (int i = 0; i < arr.length - 1; i++) { + if (arr[i].equals(arr[i + 1])) { + timeSigns.add(arr[i]); + locations.add(i); + } + } + timeSigns.add(arr[arr.length - 1]); + locations.add(arr.length - 1); + List time = new ArrayList<>(); + time.add(0); + time.add(locations.get(0)); + for (int i = 1; i < locations.size(); i++) { + time.add(locations.get(i - 1)); + time.add(locations.get(i)); + } + List startTimes = new ArrayList<>(); + List priceResult = new ArrayList<>(); + List svcPriceResult = new ArrayList<>(); + for(int i = 0, j = 0; i < locations.size(); i += 2, j ++){ + priceResult.add(REDIS.getCacheObject(priceMap.get(timeSigns.get(j)))); + svcPriceResult.add(REDIS.getCacheObject(svcPriceMap.get(timeSigns.get(j)))); + startTimes.add((int) (i * 10000 * 0.5)); + } + PolicyInfos[] repsData = new PolicyInfos[startTimes.size()]; + for(int i = 0; i < startTimes.size(); i ++){ + PolicyInfos policyInfos = new PolicyInfos(); + policyInfos.setStartTime(String.valueOf(startTimes.get(i))); + policyInfos.setElecPrice(priceResult.get(i)); + policyInfos.setServicePrice(svcPriceResult.get(i)); + repsData[i] = policyInfos; + + } + + + //封装数据 + EquipBizResponse equipBizResponse = new EquipBizResponse(); + equipBizResponse.setEquipBizSeq(equipBizRequest.getEquipBizSeq()); + equipBizResponse.setConnectorId(equipBizRequest.getConnectorId()); + equipBizResponse.setSuccStat(0); + equipBizResponse.setFailReason(0); + equipBizResponse.setSumPeriod(3); + equipBizResponse.setPolicyInfos(repsData); + + return equipBizResponse; + + + + + } + +} diff --git a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/jpa/EquipBizPolicyRepository.java b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/jpa/EquipBizPolicyRepository.java new file mode 100644 index 00000000..8cc407c0 --- /dev/null +++ b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/jpa/EquipBizPolicyRepository.java @@ -0,0 +1,16 @@ +package com.xhpc.evcs.jpa; + +import com.xhpc.evcs.domain.AuthSecretToken; +import com.xhpc.evcs.domain.XhpcChargingPile; +import com.xhpc.evcs.dto.EquipBizResponse; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.repository.query.QueryByExampleExecutor; + +import java.util.Optional; + +public interface EquipBizPolicyRepository extends JpaRepository, + QueryByExampleExecutor, JpaSpecificationExecutor { + + Optional findByConnectorId(String connectorId); +} diff --git a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/jpa/XhpcTerminalRepository.java b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/jpa/XhpcTerminalRepository.java new file mode 100644 index 00000000..8f5105a8 --- /dev/null +++ b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/jpa/XhpcTerminalRepository.java @@ -0,0 +1,24 @@ +package com.xhpc.evcs.jpa; + +import com.xhpc.common.domain.XhpcTerminal; +import com.xhpc.evcs.domain.XhpcChargingPile; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.repository.query.QueryByExampleExecutor; + +import java.util.Optional; + +/** + * SpringJPA框架,DAO层 + * 继承三个接口,泛型为将记录封装到哪个实体类对象中。 + */ +public interface XhpcTerminalRepository extends JpaRepository, + QueryByExampleExecutor, JpaSpecificationExecutor { + + /** + * 通过枪序列号查询到枪所在的桩的桩编码 + * @param serialNumber + * @return + */ + Optional findBySerialNumber(String serialNumber); +} diff --git a/evcs-modules/pom.xml b/evcs-modules/pom.xml index 76934297..69eeb154 100644 --- a/evcs-modules/pom.xml +++ b/evcs-modules/pom.xml @@ -28,7 +28,6 @@ 2.5.1 2020.0.3 2021.1 - 2.0.2 2.4.1 3.0.0 1.6.2 diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/utils/img/QrImgUtils.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/utils/img/QrImgUtils.java index 09493e72..8aa175e1 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/utils/img/QrImgUtils.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/utils/img/QrImgUtils.java @@ -53,7 +53,7 @@ public class QrImgUtils { // 创建OSSClient实例 OSSClient ossClient = new OSSClient(environment.getProperty("oss.endpoint"), environment.getProperty("oss.access-key"), environment.getProperty("oss.secret-key")); // 上传文件流 - ossClient.putObject(environment.getProperty("oss.bucket-name"), xhpcTerminal.getPileSerialNumber() + "/" + finallyImgFileName, new File(environment.getProperty("destPath") +finallyImgFileName)); + ossClient.putObject(environment.getProperty("oss.bucket-name"), xhpcTerminal.getPileSerialNumber() + "/" + finallyImgFileName, new File(environment.getProperty("oss.destPath") + "\\" + finallyImgFileName)); ossClient.shutdown(); //5.将放在阿里云上的生成的图片的路径和图片所对应的终端的id放入数据库xhpc_img表中 @@ -61,10 +61,10 @@ public class QrImgUtils { xhpcImgMapper.insert(xhpcTerminal.getPileSerialNumber() + "/" + finallyImgFileName, terminalId); //6.删除生成的二维码图片 - File QrImg = new File(environment.getProperty("destPath") + qrFileName); + File QrImg = new File(environment.getProperty("oss.destPath") + "\\" + qrFileName); QrImg.delete(); //7.删除生成本地生成的完整图片 - File finallyImg = new File(environment.getProperty("fullImgDestPath") + finallyImgFileName); + File finallyImg = new File(environment.getProperty("oss.fullImgDestPath") + finallyImgFileName); finallyImg.delete(); } catch (Exception e) { diff --git a/xhpc-modules/xhpc-charging-station/src/test/java/com/xhpc/test/excel/ReadExcelUtil.java b/xhpc-modules/xhpc-charging-station/src/test/java/com/xhpc/test/excel/ReadExcelUtil.java new file mode 100644 index 00000000..7734e964 --- /dev/null +++ b/xhpc-modules/xhpc-charging-station/src/test/java/com/xhpc/test/excel/ReadExcelUtil.java @@ -0,0 +1,295 @@ +/* +package com.xhpc.test.excel; + +import com.xhpc.common.domain.XhpcChargingPile; +import org.apache.poi.ss.usermodel.*; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +*/ +/** + * 读取Excel表格工具类 + *//* + +public class ReadExcelUtil { + + private void parseExcel(){} + private void dataToDatabase(){} + private void writeToExcel(){} + + public static void main(String[] args) throws IOException { + + //1.存储要读取的Excel的文件路径 + String pileExcelPath = "D:\\Enterprise_Resources\\XiaoHuaMaterialImgs\\pile.xlsx"; + + //2.加载Excel进内存 + File pileExcel = new File(pileExcelPath); + + //3.创建Workbook对象,将其转换成可操作的Excel + Workbook workBook = WorkbookFactory.create(pileExcel); + + //4.获取Excel表中的sheet1表 + Sheet sheet1 = workBook.getSheet("Sheet1"); + + //5.获取sheet1表的名称 + String sheetName = sheet1.getSheetName(); + + System.out.println("工作表名称:"+sheetName); + + //6.获取工作表的总行数 + int totalRows = sheet1.getPhysicalNumberOfRows(); + System.out.println("当前工作表总行数:"+totalRows); + + //7.获取工作表中的总列数 + //7.1获取第一行的记录,行索引从0开始的 + Row twoRow = sheet1.getRow(2); + int totalColumns = twoRow.getPhysicalNumberOfCells(); + System.out.println("当前sheet表中的总列数:"+totalColumns); + + //8.获取第二行的记录中的第一个单元格,单元格索引从0开始 + Cell cell = twoRow.getCell(0); + String pileName = cell.getStringCellValue(); + System.out.println("电桩名称为:"+pileName); + + //9.获取第二行的记录中的第二个单元格 + Cell cell2 = twoRow.getCell(1); + String brandModel = cell2.getStringCellValue(); + System.out.println("品牌型号为:"+brandModel); + + //10.获取第二行的记录中的第三个单元格 + Cell cell3 = twoRow.getCell(2); + String pileNational = cell3.getStringCellValue(); + System.out.println("电桩国际:"+pileNational); + + //11.获取第二行的记录中的第四个单元格 + Cell cell4 = twoRow.getCell(3); + String pilePower = cell4.getStringCellValue(); + System.out.println("电桩功率:"+pilePower); + + //12.获取第二行的记录中的第五个单元格 + Cell cell5 = twoRow.getCell(4); + int powerSupport = (int) cell5.getNumericCellValue(); + System.out.println("辅助电源支持:"+powerSupport); + + //13.获取第二行的记录中的第六个单元格 + Cell cell6 = twoRow.getCell(5); + int inputVoltage = (int) cell6.getNumericCellValue(); + System.out.println("输入电压:"+inputVoltage); + + //14.获取第二行的记录中的第六个单元格 + Cell cell7 = twoRow.getCell(6); + int maxVoltage = (int) cell7.getNumericCellValue(); + System.out.println("最大电压:"+maxVoltage); + + //15.获取第二行的记录中的第七个单元格 + Cell cell8 = twoRow.getCell(7); + int minVoltage = (int) cell8.getNumericCellValue(); + System.out.println("最小电压:"+minVoltage); + + //16.获取第二行的记录中的第八个单元格 + Cell cell9 = twoRow.getCell(8); + int maxCurrent = (int) cell9.getNumericCellValue(); + System.out.println("最大电流:"+maxCurrent); + + //17.获取第二行的记录中的第九个单元格 + Cell cell10 = twoRow.getCell(9); + int minCurrent = (int) cell10.getNumericCellValue(); + System.out.println("最小电流:"+minCurrent); + + //18.获取第二行的记录中的第十个单元格 + Cell cell11 = twoRow.getCell(10); + String pileNumber = cell11.getStringCellValue(); + System.out.println("桩编码:"+pileNumber); + + //19.获取第二行的记录中的第十一个单元格 + Cell cell12 = twoRow.getCell(11); + String StationName = cell12.getStringCellValue(); + System.out.println("场站名称:"+StationName); + + //20.获取第二行的记录中的第十二个单元格 + Cell cell13 = twoRow.getCell(12); + String terminalCount = cell13.getStringCellValue(); + System.out.println("终端数量:"+terminalCount); + + //21.获取第二行的记录中的第十三个单元格 + Cell cell14 = twoRow.getCell(13); + String pileType = cell14.getStringCellValue(); + System.out.println("电桩类型:"+pileType); + + System.out.println("==================分割线===================="); + + for (int i = 0;i storeMap = new HashMap<>(); + + for (int i = 0;i