package com.zhujizheng.IHome.versioninfo.controller; import com.zhujizheng.IHome.generator.dao.PYVersionInfo; import com.zhujizheng.IHome.util.response.ResponseResult; import com.zhujizheng.IHome.util.response.RestResultGenerator; import com.zhujizheng.IHome.versioninfo.dto.PYVersionInfoPushDTO; import com.zhujizheng.IHome.versioninfo.server.PYVersionInfoService; import com.zhujizheng.IHome.versioninfo.vo.PYVersionInfoVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.List; /** * Created with IntelliJ IDEA *

* Author: yons * Date: 2019/04/27 * Time: 00:58 * Description: * Copyright © 2019年 com.zhujizheng. All rights reserved. */ @Api("版本信息相关") @RestController @RequestMapping("/version") public class PYVersionInfoController { @Autowired private PYVersionInfoService versionInfoService; @ApiOperation("获取版本信息") @ApiImplicitParam(name = "version", value = "版本号", paramType = "path", required = true, dataType = "String") @GetMapping("/pull/{version}") public ResponseResult pullVersionInfo(@PathVariable String version) { System.out.println("version = " + version); PYVersionInfoVO versionInfoVO = versionInfoService.selectVersionInfo(version); if (versionInfoVO == null) { return RestResultGenerator.genErrorResult("获取版本信息失败"); } return RestResultGenerator.genResult(versionInfoVO, "获取版本信息成功"); } @ApiOperation("获取最新版本信息") @GetMapping("/newest") public ResponseResult newestVersionInfo() { PYVersionInfoVO versionInfoVO = versionInfoService.selectNewestVersionInfo(); if (versionInfoVO == null) { return RestResultGenerator.genErrorResult("获取最新版本信息失败"); } return RestResultGenerator.genResult(versionInfoVO, "获取最新版本信息成功"); } @ApiOperation("获取所有版本信息") @ApiImplicitParam(name = "versionId", value = "版本id", paramType = "path", required = true, dataType = "int") @GetMapping("/all/pull/{versionId}") public ResponseResult pullAllVersionInfoWithId(@PathVariable int versionId) { System.out.println("versionId = " + versionId); List list = versionInfoService.selectAllVersionInfoWithId(versionId); if (list == null) { return RestResultGenerator.genErrorResult("获取版本信息失败"); } return RestResultGenerator.genResult(list, "获取版本信息成功"); } @ApiOperation("新增版本信息") @ApiImplicitParam(name = "pushDTO", value = "版本数据", required = true, dataType = "PYVersionInfoPushDTO") @PostMapping("/add") public ResponseResult addNewVersionInfo(@Validated @RequestBody PYVersionInfoPushDTO pushDTO) { System.out.println("pushDTO = " + pushDTO); PYVersionInfoVO vo = versionInfoService.addVersionInfo(pushDTO); if (vo == null) { return RestResultGenerator.genErrorResult("新增版本失败"); } return RestResultGenerator.genResult(vo, "新增版本成功"); } @ApiOperation("删除版本") @ApiImplicitParam(name = "versionId", value = "版本id", paramType = "path", required = true, dataType = "int") @GetMapping("/delete/{versionId}") public ResponseResult deleteVersionById(@PathVariable int versionId) { System.out.println("versionId = " + versionId); int result = versionInfoService.deleteVersionInfo(versionId); if (result == 0) { return RestResultGenerator.genErrorResult("删除版本失败"); } return RestResultGenerator.genResult("删除版本成功"); } }