提交 | 用户 | 时间
|
f1162e
|
1 |
package com.iailab.module.data.ind.category.service.impl; |
潘 |
2 |
|
|
3 |
import com.iailab.framework.common.util.object.BeanUtils; |
cb49da
|
4 |
import com.iailab.framework.mybatis.core.query.LambdaQueryWrapperX; |
f1162e
|
5 |
import com.iailab.module.data.ind.category.entity.IndItemCategoryEntity; |
潘 |
6 |
import com.iailab.module.data.ind.category.service.IndItemCategoryService; |
|
7 |
import com.iailab.module.data.ind.category.vo.IndItemCategoryReqVO; |
|
8 |
import com.iailab.module.data.ind.category.dao.IndItemCategoryDao; |
|
9 |
import com.iailab.module.data.ind.category.vo.IndItemCategorySaveReqVO; |
|
10 |
import com.iailab.module.system.enums.permission.MenuTypeEnum; |
|
11 |
import lombok.extern.slf4j.Slf4j; |
|
12 |
import org.springframework.stereotype.Service; |
|
13 |
|
|
14 |
import javax.annotation.Resource; |
|
15 |
import java.util.Date; |
|
16 |
import java.util.List; |
|
17 |
import java.util.UUID; |
|
18 |
|
|
19 |
import static com.iailab.framework.common.exception.util.ServiceExceptionUtil.exception; |
|
20 |
import static com.iailab.module.system.enums.ErrorCodeConstants.*; |
|
21 |
import static com.iailab.module.data.ind.category.entity.IndItemCategoryEntity.ID_ROOT; |
|
22 |
|
|
23 |
/** |
|
24 |
* @author PanZhibao |
|
25 |
* @Description |
|
26 |
* @createTime 2024年09月10日 |
|
27 |
*/ |
|
28 |
@Service |
|
29 |
@Slf4j |
|
30 |
public class IndItemCategoryServiceImpl implements IndItemCategoryService { |
|
31 |
|
|
32 |
@Resource |
|
33 |
private IndItemCategoryDao indItemCategoryDao; |
|
34 |
|
|
35 |
@Override |
|
36 |
public List<IndItemCategoryEntity> getList(IndItemCategoryReqVO reqVO) { |
|
37 |
return indItemCategoryDao.selectList(reqVO); |
|
38 |
} |
|
39 |
|
|
40 |
@Override |
cb49da
|
41 |
public List<IndItemCategoryEntity> getSimpleList() { |
潘 |
42 |
return indItemCategoryDao.selectList(new LambdaQueryWrapperX<IndItemCategoryEntity>()); |
|
43 |
} |
|
44 |
|
|
45 |
@Override |
f1162e
|
46 |
public void create(IndItemCategorySaveReqVO createReqVO) { |
潘 |
47 |
// 校验父菜单存在 |
|
48 |
validateParentMenu(createReqVO.getPid(), null); |
|
49 |
|
|
50 |
// 插入数据库 |
|
51 |
IndItemCategoryEntity entity = BeanUtils.toBean(createReqVO, IndItemCategoryEntity.class); |
|
52 |
entity.setId(UUID.randomUUID().toString()); |
|
53 |
entity.setCreateTime(new Date()); |
|
54 |
indItemCategoryDao.insert(entity); |
|
55 |
} |
|
56 |
|
|
57 |
@Override |
|
58 |
public void update(IndItemCategorySaveReqVO updateReqVO) { |
|
59 |
// 校验父菜单存在 |
|
60 |
validateParentMenu(updateReqVO.getPid(), null); |
|
61 |
IndItemCategoryEntity entity = BeanUtils.toBean(updateReqVO, IndItemCategoryEntity.class); |
|
62 |
entity.setUpdateTime(new Date()); |
|
63 |
indItemCategoryDao.updateById(entity); |
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
public IndItemCategoryEntity get(String id) { |
|
68 |
return indItemCategoryDao.selectById(id); |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public void delete(String id) { |
|
73 |
indItemCategoryDao.deleteById(id); |
|
74 |
} |
|
75 |
|
|
76 |
private void validateParentMenu(String parentId, String childId) { |
|
77 |
if (parentId == null || ID_ROOT.equals(parentId)) { |
|
78 |
return; |
|
79 |
} |
|
80 |
// 不能设置自己为父菜单 |
|
81 |
if (parentId.equals(childId)) { |
|
82 |
throw exception(MENU_PARENT_ERROR); |
|
83 |
} |
|
84 |
IndItemCategoryEntity category = indItemCategoryDao.selectById(parentId); |
|
85 |
// 父菜单不存在 |
|
86 |
if (category == null) { |
|
87 |
throw exception(MENU_PARENT_NOT_EXISTS); |
|
88 |
} |
|
89 |
} |
|
90 |
} |