Commit f281a9b2 by 杨林龙

优化Gps基站数据落库业务

1 parent db8125c9
package cn.com.glsx.stdinterface.modules.mapper; package cn.com.glsx.stdinterface.modules.mapper;
import cn.com.glsx.stdinterface.dto.DeviceLocationDto;
import cn.com.glsx.stdinterface.modules.model.DeviceLocation; import cn.com.glsx.stdinterface.modules.model.DeviceLocation;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper; 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;
/** /**
...@@ -22,4 +24,12 @@ public interface DeviceLocationMapper extends CommonBaseMapper<DeviceLocation> { ...@@ -22,4 +24,12 @@ public interface DeviceLocationMapper extends CommonBaseMapper<DeviceLocation> {
List<String> getAllSnInNewEshield(); List<String> getAllSnInNewEshield();
DeviceLocation getDeviceLocationBySn(@Param("sn") String sn); DeviceLocation getDeviceLocationBySn(@Param("sn") String sn);
/**
* 保存和更新设备定位报表
*
* @param deviceLocationDtoList 设备定位集合
* @return
*/
Integer saveOrUpdateDeviceLocationData(@Param("deviceLocationDtoList") Collection<DeviceLocationDto> deviceLocationDtoList);
} }
\ No newline at end of file \ No newline at end of file
...@@ -6,7 +6,6 @@ import cn.com.glsx.stdinterface.modules.model.DeviceLocation; ...@@ -6,7 +6,6 @@ import cn.com.glsx.stdinterface.modules.model.DeviceLocation;
import cn.com.glsx.stdinterface.modules.model.LocationCheckBO; import cn.com.glsx.stdinterface.modules.model.LocationCheckBO;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -33,22 +32,11 @@ public class DeviceLocationService { ...@@ -33,22 +32,11 @@ public class DeviceLocationService {
* @param deviceLocationDtoList * @param deviceLocationDtoList
*/ */
public void saveOrUpdateDeviceLocationData(Collection<DeviceLocationDto> deviceLocationDtoList) { public void saveOrUpdateDeviceLocationData(Collection<DeviceLocationDto> deviceLocationDtoList) {
for (DeviceLocationDto deviceLocationDto : deviceLocationDtoList) { try {
try { Integer num = deviceLocationMapper.saveOrUpdateDeviceLocationData(deviceLocationDtoList);
DeviceLocation locationBySn = deviceLocationMapper.getDeviceLocationBySn(deviceLocationDto.getSn()); log.info("saveOrUpdateDeviceLocationData===" + num);
if (ObjectUtil.isNull(locationBySn)) { } catch (Exception e) {
DeviceLocation deviceLocation = new DeviceLocation(); e.printStackTrace();
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();
}
} }
} }
......
...@@ -21,4 +21,22 @@ ...@@ -21,4 +21,22 @@
<select id="getDeviceLocationBySn" resultMap="BaseMap"> <select id="getDeviceLocationBySn" resultMap="BaseMap">
select * from t_device_location where sn = #{sn} select * from t_device_location where sn = #{sn}
</select> </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> </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!