Commit f281a9b2 by 杨林龙

优化Gps基站数据落库业务

1 parent db8125c9
package cn.com.glsx.stdinterface.modules.mapper;
import cn.com.glsx.stdinterface.dto.DeviceLocationDto;
import cn.com.glsx.stdinterface.modules.model.DeviceLocation;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List;
/**
......@@ -22,4 +24,12 @@ public interface DeviceLocationMapper extends CommonBaseMapper<DeviceLocation> {
List<String> getAllSnInNewEshield();
DeviceLocation getDeviceLocationBySn(@Param("sn") String sn);
/**
* 保存和更新设备定位报表
*
* @param deviceLocationDtoList 设备定位集合
* @return
*/
Integer saveOrUpdateDeviceLocationData(@Param("deviceLocationDtoList") Collection<DeviceLocationDto> deviceLocationDtoList);
}
\ No newline at end of file
......@@ -6,7 +6,6 @@ import cn.com.glsx.stdinterface.modules.model.DeviceLocation;
import cn.com.glsx.stdinterface.modules.model.LocationCheckBO;
import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -33,22 +32,11 @@ public class DeviceLocationService {
* @param deviceLocationDtoList
*/
public void saveOrUpdateDeviceLocationData(Collection<DeviceLocationDto> deviceLocationDtoList) {
for (DeviceLocationDto deviceLocationDto : deviceLocationDtoList) {
try {
DeviceLocation locationBySn = deviceLocationMapper.getDeviceLocationBySn(deviceLocationDto.getSn());
if (ObjectUtil.isNull(locationBySn)) {
DeviceLocation deviceLocation = new DeviceLocation();
BeanUtils.copyProperties(deviceLocationDto, deviceLocation);
deviceLocation.setCreatedTime(new Date());
deviceLocationMapper.insertSelective(deviceLocation);
} else {
mergeData(locationBySn, deviceLocationDto);
deviceLocationMapper.updateByPrimaryKeySelective(locationBySn);
}
} catch (Exception e) {
log.error("设备号:" + deviceLocationDto.getSn() + "查询异常===" + e.getMessage());
e.printStackTrace();
}
try {
Integer num = deviceLocationMapper.saveOrUpdateDeviceLocationData(deviceLocationDtoList);
log.info("saveOrUpdateDeviceLocationData===" + num);
} catch (Exception e) {
e.printStackTrace();
}
}
......
......@@ -21,4 +21,22 @@
<select id="getDeviceLocationBySn" resultMap="BaseMap">
select * from t_device_location where sn = #{sn}
</select>
<insert id="saveOrUpdateDeviceLocationData">
INSERT INTO t_device_location (sn,last_gps_time,last_bs_time,created_time,updated_time)
values
<foreach collection="deviceLocationDtoList" item="deviceLocation" open="(" separator="," close=")">
#{deviceLocation.sn},
#{deviceLocation.lastGpsTime},
#{deviceLocation.lastBsTime},
#{deviceLocation.createdTime},
#{deviceLocation.updatedTime}
</foreach>
ON DUPLICATE KEY UPDATE
sn=values(sn),
last_gps_time=values(last_gps_time),
last_bs_time=values(last_bs_time),
created_time=values(created_time),
updated_time=values(updated_time)
</insert>
</mapper>
\ 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!