add: 周年纪念日
This commit is contained in:
@@ -2,10 +2,45 @@ package com.dota.nexus.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.dota.nexus.entity.Anniversary;
|
||||
import com.dota.nexus.entity.AnniversaryEnum;
|
||||
import com.dota.nexus.entity.vo.AnniversaryRecord;
|
||||
import com.dota.nexus.entity.vo.AnniversaryVO;
|
||||
import com.dota.nexus.mapper.AnniversaryMapper;
|
||||
import com.dota.nexus.service.AnniversaryService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Service
|
||||
public class AnniversaryServiceImpl extends ServiceImpl<AnniversaryMapper, Anniversary> implements AnniversaryService {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public AnniversaryVO getAll() {
|
||||
var aList = new ArrayList<AnniversaryRecord>();
|
||||
var bList = new ArrayList<AnniversaryRecord>();
|
||||
var res = new AnniversaryVO(aList, bList);
|
||||
var anniversaries = this.baseMapper.selectList(null);
|
||||
var now = LocalDate.now();
|
||||
for (Anniversary anniversary : anniversaries) {
|
||||
// 周年,变成今年或者明年
|
||||
if (anniversary.getType() == AnniversaryEnum.ANNIVERSARY) {
|
||||
LocalDate date = anniversary.getDate();
|
||||
date = date.withYear(now.getYear());
|
||||
if (date.isBefore(now)) {
|
||||
date = date.withYear(now.getYear() + 1);
|
||||
}
|
||||
|
||||
aList.add(new AnniversaryRecord(anniversary.getName(), date.toString(), (int) ChronoUnit.DAYS.between(date, now)));
|
||||
} else if (anniversary.getType() == AnniversaryEnum.COMMEMORATION) {
|
||||
bList.add(new AnniversaryRecord(anniversary.getName(), anniversary.getDate().toString(), (int) ChronoUnit.DAYS.between(now, anniversary.getDate())));
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user