| | |
| | | package cn.iocoder.yudao.module.system.api.dept; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.module.system.api.dept.dto.PostRespDTO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSaveReqVO; |
| | | import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; |
| | | import cn.iocoder.yudao.module.system.service.dept.PostService; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | return BeanUtils.toBean(list, PostRespDTO.class); |
| | | } |
| | | |
| | | @Override |
| | | public Long getOrCreatePostByName(String name) { |
| | | String postName = StrUtil.trim(name); |
| | | if (StrUtil.isEmpty(postName)) { |
| | | return null; |
| | | } |
| | | List<PostRespDTO> posts = getPostList(); |
| | | // 1. 已存在:直接复用 |
| | | for (PostRespDTO post : posts) { |
| | | if (postName.equals(StrUtil.trim(post.getName()))) { |
| | | return post.getId(); |
| | | } |
| | | } |
| | | // 2. 不存在:补建。code 必填且需唯一,用时间戳生成 |
| | | PostSaveReqVO createReqVO = new PostSaveReqVO(); |
| | | createReqVO.setName(postName); |
| | | createReqVO.setCode("POST_" + System.currentTimeMillis()); |
| | | createReqVO.setSort(0); |
| | | createReqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| | | return postService.createPost(createReqVO); |
| | | } |
| | | |
| | | } |