部门校验名字是否重复
parent
8ba09d4d1d
commit
6ad31a5c3f
|
|
@ -10,6 +10,7 @@ import com.zcloud.basic.info.domain.gateway.DepartmentSuperviseGateway;
|
|||
import com.zcloud.basic.info.domain.model.DepartmentE;
|
||||
import com.zcloud.basic.info.domain.model.DepartmentSuperviseE;
|
||||
import com.zcloud.basic.info.dto.DepartmentAddCmd;
|
||||
import com.zcloud.basic.info.persistence.repository.DepartmentRepository;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
|
|
@ -34,13 +35,16 @@ public class DepartmentAddExe {
|
|||
|
||||
private final DepartmentGateway departmentGateway;
|
||||
private final DepartmentSuperviseGateway departmentSuperviseGateway;
|
||||
private final DepartmentSuperviseCoConvertor departmentSuperviseCoConvertor;
|
||||
private final DepartmentRepository departmentRepository;
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long execute(DepartmentAddCmd cmd) {
|
||||
DepartmentE examTypeE = new DepartmentE();
|
||||
|
||||
//名字校验重复
|
||||
if (departmentRepository.existsByName(cmd.getName())) {
|
||||
throw new BizException("部门名称已存在");
|
||||
}
|
||||
BeanUtils.copyProperties(cmd, examTypeE);
|
||||
Long id = null;
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.zcloud.basic.info.domain.model.DepartmentE;
|
|||
import com.zcloud.basic.info.persistence.dataobject.CorpInfoDO;
|
||||
import com.zcloud.basic.info.persistence.dataobject.DepartmentDO;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -33,5 +34,7 @@ public interface DepartmentRepository extends BaseRepository<DepartmentDO> {
|
|||
|
||||
|
||||
List<DepartmentDO> listAllTree();
|
||||
|
||||
boolean existsByName(@NotEmpty(message = "名称不能为空") String name);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -123,5 +123,13 @@ public class DepartmentRepositoryImpl extends BaseRepositoryImpl<DepartmentMappe
|
|||
public List<DepartmentDO> listAllTree() {
|
||||
return departmentMapper.listAllTree();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsByName(String name) {
|
||||
QueryWrapper<DepartmentDO> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("name", name);
|
||||
queryWrapper.eq("corpinfo_id", AuthContext.getTenantId());
|
||||
return departmentMapper.selectCount(queryWrapper) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue