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;
|
}
|
}
|