| | |
| | | package com.ruoyi.other.service.impl; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.enums.FileNameType; |
| | | import com.ruoyi.basic.enums.ApplicationTypeEnum; |
| | | import com.ruoyi.basic.enums.RecordTypeEnum; |
| | | import com.ruoyi.basic.utils.FileUtil; |
| | | import com.ruoyi.other.dto.PdaVersionDTO; |
| | | import com.ruoyi.other.mapper.PdaVersionMapper; |
| | | import com.ruoyi.other.pojo.PdaVersion; |
| | | import com.ruoyi.other.service.PdaVersionService; |
| | | import com.ruoyi.other.service.TempFileService; |
| | | import com.ruoyi.sales.service.impl.CommonFileServiceImpl; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.Assert; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | @RequiredArgsConstructor |
| | |
| | | |
| | | private final PdaVersionMapper pdaVersionMapper; |
| | | |
| | | private final TempFileService tempFileService; |
| | | |
| | | private final CommonFileServiceImpl commonFileService; |
| | | private final FileUtil fileUtil; |
| | | |
| | | @Override |
| | | public IPage<PdaVersion> getAllVersion(Page<PdaVersion> page, PdaVersion pdaVersion) { |
| | | public IPage<PdaVersionDTO> getAllVersion(Page<PdaVersion> page, PdaVersion pdaVersion) { |
| | | LambdaQueryWrapper<PdaVersion> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.orderByDesc(PdaVersion::getCreateTime); |
| | | Page<PdaVersion> pdaVersionPage = pdaVersionMapper.selectPage(page, queryWrapper); |
| | | pdaVersionPage.getRecords().forEach(item ->{ |
| | | item.setCommonFileList(commonFileService.getFileListByBusinessId(item.getId(), FileNameType.APP.getValue())); |
| | | Page<PdaVersionDTO> pdaVersionDTOPage = new Page<>(page.getCurrent(), page.getSize()); |
| | | List<PdaVersionDTO> pdaVersionDTOList = new ArrayList<>(); |
| | | pdaVersionPage.getRecords().forEach(item -> { |
| | | PdaVersionDTO pdaVersionDTO = new PdaVersionDTO(); |
| | | BeanUtil.copyProperties(item, pdaVersionDTO); |
| | | pdaVersionDTO.setStorageBlobVOList(fileUtil.getStorageBlobVOsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum.APK, RecordTypeEnum.PDA_VERSION, item.getId())); |
| | | String downloadURL = fileUtil.getFileDownloadURLByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum.APK, RecordTypeEnum.PDA_VERSION, item.getId()).get(0) == null ? |
| | | "" : fileUtil.getFileDownloadURLByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum.APK, RecordTypeEnum.PDA_VERSION, item.getId()).get(0); |
| | | pdaVersionDTO.setDownloadURL(downloadURL); |
| | | pdaVersionDTOList.add(pdaVersionDTO); |
| | | }); |
| | | return pdaVersionPage; |
| | | pdaVersionDTOPage.setRecords(pdaVersionDTOList); |
| | | return pdaVersionDTOPage; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean uploadApk(MultipartFile file, String name, String version) { |
| | | public boolean add(PdaVersionDTO pdaVersion) { |
| | | // 参数校验 |
| | | Assert.notNull(file, "文件不能为空"); |
| | | Assert.hasText(version, "版本号不能为空"); |
| | | |
| | | try { |
| | | PdaVersion pdaVersion = new PdaVersion(); |
| | | pdaVersion.setName(name); |
| | | pdaVersion.setVersion(version); |
| | | pdaVersionMapper.insert(pdaVersion); |
| | | |
| | | tempFileService.uploadByCommon(file, FileNameType.APP.getValue(), pdaVersion.getId()); |
| | | return true; |
| | | } catch (Exception e) { |
| | | throw new RuntimeException("上传APK失败: " + e.getMessage()); |
| | | } |
| | | Assert.hasText(pdaVersion.getVersion(), "版本号不能为空"); |
| | | pdaVersionMapper.insert(pdaVersion); |
| | | fileUtil.saveStorageAttachment(ApplicationTypeEnum.APK, RecordTypeEnum.PDA_VERSION, pdaVersion.getId(), pdaVersion.getStorageBlobDTOList()); |
| | | return true; |
| | | } |
| | | } |