Merge branch 'dev-new' into dev-new-rabbitmq

# Conflicts:
#	jsowell-admin/src/test/java/SpringBootTestController.java
This commit is contained in:
Guoqs
2024-11-19 17:13:09 +08:00
12 changed files with 364 additions and 64 deletions

View File

@@ -18,6 +18,7 @@ import com.jsowell.pile.vo.PileReservationInfoVO;
import com.jsowell.pile.vo.uniapp.customer.PersonPileConnectorSumInfoVO;
import com.jsowell.pile.vo.uniapp.customer.PersonPileRealTimeVO;
import com.jsowell.pile.vo.uniapp.customer.PersonalPileInfoVO;
import com.jsowell.service.OrderService;
import com.jsowell.service.PileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -39,6 +40,9 @@ public class PersonPileController extends BaseController {
@Autowired
private PileService pileService;
@Autowired
private OrderService orderService;
@Autowired
private PileMerchantInfoService pileMerchantInfoService;
@@ -268,7 +272,7 @@ public class PersonPileController extends BaseController {
try {
String memberId = getMemberIdByAuthorization(request);
dto.setMemberId(memberId);
PageResponse chargingRecord = pileService.getChargingRecord(dto);
PageResponse chargingRecord = pileService.getChargingRecordV2(dto);
response = new RestApiResponse<>(chargingRecord);
} catch (BusinessException e) {
logger.error("获取个人桩充电记录 error", e);
@@ -482,4 +486,27 @@ public class PersonPileController extends BaseController {
logger.info("根据充电桩查询预约状态params:{}, result:{}", dto, JSON.toJSONString(response));
return response;
}
/**
* 保存蓝牙充电记录
* http://localhost:8080/uniapp/personalPile/saveBluetoothChargingRecord
*/
@PostMapping("/saveBluetoothChargingRecord")
public RestApiResponse<?> saveBluetoothChargingRecord(HttpServletRequest request, @RequestBody BluetoothChargingRecordDTO dto) {
RestApiResponse<?> response = null;
try {
String memberId = getMemberIdByAuthorization(request);
dto.setMemberId(memberId);
orderService.saveBluetoothChargingRecord(dto);
response = new RestApiResponse<>();
} catch (BusinessException e) {
logger.error("保存蓝牙充电记录error, params:{}", dto, e);
response = new RestApiResponse<>(e.getCode(), e.getMessage());
} catch (Exception e) {
logger.error("保存蓝牙充电记录error, params:{}", dto, e);
response = new RestApiResponse<>(ReturnCodeEnum.CODE_QUERY_RESERVATION_STATUS_ERROR);
}
logger.info("保存蓝牙充电记录params:{}, result:{}", dto, JSON.toJSONString(response));
return response;
}
}

View File

@@ -1445,4 +1445,11 @@ public class OrderService {
// }
return true;
}
/**
* 保存蓝牙充电记录
* @param dto
*/
public void saveBluetoothChargingRecord(BluetoothChargingRecordDTO dto) {
}
}

View File

@@ -86,6 +86,9 @@ public class PileService {
@Autowired
private PileReservationInfoService pileReservationInfoService;
@Autowired
private PersonalChargingRecordService personalChargingRecordService;
/**
* 查询设备信息
*
@@ -570,20 +573,6 @@ public class PileService {
if (CollectionUtils.isEmpty(accumulativeInfo)) {
throw new BusinessException(ReturnCodeEnum.CODE_QUERY_ORDER_INFO_IS_NULL);
}
// BigDecimal sumChargingTime = BigDecimal.ZERO;
// BigDecimal sumUsedElectricity = BigDecimal.ZERO;
// // 将返回的结果进行for循环将总充电量、总充电时长进行累加充电时长需要通过 充电开始时间 和 充电结束时间 进行计算)
// for (PersonPileConnectorSumInfoVO personPileConnectorSumInfoVO : accumulativeInfo) {
// if (StringUtils.isNotBlank(personPileConnectorSumInfoVO.getChargeStartTime()) && StringUtils.isNotBlank(personPileConnectorSumInfoVO.getChargeEndTime())){
// long longChargingTime = DateUtils.intervalTime(personPileConnectorSumInfoVO.getChargeStartTime(), personPileConnectorSumInfoVO.getChargeEndTime());
// BigDecimal chargingTime = new BigDecimal(String.valueOf(longChargingTime));
// sumChargingTime = sumChargingTime.add(chargingTime);
// }
// BigDecimal chargingDegree = StringUtils.isBlank(personPileConnectorSumInfoVO.getSumChargingDegree())
// ? BigDecimal.ZERO
// : new BigDecimal(personPileConnectorSumInfoVO.getSumChargingDegree());
// sumUsedElectricity = sumUsedElectricity.add(chargingDegree);
// }
Map<String, String> sumInfo = getSumInfo(accumulativeInfo);
// set 对象
PersonPileConnectorSumInfoVO vo = new PersonPileConnectorSumInfoVO();
@@ -632,6 +621,45 @@ public class PileService {
.build();
}
public PageResponse getChargingRecordV2(QueryPersonPileDTO dto) {
int pageNum = dto.getPageNum() == 0 ? 1 : dto.getPageNum();
int pageSize = dto.getPageSize() == 0 ? 10 : dto.getPageSize();
// 获取三十天前的数据
Date date = DateUtils.addMonths(new Date(), -1);
String dateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, date);
dto.setStartTime(dateStr);
dto.setEndTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, new Date()));
// 分页查询
PageHelper.startPage(pageNum, pageSize);
List<PersonalChargingRecord> personalChargingRecordList = personalChargingRecordService.getPersonalChargingRecord(dto);
if (CollectionUtils.isEmpty(personalChargingRecordList)) {
throw new BusinessException(ReturnCodeEnum.CODE_QUERY_ORDER_INFO_IS_NULL);
}
PageInfo<PersonalChargingRecord> pageInfo = new PageInfo<>(personalChargingRecordList);
List<PersonPileConnectorSumInfoVO> list = Lists.newArrayList();
PersonPileConnectorSumInfoVO vo;
for (PersonalChargingRecord personalChargingRecord : pageInfo.getList()) {
vo = new PersonPileConnectorSumInfoVO();
if (personalChargingRecord.getChargeStartTime() != null && personalChargingRecord.getChargeEndTime() != null){
vo.setChargeStartTime(DateUtils.dateTime(personalChargingRecord.getChargeStartTime()));
vo.setChargeEndTime(DateUtils.dateTime(personalChargingRecord.getChargeEndTime()));
String datePoor = DateUtils.getDatePoor(personalChargingRecord.getChargeEndTime(), personalChargingRecord.getChargeStartTime());
vo.setSumChargingTime(datePoor);
}
vo.setMemberId(personalChargingRecord.getMemberId());
vo.setSumChargingDegree(personalChargingRecord.getTotalUsedElectricity().toString());
list.add(vo);
}
return PageResponse.builder()
.pageNum(pageInfo.getPageNum())
.pageSize(pageInfo.getPageSize())
.list(list)
.pages(pageInfo.getPages())
.total(pageInfo.getTotal())
.build();
}
/**
* 获取总充电时长、总充电量
*

View File

@@ -277,41 +277,17 @@ public class SpringBootTestController {
@Qualifier("zhongDianLianPlatformServiceImpl")
private ThirdPartyPlatformService platformLogic;
@Test
public void sendRabbitMqTest() {
OrderBasicInfo orderBasicInfo = OrderBasicInfo.builder()
.orderCode("C123456789")
.merchantId("1")
.stationId("2")
.payAmount(new BigDecimal(100))
.orderAmount(new BigDecimal(100))
.settleAmount(new BigDecimal(100))
.refundAmount(new BigDecimal(0))
.build();
OrderDetail orderDetail = OrderDetail.builder()
.totalElectricityAmount(new BigDecimal(50))
.discountElectricityAmount(new BigDecimal(0))
.totalServiceAmount(new BigDecimal(50))
.discountElectricityAmount(new BigDecimal(0))
.build();
AfterSettleOrderDTO afterSettleOrderDTO = AfterSettleOrderDTO.builder()
.orderCode(orderBasicInfo.getOrderCode())
.merchantId(orderBasicInfo.getMerchantId())
.stationId(orderBasicInfo.getStationId())
.orderPayAmount(orderBasicInfo.getPayAmount())
.orderConsumeAmount(orderBasicInfo.getOrderAmount())
.orderSettleAmount(orderBasicInfo.getSettleAmount())
.orderElectricityAmount(orderDetail.getTotalElectricityAmount())
.orderElectricityDiscountAmount(orderDetail.getDiscountElectricityAmount())
.orderServiceAmount(orderDetail.getTotalServiceAmount())
.orderServiceDiscountAmount(orderDetail.getDiscountServiceAmount())
.orderRefundAmount(orderBasicInfo.getRefundAmount())
.build();
for (int i = 0; i < 10; i++) {
rabbitTemplate.convertAndSend(RabbitConstants.YKC_EXCHANGE_NAME, RabbitConstants.QUEUE_CHARGE_ORDER_DATA, afterSettleOrderDTO);
}
public void saveSOCTest() {
String transactionCode = "12345";
YKCUtils.saveSOC(transactionCode, "4");
YKCUtils.saveSOC(transactionCode, "1");
YKCUtils.saveSOC(transactionCode, "3");
YKCUtils.saveSOC(transactionCode, "5");
YKCUtils.saveSOC(transactionCode, "10");
YKCUtils.saveSOC(transactionCode, "20");
YKCUtils.saveSOC(transactionCode, "19.9");
YKCUtils.saveSOC(transactionCode, "29.9");
System.out.println(redisCache.getCacheMap(CacheConstants.GET_THE_SOC + transactionCode));
}
@Test
@@ -351,6 +327,43 @@ public class SpringBootTestController {
Map<String, String> pileStatusV2 = pileConnectorInfoService.getPileStatusV2(pileSnList);
}
@Test
public void sendRabbitMqTest() {
OrderBasicInfo orderBasicInfo = OrderBasicInfo.builder()
.orderCode("C123456789")
.merchantId("1")
.stationId("2")
.payAmount(new BigDecimal(100))
.orderAmount(new BigDecimal(100))
.settleAmount(new BigDecimal(100))
.refundAmount(new BigDecimal(0))
.build();
OrderDetail orderDetail = OrderDetail.builder()
.totalElectricityAmount(new BigDecimal(50))
.discountElectricityAmount(new BigDecimal(0))
.totalServiceAmount(new BigDecimal(50))
.discountElectricityAmount(new BigDecimal(0))
.build();
AfterSettleOrderDTO afterSettleOrderDTO = AfterSettleOrderDTO.builder()
.orderCode(orderBasicInfo.getOrderCode())
.merchantId(orderBasicInfo.getMerchantId())
.stationId(orderBasicInfo.getStationId())
.orderPayAmount(orderBasicInfo.getPayAmount())
.orderConsumeAmount(orderBasicInfo.getOrderAmount())
.orderSettleAmount(orderBasicInfo.getSettleAmount())
.orderElectricityAmount(orderDetail.getTotalElectricityAmount())
.orderElectricityDiscountAmount(orderDetail.getDiscountElectricityAmount())
.orderServiceAmount(orderDetail.getTotalServiceAmount())
.orderServiceDiscountAmount(orderDetail.getDiscountServiceAmount())
.orderRefundAmount(orderBasicInfo.getRefundAmount())
.build();
for (int i = 0; i < 10; i++) {
rabbitTemplate.convertAndSend(RabbitConstants.YKC_EXCHANGE_NAME, RabbitConstants.QUEUE_CHARGE_ORDER_DATA, afterSettleOrderDTO);
}
}
@Test
public void getEBikePileSnTest() {
List<String> strings = pileSnGenerateService.generateEBikeSN(8);

View File

@@ -47,6 +47,9 @@ public class CacheConstants {
// 缓存时间 30天
public static final int cache_expire_time_30d = cache_expire_time_1d * 30;
// 获取SOC
public static final String GET_THE_SOC = "GET_THE_SOC:";
// 第三方平台密钥配置
public static final String THIRD_PARTY_SECRET_INFO_BY_ID = "third_party_secret_info_by_id:";
public static final String THIRD_PARTY_SECRET_INFO_BY_TYPE = "third_party_secret_info_by_type:";

View File

@@ -7,6 +7,7 @@ import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.ykc.YKCBaseMessage;
import com.jsowell.common.core.domain.ykc.YKCDataProtocol;
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.core.redis.StaticRedisCache;
import com.jsowell.common.enums.ykc.PileChannelEntity;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
@@ -16,6 +17,7 @@ import lombok.extern.slf4j.Slf4j;
import java.math.BigDecimal;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@Slf4j
public class YKCUtils {
@@ -135,14 +137,6 @@ public class YKCUtils {
return Bytes.concat(headBytes, BytesUtil.intToBytes(dataFields.length, 1), dataFields, BytesUtil.intToBytes(crc16));
}
public static void main(String[] args) {
String type = "0x3B";
System.out.println(type);
byte[] bytes = BytesUtil.hexString2Bytes(type.replace("0x", ""));
System.out.println(YKCUtils.frameType2Str(bytes));
}
/**
* 保存桩最后链接到平台的时间
* @param pileSn 桩编号
@@ -337,4 +331,53 @@ public class YKCUtils {
return map.get("connectorCode");
}
/**
* 保存soc
* @param transactionCode
* @param soc
*/
public static void saveSOC(String transactionCode, String soc) {
if (StringUtils.isBlank(transactionCode) || Double.parseDouble(soc) <= 0) {
return;
}
String hashKey = CacheConstants.GET_THE_SOC + transactionCode;
RedisCache staticRedisCache = StaticRedisCache.staticRedisCache;
try {
// 检查值是否符合要求
if (!soc.matches("^-?\\d+(\\.\\d{1})?$")) {
throw new IllegalArgumentException("输入的值必须是一个最多有一位小数的数字: " + soc);
}
double doubleValue = Double.parseDouble(soc);
// 获取当前的最小值和最大值
String currentMin = (String) staticRedisCache.hget(hashKey, "min");
String currentMax = (String) staticRedisCache.hget(hashKey, "max");
double min = currentMin != null ? Double.parseDouble(currentMin) : Double.MAX_VALUE;
double max = currentMax != null ? Double.parseDouble(currentMax) : Double.MIN_VALUE;
// 更新最小值或最大值
if (doubleValue < min) {
staticRedisCache.hset(hashKey, "min", soc, 7, TimeUnit.DAYS);
}
if (doubleValue > max) {
staticRedisCache.hset(hashKey, "max", soc, 7, TimeUnit.DAYS);
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 根据的交易码获取当前soc
* @param transactionCode
*/
public static String getCurrentSOC(String transactionCode) {
String hashKey = CacheConstants.GET_THE_SOC + transactionCode;
RedisCache staticRedisCache = StaticRedisCache.staticRedisCache;
Map<String, Object> cacheMap = staticRedisCache.getCacheMap(hashKey);
// 获取最小值和最大值, 两个值中最大的为当前soc
return (String) cacheMap.get("max");
}
}

View File

@@ -0,0 +1,138 @@
package com.jsowell.pile.dto;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* 蓝牙充电记录
*/
@Data
public class BluetoothChargingRecordDTO {
// 会员id
private String memberId;
// 充电流水号
@JsonProperty(value = "TrxSN")
private String trxSN;
// 桩号
@JsonProperty(value = "PileNo")
private String pileNo;
// 枪号
@JsonProperty(value = "PlugNo")
private String plugNo;
// 启动充电时间
@JsonProperty(value = "StartTime")
private String startTime;
// 结束充电时间
@JsonProperty(value = "EndTime")
private String endTime;
// 尖单价
@JsonProperty(value = "PriceSharp")
private String priceSharp;
// 尖电量
@JsonProperty(value = "EnergySharp")
private String energySharp;
// 记损尖电量
@JsonProperty(value = "LossKwhSharp")
private String lossKwhSharp;
// 尖金额
@JsonProperty(value = "MoneySharp")
private String moneySharp;
// 峰单价
@JsonProperty(value = "PricePeak")
private String pricePeak;
// 峰电量
@JsonProperty(value = "EnergyPeak")
private String energyPeak;
// 记损峰电量
@JsonProperty(value = "LossKwhPeak")
private String lossKwhPeak;
// 峰金额
@JsonProperty(value = "MoneyPeak")
private String moneyPeak;
// 平单价
@JsonProperty(value = "PriceFlat")
private String priceFlat;
// 平电量
@JsonProperty(value = "EnergyFlat")
private String energyFlat;
// 记损平电量
@JsonProperty(value = "LossKwhFlat")
private String lossKwhFlat;
// 平金额
@JsonProperty(value = "MoneyFlat")
private String moneyFlat;
// 谷单价
@JsonProperty(value = "PriceValley")
private String priceValley;
// 谷电量
@JsonProperty(value = "EnergyValley")
private String energyValley;
// 记损谷电量
@JsonProperty(value = "LossKwhValley")
private String lossKwhValley;
// 谷金额
@JsonProperty(value = "MoneyValley")
private String moneyValley;
// 电表总起值
@JsonProperty(value = "StartKwh")
private String startKwh;
// 电表总止值
@JsonProperty(value = "StopKwh")
private String stopKwh;
// 总电量
@JsonProperty(value = "TotalEnergy")
private String totalEnergy;
// 记损总电量
@JsonProperty(value = "LossTotalKwh")
private String lossTotalKwh;
// 消费金额
@JsonProperty(value = "TotalMoney")
private String totalMoney;
// 电动汽车唯一标识
@JsonProperty(value = "VIN")
private String vin;
// 电动汽车唯一标识
@JsonProperty(value = "StartMode")
private String startMode;
// 交易日期时间
@JsonProperty(value = "TradeTime")
private String tradeTime;
// 停止原因
@JsonProperty(value = "StopReason")
private String stopReason;
// 物理卡号
@JsonProperty(value = "PCardID")
private String pCardID;
}

View File

@@ -1,9 +1,11 @@
package com.jsowell.pile.mapper;
import com.jsowell.pile.domain.PersonalChargingRecord;
import java.util.List;
import com.jsowell.pile.dto.QueryPersonPileDTO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface PersonalChargingRecordMapper {
int deleteByPrimaryKey(Integer id);
@@ -28,4 +30,6 @@ public interface PersonalChargingRecordMapper {
int batchInsert(@Param("list") List<PersonalChargingRecord> list);
PersonalChargingRecord selectByTransactionCode(String transactionCode);
List<PersonalChargingRecord> getPersonalChargingRecord(QueryPersonPileDTO dto);
}

View File

@@ -1,10 +1,11 @@
package com.jsowell.pile.service;
import java.util.List;
import com.jsowell.common.core.domain.ykc.TransactionRecordsData;
import com.jsowell.pile.domain.OrderBasicInfo;
import com.jsowell.pile.domain.PersonalChargingRecord;
import com.jsowell.pile.dto.QueryPersonPileDTO;
import java.util.List;
public interface PersonalChargingRecordService{
@@ -38,4 +39,9 @@ public interface PersonalChargingRecordService{
void processPersonalChargingRecord(TransactionRecordsData data);
void processPersonalChargingRecord(OrderBasicInfo orderBasicInfo);
/**
* 获取个人桩充电记录
*/
List<PersonalChargingRecord> getPersonalChargingRecord(QueryPersonPileDTO dto);
}

View File

@@ -4,16 +4,18 @@ import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.ykc.TransactionRecordsData;
import com.jsowell.common.util.DateUtils;
import com.jsowell.pile.domain.OrderBasicInfo;
import com.jsowell.pile.domain.PersonalChargingRecord;
import com.jsowell.pile.domain.PileBasicInfo;
import com.jsowell.pile.dto.QueryPersonPileDTO;
import com.jsowell.pile.mapper.PersonalChargingRecordMapper;
import com.jsowell.pile.service.PersonalChargingRecordService;
import com.jsowell.pile.service.PileBasicInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import com.jsowell.pile.mapper.PersonalChargingRecordMapper;
import com.jsowell.pile.domain.PersonalChargingRecord;
import com.jsowell.pile.service.PersonalChargingRecordService;
@Service
public class PersonalChargingRecordServiceImpl implements PersonalChargingRecordService{
@@ -177,4 +179,9 @@ public class PersonalChargingRecordServiceImpl implements PersonalChargingRecord
personalChargingRecordMapper.insertOrUpdateSelective(chargingRecord);
}
@Override
public List<PersonalChargingRecord> getPersonalChargingRecord(QueryPersonPileDTO dto) {
return personalChargingRecordMapper.getPersonalChargingRecord(dto);
}
}

View File

@@ -1220,4 +1220,15 @@
where del_flag = '0'
and transaction_code = #{transactionCode,jdbcType=VARCHAR}
</select>
<select id="getPersonalChargingRecord" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from personal_charging_record
where del_flag = '0'
and pile_connector_code = #{pileConnectorCode,jdbcType=VARCHAR}
AND create_time <![CDATA[ >= ]]> #{startTime,jdbcType=VARCHAR}
AND create_time <![CDATA[ <= ]]> #{endTime,jdbcType=VARCHAR}
order by create_time desc
</select>
</mapper>

View File

@@ -0,0 +1,13 @@
package com.jsowell.thirdparty.platform.service.impl;
import org.springframework.stereotype.Service;
/**
* 订单算法平台Service
*
* @author Lemon
* @Date 2024/11/19 13:49:45
*/
@Service
public class ChargeAlgorithmService {
}