cdm100构建、通电、断电功能实现
This commit is contained in:
parent
a5d1f2bdfd
commit
705250d288
@ -0,0 +1,113 @@
|
||||
package com.cdzy.ebikemaintenance.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.cdzy.common.model.CoreResult;
|
||||
import com.cdzy.common.model.JsonResult;
|
||||
import com.cdzy.ebikemaintenance.component.EbikeCoreHandler;
|
||||
import com.cdzy.ebikemaintenance.enums.CmdCode;
|
||||
import com.cdzy.ebikemaintenance.mapper.EbikeErrorMsgMapper;
|
||||
import com.cdzy.ebikemaintenance.model.dto.EbikeBatteryInfoDto;
|
||||
import com.cdzy.ebikemaintenance.model.pojo.EbikeErrorMsg;
|
||||
import com.cdzy.ebikemaintenance.service.EbikeBikeInfoService;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.cdzy.ebikemaintenance.model.pojo.table.EbikeErrorMsgTableDef.EBIKE_ERROR_MSG;
|
||||
|
||||
/**
|
||||
* 电池监控控制层。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-03-26
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/ebikeBattery")
|
||||
public class EbikeBatteryController {
|
||||
|
||||
@Resource
|
||||
private EbikeBikeInfoService bikeInfoService;
|
||||
|
||||
@Resource
|
||||
private EbikeCoreHandler coreHandler;
|
||||
|
||||
@Resource
|
||||
private EbikeErrorMsgMapper errorMsgMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 获取电池定位信息列表
|
||||
* @return 列表
|
||||
*/
|
||||
@GetMapping("list")
|
||||
public JsonResult<?> list() {
|
||||
List<EbikeBatteryInfoDto> list = bikeInfoService.getOperationalBatteryList();
|
||||
return JsonResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 断电
|
||||
* @param ecuSn ecuSn
|
||||
* @return 结果
|
||||
*/
|
||||
@GetMapping("outage")
|
||||
public DeferredResult<JsonResult<?>> outage(@RequestParam(required = true)String ecuSn) {
|
||||
DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时
|
||||
coreHandler.executeCommand(ecuSn, CmdCode.OUTAGE).whenComplete((response, ex) -> {
|
||||
if (ex != null) {
|
||||
CoreResult result = CoreResult.failed(ex.getMessage());
|
||||
deferredResult.setResult(JsonResult.success(result));
|
||||
} else {
|
||||
JSONObject jsonObject = JSONObject.parseObject(response);
|
||||
Integer code = jsonObject.getInteger("code");
|
||||
if (code == 0) {
|
||||
CoreResult success = CoreResult.success();
|
||||
deferredResult.setResult(JsonResult.success(success));
|
||||
} else {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create().where(EBIKE_ERROR_MSG.CODE.eq(code));
|
||||
EbikeErrorMsg ebikeErrorMsg = errorMsgMapper.selectOneByQuery(queryWrapper);
|
||||
CoreResult failed = CoreResult.failed(code, ebikeErrorMsg.getMsg());
|
||||
deferredResult.setResult(JsonResult.success(failed));
|
||||
}
|
||||
}
|
||||
});
|
||||
return deferredResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通电
|
||||
* @param ecuSn ecuSn
|
||||
* @return 结果
|
||||
*/
|
||||
@GetMapping("energize")
|
||||
public DeferredResult<JsonResult<?>> energize(@RequestParam(required = true)String ecuSn) {
|
||||
DeferredResult<JsonResult<?>> deferredResult = new DeferredResult<>(5000L); // 5秒超时
|
||||
coreHandler.executeCommand(ecuSn, CmdCode.ENERGIZE).whenComplete((response, ex) -> {
|
||||
if (ex != null) {
|
||||
CoreResult result = CoreResult.failed(ex.getMessage());
|
||||
deferredResult.setResult(JsonResult.success(result));
|
||||
} else {
|
||||
JSONObject jsonObject = JSONObject.parseObject(response);
|
||||
Integer code = jsonObject.getInteger("code");
|
||||
if (code == 0) {
|
||||
CoreResult success = CoreResult.success();
|
||||
deferredResult.setResult(JsonResult.success(success));
|
||||
} else {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create().where(EBIKE_ERROR_MSG.CODE.eq(code));
|
||||
EbikeErrorMsg ebikeErrorMsg = errorMsgMapper.selectOneByQuery(queryWrapper);
|
||||
CoreResult failed = CoreResult.failed(code, ebikeErrorMsg.getMsg());
|
||||
deferredResult.setResult(JsonResult.success(failed));
|
||||
}
|
||||
}
|
||||
});
|
||||
return deferredResult;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -6,6 +6,16 @@ package com.cdzy.ebikemaintenance.enums;
|
||||
*/
|
||||
public interface CmdCode {
|
||||
|
||||
/**
|
||||
* 通电
|
||||
*/
|
||||
String ENERGIZE = "energize";
|
||||
|
||||
/**
|
||||
* 断电
|
||||
*/
|
||||
String OUTAGE = "outage";
|
||||
|
||||
/**
|
||||
* 寻车指令
|
||||
*/
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
package com.cdzy.ebikemaintenance.model.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 实体类。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-03-26
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class EbikeBatteryInfoDto implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long batteryId;
|
||||
|
||||
private String ecuSn;
|
||||
|
||||
/**
|
||||
* 经度
|
||||
*/
|
||||
private Double longitude;
|
||||
|
||||
/**
|
||||
* 纬度
|
||||
*/
|
||||
private Double latitude;
|
||||
|
||||
/**
|
||||
* 电池电量
|
||||
*/
|
||||
private Integer soc;
|
||||
|
||||
/**
|
||||
* 是否放电
|
||||
*/
|
||||
private String mosState;
|
||||
}
|
||||
@ -35,6 +35,8 @@ public class EbikeBatteryInfo implements Serializable {
|
||||
@Id
|
||||
private String batteryId;
|
||||
|
||||
private String orgId;
|
||||
|
||||
/**
|
||||
* 电池编号
|
||||
*/
|
||||
|
||||
@ -2,6 +2,7 @@ package com.cdzy.ebikemaintenance.service;
|
||||
|
||||
import com.cdzy.common.model.EcuSnDto;
|
||||
import com.cdzy.common.model.JsonResult;
|
||||
import com.cdzy.ebikemaintenance.model.dto.EbikeBatteryInfoDto;
|
||||
import com.cdzy.ebikemaintenance.model.dto.request.*;
|
||||
import com.cdzy.ebikemaintenance.model.dto.response.*;
|
||||
import com.cdzy.ebikemaintenance.model.dto.response.ResEbikeBikeComDto;
|
||||
@ -320,4 +321,10 @@ public interface EbikeBikeInfoService extends IService<EbikeBikeInfo> {
|
||||
* @return 列表
|
||||
*/
|
||||
List<ResEbikeInfoRegionDto> getOperationalBikeListWithGpsByRegionId(List<Long> operationRegionIds);
|
||||
|
||||
/**
|
||||
* 获取电池定位信息
|
||||
* @return 列表
|
||||
*/
|
||||
List<EbikeBatteryInfoDto> getOperationalBatteryList();
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ import com.cdzy.common.utils.CoordinateUtil;
|
||||
import com.cdzy.ebikemaintenance.controller.EbikeInfoCoreController;
|
||||
import com.cdzy.ebikemaintenance.enums.EbikeStatus;
|
||||
import com.cdzy.ebikemaintenance.mapper.*;
|
||||
import com.cdzy.ebikemaintenance.model.dto.EbikeBatteryInfoDto;
|
||||
import com.cdzy.ebikemaintenance.model.dto.EbikeDispatchRecordsDto;
|
||||
import com.cdzy.ebikemaintenance.model.dto.request.*;
|
||||
import com.cdzy.ebikemaintenance.model.dto.response.*;
|
||||
@ -1614,6 +1615,36 @@ public class EbikeBikeInfoServiceImpl extends ServiceImpl<EbikeBikeInfoMapper, E
|
||||
return map.values().stream().toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EbikeBatteryInfoDto> getOperationalBatteryList() {
|
||||
QueryWrapper query = QueryWrapper.create()
|
||||
.select(EBIKE_BATTERY_INFO.BATTERY_ID, EBIKE_ECU_INFO.ECU_SN)
|
||||
.leftJoin(EBIKE_ECU_INFO).on(EBIKE_BIKE_INFO.ECU_ID.eq(EBIKE_ECU_INFO.ECU_ID))
|
||||
.leftJoin(EBIKE_BATTERY_INFO).on(EBIKE_BIKE_INFO.BATTERY_ID.eq(EBIKE_BATTERY_INFO.BATTERY_ID))
|
||||
.where(EBIKE_BIKE_INFO.STATE.in(new String[]{"2", "3", "4"}))
|
||||
.where(EBIKE_BIKE_INFO.IS_IN_WAREHOUSE.eq("0"));
|
||||
List<EbikeBatteryInfoDto> list = ebikeBikeInfoMapper.selectListByQueryAs(query, EbikeBatteryInfoDto.class);
|
||||
if (list == null || list.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
Map<String, EbikeBatteryInfoDto> map = list.stream().filter(entity -> entity.getEcuSn() != null).collect(Collectors.toMap(
|
||||
EbikeBatteryInfoDto::getEcuSn,
|
||||
Function.identity(),
|
||||
(oldVal, newVal) -> newVal // 重复键时覆盖旧值
|
||||
));
|
||||
List<String> strings = map.keySet().stream().toList();
|
||||
List<Object> all = redisUtil.getAll(strings);
|
||||
all.forEach(obj -> {
|
||||
ResGPSDto resGPSDto = JSON.toJavaObject(obj, ResGPSDto.class);
|
||||
EbikeBatteryInfoDto batteryInfoDto = map.get(resGPSDto.getEcuSn());
|
||||
batteryInfoDto.setLatitude(resGPSDto.getLatitude());
|
||||
batteryInfoDto.setLongitude(resGPSDto.getLongitude());
|
||||
batteryInfoDto.setSoc(resGPSDto.getSoc());
|
||||
batteryInfoDto.setMosState(resGPSDto.getMosState()==0?"关闭":"打开");
|
||||
});
|
||||
return map.values().stream().toList();
|
||||
}
|
||||
|
||||
private void modifyMaintenanceStatus(String bikeCode) {
|
||||
//是否存在维修中的订单数据
|
||||
int i = ebikeBikeInfoMapper.selectOrderCount(bikeCode);
|
||||
|
||||
@ -13,6 +13,7 @@ import com.cdzy.ebikemaintenance.utils.RedisUtil;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.geo.Point;
|
||||
|
||||
@ -36,6 +37,8 @@ class EbikeSeversetestApplicationTests {
|
||||
|
||||
@Resource
|
||||
RedisUtil redisUtil;
|
||||
@Autowired
|
||||
private EbikeCmdMapper ebikeCmdMapper;
|
||||
|
||||
|
||||
@Test
|
||||
@ -43,14 +46,24 @@ class EbikeSeversetestApplicationTests {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void addCmd() {
|
||||
EbikeCmd param = new EbikeCmd();
|
||||
param.setCmdCode("outage");
|
||||
param.setDescribe("电池断电");
|
||||
param.setCmdName("电池断电");
|
||||
ebikeCmdMapper.insert(param);
|
||||
System.out.println(param.getCmdId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void addParam() {
|
||||
EbikeParam param = new EbikeParam();
|
||||
param.setParamName("idx");
|
||||
param.setCmdId("271826173502169088");
|
||||
param.setParamName("Dsg");
|
||||
param.setCmdId("329795562900504576");
|
||||
param.setLevel(2);
|
||||
param.setValueType(3);
|
||||
param.setParentId(271827039835688960L);
|
||||
param.setValueType(1);
|
||||
param.setParentId(329796190976593920L);
|
||||
ebikeParamMapper.insert(param);
|
||||
System.out.println(param.getParamId());
|
||||
}
|
||||
@ -58,8 +71,8 @@ class EbikeSeversetestApplicationTests {
|
||||
@Test
|
||||
void addParamValue() {
|
||||
EbikeParamValue paramValue = new EbikeParamValue();
|
||||
paramValue.setParamValue("8");
|
||||
paramValue.setParamId(271827551599529984L);
|
||||
paramValue.setParamValue("0");
|
||||
paramValue.setParamId(329796780322373632L);
|
||||
ebikeParamValueMapper.insert(paramValue);
|
||||
}
|
||||
|
||||
|
||||
@ -1,13 +1,41 @@
|
||||
package com.cdzy.ebikereport;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.cdzy.common.model.EbikeTracking;
|
||||
import com.cdzy.common.model.ResGPSDto;
|
||||
import com.cdzy.common.utils.CoordinateUtil;
|
||||
import com.cdzy.ebikereport.enums.BitSwitch;
|
||||
import com.cdzy.ebikereport.utils.BinaryUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.geo.Point;
|
||||
|
||||
@SpringBootTest
|
||||
class EbikeReportApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
|
||||
Integer number = 131082;
|
||||
String binary = BinaryUtil.to32BitBinary(number);
|
||||
binary = new StringBuilder(binary).reverse().toString();
|
||||
System.out.println(binary);
|
||||
char helmet = binary.charAt(BitSwitch.IS_HELMET_EXIT);
|
||||
char acc = binary.charAt(BitSwitch.ACC_ON);
|
||||
System.out.println(acc);
|
||||
char wheelLocked = binary.charAt(BitSwitch.IS_WHEEL_LOCKED);
|
||||
char setLocked = binary.charAt(BitSwitch.IS_SEAT_LOCKED);
|
||||
char isHelmetLocked = binary.charAt(BitSwitch.IS_HELMET_LOCKED);
|
||||
char isWheelSpin = binary.charAt(BitSwitch.IS_WHEEL_SPIN);
|
||||
char isMoving = binary.charAt(BitSwitch.IS_MOVING);
|
||||
ResGPSDto resGpsDto = new ResGPSDto();
|
||||
resGpsDto.setHelmetExit(helmet);
|
||||
resGpsDto.setAccOn(acc);
|
||||
resGpsDto.setWheelLocked(wheelLocked);
|
||||
resGpsDto.setSeatLocked(setLocked);
|
||||
resGpsDto.setIsHelmetLocked(isHelmetLocked);
|
||||
resGpsDto.setIsWheelSpin(isWheelSpin);
|
||||
resGpsDto.setIsMoving(isMoving);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package com.cdzy.user;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.cdzy.user.model.dto.LoginDto;
|
||||
import com.mybatisflex.codegen.Generator;
|
||||
import com.mybatisflex.codegen.config.GlobalConfig;
|
||||
import com.mybatisflex.core.keygen.impl.SnowFlakeIDKeyGenerator;
|
||||
@ -94,4 +96,11 @@ class EbikeUserApplicationTests {
|
||||
// 返回配置
|
||||
return globalConfig;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTokenSession(){
|
||||
String loginId = StpUtil.getLoginId("kjbSzme9yQvGKVegcfsMDBtCjrgEWvXC");
|
||||
LoginDto object = (LoginDto)StpUtil.getSession().get(loginId);
|
||||
System.out.println(object);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user