提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.bpm.service.definition; |
H |
2 |
|
|
3 |
import cn.hutool.core.collection.CollUtil; |
|
4 |
import cn.hutool.core.util.ObjUtil; |
|
5 |
import com.iailab.framework.common.pojo.PageResult; |
|
6 |
import com.iailab.framework.common.util.object.BeanUtils; |
|
7 |
import com.iailab.module.bpm.controller.admin.definition.vo.category.BpmCategoryPageReqVO; |
|
8 |
import com.iailab.module.bpm.controller.admin.definition.vo.category.BpmCategorySaveReqVO; |
|
9 |
import com.iailab.module.bpm.dal.dataobject.definition.BpmCategoryDO; |
|
10 |
import com.iailab.module.bpm.dal.mysql.category.BpmCategoryMapper; |
|
11 |
import org.springframework.stereotype.Service; |
bb2880
|
12 |
import org.springframework.transaction.annotation.Transactional; |
e7c126
|
13 |
import org.springframework.validation.annotation.Validated; |
H |
14 |
|
|
15 |
import javax.annotation.Resource; |
|
16 |
import java.util.Collection; |
|
17 |
import java.util.Collections; |
|
18 |
import java.util.List; |
bb2880
|
19 |
import java.util.stream.Collectors; |
H |
20 |
import java.util.stream.IntStream; |
e7c126
|
21 |
|
H |
22 |
import static com.iailab.framework.common.exception.util.ServiceExceptionUtil.exception; |
|
23 |
import static com.iailab.module.bpm.enums.ErrorCodeConstants.*; |
|
24 |
|
|
25 |
/** |
|
26 |
* BPM 流程分类 Service 实现类 |
|
27 |
* |
|
28 |
* @author iailab |
|
29 |
*/ |
|
30 |
@Service |
|
31 |
@Validated |
|
32 |
public class BpmCategoryServiceImpl implements BpmCategoryService { |
|
33 |
|
|
34 |
@Resource |
|
35 |
private BpmCategoryMapper bpmCategoryMapper; |
|
36 |
|
|
37 |
@Override |
|
38 |
public Long createCategory(BpmCategorySaveReqVO createReqVO) { |
|
39 |
// 校验唯一 |
|
40 |
validateCategoryNameUnique(createReqVO); |
|
41 |
validateCategoryCodeUnique(createReqVO); |
|
42 |
// 插入 |
|
43 |
BpmCategoryDO category = BeanUtils.toBean(createReqVO, BpmCategoryDO.class); |
|
44 |
bpmCategoryMapper.insert(category); |
|
45 |
return category.getId(); |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
public void updateCategory(BpmCategorySaveReqVO updateReqVO) { |
|
50 |
// 校验存在 |
|
51 |
validateCategoryExists(updateReqVO.getId()); |
|
52 |
validateCategoryNameUnique(updateReqVO); |
|
53 |
validateCategoryCodeUnique(updateReqVO); |
|
54 |
// 更新 |
|
55 |
BpmCategoryDO updateObj = BeanUtils.toBean(updateReqVO, BpmCategoryDO.class); |
|
56 |
bpmCategoryMapper.updateById(updateObj); |
|
57 |
} |
|
58 |
|
|
59 |
private void validateCategoryNameUnique(BpmCategorySaveReqVO updateReqVO) { |
|
60 |
BpmCategoryDO category = bpmCategoryMapper.selectByName(updateReqVO.getName()); |
|
61 |
if (category == null |
bb2880
|
62 |
|| ObjUtil.equal(category.getId(), updateReqVO.getId())) { |
e7c126
|
63 |
return; |
H |
64 |
} |
|
65 |
throw exception(CATEGORY_NAME_DUPLICATE, updateReqVO.getName()); |
|
66 |
} |
|
67 |
|
|
68 |
private void validateCategoryCodeUnique(BpmCategorySaveReqVO updateReqVO) { |
|
69 |
BpmCategoryDO category = bpmCategoryMapper.selectByCode(updateReqVO.getCode()); |
|
70 |
if (category == null |
bb2880
|
71 |
|| ObjUtil.equal(category.getId(), updateReqVO.getId())) { |
e7c126
|
72 |
return; |
H |
73 |
} |
|
74 |
throw exception(CATEGORY_CODE_DUPLICATE, updateReqVO.getCode()); |
|
75 |
} |
|
76 |
|
|
77 |
@Override |
|
78 |
public void deleteCategory(Long id) { |
|
79 |
// 校验存在 |
|
80 |
validateCategoryExists(id); |
|
81 |
// 删除 |
|
82 |
bpmCategoryMapper.deleteById(id); |
|
83 |
} |
|
84 |
|
|
85 |
private void validateCategoryExists(Long id) { |
|
86 |
if (bpmCategoryMapper.selectById(id) == null) { |
|
87 |
throw exception(CATEGORY_NOT_EXISTS); |
|
88 |
} |
|
89 |
} |
|
90 |
|
|
91 |
@Override |
|
92 |
public BpmCategoryDO getCategory(Long id) { |
|
93 |
return bpmCategoryMapper.selectById(id); |
|
94 |
} |
|
95 |
|
|
96 |
@Override |
|
97 |
public PageResult<BpmCategoryDO> getCategoryPage(BpmCategoryPageReqVO pageReqVO) { |
|
98 |
return bpmCategoryMapper.selectPage(pageReqVO); |
|
99 |
} |
|
100 |
|
|
101 |
@Override |
|
102 |
public List<BpmCategoryDO> getCategoryListByCode(Collection<String> codes) { |
|
103 |
if (CollUtil.isEmpty(codes)) { |
|
104 |
return Collections.emptyList(); |
|
105 |
} |
|
106 |
return bpmCategoryMapper.selectListByCode(codes); |
|
107 |
} |
|
108 |
|
|
109 |
@Override |
|
110 |
public List<BpmCategoryDO> getCategoryListByStatus(Integer status) { |
|
111 |
return bpmCategoryMapper.selectListByStatus(status); |
|
112 |
} |
|
113 |
|
bb2880
|
114 |
@Override |
H |
115 |
@Transactional(rollbackFor = Exception.class) |
|
116 |
public void updateCategorySortBatch(List<Long> ids) { |
|
117 |
// 校验分类都存在 |
|
118 |
List<BpmCategoryDO> categories = bpmCategoryMapper.selectBatchIds(ids); |
|
119 |
if (categories.size() != ids.size()) { |
|
120 |
throw exception(CATEGORY_NOT_EXISTS); |
|
121 |
} |
|
122 |
|
|
123 |
// 批量更新排序 |
|
124 |
List<BpmCategoryDO> updateList = IntStream.range(0, ids.size()) |
|
125 |
.mapToObj(index -> new BpmCategoryDO().setId(ids.get(index)).setSort(index)) |
|
126 |
.collect(Collectors.toList()); |
|
127 |
bpmCategoryMapper.updateBatch(updateList); |
|
128 |
} |
|
129 |
|
e7c126
|
130 |
} |