package com.engine.custom.archives.action;

import weaver.conn.RecordSet;
import weaver.file.Prop;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 添加流程到推送记录
 */
public class AddArchivesRecordAction extends BaseBean implements Action {
    String SQL = "insert into uf_pushArchivesLog (request,type,ddsj) values (?,?,?) ";

    @Override
    public String execute(RequestInfo requestInfo) {
        String requestid = requestInfo.getRequestid();
        String workflowid = requestInfo.getWorkflowid();
        String reveive = Util.null2String(Prop.getPropValue("archives", "reveive"));
        String send = Util.null2String(Prop.getPropValue("archives", "send"));
        String SignOff = Util.null2String(Prop.getPropValue("archives", "SignOff"));
        //痩文
        List<String> reveiveArr = Arrays.asList( reveive.split(","));
        //发文
        List<String> sendArr = Arrays.asList(send.split(","));
        //签报
        List<String> SignOffArr = Arrays.asList(SignOff.split(","));
        String type = "";
        if (sendArr.contains(workflowid)){
            type = "0";
        }else if(reveiveArr.contains(workflowid)){
            type = "1";
        }else if(SignOffArr.contains(workflowid)){
            type = "2";
        }else {
            //不匹配跳过insert
            return Action.SUCCESS;
        }
        RecordSet recordSet = new RecordSet();
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String dateStr = format.format(date);
        recordSet.executeUpdate(SQL,requestid,type,dateStr);
        return null;
    }


    public static void main(String[] args) {



    }
}
