Commit 626f6f62 by 林永健

[+] 新增根据设备号获取充电枪详情接口

1 parent fe9b5b67
...@@ -41,4 +41,10 @@ public class ChargingGunController { ...@@ -41,4 +41,10 @@ public class ChargingGunController {
public ChargingGunResponse detail(@PathVariable("id") Long id) { public ChargingGunResponse detail(@PathVariable("id") Long id) {
return gunService.detail(id); return gunService.detail(id);
} }
@Operation(summary = "根据设备号(桩号+枪号)查看详情", description = "查询充电枪详情")
@GetMapping("/getByDeviceNo/{deviceNo}")
public ChargingGunResponse getByDeviceNo(@PathVariable("deviceNo") String deviceNo) {
return gunService.getByDeviceNo(deviceNo);
}
} }
...@@ -69,6 +69,16 @@ public class ChargingGunService { ...@@ -69,6 +69,16 @@ public class ChargingGunService {
return res; return res;
} }
public ChargingGunResponse getByDeviceNo(String deviceNo) {
if (!StringUtils.hasLength(deviceNo) || deviceNo.length() < 2) {
throw new RuntimeException("设备不存在");
}
String pileId = deviceNo.substring(0, deviceNo.length() - 2);
String gunNumber = deviceNo.substring(deviceNo.length() - 2);
ChargingGun res = gunMapper.findByPileIdAndNumber(pileId, Byte.parseByte(gunNumber));
return detail(res);
}
/** /**
* 同步上传数据到枪实体 * 同步上传数据到枪实体
*/ */
...@@ -94,7 +104,7 @@ public class ChargingGunService { ...@@ -94,7 +104,7 @@ public class ChargingGunService {
public void saveOrUpdate(ChargingGun entity) { public void saveOrUpdate(ChargingGun entity) {
// 来自设备端同步的设备,并无业务属性name,需要构建 // 来自设备端同步的设备,并无业务属性name,需要构建
entity.setName(StringUtils.hasLength(entity.getName()) ? entity.getName() : String.format("%s-%d", entity.getPileId(), entity.getGunNumber())); entity.setName(StringUtils.hasLength(entity.getName()) ? entity.getName() : String.format("%s-%02d", entity.getPileId(), entity.getGunNumber()));
if (Objects.isNull(entity.getId())) { if (Objects.isNull(entity.getId())) {
gunMapper.insert(entity); gunMapper.insert(entity);
log.info("新增充电枪数据, entity: {}", entity); log.info("新增充电枪数据, entity: {}", entity);
......
...@@ -36,6 +36,6 @@ ...@@ -36,6 +36,6 @@
</select> </select>
<select id="findByPileIdAndNumber" resultMap="BaseResult"> <select id="findByPileIdAndNumber" resultMap="BaseResult">
select * from charging_gun where pileId = #{pileId} and gun_number = #{gunNumber} select * from charging_gun where pile_id = #{pileId} and gun_number = #{gunNumber}
</select> </select>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!