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

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

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

@Component
public class HrmPerformanceDao {

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

    @Autowired
    private DatabaseUtils databaseUtils;

    /**
     *
     * @return
     */
    public String getAssessmentData(String khnf,String khzq,String jxhdid,String bkhr){
        String groupId = "weaver-ebuilder-form-service";
        String sourceType = "LOGIC";
        String id = "";
        try{
            String dataSql =" select id from uf_jxsjtz " +
                            " where khnf = ? " +
                            " and khzq = ? " +
                            " and jxhdid = ? " +
                            " and bkhr = ? " +
                            " and tenant_key=? \n" +
                            " and delete_type=0" ;

            log.error("dataSql:" + dataSql);
            List<String> paramList = new ArrayList<>(100);
            paramList.add(khnf);
            paramList.add(khzq);
            paramList.add(jxhdid);
            paramList.add(bkhr);
            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){
                id = String.valueOf(recordList.get(0).get("id"));
            }
        }catch (Exception e){
            log.error("e:{}" , e);
        }
        return id;
    }

    public Map<String, Object> queryEmployeeAssessmentOtherInfo(String employeeid){
        String groupId = "weaver-ebuilder-form-service";
        String sourceType = "LOGIC";
        Map<String, Object> employeeMap = new HashMap<String, Object>();
        try{

            String dataSql =" select hiredate as rzrq,zhgzr as lzrq,zzrq,personnel_status as ryzt,subcompany as gs,yjbm as bm1,ejbm as bm2,sanjbm as bm3,sijbm as bm4,rylb,location as gzdd" +
                            " from uf_jcl_employee_information \n" +
                            " where glzzyg = ? " +
                            " and tenant_key = ?  \n" +
                            " and delete_type = 0 " ;

            log.error("dataSql:{}" , dataSql);
            List<String> paramList = new ArrayList<>(100);
            paramList.add(employeeid);
            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){
                employeeMap = recordList.get(0);
            }
        }catch (Exception e){
            log.error("e:{}", e);
        }
        return employeeMap;
    }




}
