This commit is contained in:
张良(004796)
2024-02-21 14:11:43 +08:00
parent 61d00af5c6
commit c6efe0eb0b
6 changed files with 42 additions and 5 deletions

View File

@@ -16,6 +16,8 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;
@RestController
@@ -32,9 +34,33 @@ public class UserDynamicAppController {
public R<List<DynamicListVo>> page(PageQuery pageQuery, DynamicQuery query){
query.setCurrentUserId(LoginHelper.getUserId());
Page<DynamicListVo> resp = dynamicService.pageApp(pageQuery,query);
resp.getRecords().forEach(i -> {
i.setTimeDiffText(diffTime(i.getCreateTime()));
});
return R.ok(resp.getRecords());
}
private String diffTime(LocalDateTime time){
Duration duration = Duration.between(time, LocalDateTime.now());
long seconds = duration.getSeconds();
long absSeconds = Math.abs(seconds);
long days = absSeconds / (60 * 60 * 24);
long hours = (absSeconds % (60 * 60 * 24)) / (60 * 60);
long minutes = (absSeconds % (60 * 60)) / 60;
long secs = absSeconds % 60;
if(days > 0){
return "1天前";
}
if(hours > 0){
return hours+"小时前";
}
if(minutes > 0){
return minutes+"分钟前";
}
return (secs == 0 ? 1 : secs) + "秒前";
}
@PostMapping("/push")
@Operation(summary = "发布动态")
@Log(title = "发布动态", businessType = BusinessType.OTHER, isSaveDb = true)