7 changed files with 125 additions and 16 deletions
@ -0,0 +1,28 @@ |
|||||
|
package com.userinformation.backend.controller; |
||||
|
|
||||
|
import java.time.LocalDateTime; |
||||
|
|
||||
|
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
import com.userinformation.backend.service.TLogPService; |
||||
|
|
||||
|
/** |
||||
|
* @describe: t-logp image control |
||||
|
* @author: xiaowuler |
||||
|
* @createTime: 2022-02-28 13:48 |
||||
|
*/ |
||||
|
@RestController |
||||
|
@RequestMapping("tLogP") |
||||
|
public class TLogPController { |
||||
|
|
||||
|
private final TLogPService tLogPService; |
||||
|
public TLogPController(TLogPService tLogPService){ |
||||
|
this.tLogPService = tLogPService; |
||||
|
} |
||||
|
|
||||
|
@RequestMapping("findLater") |
||||
|
public String findLater(@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime startTime, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime endTime){ |
||||
|
return tLogPService.findLater(startTime, endTime); |
||||
|
} |
||||
|
} |
@ -0,0 +1,60 @@ |
|||||
|
package com.userinformation.backend.service; |
||||
|
|
||||
|
import java.io.File; |
||||
|
import java.time.Duration; |
||||
|
import java.time.LocalDateTime; |
||||
|
import java.time.format.DateTimeFormatter; |
||||
|
import java.util.Arrays; |
||||
|
import java.util.Comparator; |
||||
|
import java.util.List; |
||||
|
import java.util.Locale; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
import org.springframework.beans.factory.annotation.Value; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
/** |
||||
|
* @describe: t-logp image read |
||||
|
* @author: xiaowuler |
||||
|
* @createTime: 2022-02-28 14:12 |
||||
|
*/ |
||||
|
@Service |
||||
|
public class TLogPService { |
||||
|
|
||||
|
@Value("${custom.image.path}") |
||||
|
private String parentPath; |
||||
|
|
||||
|
@Value("${custom.parent-url}") |
||||
|
private String parentUrl; |
||||
|
|
||||
|
@Value("${server.port}") |
||||
|
private Integer port; |
||||
|
|
||||
|
private static final DateTimeFormatter COMMON_TIME_FORMAT = DateTimeFormatter.ofPattern("yyyy/yyyyMM/yyyyMMdd"); |
||||
|
private static final DateTimeFormatter FILE_FORMAT = DateTimeFormatter.ofPattern("yyyyMMddHHmm"); |
||||
|
|
||||
|
public String findLater(LocalDateTime startTime, LocalDateTime endTime){ |
||||
|
String path = "%s/picture/weibo/jiangning/T-logP/%s".formatted(parentPath, endTime.format(COMMON_TIME_FORMAT)); |
||||
|
File file = new File(path); |
||||
|
if (file.exists()){ |
||||
|
File[] files = file.listFiles((File dir, String name) -> name.startsWith("T_logP_") && name.toLowerCase(Locale.ROOT).endsWith(".png")); |
||||
|
List<String> names = Arrays.stream(files).map(f -> f.getName()).sorted(Comparator.reverseOrder()).collect(Collectors.toList()); |
||||
|
for(String name : names){ |
||||
|
if (!isAfter(startTime, endTime, name)){ |
||||
|
continue; |
||||
|
} |
||||
|
return "%s/%s".formatted(path, name).replace(parentPath, "%s:%s/product".formatted(parentUrl, port)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (endTime.getDayOfMonth() == startTime.getDayOfMonth()){ |
||||
|
return null; |
||||
|
} |
||||
|
return findLater(startTime.minusMinutes(Duration.between(startTime, endTime).toMinutes()), startTime); |
||||
|
} |
||||
|
|
||||
|
private boolean isAfter(LocalDateTime startTime, LocalDateTime endTime, String name){ |
||||
|
LocalDateTime fileTime = LocalDateTime.parse(name.toLowerCase(Locale.ROOT).replace("t_logp_", "").replace(".png", ""), FILE_FORMAT); |
||||
|
return fileTime.isBefore(endTime) && fileTime.isAfter(startTime); |
||||
|
} |
||||
|
} |
After Width: | Height: | Size: 21 KiB |
Loading…
Reference in new issue