package cn.com.ctop.kuaishou.modules.label.service.impl;

import cn.com.ctop.kuaishou.modules.label.mapper.MaterialLabelMapper;
import cn.com.ctop.kuaishou.modules.label.service.MaterialTagService;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

/**
 * @Description: 素材标签
 * @Author: zzy
 * @Date: 2021-07-30
 * @Version: V1.0
 */
@Service
@Slf4j
public class MaterialTagServiceImpl implements MaterialTagService {


    @Resource
    MaterialLabelMapper materialLabelMapper;


    /**
     * 清洗各素材指标入库
     *
     * @param
     * @return
     */
    @Override
    public Result filterMaterial() {

        try {
            //查询所有素材标签
            List<String> materiaSignature = materialLabelMapper.getMateriaSignature();
            if(!materiaSignature.isEmpty()){
                materiaSignature.stream().forEach(str->{
                    if(!str.isEmpty()){
                        //获取素材产生消耗的最早日期
                        String materialFirstDate = materialLabelMapper.getMaterialFirstDate(str);
                        //获取30天之后的日期
                        String afterDate = getDateByNumber(materialFirstDate, -30);
                        //查询素材各项指标入库
                        
                    }

                });
            }
        }catch (Exception e){

        }


        return null;
    }
    /**
     * 获取指定日期number天之后之前的日期
     *
     * @param
     * @return
     */
    public String getDateByNumber(String date,int number){
        Calendar calc = Calendar.getInstance();
        SimpleDateFormat sdf  = new SimpleDateFormat("yyyy-MM-dd");
        String AfterDate=null;
        try {
            calc.setTime(sdf.parse(date));
            calc.add(calc.DATE, number);
            AfterDate=sdf.format(calc.getTime());
        }catch (Exception e){
            log.info("获取日期失败:{}",e.toString());
        }
        return AfterDate;
    }
}
