ColumnServiceImpl.java
2.64 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
package com.sincere.student.service.impl;
import com.sincere.student.dto.ColumnDto;
import com.sincere.student.mapper.ColumnMapper;
import com.sincere.student.model.ColumnType;
import com.sincere.student.service.ColumnService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
@Service
public class ColumnServiceImpl implements ColumnService {
@Autowired
ColumnMapper columnMapper;
@Override
public List<ColumnType> getList(ColumnDto columnDto) {
if (StringUtils.isNotBlank(columnDto.getName())) {
columnDto.setName("%" + columnDto.getName() + "%");
}
return columnMapper.getList(columnDto);
}
@Override
public ColumnType selectDetail(int id) {
return columnMapper.selectDetail(id);
}
@Override
public int create(ColumnType columnType) {
//栏目类型
Integer type = columnType.getType();
//栏目排序
Integer sort = columnType.getSort();
List<ColumnType> countList = columnMapper.countSort(sort.intValue(), type.intValue(), 1, null);
if (!CollectionUtils.isEmpty(countList)) {
int i = 1;
for (ColumnType oldType : countList) {
int addSort = i + sort;
if (addSort > oldType.getSort()) {
//若已存在自增1
oldType.setSort(oldType.getSort() + 1);
columnMapper.update(oldType);
}
i++;
}
}
return columnMapper.create(columnType);
}
@Override
public int update(ColumnType columnType) {
ColumnType colum = columnMapper.selectDetail(columnType.getId());
//栏目类型
Integer type = columnType.getType();
//栏目排序
Integer sort = columnType.getSort();
List<ColumnType> countList = columnMapper.countSort(sort.intValue(), type.intValue(), 2, columnType.getId());
if (!CollectionUtils.isEmpty(countList)) {
int i = 1;
for (ColumnType oldType : countList) {
int addSort = i + sort;
if (addSort > oldType.getSort()) {
//若已存在自增1
oldType.setSort(oldType.getSort() + 1);
columnMapper.update(oldType);
}
i++;
}
}
return columnMapper.update(columnType);
}
@Override
public int delete(int id) {
return columnMapper.delete(id);
}
}