houzhongyi
2024-07-11 e7c1260db32209a078a962aaa0ad5492c35774fb
提交 | 用户 | 时间
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;
12 import org.springframework.validation.annotation.Validated;
13
14 import javax.annotation.Resource;
15 import java.util.Collection;
16 import java.util.Collections;
17 import java.util.List;
18
19 import static com.iailab.framework.common.exception.util.ServiceExceptionUtil.exception;
20 import static com.iailab.module.bpm.enums.ErrorCodeConstants.*;
21
22 /**
23  * BPM 流程分类 Service 实现类
24  *
25  * @author iailab
26  */
27 @Service
28 @Validated
29 public class BpmCategoryServiceImpl implements BpmCategoryService {
30
31     @Resource
32     private BpmCategoryMapper bpmCategoryMapper;
33
34     @Override
35     public Long createCategory(BpmCategorySaveReqVO createReqVO) {
36         // 校验唯一
37         validateCategoryNameUnique(createReqVO);
38         validateCategoryCodeUnique(createReqVO);
39         // 插入
40         BpmCategoryDO category = BeanUtils.toBean(createReqVO, BpmCategoryDO.class);
41         bpmCategoryMapper.insert(category);
42         return category.getId();
43     }
44
45     @Override
46     public void updateCategory(BpmCategorySaveReqVO updateReqVO) {
47         // 校验存在
48         validateCategoryExists(updateReqVO.getId());
49         validateCategoryNameUnique(updateReqVO);
50         validateCategoryCodeUnique(updateReqVO);
51         // 更新
52         BpmCategoryDO updateObj = BeanUtils.toBean(updateReqVO, BpmCategoryDO.class);
53         bpmCategoryMapper.updateById(updateObj);
54     }
55
56     private void validateCategoryNameUnique(BpmCategorySaveReqVO updateReqVO) {
57         BpmCategoryDO category = bpmCategoryMapper.selectByName(updateReqVO.getName());
58         if (category == null
59             || ObjUtil.equal(category.getId(), updateReqVO.getId())) {
60             return;
61         }
62         throw exception(CATEGORY_NAME_DUPLICATE, updateReqVO.getName());
63     }
64
65     private void validateCategoryCodeUnique(BpmCategorySaveReqVO updateReqVO) {
66         BpmCategoryDO category = bpmCategoryMapper.selectByCode(updateReqVO.getCode());
67         if (category == null
68             || ObjUtil.equal(category.getId(), updateReqVO.getId())) {
69             return;
70         }
71         throw exception(CATEGORY_CODE_DUPLICATE, updateReqVO.getCode());
72     }
73
74     @Override
75     public void deleteCategory(Long id) {
76         // 校验存在
77         validateCategoryExists(id);
78         // 删除
79         bpmCategoryMapper.deleteById(id);
80     }
81
82     private void validateCategoryExists(Long id) {
83         if (bpmCategoryMapper.selectById(id) == null) {
84             throw exception(CATEGORY_NOT_EXISTS);
85         }
86     }
87
88     @Override
89     public BpmCategoryDO getCategory(Long id) {
90         return bpmCategoryMapper.selectById(id);
91     }
92
93     @Override
94     public PageResult<BpmCategoryDO> getCategoryPage(BpmCategoryPageReqVO pageReqVO) {
95         return bpmCategoryMapper.selectPage(pageReqVO);
96     }
97
98     @Override
99     public List<BpmCategoryDO> getCategoryListByCode(Collection<String> codes) {
100         if (CollUtil.isEmpty(codes)) {
101             return Collections.emptyList();
102         }
103         return bpmCategoryMapper.selectListByCode(codes);
104     }
105
106     @Override
107     public List<BpmCategoryDO> getCategoryListByStatus(Integer status) {
108         return bpmCategoryMapper.selectListByStatus(status);
109     }
110
111 }