package weaver.interfaces.htsc.clwhsq;

import weaver.conn.RecordSet;
import weaver.formmode.customjavacode.AbstractCustomSqlConditionJavaCode;
import weaver.general.BaseBean;
import weaver.hrm.User;

import java.util.Map;

public class ModeSzjgSearchTemplete extends AbstractCustomSqlConditionJavaCode {

    /**
     * 生成SQL查询限制条件
     * @param param
     *  param包含(但不限于)以下数据
     *  user 当前用户
     *
     * @return
     *  返回的查询限制条件的格式举例为: t1.a = '1' and t1.b = '3' and t1.c like '%22%'
     *  其中t1为表单主表表名的别名
     */
    public String generateSqlCondition(Map<String, Object> param) throws Exception {
        User user = (User)param.get("user");
        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();
        int userid = user.getUID();
        int deptId = user.getUserDepartment();
        bb.writeLog("车辆维护申请领导部门查询人员部门id" + deptId);

        String sqlCondition = "";
        //select * from HRMDEPARTMENT WHERE ID = 492 // supdepid
        String sql = "select * from HRMDEPARTMENT WHERE ID = " + deptId;
        bb.writeLog("车辆维护申请领导部门查询sql" + sql);
        rs.execute(sql);
        if(rs.next()){
            String supdepid = rs.getString("supdepid");
            bb.writeLog("车辆维护申请领导部门supdepid" + supdepid);
            sqlCondition =" t1.ssjg = '" +supdepid +"'";
            return sqlCondition;
        }

        return sqlCondition;
    }

}

