package cn.com.victorysoft.business.calc.service;

import cn.com.victorysoft.business.calc.dao.AdjustDataSyncDao;
import cn.com.victorysoft.business.calc.dao.FlushDataSyncDao;
import cn.com.victorysoft.business.condition.service.AdjustPlanService;
import cn.com.victorysoft.business.util.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * 测调数据同步服务
 */
@Slf4j
@Service
public class AdjustDataSyncService {

    @Resource
    private AdjustDataSyncDao adjustDataSyncDao;
    @Resource
    private AdjustPlanService adjustPlanService;

    /**
     * 生成测调计划数据
     */
    @Transactional
    public void generateAdjustPlan(Date date) {
        String month = DateUtils.format(DateUtils.addMonths(date, 1), "yyyyMM");
        adjustPlanService.deleteByMonth(month);
        adjustDataSyncDao.generateAdjustPlan(date);
    }

    /**
     * 每天更新测调完成数据
     */
    public void finishAdjustPlan() {
        adjustDataSyncDao.finishAdjustPlan();
    }
}
