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;
|
}
|
|
}
|