医院废弃物信息化管理平台
“mitao”
2025-12-24 3763145f34d7706923d55edc32f5cfbc8bc08b92
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
package cn.besteam.modules.medical.service.impl;
 
import cn.besteam.common.constant.ErrorCode;
import cn.besteam.common.exception.BusinessException;
import cn.besteam.modules.medical.dto.MwAppVersionDTO;
import cn.besteam.modules.medical.entity.MwAppVersion;
import cn.besteam.modules.medical.mapper.MwAppVersionMapper;
import cn.besteam.modules.medical.service.IMwAppVersionService;
import cn.besteam.modules.system.service.IOssService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
/**
 * @Description: APP-版本
 * @author: besteam
 * @date: 2020-04-25
 * @version: V1.0
 */
@Service
public class MwAppVersionServiceImpl extends ServiceImpl<MwAppVersionMapper, MwAppVersion> implements IMwAppVersionService {
 
    @Autowired
    private IOssService ossService;
 
    @Override
    public boolean uploadApk(MwAppVersionDTO dto) {
 
        MwAppVersion appVersionEntity = getOne(new QueryWrapper<MwAppVersion>().lambda().eq(MwAppVersion::getVersion, dto.getVersion()));
        if (appVersionEntity != null) {
            throw new BusinessException(ErrorCode.MW_APK_VERSION_REPEAT);
        }
        if (!checkSuffix(dto.getFile().getOriginalFilename())) {
            throw new BusinessException(ErrorCode.MW_APK_SUFFIX_NAME_ERROR);
        }
        appVersionEntity = new MwAppVersion();
        BeanUtils.copyProperties(dto, appVersionEntity);
        appVersionEntity.setFileName(dto.getFile().getOriginalFilename());
        appVersionEntity.setDownloadUrl(ossService.upload("app",dto.getFile()));
        return save(appVersionEntity);
    }
 
    private boolean checkSuffix(String fileName) {
 
        int index = fileName.lastIndexOf(".");
        if (index == -1) {
            return false;
        }
        String suffixName = fileName.substring(index + 1);
        if (!suffixName.equals("apk")) {
            return false;
        }
        return true;
    }
 
}