doum
10 小时以前 f2b6fdd955f8ac6e5b351e0b5e3a9f583ed6da2e
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
package com.doumee.service.business.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.constants.Constants;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.DateUtil;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.AppVersionMapper;
import com.doumee.dao.business.model.AppVersion;
import com.doumee.service.business.AppVersionService;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
 
import java.io.File;
import java.util.*;
 
/**
 * APP版本Service实现
 * @author rk
 * @date 2026/04/10
 */
@Service
public class AppVersionServiceImpl implements AppVersionService {
 
    @Autowired
    private AppVersionMapper appVersionMapper;
 
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
 
    @Override
    public Integer create(AppVersion appVersion) {
        if (StringUtils.isBlank(appVersion.getVersionInfo())
                || StringUtils.isBlank(appVersion.getFileUrl())
                || StringUtils.isBlank(appVersion.getName())
                || StringUtils.isBlank(appVersion.getContent())
                || Objects.isNull(appVersion.getIsForce())
                || Objects.isNull(appVersion.getType())
                || Objects.isNull(appVersion.getFileSize())
                || Objects.isNull(appVersion.getVersionNum())) {
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        appVersionMapper.insert(appVersion);
        return appVersion.getId();
    }
 
    @Override
    public void deleteById(Integer id) {
        appVersionMapper.update(new UpdateWrapper<AppVersion>().lambda()
                .set(AppVersion::getDeleted, Constants.ONE)
                .eq(AppVersion::getId, id));
    }
 
    @Override
    public void delete(AppVersion appVersion) {
        UpdateWrapper<AppVersion> deleteWrapper = new UpdateWrapper<>(appVersion);
        appVersionMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (ids == null || ids.isEmpty()) {
            return;
        }
        appVersionMapper.deleteBatchIds(ids);
    }
 
    @Override
    public void updateById(AppVersion appVersion) {
        appVersionMapper.updateById(appVersion);
    }
 
    @Override
    public void updateByIdInBatch(List<AppVersion> appVersions) {
        if (appVersions == null || appVersions.isEmpty()) {
            return;
        }
        for (AppVersion appVersion : appVersions) {
            this.updateById(appVersion);
        }
    }
 
    @Override
    public AppVersion findById(Integer id) {
        AppVersion appVersion = appVersionMapper.selectById(id);
        if (Objects.isNull(appVersion)) {
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        return appVersion;
    }
 
    @Override
    public AppVersion findOne(AppVersion appVersion) {
        QueryWrapper<AppVersion> wrapper = new QueryWrapper<>(appVersion);
        return appVersionMapper.selectOne(wrapper);
    }
 
    @Override
    public List<AppVersion> findList(AppVersion appVersion) {
        QueryWrapper<AppVersion> wrapper = new QueryWrapper<>(appVersion);
        return appVersionMapper.selectList(wrapper);
    }
 
    @Override
    public PageData<AppVersion> findPage(PageWrap<AppVersion> pageWrap) {
        IPage<AppVersion> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<AppVersion> wrapper = new MPJLambdaWrapper<>();
        wrapper.selectAll(AppVersion.class)
                .select("su.REALNAME as createUserName")
                .leftJoin("system_user su on su.ID = t.CREATE_USER")
                .eq(AppVersion::getDeleted, Constants.ZERO);
        AppVersion model = pageWrap.getModel();
        Utils.MP.blankToNull(model);
        if (model.getVersionInfo() != null) {
            wrapper.like(AppVersion::getVersionInfo, model.getVersionInfo());
        }
        if (model.getName() != null) {
            wrapper.like(AppVersion::getName, model.getName());
        }
        if (model.getTitle() != null) {
            wrapper.like(AppVersion::getTitle, model.getTitle());
        }
        if (model.getIsForce() != null) {
            wrapper.eq(AppVersion::getIsForce, model.getIsForce());
        }
        if (model.getType() != null) {
            wrapper.eq(AppVersion::getType, model.getType());
        }
        wrapper.orderByDesc(AppVersion::getId);
        PageData<AppVersion> pageData = PageData.from(appVersionMapper.selectJoinPage(page, AppVersion.class, wrapper));
        String urlPrefix = systemDictDataBiz.queryByCode(Constants.OSS, Constants.APP_FILES_URL).getCode();
        for (AppVersion vo : pageData.getRecords()) {
            if (StringUtils.isNotBlank(vo.getFileUrl())) {
                vo.setFileFullUrl(urlPrefix + vo.getFileUrl());
            }
        }
        return pageData;
    }
 
    @Override
    public long count(AppVersion appVersion) {
        QueryWrapper<AppVersion> wrapper = new QueryWrapper<>(appVersion);
        return appVersionMapper.selectCount(wrapper);
    }
 
    @Override
    public AppVersion getLatestVersion(Integer type) {
        QueryWrapper<AppVersion> qw = new QueryWrapper<>();
        qw.lambda()
                .eq(AppVersion::getDeleted, Constants.ZERO)
                .eq(AppVersion::getType, type)
                .orderByDesc(AppVersion::getVersionNum)
                .last("limit 1");
        return appVersionMapper.selectOne(qw);
    }
 
    @Override
    public Map<String, Object> uploadFile(MultipartFile file) throws Exception {
        if (file == null || file.isEmpty()) {
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "上传文件不能为空");
        }
        String rootPath = systemDictDataBiz.queryByCode(Constants.OSS, Constants.APP_FILES).getCode();
        String urlPrefix = systemDictDataBiz.queryByCode(Constants.OSS, Constants.APP_FILES_URL).getCode();
        String originName = file.getOriginalFilename();
        String ext = ".apk";
        if (originName != null && originName.indexOf(".") > 0) {
            ext = originName.substring(originName.lastIndexOf("."));
        }
        String fileName =  UUID.randomUUID() + ext;
        File dest = new File(rootPath + fileName);
        if (!dest.getParentFile().exists()) {
            dest.getParentFile().mkdirs();
        }
        try {
            file.transferTo(dest);
        } catch (Exception e) {
            throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "文件上传失败: " + e.getMessage());
        }
        Map<String, Object> data = new HashMap<>();
        data.put("url", urlPrefix + fileName);
        data.put("imgaddr", fileName);
        data.put("imgname", fileName);
        data.put("originname", originName);
        return data;
    }
 
}