Merge branch 'dyf-device' into 6170
This commit is contained in:
@ -13,9 +13,9 @@ import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
@ -29,7 +29,7 @@ import java.util.Arrays;
|
||||
@RestController
|
||||
@RequestMapping("/app/device/voice")
|
||||
public class AppDeviceVoiceController extends BaseController {
|
||||
|
||||
|
||||
private final IAppDeviceVoiceService appDeviceVoiceService;
|
||||
|
||||
/**
|
||||
@ -54,8 +54,9 @@ public class AppDeviceVoiceController extends BaseController {
|
||||
* 新增设备语音
|
||||
*/
|
||||
@PostMapping()
|
||||
public R<Void> add(@Validated(AddGroup.class) @RequestBody AppDeviceVoiceBo bo) {
|
||||
return toAjax(appDeviceVoiceService.insertByBo(bo));
|
||||
public R<Void> add(@RequestPart("bo") @Validated(AddGroup.class) AppDeviceVoiceBo bo,
|
||||
@RequestPart(value = "file", required = false) MultipartFile file) {
|
||||
return toAjax(appDeviceVoiceService.insertByBo(bo, file));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -4,6 +4,7 @@ import com.fuyuanshen.app.domain.AppDeviceVoice;
|
||||
import com.fuyuanshen.app.domain.bo.AppDeviceVoiceBo;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -34,7 +35,7 @@ public interface IAppDeviceVoiceService {
|
||||
/**
|
||||
* 根据新增业务对象插入设备语音
|
||||
*/
|
||||
Boolean insertByBo(AppDeviceVoiceBo bo);
|
||||
Boolean insertByBo(AppDeviceVoiceBo bo, MultipartFile file);
|
||||
|
||||
/**
|
||||
* 根据编辑业务对象更新设备语音
|
||||
|
||||
@ -1,20 +1,22 @@
|
||||
package com.fuyuanshen.app.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuyuanshen.app.domain.AppDeviceVoice;
|
||||
import com.fuyuanshen.app.domain.bo.AppDeviceVoiceBo;
|
||||
import com.fuyuanshen.app.mapper.AppDeviceVoiceMapper;
|
||||
import com.fuyuanshen.app.service.IAppDeviceVoiceService;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.fuyuanshen.common.oss.core.OssClient;
|
||||
import com.fuyuanshen.common.oss.entity.UploadResult;
|
||||
import com.fuyuanshen.common.oss.factory.OssFactory;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 设备语音Service业务层处理
|
||||
@ -57,16 +59,45 @@ public class AppDeviceVoiceServiceImpl implements IAppDeviceVoiceService {
|
||||
* 根据新增业务对象插入设备语音
|
||||
*/
|
||||
@Override
|
||||
public Boolean insertByBo(AppDeviceVoiceBo bo) {
|
||||
public Boolean insertByBo(AppDeviceVoiceBo bo, MultipartFile file) {
|
||||
// 上传文件到MinIO
|
||||
String videoUrl = "";
|
||||
String coverUrl = "";
|
||||
Long size = 0L;
|
||||
Integer duration = 0;
|
||||
String type = "";
|
||||
|
||||
if (file != null && !file.isEmpty()) {
|
||||
try {
|
||||
OssClient storage = OssFactory.instance();
|
||||
String suffix = "";
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
if (originalFilename != null && originalFilename.lastIndexOf(".") > 0) {
|
||||
suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||
}
|
||||
UploadResult result = storage.uploadSuffix(file.getBytes(), suffix, file.getContentType());
|
||||
videoUrl = result.getUrl();
|
||||
size = file.getSize();
|
||||
type = file.getContentType();
|
||||
// TODO: 可以通过其他方式获取音频时长,这里暂时设置为默认值
|
||||
duration = 0;
|
||||
// TODO: 可以生成封面图,这里暂时设置为空
|
||||
coverUrl = "";
|
||||
} catch (Exception e) {
|
||||
// 文件上传失败处理
|
||||
throw new RuntimeException("文件上传失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
AppDeviceVoice add = new AppDeviceVoice();
|
||||
add.setVideoName(bo.getVideoName());
|
||||
add.setVideoUrl(bo.getVideoUrl());
|
||||
add.setVideoUrl(videoUrl);
|
||||
add.setDeviceId(bo.getDeviceId());
|
||||
add.setRemark(bo.getRemark());
|
||||
add.setType(bo.getType());
|
||||
add.setDuration(bo.getDuration());
|
||||
add.setSize(bo.getSize());
|
||||
add.setCover(bo.getCover());
|
||||
add.setType(type);
|
||||
add.setDuration(duration);
|
||||
add.setSize(size);
|
||||
add.setCover(coverUrl);
|
||||
return baseMapper.insert(add) > 0;
|
||||
}
|
||||
|
||||
@ -78,16 +109,12 @@ public class AppDeviceVoiceServiceImpl implements IAppDeviceVoiceService {
|
||||
AppDeviceVoice update = new AppDeviceVoice();
|
||||
update.setId(bo.getId());
|
||||
update.setVideoName(bo.getVideoName());
|
||||
update.setVideoUrl(bo.getVideoUrl());
|
||||
update.setDeviceId(bo.getDeviceId());
|
||||
update.setRemark(bo.getRemark());
|
||||
update.setType(bo.getType());
|
||||
update.setDuration(bo.getDuration());
|
||||
update.setSize(bo.getSize());
|
||||
update.setCover(bo.getCover());
|
||||
return baseMapper.updateById(update) > 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 校验并批量删除设备语音信息
|
||||
*/
|
||||
@ -96,6 +123,8 @@ public class AppDeviceVoiceServiceImpl implements IAppDeviceVoiceService {
|
||||
if (ids == null || ids.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
// TODO: 可以在这里添加删除MinIO文件的逻辑
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user