package com.srs.quartz.task;

import com.srs.common.utils.spring.SpringUtils;
import com.srs.staff.domain.SrsStaffOneStopCommunityActivities;
import com.srs.staff.mapper.SrsStaffOneStopCommunityActivitiesMapper;
import com.srs.staff.service.ISrsStaffOneStopCommunityActivitiesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component("ActivityStatusUpdater")
public class ActivityStatusUpdater {

//    @Autowired
//    ISrsStaffOneStopCommunityActivitiesService service;

    public void updateActivityStatus() {
        ISrsStaffOneStopCommunityActivitiesService service = SpringUtils.getBean(ISrsStaffOneStopCommunityActivitiesService.class);
        List<SrsStaffOneStopCommunityActivities> activities = service.selectSrsStaffOneStopCommunityActivitiesList(new SrsStaffOneStopCommunityActivities());
        Date now = new Date();

        for (SrsStaffOneStopCommunityActivities activity : activities) {
            if (activity.getSignUpStartTime() != null && activity.getSignUpEndTime() != null &&
                    now.after(activity.getSignUpEndTime()) && activity.getActivityStatus() == 1) {
                // 报名结束，状态变更为进行中
                activity.setActivityStatus(0l);
            }
            if (activity.getActivityStartTime() != null && activity.getActivityEndTime() != null &&
                    now.after(activity.getActivityEndTime()) && activity.getActivityStatus() == 0) {
                // 活动结束，状态变更为结束
                activity.setActivityStatus(2l);
            }
            service.updateSrsStaffOneStopCommunityActivities(activity);
        }
    }
}

