feat: 展示时间

This commit is contained in:
李京通 2025-06-07 16:54:04 +08:00
parent 96afbc47d1
commit 0c8a5ad9a0
2 changed files with 72 additions and 3 deletions

View File

@ -14,6 +14,10 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.List; import java.util.List;
/** /**
@ -36,9 +40,72 @@ public class ApprovalProcessController extends BaseController {
startPage(); startPage();
QueryWrapper<ApprovalProcess> queryWrapper = new QueryWrapper<>(approvalProcess); QueryWrapper<ApprovalProcess> queryWrapper = new QueryWrapper<>(approvalProcess);
List<ApprovalProcess> list = approvalsProcessService.list(queryWrapper); List<ApprovalProcess> list = approvalsProcessService.list(queryWrapper);
for (ApprovalProcess process : list) {
// 如果创建时间为当天的时间
if (process.getCreateTime() > System.currentTimeMillis() - 24 * 60 * 60 * 1000) {
// 一分钟之内显示刚刚
// 模拟获取创建时间戳这里以当前时间戳减去一定值为例实际应替换为 process.getCreateTime()
long createTime = process.getCreateTime();
long currentTime = System.currentTimeMillis();
String result;
if (createTime > currentTime - 60 * 1000) {
result = "刚刚";
process.setShowTime(result);
} else if (createTime <= currentTime - 60 * 1000 && createTime > currentTime - 30 * 60 * 1000) {
long minutes = (currentTime - createTime) / (60 * 1000);
result = minutes + "分钟前";
process.setShowTime(result);
} else if (createTime <= currentTime - 30 * 60 * 1000 && createTime > currentTime - 60 * 60 * 1000) {
result = "半小时前";
process.setShowTime(result);
} else if (createTime <= currentTime - 60 * 60 * 1000) {
long hours = (currentTime - createTime) / (60 * 60 * 1000);
result = hours + "小时前";
process.setShowTime(result);
} else {
result = "时间计算异常";
process.setShowTime(result);
}
/*Long createTime = process.getCreateTime();
Instant instant = Instant.ofEpochMilli(createTime);
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.of("Asia/Shanghai"));
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
String formattedTime = localDateTime.format(formatter);
process.setShowTime(formattedTime);*/
} else if (process.getCreateTime() > System.currentTimeMillis() - 24 * 60 * 60 * 1000 && process.getCreateTime() < System.currentTimeMillis() - 2 * 24 * 60 * 60 * 1000) {
// 超过一天不大于两天显示昨天
process.setShowTime("昨天");
} else {
// 超过两天显示年月日时分秒
Long createTime = process.getCreateTime();
Instant instant = Instant.ofEpochMilli(createTime);
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.of("Asia/Shanghai"));
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd");
String formattedTime = localDateTime.format(formatter);
process.setShowTime(formattedTime);
}
}
return getDataTable(list); return getDataTable(list);
} }
public static void main(String[] args) {
Long createTime = 1749279303395L;
Instant instant = Instant.ofEpochMilli(createTime);
// 2. 转换为本地时区如北京时间 UTC+8
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.of("Asia/Shanghai"));
// 3. 定义日期时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
// 4. 格式化为字符串
String formattedTime = localDateTime.format(formatter);
System.out.println(formattedTime);
}
@ApiOperation("根据编号查") @ApiOperation("根据编号查")
@PostMapping("/getByApprovalNo/{id}") @PostMapping("/getByApprovalNo/{id}")
public TableDataInfo getByApprovalNo(@PathVariable String id) { public TableDataInfo getByApprovalNo(@PathVariable String id) {
@ -58,7 +125,4 @@ public class ApprovalProcessController extends BaseController {
} }
} }

View File

@ -34,6 +34,11 @@ public class ApprovalProcess {
@ApiModelProperty("抄送人姓名") @ApiModelProperty("抄送人姓名")
private String ccName; private String ccName;
@ApiModelProperty("显示时间")
@TableField(exist = false)
private String showTime;
@ApiModelProperty("抄送人ID") @ApiModelProperty("抄送人ID")
private Long ccId; private Long ccId;