Commit 0360e840 by wnb0128

车家智能数据服务开发 图片保存功能逻辑调整--think.wang

1 parent b765872f
......@@ -33,8 +33,8 @@ public class SysFileController {
return R.ok().data(sysFileService.findByType(type));
}
@RequestMapping(value = "/saveFile", method = {RequestMethod.POST})
@ApiOperation(value = "保存图片")
@RequestMapping(value = "/batchSaveFile", method = {RequestMethod.POST})
@ApiOperation(value = "批量保存图片")
public R saveFile(@RequestBody List<FileDTO> files) {
try {
sysFileService.saveFile(files);
......@@ -44,14 +44,14 @@ public class SysFileController {
return R.ok();
}
@RequestMapping(value = "/updateFile", method = {RequestMethod.POST})
@ApiOperation(value = "更新图片")
@RequestMapping(value = "/saveFile", method = {RequestMethod.POST})
@ApiOperation(value = "保存更新图片")
public R updateFile(@RequestBody FileDTO fileDTO) {
try {
sysFileService.updateFile(fileDTO);
return R.ok().data(sysFileService.updateFile(fileDTO));
} catch (Exception e) {
log.error("保存图片失败:{}", e);
return R.error();
}
return R.ok();
}
}
......@@ -15,11 +15,11 @@ import java.util.List;
public interface SmartSysFileService {
int insertOrUpdate(SmartSysFile record);
Long insertOrUpdate(SmartSysFile record);
List<FileDTO> findByType(Byte type);
void saveFile(List<FileDTO> files);
void updateFile(FileDTO fileDTO);
FileDTO updateFile(FileDTO fileDTO);
}
package com.glsx.smart.service.impl;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import com.glsx.smart.dao.entity.SmartSysFile;
import com.glsx.smart.dao.mapper.SmartSysFileMapper;
import com.glsx.smart.exception.BusinessException;
......@@ -15,6 +10,11 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* <p>Description:
* <p>Project: chejia-smart
......@@ -26,21 +26,21 @@ import org.springframework.stereotype.Service;
@Service
public class SmartSysFileServiceImpl implements SmartSysFileService {
@Resource
private SmartSysFileMapper smartSysFileMapper;
private SmartSysFileMapper fileMapper;
@Override
public int insertOrUpdate(SmartSysFile sysFile) {
public Long insertOrUpdate(SmartSysFile sysFile) {
if (sysFile.getId() == null) {
return smartSysFileMapper.insertSelective(sysFile);
fileMapper.insertSelective(sysFile);
} else {
SmartSysFile record = smartSysFileMapper.selectByPrimaryKey(
sysFile.getId());
SmartSysFile record = fileMapper.selectByPrimaryKey(sysFile.getId());
if (record != null) {
return smartSysFileMapper.updateByPrimaryKeySelective(sysFile);
fileMapper.updateByPrimaryKeySelective(sysFile);
} else {
throw new BusinessException(ResultEnum.ID_NOT_FOUND);
}
}
return sysFile.getId();
}
/**
......@@ -51,7 +51,7 @@ public class SmartSysFileServiceImpl implements SmartSysFileService {
*/
@Override
public List<FileDTO> findByType(Byte type) {
List<SmartSysFile> list=smartSysFileMapper.findByType(type);
List<SmartSysFile> list= fileMapper.findByType(type);
List<FileDTO> fileDTOS = list.stream().map(index -> {
FileDTO fileDTO = new FileDTO();
BeanUtils.copyProperties(index, fileDTO);
......@@ -84,10 +84,11 @@ public class SmartSysFileServiceImpl implements SmartSysFileService {
* @param fileDTO 文件
*/
@Override
public void updateFile(FileDTO fileDTO) {
SmartSysFile smartSysFile=new SmartSysFile();
public FileDTO updateFile(FileDTO fileDTO) {
SmartSysFile smartSysFile = new SmartSysFile();
BeanUtils.copyProperties(fileDTO,smartSysFile);
insertOrUpdate(smartSysFile);
fileDTO.setId(insertOrUpdate(smartSysFile));
return fileDTO;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!