Commit 54210b2e by lenx065@gmail.com

调整数据结构

parent 5c400388
......@@ -15,6 +15,8 @@ public class MatchHomeListByDayResponse {
private String matchDay;
private String weekNum;
private List<MatchInfo> matchInfos;
@Data
......@@ -22,6 +24,7 @@ public class MatchHomeListByDayResponse {
@NoArgsConstructor
@AllArgsConstructor
public static class MatchInfo {
private String matchId;
// 0足球 1篮球
private Integer sportsType;
private String matchShortName;
......
......@@ -2,9 +2,11 @@ package com.live.common.domain.request;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
public class GetMatchListByRequest {
@EqualsAndHashCode(callSuper = true)
public class GetMatchListByRequest extends CommonPage {
private String sportsId;
......
......@@ -117,7 +117,7 @@ public class MatchServiceImpl implements MatchService {
wrapper.eq("source_type", 1);
if (StringUtils.isNotBlank(commonStringId.getSportsId())) {
if(commonStringId.getSportsId().equals("-1")){
if (commonStringId.getSportsId().equals("-1")) {
wrapper.eq("hot", 1);
} else {
wrapper.eq("sports_id", commonStringId.getSportsId());
......@@ -126,48 +126,50 @@ public class MatchServiceImpl implements MatchService {
if (StringUtils.isNotBlank(commonStringId.getMatchTime())) {
wrapper.ge("match_time", commonStringId.getMatchTime() + " 00:00:00");
wrapper.le("match_time", commonStringId.getSportsId() + " 23:59:59");
} else {
wrapper.ge("match_time", DateUtil.getYsdStartTime());
}
//-1 全部 0 展示正在进行 和 未开始 1 正在进行 2未开始 3完场
//1正在进行 2未开始 3完场 4 未知
Integer status = commonStringId.getStatus() == null ? 0 : commonStringId.getStatus();
int jumpNum = (commonStringId.getPageNum() - 1) * commonStringId.getPageSize();
long count = 0;
switch (status) {
case -1:
wrapper.notIn("competition_status", 4);
wrapper.orderByDesc("match_time");
wrapper.last(String.format(" limit %s,%s", 0, 30));
wrapper.orderByAsc("match_time");
count = matchMapper.selectCount(wrapper);
wrapper.last(String.format(" limit %s,%s", jumpNum, commonStringId.getPageSize()));
matches = matchMapper.selectList(wrapper);
break;
case 1:
case 2:
case 3:
wrapper.eq("competition_status", status);
wrapper.orderByDesc("match_time");
wrapper.last(String.format(" limit %s,%s", 0, 30));
wrapper.orderByAsc("match_time");
count = matchMapper.selectCount(wrapper);
wrapper.last(String.format(" limit %s,%s", jumpNum, commonStringId.getPageSize()));
matches = matchMapper.selectList(wrapper);
break;
default:
wrapper.in("competition_status", 1, 2);
wrapper.orderByDesc("match_time");
wrapper.last(String.format(" limit %s,%s", 0, 30));
wrapper.orderByAsc("match_time");
count = matchMapper.selectCount(wrapper);
wrapper.last(String.format(" limit %s,%s", jumpNum, commonStringId.getPageSize()));
matches = matchMapper.selectList(wrapper);
break;
}
MatchHomeListByDayResponse response = new MatchHomeListByDayResponse();
response.setMatchInfos(new ArrayList<>());
for (int i = matches.size() - 1; i >= 0; i--) {
if (i == matches.size() - 1) {
response.setMatchDay(DateUtil.format(matches.get(0).getMatchTime(), DateUtil.YMD_));
}
Match match = matches.get(i);
Map<String, List<MatchHomeListByDayResponse.MatchInfo>> responseMap = new LinkedHashMap<>();
for (Match match : matches) {
MatchHomeListByDayResponse.MatchInfo matchInfo = new MatchHomeListByDayResponse.MatchInfo();
matchInfo.setSubscribed(false);
matchInfo.setMatchId(match.getId());
if (DateUtil.format(match.getMatchTime(), DateUtil.YMD_).equals(response.getMatchDay())) {
try {
String phone = CommonMethod.getUserPhone(request);
User account = userMapper.selectOne(Wrappers.<User>lambdaQuery()
......@@ -204,18 +206,28 @@ public class MatchServiceImpl implements MatchService {
matchInfo.setMatchTime(DateUtil.format(match.getMatchTime(), DateUtil.HM_));
matchInfo.setSportsType(sports.getSportsId());
response.getMatchInfos().add(matchInfo);
responseMap.computeIfAbsent(DateUtil.format(match.getMatchTime(), DateUtil.YMD_),
m -> new ArrayList<>()).add(matchInfo);
}
List<MatchHomeListByDayResponse> responses = new ArrayList<>();
for(String key : responseMap.keySet()){
responses.add(MatchHomeListByDayResponse.builder()
.matchDay(key)
.weekNum(DateUtil.returnWeek(DateUtil.getDateByStringYMD(key)))
.matchInfos(responseMap.get(key))
.build());
}
return ResponseData.successResponse(response);
return ResponseData.successResponse(new ResultPage(commonStringId.getPageNum(), commonStringId.getPageSize(),
(int) count, responses));
}
@Override
public ResponseData<?> getMatchTypeInfoList(HttpServletRequest request) {
String key = RedisKeySplicing.requestLock("getMatchTypeInfoList", "0");
if(redisUtilsService.existsKey(key)){
if (redisUtilsService.existsKey(key)) {
String cacheInfo = redisUtilsService.getCacheStringInfo(key);
GetMatchTypeInfoListResponse response = JSONObject.toJavaObject(JSONObject.parseObject(cacheInfo), GetMatchTypeInfoListResponse.class);
return ResponseData.successResponse(response);
......@@ -250,7 +262,7 @@ public class MatchServiceImpl implements MatchService {
public ResponseData<?> getTeamInfoList(HttpServletRequest request) {
String key = RedisKeySplicing.requestLock("getTeamInfoList", "0");
if(redisUtilsService.existsKey(key)){
if (redisUtilsService.existsKey(key)) {
String cacheInfo = redisUtilsService.getCacheStringInfo(key);
GetTeamInfoListResponse response = JSONObject.toJavaObject(JSONObject.parseObject(cacheInfo), GetTeamInfoListResponse.class);
return ResponseData.successResponse(response);
......
......@@ -239,11 +239,6 @@ public class UserServiceImpl implements UserService {
.gold(0)
.userId(accountDb.getId())
.build());
huanXinIMService.registerUser(HuanXinIMServiceImpl.UserRegistration.builder()
.nickName(accountDb.getUserName())
.password("123456")
.username("live_" + accountDb.getId() + surroundings)
.build());
}
}
......
......@@ -33,6 +33,8 @@ public class DateUtil {
public final static String MM = "MM";
public final static String YYYY = "yyyy";
public final static Map<Integer, String> weekMap = new HashMap<>(7);
/**
* 返回一个ThreadLocal的sdf,每个线程只会new一次sdf
*
......@@ -326,6 +328,7 @@ public class DateUtil {
/**
* 获取多少天以后开始时间
*
* @return
*/
public static Date getAddDayStartTime(int addDay) {
......@@ -340,6 +343,7 @@ public class DateUtil {
/**
* 获取多少天以后结束时间
*
* @return
*/
public static Date getAddDayEndTime(int addDay) {
......@@ -377,20 +381,24 @@ public class DateUtil {
}
}
public static void main(String[] args) {
// System.out.println(DateUtil.isEffectiveDate(DateUtil.parse(DateUtil.format(new Date(), "HH:mm:ss"), "HH:mm:ss"), DateUtil.parse("00:00:00", "HH:mm:ss"), DateUtil.parse("16:00:00", "HH:mm:ss")));
// System.out.println(getYsdStartTime());
public static String returnWeek(Date date) {
if(weekMap.size() == 0){
weekMap.put(1, "星期日");
weekMap.put(2, "星期一");
weekMap.put(3, "星期二");
weekMap.put(4, "星期三");
weekMap.put(5, "星期四");
weekMap.put(6, "星期五");
weekMap.put(7, "星期六");
}
// System.out.println("25/06/2015".indexOf("/") > 3);
// System.out.println("2015/06/06".indexOf("/") > 3);
// System.out.println(parse("25/06/2015",DMY));
// Map<Date,Integer> map = new HashMap<>();
// map.put(getStartTime(),1);
// Integer num = map.get(getStartTime());
// System.out.println(num);
//
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return weekMap.get(calendar.get(Calendar.DAY_OF_WEEK));
}
public static void main(String[] args) {
System.out.println(returnWeek(getDateByStringYMD("2021-07-23")));
System.out.println("AD" + IdGen.randomLong(3) + String.valueOf(System.currentTimeMillis()).substring(5));
}
......@@ -423,6 +431,17 @@ public class DateUtil {
return 0;
}
public static Date getDateByStringYMD(String str) {
SimpleDateFormat sdf = new SimpleDateFormat(YMD_, Locale.ENGLISH);
Date d2 = null;
try {
d2 = sdf.parse(str);
} catch (ParseException e) {
e.printStackTrace();
}
return d2;
}
public static Date getEnlishDate(String str) {
SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy K:m:s a", Locale.ENGLISH);
Date d2 = null;
......
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