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().lambda() .set(AppVersion::getDeleted, Constants.ONE) .eq(AppVersion::getId, id)); } @Override public void delete(AppVersion appVersion) { UpdateWrapper deleteWrapper = new UpdateWrapper<>(appVersion); appVersionMapper.delete(deleteWrapper); } @Override public void deleteByIdInBatch(List ids) { if (ids == null || ids.isEmpty()) { return; } appVersionMapper.deleteBatchIds(ids); } @Override public void updateById(AppVersion appVersion) { appVersionMapper.updateById(appVersion); } @Override public void updateByIdInBatch(List 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 wrapper = new QueryWrapper<>(appVersion); return appVersionMapper.selectOne(wrapper); } @Override public List findList(AppVersion appVersion) { QueryWrapper wrapper = new QueryWrapper<>(appVersion); return appVersionMapper.selectList(wrapper); } @Override public PageData findPage(PageWrap pageWrap) { IPage page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); MPJLambdaWrapper 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 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 wrapper = new QueryWrapper<>(appVersion); return appVersionMapper.selectCount(wrapper); } @Override public AppVersion getLatestVersion(Integer type) { QueryWrapper 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 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 data = new HashMap<>(); data.put("url", urlPrefix + fileName); data.put("imgaddr", fileName); data.put("imgname", fileName); data.put("originname", originName); return data; } }