Commit 8923ddab by 段启岩

重构app版本获取

parent 574c2ebf
package cn.meteor.beyondclouds.modules.app.controller;
package cn.meteor.beyondclouds.modules.app.api;
import cn.meteor.beyondclouds.core.annotation.Anonymous;
import cn.meteor.beyondclouds.core.api.Response;
import cn.meteor.beyondclouds.modules.app.entity.AppVersion;
import cn.meteor.beyondclouds.modules.app.exception.VersionServiceException;
import cn.meteor.beyondclouds.modules.app.service.IAppVersionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;
/**
......@@ -21,6 +22,7 @@ import org.springframework.web.bind.annotation.RestController;
* @author 段启岩
* @since 2020-03-19
*/
@Api(tags = "app接口")
@RestController
@RequestMapping("/api")
public class AppVersionApi {
......@@ -33,17 +35,15 @@ public class AppVersionApi {
}
@Anonymous
@ApiOperation("获取版本号")
@ApiOperation("获取最新版本信息")
@GetMapping("/app/version/latest")
public Response<AppVersion> getLatestVersion() {
// TODO 获取最新版本信息
AppVersion appVersion = appVersionService.getAppVersion();
if (appVersion == null) {
return Response.error();
try {
AppVersion appVersion = appVersionService.getLatestVersion();
return Response.success(appVersion);
} catch (VersionServiceException e) {
return Response.error(e);
}
return Response.success(appVersion);
}
}
package cn.meteor.beyondclouds.modules.app.enums;
import cn.meteor.beyondclouds.core.IErrorCode;
/**
* @author meteor
*/
public enum VersionErrorCode implements IErrorCode {
VERSION_FETCH_FAILURE(20000, "版本信息获取失败!");
private Integer code;
private String msg;
VersionErrorCode(Integer code, String msg) {
this.code = code;
this.msg = msg;
}
@Override
public long code() {
return 0;
}
@Override
public String msg() {
return null;
}
}
package cn.meteor.beyondclouds.modules.app.exception;
import cn.meteor.beyondclouds.core.IErrorCode;
import cn.meteor.beyondclouds.core.exception.ServiceException;
/**
* @author meteor
*/
public class VersionServiceException extends ServiceException {
public VersionServiceException(long errorCode, String errorMsg) {
super(errorCode, errorMsg);
}
public VersionServiceException(IErrorCode errorCode) {
super(errorCode);
}
}
......@@ -20,5 +20,5 @@ public interface AppVersionMapper extends BaseMapper<AppVersion> {
* 通过sql语句根据时间降序排序数据后,限制返回最新一条
* @return
*/
AppVersion getVersionMapper();
AppVersion getLatestVersion();
}
......@@ -2,7 +2,7 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.meteor.beyondclouds.modules.app.mapper.AppVersionMapper">
<select id="getVersionMapper" resultType="cn.meteor.beyondclouds.modules.app.entity.AppVersion">
<select id="getLatestVersion" resultType="cn.meteor.beyondclouds.modules.app.entity.AppVersion">
select * from app_version order by create_time desc limit 1
</select>
......
package cn.meteor.beyondclouds.modules.app.service;
import cn.meteor.beyondclouds.modules.app.entity.AppVersion;
import cn.meteor.beyondclouds.modules.app.exception.VersionServiceException;
import com.baomidou.mybatisplus.extension.service.IService;
/**
......@@ -14,8 +15,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
public interface IAppVersionService extends IService<AppVersion> {
/**
* 根据时间倒序查询最新版本
* 根据最新版本信息
* @return AppVersion
*/
AppVersion getAppVersion();
AppVersion getLatestVersion() throws VersionServiceException;
}
package cn.meteor.beyondclouds.modules.app.service.impl;
import cn.meteor.beyondclouds.modules.app.entity.AppVersion;
import cn.meteor.beyondclouds.modules.app.enums.VersionErrorCode;
import cn.meteor.beyondclouds.modules.app.exception.VersionServiceException;
import cn.meteor.beyondclouds.modules.app.mapper.AppVersionMapper;
import cn.meteor.beyondclouds.modules.app.service.IAppVersionService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -22,22 +23,21 @@ public class AppVersionServiceImpl extends ServiceImpl<AppVersionMapper, AppVers
private AppVersionMapper appVersionMapper;
@Autowired
public void setAppVersionMapper(AppVersionMapper appVersionMapper) {
public AppVersionServiceImpl(AppVersionMapper appVersionMapper) {
this.appVersionMapper = appVersionMapper;
}
/**
* 根据时间倒序查询最新版本
* 查询最新版本信息
* @return AppVersion
*/
@Override
public AppVersion getAppVersion() {
AppVersion appVersion = appVersionMapper.getVersionMapper();
if (appVersion == null) {
public AppVersion getLatestVersion() throws VersionServiceException {
AppVersion appVersion = appVersionMapper.getLatestVersion();
if (null == appVersion) {
throw new VersionServiceException(VersionErrorCode.VERSION_FETCH_FAILURE);
}
return appVersion;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment