|
@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.sckj.common.TapholeAdminThreadLocal;
|
|
|
import com.sckj.common.core.AjaxResult;
|
|
|
+import com.sckj.common.exception.OperateException;
|
|
|
+import com.sckj.common.util.*;
|
|
|
import com.sckj.common.validate.commons.PageValidate;
|
|
|
import com.sckj.warn.validate.TAudioCreateValidate;
|
|
|
import com.sckj.warn.validate.TAudioUpdateValidate;
|
|
@@ -17,24 +19,24 @@ import com.sckj.common.config.GlobalConfig;
|
|
|
import com.sckj.common.core.PageResult;
|
|
|
import com.sckj.warn.entity.TAudio;
|
|
|
import com.sckj.warn.mapper.TAudioMapper;
|
|
|
-import com.sckj.common.util.ListUtils;
|
|
|
-import com.sckj.common.util.TimeUtils;
|
|
|
-import com.sckj.common.util.UrlUtils;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.Assert;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 音频实现类
|
|
|
+ *
|
|
|
* @author zhanghao
|
|
|
*/
|
|
|
@Service
|
|
|
-public class TAudioServiceImpl extends ServiceImpl<TAudioMapper,TAudio> {
|
|
|
+public class TAudioServiceImpl extends ServiceImpl<TAudioMapper, TAudio> {
|
|
|
|
|
|
@Resource
|
|
|
TAudioMapper tAudioMapper;
|
|
@@ -42,13 +44,13 @@ public class TAudioServiceImpl extends ServiceImpl<TAudioMapper,TAudio> {
|
|
|
/**
|
|
|
* 音频列表
|
|
|
*
|
|
|
- * @author zhanghao
|
|
|
- * @param pageValidate 分页参数
|
|
|
+ * @param pageValidate 分页参数
|
|
|
* @param searchValidate 搜索参数
|
|
|
* @return PageResult<TAudioListedVo>
|
|
|
+ * @author zhanghao
|
|
|
*/
|
|
|
public PageResult<TAudioListedVo> list(PageValidate pageValidate, TAudioSearchValidate searchValidate) {
|
|
|
- Integer page = pageValidate.getPageNo();
|
|
|
+ Integer page = pageValidate.getPageNo();
|
|
|
Integer limit = pageValidate.getPageSize();
|
|
|
|
|
|
QueryWrapper<TAudio> queryWrapper = new QueryWrapper<>();
|
|
@@ -56,24 +58,25 @@ public class TAudioServiceImpl extends ServiceImpl<TAudioMapper,TAudio> {
|
|
|
queryWrapper.orderByDesc("id");
|
|
|
|
|
|
tAudioMapper.setSearch(queryWrapper, searchValidate, new String[]{
|
|
|
- "=:createBy@create_by:str",
|
|
|
- "=:updateBy@update_by:str",
|
|
|
- "like:name:str",
|
|
|
- "=:exceptionType@exception_type:str",
|
|
|
- "=:exceptionLevel@exception_level:str",
|
|
|
- "=:path:str",
|
|
|
- "=:status:str",
|
|
|
+ "=:createBy@create_by:str",
|
|
|
+ "=:updateBy@update_by:str",
|
|
|
+ "like:name:str",
|
|
|
+ "=:exceptionType@exception_type:str",
|
|
|
+ "=:exceptionLevel@exception_level:str",
|
|
|
+ "=:path:str",
|
|
|
+ "=:status:str",
|
|
|
});
|
|
|
|
|
|
IPage<TAudio> iPage = tAudioMapper.selectPage(new Page<>(page, limit), queryWrapper);
|
|
|
|
|
|
List<TAudioListedVo> list = new LinkedList<>();
|
|
|
- for(TAudio item : iPage.getRecords()) {
|
|
|
+ for (TAudio item : iPage.getRecords()) {
|
|
|
TAudioListedVo vo = new TAudioListedVo();
|
|
|
BeanUtils.copyProperties(item, vo);
|
|
|
- vo.setPath("http://localhost:28080/api/uploads/" + vo.getPath());
|
|
|
+ String relativeUrl = UrlUtils.toAbsoluteUrl(vo.getPath());
|
|
|
+ vo.setPath(relativeUrl);
|
|
|
vo.setCreateTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(item.getCreateTime()));
|
|
|
- if (item.getUpdateTime() != null){
|
|
|
+ if (item.getUpdateTime() != null) {
|
|
|
vo.setUpdateTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(item.getUpdateTime()));
|
|
|
}
|
|
|
list.add(vo);
|
|
@@ -85,11 +88,11 @@ public class TAudioServiceImpl extends ServiceImpl<TAudioMapper,TAudio> {
|
|
|
/**
|
|
|
* 音频详情
|
|
|
*
|
|
|
- * @author zhanghao
|
|
|
* @param id 主键参数
|
|
|
* @return TAudio
|
|
|
+ * @author zhanghao
|
|
|
*/
|
|
|
-
|
|
|
+
|
|
|
public TAudioDetailVo detail(Integer id) {
|
|
|
TAudio model = tAudioMapper.selectOne(
|
|
|
new QueryWrapper<TAudio>()
|
|
@@ -98,7 +101,7 @@ public class TAudioServiceImpl extends ServiceImpl<TAudioMapper,TAudio> {
|
|
|
.last("limit 1"));
|
|
|
|
|
|
Assert.notNull(model, "数据不存在");
|
|
|
-
|
|
|
+ model.setPath(UrlUtils.toAbsoluteUrl(model.getPath()));
|
|
|
TAudioDetailVo vo = new TAudioDetailVo();
|
|
|
BeanUtils.copyProperties(model, vo);
|
|
|
return vo;
|
|
@@ -107,19 +110,32 @@ public class TAudioServiceImpl extends ServiceImpl<TAudioMapper,TAudio> {
|
|
|
/**
|
|
|
* 音频新增
|
|
|
*
|
|
|
- * @author zhanghao
|
|
|
* @param createValidate 参数
|
|
|
+ * @author zhanghao
|
|
|
*/
|
|
|
-
|
|
|
+
|
|
|
public void add(TAudioCreateValidate createValidate) {
|
|
|
TAudio model = new TAudio();
|
|
|
model.setCreateTime(new Date(System.currentTimeMillis()));
|
|
|
model.setCreateBy(String.valueOf(TapholeAdminThreadLocal.getAdminUsername()));
|
|
|
model.setName(createValidate.getName());
|
|
|
- model.setPath(createValidate.getPath());
|
|
|
model.setDuration(createValidate.getDuration());
|
|
|
model.setExceptionType(createValidate.getExceptionType());
|
|
|
model.setExceptionLevel(createValidate.getExceptionLevel());
|
|
|
+ String path = createValidate.getPath();
|
|
|
+ if (ObjectUtils.isNotEmpty(path)) {
|
|
|
+ String relativeUrl = UrlUtils.toRelativeUrl(path);
|
|
|
+ model.setPath(relativeUrl);
|
|
|
+ long audioDuration = AudioUtils.getAudioDuration(YmlUtils.get("like.upload-directory") + relativeUrl);
|
|
|
+ if (audioDuration == -1) {
|
|
|
+ model.setDuration("0");
|
|
|
+ } else {
|
|
|
+ model.setDuration(String.valueOf(audioDuration * 1.0 / 1000));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ model.setPath(null);
|
|
|
+ model.setDuration("0");
|
|
|
+ }
|
|
|
//默认新增的音频初始状态为停用
|
|
|
tAudioMapper.insert(model);
|
|
|
}
|
|
@@ -127,26 +143,38 @@ public class TAudioServiceImpl extends ServiceImpl<TAudioMapper,TAudio> {
|
|
|
/**
|
|
|
* 音频编辑
|
|
|
*
|
|
|
- * @author zhanghao
|
|
|
* @param updateValidate 参数
|
|
|
+ * @author zhanghao
|
|
|
*/
|
|
|
-
|
|
|
+
|
|
|
public int edit(TAudioUpdateValidate updateValidate) {
|
|
|
TAudio model = tAudioMapper.selectOne(
|
|
|
new QueryWrapper<TAudio>()
|
|
|
- .eq("id", updateValidate.getId()).eq("del_flag", "1")
|
|
|
- .last("limit 1"));
|
|
|
+ .eq("id", updateValidate.getId()).eq("del_flag", "1")
|
|
|
+ .last("limit 1"));
|
|
|
|
|
|
- if (model == null){
|
|
|
- return 0;
|
|
|
- }
|
|
|
+ Assert.notNull(model, "数据不存在!");
|
|
|
+
|
|
|
+ model.setId(updateValidate.getId());
|
|
|
model.setUpdateTime(new Date(System.currentTimeMillis()));
|
|
|
model.setUpdateBy(String.valueOf(TapholeAdminThreadLocal.getAdminUsername()));
|
|
|
model.setName(updateValidate.getName());
|
|
|
- model.setPath(updateValidate.getPath());
|
|
|
- model.setDuration(updateValidate.getDuration());
|
|
|
model.setExceptionType(updateValidate.getExceptionType());
|
|
|
model.setExceptionLevel(updateValidate.getExceptionLevel());
|
|
|
+ String path = updateValidate.getPath();
|
|
|
+ if (ObjectUtils.isNotEmpty(path)) {
|
|
|
+ String relativeUrl = UrlUtils.toRelativeUrl(path);
|
|
|
+ model.setPath(relativeUrl);
|
|
|
+ long audioDuration = AudioUtils.getAudioDuration(YmlUtils.get("like.upload-directory") + relativeUrl);
|
|
|
+ if (audioDuration == -1) {
|
|
|
+ model.setDuration("0");
|
|
|
+ } else {
|
|
|
+ model.setDuration(String.valueOf(audioDuration * 1.0 / 1000));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ model.setPath(null);
|
|
|
+ model.setDuration("0");
|
|
|
+ }
|
|
|
tAudioMapper.updateById(model);
|
|
|
return 1;
|
|
|
}
|
|
@@ -154,29 +182,29 @@ public class TAudioServiceImpl extends ServiceImpl<TAudioMapper,TAudio> {
|
|
|
/**
|
|
|
* 音频音频启用状态修改
|
|
|
*
|
|
|
- * @author zhanghao
|
|
|
* @param updateValidate 参数
|
|
|
+ * @author zhanghao
|
|
|
*/
|
|
|
-
|
|
|
+
|
|
|
public AjaxResult<Object> status(TAudioUpdateValidate updateValidate) {
|
|
|
TAudio model = tAudioMapper.selectOne(
|
|
|
new QueryWrapper<TAudio>()
|
|
|
- .eq("id", updateValidate.getId()).eq("del_flag", "1")
|
|
|
+ .eq("id", updateValidate.getId()).eq("del_flag", "1")
|
|
|
.last("limit 1"));
|
|
|
- if (model == null){
|
|
|
+ if (model == null) {
|
|
|
return AjaxResult.failed("未找到该音频");
|
|
|
}
|
|
|
/*如果将要修改的状态值和原来的值不同,且修改音频状态为启用*/
|
|
|
- if (!model.getStatus().equals(updateValidate.getStatus()) && updateValidate.getStatus().equals("1")){
|
|
|
+ if (!model.getStatus().equals(updateValidate.getStatus()) && updateValidate.getStatus().equals("1")) {
|
|
|
//首先查找是否存在同异常类型同危害程度的已启用音频
|
|
|
TAudio tAudio = tAudioMapper.selectOne(
|
|
|
new QueryWrapper<TAudio>()
|
|
|
- .eq("exception_type", updateValidate.getExceptionType())
|
|
|
- .eq("exception_level", updateValidate.getExceptionLevel())
|
|
|
- .eq("status", "1")
|
|
|
+ .eq("exception_type", updateValidate.getExceptionType())
|
|
|
+ .eq("exception_level", updateValidate.getExceptionLevel())
|
|
|
+ .eq("status", "1")
|
|
|
.last("limit 1"));
|
|
|
//存在冲突
|
|
|
- if (tAudio != null){
|
|
|
+ if (tAudio != null) {
|
|
|
return AjaxResult.failed("存在已启用的同类音频,禁止修改");
|
|
|
}
|
|
|
}
|
|
@@ -191,15 +219,15 @@ public class TAudioServiceImpl extends ServiceImpl<TAudioMapper,TAudio> {
|
|
|
/**
|
|
|
* 音频删除
|
|
|
*
|
|
|
- * @author zhanghao
|
|
|
* @param id 主键ID
|
|
|
+ * @author zhanghao
|
|
|
*/
|
|
|
-
|
|
|
+
|
|
|
public void del(Integer id) {
|
|
|
TAudio model = tAudioMapper.selectOne(
|
|
|
new QueryWrapper<TAudio>()
|
|
|
- .eq("id", id)
|
|
|
- .last("limit 1"));
|
|
|
+ .eq("id", id)
|
|
|
+ .last("limit 1"));
|
|
|
|
|
|
Assert.notNull(model, "数据不存在!");
|
|
|
|
|
@@ -211,13 +239,13 @@ public class TAudioServiceImpl extends ServiceImpl<TAudioMapper,TAudio> {
|
|
|
/**
|
|
|
* 音频地址查询
|
|
|
*
|
|
|
- * @author zhanghao
|
|
|
* @param id 主键ID
|
|
|
+ * @author zhanghao
|
|
|
*/
|
|
|
- public String searchPath(Long id){
|
|
|
+ public String searchPath(Long id) {
|
|
|
TAudio model = tAudioMapper.selectOne(
|
|
|
new QueryWrapper<TAudio>()
|
|
|
- .eq("id", id).eq("del_flag", "1")
|
|
|
+ .eq("id", id).eq("del_flag", "1")
|
|
|
.last("limit 1"));
|
|
|
|
|
|
Assert.notNull(model, "数据不存在!");
|
|
@@ -227,16 +255,16 @@ public class TAudioServiceImpl extends ServiceImpl<TAudioMapper,TAudio> {
|
|
|
/**
|
|
|
* 音频批量删除
|
|
|
*
|
|
|
- * @author zhanghao
|
|
|
* @param ids 主键数组
|
|
|
+ * @author zhanghao
|
|
|
*/
|
|
|
-
|
|
|
+
|
|
|
public AjaxResult<Object> del_ex(List<Long> ids) {
|
|
|
List<TAudio> models = tAudioMapper.selectList(
|
|
|
new QueryWrapper<TAudio>()
|
|
|
.in("id", ids));
|
|
|
|
|
|
- if (CollectionUtils.isEmpty(models)){
|
|
|
+ if (CollectionUtils.isEmpty(models)) {
|
|
|
return AjaxResult.failed("数据不存在");
|
|
|
}
|
|
|
TAudio model = new TAudio();
|