车辆在线查询
This commit is contained in:
parent
cb740c8c90
commit
eea1272d42
@ -23,6 +23,7 @@ import org.springframework.validation.annotation.Validated;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@ -118,6 +119,17 @@ public class EbikeBikeOrderController {
|
|||||||
return JsonResult.success();
|
return JsonResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 完成巡检工单。
|
||||||
|
// *
|
||||||
|
// * @return 结果
|
||||||
|
// */
|
||||||
|
// @PostMapping("doInspection")
|
||||||
|
// public JsonResult<?> doInspection() {
|
||||||
|
// ebikeBikeOrderService.doInspection(inspectionSwapOrderVo);
|
||||||
|
// return JsonResult.success();
|
||||||
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成调度工单。
|
* 生成调度工单。
|
||||||
*
|
*
|
||||||
@ -201,7 +213,7 @@ public class EbikeBikeOrderController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更换电池(换电工单用)
|
* 更换电池(换电工单用,完成换电工单)
|
||||||
*
|
*
|
||||||
* @return 操作结果
|
* @return 操作结果
|
||||||
*/
|
*/
|
||||||
@ -211,13 +223,25 @@ public class EbikeBikeOrderController {
|
|||||||
return JsonResult.success();
|
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 操作结果
|
* @return 操作结果
|
||||||
*/
|
*/
|
||||||
@GetMapping("bikeList")
|
@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);
|
List<EbikeOrderBikeListDto> list = ebikeBikeOrderService.bikeList(regionId);
|
||||||
return JsonResult.success(list);
|
return JsonResult.success(list);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -82,4 +82,9 @@ public class EbikeOrderBikeListDto implements Serializable {
|
|||||||
* 是否有维修工单
|
* 是否有维修工单
|
||||||
*/
|
*/
|
||||||
private Boolean hasRepairOrder;
|
private Boolean hasRepairOrder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否在线
|
||||||
|
*/
|
||||||
|
private Boolean online;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import com.cdzy.operations.model.vo.InspectionSwapOrderVo;
|
|||||||
import com.mybatisflex.core.service.IService;
|
import com.mybatisflex.core.service.IService;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -103,5 +104,12 @@ public interface EbikeBikeOrderService extends IService<EbikeBikeOrder> {
|
|||||||
* @param regionId 运营区ID
|
* @param regionId 运营区ID
|
||||||
* @return 列表
|
* @return 列表
|
||||||
*/
|
*/
|
||||||
List<EbikeOrderBikeListDto> bikeList(Long regionId);
|
List<EbikeOrderBikeListDto> bikeList(Long regionId) throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 完成调度
|
||||||
|
* @param bikeCode 车辆编号
|
||||||
|
* @param siteId 站点ID
|
||||||
|
*/
|
||||||
|
void bikeDispatch(String bikeCode, Long siteId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,9 +15,12 @@ import com.cdzy.operations.model.vo.EbikeBatteryClaimReturnVo;
|
|||||||
import com.cdzy.operations.model.vo.FaultOrderVo;
|
import com.cdzy.operations.model.vo.FaultOrderVo;
|
||||||
import com.cdzy.operations.model.vo.InspectionSwapOrderVo;
|
import com.cdzy.operations.model.vo.InspectionSwapOrderVo;
|
||||||
import com.cdzy.operations.service.EbikeBikeOrderService;
|
import com.cdzy.operations.service.EbikeBikeOrderService;
|
||||||
|
import com.cdzy.operations.utils.EmqxApiClient;
|
||||||
import com.cdzy.operations.utils.GeoCodingUtil;
|
import com.cdzy.operations.utils.GeoCodingUtil;
|
||||||
import com.cdzy.operations.utils.MinioUtil;
|
import com.cdzy.operations.utils.MinioUtil;
|
||||||
import com.cdzy.operations.utils.RedisUtil;
|
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.keygen.impl.SnowFlakeIDKeyGenerator;
|
||||||
import com.mybatisflex.core.query.QueryMethods;
|
import com.mybatisflex.core.query.QueryMethods;
|
||||||
import com.mybatisflex.core.query.QueryWrapper;
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
@ -29,6 +32,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -416,7 +420,7 @@ public class EbikeBikeOrderServiceImpl extends ServiceImpl<EbikeBikeOrderMapper,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<EbikeOrderBikeListDto> bikeList(Long regionId) {
|
public List<EbikeOrderBikeListDto> bikeList(Long regionId) throws IOException {
|
||||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||||
.select(
|
.select(
|
||||||
EBIKE_BIKE_INFO.BIKE_CODE,
|
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.REGION_ID.eq(regionId))
|
||||||
.where(EBIKE_BIKE_INFO.STATUS.eq(BikeStatus.LAUNCH))
|
.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));
|
.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<EbikeOrderBikeListDto> list = bikeInfoMapper.selectListByQueryAs(queryWrapper, EbikeOrderBikeListDto.class);
|
||||||
List<String> snList = list.stream().map(EbikeOrderBikeListDto::getEcuSn).toList();
|
List<String> snList = list.stream().map(EbikeOrderBikeListDto::getEcuSn).toList();
|
||||||
Map<String, Object> objectMap = redisUtil.batchGetEcuWithMap(snList);
|
Map<String, Object> objectMap = redisUtil.batchGetEcuWithMap(snList);
|
||||||
|
ObjectNode clientsOnline = EmqxApiClient.isClientsOnline(snList);
|
||||||
list.forEach(e -> {
|
list.forEach(e -> {
|
||||||
ResGPSDto resGPSDto = (ResGPSDto) objectMap.get(e.getEcuSn());
|
ResGPSDto resGPSDto = (ResGPSDto) objectMap.get(e.getEcuSn());
|
||||||
if (resGPSDto != null) {
|
if (resGPSDto != null) {
|
||||||
e.setSoc(resGPSDto.getSoc());
|
e.setSoc(resGPSDto.getSoc());
|
||||||
}
|
}
|
||||||
|
JsonNode jsonNode = clientsOnline.get(e.getEcuSn());
|
||||||
|
if (jsonNode != null) {
|
||||||
|
e.setOnline(Boolean.TRUE);
|
||||||
|
}else {
|
||||||
|
e.setOnline(Boolean.FALSE);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void bikeDispatch(String bikeCode, Long siteId) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
EbikeBikeInfo checkBikeCode(String bikeCode) {
|
EbikeBikeInfo checkBikeCode(String bikeCode) {
|
||||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||||
.where(EBIKE_BIKE_INFO.BIKE_CODE.eq(bikeCode))
|
.where(EBIKE_BIKE_INFO.BIKE_CODE.eq(bikeCode))
|
||||||
|
|||||||
@ -76,13 +76,13 @@ public class EmqxApiClient {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
String response = executeRequest(request);
|
String response = executeRequest(request);
|
||||||
JsonNode jsonNode = mapper.readValue(response,JsonNode.class);
|
JsonNode jsonNode = mapper.readValue(response, JsonNode.class);
|
||||||
try {
|
try {
|
||||||
JsonNode node = jsonNode.get("code");
|
JsonNode node = jsonNode.get("code");
|
||||||
if (node!=null && node.asInt() != 200) {
|
if (node != null && node.asInt() != 200) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return jsonNode.get("connected").asBoolean();
|
return jsonNode.get("connected").asBoolean();
|
||||||
@ -91,22 +91,25 @@ public class EmqxApiClient {
|
|||||||
// 查询设备在线状态
|
// 查询设备在线状态
|
||||||
public static ObjectNode isClientsOnline(List<String> clientsIds) throws IOException {
|
public static ObjectNode isClientsOnline(List<String> clientsIds) throws IOException {
|
||||||
//TODO:数量问题可以考虑分批处理
|
//TODO:数量问题可以考虑分批处理
|
||||||
Request request = buildClientsRequest("/clients?" ,clientsIds)
|
Request request = buildClientsRequest("/clients?", clientsIds)
|
||||||
.get()
|
.get()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
String response = executeRequest(request);
|
String response = executeRequest(request);
|
||||||
JsonNode json = mapper.readValue(response,JsonNode.class);
|
JsonNode json = mapper.readValue(response, JsonNode.class);
|
||||||
String data = json.get("data").asText();
|
JsonNode dataNode = json.get("data");
|
||||||
List<Map<String,Object>> list = mapper.readValue(data, List.class);
|
|
||||||
ObjectNode jsonResult = mapper.createObjectNode();
|
ObjectNode jsonResult = mapper.createObjectNode();
|
||||||
list.forEach(e->{
|
ArrayNode list = (dataNode != null && dataNode.isArray()) ? (ArrayNode) dataNode : mapper.createArrayNode();
|
||||||
boolean connected =(Boolean) e.get("connected");
|
if (list.isEmpty()) {
|
||||||
|
return jsonResult;
|
||||||
|
}
|
||||||
|
list.forEach(e -> {
|
||||||
|
boolean connected = e.get("connected").asBoolean();
|
||||||
ObjectNode jsonObject = mapper.createObjectNode();
|
ObjectNode jsonObject = mapper.createObjectNode();
|
||||||
String clientid = (String) e.get("clientid");
|
String client = e.get("clientid").asText();
|
||||||
jsonObject.put("connected", connected);
|
jsonObject.put("connected", connected);
|
||||||
jsonObject.put("ecuSn", clientid);
|
jsonObject.put("ecuSn", client);
|
||||||
jsonResult.put(clientid,jsonObject);
|
jsonResult.put(client, jsonObject);
|
||||||
});
|
});
|
||||||
return jsonResult;
|
return jsonResult;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,32 +1,16 @@
|
|||||||
package com.cdzy.operations;
|
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.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
class EbikeOperationsApplicationTests {
|
class EbikeOperationsApplicationTests {
|
||||||
|
|
||||||
@Resource
|
|
||||||
RedisUtil redisUtil;
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void contextLoads(){
|
void contextLoads() {
|
||||||
SnowFlakeIDKeyGenerator generator = new SnowFlakeIDKeyGenerator();
|
|
||||||
long nextId = generator.nextId();
|
|
||||||
redisUtil.saveDispatchOrder(nextId, "2", 5L, TimeUnit.MINUTES);
|
|
||||||
System.out.println(nextId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void deleteDispatchOrder(){
|
|
||||||
redisUtil.deleteDispatchOrder(351467314753310720L);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user