记得上下班打卡 | git大法好,push需谨慎

Commit 299ccf38 authored by wangyifan's avatar wangyifan

返回手册发布状态字段并重新排序

parent e8989233
......@@ -38,6 +38,12 @@ public class SweetManualAppletDto implements Serializable ,Cloneable{
@ApiModelProperty("纬度")
private String latitude;
@ApiModelProperty("是否发布手册 0:不发布 1:发布")
private Integer isReleaseManual;
@ApiModelProperty("是否距离今日最近 0:否 1:是")
private Integer isNear;
private static final SweetManualAppletDto obj = new SweetManualAppletDto();
public static SweetManualAppletDto getNew() {
......
......@@ -132,7 +132,8 @@
p.time_end,
t1.time_sell,
t1.pay_countdown_minute,
t1.is_member
t1.is_member,
sm.is_release_manual
FROM kylin_performances AS p
LEFT JOIN kylin_performance_status AS ps ON p.performances_id = ps.performance_id
LEFT JOIN kylin_performance_relations AS pr ON p.performances_id = pr.performance_id
......
......@@ -9,6 +9,7 @@ import com.liquidnet.service.sweet.dto.SweetPerformArtistTimeListDto;
import com.liquidnet.service.sweet.entity.SweetManualNotify;
import com.liquidnet.service.sweet.entity.SweetManualShop;
import com.liquidnet.service.sweet.entity.SweetRichtext;
import com.liquidnet.service.sweet.utils.MarkNearestUtils;
import com.liquidnet.service.sweet.utils.ObjectUtil;
import com.liquidnet.service.sweet.utils.RedisArDataUtils;
import com.liquidnet.service.sweet.utils.RedisDataUtils;
......@@ -52,6 +53,7 @@ public class SweetAppletController {
vo.add(item);
}
}
MarkNearestUtils.markNearestPerformance(vo);
return ResponseDto.success(vo);
}
......
package com.liquidnet.service.sweet.utils;
import com.liquidnet.service.sweet.dto.SweetManualAppletDto;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
public class MarkNearestUtils {
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
static {
// 如果 timeStart 是北京时间,设置时区
DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT+8"));
}
/**
* 1. 设置列表中距离当前时间最近的演出 isNear = 1,其余为 0
* 2. 按timeStart 降序排列
*
* @param list 演出手册 DTO 列表
*/
public static void markNearestPerformance(List<SweetManualAppletDto> list) {
if (list == null || list.isEmpty()) {
return;
}
Date now = new Date();
SweetManualAppletDto nearest = null;
Date nearestTime = null;
for (SweetManualAppletDto dto : list) {
if (dto.getTimeStart() == null || dto.getTimeStart().trim().isEmpty()) {
dto.setIsNear(0);
continue;
}
try {
Date startTime = DATE_FORMAT.parse(dto.getTimeStart());
// 可选:如果只考虑未来或正在进行的演出,可取消下面的注释
if (startTime.before(now)) continue;
if (nearestTime == null || startTime.before(nearestTime)) {
nearestTime = startTime;
nearest = dto;
}
} catch (ParseException e) {
// 解析失败,设为 0
dto.setIsNear(0);
}
}
// 先将所有 isNear 设为 0
for (SweetManualAppletDto dto : list) {
dto.setIsNear(0);
}
// 将最近的那个设为 1
if (nearest != null) {
nearest.setIsNear(1);
}
// 第二步:按 timeStart 降序排序(最新的在前)
list.sort((a, b) -> {
if (a.getTimeStart() == null && b.getTimeStart() == null) return 0;
if (a.getTimeStart() == null) return 1;
if (b.getTimeStart() == null) return -1;
try {
Date dateA = DATE_FORMAT.parse(a.getTimeStart());
Date dateB = DATE_FORMAT.parse(b.getTimeStart());
return dateB.compareTo(dateA); // 降序:b.compareTo(a)
} catch (ParseException e) {
// 解析失败,保持原顺序(或可抛出异常)
return 0;
}
});
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment