|
@@ -0,0 +1,183 @@
|
|
|
|
|
+package com.fdkankan.manage.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.fdkankan.common.constant.ErrorCode;
|
|
|
|
|
+import com.fdkankan.common.exception.BusinessException;
|
|
|
|
|
+import com.fdkankan.common.response.PageInfo;
|
|
|
|
|
+import com.fdkankan.common.util.DateUtil;
|
|
|
|
|
+import com.fdkankan.common.util.FileUtils;
|
|
|
|
|
+import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
|
|
|
+import com.fdkankan.manage.entity.SpaceSdk;
|
|
|
|
|
+import com.fdkankan.manage.mapper.ISpaceSdkMapper;
|
|
|
|
|
+import com.fdkankan.manage.service.ISpaceSdkService;
|
|
|
|
|
+import com.fdkankan.manage.vo.request.SpaceSdkParam;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
+
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.util.Base64;
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * <p>
|
|
|
|
|
+ * space sdk表 服务实现类
|
|
|
|
|
+ * </p>
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author
|
|
|
|
|
+ * @since 2022-06-14
|
|
|
|
|
+ */
|
|
|
|
|
+@Service
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+public class SpaceSdkServiceImpl extends ServiceImpl<ISpaceSdkMapper, SpaceSdk> implements ISpaceSdkService {
|
|
|
|
|
+
|
|
|
|
|
+ private static String DIR_NAME = "new4dkk/v2/images/_/common/data/";
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private UploadToOssUtil uploadToOssUtil;
|
|
|
|
|
+
|
|
|
|
|
+ @Value("${oss.prefix.sdk}")
|
|
|
|
|
+ private String prefixAli;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public String upload(MultipartFile file, String version, String imprintCh, String imprintEn, Integer isTop, String platformType) throws IOException {
|
|
|
|
|
+ if (!file.isEmpty()&& file.getSize() <= 0) {
|
|
|
|
|
+ throw new BusinessException(ErrorCode.FILE_NOT_EXIST);
|
|
|
|
|
+ }
|
|
|
|
|
+ String fullFileName = "";
|
|
|
|
|
+ if(platformType.equals("1")){
|
|
|
|
|
+ fullFileName = "SpaceTarget_Unity3D";
|
|
|
|
|
+ }else if(platformType.equals("2")){
|
|
|
|
|
+ fullFileName = "SpaceTarget_UE4";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String fileNameAll = "";
|
|
|
|
|
+ // 文件名全名
|
|
|
|
|
+ fileNameAll = file.getOriginalFilename();
|
|
|
|
|
+
|
|
|
|
|
+ // 将文件转字节-> 字符串
|
|
|
|
|
+ String fileContent = Base64.getEncoder().encodeToString(file.getBytes());
|
|
|
|
|
+
|
|
|
|
|
+ // 获取类路径
|
|
|
|
|
+ String resourcePath = FileUtils.getResource();
|
|
|
|
|
+ log.info("resourcePath: {}", resourcePath);
|
|
|
|
|
+
|
|
|
|
|
+ // 创建目录
|
|
|
|
|
+ String dirPath = resourcePath + DIR_NAME;
|
|
|
|
|
+ FileUtils.createDir(dirPath);
|
|
|
|
|
+
|
|
|
|
|
+ // 拼接唯一文件名
|
|
|
|
|
+ String fileName = fullFileName + "_" + version + "_" + DateUtil.dateStr() + fileNameAll;
|
|
|
|
|
+
|
|
|
|
|
+ // 文件保存路径
|
|
|
|
|
+ String filePath = dirPath + DateUtil.dateStr() + fileNameAll;
|
|
|
|
|
+
|
|
|
|
|
+ // 写文件到本地
|
|
|
|
|
+ FileUtils.base64ToFileWriter(fileContent, filePath);
|
|
|
|
|
+ log.info("filePath: {}", filePath);
|
|
|
|
|
+
|
|
|
|
|
+ // 上传到阿里云sso
|
|
|
|
|
+ uploadToOssUtil.uploadSdk(filePath, DIR_NAME + fileName);
|
|
|
|
|
+ log.info("upload success");
|
|
|
|
|
+
|
|
|
|
|
+ String url = prefixAli + DIR_NAME + fileName;
|
|
|
|
|
+
|
|
|
|
|
+ log.info("upload url: {}" + url);
|
|
|
|
|
+
|
|
|
|
|
+ this.updateTopFBySdkId(platformType);//取消所有置顶
|
|
|
|
|
+
|
|
|
|
|
+ SpaceSdk managerSdkEntity = new SpaceSdk();
|
|
|
|
|
+ managerSdkEntity.setVersion(version);
|
|
|
|
|
+ managerSdkEntity.setImprintCh(imprintCh);
|
|
|
|
|
+ managerSdkEntity.setImprintEn(imprintEn);
|
|
|
|
|
+ managerSdkEntity.setIsTop(1);
|
|
|
|
|
+ managerSdkEntity.setStatus(0);
|
|
|
|
|
+ managerSdkEntity.setPlatformType(platformType);
|
|
|
|
|
+ managerSdkEntity.setFileUrl(url);
|
|
|
|
|
+ managerSdkEntity.setFileName(fullFileName);
|
|
|
|
|
+
|
|
|
|
|
+ this.save(managerSdkEntity);
|
|
|
|
|
+
|
|
|
|
|
+ // 删除本地文件
|
|
|
|
|
+ FileUtils.deleteFile(filePath);
|
|
|
|
|
+
|
|
|
|
|
+ return url;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void updateByEntity(SpaceSdk param) {
|
|
|
|
|
+ if(param.getId() == null || StringUtils.isEmpty(param.getPlatformType()) || param.getIsTop()==null){
|
|
|
|
|
+ throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(param.getIsTop().equals(1)){
|
|
|
|
|
+ this.updateTopFBySdkId(param.getPlatformType());//取消所有置顶
|
|
|
|
|
+ }
|
|
|
|
|
+ if(!this.updateById(param)){
|
|
|
|
|
+ throw new BusinessException(ErrorCode.ERROR_MSG);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void online(SpaceSdkParam param) {
|
|
|
|
|
+ if(param.getId() == null || param.getStatus() == null){
|
|
|
|
|
+ throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
|
|
+ }
|
|
|
|
|
+ SpaceSdk managerSdkEntity = this.getById(param.getId());
|
|
|
|
|
+ if(managerSdkEntity == null ){
|
|
|
|
|
+ throw new BusinessException(-1,"获取记录为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if(managerSdkEntity.getPublishTime()!=null){
|
|
|
|
|
+ this.updateBySdkId(param.getId(),param.getStatus());
|
|
|
|
|
+ }else{
|
|
|
|
|
+ this.updateBySdkIdPublish(param.getId(),param.getStatus());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public PageInfo pageList(SpaceSdkParam param) {
|
|
|
|
|
+ LambdaQueryWrapper<SpaceSdk> queryWrapper = Wrappers.lambdaQuery();
|
|
|
|
|
+ if(param.getStatus()!=null){
|
|
|
|
|
+ queryWrapper.eq(SpaceSdk::getStatus,param.getStatus());
|
|
|
|
|
+ }
|
|
|
|
|
+ if(StringUtils.isNotEmpty(param.getSearchKey()) && !param.getSearchKey().equals("%")){
|
|
|
|
|
+ queryWrapper.like(SpaceSdk::getVersion,param.getSearchKey());
|
|
|
|
|
+ }
|
|
|
|
|
+ if(StringUtils.isNotEmpty(param.getPlatformType())){
|
|
|
|
|
+ queryWrapper.like(SpaceSdk::getPlatformType,param.getPlatformType());
|
|
|
|
|
+ }
|
|
|
|
|
+ queryWrapper.orderByDesc(SpaceSdk::getIsTop);
|
|
|
|
|
+ queryWrapper.orderByDesc(SpaceSdk::getPublishTime);
|
|
|
|
|
+ Page<SpaceSdk> page = this.page(new Page<>(param.getPageNum(),param.getPageSize()), queryWrapper);
|
|
|
|
|
+ return PageInfo.PageInfo(page);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void updateBySdkId(Long id, Integer status) {
|
|
|
|
|
+ LambdaUpdateWrapper<SpaceSdk> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
+ updateWrapper.set(SpaceSdk::getStatus,status)
|
|
|
|
|
+ .eq(SpaceSdk::getId,id);
|
|
|
|
|
+ this.update(updateWrapper);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void updateTopFBySdkId(String platformType) {
|
|
|
|
|
+ LambdaUpdateWrapper<SpaceSdk> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
+ updateWrapper.set(SpaceSdk::getIsTop,0)
|
|
|
|
|
+ .eq(SpaceSdk::getPlatformType,platformType);
|
|
|
|
|
+ this.update(updateWrapper);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void updateBySdkIdPublish(Long id, Integer status) {
|
|
|
|
|
+ LambdaUpdateWrapper<SpaceSdk> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
+ updateWrapper.set(SpaceSdk::getStatus,status)
|
|
|
|
|
+ .set(SpaceSdk::getPublishTime,new Date())
|
|
|
|
|
+ .eq(SpaceSdk::getId,id);
|
|
|
|
|
+ this.update(updateWrapper);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|