package com.engine.htsc.workflow.cmd;

import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.google.common.collect.Lists;

import com.weaver.general.Util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSet;
import weaver.hrm.User;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class WorkflowShelveCmd extends AbstractCommonCommand<Map<String, Object>> {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    public WorkflowShelveCmd(){}
    public WorkflowShelveCmd(Map<String,Object> params, User user) {
        this.user = user;
        this.params = params;
    }

    @Override
    public BizLogContext getLogContext() {
        return null;
    }

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
        Map<String,Object> datas = new HashMap<>();
        try {
            RecordSet rs = new RecordSet();
            String requestid = (String) params.get("requestid");
            String userid = (String) params.get("userid");
            rs.executeQuery("select receivedate,receivetime from workflow_currentoperator where\n" +
                    "requestid = ? and userid = ? order by receivedate desc",requestid,userid);
            if (rs.next()){
                String receivedate = Util.null2String(rs.getString("receivedate"));
                Date date = new SimpleDateFormat("yyyy-MM-dd").parse(receivedate);
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(date);
                calendar.add(Calendar.DATE,30);
                Date endDate = calendar.getTime();
                String endDateValue = new SimpleDateFormat("yyyy-MM-dd").format(endDate);
                datas.put("endDateValue",endDateValue);
            }

        }catch (Exception e){
            logger.error("errorMessage:{}", e.getMessage(), e);
        }
        return datas;
    }
}
