根据慧鹏站的 车牌号和站点code生成车辆信息和预约单信息
This commit is contained in:
parent
ee953896c9
commit
ad9fdb60e4
@ -128,7 +128,7 @@ public class RedisPermissionUtils {
|
||||
private static Object getRedisObjectValue(String key) {
|
||||
String token = SpringUtil.getToken();
|
||||
if(StringUtils.isEmpty(token)){
|
||||
log.error("SpringUtil.getRedisValue========== token is null");
|
||||
// log.info("SpringUtil.getRedisValue========== token is null");
|
||||
return null;
|
||||
}
|
||||
String jti = null;
|
||||
@ -163,9 +163,6 @@ public class RedisPermissionUtils {
|
||||
*/
|
||||
private static Object getValue(String key){
|
||||
RedisUtil redisUtil = SpringUtil.getBean(RedisUtil.class);
|
||||
if(ObjectUtils.isEmpty(redisUtil)){
|
||||
log.error("SpringUtil.getRedisValue========== redisUtil is null");
|
||||
}
|
||||
Object obj = redisUtil.get(key);
|
||||
if(ObjectUtils.isEmpty(obj)){
|
||||
log.error("SpringUtil.getRedisValue=={}========== obj is null",key);
|
||||
|
||||
@ -4,13 +4,17 @@ import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.evotech.hd.cloud.dao.BatteryStationDao;
|
||||
import com.evotech.hd.cloud.dao.OrderSwapBatteryPreDao;
|
||||
import com.evotech.hd.cloud.dao.VehicleWechatUserRelationDao;
|
||||
import com.evotech.hd.cloud.device.dh.DHRequestUtil;
|
||||
import com.evotech.hd.cloud.mqtt.message.processor.impl.MqttStateChargingDataRequestExchangeProcessor;
|
||||
import com.evotech.hd.cloud.mqtt.message.MessageTopic;
|
||||
import com.evotech.hd.cloud.mqtt.message.MqttMessageHeader;
|
||||
import com.evotech.hd.cloud.mqtt.message.processor.MqttRequestExchangeProcessor;
|
||||
import com.evotech.hd.cloud.mqtt.message.processor.impl.state.MqttStateChargingDataRequestExchangeProcessor;
|
||||
import com.evotech.hd.cloud.utils.components.SwapOrderBasicFeeComponent;
|
||||
import com.evotech.hd.common.core.entity.Result;
|
||||
import com.evotech.hd.common.core.entity.cloud.BatteryStation;
|
||||
@ -18,10 +22,13 @@ import com.evotech.hd.common.core.entity.cloud.OrderSwapBattery;
|
||||
import com.evotech.hd.common.core.entity.cloud.OrderSwapBatteryPre;
|
||||
import com.evotech.hd.common.core.utils.Collections;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @desc:
|
||||
@ -44,6 +51,10 @@ public class TestController {
|
||||
private SwapOrderBasicFeeComponent orderBasicFeeComponent;
|
||||
@Resource
|
||||
MqttStateChargingDataRequestExchangeProcessor mqttStateChargingDataRequestExchangeProcessor;
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
// @Resource
|
||||
// VehicleService vehicleService;
|
||||
// @Resource
|
||||
// MongoDBService mongoDBService;
|
||||
|
||||
@ -60,6 +71,26 @@ public class TestController {
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/mqtt/test")
|
||||
public Result mqttTest(@RequestBody JSONObject json) {
|
||||
MessageTopic topic = new MessageTopic();
|
||||
topic.setDataDirection(json.getString("dataDirection"));
|
||||
topic.setMessageType(json.getString("messageType"));
|
||||
topic.setStationCode(json.getString("stationCode"));
|
||||
MqttMessageHeader header = new MqttMessageHeader();
|
||||
header.setFunction(json.getString("function"));
|
||||
cn.hutool.json.JSONObject dataBody = JSONUtil.parseObj(json.getJSONObject("dataBoy"));
|
||||
|
||||
Map<String, MqttRequestExchangeProcessor> mqttMessageRequestExchangeProcessorMap = applicationContext.getBeansOfType(MqttRequestExchangeProcessor.class);
|
||||
for (MqttRequestExchangeProcessor processor : mqttMessageRequestExchangeProcessorMap.values()) {
|
||||
if(processor.accept(header.getFunction())){
|
||||
processor.exchange(topic, header, dataBody);
|
||||
}
|
||||
}
|
||||
return new Result().success("搞定");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("/station")
|
||||
public Result list() {
|
||||
|
||||
@ -12,13 +12,14 @@ import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
//@Component
|
||||
@Component
|
||||
@Order(value = 20)
|
||||
@Slf4j
|
||||
public class MqttConnectInit implements ApplicationRunner {
|
||||
|
||||
@ -31,7 +31,9 @@ public enum RequestFunctionTypesEnum {
|
||||
FUN_ORDERBYPLATENUM("orderByPlateNum", "orderByPlateNumResponse", "站端用车牌号查询订单"),
|
||||
FUN_CANCELORDER("cancelOrder", "cancelOrderResponse", "站端取消订单"),
|
||||
FUN_STARTSWAP("BatterySwapReq", "BatterySwapResponse", "站端回复开始换电"),
|
||||
FUN_STRATEGY_INFO("strategyInfo", "strategyInfoResponse", "站端查询充电策略");
|
||||
FUN_STRATEGY_INFO("strategyInfo", "strategyInfoResponse", "站端查询充电策略"),
|
||||
FUN_PUSH_CAR_INFO("pushCarInfo", "pushCarInfoResponse", "根据车牌号创建车辆信息和预约单并返回状态信息"),
|
||||
;
|
||||
|
||||
String function;
|
||||
String reFunction;
|
||||
|
||||
@ -0,0 +1,71 @@
|
||||
package com.evotech.hd.cloud.mqtt.message.processor.impl.request;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.evotech.hd.cloud.mqtt.enums.RequestFunctionTypesEnum;
|
||||
import com.evotech.hd.cloud.mqtt.message.MessageTopic;
|
||||
import com.evotech.hd.cloud.mqtt.message.MqttMessageHeader;
|
||||
import com.evotech.hd.cloud.mqtt.message.dto.newer.req.MqttResponse;
|
||||
import com.evotech.hd.cloud.mqtt.message.processor.MqttRequestExchangeProcessor;
|
||||
import com.evotech.hd.cloud.service.OrderSwapBatteryService;
|
||||
import com.evotech.hd.cloud.service.VehicleService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* 接收站端推送的车牌照, 创建车辆信息和预约单
|
||||
*
|
||||
* @ClassName:MqttRequestPushCarCreateMakeAppointmentExchangeProcessorImpl
|
||||
* @date: 2025年04月30日 15:34
|
||||
* @author: andy.shi
|
||||
* @contact: 17330188597
|
||||
* @remark: 开发人员联系方式 1042025947@qq.com/微信同步
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class MqttRequestPushCarCreateMakeAppointmentExchangeProcessorImpl implements MqttRequestExchangeProcessor {
|
||||
|
||||
@Resource
|
||||
VehicleService vehicleService;
|
||||
@Resource
|
||||
OrderSwapBatteryService orderSwapBatteryService;
|
||||
|
||||
@Override
|
||||
public boolean accept(String functionName) {
|
||||
return RequestFunctionTypesEnum.FUN_PUSH_CAR_INFO.getFunction().equals(functionName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exchange(MessageTopic topic, MqttMessageHeader header, JSONObject dataBody) {
|
||||
log.info("MqttRequestPushCarCreateMakeAppointmentExchangeProcessorImpl-->>>>> 请求参数{}", JSONUtil.toJsonStr(dataBody));
|
||||
String plateNum = dataBody.getStr("licensePlateNumber");
|
||||
Assert.hasText(plateNum, "licensePlateNumber is null");
|
||||
MqttResponse response = null;
|
||||
if(StringUtils.isNotEmpty(plateNum)){
|
||||
if (vehicleService.existsVehicleByPlateNum(plateNum)){
|
||||
response = new MqttResponse().success("车辆已存在, 无需创建");
|
||||
}else{
|
||||
//没有车辆信息, 开始创建
|
||||
if(vehicleService.createVehicleByPlateNum(plateNum, topic.getStationCode())){
|
||||
//创建预约订单
|
||||
if (orderSwapBatteryService.addPreByPlanNum(plateNum, topic.getStationCode())){
|
||||
//返回状态信息
|
||||
response = new MqttResponse().success("车辆初始化完成");
|
||||
}else{
|
||||
response = new MqttResponse().error("车辆初始化完成, 但是预约单创建失败了");
|
||||
}
|
||||
}else{
|
||||
response = new MqttResponse().error("创建车辆信息失败了");
|
||||
}
|
||||
|
||||
}
|
||||
}else{
|
||||
response = new MqttResponse().error("参数不全, 没有车牌号信息");
|
||||
}
|
||||
sendAESMessage(topic, header, RequestFunctionTypesEnum.FUN_PUSH_CAR_INFO, response);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.evotech.hd.cloud.mqtt.message.processor.impl;
|
||||
package com.evotech.hd.cloud.mqtt.message.processor.impl.request;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
@ -26,7 +26,7 @@ import java.util.List;
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class MqttMessageStrategyRequestExchangeProcessorImpl implements MqttRequestExchangeProcessor {
|
||||
public class MqttRequestStrategyExchangeProcessorImpl implements MqttRequestExchangeProcessor {
|
||||
@Resource
|
||||
BatteryStationCdStrategyService batteryStationCdStrategyService;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.evotech.hd.cloud.mqtt.message.processor.impl;
|
||||
package com.evotech.hd.cloud.mqtt.message.processor.impl.state;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.evotech.hd.cloud.mqtt.message.processor.impl;
|
||||
package com.evotech.hd.cloud.mqtt.message.processor.impl.state;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
@ -53,4 +53,7 @@ public interface OrderSwapBatteryService {
|
||||
public Result<BatterySwapResponse> getStartSwap(String wuid, String orderId);
|
||||
|
||||
public Result<Integer> checkList(PageListSwapOrderRequest plsor);
|
||||
|
||||
|
||||
public Boolean addPreByPlanNum(String planNum, String stationCode);
|
||||
}
|
||||
|
||||
@ -28,8 +28,19 @@ public interface VehicleService {
|
||||
public com.evotech.hd.common.core.entity.Result<List<VehicleInfo>> listWechatUserRelation(String openid, String plateNum);
|
||||
|
||||
public com.evotech.hd.common.core.entity.Result<List<VehicleWechatUserRelation>> listRelationUser(String PlantNo);
|
||||
|
||||
public Result<List<VehicleInfo>> loginList(String companyCode);
|
||||
|
||||
|
||||
|
||||
/***
|
||||
* 根据车牌号创建车辆信息
|
||||
* @param plateNum
|
||||
* @return
|
||||
*/
|
||||
public Boolean createVehicleByPlateNum(String plateNum, String stationCode);
|
||||
/***
|
||||
* 根据车牌号查找车辆是否存在
|
||||
* @param plateNum
|
||||
* @return
|
||||
*/
|
||||
public Boolean existsVehicleByPlateNum(String plateNum);
|
||||
}
|
||||
|
||||
@ -668,4 +668,44 @@ public class OrderSwapBatteryServiceImpl implements OrderSwapBatteryService {
|
||||
return new Result<Integer>().success(0);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Boolean addPreByPlanNum(String planNum, String stationCode) {
|
||||
BatteryStation batteryStation = batteryStationDao.selectOne(new LambdaQueryWrapper<BatteryStation>().eq(BatteryStation::getCode, stationCode).select(BatteryStation::getCode, BatteryStation::getName), false);
|
||||
// 3. 添加预约
|
||||
Date day = new Date();
|
||||
OrderSwapBatteryPre osbp = new OrderSwapBatteryPre();
|
||||
osbp.setSource(3);
|
||||
osbp.setSourceId(batteryStation.getCode());
|
||||
osbp.setUcode("hp_station_push");
|
||||
osbp.setUname("慧鹏站端推送");
|
||||
osbp.setPhone("12332112345");
|
||||
osbp.setPlateNum(planNum);
|
||||
osbp.setStationCode(batteryStation.getCode());
|
||||
osbp.setStationName(batteryStation.getName());
|
||||
osbp.setSwapDay(DateUtil.format(day, DatePattern.PURE_DATE_FORMATTER));
|
||||
osbp.setSwapDuration("6:00-20:00");
|
||||
osbp.setStatus(1);
|
||||
osbp.setCtime(osbp.getReservationTime());
|
||||
osbp.setCreater("TEST");
|
||||
osbp.setReservationTime(osbp.getReservationTime() == null ? day : osbp.getReservationTime());
|
||||
osbp.setCtime(day);
|
||||
int n = orderSwapBatteryPreDao.insert(osbp);
|
||||
//特殊渠道反推的数据, 不需要发送通知
|
||||
// if (n == 1) {
|
||||
// // 计算过期时间(预约时间后30分钟)
|
||||
// Date expireTime = DateUtil.offsetMinute(osbp.getReservationTime(), 90);
|
||||
// // 将预约单ID和过期时间存入Redis,设置过期时间为预约时间后30分钟
|
||||
// String redisKey = "preorder:expire:" + osbp.getPkId();
|
||||
// redisUtil.set(redisKey, expireTime);
|
||||
// // 发送服务号消息,没有消息队列,先用接口吧
|
||||
// templateMessageService.preOrderMessageSend(osbp);
|
||||
// return true;
|
||||
// }
|
||||
return true;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,18 +1,28 @@
|
||||
package com.evotech.hd.cloud.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.evotech.hd.cloud.dao.BatteryStationDao;
|
||||
import com.evotech.hd.cloud.dao.CompanyDao;
|
||||
import com.evotech.hd.cloud.dao.VehicleInfoDao;
|
||||
import com.evotech.hd.cloud.dao.VehicleWechatUserRelationDao;
|
||||
import com.evotech.hd.cloud.entity.request.PageListVehicleRequest;
|
||||
import com.evotech.hd.cloud.service.VehicleService;
|
||||
import com.evotech.hd.common.core.Dto.Result;
|
||||
import com.evotech.hd.common.core.dao.resource.CarTypeDao;
|
||||
import com.evotech.hd.common.core.entity.cloud.BatteryStation;
|
||||
import com.evotech.hd.common.core.entity.cloud.Company;
|
||||
import com.evotech.hd.common.core.entity.cloud.VehicleInfo;
|
||||
import com.evotech.hd.common.core.entity.cloud.VehicleWechatUserRelation;
|
||||
import com.evotech.hd.common.core.entity.resource.CarType;
|
||||
import com.evotech.hd.common.core.enums.CodeMsg;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Date;
|
||||
@ -26,6 +36,14 @@ public class VehicleServiceImpl implements VehicleService {
|
||||
private VehicleInfoDao vehicleInfoDao;
|
||||
@Resource
|
||||
private VehicleWechatUserRelationDao vehicleWechatUserRelationDao;
|
||||
@Resource
|
||||
private CompanyDao companyDao;
|
||||
@Resource
|
||||
private BatteryStationDao batteryStationDao;
|
||||
@Resource
|
||||
private CarTypeDao carTypeDao;
|
||||
// 车辆颜色
|
||||
String[] colorArr = {"赤", "橙", "黄", "绿", "青", "蓝", "紫"};
|
||||
|
||||
@Override
|
||||
public com.evotech.hd.common.core.entity.Result<Integer> add(VehicleInfo vi) {
|
||||
@ -155,4 +173,44 @@ public class VehicleServiceImpl implements VehicleService {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Boolean createVehicleByPlateNum(String plateNum, String stationCode) {
|
||||
BatteryStation batteryStation = batteryStationDao.selectOne(new LambdaQueryWrapper<BatteryStation>().eq(BatteryStation::getCode, stationCode).select(BatteryStation::getCarTypeCode), false);
|
||||
String typeCode = (ObjectUtils.isEmpty(batteryStation) ? "" : batteryStation.getCarTypeCode());
|
||||
if(StringUtils.isEmpty(typeCode)){
|
||||
List<CarType> carTypeList = carTypeDao.selectList(new QueryWrapper<CarType>());
|
||||
int random = RandomUtil.randomInt(0, carTypeList.size());
|
||||
CarType ct = carTypeList.get(random);
|
||||
typeCode = ct.getTypeCode();
|
||||
}
|
||||
Date d1 = new Date(); //DateUtil.offsetYear(new Date(), -3);
|
||||
Company company = companyDao.selectById(1);
|
||||
VehicleInfo vi = new VehicleInfo();
|
||||
vi.setTypeCode(typeCode);
|
||||
vi.setVinNo(RandomUtil.randomStringUpper(16));
|
||||
vi.setFrameworkNo(RandomUtil.randomStringUpper(18));
|
||||
vi.setOwnerType(2);
|
||||
vi.setCcode(company.getCcode());
|
||||
vi.setCname(company.getCname());
|
||||
vi.setOwnerId(vi.getCcode());
|
||||
vi.setOwnerName(vi.getCname());
|
||||
vi.setPlateNum(plateNum);
|
||||
vi.setEngineNo(RandomUtil.randomStringUpper(20));
|
||||
vi.setSeatsCount(RandomUtil.randomInt(2, 6));
|
||||
vi.setCarColor(colorArr[RandomUtil.randomInt(0, colorArr.length)]);
|
||||
vi.setCarArea(company.getAddressCity());
|
||||
vi.setProductionDate(DateUtil.format(DateUtil.offsetDay(d1, -RandomUtil.randomInt(30, 120)), DatePattern.PURE_DATE_PATTERN));
|
||||
vi.setPurchaseDate(DateUtil.format(d1, DatePattern.PURE_DATE_PATTERN));
|
||||
vi.setBoardDate(vi.getPurchaseDate());
|
||||
vi.setRegistrationDate(DateUtil.format(d1, DatePattern.PURE_DATE_PATTERN));
|
||||
vi.setDelFlag(0);
|
||||
return vehicleInfoDao.insert(vi) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean existsVehicleByPlateNum(String plateNum) {
|
||||
return vehicleInfoDao.exists(new LambdaQueryWrapper<VehicleInfo>().eq(VehicleInfo::getPlateNum, plateNum).select(VehicleInfo::getPkId));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -424,11 +424,7 @@ public class AddTestData {
|
||||
osbp.setStationCode(station.getCode());
|
||||
osbp.setStationName(station.getName());
|
||||
osbp.setReservationTime(new Date());
|
||||
osbp.setSwapDay(DateUtil.format(day, DatePattern.PURE_DATE_FORMATTER));
|
||||
osbp.setSwapDuration("6:00-20:00");
|
||||
osbp.setStatus(1);
|
||||
osbp.setCtime(osbp.getReservationTime());
|
||||
osbp.setCreater("TEST");
|
||||
|
||||
orderSwapBatteryPreDao.insert(osbp);
|
||||
n++;
|
||||
if (n == 3250) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user