lidongdong
2023-08-23 f7ea824a7bd55f050a7a5e9c9742cad3bcf2f18b
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package com.panzhihua.service_community.service.impl;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panzhihua.common.model.vos.community.MostBeautifulVolunteerVO;
import com.panzhihua.common.model.vos.community.VolunteerActivityVO;
import com.panzhihua.common.utlis.StringUtils;
import com.panzhihua.service_community.dao.MostBeautifulVolunteerDao;
import com.panzhihua.service_community.dao.VolunteerActivityDao;
import com.panzhihua.service_community.entity.MostBeautifulVolunteer;
import com.panzhihua.service_community.entity.VolunteerActivity;
import com.panzhihua.service_community.service.MostBeautifulVolunteerService;
import com.panzhihua.service_community.service.VolunteerActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
 
import java.util.Date;
import java.util.List;
 
@Slf4j
@Service
public class VolunteerActivityServiceImpl extends ServiceImpl<VolunteerActivityDao,
        VolunteerActivity> implements VolunteerActivityService
{
 
    @Override
    public VolunteerActivity queryById(String Id) {
        return baseMapper.queryById(Id);
    }
 
    @Override
    public IPage<VolunteerActivity> queryList(int pageNum,int pageSize,
                                              String name,
                                              String acState,
                                              String acType,
                                              Date actityBeginTime,
                                              Date actityEndTime)
    {
        Page page = new Page<VolunteerActivity>(pageNum,pageSize);
        return baseMapper.queryList(page, name, acState, acType, actityBeginTime, actityEndTime);
    }
 
    @Override
    public int insertVolunteer(VolunteerActivityVO mostBeautifulVolunteerVO) {
        return baseMapper.insertVolunteer(mostBeautifulVolunteerVO);
    }
 
    @Override
    public int updateById(VolunteerActivityVO mostBeautifulVolunteerVO) {
        return baseMapper.updateById(mostBeautifulVolunteerVO);
    }
 
    @Override
    public int deleteById(String Id) {
        return baseMapper.deleteById(Id);
    }
 
 
    /**
     * 定时任务
     * @return
     */
    @Override
    public int timedTaskVolunteerActivitiesJobHandler()
    {
        List<VolunteerActivity> list = baseMapper.timedTaskList();
        Long newTiem=System.currentTimeMillis();
        if(list.size()>0)
        {
            for (VolunteerActivity itemDate:list)
            {
                String state = itemDate.getAcState();
                //2未开始  3报名中", 4进行中"
                //活动报名开始时间
                Long applyBegintime = itemDate.getApplyBeginTime().getTime();
                //活动报名结束时间
                Long applyEndtime = itemDate.getApplyEndTime().getTime();
 
                //活动开始时间
                Long actityBegintime = itemDate.getActityBeginTime().getTime();
                //活动结束时间
                Long actityEndtime = itemDate.getActityEndTime().getTime();
 
                //判断是否在报名中
                if (newTiem >= applyBegintime && newTiem < applyEndtime)
                {
                    state = "3";
                }
                else if (newTiem>applyEndtime)
                {
                    //报名如果截止  报名人数为0   结束活动
                    Integer num=0;
                    if(!StringUtils.isEmpty(itemDate.getVolunteerNum()))
                    {
                        num=Integer.valueOf(itemDate.getVolunteerNum());
                    }
                    if(num<=0)
                    {
                        state = "6";
                    }
                }
                else if (newTiem >= actityBegintime && newTiem <= actityEndtime)
                {
                    //判断是否活动进行中
                    state = "4";
                }
                else if(newTiem>actityEndtime)
                {
                    //活动结束
                    state = "5";
                }
 
                if(!StringUtils.equals(state,itemDate.getAcState()))
                {
                    itemDate.setAcState(state);
                    baseMapper.updateById(itemDate);
                }
            }
        }
        return 1;
    }
}