Commit b603f805 by 向延琳

查询电量

1 parent 3a441445
......@@ -4,9 +4,11 @@ import cn.com.glsx.stdinterface.api.BatteryClient;
import cn.com.glsx.stdinterface.dto.DevicePowerDTO;
import cn.com.glsx.stdinterface.modules.service.BatteryService;
import com.glsx.plat.core.web.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
......@@ -34,4 +36,10 @@ public class BatteryController implements BatteryClient {
batteryService.initDataFromOld();
return R.ok();
}
@GetMapping("/queryOneBySn")
@Override
public R<DevicePowerDTO> getDevicePowerBySn(@RequestParam("sn")String sn) {
return R.ok().data(batteryService.getDevicePowerBySn(sn));
}
}
package cn.com.glsx.stdinterface.modules.converter;
import cn.com.glsx.stdinterface.dto.DevicePowerDTO;
import cn.com.glsx.stdinterface.modules.entity.DevicePower;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* @author xiangyanlin
* @date 2022/4/24
*/
@Mapper
public interface DevicePowerConverter {
DevicePowerConverter INSTANCE = Mappers.getMapper(DevicePowerConverter.class);
/**
* 实体转换
*/
DevicePowerDTO convertTo(DevicePower item);
/**
* 集合转换
*/
List<DevicePowerDTO> convertTo(List<DevicePower> item);
}
......@@ -3,6 +3,7 @@ package cn.com.glsx.stdinterface.modules.service;
import cn.com.glsx.alarm.services.model.DevicePowerDto;
import cn.com.glsx.stdinterface.common.constants.DeviceConstants;
import cn.com.glsx.stdinterface.dto.DevicePowerDTO;
import cn.com.glsx.stdinterface.modules.converter.DevicePowerConverter;
import cn.com.glsx.stdinterface.modules.entity.DevicePower;
import cn.com.glsx.stdinterface.modules.entity.Vehicle;
import cn.com.glsx.stdinterface.modules.entity.VehicleDeviceOperator;
......@@ -14,6 +15,7 @@ import com.glsx.plat.common.multithread.ListSplitIterator;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
......@@ -168,4 +170,18 @@ public class BatteryService {
.collect(Collectors.toMap(DevicePowerDto::getSn, Function.identity(), (o1, o2) -> o1)).values());
}
/**
* 根据sn获取
*/
public DevicePowerDTO getDevicePowerBySn(String sn) {
if (StringUtils.isEmpty(sn)) {
return null;
}
DevicePower devicePower = devicePowerMapper.selectBySn(sn);
if (Objects.isNull(devicePower)) {
return null;
}
return DevicePowerConverter.INSTANCE.convertTo(devicePower);
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!