fix:app版本管理细节调整

This commit is contained in:
FCL
2025-12-18 10:51:21 +08:00
parent 24f4e011be
commit 8977be538d
9 changed files with 187 additions and 192 deletions

View File

@@ -0,0 +1,8 @@
package com.zt.plat.module.qms.resource.clientManage;
public class VersionManagementConst {
public static final String UPDATE_TYPE_WAITING = "0"; //未发布
public static final String PUBLISH_FLAG_PUBLISH = "1"; //已发布
public static final String PUBLISH_FLAG_OFFLINE = "2"; //下线
}

View File

@@ -56,14 +56,14 @@ public class VersionManagementController extends AbstractFileUploadController im
@Operation(summary = "创建客户端版本管理")
@PreAuthorize("@ss.hasPermission('qms:version-management:create')")
public CommonResult<VersionManagementRespVO> createSystemVersionManagement(@Valid @RequestBody VersionManagementSaveReqVO createReqVO) {
return success(systemVersionManagementService.createSystemVersionManagement(createReqVO));
return success(systemVersionManagementService.createVersionManagement(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新客户端版本管理")
@PreAuthorize("@ss.hasPermission('qms:version-management:update')")
public CommonResult<Boolean> updateSystemVersionManagement(@Valid @RequestBody VersionManagementSaveReqVO updateReqVO) {
systemVersionManagementService.updateSystemVersionManagement(updateReqVO);
systemVersionManagementService.updateVersionManagement(updateReqVO);
return success(true);
}
@@ -72,7 +72,7 @@ public class VersionManagementController extends AbstractFileUploadController im
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('qms:version-management:delete')")
public CommonResult<Boolean> deleteSystemVersionManagement(@RequestParam("id") Long id) {
systemVersionManagementService.deleteSystemVersionManagement(id);
systemVersionManagementService.deleteVersionManagement(id);
return success(true);
}
@@ -90,7 +90,7 @@ public class VersionManagementController extends AbstractFileUploadController im
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('qms:version-management:query')")
public CommonResult<VersionManagementRespVO> getSystemVersionManagement(@RequestParam("id") Long id) {
VersionManagementDO systemVersionManagement = systemVersionManagementService.getSystemVersionManagement(id);
VersionManagementDO systemVersionManagement = systemVersionManagementService.getVersionManagement(id);
return success(BeanUtils.toBean(systemVersionManagement, VersionManagementRespVO.class));
}
@@ -98,7 +98,7 @@ public class VersionManagementController extends AbstractFileUploadController im
@Operation(summary = "获得客户端版本管理分页")
@PreAuthorize("@ss.hasPermission('qms:version-management:query')")
public CommonResult<PageResult<VersionManagementRespVO>> getSystemVersionManagementPage(@Valid VersionManagementPageReqVO pageReqVO) {
PageResult<VersionManagementDO> pageResult = systemVersionManagementService.getSystemVersionManagementPage(pageReqVO);
PageResult<VersionManagementDO> pageResult = systemVersionManagementService.getVersionManagementPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, VersionManagementRespVO.class));
}
@@ -109,7 +109,7 @@ public class VersionManagementController extends AbstractFileUploadController im
public void exportSystemVersionManagementExcel(@Valid VersionManagementPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<VersionManagementDO> list = systemVersionManagementService.getSystemVersionManagementPage(pageReqVO).getList();
List<VersionManagementDO> list = systemVersionManagementService.getVersionManagementPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "客户端版本管理.xls", "数据", VersionManagementRespVO.class,
BeanUtils.toBean(list, VersionManagementRespVO.class));
@@ -118,7 +118,7 @@ public class VersionManagementController extends AbstractFileUploadController im
@GetMapping("/checkUpdate")
@Operation(summary = "根据更新平台和安装包类型获取最新客户端版本管理信息")
public CommonResult<PageResult<VersionManagementRespVO>> checkUpdate(@Valid VersionManagementPageReqVO pageReqVO) {
public CommonResult<VersionManagementRespVO> checkUpdate(@Valid VersionManagementPageReqVO pageReqVO) {
if (pageReqVO.getApplicationCode() == null ) {
return CommonResult.error(400, "客户端编号不能为空");
@@ -126,13 +126,17 @@ public class VersionManagementController extends AbstractFileUploadController im
if (pageReqVO.getUpdatePlatform() == null ) {
return CommonResult.error(400, "更新平台不能为空");
}
PageResult<VersionManagementDO> pageResult = systemVersionManagementService.getLts(pageReqVO);
return success(BeanUtils.toBean(pageResult, VersionManagementRespVO.class));
PageResult<VersionManagementDO> pageResult = systemVersionManagementService.getList(pageReqVO);
if (pageResult.getList().size() == 0) {
return CommonResult.error(400, "没有可更新版本");
}
VersionManagementDO versionManagementDO = pageResult.getList().get(0);
return success(BeanUtils.toBean(versionManagementDO, VersionManagementRespVO.class));
}
@GetMapping("/publish")
CommonResult<Boolean> publish(@RequestParam("id") Long id) {
systemVersionManagementService.publish(id);
return success(true);
@GetMapping("/executePublish")
CommonResult<String> executePublish(@RequestParam("id") Long id) {
systemVersionManagementService.executePublish(id);
return success("发布成功");
}
}

View File

@@ -5,7 +5,7 @@ import lombok.Data;
@Schema(description = "附件实例")
@Data
public class uploadFileVo {
public class UploadFileVo {
private String id;
private String url;

View File

@@ -65,11 +65,10 @@ public class VersionManagementSaveReqVO {
@Schema(description = "备注")
private String remark;
@Schema(description = "上传文件列表")
private List<uploadFileVo> files;
@Schema(description = "上传文件Uid")
private String downloadId;
//==========扩展属性===============
@Schema(description = "上传文件列表")
private List<UploadFileVo> files;
}

View File

@@ -111,9 +111,6 @@ public class VersionManagementDO extends BusinessBaseDO {
@TableField("RMK")
private String remark;
@TableField("CREATOR")
private String creator;
@TableField("DL_ID")
private String downloadId;

View File

@@ -43,18 +43,4 @@ public interface VersionManagementMapper extends BaseMapperX<VersionManagementDO
// .last("LIMIT 1")
);
}
default List<VersionManagementDO> selectBySameCode(Long id) {
// 先根据id查询出目标记录的custDeviceCode
VersionManagementDO target = selectById(id);
if (target == null) {
return Collections.emptyList();
}
// 查询相同custDeviceCode的所有记录
return selectList(new LambdaQueryWrapperX<VersionManagementDO>()
.eq(VersionManagementDO::getApplicationCode, target.getApplicationCode())
.eq(VersionManagementDO::getPublishFlag, 1)
.orderByDesc(VersionManagementDO::getCreateTime));
}
}

View File

@@ -22,21 +22,21 @@ public interface VersionManagementService {
* @param createReqVO 创建信息
* @return 编号
*/
VersionManagementRespVO createSystemVersionManagement(@Valid VersionManagementSaveReqVO createReqVO);
VersionManagementRespVO createVersionManagement(@Valid VersionManagementSaveReqVO createReqVO);
/**
* 更新客户端版本管理
*
* @param updateReqVO 更新信息
*/
void updateSystemVersionManagement(@Valid VersionManagementSaveReqVO updateReqVO);
void updateVersionManagement(@Valid VersionManagementSaveReqVO updateReqVO);
/**
* 删除客户端版本管理
*
* @param id 编号
*/
void deleteSystemVersionManagement(Long id);
void deleteVersionManagement(Long id);
/**
* 批量删除客户端版本管理
@@ -51,7 +51,7 @@ public interface VersionManagementService {
* @param id 编号
* @return 客户端版本管理
*/
VersionManagementDO getSystemVersionManagement(Long id);
VersionManagementDO getVersionManagement(Long id);
/**
* 获得客户端版本管理分页
@@ -59,7 +59,7 @@ public interface VersionManagementService {
* @param pageReqVO 分页查询
* @return 客户端版本管理分页
*/
PageResult<VersionManagementDO> getSystemVersionManagementPage(VersionManagementPageReqVO pageReqVO);
PageResult<VersionManagementDO> getVersionManagementPage(VersionManagementPageReqVO pageReqVO);
/**
@@ -68,11 +68,11 @@ public interface VersionManagementService {
* @param pageReqVO 分页查询
* @return 客户端版本管理分页
*/
PageResult<VersionManagementDO> getLts(VersionManagementPageReqVO pageReqVO);
PageResult<VersionManagementDO> getList(VersionManagementPageReqVO pageReqVO);
/**
* 版本发布
* @param id
*/
void publish (Long id);
void executePublish(Long id);
}

View File

@@ -0,0 +1,151 @@
package com.zt.plat.module.qms.resource.clientManage.service;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zt.plat.module.qms.resource.clientManage.VersionManagementConst;
import com.zt.plat.module.qms.resource.clientManage.controller.vo.VersionManagementPageReqVO;
import com.zt.plat.module.qms.resource.clientManage.controller.vo.VersionManagementRespVO;
import com.zt.plat.module.qms.resource.clientManage.controller.vo.VersionManagementSaveReqVO;
import com.zt.plat.module.qms.resource.clientManage.controller.vo.UploadFileVo;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import java.util.*;
import com.zt.plat.module.qms.resource.clientManage.dal.dataobject.VersionManagementDO;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.module.qms.resource.clientManage.dal.mapper.VersionManagementMapper;
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception0;
import static com.zt.plat.framework.common.util.collection.CollectionUtils.convertList;
import static com.zt.plat.module.qms.enums.ErrorCodeConstants.*;
/**
* 客户端版本管理 Service 实现类
*
* @author 后台管理
*/
@Service
@Validated
public class VersionManagementServiceImpl implements VersionManagementService {
@Resource
private VersionManagementMapper versionManagementMapper;
@Override
public VersionManagementRespVO createVersionManagement(VersionManagementSaveReqVO createReqVO) {
//多条数据取第一条
// 插入
VersionManagementDO versionManagement = BeanUtils.toBean(createReqVO, VersionManagementDO.class);
// LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();//获取当前登录人通用方法
// systemVersionManagement.setCreator(String.valueOf(SecurityFrameworkUtils.getLoginUser().getId()));
handleFileParam(createReqVO);
versionManagementMapper.insert(versionManagement);
// 返回
return BeanUtils.toBean(versionManagement, VersionManagementRespVO.class);
}
@Override
public void updateVersionManagement(VersionManagementSaveReqVO updateReqVO) {
// 校验存在
validateVersionManagementExists(updateReqVO.getId());
handleFileParam(updateReqVO);
// 更新
VersionManagementDO updateObj = BeanUtils.toBean(updateReqVO, VersionManagementDO.class);
// updateObj.setUpdater(String.valueOf(SecurityFrameworkUtils.getLoginUser().getId()));
versionManagementMapper.updateById(updateObj);
}
//处理附件参数
private void handleFileParam(VersionManagementSaveReqVO reqVO){
List<UploadFileVo> files = reqVO.getFiles();
if (files == null || files.isEmpty())
return;
UploadFileVo uploadFileVo = files.get(0);
reqVO.setDownloadUrl(uploadFileVo.getUrl());
reqVO.setFileMd5(uploadFileVo.getMd5());
reqVO.setFileEncryptAlgorithm(uploadFileVo.getSha1());
reqVO.setDownloadId(uploadFileVo.getId());
}
@Override
public void deleteVersionManagement(Long id) {
// 校验存在
validateVersionManagementExists(id);
// 删除
versionManagementMapper.deleteById(id);
}
@Override
public void deleteSystemVersionManagementListByIds(List<Long> ids) {
// 校验存在
validateVersionManagementExists(ids);
// 删除
versionManagementMapper.deleteByIds(ids);
}
private void validateVersionManagementExists(List<Long> ids) {
List<VersionManagementDO> list = versionManagementMapper.selectByIds(ids);
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
throw exception(SYSTEM_VERSION_MANAGEMENT_NOT_EXISTS);
}
}
private void validateVersionManagementExists(Long id) {
if (versionManagementMapper.selectById(id) == null) {
throw exception(SYSTEM_VERSION_MANAGEMENT_NOT_EXISTS);
}
}
@Override
public VersionManagementDO getVersionManagement(Long id) {
return versionManagementMapper.selectById(id);
}
@Override
public PageResult<VersionManagementDO> getVersionManagementPage(VersionManagementPageReqVO pageReqVO) {
return versionManagementMapper.selectPage(pageReqVO);
}
@Override
public PageResult<VersionManagementDO> getList(VersionManagementPageReqVO pageReqVO) {
return versionManagementMapper.selectList(pageReqVO);
}
/*
* 发布*/
@Override
@Transactional(rollbackFor = Exception.class)
public void executePublish(Long id) {
// 校验存在
validateVersionManagementExists(id);
// 下线当前发布的版本
VersionManagementDO entity = versionManagementMapper.selectById(id);
if(ObjectUtils.isEmpty( entity.getDownloadUrl()) || ObjectUtils.isEmpty( entity.getDownloadId()))
throw exception0(SYSTEM_VERSION_MANAGEMENT_NOT_EXISTS.getCode(), "请上传附件后再发布!");
String code = entity.getApplicationCode();
LambdaQueryWrapper<VersionManagementDO> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(VersionManagementDO::getApplicationCode, code);
queryWrapper.eq(VersionManagementDO::getPublishFlag, VersionManagementConst.PUBLISH_FLAG_PUBLISH);
queryWrapper.ne(VersionManagementDO::getId, id);
List<VersionManagementDO> list = versionManagementMapper.selectList(queryWrapper);
if(!list.isEmpty()){
for(VersionManagementDO versionManagementDO : list){
versionManagementDO.setPublishFlag(VersionManagementConst.PUBLISH_FLAG_OFFLINE);
}
versionManagementMapper.updateBatch(list);
}
entity.setPublishFlag(VersionManagementConst.PUBLISH_FLAG_PUBLISH);
versionManagementMapper.updateById(entity);
}
}

View File

@@ -1,150 +0,0 @@
package com.zt.plat.module.qms.resource.clientManage.service;
import cn.hutool.core.collection.CollUtil;
import com.zt.plat.framework.security.core.util.SecurityFrameworkUtils;
import com.zt.plat.module.qms.resource.clientManage.controller.vo.VersionManagementPageReqVO;
import com.zt.plat.module.qms.resource.clientManage.controller.vo.VersionManagementRespVO;
import com.zt.plat.module.qms.resource.clientManage.controller.vo.VersionManagementSaveReqVO;
import com.zt.plat.module.qms.resource.clientManage.controller.vo.uploadFileVo;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import java.util.*;
import com.zt.plat.module.qms.resource.clientManage.dal.dataobject.VersionManagementDO;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.module.qms.resource.clientManage.dal.mapper.VersionManagementMapper;
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.zt.plat.framework.common.util.collection.CollectionUtils.convertList;
import static com.zt.plat.module.qms.enums.ErrorCodeConstants.*;
/**
* 客户端版本管理 Service 实现类
*
* @author 后台管理
*/
@Service
@Validated
public class versionManagementServiceImpl implements VersionManagementService {
@Resource
private VersionManagementMapper systemVersionManagementMapper;
@Override
public VersionManagementRespVO createSystemVersionManagement(VersionManagementSaveReqVO createReqVO) {
//多条数据取第一条
if (createReqVO.getFiles() != null && createReqVO.getFiles().size() > 0) {
uploadFileVo uploadFileVo = createReqVO.getFiles().get(0);
createReqVO.setDownloadUrl(uploadFileVo.getUrl());
createReqVO.setFileMd5(uploadFileVo.getMd5());
createReqVO.setFileEncryptAlgorithm(uploadFileVo.getSha1());
createReqVO.setDownloadId(uploadFileVo.getId());
}
// 插入
VersionManagementDO systemVersionManagement = BeanUtils.toBean(createReqVO, VersionManagementDO.class);
// LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();//获取当前登录人通用方法
systemVersionManagement.setCreator(String.valueOf(SecurityFrameworkUtils.getLoginUser().getId()));
systemVersionManagementMapper.insert(systemVersionManagement);
// 返回
return BeanUtils.toBean(systemVersionManagement, VersionManagementRespVO.class);
}
@Override
public void updateSystemVersionManagement(VersionManagementSaveReqVO updateReqVO) {
// 校验存在
validateSystemVersionManagementExists(updateReqVO.getId());
//多条数据取第一条
if (updateReqVO.getFiles() != null && updateReqVO.getFiles().size() > 0) {
uploadFileVo uploadFileVo = updateReqVO.getFiles().get(0);
updateReqVO.setDownloadUrl(uploadFileVo.getUrl());
updateReqVO.setFileMd5(uploadFileVo.getMd5());
updateReqVO.setFileEncryptAlgorithm(uploadFileVo.getSha1());
updateReqVO.setDownloadId(uploadFileVo.getId());
}
// 更新
VersionManagementDO updateObj = BeanUtils.toBean(updateReqVO, VersionManagementDO.class);
updateObj.setUpdater(String.valueOf(SecurityFrameworkUtils.getLoginUser().getId()));
systemVersionManagementMapper.updateById(updateObj);
}
@Override
public void deleteSystemVersionManagement(Long id) {
// 校验存在
validateSystemVersionManagementExists(id);
// 删除
systemVersionManagementMapper.deleteById(id);
}
@Override
public void deleteSystemVersionManagementListByIds(List<Long> ids) {
// 校验存在
validateSystemVersionManagementExists(ids);
// 删除
systemVersionManagementMapper.deleteByIds(ids);
}
private void validateSystemVersionManagementExists(List<Long> ids) {
List<VersionManagementDO> list = systemVersionManagementMapper.selectByIds(ids);
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
throw exception(SYSTEM_VERSION_MANAGEMENT_NOT_EXISTS);
}
}
private void validateSystemVersionManagementExists(Long id) {
if (systemVersionManagementMapper.selectById(id) == null) {
throw exception(SYSTEM_VERSION_MANAGEMENT_NOT_EXISTS);
}
}
@Override
public VersionManagementDO getSystemVersionManagement(Long id) {
return systemVersionManagementMapper.selectById(id);
}
@Override
public PageResult<VersionManagementDO> getSystemVersionManagementPage(VersionManagementPageReqVO pageReqVO) {
return systemVersionManagementMapper.selectPage(pageReqVO);
}
@Override
public PageResult<VersionManagementDO> getLts(VersionManagementPageReqVO pageReqVO) {
return systemVersionManagementMapper.selectList(pageReqVO);
}
@Override
public void publish(Long id) {
// 校验存在
validateSystemVersionManagementExists(id);
// 下线当前发布的版本
List<VersionManagementDO> versionManagementDOS = systemVersionManagementMapper.selectBySameCode(id);
if (versionManagementDOS.size() > 0) {
VersionManagementDO versionManagementDO = versionManagementDOS.get(0);
VersionManagementDO offlineVO = new VersionManagementDO();
offlineVO.setId(versionManagementDO.getId());
// offlineVO.setPublishFlag(2);
systemVersionManagementMapper.updateById(offlineVO);
}
VersionManagementDO onlineVO = new VersionManagementDO();
onlineVO.setId(id);
// onlineVO.setPublishFlag(1);
systemVersionManagementMapper.updateById(onlineVO);
}
}