package org.linlinjava.jz.hm.job;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.linlinjava.jz.db.domain.HmEmployRelation;
import org.linlinjava.jz.db.service.hm.HmEmployRelationService;
import org.linlinjava.jz.hm.service.HmEmployTaskJobService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 定时生成盒马保姆小程序任务job
 * 每天凌晨12:00生成当日任务
 * 处理逻辑;从hm_employ_task_set 获取数据  先插入hm_employ_clock 再插入hm_employ_task
 *
 * @author fuxubing
 */
@Component
public class HmEmployTaskJob {

    private final Log logger = LogFactory.getLog(HmEmployTaskJob.class);

    @Resource
    private HmEmployRelationService hmEmployRelationService;
    @Resource
    private HmEmployTaskJobService hmEmployTaskJobService;

    @Scheduled(cron = "0 0 0 * * ?")
    public void createTask() {
        logger.info("系统开始保姆任务创建");
        //获取所有关系
        List<HmEmployRelation> hmEmployRelations = hmEmployRelationService.queryAll();
        hmEmployRelations.forEach(item -> {
            hmEmployTaskJobService.createTask(item);
        });
    }
}
