parent
d8c4df9cff
commit
8aa074e88f
@ -0,0 +1,26 @@
|
||||
package enums;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum AppPlatformEnum {
|
||||
IOS("苹果"),
|
||||
ANDROID("安卓");
|
||||
|
||||
private final String description;
|
||||
|
||||
private static final Map<String, AppPlatformEnum> STATIC_MAP = Arrays.stream(values())
|
||||
.collect(toMap(AppPlatformEnum::name, Function.identity()));
|
||||
|
||||
public static AppPlatformEnum getByCode(String code) {
|
||||
return STATIC_MAP.get(code.toUpperCase());
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package enums;
|
||||
|
||||
public enum AppUpdateTypeEnum {
|
||||
ALL(0, ".apk", "全更新"), WGT(1, ".wgt", "局部热更新");
|
||||
|
||||
private Integer type;
|
||||
private String suffix;
|
||||
private String description;
|
||||
|
||||
AppUpdateTypeEnum(int type, String suffix, String description) {
|
||||
this.type = type;
|
||||
this.suffix = suffix;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Integer getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getSuffix() {
|
||||
return suffix;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public static AppUpdateTypeEnum getByType(Integer type) {
|
||||
for (AppUpdateTypeEnum at : AppUpdateTypeEnum.values()) {
|
||||
if (at.getType().equals(type)) {
|
||||
return at;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,156 +1,37 @@
|
||||
package com.luoo.user.service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.luoo.user.dao.AppUpdateDao;
|
||||
import com.luoo.user.pojo.AppUpdate;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AppUpdateService {
|
||||
|
||||
@Autowired
|
||||
private AppUpdateDao appUpdateDao;
|
||||
private final AppUpdateDao appUpdateDao;
|
||||
|
||||
/**
|
||||
* 根据条件查询列表
|
||||
* 获取最新版本
|
||||
* @param platform 平台
|
||||
* @param currentVersion 当前版本
|
||||
* @param deviceId 设备ID
|
||||
* @return 最新版本
|
||||
*/
|
||||
/*
|
||||
* @Override public List<AppUpdate> findListByParam(AppUpdateQuery param) {
|
||||
* return this.appUpdateDao.selectList(param); }
|
||||
*
|
||||
*//**
|
||||
* 根据条件查询列表
|
||||
*/
|
||||
/*
|
||||
* @Override public Integer findCountByParam(AppUpdateQuery param) { return
|
||||
* this.appUpdateDao.selectCount(param); }
|
||||
*
|
||||
*//**
|
||||
* 分页查询方法
|
||||
*/
|
||||
/*
|
||||
* @Override public PaginationResultVO<AppUpdate> findListByPage(AppUpdateQuery
|
||||
* param) { int count = this.findCountByParam(param); int pageSize =
|
||||
* param.getPageSize() == null ? PageSize.SIZE15.getSize() :
|
||||
* param.getPageSize();
|
||||
*
|
||||
* SimplePage page = new SimplePage(param.getPageNo(), count, pageSize);
|
||||
* param.setSimplePage(page); List<AppUpdate> list =
|
||||
* this.findListByParam(param); PaginationResultVO<AppUpdate> result = new
|
||||
* PaginationResultVO(count, page.getPageSize(), page.getPageNo(),
|
||||
* page.getPageTotal(), list); return result; }
|
||||
*
|
||||
*//**
|
||||
* 新增
|
||||
*/
|
||||
/*
|
||||
* @Override public Integer add(AppUpdate bean) { return
|
||||
* this.appUpdateDao.insert(bean); }
|
||||
*
|
||||
*//**
|
||||
* 批量新增
|
||||
*/
|
||||
/*
|
||||
* @Override public Integer addBatch(List<AppUpdate> listBean) { if (listBean ==
|
||||
* null || listBean.isEmpty()) { return 0; } return
|
||||
* this.appUpdateDao.insertBatch(listBean); }
|
||||
*
|
||||
*//**
|
||||
* 批量新增或者修改
|
||||
*/
|
||||
/*
|
||||
* @Override public Integer addOrUpdateBatch(List<AppUpdate> listBean) { if
|
||||
* (listBean == null || listBean.isEmpty()) { return 0; } return
|
||||
* this.appUpdateDao.insertOrUpdateBatch(listBean); }
|
||||
*
|
||||
*//**
|
||||
* 多条件更新
|
||||
*/
|
||||
/*
|
||||
* @Override public Integer updateByParam(AppUpdate bean, AppUpdateQuery param)
|
||||
* { StringTools.checkParam(param); return this.appUpdateDao.updateByParam(bean,
|
||||
* param); }
|
||||
*
|
||||
*//**
|
||||
* 多条件删除
|
||||
*/
|
||||
/*
|
||||
* @Override public Integer deleteByParam(AppUpdateQuery param) {
|
||||
* StringTools.checkParam(param); return this.appUpdateDao.deleteByParam(param);
|
||||
* }
|
||||
*
|
||||
*//**
|
||||
* 根据Id获取对象
|
||||
*/
|
||||
/*
|
||||
* @Override public AppUpdate getAppUpdateById(Integer id) { return
|
||||
* this.appUpdateDao.selectById(id); }
|
||||
*
|
||||
*//**
|
||||
* 根据Id修改
|
||||
*/
|
||||
|
||||
/*
|
||||
* @Override public Integer updateAppUpdateById(AppUpdate bean, Integer id) {
|
||||
* return this.appUpdateDao.updateById(bean, id); }
|
||||
*
|
||||
*//**
|
||||
* 根据Id删除
|
||||
*//*
|
||||
* @Override public Integer deleteAppUpdateById(Integer id) { return
|
||||
* this.appUpdateDao.deleteById(id); }
|
||||
*
|
||||
* @Override
|
||||
*
|
||||
* @Transactional(rollbackFor = Exception.class) public void
|
||||
* saveUpdate(AppUpdate appUpdate, MultipartFile file) { AppUpdateQuery
|
||||
* updateQuery = new AppUpdateQuery(); updateQuery.setOrderBy("id desc");
|
||||
* updateQuery.setSimplePage(new SimplePage(0, 1)); List<AppUpdate>
|
||||
* appUpdateList = appUpdateDao.selectList(updateQuery); if
|
||||
* (!appUpdateList.isEmpty()) { AppUpdate latest = appUpdateList.get(0); Long
|
||||
* dbVerion = Long.parseLong(latest.getVersion().replace(".", "")); Long
|
||||
* currentVersion = Long.parseLong(appUpdate.getVersion().replace(".", "")); if
|
||||
* (appUpdate.getId() == null && currentVersion <= dbVerion) { throw new
|
||||
* BusinessException("当前版本必须大于历史版本"); } if (appUpdate.getId() != null &&
|
||||
* currentVersion <= dbVerion &&
|
||||
* !appUpdate.getVersion().equals(latest.getVersion())) { throw new
|
||||
* BusinessException("当前版本必须大于历史版本"); } } if (appUpdate.getId() == null) {
|
||||
* appUpdate.setCreateTime(new Date());
|
||||
* appUpdate.setStatus(AppUpdateSatusEnum.INIT.getStatus());
|
||||
* appUpdateDao.insert(appUpdate); } else { appUpdate.setStatus(null);
|
||||
* appUpdate.setGrayscaleDevice(null); appUpdateDao.updateById(appUpdate,
|
||||
* appUpdate.getId()); } if (file != null) { File folder = new
|
||||
* File(appConfig.getProjectFolder() + Constants.APP_UPDATE_FOLDER); if
|
||||
* (!folder.exists()) { folder.mkdirs(); } AppUpdateTypeEnum typeEnum =
|
||||
* AppUpdateTypeEnum.getByType(appUpdate.getUpdateType()); try {
|
||||
* file.transferTo(new File(folder.getAbsolutePath() + "/" + appUpdate.getId() +
|
||||
* typeEnum.getSuffix())); } catch (IOException e) { throw new
|
||||
* BusinessException("更新App失败"); } } }
|
||||
*
|
||||
* @Override public void postUpdate(Integer id, Integer status, String
|
||||
* grayscaleDevice) { AppUpdateSatusEnum satusEnum =
|
||||
* AppUpdateSatusEnum.getByStatus(status); if (status == null) { throw new
|
||||
* BusinessException(ResponseCodeEnum.CODE_600); } if
|
||||
* (AppUpdateSatusEnum.GRAYSCALE == satusEnum &&
|
||||
* StringTools.isEmpty(grayscaleDevice)) { throw new
|
||||
* BusinessException(ResponseCodeEnum.CODE_600); } if
|
||||
* (AppUpdateSatusEnum.GRAYSCALE != satusEnum) { grayscaleDevice = ""; }
|
||||
* AppUpdate update = new AppUpdate(); update.setStatus(status);
|
||||
* update.setGrayscaleDevice(grayscaleDevice); appUpdateDao.updateById(update,
|
||||
* id); }
|
||||
*/
|
||||
|
||||
public AppUpdate getLatestUpdate(String appVersion, String deviceId) {
|
||||
return appUpdateDao.selectLatestUpdate(appVersion, deviceId);
|
||||
public AppUpdate getLatestUpdate(String platform, String currentVersion, String deviceId) {
|
||||
AppUpdate latestAppUpdate = appUpdateDao.selectLatestUpdate(platform, currentVersion, deviceId);
|
||||
// 是否强制更新
|
||||
if(Objects.nonNull(latestAppUpdate) && !latestAppUpdate.getForceUpdate()) {
|
||||
String latestVersion = latestAppUpdate.getVersion();
|
||||
log.debug("platform={}, deviceId={}, currentVersion={}, latestVersion={}", platform, deviceId, currentVersion, latestVersion);
|
||||
AppUpdate forceUpdateAppUpdate = appUpdateDao.getAndCheckForceUpdate(platform, currentVersion, latestVersion);
|
||||
if(Objects.nonNull(forceUpdateAppUpdate)){
|
||||
latestAppUpdate.setForceUpdate(true);
|
||||
}
|
||||
}
|
||||
return latestAppUpdate;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue