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

import com.alibaba.fastjson.JSONArray;
import com.weaver.common.base.entity.result.WeaResult;
import com.weaver.esb.api.rpc.EsbServerlessRpcRemoteInterface;
import com.weaver.seconddev.chapanda.beisen.util.Offer2BeiSenUtil;
import com.weaver.seconddev.chapanda.beisen.util.Token2BeiSenUtil;
import org.apache.commons.lang3.StringUtils;
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.util.HashMap;
import java.util.Map;

/***
 *  废弃，由雪峰重写了
 */
@Service("Esb2BeisenOfferCronJob")
public class Esb2BeisenOfferCronJob implements EsbServerlessRpcRemoteInterface {
    private final static Logger log = LoggerFactory.getLogger(Esb2BeisenOfferCronJob.class);

    @Autowired
    Token2BeiSenUtil token2BeiSenUtil ;

    @Autowired
    Offer2BeiSenUtil offer2BeiSenUtil;

    @Override
    public WeaResult<Map<String, Object>> execute(Map<String, Object> params) {

        log.error("EsbTrainingCronJobAction start");

//        String beishenHost = "https://openapi.italent.cn";
//        String offerUrl = "/TenantBaseExternal/api/v5/Offer/GetByTimeWindow";
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");

        JSONArray offerArray = new JSONArray();
//        LocalDate today = LocalDate.now();
//        LocalDate yesterday = today.minusDays(1);
//        String startDate = yesterday.toString();
//        String startTime = sdf.format(new Date());
//        String endDate = today.toString();
//        String endTime = sdf.format(new Date());

        String startDate = String.valueOf(params.get("startDate"));
        String startTime = String.valueOf(params.get("startTime"));
        String endDate = String.valueOf(params.get("endDate"));
        String endTime = String.valueOf(params.get("endTime"));

        String token = token2BeiSenUtil.getToken();
        log.error("token:{}",token);

        if(StringUtils.isNotBlank(token)){
            offerArray = offer2BeiSenUtil.queryOfferByDateTime(token,startDate, startTime, endDate, endTime);
        }

        log.error("offerArray:{}",offerArray.toJSONString());

        Map<String, Object> actionMap = new HashMap<String, Object>();
        actionMap.put("code",200);
        actionMap.put("msg","Esb2BeisenOfferCronJob");
        actionMap.put("offer",offerArray);
        return WeaResult.success(actionMap);
    }

    public static void main(String[] args) {

    }


}
