From 197d6766d056fda4fdf9e1f9ee26de9f9a480ef5 Mon Sep 17 00:00:00 2001 From: riku <risaku@163.com> Date: 星期四, 05 九月 2019 10:32:58 +0800 Subject: [PATCH] 完成警报、阈值的插入、更新、获取等接口 --- src/main/kotlin/com/flightfeather/obd/lightshare/web/ObdThresholdController.kt | 30 ++++++ src/main/kotlin/com/flightfeather/obd/repository/impl/ObdThresholdValueDaoImpl.kt | 46 +++++++++ src/main/kotlin/com/flightfeather/obd/lightshare/service/impl/ObdThresholdValueServiceImpl.kt | 27 +++++ src/main/kotlin/com/flightfeather/obd/lightshare/web/ObdAlarmController.kt | 21 ++++ src/main/kotlin/com/flightfeather/obd/repository/ObdDataRepository.kt | 2 src/main/kotlin/com/flightfeather/obd/repository/ObdThresholdValueRepository.kt | 27 +++++ src/main/kotlin/com/flightfeather/obd/repository/impl/ObdDataDaoImpl.kt | 4 src/main/kotlin/com/flightfeather/obd/repository/impl/ObdAlarmDaoImpl.kt | 46 +++++++++ src/main/kotlin/com/flightfeather/obd/repository/ObdAlarmRepository.kt | 22 ++++ src/main/kotlin/com/flightfeather/obd/lightshare/service/ObdAlarmService.kt | 16 +++ src/main/kotlin/com/flightfeather/obd/lightshare/service/impl/ObdAlarmServiceImpl.kt | 19 +++ src/main/kotlin/com/flightfeather/obd/lightshare/service/ObdThresholdValueService.kt | 26 +++++ src/main/kotlin/com/flightfeather/obd/socket/MessageManager.kt | 2 src/main/kotlin/com/flightfeather/obd/socket/ServerHandler.kt | 1 src/main/resources/application.yml | 2 src/main/kotlin/com/flightfeather/obd/lightshare/service/ObdDataService.kt | 3 16 files changed, 289 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/flightfeather/obd/lightshare/service/ObdAlarmService.kt b/src/main/kotlin/com/flightfeather/obd/lightshare/service/ObdAlarmService.kt new file mode 100644 index 0000000..3a84cb0 --- /dev/null +++ b/src/main/kotlin/com/flightfeather/obd/lightshare/service/ObdAlarmService.kt @@ -0,0 +1,16 @@ +package com.flightfeather.obd.lightshare.service + +import com.flightfeather.obd.lightshare.bean.AlarmDataVo + +/** + * @author riku + * Date: 2019/9/5 + */ +interface ObdAlarmService { + + /** + * 鏍规嵁vin鐮佽幏鍙栬鎶ユ暟鎹� + */ + fun getAlarmByVinCode(vinCode: String, pageNum: Int?, pageSize: Int?): MutableList<AlarmDataVo> + +} \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/obd/lightshare/service/ObdDataService.kt b/src/main/kotlin/com/flightfeather/obd/lightshare/service/ObdDataService.kt index 41865b5..2df9280 100644 --- a/src/main/kotlin/com/flightfeather/obd/lightshare/service/ObdDataService.kt +++ b/src/main/kotlin/com/flightfeather/obd/lightshare/service/ObdDataService.kt @@ -8,6 +8,9 @@ */ interface ObdDataService { + /** + * 鏍规嵁vin鐮佽幏鍙栧搴旀暟鎹� + */ fun getDataByVinCode(vinCode: String, pageNum: Int?, pageSize: Int?): MutableList<ObdDataVo> } \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/obd/lightshare/service/ObdThresholdValueService.kt b/src/main/kotlin/com/flightfeather/obd/lightshare/service/ObdThresholdValueService.kt new file mode 100644 index 0000000..9778905 --- /dev/null +++ b/src/main/kotlin/com/flightfeather/obd/lightshare/service/ObdThresholdValueService.kt @@ -0,0 +1,26 @@ +package com.flightfeather.obd.lightshare.service + +import com.flightfeather.obd.lightshare.bean.ThresholdValueVo + +/** + * @author riku + * Date: 2019/9/5 + */ +interface ObdThresholdValueService { + + /** + * 淇濆瓨 + */ + fun save(thresholdValueVo: ThresholdValueVo): Boolean + + /** + * 鏇存柊 + */ + fun update(thresholdValueVo: ThresholdValueVo): Boolean + + /** + * 鏍规嵁vin鐮佽幏鍙栧搴旈槇鍊� + */ + fun getDataByVinCode(vinCode: String): ThresholdValueVo? + +} \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/obd/lightshare/service/impl/ObdAlarmServiceImpl.kt b/src/main/kotlin/com/flightfeather/obd/lightshare/service/impl/ObdAlarmServiceImpl.kt new file mode 100644 index 0000000..8b639cf --- /dev/null +++ b/src/main/kotlin/com/flightfeather/obd/lightshare/service/impl/ObdAlarmServiceImpl.kt @@ -0,0 +1,19 @@ +package com.flightfeather.obd.lightshare.service.impl + +import com.flightfeather.obd.lightshare.bean.AlarmDataVo +import com.flightfeather.obd.lightshare.service.ObdAlarmService +import com.flightfeather.obd.repository.ObdAlarmRepository +import org.springframework.stereotype.Service + +/** + * @author riku + * Date: 2019/9/5 + */ +@Service +class ObdAlarmServiceImpl(val obdAlarmRepository: ObdAlarmRepository) : ObdAlarmService { + + override fun getAlarmByVinCode(vinCode: String, pageNum: Int?, pageSize: Int?): MutableList<AlarmDataVo> { + return obdAlarmRepository.getAlarmByVinCode(vinCode, pageNum, pageSize) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/obd/lightshare/service/impl/ObdThresholdValueServiceImpl.kt b/src/main/kotlin/com/flightfeather/obd/lightshare/service/impl/ObdThresholdValueServiceImpl.kt new file mode 100644 index 0000000..100c77d --- /dev/null +++ b/src/main/kotlin/com/flightfeather/obd/lightshare/service/impl/ObdThresholdValueServiceImpl.kt @@ -0,0 +1,27 @@ +package com.flightfeather.obd.lightshare.service.impl + +import com.flightfeather.obd.lightshare.bean.ThresholdValueVo +import com.flightfeather.obd.lightshare.service.ObdThresholdValueService +import com.flightfeather.obd.repository.ObdThresholdValueRepository +import org.springframework.stereotype.Service + +/** + * @author riku + * Date: 2019/9/5 + */ +@Service +class ObdThresholdValueServiceImpl(val obdThresholdValueRepository: ObdThresholdValueRepository) : ObdThresholdValueService { + + override fun save(thresholdValueVo: ThresholdValueVo): Boolean { + return obdThresholdValueRepository.save(thresholdValueVo) + } + + override fun update(thresholdValueVo: ThresholdValueVo): Boolean { + return obdThresholdValueRepository.update(thresholdValueVo) + } + + override fun getDataByVinCode(vinCode: String): ThresholdValueVo? { + return obdThresholdValueRepository.getByVinCode(vinCode) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/obd/lightshare/web/ObdAlarmController.kt b/src/main/kotlin/com/flightfeather/obd/lightshare/web/ObdAlarmController.kt new file mode 100644 index 0000000..c942820 --- /dev/null +++ b/src/main/kotlin/com/flightfeather/obd/lightshare/web/ObdAlarmController.kt @@ -0,0 +1,21 @@ +package com.flightfeather.obd.lightshare.web + +import com.flightfeather.obd.lightshare.service.ObdAlarmService +import org.springframework.web.bind.annotation.* + +/** + * @author riku + * Date: 2019/9/5 + */ +@RestController +@RequestMapping("obd/alarm") +class ObdAlarmController(val obdAlarmService: ObdAlarmService) { + + @GetMapping("/{id}") + fun getAlarmByVinCode( + @PathVariable("id") id: String, + @RequestParam("page", required = false) pageNum: Int?, + @RequestParam("per_page", required = false) pageSize: Int? + ) = obdAlarmService.getAlarmByVinCode(id, pageNum, pageSize) + +} \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/obd/lightshare/web/ObdThresholdController.kt b/src/main/kotlin/com/flightfeather/obd/lightshare/web/ObdThresholdController.kt new file mode 100644 index 0000000..11f93b5 --- /dev/null +++ b/src/main/kotlin/com/flightfeather/obd/lightshare/web/ObdThresholdController.kt @@ -0,0 +1,30 @@ +package com.flightfeather.obd.lightshare.web + +import com.flightfeather.obd.lightshare.bean.ThresholdValueVo +import com.flightfeather.obd.lightshare.service.ObdThresholdValueService +import org.springframework.web.bind.annotation.* + +/** + * @author riku + * Date: 2019/9/5 + */ +@RestController +@RequestMapping("obd/threshold") +class ObdThresholdController(val obdThresholdValueService: ObdThresholdValueService) { + + @GetMapping("/{id}") + fun getDataByVinCode( + @PathVariable("id") id: String + ) = obdThresholdValueService.getDataByVinCode(id) + + @PostMapping("/update") + fun update( + @RequestBody thresholdValueVo: ThresholdValueVo + ) = obdThresholdValueService.update(thresholdValueVo) + + @PutMapping("/save") + fun save( + @RequestBody thresholdValueVo: ThresholdValueVo + ) = obdThresholdValueService.save(thresholdValueVo) + +} \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/obd/repository/ObdAlarmRepository.kt b/src/main/kotlin/com/flightfeather/obd/repository/ObdAlarmRepository.kt new file mode 100644 index 0000000..78a5a00 --- /dev/null +++ b/src/main/kotlin/com/flightfeather/obd/repository/ObdAlarmRepository.kt @@ -0,0 +1,22 @@ +package com.flightfeather.obd.repository + +import com.flightfeather.obd.lightshare.bean.AlarmDataVo + +/** + * obd璀︽姤鐩稿叧鏁版嵁搴撴搷浣滄帴鍙� + * @author riku + * Date: 2019/9/5 + */ +interface ObdAlarmRepository { + + /** + * 瀛樺偍璀︽姤鏁版嵁 + */ + fun saveObdAlarm(alarmDataVo: AlarmDataVo): Boolean + + /** + * 閫氳繃姹借溅vin鐮佽幏鍙栬鎶ユ暟鎹� + */ + fun getAlarmByVinCode(vinCode: String, pageNum: Int?, pageSize: Int?): MutableList<AlarmDataVo> + +} \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/obd/repository/ObdDataRepository.kt b/src/main/kotlin/com/flightfeather/obd/repository/ObdDataRepository.kt index f600d4f..04bea7a 100644 --- a/src/main/kotlin/com/flightfeather/obd/repository/ObdDataRepository.kt +++ b/src/main/kotlin/com/flightfeather/obd/repository/ObdDataRepository.kt @@ -17,7 +17,7 @@ /** * 瀛樺偍obd鏁版嵁 */ - fun saveObdData(data:ObdDataVo) + fun saveObdData(data: ObdDataVo): Boolean /** * 閫氳繃姹借溅vin鐮佽幏鍙栨渶鏂版暟鎹� diff --git a/src/main/kotlin/com/flightfeather/obd/repository/ObdThresholdValueRepository.kt b/src/main/kotlin/com/flightfeather/obd/repository/ObdThresholdValueRepository.kt new file mode 100644 index 0000000..7698518 --- /dev/null +++ b/src/main/kotlin/com/flightfeather/obd/repository/ObdThresholdValueRepository.kt @@ -0,0 +1,27 @@ +package com.flightfeather.obd.repository + +import com.flightfeather.obd.lightshare.bean.ThresholdValueVo + +/** + * obd璀︽姤闃堝�肩浉鍏虫暟鎹簱鎿嶄綔鎺ュ彛 + * @author riku + * Date: 2019/9/5 + */ +interface ObdThresholdValueRepository { + + /** + * 瀛樺偍闃堝�� + */ + fun save(thresholdValueVo: ThresholdValueVo): Boolean + + /** + * 鏇存柊闃堝�� + */ + fun update(thresholdValueVo: ThresholdValueVo): Boolean + + /** + * 閫氳繃姹借溅vin鐮佽幏鍙栭槇鍊兼暟鎹� + */ + fun getByVinCode(vinCode: String): ThresholdValueVo? + +} \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/obd/repository/impl/ObdAlarmDaoImpl.kt b/src/main/kotlin/com/flightfeather/obd/repository/impl/ObdAlarmDaoImpl.kt new file mode 100644 index 0000000..0f18f55 --- /dev/null +++ b/src/main/kotlin/com/flightfeather/obd/repository/impl/ObdAlarmDaoImpl.kt @@ -0,0 +1,46 @@ +package com.flightfeather.obd.repository.impl + +import com.flightfeather.obd.domain.entity.AlarmData +import com.flightfeather.obd.domain.mapper.AlarmDataMapper +import com.flightfeather.obd.lightshare.bean.AlarmDataVo +import com.flightfeather.obd.repository.ObdAlarmRepository +import com.github.pagehelper.PageHelper +import org.springframework.beans.BeanUtils +import org.springframework.stereotype.Repository +import tk.mybatis.mapper.entity.Example + +/** + * @author riku + * Date: 2019/9/5 + */ +@Repository +class ObdAlarmDaoImpl(val alarmDataMapper: AlarmDataMapper) : ObdAlarmRepository { + + override fun saveObdAlarm(alarmDataVo: AlarmDataVo): Boolean { + val alarmData = AlarmData() + BeanUtils.copyProperties(alarmDataVo, alarmData) + return alarmDataMapper.insert(alarmData) == 1 + } + + 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() + } + + //鍒嗛〉 + val offset = (pageSize?.times(pageNum?.minus(1) ?: 0)) ?: 0 + PageHelper.offsetPage<AlarmData>(offset, pageSize ?: 10) + val result = alarmDataMapper.selectByExample(example) + + val resultList = mutableListOf<AlarmDataVo>() + result.forEach { + val vo = AlarmDataVo() + BeanUtils.copyProperties(it, vo) + resultList.add(vo) + } + + return resultList + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/obd/repository/impl/ObdDataDaoImpl.kt b/src/main/kotlin/com/flightfeather/obd/repository/impl/ObdDataDaoImpl.kt index 7f58318..4b49491 100644 --- a/src/main/kotlin/com/flightfeather/obd/repository/impl/ObdDataDaoImpl.kt +++ b/src/main/kotlin/com/flightfeather/obd/repository/impl/ObdDataDaoImpl.kt @@ -17,10 +17,10 @@ @Repository class ObdDataDaoImpl(val obdDataMapper: ObdDataMapper) : ObdDataRepository { - override fun saveObdData(data: ObdDataVo) { + override fun saveObdData(data: ObdDataVo): Boolean { val obdData = ObdData() BeanUtils.copyProperties(data, obdData) - obdDataMapper.insert(obdData) + return obdDataMapper.insert(obdData) == 1 } override fun getDataByVinCode(vinCode: String, pageNum: Int?, pageSize: Int?): MutableList<ObdDataVo> { diff --git a/src/main/kotlin/com/flightfeather/obd/repository/impl/ObdThresholdValueDaoImpl.kt b/src/main/kotlin/com/flightfeather/obd/repository/impl/ObdThresholdValueDaoImpl.kt new file mode 100644 index 0000000..e469391 --- /dev/null +++ b/src/main/kotlin/com/flightfeather/obd/repository/impl/ObdThresholdValueDaoImpl.kt @@ -0,0 +1,46 @@ +package com.flightfeather.obd.repository.impl + +import com.flightfeather.obd.domain.entity.ThresholdValue +import com.flightfeather.obd.domain.mapper.ThresholdValueMapper +import com.flightfeather.obd.lightshare.bean.ThresholdValueVo +import com.flightfeather.obd.repository.ObdThresholdValueRepository +import org.springframework.beans.BeanUtils +import org.springframework.stereotype.Repository +import tk.mybatis.mapper.entity.Example + +/** + * @author riku + * Date: 2019/9/5 + */ +@Repository +class ObdThresholdValueDaoImpl(val obdThresholdValueMapper: ThresholdValueMapper) : ObdThresholdValueRepository { + + override fun save(thresholdValueVo: ThresholdValueVo): Boolean { + val thresholdValue = ThresholdValue() + BeanUtils.copyProperties(thresholdValueVo, thresholdValue) + return obdThresholdValueMapper.insert(thresholdValue) == 1 + } + + override fun update(thresholdValueVo: ThresholdValueVo): Boolean { + val thresholdValue = ThresholdValue() + BeanUtils.copyProperties(thresholdValueVo, thresholdValue) + return obdThresholdValueMapper.updateByPrimaryKey(thresholdValue) == 1 + } + + override fun getByVinCode(vinCode: String): ThresholdValueVo? { + val example = Example(ThresholdValue::class.java).apply { + createCriteria().andEqualTo("obdVin", vinCode) + } + + val result = obdThresholdValueMapper.selectByExample(example) + + if (result.isNotEmpty()) { + val vo = ThresholdValueVo() + BeanUtils.copyProperties(vo, result[0]) + return vo + } + + return null + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/obd/socket/MessageManager.kt b/src/main/kotlin/com/flightfeather/obd/socket/MessageManager.kt index 1674ae2..5d99a6e 100644 --- a/src/main/kotlin/com/flightfeather/obd/socket/MessageManager.kt +++ b/src/main/kotlin/com/flightfeather/obd/socket/MessageManager.kt @@ -43,7 +43,7 @@ } } } catch (e: Throwable) { - e.printStackTrace() + println("------鏀跺埌鏍煎紡閿欒鐨勬暟鎹細$msg") } } } \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/obd/socket/ServerHandler.kt b/src/main/kotlin/com/flightfeather/obd/socket/ServerHandler.kt index 42a6c2a..9dd08db 100644 --- a/src/main/kotlin/com/flightfeather/obd/socket/ServerHandler.kt +++ b/src/main/kotlin/com/flightfeather/obd/socket/ServerHandler.kt @@ -22,6 +22,7 @@ override fun channelRead(ctx: ChannelHandlerContext?, msg: Any?) { super.channelRead(ctx, msg) + println("------鏀跺埌鐨勫師濮嬫暟鎹細$msg") if (msg is String) { MessageManager().dealMsg(msg, ctx) } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index cf37a25..2b6df51 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,7 +1,7 @@ spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://47.100.191.150:3306/obd?serverTimezone=GMT&prepStmtCacheSize=517&cachePrepStmts=true&autoReconnect=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false + url: jdbc:mysql://47.100.191.150:3306/obd?serverTimezone=Asia/Shanghai&prepStmtCacheSize=517&cachePrepStmts=true&autoReconnect=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false username: obd password: obd2019 -- Gitblit v1.9.3