| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.boot.context.event.ApplicationReadyEvent; |
| | | import org.springframework.context.event.EventListener; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | |
| | | @Slf4j |
| | | //æ¦æå¸å·¥ä¸åä¿¡æ¯å屿°æ®æ¨é(宿¶ä»»å¡) |
| | | public class ScheduledApi { |
| | | |
| | | @Value("${api.loggingEnabled:false}") |
| | | private boolean loggingEnabled; |
| | | |
| | | @Value("${api.electricityEnabled:false}") |
| | | private boolean electricityEnabled; |
| | | |
| | | @Value("${api.ip}") |
| | | private String apiIp; |
| | | |
| | | @Value("${api.entName}") |
| | | private String entName; |
| | |
| | | |
| | | private static final Random RANDOM = new Random(); |
| | | |
| | | @EventListener(ApplicationReadyEvent.class) |
| | | public void logPushStatus() { |
| | | log.info("æ¦æå¸å·¥ä¸åä¿¡æ¯å屿°æ®æ¨éé
ç½®ï¼ç»å½æ¥å¿æ¨é{}ï¼çµéæ°æ®æ¨é{}ï¼æ¨éå°åï¼{}ï¼ä¼ä¸ï¼{}", |
| | | loggingEnabled ? "å·²å¼å¯" : "å·²å
³é", |
| | | electricityEnabled ? "å·²å¼å¯" : "å·²å
³é", apiIp, entName); |
| | | } |
| | | |
| | | //æ¨éç»å½æ¥å¿æ¯å¨ |
| | | // @Scheduled(cron = "0 0 1 ? * 1") |
| | | @Scheduled(cron = "0 0 1 ? * 1") |
| | | public void logging(){ |
| | | if (!loggingEnabled) { |
| | | return; |
| | | } |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:dd"); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | //è·åç»å½æ¥å¿ |
| | |
| | | } |
| | | |
| | | //æ¨éçµæ¯æ |
| | | // @Scheduled(cron = "0 0 1 1 * ?") |
| | | @Scheduled(cron = "0 0 1 1 * ?") |
| | | public void electricity(){ |
| | | if (!electricityEnabled) { |
| | | return; |
| | | } |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:dd"); |
| | | //è·åç»å½æ¥å¿ |
| | | List<ElectricityDto> electricityDtos = new ArrayList<>(); |