Browse Source

fix: 添加调度计划名称重复校验

master_tdsql
hxh 1 year ago
parent
commit
9f503d8958
  1. 18
      shuili-system/src/main/java/com/kms/yxgh/sz/service/SzSchedulingService.java

18
shuili-system/src/main/java/com/kms/yxgh/sz/service/SzSchedulingService.java

@ -2,13 +2,16 @@ package com.kms.yxgh.sz.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kms.yxgh.sz.domain.SzScheduling;
import com.kms.yxgh.sz.dto.SzSchedulingDto;
import com.kms.yxgh.sz.mapper.SzSchedulingMapper;
import com.shuili.common.core.domain.SearchParam;
import com.shuili.common.core.service.BaseService;
import com.shuili.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -37,6 +40,10 @@ public class SzSchedulingService extends BaseService<SzSchedulingMapper, SzSched
@Transactional(rollbackFor = Exception.class)
public SzSchedulingDto add(SzSchedulingDto dto) {
if (isExistPlanName(dto.getPlanName(), null)) {
throw new RuntimeException("计划名称已存在");
}
SzScheduling entity = new SzScheduling();
entity.setWagaCode(dto.getWagaCode());
entity.setName(dto.getPlanName());
@ -46,8 +53,19 @@ public class SzSchedulingService extends BaseService<SzSchedulingMapper, SzSched
return dto;
}
//判断计划名称是否存在
public boolean isExistPlanName(String planName, String id) {
Wrapper<SzScheduling> wrapper = Wrappers.<SzScheduling>lambdaQuery()
.eq(SzScheduling::getName, planName)
.ne(StringUtils.isNotBlank(id), SzScheduling::getId, id);
return baseMapper.selectCount(wrapper) > 0;
}
@Transactional(rollbackFor = Exception.class)
public SzSchedulingDto modify(SzSchedulingDto dto) {
if (isExistPlanName(dto.getPlanName(), dto.getId())) {
throw new RuntimeException("计划名称已存在");
}
SzScheduling entity = new SzScheduling();
entity.setId(dto.getId());
entity.setWagaCode(dto.getWagaCode());

Loading…
Cancel
Save