1. add version management
This commit is contained in:
2026-04-02 15:37:41 +08:00
parent c612d69699
commit 233bb596a9
10 changed files with 255 additions and 17 deletions

View File

@@ -11,7 +11,6 @@ import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.common.pojo.entity.TourProductEntity;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.common.pojo.entity.CommonReleaseVersionEntity;
@@ -20,8 +19,6 @@ import org.springblade.modules.common.wrapper.CommonReleaseVersionWrapper;
import org.springblade.modules.common.service.ICommonReleaseVersionService;
import org.springblade.core.boot.ctrl.BladeController;
import java.util.Map;
/**
* APP版本发布管理 控制器
@@ -69,14 +66,15 @@ public class CommonReleaseVersionController extends BladeController {
return R.data(pages);
}
/**
* APP版本发布管理 新增
*/
@PostMapping("/save")
@ApiOperationSupport(order = 4)
@Operation(summary = "新增", description = "传入commonReleaseversion")
public R save(@Valid @RequestBody CommonReleaseVersionEntity commonReleaseVersion) {
return R.status(commonReleaseVersionService.save(commonReleaseVersion));
@Operation(summary = "新增", description = "传入vo")
public R save(@Valid @RequestBody CommonReleaseVersionVO vo) {
return R.status(commonReleaseVersionService.createVersion(vo));
}
/**

View File

@@ -0,0 +1,36 @@
package org.springblade.modules.common.convert;
import org.mapstruct.*;
import org.mapstruct.factory.Mappers;
import org.springblade.modules.common.eums.AppMarketChannelEnum;
import org.springblade.modules.common.eums.VersionStatus;
import org.springblade.modules.common.pojo.entity.CommonReleaseVersionEntity;
@Mapper
public interface CommonReleaseVersionConvert {
CommonReleaseVersionConvert INSTANCE = Mappers.getMapper(CommonReleaseVersionConvert.class);
@Mapping(target = "id", ignore = true)
@Mapping(target = "createTime", ignore = true)
@Mapping(target = "updateTime", ignore = true)
@Mapping(target = "createUser", ignore = true)
@Mapping(target = "updateUser", ignore = true)
CommonReleaseVersionEntity copyForChannel(CommonReleaseVersionEntity source, @Context AppMarketChannelEnum channel);
@AfterMapping
default void setChannelAndStatus(@MappingTarget CommonReleaseVersionEntity target,
@Context AppMarketChannelEnum channel) {
target.setChannelCode(channel.getCode());
// 注意:OFFICIAL 渠道状态为 PUBLISHED,其他为 ENABLED
if (channel == AppMarketChannelEnum.OFFICIAL) {
target.setPackageType(2);
target.setStatus(VersionStatus.PUBLISHED.getCode());
} else {
target.setPackageType(1);
target.setDownloadUrl(null);
target.setStatus(VersionStatus.ENABLED.getCode());
}
}
}

View File

@@ -0,0 +1,51 @@
package org.springblade.modules.common.eums;
import lombok.Getter;
@Getter
public enum AppMarketChannelEnum {
XIAOMI("xiaomi", "小米应用商店"),
HUAWEI("huawei", "华为应用市场"),
HONOR("honor", "荣耀应用市场"),
OPPO("oppo", "OPPO 软件商店"),
VIVO("vivo", "vivo 应用商店"),
APPLE("apple", "App Store"),
QIHOO("qihoo", "360手机助手"),
YINGYONGBAO("yingyongbao", "应用宝"),
PGYER("pgyer", "蒲公英分发平台"),
OFFICIAL("official", "官网/自有渠道");
private final String code;
private final String name;
AppMarketChannelEnum(String code, String name) {
this.code = code;
this.name = name;
}
/**
* 根据 code 获取枚举项
*/
public static AppMarketChannelEnum fromCode(String code) {
for (AppMarketChannelEnum channel : AppMarketChannelEnum.values()) {
if (channel.code.equalsIgnoreCase(code)) {
return channel;
}
}
throw new IllegalArgumentException("Unknown app market channel code: " + code);
}
/**
* 判断 code 是否有效
*/
public static boolean isValid(String code) {
try {
fromCode(code);
return true;
} catch (IllegalArgumentException e) {
return false;
}
}
}

View File

@@ -0,0 +1,27 @@
package org.springblade.modules.common.eums;
import lombok.Getter;
@Getter
public enum VersionStatus {
ENABLED(1, "启用"),
PUBLISHED(2, "已上架"),
EXPIRED(3, "过期");
private final int code;
private final String description;
VersionStatus(int code, String description) {
this.code = code;
this.description = description;
}
public static VersionStatus fromCode(int code) {
for (VersionStatus status : values()) {
if (status.code == code) {
return status;
}
}
throw new IllegalArgumentException("Invalid code: " + code);
}
}

View File

@@ -23,6 +23,8 @@ public interface CommonReleaseVersionMapper extends BaseMapper<CommonReleaseVers
*/
List<CommonReleaseVersionVO> selectCommonReleaseVersionPage(IPage page, CommonReleaseVersionVO commonReleaseVersion);
List<CommonReleaseVersionVO> selectCustomerCommonReleaseVersionPage(IPage page, CommonReleaseVersionVO commonReleaseVersion);
}

View File

@@ -31,6 +31,21 @@
select * from release_version where is_deleted = 0
</select>
<select id="selectCustomerCommonReleaseVersionPage" resultType="org.springblade.modules.common.pojo.vo.CommonReleaseVersionVO">
SELECT DISTINCT ON (app_type, version_name)
app_type,
version_name,
is_force_update,
download_url,
privacy_agreement_url,
user_agreement_url,
update_content,
dispatch_url,
dispatch_target_version
FROM release_version
WHERE is_deleted = 0
ORDER BY app_type, version_name, id DESC
</select>
</mapper>

View File

@@ -25,10 +25,12 @@
*/
package org.springblade.modules.common.pojo.vo;
import org.springblade.modules.common.pojo.entity.CommonReleaseVersionEntity;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
/**
* APP版本发布管理 视图实体类
@@ -37,9 +39,31 @@ import java.io.Serial;
* @since 2026-04-01
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class CommonReleaseVersionVO extends CommonReleaseVersionEntity {
public class CommonReleaseVersionVO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@NotEmpty
private String versionName;
@NotNull
private Integer appType;
@NotNull
private Integer isForceUpdate;
@NotEmpty
private String updateContent;
private String privacyAgreementUrl;
private String userAgreementUrl;
@NotEmpty
private String downloadUrl;
private String dispatchUrl;
private String dispatchTargetVersion;
}

View File

@@ -26,4 +26,6 @@ public interface ICommonReleaseVersionService extends BaseService<CommonReleaseV
boolean applyStatus(Long id);
CheckVersionResponse checkUpdate(Integer type, String version, String brand);
boolean createVersion(CommonReleaseVersionVO vo);
}

View File

@@ -1,7 +1,16 @@
package org.springblade.modules.common.service.impl;
import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import jakarta.validation.Valid;
import org.jspecify.annotations.NonNull;
import org.semver4j.Semver;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.modules.api.response.CheckVersionResponse;
import org.springblade.modules.common.convert.CommonReleaseVersionConvert;
import org.springblade.modules.common.eums.AppMarketChannelEnum;
import org.springblade.modules.common.eums.AppType;
import org.springblade.modules.common.eums.VersionStatus;
import org.springblade.modules.common.pojo.entity.CommonReleaseVersionEntity;
import org.springblade.modules.common.pojo.vo.CommonReleaseVersionVO;
import org.springblade.modules.common.mapper.CommonReleaseVersionMapper;
@@ -9,6 +18,12 @@ import org.springblade.modules.common.service.ICommonReleaseVersionService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
/**
* APP版本发布管理 服务实现类
@@ -21,7 +36,7 @@ public class CommonReleaseVersionServiceImpl extends BaseServiceImpl<CommonRelea
@Override
public IPage<CommonReleaseVersionVO> selectCommonReleaseVersionPage(IPage<CommonReleaseVersionVO> page, CommonReleaseVersionVO commonReleaseVersion) {
return page.setRecords(baseMapper.selectCommonReleaseVersionPage(page, commonReleaseVersion));
return page.setRecords(baseMapper.selectCustomerCommonReleaseVersionPage(page, commonReleaseVersion));
}
@Override
@@ -39,5 +54,68 @@ public class CommonReleaseVersionServiceImpl extends BaseServiceImpl<CommonRelea
return null;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean createVersion(CommonReleaseVersionVO vo) {
AppType appType = AppType.fromCode(vo.getAppType());
if (appType == null) {
throw new ServiceException("无效类型");
}
Semver semver = parseSemver((vo.getVersionName()));
CommonReleaseVersionEntity current = baseMapper.selectOne(
Wrappers.lambdaQuery(CommonReleaseVersionEntity.class)
.eq(CommonReleaseVersionEntity::getAppType, vo.getAppType())
.ne(CommonReleaseVersionEntity::getStatus, VersionStatus.EXPIRED.getCode())
.orderByDesc(CommonReleaseVersionEntity::getId)
.last("LIMIT 1")
);
if (current != null) {
Semver currentSemver = parseSemver(current.getVersionName());
if (currentSemver.isGreaterThan(semver)) {
throw new ServiceException("当前版本号过小");
}
}
List<CommonReleaseVersionEntity> versionList = new ArrayList<>();
CommonReleaseVersionEntity officialVersion = getCommonReleaseVersionEntity(vo);
versionList.add(officialVersion);
versionList.add(getCopyByChannel(officialVersion, AppMarketChannelEnum.PGYER));
if (vo.getAppType().equals(AppType.APP.getCode())) {
Arrays.stream(AppMarketChannelEnum.values()).filter(channel -> channel != AppMarketChannelEnum.PGYER && channel != AppMarketChannelEnum.OFFICIAL).forEach(channel -> {
versionList.add(getCopyByChannel(officialVersion, channel));
});
}
return saveBatch(versionList);
}
private static CommonReleaseVersionEntity getCommonReleaseVersionEntity(CommonReleaseVersionVO vo) {
CommonReleaseVersionEntity entity = new CommonReleaseVersionEntity();
// 手动设 VO 特有字段(或也可用另一个 MapStruct VO->Entity)
entity.setVersionName(vo.getVersionName());
entity.setAppType(vo.getAppType());
entity.setPrivacyAgreementUrl(vo.getPrivacyAgreementUrl());
entity.setUserAgreementUrl(vo.getUserAgreementUrl());
entity.setIsForceUpdate(vo.getIsForceUpdate());
entity.setUpdateContent(vo.getUpdateContent());
entity.setDownloadUrl(vo.getDownloadUrl());
entity.setDispatchUrl(vo.getDispatchUrl());
entity.setDispatchTargetVersion(vo.getDispatchTargetVersion());
// 使用 MapStruct 设置渠道和状态
return CommonReleaseVersionConvert.INSTANCE.copyForChannel(entity, AppMarketChannelEnum.OFFICIAL);
}
private static CommonReleaseVersionEntity getCopyByChannel(CommonReleaseVersionEntity entity, AppMarketChannelEnum channel) {
return CommonReleaseVersionConvert.INSTANCE.copyForChannel(entity, channel);
}
private Semver parseSemver(String versionName) {
Semver semver = Semver.coerce(versionName);
if (semver == null) {
throw new ServiceException("无效版本号: " + versionName);
}
return semver;
}
}