package vip.xiaonuo.Timer;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import vip.xiaonuo.common.timer.CommonTimerTaskRunner;
import vip.xiaonuo.sys.modular.org.entity.SysOrg;
import vip.xiaonuo.sys.modular.org.mapper.SysOrgMapper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


@Slf4j
@Component
//@Configuration
//@EnableScheduling
public class SendOrgId implements CommonTimerTaskRunner {

    @Autowired
    private SysOrgMapper orgMapper;

    @Override
//    @Scheduled(cron = "0 0/1 * * * ? ")
    public void action() {
        List<SysOrg> sysOrgs = orgMapper.selectList(new QueryWrapper<SysOrg>()
                .eq("DELETE_FLAG", "NOT_DELETE").eq("CATEGORY","PASTURE"));
        List<OrgIdVo> list = new ArrayList<>();
        for (SysOrg sysOrg : sysOrgs) {
            OrgIdVo orgIdVo = new OrgIdVo();
            orgIdVo.setFarmId(sysOrg.getId());
            orgIdVo.setName(sysOrg.getName());
            list.add(orgIdVo);
        }
        String url = "https://nk.ifarmcloud.com/secureApi/base-farm/getFarm";
        HashMap<String, String> paramsMap = new HashMap<>();
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("list", list);
        paramsMap.put("Content-Type", "application/json;charset=utf-8");
        String post = HttpRequest.post(url)
                .headerMap(paramsMap, false).body(jsonObject1.toJSONString()).timeout(30 * 1000).execute().body();
        System.out.println(post);
    }
}
