| | |
| | | |
| | | import com.flightfeather.obd.domain.entity.DataStream |
| | | import com.flightfeather.obd.domain.mapper.DataStreamMapper |
| | | import com.flightfeather.obd.domain.mapper.VehicleInfoMapper |
| | | import com.flightfeather.obd.lightshare.bean.DataStreamVo |
| | | import com.flightfeather.obd.lightshare.bean.LatLngVo |
| | | import com.flightfeather.obd.repository.DataStreamRepository |
| | | import com.flightfeather.obd.socket.bean.EngineDataStream |
| | | import com.flightfeather.obd.socket.bean.ObdPackageData |
| | | import com.flightfeather.obd.socket.bean.ReplacementData |
| | | import com.flightfeather.obd.socket.bean.SupplementDataStream |
| | | import com.flightfeather.obd.socket.eunm.ObdCommandUnit |
| | | import com.github.pagehelper.PageHelper |
| | | import org.springframework.beans.BeanUtils |
| | | import org.springframework.stereotype.Repository |
| | | import tk.mybatis.mapper.entity.Example |
| | | import java.text.SimpleDateFormat |
| | | |
| | | /** |
| | | * @author riku |
| | | * Date: 2019/9/17 |
| | | */ |
| | | @Repository |
| | | class DataStreamDaoImpl(val dataStreamMapper: DataStreamMapper): DataStreamRepository { |
| | | class DataStreamDaoImpl(val dataStreamMapper: DataStreamMapper, val vehicleInfoMapper: VehicleInfoMapper): DataStreamRepository { |
| | | |
| | | override fun saveDataStream(packageData: ObdPackageData): Boolean { |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | override fun getDataStream(deviceCode: String, pageNum: Int?, pageSize: Int?, startTime: String?, endTime: String?): List<DataStreamVo> { |
| | | val sf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss") |
| | | val example = Example(DataStream::class.java).apply { |
| | | createCriteria().andEqualTo("obdDeviceCode", deviceCode).run { |
| | | startTime?.let { |
| | | try { |
| | | val st = sf.parse(startTime) |
| | | andGreaterThanOrEqualTo("obdDataTime", st) |
| | | } catch (e: Throwable) { |
| | | e.printStackTrace() |
| | | } |
| | | } |
| | | endTime?.let { |
| | | try { |
| | | val et = sf.parse(endTime) |
| | | andLessThanOrEqualTo("obdDataTime", et) |
| | | } catch (e: Throwable) { |
| | | e.printStackTrace() |
| | | } |
| | | } |
| | | orderBy("obdDataTime").desc() |
| | | } |
| | | } |
| | | |
| | | //分页 |
| | | val offset = (pageSize?.times(pageNum?.minus(1) ?: 0)) ?: 0 |
| | | PageHelper.offsetPage<DataStream>(offset, pageSize ?: 10) |
| | | val result = dataStreamMapper.selectByExample(example) |
| | | |
| | | val resultList = mutableListOf<DataStreamVo>() |
| | | result.forEach { |
| | | val vo = DataStreamVo() |
| | | BeanUtils.copyProperties(it, vo) |
| | | resultList.add(vo) |
| | | } |
| | | |
| | | return resultList |
| | | } |
| | | |
| | | override fun getDataStreamCount(deviceCode: String, startTime: String?, endTime: String?): Int { |
| | | val sf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss") |
| | | val example = Example(DataStream::class.java).apply { |
| | | createCriteria().andEqualTo("obdDeviceCode", deviceCode).run { |
| | | startTime?.let { |
| | | try { |
| | | val st = sf.parse(startTime) |
| | | andGreaterThanOrEqualTo("obdDataTime", st) |
| | | } catch (e: Throwable) { |
| | | e.printStackTrace() |
| | | } |
| | | } |
| | | endTime?.let { |
| | | try { |
| | | val et = sf.parse(endTime) |
| | | andLessThanOrEqualTo("obdDataTime", et) |
| | | } catch (e: Throwable) { |
| | | e.printStackTrace() |
| | | } |
| | | } |
| | | orderBy("obdDataTime").desc() |
| | | } |
| | | } |
| | | |
| | | return dataStreamMapper.selectCountByExample(example) |
| | | } |
| | | |
| | | override fun getCoordinate(deviceCode: String): LatLngVo { |
| | | val example = Example(DataStream::class.java).apply { |
| | | createCriteria().andEqualTo("obdDeviceCode", deviceCode).run { |
| | | orderBy("obdDataTime").desc() |
| | | } |
| | | } |
| | | |
| | | //获取最新的一个 |
| | | PageHelper.offsetPage<DataStream>(0, 1) |
| | | val result = dataStreamMapper.selectByExample(example) |
| | | |
| | | val latLngVo = LatLngVo() |
| | | if (result.isNotEmpty()) { |
| | | result[0].let { |
| | | latLngVo.apply { |
| | | this.deviceCode = it.obdDeviceCode |
| | | obdDataTime = it.obdDataTime |
| | | lat = it.obdLat |
| | | lng = it.obdLong |
| | | } |
| | | } |
| | | } |
| | | |
| | | return latLngVo |
| | | } |
| | | |
| | | override fun getLatestDataStream(deviceCode: String): DataStream? { |
| | | val example = Example(DataStream::class.java).apply { |
| | | createCriteria().andEqualTo("obdDeviceCode", deviceCode) |
| | | orderBy("obdDataTime").desc() |
| | | } |
| | | //获取最新的一个 |
| | | PageHelper.offsetPage<DataStream>(0, 1) |
| | | return dataStreamMapper.selectByExample(example).takeIf { it.isNotEmpty() }?.get(0) |
| | | } |
| | | } |