mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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.VolunteerActivityVO;
import com.panzhihua.common.utlis.StringUtils;
import com.panzhihua.service_community.dao.VolunteerActivityDao;
import com.panzhihua.service_community.entity.VolunteerActivity;
import com.panzhihua.service_community.service.VolunteerActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
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,String userId) {
        return baseMapper.queryById(Id,userId);
    }
 
    @Override
    public IPage<VolunteerActivity> queryList(int pageNum,int pageSize,
                                              String name,
                                              String acState,
                                              String acType,
                                              String userId,
                                              Date actityBeginTime,
                                              Date actityEndTime)
    {
        Page page = new Page<VolunteerActivity>(pageNum,pageSize);
        return baseMapper.queryList(page, name, acState, acType, userId, actityBeginTime, actityEndTime);
    }
 
    @Override
    public int insertVolunteer(VolunteerActivityVO mostBeautifulVolunteerVO)
    {
        Long applyBegintime = mostBeautifulVolunteerVO.getApplyBeginTime().getTime();
        //活动报名结束时间
        Long applyEndtime = mostBeautifulVolunteerVO.getApplyEndTime().getTime();
 
        //活动开始时间
        Long actityBegintime = mostBeautifulVolunteerVO.getActityBeginTime().getTime();
        //活动结束时间
        Long actityEndtime = mostBeautifulVolunteerVO.getActityEndTime().getTime();
 
        Long newTiem=System.currentTimeMillis();
 
        //判断是否在报名中
        if (newTiem >= applyBegintime && newTiem < applyEndtime)
        {
            mostBeautifulVolunteerVO.setAcState("3");
        }
        else if (newTiem>applyEndtime  && newTiem <actityBegintime )
        {
             mostBeautifulVolunteerVO.setAcState("4");
        }
        else if (newTiem >= actityBegintime && newTiem <= actityEndtime)
        {
            //判断是否活动进行中
            mostBeautifulVolunteerVO.setAcState("4");
        }
        else if(newTiem>actityEndtime)
        {
            //活动结束
            mostBeautifulVolunteerVO.setAcState("5");
        }
 
        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  && newTiem <actityBegintime )
                {
                    //报名如果截止  报名人数为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);
 
                    VolunteerActivityVO comActDynVO = new VolunteerActivityVO();
                    comActDynVO.setId(itemDate.getId());
                    BeanUtils.copyProperties(itemDate, comActDynVO);
                    baseMapper.updateById(comActDynVO);
                }
            }
        }
        return 1;
    }
}