123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- package com.fdkankan.manage.service.impl;
- import cn.dev33.satoken.stp.StpUtil;
- 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.fyun.face.FYunFileServiceInterface;
- import com.fdkankan.manage.common.FilePath;
- import com.fdkankan.manage.common.ResultCode;
- import com.fdkankan.manage.exception.BusinessException;
- import com.fdkankan.manage.common.PageInfo;
- import com.fdkankan.common.util.DateUtil;
- import com.fdkankan.common.util.FileUtils;
- import com.fdkankan.manage.entity.SysUser;
- import com.fdkankan.manage.service.ISysUserService;
- 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 com.fdkankan.manage.vo.response.SpaceSdkVo;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.BeanUtils;
- 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.File;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- /**
- * <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
- FYunFileServiceInterface fYunFileServiceInterface;
- @Autowired
- ISysUserService sysUserService;
- @Value("${space-sdk.bucket:4dscene}")
- private String sdkBucket;
- @Value("${space-sdk.url:https://4dscene.4dage.com/}")
- private String prefixAli;
- @Override
- public String upload(MultipartFile file, String version, String imprintCh, String imprintEn, Integer isTop, Integer platformType) throws IOException {
- if (!file.isEmpty()&& file.getSize() <= 0) {
- throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
- }
- String fullFileName = "";
- if(platformType == 1){
- fullFileName = "SpaceTarget_Unity3D";
- }else if(platformType == 2){
- fullFileName = "SpaceTarget_UE4";
- }
- String fileNameAll = "";
- // 文件名全名
- fileNameAll = file.getOriginalFilename();
- // 将文件转字节-> 字符串
- // 获取类路径
- String resourcePath = FilePath.sdkLocalPath;
- 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;
- // 写文件到本地
- File file1 = new File(filePath);
- file.transferTo(file1);
- log.info("filePath: {}", filePath);
- // 上传到阿里云sso
- fYunFileServiceInterface.uploadFile(sdkBucket,filePath, DIR_NAME + fileName);
- log.info("upload success");
- String url = prefixAli + DIR_NAME + fileName;
- log.info("upload url: {}" + url);
- SpaceSdk managerSdkEntity = new SpaceSdk();
- managerSdkEntity.setVersion(version);
- managerSdkEntity.setImprintCh(imprintCh);
- managerSdkEntity.setImprintEn(imprintEn);
- managerSdkEntity.setIsTop(isTop);
- managerSdkEntity.setStatus(0);
- managerSdkEntity.setPlatformType(platformType.toString());
- managerSdkEntity.setFileUrl(url);
- managerSdkEntity.setFileName(fullFileName);
- managerSdkEntity.setSysUserId(Long.valueOf(StpUtil.getLoginId().toString()));
- this.save(managerSdkEntity);
- if(isTop == 1){
- this.updateTopFBySdkId(managerSdkEntity.getId());//取消所有置顶
- }
- this.updateById(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(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- if(param.getIsTop().equals(1)){
- this.updateTopFBySdkId(param.getId());//取消所有置顶
- }
- this.updateById(param);
- }
- @Override
- public void online(SpaceSdkParam param) {
- if(param.getId() == null || param.getStatus() == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- SpaceSdk managerSdkEntity = this.getById(param.getId());
- if(managerSdkEntity == null ){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- if(managerSdkEntity.getPublishTime()!=null){
- this.updateBySdkId(param.getId(),param.getStatus());
- }else{
- this.updateBySdkIdPublish(param.getId(),param.getStatus());
- }
- }
- @Override
- public void top(SpaceSdkParam param) {
- if(param.getId() == null || param.getIsTop()==null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- if(param.getIsTop().equals(1)){
- this.updateTopFBySdkId(param.getId());//取消所有置顶
- }
- LambdaUpdateWrapper<SpaceSdk> updateWrapper = new LambdaUpdateWrapper<>();
- updateWrapper.set(SpaceSdk::getIsTop,param.getIsTop())
- .eq(SpaceSdk::getId,param.getId());
- this.update(updateWrapper);
- }
- @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.getVersion())){
- queryWrapper.like(SpaceSdk::getVersion,param.getVersion());
- }
- if(param.getPlatformType() == null){
- param.setPlatformType(1);
- }
- queryWrapper.eq(SpaceSdk::getPlatformType,param.getPlatformType());
- queryWrapper.orderByDesc(SpaceSdk::getIsTop);
- queryWrapper.orderByDesc(SpaceSdk::getStatus);
- queryWrapper.orderByDesc(SpaceSdk::getCreateTime);
- Page<SpaceSdk> page = this.page(new Page<>(param.getPageNum(),param.getPageSize()), queryWrapper);
- List<SpaceSdkVo> voList = new ArrayList<>();
- for (SpaceSdk record : page.getRecords()) {
- SpaceSdkVo vo = new SpaceSdkVo();
- BeanUtils.copyProperties(record,vo);
- if(record.getSysUserId() !=null){
- SysUser user = sysUserService.getById(record.getSysUserId());
- if(user != null){
- vo.setCreateName(user.getNickName());
- }
- }
- voList.add(vo);
- }
- Page<SpaceSdkVo> voPage = new Page<>(param.getPageNum(),param.getPageSize());
- voPage.setRecords(voList);
- voPage.setTotal(page.getTotal());
- return PageInfo.PageInfo(voPage);
- }
- private void updateBySdkId(Long id, Integer status) {
- LambdaUpdateWrapper<SpaceSdk> updateWrapper = new LambdaUpdateWrapper<>();
- updateWrapper.set(SpaceSdk::getStatus,status == 2 ? 0:status)
- .eq(SpaceSdk::getId,id);
- this.update(updateWrapper);
- }
- private void updateTopFBySdkId(Long sdkId) {
- SpaceSdk sdk = this.getById(sdkId);
- if(sdk!=null){
- LambdaUpdateWrapper<SpaceSdk> updateWrapper = new LambdaUpdateWrapper<>();
- updateWrapper.set(SpaceSdk::getIsTop,0)
- .eq(SpaceSdk::getPlatformType,sdk.getPlatformType());
- this.update(updateWrapper);
- }
- }
- private void updateBySdkIdPublish(Long id, Integer status) {
- LambdaUpdateWrapper<SpaceSdk> updateWrapper = new LambdaUpdateWrapper<>();
- updateWrapper.set(SpaceSdk::getStatus,status == 2 ? 0 :status)
- .set(SpaceSdk::getPublishTime,new Date())
- .eq(SpaceSdk::getId,id);
- this.update(updateWrapper);
- }
- }
|