Commit 775d8f39 by 向延琳

根据sn查询增加批量查询

1 parent 0a8dbe47
...@@ -12,6 +12,8 @@ import org.springframework.web.bind.annotation.RequestParam; ...@@ -12,6 +12,8 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
/** /**
* @author xiangyanlin * @author xiangyanlin
...@@ -42,4 +44,10 @@ public class BatteryController implements BatteryClient { ...@@ -42,4 +44,10 @@ public class BatteryController implements BatteryClient {
public R<DevicePowerDTO> getDevicePowerBySn(@RequestParam("sn")String sn) { public R<DevicePowerDTO> getDevicePowerBySn(@RequestParam("sn")String sn) {
return R.ok().data(batteryService.getDevicePowerBySn(sn)); return R.ok().data(batteryService.getDevicePowerBySn(sn));
} }
@GetMapping("/queryListBySn")
@Override
public R<List<DevicePowerDTO>> getDevicePowerListBySn(Collection<String> sn) {
return R.ok().data(batteryService.getDevicePowerListBySn(sn));
}
} }
...@@ -5,6 +5,7 @@ import com.glsx.plat.mybatis.mapper.CommonBaseMapper; ...@@ -5,6 +5,7 @@ import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List; import java.util.List;
...@@ -19,6 +20,13 @@ public interface DevicePowerMapper extends CommonBaseMapper<DevicePower> { ...@@ -19,6 +20,13 @@ public interface DevicePowerMapper extends CommonBaseMapper<DevicePower> {
DevicePower selectBySn(@Param("sn") String sn, @Param("vdId") Long vdId); DevicePower selectBySn(@Param("sn") String sn, @Param("vdId") Long vdId);
/** /**
* 根据设备号获取
* @param sn 设备号集合
* @return 集合
*/
List<DevicePower> listBySn(@Param("sn") Collection<String> sn);
/**
* 批量插入或修改 * 批量插入或修改
* @param entities * @param entities
* @return * @return
......
...@@ -21,6 +21,7 @@ import org.springframework.stereotype.Service; ...@@ -21,6 +21,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
...@@ -69,6 +70,7 @@ public class BatteryService { ...@@ -69,6 +70,7 @@ public class BatteryService {
DevicePower devicePower = convert(devicePowerDTO, createdBy, updatedBy, vdId); DevicePower devicePower = convert(devicePowerDTO, createdBy, updatedBy, vdId);
DevicePower devicePowerOld = devicePowerMapper.selectBySn(devicePowerDTO.getSn(), vdId); DevicePower devicePowerOld = devicePowerMapper.selectBySn(devicePowerDTO.getSn(), vdId);
//TODO 失效过期的绑定关系 @xiangyanlin
if (Objects.isNull(devicePowerOld)) { if (Objects.isNull(devicePowerOld)) {
devicePowerMapper.insert(devicePower); devicePowerMapper.insert(devicePower);
return; return;
...@@ -186,4 +188,18 @@ public class BatteryService { ...@@ -186,4 +188,18 @@ public class BatteryService {
return DevicePowerConverter.INSTANCE.convertTo(devicePower); return DevicePowerConverter.INSTANCE.convertTo(devicePower);
} }
/**
* 根据sn获取
*/
public List<DevicePowerDTO> getDevicePowerListBySn( Collection<String> sn) {
if (CollectionUtils.isEmpty(sn)) {
return Lists.newArrayList();
}
List<DevicePower> devicePowers = devicePowerMapper.listBySn(sn);
if (CollectionUtils.isEmpty(devicePowers)) {
return Lists.newArrayList();
}
return DevicePowerConverter.INSTANCE.convertTo(devicePowers);
}
} }
...@@ -39,6 +39,15 @@ ...@@ -39,6 +39,15 @@
limit 1 limit 1
</select> </select>
<select id="listBySn" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_device_power
<foreach collection="sn" item="sn" index="index" open="(" close=")" separator=",">
#{sn}
</foreach>
</select>
<insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true"> <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
insert into t_device_power(sn, vd_id, alarm_time, soc, del_flag, created_date, created_by, updated_date, updated_by) insert into t_device_power(sn, vd_id, alarm_time, soc, del_flag, created_date, created_by, updated_date, updated_by)
values values
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!