|
|
@ -5,7 +5,6 @@ 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.base.SzException; |
|
|
|
import com.kms.yxgh.df.dto.DfYhPlanDto; |
|
|
|
import com.kms.yxgh.sz.domain.SzYhPlan; |
|
|
|
import com.kms.yxgh.sz.dto.SzYhPlanDetailDto; |
|
|
|
import com.kms.yxgh.sz.dto.SzYhPlanSearchDto; |
|
|
@ -27,67 +26,67 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
public class SzYhPlanService extends BaseService<SzYhPlanMapper, SzYhPlan> { |
|
|
|
|
|
|
|
|
|
|
|
public SzYhPlanDetailDto getDetailById(String id) { |
|
|
|
SzYhPlan szPlan = this.getById(id); |
|
|
|
return BeanCopyUtils.copy(szPlan, SzYhPlanDetailDto.class); |
|
|
|
} |
|
|
|
public SzYhPlanDetailDto getDetailById(String id) { |
|
|
|
SzYhPlan szPlan = this.getById(id); |
|
|
|
return BeanCopyUtils.copy(szPlan, SzYhPlanDetailDto.class); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public SzYhPlanDetailDto add(SzYhPlanDetailDto dto) { |
|
|
|
SzYhPlan szPlan = BeanCopyUtils.copy(dto, SzYhPlan.class); |
|
|
|
if (szPlan != null) { |
|
|
|
szPlan.setId(null); |
|
|
|
if (checkNameDistinct(szPlan.getId(), szPlan.getName())) { |
|
|
|
getBaseMapper().insert(szPlan); |
|
|
|
dto.setId(szPlan.getId()); |
|
|
|
return dto; |
|
|
|
} else { |
|
|
|
throw new SzException("该名称已存在"); |
|
|
|
} |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public SzYhPlanDetailDto add(SzYhPlanDetailDto dto) { |
|
|
|
SzYhPlan szPlan = BeanCopyUtils.copy(dto, SzYhPlan.class); |
|
|
|
if (szPlan != null) { |
|
|
|
szPlan.setId(null); |
|
|
|
if (checkNameDistinct(szPlan.getId(), szPlan.getName())) { |
|
|
|
getBaseMapper().insert(szPlan); |
|
|
|
dto.setId(szPlan.getId()); |
|
|
|
return dto; |
|
|
|
} else { |
|
|
|
throw new SzException("该名称已存在"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public SzYhPlanDetailDto update(SzYhPlanDetailDto dto) { |
|
|
|
if (exist(dto.getId())) { |
|
|
|
SzYhPlan szPlan = BeanCopyUtils.copy(dto, SzYhPlan.class); |
|
|
|
if (szPlan != null) { |
|
|
|
if (checkNameDistinct(szPlan.getId(), szPlan.getName())) { |
|
|
|
getBaseMapper().updateById(szPlan); |
|
|
|
return dto; |
|
|
|
} else { |
|
|
|
throw new SzException("该名称已存在"); |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public SzYhPlanDetailDto update(SzYhPlanDetailDto dto) { |
|
|
|
if (exist(dto.getId())) { |
|
|
|
SzYhPlan szPlan = BeanCopyUtils.copy(dto, SzYhPlan.class); |
|
|
|
if (szPlan != null) { |
|
|
|
if (checkNameDistinct(szPlan.getId(), szPlan.getName())) { |
|
|
|
getBaseMapper().updateById(szPlan); |
|
|
|
return dto; |
|
|
|
} else { |
|
|
|
throw new SzException("该名称已存在"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
throw new SzException("源数据不存在,请确认id值是否正确"); |
|
|
|
throw new SzException("源数据不存在,请确认id值是否正确"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Boolean deleteById(String id) { |
|
|
|
return removeById(id); |
|
|
|
} |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Boolean deleteById(String id) { |
|
|
|
return removeById(id); |
|
|
|
} |
|
|
|
|
|
|
|
private boolean checkNameDistinct(String id, String name) { |
|
|
|
Wrapper<SzYhPlan> wp = Wrappers.<SzYhPlan>lambdaQuery() |
|
|
|
.eq(SzYhPlan::getName, name) |
|
|
|
.ne(StringUtils.isNotEmpty(id), SzYhPlan::getId, id); |
|
|
|
return this.getBaseMapper().selectCount(wp) <= 0; |
|
|
|
} |
|
|
|
private boolean checkNameDistinct(String id, String name) { |
|
|
|
Wrapper<SzYhPlan> wp = Wrappers.<SzYhPlan>lambdaQuery() |
|
|
|
.eq(SzYhPlan::getName, name) |
|
|
|
.ne(StringUtils.isNotEmpty(id), SzYhPlan::getId, id); |
|
|
|
return this.getBaseMapper().selectCount(wp) <= 0; |
|
|
|
} |
|
|
|
|
|
|
|
private boolean exist(String id) { |
|
|
|
Wrapper<SzYhPlan> wp = Wrappers.<SzYhPlan>lambdaQuery() |
|
|
|
.eq(SzYhPlan::getId, id); |
|
|
|
return this.getBaseMapper().selectCount(wp) > 0; |
|
|
|
} |
|
|
|
private boolean exist(String id) { |
|
|
|
Wrapper<SzYhPlan> wp = Wrappers.<SzYhPlan>lambdaQuery() |
|
|
|
.eq(SzYhPlan::getId, id); |
|
|
|
return this.getBaseMapper().selectCount(wp) > 0; |
|
|
|
} |
|
|
|
|
|
|
|
public IPage<SzYhPlanSearchDto> search(SearchParam<SzYhPlanSearchDto> sp) { |
|
|
|
Page<SzYhPlanSearchDto> page = new Page<>(sp.getPageNum(), sp.getPageSize()); |
|
|
|
return this.getBaseMapper().selectPage(page, sp.getData()); |
|
|
|
Page<SzYhPlanSearchDto> page = new Page<>(sp.getPageNum(), sp.getPageSize()); |
|
|
|
return this.getBaseMapper().selectPage(page, sp.getData()); |
|
|
|
} |
|
|
|
} |
|
|
|