Skip to content

Commit 3f7c833

Browse files
committed
[代码完善](v2.5): v2.5 beta 杂项优化
2.5 Beta 详情:https://www.ydyno.com/archives/1225.html
1 parent 3095f37 commit 3f7c833

12 files changed

Lines changed: 37 additions & 52 deletions

File tree

eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ public static File upload(MultipartFile file, String filePath) {
140140
File dest = new File(path).getCanonicalFile();
141141
// 检测是否存在目录
142142
if (!dest.getParentFile().exists()) {
143-
dest.getParentFile().mkdirs();
143+
if (!dest.getParentFile().mkdirs()) {
144+
System.out.println("was not successful.");
145+
}
144146
}
145147
// 文件写入
146148
file.transferTo(dest);
@@ -220,7 +222,7 @@ private static byte[] getByte(File file) {
220222
try {
221223
InputStream in = new FileInputStream(file);
222224
try {
223-
in.read(b);
225+
System.out.println(in.read(b));
224226
} catch (IOException e) {
225227
e.printStackTrace();
226228
}

eladmin-system/src/main/java/me/zhengjie/modules/mnt/util/ZipUtils.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ public static void unZipIt(String zipFilePath, String outputFolder) {
5050
System.out.println("file unzip : " + newFile.getAbsoluteFile());
5151
//大部分网络上的源码,这里没有判断子目录
5252
if (ze.isDirectory()) {
53-
newFile.mkdirs();
53+
if (!newFile.mkdirs()) {
54+
System.out.println("was not successful.");
55+
}
5456
} else {
55-
new File(newFile.getParent()).mkdirs();
57+
if (!new File(newFile.getParent()).mkdirs()) {
58+
System.out.println("was not successful.");
59+
}
5660
FileOutputStream fos = new FileOutputStream(newFile);
5761
int len;
5862
while ((len = zis.read(buffer)) != -1) {
@@ -80,12 +84,16 @@ public static void unzip(File source, String out) throws IOException {
8084
File file = new File(out, entry.getName());
8185

8286
if (entry.isDirectory()) {
83-
file.mkdirs();
87+
if (!file.mkdirs()) {
88+
System.out.println("was not successful.");
89+
}
8490
} else {
8591
File parent = file.getParentFile();
8692

8793
if (!parent.exists()) {
88-
parent.mkdirs();
94+
if (!parent.mkdirs()) {
95+
System.out.println("was not successful.");
96+
}
8997
}
9098

9199
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))) {
@@ -115,7 +123,9 @@ public static void unzip(File source, String out) throws IOException {
115123
public static void upZipFile(File zipFile, String folderPath) throws ZipException, IOException {
116124
File desDir = new File(folderPath);
117125
if (!desDir.exists()) {
118-
desDir.mkdirs();
126+
if (!desDir.mkdirs()) {
127+
System.out.println("was not successful.");
128+
}
119129
}
120130
ZipFile zf = new ZipFile(zipFile);
121131
for (Enumeration<?> entries = zf.entries(); entries.hasMoreElements(); ) {
@@ -127,7 +137,9 @@ public static void upZipFile(File zipFile, String folderPath) throws ZipExceptio
127137
if (!desFile.exists()) {
128138
File fileParentDir = desFile.getParentFile();
129139
if (!fileParentDir.exists()) {
130-
fileParentDir.mkdirs();
140+
if (!fileParentDir.mkdirs()) {
141+
System.out.println("was not successful.");
142+
}
131143
}
132144
}
133145

eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/QuartzJobServiceImpl.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
import me.zhengjie.utils.QueryHelp;
3030
import me.zhengjie.utils.ValidationUtil;
3131
import org.quartz.CronExpression;
32-
import org.springframework.cache.annotation.CacheConfig;
33-
import org.springframework.cache.annotation.CacheEvict;
34-
import org.springframework.cache.annotation.Cacheable;
3532
import org.springframework.data.domain.Pageable;
3633
import org.springframework.stereotype.Service;
3734
import org.springframework.transaction.annotation.Propagation;
@@ -46,7 +43,6 @@
4643
*/
4744
@RequiredArgsConstructor
4845
@Service(value = "quartzJobService")
49-
@CacheConfig(cacheNames = "quartzJob")
5046
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
5147
public class QuartzJobServiceImpl implements QuartzJobService {
5248

@@ -55,7 +51,6 @@ public class QuartzJobServiceImpl implements QuartzJobService {
5551
private final QuartzManage quartzManage;
5652

5753
@Override
58-
@Cacheable
5954
public Object queryAll(JobQueryCriteria criteria, Pageable pageable){
6055
return PageUtil.toPage(quartzJobRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable));
6156
}
@@ -76,15 +71,13 @@ public List<QuartzLog> queryAllLog(JobQueryCriteria criteria) {
7671
}
7772

7873
@Override
79-
@Cacheable(key = "#p0")
8074
public QuartzJob findById(Long id) {
8175
QuartzJob quartzJob = quartzJobRepository.findById(id).orElseGet(QuartzJob::new);
8276
ValidationUtil.isNull(quartzJob.getId(),"QuartzJob","id",id);
8377
return quartzJob;
8478
}
8579

8680
@Override
87-
@CacheEvict(allEntries = true)
8881
@Transactional(rollbackFor = Exception.class)
8982
public QuartzJob create(QuartzJob resources) {
9083
if (!CronExpression.isValidExpression(resources.getCronExpression())){
@@ -96,7 +89,6 @@ public QuartzJob create(QuartzJob resources) {
9689
}
9790

9891
@Override
99-
@CacheEvict(allEntries = true)
10092
@Transactional(rollbackFor = Exception.class)
10193
public void update(QuartzJob resources) {
10294
if (!CronExpression.isValidExpression(resources.getCronExpression())){
@@ -107,7 +99,6 @@ public void update(QuartzJob resources) {
10799
}
108100

109101
@Override
110-
@CacheEvict(allEntries = true)
111102
public void updateIsPause(QuartzJob quartzJob) {
112103
if (quartzJob.getIsPause()) {
113104
quartzManage.resumeJob(quartzJob);
@@ -125,7 +116,6 @@ public void execution(QuartzJob quartzJob) {
125116
}
126117

127118
@Override
128-
@CacheEvict(allEntries = true)
129119
@Transactional(rollbackFor = Exception.class)
130120
public void delete(Set<Long> ids) {
131121
for (Long id : ids) {

eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/ExecutionJob.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public class ExecutionJob extends QuartzJobBean {
5151
private final static ThreadPoolExecutor EXECUTOR = ThreadPoolExecutorUtil.getPoll();
5252

5353
@Override
54-
@SuppressWarnings("unchecked")
5554
public void executeInternal(JobExecutionContext context) {
5655
QuartzJob quartzJob = (QuartzJob) context.getMergedJobDataMap().get(QuartzJob.JOB_KEY);
5756
// 获取spring bean

eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MenuServiceImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ public void delete(Set<Menu> menuSet) {
190190
}
191191

192192
@Override
193+
@Cacheable
193194
public Object getMenus(Long pid) {
194195
List<Menu> menus;
195196
if(pid != null && !pid.equals(0L)){
@@ -201,6 +202,7 @@ public Object getMenus(Long pid) {
201202
}
202203

203204
@Override
205+
@Cacheable
204206
public List<MenuDto> getSuperior(MenuDto menuDto, List<Menu> menus) {
205207
if(menuDto.getPid() == null){
206208
menus.addAll(menuRepository.findByPidIsNull());
@@ -291,6 +293,7 @@ public List<MenuVo> buildMenus(List<MenuDto> menuDtos) {
291293
}
292294

293295
@Override
296+
@Cacheable
294297
public Menu findOne(Long id) {
295298
Menu menu = menuRepository.findById(id).orElseGet(Menu::new);
296299
ValidationUtil.isNull(menu.getId(),"Menu","id",id);

eladmin-tools/src/main/java/me/zhengjie/config/MultipartConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ MultipartConfigElement multipartConfigElement() {
3737
String location = System.getProperty("user.home") + "/.eladmin/file/tmp";
3838
File tmpFile = new File(location);
3939
if (!tmpFile.exists()) {
40-
tmpFile.mkdirs();
40+
if (!tmpFile.mkdirs()) {
41+
System.out.println("create was not successful.");
42+
}
4143
}
4244
factory.setLocation(location);
4345
return factory.createMultipartConfig();

eladmin-tools/src/main/java/me/zhengjie/service/impl/LocalStorageServiceImpl.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
import me.zhengjie.utils.*;
2727
import me.zhengjie.repository.LocalStorageRepository;
2828
import me.zhengjie.service.LocalStorageService;
29-
import org.springframework.cache.annotation.CacheConfig;
30-
import org.springframework.cache.annotation.CacheEvict;
31-
import org.springframework.cache.annotation.Cacheable;
3229
import org.springframework.stereotype.Service;
3330
import org.springframework.transaction.annotation.Propagation;
3431
import org.springframework.transaction.annotation.Transactional;
@@ -49,38 +46,32 @@
4946
*/
5047
@Service
5148
@RequiredArgsConstructor
52-
@CacheConfig(cacheNames = "localStorage")
5349
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
5450
public class LocalStorageServiceImpl implements LocalStorageService {
5551

5652
private final LocalStorageRepository localStorageRepository;
5753
private final LocalStorageMapper localStorageMapper;
5854
private final FileProperties properties;
5955

60-
6156
@Override
62-
@Cacheable
6357
public Object queryAll(LocalStorageQueryCriteria criteria, Pageable pageable){
6458
Page<LocalStorage> page = localStorageRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
6559
return PageUtil.toPage(page.map(localStorageMapper::toDto));
6660
}
6761

6862
@Override
69-
@Cacheable
7063
public List<LocalStorageDto> queryAll(LocalStorageQueryCriteria criteria){
7164
return localStorageMapper.toDto(localStorageRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
7265
}
7366

7467
@Override
75-
@Cacheable(key = "#p0")
7668
public LocalStorageDto findById(Long id){
7769
LocalStorage localStorage = localStorageRepository.findById(id).orElseGet(LocalStorage::new);
7870
ValidationUtil.isNull(localStorage.getId(),"LocalStorage","id",id);
7971
return localStorageMapper.toDto(localStorage);
8072
}
8173

8274
@Override
83-
@CacheEvict(allEntries = true)
8475
@Transactional(rollbackFor = Exception.class)
8576
public LocalStorageDto create(String name, MultipartFile multipartFile) {
8677
FileUtil.checkSize(properties.getMaxSize(), multipartFile.getSize());
@@ -108,7 +99,6 @@ public LocalStorageDto create(String name, MultipartFile multipartFile) {
10899
}
109100

110101
@Override
111-
@CacheEvict(allEntries = true)
112102
@Transactional(rollbackFor = Exception.class)
113103
public void update(LocalStorage resources) {
114104
LocalStorage localStorage = localStorageRepository.findById(resources.getId()).orElseGet(LocalStorage::new);
@@ -118,7 +108,6 @@ public void update(LocalStorage resources) {
118108
}
119109

120110
@Override
121-
@CacheEvict(allEntries = true)
122111
@Transactional(rollbackFor = Exception.class)
123112
public void deleteAll(Long[] ids) {
124113
for (Long id : ids) {

eladmin-tools/src/main/java/me/zhengjie/service/impl/PictureServiceImpl.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import me.zhengjie.exception.BadRequestException;
3030
import me.zhengjie.utils.*;
3131
import org.springframework.beans.factory.annotation.Value;
32-
import org.springframework.cache.annotation.CacheConfig;
3332
import org.springframework.data.domain.Pageable;
3433
import org.springframework.stereotype.Service;
3534
import org.springframework.transaction.annotation.Propagation;
@@ -47,7 +46,6 @@
4746
@Slf4j
4847
@RequiredArgsConstructor
4948
@Service(value = "pictureService")
50-
@CacheConfig(cacheNames = "picture")
5149
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
5250
public class PictureServiceImpl implements PictureService {
5351

eladmin-tools/src/main/java/me/zhengjie/service/impl/QiNiuServiceImpl.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import me.zhengjie.utils.ValidationUtil;
4040
import org.springframework.beans.factory.annotation.Value;
4141
import org.springframework.cache.annotation.CacheConfig;
42-
import org.springframework.cache.annotation.CacheEvict;
4342
import org.springframework.cache.annotation.CachePut;
4443
import org.springframework.cache.annotation.Cacheable;
4544
import org.springframework.data.domain.Pageable;
@@ -86,7 +85,7 @@ public QiniuConfig find() {
8685
}
8786

8887
@Override
89-
@CachePut(cacheNames = "qiNiuConfig", key = "'1'")
88+
@CachePut(key = "'1'")
9089
@Transactional(rollbackFor = Exception.class)
9190
public QiniuConfig update(QiniuConfig qiniuConfig) {
9291
String http = "http://", https = "https://";
@@ -98,7 +97,6 @@ public QiniuConfig update(QiniuConfig qiniuConfig) {
9897
}
9998

10099
@Override
101-
@CacheEvict(allEntries = true)
102100
@Transactional(rollbackFor = Exception.class)
103101
public QiniuContent upload(MultipartFile file, QiniuConfig qiniuConfig) {
104102
FileUtil.checkSize(maxSize, file.getSize());
@@ -138,15 +136,13 @@ public QiniuContent upload(MultipartFile file, QiniuConfig qiniuConfig) {
138136
}
139137

140138
@Override
141-
@Cacheable
142139
public QiniuContent findByContentId(Long id) {
143140
QiniuContent qiniuContent = qiniuContentRepository.findById(id).orElseGet(QiniuContent::new);
144141
ValidationUtil.isNull(qiniuContent.getId(),"QiniuContent", "id",id);
145142
return qiniuContent;
146143
}
147144

148145
@Override
149-
@Cacheable
150146
public String download(QiniuContent content,QiniuConfig config){
151147
String finalUrl;
152148
String type = "公开";
@@ -162,7 +158,6 @@ public String download(QiniuContent content,QiniuConfig config){
162158
}
163159

164160
@Override
165-
@CacheEvict(allEntries = true)
166161
@Transactional(rollbackFor = Exception.class)
167162
public void delete(QiniuContent content, QiniuConfig config) {
168163
//构造一个带指定Zone对象的配置类
@@ -178,7 +173,6 @@ public void delete(QiniuContent content, QiniuConfig config) {
178173
}
179174

180175
@Override
181-
@CacheEvict(allEntries = true)
182176
@Transactional(rollbackFor = Exception.class)
183177
public void synchronize(QiniuConfig config) {
184178
if(config.getId() == null){
@@ -216,15 +210,13 @@ public void synchronize(QiniuConfig config) {
216210
}
217211

218212
@Override
219-
@CacheEvict(allEntries = true)
220213
public void deleteAll(Long[] ids, QiniuConfig config) {
221214
for (Long id : ids) {
222215
delete(findByContentId(id), config);
223216
}
224217
}
225218

226219
@Override
227-
@CacheEvict(allEntries = true)
228220
@Transactional(rollbackFor = Exception.class)
229221
public void update(String type) {
230222
qiNiuConfigRepository.update(type);

eladmin-tools/src/main/java/me/zhengjie/utils/AliPayStatusEnum.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@
2323
public enum AliPayStatusEnum {
2424

2525
/** 交易成功 */
26-
FINISHED("交易成功", "TRADE_FINISHED"),
26+
FINISHED("TRADE_FINISHED"),
2727

2828
/** 支付成功 */
29-
SUCCESS("支付成功", "TRADE_SUCCESS"),
29+
SUCCESS("TRADE_SUCCESS"),
3030

3131
/** 交易创建 */
32-
BUYER_PAY("交易创建", "WAIT_BUYER_PAY"),
32+
BUYER_PAY("WAIT_BUYER_PAY"),
3333

3434
/** 交易关闭 */
35-
CLOSED("交易关闭", "TRADE_CLOSED");
35+
CLOSED("TRADE_CLOSED");
3636

37-
private String value;
37+
private final String value;
3838

39-
AliPayStatusEnum(String name, String value) {
39+
AliPayStatusEnum(String value) {
4040
this.value = value;
4141
}
4242

0 commit comments

Comments
 (0)