| | |
| | | /** |
| | | * 保存 |
| | | */ |
| | | fun save(thresholdValueVo: ThresholdValueVo): Boolean |
| | | fun save(userId: String, thresholdValueVo: ThresholdValueVo): Boolean |
| | | |
| | | /** |
| | | * 更新 |
| | | */ |
| | | fun update(thresholdValueVo: ThresholdValueVo): Boolean |
| | | fun update(userId: String, thresholdValueVo: ThresholdValueVo): Boolean |
| | | |
| | | /** |
| | | * 根据vin码获取对应阈值 |
| | |
| | | @Service |
| | | class ObdThresholdValueServiceImpl(val obdThresholdValueRepository: ObdThresholdValueRepository) : ObdThresholdValueService { |
| | | |
| | | override fun save(thresholdValueVo: ThresholdValueVo): Boolean { |
| | | return obdThresholdValueRepository.save(thresholdValueVo) |
| | | override fun save(userId: String, thresholdValueVo: ThresholdValueVo): Boolean { |
| | | return obdThresholdValueRepository.save(userId, thresholdValueVo) |
| | | } |
| | | |
| | | override fun update(thresholdValueVo: ThresholdValueVo): Boolean { |
| | | return obdThresholdValueRepository.update(thresholdValueVo) |
| | | override fun update(userId: String, thresholdValueVo: ThresholdValueVo): Boolean { |
| | | return obdThresholdValueRepository.update(userId, thresholdValueVo) |
| | | } |
| | | |
| | | override fun getDataByVinCode(vinCode: String): ThresholdValueVo? { |
| | |
| | | @RequestMapping("obd/alarm") |
| | | class ObdAlarmController(val obdAlarmService: ObdAlarmService) { |
| | | |
| | | @GetMapping("/{id}") |
| | | @GetMapping("/{vinCode}") |
| | | fun getAlarmByVinCode( |
| | | @PathVariable("id") id: String, |
| | | @PathVariable("vinCode") vinCode: String, |
| | | @RequestParam("page", required = false) pageNum: Int?, |
| | | @RequestParam("per_page", required = false) pageSize: Int? |
| | | ) = obdAlarmService.getAlarmByVinCode(id, pageNum, pageSize) |
| | | ) = obdAlarmService.getAlarmByVinCode(vinCode, pageNum, pageSize) |
| | | |
| | | } |
| | |
| | | @RequestMapping("obd/data") |
| | | class ObdDataController(val obdDataService: ObdDataService) { |
| | | |
| | | @GetMapping("/{id}") |
| | | @GetMapping("/{vinCode}") |
| | | fun getById( |
| | | @PathVariable("id") id: String, |
| | | @PathVariable("vinCode") vinCode: String, |
| | | @RequestParam("page", required = false) pageNum: Int?, |
| | | @RequestParam("per_page", required = false) pageSize: Int? |
| | | ) = obdDataService.getDataByVinCode(id, pageNum, pageSize) |
| | | ) = obdDataService.getDataByVinCode(vinCode, pageNum, pageSize) |
| | | } |
| | |
| | | @RequestMapping("obd/threshold") |
| | | class ObdThresholdController(val obdThresholdValueService: ObdThresholdValueService) { |
| | | |
| | | @GetMapping("/{id}") |
| | | @GetMapping("/{vinCode}") |
| | | fun getDataByVinCode( |
| | | @PathVariable("id") id: String |
| | | ) = obdThresholdValueService.getDataByVinCode(id) |
| | | @PathVariable("vinCode") vinCode: String |
| | | ) = obdThresholdValueService.getDataByVinCode(vinCode) |
| | | |
| | | @PostMapping("/update") |
| | | fun update( |
| | | @RequestParam("userId") userId: String, |
| | | @RequestBody thresholdValueVo: ThresholdValueVo |
| | | ) = obdThresholdValueService.update(thresholdValueVo) |
| | | ) = obdThresholdValueService.update(userId, thresholdValueVo) |
| | | |
| | | @PutMapping("/save") |
| | | fun save( |
| | | @RequestParam("userId") userId: String, |
| | | @RequestBody thresholdValueVo: ThresholdValueVo |
| | | ) = obdThresholdValueService.save(thresholdValueVo) |
| | | ) = obdThresholdValueService.save(userId, thresholdValueVo) |
| | | |
| | | } |
| | |
| | | /** |
| | | * 存储阈值 |
| | | */ |
| | | fun save(thresholdValueVo: ThresholdValueVo): Boolean |
| | | fun save(userId: String, thresholdValueVo: ThresholdValueVo): Boolean |
| | | |
| | | /** |
| | | * 更新阈值 |
| | | */ |
| | | fun update(thresholdValueVo: ThresholdValueVo): Boolean |
| | | fun update(userId: String, thresholdValueVo: ThresholdValueVo): Boolean |
| | | |
| | | /** |
| | | * 通过汽车vin码获取阈值数据 |
| | |
| | | override fun getAlarmByVinCode(vinCode: String, pageNum: Int?, pageSize: Int?): MutableList<AlarmDataVo> { |
| | | val example = Example(AlarmData::class.java).apply { |
| | | createCriteria().andEqualTo("obdVin", vinCode) |
| | | orderBy("obdTime").desc() |
| | | orderBy("alarmTime").desc() |
| | | } |
| | | |
| | | //分页 |
| | |
| | | @Repository |
| | | class ObdThresholdValueDaoImpl(val obdThresholdValueMapper: ThresholdValueMapper) : ObdThresholdValueRepository { |
| | | |
| | | override fun save(thresholdValueVo: ThresholdValueVo): Boolean { |
| | | override fun save(userId: String, thresholdValueVo: ThresholdValueVo): Boolean { |
| | | val thresholdValue = ThresholdValue() |
| | | BeanUtils.copyProperties(thresholdValueVo, thresholdValue) |
| | | return obdThresholdValueMapper.insert(thresholdValue) == 1 |
| | | val example = Example(ThresholdValue::class.java).apply { |
| | | createCriteria().andEqualTo("obdVin", thresholdValueVo.obdVin) |
| | | } |
| | | val tempResult = obdThresholdValueMapper.selectByExample(example) |
| | | return if (tempResult.isNotEmpty()) |
| | | false |
| | | else |
| | | obdThresholdValueMapper.insert(thresholdValue) == 1 |
| | | } |
| | | |
| | | override fun update(thresholdValueVo: ThresholdValueVo): Boolean { |
| | | override fun update(userId: String, thresholdValueVo: ThresholdValueVo): Boolean { |
| | | val thresholdValue = ThresholdValue() |
| | | BeanUtils.copyProperties(thresholdValueVo, thresholdValue) |
| | | return obdThresholdValueMapper.updateByPrimaryKey(thresholdValue) == 1 |
| | | val example = Example(ThresholdValue::class.java).apply { |
| | | createCriteria().andEqualTo("obdVin", thresholdValue.obdVin) |
| | | } |
| | | return obdThresholdValueMapper.updateByExample(thresholdValue, example) == 1 |
| | | } |
| | | |
| | | override fun getByVinCode(vinCode: String): ThresholdValueVo? { |
| | |
| | | |
| | | if (result.isNotEmpty()) { |
| | | val vo = ThresholdValueVo() |
| | | BeanUtils.copyProperties(vo, result[0]) |
| | | BeanUtils.copyProperties(result[0], vo) |
| | | return vo |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | } catch (e: Throwable) { |
| | | println("------收到格式错误的数据:$msg") |
| | | // println("------收到格式错误的数据:$msg") |
| | | } |
| | | } |
| | | } |
| | |
| | | package com.flightfeather.obd.socket |
| | | |
| | | import com.flightfeather.obd.domain.entity.ObdData |
| | | import com.google.gson.Gson |
| | | import io.netty.channel.ChannelHandler |
| | | import io.netty.channel.ChannelHandlerContext |
| | | import io.netty.channel.ChannelInboundHandlerAdapter |
| | | import io.netty.util.AttributeKey |
| | |
| | | |
| | | override fun channelRead(ctx: ChannelHandlerContext?, msg: Any?) { |
| | | super.channelRead(ctx, msg) |
| | | println("------收到的原始数据:$msg") |
| | | println("------收到的原始数据:[ip:${ctx?.channel()?.remoteAddress()}]\r\n$msg") |
| | | if (msg is String) { |
| | | MessageManager().dealMsg(msg, ctx) |
| | | } |