22 分钟以前 0541c0791acea41b584f71fc59e22d4d21ba0883
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.ruoyi.other.service.impl;
 
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.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;
 
@Service
@RequiredArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class PdaVersionServiceImpl extends ServiceImpl<PdaVersionMapper, PdaVersion> implements PdaVersionService {
 
    private final PdaVersionMapper pdaVersionMapper;
 
    private final TempFileService tempFileService;
 
    private final CommonFileServiceImpl commonFileService;
 
    @Override
    public IPage<PdaVersion> 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()));
        });
        return pdaVersionPage;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean uploadApk(MultipartFile file, String name, String version) {
        // 参数校验
        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());
        }
    }
}