riku
2021-06-30 63d16d75a6f12e783bb36cfe526d9cb518b48823
1. 新增用电量数据查询接口
2. 新增swagger2库
已修改5个文件
已添加6个文件
153 ■■■■■ 文件已修改
pom.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/common/config/Swagger2Configuration.kt 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/lightshare/service/ElectricityService.kt 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/ElectricityServiceImpl.kt 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/lightshare/web/CompanyController.kt 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/lightshare/web/ElectricityController.kt 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/lightshare/web/MissionController.kt 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/com/flightfeather/uav/lightshare/web/RealTimeDataController.kt 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application-dev.yml 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application-pro.yml 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application.yml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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