提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.bpm.service.definition; |
H |
2 |
|
|
3 |
import cn.hutool.core.collection.CollUtil; |
|
4 |
import com.iailab.framework.common.enums.CommonStatusEnum; |
|
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.group.BpmUserGroupPageReqVO; |
|
8 |
import com.iailab.module.bpm.controller.admin.definition.vo.group.BpmUserGroupSaveReqVO; |
|
9 |
import com.iailab.module.bpm.dal.dataobject.definition.BpmUserGroupDO; |
|
10 |
import com.iailab.module.bpm.dal.mysql.definition.BpmUserGroupMapper; |
|
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.List; |
|
17 |
import java.util.Map; |
|
18 |
|
|
19 |
import static com.iailab.framework.common.exception.util.ServiceExceptionUtil.exception; |
|
20 |
import static com.iailab.framework.common.util.collection.CollectionUtils.convertMap; |
|
21 |
import static com.iailab.module.bpm.enums.ErrorCodeConstants.USER_GROUP_IS_DISABLE; |
|
22 |
import static com.iailab.module.bpm.enums.ErrorCodeConstants.USER_GROUP_NOT_EXISTS; |
|
23 |
|
|
24 |
/** |
|
25 |
* 用户组 Service 实现类 |
|
26 |
* |
|
27 |
* @author iailab |
|
28 |
*/ |
|
29 |
@Service |
|
30 |
@Validated |
|
31 |
public class BpmUserGroupServiceImpl implements BpmUserGroupService { |
|
32 |
|
|
33 |
@Resource |
|
34 |
private BpmUserGroupMapper userGroupMapper; |
|
35 |
|
|
36 |
@Override |
|
37 |
public Long createUserGroup(BpmUserGroupSaveReqVO createReqVO) { |
|
38 |
BpmUserGroupDO userGroup = BeanUtils.toBean(createReqVO, BpmUserGroupDO.class); |
|
39 |
userGroupMapper.insert(userGroup); |
|
40 |
return userGroup.getId(); |
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
public void updateUserGroup(BpmUserGroupSaveReqVO updateReqVO) { |
|
45 |
// 校验存在 |
|
46 |
validateUserGroupExists(updateReqVO.getId()); |
|
47 |
// 更新 |
|
48 |
BpmUserGroupDO updateObj = BeanUtils.toBean(updateReqVO, BpmUserGroupDO.class); |
|
49 |
userGroupMapper.updateById(updateObj); |
|
50 |
} |
|
51 |
|
|
52 |
@Override |
|
53 |
public void deleteUserGroup(Long id) { |
|
54 |
// 校验存在 |
|
55 |
this.validateUserGroupExists(id); |
|
56 |
// 删除 |
|
57 |
userGroupMapper.deleteById(id); |
|
58 |
} |
|
59 |
|
|
60 |
private void validateUserGroupExists(Long id) { |
|
61 |
if (userGroupMapper.selectById(id) == null) { |
|
62 |
throw exception(USER_GROUP_NOT_EXISTS); |
|
63 |
} |
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
public BpmUserGroupDO getUserGroup(Long id) { |
|
68 |
return userGroupMapper.selectById(id); |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public List<BpmUserGroupDO> getUserGroupList(Collection<Long> ids) { |
|
73 |
return userGroupMapper.selectBatchIds(ids); |
|
74 |
} |
|
75 |
|
|
76 |
|
|
77 |
@Override |
|
78 |
public List<BpmUserGroupDO> getUserGroupListByStatus(Integer status) { |
|
79 |
return userGroupMapper.selectListByStatus(status); |
|
80 |
} |
|
81 |
|
|
82 |
@Override |
|
83 |
public PageResult<BpmUserGroupDO> getUserGroupPage(BpmUserGroupPageReqVO pageReqVO) { |
|
84 |
return userGroupMapper.selectPage(pageReqVO); |
|
85 |
} |
|
86 |
|
|
87 |
@Override |
|
88 |
public void validUserGroups(Collection<Long> ids) { |
|
89 |
if (CollUtil.isEmpty(ids)) { |
|
90 |
return; |
|
91 |
} |
|
92 |
// 获得用户组信息 |
|
93 |
List<BpmUserGroupDO> userGroups = userGroupMapper.selectBatchIds(ids); |
|
94 |
Map<Long, BpmUserGroupDO> userGroupMap = convertMap(userGroups, BpmUserGroupDO::getId); |
|
95 |
// 校验 |
|
96 |
ids.forEach(id -> { |
|
97 |
BpmUserGroupDO userGroup = userGroupMap.get(id); |
|
98 |
if (userGroup == null) { |
|
99 |
throw exception(USER_GROUP_NOT_EXISTS); |
|
100 |
} |
|
101 |
if (!CommonStatusEnum.ENABLE.getStatus().equals(userGroup.getStatus())) { |
|
102 |
throw exception(USER_GROUP_IS_DISABLE, userGroup.getName()); |
|
103 |
} |
|
104 |
}); |
|
105 |
} |
|
106 |
|
|
107 |
} |