package weaver.interfaces.htsc.tgpt;

import com.alibaba.fastjson.JSONObject;
import com.engine.htsc.tgpt.service.impl.TgptServiceImpl;
import org.apache.commons.lang.StringUtils;
import weaver.conn.RecordSet;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.BaseBean;
import weaver.interfaces.htsc.GlobatTools.JAVATools;
import weaver.interfaces.htsc.comInfo.PropBean;
import weaver.interfaces.htsc.util.HttpRequestUtil;
import weaver.interfaces.schedule.BaseCronJob;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
 * @Title: ecology-9
 * @Company: 泛微软件
 * @author: K1810039
 * @version: 1.0
 * @CreateDate: 2022-08-19
 * @Description: 这是一个扫描 删除日程 的定时任务
 * @ModifyLog:
 **/
public class DeleteRcCorn extends BaseCronJob {
    @Override
    public void execute() {
        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();
        bb.writeLog("----DeleteRcCorn----");
        List<String> rcidList = new ArrayList<>();
        String sql = "";
        sql = "select RCID from uf_deleteRcfzb where SCZT = '0'";
        bb.writeLog(sql);
        rs.execute(sql);
        while (rs.next()){
            rcidList.add(rs.getString("RCID"));
        }
        bb.writeLog("rcidList:"+rcidList);
        // 根据rcid删除日程
        del(rcidList);

    }

    /**
     * 远程删除日程
     */
    public void del(List<String> rcidList){
        PropBean pb = new PropBean();
        String tgpt_del_url = pb.getPropName("tgpt_del_url");
        TgptServiceImpl tgptService = new TgptServiceImpl();
        RecordSet rs = new RecordSet();
        RecordSet rs2 = new RecordSet();
        String appToken = tgptService.getAppToken();
        HashMap<String,String> header = new HashMap<>();
        header.put("JTXT-AUTH-TOKEN",appToken);
        header.put("JTXT-AUTH-TYPE","APP");

        for (String rcid : rcidList) {
            // 2.调接口，执行删除
            String res = tgptService.httpPostRaw(tgpt_del_url + "/" + rcid, "", header, null);
            JAVATools.writelog("delRc--res:"+res);
            // 3.删除成功 则更改删除状态为 1（已删除）,删除失败不做操作
            if ("true".equals(res)){
                String updateSql = "update uf_deleteRcfzb set SCZT = '0' where RCID = '"+rcid+"'";
                JAVATools.writelog(updateSql);
                rs2.execute(updateSql);
            }
        }

    }

}