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> 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() } 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>> } 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) } } 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) { 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 = ["ä¼ä¸ç¨çµéAPIæ¥å£"]) @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) } 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) { 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) { src/main/resources/application-dev.yml
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,7 @@ springfox: documentation: swagger: v2: enabled: true src/main/resources/application-pro.yml
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,7 @@ springfox: documentation: swagger: v2: enabled: false src/main/resources/application.yml
@@ -53,3 +53,9 @@ reasonable: true supportMethodsArguments: true params: count=countSql springfox: documentation: swagger: v2: enabled: false