package weaver.interfaces.htsc.payment.common;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.engine.htsc.meeting.util.Common;
import com.engine.htsc.payment.log.PaymentLogger;
import com.engine.htsc.payment.log.PaymentLoggerFactory;
import com.engine.htsc.payment.util.AssertUtil;
import com.engine.htsc.payment.util.CommonAPI;
import com.engine.htsc.payment.util.PayUtil;
import weaver.conn.RecordSet;
import weaver.general.GCONST;
import weaver.interfaces.htsc.cus.HTUtil;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;
import weaver.workflow.request.RequestManager;

import java.util.*;
import java.util.stream.Collectors;

public class GalaxyToMode implements Action {

    private static final PaymentLogger logger = PaymentLoggerFactory.getLogger(GalaxyToMode.class);
    private final HTUtil htUtil = new HTUtil();


    @Override
    public String execute(RequestInfo requestInfo) {

        try {
            String requestid = requestInfo.getRequestid();
            RequestManager rm = requestInfo.getRequestManager();
            String tableName = rm.getBillTableName();
            String sql = "select t1.workflowid,t3.lcbh as requestmark ,t2.workcode from workflow_requestbase t1\n" +
                    "left join hrmresource t2 " +
                    "on t1.creater = t2.id " +
                    "left join " + tableName + " t3 " +
                    "on t1.requestid = t3.requestid " +
                    "where t1.requestid =?";
            Map<String, String> paramsProtoType = CommonAPI.querySingleRow(sql, requestid);
            String lcbh = paramsProtoType.get("requestmark");
            logger.info("开始插入 UF_SYNCGALAXY 建模表"+"requestid:"+requestid+"lcbh:"+lcbh);
            RecordSet toMode = new RecordSet();
            sql = "INSERT INTO UF_SYNCGALAXY(requestid,lcbh) values("+requestid+",'"+lcbh+"') ";
            toMode.executeUpdate(sql);
            return SUCCESS;
        } catch (Exception e) {
            logger.error(String.format("网报流程办结后写入UF_SYNCGALAXY出错 requestid: %s", requestInfo.getRequestid()),e);
            return SUCCESS;
        }
    }


}
