package com.weaver.seconddev.chapanda.dmp.esb;

import com.weaver.common.base.entity.result.WeaResult;
import com.weaver.esb.api.rpc.EsbServerlessRpcRemoteInterface;
import com.weaver.seconddev.chapanda.dmp.util.Esb2DmpGetGmvUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("Esb2DmpGetGmvCron")
public class Esb2DmpGetGmvCron implements EsbServerlessRpcRemoteInterface {
    private final static Logger log = LoggerFactory.getLogger(Esb2DmpGetGmvCron.class);
    @Autowired
    Esb2DmpGetGmvUtil esb2DmpGetGmvUtil;

    @Override
    public WeaResult<Map<String, Object>> execute(Map<String, Object> params) {
        log.error("Esb2DmpGetGmvCron start");
        String type = String.valueOf(params.get("type"));
        String startDate = "";
        String endDate = "";
        String year = String.valueOf(params.get("year"));
        if("1".equals(type)){
            startDate = year+"-01-01";
            endDate = year+"-12-31";
        }else{
            startDate = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()).toString();
            endDate = LocalDate.now().toString();
        }
        List<String> ebList = esb2DmpGetGmvUtil.queryGmvList(startDate,endDate);
        log.error("ebList:{}",ebList.size());

        Map<String, Object> actionMap = new HashMap<String, Object>();
        actionMap.put("code",200);
        actionMap.put("msg","Esb2DmpGetGmvCron");

        return WeaResult.success(actionMap);
    }

}
