增加校验

This commit is contained in:
2024-05-02 09:28:30 +08:00
parent 3aeed0c90c
commit d61236480a

View File

@@ -17,6 +17,7 @@ import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.domain.Page;
@@ -45,10 +46,25 @@ public class CoalWashingDailyAnalysisService
CoalWashingDailyAnalysisEntity entity = mapper.toEntity(request);
entity.setOrganizationId(Ctx.currentUser().getOrganizationId());
validate(entity);
this.repository.save(entity);
return getById(entity.getId());
}
private void validate(CoalWashingDailyAnalysisEntity entity) {
if (CollectionUtils.isNotEmpty(entity.getInputItems())){
entity.getInputItems().forEach(item -> {
if (item.getTime() == null){
throw new BizException("时间不能为空");
}
});
}
}
public CoalWashingDailyAnalysisDto calculate(CreateCoalWashingDailyAnalysisDto request) {
CoalWashingDailyAnalysisEntity entity = mapper.toEntity(request);
@@ -69,6 +85,10 @@ public class CoalWashingDailyAnalysisService
this.mapper.updateEntity(entity, request);
entity.setOrganizationId(Ctx.currentUser().getOrganizationId());
validate(entity);
this.repository.save(entity);
return getById(entity.getId());