package com.palmnest.webapp.quartz;

import com.palmnest.model.estateserve.ServiceProjectAllocation;
import com.palmnest.service.estateserve.ServiceProjectAllocationManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

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

/**
 * @Author HXT
 * @Description 更新项目服务到期状态
 * @Date 2018/9/27 15:58
 **/
@Slf4j
@Controller
@RequestMapping("/updateServiceProjectExpire/*")
@Component("updateServiceProjectExpireTask")
public class UpdateServiceProjectExpireTask {


	@Autowired
	private ServiceProjectAllocationManager serviceProjectAllocationManager;

	public void run() {

		List<ServiceProjectAllocation> list = serviceProjectAllocationManager.listAll();

		if (null != list && list.size() > 0) {

			for (ServiceProjectAllocation allocation : list) {
				//获取当前系统时间
				Date currentDate = new Date();
				//该服务过期时间
				Date expireDate = allocation.getIndate();
				if (expireDate != null && expireDate.before(currentDate)) {
					allocation.setStatus("0");//过期设置下线
					allocation.setIndate(null);//将过期时间置为null
					serviceProjectAllocationManager.updateModel(allocation);
				}
			}
		}
	}
}
