package com.engine.htsc.portal.cmd;

import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.htsc.portal.util.QueryTools;
import com.engine.htsc.response.enums.ResultEnum;
import com.engine.htsc.response.exception.ResultException;
import com.weaver.general.Util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import weaver.hrm.User;

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

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

    private Log log = LogFactory.getLog(this.getClass());

    public PortalTransactionCmd(){}
    public PortalTransactionCmd(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 {
            if (user == null) {
                throw new ResultException(ResultEnum.DEPT_EXIST_USER);
            }
            int userid = user.getUID();
            String condition = Util.null2String((String) params.get("condition"));

            //1.由我执行
            int perform = QueryTools.getPerformCount(userid,condition);

            //2.我参与的
            int participate = QueryTools.getParticipateCount(userid, condition);

            //3.我创建的
            int create = QueryTools.getCreateCount(userid, condition);

            //4.已完成
            int all = QueryTools.getAllCount(userid, condition);

            datas.put("perform",perform);
            datas.put("participate",participate);
            datas.put("create",create);
            datas.put("all",all);

        }catch (Exception e){
            e.printStackTrace();
        }
        return datas;
    }
}
