package com.gkhy.safePlatform.account.service.impl;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.gkhy.safePlatform.account.entity.app.AppVersionInfo;
|
import com.gkhy.safePlatform.account.enums.AppTypeEnum;
|
import com.gkhy.safePlatform.account.enums.AppVersionStatusEnum;
|
import com.gkhy.safePlatform.account.model.bo.ObjectItemBO;
|
import com.gkhy.safePlatform.account.model.dto.req.AppAddReqDTO;
|
import com.gkhy.safePlatform.account.model.dto.req.AppModReqDTO;
|
import com.gkhy.safePlatform.account.model.dto.resp.AppVersionRespDTO;
|
import com.gkhy.safePlatform.account.model.dto.resp.ObjectItemRespDTO;
|
import com.gkhy.safePlatform.account.model.query.AppVersionPageQuery;
|
import com.gkhy.safePlatform.account.model.query.db.AppVersionPageDBQuery;
|
import com.gkhy.safePlatform.account.service.AppVersionService;
|
import com.gkhy.safePlatform.account.service.baseService.AppVersionInfoService;
|
import com.gkhy.safePlatform.account.utils.MinioUtils;
|
import com.gkhy.safePlatform.commons.co.ContextCacheUser;
|
import com.gkhy.safePlatform.commons.enums.E;
|
import com.gkhy.safePlatform.commons.enums.ResultCodes;
|
import com.gkhy.safePlatform.commons.exception.AusinessException;
|
import com.gkhy.safePlatform.commons.exception.BusinessException;
|
import com.gkhy.safePlatform.commons.query.PageQuery;
|
import com.gkhy.safePlatform.commons.utils.StringUtils;
|
import com.gkhy.safePlatform.commons.vo.SearchResultVO;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Service;
|
|
import java.time.LocalDateTime;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
@Service("appVersionService")
|
public class AppVersionServiceImpl implements AppVersionService {
|
|
@Autowired
|
private MinioUtils minioUtils;
|
@Value("${accountminio.floders.app}")
|
private String appFloder;
|
@Autowired
|
private AppVersionInfoService appInfoService;
|
|
@Override
|
public ObjectItemRespDTO getAppPresignedUrl(ContextCacheUser currentUser, String filename) {
|
if (StringUtils.isBlank(filename)) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "文件名传入为空");
|
}
|
// todo 校验文件名是否合法
|
ObjectItemBO item = minioUtils.getPresignedUrl(appFloder, filename.trim());
|
if (item == null) {
|
throw new BusinessException(ResultCodes.SERVER_ERROR);
|
}
|
ObjectItemRespDTO respDTO = new ObjectItemRespDTO();
|
respDTO.setObjectName(item.getObjectName());
|
respDTO.setPresignedUrl(item.getPresignedUrl());
|
return respDTO;
|
}
|
|
@Override
|
public void addAppVersion(ContextCacheUser currentUser, AppAddReqDTO reqDTO) {
|
if (StringUtils.isBlank(reqDTO.getAppName())) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "文件名称不能为空");
|
}
|
if (StringUtils.isBlank(reqDTO.getCustomVersion())) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "版本号不能为空");
|
}
|
if (StringUtils.isBlank(reqDTO.getObjectName())) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "文件对象名不能为空");
|
}
|
if (reqDTO.getAppType() == null) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "app文件类型不能为空");
|
}
|
AppTypeEnum typeEnum = AppTypeEnum.parse(reqDTO.getAppType());
|
if (typeEnum == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "app文件类型非法");
|
}
|
// todo 校验文件是否存在
|
// 1.文件个数查询
|
long count = appInfoService.countByAppType(reqDTO.getAppType());
|
// 自定义版本名称是否存在
|
AppVersionInfo appVersionInfo = appInfoService.getAppVersionInfoByCustomVersion(reqDTO.getCustomVersion().trim(),reqDTO.getAppType());
|
if (appVersionInfo != null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "app自定义版本已经存在");
|
}
|
// exc
|
AppVersionInfo appEntity = new AppVersionInfo();
|
appEntity.setName(reqDTO.getAppName().trim());
|
appEntity.setInfo(reqDTO.getInfo());
|
appEntity.setVersion((int) (count + 1));
|
appEntity.setStatus(AppVersionStatusEnum.ENABLED.code);
|
appEntity.setObjectName(reqDTO.getObjectName());
|
appEntity.setGmtCreate(LocalDateTime.now());
|
appEntity.setCreateUid(currentUser.getUid());
|
appEntity.setCreateUname(currentUser.getRealName());
|
appEntity.setAppType(reqDTO.getAppType());
|
appEntity.setCustomVersion(reqDTO.getCustomVersion());
|
appInfoService.saveAppInfo(appEntity);
|
|
}
|
|
@Override
|
public void modAppVersion(ContextCacheUser currentUser, AppModReqDTO reqDTO) {
|
if (reqDTO.getId() == null) {
|
throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
|
}
|
AppVersionInfo appInfo = appInfoService.getById(reqDTO.getId());
|
if (appInfo == null) {
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "APP版本信息不存在");
|
}
|
|
AppVersionInfo appEntity = new AppVersionInfo();
|
appEntity.setId(appInfo.getId());
|
appEntity.setInfo(reqDTO.getInfo());
|
appEntity.setGmtModified(LocalDateTime.now());
|
appEntity.setModifiedUid(currentUser.getUid());
|
appEntity.setModifiedUname(currentUser.getRealName());
|
if (StringUtils.isNotBlank((reqDTO.getAppName()))) {
|
appEntity.setName(reqDTO.getAppName().trim());
|
}
|
if (StringUtils.isNotBlank(reqDTO.getCustomVersion())) {
|
AppVersionInfo version = appInfoService.getAppVersionInfoByCustomVersion(reqDTO.getCustomVersion().trim(), reqDTO.getAppType());
|
if (version != null && !version.getId().equals(appInfo.getId())) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "app自定义版本已经存在");
|
}
|
appEntity.setCustomVersion(reqDTO.getCustomVersion().trim());
|
}
|
// 文件 ObjectName
|
if (StringUtils.isNotBlank(reqDTO.getObjectName())) {
|
// todo 校验文件是否存在
|
appEntity.setObjectName(reqDTO.getObjectName().trim());
|
}
|
appInfoService.updateAppInfo(appEntity);
|
}
|
|
@Override
|
public void delAppVersion(ContextCacheUser currentUser, Long id) {
|
if (id == null) {
|
throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
|
}
|
AppVersionInfo appInfo = appInfoService.getById(id);
|
if (appInfo == null) {
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "APP版本信息不存在");
|
}
|
if (!appInfo.getStatus().equals(AppVersionStatusEnum.ENABLED.code)) {
|
throw new AusinessException(E.DATA_DATABASE_EXIST_BUT_NOT_VALID, "APP版本信息不存在");
|
}
|
AppVersionInfo appEntity = new AppVersionInfo();
|
appEntity.setId(appInfo.getId());
|
appEntity.setGmtModified(LocalDateTime.now());
|
appEntity.setModifiedUid(currentUser.getUid());
|
appEntity.setModifiedUname(currentUser.getRealName());
|
appEntity.setStatus(AppVersionStatusEnum.ABANDONED.code);
|
appInfoService.updateAppInfo(appEntity);
|
}
|
|
@Override
|
public SearchResultVO<List<AppVersionRespDTO>> listAppVersionByPage(ContextCacheUser currentUser, PageQuery<AppVersionPageQuery> pageQuery) {
|
AppVersionPageDBQuery dbQuery = new AppVersionPageDBQuery();
|
if (pageQuery.getSearchParams() != null) {
|
dbQuery.setAppType(pageQuery.getSearchParams().getAppType());
|
dbQuery.setAppName(pageQuery.getSearchParams().getAppName());
|
dbQuery.setCustomVersion(pageQuery.getSearchParams().getCustomVersion());
|
}
|
Page<AppVersionInfo> page = new Page<>(pageQuery.getPageIndex(), pageQuery.getPageSize());
|
List<AppVersionInfo> dbData = appInfoService.listAppVersionInfoByPage(page, dbQuery);
|
List<AppVersionRespDTO> result = new ArrayList<>(dbData.size());
|
if (dbData.size() > 0) {
|
AppVersionStatusEnum statusEnum;
|
AppTypeEnum appTypeEnum;
|
AppVersionRespDTO respDTO;
|
for (AppVersionInfo appVersionInfo : dbData) {
|
respDTO = new AppVersionRespDTO();
|
respDTO.setId(appVersionInfo.getId());
|
respDTO.setName(appVersionInfo.getName());
|
respDTO.setInfo(appVersionInfo.getInfo());
|
respDTO.setCustomVersion(appVersionInfo.getCustomVersion());
|
respDTO.setVersion(appVersionInfo.getVersion());
|
respDTO.setStatus(appVersionInfo.getStatus());
|
statusEnum = AppVersionStatusEnum.parse(appVersionInfo.getStatus());
|
if (statusEnum != null) {
|
respDTO.setStatusDesc(statusEnum.value);
|
}
|
respDTO.setAppType(appVersionInfo.getAppType());
|
appTypeEnum = AppTypeEnum.parse(appVersionInfo.getAppType());
|
if (appTypeEnum != null) {
|
respDTO.setAppTypeDesc(appTypeEnum.getValue());
|
}
|
respDTO.setObjectName(appVersionInfo.getObjectName());
|
respDTO.setObjectUrl(minioUtils.getAccessibleUrl(appFloder,appVersionInfo.getObjectName()));
|
respDTO.setGmtCreate(appVersionInfo.getGmtCreate());
|
respDTO.setCreateUid(appVersionInfo.getCreateUid());
|
respDTO.setCreateUname(appVersionInfo.getCreateUname());
|
respDTO.setGmtModified(appVersionInfo.getGmtModified());
|
respDTO.setModifiedUid(appVersionInfo.getModifiedUid());
|
respDTO.setModifiedUname(appVersionInfo.getModifiedUname());
|
|
result.add(respDTO);
|
}
|
}
|
|
return new SearchResultVO<>(
|
true,
|
page.getCurrent(),
|
page.getSize(),
|
page.getPages(),
|
page.getTotal(),
|
result,
|
ResultCodes.OK);
|
|
}
|
|
@Override
|
public AppVersionRespDTO getLastestAppRelease(ContextCacheUser currentUser, Byte appType) {
|
if (appType == null) {
|
throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
|
}
|
AppTypeEnum appTypeEnum = AppTypeEnum.parse(appType);
|
if (appTypeEnum == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "app类型非法");
|
}
|
AppVersionInfo appVersionInfo = appInfoService.getLastestAppRelease(appType);
|
|
AppVersionRespDTO result = null;
|
if (appVersionInfo != null) {
|
result = new AppVersionRespDTO();
|
result.setId(appVersionInfo.getId());
|
result.setName(appVersionInfo.getName());
|
result.setInfo(appVersionInfo.getInfo());
|
result.setCustomVersion(appVersionInfo.getCustomVersion());
|
result.setVersion(appVersionInfo.getVersion());
|
result.setStatus(appVersionInfo.getStatus());
|
AppVersionStatusEnum statusEnum = AppVersionStatusEnum.parse(appVersionInfo.getStatus());
|
if (statusEnum != null) {
|
result.setStatusDesc(statusEnum.value);
|
}
|
result.setAppType(appVersionInfo.getAppType());
|
appTypeEnum = AppTypeEnum.parse(appVersionInfo.getAppType());
|
if (appTypeEnum != null) {
|
result.setAppTypeDesc(appTypeEnum.getValue());
|
}
|
result.setObjectName(appVersionInfo.getObjectName());
|
result.setObjectUrl(minioUtils.getAccessibleUrl(appFloder,appVersionInfo.getObjectName()));
|
result.setGmtCreate(appVersionInfo.getGmtCreate());
|
result.setCreateUid(appVersionInfo.getCreateUid());
|
result.setCreateUname(appVersionInfo.getCreateUname());
|
result.setGmtModified(appVersionInfo.getGmtModified());
|
result.setModifiedUid(appVersionInfo.getModifiedUid());
|
result.setModifiedUname(appVersionInfo.getModifiedUname());
|
}
|
|
return result;
|
}
|
}
|