| | |
| | | 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 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.util.List; |
| | | import java.util.Objects; |
| | | import java.io.File; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * APP版本Service实现 |
| | |
| | | @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()) |
| | | || StringUtils.isBlank(appVersion.getTitle()) |
| | | || Objects.isNull(appVersion.getIsForce()) |
| | | || Objects.isNull(appVersion.getType()) |
| | | || Objects.isNull(appVersion.getFileSize()) |
| | |
| | | wrapper.eq(AppVersion::getType, model.getType()); |
| | | } |
| | | wrapper.orderByDesc(AppVersion::getId); |
| | | return PageData.from(appVersionMapper.selectJoinPage(page, AppVersion.class, wrapper)); |
| | | 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 |
| | |
| | | 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; |
| | | } |
| | | |
| | | } |