query_equip_business_policy接口开发编译通过
This commit is contained in:
parent
d74f0e38b4
commit
41e47442bb
@ -1,7 +1,6 @@
|
||||
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;
|
||||
@ -12,7 +11,10 @@ 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 java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
||||
|
||||
@ -21,16 +23,17 @@ import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
||||
public class QueryEquipBusinessPolicyController {
|
||||
|
||||
@Autowired
|
||||
private XhpcTerminalRepository XhpcTerminalRepository;
|
||||
private XhpcTerminalRepository xhpcTerminalRepository;
|
||||
|
||||
@PostMapping("/v1/query_equip_business_policy")
|
||||
public EquipBizResponse queryEquipBusinessPolicy(@RequestBody EquipBizRequest equipBizRequest) {
|
||||
//获取充电设备接口编码(枪编码)
|
||||
String connectorId = equipBizRequest.getConnectorId();
|
||||
//获取枪所对应的桩编码
|
||||
Optional<XhpcTerminal> bySerialNumber = XhpcTerminalRepository.findBySerialNumber(connectorId);
|
||||
XhpcTerminal xhpcTerminal = bySerialNumber.get();
|
||||
String pileSerialNumber = xhpcTerminal.getPileSerialNumber();
|
||||
String bySerialNumber = xhpcTerminalRepository.selectBySql(connectorId);
|
||||
System.out.println(bySerialNumber);
|
||||
|
||||
String pileSerialNumber = bySerialNumber;
|
||||
//通过桩编码,进入redis,找到其所用的费率模型id
|
||||
Map<String, Object> cacheMap = REDIS.getCacheMap("pile:" + pileSerialNumber);
|
||||
Long rateModelId = (Long) cacheMap.get("rateModelId");
|
||||
@ -39,27 +42,66 @@ public class QueryEquipBusinessPolicyController {
|
||||
String[] tfPricesSeq = rateModel.getTfPricesSeq();
|
||||
|
||||
//查询所需要的数据
|
||||
EquipBizResponse equipBizResponse = load(tfPricesSeq,equipBizRequest);
|
||||
// EquipBizResponse equipBizResponse = load(tfPricesSeq,equipBizRequest);
|
||||
|
||||
|
||||
/*//遍历获取每一个值
|
||||
ArrayList<String> intervalList = new ArrayList<>();
|
||||
|
||||
//添加计数器:
|
||||
int flag = 0;
|
||||
//遍历获取每一个时段
|
||||
//存储时段
|
||||
ArrayList<String> modelTypes = new ArrayList<>();
|
||||
//存储时段个数
|
||||
ArrayList<Integer> modelCount = new ArrayList<>();
|
||||
//个数计数器
|
||||
int count = 0;
|
||||
//最后一个时段的前一个时段的下标索引
|
||||
int index = 0;
|
||||
for (int i = 0; i < tfPricesSeq.length - 1; i++) {
|
||||
count++;
|
||||
//如果当前时段与后面的时段不相同,则表示当前时段已经结束,添加当前时段到list中,并将其坐标存放到另一个集合中。
|
||||
if (!tfPricesSeq[i].equals(tfPricesSeq[i + 1])) {
|
||||
intervalList.add(tfPricesSeq[i]);
|
||||
//将每段时间的索引,赋值
|
||||
index = i;
|
||||
modelTypes.add(tfPricesSeq[i]);
|
||||
modelCount.add(count);
|
||||
//如果这段时段结束,则重置计数器
|
||||
count = 0;
|
||||
|
||||
}
|
||||
}
|
||||
for (String value : tfPricesSeq) {
|
||||
if(!value.equals(store)){
|
||||
flag = 0; //将计数器置为0
|
||||
//获取最后一个时段的费率值
|
||||
String lastModelType = tfPricesSeq[tfPricesSeq.length - 1];
|
||||
//放入到类型list中
|
||||
modelTypes.add(lastModelType);
|
||||
//获取最后一个时段的费率的个数
|
||||
int lastCount = (tfPricesSeq.length - 1) - index;
|
||||
//放入到个数List中
|
||||
modelCount.add(lastCount);
|
||||
|
||||
//"030000" "240000"
|
||||
//定义一个初始时间段
|
||||
String initTime = "000000";
|
||||
String initTime1 = "240000";
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
//根据出现的时段个数确定他们的时间区间,然后存放至List集合中
|
||||
for (int i = 0; i < modelCount.size() - 1; i++) {
|
||||
Integer integer = modelCount.get(i);
|
||||
int hours = integer / 2;
|
||||
if (integer >= 10) {
|
||||
String str = String.valueOf(hours);
|
||||
initTime1.replace("24", "" + hours);
|
||||
} else {
|
||||
String str = String.valueOf(hours);
|
||||
initTime1.substring(2);
|
||||
}
|
||||
flag++;
|
||||
store = value;
|
||||
}*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
EquipBizResponse equipBizResponse = new EquipBizResponse();
|
||||
//总时段数
|
||||
equipBizResponse.setSumPeriod(modelTypes.size());
|
||||
|
||||
|
||||
return equipBizResponse;
|
||||
}
|
||||
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
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<XhpcChargingPile, String>,
|
||||
QueryByExampleExecutor<XhpcChargingPile>, JpaSpecificationExecutor<XhpcChargingPile> {
|
||||
|
||||
Optional<XhpcChargingPile> findByConnectorId(String connectorId);
|
||||
}
|
||||
@ -1,10 +1,11 @@
|
||||
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.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.QueryByExampleExecutor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@ -12,13 +13,20 @@ import java.util.Optional;
|
||||
* SpringJPA框架,DAO层
|
||||
* 继承三个接口,泛型为将记录封装到哪个实体类对象中。
|
||||
*/
|
||||
public interface XhpcTerminalRepository extends JpaRepository<XhpcTerminal, String>,
|
||||
@Repository
|
||||
public interface XhpcTerminalRepository extends JpaRepository<XhpcTerminal, Integer>,
|
||||
QueryByExampleExecutor<XhpcTerminal>, JpaSpecificationExecutor<XhpcTerminal> {
|
||||
|
||||
/**
|
||||
* 通过枪序列号查询到枪所在的桩的桩编码
|
||||
*
|
||||
* @param serialNumber
|
||||
* @return
|
||||
*/
|
||||
Optional<XhpcTerminal> findBySerialNumber(String serialNumber);
|
||||
Optional<XhpcTerminal> findOneBySerialNumber(String serialNumber);
|
||||
|
||||
|
||||
@Query("select t.pileSerialNumber from XhpcTerminal as t where t.serialNumber = ?1")
|
||||
String selectBySql(String serialNumber);
|
||||
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService {
|
||||
if (xhpcChargingPile.getGunNumber() > 0) {
|
||||
int number = xhpcChargingPileMapper.countXhpcTerminal(chargingStationId);
|
||||
for (int i = 1; i <= xhpcChargingPile.getGunNumber(); i++) {
|
||||
addXhpcTerminal(xhpcChargingPile.getName(), chargingStationId, rateModelId, serialNumber, chargingPileId, i,number+1);
|
||||
addXhpcTerminal(xhpcChargingPile.getName(), chargingStationId, rateModelId, serialNumber, chargingPileId, i, number + 1, xhpcChargingPile.getConnectorType());
|
||||
}
|
||||
}
|
||||
//插入redis 桩的编号
|
||||
@ -105,7 +105,7 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService {
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
private void addXhpcTerminal(String name, Long chargingStationId, Long rateModelId, String serialNumber, Long chargingPileId, int i, int number) {
|
||||
private void addXhpcTerminal(String name, Long chargingStationId, Long rateModelId, String serialNumber, Long chargingPileId, int i, int number, int conType) {
|
||||
|
||||
XhpcTerminal xhpcTerminal = new XhpcTerminal();
|
||||
xhpcTerminal.setChargingStationId(chargingStationId);
|
||||
@ -121,6 +121,7 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService {
|
||||
xhpcTerminal.setStatus(0);
|
||||
xhpcTerminal.setRateModelId(rateModelId);
|
||||
xhpcTerminal.setNumber(number);
|
||||
xhpcTerminal.setConnectorType(conType);
|
||||
xhpcTerminalMapper.addXhpcTerminal(xhpcTerminal);
|
||||
|
||||
//获取场站名称:
|
||||
@ -156,7 +157,7 @@ public class XhpcChargingPileServiceImpl implements IXhpcChargingPileService {
|
||||
Long chargingStationId = xhpcChargingPile.getChargingStationId();
|
||||
if (xhpcChargingPile.getGunNumber() > 0) {
|
||||
for (int i = 1; i <= xhpcChargingPile.getGunNumber(); i++) {
|
||||
addXhpcTerminal(xhpcChargingPile.getName(), chargingStationId, rateModelId, serialNumber, chargingPileId, i,number+1);
|
||||
addXhpcTerminal(xhpcChargingPile.getName(), chargingStationId, rateModelId, serialNumber, chargingPileId, i, number + 1, xhpcChargingPile.getConnectorType());
|
||||
}
|
||||
}
|
||||
//插入redis 桩的编号
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user