package com.mzl.flower.service.impl;
|
|
import cn.hutool.core.util.IdUtil;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.mzl.flower.entity.CalendarDO;
|
import com.mzl.flower.mapper.CalendarMapper;
|
import com.mzl.flower.service.calendar.CalendarService;
|
import org.springframework.stereotype.Service;
|
|
import java.time.LocalDateTime;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* <p>
|
* 服务实现类
|
* </p>
|
*
|
* @author @TaoJie
|
* @since 2024-09-12
|
*/
|
@Service
|
public class CalendarServiceImpl extends ServiceImpl<CalendarMapper, CalendarDO> implements CalendarService {
|
|
@Override
|
public void generateCalendar(int year) {
|
List<CalendarDO> CalendarDOList = new ArrayList<>();
|
LocalDateTime startDate = LocalDateTime.of(year, 1, 1, 0, 0);
|
LocalDateTime endDate = LocalDateTime.of(year, 12, 31, 23, 59);
|
|
|
//删除年的数据
|
QueryWrapper<CalendarDO> queryWrapper=new QueryWrapper();
|
queryWrapper.lambda().eq(CalendarDO::getCalYear,year);
|
baseMapper.delete(queryWrapper);
|
|
for (LocalDateTime date = startDate; !date.isAfter(endDate); date = date.plusDays(1)) {
|
CalendarDO CalendarDO = new CalendarDO();
|
CalendarDO.setId(IdUtil.simpleUUID());
|
CalendarDO.setCalYear(String.valueOf(date.getYear()));
|
CalendarDO.setCalMonth(String.valueOf(date.getMonthValue()));
|
CalendarDO.setCalDay(String.valueOf(date.getDayOfMonth()));
|
CalendarDO.setCalDate(date);
|
CalendarDO.setCalWeek(String.valueOf(date.getDayOfWeek().getValue()));
|
CalendarDO.setType(0);
|
CalendarDO.setCreateTime(LocalDateTime.now());
|
CalendarDO.setUpdateTime(LocalDateTime.now());
|
CalendarDOList.add(CalendarDO);
|
|
// 重新生成年的数据
|
baseMapper.insert(CalendarDO);
|
}
|
|
}
|
}
|