package com.engine.kq.wfset.action;

import com.engine.kq.biz.KQAttProcSetComInfo;
import com.engine.kq.enums.KqSplitFlowTypeEnum;
import com.engine.kq.log.KQLog;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

/**
 * 兼容E8的请假释放action
 */
public class KqReleaseVacationAction extends BaseBean implements Action {
  private KQLog kqLog = new KQLog();

  @Override
  public String execute(RequestInfo request) {
    //e8 的状态标识
    int RELEASE = 2;
    this.writeLog("KqReleaseVacationAction", "do action on request:" + request.getRequestid());
    String requestid = request.getRequestid();
    kqLog.info("do KqReleaseVacationAction on requestid:"+requestid);
    int requestidInt = Util.getIntValue(requestid, 0);
    String workflowid = request.getWorkflowid();
    KQAttProcSetComInfo kqAttProcSetComInfo = new KQAttProcSetComInfo();
    int cur_kqtype = Util.getIntValue(kqAttProcSetComInfo.getkqType(workflowid),-1);

    if(cur_kqtype != KqSplitFlowTypeEnum.LEAVE.getFlowtype()){
      return Action.SUCCESS;
    }

    try {

      RecordSet rs = new RecordSet();
      String updateFreezeSql = "update KQ_ATT_VACATION set status=2 where requestId=? and workflowId = ? ";
      boolean isUpdate = rs.executeUpdate(updateFreezeSql,requestidInt,workflowid);
      if(!isUpdate){
        request.getRequestManager().setMessageid("666" + request.getRequestid() + "999");
        request.getRequestManager().setMessagecontent(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(82824,weaver.general.ThreadVarLanguage.getLang())+"action"+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005361,weaver.general.ThreadVarLanguage.getLang())+"("+RELEASE+","+requestid+","+workflowid+")");
        return Action.FAILURE_AND_CONTINUE;
      }

    } catch (Exception e) {
      writeLog(e);
      request.getRequestManager().setMessageid("11111" + request.getRequestid() + "22222");
      request.getRequestManager().setMessagecontent("请假流程【释放action】报错，请联系管理员！");
      return Action.FAILURE_AND_CONTINUE;
    }

    return Action.SUCCESS;

  }

}
