tj
2025-06-05 2d549a04870d1315868a7cf19952b64e8071e711
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.cloudroam.service.impl;
 
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cloudroam.common.enumeration.CalendarTypeEnum;
import com.cloudroam.dto.calendar.CalendarPageDTO;
import com.cloudroam.mapper.CalCalendarMapperCustom;
import com.cloudroam.model.CalCalendarDO;
import com.cloudroam.mapper.CalCalendarMapper;
import com.cloudroam.model.CalCalendarHolidayDO;
import com.cloudroam.service.CalCalendarService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
 
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author generator@TaoJie
 * @since 2024-07-25
 */
@Service
public class CalCalendarServiceImpl extends ServiceImpl<CalCalendarMapper, CalCalendarDO> implements CalCalendarService {
 
    @Autowired
    private CalCalendarMapperCustom calCalendarMapperCustom;
 
    @Override
    public void generateCalendar(int year) {
        List<CalCalendarDO> calCalendarDOList = new ArrayList<>();
        LocalDateTime startDate = LocalDateTime.of(year, 1, 1, 0, 0);
        LocalDateTime endDate = LocalDateTime.of(year, 12, 31, 23, 59);
 
 
        //删除年的数据
        QueryWrapper<CalCalendarDO> queryWrapper=new QueryWrapper();
        queryWrapper.lambda().eq(CalCalendarDO::getCalYear,year);
        baseMapper.delete(queryWrapper);
 
        for (LocalDateTime date = startDate; !date.isAfter(endDate); date = date.plusDays(1)) {
            CalCalendarDO calCalendarDO = new CalCalendarDO();
            calCalendarDO.setId(IdUtil.simpleUUID());
            calCalendarDO.setCalYear(String.valueOf(date.getYear()));
            calCalendarDO.setCalMonth(String.valueOf(date.getMonthValue()));
            calCalendarDO.setCalDay(String.valueOf(date.getDayOfMonth()));
            calCalendarDO.setCalDate(date);
            calCalendarDO.setCalWeek(String.valueOf(date.getDayOfWeek().getValue()));
            calCalendarDO.setType(CalendarTypeEnum.NONE.getCode());
            calCalendarDO.setCreateTime(new Date());
            calCalendarDO.setUpdateTime(new Date());
            calCalendarDOList.add(calCalendarDO);
 
            // 重新生成年的数据
            baseMapper.insert(calCalendarDO);
        }
 
//        repository.saveAll(events);
    }
 
    @Override
    public List<CalCalendarDO> getCalendarList(CalendarPageDTO dto) {
        QueryWrapper<CalCalendarDO> queryWrapper=new QueryWrapper<>();
        if(!StringUtils.isEmpty(dto.getCalMonth())){
            queryWrapper.lambda().eq(CalCalendarDO::getCalMonth,dto.getCalMonth());
        }
        if(!StringUtils.isEmpty(dto.getCalMonthStart())){
            queryWrapper.lambda().ge(CalCalendarDO::getCalMonth,dto.getCalMonthStart());
        }
        if(!StringUtils.isEmpty(dto.getCalMonthEnd())){
            queryWrapper.lambda().le(CalCalendarDO::getCalMonth,dto.getCalMonthEnd());
        }
        return baseMapper.selectList(queryWrapper);
    }
 
}