package weaver.interfaces.htsc.wdzx;

import weaver.conn.RecordSet;
import weaver.formmode.customjavacode.AbstractCustomSqlConditionJavaCode;
import weaver.general.BaseBean;
import weaver.hrm.User;
import weaver.hrm.resource.ResourceComInfo;
import weaver.interfaces.htsc.GlobatTools.JAVATools;

import java.util.Map;

public class ModeqbSearchTemplate extends AbstractCustomSqlConditionJavaCode {
    @Override
    public String generateSqlCondition(Map<String, Object> param) throws Exception {
        User user = (User)param.get("user");
        BaseBean bb = new BaseBean();
        RecordSet rs = new RecordSet();
        String sqlCondition = "";
        // (userid in(glyfzzd) or userid in(cjrfzzd)) and ywcj = ywcj
        int userid = user.getUID();
        String userids = "select * from hrmresource where workcode in (select workcode  from hrmresource where id in ("+userid+")) ";
        rs.execute(userids);
        while(rs.next()){
            String id = rs.getString("id");
            sqlCondition += sqlCondition == "" ? " instr( ','|| t1.cjrfzzd || ',' , ',"+id+",') >0  " : " or instr( ','|| t1.cjrfzzd || ',' , ',"+id+",') >0 ";
            sqlCondition += sqlCondition == "" ?  " instr( ','|| t1.glyfzzd || ',' , ',"+id+",') >0  " : "  or instr( ','|| t1.glyfzzd || ',' , ',"+id+",') >0  ";
        }
        if(!"".equals(sqlCondition)){
            sqlCondition = "("+sqlCondition+")" ;
        }
        bb.writeLog("我全部的sqlCondition====" + sqlCondition);
        return sqlCondition;
    }
}