Commit 0360e840 by wnb0128

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

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