SmartSysFileServiceImpl.java
2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package com.glsx.smart.service.impl;
import com.glsx.smart.dao.entity.SmartSysFile;
import com.glsx.smart.dao.mapper.SmartSysFileMapper;
import com.glsx.smart.exception.BusinessException;
import com.glsx.smart.exception.ResultEnum;
import com.glsx.smart.pojo.FileDTO;
import com.glsx.smart.service.SmartSysFileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* <p>Description:
* <p>Project: chejia-smart
*
* @author wbh
* @date 2021-03-15
*/
@Slf4j
@Service
public class SmartSysFileServiceImpl implements SmartSysFileService {
@Resource
private SmartSysFileMapper fileMapper;
@Override
public Long insertOrUpdate(SmartSysFile sysFile) {
if (sysFile.getId() == null) {
fileMapper.insert(sysFile);
} else {
SmartSysFile record = fileMapper.selectByPrimaryKey(sysFile.getId());
if (record != null) {
fileMapper.updateByPrimaryKeySelective(sysFile);
} else {
throw new BusinessException(ResultEnum.ID_NOT_FOUND);
}
}
return sysFile.getId();
}
/**
* 查询图标列表
*
* @param type 文件类型
* @return
*/
@Override
public List<FileDTO> findByType(Byte type) {
List<SmartSysFile> list = fileMapper.findByType(type);
List<FileDTO> fileDTOS = list.stream().map(index -> {
FileDTO fileDTO = new FileDTO();
BeanUtils.copyProperties(index, fileDTO);
return fileDTO;
}).collect(Collectors.toList());
return fileDTOS;
}
/**
* 保存图标
*
* @param files 文件集合
*/
@Override
public List<Map<String,Object>> saveFile(List<FileDTO> files) {
List<Map<String,Object>> longList=new ArrayList<>();
List<SmartSysFile> list = files.stream().map(index -> {
SmartSysFile fileDTO = new SmartSysFile();
fileDTO.setCreateTime(new Date());
BeanUtils.copyProperties(index, fileDTO);
return fileDTO;
}).collect(Collectors.toList());
list.forEach(index -> {
Map<String,Object> map=new HashMap<>();
Long aLong = insertOrUpdate(index);
map.put("id",aLong);
map.put("name",index.getName());
longList.add(map);
});
return longList;
}
/**
* 更新图标
*
* @param fileDTO 文件
*/
@Override
public FileDTO updateFile(FileDTO fileDTO) {
SmartSysFile smartSysFile = new SmartSysFile();
BeanUtils.copyProperties(fileDTO, smartSysFile);
fileDTO.setId(insertOrUpdate(smartSysFile));
return fileDTO;
}
}