package weaver.interfaces.htsc.gwlc;

import cn.hutool.core.date.DateUtil;
import com.sap.db.jdbc.Hash;
import oracle.sql.JAVA_STRUCT;
import org.apache.commons.lang.StringUtils;
import weaver.general.Util;
import weaver.interfaces.htsc.GlobatTools.JAVATools;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author xf
 * @version 1.0.0
 * @ClassName GwfirstnumberAction.java
 * @createTime 2022年01月05日 13:52:00
 */
public class GwfirstnumberAction implements Action {

    @Override
    public String execute(RequestInfo requestInfo) {
        String requestid= Util.null2String(requestInfo.getRequestid());
        if("".equals(requestid)){
            JAVATools.SetCmdwritelog("流程修改排版的requestid获取失败"+requestid);
            return Action.SUCCESS;
        }
        String tablename=JAVATools.getMaintable(requestid);
        String unnumber=JAVATools.getmainunnumber(requestid);
        if("".equals(tablename)){
            JAVATools.SetCmdwritelog("流程修改排版的表明获取获取失败"+requestid);
            return Action.SUCCESS;
        }
        String pbrq= DateUtil.format(new Date(),"yyyy-MM-dd");
        Map<String,String> wheremap=new HashMap<>(1);
        wheremap.put("requestid",requestid);
        Map<String,String> setmap=new HashMap<>(1);
        setmap.put("pbrq",pbrq);
        boolean flag=JAVATools.Updatesql(setmap,tablename,wheremap);
        if(flag){
            JAVATools.SetCmdwritelog("流程修改排版的档期日期成功"+requestid);
        }else{
            JAVATools.SetCmdwritelog("流程修改排版的档期日期失败"+requestid);
        }

        String gsfwunnumber="gsfw";
        if(gsfwunnumber.equals(unnumber)){
            gsfwReload(requestid,tablename);
        }
        return Action.SUCCESS;
    }

    private void gsfwReload(String requestid,String tablename){
        Map<String,Object> tablemap=JAVATools.gettablevalue(requestid);
        if(tablemap==null || tablemap.size()<=0){
            return ;
        }
        String qfrq=Util.null2String(tablemap.get("qfrq"));
        if(StringUtils.isBlank(qfrq)){
            String pbrq= DateUtil.format(new Date(),"yyyy-MM-dd");
            Map<String,String> wheremap=new HashMap<>(1);
            wheremap.put("requestid",requestid);
            Map<String,String> setmap=new HashMap<>(1);
            setmap.put("qfrq",pbrq);
            boolean flag=JAVATools.Updatesql(setmap,tablename,wheremap);

            if(flag){
                JAVATools.SetCmdwritelog("流程修改公司印发日期成功"+requestid);
            }else{
                JAVATools.SetCmdwritelog("流程修改公司印发日期失败"+requestid);
            }
        }

    }
}
