Merge branch 'feature/REQ-1212' into feature/REQ-1102
This commit is contained in:
commit
e739e0f151
@ -57,7 +57,7 @@ public interface SaasBasicDictApi {
|
||||
/**
|
||||
* 添加字典
|
||||
*
|
||||
* @param req 其中name同一个父级节点,名称不能重复,codeMap全局唯一
|
||||
* @param req 其中name,code在同一个父级节点下不能重复
|
||||
* @return 节点id
|
||||
*/
|
||||
@PostMapping("api/dict/create")
|
||||
|
||||
@ -1,9 +1,12 @@
|
||||
package cn.axzo.tyr.client.model.dict.request;
|
||||
|
||||
import cn.axzo.tyr.client.common.annotation.EnumValidator;
|
||||
import cn.axzo.tyr.client.model.DictTypeFiledEnum;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* @author: chenwenjian
|
||||
@ -15,22 +18,19 @@ import javax.validation.constraints.NotBlank;
|
||||
@Data
|
||||
public class BasicDictCreateReq {
|
||||
|
||||
/**
|
||||
* 工作台类型,"ent", "proj", "oms"
|
||||
*/
|
||||
@NotBlank(message = "工作台类型不能为空")
|
||||
private String workspaceType;
|
||||
|
||||
/**
|
||||
* 类型,"ouType", "terminal"
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 所属上级节点id
|
||||
*/
|
||||
@NotNull(message = "所属上级不能为空")
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* type类型不能为空
|
||||
*/
|
||||
@NotNull(message = "type类型不能为空")
|
||||
@EnumValidator(enumClass = DictTypeFiledEnum.class, message = "枚举类型错误")
|
||||
private DictTypeFiledEnum type;
|
||||
|
||||
/**
|
||||
* 字典名称
|
||||
*/
|
||||
|
||||
@ -54,4 +54,8 @@ public class BasicDictQueryReq {
|
||||
*/
|
||||
private Boolean status;
|
||||
|
||||
/**
|
||||
* 层级
|
||||
*/
|
||||
private Integer level;
|
||||
}
|
||||
|
||||
@ -34,6 +34,7 @@ public class SaasBasicDictDao extends ServiceImpl<SaasBasicDictMapper, SaasBasic
|
||||
.eq(Objects.nonNull(req.getType()), SaasBasicDict::getType, Objects.nonNull(req.getType()) ? req.getType().getValue() : "")
|
||||
.in(Objects.nonNull(req.getCodes()), SaasBasicDict::getCode, req.getCodes())
|
||||
.eq(Objects.nonNull(req.getStatus()), SaasBasicDict::getStatus, Boolean.TRUE.equals(req.getStatus()) ? 1 : 0)
|
||||
.eq(Objects.nonNull(req.getLevel()), SaasBasicDict::getLevel, req.getLevel())
|
||||
.like(Objects.nonNull(req.getName()), SaasBasicDict::getName, req.getName());
|
||||
}
|
||||
List<SaasBasicDict> basicDictList = queryChainWrapper.orderByDesc(SaasBasicDict::getSort).list();
|
||||
|
||||
@ -1,14 +1,18 @@
|
||||
package cn.axzo.tyr.server.service.impl;
|
||||
|
||||
import cn.axzo.basics.common.BeanMapper;
|
||||
import cn.axzo.framework.domain.ServiceException;
|
||||
import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
import cn.axzo.tyr.client.model.DictTypeFiledEnum;
|
||||
import cn.axzo.tyr.client.model.dict.request.*;
|
||||
import cn.axzo.tyr.client.model.dict.response.BasicDictNodeResp;
|
||||
import cn.axzo.tyr.client.model.dict.response.BasicDictTreeResp;
|
||||
import cn.axzo.tyr.server.repository.SaasBasicDictDao;
|
||||
import cn.axzo.tyr.server.repository.entity.SaasBasicDict;
|
||||
import cn.axzo.tyr.server.service.SaasBasicDictService;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -103,8 +107,49 @@ public class SaasBasicDictServiceImpl implements SaasBasicDictService {
|
||||
return ApiResult.ok(saasBasicDictDao.getBasicDictNode(req));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建字典节点
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ApiResult<Long> create(BasicDictCreateReq req) {
|
||||
SaasBasicDict parent = saasBasicDictDao.getById(req.getParentId());
|
||||
if (Objects.isNull(parent)) {
|
||||
throw new ServiceException("不存在给定的上级节点");
|
||||
}
|
||||
// 获取所属父节点下所有同级节点,name和code在同级节点中不能重复
|
||||
List<BasicDictNodeResp> brotherNodeList = saasBasicDictDao.getBasicDictNodeList(
|
||||
BasicDictQueryReq.builder()
|
||||
.parentId(req.getParentId())
|
||||
.type(req.getType())
|
||||
.build());
|
||||
brotherNodeList.forEach(n -> {
|
||||
if (n.getName().equals(req.getName())) {
|
||||
throw new ServiceException("该节点下已存在名称为" + req.getName() + "的节点");
|
||||
}
|
||||
if (n.getCode().equals(req.getCode())) {
|
||||
throw new ServiceException("该节点下已存在code为" + req.getName() + "的节点");
|
||||
}
|
||||
});
|
||||
int count = 0;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
// 生成唯一的unique_code,若生成了与数据库中已存在uniqueCode
|
||||
String uniqueCode = RandomUtil.randomString(10);
|
||||
SaasBasicDict saasBasicDict = BeanMapper.copyBean(req, SaasBasicDict.class, (b, s) -> {
|
||||
s.setWorkspaceType(parent.getWorkspaceType());
|
||||
s.setType(b.getType().getValue());
|
||||
s.setUniqueCode(uniqueCode);
|
||||
s.setLevel(parent.getLevel()+1);
|
||||
s.setPath(String.join(",",parent.getPath(),uniqueCode));
|
||||
});
|
||||
try{
|
||||
boolean save = saasBasicDictDao.save(saasBasicDict);
|
||||
}catch (MybatisPlusException e){
|
||||
// if ()
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user