车辆在线查询

This commit is contained in:
attiya 2025-12-05 10:45:04 +08:00
parent cb740c8c90
commit eea1272d42
6 changed files with 81 additions and 40 deletions

View File

@ -23,6 +23,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
@ -118,6 +119,17 @@ public class EbikeBikeOrderController {
return JsonResult.success();
}
// /**
// * 完成巡检工单
// *
// * @return 结果
// */
// @PostMapping("doInspection")
// public JsonResult<?> doInspection() {
// ebikeBikeOrderService.doInspection(inspectionSwapOrderVo);
// return JsonResult.success();
// }
/**
* 生成调度工单
*
@ -201,7 +213,7 @@ public class EbikeBikeOrderController {
}
/**
* 更换电池换电工单用
* 更换电池换电工单用,完成换电工单
*
* @return 操作结果
*/
@ -211,13 +223,25 @@ public class EbikeBikeOrderController {
return JsonResult.success();
}
// /**
// * 完成调度工单
// *
// * @param bikeCode 车辆编号
// * @return 结果
// */
// @GetMapping("bikeDispatch")
// public JsonResult<?> bikeDispatch(@NotNull(message = "车辆编号不能为空") String bikeCode,@NotNull(message = "站点ID不能为空")Long siteId) {
// ebikeBikeOrderService.bikeDispatch(bikeCode,siteId);
// return JsonResult.success();
// }
/**
* 车辆列表工单用
*
* @return 操作结果
*/
@GetMapping("bikeList")
public JsonResult<List<EbikeOrderBikeListDto>> bikeList(@RequestParam("regionId") Long regionId) {
public JsonResult<List<EbikeOrderBikeListDto>> bikeList(@RequestParam("regionId") Long regionId) throws IOException {
List<EbikeOrderBikeListDto> list = ebikeBikeOrderService.bikeList(regionId);
return JsonResult.success(list);
}

View File

@ -82,4 +82,9 @@ public class EbikeOrderBikeListDto implements Serializable {
* 是否有维修工单
*/
private Boolean hasRepairOrder;
/**
* 是否在线
*/
private Boolean online;
}

View File

@ -11,6 +11,7 @@ import com.cdzy.operations.model.vo.InspectionSwapOrderVo;
import com.mybatisflex.core.service.IService;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
/**
@ -103,5 +104,12 @@ public interface EbikeBikeOrderService extends IService<EbikeBikeOrder> {
* @param regionId 运营区ID
* @return 列表
*/
List<EbikeOrderBikeListDto> bikeList(Long regionId);
List<EbikeOrderBikeListDto> bikeList(Long regionId) throws IOException;
/**
* 完成调度
* @param bikeCode 车辆编号
* @param siteId 站点ID
*/
void bikeDispatch(String bikeCode, Long siteId);
}

View File

@ -15,9 +15,12 @@ import com.cdzy.operations.model.vo.EbikeBatteryClaimReturnVo;
import com.cdzy.operations.model.vo.FaultOrderVo;
import com.cdzy.operations.model.vo.InspectionSwapOrderVo;
import com.cdzy.operations.service.EbikeBikeOrderService;
import com.cdzy.operations.utils.EmqxApiClient;
import com.cdzy.operations.utils.GeoCodingUtil;
import com.cdzy.operations.utils.MinioUtil;
import com.cdzy.operations.utils.RedisUtil;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.mybatisflex.core.keygen.impl.SnowFlakeIDKeyGenerator;
import com.mybatisflex.core.query.QueryMethods;
import com.mybatisflex.core.query.QueryWrapper;
@ -29,6 +32,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
@ -416,7 +420,7 @@ public class EbikeBikeOrderServiceImpl extends ServiceImpl<EbikeBikeOrderMapper,
}
@Override
public List<EbikeOrderBikeListDto> bikeList(Long regionId) {
public List<EbikeOrderBikeListDto> bikeList(Long regionId) throws IOException {
QueryWrapper queryWrapper = QueryWrapper.create()
.select(
EBIKE_BIKE_INFO.BIKE_CODE,
@ -470,19 +474,32 @@ public class EbikeBikeOrderServiceImpl extends ServiceImpl<EbikeBikeOrderMapper,
)
.where(EBIKE_BIKE_INFO.REGION_ID.eq(regionId))
.where(EBIKE_BIKE_INFO.STATUS.eq(BikeStatus.LAUNCH))
.where(EBIKE_BIKE_INFO.USAGE_STATUS.ne(BikeUsageStatus.BIND))
.leftJoin(EBIKE_ECU_INFO).on(EBIKE_ECU_INFO.ECU_ID.eq(EBIKE_BIKE_INFO.ECU_ID));
List<EbikeOrderBikeListDto> list = bikeInfoMapper.selectListByQueryAs(queryWrapper, EbikeOrderBikeListDto.class);
List<String> snList = list.stream().map(EbikeOrderBikeListDto::getEcuSn).toList();
Map<String, Object> objectMap = redisUtil.batchGetEcuWithMap(snList);
ObjectNode clientsOnline = EmqxApiClient.isClientsOnline(snList);
list.forEach(e -> {
ResGPSDto resGPSDto = (ResGPSDto) objectMap.get(e.getEcuSn());
if (resGPSDto != null) {
e.setSoc(resGPSDto.getSoc());
}
JsonNode jsonNode = clientsOnline.get(e.getEcuSn());
if (jsonNode != null) {
e.setOnline(Boolean.TRUE);
}else {
e.setOnline(Boolean.FALSE);
}
});
return list;
}
@Override
public void bikeDispatch(String bikeCode, Long siteId) {
}
EbikeBikeInfo checkBikeCode(String bikeCode) {
QueryWrapper queryWrapper = QueryWrapper.create()
.where(EBIKE_BIKE_INFO.BIKE_CODE.eq(bikeCode))

View File

@ -76,37 +76,40 @@ public class EmqxApiClient {
.build();
String response = executeRequest(request);
JsonNode jsonNode = mapper.readValue(response,JsonNode.class);
try {
JsonNode node = jsonNode.get("code");
if (node!=null && node.asInt() != 200) {
return false;
}
}catch (Exception e){
return false;
}
JsonNode jsonNode = mapper.readValue(response, JsonNode.class);
try {
JsonNode node = jsonNode.get("code");
if (node != null && node.asInt() != 200) {
return false;
}
} catch (Exception e) {
return false;
}
return jsonNode.get("connected").asBoolean();
}
// 查询设备在线状态
public static ObjectNode isClientsOnline(List<String> clientsIds) throws IOException {
//TODO:数量问题可以考虑分批处理
Request request = buildClientsRequest("/clients?" ,clientsIds)
Request request = buildClientsRequest("/clients?", clientsIds)
.get()
.build();
String response = executeRequest(request);
JsonNode json = mapper.readValue(response,JsonNode.class);
String data = json.get("data").asText();
List<Map<String,Object>> list = mapper.readValue(data, List.class);
JsonNode json = mapper.readValue(response, JsonNode.class);
JsonNode dataNode = json.get("data");
ObjectNode jsonResult = mapper.createObjectNode();
list.forEach(e->{
boolean connected =(Boolean) e.get("connected");
ArrayNode list = (dataNode != null && dataNode.isArray()) ? (ArrayNode) dataNode : mapper.createArrayNode();
if (list.isEmpty()) {
return jsonResult;
}
list.forEach(e -> {
boolean connected = e.get("connected").asBoolean();
ObjectNode jsonObject = mapper.createObjectNode();
String clientid = (String) e.get("clientid");
String client = e.get("clientid").asText();
jsonObject.put("connected", connected);
jsonObject.put("ecuSn", clientid);
jsonResult.put(clientid,jsonObject);
jsonObject.put("ecuSn", client);
jsonResult.put(client, jsonObject);
});
return jsonResult;
}
@ -143,7 +146,7 @@ public class EmqxApiClient {
// 添加订阅
public void addSubscription(String clientId, String topic, int qos) throws IOException {
ObjectNode json = mapper.createObjectNode();
ObjectNode json = mapper.createObjectNode();
json.put("topic", topic);
json.put("qos", qos);

View File

@ -1,32 +1,16 @@
package com.cdzy.operations;
import com.cdzy.operations.utils.RedisUtil;
import com.mybatisflex.core.keygen.impl.SnowFlakeIDKeyGenerator;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.concurrent.TimeUnit;
@SpringBootTest
class EbikeOperationsApplicationTests {
@Resource
RedisUtil redisUtil;
@Test
void contextLoads(){
SnowFlakeIDKeyGenerator generator = new SnowFlakeIDKeyGenerator();
long nextId = generator.nextId();
redisUtil.saveDispatchOrder(nextId, "2", 5L, TimeUnit.MINUTES);
System.out.println(nextId);
void contextLoads() {
}
@Test
void deleteDispatchOrder(){
redisUtil.deleteDispatchOrder(351467314753310720L);
}
}