package com.weaver.seconddev.chapanda.beisen.dao;

import com.weaver.ebuilder.datasource.api.entity.SqlParamEntity;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.weaver.seconddev.chapanda.beisen.constant.Constants;
import com.weaver.seconddev.chapanda.beisen.util.DatabaseUtils;
import java.util.*;


/***
 * 离职年假转换  POC开发的
 */
@Component
public class ConversionResignDao {

    private final static Logger log = LoggerFactory.getLogger(ConversionResignDao.class);

    @Autowired
    private DatabaseUtils databaseUtils;


    /***
     *
     * @return
     */
    public String queryEmployeeById(String employeeId){
        String groupId = "weaver-ebuilder-form-service";
        String sourceType = "LOGIC";
        String hiredate = "";
        try{
            String dataSql =" select hiredate " +
                            " from eteams.employee  " +
                            " where id = '"+employeeId+"' \n" +
                            " and delete_type = 0 \n" +
                            " and tenant_key = '"+Constants.TENANT_KEY+"'  " ;

            log.error("dataSql:" + dataSql);
            List<String> paramList = new ArrayList<>(100);
            List<SqlParamEntity> sqlParamList = databaseUtils.querySqlParamEntity(paramList);
            Map<String, Object> result = databaseUtils.executeForQuery(sourceType, groupId, dataSql, sqlParamList);
            List<Map<String, Object>> recordList = databaseUtils.getDataSourceList(result);
            log.error("recordList:"+recordList.size());
            if(recordList.size()>0){
                Map<String,Object> recordMap = recordList.get(0);
                hiredate = String.valueOf(recordMap.get("hiredate"));
            }
        }catch (Exception e){
            e.printStackTrace();
            log.error("e:" + e);
        }
        return hiredate;
    }


    /***
     *
     * @param employeeid
     * @param lznf
     * @return
     */
    public Double queryEmployeeAnnualLeave(String employeeid,String lznf){
        String groupId = "weaver-salary-report";
        String sourceType = "LOGIC";
        Double annualBase = 0.0;
        try{
            String dataSql =" select base " +
                            " from attend_vacation_info_v2 " +
                            " where employee = ? \n" +
                            " and year = ? " +
                            " and tenant_key= ?\n" +
                            " and DELETE_TYPE = 0" ;

            log.error("dataSql:" + dataSql);
            List<String> paramList = new ArrayList<>(100);

            paramList.add(employeeid);
            paramList.add(lznf);
            paramList.add(Constants.TENANT_KEY);

            List<SqlParamEntity> sqlParamList = databaseUtils.querySqlParamEntity(paramList);
            Map<String, Object> result = databaseUtils.executeForQuery(sourceType, groupId, dataSql, sqlParamList);
            List<Map<String, Object>> recordList = databaseUtils.getDataSourceList(result);
            log.error("recordList:"+recordList.size());
            if(recordList.size()>0){
                Map<String,Object> recordMap = recordList.get(0);
                String base = String.valueOf(recordMap.get("base"));
                if(StringUtils.isNotBlank(base)){
                    annualBase = Double.valueOf(base);
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            annualBase  = 0.0 ;
            log.error("e:" + e);
        }
        return annualBase;
    }

}
