From 63d16d75a6f12e783bb36cfe526d9cb518b48823 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期三, 30 六月 2021 17:58:52 +0800
Subject: [PATCH] 1. 新增用电量数据查询接口 2. 新增swagger2库
---
src/main/kotlin/com/flightfeather/uav/common/config/Swagger2Configuration.kt | 47 +++++++++++++++
src/main/kotlin/com/flightfeather/uav/lightshare/service/ElectricityService.kt | 9 +++
src/main/kotlin/com/flightfeather/uav/lightshare/web/ElectricityController.kt | 26 ++++++++
src/main/kotlin/com/flightfeather/uav/lightshare/web/RealTimeDataController.kt | 2
src/main/kotlin/com/flightfeather/uav/lightshare/web/MissionController.kt | 2
src/main/kotlin/com/flightfeather/uav/lightshare/web/CompanyController.kt | 2
src/main/resources/application-dev.yml | 7 ++
src/main/resources/application-pro.yml | 7 ++
pom.xml | 5 +
src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/ElectricityServiceImpl.kt | 40 +++++++++++++
src/main/resources/application.yml | 6 ++
11 files changed, 153 insertions(+), 0 deletions(-)
diff --git a/pom.xml b/pom.xml
index f4855d6..ae1c2f8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -151,6 +151,11 @@
<version>${kotlin.version}</version>
</dependency>
+ <dependency>
+ <groupId>io.springfox</groupId>
+ <artifactId>springfox-boot-starter</artifactId>
+ <version>3.0.0</version>
+ </dependency>
</dependencies>
<build>
diff --git a/src/main/kotlin/com/flightfeather/uav/common/config/Swagger2Configuration.kt b/src/main/kotlin/com/flightfeather/uav/common/config/Swagger2Configuration.kt
new file mode 100644
index 0000000..9f81f98
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/uav/common/config/Swagger2Configuration.kt
@@ -0,0 +1,47 @@
+package com.flightfeather.uav.common.config
+
+import org.springframework.beans.factory.annotation.Value
+import org.springframework.context.annotation.Bean
+import org.springframework.context.annotation.Configuration
+import springfox.documentation.builders.ApiInfoBuilder
+import springfox.documentation.builders.PathSelectors
+import springfox.documentation.builders.RequestHandlerSelectors
+import springfox.documentation.spi.DocumentationType
+import springfox.documentation.spring.web.plugins.Docket
+import springfox.documentation.swagger2.annotations.EnableSwagger2
+
+/**
+ * @author riku
+ * Date: 2020/8/28
+ */
+@Configuration
+@EnableSwagger2
+class Swagger2Configuration {
+
+ companion object {
+ const val SWAGGER_SCAN_BASE_PACKAGE = "cn.flightfeather.uav"
+
+ const val VERSION = "1.0.0"
+ }
+
+ @Value("\${springfox.documentation.swagger.v2.enabled}")
+ private val swagger2Enable: Boolean = true
+
+ @Bean
+ fun createRestApi(): Docket =
+ Docket(DocumentationType.SWAGGER_2)
+ .enable(swagger2Enable)
+ .apiInfo(apiInfo())
+ .select()
+ .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_BASE_PACKAGE))
+ .paths(PathSelectors.any())
+ .build()
+
+
+ private fun apiInfo() =
+ ApiInfoBuilder()
+ .title("椋炵窘璧拌埅鐩戞祴鏈嶅姟")
+ .description("椋炵窘璧拌埅鐩戞祴鏈嶅姟 API 鎺ュ彛鏂囨。")
+ .version(VERSION)
+ .build()
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/service/ElectricityService.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/service/ElectricityService.kt
new file mode 100644
index 0000000..4566dc8
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/service/ElectricityService.kt
@@ -0,0 +1,9 @@
+package com.flightfeather.uav.lightshare.service
+
+import com.flightfeather.uav.domain.entity.ElectricMinuteValue
+import com.flightfeather.uav.lightshare.bean.BaseResponse
+
+interface ElectricityService {
+
+ fun getMinuteData(deviceCode: String, startTime: String?, endTime: String?, page: Int?, perPage: Int?): BaseResponse<List<ElectricMinuteValue>>
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/ElectricityServiceImpl.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/ElectricityServiceImpl.kt
new file mode 100644
index 0000000..dd0a575
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/ElectricityServiceImpl.kt
@@ -0,0 +1,40 @@
+package com.flightfeather.uav.lightshare.service.impl
+
+import com.flightfeather.uav.domain.entity.ElectricMinuteValue
+import com.flightfeather.uav.domain.mapper.ElectricMinuteValueMapper
+import com.flightfeather.uav.lightshare.bean.BaseResponse
+import com.flightfeather.uav.lightshare.bean.DataHead
+import com.flightfeather.uav.lightshare.service.ElectricityService
+import com.github.pagehelper.PageHelper
+import org.springframework.stereotype.Service
+import tk.mybatis.mapper.entity.Example
+import java.text.SimpleDateFormat
+
+@Service
+class ElectricityServiceImpl(private val electricMinuteValueMapper: ElectricMinuteValueMapper) : ElectricityService {
+
+ private var dateFormatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
+
+ override fun getMinuteData(
+ deviceCode: String, startTime: String?,
+ endTime: String?, page: Int?, perPage: Int?
+ ): BaseResponse<List<ElectricMinuteValue>> {
+ val perP = perPage ?: 60
+ val p = page ?: 1
+ val sTime = startTime?.let { dateFormatter.parse(it) }
+ val eTime = endTime?.let { dateFormatter.parse(it) }
+ val pageInfo = PageHelper.startPage<ElectricMinuteValue>(p, perP)
+ val result = mutableListOf<ElectricMinuteValue>()
+ electricMinuteValueMapper.selectByExample(Example(ElectricMinuteValue::class.java).apply {
+ createCriteria().andEqualTo("mvStatCode", deviceCode)
+ .apply {
+ sTime?.let { andGreaterThanOrEqualTo("mvDataTime", it) }
+ eTime?.let { andLessThanOrEqualTo("mvDataTime", it) }
+ }
+ orderBy("mvDataTime")
+ }).forEach {
+ it?.let { result.add(it) }
+ }
+ return BaseResponse(true, head = DataHead(pageInfo.pageNum, pageInfo.pages), data = result)
+ }
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/web/CompanyController.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/web/CompanyController.kt
index e4c280e..10bef47 100644
--- a/src/main/kotlin/com/flightfeather/uav/lightshare/web/CompanyController.kt
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/web/CompanyController.kt
@@ -1,10 +1,12 @@
package com.flightfeather.uav.lightshare.web
import com.flightfeather.uav.lightshare.service.CompanyService
+import io.swagger.annotations.Api
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
+@Api(tags = ["宸ヤ笟浼佷笟淇℃伅API鎺ュ彛"])
@RestController
@RequestMapping("air/company")
class CompanyController(private val companyService: CompanyService) {
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/web/ElectricityController.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/web/ElectricityController.kt
new file mode 100644
index 0000000..bd69609
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/web/ElectricityController.kt
@@ -0,0 +1,26 @@
+package com.flightfeather.uav.lightshare.web
+
+import com.flightfeather.uav.lightshare.service.ElectricityService
+import io.swagger.annotations.Api
+import io.swagger.annotations.ApiOperation
+import io.swagger.annotations.ApiParam
+import org.springframework.web.bind.annotation.GetMapping
+import org.springframework.web.bind.annotation.RequestMapping
+import org.springframework.web.bind.annotation.RequestParam
+import org.springframework.web.bind.annotation.RestController
+
+@Api(tags = ["浼佷笟鐢ㄧ數閲廇PI鎺ュ彛"])
+@RestController
+@RequestMapping("electric/data")
+class ElectricityController (private val electricityService: ElectricityService) {
+
+ @ApiOperation(value = "鑾峰彇浼佷笟鐢ㄧ數閲忓垎閽熷潎鍊�")
+ @GetMapping("/minute")
+ fun getMinuteData(
+ @ApiParam("璁惧缂栧彿") @RequestParam(value = "deviceCode") deviceCode: String,
+ @ApiParam(value = "寮�濮嬫椂闂�", example = "yyyy-MM-dd HH:mm:ss") @RequestParam(value = "startTime", required = false) startTime: String?,
+ @ApiParam(value = "缁撴潫鏃堕棿", example = "yyyy-MM-dd HH:mm:ss") @RequestParam(value = "endTime", required = false) endTime: String?,
+ @RequestParam(value = "page", required = false) page: Int?,
+ @RequestParam(value = "perPage", required = false) perPage: Int?
+ ) = electricityService.getMinuteData(deviceCode, startTime, endTime, page, perPage)
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/web/MissionController.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/web/MissionController.kt
index e96d5e5..e8ccb52 100644
--- a/src/main/kotlin/com/flightfeather/uav/lightshare/web/MissionController.kt
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/web/MissionController.kt
@@ -2,8 +2,10 @@
import com.flightfeather.uav.domain.entity.Mission
import com.flightfeather.uav.lightshare.service.MissionService
+import io.swagger.annotations.Api
import org.springframework.web.bind.annotation.*
+@Api(tags = ["璧拌埅鐩戞祴浠诲姟API鎺ュ彛"])
@RestController
@RequestMapping("air/mission")
class MissionController(private val missionService: MissionService) {
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/web/RealTimeDataController.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/web/RealTimeDataController.kt
index a77dff3..cc05b83 100644
--- a/src/main/kotlin/com/flightfeather/uav/lightshare/web/RealTimeDataController.kt
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/web/RealTimeDataController.kt
@@ -1,9 +1,11 @@
package com.flightfeather.uav.lightshare.web
import com.flightfeather.uav.lightshare.service.RealTimeDataService
+import io.swagger.annotations.Api
import org.springframework.web.bind.annotation.*
import org.springframework.web.multipart.MultipartFile
+@Api(tags = ["璧拌埅鐩戞祴鏁版嵁API鎺ュ彛"])
@RestController
@RequestMapping("air/realtime")
class RealTimeDataController(val realTimeDataService: RealTimeDataService) {
diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml
new file mode 100644
index 0000000..f03bef2
--- /dev/null
+++ b/src/main/resources/application-dev.yml
@@ -0,0 +1,7 @@
+springfox:
+ documentation:
+ swagger:
+ v2:
+ enabled: true
+
+
diff --git a/src/main/resources/application-pro.yml b/src/main/resources/application-pro.yml
new file mode 100644
index 0000000..135277d
--- /dev/null
+++ b/src/main/resources/application-pro.yml
@@ -0,0 +1,7 @@
+springfox:
+ documentation:
+ swagger:
+ v2:
+ enabled: false
+
+
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 7a28b65..1087cd6 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -53,3 +53,9 @@
reasonable: true
supportMethodsArguments: true
params: count=countSql
+
+springfox:
+ documentation:
+ swagger:
+ v2:
+ enabled: false
\ No newline at end of file
--
Gitblit v1.9.3