package net.gepafin.tendermanagement.dao; import java.time.LocalDateTime; import java.time.LocalTime; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import net.gepafin.tendermanagement.entities.ApplicationEntity; import net.gepafin.tendermanagement.entities.HubEntity; import net.gepafin.tendermanagement.entities.ProtocolEntity; import net.gepafin.tendermanagement.repositories.ProtocolRepository; import net.gepafin.tendermanagement.util.DateTimeUtil; @Component public class ProtocolDao { @Autowired private ProtocolRepository protocolRepository; @Value("${default.hub.uuid}") private String defaultHubUuid; public Long getProtocolNumber(HubEntity hubEntity) { Long maxProtocolNumber = protocolRepository.findMaxProtocolNumberAndHubId(hubEntity.getId()); Long startNumber = 10000001L; if(Boolean.FALSE.equals(defaultHubUuid.equals(hubEntity.getUniqueUuid()))) { startNumber = 20000001L; } return (maxProtocolNumber != null) ? maxProtocolNumber + 1 : startNumber; } public ProtocolEntity createProtocolEntity(ApplicationEntity applicationEntity,Long protocolNumber, Long hubId){ ProtocolEntity protocolEntity=new ProtocolEntity(); protocolEntity.setCall(applicationEntity.getCall().getId()); LocalDateTime utcDateTime = DateTimeUtil.DateServerToUTC(LocalDateTime.now()); protocolEntity.setYear(utcDateTime.getYear()); protocolEntity.setProtocolNumber(protocolNumber); protocolEntity.setTime(LocalTime.now()); protocolEntity.setApplicationId(applicationEntity.getId()); protocolEntity.setHubId(hubId); protocolRepository.save(protocolEntity); return protocolEntity; } }