package com.engine.attendance.workflow.cmd;

import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.common.util.DbTools;
import com.engine.core.interceptor.CommandContext;
import lombok.extern.slf4j.Slf4j;
import weaver.general.Util;
import weaver.hrm.User;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
public class GetAskForLeaveRecordListCmd extends AbstractCommonCommand<Map<String, Object>> {

    public GetAskForLeaveRecordListCmd(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> retmap = new HashMap<String, Object>();
        //获取主表id列表
        String targetUserId = Util.null2String(params.get("targetUserId"));
        String businessTripsType = Util.null2String(params.get("businessTripsType"));
        String startDate = Util.null2String(params.get("startDate"));
        String endDate = Util.null2String(params.get("endDate"));
        log.info("targetUserId : {}, businessTripsType : {}, startDate : {}, endDate : {}", targetUserId, businessTripsType, startDate, endDate);

        String detailSql = "select a.id,a.cxqj,a.ksrq,a.kssj,a.jsrq,a.jssj,a.qjsc,a.qtj,a.btj,a.cxsm from uf_jcl_kq_qjjl_dt1 a left join uf_jcl_kq_qjjl b on a.mainid=b.id where (a.cxqj is null or a.cxqj<>1) and b.qjry =? and a.ksrq >= ? and a.ksrq <= ? and b.jqlx=?";
        List<Map<String, Object>> detailList = DbTools.getSqlToList(detailSql,targetUserId,startDate,endDate,businessTripsType);
        if (detailList.size() > 0) {
            retmap.put("result", detailList);
        } else {
            retmap.put("result", null);
        }
        log.info("detailList : [{}]", detailList);

        return retmap;
    }
}
